Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting the vector points of a letter in a truetype font

Tags:

c++

fonts

winapi

Since True Type fonts are just vectors, I was wondering if there was a way to get the vectors (array of points) for a letter given that i'm using the WinAPI. Thanks

like image 800
jmasterx Avatar asked May 02 '10 01:05

jmasterx


2 Answers

Use the GetGlyphOutline function with the GGO_NATIVE option.

http://msdn.microsoft.com/en-us/library/dd144891%28v=VS.85%29.aspx

Actually, True Type fonts are defined by Bezier curves, not vectors, so you get back a list of curves. Most graphics libraries have a way of drawing Bezier curves anyway so you can get by just knowing that a curve is defined by several control points.

The font will be pre-fitted to a grid (eg, hinting).

like image 166
Steve Hanov Avatar answered Nov 14 '22 21:11

Steve Hanov


I don't know if the Win32 API will give you a deconstructed glyph. The FOSS FreeType2 library provides glyph points in FT_Outline::points.

Note that a glyph is more than its points. You have to work with Bézier curves and hinting to reproduce a glyph correctly. The hinting part is crucial for small fonts, and is extremely difficult to get right. FreeType usually does all this for you.

like image 43
Marcelo Cantos Avatar answered Nov 14 '22 23:11

Marcelo Cantos