• Advertisement
Sign in to follow this  

CreateFont

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

I'm having a couple of problems with getting the correct size of a character in a windows font.
Quote:
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/gdi/fontext_8fp0.asp nHeight [in] Specifies the height, in logical units, of the font's character cell or character. The character height value (also known as the em height) is the character cell height value minus the internal-leading value. The font mapper interprets the value specified in nHeight in the following manner. Value Meaning > 0 The font mapper transforms this value into device units and matches it against the cell height of the available fonts. 0 The font mapper uses a default height value when it searches for a match. < 0 The font mapper transforms this value into device units and matches its absolute value against the character height of the available fonts. For all height comparisons, the font mapper looks for the largest font that does not exceed the requested size.
1. First of all what is the difference between the "> 0" and "< 0" values? 2. I know that I can get the width of the characters using "GetCharWidth32", but how do I get the height? I know that I can give CreateFont a height, but the function takes it and looks for the largest possible font without exceeding the size, but it's not necessarily the size of the font.

Share this post


Link to post
Share on other sites
Advertisement
1. The > 0 and < 0 are identical, because < 0 will take the absolute value (positive) of the given height; this is done to avoid problems with negative heights, which isn't very friendly on code sometimes.

2. Use 0 for the default height. Or if you want to set a certain height, then give it a height... Not sure what's throwing you off here. GetCharWidth32 will just give you the width of an array of characters (i.e. a string) based on the width of the already defined and selected font. So you're going to have to give your own width too...

Share this post


Link to post
Share on other sites
1. A > 0 height value is used as the "cell height" for the font - the total height of the box in which all characters must fit. A height value < 0 is negated (so that it is positive), and then used as the "character height", which is the cell height minus the "internal-leading value". The internal leading value is, AFAIK, a space reserved at the top of the cell for accents etc.

Thus, specifying the size as -x will generally lead to a larger font than if you had specified +x.

Share this post


Link to post
Share on other sites
If you want to specify a font point size, you can use the method described in CreateFont:
nHeight = -MulDiv(PointSize, GetDeviceCaps(hDC, LOGPIXELSY), 72);

Fonts don't have a fixed size really, they tend to be TrueType. You could use a point size of 12, which is a fairly standard size. I always pass 0 for the font width, that causes the GDI to chose a reasonable width.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement