From ca7b77431d1e0aaa803722be8be85a368a385f47 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Tue, 13 May 2014 21:26:34 -0400 Subject: [PATCH] [ot] Factor out code between cmap sutable format 12 and 13 --- src/hb-ot-cmap-table.hh | 43 +++++++++++++---------------------------- 1 file changed, 13 insertions(+), 30 deletions(-) diff --git a/src/hb-ot-cmap-table.hh b/src/hb-ot-cmap-table.hh index 73f649818..014111604 100644 --- a/src/hb-ot-cmap-table.hh +++ b/src/hb-ot-cmap-table.hh @@ -196,7 +196,8 @@ struct CmapSubtableTrimmed struct CmapSubtableFormat6 : CmapSubtableTrimmed {}; struct CmapSubtableFormat10 : CmapSubtableTrimmed {}; -struct CmapSubtableFormat12 +template +struct CmapSubtableLongSegmented { friend struct CmapSubtable; @@ -206,8 +207,7 @@ struct CmapSubtableFormat12 int i = groups.search (codepoint); if (i == -1) return false; - const CmapSubtableLongGroup &group = groups[i]; - *glyph = group.glyphID + (codepoint - group.startCharCode); + *glyph = T::group_get_glyph (groups[i], codepoint); return true; } @@ -227,35 +227,18 @@ struct CmapSubtableFormat12 DEFINE_SIZE_ARRAY (16, groups); }; -struct CmapSubtableFormat13 +struct CmapSubtableFormat12 : CmapSubtableLongSegmented { - friend struct CmapSubtable; + static inline hb_codepoint_t group_get_glyph (const CmapSubtableLongGroup &group, + hb_codepoint_t u) + { return group.glyphID + (u - group.startCharCode); } +}; - private: - inline bool get_glyph (hb_codepoint_t codepoint, hb_codepoint_t *glyph) const - { - int i = groups.search (codepoint); - if (i == -1) - return false; - const CmapSubtableLongGroup &group = groups[i]; - *glyph = group.glyphID; - return true; - } - - inline bool sanitize (hb_sanitize_context_t *c) { - TRACE_SANITIZE (this); - return TRACE_RETURN (c->check_struct (this) && groups.sanitize (c)); - } - - protected: - USHORT format; /* Subtable format; set to 13. */ - USHORT reserved; /* Reserved; set to 0. */ - ULONG length; /* Byte length of this subtable. */ - ULONG language; /* Ignore. */ - LongArrayOf - groups; /* Groupings. */ - public: - DEFINE_SIZE_ARRAY (16, groups); +struct CmapSubtableFormat13 : CmapSubtableLongSegmented +{ + static inline hb_codepoint_t group_get_glyph (const CmapSubtableLongGroup &group, + hb_codepoint_t u HB_UNUSED) + { return group.glyphID; } }; struct CmapSubtable