473,394 Members | 2,063 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

interpreting glyph outlines from ttfquery?

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

Mar 22 '07 #1
2 2692
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.
Mar 22 '07 #2
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/...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

Mar 22 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: r6uji7 | last post by:
hello, i am new to PHP programming and wondered if u could help. lets say i have the following files: 1. error.php: that is routed to for all errors. this page should display proper and...
4
by: David Winter | last post by:
I am looking for something I have seen a few months ago. Maybe someone here remembers where this site is or has built something similar ... I couldn't find it. What I am looking for is a web...
1
by: Charlie | last post by:
Hi, I'm looking for a way to obtain the width of a string, either in actual inches/centimeters, or pixels will also work. Unfortunately this seems difficult as I'd like to keep things as close to...
3
by: Chris Saunders | last post by:
I am attempting to write and interface from another language to some C code. I am having some difficulty interpreting a declaration. int (*SSL_CTX_get_verify_callback(SSL_CTX...
3
by: Chris Saunders | last post by:
Hope this question is appropriate here. I'm writing an interface to some C code for the language Eiffel. I have come across this macro and am having difficuly interpreting what it returns: ...
0
by: Julia | last post by:
Hi, Is it possible to set a different image for the sort Glyph in DataGridView? Thanks in advance.
11
by: Chris Hayes | last post by:
Greetings, I have an ASP.NET page that accepts input from an HtmlInputFile object. I have set the maximum size for HttpRequests to 2MB in the web.config file. And now I am trying to CATCH...
11
by: Manmeet Mittal | last post by:
> Hi all this is Manmeet Mittal,
0
by: Greg Wright | last post by:
I had the same problem and found that if I set Virtual = false, then the glyph went away after doing the EndEdit() function. I didn't have to do an EndEdit at all after that to get the Pencil gliph...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.