Sign in to follow this  

Problem with Font Sizeing

This topic is 4303 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

Hello everyone, i am creating and render fonts like this:
LOGFONT lf= {6,0,0,0,FW_MEDIUM,false,false,false,DEFAULT_CHARSET,OUT_TT_PRECIS,CLIP_DEFAULT_PRECIS,PROOF_QUALITY,DEFAULT_PITCH,"Verdana"}; 
D3DXCreateFont(Device, lf.lfWidth, lf.lfHeight, lf.lfWeight, 1, lf.lfItalic, lf.lfCharSet, lf.lfOutPrecision, lf.lfQuality, lf.lfPitchAndFamily, lf.lfFaceName, &m_Font);
m_Font->DrawText(NULL, m_Text.c_str(), m_Text.length(), &Rct, DT_LEFT, D3DCOLOR_XRGB(255,255,255));



the problem i have is that the size of the text is too big and if i try to make it smalle it gets all scrambled here two images one with a size of 6 the next with a size of 3 anyone know how i get the text looking right even in smaller sizes?

Share this post


Link to post
Share on other sites
You're never going to get fonts that small to be readable. The height (assuming the default MM_TEXT mapping mode) is specified in pixels. There's no way to get a 3-pixel-high font to work, and 6 pixels is going to be just barely readable.

Share this post


Link to post
Share on other sites
thx for the hint

i found the error but i dont really understand why

typedef struct tagLOGFONT {
LONG lfHeight;
LONG lfWidth;
LONG lfEscapement;
LONG lfOrientation;
LONG lfWeight;
BYTE lfItalic;
BYTE lfUnderline;
BYTE lfStrikeOut;
BYTE lfCharSet;
BYTE lfOutPrecision;
BYTE lfClipPrecision;
BYTE lfQuality;
BYTE lfPitchAndFamily;
TCHAR lfFaceName[LF_FACESIZE];
} LOGFONT, *PLOGFONT;

Somehow LONG lfHeight defines the width of my text and LONG lfWidth defines the height of it.

Not really sure why this is but now i can set it to anything i want to and it works fine

Share this post


Link to post
Share on other sites
Quote:
Original post by Rozik
Somehow LONG lfHeight defines the width of my text and LONG lfWidth defines the height of it.


That's not true. The height specifies the height. However, it is interpreted in the following way:

- A positive value specifies the "cell" height (character height plus internal leading value). So, specifying 6 for the height actually results in characters that are smaller than 6 pixels high. (The cell height includes the spacing between lines of text.)

- A value of zero indicates to use the default height.

- A negative value specifies the "character" height (cell height minus internal leading value). So, specifying a -6 for the height will get you characters that are actually 6 pixels high.

The width specifies the average character width of characters in the font. A value of zero specifies that a closest match, based on the difference between the device aspect ratio and the digitization aspect ratio of fonts is used.

TrueType fonts are continuously scalable and will give best results. Device fonts are designed for specific sizes and don't scale very well. If you specify a negative value for the lfHeight, zero for the lfWidth, and OUT_TT_PRECIS or OUT_TT_ONLY_PRECIS for lfOutPrecision, you will get the best results.

The lfWeight value also comes into play. Specifying FW_MEDIUM means that a little extra "fat" is included in the output pixels to make the font appear "heavier". A value of FW_REGULAR will more closely match the designed appearance of the font.

If you are more interested in the width of the characters than the height, then specify zero for the height and a non-zero value for the width.

Be aware that the font mapper is still going to provide a closest-match to the values you specify, so you can't guarantee that you will always get exactly what you ask for. If you really need characters that are exactly the width and height you request, then your only choice is to hand-draw them into a bitmap and use textured quads (or ID3DXSprite) to draw your text.

Share this post


Link to post
Share on other sites

This topic is 4303 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this