Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sparse cff2 #3234

Merged
merged 3 commits into from
Aug 2, 2023
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
28 changes: 22 additions & 6 deletions Lib/fontTools/varLib/cff.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,10 +350,24 @@
addCFFVarStore(varFont, model, cvData.varDataList, cvData.masterSupports)


def _get_cs(charstrings, glyphName):
def _get_cs(charstrings, glyphName, filterEmpty=False):
if glyphName not in charstrings:
return None
return charstrings[glyphName]
cs = charstrings[glyphName]

if filterEmpty:
cs.decompile()
# print(cs.program)
if cs.program == []: # CFF2 empty charstring
return None

Check warning on line 362 in Lib/fontTools/varLib/cff.py

View check run for this annotation

Codecov / codecov/patch

Lib/fontTools/varLib/cff.py#L362

Added line #L362 was not covered by tests
elif (
len(cs.program) <= 2
and cs.program[-1] == "endchar"
and (len(cs.program) == 1 or type(cs.program[0]) in (int, float))
): # CFF1 empty charstring
return None

return cs


def _add_new_vsindex(
Expand All @@ -373,16 +387,15 @@


def merge_charstrings(glyphOrder, num_masters, top_dicts, masterModel):

vsindex_dict = {}
vsindex_by_key = {}
varDataList = []
masterSupports = []
default_charstrings = top_dicts[0].CharStrings
for gid, gname in enumerate(glyphOrder):
all_cs = [_get_cs(td.CharStrings, gname) for td in top_dicts]
if len([gs for gs in all_cs if gs is not None]) == 1:
continue
all_cs = [
_get_cs(td.CharStrings, gname, i != 0) for i, td in enumerate(top_dicts)
]
model, model_cs = masterModel.getSubModel(all_cs)
# create the first pass CFF2 charstring, from
# the default charstring.
Expand Down Expand Up @@ -411,6 +424,9 @@
)
default_charstrings[gname] = new_cs

if not region_cs:
continue

if (not var_pen.seen_moveto) or ("blend" not in new_cs.program):
# If this is not a marking glyph, or if there are no blend
# arguments, then we can use vsindex 0. No need to
Expand Down