Jump to content
  • Advertisement
Sign in to follow this  
pyropaul2

font.MeasureString and the Space Character

This topic is 3275 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 scrolling text in a scrolling banner control which, by in large, works well during test. However, so that I'm not scroll large amounts of text off screen onto the rectangle and using Proc, I'm trying to cut the text into characters and add/remove characters as they enter/leave the display rectangle. The problem is that when the character is a SPACE its length is 0. When the SPACE is part of a text string it has a length >0. I've tried simply calculating the SPACE length and just adding the static value but it causes the screen motion to jerk. If I replace the SPACE with another character (in this case ".") the motion and expected behaviour is fine. Below, I've got the output of some tests, the space does not get counted in the second output (714). ss to manipulate a string that contains surrogate and combining characters.The .NET Framework defines a text element a...722 characters.The .NET Framework defines a text element as a unit of text that is displayed as a single character, that is, a g...714 This code slits the strings into chars: private void CharProperties() { // gets each charater in the RSS Feed array and stores this // charater in ArDisplayChars along with its DX size ArDisplayChars.Clear(); int DxCharFontSize = 0; foreach (string StrSegments in FeedText) { foreach (char ch in StrSegments) { DxCharFontSize = font.MeasureString(null, ch.ToString(), DrawTextFormat.None, Color.Red).Width; ArDisplayChars.Add(new CharProps(ch, DxCharFontSize)); } } }

Share this post


Link to post
Share on other sites
Advertisement
ss to manipulate a string that contains surrogate and combining SPACE SPACE SPACE SPACE characters.The .NET Framework defines a text element a...722

SPACE SPACE SPACE SPACE characters.The .NET Framework defines a text element as a unit of text that is displayed as a single character, that is, a g...714

Share this post


Link to post
Share on other sites
Thanks mattd, it does.

I was also doing some tests as follows:

Create a string that has the characters either side of the SPACE character and the SPACE Character itself. Then, I create a string of just the two characters.
Finally, I subtract the 2nd string length from the first. I've found that the space seems to be a variable length character. With my test it varied between 16 & 24 (using Arial Size 40).

That was helpful, thanks very much.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!