src/hb-buffer-private.hh | 5 ++-- src/hb-font-private.hh | 40 ++++++++++++++++++++++++++++++++ src/hb-ot-layout-private.hh | 1 src/hb-ot-shape.cc | 54 ++++++++++++++++++++++++-------------------- 4 files changed, 74 insertions(+), 26 deletions(-)
New commits: commit bee901b38ef3c26a04f69c299c8d5e028a0090e9 Author: Behdad Esfahbod <[email protected]> Date: Wed Nov 4 19:28:17 2015 -0800 Optimize positioning direction calculations It makes the binary smaller AND faster. Yumm! diff --git a/src/hb-font-private.hh b/src/hb-font-private.hh index c05499d..952682d 100644 --- a/src/hb-font-private.hh +++ b/src/hb-font-private.hh @@ -298,6 +298,26 @@ struct hb_font_t { } } + inline void add_glyph_h_origin (hb_codepoint_t glyph, + hb_position_t *x, hb_position_t *y) + { + hb_position_t origin_x, origin_y; + + get_glyph_h_origin (glyph, &origin_x, &origin_y); + + *x += origin_x; + *y += origin_y; + } + inline void add_glyph_v_origin (hb_codepoint_t glyph, + hb_position_t *x, hb_position_t *y) + { + hb_position_t origin_x, origin_y; + + get_glyph_v_origin (glyph, &origin_x, &origin_y); + + *x += origin_x; + *y += origin_y; + } inline void add_glyph_origin_for_direction (hb_codepoint_t glyph, hb_direction_t direction, hb_position_t *x, hb_position_t *y) @@ -310,6 +330,26 @@ struct hb_font_t { *y += origin_y; } + inline void subtract_glyph_h_origin (hb_codepoint_t glyph, + hb_position_t *x, hb_position_t *y) + { + hb_position_t origin_x, origin_y; + + get_glyph_h_origin (glyph, &origin_x, &origin_y); + + *x -= origin_x; + *y -= origin_y; + } + inline void subtract_glyph_v_origin (hb_codepoint_t glyph, + hb_position_t *x, hb_position_t *y) + { + hb_position_t origin_x, origin_y; + + get_glyph_v_origin (glyph, &origin_x, &origin_y); + + *x -= origin_x; + *y -= origin_y; + } inline void subtract_glyph_origin_for_direction (hb_codepoint_t glyph, hb_direction_t direction, hb_position_t *x, hb_position_t *y) diff --git a/src/hb-ot-shape.cc b/src/hb-ot-shape.cc index be9c438..455ebab 100644 --- a/src/hb-ot-shape.cc +++ b/src/hb-ot-shape.cc @@ -650,17 +650,26 @@ hb_ot_position_default (hb_ot_shape_context_t *c) unsigned int count = c->buffer->len; hb_glyph_info_t *info = c->buffer->info; hb_glyph_position_t *pos = c->buffer->pos; - for (unsigned int i = 0; i < count; i++) - { - c->font->get_glyph_advance_for_direction (info[i].codepoint, - direction, - &pos[i].x_advance, - &pos[i].y_advance); - c->font->subtract_glyph_origin_for_direction (info[i].codepoint, - direction, - &pos[i].x_offset, - &pos[i].y_offset); + if (HB_DIRECTION_IS_HORIZONTAL (direction)) + { + for (unsigned int i = 0; i < count; i++) + { + pos[i].x_advance = c->font->get_glyph_h_advance (info[i].codepoint); + c->font->subtract_glyph_h_origin (info[i].codepoint, + &pos[i].x_offset, + &pos[i].y_offset); + } + } + else + { + for (unsigned int i = 0; i < count; i++) + { + pos[i].y_advance = c->font->get_glyph_v_advance (info[i].codepoint); + c->font->subtract_glyph_v_origin (info[i].codepoint, + &pos[i].x_offset, + &pos[i].y_offset); + } } if (c->buffer->scratch_flags & HB_BUFFER_SCRATCH_FLAG_HAS_SPACE_FALLBACK) _hb_ot_shape_fallback_spaces (c->plan, c->font, c->buffer); @@ -708,23 +717,19 @@ hb_ot_position_complex (hb_ot_shape_context_t *c) hb_glyph_info_t *info = c->buffer->info; hb_glyph_position_t *pos = c->buffer->pos; - /* Change glyph origin to what GPOS expects, apply GPOS, change it back. */ + /* Change glyph origin to what GPOS expects (horizontal), apply GPOS, change it back. */ - for (unsigned int i = 0; i < count; i++) { - c->font->add_glyph_origin_for_direction (info[i].codepoint, - HB_DIRECTION_LTR, - &pos[i].x_offset, - &pos[i].y_offset); - } + for (unsigned int i = 0; i < count; i++) + c->font->add_glyph_h_origin (info[i].codepoint, + &pos[i].x_offset, + &pos[i].y_offset); c->plan->position (c->font, c->buffer); - for (unsigned int i = 0; i < count; i++) { - c->font->subtract_glyph_origin_for_direction (info[i].codepoint, - HB_DIRECTION_LTR, - &pos[i].x_offset, - &pos[i].y_offset); - } + for (unsigned int i = 0; i < count; i++) + c->font->subtract_glyph_h_origin (info[i].codepoint, + &pos[i].x_offset, + &pos[i].y_offset); ret = true; } commit e3e4bb011ae1a2f1ba05e7ea450595b185304bec Author: Behdad Esfahbod <[email protected]> Date: Wed Nov 4 18:58:02 2015 -0800 Don't do fractions if buffer is ASCII-only diff --git a/src/hb-buffer-private.hh b/src/hb-buffer-private.hh index 574fb36..8550517 100644 --- a/src/hb-buffer-private.hh +++ b/src/hb-buffer-private.hh @@ -43,8 +43,9 @@ template <> class hb_mark_as_flags_t<hb_buffer_serialize_flags_t> {}; enum hb_buffer_scratch_flags_t { HB_BUFFER_SCRATCH_FLAG_DEFAULT = 0x00000000u, - HB_BUFFER_SCRATCH_FLAG_HAS_DEFAULT_IGNORABLES = 0x00000001u, - HB_BUFFER_SCRATCH_FLAG_HAS_SPACE_FALLBACK = 0x00000002u, + HB_BUFFER_SCRATCH_FLAG_HAS_NON_ASCII = 0x00000001u, + HB_BUFFER_SCRATCH_FLAG_HAS_DEFAULT_IGNORABLES = 0x00000002u, + HB_BUFFER_SCRATCH_FLAG_HAS_SPACE_FALLBACK = 0x00000004u, }; template <> class hb_mark_as_flags_t<hb_buffer_scratch_flags_t> {}; diff --git a/src/hb-ot-layout-private.hh b/src/hb-ot-layout-private.hh index 60fca26..049b232 100644 --- a/src/hb-ot-layout-private.hh +++ b/src/hb-ot-layout-private.hh @@ -249,6 +249,7 @@ _hb_glyph_info_set_unicode_props (hb_glyph_info_t *info, hb_buffer_t *buffer) if (u >= 0x80) { + buffer->scratch_flags |= HB_BUFFER_SCRATCH_FLAG_HAS_NON_ASCII; if (unlikely (unicode->is_default_ignorable (u))) { buffer->scratch_flags |= HB_BUFFER_SCRATCH_FLAG_HAS_DEFAULT_IGNORABLES; diff --git a/src/hb-ot-shape.cc b/src/hb-ot-shape.cc index 30563d0..be9c438 100644 --- a/src/hb-ot-shape.cc +++ b/src/hb-ot-shape.cc @@ -346,7 +346,8 @@ hb_ot_mirror_chars (hb_ot_shape_context_t *c) static inline void hb_ot_shape_setup_masks_fraction (hb_ot_shape_context_t *c) { - if (!c->plan->has_frac) + if (!(c->buffer->scratch_flags & HB_BUFFER_SCRATCH_FLAG_HAS_NON_ASCII) || + !c->plan->has_frac) return; hb_buffer_t *buffer = c->buffer; _______________________________________________ HarfBuzz mailing list [email protected] http://lists.freedesktop.org/mailman/listinfo/harfbuzz
