<div dir="ltr"><div>Hi,</div><div> </div><div>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</div><div>{code}</div><div>const uint16_t *string = ..; // UTF-16 string<br>int str_len = ..; // length of `string` buffer</div><div> </div><div>hb_buffer_add_utf16(buffer, string, str_len, 0, str_len);</div><div>..</div><div>hb_shape_full(..);</div><div> </div><div>const uint num_glyphs = hb_buffer_get_length(buffer);</div><div>ensureSpace(num_glyphs); // ensure we have enough space for shaped glyphs and metrics (here we reallocate the `glyphs`, `advances`, and `offsets` buffers, if needed)<br></div><div>ushort *log_clusters = ..;</div><div>uint *glyphs = ..;<div>float *advances = ..;</div><div>float *offsets_x = ..;</div><div>float *offsets_y = ..;</div></div><div> </div><div>// fetch the shaped glyphs and metrics<br>b_glyph_info_t *infos = hb_buffer_get_glyph_infos(buffer, 0);<br>hb_glyph_position_t *positions = hb_buffer_get_glyph_positions(buffer, 0);<br>uint str_pos = 0;<br>uint last_cluster = ~0u;<br>uint last_glyph_pos = 0;<br>for (uint i = 0; i < num_glyphs; ++i) {<br>    glyphs[i] = infos[i].codepoint;</div><div>    advances[i] = positions[i].x_advance;<br>    offsets_x[i] = positions[i].x_offset;<br>    offsets_y[i] = positions[i].y_offset;</div><div> </div><div>    uint cluster = infos[i].cluster;<br>    if (last_cluster != cluster) {<br>        // fix up clusters so that the cluster indices will be monotonic<br>        // and thus we never return out-of-order indices<br>        while (last_cluster++ < cluster && str_pos < str_len)<br>            log_clusters[str_pos++] = last_glyph_pos;</div><div>        // [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;<br>        last_glyph_pos = i;<br>        last_cluster = cluster;<br>    }<br>}<br>while (str_pos < str_len)<br>    log_clusters[str_pos++] = last_glyph_pos;</div><div><div>{code}</div><div> </div></div></div><div class="gmail_extra"><br clear="all"><div>Regards,<br>Konstantin</div>
<br><div class="gmail_quote">2014-10-30 6:50 GMT+04:00  <span dir="ltr"><<a href="mailto:ff.feng@sunmedia.com.cn" target="_blank">ff.feng@sunmedia.com.cn</a>></span>:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><font face="sans-serif">Hi !</font>
<br>
<br><font face="sans-serif">I'm developing a font engine with harfbuzz
& freetype for Cambodia. </font>
<br><font face="sans-serif">I can get the correct glyph index array
and position array by harfbuzz. </font>
<br><font face="sans-serif">That's sweet.</font>
<br>
<br><font face="sans-serif">Now I got a problem : I'm wondering
how many unicode(UTF16) form a glyph?</font>
<br><font face="sans-serif">(If I specify a item in the glyph index
array from hb_buffer_get_glyph_infos)</font>
<br>
<br><font face="sans-serif">thanks a lot & sorry for my poor
English.</font>
<br>
<br>
<br><font face="sans-serif">Best regards,</font>
<br>
<p><span style="font-family:"Arial";font-size:8pt">**********************************************************************</span></p>
<p><span style="font-family:"Arial";font-size:8pt">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. </span></p>
<p><span style="font-family:"Arial";font-size:8pt">**********************************************************************</span></p>
<p><span style="font-family:"Arial";font-size:8pt"> </span></p>
<br>_______________________________________________<br>
HarfBuzz mailing list<br>
<a href="mailto:HarfBuzz@lists.freedesktop.org">HarfBuzz@lists.freedesktop.org</a><br>
<a href="http://lists.freedesktop.org/mailman/listinfo/harfbuzz" target="_blank">http://lists.freedesktop.org/mailman/listinfo/harfbuzz</a><br>
<br></blockquote></div><br></div>