From 8bb5deba9630d35878eb6edb4643ecfabf99f15f Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Thu, 2 Aug 2012 10:07:58 -0400 Subject: [PATCH] [OT] Pipe shape_plan down to pause_callbacks --- src/hb-ot-map-private.hh | 8 ++-- src/hb-ot-map.cc | 11 +++--- src/hb-ot-shape-complex-indic-machine.rl | 4 +- src/hb-ot-shape-complex-indic.cc | 50 ++++++++++++------------ src/hb-ot-shape-private.hh | 6 +++ src/hb-ot-shape.cc | 28 +++++++------ 6 files changed, 57 insertions(+), 50 deletions(-) diff --git a/src/hb-ot-map-private.hh b/src/hb-ot-map-private.hh index 18517c4b..b9c67362 100644 --- a/src/hb-ot-map-private.hh +++ b/src/hb-ot-map-private.hh @@ -62,7 +62,7 @@ struct hb_ot_map_t { return a->index < b->index ? -1 : a->index > b->index ? 1 : 0; } }; - typedef void (*pause_func_t) (const hb_ot_map_t *map, hb_font_t *font, hb_buffer_t *buffer); + typedef void (*pause_func_t) (const struct hb_ot_shape_plan_t *plan, hb_font_t *font, hb_buffer_t *buffer); struct pause_map_t { unsigned int num_lookups; /* Cumulative */ @@ -112,9 +112,9 @@ struct hb_ot_map_t inline hb_tag_t get_chosen_script (unsigned int table_index) const { return chosen_script[table_index]; } - HB_INTERNAL void substitute_closure (hb_face_t *face, hb_set_t *glyphs) const; - HB_INTERNAL void substitute (hb_font_t *font, hb_buffer_t *buffer) const; - HB_INTERNAL void position (hb_font_t *font, hb_buffer_t *buffer) const; + HB_INTERNAL void substitute_closure (const struct hb_ot_shape_plan_t *plan, hb_face_t *face, hb_set_t *glyphs) const; + HB_INTERNAL void substitute (const struct hb_ot_shape_plan_t *plan, hb_font_t *font, hb_buffer_t *buffer) const; + HB_INTERNAL void position (const struct hb_ot_shape_plan_t *plan, hb_font_t *font, hb_buffer_t *buffer) const; inline void finish (void) { features.finish (); diff --git a/src/hb-ot-map.cc b/src/hb-ot-map.cc index 62afdef0..7eed624c 100644 --- a/src/hb-ot-map.cc +++ b/src/hb-ot-map.cc @@ -75,7 +75,7 @@ void hb_ot_map_builder_t::add_feature (hb_tag_t tag, unsigned int value, bool gl /* Keep the next two functions in sync. */ -void hb_ot_map_t::substitute (hb_font_t *font, hb_buffer_t *buffer) const +void hb_ot_map_t::substitute (const hb_ot_shape_plan_t *plan, hb_font_t *font, hb_buffer_t *buffer) const { const unsigned int table_index = 0; unsigned int i = 0; @@ -88,14 +88,14 @@ void hb_ot_map_t::substitute (hb_font_t *font, hb_buffer_t *buffer) const buffer->clear_output (); if (pause->callback) - pause->callback (this, font, buffer); + pause->callback (plan, font, buffer); } for (; i < lookups[table_index].len; i++) hb_ot_layout_substitute_lookup (font, buffer, lookups[table_index][i].index, lookups[table_index][i].mask); } -void hb_ot_map_t::position (hb_font_t *font, hb_buffer_t *buffer) const +void hb_ot_map_t::position (const hb_ot_shape_plan_t *plan, hb_font_t *font, hb_buffer_t *buffer) const { const unsigned int table_index = 1; unsigned int i = 0; @@ -106,15 +106,14 @@ void hb_ot_map_t::position (hb_font_t *font, hb_buffer_t *buffer) const hb_ot_layout_position_lookup (font, buffer, lookups[table_index][i].index, lookups[table_index][i].mask); if (pause->callback) - pause->callback (this, font, buffer); + pause->callback (plan, font, buffer); } for (; i < lookups[table_index].len; i++) hb_ot_layout_position_lookup (font, buffer, lookups[table_index][i].index, lookups[table_index][i].mask); } -void hb_ot_map_t::substitute_closure (hb_face_t *face, - hb_set_t *glyphs) const +void hb_ot_map_t::substitute_closure (const hb_ot_shape_plan_t *plan, hb_face_t *face, hb_set_t *glyphs) const { unsigned int table_index = 0; unsigned int i = 0; diff --git a/src/hb-ot-shape-complex-indic-machine.rl b/src/hb-ot-shape-complex-indic-machine.rl index 25e308d2..25c0e658 100644 --- a/src/hb-ot-shape-complex-indic-machine.rl +++ b/src/hb-ot-shape-complex-indic-machine.rl @@ -92,14 +92,14 @@ main := |* if (0) fprintf (stderr, "syllable %d..%d %s\n", last, p+1, #func); \ for (unsigned int i = last; i < p+1; i++) \ info[i].syllable() = syllable_serial; \ - PASTE (initial_reordering_, func) (map, buffer, mask_array, last, p+1); \ + PASTE (initial_reordering_, func) (plan, buffer, mask_array, last, p+1); \ last = p+1; \ syllable_serial++; \ if (unlikely (!syllable_serial)) syllable_serial++; \ } HB_STMT_END static void -find_syllables (const hb_ot_map_t *map, hb_buffer_t *buffer, hb_mask_t *mask_array) +find_syllables (const hb_ot_shape_plan_t *plan, hb_buffer_t *buffer, hb_mask_t *mask_array) { unsigned int p, pe, eof, ts, te, act; int cs; diff --git a/src/hb-ot-shape-complex-indic.cc b/src/hb-ot-shape-complex-indic.cc index 6b55fb76..be37cddb 100644 --- a/src/hb-ot-shape-complex-indic.cc +++ b/src/hb-ot-shape-complex-indic.cc @@ -108,14 +108,12 @@ struct indic_shape_plan_t unsigned int count; }; - indic_shape_plan_t (const hb_ot_map_t *map_) : - map (map_), - pref (map_, HB_TAG('p','r','e','f')), - blwf (map_, HB_TAG('b','l','w','f')), - pstf (map_, HB_TAG('p','s','t','f')), - is_old_spec (IS_OLD_INDIC_TAG (map->get_chosen_script (0))) {} - - const hb_ot_map_t *map; + indic_shape_plan_t (const hb_ot_shape_plan_t *plan) : + pref (&plan->map, HB_TAG('p','r','e','f')), + blwf (&plan->map, HB_TAG('b','l','w','f')), + pstf (&plan->map, HB_TAG('p','s','t','f')), + is_old_spec (IS_OLD_INDIC_TAG (plan->map.get_chosen_script (0))) {} + would_apply_feature_t pref; would_apply_feature_t blwf; would_apply_feature_t pstf; @@ -192,11 +190,11 @@ indic_other_features[] = static void -initial_reordering (const hb_ot_map_t *map, +initial_reordering (const hb_ot_shape_plan_t *plan, hb_font_t *font, hb_buffer_t *buffer); static void -final_reordering (const hb_ot_map_t *map, +final_reordering (const hb_ot_shape_plan_t *plan, hb_font_t *font, hb_buffer_t *buffer); @@ -260,7 +258,7 @@ compare_indic_order (const hb_glyph_info_t *pa, const hb_glyph_info_t *pb) static void -update_consonant_positions (const hb_ot_map_t *map, +update_consonant_positions (const hb_ot_shape_plan_t *plan, hb_buffer_t *buffer, hb_font_t *font) { @@ -280,7 +278,7 @@ update_consonant_positions (const hb_ot_map_t *map, default: virama = 0; break; } - indic_shape_plan_t indic_plan (map); + indic_shape_plan_t indic_plan (plan); unsigned int consonant_pos = indic_plan.is_old_spec ? 0 : 1; hb_codepoint_t glyphs[2]; @@ -303,7 +301,7 @@ update_consonant_positions (const hb_ot_map_t *map, * https://www.microsoft.com/typography/otfntdev/devanot/shaping.aspx */ static void -initial_reordering_consonant_syllable (const hb_ot_map_t *map, hb_buffer_t *buffer, hb_mask_t *basic_mask_array, +initial_reordering_consonant_syllable (const hb_ot_shape_plan_t *plan, hb_buffer_t *buffer, hb_mask_t *basic_mask_array, unsigned int start, unsigned int end) { hb_glyph_info_t *info = buffer->info; @@ -508,7 +506,7 @@ initial_reordering_consonant_syllable (const hb_ot_map_t *map, hb_buffer_t *buff /* For old-style Indic script tags, move the first post-base Halant after * last consonant. */ - if (IS_OLD_INDIC_TAG (map->get_chosen_script (0))) { + if (IS_OLD_INDIC_TAG (plan->map.get_chosen_script (0))) { for (unsigned int i = base + 1; i < end; i++) if (info[i].indic_category() == OT_H) { unsigned int j; @@ -650,17 +648,17 @@ initial_reordering_consonant_syllable (const hb_ot_map_t *map, hb_buffer_t *buff static void -initial_reordering_vowel_syllable (const hb_ot_map_t *map, +initial_reordering_vowel_syllable (const hb_ot_shape_plan_t *plan, hb_buffer_t *buffer, hb_mask_t *basic_mask_array, unsigned int start, unsigned int end) { /* We made the vowels look like consonants. So let's call the consonant logic! */ - initial_reordering_consonant_syllable (map, buffer, basic_mask_array, start, end); + initial_reordering_consonant_syllable (plan, buffer, basic_mask_array, start, end); } static void -initial_reordering_standalone_cluster (const hb_ot_map_t *map, +initial_reordering_standalone_cluster (const hb_ot_shape_plan_t *plan, hb_buffer_t *buffer, hb_mask_t *basic_mask_array, unsigned int start, unsigned int end) @@ -677,11 +675,11 @@ initial_reordering_standalone_cluster (const hb_ot_map_t *map, return; } - initial_reordering_consonant_syllable (map, buffer, basic_mask_array, start, end); + initial_reordering_consonant_syllable (plan, buffer, basic_mask_array, start, end); } static void -initial_reordering_non_indic (const hb_ot_map_t *map HB_UNUSED, +initial_reordering_non_indic (const hb_ot_shape_plan_t *plan HB_UNUSED, hb_buffer_t *buffer HB_UNUSED, hb_mask_t *basic_mask_array HB_UNUSED, unsigned int start HB_UNUSED, unsigned int end HB_UNUSED) @@ -693,18 +691,18 @@ initial_reordering_non_indic (const hb_ot_map_t *map HB_UNUSED, #include "hb-ot-shape-complex-indic-machine.hh" static void -initial_reordering (const hb_ot_map_t *map, +initial_reordering (const hb_ot_shape_plan_t *plan, hb_font_t *font, hb_buffer_t *buffer) { - update_consonant_positions (map, buffer, font); + update_consonant_positions (plan, buffer, font); hb_mask_t basic_mask_array[ARRAY_LENGTH (indic_basic_features)] = {0}; unsigned int num_masks = ARRAY_LENGTH (indic_basic_features); for (unsigned int i = 0; i < num_masks; i++) - basic_mask_array[i] = map->get_1_mask (indic_basic_features[i].tag); + basic_mask_array[i] = plan->map.get_1_mask (indic_basic_features[i].tag); - find_syllables (map, buffer, basic_mask_array); + find_syllables (plan, buffer, basic_mask_array); } static void @@ -1057,15 +1055,15 @@ final_reordering_syllable (hb_buffer_t *buffer, static void -final_reordering (const hb_ot_map_t *map, +final_reordering (const hb_ot_shape_plan_t *plan, hb_font_t *font HB_UNUSED, hb_buffer_t *buffer) { unsigned int count = buffer->len; if (!count) return; - hb_mask_t init_mask = map->get_1_mask (HB_TAG('i','n','i','t')); - hb_mask_t pref_mask = map->get_1_mask (HB_TAG('p','r','e','f')); + hb_mask_t init_mask = plan->map.get_1_mask (HB_TAG('i','n','i','t')); + hb_mask_t pref_mask = plan->map.get_1_mask (HB_TAG('p','r','e','f')); hb_glyph_info_t *info = buffer->info; unsigned int last = 0; diff --git a/src/hb-ot-shape-private.hh b/src/hb-ot-shape-private.hh index 0c265280..da8a6dbe 100644 --- a/src/hb-ot-shape-private.hh +++ b/src/hb-ot-shape-private.hh @@ -44,6 +44,12 @@ struct hb_ot_shape_plan_t hb_segment_properties_t props; const struct hb_ot_complex_shaper_t *shaper; hb_ot_map_t map; + + inline void substitute_closure (hb_face_t *face, hb_set_t *glyphs) const { map.substitute_closure (this, face, glyphs); } + inline void substitute (hb_font_t *font, hb_buffer_t *buffer) const { map.substitute (this, font, buffer); } + inline void position (hb_font_t *font, hb_buffer_t *buffer) const { map.position (this, font, buffer); } + + void finish (void) { map.finish (); } }; struct hb_ot_shape_planner_t diff --git a/src/hb-ot-shape.cc b/src/hb-ot-shape.cc index c874fb53..67330b41 100644 --- a/src/hb-ot-shape.cc +++ b/src/hb-ot-shape.cc @@ -77,14 +77,16 @@ hb_ot_shape_collect_features (hb_ot_shape_planner_t *planner, const hb_feature_t *user_features, unsigned int num_user_features) { + hb_ot_map_builder_t *map = &planner->map; + switch (props->direction) { case HB_DIRECTION_LTR: - planner->map.add_bool_feature (HB_TAG ('l','t','r','a')); - planner->map.add_bool_feature (HB_TAG ('l','t','r','m')); + map->add_bool_feature (HB_TAG ('l','t','r','a')); + map->add_bool_feature (HB_TAG ('l','t','r','m')); break; case HB_DIRECTION_RTL: - planner->map.add_bool_feature (HB_TAG ('r','t','l','a')); - planner->map.add_bool_feature (HB_TAG ('r','t','l','m'), false); + map->add_bool_feature (HB_TAG ('r','t','l','a')); + map->add_bool_feature (HB_TAG ('r','t','l','m'), false); break; case HB_DIRECTION_TTB: case HB_DIRECTION_BTT: @@ -96,7 +98,7 @@ hb_ot_shape_collect_features (hb_ot_shape_planner_t *planner, #define ADD_FEATURES(array) \ HB_STMT_START { \ for (unsigned int i = 0; i < ARRAY_LENGTH (array); i++) \ - planner->map.add_bool_feature (array[i]); \ + map->add_bool_feature (array[i]); \ } HB_STMT_END if (planner->shaper->collect_features) @@ -116,7 +118,7 @@ hb_ot_shape_collect_features (hb_ot_shape_planner_t *planner, for (unsigned int i = 0; i < num_user_features; i++) { const hb_feature_t *feature = &user_features[i]; - planner->map.add_feature (feature->tag, feature->value, (feature->start == 0 && feature->end == (unsigned int) -1)); + map->add_feature (feature->tag, feature->value, (feature->start == 0 && feature->end == (unsigned int) -1)); } } @@ -183,7 +185,7 @@ _hb_ot_shaper_shape_plan_data_create (hb_shape_plan_t *shape_plan, void _hb_ot_shaper_shape_plan_data_destroy (hb_ot_shaper_shape_plan_data_t *data) { - data->map.finish (); + data->finish (); free (data); } @@ -211,7 +213,9 @@ struct hb_ot_shape_context_t static void hb_ot_shape_setup_masks (hb_ot_shape_context_t *c) { - hb_mask_t global_mask = c->plan->map.get_global_mask (); + hb_ot_map_t *map = &c->plan->map; + + hb_mask_t global_mask = map->get_global_mask (); c->buffer->reset_masks (global_mask); if (c->plan->shaper->setup_masks) @@ -222,7 +226,7 @@ hb_ot_shape_setup_masks (hb_ot_shape_context_t *c) const hb_feature_t *feature = &c->user_features[i]; if (!(feature->start == 0 && feature->end == (unsigned int)-1)) { unsigned int shift; - hb_mask_t mask = c->plan->map.get_mask (feature->tag, &shift); + hb_mask_t mask = map->get_mask (feature->tag, &shift); c->buffer->set_masks (feature->value << shift, mask, feature->start, feature->end); } } @@ -352,7 +356,7 @@ hb_ot_substitute_complex (hb_ot_shape_context_t *c) hb_synthesize_glyph_classes (c); if (hb_ot_layout_has_substitution (c->face)) - c->plan->map.substitute (c->font, c->buffer); + c->plan->substitute (c->font, c->buffer); hb_ot_layout_substitute_finish (c->font, c->buffer); @@ -408,7 +412,7 @@ hb_ot_position_complex (hb_ot_shape_context_t *c) &c->buffer->pos[i].y_offset); } - c->plan->map.position (c->font, c->buffer); + c->plan->position (c->font, c->buffer); for (unsigned int i = 0; i < count; i++) { c->font->subtract_glyph_origin_for_direction (c->buffer->info[i].codepoint, @@ -588,7 +592,7 @@ hb_ot_shape_glyphs_closure (hb_font_t *font, do { copy.set (glyphs); - HB_SHAPER_DATA_GET (shape_plan)->map.substitute_closure (font->face, glyphs); + HB_SHAPER_DATA_GET (shape_plan)->substitute_closure (font->face, glyphs); } while (!copy.equal (glyphs)); hb_shape_plan_destroy (shape_plan); -- GitLab