Add quick reuse of default weight/width/slope grades in customized build (#1215).
This commit is contained in:
parent
a6052e1a1c
commit
32f88103de
3 changed files with 28 additions and 7 deletions
|
@ -2955,19 +2955,19 @@ Subsection `variants` is used to configure character variants in the font. Prope
|
||||||
|
|
||||||
#### Configuring Weights, Widths and Slopes
|
#### Configuring Weights, Widths and Slopes
|
||||||
|
|
||||||
Subsection `weights` is used to change the weight grades that the custom family needs. It is a dictionary of sub-objects with properties:
|
Subsection `weights` is used to change the weight grades that the custom family needs. It is a dictionary of either strings formatted in `default.<weight>` format, meaning reusing a default weight grade, or sub-objects with properties:
|
||||||
|
|
||||||
* `shape`: Number, configures the weight grade of the glyphs' shapes.
|
* `shape`: Number, configures the weight grade of the glyphs' shapes.
|
||||||
* `menu`: Integer, configures the weight grade used when naming fonts.
|
* `menu`: Integer, configures the weight grade used when naming fonts.
|
||||||
* `css`: Integer, configures the weight grade used in web font CSS.
|
* `css`: Integer, configures the weight grade used in web font CSS.
|
||||||
|
|
||||||
Subsection `widths` is used to change the width grades that the custom family needs. It is a dictionary of sub-objects with properties:
|
Subsection `widths` is used to change the width grades that the custom family needs. It is a dictionary of either strings formatted in `default.<width>` format, meaning reusing a default width grade, or sub-objects with properties:
|
||||||
|
|
||||||
* `shape`: Number, configures the width of the glyphs' shapes, measured in 1/1000 em.
|
* `shape`: Number, configures the width of the glyphs' shapes, measured in 1/1000 em.
|
||||||
* `menu`: Integer, configures the width grade used when naming fonts. The valid values are `1` to `9`, inclusive.
|
* `menu`: Integer, configures the width grade used when naming fonts. The valid values are `1` to `9`, inclusive.
|
||||||
* `css`: String, configures the [font-stretch](https://developer.mozilla.org/en-US/docs/Web/CSS/font-stretch) value used in web font CSS.
|
* `css`: String, configures the [font-stretch](https://developer.mozilla.org/en-US/docs/Web/CSS/font-stretch) value used in web font CSS.
|
||||||
|
|
||||||
Subsection `slopes` is used to change the slope angles and grades that the custom family needs. It is a dictionary of sub-objects with properties:
|
Subsection `slopes` is used to change the slope angles and grades that the custom family needs. It is a dictionary of either strings formatted in `default.<slope>` format, meaning reusing a default slope grade, or sub-objects with properties:
|
||||||
|
|
||||||
* `angle`: Number, configures the slope angle in degrees. The valid vales are `0` to `15`, inclusive.
|
* `angle`: Number, configures the slope angle in degrees. The valid vales are `0` to `15`, inclusive.
|
||||||
* `shape`: String from `upright`, `italic` or `oblique`. Configures the slope used for variant selection.
|
* `shape`: String from `upright`, `italic` or `oblique`. Configures the slope used for variant selection.
|
||||||
|
|
|
@ -2,3 +2,4 @@
|
||||||
* Refine the alignment of Number Sign (`#`) to align with numbers (#1210).
|
* Refine the alignment of Number Sign (`#`) to align with numbers (#1210).
|
||||||
* Add tailless variants for Greek small Mu (`μ`) (#1211).
|
* Add tailless variants for Greek small Mu (`μ`) (#1211).
|
||||||
* Remove unnecessary serifs of Greek Capital Ksi (`Ξ`) (#1212).
|
* Remove unnecessary serifs of Greek Capital Ksi (`Ξ`) (#1212).
|
||||||
|
* Add quick reuse of default weight/width/slope grades in customized build (#1215).
|
26
verdafile.js
26
verdafile.js
|
@ -925,9 +925,29 @@ function validateAndShimBuildPlans(prefix, bp, dWeights, dSlopes, dWidths) {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
bp.weights = bp.weights || dWeights;
|
bp.weights = shimBpAspect("weights", bp.weights, dWeights);
|
||||||
bp.slopes = bp.slopes || bp.slants || dSlopes;
|
bp.slopes = shimBpAspect("slopes", bp.slopes || bp.slants, dSlopes);
|
||||||
bp.widths = bp.widths || dWidths;
|
bp.widths = shimBpAspect("widths", bp.widths, dWidths);
|
||||||
|
}
|
||||||
|
function shimBpAspect(aspectName, aspect, defaultAspect) {
|
||||||
|
if (!aspect) return defaultAspect;
|
||||||
|
const result = {};
|
||||||
|
for (const [k, v] of Object.entries(aspect)) {
|
||||||
|
shimBpAspectKey(aspectName, result, k, v, defaultAspect);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
function shimBpAspectKey(aspectName, sink, k, v, defaultAspect) {
|
||||||
|
if (typeof v === "string") {
|
||||||
|
if (!/^default\./.test(v))
|
||||||
|
throw new Error(`Invalid configuration '${v}' for ${aspectName}.${k}'`);
|
||||||
|
const remappingKey = v.slice("default.".length);
|
||||||
|
if (!defaultAspect[remappingKey])
|
||||||
|
throw new Error(`Invalid configuration '${v}' for ${aspectName}.${k}'`);
|
||||||
|
sink[k] = defaultAspect[remappingKey];
|
||||||
|
} else {
|
||||||
|
sink[k] = v;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Recommended weight validation
|
// Recommended weight validation
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue