coldtype.pens.datpen.DATPen

class DATPen(*args, **kwargs)

Bases: drafting.pens.draftingpen.DraftingPen

Main vector representation in Coldtype

DATPen is a subclass of fontTools RecordingPen

addFrame(frame, typographic=False, passthru=False)

Add a new frame to the DATPen, replacing any old frame. Passthru ignored, there for compatibility

ambit(th=False, tv=False)

Get the calculated rect boundary of the DraftingPen; th means (t)rue (h)orizontal; ty means (t)rue (v)ertical; passing either ignores a non-bounds-derived frame in either dimension

attr(tag=None, field=None, **kwargs)

Set a style attribute on the pen.

bounds()

Calculate the bounds of this shape; mostly for internal use.

cast(_class, *args)

Quickly cast to a (different) subclass.

catmull(points, close=False)

Run a catmull spline through a series of points

chain(fn: Callable[[DraftingPen], None], *args)

For simple take-one callback functions in a chain

clearAttrs()

Remove all styling.

clearFrame()

Remove the DATPen frame.

closePath()

Close the current sub path. You must call either pen.closePath() or pen.endPath() after each sub path.

contain(rect)

For conveniently marking an arbitrary Rect container.

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. If the number of control points is > 2, the segment is split into multiple bezier segments. This works like this:

Let n be the number of control points (which is the number of arguments to this call minus 1). If n==2, a plain vanilla cubic bezier is drawn. If n==1, we fall back to a quadratic segment and if n==0 we draw a straight line. It gets interesting when n>2: n-1 PostScript-style cubic segments will be drawn as if it were one curve. See decomposeSuperBezierSegment().

The conversion algorithm used for n>2 is inspired by NURB splines, and is conceptually equivalent to the TrueType “implied points” principle. See also decomposeQuadraticSegment().

difference(otherPen)

Calculate and return the difference of this shape and another.

dots(radius=4)

(Necessary?) Create circles at moveTo commands

endPath()

End the current sub path, but don’t close it. You must call either pen.closePath() or pen.endPath() after each sub path.

explode()

Read each contour into its own DATPen; returns a DATPens

f(*value)

Get/set a (f)ill

fill(*value)

Get/set a (f)ill

filmjitter(doneness, base=0, speed=10, 20, scale=2, 3, octaves=16)

An easy way to make something move in a way reminiscent of misregistered film

flatpoints()

Returns a flat list of points from the DATPen’s original contours; does not modify the DATPen

flatten(length=10)

Runs a fontTools FlattenPen on this pen

frameSet(th=False, tv=False)

Return a new DATPen represent ation of the frame of this DATPen.

glyph(glyph)

Play a glyph (like from defcon) into this pen.

gridlines(rect, x=20, y=None, absolute=False)

Construct a grid in the pen using x and (optionally) y subdivisions

hull(points)

Same as DraftingPen.line but calls closePath instead of endPath`

image(src=None, rect=Rect([0, 0, 500, 500]), pattern=True, opacity=1.0)

Get/set an image fill

img(src=None, rect=Rect([0, 0, 500, 500]), pattern=True, opacity=1.0)

Get/set an image fill

intersection(otherPen)

Calculate and return the intersection of this shape and another.

length(t=1)

Get the length of the curve for time t

line(points, moveTo=True, endPath=True)

Syntactic sugar for moveTo`+`lineTo`(…)+`endPath; can have any number of points

lineTo(p1)

Draw a straight line from the current point to ‘pt’.

lines()

Returns lines connecting point-representation of flatpoints

moveTo(p0)

Begin a new sub path, set the current point to ‘pt’. You must end each sub path with a call to pen.closePath() or pen.endPath().

noop(*args, **kwargs)

Does nothing

offset(x, y=None, transformFrame=True)

Translate this shape by x and y (pixel values).

ol(offset=1, drawInner=True, drawOuter=True, cap='square')

AKA expandStroke

outline(offset=1, drawInner=True, drawOuter=True, cap='square')

AKA expandStroke

oval(rect)

Oval primitive

pen()

Return a single-pen representation of this pen(set).

point_t(t=0.5)

Get point value for time t

points()

Returns a list of points grouped by contour from the DATPen’s original contours; useful for drawing bezier skeletons; does not modify the DATPen

polygon(sides, rect)

Polygon primitive; WIP

qCurveTo(*points)

Draw a whole string of quadratic curve segments.

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

This method implements TrueType-style curves, breaking up curves using ‘implied points’: between each two consequtive off-curve points, there is one implied point exactly in the middle between them. See also decomposeQuadraticSegment().

The last argument (normally the on-curve point) may be None. This is to support contours that have NO on-curve points (a rarely seen feature of TrueType outlines).

rasterized(rect, scale=1, pen_class=None, context=None)

Same as precompose but returns the Image created rather than setting that image as the attr-image of this pen

record(pen)

Play a pen into this pen, meaning that pen will be added to this one’s value.

rect(rect)

Rectangle primitive — moveTo/lineTo/lineTo/lineTo/closePath

removeOverlap()

Remove overlaps within this shape and return itself.

replace(fn: Callable[[DraftingPen], None], *args)

For simple take-one callback functions in a chain, to return what the function returns (not the element itself)

reverse()

Reverse the winding direction of the pen.

reverseDifference(otherPen)

Calculate and return the reverseDifference of this shape and another.

rotate(degrees, point=None)

Rotate this shape by a degree (in 360-scale, counterclockwise).

roughen(amplitude=10, threshold=10, ignore_ends=False)

Randomizes points in skeleton

round()

Round the values of this pen to integer values.

round_to(rounding)

Round the values of this pen to nearest multiple of rounding.

roundedRect(rect, hr, vr=None)

Rounded rectangle primitive

s(*value)

Get/set a (s)troke

scale(scaleX, scaleY=None, point=None)

Scale this shape by a percentage amount (1-scale).

scaleToHeight(h, shrink_only=False)

Scale this shape horizontally

scaleToRect(rect, preserveAspect=True, shrink_only=False)

Scale this shape into a Rect.

scaleToWidth(w, shrink_only=False)

Scale this shape horizontally

sine(r, periods)

Sine-wave primitive

skeleton(scale=1, returnSet=False)

Vector-editing visualization

skeletonPoints()

WIP

sleep(time)

Sleep call within the chain (if you want to measure something)

smooth()

Runs a catmull spline on the datpen, useful in combination as flatten+roughen+smooth

standingwave(r, periods, direction=1)

Standing-wave primitive

stroke(*value)

Get/set a (s)troke

strokeWidth(value)

Get/set a (s)troke (w)idth

subsegment(start=0, end=1)

Return a subsegment of the pen based on t values start and end

sw(value)

Get/set a (s)troke (w)idth

to_glyph(name=None, width=None)

Create a glyph (like from defcon) using this pen’s value. Warning: if path is unended, closedPath will be called

transform(transform, transformFrame=True)

Perform an arbitrary transformation on the pen, using the fontTools Transform class.

translate(x, y=None, transformFrame=True)

Translate this shape by x and y (pixel values).

union(otherPen)

Calculate and return the union of this shape and another.

ups()

Convert this single pen into a collection of pens, with one-pen in the collection (this pen)

xor(otherPen)

Calculate and return the XOR of this shape and another.