Skip to content

Commit

Permalink
restore glyph_data as list of paths to be parsed into GlyphData objec…
Browse files Browse the repository at this point in the history
…t (but only once)

Fixes #1019
  • Loading branch information
anthrotype committed Aug 15, 2024
1 parent 6c459b2 commit 47dc620
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 11 deletions.
12 changes: 11 additions & 1 deletion Lib/glyphsLib/builder/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
)
Expand Down Expand Up @@ -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
)
Expand Down
13 changes: 3 additions & 10 deletions Lib/glyphsLib/builder/builders.py
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down

0 comments on commit 47dc620

Please sign in to comment.