Skip to content
This repository has been archived by the owner on Aug 9, 2023. It is now read-only.

Commit

Permalink
Add reverse_direction argument
Browse files Browse the repository at this point in the history
As described in
#20 (comment)
  • Loading branch information
James Godfrey-Kittle committed May 11, 2016
1 parent a3922c0 commit 3307c5d
Showing 1 changed file with 10 additions and 5 deletions.
15 changes: 10 additions & 5 deletions Lib/cu2qu/ufo.py
Expand Up @@ -27,7 +27,9 @@
from __future__ import print_function, division, absolute_import

from fontTools.pens.basePen import AbstractPen

from cu2qu import curve_to_quadratic, curves_to_quadratic
from cu2qu.pens import ReverseContourPen

__all__ = ['fonts_to_quadratic', 'font_to_quadratic']

Expand Down Expand Up @@ -97,11 +99,13 @@ def _get_segments(glyph):
return pen.segments


def _set_segments(glyph, segments):
def _set_segments(glyph, segments, reverse_direction):
"""Draw segments as extracted by GetSegmentsPen back to a glyph."""

glyph.clearContours()
pen = glyph.getPen()
if reverse_direction:
pen = ReverseContourPen(pen)
for tag, args in segments:
if tag == 'move':
pen.moveTo(*args)
Expand Down Expand Up @@ -133,7 +137,7 @@ def _segments_to_quadratic(segments, max_err, stats):
return [('qcurve', p) for p in new_points]


def _fonts_to_quadratic(fonts, max_err, stats):
def _fonts_to_quadratic(fonts, max_err, reverse_direction, stats):
"""Do the actual conversion of fonts, after arguments have been set up."""

for glyphs in zip(*fonts):
Expand All @@ -155,10 +159,11 @@ def _fonts_to_quadratic(fonts, max_err, stats):

new_segments_by_glyph = zip(*new_segments_by_location)
for glyph, new_segments in zip(glyphs, new_segments_by_glyph):
_set_segments(glyph, new_segments)
_set_segments(glyph, new_segments, reverse_direction)


def fonts_to_quadratic(fonts, max_err_em=None, max_err=None,
def fonts_to_quadratic(
fonts, max_err_em=None, max_err=None, reverse_direction=False,
stats=None, dump_stats=False):
"""Convert the curves of a collection of fonts to quadratic.
Expand Down Expand Up @@ -187,7 +192,7 @@ def fonts_to_quadratic(fonts, max_err_em=None, max_err=None,
num_fonts = len(fonts)
assert len(max_errors) == num_fonts

_fonts_to_quadratic(fonts, max_errors, stats)
_fonts_to_quadratic(fonts, max_errors, reverse_direction, stats)

if dump_stats:
spline_lengths = sorted(stats.keys())
Expand Down

0 comments on commit 3307c5d

Please sign in to comment.