[varLib.avarPlanner] Add one-line docstrings
This commit is contained in:
parent
0330d3c5b9
commit
b06dec0e94
@ -72,16 +72,19 @@ SAMPLES = 8
|
|||||||
|
|
||||||
|
|
||||||
def interpolateLinear(t, a, b):
|
def interpolateLinear(t, a, b):
|
||||||
|
"""Linear interpolation between a and b, with t typically in [0, 1]."""
|
||||||
return a + t * (b - a)
|
return a + t * (b - a)
|
||||||
|
|
||||||
|
|
||||||
def interpolateLog(t, a, b):
|
def interpolateLog(t, a, b):
|
||||||
|
"""Logarithmic interpolation between a and b, with t typically in [0, 1]."""
|
||||||
logA = math.log(a)
|
logA = math.log(a)
|
||||||
logB = math.log(b)
|
logB = math.log(b)
|
||||||
return math.exp(logA + t * (logB - logA))
|
return math.exp(logA + t * (logB - logA))
|
||||||
|
|
||||||
|
|
||||||
def measureWeight(glyphset, glyphs=None):
|
def measureWeight(glyphset, glyphs=None):
|
||||||
|
"""Measure the perceptual-average weight of the given glyphs."""
|
||||||
if isinstance(glyphs, dict):
|
if isinstance(glyphs, dict):
|
||||||
frequencies = glyphs
|
frequencies = glyphs
|
||||||
else:
|
else:
|
||||||
@ -108,6 +111,7 @@ def measureWeight(glyphset, glyphs=None):
|
|||||||
|
|
||||||
|
|
||||||
def measureWidth(glyphset, glyphs=None):
|
def measureWidth(glyphset, glyphs=None):
|
||||||
|
"""Measure the average width of the given glyphs."""
|
||||||
if isinstance(glyphs, dict):
|
if isinstance(glyphs, dict):
|
||||||
frequencies = glyphs
|
frequencies = glyphs
|
||||||
else:
|
else:
|
||||||
@ -135,6 +139,7 @@ def measureWidth(glyphset, glyphs=None):
|
|||||||
|
|
||||||
|
|
||||||
def measureSlant(glyphset, glyphs=None):
|
def measureSlant(glyphset, glyphs=None):
|
||||||
|
"""Measure the average slant angle of the given glyphs."""
|
||||||
if isinstance(glyphs, dict):
|
if isinstance(glyphs, dict):
|
||||||
frequencies = glyphs
|
frequencies = glyphs
|
||||||
else:
|
else:
|
||||||
@ -162,6 +167,8 @@ def measureSlant(glyphset, glyphs=None):
|
|||||||
|
|
||||||
|
|
||||||
def sanitizeWidth(userTriple, designTriple, pins, measurements):
|
def sanitizeWidth(userTriple, designTriple, pins, measurements):
|
||||||
|
"""Sanitize the width axis limits."""
|
||||||
|
|
||||||
minVal, defaultVal, maxVal = (
|
minVal, defaultVal, maxVal = (
|
||||||
measurements[designTriple[0]],
|
measurements[designTriple[0]],
|
||||||
measurements[designTriple[1]],
|
measurements[designTriple[1]],
|
||||||
@ -197,6 +204,8 @@ def sanitizeWidth(userTriple, designTriple, pins, measurements):
|
|||||||
|
|
||||||
|
|
||||||
def sanitizeWeight(userTriple, designTriple, pins, measurements):
|
def sanitizeWeight(userTriple, designTriple, pins, measurements):
|
||||||
|
"""Sanitize the weight axis limits."""
|
||||||
|
|
||||||
if len(set(userTriple)) < 3:
|
if len(set(userTriple)) < 3:
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@ -260,6 +269,8 @@ def sanitizeWeight(userTriple, designTriple, pins, measurements):
|
|||||||
|
|
||||||
|
|
||||||
def sanitizeSlant(userTriple, designTriple, pins, measurements):
|
def sanitizeSlant(userTriple, designTriple, pins, measurements):
|
||||||
|
"""Sanitize the slant axis limits."""
|
||||||
|
|
||||||
log.info("Original slant axis limits: %g:%g:%g", *userTriple)
|
log.info("Original slant axis limits: %g:%g:%g", *userTriple)
|
||||||
log.info(
|
log.info(
|
||||||
"Calculated slant axis limits: %g:%g:%g",
|
"Calculated slant axis limits: %g:%g:%g",
|
||||||
@ -301,6 +312,8 @@ def planAxis(
|
|||||||
pins=None,
|
pins=None,
|
||||||
sanitizeFunc=None,
|
sanitizeFunc=None,
|
||||||
):
|
):
|
||||||
|
"""Plan an axis."""
|
||||||
|
|
||||||
if samples is None:
|
if samples is None:
|
||||||
samples = SAMPLES
|
samples = SAMPLES
|
||||||
if glyphs is None:
|
if glyphs is None:
|
||||||
@ -424,6 +437,8 @@ def planWeightAxis(
|
|||||||
pins=None,
|
pins=None,
|
||||||
sanitize=False,
|
sanitize=False,
|
||||||
):
|
):
|
||||||
|
"""Plan a weight axis."""
|
||||||
|
|
||||||
if weights is None:
|
if weights is None:
|
||||||
weights = WEIGHTS
|
weights = WEIGHTS
|
||||||
|
|
||||||
@ -456,6 +471,8 @@ def planWidthAxis(
|
|||||||
pins=None,
|
pins=None,
|
||||||
sanitize=False,
|
sanitize=False,
|
||||||
):
|
):
|
||||||
|
"""Plan a width axis."""
|
||||||
|
|
||||||
if widths is None:
|
if widths is None:
|
||||||
widths = WIDTHS
|
widths = WIDTHS
|
||||||
|
|
||||||
@ -488,6 +505,8 @@ def planSlantAxis(
|
|||||||
pins=None,
|
pins=None,
|
||||||
sanitize=False,
|
sanitize=False,
|
||||||
):
|
):
|
||||||
|
"""Plan a slant axis."""
|
||||||
|
|
||||||
if slants is None:
|
if slants is None:
|
||||||
slants = SLANTS
|
slants = SLANTS
|
||||||
|
|
||||||
@ -509,6 +528,8 @@ def planSlantAxis(
|
|||||||
|
|
||||||
|
|
||||||
def makeDesignspaceSnippet(axisTag, axisName, axisLimit, mapping):
|
def makeDesignspaceSnippet(axisTag, axisName, axisLimit, mapping):
|
||||||
|
"""Make a designspace snippet for a single axis."""
|
||||||
|
|
||||||
designspaceSnippet = (
|
designspaceSnippet = (
|
||||||
' <axis tag="%s" name="%s" minimum="%g" default="%g" maximum="%g"'
|
' <axis tag="%s" name="%s" minimum="%g" default="%g" maximum="%g"'
|
||||||
% ((axisTag, axisName) + axisLimit)
|
% ((axisTag, axisName) + axisLimit)
|
||||||
@ -528,9 +549,10 @@ def makeDesignspaceSnippet(axisTag, axisName, axisLimit, mapping):
|
|||||||
|
|
||||||
|
|
||||||
def addEmptyAvar(font):
|
def addEmptyAvar(font):
|
||||||
font["avar"] = newTable("avar")
|
"""Add an empty `avar` table to the font."""
|
||||||
|
font["avar"] = avar = newTable("avar")
|
||||||
for axis in fvar.axes:
|
for axis in fvar.axes:
|
||||||
font["avar"].segments[axis.axisTag] = {}
|
avar.segments[axis.axisTag] = {}
|
||||||
|
|
||||||
|
|
||||||
def main(args=None):
|
def main(args=None):
|
||||||
|
Loading…
x
Reference in New Issue
Block a user