Skip to content

Mangled contours if start point is offcurve #5

@frankrolf

Description

@frankrolf

I noticed that an interpolation with scaleFast may mangle curves if the starting point is inconsistent across masters – one contour may start with an offcurve, the other with an oncurve. While this doesn’t cause any problems in many interpolation scenarios, scaleFast isn’t that forgiving:

Screen Shot 2019-09-26 at 12 11 10

I solved the issue by pre-processing my UFOs with this little script first, which makes sure all contours start with oncurve points:

from fontTools.ufoLib.pointPen import PointToSegmentPen


def redraw_glyph(g):
    contours = []

    for contour in g.contours:
        points = [p for p in contour.points]
        while points[0].type == 'offcurve':
            points.append(points.pop(0))
        contours.append(points)

    g.prepareUndo('redraw')
    rg = RGlyph()
    ppen = PointToSegmentPen(rg.getPen())

    for contour in contours:
        ppen.beginPath()
        for point in contour:
            if point.type == 'offcurve':
                ptype = None
            else:
                ptype = point.type
            ppen.addPoint((point.x, point.y), ptype)
        ppen.endPath()

    g.clearContours()
    g.appendGlyph(rg)
    g.performUndo()

f = CurrentFont()
glyphs_with_contours = [g for g in f if len(g.contours)]
glyphs_with_offcurve_start = []

for g in glyphs_with_contours:
    for contour in g.contours:
        first_point = contour.points[0]
        first_bPoint = contour.bPoints[0]
        first_point_coords = (first_point.x, first_point.y)
        if first_point_coords != first_bPoint.anchor:
            glyphs_with_offcurve_start.append(g)

for g in glyphs_with_offcurve_start:
    print(g.name)
    redraw_glyph(g)

(for a modernized version of this script, which processes all UFOs at once, see https://gist.github.com/frankrolf/e75980e3895df26615cc8ed1e60f9c5b )

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions