4 The base node includes:
5 fromNode - convert the XML_Tree node into object with vars
8 // iternate tree with writePDF
10 childrenWritePDF($pdf,$data)
12 // shift coordinates of group dynamic elements
13 // so the x is relative to the block corner.
14 shiftChildren($x,$y) {
17 // find a dynamic block and calculate how much data it can hold.
18 // so you know how many pages are needed.
22 class XML_SvgToPDF_Base {
26 var $width = 0; // used in svg..
30 var $children = array();
39 var $sodipodilinespacing;
40 var $sodipodinonprintable;
41 var $sodipodinodetypes;
72 static function factory($node)
74 if (is_a($node, 'XML_SvgToPDF_Base')) {
78 $class = 'XML_SvgToPDF_'.$node->name;
80 if (strlen(trim($node->content)) && (@$this->language)) {
81 $node->language = $this->language;
86 //echo "look for $class?";
87 if (!class_exists($class)) {
89 $file = dirname(__FILE__) .'/'.ucfirst(strtolower($node->name)). '.php';
91 if (file_exists($file)) {
92 require_once 'XML/SvgToPdf/'.ucfirst(strtolower($node->name)) . '.php';
95 // now if it doesnt exist..
96 if (!class_exists($class)) {
98 $class = 'XML_SvgToPDF_Base';
105 function factoryChildren($ar) {
108 $this->children[] = $this->factory($c);
114 function fromXmlNode(DomElement $node)
116 // extract attributes
117 foreach($node->attributes as $k=>$v) {
118 if (in_array($k, array('style'))) {
121 $k = preg_replace('/[^a-z]+/', '', $k);
123 $v = is_object($v) ? $v->value : $v;
124 if (preg_match('/[0-9]+mm$/',$v)) {
125 $vv = str_replace('mm','',$v);
126 $vv = $vv * 3.543307;
135 if ($node->hasAttribute('style') && strlen($node->getAttribute('style'))) {
137 $s = explode(';',$node->getAttribute('style'));
139 if (!strlen(trim($ss))) {
143 $sss = explode(':',$ss);
144 if (preg_match('/[0-9]+pt$/',$sss[1])) {
145 $sss[1] = str_replace('pt','',$sss[1]);
147 $style[$sss[0]] = $sss[1];
149 $this->style = $style;
151 $this->name = $node->tagName;
154 if ($node->children) {
155 $this->factoryChildren($node->children);
161 // if node is a tspan
168 function fromNode($node) {
170 if ($node->attributes) {
171 foreach($node->attributes as $k=>$v) {
173 //echo $node->name . ":" . $k . "=>". $v. "<BR>";
175 if (strpos($k,':')) {
176 $kk = explode(':',$k);
180 if (preg_match('/[0-9]+mm$/',$v)) {
181 $v = str_replace('mm','',$v);
191 if (isset($this->style) && is_string($this->style)) {
193 $s = explode(';',$this->style);
195 if (!strlen(trim($ss))) {
198 if (strpos($ss,':') === false) {
202 $sss = explode(':',$ss);
203 if (preg_match('/[0-9]+pt$/',$sss[1])) {
204 $sss[1] = str_replace('pt','',$sss[1]);
206 $style[$sss[0]] = $sss[1];
208 $this->style = $style;
211 $this->name = $node->name;
213 if ($node->content) {
214 $this->content = trim($node->content);
215 //echo $node->name . ":CONTENT=>". $node->content. "<BR>";
218 if ($node->children) {
219 $this->factoryChildren($node->children);
221 // echo "<PRE>BEFORE:";print_r($this->toArray());
223 //echo "<PRE>AFTER:";print_r($this->toArray());
227 function transform() {
228 if (empty($this->transform)) {
231 // do not transform tspans -- done by overwriting this...
232 //if ($this->x === false) {
236 // deal with transformation..
237 $tr = $this->transform;
238 if (preg_match('/scale\(([0-9e.-]+),([0-9e.-]+)\)/',$tr,$args)) {
242 } else if (preg_match('/matrix\(([0-9e.-]+),([0-9e.-]+),([0-9e.-]+),([0-9e.-]+),([0-9e.-]+),([0-9e.-]+)\)/',$tr,$args)) {
244 require_once 'Math/Matrix.php';
245 $matrix = new Math_Matrix( array(
246 array($args[0],$args[2],$args[4]),
247 array($args[1],$args[3],$args[5]),
251 } else if (preg_match('/translate\(([0-9e.-]+),([0-9e.-]+)\)/',$tr,$args)) {
254 $method = 'translate';
256 echo "<PRE>no match?";print_r($this); exit;
264 if (empty($this->children)) {
267 foreach(array_keys($this->children) as $i) {
268 if ($this->children[$i]->x === false) {
270 // echo "<PRE>";print_r($this);exit;
272 $this->children[$i]->x *= $xscale;
273 $this->children[$i]->y *= $yscale;
277 $v = new Math_Vector(array($this->x,$this->y,0));
279 $r = $matrix->vectorMultiply($v);
283 //echo "<PRE>";var_dump( $r);exit;
284 if (empty($this->children)) {
287 foreach(array_keys($this->children) as $i) {
288 if ($this->children[$i]->x === false) {
290 // echo "<PRE>";print_r($this);exit;
292 $v = new Math_Vector(array($this->children[$i]->x,$this->children[$i]->y,0));
293 $r = $matrix->vectorMultiply($v);
295 $this->children[$i]->x = $r[0];
296 $this->children[$i]->y = $r[1];
301 if ($this->x !== false && $this->y !== false) {
306 if (empty($this->children)) {
309 foreach(array_keys($this->children) as $i) {
310 if ($this->children[$i]->x === false || $this->children[$i]->y === false) {
312 // echo "<PRE>";print_r($this);exit;
314 $this->children[$i]->x += $x;
315 $this->children[$i]->y += $y;
326 function writePDF($pdf,$data) {
327 $this->childrenWritePDF($pdf,$data);
330 function childrenWritePDF($pdf,&$data) {
331 if (!@$this->children) {
334 foreach(array_keys($this->children) as $k) {
335 if (empty($this->children[$k])) {
338 if (!method_exists($this->children[$k],'writePDF')) {
339 echo '<PRE>'; print_r(array($this, $k));
340 trigger_error( "OOPS unknown object?" );
342 $this->children[$k]->writePDF($pdf,$data);
347 // add the values to the children..
348 function shiftChildren($x,$y) {
349 if (empty($this->children)) {
352 foreach(array_keys($this->children) as $k) {
353 if (!$this->children[$k]) {
356 $this->children[$k]->shift($x,$y);
360 function shift($x,$y) {
361 //XML_SvgToPDF::debug('shift');
362 //XML_SvgToPDF::debug(array($x,$y));
363 //XML_SvgToPDF::debug($this);
369 //var_dump(array("SHIFT", $x, $y, "TO: ", $this->x , $this->y));
370 if ($this->x !== false) {
373 if ($this->y !== false) {
376 //XML_SvgToPDF::debug($this);
377 $this->shiftChildren($x,$y);
379 function calcPerPage() {
381 foreach($this->children as $n) {
385 if (!is_a($n, 'XML_SvgToPDF_G')) {
388 if (!isset($n->settings) || !isset($n->settings['dynamic'])) {
393 $rows = isset($n->settings['rows']) ? $n->settings['rows'] : 1;
394 $cols = isset($n->settings['cols']) ? $n->settings['cols'] : 1;
395 // return array($n->settings['dynamic'], $rows * $cols);
398 $ret[$n->settings['dynamic']] = $rows * $cols;
404 //return array('',0);
414 function toColor($color) {
415 if (!$color || ($color == 'none')) {
419 if ($color == 'black') {
424 hexdec(substr($color,1,2)),
425 hexdec(substr($color,3,2)),
426 hexdec(substr($color,5,2)));
433 $ret['__CLASS__'] = get_class($this);
434 foreach($ar as $k=>$v) {
435 if (is_array($v) || is_object($v)) {
436 $ret[$k] = "**ARRAY|OBJECT**";