[subset] Address VARC review comments

Short-circuit unchanged-index checks and simplify glyph closure to use
one pending set with the output glyph set tracking visited glyphs.

Strengthen retained-glyph-ID coverage by comparing the source and subset
outlines using the original glyph ID.

Tested with: meson test -C build --print-errorlogs

Assisted-by: OpenAI Codex <openai-codex@users.noreply.github.com>
This commit is contained in:
Behdad Esfahbod committed 2026-09-10 13:24:14 -06:00
1 parent d268a23eeb
commit 155a9d88e8
3 files changed
+60 -34

No files matched your search

+7 -5
View File
@@ -189,14 +189,16 @@ struct varc_subset_plan_t
private:
bool auxiliary_indices_unchanged () const
{
bool unchanged = true;
for (hb_codepoint_t old_index : condition_indices)
unchanged &= condition_map.get (old_index) == old_index;
if (condition_map.get (old_index) != old_index)
return false;
for (hb_codepoint_t old_index : axis_indices)
unchanged &= axis_indices_map.get (old_index) == old_index;
if (axis_indices_map.get (old_index) != old_index)
return false;
for (hb_codepoint_t old_index : var_indices)
unchanged &= varidx_map.get (old_index) == old_index;
return unchanged;
if (varidx_map.get (old_index) != old_index)
return false;
return true;
}
bool append_varint (uint32_t value)
+21 -21
View File
@@ -151,35 +151,35 @@ VARC::closure_glyphs (hb_set_t *glyphset) const
if (unlikely (glyphset->in_error ()))
return false;
hb_set_t visited;
while (true)
hb_set_t pending = *glyphset;
if (unlikely (pending.in_error ()))
return false;
while (pending)
{
hb_set_t pending = *glyphset;
pending.subtract (visited);
if (unlikely (pending.in_error ()))
return false;
if (!pending) break;
visited.union_ (pending);
if (unlikely (visited.in_error ()))
return false;
hb_codepoint_t gid = pending.get_min ();
pending.del (gid);
for (hb_codepoint_t gid : pending)
unsigned index = (this+coverage).get_coverage (gid);
if (index == NOT_COVERED) continue;
hb_ubytes_t record = (this+glyphRecords)[index];
while (record)
{
unsigned index = (this+coverage).get_coverage (gid);
if (index == NOT_COVERED) continue;
hb_ubytes_t record = (this+glyphRecords)[index];
while (record)
VarComponent::record_t component;
if (unlikely (!VarComponent::decompile_record (*this, record,
nullptr, nullptr, &component)))
return false;
if (!glyphset->has (component.gid))
{
VarComponent::record_t component;
if (unlikely (!VarComponent::decompile_record (*this, record,
nullptr, nullptr, &component)))
return false;
glyphset->add (component.gid);
if (unlikely (glyphset->in_error ()))
return false;
record = record.sub_array (component.size);
pending.add (component.gid);
if (unlikely (pending.in_error ()))
return false;
}
record = record.sub_array (component.size);
}
}
return true;
+32 -8
View File
@@ -61,14 +61,8 @@ draw_close_path (hb_draw_funcs_t *funcs HB_UNUSED, void *data,
{ g_string_append_c ((GString *) data, 'Z'); }
static char *
draw_unicode_at (hb_face_t *face, hb_codepoint_t unicode,
const hb_variation_t *variations, unsigned variation_count)
draw_glyph (hb_font_t *font, hb_codepoint_t gid)
{
hb_font_t *font = hb_font_create (face);
hb_font_set_variations (font, variations, variation_count);
hb_codepoint_t gid;
g_assert_true (hb_font_get_nominal_glyph (font, unicode, &gid));
hb_draw_funcs_t *funcs = hb_draw_funcs_create ();
hb_draw_funcs_set_move_to_func (funcs, draw_move_to, NULL, NULL);
hb_draw_funcs_set_line_to_func (funcs, draw_line_to, NULL, NULL);
@@ -79,10 +73,23 @@ draw_unicode_at (hb_face_t *face, hb_codepoint_t unicode,
hb_font_draw_glyph (font, gid, funcs, path);
hb_draw_funcs_destroy (funcs);
hb_font_destroy (font);
return g_string_free (path, false);
}
static char *
draw_unicode_at (hb_face_t *face, hb_codepoint_t unicode,
const hb_variation_t *variations, unsigned variation_count)
{
hb_font_t *font = hb_font_create (face);
hb_font_set_variations (font, variations, variation_count);
hb_codepoint_t gid;
g_assert_true (hb_font_get_nominal_glyph (font, unicode, &gid));
char *path = draw_glyph (font, gid);
hb_font_destroy (font);
return path;
}
static char *
draw_unicode (hb_face_t *face, hb_codepoint_t unicode)
{ return draw_unicode_at (face, unicode, NULL, 0); }
@@ -240,6 +247,23 @@ test_subset_varc_retain_gids (void)
g_assert_cmpuint (hb_face_get_glyph_count (subset), ==, 7);
assert_has_varc (subset, true);
hb_font_t *source_font = hb_font_create (face);
hb_font_t *subset_font = hb_font_create (subset);
hb_codepoint_t old_gid;
hb_codepoint_t subset_gid;
g_assert_true (hb_font_get_nominal_glyph (source_font, 0xAC00, &old_gid));
g_assert_true (hb_font_get_nominal_glyph (subset_font, 0xAC00, &subset_gid));
g_assert_cmpuint (subset_gid, ==, old_gid);
char *source_path = draw_glyph (source_font, old_gid);
char *subset_path = draw_glyph (subset_font, old_gid);
g_assert_cmpstr (source_path, !=, "");
g_assert_cmpstr (subset_path, ==, source_path);
g_free (subset_path);
g_free (source_path);
hb_font_destroy (subset_font);
hb_font_destroy (source_font);
hb_face_destroy (subset);
hb_face_destroy (face);
}