diff options
Diffstat (limited to 'lib/lettering')
| -rw-r--r-- | lib/lettering/font.py | 5 | ||||
| -rw-r--r-- | lib/lettering/kerning.py | 25 |
2 files changed, 19 insertions, 11 deletions
diff --git a/lib/lettering/font.py b/lib/lettering/font.py index 7b479072..b1979067 100644 --- a/lib/lettering/font.py +++ b/lib/lettering/font.py @@ -14,7 +14,6 @@ from ..elements import nodes_to_elements from ..exceptions import InkstitchException from ..i18n import _, get_languages from ..stitches.auto_satin import auto_satin -from ..svg import PIXELS_PER_MM from ..svg.tags import INKSCAPE_LABEL, SVG_GROUP_TAG, SVG_PATH_TAG from ..utils import Point from .font_variant import FontVariant @@ -108,7 +107,7 @@ class Font(object): name = localized_font_metadata('name', '') description = localized_font_metadata('description', '') default_glyph = font_metadata('defalt_glyph', "�") - leading = font_metadata('leading', 5, multiplier=PIXELS_PER_MM) + leading = font_metadata('leading', 100) kerning_pairs = font_metadata('kerning_pairs', {}) auto_satin = font_metadata('auto_satin', True) min_scale = font_metadata('min_scale', 1.0) @@ -124,7 +123,7 @@ class Font(object): horiz_adv_x_default = font_metadata('horiz_adv_x_default') # Define by <glyph glyph-name="space" unicode=" " horiz-adv-x="22" />, Example font.json : "horiz_adv_x_space":22, - word_spacing = font_metadata('horiz_adv_x_space', 0) + word_spacing = font_metadata('horiz_adv_x_space', 20) reversible = font_metadata('reversible', True) diff --git a/lib/lettering/kerning.py b/lib/lettering/kerning.py index 6db9ba1e..6380f1a6 100644 --- a/lib/lettering/kerning.py +++ b/lib/lettering/kerning.py @@ -12,7 +12,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) @@ -51,21 +51,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): |
