Sam Howard

Sam is a developer at IDRsolutions who mostly specialises in font support and conversion. He’s also enjoyed working with Java 3D, Java FX and Swing. His other interests include music and game design.

Font Scaling look wrong on Android? This might be why.

1 min read

Fonts on Android
Fonts Scaling on Android looks wrong

I spend a lot of time working with fonts in our PDF to HTML5 Converter and have found that the set up for rendering fonts on the web is pretty complex. Browsers need to run on many different platforms, and so use a range of different font rendering engines – sometimes provided by the operating system, and sometimes as an included library. Chrome and Firefox also use a library called OTS to pre-check fonts, but issues – like incorrect font scaling – occasionally slip through.

We were seeing some converted CFF fonts rendering at the wrong size in Chrome on Android. It turns out that the font renderer used on Android does not support a value called FontMatrix which allows you to apply a scale and transform to all of your glyphs.

Since some fonts are actually drawn at a different size (in my experience, usually around twice the size) and then scaled appropriately using FontMatrix, we have a problem.

So how do we fix it?

First off, we work out the scale from the FontMatrix, then set FontMatrix to the default values. We read the glyph descriptions into an intermediate format, scale them, and then convert them back to binary. We then use these updated glyphs to generate a whole bunch of metrics which browsers use for positioning, and scale a few other values to make sure glyph widths come out right.

That might seem like a lot to do just to support a very small set of CFF fonts, but when it comes to fonts, all browsers have their quirks – and we’re committed to supporting as many files, browsers and platforms as we can.

Hopefully you have found this useful.

If you’re a first-time reader, or simply want to be notified when we post new articles and updates, you can keep up to date by social media (TwitterFacebook and Google+) or the Blog RSS.

Sam Howard

Sam is a developer at IDRsolutions who mostly specialises in font support and conversion. He’s also enjoyed working with Java 3D, Java FX and Swing. His other interests include music and game design.

How to run CheckStyle, PMD and FindBugs from Maven

What is static program analysis? Static analysis provides testing against code bases and binaries without the execution of any code. IDEs do this too...
Ovidijus Okinskas
2 min read

Leave a Reply

Your email address will not be published. Required fields are marked *