ttfquery.glyph
Representation of a single glyph including contour extraction
Functions
decomposeOutline(
contour
,
steps
= 3
)
Decompose a single TrueType contour to a line-loop
In essence, this is the "interpretation" of the font
as geometric primitives. I only support line and
quadratic (conic) segments, which should support most
TrueType fonts as far as I know.
The process consists of first scanning for any multi-
off-curve control-point runs. For each pair of such
control points, we insert a new on-curve control point.
Once we have the "expanded" control point array we
scan through looking for each segment which includes
an off-curve control point. These should only be
bracketed by on-curve control points. For each
found segment, we call our integrateQuadratic method
to produce a set of points interpolating between the
end points as affected by the middle control point.
All other control points merely generate a single
line-segment between the endpoints.
integrateQuadratic(
points
,
steps
= 3
)
Get points on curve for quadratic w/ end points A and C
Basis Equations are taken from here:
http://www.truetype.demon.co.uk/ttoutln.htm
This is a very crude approach to the integration,
everything is coded directly in Python, with no
attempts to speed up the process.
XXX Should eventually provide adaptive steps so that
the angle between the elements can determine how
many steps are used.
Classes
Object encapsulating metadata regarding a particular glyph
__init__(
self
,
glyphName
)
Initialize the glyph object
- glyphName
- font's glyphName for this glyph, see glyphquery.glyphName() for extracting the appropriate name from character and encoding.
_calculateContours(
self
,
charglyf
,
glyf
,
font
)
Create expanded contour data-set from TTF charglyph entry
This is called recursively for composite glyphs, so
I suppose a badly-formed TTF file could cause an infinite
loop.
- charglyph
- glyf table's entry for the target character
- glyf
- the glyf table (used for recursive calls)