[HarfBuzz] HarfBuzz glyph offsets
Nikolay Sivov
bunglehead at gmail.com
Wed Dec 23 15:12:28 PST 2015
On 24.12.2015 1:37, Jonathan Blow wrote:
>>
>>
>>
>> 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.
>>
>
> Okay, this is confusing. Maybe this has to do with different cultural
> assumptions or different ideas about what the software looks like, but
> bearings are just offsets to me. When I look at this diagram from the
> FreeType documentation:
>
> http://www.freetype.org/freetype2/docs/tutorial/step2.html
>
> It says that wherever the cursor is, add bearingX as an offset and draw the
> thing in the box. And in fact this is how I draw things when they show up
> in the proper places. So I am not sure what you mean here; my guess is that
> you are thinking of there being a little bit of a software stack living
> below you that itself adds bearingX to draw the thing in the box, so that
> it would be incorrect for you to do so?
>
> So then my interpretation is that the 'offsets' from HB are additional and
> are not meant to include bearings, and are only for kerning or for like
> things, and I should actually add both offsets together I guess.
>
You don't need to look into bearings metrics if you want to render
something. And no, they are not offsets.
HB gives you advances and offset vectors. So what you need to do is:
(origin) -> (render glyph at origin+offset) -> (move origin by advance)
-> repeat.
Offsets are relative to current origin and do not affect how origin is
moving from glyph to glyph.
>
>> 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.
>>
>
> That's quite possible, I will investigate. My old code, pre-HB, would
> switch to drawing glyphs right-to-left for RTL languages, but upon starting
> to use HB I was pretty confused because it looks to me like HB is always
> giving me glyphs in left-to-right order, even for RTL languages (if there
> is a setting that changes this, I have no idea). So at some point I just
> simplified all the rendering code to always be LTR, though it is possible I
> made a mistake or else for some reason kerning is RTL while everything else
> is LTR which would be really weird??
Directionality is more complicated than setting a text property
unfortunately. To shape it properly you have to pass segments of text of
same resolved direction to HB, it won't do it for you.
>
> Oh wait ... I remember something about kerning in otf/ttf always having to
> do with the logical order of glyphs and not the display order; does HB keep
> this convention? I had interpreted offsets as being screen positions, not
> deltas in some abstract kerning space, so that could be the source of the
> issue.
Opentype 'kern' kerning adjustments will be applied to advances/offsets.
>
>>
>> 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).
>>
>
> In this case we have a fixed set of languages (currently 15) that we are
> just swapping in and out, so I can set this stuff on a per-language basis,
> so I guess for each one I need to know:
>
> * what to pass to hb_buffer_set_script
>
> * what to pass to hb_buffer_set_language (I am not sure how this latter
> affects results in different ways than the former)
Language is not the same as script, that's why there's a separate
setting. Take a look how opentype features are organized to get an idea
of how scripts and languages relate.
For script you should pass a script your segment has, this could be
determined using Unicode char ranges data. Language should be set
explicitly.
>
> ... Anything else?
>
>
>
> _______________________________________________
> HarfBuzz mailing list
> HarfBuzz at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/harfbuzz
>
More information about the HarfBuzz
mailing list