diff --git a/src/tables/sfnt.mjs b/src/tables/sfnt.mjs index 3d8b9428..6e526f64 100644 --- a/src/tables/sfnt.mjs +++ b/src/tables/sfnt.mjs @@ -292,16 +292,17 @@ function fontToSfntTable(font) { const fontNamesWindows = font.names.windows || {}; // do this as a loop to reduce redundant code - for (const platform in ['unicode', 'macintosh', 'windows']) { + for (const platform in names) { names[platform] = names[platform] || {}; if (!names[platform].uniqueID) { - names.unicode.uniqueID = {en: font.getEnglishName('manufacturer') + ':' + englishFullName}; + const manufacturer = font.getEnglishName('manufacturer') || ''; + names[platform].uniqueID = { en: `${manufacturer}: ${englishFullName}` }; } if (!names[platform].postScriptName) { - names.unicode.postScriptName = {en: postScriptName}; + names[platform].postScriptName = {en: postScriptName}; } } diff --git a/test/tables/sfnt.spec.mjs b/test/tables/sfnt.spec.mjs index 0c4d9110..a6acd8e5 100644 --- a/test/tables/sfnt.spec.mjs +++ b/test/tables/sfnt.spec.mjs @@ -1,7 +1,7 @@ import assert from 'assert'; import Font from '../../src/font.mjs'; -import sfnt from '../../src/tables/sfnt.mjs'; import name from '../../src/tables/name.mjs'; +import sfnt from '../../src/tables/sfnt.mjs'; import { encode } from '../../src/types.mjs'; function encodeAndParseTable(table, parser) { @@ -60,7 +60,8 @@ describe('tables/sfnt.mjs', function () { license: { en: ' ' }, licenseURL: { en: ' ' }, preferredFamily: { en: defaultFont.familyName }, // 'MyFont' - preferredSubfamily: { en: defaultFont.styleName } // 'Medium' + preferredSubfamily: { en: defaultFont.styleName }, // 'Medium' + uniqueID: { en: ` : ${defaultFont.familyName} ${defaultFont.styleName}` }, }, windows: { copyright: { en: ' ' }, @@ -78,7 +79,8 @@ describe('tables/sfnt.mjs', function () { license: { en: ' ' }, licenseURL: { en: ' ' }, preferredFamily: { en: defaultFont.familyName }, // 'MyFont' - preferredSubfamily: { en: defaultFont.styleName } // 'Medium' + preferredSubfamily: { en: defaultFont.styleName }, // 'Medium' + uniqueID: { en: ` : ${defaultFont.familyName} ${defaultFont.styleName}` }, } }); }); @@ -121,7 +123,9 @@ describe('tables/sfnt.mjs', function () { fullName: { en: fullName }, version: { en: version }, preferredFamily: { en: preferredFamily }, - preferredSubfamily: { en: preferredSubfamily} + preferredSubfamily: { en: preferredSubfamily }, + postScriptName: { en: `${fontFamily.replaceAll(' ', '')}-${fontSubfamily}` }, + uniqueID: { en: `: ${fontFamily} ${fontSubfamily}` }, }, windows: { fontFamily: { en: fontFamily }, @@ -129,7 +133,9 @@ describe('tables/sfnt.mjs', function () { fullName: { en: fullName }, version: { en: version }, preferredFamily: { en: preferredFamily }, - preferredSubfamily: { en: preferredSubfamily} + preferredSubfamily: { en: preferredSubfamily}, + postScriptName: { en: `${fontFamily.replaceAll(' ', '')}-${fontSubfamily}` }, + uniqueID: { en: `: ${fontFamily} ${fontSubfamily}` }, } }); });