I don’t think this rounding is needed

This commit is contained in:
Khaled Hosny 2017-10-14 18:52:26 +02:00
parent 0355d967a0
commit 2a69b4b619

View File

@ -2,47 +2,8 @@ from __future__ import print_function, division, absolute_import
from fontTools.misc.py23 import *
from fontTools.pens.basePen import BasePen
# Number to String Conversion
def valueToString(v):
"""
>>> valueToString(0)
'0'
>>> valueToString(10)
'10'
>>> valueToString(-10)
'-10'
>>> valueToString(0.1)
'0.1'
>>> valueToString(0.0001)
'0.0001'
>>> valueToString(0.00001)
'0'
>>> valueToString(10.0001)
'10.0001'
>>> valueToString(10.00001)
'10'
"""
if int(v) == v:
v = "%d" % (int(v))
else:
v = "%.4f" % v
# strip unnecessary zeros
# there is probably an easier way to do this
compiled = []
for c in reversed(v):
if not compiled and c == "0":
continue
compiled.append(c)
v = "".join(reversed(compiled))
if v.endswith("."):
v = v[:-1]
if not v:
v = "0"
return v
def pointToString(pt):
return " ".join([valueToString(i) for i in pt])
return " ".join([str(i) for i in pt])
class SVGPen(BasePen):
@ -130,11 +91,11 @@ class SVGPen(BasePen):
# vertical line
elif x == self._lastX:
cmd = "V"
pts = valueToString(y)
pts = str(y)
# horizontal line
elif y == self._lastY:
cmd = "H"
pts = valueToString(x)
pts = str(x)
# previous was a moveto
elif self._lastCommand == "M":
cmd = None