mesaglam / alivepdf

Automatically exported from code.google.com/p/alivepdf
0 stars 0 forks source link

Special characters problem in "writeText" function. #17

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?

First acknowledge you and the job, I am speaking Spanish and use the PDF
class, it turns out that when you have many special characters like "ñ, á,
é, í, ó and ú" loses the result of text and generates only one long line 
row.
This prevents you can generate the document, your help and you could verify
it is correct.
Thanks for your help. Greetings.
Text sample test:

myPDF.writeText (5,"Lorem ipsum máñana él día nótorio último Lorem ipsum
máñana él día nótorio último Lorem ipsum máñana él día nótorio 
último Lorem
ipsum máñana él día nótorio último Lorem ipsum máñana él día nótorio 
último
Lorem ipsum máñana él día nótorio último Lorem ipsum máñana él día 
nótorio
último Lorem ipsum máñana él día nótorio último Lorem ipsum máñana él 
día
nótorio último Lorem ipsum máñana él día nótorio último Lorem ipsum 
máñana
él día nótorio último Lorem ipsum máñana él día nótorio último Lorem 
ipsum
máñana él día nótorio último Lorem ipsum máñana él día nótorio 
último Lorem
ipsum máñana él día nótorio último Lorem ipsum máñana él día nótorio 
último
Lorem ipsum máñana él día nótorio último Lorem ipsum máñana él día 
nótorio
último Lorem ipsum máñana él día nótorio último Lorem ipsum máñana él 
día
nótorio último Lorem ipsum máñana él día nótorio último Lorem ipsum 
máñana
él día nótorio último Lorem ipsum máñana él día nótorio último");

What version of the product are you using? On what operating system?
The version is 0.1.4, my operating system is Win2000Sp4.

Please provide any additional information below.
With this type of special characters and had some problems.

Original issue reported on code.google.com by castroma...@gmail.com on 13 Nov 2007 at 1:50

GoogleCodeExporter commented 9 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

GoogleCodeExporter commented 9 years ago
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

GoogleCodeExporter commented 9 years ago
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

GoogleCodeExporter commented 9 years ago
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