[graphite] Simplify direction handling

This commit is contained in:
Behdad Esfahbod 2023-02-24 13:34:16 -07:00
parent ec3270c7bb
commit b130b2b331
1 changed files with 11 additions and 12 deletions

View File

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