Checking height and width of an image generated by SDL_ttf

Hi,

I’m trying to figure out a way to make a ttf string surface with SDL_ttf.
The problem is I needed to cut the string surface if the string is too
long, it will be cut and a new string surface under it will be created. In
other word, I need to implement a word wrap function to it. What I have in
mind is this:

  1. Render the string
  2. Check the surface’s dimension (h & w)
  3. If it’s to long:
    3.1. Free the surface
    3.2. Cut the last word from the string and push to a new string
    3.3. Re-render the string
    3.4. Loop to 2
  4. If not:
    4.1. Check if there’s a new string generated from the last string
    4.1.1. If there is a new string:
    4.1.1.1. Loop to 1
    4.1.2. If not:
    4.1.2.1. End

IMHO, the render, re-render, free loop will take a long time to process.
Is there any other way to solve this elegantly?

Thanks in advance.

Fare thee well,
Bawenang R. P. P.----------------
ERROR: Brain not found. Please insert a new brain!

?Do nothing which is of no use.? - Miyamoto Musashi.

“I live for my dream. And my dream is to live my life to the fullest.”

http://www.libsdl.org/cgi/docwiki.cgi/SDL_5fttf_2fFunctions_2fAttributes_2fTTF_5fSizeText
perhaps?On 19/07/07, benang at cs.its.ac.id wrote:

Hi,

I’m trying to figure out a way to make a ttf string surface with SDL_ttf.
The problem is I needed to cut the string surface if the string is too
long, it will be cut and a new string surface under it will be created. In
other word, I need to implement a word wrap function to it. What I have in
mind is this…

Hello !

IMHO, the render, re-render, free loop will take a long time to process.
Is there any other way to solve this elegantly?

Render the different characters
of the string seperately.

Then you can calculate with their widths & heights
and create a new surface and then blit them
the way you want.

If you are using characters more than once,
which is normal in a language,
you can also save memory with this way.

CU