[graphite] Simplify direction handling

pull/4131/head
Behdad Esfahbod 2 years ago
parent ec3270c7bb
commit b130b2b331
  1. 23
      src/hb-graphite2.cc

@ -248,19 +248,19 @@ _hb_graphite2_shape (hb_shape_plan_t *shape_plan HB_UNUSED,
gr_fref_set_feature_value (fref, features[i].value, feats);
}
hb_direction_t target_direction = buffer->props.direction;
hb_direction_t direction = buffer->props.direction;
hb_direction_t horiz_dir = hb_script_get_horizontal_direction (buffer->props.script);
/* TODO vertical:
* The only BTT vertical script is Ogham, but it's not clear to me whether OpenType
* Ogham fonts are supposed to be implemented BTT or not. Need to research that
* first. */
if ((HB_DIRECTION_IS_HORIZONTAL (target_direction) &&
target_direction != horiz_dir && horiz_dir != HB_DIRECTION_INVALID) ||
(HB_DIRECTION_IS_VERTICAL (target_direction) &&
target_direction != HB_DIRECTION_TTB))
if ((HB_DIRECTION_IS_HORIZONTAL (direction) &&
direction != horiz_dir && horiz_dir != HB_DIRECTION_INVALID) ||
(HB_DIRECTION_IS_VERTICAL (direction) &&
direction != HB_DIRECTION_TTB))
{
hb_buffer_reverse_clusters (buffer);
buffer->props.direction = HB_DIRECTION_REVERSE (buffer->props.direction);
direction = HB_DIRECTION_REVERSE (direction);
}
gr_segment *seg = nullptr;
@ -280,7 +280,7 @@ _hb_graphite2_shape (hb_shape_plan_t *shape_plan HB_UNUSED,
HB_TAG_NONE, // https://github.com/harfbuzz/harfbuzz/issues/3439#issuecomment-1442650148
feats,
gr_utf32, chars, buffer->len,
2 | (hb_buffer_get_direction (buffer) == HB_DIRECTION_RTL ? 1 : 0));
2 | (direction == HB_DIRECTION_RTL ? 1 : 0));
if (unlikely (!seg)) {
if (feats) gr_featureval_destroy (feats);
@ -332,7 +332,7 @@ _hb_graphite2_shape (hb_shape_plan_t *shape_plan HB_UNUSED,
float yscale = (float) font->y_scale / upem;
yscale *= yscale / xscale;
unsigned int curradv = 0;
if (HB_DIRECTION_IS_BACKWARD(buffer->props.direction))
if (HB_DIRECTION_IS_BACKWARD (direction))
{
curradv = gr_slot_origin_X(gr_seg_first_slot(seg)) * xscale;
clusters[0].advance = gr_seg_advance_X(seg) * xscale - curradv;
@ -361,7 +361,7 @@ _hb_graphite2_shape (hb_shape_plan_t *shape_plan HB_UNUSED,
c->num_chars = before - c->base_char;
c->base_glyph = ic;
c->num_glyphs = 0;
if (HB_DIRECTION_IS_BACKWARD(buffer->props.direction))
if (HB_DIRECTION_IS_BACKWARD (direction))
{
c->advance = curradv - gr_slot_origin_X(is) * xscale;
curradv -= c->advance;
@ -380,7 +380,7 @@ _hb_graphite2_shape (hb_shape_plan_t *shape_plan HB_UNUSED,
clusters[ci].num_chars = after + 1 - clusters[ci].base_char;
}
if (HB_DIRECTION_IS_BACKWARD(buffer->props.direction))
if (HB_DIRECTION_IS_BACKWARD (direction))
clusters[ci].advance += curradv;
else
clusters[ci].advance += gr_seg_advance_X(seg) * xscale - curradv;
@ -402,7 +402,7 @@ _hb_graphite2_shape (hb_shape_plan_t *shape_plan HB_UNUSED,
unsigned int currclus = UINT_MAX;
const hb_glyph_info_t *info = buffer->info;
hb_glyph_position_t *pPos = hb_buffer_get_glyph_positions (buffer, nullptr);
if (!HB_DIRECTION_IS_BACKWARD(buffer->props.direction))
if (!HB_DIRECTION_IS_BACKWARD (direction))
{
curradvx = 0;
for (is = gr_seg_first_slot (seg); is; pPos++, ++info, is = gr_slot_next_in_segment (is))
@ -446,7 +446,6 @@ _hb_graphite2_shape (hb_shape_plan_t *shape_plan HB_UNUSED,
buffer->clear_glyph_flags ();
buffer->unsafe_to_break ();
buffer->props.direction = target_direction;
return true;
}

Loading…
Cancel
Save