FAQ
Cover
This is the archive Discourse for the Processing (ALPHA) software.
Please visit the new Processing forum for current information.

   Processing 1.0 _ALPHA_
   Programming Questions & Help
   Programs
(Moderators: fry, REAS)
   string pixel length
« Previous topic | Next topic »

Pages: 1 
   Author  Topic: string pixel length  (Read 965 times)
eskimoblood

222550793222550793 WWW
string pixel length
« on: Mar 18th, 2005, 1:36pm »

Is there a easy way to calculate the pixel length of a string.
 
toxi

WWW
Re: string pixel length
« Reply #1 on: Mar 18th, 2005, 2:18pm »

erm... do you mean the pixel width of a string...
 
a) at a certain font size in 2D (no scale, no rotation)
b) like option a) but with transformation
c) at a certain font size in 3D
 
do you want to use the default text engine or FastText (2d only) if the latter, you can use a function from the version of the class i've posted over here... the method is suitable called "getPixelWidth()"
 
the other options are more involved and will probably be require some hacks, but really we'll need more context from you first...
 

http://toxi.co.uk/
eskimoblood

222550793222550793 WWW
Re: string pixel length
« Reply #2 on: Mar 18th, 2005, 4:46pm »

I wanna draw a string in a rect, and therefor I need the  width of the string. I use the default text engine because I'll need some letters like .
 
fry


WWW
Re: string pixel length
« Reply #3 on: Mar 18th, 2005, 6:12pm »

font.width() is what you're looking for:
 
BFont font = loadFont("Arial-48.vlw");
float size = font.width("potato");
 
eskimoblood

222550793222550793 WWW
Re: string pixel length
« Reply #4 on: Mar 19th, 2005, 2:01pm »

Cool, that's it.
 
Pages: 1 

« Previous topic | Next topic »