<?php
/* usage:
-
+ (used by Hebe)
*install Fpdf as a PEAR package by:
pear install http://www.akbkhome.com:81/svn/akpear/Fpdf/Fpdf-1.51.tgz
*/
+ require_once 'XML/SvgToPdf/Base.php';
// current options for generated file..
class XML_SvgToPDF {
+
var $language;
-
- static function debug($s,$e=0) {
+ static function debug($s,$e=0)
+ {
if (!$GLOBALS['_XML_SVGTOPDF']['options']['debug']) {
- return;
+ return;
}
echo "<PRE>".print_R($s,true). "</PRE>";
if ($e) {
$t = new XML_SvgToPDF;
- $t->language = $data['language'];
- require_once 'XML/Tree/Morph.php';
-
+ $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'),
+ '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;
//echo "<PRE>";print_r($tree);exit;
- $w = empty($tree->width) ? 0 : $tree->width;
- $h = empty($tree->height) ? 0 : $tree->height;
- $orientation = (preg_replace('/[^0-9.]+/','', $w)*1) > (preg_replace('/[^0-9.]+/','', $h)*1) ? 'L' : 'P';
- //var_dump($orientation);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/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();
- }
+ //die("trying chinese");
+ require_once 'Fpdf/tFPDF.php' ;
- $pdf->setAutoPageBreak(false);
+ $pdf = new tFPDF($orientation ,'mm','A4');
+ $pdf->AddFont('ARIALUNI','','ARIALUNI.ttf',true);
+ //print_R($pdf);exit;
+//
+ $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();
// $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;
$page++;
$t->debug("<B>PAGE $page<B>");
+
$pdf->addPage();
-
$tree->writePDF($pdf,$page_data);
-
-
+
//$tree->writePDF($pdf,$data);
}
function parseSvg($svgFileName)
{
- libxml_use_internal_errors(true);
$d = new DOMDocument();
$d->load($svgFileName);
// print_r($d);
return $this->parseNode($d->documentElement);
}
- function parseXMLNode($n)
+ function parseNode($n)
{
// do children first..
//print_r(array("PARSENODE:",$n));
- if (empty($n)) {
- return array();
- }
$children = array();
if ($n->childNodes->length) {
foreach($n->childNodes as $cn) {
return $children;
}
- // fixme.. this is the Dom Version..
$ret = $this->buildObject($n,$children);
return $ret;
function buildNull($node) {
return;
}
- function buildObject($node )
+ function buildObject($node, $children)
{
- require_once 'XML/SvgToPdf/Base.php';
-
- return XML_SvgToPDF_Base::factory($node);
-
+ $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;
}