[OTLayout] Refactor a bit more
diff --git a/src/hb-ot-layout-gsubgpos-private.hh b/src/hb-ot-layout-gsubgpos-private.hh
index 5a5bce3..5169e78 100644
--- a/src/hb-ot-layout-gsubgpos-private.hh
+++ b/src/hb-ot-layout-gsubgpos-private.hh
@@ -278,14 +278,12 @@
hb_apply_context_t (unsigned int table_index_,
hb_font_t *font_,
- hb_buffer_t *buffer_,
- hb_mask_t lookup_mask_,
- bool auto_zwj_) :
+ hb_buffer_t *buffer_) :
table_index (table_index_),
font (font_), face (font->face), buffer (buffer_),
direction (buffer_->props.direction),
- lookup_mask (lookup_mask_),
- auto_zwj (auto_zwj_),
+ lookup_mask (1),
+ auto_zwj (true),
recurse_func (NULL),
nesting_level_left (MAX_NESTING_LEVEL),
lookup_props (0),
@@ -293,6 +291,8 @@
has_glyph_classes (gdef.has_glyph_classes ()),
debug_depth (0) {}
+ inline void set_lookup_mask (hb_mask_t mask) { lookup_mask = mask; }
+ inline void set_auto_zwj (bool auto_zwj_) { auto_zwj = auto_zwj_; }
inline void set_recurse_func (recurse_func_t func) { recurse_func = func; }
inline void set_lookup_props (unsigned int lookup_props_) { lookup_props = lookup_props_; }
inline void set_lookup (const Lookup &l) { lookup_props = l.get_props (); }
diff --git a/src/hb-ot-layout-private.hh b/src/hb-ot-layout-private.hh
index bd01078..a9de356 100644
--- a/src/hb-ot-layout-private.hh
+++ b/src/hb-ot-layout-private.hh
@@ -202,12 +202,19 @@
hb_ot_layout_substitute_start (hb_font_t *font,
hb_buffer_t *buffer);
-HB_INTERNAL hb_bool_t
-hb_ot_layout_substitute_lookup (hb_font_t *font,
- hb_buffer_t *buffer,
- unsigned int lookup_index,
- hb_mask_t mask,
- hb_bool_t auto_zwj);
+
+struct hb_ot_layout_lookup_accelerator_t;
+
+namespace OT {
+ struct hb_apply_context_t;
+ struct SubstLookup;
+}
+
+HB_INTERNAL void
+hb_ot_layout_substitute_lookup (OT::hb_apply_context_t *c,
+ const OT::SubstLookup &lookup,
+ const hb_ot_layout_lookup_accelerator_t &accel);
+
/* Should be called after all the substitute_lookup's are done */
HB_INTERNAL void
@@ -220,13 +227,6 @@
hb_ot_layout_position_start (hb_font_t *font,
hb_buffer_t *buffer);
-HB_INTERNAL hb_bool_t
-hb_ot_layout_position_lookup (hb_font_t *font,
- hb_buffer_t *buffer,
- unsigned int lookup_index,
- hb_mask_t mask,
- hb_bool_t auto_zwj);
-
/* Should be called after all the position_lookup's are done */
HB_INTERNAL void
hb_ot_layout_position_finish (hb_font_t *font,
diff --git a/src/hb-ot-layout.cc b/src/hb-ot-layout.cc
index a944a95..d1d63e3 100644
--- a/src/hb-ot-layout.cc
+++ b/src/hb-ot-layout.cc
@@ -669,22 +669,6 @@
OT::GSUB::substitute_start (font, buffer);
}
-hb_bool_t
-hb_ot_layout_substitute_lookup (hb_font_t *font,
- hb_buffer_t *buffer,
- unsigned int lookup_index,
- hb_mask_t mask,
- hb_bool_t auto_zwj)
-{
- if (unlikely (lookup_index >= hb_ot_layout_from_face (font->face)->gsub_lookup_count)) return false;
-
- OT::hb_apply_context_t c (0, font, buffer, mask, auto_zwj);
-
- const OT::SubstLookup& l = hb_ot_layout_from_face (font->face)->gsub->get_lookup (lookup_index);
-
- return l.apply_string (&c, &hb_ot_layout_from_face (font->face)->gsub_accels[lookup_index].digest);
-}
-
void
hb_ot_layout_substitute_finish (hb_font_t *font, hb_buffer_t *buffer)
{
@@ -719,22 +703,6 @@
OT::GPOS::position_start (font, buffer);
}
-hb_bool_t
-hb_ot_layout_position_lookup (hb_font_t *font,
- hb_buffer_t *buffer,
- unsigned int lookup_index,
- hb_mask_t mask,
- hb_bool_t auto_zwj)
-{
- if (unlikely (lookup_index >= hb_ot_layout_from_face (font->face)->gpos_lookup_count)) return false;
-
- OT::hb_apply_context_t c (1, font, buffer, mask, auto_zwj);
-
- const OT::PosLookup& l = hb_ot_layout_from_face (font->face)->gpos->get_lookup (lookup_index);
-
- return l.apply_string (&c, &hb_ot_layout_from_face (font->face)->gpos_accels[lookup_index].digest);
-}
-
void
hb_ot_layout_position_finish (hb_font_t *font, hb_buffer_t *buffer)
{
@@ -788,35 +756,57 @@
/*
- * Parts of hb-ot-map are implemented here such that they have direct
+ * Parts of different types are implemented here such that they have direct
* access to GSUB/GPOS lookups.
*/
-inline void hb_ot_map_t::apply (unsigned int table_index,
+struct GSUBProxy
+{
+ static const unsigned int table_index = 0;
+ typedef OT::SubstLookup Lookup;
+
+ GSUBProxy (hb_face_t *face) :
+ table (*hb_ot_layout_from_face (face)->gsub),
+ accels (hb_ot_layout_from_face (face)->gsub_accels) {}
+
+ const OT::GSUB &table;
+ const hb_ot_layout_lookup_accelerator_t *accels;
+};
+
+struct GPOSProxy
+{
+ static const unsigned int table_index = 1;
+ typedef OT::PosLookup Lookup;
+
+ GPOSProxy (hb_face_t *face) :
+ table (*hb_ot_layout_from_face (face)->gpos),
+ accels (hb_ot_layout_from_face (face)->gpos_accels) {}
+
+ const OT::GPOS &table;
+ const hb_ot_layout_lookup_accelerator_t *accels;
+};
+
+
+template <typename Proxy>
+inline void hb_ot_map_t::apply (const Proxy &proxy,
const hb_ot_shape_plan_t *plan,
hb_font_t *font,
hb_buffer_t *buffer) const
{
+ const unsigned int table_index = proxy.table_index;
unsigned int i = 0;
+ OT::hb_apply_context_t c (table_index, font, buffer);
for (unsigned int stage_index = 0; stage_index < stages[table_index].len; stage_index++) {
const stage_map_t *stage = &stages[table_index][stage_index];
for (; i < stage->last_lookup; i++)
- switch (table_index)
- {
- case 0:
- hb_ot_layout_substitute_lookup (font, buffer, lookups[table_index][i].index,
- lookups[table_index][i].mask,
- lookups[table_index][i].auto_zwj);
- break;
-
- case 1:
- hb_ot_layout_position_lookup (font, buffer, lookups[table_index][i].index,
- lookups[table_index][i].mask,
- lookups[table_index][i].auto_zwj);
- break;
- }
+ {
+ unsigned int lookup_index = lookups[table_index][i].index;
+ c.set_lookup_mask (lookups[table_index][i].mask);
+ c.set_auto_zwj (lookups[table_index][i].auto_zwj);
+ proxy.table.get_lookup (lookup_index).apply_string (&c, &proxy.accels[lookup_index].digest);
+ }
if (stage->pause_func)
{
@@ -828,10 +818,20 @@
void hb_ot_map_t::substitute (const hb_ot_shape_plan_t *plan, hb_font_t *font, hb_buffer_t *buffer) const
{
- apply (0, plan, font, buffer);
+ GSUBProxy proxy (font->face);
+ apply (proxy, plan, font, buffer);
}
void hb_ot_map_t::position (const hb_ot_shape_plan_t *plan, hb_font_t *font, hb_buffer_t *buffer) const
{
- apply (1, plan, font, buffer);
+ GPOSProxy proxy (font->face);
+ apply (proxy, plan, font, buffer);
+}
+
+HB_INTERNAL void
+hb_ot_layout_substitute_lookup (OT::hb_apply_context_t *c,
+ const OT::SubstLookup &lookup,
+ const hb_ot_layout_lookup_accelerator_t &accel)
+{
+ lookup.apply_string (c, &accel.digest);
}
diff --git a/src/hb-ot-map-private.hh b/src/hb-ot-map-private.hh
index 5ed54a6..0e718a6 100644
--- a/src/hb-ot-map-private.hh
+++ b/src/hb-ot-map-private.hh
@@ -118,10 +118,9 @@
}
HB_INTERNAL void collect_lookups (unsigned int table_index, hb_set_t *lookups) const;
- HB_INTERNAL inline void apply (unsigned int table_index,
- const struct hb_ot_shape_plan_t *plan,
- hb_font_t *font,
- hb_buffer_t *buffer) const;
+ template <typename Proxy>
+ HB_INTERNAL inline void apply (const Proxy &proxy,
+ const struct hb_ot_shape_plan_t *plan, hb_font_t *font, hb_buffer_t *buffer) 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;
diff --git a/src/hb-ot-shape-complex-arabic-fallback.hh b/src/hb-ot-shape-complex-arabic-fallback.hh
index 91d6e44..6b2b87e 100644
--- a/src/hb-ot-shape-complex-arabic-fallback.hh
+++ b/src/hb-ot-shape-complex-arabic-fallback.hh
@@ -246,10 +246,13 @@
hb_font_t *font,
hb_buffer_t *buffer)
{
+ OT::hb_apply_context_t c (0, font, buffer);
for (unsigned int i = 0; i < ARABIC_NUM_FALLBACK_FEATURES; i++)
if (fallback_plan->lookup_array[i]) {
- OT::hb_apply_context_t c (0, font, buffer, fallback_plan->mask_array[i], true/*auto_zwj*/);
- fallback_plan->lookup_array[i]->apply_string (&c, &fallback_plan->accel_array[i].digest);
+ c.set_lookup_mask (fallback_plan->mask_array[i]);
+ hb_ot_layout_substitute_lookup (&c,
+ *fallback_plan->lookup_array[i],
+ fallback_plan->accel_array[i]);
}
}
diff --git a/src/hb-ot-shape-fallback.cc b/src/hb-ot-shape-fallback.cc
index 3341825..284d030 100644
--- a/src/hb-ot-shape-fallback.cc
+++ b/src/hb-ot-shape-fallback.cc
@@ -420,7 +420,8 @@
hb_mask_t kern_mask = plan->map.get_1_mask (HB_DIRECTION_IS_HORIZONTAL (buffer->props.direction) ?
HB_TAG ('k','e','r','n') : HB_TAG ('v','k','r','n'));
- OT::hb_apply_context_t c (1, font, buffer, kern_mask, true/*auto_zwj*/);
+ OT::hb_apply_context_t c (1, font, buffer);
+ c.set_lookup_mask (kern_mask);
c.set_lookup_props (OT::LookupFlag::IgnoreMarks);
for (buffer->idx = 0; buffer->idx < count;)