From 84b9e9c387a355e689bfc0153f7911e50a072808 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Tue, 9 Jul 2019 16:14:01 -0700 Subject: [PATCH] [varLib.featureVars] Fix region-merging code on Py3 We should clean up all the various "convert dict to tuple" duplicated code, but this fixes it for now. doctest updated. Fixes https://github.com/fonttools/fonttools/issues/1659 --- Lib/fontTools/varLib/featureVars.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Lib/fontTools/varLib/featureVars.py b/Lib/fontTools/varLib/featureVars.py index 4caf30a22..e3aa6b6e7 100644 --- a/Lib/fontTools/varLib/featureVars.py +++ b/Lib/fontTools/varLib/featureVars.py @@ -71,7 +71,7 @@ def overlayFeatureVariations(conditionalSubstitutions): and rules with the same Box merged. The more specific rules appear earlier in the resulting list. Moreover, instead of just a dictionary of substitutions, a list of dictionaries is returned for substitutions corresponding to each - uniq space, with each dictionary being identical to one of the input + unique space, with each dictionary being identical to one of the input substitution dictionaries. These dictionaries are not merged to allow data sharing when they are converted into font tables. @@ -79,6 +79,7 @@ def overlayFeatureVariations(conditionalSubstitutions): >>> condSubst = [ ... # A list of (Region, Substitution) tuples. ... ([{"wght": (0.5, 1.0)}], {"dollar": "dollar.rvrn"}), + ... ([{"wght": (0.5, 1.0)}], {"dollar": "dollar.rvrn"}), ... ([{"wdth": (0.5, 1.0)}], {"cent": "cent.rvrn"}), ... ] >>> from pprint import pprint @@ -107,7 +108,8 @@ def overlayFeatureVariations(conditionalSubstitutions): # rules for the same region. merged = OrderedDict() for key,value in reversed(conditionalSubstitutions): - key = tuple(sorted(hashdict(cleanupBox(k)) for k in key)) + key = tuple(sorted((hashdict(cleanupBox(k)) for k in key), + key=lambda d: tuple(sorted(d.items())))) if key in merged: merged[key].update(value) else: