We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › Finding the height of a block of text
Page Index Toggle Pages: 1
Finding the height of a block of text (Read 2491 times)
Finding the height of a block of text
Jan 25th, 2009, 4:58am
 
So there's a built-in function for finding the width of a chunk of text (textWidth), but is there any way to find the HEIGHT of a block of text?  There's no textHeight function, surprisingly (at least to me...maybe there's a good reason I don't know about though), and because I'm using the text function for wrapping, there's really no way for me to know how tall a wrapped text block is.

Is there something built in to Processing that might help me with this, or does anyone have a suggestion for how I might pull this off?  I know that worst case scenario I can ditch the auto-wrapping and write my own, so as to have full information about height from there, but I'd really like to avoid that if possible.
Re: Finding the height of a block of text
Reply #1 - Jan 25th, 2009, 11:12am
 
I don't think so. In PGraphics.java (source code of Processing), I see the height is tracked with a local variable (y) to be able to display the lines one below the previous. But the information is lost after drawing.
I suppose the reasoning behind not making this info available is that it is expected that the height info is the height of the box (which is approximate if the text is smaller than the box).

If you go the manual way, looking at text(String str, float x1, float y1, float x2, float y2) code in the above mentioned file might help, perhaps.
Re: Finding the height of a block of text
Reply #2 - Jan 25th, 2009, 8:18pm
 
Okay, I guess I'll work on doing it manually then.

Thanks for the quick response!
Re: Finding the height of a block of text
Reply #3 - Mar 3rd, 2010, 3:46am
 
Any new progress on this? I don't quite understand your advice PhiLho and don't understand the repository for looking at the source code. Is there something like in Google Code to just see the latest package?

If you use the text(string, float, float, float, float) function then you can access that variable y in the core?

Thanks for the help!
Re: Finding the height of a block of text
Reply #4 - Mar 3rd, 2010, 4:25am
 
int textHeightInPixels = textAscent() + textDescent(); // ??
Re: Finding the height of a block of text
Reply #5 - Mar 3rd, 2010, 5:44am
 
Interesting, thanks for sharing!
Re: Finding the height of a block of text
Reply #6 - Jun 11th, 2010, 3:21am
 
Page Index Toggle Pages: 1