[HarfBuzz] HarfBuzz 1.0 API; the message you were hoping would never come

Konstantin Ritt ritt.ks at gmail.com
Sun Jan 5 22:25:55 PST 2014


2014/1/6 Khaled Hosny <khaledhosny at eglug.org>

> Another thing that I’d like to see sorted before the API is finalised,
> is reverse mapping of output glyphs to input characters with proper
> handling of combing marks. I feel we should keep the current cluster
> stuff since it might have its uses (I’m not sure though) and introduce a
> separate way for that mapping. Either way, I think a more indicative
> name would be better (it took me sometime to understand what those
> clusters are for and they mislead me quit a bit when I tried to use
> HarfBuzz for the first time).
>
> Regards,
> Khaled
>

Oh, I thought I'm the only one who felt into that trouble :)

Here is a result of my tries and fails:
[code]

        ushort *log_clusters = ...;
        const uint num_glyphs = hb_buffer_get_length(buffer);
        hb_glyph_info_t *infos = hb_buffer_get_glyph_infos(buffer, 0);

        for (uint i = 0; i < num_glyphs; ++i) {

            log_clusters[i] = infos[i].cluster;

            // ... glyphs[i] = infos[i].codepoint; and so on
        }


        // adjust clusters

        uint glyph_pos = 0;

        for (uint i = 0; i < num_characters; ++i) {

            if (i != infos[glyph_pos].cluster) {

                for (uint j = glyph_pos + 1; j < num_glyphs; ++j) {

                    if (i <= infos[j].cluster) {

                        if (i == infos[j].cluster)

                            glyph_pos = j;

                        break;

                    }

                }

            }

            log_clusters[i] = glyph_pos;

        }

[/code]

You could agree that the latter part is not obvious.
And except of bringing some inconvenience to the user, lack of reverse
mapping API also hits the performance a bit since we can not avoid this
loop with "if (num_glyphs != num_characters)".

Regards,
Konstantin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/harfbuzz/attachments/20140106/fb0815ca/attachment.html>


More information about the HarfBuzz mailing list