[cmap] Add hb_subset_collect_variation_selectors()

To be moved to hb-face later.
This commit is contained in:
Behdad Esfahbod 2018-08-25 15:56:07 -07:00
parent 3336de2479
commit 4806b3800d
3 changed files with 49 additions and 9 deletions

View File

@ -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;
};

View File

@ -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();
}

View File

@ -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 */