BezierPath

BezierPath(path=None, glyphSet=None)

Return a BezierPath object. This is a reusable object, if you want to draw the same over and over again.

# create a bezier path
path = BezierPath()

# move to a point
path.moveTo((100, 100))
# line to a point
path.lineTo((100, 200))
path.lineTo((200, 200))
# close the path
path.closePath()

# loop over a range of 10
for i in range(10):
    # set a random color with alpha value of .3
    fill(random(), random(), random(), .3)
    # in each loop draw the path
    drawPath(path)
    # translate the canvas
    translate(50, 50)

path.text("Hello world", font="Helvetica", fontSize=30, offset=(210, 210))

print("All Points:")
print(path.points)

print("On Curve Points:")
print(path.onCurvePoints)

print("Off Curve Points:")
print(path.offCurvePoints)

# print out all points from all segments in all contours
for contour in path.contours:
    for segment in contour:
        for x, y in segment:
            print((x, y))
    print(["contour is closed", "contour is open"][contour.open])

# translate the path
path.translate(0, -100)
# draw the path again
drawPath(path)
# translate the path
path.translate(-300, 0)
path.scale(2)
# draw the path again
drawPath(path)
class BezierPath(path=None, glyphSet=None)

A bezier path object, if you want to draw the same over and over again.

contourClass

alias of BezierContour

moveTo(point)

Move to a point x, y.

lineTo(point)

Line to a point x, y.

curveTo(*points)

Draw a cubic bezier with an arbitrary number of control points.

The last point specified is on-curve, all others are off-curve (control) points.

qCurveTo(*points)

Draw a whole string of quadratic curve segments.

The last point specified is on-curve, all others are off-curve (control) points.

closePath()

Close the path.

beginPath(identifier=None)

Begin using the path as a so called point pen and start a new subpath.

addPoint(point, segmentType=None, smooth=False, name=None, identifier=None, **kwargs)

Use the path as a point pen and add a point to the current subpath. beginPath must have been called prior to adding points with addPoint calls.

endPath()

End the current subpath. Calling this method has two distinct meanings depending on the context:

When the bezier path is used as a segment pen (using moveTo, lineTo, etc.), the current subpath will be finished as an open contour.

When the bezier path is used as a point pen (using beginPath, addPoint and endPath), the path will process all the points added with addPoint, finishing the current subpath.

addComponent(glyphName, transformation)

Add a sub glyph. The ‘transformation’ argument must be a 6-tuple containing an affine transformation, or a Transform object from the fontTools.misc.transform module. More precisely: it should be a sequence containing 6 numbers.

A glyphSet is required during initialization of the BezierPath object.

drawToPen(pen)

Draw the bezier path into a pen

drawToPointPen(pointPen)

Draw the bezier path into a point pen.

arc(center, radius, startAngle, endAngle, clockwise)

Arc with center and a given radius, from startAngle to endAngle, going clockwise if clockwise is True and counter clockwise if clockwise is False.

arcTo(pt1, pt2, radius)

Arc from one point to an other point with a given radius.

rect(x, y, w, h)

Add a rectangle at possition x, y with a size of w, h

oval(x, y, w, h)

Add a oval at possition x, y with a size of w, h

text(txt, offset=None, font='LucidaGrande', fontSize=10, align=None)

Draws a txt with a font and fontSize at an offset in the bezier path. If a font path is given the font will be installed and used directly.

Optionally an alignment can be set. Possible align values are: “left”, “center” and “right”.

The default alignment is left.

Optionally txt can be a FormattedString.

textBox(txt, box, font='LucidaGrande', fontSize=10, align=None, hyphenation=None)

Draws a txt with a font and fontSize in a box in the bezier path. If a font path is given the font will be installed and used directly.

Optionally an alignment can be set. Possible align values are: “left”, “center” and “right”.

The default alignment is left.

Optionally hyphenation can be provided.

Optionally txt can be a FormattedString. Optionally box can be a BezierPath.

traceImage(path, threshold=0.2, blur=None, invert=False, turd=2, tolerance=0.2, offset=None)

Convert a given image to a vector outline.

Optionally some tracing options can be provide:

  • threshold: the threshold used to bitmap an image
  • blur: the image can be blurred
  • invert: invert to the image
  • turd: the size of small turd that can be ignored
  • tolerance: the precision tolerance of the vector outline
  • offset: add the traced vector outline with an offset to the BezierPath
getNSBezierPath()

Return the nsBezierPath.

setNSBezierPath(path)

Set a nsBezierPath.

pointInside(xy)

Check if a point x, y is inside a path.

bounds()

Return the bounding box of the path.

controlPointBounds()

Return the bounding box of the path including the offcurve points.

optimizePath()
copy()

Copy the bezier path.

reverse()

Reverse the path direction

appendPath(otherPath)

Append a path.

translate(x=0, y=0)

Translate the path with a given offset.

rotate(angle, center=(0, 0))

Rotate the path around the center point (which is the origin by default) with a given angle in degrees.

scale(x=1, y=None, center=(0, 0))

Scale the path with a given x (horizontal scale) and y (vertical scale).

If only 1 argument is provided a proportional scale is applied.

The center of scaling can optionally be set via the center keyword argument. By default this is the origin.

skew(angle1, angle2=0, center=(0, 0))

Skew the path with given angle1 and angle2.

If only one argument is provided a proportional skew is applied.

The center of skewing can optionally be set via the center keyword argument. By default this is the origin.

transform(transformMatrix, center=(0, 0))

Transform a path with a transform matrix (xy, xx, yy, yx, x, y).

union(other)

Return the union between two bezier paths.

removeOverlap()

Remove all overlaps in a bezier path.

difference(other)

Return the difference between two bezier paths.

intersection(other)

Return the intersection between two bezier paths.

xor(other)

Return the xor between two bezier paths.

intersectionPoints(other=None)

Return a list of intersection points as x, y tuples.

Optionaly provide an other path object to find intersection points.

points

Return a list of all points.

onCurvePoints

Return a list of all on curve points.

offCurvePoints

Return a list of all off curve points.

contours

Return a list of contours with all point coordinates sorted in segments. A contour object has an open attribute.