fix svgtopdf
authorAlan <alan@roojs.com>
Tue, 27 Feb 2024 09:11:47 +0000 (17:11 +0800)
committerAlan <alan@roojs.com>
Tue, 27 Feb 2024 09:11:47 +0000 (17:11 +0800)
FpdfAlt.php
FpdfAlt/Chinese.php
XML/SvgToPdfAlt.php
XML/SvgToPdfAlt/G.php
XML/SvgToPdfAlt/Text.php
XML/SvgToPdfAlt/Tspan.php

index 5886633..2aa0b90 100644 (file)
@@ -484,7 +484,7 @@ function Rect($x,$y,$w,$h,$style='')
 \r
 function AddFont($family,$style='',$file='')\r
 {\r
-       //Add a TrueType or Type1 font\r
+       //var_dump(array($family, $style, $file));//Add a TrueType or Type1 font\r
        $family=strtolower($family);\r
        if($family=='arial')\r
                $family='helvetica';\r
index 909e06b..adcd675 100644 (file)
@@ -111,7 +111,7 @@ class FpdfAlt_Chinese extends FpdfAlt
             $c=$s[$i];
             if(ord($c)<128)
             {
-                $l+=$cw[$c];
+                $l+= isset($cw[$c]) ? $cw[$c] : 0;
                 $i++;
             }
             else
@@ -320,7 +320,8 @@ class FpdfAlt_Chinese extends FpdfAlt
     
     function _putfonts()
     {
-        $nf=$this->n;
+        print_R($this->fonts);
+               $nf=$this->n;
         foreach($this->diffs as $diff)
         {
             //Encodings
@@ -328,6 +329,8 @@ class FpdfAlt_Chinese extends FpdfAlt
             $this->_out('<</Type /Encoding /BaseEncoding /WinAnsiEncoding /Differences ['.$diff.']>>');
             $this->_out('endobj');
         }
+               
+               
         foreach($this->FontFiles as $file=>$info)
         {
             //Font file embedding
@@ -336,6 +339,7 @@ class FpdfAlt_Chinese extends FpdfAlt
             if(defined('FPDF_FONTPATH'))
                 $file=FPDF_FONTPATH.$file;
             $size=filesize($file);
+                       
             if(!$size)
                 $this->Error('Font file not found');
             $this->_out('<</Length '.$size);
@@ -389,7 +393,7 @@ class FpdfAlt_Chinese extends FpdfAlt
                 $this->_out('endobj');
                 if($font['type']!='core')
                 {
-                    //Widths
+                                       //Widths
                     $this->_newobj();
                     $cw=&$font['cw'];
                     $s='[';
@@ -409,7 +413,7 @@ class FpdfAlt_Chinese extends FpdfAlt
                     $this->_out('endobj');
                 }
             }
-        }
+        } 
     }
     
     function _putType0($font)
@@ -452,4 +456,3 @@ class FpdfAlt_Chinese extends FpdfAlt
        $this->_out('endobj');
 }
 }
-?>
index f71ece2..de9498f 100644 (file)
@@ -92,9 +92,9 @@ class XML_SvgToPDFAlt {
                  );
 
         $tree = $x->getTreeFromFile();
         
-        //echo '<PRE>'.htmlspecialchars(print_r($tree,true));exit;
+        
+        ///echo '<PRE>'.htmlspecialchars(print_r($tree,true));exit;
         
         $tree = $t->buildobject($tree);
  //echo '<PRE>'.htmlspecialchars(print_r($tree,true));
@@ -133,6 +133,7 @@ class XML_SvgToPDFAlt {
             $pdf->addPage();
             $tree->writePDF($pdf,$data);
             $t->debug($tree);
+         
             return $pdf;
         }
         
@@ -161,7 +162,7 @@ class XML_SvgToPDFAlt {
             $tree->writePDF($pdf,$page_data);
         }
         
-        $t->debug($tree);
+        $t->debug($tree, true);
         return $pdf;
     }
     
index 32ed5a1..16c36ed 100644 (file)
@@ -21,7 +21,7 @@ class XML_SvgToPDFAlt_G     extends XML_SvgToPDFAlt_Base {
         
         $isDynamic = false;
         foreach(array_keys($this->children) as $k) {
-            if (!is_a($this->children[$k], 'XML_SvgToPDF_Text')) {
+            if (!is_a($this->children[$k], 'XML_SvgToPDFAlt_Text')) {
                 continue;
             }
             
@@ -51,7 +51,7 @@ class XML_SvgToPDFAlt_G     extends XML_SvgToPDFAlt_Base {
          //look for the bounding box..
         $boundingbox = false;
         foreach(array_keys($this->children) as $k) {
-            if (!is_a($this->children[$k], 'XML_SvgToPDF_Rect')) {
+            if (!is_a($this->children[$k], 'XML_SvgToPDFAlt_Rect')) {
                continue;
             }
             if (@$this->children[$k]->nonprintable == 'true') {
@@ -128,12 +128,12 @@ class XML_SvgToPDFAlt_G     extends XML_SvgToPDFAlt_Base {
         $kmax = count($keys);
         //XML_SvgToPDF::debug(array($x,$y,$w,$h));
         //XML_SvgToPDF::debug($keys);
-        XML_SvgToPDF::debug($this->settings);
+        XML_SvgToPDFAlt::debug($this->settings);
         for($r=0;$r<$this->settings['rows'];$r++) {
             $yy = $y + ($r*$h);
             for($c=0;$c<$this->settings['cols'];$c++) {
                 $xx = $x + ($c*$w);
-                XML_SvgToPDF::debug(array($xx,$yy));
+                XML_SvgToPDFAlt::debug(array($xx,$yy));
                 foreach(array_keys($this->children) as $k) {
                     if (!$this->children[$k]) {
                         continue;
index e617646..a26e9b7 100644 (file)
@@ -110,7 +110,7 @@ class XML_SvgToPDFAlt_Text  extends XML_SvgToPDFAlt_Base {
             $xx = isset($c->x) ? $c->x + @$this->xx : $x;
             $yy = isset($c->y) ? $c->y + @$this->yy : $y + ($lineno * $size * 1.3);
             $lineno++;              
-            $val = @$c->content;
+            $val = isset($c->content) ? $c->content : '';
             
             if (isset($c->args)) {
                 
@@ -131,7 +131,7 @@ class XML_SvgToPDFAlt_Text  extends XML_SvgToPDFAlt_Base {
                      
                 $val = vsprintf($val,$args);
                 
-                if ($has_template && ($font == 'Big5')) {
+               if ($has_template && ($font == 'Big5')) {
                     require_once  'Text/ZhDetect.php';
                     $detect = new Text_zhDetect;
                     $type = $detect->guess($val);
@@ -142,12 +142,14 @@ class XML_SvgToPDFAlt_Text  extends XML_SvgToPDFAlt_Base {
                             $weight,
                             $size);
                     } else {
+                                               $vv = $val;
                         $val = @iconv('utf8', 'BIG5//IGNORE', $val);
+                                               //var_dump(array($vv, $val));
                         $pdf->setFont('Big5' ,
                             $weight,
                             $size);
                    }
-                }
+                 }
                 
                 /*
                 
@@ -165,14 +167,12 @@ class XML_SvgToPDFAlt_Text  extends XML_SvgToPDFAlt_Base {
             }
             
             $talign = $align;
-            if ((!@$this->children[$i+1] ||  !strlen(trim(@$this->children[$i+1]->content))) && ($align == 'J')) {
+            if ((empty($this->children[$i+1]) ||  !isset($this->children[$i+1]->content) || !strlen(trim($this->children[$i+1]->content))) && ($align == 'J')) {
                 $talign = 'L';
             }
             
             
-            
-            
-            
+             
             
             
             
@@ -288,7 +288,7 @@ class XML_SvgToPDFAlt_Text  extends XML_SvgToPDFAlt_Base {
     
     function multiLine(&$pdf,$lines,$x,$y,$h,$align) {
         // now dealing with mm
-        XML_SvgToPDFAlt::debug("MULTILINE " .implode("\n",$lines) . " $x, $y, $h");
+        XML_SvgToPDFAlt::debug("MULTILINE '" .implode("\n",$lines) . "' $x, $y, $h");
         $yoffset  = 0;
         $line = -1;
         foreach ($lines as $l=>$v) {
index 4e217fb..bb48c4f 100644 (file)
@@ -26,12 +26,15 @@ class XML_SvgToPDFAlt_Tspan extends XML_SvgToPDFAlt_Base {
 
                 $this->content =  preg_replace_callback(
                         '/&#(\d+);/m',
-                            function($m) { return chr($m[1]); }  ,$this->content);
+                            function($m) {
+                            
+                                return mb_chr($m[1]);
+                            }  ,$this->content);
             }
             if (@$node->language) {
                 // todo - other conversions....
 
-                $this->content = mb_convert_encoding($this->content,'BIG-5','UTF-8');
+                //$this->content = mb_convert_encoding($this->content,'BIG-5','UTF-8');
 
                 
             }