[HarfBuzz] How many unicode make up a glyph?

Konstantin Ritt ritt.ks at gmail.com
Thu Oct 30 05:31:55 PDT 2014


Hi,

if I understood you correctly, you're talking about the Unicode code point
to glyph mapping (aka logical to visual cluster mapping). If so, it would
look like
{code}
const uint16_t *string = ..; // UTF-16 string
int str_len = ..; // length of `string` buffer

hb_buffer_add_utf16(buffer, string, str_len, 0, str_len);
..
hb_shape_full(..);

const uint num_glyphs = hb_buffer_get_length(buffer);
ensureSpace(num_glyphs); // ensure we have enough space for shaped glyphs
and metrics (here we reallocate the `glyphs`, `advances`, and
`offsets` buffers, if needed)
ushort *log_clusters = ..;
uint *glyphs = ..;
float *advances = ..;
float *offsets_x = ..;
float *offsets_y = ..;

// fetch the shaped glyphs and metrics
b_glyph_info_t *infos = hb_buffer_get_glyph_infos(buffer, 0);
hb_glyph_position_t *positions = hb_buffer_get_glyph_positions(buffer, 0);
uint str_pos = 0;
uint last_cluster = ~0u;
uint last_glyph_pos = 0;
for (uint i = 0; i < num_glyphs; ++i) {
    glyphs[i] = infos[i].codepoint;
    advances[i] = positions[i].x_advance;
    offsets_x[i] = positions[i].x_offset;
    offsets_y[i] = positions[i].y_offset;

    uint cluster = infos[i].cluster;
    if (last_cluster != cluster) {
        // fix up clusters so that the cluster indices will be monotonic
        // and thus we never return out-of-order indices
        while (last_cluster++ < cluster && str_pos < str_len)
            log_clusters[str_pos++] = last_glyph_pos;
        // [last_glyph_pos..i) forms a single glyph cluster; if you have
glyph attributes, here you could remember the cluster start for iterating
over the glyph clusters later, e.g. attribs[i].clusterStart = true;
        last_glyph_pos = i;
        last_cluster = cluster;
    }
}
while (str_pos < str_len)
    log_clusters[str_pos++] = last_glyph_pos;
{code}


Regards,
Konstantin

2014-10-30 6:50 GMT+04:00 <ff.feng at sunmedia.com.cn>:

> Hi !
>
> I'm developing a font engine with harfbuzz & freetype for Cambodia.
> I can get the correct glyph index array and position array by harfbuzz.
> That's sweet.
>
> Now I got a problem : I'm wondering how many unicode(UTF16) form a glyph?
> (If I specify a item in the glyph index array from
> hb_buffer_get_glyph_infos)
>
> thanks a lot & sorry for my poor English.
>
>
> Best regards,
>
> **********************************************************************
>
> The preceding e-mail message (including any attachments) may contain
> confidential information intended for a specific individual and purpose.If
> you are not an intended recipient of this message, please notify the sender
> by replying to this message and then delete it from your
> system.Use,dissemination, distribution, or reproduction of this message by
> unintended recipients is not authorized and may be unlawful.
>
> **********************************************************************
>
>
>
> _______________________________________________
> HarfBuzz mailing list
> HarfBuzz at lists.freedesktop.org
> http://lists.freedesktop.org/mailman/listinfo/harfbuzz
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freedesktop.org/archives/harfbuzz/attachments/20141030/5eb8138f/attachment.html>


More information about the HarfBuzz mailing list