Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Best way to measure text?  (Read 2107 times)

0 Members and 1 Guest are viewing this topic.

Celtic Minstrel

  • Jr. Member
  • **
  • Posts: 80
    • View Profile
Best way to measure text?
« on: June 24, 2012, 08:55:28 am »
Since there's no measureText function anywhere, I've been measuring the size of a string by constructing a Text object, getting the bounds, and then discarding it. Is that a reasonable way to measure text, or would you say I should be using just a Font and calculating the size one character at a time by accessing the glyphs?

To put this another way, does constructing a text object with a string do anything towards rendering, or does it just store the string and font attributes and calculate the size of the string, leaving any rendering to when draw() is called?

I'll note that the lack of a measureText function in Font surprised me at first, since this is kind of an important thing to have. I've actually been having small performance issues in rendering large quantities of text and have figured out that the measuring, wrapping algorithm, and rendering take the most time overall. I think my wrapping algorithm could also use some work, but I'd like to know if there's any point in changing the measuring algorithm as well.

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Best way to measure text?
« Reply #1 on: June 24, 2012, 10:33:50 am »
Obviously, constructing a sf::Text object just to measure its string is overkill. It allocates the vertex array and computes all the vertices' attributes.

I plan to implement this feature soon in SFML 2.
Laurent Gomila - SFML developer

Celtic Minstrel

  • Jr. Member
  • **
  • Posts: 80
    • View Profile
Re: Best way to measure text?
« Reply #2 on: June 24, 2012, 03:51:56 pm »
Should I make a ticket on the issue tracker?

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32504
    • View Profile
    • SFML's website
    • Email
Re: Best way to measure text?
« Reply #3 on: June 24, 2012, 04:50:35 pm »
No, I'll do it myself :)
Laurent Gomila - SFML developer