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

[varLib_instancer - updateNameRecords] Allow NameRecord that do not exist for an platform #2941

Open
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

moi15moi
Copy link

Problem that this PR solve

When updating namerecord, allow an NameRecord that do not exist for an platform.

Example of an case where this PR is usefull

When trying to instantiateVariableFont with the font Bahnschrift, an exception is raised.

from fontTools import ttLib
from fontTools.ttLib.tables._f_v_a_r import NamedInstance
from fontTools.varLib import instancer
from typing import List

fontCollection = ttLib.TTCollection()
font = ttLib.TTFont("BAHNSCHRIFT.TTF")
instances: List[NamedInstance] = font["fvar"].instances

for instance in instances:
    generatedFont = instancer.instantiateVariableFont(font, instance.coordinates,  updateFontNames=True)
    fontCollection.fonts.append(generatedFont)

savePath = "BAHNSCHRIFT.ttc"
fontCollection.save(savePath)

It append because the platform 1 doesn't have the nameID that the stat table use.
So, when it try to getName, it return None which raise an exception.

In order not to raise the exception, we catch it and set the variable to None. Like that, we can instantiate our variable font without problem.

…e is not in the Naming Table, set name them to None
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

1 participant