Getting vertical metrics for an instance

I’m looking for the most performant way to get the interpolated vertical metrics for an instance, via Python. I can get it like this…

myInstance.interpolatedFont.masters[0].ascender

…but the docs lead me to think that this might not be as performant as using interpolatedFontProxy. I don’t care about any glyph data, and don’t want to be slowed down by waiting for glyphs to interpolate. The problem is that interpolatedFontProxy.fontMasters() returns a list of multiple masters (like my original font) rather than a single interpolated master, like interpolatedFont does.

What’s the fastest approach for getting an instance’s interpolated vertical metrics?

Metrics are available in all GSLayer objects, so that’s what I would probably use. This will get you the interpolated metrics:

inst = Font.instances[0]
ifp = inst.interpolatedFontProxy
print(ifp.glyphs['A'].layers[0].metrics)

It should be fast since it only needs to interpolate one glyph.

master = font.interpolateFontMaster_interpolation_scale_thin_error_(instance, instance.instanceInterpolations, 1, True, None)

The resulting GSFontMaster doesn’t have any metrics.

The master needs to have access to the font.

master = font.interpolateFontMaster_interpolation_scale_thin_error_(instance, instance.instanceInterpolations, 1, True, None)
master.font = font

Thanks, Georg! That method seems to return a tuple, so it needs a [0] at the end. But then it works. Out of curiosity, what does the thin True parameter mean?

It controls how much extra data is interpolated.

1 Like