From: Alan Date: Tue, 27 Feb 2024 09:11:47 +0000 (+0800) Subject: fix svgtopdf X-Git-Url: http://git.roojs.org/?p=pear;a=commitdiff_plain;h=30ef61b8d946e3fbf62d857be71e2da7c284b77c fix svgtopdf --- diff --git a/FpdfAlt.php b/FpdfAlt.php index 58866333..2aa0b908 100644 --- a/FpdfAlt.php +++ b/FpdfAlt.php @@ -484,7 +484,7 @@ function Rect($x,$y,$w,$h,$style='') function AddFont($family,$style='',$file='') { - //Add a TrueType or Type1 font + //var_dump(array($family, $style, $file));//Add a TrueType or Type1 font $family=strtolower($family); if($family=='arial') $family='helvetica'; diff --git a/FpdfAlt/Chinese.php b/FpdfAlt/Chinese.php index 909e06b3..adcd675c 100644 --- a/FpdfAlt/Chinese.php +++ b/FpdfAlt/Chinese.php @@ -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('<>'); $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('<_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'); } } -?> diff --git a/XML/SvgToPdfAlt.php b/XML/SvgToPdfAlt.php index f71ece23..de9498f3 100644 --- a/XML/SvgToPdfAlt.php +++ b/XML/SvgToPdfAlt.php @@ -92,9 +92,9 @@ class XML_SvgToPDFAlt { ); $tree = $x->getTreeFromFile(); - - //echo '
'.htmlspecialchars(print_r($tree,true));exit;
+        
+        ///echo '
'.htmlspecialchars(print_r($tree,true));exit;
         
         $tree = $t->buildobject($tree);
  //echo '
'.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;
     }
     
diff --git a/XML/SvgToPdfAlt/G.php b/XML/SvgToPdfAlt/G.php
index 32ed5a14..16c36edf 100644
--- a/XML/SvgToPdfAlt/G.php
+++ b/XML/SvgToPdfAlt/G.php
@@ -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;
diff --git a/XML/SvgToPdfAlt/Text.php b/XML/SvgToPdfAlt/Text.php
index e6176468..a26e9b78 100644
--- a/XML/SvgToPdfAlt/Text.php
+++ b/XML/SvgToPdfAlt/Text.php
@@ -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) {
diff --git a/XML/SvgToPdfAlt/Tspan.php b/XML/SvgToPdfAlt/Tspan.php
index 4e217fb5..bb48c4f0 100644
--- a/XML/SvgToPdfAlt/Tspan.php
+++ b/XML/SvgToPdfAlt/Tspan.php
@@ -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');
 
                 
             }