[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[ft] In freetype how can one set font size in pt, but keep resolution in
From: |
Andrew John Clayphan |
Subject: |
[ft] In freetype how can one set font size in pt, but keep resolution independent? |
Date: |
Tue, 16 May 2006 21:41:31 +1000 (EST) |
Hi,
Got a question regarding how does one set font in pt's in freetype, but keep
resolution independent.
I'm trying to set a fontsize (that is a long) which is to represent the size in
points (pt).
What i am trying to do is set the fontsize in the new face that I have created,
however I want to use UNSCALED everywhere.
Up until now, i haven't actually set the size of the font, i've been using
whatever default freetype gives me (which I think uses 10pt by default). Now
when I come to finalising a piece of code, I can't find a suitable operation
that can set a font size in points for me. Everything I find either asks for
integers or will turn on devide dependent resolution attributes.
So, I looked at the following functions;
FT_Set_Char_Size, // but it seems to do nothing for me
FT_Set_Pixel_Size, // but that only accepts integers, and my fontsize variable
is a long
I read through a bunch of the freetype API documentation, the tutorials, the
glyph conventions, but still am unsure how to set a fontsize (that is a long)
and make the output still be using UNSCALED everywhere (that is, I don't want
anything dependent on resolution, since im not actually doing any rendering
just grabbing the horiAdvance metric and kerning data)
This is my sandbox testing code so far, can anyone see what I might be missing?
/* **** START SNIP **** */
FT_Library library; /* handle to library */
FT_Face face; /* handle to face object */
FT_GlyphSlot slot;
FT_Error error;
error = FT_Init_FreeType( &library );
if ( error ) { cout << "Died on freetype initialisation" << endl; exit(1); }
error = FT_New_Face(library,"/usr/share/fonts/dejavu-fonts/DejaVuSans.ttf",
0, &face);
if (error) { cout << "Died when loading the font" << endl; exit(1); }
// Thought this function would do it for me, however seems to do nothing for
me
// Since when i changed the numbers my debug was still the same
error = FT_Set_Char_Size(face, // handle to face object
22*64, // char_width in 1/64th of points
22*64, // char_height in 1/64th of points
0, // horizontal device resolution
0 ); // vertical device resolution
if (error) { cout << "Died on set char size function" << endl; exit(1); }
FT_UInt glyph_index = FT_Get_Char_Index(face, 'a'); // Testing the letter a
cout << "glyph index = " << glyph_index << endl;
// Have to keep on NO_SCALE else resolution will affect the metrics
error = FT_Load_Glyph(face, glyph_index, FT_LOAD_NO_SCALE);
if (error) { cout << "died on load glyph" << endl; exit(1); }
error = FT_Render_Glyph(face->glyph, // glyph slot
FT_RENDER_MODE_NORMAL); // render mode
if (error) { cout << "died on render of glyph" << endl; exit(1); }
// Debug printout (slot)
cout << "horizontal advance is" << face->glyph->metrics.horiAdvance << endl;
/* **** END SNIP **** */
Any replies to my query would be very appreciated.
Cheers,
Andrew
- [ft] In freetype how can one set font size in pt, but keep resolution independent?,
Andrew John Clayphan <=