Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


True Type fonts and sizes

This topic is 6767 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

If Im using true type fonts (blitting each letter to a surface from GDI - then using hardware acc to get them on the screen) how can I compensate for each letters width and height? I think it would be simplest to center each letter on it''s surface and blit at fixed width/height - instead of giving each letter a width and height and looking them up each time I want to draw a string. Also, is there a way to relate the size of the font (12, 14, whatever) to the average width and height? I want to make my font engine as rubost and flexible as possible, by allowing any size font to be created. any help would be appreciated Ratman

Share this post

Link to post
Share on other sites
Why not GetDC the DDraw surface, attach a HFONT to it, and draw the characters directly onto the DDraw surface, before calling ReleaseDC?

Do things like that not work on DDraw DCs?

To get font metrics, call GetTextMetrics. eg

HDC hdc;
HFONT hfont, hOldFont;
int nWidth=30, nHeight=30;

// This next is just to illustrate what pSurface is
iDirectDrawSurface7* pSurface = GlobalGetFontSurface();

memset(&lf, 0, sizeof(LOGFONT));
hdc = pSurface->GetDC();

lf.lfHeight = 12; // Or -12, or something. Try it.
lf.lfWeight = FW_NORMAL;
lf.lfCharset = DEFAULT_CHARSET;
lf.lfOutPrecision = OUT_DEFAULT_PRECIS;
lf.lfFaceName = _T("Arial");

hfont = CreateFontIndirect(&lf);
hOldFont = SelectObject(hdc, hfont);

GetTextMetrics(hdc, &tm);

//These are in device mapping units.
//Might be wise to set the surface device unit
//mapping to pixels beforehand.
nHeight = tm.tmHeight;
nWidth = tm.tmMaxCharWidth;

/* Insert draw-font-to-surface loop here: */

SelectObject(hdc, hOldFont);


Hmm. Now that I think about it, drawing to a proper GDI dc would be better, because then you can find out how big the font surface needs to be, create it with the required dimensions, then blit from the GDI surface to the DDraw surface.

Anyway, that code should be about right. I expect it needs some fiddling, since I just made it up, using the MSDN Library to get the function params and structures.

Hope that helps.


Share this post

Link to post
Share on other sites
Thats not really what I meant...

I have my engine working. I create 89 surfaces, each 10x10 and then use GDI to blit each invidividual character to a single surface. So then I can hardware acceleration to actually blit the letter. It takes a little while to load up, but once it does the text is very fast.

My question is, the ! mark takes up 1 pixel in width. a O takes up more. And unless I mistaken, thats the whole purpose of true type fonts - each letter has a differnt width and is spaced out accordingly. My question is, how (if its possible) can I get the width of each individual letter so I can create that surface the correct length.

The other part is (if the above cannot be done), if I create a font with size 14, is there any rule to get that into width/height? Say I creat an arial font with size 14, can I find out how big the biggest character will be, so I can make all the surfaces that size?

Hope this clears things up

Share this post

Link to post
Share on other sites
Guest Anonymous Poster

I think the purpose of TTFs is that they can produce high quality fonts.
Width and spacing have little to do with it. They use things like bezier
curves to draw them.

Check out this for general info:


For widths on TTFs, lookup this Windows function:

Share this post

Link to post
Share on other sites
you could be right, but this is how I remember reading it:

Normal fonts are like a typewriter, everything is evenly spaced. When you type an "i" on the type writer, it moves over as much as it did when you typed an "O". In true type fonts, each letter "spaces out" as much as it needs to, so things look more natural.

The GetCharABCWidths() should be what I need though...


Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!