Refactoring ot-map building to make chosen script available earlier

This commit is contained in:
Behdad Esfahbod 2012-11-12 17:57:24 -08:00
parent f17ed8116e
commit 6fddf2d739
3 changed files with 40 additions and 28 deletions

View File

@ -151,7 +151,8 @@ struct hb_ot_map_builder_t
{
public:
hb_ot_map_builder_t (void) { memset (this, 0, sizeof (*this)); }
HB_INTERNAL hb_ot_map_builder_t (hb_face_t *face_,
const hb_segment_properties_t *props_);
HB_INTERNAL void add_feature (hb_tag_t tag, unsigned int value, bool global, bool has_fallback = false);
@ -163,9 +164,7 @@ struct hb_ot_map_builder_t
inline void add_gpos_pause (hb_ot_map_t::pause_func_t pause_func)
{ add_pause (1, pause_func); }
HB_INTERNAL void compile (hb_face_t *face,
const hb_segment_properties_t *props,
struct hb_ot_map_t &m);
HB_INTERNAL void compile (struct hb_ot_map_t &m);
inline void finish (void) {
feature_infos.finish ();
@ -195,6 +194,12 @@ struct hb_ot_map_builder_t
HB_INTERNAL void add_pause (unsigned int table_index, hb_ot_map_t::pause_func_t pause_func);
hb_face_t *face;
hb_segment_properties_t props;
hb_tag_t chosen_script[2];
unsigned int script_index[2], language_index[2];
unsigned int current_stage[2]; /* GSUB/GPOS */
hb_prealloced_array_t<feature_info_t,16> feature_infos;
hb_prealloced_array_t<pause_info_t, 1> pauses[2]; /* GSUB/GPOS */

View File

@ -59,6 +59,30 @@ hb_ot_map_t::add_lookups (hb_face_t *face,
} while (len == ARRAY_LENGTH (lookup_indices));
}
hb_ot_map_builder_t::hb_ot_map_builder_t (hb_face_t *face_,
const hb_segment_properties_t *props_)
{
memset (this, 0, sizeof (*this));
face = face_;
props = *props_;
/* Fetch script/language indices for GSUB/GPOS. We need these later to skip
* features not available in either table and not waste precious bits for them. */
hb_tag_t script_tags[3] = {HB_TAG_NONE, HB_TAG_NONE, HB_TAG_NONE};
hb_tag_t language_tag;
hb_ot_tags_from_script (props.script, &script_tags[0], &script_tags[1]);
language_tag = hb_ot_tag_from_language (props.language);
for (unsigned int table_index = 0; table_index < 2; table_index++) {
hb_tag_t table_tag = table_tags[table_index];
hb_ot_layout_table_choose_script (face, table_tag, script_tags, &script_index[table_index], &chosen_script[table_index]);
hb_ot_layout_script_find_language (face, table_tag, script_index[table_index], language_tag, &language_index[table_index]);
}
}
void hb_ot_map_builder_t::add_feature (hb_tag_t tag, unsigned int value, bool global, bool has_fallback)
{
@ -133,33 +157,16 @@ void hb_ot_map_builder_t::add_pause (unsigned int table_index, hb_ot_map_t::paus
}
void
hb_ot_map_builder_t::compile (hb_face_t *face,
const hb_segment_properties_t *props,
hb_ot_map_t &m)
hb_ot_map_builder_t::compile (hb_ot_map_t &m)
{
m.global_mask = 1;
m.global_mask = 1;
for (unsigned int table_index = 0; table_index < 2; table_index++)
m.chosen_script[table_index] = chosen_script[table_index];
if (!feature_infos.len)
return;
/* Fetch script/language indices for GSUB/GPOS. We need these later to skip
* features not available in either table and not waste precious bits for them. */
hb_tag_t script_tags[3] = {HB_TAG_NONE};
hb_tag_t language_tag;
hb_ot_tags_from_script (props->script, &script_tags[0], &script_tags[1]);
language_tag = hb_ot_tag_from_language (props->language);
unsigned int script_index[2], language_index[2];
for (unsigned int table_index = 0; table_index < 2; table_index++) {
hb_tag_t table_tag = table_tags[table_index];
hb_ot_layout_table_choose_script (face, table_tag, script_tags, &script_index[table_index], &m.chosen_script[table_index]);
hb_ot_layout_script_find_language (face, table_tag, script_index[table_index], language_tag, &language_index[table_index]);
}
/* Sort features and merge duplicates */
{
feature_infos.sort ();

View File

@ -65,14 +65,14 @@ struct hb_ot_shape_planner_t
face (master_plan->face),
props (master_plan->props),
shaper (NULL),
map () {}
map (face, &props) {}
~hb_ot_shape_planner_t (void) { map.finish (); }
inline void compile (hb_ot_shape_plan_t &plan)
{
plan.props = props;
plan.shaper = shaper;
map.compile (face, &props, plan.map);
map.compile (plan.map);
}
private: