-
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 pull request #535 from Adylic/feature/thai-context-substitution…
…s-support feat: Added a thai context to the bidi and substitution features
- Loading branch information
Showing
9 changed files
with
245 additions
and
10 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
import { isThaiChar } from '../../../char.js'; | ||
|
||
/** | ||
* Thai word context checkers | ||
*/ | ||
function thaiWordStartCheck(contextParams) { | ||
const char = contextParams.current; | ||
const prevChar = contextParams.get(-1); | ||
return ( | ||
// ? thai first char | ||
(prevChar === null && isThaiChar(char)) || | ||
// ? thai char preceded with a non thai char | ||
(!isThaiChar(prevChar) && isThaiChar(char)) | ||
); | ||
} | ||
|
||
function thaiWordEndCheck(contextParams) { | ||
const nextChar = contextParams.get(1); | ||
return ( | ||
// ? last thai char | ||
(nextChar === null) || | ||
// ? next char is not thai | ||
(!isThaiChar(nextChar)) | ||
); | ||
} | ||
|
||
export default { | ||
startCheck: thaiWordStartCheck, | ||
endCheck: thaiWordEndCheck | ||
}; |
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 Thai Glyph Composition feature to tokens | ||
*/ | ||
|
||
import { ContextParams } from '../../tokenizer.js'; | ||
import applySubstitution from '../applySubstitution.js'; | ||
|
||
/** | ||
* Update context params | ||
* @param {any} tokens a list of tokens | ||
* @param {number} index current item index | ||
*/ | ||
function getContextParams(tokens, index) { | ||
const context = tokens.map(token => token.activeState.value); | ||
return new ContextParams(context, index || 0); | ||
} | ||
|
||
/** | ||
* Apply Thai required glyphs composition substitutions | ||
* @param {ContextRange} range a range of tokens | ||
*/ | ||
function thaiGlyphComposition(range) { | ||
const script = 'thai'; | ||
let tokens = this.tokenizer.getRangeTokens(range); | ||
let contextParams = getContextParams(tokens, 0); | ||
contextParams.context.forEach((glyphIndex, index) => { | ||
contextParams.setCurrentIndex(index); | ||
let substitutions = this.query.lookupFeature({ | ||
tag: 'ccmp', script, contextParams | ||
}); | ||
if (substitutions.length) { | ||
substitutions.forEach( | ||
action => applySubstitution(action, tokens, index) | ||
); | ||
contextParams = getContextParams(tokens, index); | ||
} | ||
}); | ||
} | ||
|
||
export default thaiGlyphComposition; |
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 Thai Ligatures feature to tokens | ||
*/ | ||
|
||
import { ContextParams } from '../../tokenizer.js'; | ||
import applySubstitution from '../applySubstitution.js'; | ||
|
||
/** | ||
* Update context params | ||
* @param {any} tokens a list of tokens | ||
* @param {number} index current item index | ||
*/ | ||
function getContextParams(tokens, index) { | ||
const context = tokens.map(token => token.activeState.value); | ||
return new ContextParams(context, index || 0); | ||
} | ||
|
||
/** | ||
* Apply Thai required glyphs composition substitutions | ||
* @param {ContextRange} range a range of tokens | ||
*/ | ||
function thaiLigatures(range) { | ||
const script = 'thai'; | ||
let tokens = this.tokenizer.getRangeTokens(range); | ||
let contextParams = getContextParams(tokens, 0); | ||
contextParams.context.forEach((glyphIndex, index) => { | ||
contextParams.setCurrentIndex(index); | ||
let substitutions = this.query.lookupFeature({ | ||
tag: 'liga', script, contextParams | ||
}); | ||
if (substitutions.length) { | ||
substitutions.forEach( | ||
action => applySubstitution(action, tokens, index) | ||
); | ||
contextParams = getContextParams(tokens, index); | ||
} | ||
}); | ||
} | ||
|
||
export default thaiLigatures; |
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 Thai required ligatures feature to tokens | ||
*/ | ||
|
||
import { ContextParams } from '../../tokenizer.js'; | ||
import applySubstitution from '../applySubstitution.js'; | ||
|
||
/** | ||
* Update context params | ||
* @param {any} tokens a list of tokens | ||
* @param {number} index current item index | ||
*/ | ||
function getContextParams(tokens, index) { | ||
const context = tokens.map(token => token.activeState.value); | ||
return new ContextParams(context, index || 0); | ||
} | ||
|
||
/** | ||
* Apply Thai required glyphs composition substitutions | ||
* @param {ContextRange} range a range of tokens | ||
*/ | ||
function thaiRequiredLigatures(range) { | ||
const script = 'thai'; | ||
let tokens = this.tokenizer.getRangeTokens(range); | ||
let contextParams = getContextParams(tokens, 0); | ||
contextParams.context.forEach((glyphIndex, index) => { | ||
contextParams.setCurrentIndex(index); | ||
let substitutions = this.query.lookupFeature({ | ||
tag: 'rlig', script, contextParams | ||
}); | ||
if (substitutions.length) { | ||
substitutions.forEach( | ||
action => applySubstitution(action, tokens, index) | ||
); | ||
contextParams = getContextParams(tokens, index); | ||
} | ||
}); | ||
} | ||
|
||
export default thaiRequiredLigatures; |
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
Binary file not shown.