Skip to content

Commit

Permalink
[varLib.avarPlanner] Increase target widths
Browse files Browse the repository at this point in the history
  • Loading branch information
behdad committed Jul 23, 2023
1 parent a9fbeda commit e2d7c25
Showing 1 changed file with 31 additions and 6 deletions.
37 changes: 31 additions & 6 deletions Lib/fontTools/varLib/avarPlanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,34 @@
from fontTools.misc.cliTools import makeOutputFileName
from math import exp, log

WEIGHTS = [100, 200, 300, 400, 500, 600, 700, 800, 900]
WEIGHTS = [
50,
100,
150,
200,
250,
300,
350,
400,
450,
500,
550,
600,
650,
700,
750,
800,
850,
900,
950,
]

SAMPLES = 8


def getGlyphsetBlackness(glyphset, frequencies=None):
wght_sum = wdth_sum = 0

Check warning on line 32 in Lib/fontTools/varLib/avarPlanner.py

View check run for this annotation

Codecov / codecov/patch

Lib/fontTools/varLib/avarPlanner.py#L32

Added line #L32 was not covered by tests
for glyph_name in glyphset:

if frequencies is not None:
frequency = frequencies.get(glyph_name, 0)

Check warning on line 35 in Lib/fontTools/varLib/avarPlanner.py

View check run for this annotation

Codecov / codecov/patch

Lib/fontTools/varLib/avarPlanner.py#L35

Added line #L35 was not covered by tests
if frequency == 0:
Expand All @@ -30,7 +49,9 @@ def getGlyphsetBlackness(glyphset, frequencies=None):
return wght_sum / wdth_sum

Check warning on line 49 in Lib/fontTools/varLib/avarPlanner.py

View check run for this annotation

Codecov / codecov/patch

Lib/fontTools/varLib/avarPlanner.py#L49

Added line #L49 was not covered by tests


def planWeightAxis(font, minValue, defaultValue, maxValue, weights=WEIGHTS, frequencies=None):
def planWeightAxis(
font, minValue, defaultValue, maxValue, weights=WEIGHTS, frequencies=None
):
print("Weight min/default/max:", minValue, defaultValue, maxValue)

Check warning on line 55 in Lib/fontTools/varLib/avarPlanner.py

View check run for this annotation

Codecov / codecov/patch

Lib/fontTools/varLib/avarPlanner.py#L55

Added line #L55 was not covered by tests

out = {}
Expand All @@ -40,7 +61,9 @@ def planWeightAxis(font, minValue, defaultValue, maxValue, weights=WEIGHTS, freq
axisWeightAverage = {}

Check warning on line 61 in Lib/fontTools/varLib/avarPlanner.py

View check run for this annotation

Codecov / codecov/patch

Lib/fontTools/varLib/avarPlanner.py#L60-L61

Added lines #L60 - L61 were not covered by tests
for weight in sorted({minValue, defaultValue, maxValue}):
glyphset = font.getGlyphSet(location={"wght": weight})
axisWeightAverage[weight] = getGlyphsetBlackness(glyphset, frequencies) / (upem * upem)
axisWeightAverage[weight] = getGlyphsetBlackness(glyphset, frequencies) / (

Check warning on line 64 in Lib/fontTools/varLib/avarPlanner.py

View check run for this annotation

Codecov / codecov/patch

Lib/fontTools/varLib/avarPlanner.py#L63-L64

Added lines #L63 - L64 were not covered by tests
upem * upem
)

print("Calculated average glyph black ratio:", axisWeightAverage)

Check warning on line 68 in Lib/fontTools/varLib/avarPlanner.py

View check run for this annotation

Codecov / codecov/patch

Lib/fontTools/varLib/avarPlanner.py#L68

Added line #L68 was not covered by tests

Expand All @@ -54,14 +77,16 @@ def planWeightAxis(font, minValue, defaultValue, maxValue, weights=WEIGHTS, freq

bias = -1 if extremeValue < defaultValue else 0

Check warning on line 78 in Lib/fontTools/varLib/avarPlanner.py

View check run for this annotation

Codecov / codecov/patch

Lib/fontTools/varLib/avarPlanner.py#L78

Added line #L78 was not covered by tests

print("Planning target weights", targetWeights)
print("Planning target weights", sorted(targetWeights))
print("Sampling", SAMPLES, "points in range", rangeMin, rangeMax)
weightBlackness = axisWeightAverage.copy()

Check warning on line 82 in Lib/fontTools/varLib/avarPlanner.py

View check run for this annotation

Codecov / codecov/patch

Lib/fontTools/varLib/avarPlanner.py#L80-L82

Added lines #L80 - L82 were not covered by tests
for sample in range(1, SAMPLES + 1):
weight = rangeMin + (rangeMax - rangeMin) * sample / (SAMPLES + 1)
print("Sampling weight", weight)
glyphset = font.getGlyphSet(location={"wght": weight})
weightBlackness[weight] = getGlyphsetBlackness(glyphset, frequencies) / (upem * upem)
weightBlackness[weight] = getGlyphsetBlackness(glyphset, frequencies) / (

Check warning on line 87 in Lib/fontTools/varLib/avarPlanner.py

View check run for this annotation

Codecov / codecov/patch

Lib/fontTools/varLib/avarPlanner.py#L84-L87

Added lines #L84 - L87 were not covered by tests
upem * upem
)
print("Sampled average glyph black ratio:", weightBlackness)

Check warning on line 90 in Lib/fontTools/varLib/avarPlanner.py

View check run for this annotation

Codecov / codecov/patch

Lib/fontTools/varLib/avarPlanner.py#L90

Added line #L90 was not covered by tests

blacknessWeight = {}

Check warning on line 92 in Lib/fontTools/varLib/avarPlanner.py

View check run for this annotation

Codecov / codecov/patch

Lib/fontTools/varLib/avarPlanner.py#L92

Added line #L92 was not covered by tests
Expand Down

0 comments on commit e2d7c25

Please sign in to comment.