Skip to content

Commit

Permalink
Make the WWS.inherits consistent with variants inheritance configurat…
Browse files Browse the repository at this point in the history
…ion (#2251)

* Make the WWS.inherits consistent with variants inheritance configuration

* doc refine
  • Loading branch information
be5invis authored Mar 22, 2024
1 parent a7b4790 commit 96456df
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 26 deletions.
27 changes: 11 additions & 16 deletions doc/custom-build.md
Original file line number Diff line number Diff line change
Expand Up @@ -100,22 +100,6 @@ Subsection `ligations` is used to customize the ligation set assigned to `calt`

* `inherits`: Optional, String, defines the inherited ligation set. When absent, the ligation set will not inherit any other sets. Valid values are:

- `--default-center-ops--`: Default ligation set would be assigned to undefined.
- `--c-center-ops--`: Default ligation set would be assigned to undefined.
- `--default-equality-inequality--`: Default ligation set would be assigned to undefined.
- `--c-equality-inequality--`: Default ligation set would be assigned to undefined.
- `--raku-equality-inequality--`: Default ligation set would be assigned to undefined.
- `--ml-equality-inequality--`: Default ligation set would be assigned to undefined.
- `--fstar-equality-inequality--`: Default ligation set would be assigned to undefined.
- `--haskell-equality-inequality--`: Default ligation set would be assigned to undefined.
- `--matlab-equality-inequality--`: Default ligation set would be assigned to undefined.
- `--verilog-equality-inequality--`: Default ligation set would be assigned to undefined.
- `--wolfram-equality-inequality--`: Default ligation set would be assigned to undefined.
- `--erlang-equality-inequality--`: Default ligation set would be assigned to undefined.
- `--default-kern--`: Default ligation set would be assigned to undefined.
- `--default-chaining--`: Default ligation set would be assigned to undefined.
- `--fast-chaining--`: Default ligation set would be assigned to undefined.
- `--c-like-chaining--`: Default ligation set would be assigned to undefined.
- `default-calt`: Inherit default ligation set.
- `dlig`: Default ligation set would be assigned to Discretionary ligatures.
- `clike`: Default ligation set would be assigned to C-Like.
Expand Down Expand Up @@ -3213,6 +3197,17 @@ Subsection `slopes` is used to change the slope angles and grades that the custo
* `menu`: String from `upright`, `italic` or `oblique`. Configures the slope grade used when naming fonts.
* `css`: String from `normal`, `italic` or `oblique`. Configures the [CSS font-style](https://developer.mozilla.org/zh-CN/docs/Web/CSS/font-style) value.

In addition to list all the weights/widths/slopes directly, the user could also configure the weights/widths/slopes list using “inherits” to inherit the list from another build plan:

```toml
[buildPlans.IosevkaCustom2]
family = "Iosevka Custom 2"

weights.inherits = "buildPlans.IosevkaCustom1" # Inherit weights list from "IosevkaCustom1"
widths.inherits = "buildPlans.IosevkaCustom1" # Inherit widths list from "IosevkaCustom1"
slopes.inherits = "default" # Inherit slopes list from default
```

#### Compatibility Ligatures

Certain software, notably Emacs, relies on pre-encoded ligatures instead of OpenType to provide ligations. Iosevka could be configured with additional subsection `compatibilityLigatures`, being an array of records with following fields:
Expand Down
1 change: 1 addition & 0 deletions tools/amend-readme/src/sections/lig-set-pre-def.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export default async function processLigSetPreDef(argv, dirs) {
const headerPath = path.resolve(dirs.fragments, "description-predefined-ligation-sets.md");
md.log(await fs.promises.readFile(headerPath, "utf-8"));
for (const gr in ligData.rawSets) {
if (!ligData.rawSets[gr].desc) continue;
const readmeDesc =
ligData.rawSets[gr].readmeDesc ||
`Default ligation set would be assigned to ${ligData.rawSets[gr].desc}`;
Expand Down
53 changes: 43 additions & 10 deletions verdafile.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -1272,22 +1272,48 @@ function resolveWws(bpName, buildPlans, defaultConfig) {
function resolveWwsAspect(aspectName, bpName, buildPlans, defaultConfig, deps) {
const bp = buildPlans[bpName];
if (!bp) fail(`Build plan ${bpName} not found.`);
if (deps.includes(bp)) {
fail(`Circular dependency detected when resolving ${aspectName} of ${bp.family}.`);
}
const updatedDeps = [...deps, bpName];

if (bp[aspectName]) {
return shimBpAspect(aspectName, bp[aspectName], defaultConfig[aspectName]);
const aspect = bp[aspectName];
if (typeof aspect.inherits == "string") {
if (aspect.inherits === "default") {
return defaultConfig[aspectName];
} else {
// Make sure it start with `buildPlans.`
if (!aspect.inherits.startsWith("buildPlans.")) {
fail(
`Invalid \`inherits\`2 value for ${aspectName} in ${bpName}. ` +
`It must be \`default\` or start with \`buildPlans.\`.`,
);
}
const inheritedPlanName = aspect.inherits.slice("buildPlans.".length);
return resolveWwsAspect(
aspectName,
inheritedPlanName,
buildPlans,
defaultConfig,
updatedDeps,
);
}
} else {
return shimBpAspect(aspectName, bp[aspectName], defaultConfig[aspectName]);
}
} else if (bp[`${aspectName}-inherits`]) {
echo.warn(
`The ${aspectName}-inherits syntax is deprecated. ` +
`Use the new syntax \`${aspectName}.inherits = "buildPlans.<plan name>\` instead.`,
);
const inheritedPlanName = bp[`${aspectName}-inherits`];
const inheritedPlan = buildPlans[inheritedPlanName];
if (deps.includes(inheritedPlan))
fail(`Circular dependency detected when resolving ${aspectName} of ${bp.family}.`);

const updatedDes = [...deps, bpName];
return resolveWwsAspect(
aspectName,
inheritedPlanName,
buildPlans,
defaultConfig,
updatedDes,
updatedDeps,
);
} else {
return defaultConfig[aspectName];
Expand All @@ -1304,11 +1330,18 @@ function shimBpAspect(aspectName, aspect, defaultAspect) {
}
function shimBpAspectKey(aspectName, sink, k, v, defaultAspect) {
if (typeof v === "string") {
if (!/^default\./.test(v))
throw new Error(`Invalid configuration '${v}' for ${aspectName}.${k}'`);
if (!v.startsWith("default."))
throw new Error(
`Invalid configuration '${v}' for ${aspectName}.${k}'. ` +
`It must start with 'default.'`,
);
const remappingKey = v.slice("default.".length);
if (!defaultAspect[remappingKey])
throw new Error(`Invalid configuration '${v}' for ${aspectName}.${k}'`);
throw new Error(
`Invalid configuration '${v}' for ${aspectName}.${k}'. ` +
`The default aspect doesn't have a key '${remappingKey}'.`,
);

sink[k] = defaultAspect[remappingKey];
} else {
sink[k] = v;
Expand Down

0 comments on commit 96456df

Please sign in to comment.