Skip to content

Commit f8108ec

Browse files
authored
Bug fix for #757 - write all name table entries for fonts crafted from scratch (#758)
* Main bug fix - `for...in` loop iterates over keys in `names` object, not indexes of an array of strings - if `uniqueID` or `postScriptName` is found to be missing, update the platform that is currently being looped over, not just the `unicode` platform. * Added tests for new name table entries Test now checks for defaults for `postScriptName` and also `uniqueID` Generating a `uniqueID` now provides a fallback empty string if no `manufacturer` exists.
1 parent 52d167f commit f8108ec

File tree

2 files changed

+15
-8
lines changed

2 files changed

+15
-8
lines changed

src/tables/sfnt.mjs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -292,16 +292,17 @@ function fontToSfntTable(font) {
292292
const fontNamesWindows = font.names.windows || {};
293293

294294
// do this as a loop to reduce redundant code
295-
for (const platform in ['unicode', 'macintosh', 'windows']) {
295+
for (const platform in names) {
296296

297297
names[platform] = names[platform] || {};
298298

299299
if (!names[platform].uniqueID) {
300-
names.unicode.uniqueID = {en: font.getEnglishName('manufacturer') + ':' + englishFullName};
300+
const manufacturer = font.getEnglishName('manufacturer') || '';
301+
names[platform].uniqueID = { en: `${manufacturer}: ${englishFullName}` };
301302
}
302303

303304
if (!names[platform].postScriptName) {
304-
names.unicode.postScriptName = {en: postScriptName};
305+
names[platform].postScriptName = {en: postScriptName};
305306
}
306307
}
307308

test/tables/sfnt.spec.mjs

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import assert from 'assert';
22
import Font from '../../src/font.mjs';
3-
import sfnt from '../../src/tables/sfnt.mjs';
43
import name from '../../src/tables/name.mjs';
4+
import sfnt from '../../src/tables/sfnt.mjs';
55
import { encode } from '../../src/types.mjs';
66

77
function encodeAndParseTable(table, parser) {
@@ -60,7 +60,8 @@ describe('tables/sfnt.mjs', function () {
6060
license: { en: ' ' },
6161
licenseURL: { en: ' ' },
6262
preferredFamily: { en: defaultFont.familyName }, // 'MyFont'
63-
preferredSubfamily: { en: defaultFont.styleName } // 'Medium'
63+
preferredSubfamily: { en: defaultFont.styleName }, // 'Medium'
64+
uniqueID: { en: ` : ${defaultFont.familyName} ${defaultFont.styleName}` },
6465
},
6566
windows: {
6667
copyright: { en: ' ' },
@@ -78,7 +79,8 @@ describe('tables/sfnt.mjs', function () {
7879
license: { en: ' ' },
7980
licenseURL: { en: ' ' },
8081
preferredFamily: { en: defaultFont.familyName }, // 'MyFont'
81-
preferredSubfamily: { en: defaultFont.styleName } // 'Medium'
82+
preferredSubfamily: { en: defaultFont.styleName }, // 'Medium'
83+
uniqueID: { en: ` : ${defaultFont.familyName} ${defaultFont.styleName}` },
8284
}
8385
});
8486
});
@@ -121,15 +123,19 @@ describe('tables/sfnt.mjs', function () {
121123
fullName: { en: fullName },
122124
version: { en: version },
123125
preferredFamily: { en: preferredFamily },
124-
preferredSubfamily: { en: preferredSubfamily}
126+
preferredSubfamily: { en: preferredSubfamily },
127+
postScriptName: { en: `${fontFamily.replaceAll(' ', '')}-${fontSubfamily}` },
128+
uniqueID: { en: `: ${fontFamily} ${fontSubfamily}` },
125129
},
126130
windows: {
127131
fontFamily: { en: fontFamily },
128132
fontSubfamily: { en: fontSubfamily},
129133
fullName: { en: fullName },
130134
version: { en: version },
131135
preferredFamily: { en: preferredFamily },
132-
preferredSubfamily: { en: preferredSubfamily}
136+
preferredSubfamily: { en: preferredSubfamily},
137+
postScriptName: { en: `${fontFamily.replaceAll(' ', '')}-${fontSubfamily}` },
138+
uniqueID: { en: `: ${fontFamily} ${fontSubfamily}` },
133139
}
134140
});
135141
});

0 commit comments

Comments
 (0)