From bd0e542525d41d9ebe51cbcab8151d65eb984b2e Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Sat, 25 Aug 2018 09:33:30 -0700 Subject: [PATCH] [cmap] Simplify collect_unicodes() Don't use accelerator (almost). Hooks up Format13 as well. --- src/hb-ot-cmap-table.hh | 52 +++++++++++++++++++++++------------------ 1 file changed, 29 insertions(+), 23 deletions(-) diff --git a/src/hb-ot-cmap-table.hh b/src/hb-ot-cmap-table.hh index 925101f77..2f88a767d 100644 --- a/src/hb-ot-cmap-table.hh +++ b/src/hb-ot-cmap-table.hh @@ -283,17 +283,6 @@ struct CmapSubtableFormat4 return *glyph != 0; } - static inline void collect_unicodes_func (const void *obj, hb_set_t *out) - { - const accelerator_t *thiz = (const accelerator_t *) obj; - for (unsigned int i = 0; i < thiz->segCount; i++) - { - if (thiz->startCount[i] != 0xFFFFu - || thiz->endCount[i] != 0xFFFFu) // Skip the last segment (0xFFFF) - hb_set_add_range (out, thiz->startCount[i], thiz->endCount[i]); - } - } - const HBUINT16 *endCount; const HBUINT16 *startCount; const HBUINT16 *idDelta; @@ -309,6 +298,18 @@ struct CmapSubtableFormat4 accel.init (this); return accel.get_glyph_func (&accel, codepoint, glyph); } + inline void collect_unicodes (hb_set_t *out) const + { + unsigned int segCount = this->segCountX2 / 2; + const HBUINT16 *endCount = this->values; + const HBUINT16 *startCount = endCount + segCount + 1; + + for (unsigned int i = 0; i < segCount; i++) + { + if (startCount[i] != 0xFFFFu || endCount[i] != 0xFFFFu) // Skip the last segment (0xFFFF) + hb_set_add_range (out, startCount[i], endCount[i]); + } + } inline bool sanitize (hb_sanitize_context_t *c) const { @@ -690,6 +691,19 @@ struct CmapSubtable default: return false; } } + inline void collect_unicodes (hb_set_t *out) const + { + switch (u.format) { +// case 0: u.format0 .collect_unicodes (out); return; + case 4: u.format4 .collect_unicodes (out); return; +// case 6: u.format6 .collect_unicodes (out); return; +// case 10: u.format10.collect_unicodes (out); return; + case 12: u.format12.collect_unicodes (out); return; + case 13: u.format13.collect_unicodes (out); return; + case 14: + default: return; + } + } inline bool sanitize (hb_sanitize_context_t *c) const { @@ -901,9 +915,10 @@ struct cmap { this->blob = hb_sanitize_context_t().reference_table (face); const cmap *table = this->blob->as (); - const CmapSubtable *subtable = nullptr; const CmapSubtableFormat14 *subtable_uvs = nullptr; + subtable = nullptr; + bool symbol = false; /* 32-bit subtables. */ if (!subtable) subtable = table->find_subtable (3, 10); @@ -939,24 +954,20 @@ struct cmap if (unlikely (symbol)) { this->get_glyph_func = get_glyph_from_symbol; - this->collect_unicodes_func = collect_unicodes_func_nil; } else { switch (subtable->u.format) { /* Accelerate format 4 and format 12. */ default: this->get_glyph_func = get_glyph_from; - this->collect_unicodes_func = collect_unicodes_func_nil; break; case 12: this->get_glyph_func = get_glyph_from; - this->collect_unicodes_func = collect_unicodes_from; break; case 4: { this->format4_accel.init (&subtable->u.format4); this->get_glyph_data = &this->format4_accel; this->get_glyph_func = this->format4_accel.get_glyph_func; - this->collect_unicodes_func = this->format4_accel.collect_unicodes_func; } break; } @@ -992,7 +1003,7 @@ struct cmap inline void collect_unicodes (hb_set_t *out) const { - this->collect_unicodes_func (get_glyph_data, out); + subtable->collect_unicodes (out); } protected: @@ -1002,11 +1013,6 @@ struct cmap typedef void (*hb_cmap_collect_unicodes_func_t) (const void *obj, hb_set_t *out); - static inline void collect_unicodes_func_nil (const void *obj, hb_set_t *out) - { - // NOOP - } - template static inline bool get_glyph_from (const void *obj, hb_codepoint_t codepoint, @@ -1047,9 +1053,9 @@ struct cmap } private: + const CmapSubtable *subtable; hb_cmap_get_glyph_func_t get_glyph_func; const void *get_glyph_data; - hb_cmap_collect_unicodes_func_t collect_unicodes_func; CmapSubtableFormat4::accelerator_t format4_accel;