[HarfBuzz] A couple of clarifications regarding HarfBuzz
behdad at behdad.org
Wed Oct 20 17:17:05 PDT 2010
On 10/20/10 11:07, Tom Hacohen wrote:
> Dear all,
> I have a couple of questions about things I don't completely understand.
> 1. What does the direction in hb_buffer mean (I'm only talking about LTR
> and RTL, TTB and BTT have more implications)? From what I've seen, it
> only controls whether it should reverse the order of buffer, or not.
Yes, that's it. It's more than plain reversal at the end though. You get the
direction from the output of UAX#9 (eg. FriBidi).
> 2. What does language (in hb_buffer) does? Isn't script enough?
Language is used to do language-specific adjustments when appropriate. You
typically just pass the locale or whatever your higher-level tells you (think
of lang attribute in html) to hb_language_from_string.
> 3. What's the implications of working without setting Unicode functions?
> I don't want to depend on GLib/ICU, and I want to know if I should take
> the effort of implementing my own.
Some of the fallbacks and specific details wouldn't work. For example,
mirroring would not work, which means that you would get incorrect result when
brackets are used in Arabic.
Also, Jonathan Kew has some code in Firefox to implement those. You may want
to check them out.
> 4. I assume the parameter to hb_buffer_create is for allocating the
> needed space as a single bulk and thus avoiding memory fragmentation,
> but how much should I allocate? I mean, I don't know HarfBuzz's
> internals to guess, should I just pass my string's length? Will harfbuzz
> do the needed calculations?
HarfBuzz does the right thing no matter what you pass in. So you can safely
pass 0. String length in characters would be most appropriate if you have it.
> 5. What do the features in hb_shape stand for and how do I manipulate
> them? (I assume this question is because my lack of knowledge and not
> HarfBuzz's lack of docs).
Those are OpenType features. You can ignore them for now I would say.
> 6. How can I translate an index in the buffer to an index in the
> pre-shaped string? (Because indexes may change because of ligatures)
The output glyphs have a member called ->cluster, which points to the start
index of the cluster a glyph is part of.
> 7. That's maybe not completely HarfBuzz related, but how do I get the
> pen positions inside a ligature? (for drawing cursor, handling
> selection, etc etc) or should I just treat the ligature as one group
> once it has shaped into one?
The low-level API to fetch that information from GDEF is available through
hb_ot_layout_get_lig_carets(), however, very few fonts provide such
information. It's common to just divide the width by the number of graphemes.
> I'll probably have more questions later, but those are the basic ones I
> have, thanks,
More information about the HarfBuzz