Skip to content

Commit 006d0da

Browse files
committed
Merge with upstream repo
2 parents 72b8e42 + 417af0c commit 006d0da

25 files changed

Lines changed: 459 additions & 75 deletions

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -180,14 +180,14 @@ Fontkit includes several methods for accessing glyph metrics and performing layo
180180

181181
Returns the advance width (described above) for a single glyph id.
182182

183-
#### `font.layout(string, features = [])`
183+
#### `font.layout(string, features = [] | {})`
184184

185185
This method returns a `GlyphRun` object, which includes an array of `Glyph`s and `GlyphPosition`s for the given string.
186186
`Glyph` objects are described below. `GlyphPosition` objects include 4 properties: `xAdvance`, `yAdvance`, `xOffset`,
187187
and `yOffset`.
188188

189-
The `features` parameter is an array of [OpenType feature tags](https://www.microsoft.com/typography/otspec/featuretags.htm) to be applied
190-
in addition to the default set. If this is an AAT font, the OpenType feature tags are mapped to AAT features.
189+
The `features` parameter is either an array of [OpenType feature tags](https://www.microsoft.com/typography/otspec/featuretags.htm) to be applied
190+
in addition to the default set, or an object mapping OpenType features to a boolean enabling or disabling each. If this is an AAT font, the OpenType feature tags are mapped to AAT features.
191191

192192
### Variation fonts
193193

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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",

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
/**

src/opentype/GSUBProcessor.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,14 @@ export default class GSUBProcessor extends OTProcessor {
2828
let index = this.coverageIndex(table.coverage);
2929
if (index !== -1) {
3030
let sequence = table.sequences.get(index);
31+
32+
if (sequence.length === 0) {
33+
// If the sequence length is zero, delete the glyph.
34+
// The OpenType spec disallows this, but seems like Harfbuzz and Uniscribe allow it.
35+
this.glyphs.splice(this.glyphIterator.index, 1);
36+
return true;
37+
}
38+
3139
this.glyphIterator.cur.id = sequence[0];
3240
this.glyphIterator.cur.ligatureComponent = 0;
3341

0 commit comments

Comments
 (0)