interpreting glyph outlines from ttfquery?

S

swiftset

I'm try to convert a glyph into a format I can easily numerically
manipulate. So far I've figured out how to use ttfquery to get a list
that represents the outline of a contour in a glyph:

from ttfquery import describe, glyphquery, glyph
f = describe.openFont("/usr/share/fonts/truetype/freefont/
FreeSans.ttf")
n = glyphquery.glyphName(f, 'D')
g = glyph.Glyph(n)
c = g.calculateContours(f)
o = glyph.decomposeOutline(c[1])

o looks like:

[array([182, 82],'s'),
(354, 82),
(420.22222222222229, 90.000000000000014),
(474.88888888888891, 114.0), ...,
array([182, 82],'s'),
array([182, 82],'s')]

Is this a polyline?

Thanks,
Alex
 
?

=?ISO-8859-2?Q?Wojciech_Mu=B3a?=

swiftset said:
I'm try to convert a glyph into a format I can easily numerically
manipulate. So far I've figured out how to use ttfquery to get a list
that represents the outline of a contour in a glyph:

from ttfquery import describe, glyphquery, glyph
f = describe.openFont("/usr/share/fonts/truetype/freefont/
FreeSans.ttf")
n = glyphquery.glyphName(f, 'D')
g = glyph.Glyph(n)
c = g.calculateContours(f)
o = glyph.decomposeOutline(c[1])

o looks like:

[array([182, 82],'s'),
(354, 82),
(420.22222222222229, 90.000000000000014),
(474.88888888888891, 114.0), ...,
array([182, 82],'s'),
array([182, 82],'s')]

Is this a polyline?

decomposeOutline docstring confirms -- it's a polyline. I think
elements marked with 's' starts new subpath.

w.
 
M

Mike C. Fletcher

Wojciech said:
swiftset said:
I'm try to convert a glyph into a format I can easily numerically
manipulate. So far I've figured out how to use ttfquery to get a list
that represents the outline of a contour in a glyph:

from ttfquery import describe, glyphquery, glyph
f = describe.openFont("/usr/share/fonts/truetype/freefont/
FreeSans.ttf")
n = glyphquery.glyphName(f, 'D')
g = glyph.Glyph(n)
c = g.calculateContours(f)
o = glyph.decomposeOutline(c[1])

o looks like:

[array([182, 82],'s'),
(354, 82),
(420.22222222222229, 90.000000000000014),
(474.88888888888891, 114.0), ...,
array([182, 82],'s'),
array([182, 82],'s')]

Is this a polyline?

decomposeOutline docstring confirms -- it's a polyline. I think
elements marked with 's' starts new subpath.

w.
Examples of rendering self.contours and self.outlines (created by
self.compile on the Glyph) using OpenGL operations are in the toolsfont
module in OpenGLContext:

http://pyopengl.cvs.sourceforge.net/pyopengl/OpenGLContext/scenegraph/text/toolsfont.py?view=markup

The outlines are simple 2D line-loops, the things with 's' are array
objects (not start coordinates), you can convert the whole thing to a
consistent array with numpy.array (or Numeric.array). That is, the 's'
is just an artefact of how the calculation was done, the values are all
2-element coordinates, some as Python tuples, some as 2-element
Numeric/numpy "short" arrays.

HTH,
Mike

--
________________________________________________
Mike C. Fletcher
Designer, VR Plumber, Coder
http://www.vrplumber.com
http://blog.vrplumber.com
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top