-
Notifications
You must be signed in to change notification settings - Fork 507
Feature/ccmp #688
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Feature/ccmp #688
Changes from 16 commits
0979cba
ecf2f79
85db1a7
86d86bd
76effae
9f1e134
56d4612
d346d0a
afca906
97ae7a3
cbd1cf5
b2321ab
d626e78
8987892
75e6451
7eb2bde
5517e76
8ec646c
7afb593
9d2d970
6c8e37f
2befe8a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
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 | ||
Connum marked this conversation as resolved.
Show resolved
Hide resolved
|
||
* @param {ContextRange} range a range of tokens | ||
*/ | ||
function ccmpReplacementLigatures(range) { | ||
const script = 'delf'; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I guess this should be 'DFLT'? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is the only place in the codebase with There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry this made it through the review process, I didn't follow up because it was marked as resolved. Good catch, thanks! @TonyJR could you comment on this please? I think it should be DFLT for the default script. And for the future, please let reviewers resolve the conversations. :) |
||
const tag = 'ccmp'; | ||
let tokens = this.tokenizer.getRangeTokens(range); | ||
let contextParams = getContextParams(tokens); | ||
for(let index = 0; index < contextParams.context.length; index++) { | ||
if (!this.query.getFeature({tag, script, contextParams})){ | ||
continue; | ||
} | ||
contextParams.setCurrentIndex(index); | ||
let substitutions = this.query.lookupFeature({ | ||
tag, script, contextParams | ||
}); | ||
if (substitutions.length) { | ||
for(let i = 0; i < substitutions.length; i++) { | ||
const action = substitutions[i]; | ||
applySubstitution(action, tokens, index); | ||
} | ||
contextParams = getContextParams(tokens); | ||
} | ||
} | ||
} | ||
|
||
export default ccmpReplacementLigatures; | ||
|
||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
function ccmpReplacementStartCheck(contextParams) { | ||
return contextParams.index === 0 && contextParams.context.length > 1; | ||
} | ||
|
||
function ccmpReplacementEndCheck(contextParams) { | ||
return contextParams.index === contextParams.context.length - 1; | ||
} | ||
|
||
export default { | ||
startCheck: ccmpReplacementStartCheck, | ||
endCheck: ccmpReplacementEndCheck | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import assert from 'assert'; | ||
TonyJR marked this conversation as resolved.
Show resolved
Hide resolved
|
||
import { parse } from '../src/opentype.js'; | ||
import { readFileSync } from 'fs'; | ||
const loadSync = (url, opt) => parse(readFileSync(url), opt); | ||
|
||
describe('noto emoji with ccmp', () => { | ||
let notoEmojiFont; | ||
let substitution; | ||
before(()=> { | ||
notoEmojiFont = loadSync('./test/fonts/noto-emoji.ttf'); | ||
}); | ||
|
||
describe('ccmp features', () => { | ||
|
||
it('shape emoji with sub_0', () => { | ||
let options = { | ||
kerning: true, | ||
language: 'dflt', | ||
features: [ | ||
{ script: 'DFLT', tags: ['ccmp'] }, | ||
] | ||
}; | ||
let glyphIndexes = notoEmojiFont.stringToGlyphIndexes('👨👩👧👦👨👩👧',options); | ||
assert.deepEqual(glyphIndexes, [1463,1462]); | ||
}); | ||
|
||
it('shape emoji with sub_5', () => { | ||
let options = { | ||
kerning: true, | ||
language: 'dflt', | ||
features: [ | ||
{ script: 'DFLT', tags: ['ccmp'] }, | ||
] | ||
}; | ||
let glyphIndexes = notoEmojiFont.stringToGlyphIndexes('🇺🇺',options); | ||
assert.deepEqual(glyphIndexes, [1850]); | ||
}); | ||
}); | ||
}); |
Uh oh!
There was an error while loading. Please reload this page.