coldtype.pens.datpen.DATPen

class DATPen(*args, **kwargs)

Bases: coldtype.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

add_frame(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

ch(fn: Callable[[coldtype.pens.draftingpen.DraftingPen], None], *args)

For simple take-one callback functions in a chain

chain(fn: Callable[[coldtype.pens.draftingpen.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

flatpoints()

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

flatten(length=10, segmentLines=True)

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, glyphSet=None)

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=False, opacity=1.0)

Get/set an image fill

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

Get/set an image fill

intersection(otherPen)

Calculate and return the intersection of this shape and another.

layer(*layers)

For every lambda function you pass in, a copy of the original pen is made and passed to your function, building up a multi-layered version and removing the original version; alternatively, pass in an integer n to simply duplicate the current value of the pen n-times

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

null()

For chaining; return an empty instead of this pen

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

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

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

AKA expandStroke

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

AKA expandStroke

oval(rect)

Oval primitive

pen()

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

pens()

Return a set representation of this

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

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).

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.

remove_overlap()

Remove overlaps within this shape and return itself.

reverse()

Reverse the winding direction of the pen.

reverseDifference(otherPen)

Calculate and return the reverseDifference of this shape and another.

ro()

Remove overlaps within this shape and return itself.

rotate(degrees, point=None)

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

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

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

skeleton(scale=1, returnSet=False)

Vector-editing visualization

skeletonPoints()

WIP

sleep(time)

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

smoothen()

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

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

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

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

to_glyph(name=None, width=None, allow_blank=False)

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.