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 & HelpSyntax Questions › "end coordinates" of a piece of text
Page Index Toggle Pages: 1
"end coordinates" of a piece of text ? (Read 359 times)
"end coordinates" of a piece of text ?
Aug 3rd, 2006, 4:38am
 
Hi again,

Sorry that I didn't ask the previous question correctly enough: how do I find the "end coordinates" of a paragraph?

import processing.opengl.*;

PFont font;
//////////////////////////////////////
TEXTWIDTH txt;
class TEXTWIDTH {
 void txtWidth() {
   textFont(font, 14);
   textLeading(20);
   
 
   //String s = "this is a paragraph";
   String s = "this is a\nparagraph";
   float sw = textWidth(s);
   //float sh = textLeading(s);
   text(s, 10, 50);
   stroke(255);
   line(sw, 0, sw, 20); // line(sw, sh, sw, sh+20); ?
   
 }
}
//////////////////////////////////////
void setup(){
 size(200,200, OPENGL);
 txt = new TEXTWIDTH();
 font = loadFont("Avenir-Medium-48.vlw");

}


void draw(){
background(0);
 
 txt.txtWidth();  

}
Re: "end coordinates" of a piece of text
Reply #1 - Aug 3rd, 2006, 11:34am
 
You have to add the x coordinate of your text call (text(s, 10, 50); ) to the width of text.

Code:

class TEXTWIDTH {
void txtWidth() {
textFont(font, 14);
textLeading(20);


//String s = "this is a paragraph";
String s = "this is a\nparagraph";
float sw = textWidth(s);
//float sh = textLeading(s);
text(s, 10, 50);
stroke(255);
line(10+sw, 0, 10+sw, 80); // line(sw, sh, sw, sh+20); ?

}
}
Page Index Toggle Pages: 1