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:
parent
5de673c424
commit
28bb992c1f
@ -47,9 +47,9 @@ def fixedToFloat(value, precisionBits):
|
||||
|
||||
def floatToFixed(value, precisionBits):
|
||||
"""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):
|
||||
"""Converts a float to a fixed-point number given the number of
|
||||
|
@ -217,7 +217,7 @@ encodeIntT2 = getIntEncoder("t2")
|
||||
|
||||
def encodeFixed(f, pack=struct.pack):
|
||||
# For T2 only
|
||||
return b"\xff" + pack(">l", int(round(f * 65536)))
|
||||
return b"\xff" + pack(">l", round(f * 65536))
|
||||
|
||||
def encodeFloat(f):
|
||||
# For CFF only, used in cffLib
|
||||
|
@ -2890,7 +2890,7 @@ class Subsetter(object):
|
||||
log.info("%s Unicode ranges pruned: %s", tag, sorted(new_uniranges))
|
||||
if self.options.recalc_average_width:
|
||||
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:
|
||||
font[tag].xAvgCharWidth = avg_width
|
||||
log.info("%s xAvgCharWidth updated: %d", tag, avg_width)
|
||||
|
@ -149,8 +149,8 @@ class table_O_S_2f_2(DefaultTable.DefaultTable):
|
||||
data = sstruct.pack(OS2_format_2, self)
|
||||
elif self.version == 5:
|
||||
d = self.__dict__.copy()
|
||||
d['usLowerOpticalPointSize'] = int(round(self.usLowerOpticalPointSize * 20))
|
||||
d['usUpperOpticalPointSize'] = int(round(self.usUpperOpticalPointSize * 20))
|
||||
d['usLowerOpticalPointSize'] = round(self.usLowerOpticalPointSize * 20)
|
||||
d['usUpperOpticalPointSize'] = round(self.usUpperOpticalPointSize * 20)
|
||||
data = sstruct.pack(OS2_format_5, d)
|
||||
else:
|
||||
from fontTools import ttLib
|
||||
|
@ -1079,8 +1079,8 @@ class GlyphComponent(object):
|
||||
data = data + struct.pack(">HH", self.firstPt, self.secondPt)
|
||||
flags = flags | ARG_1_AND_2_ARE_WORDS
|
||||
else:
|
||||
x = int(round(self.x))
|
||||
y = int(round(self.y))
|
||||
x = round(self.x)
|
||||
y = round(self.y)
|
||||
flags = flags | ARGS_ARE_XY_VALUES
|
||||
if (-128 <= x <= 127) and (-128 <= y <= 127):
|
||||
data = data + struct.pack(">bb", x, y)
|
||||
@ -1242,7 +1242,7 @@ class GlyphCoordinates(object):
|
||||
return
|
||||
a = array.array("h")
|
||||
for n in self._a:
|
||||
a.append(int(round(n)))
|
||||
a.append(round(n))
|
||||
self._a = a
|
||||
|
||||
def relativeToAbsolute(self):
|
||||
|
@ -78,14 +78,14 @@ class table__h_m_t_x(DefaultTable.DefaultTable):
|
||||
lastIndex = 1
|
||||
break
|
||||
additionalMetrics = metrics[lastIndex:]
|
||||
additionalMetrics = [int(round(sb)) for _, sb in additionalMetrics]
|
||||
additionalMetrics = [round(sb) for _, sb in additionalMetrics]
|
||||
metrics = metrics[:lastIndex]
|
||||
numberOfMetrics = len(metrics)
|
||||
setattr(ttFont[self.headerTag], self.numberOfMetricsName, numberOfMetrics)
|
||||
|
||||
allMetrics = []
|
||||
for advance, sb in metrics:
|
||||
allMetrics.extend([int(round(advance)), int(round(sb))])
|
||||
allMetrics.extend([round(advance), round(sb)])
|
||||
metricsFmt = ">" + self.longMetricFormat * numberOfMetrics
|
||||
try:
|
||||
data = struct.pack(metricsFmt, *allMetrics)
|
||||
|
@ -307,7 +307,7 @@ class DeciPoints(FloatValue):
|
||||
return reader.readUShort() / 10
|
||||
|
||||
def write(self, writer, font, tableDict, value, repeatIndex=None):
|
||||
writer.writeUShort(int(round(value * 10)))
|
||||
writer.writeUShort(round(value * 10))
|
||||
|
||||
class Fixed(FloatValue):
|
||||
staticSize = 4
|
||||
|
@ -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.
|
||||
# ('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)'),
|
||||
|
||||
|
||||
#
|
||||
|
@ -371,7 +371,7 @@ def _merge_TTHinting(font, model, master_ttfs, tolerance=0.5):
|
||||
deltas = model.getDeltas(all_cvs)
|
||||
supports = model.supports
|
||||
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):
|
||||
continue
|
||||
var = TupleVariation(support, delta)
|
||||
|
@ -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)
|
||||
break
|
||||
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)
|
||||
threshold = 7
|
||||
if item_cost >= threshold:
|
||||
|
@ -727,7 +727,7 @@ def merge(merger, self, lst):
|
||||
|
||||
assert dev.DeltaFormat == 0x8000
|
||||
varidx = (dev.StartSize << 16) + dev.EndSize
|
||||
delta = int(round(instancer[varidx]))
|
||||
delta = round(instancer[varidx])
|
||||
|
||||
attr = v+'Coordinate'
|
||||
setattr(self, attr, getattr(self, attr) + delta)
|
||||
@ -750,7 +750,7 @@ def merge(merger, self, lst):
|
||||
|
||||
assert dev.DeltaFormat == 0x8000
|
||||
varidx = (dev.StartSize << 16) + dev.EndSize
|
||||
delta = int(round(instancer[varidx]))
|
||||
delta = round(instancer[varidx])
|
||||
|
||||
setattr(self, name, getattr(self, name) + delta)
|
||||
|
||||
|
@ -87,7 +87,7 @@ def instantiateVariableFont(varfont, location, inplace=False):
|
||||
if c is not None:
|
||||
deltas[i] = deltas.get(i, 0) + scalar * c
|
||||
for i, delta in deltas.items():
|
||||
cvt[i] += int(round(delta))
|
||||
cvt[i] += round(delta)
|
||||
|
||||
if 'MVAR' in varfont:
|
||||
log.info("Mutating MVAR table")
|
||||
@ -99,7 +99,7 @@ def instantiateVariableFont(varfont, location, inplace=False):
|
||||
if mvarTag not in MVAR_entries:
|
||||
continue
|
||||
tableTag, itemName = MVAR_entries[mvarTag]
|
||||
delta = int(round(varStoreInstancer[rec.VarIdx]))
|
||||
delta = round(varStoreInstancer[rec.VarIdx])
|
||||
if not delta:
|
||||
continue
|
||||
setattr(varfont[tableTag], itemName,
|
||||
|
@ -49,7 +49,7 @@ class OnlineVarStoreBuilder(object):
|
||||
return self._store
|
||||
|
||||
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)
|
||||
inner = len(self._data.Item)
|
||||
self._data.Item.append(deltas)
|
||||
|
Loading…
x
Reference in New Issue
Block a user