drafting.pens.draftingpen.DraftingPen¶
-
class
DraftingPen
(*args)¶ Bases:
fontTools.pens.recordingPen.RecordingPen
,drafting.sh.context.SHContext
Fluent subclass of 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.
-
chain
(fn: Callable[[drafting.pens.draftingpen.DraftingPen], None], *args)¶ For simple take-one callback functions in a chain
-
clearAttrs
()¶ Remove all styling.
-
closePath
()¶ Close the current sub path. You must call either pen.closePath() or pen.endPath() after each sub path.
-
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.
-
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
-
flatten
(length=10)¶ Runs a fontTools FlattenPen on this pen
-
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’.
-
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
-
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.
-
replace
(fn: Callable[[drafting.pens.draftingpen.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).
-
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
-
sleep
(time)¶ Sleep call within the chain (if you want to measure something)
-
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.
-