Ejemplo n.º 1
0
 /**
  * 
  * Static ! not sure why!?
  * 
  */
 static function construct($svg, $data = array())
 {
     if (is_object($data)) {
         $data = (array) $data;
     }
     $t = new XML_SvgToPDF();
     $t->language = @$data['language'];
     /*
     $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'),
                     )
                 )
              );
     
     $tree = $x->getTreeFromFile();
           
     $tree = $t->buildobject($tree);
     */
     //echo "<PRE>";
     $tree = $t->parseSvg($svg);
     //echo "<PRE>";print_r($tree);exit;
     //echo "<PRE>";print_r($tree);exit;
     $orientation = preg_replace('/[^0-9.]+/', '', $tree->width) * 1 > preg_replace('/[^0-9.]+/', '', $tree->height) * 1 ? 'L' : 'P';
     //var_dump($orientation);exit;
     $GLOBALS['_XML_SVGTOPDF']['options']['file'] = $svg;
     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
         $pdf->open();
     } else {
         $pdf = new tFPDF($orientation, 'mm', 'A4');
         $pdf->open();
     }
     $pdf->setAutoPageBreak(false);
     $pdf->AliasNbPages();
     // convert data to array.
     if (is_object($data)) {
         $data = (array) $data;
     }
     // assoc. array of key => no of fields per page.
     $perPage = $tree->calcPerPage();
     //list($var,$perpage) = $tree->calcPerPage();
     //if (empty($data) || !@$var || !@count($data[$var])) {
     //         print_r("<PRE>");
     //          print_r($data['transactions'][0]);
     //          $data['transactions'][0]->desc = 'abcdefghijklmnopqrstuvwxyz Z';
     //           print_r($data['transactions'][0]->desc);
     // no dynamic blocks:
     if (!$perPage || empty($data)) {
         $pdf->addPage();
         $tree->writePDF($pdf, $data);
         $t->debug($tree);
         return $pdf;
     }
     // build blocks of data for each page.
     $haveData = true;
     $page = 0;
     //    $originalData = $data;
     //$alldata = $data[$var];
     //  while (count($alldata))  {
     //print_r($perPage);exit;
     while (true == $haveData) {
         $page_data = $data;
         $haveData = false;
         //print_r($perPage);
         // replaces the properties that have 'page data'
         foreach ($perPage as $k => $v) {
             if (empty($data[$k])) {
                 $page_data[$k] = array();
                 continue;
             }
             $haveData = true;
             $page_data[$k] = self::fetchRows($data, $k, $v);
             //$page_data[$k] = array_splice ( $data[$k], 0,$v);
         }
         if ($page && !$haveData) {
             break;
         }
         $page++;
         $t->debug("<B>PAGE {$page}<B>");
         $pdf->addPage();
         $tree->writePDF($pdf, $page_data);
         //$tree->writePDF($pdf,$data);
     }
     $t->debug($tree);
     return $pdf;
 }