From 8f78847376b0ad074f139ded1e35e5db9c55d0b7 Mon Sep 17 00:00:00 2001 From: KojiAndoJC <106056103+KojiAndoJC@users.noreply.github.com> Date: Wed, 25 May 2022 16:39:57 +0900 Subject: [PATCH 1/2] Fix the Variation Selector handling Fix the problem that the variable `i` was overwritten and the non-default UVS wasn't used when the default UVS exists. --- src/CmapProcessor.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/CmapProcessor.js b/src/CmapProcessor.js index 23843c66..1e927de4 100644 --- a/src/CmapProcessor.js +++ b/src/CmapProcessor.js @@ -156,15 +156,21 @@ export default class CmapProcessor { let selectors = this.uvs.varSelectors.toArray(); let i = binarySearch(selectors, x => variationSelector - x.varSelector); + if (i === -1) { + 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) { + return 0; + } } - if (i !== -1 && sel.nonDefaultUVS) { + if (sel.nonDefaultUVS) { i = binarySearch(sel.nonDefaultUVS, x => codepoint - x.unicodeValue); if (i !== -1) { return sel.nonDefaultUVS[i].glyphID; From 344f4dddf0be2a9b9b8a2a9b2298eb8765537187 Mon Sep 17 00:00:00 2001 From: KojiAndoJC <106056103+KojiAndoJC@users.noreply.github.com> Date: Sun, 29 May 2022 09:22:00 +0900 Subject: [PATCH 2/2] Better fix so as not to override a variable --- src/CmapProcessor.js | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/src/CmapProcessor.js b/src/CmapProcessor.js index 1e927de4..35d712d1 100644 --- a/src/CmapProcessor.js +++ b/src/CmapProcessor.js @@ -156,13 +156,10 @@ export default class CmapProcessor { let selectors = this.uvs.varSelectors.toArray(); let i = binarySearch(selectors, x => variationSelector - x.varSelector); - if (i === -1) { - return 0; - } let sel = selectors[i]; - if (sel.defaultUVS) { - i = binarySearch(sel.defaultUVS, x => + if (i !== -1 && sel.defaultUVS) { + let i = binarySearch(sel.defaultUVS, x => codepoint < x.startUnicodeValue ? -1 : codepoint > x.startUnicodeValue + x.additionalCount ? +1 : 0 ); if (i !== -1) { @@ -170,8 +167,8 @@ export default class CmapProcessor { } } - if (sel.nonDefaultUVS) { - i = binarySearch(sel.nonDefaultUVS, x => codepoint - x.unicodeValue); + if (i !== -1 && sel.nonDefaultUVS) { + let i = binarySearch(sel.nonDefaultUVS, x => codepoint - x.unicodeValue); if (i !== -1) { return sel.nonDefaultUVS[i].glyphID; }