Skip to content

Commit

Permalink
replace forEach() in new thai features
Browse files Browse the repository at this point in the history
  • Loading branch information
Connum authored and yne committed Mar 9, 2023
1 parent 74e189e commit 66c9899
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 18 deletions.
6 changes: 3 additions & 3 deletions src/bidi.js
Original file line number Diff line number Diff line change
Expand Up @@ -200,12 +200,12 @@ function applyUnicodeVariationSequences() {
function applyThaiFeatures() {
checkGlyphIndexStatus.call(this);
const ranges = this.tokenizer.getContextRanges('thaiWord');
ranges.forEach(range => {
for(let i = 0; i < ranges.length; i++) {
const range = ranges[i];
if (this.hasFeatureEnabled('thai', 'liga')) thaiLigatures.call(this, range);
if (this.hasFeatureEnabled('thai', 'rlig')) thaiRequiredLigatures.call(this, range);
if (this.hasFeatureEnabled('thai', 'ccmp')) thaiGlyphComposition.call(this, range);
});

}
}

/**
Expand Down
11 changes: 6 additions & 5 deletions src/features/thai/thaiGlyphComposition.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,18 +23,19 @@ function thaiGlyphComposition(range) {
const script = 'thai';
let tokens = this.tokenizer.getRangeTokens(range);
let contextParams = getContextParams(tokens, 0);
contextParams.context.forEach((glyphIndex, index) => {
for(let index = 0; index < contextParams.context.length; index++) {
contextParams.setCurrentIndex(index);
let substitutions = this.query.lookupFeature({
tag: 'ccmp', script, contextParams
});
if (substitutions.length) {
substitutions.forEach(
action => applySubstitution(action, tokens, index)
);
for(let i = 0; i < substitutions.length; i++) {
const action = substitutions[i];
applySubstitution(action, tokens, index);
}
contextParams = getContextParams(tokens, index);
}
});
}
}

export default thaiGlyphComposition;
14 changes: 9 additions & 5 deletions src/features/thai/thaiLigatures.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
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
Expand All @@ -23,18 +26,19 @@ function thaiLigatures(range) {
const script = 'thai';
let tokens = this.tokenizer.getRangeTokens(range);
let contextParams = getContextParams(tokens, 0);
contextParams.context.forEach((glyphIndex, index) => {
for(let index = 0; index < contextParams.context.length; index++) {
contextParams.setCurrentIndex(index);
let substitutions = this.query.lookupFeature({
tag: 'liga', script, contextParams
});
if (substitutions.length) {
substitutions.forEach(
action => applySubstitution(action, tokens, index)
);
for(let i = 0; i < substitutions.length; i++) {
const action = substitutions[i];
applySubstitution(action, tokens, index);
}
contextParams = getContextParams(tokens, index);
}
});
}
}

export default thaiLigatures;
14 changes: 9 additions & 5 deletions src/features/thai/thaiRequiredLigatures.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@
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
Expand All @@ -23,18 +26,19 @@ function thaiRequiredLigatures(range) {
const script = 'thai';
let tokens = this.tokenizer.getRangeTokens(range);
let contextParams = getContextParams(tokens, 0);
contextParams.context.forEach((glyphIndex, index) => {
for(let index = 0; index < contextParams.context.length; index++) {
contextParams.setCurrentIndex(index);
let substitutions = this.query.lookupFeature({
tag: 'rlig', script, contextParams
});
if (substitutions.length) {
substitutions.forEach(
action => applySubstitution(action, tokens, index)
);
for(let i = 0; i < substitutions.length; i++) {
const action = substitutions[i];
applySubstitution(action, tokens, index);
}
contextParams = getContextParams(tokens, index);
}
});
}
}

export default thaiRequiredLigatures;

0 comments on commit 66c9899

Please sign in to comment.