Skip to content

Commit

Permalink
Address feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
simoncozens committed Oct 28, 2021
1 parent d645d94 commit e1ed3bb
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 16 deletions.
4 changes: 3 additions & 1 deletion Lib/fontTools/feaLib/ast.py
Original file line number Diff line number Diff line change
Expand Up @@ -2062,7 +2062,7 @@ def asFea(self, res="", indent=""):
return res

class VariationBlock(Block):
"""A named feature block."""
"""A variation feature block, applicable in a given set of conditions."""

def __init__(self, name, conditionset, use_extension=False, location=None):
Block.__init__(self, location)
Expand All @@ -2078,6 +2078,8 @@ def build(self, builder):
self.location,
)

# language exclude_dflt statements modify builder.features_
# limit them to this block with temporary builder.features_
features = builder.features_
builder.features_ = {}
Block.build(self, builder)
Expand Down
12 changes: 6 additions & 6 deletions Lib/fontTools/feaLib/variableScalar.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
from fontTools.varLib.models import VariationModel, normalizeValue


class Location(dict):
def __hash__(self):
return hash(frozenset(self))
def Location(loc):
return tuple(sorted(loc.items()))


class VariableScalar:
Expand All @@ -18,7 +17,7 @@ def __init__(self, location_value={}):
def __repr__(self):
items = []
for location,value in self.values.items():
loc = ",".join(["%s=%i" % (ax,loc) for ax,loc in location.items()])
loc = ",".join(["%s=%i" % (ax,loc) for ax,loc in location])
items.append("%s:%i" % (loc, value))
return "("+(" ".join(items))+")"

Expand Down Expand Up @@ -47,6 +46,7 @@ def _normalized_location(self, location):
return Location(normalized_location)

def fix_location(self, location):
location = dict(location)
for tag, axis in self.axes_dict.items():
if tag not in location:
location[tag] = axis.defaultValue
Expand All @@ -59,7 +59,7 @@ def add_value(self, location, value):
self.values[Location(location)] = value

def fix_all_locations(self):
self.values = {self.fix_location(l): v for l,v in self.values.items()}
self.values = {Location(self.fix_location(l)): v for l,v in self.values.items()}

@property
def default(self):
Expand All @@ -79,7 +79,7 @@ def value_at_location(self, location):

@property
def model(self):
locations = [self._normalized_location(k) for k in self.values.keys()]
locations = [dict(self._normalized_location(k)) for k in self.values.keys()]
return VariationModel(locations)

def get_deltas_and_supports(self):
Expand Down
2 changes: 1 addition & 1 deletion Tests/feaLib/data/variable_scalar_anchor.fea
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
languagesystem DFLT dflt;
feature kern {
pos cursive one <anchor 0 (wght=200:12 wght=900:22 wght=900,wdth=150:42)> <anchor NULL>;
pos cursive one <anchor 0 (wght=200:12 wght=900:22 wdth=150,wght=900:42)> <anchor NULL>;
} kern;
2 changes: 1 addition & 1 deletion Tests/feaLib/data/variable_scalar_valuerecord.fea
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
languagesystem DFLT dflt;
feature kern {
pos one 1;
pos two <0 (wght=200:12 wght=900:22 wght=900,wdth=150:42) 0 0>;
pos two <0 (wght=200:12 wght=900:22 wdth=150,wght=900:42) 0 0>;
} kern;
14 changes: 7 additions & 7 deletions Tests/feaLib/parser_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,10 +175,10 @@ def test_anchor_format_e_undefined(self):
def test_anchor_variable_scalar(self):
doc = self.parse(
"feature test {"
" pos cursive A <anchor (wght=200:-100 wght=900:-150 wght=900,wdth=150:-120) -20> <anchor NULL>;"
" pos cursive A <anchor (wght=200:-100 wght=900:-150 wdth=150,wght=900:-120) -20> <anchor NULL>;"
"} test;")
anchor = doc.statements[0].statements[0].entryAnchor
self.assertEqual(anchor.asFea(), "<anchor (wght=200:-100 wght=900:-150 wght=900,wdth=150:-120) -20>")
self.assertEqual(anchor.asFea(), "<anchor (wght=200:-100 wght=900:-150 wdth=150,wght=900:-120) -20>")

def test_anchordef(self):
[foo] = self.parse("anchorDef 123 456 foo;").statements
Expand Down Expand Up @@ -1813,9 +1813,9 @@ def test_valuerecord_format_d(self):
self.assertEqual(value.asFea(), "<NULL>")

def test_valuerecord_variable_scalar(self):
doc = self.parse("feature test {valueRecordDef <0 (wght=200:-100 wght=900:-150 wght=900,wdth=150:-120) 0 0> foo;} test;")
doc = self.parse("feature test {valueRecordDef <0 (wght=200:-100 wght=900:-150 wdth=150,wght=900:-120) 0 0> foo;} test;")
value = doc.statements[0].statements[0].value
self.assertEqual(value.asFea(), "<0 (wght=200:-100 wght=900:-150 wght=900,wdth=150:-120) 0 0>")
self.assertEqual(value.asFea(), "<0 (wght=200:-100 wght=900:-150 wdth=150,wght=900:-120) 0 0>")

def test_valuerecord_named(self):
doc = self.parse("valueRecordDef <1 2 3 4> foo;"
Expand Down Expand Up @@ -1852,13 +1852,13 @@ def test_conditionset(self):
doc = self.parse("conditionset heavy { wght 700 900; } heavy;")
value = doc.statements[0]
self.assertEqual(value.conditions["wght"], (700, 900))
self.assertEqual(value.asFea(), "conditionset heavy {\n wght 700 900;\n} heavy;\n")
self.assertEqual(value.asFea(), "conditionset heavy {\n wght 700 900;\n} heavy;\n")

doc = self.parse("conditionset heavy { wght 700 900; opsz 17 18;} heavy;")
value = doc.statements[0]
self.assertEqual(value.conditions["wght"], (700, 900))
self.assertEqual(value.conditions["opsz"], (17, 18))
self.assertEqual(value.asFea(), "conditionset heavy {\n wght 700 900;\n opsz 17 18;\n} heavy;\n")
self.assertEqual(value.asFea(), "conditionset heavy {\n wght 700 900;\n opsz 17 18;\n} heavy;\n")

def test_conditionset_same_axis(self):
self.assertRaisesRegex(
Expand All @@ -1870,7 +1870,7 @@ def test_conditionset_float(self):
doc = self.parse("conditionset heavy { wght 700.0 900.0; } heavy;")
value = doc.statements[0]
self.assertEqual(value.conditions["wght"], (700.0, 900.0))
self.assertEqual(value.asFea(), "conditionset heavy {\n wght 700.0 900.0;\n} heavy;\n")
self.assertEqual(value.asFea(), "conditionset heavy {\n wght 700.0 900.0;\n} heavy;\n")

def test_variation(self):
doc = self.parse("variation rvrn heavy { sub a by b; } rvrn;")
Expand Down

0 comments on commit e1ed3bb

Please sign in to comment.