Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Lib/ufo2ft/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ class CFFOptimization(IntEnum):

EXPLICIT_CLOSING_LINE_KEY = UFO2FT_PREFIX + "explicitClosingLine"

EMPTY_NOT_SPARSE_KEY = UFO2FT_PREFIX + "instantiator.emptyNotSparse"

MTI_FEATURES_PREFIX = UFO2FT_PREFIX + "mtiFeatures"

FEATURE_WRITERS_KEY = UFO2FT_PREFIX + "featureWriters"
Expand Down
10 changes: 8 additions & 2 deletions Lib/ufo2ft/instantiator.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
from fontTools.ttLib.tables._n_a_m_e import NameRecord as ftNameRecord
from fontTools.ttLib.tables._n_a_m_e import _makeWindowsName

from ufo2ft.constants import OPENTYPE_CATEGORIES_KEY
from ufo2ft.constants import EMPTY_NOT_SPARSE_KEY, OPENTYPE_CATEGORIES_KEY
from ufo2ft.util import (
_getNewGlyphFactory,
importUfoModule,
Expand Down Expand Up @@ -1084,6 +1084,10 @@ def collect_glyph_masters(
what ufoProcessor is doing. In e.g. Mutator Sans, the 'S.closed' glyph is left
empty in one source layer. One could treat this as a source error, but ufoProcessor
specifically has code to skip that empty glyph and carry on.

An empty glyph whose lib sets
"com.github.googlei18n.ufo2ft.instantiator.emptyNotSparse" to True is meant
to be empty, e.g. a master layer drawn empty in Glyphs, and is kept.
"""
locations_and_masters = []
default_glyph_empty = False
Expand Down Expand Up @@ -1119,7 +1123,9 @@ def collect_glyph_masters(
locations_and_masters = [
(loc, master)
for loc, master in locations_and_masters
if master.contours or master.components
if master.contours
or master.components
or master.lib.get(EMPTY_NOT_SPARSE_KEY)
]

return locations_and_masters
Expand Down
33 changes: 33 additions & 0 deletions tests/instantiator_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1661,3 +1661,36 @@ def test_opentype_categories_from_source_at_instance_location(ufo_module):
{"a": "base"},
{"a": "base", "b": "base"},
]


@pytest.mark.parametrize("marked,empty", [(True, True), (False, True), (True, False)])
def test_explicit_empty_not_sparse_glyph(ufo_module, marked, empty):
d = designspaceLib.DesignSpaceDocument()
d.addAxisDescriptor(
name="Weight", tag="wght", minimum=100, default=100, maximum=200
)
for value in (100, 200):
font = ufo_module.Font()
glyph = font.newGlyph("a")
glyph.width = 500 if value == 100 else 700
if value == 100 or not empty:
pen = glyph.getPen()
pen.moveTo((0, 0))
pen.lineTo((100, 0))
pen.lineTo((100, 100))
pen.closePath()
if value == 200 and marked:
glyph.lib["com.github.googlei18n.ufo2ft.instantiator.emptyNotSparse"] = True
d.addSourceDescriptor(location={"Weight": value}, font=font)
d.addInstanceDescriptor(styleName="Bold", location={"Weight": 200})
d.addInstanceDescriptor(styleName="Between", location={"Weight": 150})
generator = ufo2ft.instantiator.Instantiator.from_designspace(d)
glyph = generator.generate_instance(d.instances[0])["a"]
if marked and empty:
assert len(glyph) == 0
assert glyph.width == 700
with pytest.raises(ufo2ft.instantiator.InstantiatorError):
generator.generate_instance(d.instances[1])
else:
assert len(glyph) == 1
assert len(generator.generate_instance(d.instances[1])["a"]) == 1
Loading