Bad font data after instantiating variable font
See original GitHub issueI’m coming across bad font data when using fontTools pens to interact with instantiated variable fonts. The problem can be reproduced in every contour in every Quadratic variable font I’ve tried.
When reading the point data with a pen, the point order is offset by one (which in this case I don’t mind) and the last two lineTo
points are joined together into a qCurve
segment (which distorts the shape). The problem happens in both the instancer
and mutator
variations of the instantiateVariableFont
function.
However, the font data in the TTF looks fine to me when I save it to a file and open it in an editor or read through a TTX dump.
This demo just happens to use Monserrat (to make sure that the problem wasn’t in my own font) and I set the location to the default weight to make the output comparison more clear, but the problem happens at any location (and with any Quadratic TTF)
Can anyone think of what I might be doing wrong, or where the problem might be coming from?
from fontTools.varLib import mutator, instancer
from fontTools.ttLib import TTFont
from fontTools.pens.recordingPen import RecordingPen
def printReport(f):
g = f.getGlyphSet()["I"]
pen = RecordingPen()
g.draw(pen)
for i in pen.value:
print(i)
fontPath = "Montserrat-VF.ttf"
location = {"wght":100}
print("Default:")
f = TTFont(fontPath)
printReport(f)
print("\nmutator.instantiateVariableFont")
instM = mutator.instantiateVariableFont(f, location)
#instM.save("mutator.ttf")
printReport(instM)
print("\ninstancer.instantiateVariableFont")
instI = instancer.instantiateVariableFont(f, location)
#instI.save("instancer.ttf")
printReport(instI)
Output:
Default:
('moveTo', ((133, 700),))
('lineTo', ((153, 700),))
('lineTo', ((153, 0),))
('lineTo', ((133, 0),))
('lineTo', ((133, 700),))
('closePath', ())
mutator.instantiateVariableFont
('moveTo', ((153, 700),))
('lineTo', ((153, 0),))
('lineTo', ((133, 0),))
('qCurveTo', ((133, 700), (153, 700)))
('closePath', ())
instancer.instantiateVariableFont
('moveTo', ((153, 700),))
('lineTo', ((153, 0),))
('lineTo', ((133, 0),))
('qCurveTo', ((133, 700), (153, 700)))
('closePath', ())
Issue Analytics
- State:
- Created 4 years ago
- Comments:6 (1 by maintainers)
Top GitHub Comments
Formally this bug is 16 years old! This code barely changed in the meantime, it only got moved around a bit.
thanks Just! https://github.com/fonttools/fonttools/releases/tag/4.2.1