-
Notifications
You must be signed in to change notification settings - Fork 484
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' into feature/thai-context-substitutions-support
# Conflicts: # src/bidi.js # test/bidi.js
- Loading branch information
Showing
19 changed files
with
848 additions
and
130 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
38 changes: 38 additions & 0 deletions
38
src/features/unicode/contextCheck/variationSequenceCheck.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/** | ||
* Unicode Variation Sequence context checkers | ||
*/ | ||
|
||
function isVariationSequenceSelector(char) { | ||
if (char === null) return false; | ||
const charCode = char.codePointAt(0); | ||
return ( | ||
// Mongolian Variation Selectors | ||
(charCode >= 0x180B && charCode <= 0x180D) || | ||
// Generic Variation Selectors | ||
(charCode >= 0xFE00 && charCode <= 0xFE0F) || | ||
// Ideographic Variation Sequences | ||
(charCode >= 0xE0100 && charCode <= 0xE01EF) | ||
); | ||
} | ||
|
||
function unicodeVariationSequenceStartCheck(contextParams) { | ||
const char = contextParams.current; | ||
const nextChar = contextParams.get(1); | ||
return ( | ||
(nextChar === null && isVariationSequenceSelector(char)) || | ||
(isVariationSequenceSelector(nextChar)) | ||
); | ||
} | ||
|
||
function unicodeVariationSequenceEndCheck(contextParams) { | ||
const nextChar = contextParams.get(1); | ||
return ( | ||
(nextChar === null) || | ||
(!isVariationSequenceSelector(nextChar)) | ||
); | ||
} | ||
|
||
export default { | ||
startCheck: unicodeVariationSequenceStartCheck, | ||
endCheck: unicodeVariationSequenceEndCheck | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
/** | ||
* Apply unicode variation sequences to a range of tokens | ||
*/ | ||
|
||
/** | ||
* Apply unicode variation squences to a context range | ||
* @param {ContextRange} range a range of tokens | ||
* | ||
* @TODO: We could incorporate the data from | ||
* https://www.unicode.org/Public/UCD/latest/ucd/StandardizedVariants.txt | ||
* https://www.unicode.org/Public/UCD/latest/ucd/emoji/emoji-variation-sequences.txt | ||
* https://www.unicode.org/ivd/data/2022-09-13/IVD_Sequences.txt | ||
* and ignore any sequences that are not standardized, but that would have to be | ||
* kept up-do-date and result in huge data overhead | ||
*/ | ||
function unicodeVariationSequence(range) { | ||
const font = this.query.font; | ||
const tokens = this.tokenizer.getRangeTokens(range); | ||
// treat varSelector as if not there (this should have been the default even before supporting UVSes) | ||
// https://unicode.org/faq/vs.html#6 | ||
tokens[1].setState('deleted', true); | ||
if(font.tables.cmap && font.tables.cmap.varSelectorList) { | ||
const baseCodePoint = tokens[0].char.codePointAt(0); | ||
const vsCodePoint = tokens[1].char.codePointAt(0); | ||
const selectorLookup = font.tables.cmap.varSelectorList[vsCodePoint]; | ||
if (selectorLookup !== undefined) { | ||
if (selectorLookup.nonDefaultUVS) { | ||
const mappings = selectorLookup.nonDefaultUVS.uvsMappings; | ||
if(mappings[baseCodePoint]) { | ||
const replacementGlyphId = mappings[baseCodePoint].glyphID; | ||
if(font.glyphs.glyphs[replacementGlyphId] !== undefined) { | ||
tokens[0].setState('glyphIndex', replacementGlyphId); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
export default unicodeVariationSequence; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.