[HarfBuzz] Questions about positioning

Behdad Esfahbod behdad at behdad.org
Tue Nov 20 03:14:09 UTC 2018


Hi Sylvain,

On Mon, Nov 19, 2018 at 11:52 AM Sylvain Becker <sylvain.becker at gmail.com>
wrote:

> Hello,
>
> I am using HarfBuzz and FreeType to render text in 70 languages and result
> is very good, even looking into details!
> I wonder if I could get some explanation to deal with better positioning.
>

Good to hear.

Both HB and FT provides datas: which ones to choose explicitly?
>

You mostly want the HB numbers, except for rasterizing glyph bitmaps, which
is FT's forte.


> Format is fractional 26/6, but how and when to round?
>

Depends on many factors.  This might help: http://goo.gl/yf3M7

I've sum up all positions datas (with owner prefixes).
> This is about horizontal layout and LTR (but could also be RTL).
>
> From FreeType (Face/glyph/metrics).
> - FT_offset_x (horiBearingX),
>

You don't need that per se.  When you render a bitmap using FreeType
though, that bitmap has left/top positioning that you need to add to
HarfBuzz glyph position.


> - FT_kerning_x
>

You don't need this.  HarfBuzz does kerning and other positioning.


> - FT_rsb/lsb_deltas (hinting)
>

Nice idea.  Used by no one.  ignore.

- FT_advance_x
>

Ignore.  HarfBuzz does positioning.


> From HarfBuzz (hb_glyph_position_t)
> - HB_x_advance
> - HB_x_offset
> - HB_y_offset
>

Glyph "origin" for glyph number i in the shape result buffer is:

  x = sum(x_advance[j] for 0 <= j < i) + x_offset[i]
  y = y_offset[i]


> In y axis:
> - FT_offset_y (ascender or height - horiBearingY)
>

Again, ignore.

- HB_y_offset
>

See above.

Rounding:
> - FLOOR(X) (((X) & -64) / 64)
> - CEIL(X)  FLOOR((X) + 63)
> - ROUND(X) FLOOR((X) + 32)
>
> - How to round and when?
>

Depends on 1. whether you want linearly-scalable layout, or pixel-optimized
layout, and your graphics system's capabilities for rendering
subpixel-positioned glyphs and whether you want that (extra memory / CPU
cost).

(Why does HB provide fractionnals if tutorials start by using floor()?).
>

Some graphics systems only support pixel-aligned glyph rendering.


> - With hinting (auto hinted), should we use FT rsb/lsb_detlas?
>

Again, nice idea, too cumbersome to use.

- What about FT kerning ?
>

Never.

Of course I've a start of a solution. Result looks 99% ok I guess.
> Maybe I've some rounding (1px) between spacing or hinted glyph offset.
>
> I've also seen:
>
> https://github.com/harfbuzz/harfbuzz-tutorial/blob/master/hello-harfbuzz-freetype.c
> https://cgit.freedesktop.org/cairo/tree/src/cairo-ft-font.c
> But for instance:
> - HB provides fractionals 26/6, but tutorial starts by using floor()?
> - Cairo convert to double and don't use rsb/lsb_delta, not even kerning
> and is not aware of HB ?
>

Cairo receives final glyph positions, so doesn't need to know about HB

Thanks for you help,
> Sylvain
>

Hope that helps.

-- 
behdad
http://behdad.org/
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.freedesktop.org/archives/harfbuzz/attachments/20181119/cd0359b3/attachment.html>


More information about the HarfBuzz mailing list