[HarfBuzz] Problems with TTB Japanese

Simon Cozens simon at simon-cozens.org
Thu Jun 11 20:55:27 PDT 2015


On 12/06/2015 09:17, Behdad Esfahbod wrote:
> This happens because HarfBuzz thinks your font instance is set for horizontal
> typesetting.  That is, this returns offsets that work with a font that has
> origin at baseline-left.  What you expect instead can be achieved by
> configuring the font to use a top-center origin.
> 
> What font funcs are you using?

This may be the problem. I'm using hb_ft_font_create, getting the glyph
information and positions. I use x_offset and y_offset from
hb_buffer_get_glyph_positions to alter the cursor position. (because
otherwise Arabic doesn't work),  and then use a function like this to
get the metrics to put the glyph in a (TeX-like) box:

(Following code mostly stolen from XeTeX, with the TTB special case
added yesterday after talking to the rubber duck.)

void calculate_extents(box* b, hb_glyph_info_t glyph_info,
hb_glyph_position_t glyph_pos, FT_Face ft_face, double point_size,
hb_direction_t direction) {
  FT_Error error = FT_Load_Glyph(ft_face, glyph_info.codepoint,
FT_LOAD_NO_SCALE);
  if (error) return;
  FT_Glyph glyph;
  error = FT_Get_Glyph(ft_face->glyph, &glyph);
  if (error) return;
  FT_BBox ft_bbox;
  FT_Glyph_Get_CBox(glyph, FT_GLYPH_BBOX_UNSCALED, &ft_bbox);
  FT_Fixed advance;
  FT_Get_Advance(ft_face, glyph_info.codepoint, FT_LOAD_NO_SCALE, &advance);
  const FT_Glyph_Metrics *ftmetrics = &ft_face->glyph->metrics;
  b->width = advance * point_size / ft_face->units_per_EM;
  if (direction == HB_DIRECTION_TTB) {
    FT_Get_Advance(ft_face, glyph_info.codepoint, FT_LOAD_NO_SCALE |
FT_LOAD_VERTICAL_LAYOUT, &advance);
    b->height = advance * point_size / ft_face->units_per_EM;
    b->depth = 0;
  } else {
    b->height = ft_bbox.yMax * point_size / ft_face->units_per_EM;
    b->depth = -ft_bbox.yMin * point_size / ft_face->units_per_EM;
  }
  FT_Done_Glyph(glyph);
}


I don't see a way to tell hb-ft that the font is going to be used with
vertical baselines.

S


More information about the HarfBuzz mailing list