[config] Better compile away morx/kerx/trak

Part of https://github.com/harfbuzz/harfbuzz/issues/1652
This commit is contained in:
Behdad Esfahbod 2019-05-13 14:45:51 -07:00
parent b1d3e54bd3
commit 809c587083
2 changed files with 25 additions and 25 deletions

View File

@ -55,13 +55,9 @@ hb_ot_shape_collect_features (hb_ot_shape_planner_t *planner,
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 @@ hb_ot_shape_planner_t::hb_ot_shape_planner_t (hb_face_t *fac
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 @@ hb_ot_shape_planner_t::compile (hb_ot_shape_plan_t &plan,
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 @@ hb_ot_shape_planner_t::compile (hb_ot_shape_plan_t &plan,
* 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 @@ hb_ot_shape_planner_t::compile (hb_ot_shape_plan_t &plan,
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 @@ hb_ot_shape_planner_t::compile (hb_ot_shape_plan_t &plan,
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 @@ void
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 @@ hb_ot_shape_plan_t::position (hb_font_t *font,
{
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 @@ hb_ot_shape_collect_features (hb_ot_shape_planner_t *planner,
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 @@ hb_ot_shape_collect_features (hb_ot_shape_planner_t *planner,
aat_map->add_feature (feature->tag, feature->value);
}
}
#endif
if (planner->shaper->override_features)
planner->shaper->override_features (planner);
@ -783,10 +777,8 @@ static inline void
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 @@ hb_ot_position_complex (const hb_ot_shape_context_t *c)
/* 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. */

View File

@ -80,10 +80,16 @@ struct hb_ot_shape_plan_t
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 @@ struct hb_ot_shape_planner_t
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;