Add HB_NO_AAT

Part of https://github.com/harfbuzz/harfbuzz/issues/1652
This commit is contained in:
Behdad Esfahbod 2019-05-10 23:31:05 -07:00
parent 62dfe7aea2
commit 2c93f0dee3
4 changed files with 107 additions and 1 deletions

View File

@ -135,6 +135,10 @@ static const hb_aat_feature_mapping_t feature_mappings[] =
const hb_aat_feature_mapping_t * const hb_aat_feature_mapping_t *
hb_aat_layout_find_feature_mapping (hb_tag_t tag) hb_aat_layout_find_feature_mapping (hb_tag_t tag)
{ {
#ifdef HB_NO_AAT
return nullptr;
#endif
return (const hb_aat_feature_mapping_t *) bsearch (&tag, return (const hb_aat_feature_mapping_t *) bsearch (&tag,
feature_mappings, feature_mappings,
ARRAY_LENGTH (feature_mappings), ARRAY_LENGTH (feature_mappings),
@ -147,6 +151,8 @@ hb_aat_layout_find_feature_mapping (hb_tag_t tag)
* hb_aat_apply_context_t * hb_aat_apply_context_t
*/ */
/* Note: This context is used for kerning, even without AAT. */
AAT::hb_aat_apply_context_t::hb_aat_apply_context_t (const hb_ot_shape_plan_t *plan_, AAT::hb_aat_apply_context_t::hb_aat_apply_context_t (const hb_ot_shape_plan_t *plan_,
hb_font_t *font_, hb_font_t *font_,
hb_buffer_t *buffer_, hb_buffer_t *buffer_,
@ -183,6 +189,10 @@ void
hb_aat_layout_compile_map (const hb_aat_map_builder_t *mapper, hb_aat_layout_compile_map (const hb_aat_map_builder_t *mapper,
hb_aat_map_t *map) hb_aat_map_t *map)
{ {
#ifdef HB_NO_AAT
return;
#endif
const AAT::morx& morx = *mapper->face->table.morx; const AAT::morx& morx = *mapper->face->table.morx;
if (morx.has_data ()) if (morx.has_data ())
{ {
@ -209,6 +219,10 @@ hb_aat_layout_compile_map (const hb_aat_map_builder_t *mapper,
hb_bool_t hb_bool_t
hb_aat_layout_has_substitution (hb_face_t *face) hb_aat_layout_has_substitution (hb_face_t *face)
{ {
#ifdef HB_NO_AAT
return false;
#endif
return face->table.morx->has_data () || return face->table.morx->has_data () ||
face->table.mort->has_data (); face->table.mort->has_data ();
} }
@ -218,6 +232,10 @@ hb_aat_layout_substitute (const hb_ot_shape_plan_t *plan,
hb_font_t *font, hb_font_t *font,
hb_buffer_t *buffer) hb_buffer_t *buffer)
{ {
#ifdef HB_NO_AAT
return;
#endif
hb_blob_t *morx_blob = font->face->table.morx.get_blob (); hb_blob_t *morx_blob = font->face->table.morx.get_blob ();
const AAT::morx& morx = *morx_blob->as<AAT::morx> (); const AAT::morx& morx = *morx_blob->as<AAT::morx> ();
if (morx.has_data ()) if (morx.has_data ())
@ -240,6 +258,10 @@ hb_aat_layout_substitute (const hb_ot_shape_plan_t *plan,
void void
hb_aat_layout_zero_width_deleted_glyphs (hb_buffer_t *buffer) hb_aat_layout_zero_width_deleted_glyphs (hb_buffer_t *buffer)
{ {
#ifdef HB_NO_AAT
return;
#endif
unsigned int count = buffer->len; unsigned int count = buffer->len;
hb_glyph_info_t *info = buffer->info; hb_glyph_info_t *info = buffer->info;
hb_glyph_position_t *pos = buffer->pos; hb_glyph_position_t *pos = buffer->pos;
@ -257,6 +279,10 @@ is_deleted_glyph (const hb_glyph_info_t *info)
void void
hb_aat_layout_remove_deleted_glyphs (hb_buffer_t *buffer) hb_aat_layout_remove_deleted_glyphs (hb_buffer_t *buffer)
{ {
#ifdef HB_NO_AAT
return;
#endif
hb_ot_layout_delete_glyphs_inplace (buffer, is_deleted_glyph); hb_ot_layout_delete_glyphs_inplace (buffer, is_deleted_glyph);
} }
@ -270,6 +296,10 @@ hb_aat_layout_remove_deleted_glyphs (hb_buffer_t *buffer)
hb_bool_t hb_bool_t
hb_aat_layout_has_positioning (hb_face_t *face) hb_aat_layout_has_positioning (hb_face_t *face)
{ {
#ifdef HB_NO_AAT
return false;
#endif
return face->table.kerx->has_data (); return face->table.kerx->has_data ();
} }
@ -278,6 +308,10 @@ hb_aat_layout_position (const hb_ot_shape_plan_t *plan,
hb_font_t *font, hb_font_t *font,
hb_buffer_t *buffer) hb_buffer_t *buffer)
{ {
#ifdef HB_NO_AAT
return;
#endif
hb_blob_t *kerx_blob = font->face->table.kerx.get_blob (); hb_blob_t *kerx_blob = font->face->table.kerx.get_blob ();
const AAT::kerx& kerx = *kerx_blob->as<AAT::kerx> (); const AAT::kerx& kerx = *kerx_blob->as<AAT::kerx> ();
@ -297,6 +331,10 @@ hb_aat_layout_position (const hb_ot_shape_plan_t *plan,
hb_bool_t hb_bool_t
hb_aat_layout_has_tracking (hb_face_t *face) hb_aat_layout_has_tracking (hb_face_t *face)
{ {
#ifdef HB_NO_AAT
return false;
#endif
return face->table.trak->has_data (); return face->table.trak->has_data ();
} }
@ -305,6 +343,10 @@ hb_aat_layout_track (const hb_ot_shape_plan_t *plan,
hb_font_t *font, hb_font_t *font,
hb_buffer_t *buffer) hb_buffer_t *buffer)
{ {
#ifdef HB_NO_AAT
return;
#endif
const AAT::trak& trak = *font->face->table.trak; const AAT::trak& trak = *font->face->table.trak;
AAT::hb_aat_apply_context_t c (plan, font, buffer); AAT::hb_aat_apply_context_t c (plan, font, buffer);
@ -328,6 +370,12 @@ hb_aat_layout_get_feature_types (hb_face_t *face,
unsigned int *feature_count, /* IN/OUT. May be NULL. */ unsigned int *feature_count, /* IN/OUT. May be NULL. */
hb_aat_layout_feature_type_t *features /* OUT. May be NULL. */) hb_aat_layout_feature_type_t *features /* OUT. May be NULL. */)
{ {
#ifdef HB_NO_AAT
if (feature_count)
*feature_count = 0;
return 0;
#endif
return face->table.feat->get_feature_types (start_offset, feature_count, features); return face->table.feat->get_feature_types (start_offset, feature_count, features);
} }
@ -344,6 +392,10 @@ hb_ot_name_id_t
hb_aat_layout_feature_type_get_name_id (hb_face_t *face, hb_aat_layout_feature_type_get_name_id (hb_face_t *face,
hb_aat_layout_feature_type_t feature_type) hb_aat_layout_feature_type_t feature_type)
{ {
#ifdef HB_NO_AAT
return HB_OT_NAME_ID_INVALID;
#endif
return face->table.feat->get_feature_name_id (feature_type); return face->table.feat->get_feature_name_id (feature_type);
} }
@ -372,5 +424,11 @@ hb_aat_layout_feature_type_get_selector_infos (hb_face_t
hb_aat_layout_feature_selector_info_t *selectors, /* OUT. May be NULL. */ hb_aat_layout_feature_selector_info_t *selectors, /* OUT. May be NULL. */
unsigned int *default_index /* OUT. May be NULL. */) unsigned int *default_index /* OUT. May be NULL. */)
{ {
#ifdef HB_NO_AAT
if (selector_count)
*selector_count = 0;
return 0;
#endif
return face->table.feat->get_selector_infos (feature_type, start_offset, selector_count, selectors, default_index); return face->table.feat->get_selector_infos (feature_type, start_offset, selector_count, selectors, default_index);
} }

View File

@ -34,6 +34,10 @@
void hb_aat_map_builder_t::add_feature (hb_tag_t tag, void hb_aat_map_builder_t::add_feature (hb_tag_t tag,
unsigned int value) unsigned int value)
{ {
#ifdef HB_NO_AAT
return;
#endif
if (tag == HB_TAG ('a','a','l','t')) if (tag == HB_TAG ('a','a','l','t'))
{ {
feature_info_t *info = features.push(); feature_info_t *info = features.push();
@ -53,6 +57,10 @@ void hb_aat_map_builder_t::add_feature (hb_tag_t tag,
void void
hb_aat_map_builder_t::compile (hb_aat_map_t &m) hb_aat_map_builder_t::compile (hb_aat_map_t &m)
{ {
#ifdef HB_NO_AAT
return;
#endif
/* Sort features and merge duplicates */ /* Sort features and merge duplicates */
if (features.length) if (features.length)
{ {

View File

@ -128,9 +128,13 @@ struct KernSubTable
TRACE_DISPATCH (this, subtable_type); TRACE_DISPATCH (this, subtable_type);
switch (subtable_type) { switch (subtable_type) {
case 0: return_trace (c->dispatch (u.format0)); case 0: return_trace (c->dispatch (u.format0));
#ifndef HB_NO_AAT
case 1: return_trace (u.header.apple ? c->dispatch (u.format1, hb_forward<Ts> (ds)...) : c->default_return_value ()); case 1: return_trace (u.header.apple ? c->dispatch (u.format1, hb_forward<Ts> (ds)...) : c->default_return_value ());
#endif
case 2: return_trace (c->dispatch (u.format2)); case 2: return_trace (c->dispatch (u.format2));
#ifndef HB_NO_AAT
case 3: return_trace (u.header.apple ? c->dispatch (u.format3, hb_forward<Ts> (ds)...) : c->default_return_value ()); case 3: return_trace (u.header.apple ? c->dispatch (u.format3, hb_forward<Ts> (ds)...) : c->default_return_value ());
#endif
default: return_trace (c->default_return_value ()); default: return_trace (c->default_return_value ());
} }
} }
@ -278,7 +282,9 @@ struct kern
{ {
switch (get_type ()) { switch (get_type ()) {
case 0: return u.ot.has_state_machine (); case 0: return u.ot.has_state_machine ();
#ifndef HB_NO_AAT
case 1: return u.aat.has_state_machine (); case 1: return u.aat.has_state_machine ();
#endif
default:return false; default:return false;
} }
} }
@ -287,7 +293,9 @@ struct kern
{ {
switch (get_type ()) { switch (get_type ()) {
case 0: return u.ot.has_cross_stream (); case 0: return u.ot.has_cross_stream ();
#ifndef HB_NO_AAT
case 1: return u.aat.has_cross_stream (); case 1: return u.aat.has_cross_stream ();
#endif
default:return false; default:return false;
} }
} }
@ -296,7 +304,9 @@ struct kern
{ {
switch (get_type ()) { switch (get_type ()) {
case 0: return u.ot.get_h_kerning (left, right); case 0: return u.ot.get_h_kerning (left, right);
#ifndef HB_NO_AAT
case 1: return u.aat.get_h_kerning (left, right); case 1: return u.aat.get_h_kerning (left, right);
#endif
default:return 0; default:return 0;
} }
} }
@ -311,7 +321,9 @@ struct kern
TRACE_DISPATCH (this, subtable_type); TRACE_DISPATCH (this, subtable_type);
switch (subtable_type) { switch (subtable_type) {
case 0: return_trace (c->dispatch (u.ot, hb_forward<Ts> (ds)...)); case 0: return_trace (c->dispatch (u.ot, hb_forward<Ts> (ds)...));
#ifndef HB_NO_AAT
case 1: return_trace (c->dispatch (u.aat, hb_forward<Ts> (ds)...)); case 1: return_trace (c->dispatch (u.aat, hb_forward<Ts> (ds)...));
#endif
default: return_trace (c->default_return_value ()); default: return_trace (c->default_return_value ());
} }
} }
@ -328,7 +340,9 @@ struct kern
HBUINT32 version32; HBUINT32 version32;
HBUINT16 major; HBUINT16 major;
KernOT ot; KernOT ot;
#ifndef HB_NO_AAT
KernAAT aat; KernAAT aat;
#endif
} u; } u;
public: public:
DEFINE_SIZE_UNION (4, version32); DEFINE_SIZE_UNION (4, version32);

View File

@ -58,6 +58,10 @@ hb_ot_shape_collect_features (hb_ot_shape_planner_t *planner,
static bool static bool
_hb_apply_morx (hb_face_t *face) _hb_apply_morx (hb_face_t *face)
{ {
#ifdef HB_NO_AAT
return false;
#endif
if (hb_options ().aat && if (hb_options ().aat &&
hb_aat_layout_has_substitution (face)) hb_aat_layout_has_substitution (face))
return true; return true;
@ -83,8 +87,10 @@ hb_ot_shape_planner_t::hb_ot_shape_planner_t (hb_face_t *fac
script_zero_marks = shaper->zero_width_marks != HB_OT_SHAPE_ZERO_WIDTH_MARKS_NONE; script_zero_marks = shaper->zero_width_marks != HB_OT_SHAPE_ZERO_WIDTH_MARKS_NONE;
script_fallback_mark_positioning = shaper->fallback_position; script_fallback_mark_positioning = shaper->fallback_position;
#ifndef HB_NO_AAT
if (apply_morx) if (apply_morx)
shaper = &_hb_ot_complex_shaper_default; shaper = &_hb_ot_complex_shaper_default;
#endif
} }
void void
@ -94,8 +100,10 @@ hb_ot_shape_planner_t::compile (hb_ot_shape_plan_t &plan,
plan.props = props; plan.props = props;
plan.shaper = shaper; plan.shaper = shaper;
map.compile (plan.map, key); map.compile (plan.map, key);
#ifndef HB_NO_AAT
if (apply_morx) if (apply_morx)
aat_map.compile (plan.aat_map); aat_map.compile (plan.aat_map);
#endif
plan.frac_mask = plan.map.get_1_mask (HB_TAG ('f','r','a','c')); 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')); plan.numr_mask = plan.map.get_1_mask (HB_TAG ('n','u','m','r'));
@ -130,12 +138,18 @@ hb_ot_shape_planner_t::compile (hb_ot_shape_plan_t &plan,
* Decide who does positioning. GPOS, kerx, kern, or fallback. * Decide who does positioning. GPOS, kerx, kern, or fallback.
*/ */
if (hb_options ().aat && hb_aat_layout_has_positioning (face)) if (0)
;
#ifndef HB_NO_AAT
else if (hb_options ().aat && hb_aat_layout_has_positioning (face))
plan.apply_kerx = true; plan.apply_kerx = true;
#endif
else if (!apply_morx && !disable_gpos && hb_ot_layout_has_positioning (face)) else if (!apply_morx && !disable_gpos && hb_ot_layout_has_positioning (face))
plan.apply_gpos = true; plan.apply_gpos = true;
#ifndef HB_NO_AAT
else if (hb_aat_layout_has_positioning (face)) else if (hb_aat_layout_has_positioning (face))
plan.apply_kerx = true; plan.apply_kerx = true;
#endif
if (!plan.apply_kerx && !has_gpos_kern) if (!plan.apply_kerx && !has_gpos_kern)
{ {
@ -202,9 +216,11 @@ void
hb_ot_shape_plan_t::substitute (hb_font_t *font, hb_ot_shape_plan_t::substitute (hb_font_t *font,
hb_buffer_t *buffer) const hb_buffer_t *buffer) const
{ {
#ifndef HB_NO_AAT
if (unlikely (apply_morx)) if (unlikely (apply_morx))
hb_aat_layout_substitute (this, font, buffer); hb_aat_layout_substitute (this, font, buffer);
else else
#endif
map.substitute (this, font, buffer); map.substitute (this, font, buffer);
} }
@ -214,15 +230,19 @@ hb_ot_shape_plan_t::position (hb_font_t *font,
{ {
if (this->apply_gpos) if (this->apply_gpos)
map.position (this, font, buffer); map.position (this, font, buffer);
#ifndef HB_NO_AAT
else if (this->apply_kerx) else if (this->apply_kerx)
hb_aat_layout_position (this, font, buffer); hb_aat_layout_position (this, font, buffer);
#endif
else if (this->apply_kern) else if (this->apply_kern)
hb_ot_layout_kern (this, font, buffer); hb_ot_layout_kern (this, font, buffer);
else else
_hb_ot_shape_fallback_kern (this, font, buffer); _hb_ot_shape_fallback_kern (this, font, buffer);
#ifndef HB_NO_AAT
if (this->apply_trak) if (this->apply_trak)
hb_aat_layout_track (this, font, buffer); hb_aat_layout_track (this, font, buffer);
#endif
} }
@ -318,6 +338,7 @@ hb_ot_shape_collect_features (hb_ot_shape_planner_t *planner,
feature->value); feature->value);
} }
#ifndef HB_NO_AAT
if (planner->apply_morx) if (planner->apply_morx)
{ {
hb_aat_map_builder_t *aat_map = &planner->aat_map; hb_aat_map_builder_t *aat_map = &planner->aat_map;
@ -327,6 +348,7 @@ hb_ot_shape_collect_features (hb_ot_shape_planner_t *planner,
aat_map->add_feature (feature->tag, feature->value); aat_map->add_feature (feature->tag, feature->value);
} }
} }
#endif
if (planner->shaper->override_features) if (planner->shaper->override_features)
planner->shaper->override_features (planner); planner->shaper->override_features (planner);
@ -761,8 +783,10 @@ static inline void
hb_ot_substitute_post (const hb_ot_shape_context_t *c) hb_ot_substitute_post (const hb_ot_shape_context_t *c)
{ {
hb_ot_hide_default_ignorables (c->buffer, c->font); hb_ot_hide_default_ignorables (c->buffer, c->font);
#ifndef HB_NO_AAT
if (c->plan->apply_morx) if (c->plan->apply_morx)
hb_aat_layout_remove_deleted_glyphs (c->buffer); hb_aat_layout_remove_deleted_glyphs (c->buffer);
#endif
if (c->plan->shaper->postprocess_glyphs) if (c->plan->shaper->postprocess_glyphs)
c->plan->shaper->postprocess_glyphs (c->plan, c->buffer, c->font); c->plan->shaper->postprocess_glyphs (c->plan, c->buffer, c->font);
@ -896,8 +920,10 @@ hb_ot_position_complex (const hb_ot_shape_context_t *c)
/* Finish off. Has to follow a certain order. */ /* Finish off. Has to follow a certain order. */
hb_ot_layout_position_finish_advances (c->font, c->buffer); hb_ot_layout_position_finish_advances (c->font, c->buffer);
hb_ot_zero_width_default_ignorables (c->buffer); hb_ot_zero_width_default_ignorables (c->buffer);
#ifndef HB_NO_AAT
if (c->plan->apply_morx) if (c->plan->apply_morx)
hb_aat_layout_zero_width_deleted_glyphs (c->buffer); hb_aat_layout_zero_width_deleted_glyphs (c->buffer);
#endif
hb_ot_layout_position_finish_offsets (c->font, c->buffer); hb_ot_layout_position_finish_offsets (c->font, c->buffer);
/* The nil glyph_h_origin() func returns 0, so no need to apply it. */ /* The nil glyph_h_origin() func returns 0, so no need to apply it. */