codice:
this.drawTextBox = function drawTextBox(strText, w, h, align, valign, border)
{
if (!align) {align = 'L';}
if (!valign) {valign = 'T';}
if (!border) {border = 1;}
xi = this.GetX();
yi = this.GetY();
hrow = this.FontSize;
textrows = this.drawRows(w,hrow,strText,0,align,0,0,0);
maxrows = Math.floor(h/this.FontSize);
rows = Math.min(textrows,maxrows);
dy = 0;
if (valign.toUpperCase =='M')
{
dy = (h-rows*this.FontSize)/2;
}
if (valign.toUpperCase =='B')
{
dy = h-rows*this.FontSize;
}
this.SetY(yi+dy);
this.SetX(xi);
this. drawRows(w,hrow,strText,0,align,0,rows,1);
if (border==1)
{
this.Rect(xi,yi,w,h);
}
}
this.drawRows = function drawRows(w, h, txt, border, align, fill, maxline,prn)
{
if (!border) { border = 0;}
if (!align) { align = 'J';}
if (!fill) { fill = 0;}
if (!maxline){ maxline = 0;}
if (!prn) { prn = 0;}
cw = this.CurrentFont['cw'];
if(w==0) { w=this.w-this.rMargin-this.x;}
wmax=(w-2*this.cMargin)*1000/this.FontSize;
// ORIGINALE
//s=str_replace("\r",'',txt);
//MODIFICATO
s=txt.replace("\r",'');
// non so se server il regexp
//rExp = /\r/gi;
//s=txt.replace(rExp,'');
nb=s.length;
if ((nb>0) && (s[nb-1]=="\n")) {nb--;}
b=0;
if(border)
{
if(border==1)
{
border='LTRB';
b='LRT';
b2='LR';
}
else
{
b2='';
if(border.indexOf('L') > 0)
b2+='L';
if(border.indexOf('R') > 0)
b2+='R';
b= (border.indexOf('T') > 0) ? b2 + 'T' : b2;
}
}
sep=-1;
i=0;
j=0;
l=0;
ns=0;
nl=1;
while(i<nb)
{
//Get next character
c=s[i];
// OKS
if (c=="\n")
{
//Explicit line break
if(this.ws>0)
{
this.ws=0;
if (prn==1) this._out('0 Tw');
}
if (prn==1)
{
this.Cell(w,h,s.substr(j,i-j),b,2,align,fill);
}
i++;
sep=-1;
j=i;
l=0;
ns=0;
nl++;
if ((border) && (nl==2)) b=b2;
if ( maxline && nl > maxline ) {return s.substr(i);}
continue;
}
if(c==' ')
{
sep=i;
ls=l;
ns++;
}
l+=cw[c];
if(l>wmax)
{
//Automatic line break
if(sep==-1)
{
if(i==j) i++;
if(this.ws>0)
{
this.ws=0;
if (prn==1) this._out('0 Tw');
}
if (prn==1)
{
this.Cell(w,h,s.substr(j,i-j),b,2,align,fill);
}
}
else
{
if(align=='J')
{
this.ws=(ns>1) ? (wmax-ls)/1000*this.FontSize/(ns-1) : 0;
if (prn==1) this._out(sprintf('%.3f Tw',this.ws*this.k));
}
if (prn==1){
this.Cell(w,h,s.substr(j,sep-j),b,2,align,fill);
}
i=sep+1;
}
sep=-1;
j=i;
l=0;
ns=0;
nl++;
if((border) && (nl==2)) b=b2;
if ( maxline && nl > maxline ) {return s.substr(i);}
}
else
{
i++;
}
}
//Last chunk
if(this.ws>0)
{
this.ws=0;
if (prn==1) this._out('0 Tw');
}
if( border && (border.indexOf('B')>0) ) b +='B';
if (prn==1)
{
this.Cell(w,h,s.substr(j,i-j),b,2,align,fill);
}
this.x=this.lMargin;
return nl;
}