Skip to content

Commit

Permalink
Allow the user to customize the characters' width freely (#554).
Browse files Browse the repository at this point in the history
  • Loading branch information
be5invis committed Jun 7, 2020
1 parent 275fc23 commit 966838a
Show file tree
Hide file tree
Showing 9 changed files with 163 additions and 115 deletions.
10 changes: 5 additions & 5 deletions build-plans.toml
Original file line number Diff line number Diff line change
Expand Up @@ -360,7 +360,7 @@ snapshotFamily = 'iosevka-aile'
design = ["diversity-2"]

[buildPlans.iosevka-aile.widths.normal]
shape = 7
shape = 576
menu = 5
css = "normal"

Expand All @@ -379,7 +379,7 @@ snapshotFamily = 'iosevka-etoile'
design = ["diversity-1"]

[buildPlans.iosevka-etoile.widths.normal]
shape = 7
shape = 576
menu = 5
css = "normal"

Expand All @@ -398,7 +398,7 @@ snapshotFamily = 'iosevka-sparkle'
design = ["diversity-1"]

[buildPlans.iosevka-sparkle.widths.normal]
shape = 7
shape = 576
menu = 5
css = "normal"

Expand Down Expand Up @@ -614,12 +614,12 @@ italic = "italic"
# and "menu" only support 1 ... 9

[widths.normal]
shape = 5
shape = 500
menu = 5
css = "normal"

[widths.extended]
shape = 7
shape = 576
menu = 7
css = "expanded"

1 change: 1 addition & 0 deletions changes/3.2.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,3 +9,4 @@
* Add parenthesis variant with larger contour (#570).
* Fix placement of U+0315 COMBINING COMMA ABOVE RIGHT (#583).
* Fix shape of U+1D24 LATIN LETTER VOICED LARYNGEAL SPIRANT (#584).
* Allow the user to customize the characters' width freely (#554).
5 changes: 4 additions & 1 deletion gen/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,10 @@ async function getParameters(argv) {
const rawVariantsData = await tryParseToml(VARIANTS_TOML);
const rawLigationData = await tryParseToml(LIGATIONS_TOML);

const para = Parameters.build(parametersData, argv.hives, { shapeWeight: argv.shape.weight });
const para = Parameters.build(parametersData, argv.hives, {
shapeWeight: argv.shape.weight,
shapeWidth: argv.shape.width
});

const variantsData = FormVariantData(rawVariantsData, para);
para.variants = variantsData;
Expand Down
41 changes: 18 additions & 23 deletions params/parameters.toml
Original file line number Diff line number Diff line change
Expand Up @@ -271,7 +271,18 @@ spacing = 0
# NOTE: this section is highly experimental
# HANDLE WITH EXTREME CARE
# Expanded : I heard someone want it being wider...
[wd-9.multiplies]
[shapeWidth.multiplies.blend.500]
width = 1
stroke = 1
sb = 1
jut = 1
longjut = 1
rhook = 1
rbalance = 1
tbalance = 1
smallsmooth = 1

[shapeWidth.multiplies.blend.664]
width = 1.328 # 664 for normal char
stroke = 1.103 # Make strokes a little thicker
sb = 1.777
Expand All @@ -282,10 +293,7 @@ rbalance = 1.236
tbalance = 1.210
smallsmooth = 1.103

[ultra-extended]
inherits = ['wd-9']

[wd-8.multiplies]
[shapeWidth.multiplies.blend.618]
width = 1.236 # 618 for normal char
stroke = 1.075 # Make strokes a little thicker
sb = 1.539
Expand All @@ -296,10 +304,7 @@ rbalance = 1.236
tbalance = 1.154
smallsmooth = 1.075

[extra-extended]
inherits = ['wd-8']

[wd-7.multiplies]
[shapeWidth.multiplies.blend.576]
width = 1.152 # 576mem for normal char
stroke = 1.050 # Make strokes a little thicker
sb = 1.333
Expand All @@ -310,10 +315,7 @@ rbalance = 1.152
tbalance = 1.100
smallsmooth = 1.050

[extended]
inherits = ['wd-7']

[wd-6.multiplies]
[shapeWidth.multiplies.blend.537]
width = 1.074 # 537mem for normal char
stroke = 1.023 # Make strokes a little thicker
sb = 1.154
Expand All @@ -324,10 +326,7 @@ rbalance = 1.074
tbalance = 1.049
smallsmooth = 1.023

[semi-extended]
inherits = ['wd-6']

[wd-4.multiplies]
[shapeWidth.multiplies.blend.466]
width = 0.932 # 466mem for normal char
stroke = 0.975
sb = 0.866
Expand All @@ -338,10 +337,7 @@ rbalance = 0.931
tbalance = 0.953
smallsmooth = 0.975

[semi-condensed]
inherits = ['wd-4']

[wd-3.multiplies]
[shapeWidth.multiplies.blend.434]
width = 0.868 # 434mem for normal char
stroke = 0.952
sb = 0.750
Expand All @@ -352,8 +348,7 @@ rbalance = 0.868
tbalance = 0.909
smallsmooth = 0.952

[condensed]
inherits = ['wd-3']
###### Diversity

[diversity-1]
diversityM = 1.25
Expand Down
16 changes: 9 additions & 7 deletions private-build-plans.sample.toml
Original file line number Diff line number Diff line change
Expand Up @@ -49,18 +49,20 @@ oblique = "oblique"
# Override default building widths
# When buildPlans.<plan name>.widths is absent, all widths would built and mapped to
# default values.
# IMPORTANT : Currently "shape" property only supports integers between 3 and 9 (inclusive), while
# "menu" only supports integers between 1 and 9 (inclusive).
# If you decide to use custom widths you have to define all the widths you
# plan to use otherwise they will not be built.
# IMPORTANT : Currently "shape" property only supports numbers between 434 and 664 (inclusive),
# while "menu" only supports integers between 1 and 9 (inclusive).
# The "shape" parameter specifies the unit width, measured in 1/1000 em. The glyphs'
# width are equal to, or a simple multiple of the unit width.
# If you decide to use custom widths you have to define all the widths you plan to use,
# otherwise they will not be built.

[buildPlans.iosevka-custom.widths.normal]
shape = 5 # Width grade of glyph shapes. NOT actual character width.
menu = 5 # Width grade for the font's names. NOT actual character width.
shape = 500 # Unit Width, measured in 1/1000 em.
menu = 5 # Width grade for the font's names.
css = "normal" # "font-stretch' property of webfont CSS.

[buildPlans.iosevka-custom.widths.extended]
shape = 7
shape = 576
menu = 7
css = "expanded"

Expand Down
31 changes: 0 additions & 31 deletions support/param-blend.js

This file was deleted.

100 changes: 100 additions & 0 deletions support/parameters.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
"use strict";

const monotonicInterpolate = require("./monotonic-interpolate");

function build(parametersData, styles, blendArgs) {
const sink = {};
for (const item of styles) intro(parametersData, item, blendArgs, sink);
return sink;
}
exports.build = build;

function intro(source, style, blendArgs, sink) {
let hive = source[style];
if (!hive) return;
hive = { ...hive };

if (hive.inherits) {
for (const hn of hive.inherits) intro(source, hn, blendArgs, sink);
delete hive.inherits;
}
if (hive.multiplies) {
const mu = hiveBlend(hive.multiplies, getBlendArg(blendArgs, style), sink);
for (const k in mu) sink[k] = (sink[k] || 0) * mu[k];
delete hive.multiplies;
}
if (hive.adds) {
const mu = hiveBlend(hive.adds, getBlendArg(blendArgs, style), sink);
for (const k in mu) sink[k] = (sink[k] || 0) + mu[k];
delete hive.adds;
}
if (hive.appends) {
const mu = hive.appends;
for (const k in mu) sink[k] = [...(sink[k] || []), ...mu[k]];
delete hive.appends;
}
hive = hiveBlend(hive, getBlendArg(blendArgs, style), sink);
for (const k in hive) sink[k] = hive[k];
}

function getBlendArg(blendArgs, style) {
if (!blendArgs) return undefined;
return blendArgs[style];
}

function hiveBlend(hive, value, sink) {
if (!hive || !hive.blend || value == null) return hive;

const generatedHive = {};
const block = hive.blend;
let keys = new Set();
for (const grade in block) {
sink[grade] = block[grade];
if (!isFinite(parseFloat(grade))) continue;
for (const key in block[grade]) {
if (block[grade][key] == null) continue;
keys.add(key);
}
}

for (const key of keys) {
let xs = [],
ys = [];
for (const grade in block) {
if (!isFinite(parseFloat(grade))) continue;
if (block[grade][key] == null) continue;
xs.push(grade);
ys.push(block[grade][key]);
}
generatedHive[key] = monotonicInterpolate(xs, ys)(value);
}
return generatedHive;
}

function numericConfigExists(x) {
return x != null && isFinite(x);
}
function applyMetricOverride(para, mo) {
if (numericConfigExists(mo.leading)) {
para.leading = mo.leading;
}
if (numericConfigExists(mo.winMetricAscenderPad)) {
para.winMetricAscenderPad = mo.winMetricAscenderPad;
}
if (numericConfigExists(mo.winMetricDescenderPad)) {
para.winMetricDescenderPad = mo.winMetricDescenderPad;
}
if (numericConfigExists(mo.powerlineScaleY)) {
para.powerlineScaleY = mo.powerlineScaleY;
}
if (numericConfigExists(mo.powerlineScaleX)) {
para.powerlineScaleX = mo.powerlineScaleX;
}
if (numericConfigExists(mo.powerlineShiftY)) {
para.powerlineShiftY = mo.powerlineShiftY;
}
if (numericConfigExists(mo.powerlineShiftX)) {
para.powerlineShiftX = mo.powerlineShiftX;
}
}
exports.applyMetricOverride = applyMetricOverride;
43 changes: 0 additions & 43 deletions support/parameters.ptl

This file was deleted.

Loading

0 comments on commit 966838a

Please sign in to comment.