[HarfBuzz] Kerning, glyph width, and x advance

Martin Hosken mhosken at gmail.com
Thu Sep 3 23:40:54 PDT 2015


Dear Simon,

> So I'm using Harfbuzz to shape stuff and put it out to PDF. When you
> output a string in PDF, you are expected to kern it manually, or else
> each glyph will be placed one after the other with no kerning:
> 
>  No kerning: Td (VAVAVOOM) Tj
>     Kerning: Td[(V) 153 (A) 122 (V) ... ]TJ
> 
> The numeric values in the TJ array are the distances to go back after
> the glyph is painted. In other words, this is the unkerned X advance
> minus the kerned X advance.
> 
> I had assumed that the unkerned glyph advance was the width of the
> character, but that's not the case:

No. There is an advance array in the pdf as part of the font definition. It comes from the hmtx table with each glyph having its own advance width which is independent of the bounding box of the glyph. So you'll need to basically calculate the distance between adjacent glyphs and subtract the advance of the first width to get your number. But thankfully you won't need to run shaping twice.

Yours,
Martin


More information about the HarfBuzz mailing list