180 lines
14 KiB
HTML
180 lines
14 KiB
HTML
|
|
<!doctype html PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
|
|
<html><head><title>Python: module fontTools.pens.basePen</title>
|
|
</head><body bgcolor="#f0f0f8">
|
|
|
|
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="heading">
|
|
<tr bgcolor="#7799ee">
|
|
<td valign=bottom> <br>
|
|
<font color="#ffffff" face="helvetica, arial"> <br><big><big><strong><a href="fontTools.html"><font color="#ffffff">fontTools</font></a>.<a href="fontTools.pens.html"><font color="#ffffff">pens</font></a>.basePen</strong></big></big></font></td
|
|
><td align=right valign=bottom
|
|
><font color="#ffffff" face="helvetica, arial"><a href=".">index</a><br><a href="file:/code/fontTools/Lib/fontTools/pens/basePen.py">/code/fontTools/Lib/fontTools/pens/basePen.py</a></font></td></tr></table>
|
|
<p><tt>fontTools.pens.basePen.py -- Tools and base classes to build pen objects.<br>
|
|
<br>
|
|
The Pen Protocol<br>
|
|
<br>
|
|
A Pen is a kind of object that standardizes the way how to "draw" outlines:<br>
|
|
it is a middle man between an outline and a drawing. In other words:<br>
|
|
it is an abstraction for drawing outlines, making sure that outline objects<br>
|
|
don't need to know the details about how and where they're being drawn, and<br>
|
|
that drawings don't need to know the details of how outlines are stored.<br>
|
|
<br>
|
|
The most basic pattern is this:<br>
|
|
<br>
|
|
outline.draw(pen) # 'outline' draws itself onto 'pen'<br>
|
|
<br>
|
|
Pens can be used to render outlines to the screen, but also to construct<br>
|
|
new outlines. Eg. an outline object can be both a drawable object (it has a<br>
|
|
draw() method) as well as a pen itself: you *build* an outline using pen<br>
|
|
methods.<br>
|
|
<br>
|
|
The <a href="#AbstractPen">AbstractPen</a> class defines the Pen protocol. It implements almost<br>
|
|
nothing (only no-op closePath() and endPath() methods), but is useful<br>
|
|
for documentation purposes. Subclassing it basically tells the reader:<br>
|
|
"this class implements the Pen protocol.". An examples of an <a href="#AbstractPen">AbstractPen</a><br>
|
|
subclass is fontTools.pens.transformPen.TransformPen.<br>
|
|
<br>
|
|
The <a href="#BasePen">BasePen</a> class is a base implementation useful for pens that actually<br>
|
|
draw (for example a pen renders outlines using a native graphics engine).<br>
|
|
<a href="#BasePen">BasePen</a> contains a lot of base functionality, making it very easy to build<br>
|
|
a pen that fully conforms to the pen protocol. Note that if you subclass<br>
|
|
<a href="#BasePen">BasePen</a>, you _don't_ override moveTo(), lineTo(), etc., but _moveTo(),<br>
|
|
_lineTo(), etc. See the <a href="#BasePen">BasePen</a> doc string for details. Examples of<br>
|
|
<a href="#BasePen">BasePen</a> subclasses are fontTools.pens.boundsPen.BoundsPen and<br>
|
|
fontTools.pens.cocoaPen.CocoaPen.<br>
|
|
<br>
|
|
Coordinates are usually expressed as (x, y) tuples, but generally any<br>
|
|
sequence of length 2 will do.</tt></p>
|
|
<p>
|
|
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
|
|
<tr bgcolor="#ee77aa">
|
|
<td colspan=3 valign=bottom> <br>
|
|
<font color="#ffffff" face="helvetica, arial"><big><strong>Classes</strong></big></font></td></tr>
|
|
|
|
<tr><td bgcolor="#ee77aa"><tt> </tt></td><td> </td>
|
|
<td width="100%"><dl>
|
|
<dt><font face="helvetica, arial"><a href="fontTools.pens.basePen.html#AbstractPen">AbstractPen</a>
|
|
</font></dt><dd>
|
|
<dl>
|
|
<dt><font face="helvetica, arial"><a href="fontTools.pens.basePen.html#BasePen">BasePen</a>
|
|
</font></dt></dl>
|
|
</dd>
|
|
</dl>
|
|
<p>
|
|
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
|
|
<tr bgcolor="#ffc8d8">
|
|
<td colspan=3 valign=bottom> <br>
|
|
<font color="#000000" face="helvetica, arial"><a name="AbstractPen">class <strong>AbstractPen</strong></a></font></td></tr>
|
|
|
|
<tr><td bgcolor="#ffc8d8"><tt> </tt></td><td> </td>
|
|
<td width="100%">Methods defined here:<br>
|
|
<dl><dt><a name="AbstractPen-addComponent"><strong>addComponent</strong></a>(self, glyphName, transformation)</dt><dd><tt>Add a sub glyph. The 'transformation' argument must be a 6-tuple<br>
|
|
containing an affine transformation, or a Transform object from the<br>
|
|
fontTools.misc.transform module. More precisely: it should be a<br>
|
|
sequence containing 6 numbers.</tt></dd></dl>
|
|
|
|
<dl><dt><a name="AbstractPen-closePath"><strong>closePath</strong></a>(self)</dt><dd><tt>Close the current sub path. You must call either pen.<a href="#AbstractPen-closePath">closePath</a>()<br>
|
|
or pen.<a href="#AbstractPen-endPath">endPath</a>() after each sub path.</tt></dd></dl>
|
|
|
|
<dl><dt><a name="AbstractPen-curveTo"><strong>curveTo</strong></a>(self, *points)</dt><dd><tt>Draw a cubic bezier with an arbitrary number of control points.<br>
|
|
<br>
|
|
The last point specified is on-curve, all others are off-curve<br>
|
|
(control) points. If the number of control points is > 2, the<br>
|
|
segment is split into multiple bezier segments. This works<br>
|
|
like this:<br>
|
|
<br>
|
|
Let n be the number of control points (which is the number of<br>
|
|
arguments to this call minus 1). If n==2, a plain vanilla cubic<br>
|
|
bezier is drawn. If n==1, we fall back to a quadratic segment and<br>
|
|
if n==0 we draw a straight line. It gets interesting when n>2:<br>
|
|
n-1 PostScript-style cubic segments will be drawn as if it were<br>
|
|
one curve. See <a href="#-decomposeSuperBezierSegment">decomposeSuperBezierSegment</a>().<br>
|
|
<br>
|
|
The conversion algorithm used for n>2 is inspired by NURB<br>
|
|
splines, and is conceptually equivalent to the TrueType "implied<br>
|
|
points" principle. See also <a href="#-decomposeQuadraticSegment">decomposeQuadraticSegment</a>().</tt></dd></dl>
|
|
|
|
<dl><dt><a name="AbstractPen-endPath"><strong>endPath</strong></a>(self)</dt><dd><tt>End the current sub path, but don't close it. You must call<br>
|
|
either pen.<a href="#AbstractPen-closePath">closePath</a>() or pen.<a href="#AbstractPen-endPath">endPath</a>() after each sub path.</tt></dd></dl>
|
|
|
|
<dl><dt><a name="AbstractPen-lineTo"><strong>lineTo</strong></a>(self, pt)</dt><dd><tt>Draw a straight line from the current point to 'pt'.</tt></dd></dl>
|
|
|
|
<dl><dt><a name="AbstractPen-moveTo"><strong>moveTo</strong></a>(self, pt)</dt><dd><tt>Begin a new sub path, set the current point to 'pt'. You must<br>
|
|
end each sub path with a call to pen.<a href="#AbstractPen-closePath">closePath</a>() or pen.<a href="#AbstractPen-endPath">endPath</a>().</tt></dd></dl>
|
|
|
|
<dl><dt><a name="AbstractPen-qCurveTo"><strong>qCurveTo</strong></a>(self, *points)</dt><dd><tt>Draw a whole string of quadratic curve segments.<br>
|
|
<br>
|
|
The last point specified is on-curve, all others are off-curve<br>
|
|
points.<br>
|
|
<br>
|
|
This method implements TrueType-style curves, breaking up curves<br>
|
|
using 'implied points': between each two consequtive off-curve points,<br>
|
|
there is one implied point exactly in the middle between them. See<br>
|
|
also <a href="#-decomposeQuadraticSegment">decomposeQuadraticSegment</a>().<br>
|
|
<br>
|
|
The last argument (normally the on-curve point) may be None.<br>
|
|
This is to support contours that have NO on-curve points (a rarely<br>
|
|
seen feature of TrueType outlines).</tt></dd></dl>
|
|
|
|
</td></tr></table> <p>
|
|
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
|
|
<tr bgcolor="#ffc8d8">
|
|
<td colspan=3 valign=bottom> <br>
|
|
<font color="#000000" face="helvetica, arial"><a name="BasePen">class <strong>BasePen</strong></a>(<a href="fontTools.pens.basePen.html#AbstractPen">AbstractPen</a>)</font></td></tr>
|
|
|
|
<tr bgcolor="#ffc8d8"><td rowspan=2><tt> </tt></td>
|
|
<td colspan=2><tt>Base class for drawing pens. You must override _moveTo, _lineTo and<br>
|
|
_curveToOne. You may additionally override _closePath, _endPath,<br>
|
|
addComponent and/or _qCurveToOne. You should not override any other<br>
|
|
methods.<br> </tt></td></tr>
|
|
<tr><td> </td>
|
|
<td width="100%">Methods defined here:<br>
|
|
<dl><dt><a name="BasePen-__init__"><strong>__init__</strong></a>(self, glyphSet)</dt></dl>
|
|
|
|
<dl><dt><a name="BasePen-addComponent"><strong>addComponent</strong></a>(self, glyphName, transformation)</dt><dd><tt>This default implementation simply transforms the points<br>
|
|
of the base glyph and draws it onto self.</tt></dd></dl>
|
|
|
|
<dl><dt><a name="BasePen-closePath"><strong>closePath</strong></a>(self)</dt></dl>
|
|
|
|
<dl><dt><a name="BasePen-curveTo"><strong>curveTo</strong></a>(self, *points)</dt></dl>
|
|
|
|
<dl><dt><a name="BasePen-endPath"><strong>endPath</strong></a>(self)</dt></dl>
|
|
|
|
<dl><dt><a name="BasePen-lineTo"><strong>lineTo</strong></a>(self, pt)</dt></dl>
|
|
|
|
<dl><dt><a name="BasePen-moveTo"><strong>moveTo</strong></a>(self, pt)</dt></dl>
|
|
|
|
<dl><dt><a name="BasePen-qCurveTo"><strong>qCurveTo</strong></a>(self, *points)</dt></dl>
|
|
|
|
</td></tr></table></td></tr></table><p>
|
|
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
|
|
<tr bgcolor="#eeaa77">
|
|
<td colspan=3 valign=bottom> <br>
|
|
<font color="#ffffff" face="helvetica, arial"><big><strong>Functions</strong></big></font></td></tr>
|
|
|
|
<tr><td bgcolor="#eeaa77"><tt> </tt></td><td> </td>
|
|
<td width="100%"><dl><dt><a name="-decomposeQuadraticSegment"><strong>decomposeQuadraticSegment</strong></a>(points)</dt><dd><tt>Split the quadratic curve segment described by 'points' into a list<br>
|
|
of "atomic" quadratic segments. The 'points' argument must be a sequence<br>
|
|
with length 2 or greater, containing (x, y) coordinates. The last point<br>
|
|
is the destination on-curve point, the rest of the points are off-curve<br>
|
|
points. The start point should not be supplied.<br>
|
|
<br>
|
|
This function returns a list of (pt1, pt2) tuples, which each specify a<br>
|
|
plain quadratic bezier segment.</tt></dd></dl>
|
|
<dl><dt><a name="-decomposeSuperBezierSegment"><strong>decomposeSuperBezierSegment</strong></a>(points)</dt><dd><tt>Split the SuperBezier described by 'points' into a list of regular<br>
|
|
bezier segments. The 'points' argument must be a sequence with length<br>
|
|
3 or greater, containing (x, y) coordinates. The last point is the<br>
|
|
destination on-curve point, the rest of the points are off-curve points.<br>
|
|
The start point should not be supplied.<br>
|
|
<br>
|
|
This function returns a list of (pt1, pt2, pt3) tuples, which each<br>
|
|
specify a regular curveto-style bezier segment.</tt></dd></dl>
|
|
</td></tr></table><p>
|
|
<table width="100%" cellspacing=0 cellpadding=2 border=0 summary="section">
|
|
<tr bgcolor="#55aa55">
|
|
<td colspan=3 valign=bottom> <br>
|
|
<font color="#ffffff" face="helvetica, arial"><big><strong>Data</strong></big></font></td></tr>
|
|
|
|
<tr><td bgcolor="#55aa55"><tt> </tt></td><td> </td>
|
|
<td width="100%"><strong>__all__</strong> = ['AbstractPen', 'BasePen', 'decomposeSuperBezierSegment', 'decomposeQuadraticSegment']</td></tr></table>
|
|
</body></html> |