[HarfBuzz] Dealing with ligatures and text input
Khaled Hosny
khaledhosny at eglug.org
Wed Jan 21 13:19:39 PST 2015
On Wed, Jan 21, 2015 at 04:20:30PM +0100, Diederick Huijbers wrote:
> Hi,
>
> I'm working on a C/C++/OpenGL text input field and wondering if
> someone can give me some advise on how to deal with ligatures and text
> input.
>
> Lets say I have a input field and I type "fi". Now, harfbuzz will
> replace these two characters by the "fi" ligature.
HarfBuzz is merely respecting the font designer’s decision of having or
not having any given ligature.
> To be honest, I've no idea if the ligature "fi" makes the text more
> readable, but I assume it does.
>
> But if I use ligatures (because of the reasons harfbuzz uses them),
> how would I deal with e.g. the placement of the caret in the text
> input field. I should allow the user to move the caret between the "f"
> and "i" for example. Though how would I know the correct (visual) x
> position ?
If you know that a given glyph is a ligature (note that some fonts
implement “ligatures” in a way that gives you the same number of glyphs
for the input characters, so no assumptions should be made here), you
can call “hb_ot_layout_get_ligature_carets()” to get the proper caret
positions inside the ligature. Unfortunately very few fonts provide the
data used by this API (because almost no applications use it), so you
will need a fallback approximation, and AFAIK most applications just
divide the ligature width on the number of its components, so for “fi”
you would place the caret on the middle of the ligature and so on.
> And lets say I use the input field so a user can register him/herself
> and the value is stored in a database. Would I store the "fi" ligature
> or both characters separately?
Your text processing should always be done on the input text stream, not
the glyph indices returned by Harfbuzz.
> Currently I think disabling ligatures is my best option, but I'm not
> sure how I can disable this with harfbuzz.
Even if you can get away with disabling ligatures in Latin script, what
about other scripts where they might be required for proper text
shaping?
Regards,
Khaled
More information about the HarfBuzz
mailing list