collect_unicodes() with clamp, calling add_range()

Use add_range instead an inner loop, clamp its input number by
number of glyphs a face has.

Even the face cmap12 and 13 have 32-bit hb_codepoint_t, which is here
used to make timeout, face's maxp has 16-bit gid limitation at least for now,
using that makes sure we both fix and the timeout and don't need to change
much things here also in order to support 32-bit gids also someday.

Fixes #2204
This commit is contained in:
Michiharu Ariza 2020-02-29 01:32:29 -08:00 committed by GitHub
parent 414529e45a
commit 5ab50eebd7
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 19 additions and 13 deletions

View File

@ -546,7 +546,7 @@ void
hb_face_collect_unicodes (hb_face_t *face,
hb_set_t *out)
{
face->table.cmap->collect_unicodes (out);
face->table.cmap->collect_unicodes (out, face->get_num_glyphs ());
}
/**
* hb_face_collect_variation_selectors:

View File

@ -539,20 +539,26 @@ struct CmapSubtableLongSegmented
return true;
}
void collect_unicodes (hb_set_t *out) const
void collect_unicodes (hb_set_t *out, unsigned int num_glyphs) const
{
for (unsigned int i = 0; i < this->groups.len; i++)
{
hb_codepoint_t start = this->groups[i].startCharCode;
hb_codepoint_t end = hb_min ((hb_codepoint_t) this->groups[i].endCharCode,
(hb_codepoint_t) HB_UNICODE_MAX);
for (hb_codepoint_t codepoint = start; codepoint <= end; codepoint++)
hb_codepoint_t gid = this->groups[i].glyphID;
if (!gid)
{
hb_codepoint_t gid = T::group_get_glyph (this->groups[i], codepoint);
if (unlikely (!gid))
continue;
out->add (codepoint);
/* Intention is: if (hb_is_same (T, CmapSubtableFormat13)) continue; */
if (! T::group_get_glyph (this->groups[i], end)) continue;
start++;
gid++;
}
if (unlikely ((unsigned int) gid >= num_glyphs)) continue;
if (unlikely ((unsigned int) (gid + end - start) >= num_glyphs))
end = start + (hb_codepoint_t) num_glyphs - gid;
out->add_range (start, end);
}
}
@ -1077,15 +1083,15 @@ struct CmapSubtable
default: return false;
}
}
void collect_unicodes (hb_set_t *out) const
void collect_unicodes (hb_set_t *out, unsigned int num_glyphs = UINT_MAX) const
{
switch (u.format) {
case 0: u.format0 .collect_unicodes (out); return;
case 4: u.format4 .collect_unicodes (out); return;
case 6: u.format6 .collect_unicodes (out); return;
case 10: u.format10.collect_unicodes (out); return;
case 12: u.format12.collect_unicodes (out); return;
case 13: u.format13.collect_unicodes (out); return;
case 12: u.format12.collect_unicodes (out, num_glyphs); return;
case 13: u.format13.collect_unicodes (out, num_glyphs); return;
case 14:
default: return;
}
@ -1417,8 +1423,8 @@ struct cmap
return get_nominal_glyph (unicode, glyph);
}
void collect_unicodes (hb_set_t *out) const
{ subtable->collect_unicodes (out); }
void collect_unicodes (hb_set_t *out, unsigned int num_glyphs) const
{ subtable->collect_unicodes (out, num_glyphs); }
void collect_variation_selectors (hb_set_t *out) const
{ subtable_uvs->collect_variation_selectors (out); }
void collect_variation_unicodes (hb_codepoint_t variation_selector,