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.
Page Index Toggle Pages: 1
Word Wrap (Read 1256 times)
Word Wrap
May 10th, 2007, 12:34pm
 
hello,

anybody successful in programming word wrap?

we tried
http://www.shiffman.net/2006/10/17/word-wrap-in-processing/
  but we couldn't implement it. we had problems with strings and arraylists.

here is our code. we don't know why the string repeats and starts with null?



String message ;
String [] translatedMessage;

void setup ()
{
  size(600, 400);
  background(255);
  PFont fontA = loadFont("Arial-Black-48.vlw");
  textFont(fontA, 32);
 }
 
 void draw ()
 {
   background (255);
   translatedMessage= loadStrings ("test.txt");
   fill(0);
   String wort= translatedMessage [0];
   wort =  breakWord (wort, 200);  
   text(wort, 10, 60);
 }
 
String breakWord (String WordIn, int w)
{
char[] Letter = new char [1];
float laenge = 0;
 
 for (int j=0; j<WordIn.length(); j++)
 {
  Letter [0] = WordIn.charAt(j);
    laenge = laenge + textWidth (new String (Letter));


if (laenge>w)
{
 message= message+ "\n";
 laenge=0;
 message=message + new String (Letter);
}
else
{
  message=message + new String (Letter);  
}
 
 }
 
return (message);  
}



thank you.
Re: Word Wrap
Reply #1 - May 11th, 2007, 2:20pm
 
use the version of text() that includes a width and height parameter. this will give you a word wrapped text box.
Re: Word Wrap
Reply #2 - May 11th, 2007, 6:37pm
 
sorry, we didn't notice this function.
thank you very much.

Page Index Toggle Pages: 1