From 1dcf5fb038e7c2d3d03a50c4cd9869a922f9adf7 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Sat, 25 Aug 2018 16:11:26 -0700 Subject: [PATCH] [cmap Add hb_subset_collect_variation_unicodes() To be moved to hb-face.h later. --- src/hb-ot-cmap-table.hh | 59 ++++++++++++++++++++++++++++++++++------- src/hb-subset.cc | 25 ++++++++++++++++- src/hb-subset.h | 10 +++++-- 3 files changed, 82 insertions(+), 12 deletions(-) diff --git a/src/hb-ot-cmap-table.hh b/src/hb-ot-cmap-table.hh index 2f115e2e..31f3b309 100644 --- a/src/hb-ot-cmap-table.hh +++ b/src/hb-ot-cmap-table.hh @@ -296,7 +296,7 @@ struct CmapSubtableFormat4 { /* XXX This does NOT skip over chars mapping to gid0... */ if (this->startCount[i] != 0xFFFFu || this->endCount[i] != 0xFFFFu) // Skip the last segment (0xFFFF) - hb_set_add_range (out, this->startCount[i], this->endCount[i]); + out->add_range (this->startCount[i], this->endCount[i]); } } @@ -459,11 +459,9 @@ struct CmapSubtableLongSegmented inline void collect_unicodes (hb_set_t *out) const { for (unsigned int i = 0; i < this->groups.len; i++) { - hb_set_add_range (out, - MIN ((unsigned int) this->groups[i].startCharCode, - (unsigned int) HB_MAX_UNICODE_CODEPOINT_VALUE), - MIN ((unsigned int) this->groups[i].endCharCode, - (unsigned int) HB_MAX_UNICODE_CODEPOINT_VALUE)); + out->add_range (this->groups[i].startCharCode, + MIN ((hb_codepoint_t) this->groups[i].endCharCode, + (hb_codepoint_t) HB_MAX_UNICODE_CODEPOINT_VALUE)); } } @@ -600,7 +598,23 @@ struct UnicodeValueRange DEFINE_SIZE_STATIC (4); }; -typedef SortedArrayOf DefaultUVS; +struct DefaultUVS : SortedArrayOf +{ + inline void collect_unicodes (hb_set_t *out) const + { + unsigned int count = len; + for (unsigned int i = 0; i < count; i++) + { + hb_codepoint_t first = arrayZ[i].startUnicodeValue; + hb_codepoint_t last = MIN ((hb_codepoint_t) (first + arrayZ[i].additionalCount), + (hb_codepoint_t) HB_MAX_UNICODE_CODEPOINT_VALUE); + out->add_range (first, last); + } + } + + public: + DEFINE_SIZE_ARRAY (4, arrayZ); +}; struct UVSMapping { @@ -621,7 +635,18 @@ struct UVSMapping DEFINE_SIZE_STATIC (5); }; -typedef SortedArrayOf NonDefaultUVS; +struct NonDefaultUVS : SortedArrayOf +{ + inline void collect_unicodes (hb_set_t *out) const + { + unsigned int count = len; + for (unsigned int i = 0; i < count; i++) + out->add (arrayZ[i].glyphID); + } + + public: + DEFINE_SIZE_ARRAY (4, arrayZ); +}; struct VariationSelectorRecord { @@ -644,6 +669,12 @@ struct VariationSelectorRecord return GLYPH_VARIANT_NOT_FOUND; } + inline void collect_unicodes (hb_set_t *out, const void *base) const + { + (base+defaultUVS).collect_unicodes (out); + (base+nonDefaultUVS).collect_unicodes (out); + } + inline int cmp (const hb_codepoint_t &variation_selector) const { return varSelector.cmp (variation_selector); @@ -672,7 +703,7 @@ struct CmapSubtableFormat14 hb_codepoint_t variation_selector, hb_codepoint_t *glyph) const { - return record[record.bsearch(variation_selector)].get_glyph (codepoint, glyph, this); + return record[record.bsearch (variation_selector)].get_glyph (codepoint, glyph, this); } inline void collect_variation_selectors (hb_set_t *out) const @@ -681,6 +712,11 @@ struct CmapSubtableFormat14 for (unsigned int i = 0; i < count; i++) out->add (record.arrayZ[i].varSelector); } + inline void collect_variation_unicodes (hb_codepoint_t variation_selector, + hb_set_t *out) const + { + record[record.bsearch (variation_selector)].collect_unicodes (out, this); + } inline bool sanitize (hb_sanitize_context_t *c) const { @@ -1045,6 +1081,11 @@ struct cmap { subtable_uvs->collect_variation_selectors (out); } + inline void collect_variation_unicodes (hb_codepoint_t variation_selector, + hb_set_t *out) const + { + subtable_uvs->collect_variation_unicodes (variation_selector, out); + } protected: typedef bool (*hb_cmap_get_glyph_func_t) (const void *obj, diff --git a/src/hb-subset.cc b/src/hb-subset.cc index 01d9b89a..77d9e81c 100644 --- a/src/hb-subset.cc +++ b/src/hb-subset.cc @@ -263,7 +263,8 @@ hb_subset_collect_unicodes (hb_face_t *face, hb_set_t *out) * Since: REPLACEME */ void -hb_subset_collect_variation_selectors (hb_face_t *face, hb_set_t *out) +hb_subset_collect_variation_selectors (hb_face_t *face, + hb_set_t *out) { /* XXX Use saved accel. */ OT::cmap::accelerator_t cmap; @@ -271,3 +272,25 @@ hb_subset_collect_variation_selectors (hb_face_t *face, hb_set_t *out) cmap.collect_variation_selectors (out); cmap.fini(); } + +/** + * hb_subset_collect_variation_unicodes: + * @face: font face. + * @out: set to add Unicode characters for @variation_selector covered by @face to. + * + * + * + * Since: REPLACEME + */ +void +hb_subset_collect_variation_unicodes (hb_face_t *face, + hb_codepoint_t variation_selector, + hb_set_t *out) +{ + /* XXX Use saved accel. */ + OT::cmap::accelerator_t cmap; + cmap.init (face); + cmap.collect_variation_unicodes (variation_selector, out); + cmap.fini(); +} + diff --git a/src/hb-subset.h b/src/hb-subset.h index 745bacf2..1e7d8f52 100644 --- a/src/hb-subset.h +++ b/src/hb-subset.h @@ -84,10 +84,16 @@ hb_subset (hb_face_t *source, /* TODO Move to hb-face.h. */ HB_EXTERN 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); HB_EXTERN void -hb_subset_collect_variation_selectors (hb_face_t *source, hb_set_t *out); +hb_subset_collect_variation_selectors (hb_face_t *face, + hb_set_t *out); + +HB_EXTERN void +hb_subset_collect_variation_unicodes (hb_face_t *face, + hb_codepoint_t variation_selector, + hb_set_t *out); HB_END_DECLS -- GitLab