Skip to content
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
7 changes: 5 additions & 2 deletions src/CmapProcessor.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,13 +159,16 @@ export default class CmapProcessor {
let sel = selectors[i];

if (i !== -1 && sel.defaultUVS) {
i = binarySearch(sel.defaultUVS, x =>
let i = binarySearch(sel.defaultUVS, x =>
codepoint < x.startUnicodeValue ? -1 : codepoint > x.startUnicodeValue + x.additionalCount ? +1 : 0
);
if (i !== -1) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should this be the opposite, i.e. i === -1?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm sorry I didn't make it clear enough. My pull request fixes two problems.

  1. When the default UVS table exists and its entry not exists (i === -1), the variable i was overwriten and the non-default UVS isn't used.
  2. When the default entry exists ( i !== -1 ), it means "the default glyph (the same glyph as base character) should be used" and checking the non-default UVS is unnecessary. By returning 0, the Variation Selector is ignored correctly here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A test would help understanding the issue and ensuring the fix is correct

return 0;
}
}

if (i !== -1 && sel.nonDefaultUVS) {
i = binarySearch(sel.nonDefaultUVS, x => codepoint - x.unicodeValue);
let i = binarySearch(sel.nonDefaultUVS, x => codepoint - x.unicodeValue);
if (i !== -1) {
return sel.nonDefaultUVS[i].glyphID;
}
Expand Down