I don’t think this rounding is needed
This commit is contained in:
parent
0355d967a0
commit
2a69b4b619
@ -2,47 +2,8 @@ from __future__ import print_function, division, absolute_import
|
|||||||
from fontTools.misc.py23 import *
|
from fontTools.misc.py23 import *
|
||||||
from fontTools.pens.basePen import BasePen
|
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):
|
def pointToString(pt):
|
||||||
return " ".join([valueToString(i) for i in pt])
|
return " ".join([str(i) for i in pt])
|
||||||
|
|
||||||
class SVGPen(BasePen):
|
class SVGPen(BasePen):
|
||||||
|
|
||||||
@ -130,11 +91,11 @@ class SVGPen(BasePen):
|
|||||||
# vertical line
|
# vertical line
|
||||||
elif x == self._lastX:
|
elif x == self._lastX:
|
||||||
cmd = "V"
|
cmd = "V"
|
||||||
pts = valueToString(y)
|
pts = str(y)
|
||||||
# horizontal line
|
# horizontal line
|
||||||
elif y == self._lastY:
|
elif y == self._lastY:
|
||||||
cmd = "H"
|
cmd = "H"
|
||||||
pts = valueToString(x)
|
pts = str(x)
|
||||||
# previous was a moveto
|
# previous was a moveto
|
||||||
elif self._lastCommand == "M":
|
elif self._lastCommand == "M":
|
||||||
cmd = None
|
cmd = None
|
||||||
|
Loading…
x
Reference in New Issue
Block a user