From 94759e8219ed08392573bae948a8135e16b8e0d0 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Tue, 13 May 2014 21:17:28 -0400 Subject: [PATCH] [ot] Factor out code between cmap subtable format 6 and 10 --- src/hb-ot-cmap-table.hh | 49 +++++++++-------------------------------- 1 file changed, 10 insertions(+), 39 deletions(-) diff --git a/src/hb-ot-cmap-table.hh b/src/hb-ot-cmap-table.hh index 7c7ac3c34..73f649818 100644 --- a/src/hb-ot-cmap-table.hh +++ b/src/hb-ot-cmap-table.hh @@ -160,7 +160,8 @@ struct CmapSubtableLongGroup DEFINE_SIZE_STATIC (12); }; -struct CmapSubtableFormat6 +template +struct CmapSubtableTrimmed { friend struct CmapSubtable; @@ -181,49 +182,19 @@ struct CmapSubtableFormat6 } protected: - USHORT format; /* Subtable format; set to 6. */ - USHORT length; /* Byte length of this subtable. */ - USHORT language; /* Ignore. */ - USHORT startCharCode; /* First character code covered. */ - ArrayOf + UINT formatReserved; /* Subtable format and (maybe) padding. */ + UINT length; /* Byte length of this subtable. */ + UINT language; /* Ignore. */ + UINT startCharCode; /* First character code covered. */ + GenericArrayOf glyphIdArray; /* Array of glyph index values for character * codes in the range. */ public: - DEFINE_SIZE_ARRAY (10, glyphIdArray); + DEFINE_SIZE_ARRAY (5 * sizeof (UINT), glyphIdArray); }; -struct CmapSubtableFormat10 -{ - friend struct CmapSubtable; - - private: - inline bool get_glyph (hb_codepoint_t codepoint, hb_codepoint_t *glyph) const - { - /* Rely on our implicit array bound-checking. */ - hb_codepoint_t gid = glyphIdArray[codepoint - startCharCode]; - if (!gid) - return false; - *glyph = gid; - return true; - } - - inline bool sanitize (hb_sanitize_context_t *c) { - TRACE_SANITIZE (this); - return TRACE_RETURN (c->check_struct (this) && glyphIdArray.sanitize (c)); - } - - protected: - USHORT format; /* Subtable format; set to 10. */ - USHORT reserved; /* Reserved; set to 0. */ - ULONG length; /* Byte length of this subtable. */ - ULONG language; /* Ignore. */ - ULONG startCharCode; /* First character code covered. */ - LongArrayOf - glyphIdArray; /* Array of glyph index values for character - * codes in the range. */ - public: - DEFINE_SIZE_ARRAY (20, glyphIdArray); -}; +struct CmapSubtableFormat6 : CmapSubtableTrimmed {}; +struct CmapSubtableFormat10 : CmapSubtableTrimmed {}; struct CmapSubtableFormat12 {