Skip to content

Commit

Permalink
[varLib.avarPlanner] Calculate slant axis average perceptually
Browse files Browse the repository at this point in the history
  • Loading branch information
behdad committed Jul 24, 2023
1 parent b06dec0 commit 2223193
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions Lib/fontTools/varLib/avarPlanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ def interpolateLog(t, a, b):


def measureWeight(glyphset, glyphs=None):
"""Measure the perceptual-average weight of the given glyphs."""
"""Measure the perceptual average weight of the given glyphs."""
if isinstance(glyphs, dict):
frequencies = glyphs

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

View check run for this annotation

Codecov / codecov/patch

Lib/fontTools/varLib/avarPlanner.py#L89

Added line #L89 was not covered by tests
else:
Expand All @@ -104,8 +104,9 @@ def measureWeight(glyphset, glyphs=None):
pen = AreaPen(glyphset=glyphset)
glyph.draw(pen)

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

View check run for this annotation

Codecov / codecov/patch

Lib/fontTools/varLib/avarPlanner.py#L104-L105

Added lines #L104 - L105 were not covered by tests

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

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

View check run for this annotation

Codecov / codecov/patch

Lib/fontTools/varLib/avarPlanner.py#L107-L109

Added lines #L107 - L109 were not covered by tests

return wght_sum / wdth_sum

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

View check run for this annotation

Codecov / codecov/patch

Lib/fontTools/varLib/avarPlanner.py#L111

Added line #L111 was not covered by tests

Expand Down Expand Up @@ -139,7 +140,7 @@ def measureWidth(glyphset, glyphs=None):


def measureSlant(glyphset, glyphs=None):
"""Measure the average slant angle of the given glyphs."""
"""Measure the perceptual average slant angle of the given glyphs."""
if isinstance(glyphs, dict):
frequencies = glyphs

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

View check run for this annotation

Codecov / codecov/patch

Lib/fontTools/varLib/avarPlanner.py#L145

Added line #L145 was not covered by tests
else:
Expand All @@ -160,8 +161,9 @@ def measureSlant(glyphset, glyphs=None):
pen = StatisticsPen(glyphset=glyphset)
glyph.draw(pen)

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

View check run for this annotation

Codecov / codecov/patch

Lib/fontTools/varLib/avarPlanner.py#L161-L162

Added lines #L161 - L162 were not covered by tests

slnt_sum += pen.slant * frequency
freq_sum += frequency
mult = glyph.width * frequency
slnt_sum += mult * pen.slant
freq_sum += mult

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

View check run for this annotation

Codecov / codecov/patch

Lib/fontTools/varLib/avarPlanner.py#L164-L166

Added lines #L164 - L166 were not covered by tests

return -math.degrees(math.atan(slnt_sum / freq_sum))

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

View check run for this annotation

Codecov / codecov/patch

Lib/fontTools/varLib/avarPlanner.py#L168

Added line #L168 was not covered by tests

Expand Down

0 comments on commit 2223193

Please sign in to comment.