Wojciech Muła wrote:
> swiftset wrote:
>   
>> 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

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to