Skip to content

Commit

Permalink
[varLib.avarPlanner] Better blackness calculation
Browse files Browse the repository at this point in the history
Consider glyph width.
  • Loading branch information
behdad committed Jul 23, 2023
1 parent 8557e53 commit 7d05b89
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions Lib/fontTools/varLib/avarPlanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def getGlyphsetBlackness(glyphset):
pen = AreaPen(glyphset=glyphset)
glyph.draw(pen)

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

View check run for this annotation

Codecov / codecov/patch

Lib/fontTools/varLib/avarPlanner.py#L16-L17

Added lines #L16 - L17 were not covered by tests

wght_sum += abs(pen.value)
wght_sum += abs(pen.value) * glyph.width
wdth_sum += glyph.width

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

View check run for this annotation

Codecov / codecov/patch

Lib/fontTools/varLib/avarPlanner.py#L19-L20

Added lines #L19 - L20 were not covered by tests

return wght_sum / wdth_sum

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

View check run for this annotation

Codecov / codecov/patch

Lib/fontTools/varLib/avarPlanner.py#L22

Added line #L22 was not covered by tests
Expand All @@ -32,7 +32,7 @@ def planWeightAxis(font, minValue, defaultValue, maxValue, weights=WEIGHTS):
axisWeightAverage = {}

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#L31-L32

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

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#L34-L35

Added lines #L34 - L35 were not covered by tests

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

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

View check run for this annotation

Codecov / codecov/patch

Lib/fontTools/varLib/avarPlanner.py#L37

Added line #L37 was not covered by tests

Expand All @@ -53,7 +53,7 @@ def planWeightAxis(font, minValue, defaultValue, maxValue, weights=WEIGHTS):
weight = rangeMin + (rangeMax - rangeMin) * sample / (SAMPLES + 1)
print("Sampling weight", weight)
glyphset = font.getGlyphSet(location={"wght": weight})
weightBlackness[weight] = getGlyphsetBlackness(glyphset) / upem
weightBlackness[weight] = getGlyphsetBlackness(glyphset) / (upem * upem)
print("Sampled average glyph black ratio:", weightBlackness)

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

View check run for this annotation

Codecov / codecov/patch

Lib/fontTools/varLib/avarPlanner.py#L53-L57

Added lines #L53 - L57 were not covered by tests

blacknessWeight = {}

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

View check run for this annotation

Codecov / codecov/patch

Lib/fontTools/varLib/avarPlanner.py#L59

Added line #L59 was not covered by tests
Expand Down

0 comments on commit 7d05b89

Please sign in to comment.