<div dir="ltr">ok thanks!! && in that case yall best fix the example at <a href="https://github.com/behdad/harfbuzz/blob/master/src/sample.py">https://github.com/behdad/harfbuzz/blob/master/src/sample.py</a> then because it just uses <span style="font-family:monospace,monospace">string.encode('utf-x')</span>. which is confusing.<br></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Jun 16, 2016 at 10:44 PM, Khaled Hosny <span dir="ltr"><<a href="mailto:khaledhosny@eglug.org" target="_blank">khaledhosny@eglug.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">On Thu, Jun 16, 2016 at 09:35:03PM -0400, Kelvin Ma wrote:<br>
> When I run a simple harfbuzz shaping like<br>
><br>
> string = 'In begíffi our '<br>
> > utfstring = string.encode('utf-8')<br>
> ><br>
> > buf = hb.buffer_create()<br>
> > hb.buffer_add_utf8(buf, utfstring, 0, -1)<br>
> > hb.buffer_guess_segment_properties(buf)<br>
> ><br>
> > hb.shape(font, buf, [])<br>
> > infos = hb.buffer_get_glyph_infos(buf)<br>
> > positions = hb.buffer_get_glyph_positions(buf)<br>
> ><br>
><br>
> I get<br>
><br>
> len(string) = 15<br>
> len(infos) = 13<br>
> len(positions) = 13<br>
><br>
> which makes sense, three glyphs became one so 15 characters makes 13<br>
> glyphs. But the cluster values are wrong because they don’t line up with<br>
> the character indexes any more (because of the accented character).<br>
><br>
> But then when I change it to utf-16<br>
><br>
> string = 'In begíffi our '<br>
> > utfstring = string.encode('utf-16')<br>
<br>
</span>You need here a list of UTF-16 code units, but string.encode('utf-16')<br>
just gives you UTF-16 bytes array. You need something like:<br>
<br>
utfstring = [int.from_bytes(c.encode("utf-16be"), byteorder='big') for c in string]<br>
<br>
(This does not handle non-BMP characters that will be encoded as two<br>
UTF-16 code units, but you get the idea).<br>
<br>
> > hb.buffer_add_utf16(buf, utfstring, 0, -1)<br>
<br>
And pass the list length here (or add null character at the end of the<br>
list).<br>
<span class=""><br>
> And when I change it to utf-32, which this post<br>
</span>> <<a href="http://comments.gmane.org/gmane.comp.freedesktop.harfbuzz/1836" rel="noreferrer" target="_blank">http://comments.gmane.org/gmane.comp.freedesktop.harfbuzz/1836</a>> says<br>
<span class="">> should make it give character counts, but<br>
<br>
</span>Same as above.<br>
<br>
Regards,<br>
Khaled<br>
</blockquote></div><br></div>