From 6c459b21b37a41802dea2f521b105d350f2e7d60 Mon Sep 17 00:00:00 2001 From: Cosimo Lupo Date: Thu, 15 Aug 2024 17:34:47 +0100 Subject: [PATCH 1/2] add repro for issue #1019 --- tests/builder/builder_test.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/builder/builder_test.py b/tests/builder/builder_test.py index aaa39286b..c32f870f3 100644 --- a/tests/builder/builder_test.py +++ b/tests/builder/builder_test.py @@ -2298,6 +2298,8 @@ def test_custom_glyph_data(ufo_module): font = generate_minimal_font() for glyph_name in ("A", "Aitalic-math", "Aitalic-math.ssty1", "foo", "bar", "baz"): add_glyph(font, glyph_name) + # add a composite glyph to trigger propagate_anchors + add_component(font, "bar", "baz", (1, 0, 0, 1, 0, 0)) font.glyphs["baz"].production = "bazglyph" font.glyphs["baz"].category = "Number" font.glyphs["baz"].subCategory = "Decimal Digit" From 47dc620a3a89a1e0d355e5268211665cc214cc7c Mon Sep 17 00:00:00 2001 From: Cosimo Lupo Date: Thu, 15 Aug 2024 17:43:51 +0100 Subject: [PATCH 2/2] restore glyph_data as list of paths to be parsed into GlyphData object (but only once) Fixes #1019 --- Lib/glyphsLib/builder/__init__.py | 12 +++++++++++- Lib/glyphsLib/builder/builders.py | 13 +++---------- 2 files changed, 14 insertions(+), 11 deletions(-) diff --git a/Lib/glyphsLib/builder/__init__.py b/Lib/glyphsLib/builder/__init__.py index 1dcfe0278..263d4d869 100644 --- a/Lib/glyphsLib/builder/__init__.py +++ b/Lib/glyphsLib/builder/__init__.py @@ -15,7 +15,7 @@ import copy import logging -from glyphsLib import classes +from glyphsLib import classes, glyphdata from .builders import UFOBuilder, GlyphsBuilder from .transformations import TRANSFORMATIONS, TRANSFORMATION_CUSTOM_PARAMS @@ -61,9 +61,14 @@ def to_ufos( If preserve_original is True, this works on a copy of the font object to avoid modifying the original object. + + The optional glyph_data parameter takes a list of GlyphData.xml paths or + a pre-parsed GlyphData object that overrides the default one. """ if preserve_original: font = copy.deepcopy(font) + if glyph_data is not None and not isinstance(glyph_data, glyphdata.GlyphData): + glyph_data = glyphdata.GlyphData.from_files(*glyph_data) font = preflight_glyphs( font, glyph_data=glyph_data, do_propagate_all_anchors=propagate_anchors ) @@ -128,9 +133,14 @@ def to_designspace( If preserve_original is True, this works on a copy of the font object to avoid modifying the original object. + + The optional glyph_data parameter takes a list of GlyphData.xml paths or + a pre-parsed GlyphData object that overrides the default one. """ if preserve_original: font = copy.deepcopy(font) + if glyph_data is not None and not isinstance(glyph_data, glyphdata.GlyphData): + glyph_data = glyphdata.GlyphData.from_files(*glyph_data) font = preflight_glyphs( font, glyph_data=glyph_data, do_propagate_all_anchors=propagate_anchors ) diff --git a/Lib/glyphsLib/builder/builders.py b/Lib/glyphsLib/builder/builders.py index 70c1d4014..460a17506 100644 --- a/Lib/glyphsLib/builder/builders.py +++ b/Lib/glyphsLib/builder/builders.py @@ -184,16 +184,9 @@ def __init__( # instances with matching 'familyName' custom parameter self._do_filter_instances_by_family = True - if glyph_data: - from io import BytesIO - - glyphdata_files = [] - for path in glyph_data: - with open(path, "rb") as fp: - glyphdata_files.append(BytesIO(fp.read())) - self.glyphdata = glyphdata.GlyphData.from_files(*glyphdata_files) - else: - self.glyphdata = None + if glyph_data is not None and not isinstance(glyph_data, glyphdata.GlyphData): + glyph_data = glyphdata.GlyphData.from_files(*glyph_data) + self.glyphdata = glyph_data def _is_vertical(self): master_ids = {m.id for m in self.font.masters}