[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
RE: Information Request
RE: Information Request
Mon, 10 Apr 2000 13:25:45 -0400
Yes. You would need to write a function to get the advance width of
each character at the appropriate size.
Here's some code I use to accomplish the same thing use FreeType 1.3.1.
Note that I've omitted error handling for clarity and deleted a lot of
proprietary stuff that I'm not supposed disclose, and I haven't tried
compiling it after deleting the proprietary stuff, so it will probably
need tweaking in order to work properly. Also, it assumes there's
already a FreeType library instance avaialble in the global variable
FreeTypeLib, and it assumes you only care about the Unicode character
map from the font. Anyway, for what it's worth, here it is:
short Platform, Encoding;
int i, width=0;
TT_Open_Face( FreeTypeLib, font, &Face );
TT_Get_Face_Properties( Face, &Properties );
for ( i = 0; i < Properties.num_CharMaps; i++ )
if ( TT_Get_CharMap_ID( Face, i, &Platform, &Encoding ) == 0)
if ( Platform == 3 && Encoding == 1 ) ||
( Platform == 0 && Encoding == 0) )
TT_Get_CharMap( Face, i, &Chars );
FoundOne = 1;
if( !FoundOne )
TT_New_Instance( CF->Face, &Instance );
TT_Set_Instance_Resolutions( Instance, dpi_x, dpi_y );
TT_Set_Instance_Transform_Flags( Instance, FALSE, FALSE );
TT_Set_Instance_CharSize( Instance, ptsize * 64 );
for ( ; *string; string++ )
TT_New_Glyph( face, &glyph );
TT_Load_Glyph( Instance, glyph, index,
TTLOAD_SCALE_GLYPH | TTLOAD_HINT_GLYPH );
TT_Get_Glyph_Metrics( glyph, &metrics );
width += (metrics.advance+32) / 64;
TT_Done_Glyph( glyph );
Hope this helps!
Matthew A. Feinberg
Catharon Productions, Inc.
2119 Route 66, Ghent, NY 12075, USA
From: Brian Cowie [mailto:address@hidden
Sent: Monday, April 10, 2000 11:49 AM
Subject: Information Request
I've looked through the documentation and can't find an answer for my
question, so I'm writing directly.
What I'd like is some function, where I can give it the following
a font size
a device resolution
The return from the function would give me:
the length of the string, in the device resolution, at the specified
For example, if I gave the function a string "0123456789', for a Courier
10-pitch font and a 300 dpi device, the function should return a result
300. That is, ten characters of a 10-pitch font should be 1 inch or 300
long. It would also be helpful if the function could also return the
of the string.
Can I use FreeType to do this?