tags:

views:

285

answers:

1

While rendering text with dojo's gfx, is there a way to tell how much space the text would take, just in case I need to wrap it so it fits a given width? How would you manage to print text of arbitrary lengths if you had to make them fit areas of restricted width?

Update: Sorry, I should have mentioned I need to do the wrapping on the server side. My app has to figure out size and position of all elements and then render the gfx script that ultimately draws them. I know the font and font size I'll use with gfx. Wrapping a string would result in rendering multiple createText calls. The question is, how do I split the string? (This should be trivial if the font was fixed-width)

Thanks!

+3  A: 

I would suggest to use dojox.html.metrics module, specifically getTextBox(text, style) function. Just use the same style you'll be using in dojox.gfx: font, size, decorations.

If you look at this function you will see that it is a simple helper for dojo.marginBox(), so if you don't want to pull in another file, you can do the same in you code and call marginBox() directly, which is in the Dojo Base and always available.

Eugene Lazutkin
Thanks, but I realize I didn't ask the right question, please see the edit.
Germán
There is no unified method to measure text on the server. You have to have exactly the same font on the server as your clients in their browsers, and it depends on what kind of OS is used on the server. In any case this question goes out of "dojo" category.
Eugene Lazutkin