FreeType font pixel size

Started by
2 comments, last by Gamer Gamester 16 years, 1 month ago
I been trying to figure this out for hours now. How do i determine the maximum size of loaded font after i set the font/char size? I dont like the way i am rendering right now. if you look at the 2nd picture in this page http://freetype.sourceforge.net/freetype2/docs/tutorial/step2.html you'll see the origin is top center. I want to render in such a way that the origin is top left. I also want to know the largest yAdvance (i made this word up) so know where to start rendering the origin when the text goes to a new line.
Advertisement
Quote:Original post by EccentricSight
How do i determine the maximum size of loaded font after i set the font/char size?

It depends on whether the font has bitmap or vector glyphs (or both).

If it contains vector glyphs, then you can make them as big as you want (no technical limit I believe... though perhaps eventually memory/freetype wouldn't be able to handle it -- but that would be far beyond the practical limit: however big a person would actually want a font's glyphs to be).

If it's bitmap glyphs, then you have to find out for what sizes the font has bitmaps. I only use vector fonts myself, so I'm not positive how to do this, but I believe you can check the face->fixed_sizes pointer. It points to an array of FT_Bitmap_Size elements, which should contain all your font size possibilities.

Quote:Original post by EccentricSight
I dont like the way i am rendering right now. if you look at the 2nd picture in this page
http://freetype.sourceforge.net/freetype2/docs/tutorial/step2.html

you'll see the origin is top center. I want to render in such a way that the origin is top left.

The 2nd picture you are referring to is an example of vertical text (text that reads from top to bottom, not left to right). Is this what you want? If you're using an English font, you typically want horizontal metrics (and that's typically all the font has), and for these the origin is usually bottom left.

I'm not sure if you can change the origin, but I'm also not sure why you'd want to. It works out quite nicely to render a font with a lower-left origin, I believe that's how typographers have been doing it for years though I'm no expert on typography. I'm not sure what you're using to render the glyphs, but it's usually not to hard to switch from a top-left origin rendering to a bottom-left one. I or someone may be able to give you some help on this if you tell us what you're using.

Quote:Original post by EccentricSight
I also want to know the largest yAdvance (i made this word up) so know where to start rendering the origin when the text goes to a new line.

You can use face->height to get the font's height in font units, but for a sized font you probably want to use the value face->size->metrics.height (after you've sized the font), which is in 26.6 fractional pixels (You'll have to multiply the value in face->size->metrics.height by 64 to get the actual height in pixels).
Alright awesome, i did row*(face->size->metrics.height/64) - slot->bitmap_top and it looks like it will guarantees me the height will always be bigger then the bitmap top. Here is the pic of after its been rendered
http://i28.tinypic.com/1247pjs.png

Its not exact as top as it could be but there isnt to much room. it also spaces the rows apart real nice and i dont have to worry about yMin, such as the bottom of p interfering with the row beneath.


Next question is about the font size. I do
error = FT_Set_Char_Size( face, size * 64, 0, 96, 0 );
size being 16 in the image i pasted. 96 for my screen DPI (instead of 300 that showed in the tutorial :|). The font looks slightly bigger then the font would look in a program like MS paint. Am i doing the calculations correctly or am i doing something wrong?
You don't seem to be doing anything wrong. I'm not sure why they'd be different (I'm not much of a font expert), but so long as they look good to you I wouldn't really worry about it. It might have to do with SDL or your rendering context. Perhaps there's some font gurus who would know more.

I always just use FT_Set_Pixel_Sizes( face, size, 0 ). That way I can just choose the size I want in pixels, and don't have to concern myself with DPI.

This topic is closed to new replies.

Advertisement