Skip to content

Commit

Permalink
Run black on all touched files
Browse files Browse the repository at this point in the history
  • Loading branch information
simoncozens committed Oct 28, 2021
1 parent 8f06c0e commit eab87ed
Show file tree
Hide file tree
Showing 5 changed files with 876 additions and 597 deletions.
32 changes: 25 additions & 7 deletions Lib/fontTools/feaLib/ast.py
Expand Up @@ -1262,11 +1262,21 @@ def build(self, builder):
if not self.replacement and hasattr(self.glyph, "glyphSet"):
for glyph in self.glyph.glyphSet():
builder.add_multiple_subst(
self.location, prefix, glyph, suffix, self.replacement, self.forceChain
self.location,
prefix,
glyph,
suffix,
self.replacement,
self.forceChain,
)
else:
builder.add_multiple_subst(
self.location, prefix, self.glyph, suffix, self.replacement, self.forceChain
self.location,
prefix,
self.glyph,
suffix,
self.replacement,
self.forceChain,
)

def asFea(self, indent=""):
Expand Down Expand Up @@ -2061,18 +2071,26 @@ def asFea(self, res="", indent=""):
res += indent + "}" + f" {self.name};\n"
return res


class VariationBlock(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)
self.name, self.conditionset, self.use_extension = name, conditionset, use_extension
self.name, self.conditionset, self.use_extension = (
name,
conditionset,
use_extension,
)

def build(self, builder):
"""Call the ``start_feature`` callback on the builder object, visit
all the statements in this feature, and then call ``end_feature``."""
builder.start_feature(self.location, self.name)
if self.conditionset != "NULL" and self.conditionset not in builder.conditionsets_:
if (
self.conditionset != "NULL"
and self.conditionset not in builder.conditionsets_
):
raise FeatureLibError(
f"variation block used undefined conditionset {self.conditionset}",
self.location,
Expand All @@ -2084,7 +2102,9 @@ def build(self, builder):
builder.features_ = {}
Block.build(self, builder)
for key, value in builder.features_.items():
items = builder.feature_variations_.setdefault(key,{}).setdefault(self.conditionset,[])
items = builder.feature_variations_.setdefault(key, {}).setdefault(
self.conditionset, []
)
items.extend(value)
if key not in features:
features[key] = [] # Ensure we make a feature record
Expand All @@ -2100,5 +2120,3 @@ def asFea(self, indent=""):
res += Block.asFea(self, indent=indent)
res += indent + "} %s;\n" % self.name.strip()
return res


50 changes: 31 additions & 19 deletions Lib/fontTools/feaLib/parser.py
Expand Up @@ -385,8 +385,7 @@ def parse_glyphclass_(self, accept_glyphname, accept_null=False):
self.expect_symbol_("-")
range_end = self.expect_cid_()
self.check_glyph_name_in_glyph_set(
f"cid{range_start:05d}",
f"cid{range_end:05d}",
f"cid{range_start:05d}", f"cid{range_end:05d}",
)
glyphs.add_cid_range(
range_start,
Expand Down Expand Up @@ -482,7 +481,7 @@ def parse_glyph_pattern_(self, vertical):
raise FeatureLibError(
"Positioning cannot be applied in the bactrack glyph sequence, "
"before the marked glyph sequence.",
self.cur_token_location_
self.cur_token_location_,
)
marked_values = values[len(prefix) : len(prefix) + len(glyphs)]
if any(marked_values):
Expand All @@ -491,7 +490,7 @@ def parse_glyph_pattern_(self, vertical):
"Positioning values are allowed only in the marked glyph "
"sequence, or after the final glyph node when only one glyph "
"node is marked.",
self.cur_token_location_
self.cur_token_location_,
)
values = marked_values
elif values and values[-1]:
Expand All @@ -500,15 +499,15 @@ def parse_glyph_pattern_(self, vertical):
"Positioning values are allowed only in the marked glyph "
"sequence, or after the final glyph node when only one glyph "
"node is marked.",
self.cur_token_location_
self.cur_token_location_,
)
values = values[-1:]
elif any(values):
raise FeatureLibError(
"Positioning values are allowed only in the marked glyph "
"sequence, or after the final glyph node when only one glyph "
"node is marked.",
self.cur_token_location_
self.cur_token_location_,
)
return (prefix, glyphs, lookups, values, suffix, hasMarks)

Expand Down Expand Up @@ -1010,8 +1009,8 @@ def parse_size_parameters_(self):
location = self.cur_token_location_
DesignSize = self.expect_decipoint_()
SubfamilyID = self.expect_number_()
RangeStart = 0.
RangeEnd = 0.
RangeStart = 0.0
RangeEnd = 0.0
if self.next_token_type_ in (Lexer.NUMBER, Lexer.FLOAT) or SubfamilyID != 0:
RangeStart = self.expect_decipoint_()
RangeEnd = self.expect_decipoint_()
Expand Down Expand Up @@ -1590,11 +1589,20 @@ def parse_device_(self):
return result

def is_next_value_(self):
return self.next_token_type_ is Lexer.NUMBER or self.next_token_ == "<" or self.next_token_ == "("
return (
self.next_token_type_ is Lexer.NUMBER
or self.next_token_ == "<"
or self.next_token_ == "("
)

def parse_valuerecord_(self, vertical):
if (self.next_token_type_ is Lexer.SYMBOL and self.next_token_ == "(") or self.next_token_type_ is Lexer.NUMBER:
number, location = self.expect_number_(variable=True), self.cur_token_location_
if (
self.next_token_type_ is Lexer.SYMBOL and self.next_token_ == "("
) or self.next_token_type_ is Lexer.NUMBER:
number, location = (
self.expect_number_(variable=True),
self.cur_token_location_,
)
if vertical:
val = self.ast.ValueRecord(
yAdvance=number, vertical=vertical, location=location
Expand Down Expand Up @@ -1879,7 +1887,9 @@ def parse_conditionset_(self):

axis = self.cur_token_
if axis in conditions:
raise FeatureLibError(f"Repeated condition for axis {axis}", self.cur_token_location_)
raise FeatureLibError(
f"Repeated condition for axis {axis}", self.cur_token_location_
)

if self.next_token_type_ is Lexer.FLOAT:
min_value = self.expect_float_()
Expand All @@ -1898,9 +1908,7 @@ def parse_conditionset_(self):

finalname = self.expect_name_()
if finalname != name:
raise FeatureLibError(
'Expected "%s"' % name, self.cur_token_location_
)
raise FeatureLibError('Expected "%s"' % name, self.cur_token_location_)
return self.ast.ConditionsetStatement(name, conditions)

def parse_block_(
Expand Down Expand Up @@ -2142,7 +2150,7 @@ def expect_number_(self, variable=False):
raise FeatureLibError("Expected a number", self.cur_token_location_)

def expect_variable_scalar_(self):
self.advance_lexer_() # "("
self.advance_lexer_() # "("
scalar = VariableScalar()
while True:
if self.cur_token_type_ == Lexer.SYMBOL and self.cur_token_ == ")":
Expand All @@ -2159,15 +2167,19 @@ def expect_master_(self):
axis = self.cur_token_
self.advance_lexer_()
if not (self.cur_token_type_ is Lexer.SYMBOL and self.cur_token_ == "="):
raise FeatureLibError("Expected an equals sign", self.cur_token_location_)
raise FeatureLibError(
"Expected an equals sign", self.cur_token_location_
)
value = self.expect_number_()
location[axis] = value
if self.next_token_type_ is Lexer.NAME and self.next_token_[0] == ":":
# Lexer has just read the value as a glyph name. We'll correct it later
break
self.advance_lexer_()
if not(self.cur_token_type_ is Lexer.SYMBOL and self.cur_token_ == ","):
raise FeatureLibError("Expected an comma or an equals sign", self.cur_token_location_)
if not (self.cur_token_type_ is Lexer.SYMBOL and self.cur_token_ == ","):
raise FeatureLibError(
"Expected an comma or an equals sign", self.cur_token_location_
)
self.advance_lexer_()
self.advance_lexer_()
value = int(self.cur_token_[1:])
Expand Down
14 changes: 9 additions & 5 deletions Lib/fontTools/feaLib/variableScalar.py
Expand Up @@ -16,10 +16,10 @@ 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])
for location, value in self.values.items():
loc = ",".join(["%s=%i" % (ax, loc) for ax, loc in location])
items.append("%s:%i" % (loc, value))
return "("+(" ".join(items))+")"
return "(" + (" ".join(items)) + ")"

@property
def does_vary(self):
Expand All @@ -29,7 +29,9 @@ def does_vary(self):
@property
def axes_dict(self):
if not self.axes:
raise ValueError(".axes must be defined on variable scalar before interpolating")
raise ValueError(
".axes must be defined on variable scalar before interpolating"
)
return {ax.axisTag: ax for ax in self.axes}

def _normalized_location(self, location):
Expand Down Expand Up @@ -59,7 +61,9 @@ def add_value(self, location, value):
self.values[Location(location)] = value

def fix_all_locations(self):
self.values = {Location(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 Down

0 comments on commit eab87ed

Please sign in to comment.