We are about to switch to a new forum software. Until then we have removed the registration on this forum.
I have been breaking my brain over something that should be very simple: getting the height of wrapping text. It seems that processing has no function to calculate the height of wrapped text? I found an old workaround, dating from 2006 and 2007 (!), but this doesn't include a working example. http://wiki.processing.org/index.php?title=Word_wrap_text Does anyone have a better method to calculate the height of wrapping text?
Answers
The following code is an old snippet I coded in Processing 1.5.1, but it still works in Processing 2.X:
Just use createLineBreaks() to get the wrapped text and use textHeight() to get it's height.
Or simply use Daniel Shiffman's function like the following (not tested):
Thanks! Using your code and Daniel Shiffman's I was able to create a wrapping textfield with a measurable height :-) I have to say it's still a slightly convoluted way for something that should be simple. I hope Processing will add better support for text in the future!
Yub, and it's pretty slow performance wise - try to re-calculate the text height as few times as possible.
Would be great if Processing's text(str, x1, y1, x2, y2) would simply return a float[]/PVector containing the resulting text box dimensions. :)