Sign in to follow this  
EricmBrown

Font Length

Recommended Posts

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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

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