int foldString(padFmt padelm,Graphics g)
{
int endx,lcount=0,lnum=1;
int stposy;
int indx,last;
int lnHeight,vlnHeight,height=0,width=0;
int posx,posy;
String line="",cst,pString;
char ch;
boolean vert1;
FontMetrics fm;
int totalWidth=0,totalHeight=0;
String dst;
pString=DateFormat.getTimeInstance().format(padelm.eDate)+"\n"+padelm.string;
last=pString.length();
vert1=padelm.vertSty;
fm=getFontMetrics(padelm.font);
lnHeight=fm.getHeight();
vlnHeight=lnHeight-6;
stposy=padelm.posy+lnHeight-4;
posx=padelm.posx;posy=padelm.posy;
for(indx=0;indx<last;indx++){
ch=pString.charAt(indx);
if(vert1){//tategaki
if(ch !='\n'){
cst="";cst+=ch;
//System.out.println(cst+":"+posx+":"+height);
if(g != null) g.drawString(cst,posx,posy);
posy+=vlnHeight;
height+=vlnHeight;
//get max character width
if(width<fm.charWidth(ch)) width=fm.charWidth(ch);
}
if(height>(padelm.height-vlnHeight) || ch=='\n' || indx==last-1){
//System.out.println("next column:"+height+":"+padelm.height+":"+width);
posy=padelm.posy;
posx=posx-(width+6);//4は行間の間隔
totalWidth=totalWidth+(width+6);
height=0;width=0;lnum++;
}
} else { //yokogaki
if( width+fm.charWidth(ch)>padelm.width ||ch=='\n' ){
if(g != null) g.drawString(line,padelm.posx,stposy);
stposy +=lnHeight;
totalHeight+=lnHeight;
width=0;
line="";lcount=0;lnum++;
}
if(ch != '\n') {
line +=ch;
lcount++;
width+=fm.charWidth(ch);
if(indx==last-1 ) {//残りの文字列を表示する
if(g !=null) g.drawString(line,padelm.posx,stposy);
totalHeight+=lnHeight;
}
}
}//if !vert
}//for
if(vert1) {
padelm.width=totalWidth;
padelm.rectx=padelm.posx-padelm.width+padelm.fontsize;
padelm.recty=padelm.posy-padelm.fontsize;
}
else {
padelm.height=totalHeight;
padelm.rectx=padelm.posx;
padelm.recty=padelm.posy;
}
return lnum;
}