From b7878cd58ea9a67236e1e0228c35b5b03ec4ff9c Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Tue, 13 May 2014 21:47:51 -0400 Subject: [PATCH] [ot] Implement cmap subtable format 0 --- src/hb-open-type-private.hh | 3 ++- src/hb-ot-cmap-table.hh | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 34 insertions(+), 1 deletion(-) diff --git a/src/hb-open-type-private.hh b/src/hb-open-type-private.hh index d9be744c..965d4d7a 100644 --- a/src/hb-open-type-private.hh +++ b/src/hb-open-type-private.hh @@ -132,7 +132,7 @@ static inline Type& StructAfter(TObject &X) /* Global nul-content Null pool. Enlarge as necessary. */ /* TODO This really should be a extern HB_INTERNAL and defined somewhere... */ -static const void *_NullPool[64 / sizeof (void *)]; +static const void *_NullPool[(256+8) / sizeof (void *)]; /* Generic nul-content Null objects. */ template @@ -572,6 +572,7 @@ struct IntType DEFINE_SIZE_STATIC (Size); }; +typedef uint8_t BYTE; /* 8-bit unsigned integer. */ typedef IntType USHORT; /* 16-bit unsigned integer. */ typedef IntType SHORT; /* 16-bit signed integer. */ typedef IntType ULONG; /* 32-bit unsigned integer. */ diff --git a/src/hb-ot-cmap-table.hh b/src/hb-ot-cmap-table.hh index 01411160..73734a61 100644 --- a/src/hb-ot-cmap-table.hh +++ b/src/hb-ot-cmap-table.hh @@ -40,6 +40,35 @@ namespace OT { #define HB_OT_TAG_cmap HB_TAG('c','m','a','p') +struct CmapSubtableFormat0 +{ + friend struct CmapSubtable; + + private: + inline bool get_glyph (hb_codepoint_t codepoint, hb_codepoint_t *glyph) const + { + hb_codepoint_t gid = codepoint < 256 ? glyphIdArray[codepoint] : 0; + 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)); + } + + protected: + USHORT format; /* Format number is set to 0. */ + USHORT length; /* Byte length of this subtable. */ + USHORT language; /* Ignore. */ + BYTE glyphIdArray[256];/* An array that maps character + * code to glyph index values. */ + public: + DEFINE_SIZE_STATIC (6 + 256); +}; + struct CmapSubtableFormat4 { friend struct CmapSubtable; @@ -246,6 +275,7 @@ struct CmapSubtable inline bool get_glyph (hb_codepoint_t codepoint, hb_codepoint_t *glyph) const { switch (u.format) { + case 0: return u.format0 .get_glyph(codepoint, glyph); case 4: return u.format4 .get_glyph(codepoint, glyph); case 6: return u.format6 .get_glyph(codepoint, glyph); case 10: return u.format10.get_glyph(codepoint, glyph); @@ -259,6 +289,7 @@ struct CmapSubtable TRACE_SANITIZE (this); if (!u.format.sanitize (c)) return TRACE_RETURN (false); switch (u.format) { + case 0: return TRACE_RETURN (u.format0 .sanitize (c)); case 4: return TRACE_RETURN (u.format4 .sanitize (c)); case 6: return TRACE_RETURN (u.format6 .sanitize (c)); case 10: return TRACE_RETURN (u.format10.sanitize (c)); @@ -271,6 +302,7 @@ struct CmapSubtable protected: union { USHORT format; /* Format identifier */ + CmapSubtableFormat0 format0; CmapSubtableFormat4 format4; CmapSubtableFormat6 format6; CmapSubtableFormat10 format10; -- GitLab