Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bug in variation form lookup #349

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions src/CmapProcessor.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,26 +151,38 @@ export default class CmapProcessor {

getVariationSelector(codepoint, variationSelector) {
if (!this.uvs) {
// This font file does not contain information about variation forms.
return 0;
}

let selectors = this.uvs.varSelectors.toArray();
let i = binarySearch(selectors, x => variationSelector - x.varSelector);
if (i === -1) {
// There is no information about the specified variation form.
return 0;
}
let sel = selectors[i];

if (i !== -1 && sel.defaultUVS) {
if (sel.defaultUVS) {
i = binarySearch(sel.defaultUVS, x =>
codepoint < x.startUnicodeValue ? -1 : codepoint > x.startUnicodeValue + x.additionalCount ? +1 : 0
);
if (i !== -1) {
// Since this variation is the default form of this character,
// the base character’s glyph should be searched for as usual.
return 0;
}
}

if (i !== -1 && sel.nonDefaultUVS) {
if (sel.nonDefaultUVS) {
i = binarySearch(sel.nonDefaultUVS, x => codepoint - x.unicodeValue);
if (i !== -1) {
// The glyph for this variation form has been identified.
return sel.nonDefaultUVS[i].glyphID;
}
}

// The variation form was not found.
return 0;
}

Expand Down