From 4806b3800d77603c203e8bb2e88baeb2b3a14f05 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Sat, 25 Aug 2018 15:56:07 -0700 Subject: [PATCH] [cmap] Add hb_subset_collect_variation_selectors() To be moved to hb-face later. --- src/hb-ot-cmap-table.hh | 20 ++++++++++++++++---- src/hb-subset.cc | 30 ++++++++++++++++++++++++++---- src/hb-subset.h | 8 +++++++- 3 files changed, 49 insertions(+), 9 deletions(-) diff --git a/src/hb-ot-cmap-table.hh b/src/hb-ot-cmap-table.hh index bf9874a3e..2f115e2e4 100644 --- a/src/hb-ot-cmap-table.hh +++ b/src/hb-ot-cmap-table.hh @@ -594,7 +594,7 @@ struct UnicodeValueRange } HBUINT24 startUnicodeValue; /* First value in this range. */ - HBUINT8 additionalCount; /* Number of additional values in this + HBUINT8 additionalCount; /* Number of additional values in this * range. */ public: DEFINE_SIZE_STATIC (4); @@ -675,6 +675,13 @@ struct CmapSubtableFormat14 return record[record.bsearch(variation_selector)].get_glyph (codepoint, glyph, this); } + inline void collect_variation_selectors (hb_set_t *out) const + { + unsigned int count = record.len; + for (unsigned int i = 0; i < count; i++) + out->add (record.arrayZ[i].varSelector); + } + inline bool sanitize (hb_sanitize_context_t *c) const { TRACE_SANITIZE (this); @@ -977,7 +984,7 @@ struct cmap /* Meh. */ if (!subtable_uvs) subtable_uvs = &Null(CmapSubtableFormat14); - this->uvs_table = subtable_uvs; + this->subtable_uvs = subtable_uvs; this->get_glyph_data = subtable; if (unlikely (symbol)) @@ -1018,7 +1025,7 @@ struct cmap hb_codepoint_t variation_selector, hb_codepoint_t *glyph) const { - switch (this->uvs_table->get_glyph_variant (unicode, + switch (this->subtable_uvs->get_glyph_variant (unicode, variation_selector, glyph)) { @@ -1034,6 +1041,10 @@ struct cmap { subtable->collect_unicodes (out); } + inline void collect_variation_selectors (hb_set_t *out) const + { + subtable_uvs->collect_variation_selectors (out); + } protected: typedef bool (*hb_cmap_get_glyph_func_t) (const void *obj, @@ -1073,12 +1084,13 @@ struct cmap private: const CmapSubtable *subtable; + const CmapSubtableFormat14 *subtable_uvs; + hb_cmap_get_glyph_func_t get_glyph_func; const void *get_glyph_data; CmapSubtableFormat4::accelerator_t format4_accel; - const CmapSubtableFormat14 *uvs_table; hb_blob_t *blob; }; diff --git a/src/hb-subset.cc b/src/hb-subset.cc index 2e991de20..01d9b89a2 100644 --- a/src/hb-subset.cc +++ b/src/hb-subset.cc @@ -238,14 +238,36 @@ hb_subset (hb_face_t *source, /** * hb_subset_collect_unicodes: - * @source: font face data to load. - * @out: set to add the all codepoints covered by font face, source. + * @face: font face. + * @out: set to add Unicode characters covered by @face to. + * + * Since: REPLACEME */ void -hb_subset_collect_unicodes (hb_face_t *source, hb_set_t *out) +hb_subset_collect_unicodes (hb_face_t *face, hb_set_t *out) { + /* XXX Use saved accel. */ OT::cmap::accelerator_t cmap; - cmap.init (source); + cmap.init (face); cmap.collect_unicodes (out); cmap.fini(); } + +/** + * hb_subset_collect_variation_selectors: + * @face: font face. + * @out: set to add Variation Selector characters covered by @face to. + * + * + * + * Since: REPLACEME + */ +void +hb_subset_collect_variation_selectors (hb_face_t *face, hb_set_t *out) +{ + /* XXX Use saved accel. */ + OT::cmap::accelerator_t cmap; + cmap.init (face); + cmap.collect_variation_selectors (out); + cmap.fini(); +} diff --git a/src/hb-subset.h b/src/hb-subset.h index b79b80946..745bacf23 100644 --- a/src/hb-subset.h +++ b/src/hb-subset.h @@ -80,10 +80,16 @@ hb_subset (hb_face_t *source, hb_subset_profile_t *profile, hb_subset_input_t *input); -/* hb_subset_collect_unicodes */ + +/* TODO Move to hb-face.h. */ + HB_EXTERN void hb_subset_collect_unicodes (hb_face_t *source, hb_set_t *out); +HB_EXTERN void +hb_subset_collect_variation_selectors (hb_face_t *source, hb_set_t *out); + + HB_END_DECLS #endif /* HB_SUBSET_H */