summaryrefslogtreecommitdiffstats
path: root/contrib/python/fonttools/fontTools/varLib/interpolatableTestContourOrder.py
diff options
context:
space:
mode:
authorzverevgeny <[email protected]>2025-05-13 19:00:02 +0300
committerzverevgeny <[email protected]>2025-05-13 19:13:54 +0300
commit92e06374736aa28637dc0e706455b65c8268a5e6 (patch)
tree3df370c199ae25d308e542f02af20f43eab78f8a /contrib/python/fonttools/fontTools/varLib/interpolatableTestContourOrder.py
parentdc63d5794da99c2ebe3f32914d0351d9707660b0 (diff)
Import matplotlib
commit_hash:d59c2338025ef8fd1e1f961ed9d8d5fd52d0bd96
Diffstat (limited to 'contrib/python/fonttools/fontTools/varLib/interpolatableTestContourOrder.py')
-rw-r--r--contrib/python/fonttools/fontTools/varLib/interpolatableTestContourOrder.py82
1 files changed, 82 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..36885297984
--- /dev/null
+++ b/contrib/python/fonttools/fontTools/varLib/interpolatableTestContourOrder.py
@@ -0,0 +1,82 @@
+from .interpolatableHelpers import *
+import logging
+
+log = logging.getLogger("fontTools.varLib.interpolatable")
+
+
+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_green_reversed,
+ identity_cost_green_reversed,
+ ) = matching_for_vectors(m0Green, m1GreenReversed)
+ done = matching_cost_green_reversed == identity_cost_green_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
+
+ this_tolerance = matching_cost / identity_cost if identity_cost else 1
+ log.debug(
+ "test-contour-order: tolerance %g",
+ this_tolerance,
+ )
+ return this_tolerance, matching