Skip to content

Commit 570d285

Browse files
committed
treat endchar operator with 4 arguments as seac operator (fix foliojs#322)
1 parent a5fe0a1 commit 570d285

File tree

5 files changed

+125
-2
lines changed

5 files changed

+125
-2
lines changed

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
],
1414
"scripts": {
1515
"test": "run-s build mocha",
16-
"mocha": "mocha",
16+
"mocha": "mocha -g \"seac\"",
1717
"build": "parcel build",
1818
"prepublish": "run-s clean trie:** build",
1919
"trie:data": "node src/opentype/shapers/generate-data.js",

src/glyph/CFFGlyph.js

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import Glyph from './Glyph';
22
import Path from './Path';
3+
import { StandardEncoding } from '../cff/CFFEncodings';
4+
import CFFStandardStrings from '../cff/CFFStandardStrings';
35

46
/**
57
* Represents an OpenType PostScript glyph, in the Compact Font Format.
@@ -57,6 +59,9 @@ export default class CFFGlyph extends Glyph {
5759
let vsindex = privateDict.vsindex;
5860
let variationProcessor = this._font._variationProcessor;
5961

62+
let encodingVector;
63+
const font = this._font;
64+
6065
function checkWidth() {
6166
if (width == null) {
6267
width = stack.shift() + privateDict.nominalWidthX;
@@ -80,6 +85,14 @@ export default class CFFGlyph extends Glyph {
8085
path.moveTo(x, y);
8186
open = true;
8287
}
88+
89+
function glyphForName(name) {
90+
if (!encodingVector) {
91+
encodingVector = cff.topDict.charset.glyphs.map(g => CFFStandardStrings[g]);
92+
}
93+
const glyphId = Math.max(0, encodingVector.indexOf(name) + 1); // .notdef is not included, hence + 1
94+
return font.getGlyph(glyphId);
95+
};
8396

8497
let parse = function () {
8598
while (stream.pos < end) {
@@ -168,7 +181,23 @@ export default class CFFGlyph extends Glyph {
168181
break;
169182
}
170183

171-
if (stack.length > 0) {
184+
if(stack.length >= 4) {
185+
// Type 2 Charstring Format Appendix C
186+
// treat like Type 1 seac command (standard encoding accented character)
187+
const acharName = StandardEncoding?.[stack.pop()];
188+
const bcharName = StandardEncoding?.[stack.pop()];
189+
const ady = stack.pop();
190+
const adx = stack.pop();
191+
// const asb = stack.pop(); // ignored for Type 2
192+
193+
const achar = glyphForName(acharName);
194+
const bchar = glyphForName(bcharName);
195+
196+
const aPathShifted = achar.path.translate(adx, ady);
197+
path.commands = [...bchar.path.commands, ...aPathShifted.commands];
198+
199+
open = false;
200+
} else if (stack.length > 0) {
172201
checkWidth();
173202
}
174203

test/data/unicode/OFL.txt

Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
TestCFFThree
2+
Copyright © 2023 Unicode, Inc.
3+
4+
This Font Software is licensed under the SIL Open Font License, Version 1.1.
5+
This license is copied below, and is also available with a FAQ at:
6+
http://scripts.sil.org/OFL
7+
8+
---------------------------------------------------------------------------
9+
SIL OPEN FONT LICENSE Version 1.1 - 26 February 2007
10+
---------------------------------------------------------------------------
11+
12+
PREAMBLE
13+
14+
The goals of the Open Font License (OFL) are to stimulate worldwide development
15+
of collaborative font projects, to support the font creation efforts of academic
16+
and linguistic communities, and to provide a free and open framework in which
17+
fonts may be shared and improved in partnership with others.
18+
19+
The OFL allows the licensed fonts to be used, studied, modified and redistributed
20+
freely as long as they are not sold by themselves. The fonts, including any
21+
derivative works, can be bundled, embedded, redistributed and/or sold with any
22+
software provided that any reserved names are not used by derivative works. The
23+
fonts and derivatives, however, cannot be released under any other type of license.
24+
The requirement for fonts to remain under this license does not apply to any
25+
document created using the fonts or their derivatives.
26+
27+
DEFINITIONS
28+
29+
"Font Software" refers to the set of files released by the Copyright Holder(s) under
30+
this license and clearly marked as such. This may include source files, build
31+
scripts and documentation.
32+
33+
"Reserved Font Name" refers to any names specified as such after the copyright
34+
statement(s).
35+
36+
"Original Version" refers to the collection of Font Software components as
37+
distributed by the Copyright Holder(s).
38+
39+
"Modified Version" refers to any derivative made by adding to, deleting, or
40+
substituting -- in part or in whole -- any of the components of the Original Version,
41+
by changing formats or by porting the Font Software to a new environment.
42+
43+
"Author" refers to any designer, engineer, programmer, technical writer or other
44+
person who contributed to the Font Software.
45+
46+
PERMISSION & CONDITIONS
47+
48+
Permission is hereby granted, free of charge, to any person obtaining a copy of the
49+
Font Software, to use, study, copy, merge, embed, modify, redistribute, and sell
50+
modified and unmodified copies of the Font Software, subject to the following
51+
conditions:
52+
53+
1) Neither the Font Software nor any of its individual components, in Original or
54+
Modified Versions, may be sold by itself.
55+
56+
2) Original or Modified Versions of the Font Software may be bundled, redistributed
57+
and/or sold with any software, provided that each copy contains the above copyright
58+
notice and this license. These can be included either as stand-alone text files,
59+
human-readable headers or in the appropriate machine-readable metadata fields within
60+
text or binary files as long as those fields can be easily viewed by the user.
61+
62+
3) No Modified Version of the Font Software may use the Reserved Font Name(s) unless
63+
explicit written permission is granted by the corresponding Copyright Holder. This
64+
restriction only applies to the primary font name as presented to the users.
65+
66+
4) The name(s) of the Copyright Holder(s) or the Author(s) of the Font Software shall
67+
not be used to promote, endorse or advertise any Modified Version, except to
68+
acknowledge the contribution(s) of the Copyright Holder(s) and the Author(s) or with
69+
their explicit written permission.
70+
71+
5) The Font Software, modified or unmodified, in part or in whole, must be distributed
72+
entirely under this license, and must not be distributed under any other license. The
73+
requirement for fonts to remain under this license does not apply to any document
74+
created using the Font Software.
75+
76+
TERMINATION
77+
78+
This license becomes null and void if any of the above conditions are not met.
79+
80+
DISCLAIMER
81+
82+
THE FONT SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
83+
INCLUDING BUT NOT LIMITED TO ANY WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
84+
PARTICULAR PURPOSE AND NONINFRINGEMENT OF COPYRIGHT, PATENT, TRADEMARK, OR OTHER
85+
RIGHT. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
86+
LIABILITY, INCLUDING ANY GENERAL, SPECIAL, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES,
87+
WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF THE USE OR
88+
INABILITY TO USE THE FONT SOFTWARE OR FROM OTHER DEALINGS IN THE FONT SOFTWARE.

test/data/unicode/TestCFFThree.otf

2.64 KB
Binary file not shown.

test/glyphs.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,12 @@ describe('glyphs', function () {
138138
let glyph = font.getGlyph(5);
139139
return assert.equal(glyph.name, 'D');
140140
});
141+
142+
it('should handle seac-like endchar operators', function () {
143+
let font2 = fontkit.openSync(new URL('data/unicode/TestCFFThree.otf', import.meta.url));
144+
assert.equal(font2.getGlyph(3).path.toSVG(), 'M203 367C227 440 248 512 268 588L272 588C293 512 314 440 338 367L369 267L172 267ZM3 0L88 0L151 200L390 200L452 0L541 0L319 656L225 656ZM300 653L342 694L201 861L143 806Z');
145+
assert.equal(font2.getGlyph(4).path.toSVG(), 'M323 -12C457 -12 558 60 558 271L558 656L478 656L478 269C478 111 410 61 323 61C237 61 170 111 170 269L170 656L87 656L87 271C87 60 189 -12 323 -12ZM220 727C248 727 269 749 269 777C269 805 248 827 220 827C191 827 170 805 170 777C170 749 191 727 220 727ZM412 727C441 727 462 749 462 777C462 805 441 827 412 827C384 827 363 805 363 777C363 749 384 727 412 727Z');
146+
})
141147
});
142148

143149
describe('CFF glyphs (CID font)', function () {

0 commit comments

Comments
 (0)