Skip to content
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

handle endchar command with seac parameters (standard encoding accented characters) #633

Merged
merged 1 commit into from
Nov 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 46 additions & 1 deletion src/tables/cff.js
Original file line number Diff line number Diff line change
Expand Up @@ -824,7 +824,52 @@ function parseCFFCharstring(font, glyph, code, version) {
break;
}

if (stack.length > 0 && !haveWidth) {
if (stack.length >= 4) {
// Type 2 Charstring Format Appendix C
// treat like Type 1 seac command (standard encoding accented character)
const acharName = cffStandardEncoding[stack.pop()];
const bcharName = cffStandardEncoding[stack.pop()];
const ady = stack.pop();
const adx = stack.pop();
// const asb = stack.pop(); // ignored for Type 2
if ( acharName && bcharName ) {
glyph.isComposite = true;
glyph.components = [];

const acharGlyphIndex = font.cffEncoding.charset.indexOf(acharName);
const bcharGlyphIndex = font.cffEncoding.charset.indexOf(bcharName);

glyph.components.push({
glyphIndex: bcharGlyphIndex,
dx: 0,
dy: 0
});
glyph.components.push({
glyphIndex: acharGlyphIndex,
dx: adx,
dy: ady
});
p.extend(font.glyphs.get(bcharGlyphIndex).path);
const acharGlyph = font.glyphs.get(acharGlyphIndex);
const shiftedCommands = JSON.parse(JSON.stringify(acharGlyph.path.commands)); // make a deep clone
for (let i = 0; i < shiftedCommands.length; i += 1) {
const cmd = shiftedCommands[i];
if (cmd.type !== 'Z') {
cmd.x += adx;
cmd.y += ady;
}
if ( cmd.type === 'Q' || cmd.type === 'C' ) {
cmd.x1 += adx;
cmd.y1 += ady;
}
if ( cmd.type === 'C' ) {
cmd.x2 += adx;
cmd.y2 += ady;
}
}
p.extend(shiftedCommands);
}
} else if (stack.length > 0 && !haveWidth) {
width = stack.shift() + nominalWidthX;
haveWidth = true;
}
Expand Down
Binary file added test/fonts/AbrilFatface-Regular.otf
Binary file not shown.
5 changes: 5 additions & 0 deletions test/fonts/LICENSE
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
AbrilFatface-Regular.otf
Copyright (c) 2011, Copyright (c) 2011, TypeTogether (www.type-together.com [email protected]), with Reserved Font Names “Abril” and “Abril Fatface”
SIL Open Font License, Version 1.1.
https://www.fontsquirrel.com/license/abril-fatface

Changa-Regular.ttf
Copyright 2011 Eduardo Tunni (www.tipo.net.ar)
SIL Open Font License, Version 1.1.
Expand Down
13 changes: 13 additions & 0 deletions test/tables/cff.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,4 +138,17 @@ describe('tables/cff.js', function () {
{ type: 'L', x: 50, y: 500 }
] );
});

it('can handle standard encoding accented characters via endchar', function() {
const font = loadSync('./test/fonts/AbrilFatface-Regular.otf', { lowMemory: true });
const glyph13 = font.glyphs.get(13); // the semicolon is combined of comma and period
const commands = glyph13.path.commands;
assert.equal(glyph13.isComposite, true);
assert.equal(commands.length, 15);
assert.deepEqual(commands[0], { type: 'M', x: 86, y: -156 });
assert.deepEqual(commands[7], { type: 'C', x: 74, y: -141, x1: 174, y1: -35, x2: 162, y2: -66 });
assert.deepEqual(commands[9], { type: 'M', x: 36, y: 407 });
assert.deepEqual(commands[13], { type: 'C', x: 36, y: 407, x1: 66, y1: 495, x2: 36, y2: 456 });
assert.deepEqual(commands[14], { type: 'Z' });
});
});
Loading