[subset] glyph closure for CMAP14

This commit is contained in:
Qunxin Liu 2019-08-07 13:17:26 -07:00 committed by Garret Rieger
parent bbe878006d
commit 078ddbd0f6
2 changed files with 43 additions and 1 deletions

View File

@ -708,6 +708,16 @@ struct NonDefaultUVS : SortedArrayOf<UVSMapping, HBUINT32>
out->add (arrayZ[i].glyphID);
}
void closure_glyphs (const hb_set_t *unicodes,
hb_set_t *glyphset) const
{
+ as_array ()
| hb_filter ([&] (const UVSMapping& _) { return hb_set_has (unicodes, _.unicodeValue); })
| hb_map (&UVSMapping::glyphID)
| hb_sink (glyphset)
;
}
public:
DEFINE_SIZE_ARRAY (4, *this);
};
@ -778,6 +788,17 @@ struct CmapSubtableFormat14
record.bsearch (variation_selector).collect_unicodes (out, this);
}
void closure_glyphs (const hb_set_t *unicodes,
hb_set_t *glyphset) const
{
+ hb_iter (record)
| hb_filter ([&] (const VariationSelectorRecord& _) { return _.nonDefaultUVS != 0 && hb_set_has (unicodes, _.varSelector); })
| hb_map (&VariationSelectorRecord::nonDefaultUVS)
| hb_map (hb_add (this))
| hb_apply ([=] (const NonDefaultUVS& _) { _.closure_glyphs (unicodes, glyphset); })
;
}
bool sanitize (hb_sanitize_context_t *c) const
{
TRACE_SANITIZE (this);
@ -952,6 +973,17 @@ struct cmap
}
void closure_glyphs (const hb_set_t *unicodes,
hb_set_t *glyphset) const
{
+ hb_iter (encodingRecord)
| hb_map (&EncodingRecord::subtable)
| hb_map (hb_add (this))
| hb_filter ([&] (const CmapSubtable& _) { return _.u.format == 14; })
| hb_apply ([=] (const CmapSubtable& _) { _.u.format14.closure_glyphs (unicodes, glyphset); })
;
}
bool subset (hb_subset_context_t *c) const
{
TRACE_SUBSET (this);
@ -968,7 +1000,6 @@ struct cmap
if (unlikely (!unicode_bmp && !ms_bmp)) return_trace (false);
if (unlikely (has_format12 && (!unicode_ucs4 && !ms_ucs4))) return_trace (false);
auto it =
+ hb_iter (c->plan->unicodes)
| hb_map ([&] (hb_codepoint_t _)
@ -1161,6 +1192,7 @@ struct cmap
CmapSubtableFormat4::accelerator_t format4_accel;
public:
hb_blob_ptr_t<cmap> table;
};

View File

@ -87,6 +87,14 @@ _gsub_closure (hb_face_t *face, hb_set_t *gids_to_retain)
}
#endif
static inline void
_cmap_closure (hb_face_t *face,
const hb_set_t *unicodes,
hb_set_t *glyphset)
{
face->table.cmap->table->closure_glyphs (unicodes, glyphset);
}
static inline void
_remove_invalid_gids (hb_set_t *glyphs,
unsigned int num_glyphs)
@ -128,6 +136,8 @@ _populate_gids_to_retain (hb_subset_plan_t* plan,
plan->codepoint_to_glyph->set (cp, gid);
plan->_glyphset_gsub->add (gid);
}
_cmap_closure (plan->source, plan->unicodes, plan->_glyphset_gsub);
#ifndef HB_NO_SUBSET_LAYOUT
if (close_over_gsub)