Skip to content

Commit

Permalink
Merge pull request #581 from anthrotype/fix-bracket-glyphs-GDEF
Browse files Browse the repository at this point in the history
update autogenerated GDEF table after applying bracket glyphs
  • Loading branch information
anthrotype authored Jan 29, 2020
2 parents 11e5976 + 6a051a2 commit 584ceb7
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Lib/glyphsLib/builder/builders.py
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,11 @@ def _apply_bracket_layers(self):
# Finally, copy bracket layers to their own glyphs.
self._copy_bracket_layers_to_ufo_glyphs(bracket_layer_map)

# re-generate the GDEF table since we have added new BRACKET glyphs, which may
# also need to be included: https://github.com/googlefonts/glyphsLib/issues/578
if self.generate_GDEF:
self.to_ufo_features()

def _copy_bracket_layers_to_ufo_glyphs(self, bracket_layer_map):
font = self.font
master_ids = {m.id for m in font.masters}
Expand Down
52 changes: 52 additions & 0 deletions tests/builder/designspace_gen_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,12 +14,16 @@
# limitations under the License.


import io
import os
from xmldiff import main, formatting

import itertools
import pytest

import fontTools.feaLib.parser
import fontTools.feaLib.ast

import glyphsLib
from glyphsLib import to_designspace, to_glyphs
from glyphsLib.util import open_ufo
Expand Down Expand Up @@ -409,3 +413,51 @@ def test_designspace_generation_bracket_no_export_glyph(datadir, ufo_module):
"Bold",
"Bold ]570]",
}


def test_designspace_generation_bracket_GDEF(datadir, ufo_module):
with open(str(datadir.join("BracketTestFont.glyphs"))) as f:
font = glyphsLib.load(f)

# add some attaching anchors to the "x" glyph and its (bracket) layers to
# trigger the generation of GDEF table
for layer in font.glyphs["x"].layers:
anchor = glyphsLib.classes.GSAnchor()
anchor.name = "top"
anchor.position = (0, 0)
layer.anchors.append(anchor)

designspace = to_designspace(font, ufo_module=ufo_module, generate_GDEF=True)

for source in designspace.sources:
ufo = source.font
features = fontTools.feaLib.parser.Parser(
io.StringIO(ufo.features.text), glyphNames=ufo.keys()
).parse()
for stmt in features.statements:
if (
isinstance(stmt, fontTools.feaLib.ast.TableBlock)
and stmt.name == "GDEF"
):
gdef = stmt
for stmt in gdef.statements:
if isinstance(stmt, fontTools.feaLib.ast.GlyphClassDefStatement):
glyph_class_defs = stmt
break
else:
pytest.fail(
f"No GDEF.GlyphClassDef statement found in {ufo!r} features:\n"
f"{ufo.features.text}"
)
break
else:
pytest.fail(
f"No GDEF table definition found in {ufo!r} features:\n"
f"{ufo.features.text}"
)

assert set(glyph_class_defs.baseGlyphs.glyphSet()) == {
"x",
"x.BRACKET.300",
"x.BRACKET.600",
}

0 comments on commit 584ceb7

Please sign in to comment.