Merge pull request #16 from googlei18n/py23

Use __future__ imports to ease Python2/3 compat
This commit is contained in:
Behdad Esfahbod 2015-12-04 22:44:53 -08:00
commit 1ab0631ba4
2 changed files with 11 additions and 7 deletions

View File

@ -13,6 +13,8 @@
# limitations under the License.
from __future__ import print_function, division, absolute_import
from math import hypot
from fontTools.misc import bezierTools
@ -110,10 +112,10 @@ def cubic_approx_spline(p, n):
return p[0], p1, p[3]
spline = [p[0]]
ts = [(float(i) / n) for i in range(1, n)]
ts = [i / n for i in range(1, n)]
segments = bezierTools.splitCubicAtT(p[0], p[1], p[2], p[3], *ts)
for i in range(len(segments)):
segment = cubic_approx(segments[i], float(i) / (n - 1))
segment = cubic_approx(segments[i], i / (n - 1))
spline.append(segment[1])
spline.append(p[3])
return spline
@ -125,15 +127,15 @@ def curve_spline_dist(bezier, spline):
TOTAL_STEPS = 20
error = 0
n = len(spline) - 2
steps = TOTAL_STEPS / n
steps = TOTAL_STEPS // n
for i in range(1, n + 1):
segment = [
spline[0] if i == 1 else segment[2],
spline[i],
spline[i + 1] if i == n else lerp_pt(spline[i], spline[i + 1], 0.5)]
for j in range(steps):
p1 = cubic_bezier_at(bezier, (float(j) / steps + i - 1) / n)
p2 = quadratic_bezier_at(segment, float(j) / steps)
p1 = cubic_bezier_at(bezier, (j / steps + i - 1) / n)
p2 = quadratic_bezier_at(segment, j / steps)
error = max(error, dist(p1, p2))
return error

View File

@ -24,6 +24,8 @@ the resulting splines are interpolation-compatible.
"""
from __future__ import print_function, division, absolute_import
from robofab.objects.objectsRF import RSegment
from cu2qu import curve_to_quadratic, curves_to_quadratic
@ -63,8 +65,8 @@ def fonts_to_quadratic(*fonts, **kwargs):
if dump_report:
spline_lengths = report.keys()
spline_lengths.sort()
print 'New spline lengths:\n%s\n' % (
'\n'.join('%s: %d' % (l, report[l]) for l in spline_lengths))
print('New spline lengths:\n%s\n' % (
'\n'.join('%s: %d' % (l, report[l]) for l in spline_lengths)))
return report