From: Behdad Esfahbod Date: Tue, 12 Oct 2010 19:35:45 +0000 (-0400) Subject: More refactoring X-Git-Tag: 2.0_alpha~7^2~507 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=d2ba016ca1ba7489537768b619980d5159b5870c;p=apps%2Fhome%2Fvideo-player.git More refactoring --- diff --git a/src/hb-ot-map-private.hh b/src/hb-ot-map-private.hh index 816ce4f..abf96f2 100644 --- a/src/hb-ot-map-private.hh +++ b/src/hb-ot-map-private.hh @@ -73,32 +73,10 @@ struct hb_ot_map_t { { return a->index < b->index ? -1 : a->index > b->index ? 1 : 0; } }; - - void - add_lookups (hb_ot_shape_context_t *c, - unsigned int table_index, - unsigned int feature_index, - hb_mask_t mask) - { - unsigned int i = MAX_LOOKUPS - lookup_count[table_index]; - lookup_map_t *lookups = lookup_maps[table_index] + lookup_count[table_index]; - - unsigned int *lookup_indices = (unsigned int *) lookups; - - hb_ot_layout_feature_get_lookup_indexes (c->face, - table_tags[table_index], - feature_index, - 0, &i, - lookup_indices); - - lookup_count[table_index] += i; - - while (i--) { - lookups[i].mask = mask; - lookups[i].index = lookup_indices[i]; - } - } - + HB_INTERNAL void add_lookups (hb_ot_shape_plan_context_t *c, + unsigned int table_index, + unsigned int feature_index, + hb_mask_t mask); public: @@ -117,7 +95,7 @@ struct hb_ot_map_t { inline void add_bool_feature (hb_tag_t tag, bool global = true) { add_feature (tag, 1, global); } - HB_INTERNAL void compile (hb_ot_shape_context_t *c); + HB_INTERNAL void compile (hb_ot_shape_plan_context_t *c); hb_mask_t get_global_mask (void) const { return global_mask; } diff --git a/src/hb-ot-map.cc b/src/hb-ot-map.cc index 8cf21b4..84149b8 100644 --- a/src/hb-ot-map.cc +++ b/src/hb-ot-map.cc @@ -34,7 +34,33 @@ HB_BEGIN_DECLS void -hb_ot_map_t::compile (hb_ot_shape_context_t *c) +hb_ot_map_t::add_lookups (hb_ot_shape_plan_context_t *c, + unsigned int table_index, + unsigned int feature_index, + hb_mask_t mask) +{ + unsigned int i = MAX_LOOKUPS - lookup_count[table_index]; + lookup_map_t *lookups = lookup_maps[table_index] + lookup_count[table_index]; + + unsigned int *lookup_indices = (unsigned int *) lookups; + + hb_ot_layout_feature_get_lookup_indexes (c->face, + table_tags[table_index], + feature_index, + 0, &i, + lookup_indices); + + lookup_count[table_index] += i; + + while (i--) { + lookups[i].mask = mask; + lookups[i].index = lookup_indices[i]; + } +} + + +void +hb_ot_map_t::compile (hb_ot_shape_plan_context_t *c) { global_mask = 0; lookup_count[0] = lookup_count[1] = 0; @@ -49,8 +75,8 @@ hb_ot_map_t::compile (hb_ot_shape_context_t *c) const hb_tag_t *script_tags; hb_tag_t language_tag; - script_tags = hb_ot_tags_from_script (c->buffer->props.script); - language_tag = hb_ot_tag_from_language (c->buffer->props.language); + script_tags = hb_ot_tags_from_script (c->props->script); + language_tag = hb_ot_tag_from_language (c->props->language); unsigned int script_index[2], language_index[2]; for (unsigned int table_index = 0; table_index < 2; table_index++) { diff --git a/src/hb-ot-shape-private.hh b/src/hb-ot-shape-private.hh index b00be33..0d21e88 100644 --- a/src/hb-ot-shape-private.hh +++ b/src/hb-ot-shape-private.hh @@ -37,14 +37,26 @@ HB_BEGIN_DECLS struct hb_ot_map_t; +struct hb_ot_shape_plan_context_t +{ + struct hb_ot_map_t *map; + + hb_face_t *face; + hb_segment_properties_t *props; + + const hb_feature_t *user_features; + unsigned int num_user_features; +}; + + struct hb_ot_shape_context_t { /* Input to hb_ot_shape() */ hb_font_t *font; hb_face_t *face; hb_buffer_t *buffer; - hb_feature_t *features; - unsigned int num_features; + const hb_feature_t *user_features; + unsigned int num_user_features; /* Transient stuff */ hb_direction_t original_direction; diff --git a/src/hb-ot-shape.cc b/src/hb-ot-shape.cc index 8fc9c4f..b0494c7 100644 --- a/src/hb-ot-shape.cc +++ b/src/hb-ot-shape.cc @@ -49,9 +49,9 @@ hb_tag_t default_features[] = { }; static void -hb_ot_shape_collect_features (hb_ot_shape_context_t *c) +hb_ot_shape_collect_features (hb_ot_shape_plan_context_t *c) { - switch (c->original_direction) { + switch (c->props->direction) { case HB_DIRECTION_LTR: c->map->add_bool_feature (HB_TAG ('l','t','r','a')); c->map->add_bool_feature (HB_TAG ('l','t','r','m')); @@ -71,8 +71,8 @@ hb_ot_shape_collect_features (hb_ot_shape_context_t *c) /* complex */ - for (unsigned int i = 0; i < c->num_features; i++) { - const hb_feature_t *feature = &c->features[i]; + for (unsigned int i = 0; i < c->num_user_features; i++) { + const hb_feature_t *feature = &c->user_features[i]; c->map->add_feature (feature->tag, feature->value, (feature->start == 0 && feature->end == (unsigned int) -1)); } } @@ -85,9 +85,9 @@ hb_ot_shape_setup_masks (hb_ot_shape_context_t *c) if (global_mask) c->buffer->set_masks (global_mask, global_mask, 0, (unsigned int) -1); - for (unsigned int i = 0; i < c->num_features; i++) + for (unsigned int i = 0; i < c->num_user_features; i++) { - hb_feature_t *feature = &c->features[i]; + 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->map->get_mask (feature->tag, &shift); @@ -271,6 +271,9 @@ hb_position_complex_fallback_visual (hb_ot_shape_context_t *c) static void hb_ot_shape_internal (hb_ot_shape_context_t *c) { + /* Save the original direction, we use it later. */ + c->original_direction = c->buffer->props.direction; + hb_ot_shape_setup_masks (c); hb_form_clusters (c); @@ -315,22 +318,32 @@ hb_ot_shape_internal (hb_ot_shape_context_t *c) } void +hb_ot_shape_plan_internal (hb_ot_map_t *map, + hb_face_t *face, + hb_segment_properties_t *props, + const hb_feature_t *user_features, + unsigned int num_user_features) +{ + hb_ot_shape_plan_context_t c = {map, face, props, user_features, num_user_features}; + + hb_ot_shape_collect_features (&c); + + map->compile (&c); +} + +void hb_ot_shape (hb_font_t *font, hb_face_t *face, hb_buffer_t *buffer, - hb_feature_t *features, - unsigned int num_features) + const hb_feature_t *user_features, + unsigned int num_user_features) { - hb_ot_shape_context_t c = {font, face, buffer, features, num_features}; hb_ot_map_t map; - /* Setup transient context members */ - c.original_direction = buffer->props.direction; - c.map = ↦ - - hb_ot_shape_collect_features (&c); - c.map->compile (&c); + hb_ot_shape_plan_internal (&map, face, &buffer->props, user_features, num_user_features); + hb_ot_shape_context_t c = {font, face, buffer, user_features, num_user_features}; + c.map = ↦ hb_ot_shape_internal (&c); } diff --git a/src/hb-ot-shape.h b/src/hb-ot-shape.h index 182d951..c90e0fe 100644 --- a/src/hb-ot-shape.h +++ b/src/hb-ot-shape.h @@ -34,11 +34,11 @@ HB_BEGIN_DECLS void -hb_ot_shape (hb_font_t *font, - hb_face_t *face, - hb_buffer_t *buffer, - hb_feature_t *features, - unsigned int num_features); +hb_ot_shape (hb_font_t *font, + hb_face_t *face, + hb_buffer_t *buffer, + const hb_feature_t *user_features, + unsigned int num_user_features); HB_END_DECLS