replace int(round(...)) with round(...)

We don't need to cast to int when using the round function from py23,
as this is a backport of python3's built-in round and thus it returns
an int when called with a single argument.
This commit is contained in:
Cosimo Lupo 2017-10-22 12:03:52 +01:00
parent 5de673c424
commit 28bb992c1f
13 changed files with 20 additions and 20 deletions

View File

@ -47,9 +47,9 @@ def fixedToFloat(value, precisionBits):
def floatToFixed(value, precisionBits): def floatToFixed(value, precisionBits):
"""Converts a float to a fixed-point number given the number of """Converts a float to a fixed-point number given the number of
precisionBits. Ie. int(round(value * (1<<precisionBits))). precisionBits. Ie. round(value * (1<<precisionBits)).
""" """
return int(round(value * (1<<precisionBits))) return round(value * (1<<precisionBits))
def floatToFixedToFloat(value, precisionBits): def floatToFixedToFloat(value, precisionBits):
"""Converts a float to a fixed-point number given the number of """Converts a float to a fixed-point number given the number of

View File

@ -217,7 +217,7 @@ encodeIntT2 = getIntEncoder("t2")
def encodeFixed(f, pack=struct.pack): def encodeFixed(f, pack=struct.pack):
# For T2 only # For T2 only
return b"\xff" + pack(">l", int(round(f * 65536))) return b"\xff" + pack(">l", round(f * 65536))
def encodeFloat(f): def encodeFloat(f):
# For CFF only, used in cffLib # For CFF only, used in cffLib

View File

@ -2890,7 +2890,7 @@ class Subsetter(object):
log.info("%s Unicode ranges pruned: %s", tag, sorted(new_uniranges)) log.info("%s Unicode ranges pruned: %s", tag, sorted(new_uniranges))
if self.options.recalc_average_width: if self.options.recalc_average_width:
widths = [m[0] for m in font["hmtx"].metrics.values() if m[0] > 0] widths = [m[0] for m in font["hmtx"].metrics.values() if m[0] > 0]
avg_width = int(round(sum(widths) / len(widths))) avg_width = round(sum(widths) / len(widths))
if avg_width != font[tag].xAvgCharWidth: if avg_width != font[tag].xAvgCharWidth:
font[tag].xAvgCharWidth = avg_width font[tag].xAvgCharWidth = avg_width
log.info("%s xAvgCharWidth updated: %d", tag, avg_width) log.info("%s xAvgCharWidth updated: %d", tag, avg_width)

View File

@ -149,8 +149,8 @@ class table_O_S_2f_2(DefaultTable.DefaultTable):
data = sstruct.pack(OS2_format_2, self) data = sstruct.pack(OS2_format_2, self)
elif self.version == 5: elif self.version == 5:
d = self.__dict__.copy() d = self.__dict__.copy()
d['usLowerOpticalPointSize'] = int(round(self.usLowerOpticalPointSize * 20)) d['usLowerOpticalPointSize'] = round(self.usLowerOpticalPointSize * 20)
d['usUpperOpticalPointSize'] = int(round(self.usUpperOpticalPointSize * 20)) d['usUpperOpticalPointSize'] = round(self.usUpperOpticalPointSize * 20)
data = sstruct.pack(OS2_format_5, d) data = sstruct.pack(OS2_format_5, d)
else: else:
from fontTools import ttLib from fontTools import ttLib

View File

@ -1079,8 +1079,8 @@ class GlyphComponent(object):
data = data + struct.pack(">HH", self.firstPt, self.secondPt) data = data + struct.pack(">HH", self.firstPt, self.secondPt)
flags = flags | ARG_1_AND_2_ARE_WORDS flags = flags | ARG_1_AND_2_ARE_WORDS
else: else:
x = int(round(self.x)) x = round(self.x)
y = int(round(self.y)) y = round(self.y)
flags = flags | ARGS_ARE_XY_VALUES flags = flags | ARGS_ARE_XY_VALUES
if (-128 <= x <= 127) and (-128 <= y <= 127): if (-128 <= x <= 127) and (-128 <= y <= 127):
data = data + struct.pack(">bb", x, y) data = data + struct.pack(">bb", x, y)
@ -1242,7 +1242,7 @@ class GlyphCoordinates(object):
return return
a = array.array("h") a = array.array("h")
for n in self._a: for n in self._a:
a.append(int(round(n))) a.append(round(n))
self._a = a self._a = a
def relativeToAbsolute(self): def relativeToAbsolute(self):

View File

@ -78,14 +78,14 @@ class table__h_m_t_x(DefaultTable.DefaultTable):
lastIndex = 1 lastIndex = 1
break break
additionalMetrics = metrics[lastIndex:] additionalMetrics = metrics[lastIndex:]
additionalMetrics = [int(round(sb)) for _, sb in additionalMetrics] additionalMetrics = [round(sb) for _, sb in additionalMetrics]
metrics = metrics[:lastIndex] metrics = metrics[:lastIndex]
numberOfMetrics = len(metrics) numberOfMetrics = len(metrics)
setattr(ttFont[self.headerTag], self.numberOfMetricsName, numberOfMetrics) setattr(ttFont[self.headerTag], self.numberOfMetricsName, numberOfMetrics)
allMetrics = [] allMetrics = []
for advance, sb in metrics: for advance, sb in metrics:
allMetrics.extend([int(round(advance)), int(round(sb))]) allMetrics.extend([round(advance), round(sb)])
metricsFmt = ">" + self.longMetricFormat * numberOfMetrics metricsFmt = ">" + self.longMetricFormat * numberOfMetrics
try: try:
data = struct.pack(metricsFmt, *allMetrics) data = struct.pack(metricsFmt, *allMetrics)

View File

@ -307,7 +307,7 @@ class DeciPoints(FloatValue):
return reader.readUShort() / 10 return reader.readUShort() / 10
def write(self, writer, font, tableDict, value, repeatIndex=None): def write(self, writer, font, tableDict, value, repeatIndex=None):
writer.writeUShort(int(round(value * 10))) writer.writeUShort(round(value * 10))
class Fixed(FloatValue): class Fixed(FloatValue):
staticSize = 4 staticSize = 4

View File

@ -1459,7 +1459,7 @@ otData = [
]), ]),
# If the 'morx' table version is 3 or greater, then the last subtable in the chain is followed by a subtableGlyphCoverageArray, as described below. # If the 'morx' table version is 3 or greater, then the last subtable in the chain is followed by a subtableGlyphCoverageArray, as described below.
# ('Offset', 'MarkGlyphSetsDef', None, 'int(round(Version*0x10000)) >= 0x00010002', 'Offset to the table of mark set definitions-from beginning of GDEF header (may be NULL)'), # ('Offset', 'MarkGlyphSetsDef', None, 'round(Version*0x10000) >= 0x00010002', 'Offset to the table of mark set definitions-from beginning of GDEF header (may be NULL)'),
# #

View File

@ -371,7 +371,7 @@ def _merge_TTHinting(font, model, master_ttfs, tolerance=0.5):
deltas = model.getDeltas(all_cvs) deltas = model.getDeltas(all_cvs)
supports = model.supports supports = model.supports
for i,(delta,support) in enumerate(zip(deltas[1:], supports[1:])): for i,(delta,support) in enumerate(zip(deltas[1:], supports[1:])):
delta = [int(round(d)) for d in delta] delta = [round(d) for d in delta]
if all(abs(v) <= tolerance for v in delta): if all(abs(v) <= tolerance for v in delta):
continue continue
var = TupleVariation(support, delta) var = TupleVariation(support, delta)

View File

@ -146,7 +146,7 @@ def test(glyphsets, glyphs=None, names=None):
print('%s: %s+%s: Glyph has wrong contour/component order: %s' % (glyph_name, names[i], names[i+1], matching)) #, m0, m1) print('%s: %s+%s: Glyph has wrong contour/component order: %s' % (glyph_name, names[i], names[i+1], matching)) #, m0, m1)
break break
upem = 2048 upem = 2048
item_cost = int(round((matching_cost / len(m0) / len(m0[0])) ** .5 / upem * 100)) item_cost = round((matching_cost / len(m0) / len(m0[0])) ** .5 / upem * 100)
hist.append(item_cost) hist.append(item_cost)
threshold = 7 threshold = 7
if item_cost >= threshold: if item_cost >= threshold:

View File

@ -727,7 +727,7 @@ def merge(merger, self, lst):
assert dev.DeltaFormat == 0x8000 assert dev.DeltaFormat == 0x8000
varidx = (dev.StartSize << 16) + dev.EndSize varidx = (dev.StartSize << 16) + dev.EndSize
delta = int(round(instancer[varidx])) delta = round(instancer[varidx])
attr = v+'Coordinate' attr = v+'Coordinate'
setattr(self, attr, getattr(self, attr) + delta) setattr(self, attr, getattr(self, attr) + delta)
@ -750,7 +750,7 @@ def merge(merger, self, lst):
assert dev.DeltaFormat == 0x8000 assert dev.DeltaFormat == 0x8000
varidx = (dev.StartSize << 16) + dev.EndSize varidx = (dev.StartSize << 16) + dev.EndSize
delta = int(round(instancer[varidx])) delta = round(instancer[varidx])
setattr(self, name, getattr(self, name) + delta) setattr(self, name, getattr(self, name) + delta)

View File

@ -87,7 +87,7 @@ def instantiateVariableFont(varfont, location, inplace=False):
if c is not None: if c is not None:
deltas[i] = deltas.get(i, 0) + scalar * c deltas[i] = deltas.get(i, 0) + scalar * c
for i, delta in deltas.items(): for i, delta in deltas.items():
cvt[i] += int(round(delta)) cvt[i] += round(delta)
if 'MVAR' in varfont: if 'MVAR' in varfont:
log.info("Mutating MVAR table") log.info("Mutating MVAR table")
@ -99,7 +99,7 @@ def instantiateVariableFont(varfont, location, inplace=False):
if mvarTag not in MVAR_entries: if mvarTag not in MVAR_entries:
continue continue
tableTag, itemName = MVAR_entries[mvarTag] tableTag, itemName = MVAR_entries[mvarTag]
delta = int(round(varStoreInstancer[rec.VarIdx])) delta = round(varStoreInstancer[rec.VarIdx])
if not delta: if not delta:
continue continue
setattr(varfont[tableTag], itemName, setattr(varfont[tableTag], itemName,

View File

@ -49,7 +49,7 @@ class OnlineVarStoreBuilder(object):
return self._store return self._store
def storeMasters(self, master_values): def storeMasters(self, master_values):
deltas = [int(round(d)) for d in self._model.getDeltas(master_values)] deltas = [round(d) for d in self._model.getDeltas(master_values)]
base = deltas.pop(0) base = deltas.pop(0)
inner = len(self._data.Item) inner = len(self._data.Item)
self._data.Item.append(deltas) self._data.Item.append(deltas)