From dcebcf38bfee5d942f97e85394c1144796f1f6bb Mon Sep 17 00:00:00 2001 From: Jany Belluz Date: Mon, 23 Oct 2017 15:36:56 +0100 Subject: [PATCH] Rename ufo_module, glyphs_module, masters --- Lib/glyphsLib/builder/__init__.py | 11 +++++---- Lib/glyphsLib/builder/builders.py | 38 +++++++++++++++++++------------ Lib/glyphsLib/builder/font.py | 2 +- 3 files changed, 30 insertions(+), 21 deletions(-) diff --git a/Lib/glyphsLib/builder/__init__.py b/Lib/glyphsLib/builder/__init__.py index ad2424cd8..019052132 100644 --- a/Lib/glyphsLib/builder/__init__.py +++ b/Lib/glyphsLib/builder/__init__.py @@ -23,7 +23,7 @@ def to_ufos(font, include_instances=False, family_name=None, - propagate_anchors=True, defcon=defcon): + propagate_anchors=True, ufo_module=defcon): """Take .glyphs file data and load it into UFOs. Takes in data as Glyphs.app-compatible classes, as documented at @@ -36,23 +36,24 @@ def to_ufos(font, include_instances=False, family_name=None, """ builder = UFOBuilder( font, - defcon, + ufo_module=ufo_module, family_name=family_name, propagate_anchors=propagate_anchors) - result = list(builder.master_ufos) + result = list(builder.masters) if include_instances: return result, builder.instance_data return result -def to_glyphs(ufos, designspace=None, classes=classes): +def to_glyphs(ufos, designspace=None, glyphs_module=classes): """ Take a list of UFOs and combine them into a single .glyphs file. This should be the inverse function of `to_ufos`, so we should have to_glyphs(to_ufos(font)) == font """ - builder = GlyphsBuilder(ufos, designspace=designspace, classes=classes) + builder = GlyphsBuilder( + ufos, designspace=designspace, glyphs_module=glyphs_module) return builder.font diff --git a/Lib/glyphsLib/builder/builders.py b/Lib/glyphsLib/builder/builders.py index 7355dbca7..09134c5a0 100644 --- a/Lib/glyphsLib/builder/builders.py +++ b/Lib/glyphsLib/builder/builders.py @@ -18,29 +18,35 @@ from collections import OrderedDict import logging +import defcon logger = logging.getLogger(__name__) +from glyphsLib import classes from .constants import PUBLIC_PREFIX, GLYPHS_PREFIX class UFOBuilder(object): """Builder for Glyphs to UFO + designspace.""" - def __init__(self, font, defcon, family_name=None, propagate_anchors=True): + def __init__(self, + font, + ufo_module=defcon, + family_name=None, + propagate_anchors=True): """Create a builder that goes from Glyphs to UFO + designspace. Keyword arguments: font -- The GSFont object to transform into UFOs - defcon -- The defcon module to use to build UFO objects (you can pass - a custom module that has the same classes as the official - defcon to get instances of your own classes) + ufo_module -- A Python module to use to build UFO objects (you can pass + a custom module that has the same classes as the official + defcon to get instances of your own classes) family_name -- if provided, the master UFOs will be given this name and only instances with this name will be returned. propagate_anchors -- set to False to prevent anchor propagation """ self.font = font - self.defcon = defcon + self.ufo_module = ufo_module # The set of UFOs (= defcon.Font objects) that will be built, # indexed by master ID, the same order as masters in the source GSFont. @@ -77,7 +83,7 @@ def __init__(self, font, defcon, family_name=None, propagate_anchors=True): @property - def master_ufos(self): + def masters(self): """Get an iterator over master UFOs that match the given family_name. """ if self._ufos: @@ -173,7 +179,7 @@ def instance_data(self): self._instance_family_name)) instance_data = {'data': instances} - first_ufo = next(iter(self.master_ufos)) + first_ufo = next(iter(self.masters)) # the 'Variation Font Origin' is a font-wide custom parameter, thus it is # shared by all the master ufos; here we just get it from the first one @@ -219,20 +225,22 @@ def filter_instances_by_family(instances, family_name=None): class GlyphsBuilder(object): """Builder for UFO + designspace to Glyphs.""" - def __init__(self, ufos, designspace, classes): + def __init__(self, ufos, designspace=None, glyphs_module=classes): """Create a builder that goes from UFOs + designspace to Glyphs. Keyword arguments: ufos -- The list of UFOs to combine into a GSFont designspace -- A MutatorMath Designspace to use for the GSFont - classes -- The glyphsLib.classes module to use to build glyphsLib - classes (you can pass a custom module with the same classes - as the official glyphsLib.classes to get instances of your - own classes) + glyphs_module -- The glyphsLib.classes module to use to build glyphsLib + classes (you can pass a custom module with the same + classes as the official glyphsLib.classes to get + instances of your own classes, or pass the Glyphs.app + module that holds the official classes to import UFOs + into Glyphs.app) """ self.ufos = ufos self.designspace = designspace - self.classes = classes + self.glyphs_module = glyphs_module self._font = None """The GSFont that will be built.""" @@ -244,9 +252,9 @@ def font(self): if self._font is not None: return self._font - self._font = self.classes.GSFont() + self._font = self.glyphs_module.GSFont() for index, ufo in enumerate(self.ufos): - master = self.classes.GSFontMaster() + master = self.glyphs_module.GSFontMaster() self.to_glyphs_font_attributes(ufo, master, is_initial=(index == 0)) self._font.masters.insert(len(self._font.masters), master) diff --git a/Lib/glyphsLib/builder/font.py b/Lib/glyphsLib/builder/font.py index 4d6ed96d0..c209693f0 100644 --- a/Lib/glyphsLib/builder/font.py +++ b/Lib/glyphsLib/builder/font.py @@ -47,7 +47,7 @@ def to_ufo_font_attributes(self, family_name): manufacturer_url = font.manufacturerURL for master in font.masters: - ufo = self.defcon.Font() + ufo = self.ufo_module.Font() if date_created is not None: ufo.info.openTypeHeadCreated = date_created