mirror of
https://github.com/storytold/harfbuzz.git
synced 2026-11-25 08:51:07 +01:00
[subset] Remap ClassDef glyphs through the flat array
Extend the flat old-to-new gid array introduced for Coverage::subset to ClassDef subsetting: add a map_gsub_glyph() helper on the plan and use it in ClassDefFormat1/2::subset in place of per-glyph glyph_map_gsub hash lookups. The use_class_zero glyph counts switch from the map to the equivalent glyphset_gsub set. Tested with meson test (all tests pass). Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
f6bcedab83
commit
f5ce090554
3 files changed
+23
-12
No files matched your search
@@ -189,12 +189,12 @@ struct Coverage
|
||||
bool subset (hb_subset_context_t *c) const
|
||||
{
|
||||
TRACE_SUBSET (this);
|
||||
const hb_vector_t<hb_codepoint_t> &glyph_map = c->plan->glyph_map_gsub_flat;
|
||||
const hb_subset_plan_t *plan = c->plan;
|
||||
auto it =
|
||||
+ iter ()
|
||||
| hb_take (c->plan->source->get_num_glyphs ())
|
||||
| hb_map_retains_sorting ([&glyph_map] (hb_codepoint_t g) {
|
||||
return g < glyph_map.length ? glyph_map.arrayZ[g] : HB_MAP_VALUE_INVALID;
|
||||
| hb_take (plan->source->get_num_glyphs ())
|
||||
| hb_map_retains_sorting ([plan] (hb_codepoint_t g) {
|
||||
return plan->map_gsub_glyph (g);
|
||||
})
|
||||
| hb_filter ([] (hb_codepoint_t glyph) { return glyph != HB_MAP_VALUE_INVALID; })
|
||||
;
|
||||
|
||||
@@ -1551,7 +1551,6 @@ struct ClassDefFormat1_3
|
||||
const Coverage* glyph_filter = nullptr) const
|
||||
{
|
||||
TRACE_SUBSET (this);
|
||||
const hb_map_t &glyph_map = c->plan->glyph_map_gsub;
|
||||
|
||||
hb_sorted_vector_t<hb_codepoint_pair_t> glyph_and_klass;
|
||||
hb_set_t orig_klasses;
|
||||
@@ -1561,7 +1560,7 @@ struct ClassDefFormat1_3
|
||||
|
||||
for (const hb_codepoint_t gid : + hb_range (start, end))
|
||||
{
|
||||
hb_codepoint_t new_gid = glyph_map[gid];
|
||||
hb_codepoint_t new_gid = c->plan->map_gsub_glyph (gid);
|
||||
if (new_gid == HB_MAP_VALUE_INVALID) continue;
|
||||
if (glyph_filter && !glyph_filter->has(gid)) continue;
|
||||
|
||||
@@ -1574,9 +1573,10 @@ struct ClassDefFormat1_3
|
||||
|
||||
if (use_class_zero)
|
||||
{
|
||||
const hb_set_t& glyphset = *c->plan->glyphset_gsub ();
|
||||
unsigned glyph_count = glyph_filter
|
||||
? hb_len (hb_iter (glyph_map.keys()) | hb_filter (glyph_filter))
|
||||
: glyph_map.get_population ();
|
||||
? hb_len (hb_iter (glyphset) | hb_filter (glyph_filter))
|
||||
: glyphset.get_population ();
|
||||
use_class_zero = glyph_count <= glyph_and_klass.length;
|
||||
}
|
||||
if (!ClassDef_remap_and_serialize (c->serializer,
|
||||
@@ -1810,7 +1810,6 @@ struct ClassDefFormat2_4
|
||||
const Coverage* glyph_filter = nullptr) const
|
||||
{
|
||||
TRACE_SUBSET (this);
|
||||
const hb_map_t &glyph_map = c->plan->glyph_map_gsub;
|
||||
const hb_set_t &glyph_set = *c->plan->glyphset_gsub ();
|
||||
|
||||
hb_sorted_vector_t<hb_codepoint_pair_t> glyph_and_klass;
|
||||
@@ -1823,7 +1822,7 @@ struct ClassDefFormat2_4
|
||||
{
|
||||
unsigned klass = get_class (g);
|
||||
if (!klass) continue;
|
||||
hb_codepoint_t new_gid = glyph_map[g];
|
||||
hb_codepoint_t new_gid = c->plan->map_gsub_glyph (g);
|
||||
if (new_gid == HB_MAP_VALUE_INVALID) continue;
|
||||
if (glyph_filter && !glyph_filter->has (g)) continue;
|
||||
glyph_and_klass.push (hb_pair (new_gid, klass));
|
||||
@@ -1841,7 +1840,7 @@ struct ClassDefFormat2_4
|
||||
hb_codepoint_t end = hb_min (range.last + 1, num_source_glyphs);
|
||||
for (hb_codepoint_t g = start; g < end; g++)
|
||||
{
|
||||
hb_codepoint_t new_gid = glyph_map[g];
|
||||
hb_codepoint_t new_gid = c->plan->map_gsub_glyph (g);
|
||||
if (new_gid == HB_MAP_VALUE_INVALID) continue;
|
||||
if (glyph_filter && !glyph_filter->has (g)) continue;
|
||||
|
||||
@@ -1854,7 +1853,7 @@ struct ClassDefFormat2_4
|
||||
const hb_set_t& glyphset = *c->plan->glyphset_gsub ();
|
||||
unsigned glyph_count = glyph_filter
|
||||
? hb_len (hb_iter (glyphset) | hb_filter (glyph_filter))
|
||||
: glyph_map.get_population ();
|
||||
: glyphset.get_population ();
|
||||
use_class_zero = use_class_zero && glyph_count <= glyph_and_klass.length;
|
||||
if (!ClassDef_remap_and_serialize (c->serializer,
|
||||
orig_klasses,
|
||||
|
||||
@@ -241,6 +241,18 @@ struct hb_subset_plan_t
|
||||
return &_glyphset_gsub;
|
||||
}
|
||||
|
||||
/*
|
||||
* Old-to-new glyph id mapping for GSUB glyphs, through the flat
|
||||
* array; returns HB_MAP_VALUE_INVALID for glyphs not retained.
|
||||
*/
|
||||
inline hb_codepoint_t
|
||||
map_gsub_glyph (hb_codepoint_t old_gid) const
|
||||
{
|
||||
return old_gid < glyph_map_gsub_flat.length
|
||||
? glyph_map_gsub_flat.arrayZ[old_gid]
|
||||
: HB_MAP_VALUE_INVALID;
|
||||
}
|
||||
|
||||
/*
|
||||
* The total number of output glyphs in the final subset.
|
||||
*/
|
||||
|
||||
Reference in new issue
Block a user