summaryrefslogtreecommitdiffstats
path: root/contrib/python/fonttools/fontTools/varLib/interpolatableTestContourOrder.py
diff options
context:
space:
mode:
authorrobot-contrib <[email protected]>2023-12-17 11:17:16 +0300
committerrobot-contrib <[email protected]>2023-12-17 11:37:17 +0300
commit85fcbbd6d8436b62e46d5a4e2ed1a6d72b61dc62 (patch)
tree0db5875d7d5725c79befec0b06c37ea297ba001e /contrib/python/fonttools/fontTools/varLib/interpolatableTestContourOrder.py
parente0fee3f62fb672ae80623ec56a78649a8acc1fdd (diff)
Update contrib/python/fonttools to 4.46.0
Diffstat (limited to 'contrib/python/fonttools/fontTools/varLib/interpolatableTestContourOrder.py')
-rw-r--r--contrib/python/fonttools/fontTools/varLib/interpolatableTestContourOrder.py74
1 files changed, 74 insertions, 0 deletions
diff --git a/contrib/python/fonttools/fontTools/varLib/interpolatableTestContourOrder.py b/contrib/python/fonttools/fontTools/varLib/interpolatableTestContourOrder.py
new file mode 100644
index 00000000000..d089e435767
--- /dev/null
+++ b/contrib/python/fonttools/fontTools/varLib/interpolatableTestContourOrder.py
@@ -0,0 +1,74 @@
+from .interpolatableHelpers import *
+
+
+def test_contour_order(glyph0, glyph1):
+ # We try matching both the StatisticsControlPen vector
+ # and the StatisticsPen vector.
+ #
+ # If either method found a identity matching, accept it.
+ # This is crucial for fonts like Kablammo[MORF].ttf and
+ # Nabla[EDPT,EHLT].ttf, since they really confuse the
+ # StatisticsPen vector because of their area=0 contours.
+
+ n = len(glyph0.controlVectors)
+ matching = None
+ matching_cost = 0
+ identity_cost = 0
+ done = n <= 1
+ if not done:
+ m0Control = glyph0.controlVectors
+ m1Control = glyph1.controlVectors
+ (
+ matching_control,
+ matching_cost_control,
+ identity_cost_control,
+ ) = matching_for_vectors(m0Control, m1Control)
+ done = matching_cost_control == identity_cost_control
+ if not done:
+ m0Green = glyph0.greenVectors
+ m1Green = glyph1.greenVectors
+ (
+ matching_green,
+ matching_cost_green,
+ identity_cost_green,
+ ) = matching_for_vectors(m0Green, m1Green)
+ done = matching_cost_green == identity_cost_green
+
+ if not done:
+ # See if reversing contours in one master helps.
+ # That's a common problem. Then the wrong_start_point
+ # test will fix them.
+ #
+ # Reverse the sign of the area (0); the rest stay the same.
+ if not done:
+ m1ControlReversed = [(-m[0],) + m[1:] for m in m1Control]
+ (
+ 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
+ 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
+
+ if not done:
+ # Otherwise, use the worst of the two matchings.
+ if (
+ matching_cost_control / identity_cost_control
+ < matching_cost_green / identity_cost_green
+ ):
+ matching = matching_control
+ matching_cost = matching_cost_control
+ identity_cost = identity_cost_control
+ else:
+ matching = matching_green
+ matching_cost = matching_cost_green
+ identity_cost = identity_cost_green
+
+ return matching, matching_cost, identity_cost