[HarfBuzz] HarfBuzz glyph offsets

Khaled Hosny khaledhosny at eglug.org
Wed Dec 23 13:46:59 PST 2015


On Wed, Dec 23, 2015 at 01:27:45PM -0800, Jonathan Blow wrote:
> I am having a weird problem where I can render text with HarfBuzz and it is
> generally doing the right thing in terms of shaping, but glyph offsets seem
> to be coming out zero all the time, leading to general badness.
> 
> Here's a very clear case, I am rendering Chinese with the initial character
> being this left-bracket-quote-thing that is supposed to be offset pretty
> far to the right:
> 
> [image: Inline image 1]
> 
> (Yeah, nothing is really happening here to shape this text, I am just
> saying that the shaping and all that is working fine with Arabic etc, but
> this particular square-bracket quote is a really obvious case of an offset
> being wrong).
> 
> The hb_glyph_position_t for this glyph gives me:
> 
> x_advance = 2880
> y_advance = 0
> x_offset = 0
> y_offset = 0
> 
> Now, when I ask FreeType about the glyph,
> 
> format = FT_GLYPH_FORMAT_BITMAP
> bitmap_left = 29
> bitmap_top = 39
> advance.x = 2880
> advance.y = 0
> metrics.horiBearingX = 1856
> metrics.horiBearingY = 2496
> metrics.horiAdvanace = 2880
> 
> So the advances agree, but the offsets are getting dropped on the floor
> somehow.

FreeType does not give you any offsets. Unless you mean the side
bearings, but they are very different things and shouldn’t be used for
glyph placement at all. You are getting 0 offsets because either the
font does not do any special positioning here (not uncommon for old
Chinese fonts), or something is wrong in the way the text is shaped.

> (My Arabic rendering is messed up too, by the way ... you can see the
> current results at this blog posting:
> http://the-witness.net/news/2015/12/entering-the-home-stretch/ ... so it is
> not like this is a corner case.)

For Arabic, it looks like you are applying the kerning on the wrong
direction, see how the ا in لطراز is moving closer to the ز instead of
the ر as I’d expect it.

> 
> To shape I am doing this:
> 
>     hb_buffer_clear_contents(hb_buffer);
>     hb_buffer_set_direction(hb_buffer, HB_DIRECTION_LTR);
>     hb_buffer_set_script(hb_buffer, HB_SCRIPT_UNKNOWN);

If you are not setting the correct text script, then you are unlikely to
get correct output. You need to analyse the text and pass the correct
script to HarfBuzz (resolving characters with common and inhere tied
script properties, etc).

Regards,
Khaled


More information about the HarfBuzz mailing list