From 183b2451fd6515f72c709a40b4e5ab5735427823 Mon Sep 17 00:00:00 2001 From: Kaalleen <36401965+kaalleen@users.noreply.github.com> Date: Mon, 22 Mar 2021 17:06:48 +0100 Subject: update font tools etc (#1086) * update font tools * fix tie error * ignore duplicated commands --- lib/lettering/kerning.py | 25 +++++++++++++++++-------- 1 file changed, 17 insertions(+), 8 deletions(-) (limited to 'lib/lettering/kerning.py') diff --git a/lib/lettering/kerning.py b/lib/lettering/kerning.py index 920e7d59..710b02aa 100644 --- a/lib/lettering/kerning.py +++ b/lib/lettering/kerning.py @@ -7,7 +7,7 @@ class FontKerning(object): This class reads kerning information from an SVG file """ def __init__(self, path): - with open(path) as svg: + with open(path, 'r', encoding="utf-8") as svg: self.svg = etree.parse(svg) # horiz_adv_x defines the wdith of specific letters (distance to next letter) @@ -46,21 +46,30 @@ class FontKerning(object): # the space character def word_spacing(self): xpath = "string(.//svg:glyph[@glyph-name='space'][1]/@*[name()='horiz-adv-x'])" - word_spacing = self.svg.xpath(xpath, namespaces=NSS) or 26 - return int(word_spacing) + word_spacing = self.svg.xpath(xpath, namespaces=NSS) + try: + return int(word_spacing) + except ValueError: + return None # default letter spacing def letter_spacing(self): xpath = "string(.//svg:font[@horiz-adv-x][1]/@*[name()='horiz-adv-x'])" - letter_spacing = self.svg.xpath(xpath, namespaces=NSS) or 0 - return int(letter_spacing) + letter_spacing = self.svg.xpath(xpath, namespaces=NSS) + try: + return int(letter_spacing) + except ValueError: + return None # this value will be saved into the json file to preserve it for later font edits # additionally it serves to automatically define the line height (leading) - def units_per_em(self, default=100): + def units_per_em(self): xpath = "string(.//svg:font-face[@units-per-em][1]/@*[name()='units-per-em'])" - units_per_em = self.svg.xpath(xpath, namespaces=NSS) or default - return int(units_per_em) + units_per_em = self.svg.xpath(xpath, namespaces=NSS) + try: + return int(units_per_em) + except ValueError: + return None """ def missing_glyph_spacing(self): -- cgit v1.2.3