[HarfBuzz] harfbuzz-ng: Branch 'master'

Harshula harshula at gmail.com
Thu Sep 6 11:47:25 PDT 2012


On Wed, 2012-07-25 at 16:21 -0700, Behdad Esfahbod wrote:
> src/hb-old.cc                |   51 +++++++++++++++++++++++++++++++++----------
>  src/hb-old/harfbuzz-shaper.h |    1 
>  src/hb-uniscribe.cc          |    5 ++--
>  3 files changed, 44 insertions(+), 13 deletions(-)
> 
> New commits:
> commit 91e721ea8693205f4f738bca97a5055ee75cf463
> Author: Behdad Esfahbod <behdad at behdad.org>
> Date:   Wed Jul 25 19:20:34 2012 -0400
> 
>     [hb-old] Fix clusters
>     
>     Unlike its "documentation", hb-old's log_clusters are, well, indeed
>     logical, not visual.  Fixup.  Adapted / copied from hb-uniscribe.

<snip>

>    HB_ShaperItem item = {0};
>  
>    ALLOCATE_ARRAY (const HB_UChar16, item.string, chars_len);
> +  ALLOCATE_ARRAY (unsigned short, item.log_clusters, chars_len + 2);

Why is the length "chars_len + 2"?

Exactly what should be the correct length is not clear from:
------------------------------------------------------------
struct HB_ShaperItem_ {
...
246     hb_uint32 num_glyphs;                   /* input: capacity of
output arrays <glyphs>, <attributes>, <advances>, <offsets>, and
<log_clusters>; */
247                                             /* output: required
capacity (may be larger than actual capacity) */
...
249     HB_Glyph *glyphs;                       /* output: <num_glyphs>
indicesof shaped glyphs */
250     HB_GlyphAttributes *attributes;         /* output: <num_glyphs>
glyph attributes */
251     HB_Fixed *advances;                     /* output: <num_glyphs>
advances */
252     HB_FixedPoint *offsets;                 /* output: <num_glyphs>
offsets */
253     unsigned short *log_clusters;           /* output: for each
output glyph, the index in the input of the start of its logical cluster
*/
254     /* XXX the discription for log_clusters is wrong.  It maps each
input position to output glyph position! */
255 
...
};
------------------------------------------------------------
=> hb_uint32 num_glyphs; /* input: capacity of output arrays <glyphs>,
<attributes>, <advances>, <offsets>, and <log_clusters>; */

=> "XXX the discription for log_clusters is wrong.  It maps each input
position to output glyph position!"

But looking at src/hb-old/harfbuzz-indic.cpp:
------------------------------------------------------------
1198 static bool indic_shape_syllable(HB_Bool openType, HB_ShaperItem
*item, bool invalid)
...
1208     int len = (int)item->item.length;
...
1211     if ((int)item->num_glyphs < len+4) {
1212         item->num_glyphs = len+4;
1213         return false;
1214     }
...
1554         HB_STACKARRAY(unsigned short, clusters, len);
...
1643         item->log_clusters = clusters;
...
1678             while (i < item->num_glyphs) {
1679                 if (form(reordered[otl_glyphs[i].cluster]) ==
Control) {
1680                     ++i;
1681                     if (i >= item->num_glyphs)
1682                         break;
1683                 }
1684                 item->glyphs[j] = item->glyphs[i];
1685                 item->attributes[j] = item->attributes[i];
1686                 item->offsets[j] = item->offsets[i];
1687                 item->advances[j] = item->advances[i];
1688                 ++i;
1689                 ++j;
1690             }
------------------------------------------------------------
=> item's log_clusters array has a length of item.item.length
=> item's glyphs, attributes, offsets, advances arrays have a length of
item.num_glyphs.

and looking at src/hb-old.cc:
------------------------------------------------------------
_hb_old_shape (hb_shape_plan_t    *shape_plan,
...
  item.stringLength = chars_len;
...
  item.item.length = item.stringLength;
------------------------------------------------------------
=> item.item.length is chars_len.

So the "chars_len + 2" probably should just be "chars_len" in:
------------------------------------------------------------
272 _hb_old_shape (hb_shape_plan_t    *shape_plan,
...
316   ALLOCATE_ARRAY (unsigned short, item.log_clusters, chars_len + 2);
------------------------------------------------------------

cya,
#




More information about the HarfBuzz mailing list