Allowed customizing menu WWS value to name map (#2488). (#2535)

This commit is contained in:
Belleve 2024-10-06 12:32:42 -10:00 committed by GitHub
parent b5acd21122
commit 4d19a20610
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 70 additions and 23 deletions

View file

@ -3,3 +3,4 @@
* Optimize glyphs for cursive variants for Greek Lower Beta (`β`) and Cyrillic Lower Ve (`в`). * Optimize glyphs for cursive variants for Greek Lower Beta (`β`) and Cyrillic Lower Ve (`в`).
* Optimize glyphs for Volapük Ae/Oe/Ue (`U+A79A`..`U+A79F`). * Optimize glyphs for Volapük Ae/Oe/Ue (`U+A79A`..`U+A79F`).
* Optimize glyph for Cyrillic Lower Dzze (`U+A689`) under italics. * Optimize glyph for Cyrillic Lower Dzze (`U+A689`) under italics.
* Allowed customizing menu WWS value to name map (#2488).

View file

@ -3634,8 +3634,29 @@ The properties in the `namingOverride` section could be uase to override menu na
- `urlDesigner`: Name ID 12, URL of typeface designer. - `urlDesigner`: Name ID 12, URL of typeface designer.
- `license` (or alternatively `licence`): Name ID 13, license description. - `license` (or alternatively `licence`): Name ID 13, license description.
- `licenseURL` (or alternatively `licenceURL`): Name ID 14, license Info URL. - `licenseURL` (or alternatively `licenceURL`): Name ID 14, license Info URL.
- `version`: Override font version. The version number should follow [SemVer](https://semver.org/), like being `1.0.0`.
In addition, you can also use the `version` property to override font version. The version number should follow [SemVer](https://semver.org/), like being `1.0.0`. Additionally, the `namingOverride` section now supports a `menuNameMap` configuration property. This property allows for the customization of menu names based on specific attributes related to the font's style and characteristics. The `menuNameMap` configuration is structured as follows:
- `weight`: A mapping of menu weight numbers to their corresponding names.
- `width`: A mapping of menu width numbers to their corresponding names.
- `slope`: A mapping of menu slope values (`"normal"`/`"italic"`/`"oblique"`) to their corresponding names.
- `weightShort`: A mapping of menu weight numbers to short names.
- `widthShort`: A mapping of menu width numbers to short names.
- `slopeShort`: A mapping of menu slope values (`"normal"`/`"italic"`/`"oblique"`) to short names.
You are allowed to provide override names only for the values that you want to have custom names. Any values not specified in these mappings will use the default names.
For example, the following configuration:
```toml
[buildPlans.IosevkaCustom.namingOverride.menuNameMap.width]
7 = "Expanded"
[buildPlans.IosevkaCustom.namingOverride.menuNameMap.widthShort]
7 = "Exp"
```
... will name width 7 to "Expanded" in full, and "Exp" in short.
#### Sample Configuration #### Sample Configuration

View file

@ -12,6 +12,19 @@ export function createNamingDictFromArgv(argv) {
weight: argv.menu.weight - 0, weight: argv.menu.weight - 0,
width: argv.menu.width - 0, width: argv.menu.width - 0,
slope: argv.menu.slope, slope: argv.menu.slope,
menuNameMap: {
weight: { ...WeightToMenuMap, ...argv.namingOverride?.menuNameMap?.weight },
width: { ...WidthToMenuMap, ...argv.namingOverride?.menuNameMap?.width },
slope: { ...SlopeToMenuMap, ...argv.namingOverride?.menuNameMap?.slope },
weightShort: {
...WeightToMenuShortMap,
...argv.namingOverride?.menuNameMap?.weightShort,
},
widthShort: { ...WidthToMenuShortMap, ...argv.namingOverride?.menuNameMap?.widthShort },
slopeShort: { ...SlopeToMenuShortMap, ...argv.namingOverride?.menuNameMap?.slopeShort },
},
}; };
} }
@ -26,7 +39,7 @@ export function assignFontNames(font, naming, isQuasiProportional) {
function setMainNames(font, naming) { function setMainNames(font, naming) {
// Preferred names // Preferred names
const family = naming.family.trim(); const family = naming.family.trim();
const style = getStyle(naming.weight, naming.width, naming.slope); const style = getStyle(naming.menuNameMap, naming.weight, naming.width, naming.slope);
nameFont(font, Ot.Name.NameID.PreferredFamily, family); nameFont(font, Ot.Name.NameID.PreferredFamily, family);
nameFont(font, Ot.Name.NameID.PreferredSubfamily, style); nameFont(font, Ot.Name.NameID.PreferredSubfamily, style);
@ -34,7 +47,12 @@ function setMainNames(font, naming) {
nameFont(font, Ot.Name.NameID.WwsSubfamily, style); nameFont(font, Ot.Name.NameID.WwsSubfamily, style);
// Compat names // Compat names
const compat = getStyleLinkedStyles(naming.weight, naming.width, naming.slope); const compat = getStyleLinkedStyles(
naming.menuNameMap,
naming.weight,
naming.width,
naming.slope,
);
let compatFamily = family; let compatFamily = family;
if (compat.familySuffix !== "Regular") compatFamily = family + " " + compat.familySuffix; if (compat.familySuffix !== "Regular") compatFamily = family + " " + compat.familySuffix;
if (compatFamily.length >= 31) compatFamily = family + " " + compat.familySuffixShort; if (compatFamily.length >= 31) compatFamily = family + " " + compat.familySuffixShort;
@ -155,7 +173,7 @@ function applyMiscProps(font) {
); );
} }
///////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////
function accumulateFlags(...entries) { function accumulateFlags(...entries) {
let s = 0; let s = 0;
@ -165,7 +183,7 @@ function accumulateFlags(...entries) {
return s; return s;
} }
function getStyleLinkedStyles(weight, width, slope) { function getStyleLinkedStyles(menuNameMap, weight, width, slope) {
let linkWeight = weight; let linkWeight = weight;
let linkSlope = slope; let linkSlope = slope;
let nameSuffixWeight = 400; let nameSuffixWeight = 400;
@ -183,9 +201,14 @@ function getStyleLinkedStyles(weight, width, slope) {
} }
return { return {
style: getStyle(linkWeight, 5, linkSlope), style: getStyle(menuNameMap, linkWeight, 5, linkSlope),
familySuffix: getStyle(nameSuffixWeight, nameSuffixWidth, nameSuffixSlope), familySuffix: getStyle(menuNameMap, nameSuffixWeight, nameSuffixWidth, nameSuffixSlope),
familySuffixShort: getShortStyle(nameSuffixWeight, nameSuffixWidth, nameSuffixSlope), familySuffixShort: getShortStyle(
menuNameMap,
nameSuffixWeight,
nameSuffixWidth,
nameSuffixSlope,
),
}; };
} }
@ -205,22 +228,24 @@ function nameFontImpl(records, platformID, encodingID, languageID, nameID, value
records.push({ platformID, encodingID, languageID, nameID, value }); records.push({ platformID, encodingID, languageID, nameID, value });
} }
function getStyle(weight, width, slope) { function getStyle(menuNameMap, weight, width, slope) {
const weightPart = weightToMenuStyleMap[weight] ?? "W" + weight; const weightPart = menuNameMap.weight[weight] ?? "W" + weight;
const widthPart = widthToMenuStyleMap[width] ?? "Wd" + width; const widthPart = menuNameMap.width[width] ?? "Wd" + width;
const slopePart = slopeToMenuStyleMap[slope] ?? ""; const slopePart = menuNameMap.slope[slope] ?? "";
const rawName = weightPart + " " + widthPart + " " + slopePart; const rawName = weightPart + " " + widthPart + " " + slopePart;
return rawName.replace(/ +/g, " ").trim() || "Regular"; return rawName.replace(/ +/g, " ").trim() || "Regular";
} }
function getShortStyle(weight, width, slope) { function getShortStyle(menuNameMap, weight, width, slope) {
const weightPart = weightToMenuStyleMapShort[weight] ?? "W" + weight; const weightPart = menuNameMap.weightShort[weight] ?? "W" + weight;
const widthPart = widthToMenuStyleMapShort[width] ?? "Wd" + width; const widthPart = menuNameMap.widthShort[width] ?? "Wd" + width;
const slopePart = slopeToMenuStyleMapShort[slope] ?? ""; const slopePart = menuNameMap.slopeShort[slope] ?? "";
const rawName = weightPart + " " + widthPart + " " + slopePart; const rawName = weightPart + " " + widthPart + " " + slopePart;
return rawName.replace(/ +/g, " ").trim() || "Regular"; return rawName.replace(/ +/g, " ").trim() || "Regular";
} }
const weightToMenuStyleMap = { ///////////////////////////////////////////////////////////////////////////////////////////////////
const WeightToMenuMap = {
100: "Thin", 100: "Thin",
200: "Extralight", 200: "Extralight",
300: "Light", 300: "Light",
@ -233,7 +258,7 @@ const weightToMenuStyleMap = {
800: "Extrabold", 800: "Extrabold",
900: "Heavy", 900: "Heavy",
}; };
const widthToMenuStyleMap = { const WidthToMenuMap = {
1: "Ultra-Condensed", 1: "Ultra-Condensed",
2: "Extra-Condensed", 2: "Extra-Condensed",
3: "Condensed", 3: "Condensed",
@ -244,12 +269,12 @@ const widthToMenuStyleMap = {
8: "Extra-Extended", 8: "Extra-Extended",
9: "Ultra-Extended", 9: "Ultra-Extended",
}; };
const slopeToMenuStyleMap = { const SlopeToMenuMap = {
normal: "", normal: "",
italic: "Italic", italic: "Italic",
oblique: "Oblique", oblique: "Oblique",
}; };
const weightToMenuStyleMapShort = { const WeightToMenuShortMap = {
100: "Th", 100: "Th",
200: "XLt", 200: "XLt",
300: "Lt", 300: "Lt",
@ -262,7 +287,7 @@ const weightToMenuStyleMapShort = {
800: "XBd", 800: "XBd",
900: "Hv", 900: "Hv",
}; };
const widthToMenuStyleMapShort = { const WidthToMenuShortMap = {
1: "UltCn", 1: "UltCn",
2: "XCn", 2: "XCn",
3: "Cn", 3: "Cn",
@ -273,13 +298,13 @@ const widthToMenuStyleMapShort = {
8: "XEx", 8: "XEx",
9: "UltEx", 9: "UltEx",
}; };
const slopeToMenuStyleMapShort = { const SlopeToMenuShortMap = {
normal: "", normal: "",
italic: "It", italic: "It",
oblique: "Obl", oblique: "Obl",
}; };
///////////////////////////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////////////////////////
function ancNameEntry(input) { function ancNameEntry(input) {
return input.replace(/\{\{currentYear\}\}/g, () => String(new Date().getFullYear())); return input.replace(/\{\{currentYear\}\}/g, () => String(new Date().getFullYear()));