Font Length

Started by
7 comments, last by EricmBrown 18 years, 1 month ago
Just a quick technical question about font lengths. If i have a string that says "Hello World" in font size 14. Is the size of each char 14 pixels long? Does it depend on the font type? If not, how do I determine the length of a font character? By the way. I'm using the windows CreateFont() command along w/ wglUseFontBitmaps() if that makes a difference. Thanks
Advertisement
Font size only says something about the height of a font (and as far as I know is no "everything included" measurement). There has to be a special function to calculate the necessary space but I never needed it yet, so I can't help you any further.
To my knowledge, it depends on the font type. I don't know in GL.

In d3d, Font.Draw with the calcrect flag, or Font.MeasureString in MDX.
I don't know about the 'CreateFont' function but in a general font sense.....

In order to calc the 'size' of each character it depends on the font type, if it's a fixed width font then obviously it will be easy to calc (width x num. characters), but if it's a proportional font then it'll be slightly more difficult as each charcter will have it's own width ('i' will obviously be less wide than 'o') and the characters will be moved/spaced based on the kerning of each character, and this spacing could depend on what letters are next to each other, some characters could in some cases overlap each other, 'wm' for instance (bah..but not on the font used in this fourm :) ).

It really depends on how much functionality you need from your font system, most of the time fixed spaced fonts are ok for playing around with, but to get nice looking text I always go for proportional fonts.

Anyway HTHs

Paul
GetTextExtentPoint32 looks promising...
Essentially all I need is to determine When a word in a string has extended beyond the textBox boundary so that i can move it to the line below.
Hi Eric, I believe your looking for the
GetTextMetrics
function. After calling that on the Device Content where your current font is
selected, you can find the Average font width and height. With this information
you can make a bounding box around the font, and then do boundry collision detection.

**EDIT**
Trap's solution does indeed look promising.
Like Paul said, if your Font is proportional, then GetCharWidth32() will do the trick.


- xeddiex
one..
Thanks guys, I havent tested those functions yet, but they seem to be exactly what I was looking for :)

This topic is closed to new replies.

Advertisement