Fix #8052 - fixing pdf
[pear] / XML / SvgToPdf.php
index 58700aa..c3b44b9 100644 (file)
@@ -41,9 +41,6 @@
         
 */
 
-require_once 'XML/Tree/Morph.php';
-require_once 'Fpdf/tFPDF.php'; 
-require_once 'XML/SvgToPdf/Base.php';
 
 // current options for generated file..
 
@@ -81,32 +78,33 @@ class XML_SvgToPDF {
         $t = new XML_SvgToPDF;
         
         $t->language =  $data['language'];
-       /*
+        require_once 'XML/Tree/Morph.php';
+
         $x = new XML_Tree_Morph( 
                     $svg,
                     array(
                        'debug' => 0,
                        'filter' => array(
-                           'svg'    => array(&$t, 'buildObject'),
-                           'image'    => array(&$t, 'buildObject'),
-                           'text'    => array(&$t, 'buildObject'),
-                           'tspan'   => array(&$t, 'buildObject'),
-                           'rect'   => array(&$t, 'buildObject'),
-                           'g'   =>  array(&$t, 'buildObject'),
-                           'path'   =>  array(&$t, 'buildObject'),
-                           'sodipodi:namedview' =>  array(&$t, 'buildNull'),
-                           'defs' =>  array(&$t, 'buildNull'),
+                           'svg'    => array($t, 'buildObject'),
+                           'image'    => array($t, 'buildObject'),
+                           'text'    => array($t, 'buildObject'),
+                           'tspan'   => array($t, 'buildObject'),
+                           'rect'   => array($t, 'buildObject'),
+                           'g'   =>  array($t, 'buildObject'),
+                           'path'   =>  array($t, 'buildObject'),
+                           'sodipodi:namedview' =>  array($t, 'buildNull'),
+                           'defs' =>  array($t, 'buildNull'),
                         )
                     )
                  );
         
         $tree = $x->getTreeFromFile();
-              
+       //echo '<PRE>'; print_R($tree);      exit;
         $tree = $t->buildobject($tree);
-        */
+       //   echo '<PRE>'; print_R($tree);      exit;
          //echo "<PRE>";
-        $tree = $t->parseSvg($svg);
-        //echo "<PRE>";print_r($tree);exit;
+       // $tree = $t->parseSvg($svg);
+        // echo "<PRE>";print_r($tree);exit;
         
         
         
@@ -121,34 +119,20 @@ class XML_SvgToPDF {
 
         if ($data['language'] == 'big5') {
           //die("trying chinese");
-            require_once  'Fpdf/tFPDF.php' ;
-
-            $pdf = new tFPDF($orientation ,'mm','A4');
-            
-            // we originally used ARIALUNI.ttf'
-            
-            $font = '/usr/share/fonts/truetype/msttcorefonts/Arial.ttf';
-            
-            if (!file_exists('/usr/share/fonts/truetype/msttcorefonts/Arial.ttf')) {
-                die("install msttcorefonts package");
-            }
             
-            //$pdf->AddFont('ARIALUNI','',$font,true);
-            
-            $pdf->AddFont('ARIALUNI','','/usr/share/fonts/truetype/msttcorefonts/Arial.ttf',true);
-            $pdf->AddFont('ARIALUNI','B','/usr/share/fonts/truetype/msttcorefonts/Arial_Bold.ttf',true);
-            
-//            $pdf->SetFont('ARIALUNI','',14);
-//            require_once 'Fpdf/Chinese-unicode.php';
-//
-//            $pdf=new PDF_Unicode($orientation ,'mm','A4');
-////            $pdf->AddGBFont();
-////            $pdf->AddBig5Font();
-//            $pdf->AddUniCNSFont('Uni');
-            //$pdf->AddUniCNSFont('Uni'); 
-            //AddUniCNShwFont
+               
+            require_once 'Fpdf/Unicode.php';
+
+            $pdf=new FPDF_Unicode($orientation ,'mm','A4');
+            $pdf->AddGBFont();
+            $pdf->AddBig5Font();
+            $pdf->AddUniCNShwFont(); 
             $pdf->open();            
+
+         
         } else {
+            require_once  'Fpdf/tFPDF.php' ;
+
             $pdf=new tFPDF($orientation ,'mm','A4');
             $pdf->open();
         }
@@ -216,11 +200,12 @@ class XML_SvgToPDF {
             $page++;
                 
             $t->debug("<B>PAGE $page<B>");
-         
             
             $pdf->addPage();
+
             $tree->writePDF($pdf,$page_data);
-            
+                
+      
             //$tree->writePDF($pdf,$data);
         }
        
@@ -228,7 +213,7 @@ class XML_SvgToPDF {
         return $pdf;
     }
     
-    function fetchRows(&$original_data, $key, $rows) {
+    static function fetchRows(&$original_data, $key, $rows) {
         $ret = array();
         while ($rows > -1 && !empty($original_data[$key])) {
             $addrow = array_shift($original_data[$key]);
@@ -256,7 +241,7 @@ class XML_SvgToPDF {
         return $this->parseNode($d->documentElement);
     }
     
-    function parseNode($n)
+    function parseXMLNode($n)
     {
         // do children first..
         //print_r(array("PARSENODE:",$n));
@@ -285,6 +270,7 @@ class XML_SvgToPDF {
             return $children;
             
         }
+        // fixme.. this is the Dom Version..
         $ret = $this->buildObject($n,$children);
         
         return $ret;
@@ -298,33 +284,12 @@ class XML_SvgToPDF {
     function buildNull($node) {
         return;
     }
-    function buildObject($node, $children) {
-        $class = 'XML_SvgToPDF_'.$node->tagName;
-        /*
-        if (strlen(trim($node->content)) && (@$this->language)) {
-            $node->language = $this->language;
-        }
-        */
-
-        //echo "look for $class?";
-        if (!class_exists($class)) {
-            // try loading it..
-            $file = dirname(__FILE__) . '/SvgToPdf/'.ucfirst(strtolower($node->tagName)). '.php';
-            $this->debug("loading  $file");
-            if (file_exists($file)) {
-                require_once 'XML/SvgToPdf/'.ucfirst(strtolower($node->tagName)) . '.php';
-            }
-        }
-        // now if it doesnt exist..
-        if (!class_exists($class)) {
-            $this->debug("can not find $class");
-           $class = 'XML_SvgToPDF_Base';
-        }
-        $r = new $class;
-        $r->children = $children;
-        $r->fromXmlNode($node);
-        return $r;
+    function buildObject($node )
+    {
+        require_once 'XML/SvgToPdf/Base.php';
+        
+        return XML_SvgToPDF_Base::factory($node);
+         
     }