[HarfBuzz] Kerning, glyph width, and x advance

Simon Cozens simon at simon-cozens.org
Thu Sep 3 16:02:42 PDT 2015


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:

$ hb-shape --features='-kern' --show-extents
/Library/Fonts/SuperClarendon.ttc 'VAV'
[V=0+900<38,761,824,-761>|A=1+900<38,761,824,-761>|V=2+900<38,761,824,-761>]

(This is not an OT/FT difference.)

If I want to support OpenType kerning, and I need to compute the
distance-to-go-back, do I really have to shape everything twice and then
compare the x advances, or is there a smarter way to do it?


More information about the HarfBuzz mailing list