Jump to content
  • Advertisement
Sign in to follow this  
gunner_uk2000

Pixcel size of a String...

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

How would I calculate the length in pixels of a char array? I'm not sure of how I would get the character sizes (pixels) for different fonts and sizes(pt). Anyone have any ideas? (if I can find out the sizes then the algorithm is pretty simple)

Share this post


Link to post
Share on other sites
Advertisement
It depends on how you're rendering the text. You should look in the documentation for your graphics library.

Also, moved to For Beginners.

Share this post


Link to post
Share on other sites
Quote:
Original post by Sneftel
It depends on how you're rendering the text. You should look in the documentation for your graphics library.

Also, moved to For Beginners.


I'm using DirectX and using the ID3DXFont class to render the text.

Share this post


Link to post
Share on other sites
You need to loop through all the characters in the string and find the width of each character in the string. Add all these values together, and add in the gap between each character as well. This will give you the width in pixels.

I'm not familiar with the DirectX libraries but I would guess there is some sort of function you can call that will give you the width of each character. Someone else may be able to help you with the function call, or it might be in the documentation with DirectX.

Share this post


Link to post
Share on other sites
Quote:
Original post by Sneftel
You should look in the documentation for your graphics library.


Link. Pay special attention to DT_CALCRECT.

Share this post


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

  • Advertisement
×

Important Information

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

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!