Skip to content

Commit

Permalink
custom_params: register ReplacePrefix before ReplaceFeature
Browse files Browse the repository at this point in the history
This way, ReplacePrefix will be applied before ReplaceFeature.
This is important because, when these two params are used in combination
and the replaced feature contains a reference to a lookup only contained
in the prefix to be replaced, feaLib Parser will trigger an error if
it cannot resolve the lookup reference. Thus it is important to replace
the prefix before the feature body.
  • Loading branch information
anthrotype committed Aug 15, 2019
1 parent 44a30a0 commit 58b0fe4
Showing 1 changed file with 21 additions and 21 deletions.
42 changes: 21 additions & 21 deletions Lib/glyphsLib/builder/custom_params.py
Original file line number Diff line number Diff line change
Expand Up @@ -650,27 +650,6 @@ def to_ufo(self, builder, glyphs, ufo):
register(FilterParamHandler())


class ReplaceFeatureParamHandler(AbstractParamHandler):
def to_ufo(self, builder, glyphs, ufo):
for value in glyphs.get_custom_values("Replace Feature"):
tag, repl = re.split(r"\s*;\s*", value, 1)
ufo._owner.features.text = replace_feature(
tag, repl, ufo._owner.features.text or ""
)

def to_glyphs(self, glyphs, ufo):
# TODO: (jany) The "Replace Feature" custom parameter can be used to
# have one master/instance with different features than what is stored
# in the GSFont. When going from several UFOs to one GSFont, we could
# detect when UFOs have different features, put the common ones in
# GSFont and replace the different ones with this custom parameter.
# See the file `tests/builder/features_test.py`.
pass


register(ReplaceFeatureParamHandler())


class ReplacePrefixParamHandler(AbstractParamHandler):
def to_ufo(self, builder, glyphs, ufo):
repl_map = {}
Expand Down Expand Up @@ -699,6 +678,27 @@ def to_glyphs(self, glyphs, ufo):
register(ReplacePrefixParamHandler())


class ReplaceFeatureParamHandler(AbstractParamHandler):
def to_ufo(self, builder, glyphs, ufo):
for value in glyphs.get_custom_values("Replace Feature"):
tag, repl = re.split(r"\s*;\s*", value, 1)
ufo._owner.features.text = replace_feature(
tag, repl, ufo._owner.features.text or ""
)

def to_glyphs(self, glyphs, ufo):
# TODO: (jany) The "Replace Feature" custom parameter can be used to
# have one master/instance with different features than what is stored
# in the GSFont. When going from several UFOs to one GSFont, we could
# detect when UFOs have different features, put the common ones in
# GSFont and replace the different ones with this custom parameter.
# See the file `tests/builder/features_test.py`.
pass


register(ReplaceFeatureParamHandler())


class ReencodeGlyphsParamHandler(AbstractParamHandler):
""" The "Reencode Glyphs" custom parameter contains a list of
'glyphname=unicodevalue' strings: e.g., ["smiley=E100", "logo=E101"].
Expand Down

0 comments on commit 58b0fe4

Please sign in to comment.