[HarfBuzz] Zero-width joiner has width

Simon Cozens simon at simon-cozens.org
Sun Aug 9 01:15:25 PDT 2015


On 08/08/2015 16:31, Behdad Esfahbod wrote:
> The 'm' has advance of 1645 units in a 2048-unit font.  At 10pt, that means:
>>>> 1645 / 2048. * 10
> 8.0322265625
> 
> So we're losing something on the way.  How do you setup the font scale?  Show
> me the code.
> In general, for something like Sile, you probably want to shape text at the
> upem size to have on precision loss whatsoever.

OK, I'm now trying to set the scaling to the font upem, but I'm not
getting that working either. Assuming an incoming FT_Face face:

    hb_ft_font = hb_ft_font_create(face, NULL);
    hb_face_t* hbFace = hb_font_get_face(hb_ft_font);

    /* Attempt to set upem scale */
    unsigned int upem = hb_face_get_upem(hbFace);
    hb_font_set_scale(hb_ft_font, upem, upem);
    printf("upem = %i\n", upem);

This prints "upem = 2048"; so far so good. Now after shaping:

...
    shape_plan = hb_shape_plan_create_cached(hbFace, &segment_props,
features, nFeatures, NULL);
    int res = hb_shape_plan_execute(shape_plan, hb_ft_font, buf,
features, nFeatures);

    glyph_info   = hb_buffer_get_glyph_infos(buf, &glyph_count);
    glyph_pos    = hb_buffer_get_glyph_positions(buf, &glyph_count);
...
    lua_pushstring(L, "x_advance");
    lua_pushnumber(L, glyph_pos[j].x_advance);
    lua_settable(L, -3);
...

{
  {
    codepoint = 77,
    depth = 0,
    height = 4.6875,
    name = "m",
    x_advance = 514,
  },
}

Should be 1645, right? I am not sure where 514 is coming from.

The full shaper code is at
https://github.com/simoncozens/sile/blob/master/src/justenoughharfbuzz.c#L292



More information about the HarfBuzz mailing list