Sam Howard Sam is a developer at IDRsolutions who specialises in font rendering and conversion. He's also enjoyed working with SVG, Java 3D, Java FX and Swing.

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.

IDRsolutions develop a Java PDF Viewer and SDK, an Adobe forms to HTML5 forms converter, a PDF to HTML5 converter and a Java ImageIO replacement. On the blog our team post anything interesting they learn about.

Sam Howard Sam is a developer at IDRsolutions who specialises in font rendering and conversion. He's also enjoyed working with SVG, Java 3D, Java FX and Swing.

Leave a Reply

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

IDRsolutions Ltd 2019. All rights reserved.