public void text(String str,float x1,float y1,float x2,float y2){
  if (textFont == null) {
    defaultFontOrDeath("text");
  }
  float hradius, vradius;
switch (rectMode) {
case CORNER:
    x2+=x1;
  y2+=y1;
break;
case RADIUS:
hradius=x2;
vradius=y2;
x2=x1 + hradius;
y2=y1 + vradius;
x1-=hradius;
y1-=vradius;
break;
case CENTER:
hradius=x2 / 2.0f;
vradius=y2 / 2.0f;
x2=x1 + hradius;
y2=y1 + vradius;
x1-=hradius;
y1-=vradius;
}
if (x2 < x1) {
float temp=x1;
x1=x2;
x2=temp;
}
if (y2 < y1) {
float temp=y1;
y1=y2;
y2=temp;
}
float boxWidth=x2 - x1;
float spaceWidth=textWidth(' ');
if (textBreakStart == null) {
textBreakStart=new int[20];
textBreakStop=new int[20];
}
textBreakCount=0;
int length=str.length();
if (length + 1 > textBuffer.length) {
textBuffer=new char[length + 1];
}
str.getChars(0,length,textBuffer,0);
textBuffer[length++]='\n';
int sentenceStart=0;
for (int i=0; i < length; i++) {
if (textBuffer[i] == '\n') {
boolean legit=textSentence(textBuffer,sentenceStart,i,boxWidth,spaceWidth);
if (!legit) break;
sentenceStart=i + 1;
}
}
float lineX=x1;
if (textAlign == CENTER) {
lineX=lineX + boxWidth / 2f;
}
 else if (textAlign == RIGHT) {
lineX=x2;
}
float boxHeight=y2 - y1;
float topAndBottom=textAscent() + textDescent();
int lineFitCount=1 + PApplet.floor((boxHeight - topAndBottom) / textLeading);
int lineCount=Math.min(textBreakCount,lineFitCount);
if (textAlignY == CENTER) {
float lineHigh=textAscent() + textLeading * (lineCount - 1);
float y=y1 + textAscent() + (boxHeight - lineHigh) / 2;
for (int i=0; i < lineCount; i++) {
textLineAlignImpl(textBuffer,textBreakStart[i],textBreakStop[i],lineX,y);
y+=textLeading;
}
}
 else if (textAlignY == BOTTOM) {
float y=y2 - textDescent() - textLeading * (lineCount - 1);
for (int i=0; i < lineCount; i++) {
textLineAlignImpl(textBuffer,textBreakStart[i],textBreakStop[i],lineX,y);
y+=textLeading;
}
}
 else {
float y=y1 + textAscent();
for (int i=0; i < lineCount; i++) {
textLineAlignImpl(textBuffer,textBreakStart[i],textBreakStop[i],lineX,y);
y+=textLeading;
}
}
}

public void text ( String str , float x1 , float y1 , float x2 , float y2 ) { if ( textFont == null ) { defaultFontOrDeath ( "text" ) ; } float hradius , vradius ; switch ( rectMode ) { case CORNER : x2 += x1 ; y2 += y1 ; break ; case RADIUS : hradius = x2 ; vradius = y2 ; x2 = x1 + hradius ; y2 = y1 + vradius ; x1 -= hradius ; y1 -= vradius ; break ; case CENTER : hradius = x2 / 2.0f ; vradius = y2 / 2.0f ; x2 = x1 + hradius ; y2 = y1 + vradius ; x1 -= hradius ; y1 -= vradius ; } if ( x2 < x1 ) { float temp = x1 ; x1 = x2 ; x2 = temp ; } if ( y2 < y1 ) { float temp = y1 ; y1 = y2 ; y2 = temp ; } float boxWidth = x2 - x1 ; float spaceWidth = textWidth ( ' ' ) ; if ( textBreakStart == null ) { textBreakStart = new int [ 20 ] ; textBreakStop = new int [ 20 ] ; } textBreakCount = 0 ; int length = str . length ( ) ; if ( length + 1 > textBuffer . length ) { textBuffer = new char [ length + 1 ] ; } str . getChars ( 0 , length , textBuffer , 0 ) ; textBuffer [ length ++ ] = '\n' ; int sentenceStart = 0 ; for ( int i = 0 ; i < length ; i ++ ) { if ( textBuffer [ i ] == '\n' ) { boolean legit = textSentence ( textBuffer , sentenceStart , i , boxWidth , spaceWidth ) ; if ( ! legit ) break ; sentenceStart = i + 1 ; } } float lineX = x1 ; if ( textAlign == CENTER ) { lineX = lineX + boxWidth / 2f ; } else if ( textAlign == RIGHT ) { lineX = x2 ; } float boxHeight = y2 - y1 ; float topAndBottom = textAscent ( ) + textDescent ( ) ; int lineFitCount = 1 + PApplet . floor ( ( boxHeight - topAndBottom ) / textLeading ) ; int lineCount = Math . min ( textBreakCount , lineFitCount ) ; if ( textAlignY == CENTER ) { float lineHigh = textAscent ( ) + textLeading * ( lineCount - 1 ) ; float y = y1 + textAscent ( ) + ( boxHeight - lineHigh ) / 2 ; for ( int i = 0 ; i < lineCount ; i ++ ) { textLineAlignImpl ( textBuffer , textBreakStart [ i ] , textBreakStop [ i ] , lineX , y ) ; y += textLeading ; } } else if ( textAlignY == BOTTOM ) { float y = y2 - textDescent ( ) - textLeading * ( lineCount - 1 ) ; for ( int i = 0 ; i < lineCount ; i ++ ) { textLineAlignImpl ( textBuffer , textBreakStart [ i ] , textBreakStop [ i ] , lineX , y ) ; y += textLeading ; } } else { float y = y1 + textAscent ( ) ; for ( int i = 0 ; i < lineCount ; i ++ ) { textLineAlignImpl ( textBuffer , textBreakStart [ i ] , textBreakStop [ i ] , lineX , y ) ; y += textLeading ; } } }
draw text in a box that is constrained to a particular size . the current rectmode ( ) determines what the coordinates mean ( whether x1 / y1 / x2 / y2 or x / y / w / h ) . < p / > note that the x , y coords of the start of the box will align with the * ascent * of the text , not the baseline , as is the case for the other text ( ) functions . < p / > newlines that are \ n ( unix newline or linefeed char , ascii 10 ) are honored , and \ r ( carriage return , windows and mac os ) are ignored .
