Skip to content

Commit 9f9b6be

Browse files
authored
Merge pull request #1 from Cryptact/feat-fix-subsetting
feat: fix Asian font subsets, update `package.json` and `README.md`
2 parents 72b8e42 + 2bc56ce commit 9f9b6be

26 files changed

Lines changed: 578 additions & 160 deletions

.github/workflows/publish.yml

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
name: Publish Package to npmjs
2+
on:
3+
release:
4+
types: [published]
5+
jobs:
6+
build:
7+
runs-on: ubuntu-latest
8+
steps:
9+
- uses: actions/checkout@v4
10+
11+
- name: Setup Node.js
12+
uses: actions/setup-node@v4
13+
with:
14+
node-version: "20.x"
15+
registry-url: "https://registry.npmjs.org"
16+
17+
- name: Install dependencies
18+
run: yarn install --frozen-lockfile
19+
20+
- name: Build
21+
run: yarn make
22+
23+
- name: Release latest
24+
run: yarn releaseLatest
25+
env:
26+
NODE_AUTH_TOKEN: ${{ secrets.NPM_TOKEN }}

README.md

Lines changed: 91 additions & 80 deletions
Large diffs are not rendered by default.

package.json

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
2-
"name": "@pdf-lib/fontkit",
3-
"version": "1.1.0",
2+
"name": "@cryptact/fontkit",
3+
"version": "1.2.0",
44
"description": "An advanced font engine for Node and the browser",
55
"main": "dist/fontkit.umd.js",
66
"unpkg": "dist/fontkit.umd.min.js",
@@ -34,14 +34,14 @@
3434
"babel-plugin-istanbul": "^4.1.3",
3535
"base64-arraybuffer": "^0.1.5",
3636
"buffer": "^5.6.0",
37-
"clone": "^1.0.1",
37+
"clone": "^1.0.4",
3838
"codepoints": "^1.2.0",
39-
"concat-stream": "^1.4.6",
39+
"concat-stream": "^1.6.2",
4040
"deep-equal": "^1.0.0",
41-
"dfa": "^1.0.0",
41+
"dfa": "^1.2.0",
4242
"esdoc": "^0.4.8",
4343
"esdoc-es7-plugin": "0.0.3",
44-
"iconv-lite": "^0.4.13",
44+
"iconv-lite": "^0.4.24",
4545
"mocha": "^2.0.1",
4646
"nyc": "^10.3.2",
4747
"rollup": "^2.10.2",
@@ -56,7 +56,7 @@
5656
},
5757
"repository": {
5858
"type": "git",
59-
"url": "git://github.com/Hopding/fontkit.git"
59+
"url": "git://github.com/Cryptact/fontkit.git"
6060
},
6161
"keywords": [
6262
"opentype",
@@ -68,12 +68,9 @@
6868
"layout"
6969
],
7070
"author": "Andrew Dillon <andrew.dillon.j@gmail.com>",
71-
"contributors": [
72-
"Devon Govett <devongovett@gmail.com> (http://badassjs.com/)"
73-
],
7471
"bugs": {
75-
"url": "https://github.com/Hopding/fontkit/issues"
72+
"url": "https://github.com/Cryptact/fontkit/issues"
7673
},
7774
"license": "MIT",
78-
"homepage": "https://github.com/Hopding/fontkit"
75+
"homepage": "https://github.com/Cryptact/fontkit"
7976
}

src/TTFFont.js

Lines changed: 24 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ export default class TTFFont {
2525
}
2626

2727
constructor(stream, variationCoords = null) {
28+
this.defaultLanguage = null;
2829
this.stream = stream;
2930
this.variationCoords = variationCoords;
3031

@@ -44,6 +45,10 @@ export default class TTFFont {
4445
}
4546
}
4647

48+
setDefaultLanguage(lang = null) {
49+
this.defaultLanguage = lang;
50+
}
51+
4752
_getTable(table) {
4853
if (!(table.tag in this._tables)) {
4954
try {
@@ -83,34 +88,36 @@ export default class TTFFont {
8388
return result;
8489
}
8590

86-
/**
87-
* The unique PostScript name for this font
88-
* @type {string}
89-
*/
90-
get postscriptName() {
91-
let name = this.name.records.postscriptName;
92-
if (name) {
93-
let lang = Object.keys(name)[0];
94-
return name[lang];
95-
}
96-
97-
return null;
98-
}
99-
10091
/**
10192
* Gets a string from the font's `name` table
10293
* `lang` is a BCP-47 language code.
10394
* @return {string}
10495
*/
105-
getName(key, lang = 'en') {
106-
let record = this.name.records[key];
96+
getName(key, lang = this.defaultLanguage || fontkit.defaultLanguage) {
97+
let record = this.name && this.name.records[key];
10798
if (record) {
108-
return record[lang];
99+
// Attempt to retrieve the entry, depending on which translation is available:
100+
return (
101+
record[lang]
102+
|| record[this.defaultLanguage]
103+
|| record[fontkit.defaultLanguage]
104+
|| record['en']
105+
|| record[Object.keys(record)[0]] // Seriously, ANY language would be fine
106+
|| null
107+
);
109108
}
110109

111110
return null;
112111
}
113112

113+
/**
114+
* The unique PostScript name for this font, e.g. "Helvetica-Bold"
115+
* @type {string}
116+
*/
117+
get postscriptName() {
118+
return this.getName('postscriptName');
119+
}
120+
114121
/**
115122
* The font's full name, e.g. "Helvetica Bold"
116123
* @type {string}

src/aat/AATMorxProcessor.js

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,17 +44,22 @@ export default class AATMorxProcessor {
4444
}
4545

4646
// Processes an array of glyphs and applies the specified features
47-
// Features should be in the form of {featureType:{featureSetting:true}}
47+
// Features should be in the form of {featureType:{featureSetting:boolean}}
4848
process(glyphs, features = {}) {
4949
for (let chain of this.morx.chains) {
5050
let flags = chain.defaultFlags;
5151

5252
// enable/disable the requested features
5353
for (let feature of chain.features) {
5454
let f;
55-
if ((f = features[feature.featureType]) && f[feature.featureSetting]) {
56-
flags &= feature.disableFlags;
57-
flags |= feature.enableFlags;
55+
if (f = features[feature.featureType]) {
56+
if (f[feature.featureSetting]) {
57+
flags &= feature.disableFlags;
58+
flags |= feature.enableFlags;
59+
} else if (f[feature.featureSetting] === false) {
60+
flags |= ~feature.disableFlags;
61+
flags &= ~feature.enableFlags;
62+
}
5863
}
5964
}
6065

src/base.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,10 @@ const fontkit = {
2525
},
2626
};
2727

28+
fontkit.defaultLanguage = 'en';
29+
fontkit.setDefaultLanguage = function(lang = 'en') {
30+
fontkit.defaultLanguage = lang;
31+
};
32+
2833
export default fontkit;
34+

src/cff/CFFFont.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,7 @@ class CFFFont {
127127

128128
if (gid < ranges[mid].first) {
129129
high = mid - 1;
130-
} else if (mid < high && gid > ranges[mid + 1].first) {
130+
} else if (mid < high && gid >= ranges[mid + 1].first) {
131131
low = mid + 1;
132132
} else {
133133
return ranges[mid].fd;

src/cff/CFFTop.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,9 @@ class CFFPrivateOp {
156156
let FontDict = new CFFDict([
157157
// key name type(s) default
158158
[18, 'Private', new CFFPrivateOp, null],
159-
[[12, 38], 'FontName', 'sid', null]
159+
[[12, 38], 'FontName', 'sid', null],
160+
[[12, 7], 'FontMatrix', 'array', [0.001, 0, 0, 0.001, 0, 0]],
161+
[[12, 5], 'PaintType', 'number', 0],
160162
]);
161163

162164
let CFFTopDict = new CFFDict([

src/glyph/CFFGlyph.js

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,10 +24,8 @@ export default class CFFGlyph extends Glyph {
2424
}
2525

2626
_getPath() {
27-
let { stream } = this._font;
28-
let { pos } = stream;
29-
3027
let cff = this._font.CFF2 || this._font['CFF '];
28+
let { stream } = cff;
3129
let str = cff.topDict.CharStrings[this.id];
3230
let end = str.offset + str.length;
3331
stream.pos = str.offset;
@@ -49,7 +47,7 @@ export default class CFFGlyph extends Glyph {
4947
let gsubrs = cff.globalSubrIndex || [];
5048
let gsubrsBias = this.bias(gsubrs);
5149

52-
let privateDict = cff.privateDictForGlyph(this.id);
50+
let privateDict = cff.privateDictForGlyph(this.id) || {};
5351
let subrs = privateDict.Subrs || [];
5452
let subrsBias = this.bias(subrs);
5553

src/glyph/Path.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,11 @@ export default class Path {
2727
* @return {string}
2828
*/
2929
toFunction() {
30-
return (ctx) => this.commands.forEach((c) => ctx[c.command].apply(ctx, c.args));
30+
return ctx => {
31+
this.commands.forEach(c => {
32+
return ctx[c.command].apply(ctx, c.args)
33+
})
34+
};
3135
}
3236

3337
/**

0 commit comments

Comments
 (0)