From a6fbd0752ada8f1ae64b77b09b84202c969a3b9b Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Fri, 28 Aug 2009 17:14:33 -0400 Subject: [PATCH] [HB] Add GSUB/GPOS tracing --- pango/opentype/hb-ot-layout-gpos-private.hh | 29 +++++++++++++-- pango/opentype/hb-ot-layout-gsub-private.hh | 28 ++++++++++++-- pango/opentype/hb-ot-layout-gsubgpos-private.hh | 49 ++++++++++++++++++++++++- 3 files changed, 98 insertions(+), 8 deletions(-) diff --git a/pango/opentype/hb-ot-layout-gpos-private.hh b/pango/opentype/hb-ot-layout-gpos-private.hh index b152308..07f5c8e 100644 --- a/pango/opentype/hb-ot-layout-gpos-private.hh +++ b/pango/opentype/hb-ot-layout-gpos-private.hh @@ -317,6 +317,7 @@ struct MarkArray const AnchorMatrix &anchors, unsigned int class_count, unsigned int glyph_pos) const { + APPLY_DEBUG (); const MarkRecord &record = markRecord[mark_index]; unsigned int mark_class = record.klass; @@ -360,6 +361,7 @@ struct SinglePosFormat1 private: inline bool apply (APPLY_ARG_DEF) const { + APPLY_DEBUG (); unsigned int index = (this+coverage) (IN_CURGLYPH ()); if (HB_LIKELY (index == NOT_COVERED)) return false; @@ -396,6 +398,7 @@ struct SinglePosFormat2 private: inline bool apply (APPLY_ARG_DEF) const { + APPLY_DEBUG (); unsigned int index = (this+coverage) (IN_CURGLYPH ()); if (HB_LIKELY (index == NOT_COVERED)) return false; @@ -437,6 +440,7 @@ struct SinglePos private: inline bool apply (APPLY_ARG_DEF) const { + APPLY_DEBUG (); switch (u.format) { case 1: return u.format1->apply (APPLY_ARG); case 2: return u.format2->apply (APPLY_ARG); @@ -503,6 +507,7 @@ struct PairPosFormat1 private: inline bool apply (APPLY_ARG_DEF) const { + APPLY_DEBUG (); unsigned int end = MIN (buffer->in_length, buffer->in_pos + context_length); if (HB_UNLIKELY (buffer->in_pos + 2 > end)) return false; @@ -575,6 +580,7 @@ struct PairPosFormat2 private: inline bool apply (APPLY_ARG_DEF) const { + APPLY_DEBUG (); unsigned int end = MIN (buffer->in_length, buffer->in_pos + context_length); if (HB_UNLIKELY (buffer->in_pos + 2 > end)) return false; @@ -657,6 +663,7 @@ struct PairPos private: inline bool apply (APPLY_ARG_DEF) const { + APPLY_DEBUG (); switch (u.format) { case 1: return u.format1->apply (APPLY_ARG); case 2: return u.format2->apply (APPLY_ARG); @@ -709,6 +716,7 @@ struct CursivePosFormat1 private: inline bool apply (APPLY_ARG_DEF) const { + APPLY_DEBUG (); /* Now comes the messiest part of the whole OpenType specification. At first glance, cursive connections seem easy to understand, but there are pitfalls! The reason is that @@ -904,6 +912,7 @@ struct CursivePos private: inline bool apply (APPLY_ARG_DEF) const { + APPLY_DEBUG (); switch (u.format) { case 1: return u.format1->apply (APPLY_ARG); default:return false; @@ -941,6 +950,7 @@ struct MarkBasePosFormat1 private: inline bool apply (APPLY_ARG_DEF) const { + APPLY_DEBUG (); unsigned int mark_index = (this+markCoverage) (IN_CURGLYPH ()); if (HB_LIKELY (mark_index == NOT_COVERED)) return false; @@ -998,6 +1008,7 @@ struct MarkBasePos private: inline bool apply (APPLY_ARG_DEF) const { + APPLY_DEBUG (); switch (u.format) { case 1: return u.format1->apply (APPLY_ARG); default:return false; @@ -1041,6 +1052,7 @@ struct MarkLigPosFormat1 private: inline bool apply (APPLY_ARG_DEF) const { + APPLY_DEBUG (); unsigned int mark_index = (this+markCoverage) (IN_CURGLYPH ()); if (HB_LIKELY (mark_index == NOT_COVERED)) return false; @@ -1121,6 +1133,7 @@ struct MarkLigPos private: inline bool apply (APPLY_ARG_DEF) const { + APPLY_DEBUG (); switch (u.format) { case 1: return u.format1->apply (APPLY_ARG); default:return false; @@ -1158,6 +1171,7 @@ struct MarkMarkPosFormat1 private: inline bool apply (APPLY_ARG_DEF) const { + APPLY_DEBUG (); unsigned int mark1_index = (this+mark1Coverage) (IN_CURGLYPH ()); if (HB_LIKELY (mark1_index == NOT_COVERED)) return false; @@ -1220,6 +1234,7 @@ struct MarkMarkPos private: inline bool apply (APPLY_ARG_DEF) const { + APPLY_DEBUG (); switch (u.format) { case 1: return u.format1->apply (APPLY_ARG); default:return false; @@ -1252,7 +1267,10 @@ struct ContextPos : Context private: inline bool apply (APPLY_ARG_DEF) const - { return Context::apply (APPLY_ARG, position_lookup); } + { + APPLY_DEBUG (); + return Context::apply (APPLY_ARG, position_lookup); + } }; ASSERT_SIZE (ContextPos, 2); @@ -1262,7 +1280,10 @@ struct ChainContextPos : ChainContext private: inline bool apply (APPLY_ARG_DEF) const - { return ChainContext::apply (APPLY_ARG, position_lookup); } + { + APPLY_DEBUG (); + return ChainContext::apply (APPLY_ARG, position_lookup); + } }; ASSERT_SIZE (ChainContextPos, 2); @@ -1306,6 +1327,7 @@ struct PosLookupSubTable inline bool apply (APPLY_ARG_DEF, unsigned int lookup_type) const { + APPLY_DEBUG (); switch (lookup_type) { case Single: return u.single->apply (APPLY_ARG); case Pair: return u.pair->apply (APPLY_ARG); @@ -1392,7 +1414,7 @@ struct PosLookup : Lookup return false; for (unsigned int i = 0; i < get_subtable_count (); i++) - if (get_subtable (i).apply (APPLY_ARG, lookup_type)) + if (get_subtable (i).apply (APPLY_ARG_INIT, lookup_type)) return true; return false; @@ -1479,6 +1501,7 @@ ASSERT_SIZE (GPOS, 10); inline bool ExtensionPos::apply (APPLY_ARG_DEF) const { + APPLY_DEBUG (); unsigned int lookup_type = get_type (); if (HB_UNLIKELY (lookup_type == PosLookupSubTable::Extension)) diff --git a/pango/opentype/hb-ot-layout-gsub-private.hh b/pango/opentype/hb-ot-layout-gsub-private.hh index 4c682fe..992f453 100644 --- a/pango/opentype/hb-ot-layout-gsub-private.hh +++ b/pango/opentype/hb-ot-layout-gsub-private.hh @@ -38,6 +38,7 @@ struct SingleSubstFormat1 inline bool apply (APPLY_ARG_DEF) const { + APPLY_DEBUG (); hb_codepoint_t glyph_id = IN_CURGLYPH (); unsigned int index = (this+coverage) (glyph_id); if (HB_LIKELY (index == NOT_COVERED)) @@ -76,6 +77,7 @@ struct SingleSubstFormat2 inline bool apply (APPLY_ARG_DEF) const { + APPLY_DEBUG (); hb_codepoint_t glyph_id = IN_CURGLYPH (); unsigned int index = (this+coverage) (glyph_id); if (HB_LIKELY (index == NOT_COVERED)) @@ -118,6 +120,7 @@ struct SingleSubst inline bool apply (APPLY_ARG_DEF) const { + APPLY_DEBUG (); switch (u.format) { case 1: return u.format1->apply (APPLY_ARG); case 2: return u.format2->apply (APPLY_ARG); @@ -152,6 +155,7 @@ struct Sequence private: inline bool apply (APPLY_ARG_DEF) const { + APPLY_DEBUG (); if (HB_UNLIKELY (!substitute.len)) return false; @@ -193,6 +197,7 @@ struct MultipleSubstFormat1 inline bool apply (APPLY_ARG_DEF) const { + APPLY_DEBUG (); unsigned int index = (this+coverage) (IN_CURGLYPH ()); if (HB_LIKELY (index == NOT_COVERED)) @@ -225,6 +230,7 @@ struct MultipleSubst inline bool apply (APPLY_ARG_DEF) const { + APPLY_DEBUG (); switch (u.format) { case 1: return u.format1->apply (APPLY_ARG); default:return false; @@ -261,6 +267,7 @@ struct AlternateSubstFormat1 inline bool apply (APPLY_ARG_DEF) const { + APPLY_DEBUG (); hb_codepoint_t glyph_id = IN_CURGLYPH (); unsigned int index = (this+coverage) (glyph_id); @@ -319,6 +326,7 @@ struct AlternateSubst inline bool apply (APPLY_ARG_DEF) const { + APPLY_DEBUG (); switch (u.format) { case 1: return u.format1->apply (APPLY_ARG); default:return false; @@ -350,6 +358,7 @@ struct Ligature private: inline bool apply (APPLY_ARG_DEF, bool is_mark) const { + APPLY_DEBUG (); unsigned int i, j; unsigned int count = component.len; unsigned int end = MIN (buffer->in_length, buffer->in_pos + context_length); @@ -435,6 +444,7 @@ struct LigatureSet private: inline bool apply (APPLY_ARG_DEF, bool is_mark) const { + APPLY_DEBUG (); unsigned int num_ligs = ligature.len; for (unsigned int i = 0; i < num_ligs; i++) { @@ -466,6 +476,7 @@ struct LigatureSubstFormat1 private: inline bool apply (APPLY_ARG_DEF) const { + APPLY_DEBUG (); hb_codepoint_t glyph_id = IN_CURGLYPH (); bool first_is_mark = !!(property & HB_OT_LAYOUT_GLYPH_CLASS_MARK); @@ -501,6 +512,7 @@ struct LigatureSubst private: inline bool apply (APPLY_ARG_DEF) const { + APPLY_DEBUG (); switch (u.format) { case 1: return u.format1->apply (APPLY_ARG); default:return false; @@ -534,7 +546,10 @@ struct ContextSubst : Context private: inline bool apply (APPLY_ARG_DEF) const - { return Context::apply (APPLY_ARG, substitute_lookup); } + { + APPLY_DEBUG (); + return Context::apply (APPLY_ARG, substitute_lookup); + } }; ASSERT_SIZE (ContextSubst, 2); @@ -544,7 +559,10 @@ struct ChainContextSubst : ChainContext private: inline bool apply (APPLY_ARG_DEF) const - { return ChainContext::apply (APPLY_ARG, substitute_lookup); } + { + APPLY_DEBUG (); + return ChainContext::apply (APPLY_ARG, substitute_lookup); + } }; ASSERT_SIZE (ChainContextSubst, 2); @@ -571,6 +589,7 @@ struct ReverseChainSingleSubstFormat1 private: inline bool apply (APPLY_ARG_DEF) const { + APPLY_DEBUG (); if (HB_UNLIKELY (context_length != NO_CONTEXT)) return false; /* No chaining to this type */ @@ -634,6 +653,7 @@ struct ReverseChainSingleSubst private: inline bool apply (APPLY_ARG_DEF) const { + APPLY_DEBUG (); switch (u.format) { case 1: return u.format1->apply (APPLY_ARG); default:return false; @@ -680,6 +700,7 @@ struct SubstLookupSubTable inline bool apply (APPLY_ARG_DEF, unsigned int lookup_type) const { + APPLY_DEBUG (); switch (lookup_type) { case Single: return u.single->apply (APPLY_ARG); case Multiple: return u.multiple->apply (APPLY_ARG); @@ -767,7 +788,7 @@ struct SubstLookup : Lookup unsigned int count = get_subtable_count (); for (unsigned int i = 0; i < count; i++) - if (get_subtable (i).apply (APPLY_ARG, lookup_type)) + if (get_subtable (i).apply (APPLY_ARG_INIT, lookup_type)) return true; return false; @@ -865,6 +886,7 @@ ASSERT_SIZE (GSUB, 10); inline bool ExtensionSubst::apply (APPLY_ARG_DEF) const { + APPLY_DEBUG (); unsigned int lookup_type = get_type (); if (HB_UNLIKELY (lookup_type == SubstLookupSubTable::Extension)) diff --git a/pango/opentype/hb-ot-layout-gsubgpos-private.hh b/pango/opentype/hb-ot-layout-gsubgpos-private.hh index 559ee08..0dadbe8 100644 --- a/pango/opentype/hb-ot-layout-gsubgpos-private.hh +++ b/pango/opentype/hb-ot-layout-gsubgpos-private.hh @@ -31,20 +31,53 @@ #include "hb-ot-layout-gdef-private.hh" +#ifndef HB_DEBUG_APPLY +#define HB_DEBUG_APPLY HB_DEBUG +#endif + +#if HB_DEBUG_APPLY +#define APPLY_DEBUG_ARG_DEF , unsigned int apply_depth +#define APPLY_DEBUG_ARG , apply_depth + 1 +#define APPLY_DEBUG_ARG_INIT , 1 +#define APPLY_DEBUG() \ + HB_STMT_START { \ + if (apply_depth < HB_DEBUG_APPLY) \ + fprintf (stderr, "APPLY(%p) %-*d-> %s\n", \ + (CONST_CHARP (this) == NullPool) ? 0 : this, \ + apply_depth, apply_depth, \ + __PRETTY_FUNCTION__); \ + } HB_STMT_END +#else +#define APPLY_DEBUG_ARG_DEF +#define APPLY_DEBUG_ARG +#define APPLY_DEBUG_ARG_INIT +#define APPLY_DEBUG() HB_STMT_START {} HB_STMT_END +#endif + #define APPLY_ARG_DEF \ hb_ot_layout_context_t *context, \ hb_buffer_t *buffer, \ unsigned int context_length HB_GNUC_UNUSED, \ unsigned int nesting_level_left HB_GNUC_UNUSED, \ unsigned int lookup_flag, \ - unsigned int property HB_GNUC_UNUSED /* propety of first glyph */ + unsigned int property HB_GNUC_UNUSED /* propety of first glyph */ \ + APPLY_DEBUG_ARG_DEF #define APPLY_ARG \ context, \ buffer, \ context_length, \ nesting_level_left, \ lookup_flag, \ - property + property \ + APPLY_DEBUG_ARG +#define APPLY_ARG_INIT \ + context, \ + buffer, \ + context_length, \ + nesting_level_left, \ + lookup_flag, \ + property \ + APPLY_DEBUG_ARG_INIT typedef bool (*match_func_t) (hb_codepoint_t glyph_id, const USHORT &value, char *data); @@ -257,6 +290,7 @@ struct Rule private: inline bool apply (APPLY_ARG_DEF, ContextLookupContext &lookup_context) const { + APPLY_DEBUG (); const LookupRecord *lookupRecord = &CONST_CAST (LookupRecord, input, sizeof (input[0]) * (inputCount ? inputCount - 1 : 0)); return context_lookup (APPLY_ARG, inputCount, input, @@ -289,6 +323,7 @@ struct RuleSet { inline bool apply (APPLY_ARG_DEF, ContextLookupContext &lookup_context) const { + APPLY_DEBUG (); unsigned int num_rules = rule.len; for (unsigned int i = 0; i < num_rules; i++) { @@ -318,6 +353,7 @@ struct ContextFormat1 private: inline bool apply (APPLY_ARG_DEF, apply_lookup_func_t apply_func) const { + APPLY_DEBUG (); unsigned int index = (this+coverage) (IN_CURGLYPH ()); if (HB_LIKELY (index == NOT_COVERED)) return false; @@ -354,6 +390,7 @@ struct ContextFormat2 private: inline bool apply (APPLY_ARG_DEF, apply_lookup_func_t apply_func) const { + APPLY_DEBUG (); unsigned int index = (this+coverage) (IN_CURGLYPH ()); if (HB_LIKELY (index == NOT_COVERED)) return false; @@ -398,6 +435,7 @@ struct ContextFormat3 private: inline bool apply (APPLY_ARG_DEF, apply_lookup_func_t apply_func) const { + APPLY_DEBUG (); unsigned int index = (this+coverage[0]) (IN_CURGLYPH ()); if (HB_LIKELY (index == NOT_COVERED)) return false; @@ -441,6 +479,7 @@ struct Context protected: inline bool apply (APPLY_ARG_DEF, apply_lookup_func_t apply_func) const { + APPLY_DEBUG (); switch (u.format) { case 1: return u.format1->apply (APPLY_ARG, apply_func); case 2: return u.format2->apply (APPLY_ARG, apply_func); @@ -522,6 +561,7 @@ struct ChainRule private: inline bool apply (APPLY_ARG_DEF, ChainContextLookupContext &lookup_context) const { + APPLY_DEBUG (); const HeadlessArrayOf &input = CONST_NEXT (HeadlessArrayOf, backtrack); const ArrayOf &lookahead = CONST_NEXT (ArrayOf, input); const ArrayOf &lookup = CONST_NEXT (ArrayOf, lookahead); @@ -567,6 +607,7 @@ struct ChainRuleSet { inline bool apply (APPLY_ARG_DEF, ChainContextLookupContext &lookup_context) const { + APPLY_DEBUG (); unsigned int num_rules = rule.len; for (unsigned int i = 0; i < num_rules; i++) { @@ -596,6 +637,7 @@ struct ChainContextFormat1 private: inline bool apply (APPLY_ARG_DEF, apply_lookup_func_t apply_func) const { + APPLY_DEBUG (); unsigned int index = (this+coverage) (IN_CURGLYPH ()); if (HB_LIKELY (index == NOT_COVERED)) return false; @@ -631,6 +673,7 @@ struct ChainContextFormat2 private: inline bool apply (APPLY_ARG_DEF, apply_lookup_func_t apply_func) const { + APPLY_DEBUG (); unsigned int index = (this+coverage) (IN_CURGLYPH ()); if (HB_LIKELY (index == NOT_COVERED)) return false; @@ -691,6 +734,7 @@ struct ChainContextFormat3 inline bool apply (APPLY_ARG_DEF, apply_lookup_func_t apply_func) const { + APPLY_DEBUG (); const OffsetArrayOf &input = CONST_NEXT (OffsetArrayOf, backtrack); unsigned int index = (this+input[0]) (IN_CURGLYPH ()); @@ -748,6 +792,7 @@ struct ChainContext protected: inline bool apply (APPLY_ARG_DEF, apply_lookup_func_t apply_func) const { + APPLY_DEBUG (); switch (u.format) { case 1: return u.format1->apply (APPLY_ARG, apply_func); case 2: return u.format2->apply (APPLY_ARG, apply_func); -- 2.7.4