[HarfBuzz] Kerning, glyph width, and x advance

Behdad Esfahbod behdad at behdad.org
Thu Sep 3 23:50:12 PDT 2015


Simon,

You are confusing a few different things!  The width reported by glyph
extents is the ink width.  That's different from advance width because even
without kerning, adjacent glyphs typically don't touch each other.

You need the advance width, and you can get that using
hb_font_get_glyph_h_advance().

Also, don't try to second-guess the shaper, ever!  Even if you turn kern
feature off, other things might be happening that change the advance width,
so never assume that it's the default advance width even if kern feature is
off.

behdad

On Fri, Sep 4, 2015 at 3:32 AM, Simon Cozens <simon at simon-cozens.org> wrote:

> 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?
> _______________________________________________
> HarfBuzz mailing list
> HarfBuzz at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/harfbuzz
>



-- 
behdad
http://behdad.org/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/harfbuzz/attachments/20150904/4ec426db/attachment.html>


More information about the HarfBuzz mailing list