[subset] Fix broken cmap creation.

It was ignoring the restriction that gids must be consecutive to be placed into a single group.
This commit is contained in:
Garret Rieger 2018-04-18 17:13:37 -07:00
parent a47070cd40
commit 5e318e09ba
1 changed files with 16 additions and 7 deletions

View File

@ -539,6 +539,14 @@ struct cmap
encodingRecord.sanitize (c, this)); encodingRecord.sanitize (c, this));
} }
static inline bool _is_gid_consecutive (CmapSubtableLongGroup *group,
hb_codepoint_t cp,
hb_codepoint_t new_gid)
{
return (cp - 1 == group->endCharCode) &&
new_gid == group->glyphID + (cp - group->startCharCode);
}
inline bool populate_groups (hb_subset_plan_t *plan, inline bool populate_groups (hb_subset_plan_t *plan,
hb_prealloced_array_t<CmapSubtableLongGroup> *groups) const hb_prealloced_array_t<CmapSubtableLongGroup> *groups) const
{ {
@ -546,17 +554,18 @@ struct cmap
for (unsigned int i = 0; i < plan->codepoints.len; i++) { for (unsigned int i = 0; i < plan->codepoints.len; i++) {
hb_codepoint_t cp = plan->codepoints[i]; hb_codepoint_t cp = plan->codepoints[i];
if (!group || cp - 1 != group->endCharCode) hb_codepoint_t new_gid;
if (unlikely (!hb_subset_plan_new_gid_for_codepoint (plan, cp, &new_gid)))
{
DEBUG_MSG(SUBSET, nullptr, "Unable to find new gid for %04x", cp);
return false;
}
if (!group || !_is_gid_consecutive (group, cp, new_gid))
{ {
group = groups->push (); group = groups->push ();
group->startCharCode.set (cp); group->startCharCode.set (cp);
group->endCharCode.set (cp); group->endCharCode.set (cp);
hb_codepoint_t new_gid;
if (unlikely (!hb_subset_plan_new_gid_for_codepoint (plan, cp, &new_gid)))
{
DEBUG_MSG(SUBSET, nullptr, "Unable to find new gid for %04x", cp);
return false;
}
group->glyphID.set (new_gid); group->glyphID.set (new_gid);
} else } else
{ {