Open GoogleCodeExporter opened 8 years ago
I found what the problem looks at the function where accumulates "l" and
commented
code, and I am now working properly.
public function writeText ( pHeight:Number, pText:String, pLink:String='' ):void
{
//Output text in flowing mode
var cw:Object = this.currentFont.cw;
var w:Number = currentPage.w-this.rMargin-this.x;
var wmax:Number = (w-2*this.cMargin)*1000/this.fontSize;
var s:String = str_replace ("\r",'',pText);
var cwAux:int = 0;
//var s:String = ",,,"
var nb:int = s.length;
var sep:int = -1;
var i:int = 0;
var j:int = 0;
var l:int = 0;
var nl:int = 1;
while( i<nb )
{
//Get next character
var c:String = s.charAt(i);
if(c=="\n")
{
//Explicit line break
this.addCell (w,pHeight,s.substr(j,i-j),0,2,'',0,pLink);
i++;
sep=-1;
j=i;
l=0;
if(nl==1)
{
this.x = this.lMargin;
w = currentPage.w-this.rMargin-this.x;
wmax= (w-2*this.cMargin)*1000/this.fontSize;
}
nl++;
continue;
}
if(c==' ') sep=i;
/*
Here verify if the character is unknown I value 500 by default, because the
problem is that if the character is not in the array can not add accumulator
"l".
Notice whether this solution is valid. Thanks
*/
cwAux = int(cw[c]);
if (cwAux == 0)
{
cwAux = 500;
}
l+=cwAux;
if(l>wmax)
{
//Automatic line break
if(sep==-1)
{
if(this.x>this.lMargin)
{
//Move to next line
this.x = this.lMargin;
this.y += currentPage.h;
w = currentPage.w-this.rMargin-this.x;
wmax = (w-2*this.cMargin)*1000/this.fontSize;
i++;
nl++;
continue;
}
if(i==j) i++;
this.addCell (w,pHeight,s.substr(j,i-j),0,2,'',0,pLink);
}
else
{
this.addCell (w,pHeight,s.substr(j,sep-j),0,2,'',0,pLink);
i=sep+1;
}
sep=-1;
j=i;
l=0;
if(nl==1)
{
this.x=this.lMargin;
w=currentPage.w-this.rMargin-this.x;
wmax=(w-2*this.cMargin)*1000/this.fontSize;
}
nl++;
}
else i++;
}
//Last chunk
if (i!=j) this.addCell (l/1000*this.fontSize,pHeight,s.substr(j),0,0,'',0,pLink);
}
Original comment by castroma...@gmail.com
on 13 Nov 2007 at 3:31
We must correct the following function to operate the 'link' correct:
private function GetStringWidth(s:String):Number
{
var s:String = String ( s );
cw = currentFont.cw
var w:Number=0;
var l:int = s.length;
var cwAux:Number = 0;
for(var i:int=0;i<l;i++)
{
cwAux = Number(cw[s.charAt(i)]);
if (isNaN(cwAux))
{
cwAux = 500;
}
w+= cwAux;
}
return w*fontSize/1000;
}
Original comment by castroma...@gmail.com
on 13 Nov 2007 at 4:17
Hi castromatias,
Thanks for tracking, I will include that and also optimize some other things
related
to special characters in the next version ;)
kind regards,
Thibault
Original comment by thibault.imbert
on 13 Nov 2007 at 6:46
Hi, I'm trying to write text (using writeText function) with special spanish
characters (same as castromatias) from an utf-8 xml but I always get wrong
results:
Ä, Â, etc... followed by another character.
I changed /WinAnsiEncoding encoding to all the posibilities (i think) but the
result
is the same.
When I debug code I see correct characters in Flex but when pdf is generated
everyone
turns wrong.
Thanks,
Fer
Original comment by quintero...@gmail.com
on 3 Apr 2008 at 9:41
Original issue reported on code.google.com by
castroma...@gmail.com
on 13 Nov 2007 at 1:50