diff options
Diffstat (limited to 'src/3rdparty/harfbuzz-ng/src/hb-ot-shape.cc')
-rw-r--r-- | src/3rdparty/harfbuzz-ng/src/hb-ot-shape.cc | 196 |
1 files changed, 107 insertions, 89 deletions
diff --git a/src/3rdparty/harfbuzz-ng/src/hb-ot-shape.cc b/src/3rdparty/harfbuzz-ng/src/hb-ot-shape.cc index 40332d69f1..ddd6662e84 100644 --- a/src/3rdparty/harfbuzz-ng/src/hb-ot-shape.cc +++ b/src/3rdparty/harfbuzz-ng/src/hb-ot-shape.cc @@ -69,6 +69,9 @@ hb_ot_shape_collect_features (hb_ot_shape_planner_t *planner, { hb_ot_map_builder_t *map = &planner->map; + map->add_global_bool_feature (HB_TAG('r','v','r','n')); + map->add_gsub_pause (NULL); + switch (props->direction) { case HB_DIRECTION_LTR: map->add_global_bool_feature (HB_TAG ('l','t','r','a')); @@ -145,7 +148,7 @@ _hb_ot_shaper_face_data_destroy (hb_ot_shaper_face_data_t *data) struct hb_ot_shaper_font_data_t {}; hb_ot_shaper_font_data_t * -_hb_ot_shaper_font_data_create (hb_font_t *font) +_hb_ot_shaper_font_data_create (hb_font_t *font HB_UNUSED) { return (hb_ot_shaper_font_data_t *) HB_SHAPER_DATA_SUCCEEDED; } @@ -163,7 +166,9 @@ _hb_ot_shaper_font_data_destroy (hb_ot_shaper_font_data_t *data) hb_ot_shaper_shape_plan_data_t * _hb_ot_shaper_shape_plan_data_create (hb_shape_plan_t *shape_plan, const hb_feature_t *user_features, - unsigned int num_user_features) + unsigned int num_user_features, + const int *coords, + unsigned int num_coords) { hb_ot_shape_plan_t *plan = (hb_ot_shape_plan_t *) calloc (1, sizeof (hb_ot_shape_plan_t)); if (unlikely (!plan)) @@ -173,9 +178,10 @@ _hb_ot_shaper_shape_plan_data_create (hb_shape_plan_t *shape_plan, planner.shaper = hb_ot_shape_complex_categorize (&planner); - hb_ot_shape_collect_features (&planner, &shape_plan->props, user_features, num_user_features); + hb_ot_shape_collect_features (&planner, &shape_plan->props, + user_features, num_user_features); - planner.compile (*plan); + planner.compile (*plan, coords, num_coords); if (plan->shaper->data_create) { plan->data = plan->shaper->data_create (plan); @@ -212,6 +218,8 @@ struct hb_ot_shape_context_t unsigned int num_user_features; /* Transient stuff */ + bool fallback_positioning; + bool fallback_glyph_classes; hb_direction_t target_direction; }; @@ -228,7 +236,7 @@ hb_set_unicode_props (hb_buffer_t *buffer) unsigned int count = buffer->len; hb_glyph_info_t *info = buffer->info; for (unsigned int i = 0; i < count; i++) - _hb_glyph_info_set_unicode_props (&info[i], buffer->unicode); + _hb_glyph_info_set_unicode_props (&info[i], buffer); } static void @@ -245,7 +253,7 @@ hb_insert_dotted_circle (hb_buffer_t *buffer, hb_font_t *font) hb_glyph_info_t dottedcircle = {0}; dottedcircle.codepoint = 0x25CCu; - _hb_glyph_info_set_unicode_props (&dottedcircle, buffer->unicode); + _hb_glyph_info_set_unicode_props (&dottedcircle, buffer); buffer->clear_output (); @@ -254,7 +262,7 @@ hb_insert_dotted_circle (hb_buffer_t *buffer, hb_font_t *font) info.cluster = buffer->cur().cluster; info.mask = buffer->cur().mask; buffer->output_info (info); - while (buffer->idx < buffer->len) + while (buffer->idx < buffer->len && !buffer->in_error) buffer->next_glyph (); buffer->swap_buffers (); @@ -263,16 +271,18 @@ hb_insert_dotted_circle (hb_buffer_t *buffer, hb_font_t *font) static void hb_form_clusters (hb_buffer_t *buffer) { - if (buffer->cluster_level != HB_BUFFER_CLUSTER_LEVEL_MONOTONE_GRAPHEMES) + if (!(buffer->scratch_flags & HB_BUFFER_SCRATCH_FLAG_HAS_NON_ASCII) || + buffer->cluster_level != HB_BUFFER_CLUSTER_LEVEL_MONOTONE_GRAPHEMES) return; - /* Loop duplicated in hb_ensure_native_direction(). */ + /* Loop duplicated in hb_ensure_native_direction(), and in _hb-coretext.cc */ unsigned int base = 0; unsigned int count = buffer->len; hb_glyph_info_t *info = buffer->info; for (unsigned int i = 1; i < count; i++) { - if (likely (!HB_UNICODE_GENERAL_CATEGORY_IS_MARK (_hb_glyph_info_get_general_category (&info[i])))) + if (likely (!HB_UNICODE_GENERAL_CATEGORY_IS_MARK (_hb_glyph_info_get_general_category (&info[i])) && + !_hb_glyph_info_is_joiner (&info[i]))) { buffer->merge_clusters (base, i); base = i; @@ -346,7 +356,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; @@ -416,7 +427,8 @@ hb_ot_zero_width_default_ignorables (hb_ot_shape_context_t *c) { hb_buffer_t *buffer = c->buffer; - if (buffer->flags & HB_BUFFER_FLAG_PRESERVE_DEFAULT_IGNORABLES) + if (!(buffer->scratch_flags & HB_BUFFER_SCRATCH_FLAG_HAS_DEFAULT_IGNORABLES) || + (buffer->flags & HB_BUFFER_FLAG_PRESERVE_DEFAULT_IGNORABLES)) return; unsigned int count = buffer->len; @@ -433,7 +445,8 @@ hb_ot_hide_default_ignorables (hb_ot_shape_context_t *c) { hb_buffer_t *buffer = c->buffer; - if (buffer->flags & HB_BUFFER_FLAG_PRESERVE_DEFAULT_IGNORABLES) + if (!(buffer->scratch_flags & HB_BUFFER_SCRATCH_FLAG_HAS_DEFAULT_IGNORABLES) || + (buffer->flags & HB_BUFFER_FLAG_PRESERVE_DEFAULT_IGNORABLES)) return; unsigned int count = buffer->len; @@ -451,7 +464,7 @@ hb_ot_hide_default_ignorables (hb_ot_shape_context_t *c) return; hb_codepoint_t space; - if (c->font->get_glyph (' ', 0, &space)) + if (c->font->get_nominal_glyph (' ', &space)) { /* Replace default-ignorables with a zero-advance space glyph. */ for (/*continue*/; i < count; i++) @@ -525,7 +538,7 @@ hb_synthesize_glyph_classes (hb_ot_shape_context_t *c) hb_glyph_info_t *info = c->buffer->info; for (unsigned int i = 0; i < count; i++) { - hb_ot_layout_glyph_class_mask_t klass; + hb_ot_layout_glyph_props_flags_t klass; /* Never mark default-ignorables as marks. * They won't get in the way of lookups anyway, @@ -549,9 +562,6 @@ hb_ot_substitute_default (hb_ot_shape_context_t *c) { hb_buffer_t *buffer = c->buffer; - if (c->plan->shaper->preprocess_text) - c->plan->shaper->preprocess_text (c->plan, buffer, c->font); - hb_ot_shape_initialize_masks (c); hb_ot_mirror_chars (c); @@ -563,7 +573,7 @@ hb_ot_substitute_default (hb_ot_shape_context_t *c) hb_ot_shape_setup_masks (c); /* This is unfortunate to go here, but necessary... */ - if (!hb_ot_layout_has_positioning (c->face)) + if (c->fallback_positioning) _hb_ot_shape_fallback_position_recategorize_marks (c->plan, c->font, buffer); hb_ot_map_glyphs_fast (buffer); @@ -576,7 +586,6 @@ hb_ot_substitute_complex (hb_ot_shape_context_t *c) { hb_buffer_t *buffer = c->buffer; - _hb_buffer_allocate_gsubgpos_vars (buffer); hb_ot_layout_substitute_start (c->font, buffer); if (!hb_ot_layout_has_glyph_classes (c->face)) @@ -584,8 +593,6 @@ hb_ot_substitute_complex (hb_ot_shape_context_t *c) c->plan->substitute (c->font, buffer); - hb_ot_layout_substitute_finish (c->font, buffer); - return; } @@ -593,6 +600,9 @@ static inline void hb_ot_substitute (hb_ot_shape_context_t *c) { hb_ot_substitute_default (c); + + _hb_buffer_allocate_gsubgpos_vars (c->buffer); + hb_ot_substitute_complex (c); } @@ -613,20 +623,6 @@ zero_mark_width (hb_glyph_position_t *pos) } static inline void -zero_mark_widths_by_unicode (hb_buffer_t *buffer, bool adjust_offsets) -{ - unsigned int count = buffer->len; - hb_glyph_info_t *info = buffer->info; - for (unsigned int i = 0; i < count; i++) - if (_hb_glyph_info_get_general_category (&info[i]) == HB_UNICODE_GENERAL_CATEGORY_NON_SPACING_MARK) - { - if (adjust_offsets) - adjust_mark_offsets (&buffer->pos[i]); - zero_mark_width (&buffer->pos[i]); - } -} - -static inline void zero_mark_widths_by_gdef (hb_buffer_t *buffer, bool adjust_offsets) { unsigned int count = buffer->len; @@ -647,26 +643,39 @@ 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); + /* The nil glyph_h_origin() func returns 0, so no need to apply it. */ + if (c->font->has_glyph_h_origin_func ()) + 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); } + 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); } -static inline bool +static inline void hb_ot_position_complex (hb_ot_shape_context_t *c) { - bool ret = false; + hb_ot_layout_position_start (c->font, c->buffer); + unsigned int count = c->buffer->len; - bool has_positioning = hb_ot_layout_has_positioning (c->face); + /* If the font has no GPOS, AND, no fallback positioning will * happen, AND, direction is forward, then when zeroing mark * widths, we shift the mark with it, such that the mark @@ -676,8 +685,9 @@ hb_ot_position_complex (hb_ot_shape_context_t *c) * If fallback positinoing happens or GPOS is present, we don't * care. */ - bool adjust_offsets_when_zeroing = !(has_positioning || c->plan->shaper->fallback_position || - HB_DIRECTION_IS_BACKWARD (c->buffer->props.direction)); + bool adjust_offsets_when_zeroing = c->fallback_positioning && + !c->plan->shaper->fallback_position && + HB_DIRECTION_IS_FORWARD (c->buffer->props.direction); switch (c->plan->shaper->zero_width_marks) { @@ -685,79 +695,65 @@ hb_ot_position_complex (hb_ot_shape_context_t *c) zero_mark_widths_by_gdef (c->buffer, adjust_offsets_when_zeroing); break; - /* Not currently used for any shaper: - case HB_OT_SHAPE_ZERO_WIDTH_MARKS_BY_UNICODE_EARLY: - zero_mark_widths_by_unicode (c->buffer, adjust_offsets_when_zeroing); - break; - */ - default: case HB_OT_SHAPE_ZERO_WIDTH_MARKS_NONE: - case HB_OT_SHAPE_ZERO_WIDTH_MARKS_BY_UNICODE_LATE: case HB_OT_SHAPE_ZERO_WIDTH_MARKS_BY_GDEF_LATE: break; } - if (has_positioning) + if (likely (!c->fallback_positioning)) { 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); - } + /* The nil glyph_h_origin() func returns 0, so no need to apply it. */ + if (c->font->has_glyph_h_origin_func ()) + 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); - } + /* The nil glyph_h_origin() func returns 0, so no need to apply it. */ + if (c->font->has_glyph_h_origin_func ()) + 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; } switch (c->plan->shaper->zero_width_marks) { - case HB_OT_SHAPE_ZERO_WIDTH_MARKS_BY_UNICODE_LATE: - zero_mark_widths_by_unicode (c->buffer, adjust_offsets_when_zeroing); - break; - case HB_OT_SHAPE_ZERO_WIDTH_MARKS_BY_GDEF_LATE: zero_mark_widths_by_gdef (c->buffer, adjust_offsets_when_zeroing); break; default: case HB_OT_SHAPE_ZERO_WIDTH_MARKS_NONE: - //case HB_OT_SHAPE_ZERO_WIDTH_MARKS_BY_UNICODE_EARLY: case HB_OT_SHAPE_ZERO_WIDTH_MARKS_BY_GDEF_EARLY: break; } - return ret; + /* Finishing off GPOS has to follow a certain order. */ + hb_ot_layout_position_finish_advances (c->font, c->buffer); + hb_ot_zero_width_default_ignorables (c); + hb_ot_layout_position_finish_offsets (c->font, c->buffer); } static inline void hb_ot_position (hb_ot_shape_context_t *c) { - hb_ot_layout_position_start (c->font, c->buffer); + c->buffer->clear_positions (); hb_ot_position_default (c); - hb_bool_t fallback = !hb_ot_position_complex (c); - - hb_ot_zero_width_default_ignorables (c); - - hb_ot_layout_position_finish (c->font, c->buffer); + hb_ot_position_complex (c); - if (fallback && c->plan->shaper->fallback_position) + if (c->fallback_positioning && c->plan->shaper->fallback_position) _hb_ot_shape_fallback_position (c->plan, c->font, c->buffer); if (HB_DIRECTION_IS_BACKWARD (c->buffer->props.direction)) @@ -765,7 +761,7 @@ hb_ot_position (hb_ot_shape_context_t *c) /* Visual fallback goes here. */ - if (fallback) + if (c->fallback_positioning) _hb_ot_shape_fallback_kern (c->plan, c->font, c->buffer); _hb_buffer_deallocate_gsubgpos_vars (c->buffer); @@ -778,6 +774,17 @@ static void hb_ot_shape_internal (hb_ot_shape_context_t *c) { c->buffer->deallocate_var_all (); + c->buffer->scratch_flags = HB_BUFFER_SCRATCH_FLAG_DEFAULT; + if (likely (!_hb_unsigned_int_mul_overflows (c->buffer->len, HB_BUFFER_MAX_EXPANSION_FACTOR))) + { + c->buffer->max_len = MAX (c->buffer->len * HB_BUFFER_MAX_EXPANSION_FACTOR, + (unsigned) HB_BUFFER_MAX_LEN_MIN); + } + + bool disable_otl = c->plan->shaper->disable_otl && c->plan->shaper->disable_otl (c->plan); + //c->fallback_substitute = disable_otl || !hb_ot_layout_has_substitution (c->face); + c->fallback_positioning = disable_otl || !hb_ot_layout_has_positioning (c->face); + c->fallback_glyph_classes = disable_otl || !hb_ot_layout_has_glyph_classes (c->face); /* Save the original direction, we use it later. */ c->target_direction = c->buffer->props.direction; @@ -792,15 +799,22 @@ hb_ot_shape_internal (hb_ot_shape_context_t *c) hb_ensure_native_direction (c->buffer); + if (c->plan->shaper->preprocess_text) + c->plan->shaper->preprocess_text (c->plan, c->buffer, c->font); + hb_ot_substitute (c); hb_ot_position (c); hb_ot_hide_default_ignorables (c); + if (c->plan->shaper->postprocess_glyphs) + c->plan->shaper->postprocess_glyphs (c->plan, c->buffer, c->font); + _hb_buffer_deallocate_unicode_vars (c->buffer); c->buffer->props.direction = c->target_direction; + c->buffer->max_len = HB_BUFFER_MAX_LEN_DEFAULT; c->buffer->deallocate_var_all (); } @@ -820,6 +834,8 @@ _hb_ot_shape (hb_shape_plan_t *shape_plan, /** + * hb_ot_shape_plan_collect_lookups: + * * Since: 0.9.7 **/ void @@ -841,18 +857,20 @@ add_char (hb_font_t *font, hb_set_t *glyphs) { hb_codepoint_t glyph; - if (font->get_glyph (u, 0, &glyph)) + if (font->get_nominal_glyph (u, &glyph)) glyphs->add (glyph); if (mirror) { hb_codepoint_t m = unicode->mirroring (u); - if (m != u && font->get_glyph (m, 0, &glyph)) + if (m != u && font->get_nominal_glyph (m, &glyph)) glyphs->add (glyph); } } /** + * hb_ot_shape_glyphs_closure: + * * Since: 0.9.2 **/ void |