question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Bad font data after instantiating variable font

See original GitHub issue

I’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:closed
  • Created 4 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

3reactions
justvanrossumcommented, Dec 6, 2019

Formally this bug is 16 years old! This code barely changed in the meantime, it only got moved around a bit.

1reaction
anthrotypecommented, Dec 6, 2019
Read more comments on GitHub >

github_iconTop Results From Across the Web

Variable fonts, axes values - Page 3 - TypeDrawers
I'm interested by how the location of an instance could be used as a data point in user interfaces. In terms of UI,...
Read more >
Best Practices When Using Fonts - Joy of Code
Everything I know about best practices when using fonts on the web. ... Variable Fonts Are The Future of Fonts; How to Subset...
Read more >
Failed to decode downloaded font, OTS parsing error
I am doing assets pre-compile, and running the application in production mode. After compilation when I load the ...
Read more >
Instantiation from Glyphs source: usWeightClass is set wrong
And user-space coordinates are usWeightClass values? Thing is, the font doesn't compile without Axis Location parameters: ufo2ft.errors.
Read more >
1690235 - Wrong Unicode characters on Greek letters on print to pdf ...
""The latest pre-built binary version of the Last Resort font, which corresponds to "Unicode Version 13.0.0", can be easily downloaded from the Latest ......
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found