FAQ
Cover
\
Build
\
Source
\
Bugs
\
Reference
\
Libraries
\
Tools
The bugs database has moved
here
.
Bug 844 : text( String, float, float, float, float ) draws text outside box
Last modified: 2008-08-11 08:41
P
roject:
processing
trash
Version:
unspecified
Co
m
ponent:
android
book
core
libraries
pde
reference
tools
web
Status:
RESOLVED
Resolution:
FIXED -
Pr
i
ority:
P4
Severity:
normal
Platform
All
O
S:
All
Windows
Mac OS
Linux
Other
Reporter:
fjen
Assigned To:
fry
Attachment
Type
Created
Size
Actions
Description
: Opened: 2008-07-08 12:13
if you have a really long word combined with newlines the text-block implementation draws
the long text over the edge of the box.
size( 200, 200 );
background( 0 );
noStroke();
stroke(255);
line( 60,0,60,height);
fill(255);
PFont fnt = createFont("Arial-Bold",12);
textFont( fnt );
String lStr = "FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF";
text( lStr, 10, 10, 50, 50 );
lStr += "\nXX"; // add newline and XX
text( lStr, 10, 70, 50, 50 );
F
Additional Comment
#1 From fry 2008-07-14 06:26
try using the Create Font tool with Arial Bold 12. does the same thing
happen? i suspect it's because it's usign the native font metrics when the
native font is in use (since that's what happens with createFont()).
Additional Comment
#2 From fjen 2008-07-15 10:14
same problem with loadFont() ...
Additional Comment
#3 From fry 2008-07-19 16:03
bummer.. ok, will look into it.
Additional Comment
#4 From fjen 2008-08-06 13:39
not sure this is something for the release but it helped me for the moment:
String[] getLinesText ( String text, PFont font, int maxWidth )
{
if ( text == null || text.equals("") ) return new String[0];
textFont(font);
String[] lns = split(text,"\n");
int l = 0;
int s = ceil( textWidth( " " ) );
String[] lines = new String[text.length()];
for ( int i = 0; i < lns.length && l < lines.length; i++ )
{
int w = ceil(textWidth(lns[i]));
if ( w > maxWidth )
{
String[] words = split( lns[i], " " );
int c = 0;
String ln = "";
int ll = 0;
for ( int ii = 0; ii < words.length; ii++ )
{
int cc = ceil( textWidth( words[ii] ) );
if ( c + cc + s <= maxWidth )
{
ln += words[ii] + (words.length-1 == ii ? "" : " ");
c += cc + s;
}
else if ( cc > maxWidth )
{
int ww = 0;
String wr = words[ii];
int ic = 0;
for ( ; ic <= wr.length(); ic++ )
{
ww += textWidth( wr.charAt(ic) );
if ( c + s + ww > maxWidth )
{
//ic--;
break;
}
}
ln += words[ii].substring(0,ic);
lines[l+ll] = ln;
ln = words[ii].substring(ic);
c = ceil(textWidth( ln )) + s;
ll++;
while ( textWidth( ln ) > maxWidth )
{
ic = 0;
ww = 0;
for ( ; ic <= ln.length(); ic++ )
{
ww += textWidth( ln.charAt(ic) );
if ( ww > maxWidth )
{
ic--;
break;
}
}
lines[l+ll] = ln.substring(0,ic);
ln = ln.substring(ic);
c = ceil(textWidth( ln )) + s;
ll++;
}
}
else
{
lines[l+ll] = ln;
ln = words[ii] + (words.length-1 == ii ? "" : " ");
ll++;
c = cc;
}
}
if ( !ln.equals("") )
{
lines[l+ll] = ln;
ll++;
}
l += ll;
}
else
{
lines[l] = lns[i];
l++;
}
}
return lines;
}
it will split the given text into lines not longer than maxWidth. words longer than a line are
split just before hitting maxWidth.
Additional Comment
#5 From fry 2008-08-06 13:50
ah, i see now.. the problem only happens when there are newlines.
even better, if you use this:
lStr = "XX\n" + lStr;
it'll actually chop off the last bit of text.
checking into it now.
Additional Comment
#6 From fry 2008-08-06 14:00
scratch that last point, it's just that the text box is really small.
found the problem, fixing it now.
Additional Comment
#7 From fry 2008-08-11 08:41
Fixed for 0145.