[HarfBuzz] Questions about interacting with HarfBuzz
Behdad Esfahbod
behdad at behdad.org
Tue Oct 9 10:38:21 PDT 2012
Hi Lóránt,
Sorry for the delayed response. I've been traveling. (and will be for the
next few weeks). Grigori already gave you some ideas, I'll try to complement
them:
On 10/02/2012 04:51 PM, Lóránt Pintér wrote:
> Hi Behdad,
>
> I finally managed to get OT layouting with HarfBuzz to work in JavaScript via
> Emscripten. It's awesome! :) There are still some open questions though. Can
Fantastic! Got any demos?
> you please help me with them?
>
> * *How should I find out if a glyph returned by hb_shape() is a ligature?*
Well, easier if you tell us what exactly you want to do. That a glyph is a
ligature is not such an interesting concept for most usecases.
Typically what you need is cursor positions. In general, there is no cursor
position after every character. You need to use the Unicode Grapheme
Boundaries algorithm to determine where there are cursor positions. Then, the
shaping result divides text into a bunch of "clusters". Each cluster consists
of one or more characters, and one or more glyphs. That's all you can rely
on. If the number of characters in the cluster is more than the number of
glyphs in the cluster, you can be sure that there is *some* ligature glyph in
there. But as I said, it doesn't really mean much.
Now, having the cluster, and the number of cursor positions in the cluster,
you can go ahead and decide where to draw the cursor. If the ligature-carets
are available, you can try using them. Otherwise, just divide the width of
the cluster evenly by the number of the cursor positions.
> I found some static functions in hb-ot-layout-private.hh like
> is_a_ligature(), but these are not C externs, so I cannot access them
> from JavaScript. Is there some other way supported by HarfBuzz, or shall
> I re-implement these functions in JS by inspecting the glyph_info_t struct?
Those wont work. Please don't try peeking in.
> * *How can I find internal x_advance positions inside a ligature?* The
> GDEF table should contain information about this. Does HarfBuzz expose
> it in any way?
See my notes above. "internal x_advance" doesn't mean much. Fonts can be
designed in funny ways. The individual x_advance of the glyphs should not be
used. You can get them using hb_font_get_glyph_h_advance() though.
> * *How should I find out if a character was split into multiple glyphs?* I
> guess the "cluster" field of a glyph_info_t is about this, right? If I
> have a blown-up character, how can I find the caret positions that I
> should use?
Same comments.
> * *Can HarfBuzz handle the Apple "kern," "morx" etc. tables?* If not, is
> it safe to use FontForge to convert these fonts to use OpenType's
> GPOS/GSUB etc.? This is not very
> encouraging: http://fontforge.org/gposgsub.html
No 'morx'. And as you noted, the conversion is not straightforward.
> * *Which features are turned on by default?* I can see that ligatures and
> kerning are turned on for my simple Latin text, and I can successfully
> turn them off by supplying features "-kern" and "-liga," but I'm still
> curious what the defaults are.
See hb-ot-shape.cc.
> * *When kerning is applied, I get funny x_advances.* This might be an
> error on my side, but currently when a pair of glyphs is kerned, the
> first character get's an x_advance that seems to have something like
> "42949017" subtracted from it. Because ligature substitution works
> perfectly, I assume GSUB table parsing works fine, so I don't see why
> GPOS would fail. Any pointers here?
Can't help without seeing the code / font. Did you try the code in C first BTW?
Cheers,
behdad
> Thanks a lot for any help you can provide! Also, if I can help out with
> writing documentation, please let me know.
>
> Lorant
More information about the HarfBuzz
mailing list