refactored the process of weight assigning.

This commit is contained in:
belleve 2018-07-20 17:57:57 +08:00
parent 7436a059d3
commit b4ba453ad8
15 changed files with 137 additions and 119 deletions

View file

@ -173,20 +173,45 @@ from = [
"iosevka-cc-slab"
]
# Weight mappings (style => CSS)
# Weight mappings (style => shape weight, CSS weight)
# Shape weight : affects the shape of the glyphs
# CSS weight : affects the font menu name and webfont CSS
# Comment the lines to build less weights
# NOTE: This mapping does NOT affect the font's metadata, only affects
# the webfont CSS. Change `parameters.toml` instead.
[weights]
thin = 100
extralight = 200
light = 300
book = 400
medium = 500
semibold = 600
bold = 700
extrabold = 800
heavy = 900
[weights.thin]
shape = 100
css = 100
[weights.extralight]
shape = 200
css = 200
[weights.light]
shape = 300
css = 300
[weights.regular]
shape = 400
css = 400
[weights.medium]
shape = 500
css = 500
[weights.semibold]
shape = 600
css = 600
[weights.bold]
shape = 700
css = 700
[weights.extrabold]
shape = 800
css = 800
[weights.heavy]
shape = 900
css = 900
# Slant mappings (style => CSS)
# NOTE: This mapping does NOT affect the font's metadata, only affects

View file

@ -108,8 +108,14 @@ function getParameters(argv) {
para.variants = variantsData;
para.variantSelector = parameters.build(variantsData, argv._);
para.defaultVariant = variantsData.default;
if (argv.family) para.family = argv.family;
if (argv.ver) para.version = argv.ver;
para.naming = {
family: argv.family,
version: argv.ver,
weight: argv.weight - 0,
slant: argv.slant
};
return para;
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 123 KiB

After

Width:  |  Height:  |  Size: 123 KiB

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 22 KiB

After

Width:  |  Height:  |  Size: 22 KiB

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 129 KiB

After

Width:  |  Height:  |  Size: 130 KiB

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 422 KiB

After

Width:  |  Height:  |  Size: 422 KiB

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 191 KiB

After

Width:  |  Height:  |  Size: 191 KiB

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 180 KiB

After

Width:  |  Height:  |  Size: 180 KiB

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 356 KiB

After

Width:  |  Height:  |  Size: 356 KiB

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 805 KiB

After

Width:  |  Height:  |  Size: 805 KiB

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 82 KiB

After

Width:  |  Height:  |  Size: 82 KiB

Before After
Before After

Binary file not shown.

Before

Width:  |  Height:  |  Size: 342 KiB

After

Width:  |  Height:  |  Size: 341 KiB

Before After
Before After

View file

@ -29,41 +29,65 @@ define [nameFont font nameid str] : begin
nameID nameid
nameString str
define weightToMenuStyleMap : object
100 "Thin"
200 "Extralight"
300 "Light"
400 ""
500 "Medium"
600 "Semibold"
700 "Bold"
800 "Extrabold"
900 "Heavy"
define slantToMenuStyleMap : object
normal ""
italic "Italic"
oblique "Oblique"
define [getStyle weight slant] : [(weightToMenuStyleMap.(weight) + " " + slantToMenuStyleMap.(slant)).trim] || "Regular"
export : define [assignFontNames para metrics font] : begin
set font.name {}
set para.family [para.family.trim]
set para.style : [para.style.trim] || "Regular"
define family : para.naming.family.trim
define style : getStyle para.naming.weight para.naming.slant
define version para.naming.version
nameFont font PREFERRED_FAMILY para.family # Preferred Family
nameFont font PREFERRED_STYLE para.style # Preferred Style
nameFont font WWS_PREFERRED_FAMILY para.family # WWS Preferred Family
nameFont font WWS_PREFERRED_STYLE para.style # WWS Preferred Style
define isItalic : para.naming.slant == "italic"
define isOblique : para.naming.slant == "oblique"
define isBold : para.naming.weight > 650
set font.name.preferredFamily para.family
set font.name.preferredSubFamily para.style
if (para.style == 'Regular' || para.style == 'Bold' || para.style == 'Italic' || para.style == "Bold Italic") : then
nameFont font FAMILY para.family # Family
nameFont font STYLE para.style # Style
nameFont font PREFERRED_FAMILY family # Preferred Family
nameFont font PREFERRED_STYLE style # Preferred Style
nameFont font WWS_PREFERRED_FAMILY family # WWS Preferred Family
nameFont font WWS_PREFERRED_STYLE style # WWS Preferred Style
set font.name.preferredFamily family
set font.name.preferredSubFamily style
if (style == 'Regular' || style == 'Bold' || style == 'Italic' || style == "Bold Italic") : then
nameFont font FAMILY family # Family
nameFont font STYLE style # Style
: else
local compatFamilySuffix : para.style.replace [regex ' Italic$'] '' :.replace [regex ' Extra'] 'X'
local compatStyle : if [[regex ' Italic$'].test para.style] 'Italic' 'Regular'
nameFont font FAMILY : para.family + ' ' + compatFamilySuffix
local compatFamilySuffix : style.replace [regex ' Italic$'] '' :.replace [regex ' Extra'] 'X'
local compatStyle : if [[regex ' Italic$'].test style] 'Italic' 'Regular'
nameFont font FAMILY : family + ' ' + compatFamilySuffix
nameFont font STYLE compatStyle
nameFont font UNIQUE_NAME "\(para.family) \(para.style) \(para.version)" # Unique Name
nameFont font UNIQUE_NAME "\(family) \(style) \(version)" # Unique Name
local fontfullName : if (para.style != 'Regular') (para.family + ' ' + para.style) para.family
local fontfullName : if (style != 'Regular') (family + ' ' + style) family
nameFont font FULL_NAME fontfullName # Full Name
nameFont font POSTSCRIPT : fontfullName.replace [regex ' ' 'g'] '-' # Postscript
nameFont font VERSION para.version # Version
nameFont font VERSION version # Version
nameFont font COPYRIGHT para.copyright # Copyright
nameFont font COPYRIGHT para.copyright # Copyright
nameFont font MANUFACTURER para.manufacturer # Manufacturer
nameFont font DESIGNER para.designer # Designer
nameFont font DESCRIPTION para.description # Description
nameFont font LICENCE para.licence # Licence
nameFont font DESIGNER para.designer # Designer
nameFont font DESCRIPTION para.description # Description
nameFont font LICENCE para.licence # Licence
set font.name : font.name.sort : lambda [a b] : begin
if (a.platformID != b.platformID) : return : a.platformID - b.platformID
@ -72,18 +96,18 @@ export : define [assignFontNames para metrics font] : begin
return : a.nameID - b.nameID
# Weight, width and slantness
set font.OS_2.usWeightClass para.weight
set font.OS_2.usWeightClass para.naming.weight
set font.OS_2.panose.3 9 # Monospaced
set font.OS_2.panose.2 : 1 + para.weight / 100
set font.OS_2.panose.2 : 1 + para.naming.weight / 100
set font.OS_2.fsSelection : object
oblique : not : not para.isOblique
bold : not : not para.isBold
italic : not : not (para.isItalic || para.isOblique)
regular : not : not ([not para.isBold] && [not para.isItalic] && [not para.isOblique])
oblique : not : not isOblique
bold : not : not isBold
italic : not : not (isItalic || isOblique)
regular : not : not ([not isBold] && [not isItalic] && [not isOblique])
useTypoMetrics true
set font.OS_2.sFamilyClass : 8 * 0x100 + 9
set font.post.isFixedPitch true
set font.OS_2.xAvgCharWidth para.width
set font.head.macStyle : object
bold : not : not para.isBold
italic : not : not (para.isItalic || para.isOblique)
bold : not : not isBold
italic : not : not (isItalic || isOblique)

View file

@ -59,8 +59,8 @@ jbalance = 63
fbalance = 6
onebalance = 30
isBold = false # Mark the font as bold?
isItalic = false # Use italic shapes?
isOblique = false # Use oblique shapes?
lllcrowdedness = 3.33333333
@ -82,10 +82,7 @@ noCJKV = true
verbose = true
### Weights
[w-thin]
weight = 100
style = 'Thin'
[w-100]
stroke = 18
sb = 72
dotsize = 53
@ -97,10 +94,7 @@ vtipfine = 1
shoulderfine = 0.8
pbarpos = 0.5
[w-extralight]
weight = 200
style = 'Extralight'
[w-200]
stroke = 36
sb = 68
dotsize = 70
@ -111,10 +105,7 @@ cthinb = 0.75
vtipfine = 1
pbarpos = 0.5
[w-light]
weight = 300
style = 'Light'
[w-300]
stroke = 56
sb = 64
dotsize = 100
@ -123,53 +114,39 @@ periodsize = 115
vtipfine = 0.9
pbarpos = 0.51
[w-book]
isBold = false
weight = 400 # "Weight" metadata.
style = ''
[w-400]
sb = 60 # Side bearing.
stroke = 72 # Stroke width of horizontal strokes.
dotsize = 125 # "Visual" size of dots in /i.
periodsize = 140 # "Visual" size of period.
[w-medium]
weight = 500
style = 'Medium'
[w-500]
sb = 57
stroke = 81
dotsize = 133
periodsize = 158
stroke = 84
dotsize = 135
periodsize = 160
smooth = 200
[w-semibold]
weight = 600
style = 'Semibold'
[w-600]
sb = 54
stroke = 92
dotsize = 140
periodsize = 165
stroke = 97
dotsize = 145
periodsize = 168
essx = 1.07
rbalance = 55
rbalance2 = 20
smooth = 203
[w-bold]
isBold = true
weight = 700
style = 'Bold'
[w-700]
sb = 50
stroke = 102
dotsize = 152
periodsize = 176
stroke = 106
dotsize = 157
periodsize = 180
essx = 1.06
essxq = 1.10
jut = 87
vjut = 155
jut = 89
vjut = 158
barpos = 0.51
fivebarpos = 0.64
@ -178,32 +155,24 @@ rbalance2 = 23
rhook = 95
smooth = 206
[w-extrabold]
isBold = true
weight = 800
style = 'Extrabold'
[w-800]
sb = 45
stroke = 112
dotsize = 164
periodsize = 184
stroke = 116
dotsize = 167
periodsize = 188
essx = 1.05
essxq = 1.15
jut = 94
vjut = 170
jut = 96
vjut = 172
barpos = 0.51
fivebarpos = 0.64
rbalance = 50
rbalance2 = 25
rhook = 97
smooth = 212
[w-heavy]
isBold = true
weight = 900
style = 'Heavy'
smooth = 210
[w-900]
sb = 42
stroke = 126
dotsize = 180
@ -221,27 +190,16 @@ rhook = 105
smooth = 215
### Slantness
[s-upright]
isItalic = false
[s-italic]
isItalic = true
slantAngle = 10
jhook = 120
[s-italic.adds]
style = " Italic"
[s-oblique]
isOblique = true
isItalic = false
slantAngle = 10
jhook = 120
[s-oblique.adds]
style = " Oblique"
### Slab variant
[slab]
slab = true

View file

@ -83,13 +83,13 @@ oracle(`o:suffixes`).def(async target => {
for (const w in weights) {
for (const s in slants) {
const suffix =
(w === "book" ? (s === "upright" ? "regular" : "") : w) +
(w === "regular" ? (s === "upright" ? "regular" : "") : w) +
(s === "upright" ? "" : s);
mapping[suffix] = {
hives: [`w-${w}`, `s-${s}`],
hives: [`w-${weights[w].shape}`, `s-${s}`],
weight: w,
slant: s,
cssWeight: weights[w],
cssWeight: weights[w].css,
cssStyle: slants[s]
};
}
@ -173,17 +173,22 @@ oracle("collection-parts-of:*").def(async (target, id) => {
///////////////////////////////////////////////////////////
file(`${BUILD}/*/*.ttf`).def(async (target, prefix, suffix) => {
const [{ hives, family }, version] = await target.need(`hives-of:${suffix}`, `o:version`);
const [{ hives, family, cssWeight, cssStyle }, version] = await target.need(
`hives-of:${suffix}`,
`o:version`
);
const otd = target.path.dir + "/" + target.path.name + ".otd";
const charmap = target.path.dir + "/" + target.path.name + ".charmap";
await target.need("scripts", "parameters.toml", `dir:${target.path.dir}`);
await run(
GENERATE,
hives,
["-o", otd],
["--charmap", charmap],
["--family", family],
["--ver", version]
["--ver", version],
["--weight", cssWeight],
["--slant", cssStyle],
hives
);
await run("otfccbuild", otd, "-o", target.path.full, "-O3", "--keep-average-char-width");
await rm(otd);