Skip to content

Commit

Permalink
[interpolatable] Fixup
Browse files Browse the repository at this point in the history
  • Loading branch information
behdad committed Dec 1, 2023
1 parent a978538 commit 7636a2e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 20 deletions.
32 changes: 18 additions & 14 deletions Lib/fontTools/varLib/interpolatable.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,7 @@ def _populate(self, glyphset):

greenStats = StatisticsPen(glyphset=glyphset)
rpen.replay(greenStats)
self.greenVectorsNormalized.append(
contour_vector_from_stats(greenStats)
)
self.greenVectorsNormalized.append(contour_vector_from_stats(greenStats))

# Check starting point
if nodeTypes[0] == "addComponent":
Expand All @@ -129,8 +127,7 @@ def _populate(self, glyphset):
# Add mirrored rotations
add_isomorphisms(points.value, isomorphisms, True)


def draw(self, pen, countor_idx = None):
def draw(self, pen, countor_idx=None):
if countor_idx is None:
for contour in self.recordings:
contour.draw(pen)
Expand Down Expand Up @@ -284,14 +281,11 @@ def grand_parent(i, glyphname):
# "contour_order" check
#

matching, matching_cost, identity_cost = test_contour_order(
glyph0, glyph1
)
matching, matching_cost, identity_cost = test_contour_order(glyph0, glyph1)
if matching_cost < identity_cost * tolerance:
log.debug(
"matching_control_ratio %g; matching_green_ratio %g.",
matching_cost_control / identity_cost_control,
matching_cost_green / identity_cost_green,
"matching_ratio %g",
matching_cost / identity_cost,
)
this_tolerance = matching_cost / identity_cost
log.debug("tolerance: %g", this_tolerance)
Expand All @@ -303,7 +297,7 @@ def grand_parent(i, glyphname):
"master_2": names[m1idx],
"master_1_idx": m0idx,
"master_2_idx": m1idx,
"value_1": list(range(n)),
"value_1": list(range(len(matching))),
"value_2": matching,
"tolerance": this_tolerance,
},
Expand Down Expand Up @@ -344,7 +338,12 @@ def grand_parent(i, glyphname):
midRecording.append(None)

for ix, (contour0, contour1) in enumerate(zip(m0, m1)):
if contour0 is None or contour1 is None or len(contour0) == 0 or len(contour0) != len(contour1):
if (
contour0 is None
or contour1 is None
or len(contour0) == 0
or len(contour0) != len(contour1)
):
# We already reported this; or nothing to do; or not compatible
# after reordering above.
continue
Expand Down Expand Up @@ -572,7 +571,12 @@ def grand_parent(i, glyphname):
)

for ix, (contour0, contour1) in enumerate(zip(m0, m1)):
if contour0 is None or contour1 is None or len(contour0) == 0 or len(contour0) != len(contour1):
if (
contour0 is None
or contour1 is None
or len(contour0) == 0
or len(contour0) != len(contour1)
):
# We already reported this; or nothing to do; or not compatible
# after reordering above.
continue
Expand Down
9 changes: 3 additions & 6 deletions Lib/fontTools/varLib/interpolatableTestContourOrder.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from .interpolatableHelpers import *


def test_contour_order(glyph0, glyph1):
# We try matching both the StatisticsControlPen vector
# and the StatisticsPen vector.
Expand Down Expand Up @@ -46,19 +47,15 @@ def test_contour_order(glyph0, glyph1):
matching_cost_control_reversed,
identity_cost_control_reversed,
) = matching_for_vectors(m0Control, m1ControlReversed)
done = (
matching_cost_control_reversed == identity_cost_control_reversed
)
done = matching_cost_control_reversed == identity_cost_control_reversed
if not done:
m1GreenReversed = [(-m[0],) + m[1:] for m in m1Green]
(
matching_control_reversed,
matching_cost_control_reversed,
identity_cost_control_reversed,
) = matching_for_vectors(m0Control, m1ControlReversed)
done = (
matching_cost_control_reversed == identity_cost_control_reversed
)
done = matching_cost_control_reversed == identity_cost_control_reversed

if not done:
# Otherwise, use the worst of the two matchings.
Expand Down

0 comments on commit 7636a2e

Please sign in to comment.