-
Notifications
You must be signed in to change notification settings - Fork 501
/
Copy pathlatinLigatures.js
44 lines (39 loc) · 1.36 KB
/
latinLigatures.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
/**
* Apply Latin ligature feature to a range of tokens
*/
import { ContextParams } from '../../tokenizer.js';
import applySubstitution from '../applySubstitution.js';
// @TODO: use commonFeatureUtils.js for reduction of code duplication
// once #564 has been merged.
/**
* 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 Arabic required ligatures to a context range
* @param {ContextRange} range a range of tokens
*/
function latinLigature(range) {
const script = 'latn';
let tokens = this.tokenizer.getRangeTokens(range);
let contextParams = getContextParams(tokens);
for(let index = 0; index < contextParams.context.length; index++) {
contextParams.setCurrentIndex(index);
let substitutions = this.query.lookupFeature({
tag: 'liga', script, contextParams
});
if (substitutions.length) {
for(let i = 0; i < substitutions.length; i++) {
const action = substitutions[i];
applySubstitution.call(this, action, tokens, index);
}
contextParams = getContextParams(tokens);
}
}
}
export default latinLigature;