[config] Better compile away morx/kerx/trak
Part of https://github.com/harfbuzz/harfbuzz/issues/1652
diff --git a/src/hb-ot-shape.cc b/src/hb-ot-shape.cc
index 09b8a58..89de008 100644
--- a/src/hb-ot-shape.cc
+++ b/src/hb-ot-shape.cc
@@ -55,13 +55,9 @@
const hb_feature_t *user_features,
unsigned int num_user_features);
-static bool
+static inline bool
_hb_apply_morx (hb_face_t *face)
{
-#ifdef HB_NO_SHAPE_AAT
- return false;
-#endif
-
if (hb_options ().aat &&
hb_aat_layout_has_substitution (face))
return true;
@@ -79,18 +75,18 @@
face (face),
props (*props),
map (face, props),
- aat_map (face, props),
- apply_morx (_hb_apply_morx (face))
+ aat_map (face, props)
+#ifndef HB_NO_SHAPE_AAT
+ , apply_morx (_hb_apply_morx (face))
+#endif
{
shaper = hb_ot_shape_complex_categorize (this);
script_zero_marks = shaper->zero_width_marks != HB_OT_SHAPE_ZERO_WIDTH_MARKS_NONE;
script_fallback_mark_positioning = shaper->fallback_position;
-#ifndef HB_NO_SHAPE_AAT
if (apply_morx)
shaper = &_hb_ot_complex_shaper_default;
-#endif
}
void
@@ -100,10 +96,8 @@
plan.props = props;
plan.shaper = shaper;
map.compile (plan.map, key);
-#ifndef HB_NO_SHAPE_AAT
if (apply_morx)
aat_map.compile (plan.aat_map);
-#endif
plan.frac_mask = plan.map.get_1_mask (HB_TAG ('f','r','a','c'));
plan.numr_mask = plan.map.get_1_mask (HB_TAG ('n','u','m','r'));
@@ -132,7 +126,9 @@
* Decide who does substitutions. GSUB, morx, or fallback.
*/
+#ifndef HB_NO_SHAPE_AAT
plan.apply_morx = apply_morx;
+#endif
/*
* Decide who does positioning. GPOS, kerx, kern, or fallback.
@@ -154,8 +150,12 @@
if (!plan.apply_kerx && !has_gpos_kern)
{
/* Apparently Apple applies kerx if GPOS kern was not applied. */
- if (hb_aat_layout_has_positioning (face))
+ if (0)
+ ;
+#ifndef HB_NO_SHAPE_AAT
+ else if (hb_aat_layout_has_positioning (face))
plan.apply_kerx = true;
+#endif
else if (hb_ot_layout_has_kerning (face))
plan.apply_kern = true;
}
@@ -172,8 +172,10 @@
plan.fallback_mark_positioning = plan.adjust_mark_positioning_when_zeroing &&
script_fallback_mark_positioning;
+#ifndef HB_NO_SHAPE_AAT
/* Currently we always apply trak. */
plan.apply_trak = plan.requested_tracking && hb_aat_layout_has_tracking (face);
+#endif
}
bool
@@ -216,11 +218,9 @@
hb_ot_shape_plan_t::substitute (hb_font_t *font,
hb_buffer_t *buffer) const
{
-#ifndef HB_NO_SHAPE_AAT
if (unlikely (apply_morx))
hb_aat_layout_substitute (this, font, buffer);
else
-#endif
map.substitute (this, font, buffer);
}
@@ -230,19 +230,15 @@
{
if (this->apply_gpos)
map.position (this, font, buffer);
-#ifndef HB_NO_SHAPE_AAT
else if (this->apply_kerx)
hb_aat_layout_position (this, font, buffer);
-#endif
else if (this->apply_kern)
hb_ot_layout_kern (this, font, buffer);
else
_hb_ot_shape_fallback_kern (this, font, buffer);
-#ifndef HB_NO_SHAPE_AAT
if (this->apply_trak)
hb_aat_layout_track (this, font, buffer);
-#endif
}
@@ -338,7 +334,6 @@
feature->value);
}
-#ifndef HB_NO_SHAPE_AAT
if (planner->apply_morx)
{
hb_aat_map_builder_t *aat_map = &planner->aat_map;
@@ -348,7 +343,6 @@
aat_map->add_feature (feature->tag, feature->value);
}
}
-#endif
if (planner->shaper->override_features)
planner->shaper->override_features (planner);
@@ -783,10 +777,8 @@
hb_ot_substitute_post (const hb_ot_shape_context_t *c)
{
hb_ot_hide_default_ignorables (c->buffer, c->font);
-#ifndef HB_NO_SHAPE_AAT
if (c->plan->apply_morx)
hb_aat_layout_remove_deleted_glyphs (c->buffer);
-#endif
if (c->plan->shaper->postprocess_glyphs)
c->plan->shaper->postprocess_glyphs (c->plan, c->buffer, c->font);
@@ -920,10 +912,8 @@
/* Finish off. Has to follow a certain order. */
hb_ot_layout_position_finish_advances (c->font, c->buffer);
hb_ot_zero_width_default_ignorables (c->buffer);
-#ifndef HB_NO_SHAPE_AAT
if (c->plan->apply_morx)
hb_aat_layout_zero_width_deleted_glyphs (c->buffer);
-#endif
hb_ot_layout_position_finish_offsets (c->font, c->buffer);
/* The nil glyph_h_origin() func returns 0, so no need to apply it. */
diff --git a/src/hb-ot-shape.hh b/src/hb-ot-shape.hh
index 73a11e1..b7c0f10 100644
--- a/src/hb-ot-shape.hh
+++ b/src/hb-ot-shape.hh
@@ -80,10 +80,16 @@
bool adjust_mark_positioning_when_zeroing : 1;
bool apply_gpos : 1;
- bool apply_kerx : 1;
bool apply_kern : 1;
+#ifndef HB_NO_SHAPE_AAT
+ bool apply_kerx : 1;
bool apply_morx : 1;
bool apply_trak : 1;
+#else
+ static constexpr bool apply_kerx = false;
+ static constexpr bool apply_morx = false;
+ static constexpr bool apply_trak = false;
+#endif
void collect_lookups (hb_tag_t table_tag, hb_set_t *lookups) const
{
@@ -113,7 +119,11 @@
hb_segment_properties_t props;
hb_ot_map_builder_t map;
hb_aat_map_builder_t aat_map;
+#ifndef HB_NO_SHAPE_AAT
bool apply_morx : 1;
+#else
+ static constexpr bool apply_morx = false;
+#endif
bool script_zero_marks : 1;
bool script_fallback_mark_positioning : 1;
const struct hb_ot_complex_shaper_t *shaper;