[subset] consider variation selectors subsetting cmap14

cmap14 subsetting code was not considering variation selectors in the input unicode set when deciding which variant glyphs to keep. This updates subsetting to only keeps variant glyphs if their variation selector code point is in the input unicodes set.

For https://github.com/harfbuzz/harfbuzz/issues/4911
This commit is contained in:
Garret Rieger authored and Behdad Esfahbod committed 2024-11-11 13:45:08 -07:00
1 parent 1767f99e2e
commit b0d52abe97
330 files changed
+63 -19

No files matched your search

+4
View File
@@ -1397,6 +1397,9 @@ struct CmapSubtableFormat14
hb_vector_t<hb_pair_t<unsigned, unsigned>> obj_indices;
for (int i = src_tbl->record.len - 1; i >= 0; i--)
{
if (!unicodes->has(src_tbl->record[i].varSelector))
continue;
hb_pair_t<unsigned, unsigned> result = src_tbl->record[i].copy (c, unicodes, glyphs_requested, glyph_map, base);
if (result.first || result.second)
obj_indices.push (result);
@@ -1453,6 +1456,7 @@ struct CmapSubtableFormat14
{
+ hb_iter (record)
| hb_filter (hb_bool, &VariationSelectorRecord::nonDefaultUVS)
| hb_filter (unicodes, &VariationSelectorRecord::varSelector)
| hb_map (&VariationSelectorRecord::nonDefaultUVS)
| hb_map (hb_add (this))
| hb_apply ([=] (const NonDefaultUVS& _) { _.closure_glyphs (unicodes, glyphset); })
+2 -2
View File
@@ -284,8 +284,8 @@ struct OS2
os2_prime->usWidthClass = width_class;
}
os2_prime->usFirstCharIndex = hb_min (0xFFFFu, c->plan->unicodes.get_min ());
os2_prime->usLastCharIndex = hb_min (0xFFFFu, c->plan->unicodes.get_max ());
os2_prime->usFirstCharIndex = hb_min (0xFFFFu, c->plan->os2_info.min_cmap_codepoint);
os2_prime->usLastCharIndex = hb_min (0xFFFFu, c->plan->os2_info.max_cmap_codepoint);
if (c->plan->flags & HB_SUBSET_FLAGS_NO_PRUNE_UNICODE_RANGES)
return_trace (true);
+17 -1
View File
@@ -678,7 +678,8 @@ _populate_unicodes_to_retain (const hb_set_t *unicodes,
hb_subset_plan_t *plan)
{
OT::cmap::accelerator_t cmap (plan->source);
unsigned size_threshold = plan->source->get_num_glyphs ();
unsigned size_threshold = plan->source->get_num_glyphs ();
if (glyphs->is_empty () && unicodes->get_population () < size_threshold)
{
@@ -797,6 +798,21 @@ _populate_unicodes_to_retain (const hb_set_t *unicodes,
plan->unicodes.add_sorted_array (&arr.arrayZ->first, arr.length, sizeof (*arr.arrayZ));
plan->_glyphset_gsub.add_array (&arr.arrayZ->second, arr.length, sizeof (*arr.arrayZ));
}
// Variation selectors don't have glyphs associated with them in the cmap so they will have been filtered out above
// but should still be retained. Add them back here.
// However, the min and max codepoints for OS/2 should be calculated without considering variation selectors,
// so record those first.
plan->os2_info.min_cmap_codepoint = plan->unicodes.get_min();
plan->os2_info.max_cmap_codepoint = plan->unicodes.get_max();
hb_set_t variation_selectors_to_retain;
cmap.collect_variation_selectors(&variation_selectors_to_retain);
+ variation_selectors_to_retain.iter()
| hb_filter(unicodes)
| hb_sink(&plan->unicodes)
;
}
static unsigned
+9
View File
@@ -41,6 +41,13 @@ namespace OT {
struct Feature;
}
struct os2_info_t {
hb_codepoint_t min_cmap_codepoint;
hb_codepoint_t max_cmap_codepoint;
};
typedef struct os2_info_t os2_info_t;
struct head_maxp_info_t
{
head_maxp_info_t ()
@@ -180,6 +187,8 @@ struct hb_subset_plan_t
//recalculated head/maxp table info after instancing
mutable head_maxp_info_t head_maxp_info;
os2_info_t os2_info;
const hb_subset_accelerator_t* accelerator;
hb_subset_accelerator_t* inprogress_accelerator;
+2
View File
@@ -145,6 +145,7 @@ test_subset_cmap_noto_color_emoji_noop (void)
hb_set_add (codepoints, 0xAE);
hb_set_add (codepoints, 0x2049);
hb_set_add (codepoints, 0x20E3);
hb_set_add (codepoints, 0xfe0f);
face_subset = hb_subset_test_create_subset (face, hb_subset_test_create_input (codepoints));
hb_set_destroy (codepoints);
@@ -165,6 +166,7 @@ test_subset_cmap_noto_color_emoji_non_consecutive_glyphs (void)
hb_set_add (codepoints, 0x38);
hb_set_add (codepoints, 0xAE);
hb_set_add (codepoints, 0x2049);
hb_set_add (codepoints, 0xfe0f);
face_subset = hb_subset_test_create_subset (face, hb_subset_test_create_input (codepoints));
hb_set_destroy (codepoints);
Loaded 100 of 330 files, more files were not shown because too many files have changed in this diff. Show more