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 #[AllowDynamicProperties]
23 class XML_SvgToPDFAlt_Base {
27 function fromNode($node) {
29 if ($node->attributes) {
30 foreach($node->attributes as $k=>$v) {
32 $kk = explode(':',$k);
37 if (preg_match('/[0-9]+mm$/',$v)) {
38 $v = str_replace('mm','',$v);
42 $this->{'_'.$k} = $v;// save the original..
49 if (isset($this->style)) {
50 $s = explode(';',$this->style);
52 if (!strlen(trim($ss))) {
55 if (strpos($ss,':') === false) {
59 $sss = explode(':',$ss);
60 if (preg_match('/[0-9]+pt$/',$sss[1])) {
61 $sss[1] = str_replace('pt','',$sss[1]);
63 $style[$sss[0]] = $sss[1];
65 $this->style = $style;
70 $this->content = trim($node->content);
72 if ($node->children) {
73 $this->children = $node->children;
79 function transform() {
80 if (!@$this->transform) {
83 // deal with transformation..
84 $tr = $this->transform;
85 if (preg_match('/scale\(([0-9e.-]+),([0-9e.-]+)\)/',$tr,$args)) {
86 $xscale = (float)$args[1];
87 $yscale = (float)$args[2];
89 } else if (preg_match('/matrix\(([0-9e.-]+),([0-9e.-]+),([0-9e.-]+),([0-9e.-]+),([0-9e.-]+),([0-9e.-]+)\)/',$tr,$args)) {
91 require_once 'Math/Matrix.php';
92 $matrix = new Math_Matrix( array(
93 array((float)$args[0],(float)$args[2],(float)$args[4]),
94 array((float)$args[1],(float)$args[3],(float)$args[5]),
98 } else if (preg_match('/translate\(([0-9e.-]+),([0-9e.-]+)\)/',$tr,$args)) {
100 $y =(float) $args[2];
101 $method = 'translate';
103 echo "<PRE>no match?";print_r($this); exit;
111 if (!@$this->children) {
114 foreach(array_keys($this->children) as $i) {
115 if (!isset($this->children[$i]->x)) {
117 // echo "<PRE>";print_r($this);exit;
119 $this->children[$i]->x *= $xscale;
120 $this->children[$i]->y *= $yscale;
124 $v = new Math_Vector(array($this->x,$this->y,0));
126 $r = $matrix->vectorMultiply($v);
130 //echo "<PRE>";var_dump( $r);exit;
131 if (!@$this->children) {
134 foreach(array_keys($this->children) as $i) {
135 if (!isset($this->children[$i]->x)) {
137 // echo "<PRE>";print_r($this);exit;
139 $v = new Math_Vector(array($this->children[$i]->x,$this->children[$i]->y,0));
140 $r = $matrix->vectorMultiply($v);
142 $this->children[$i]->x = $r[0];
143 $this->children[$i]->y = $r[1];
148 //echo 'translate' . $x .',' . $y . "\n";
149 if (isset($this->x) && isset($this->y)) {
154 if (!@$this->children) {
157 foreach(array_keys($this->children) as $i) {
158 if (!isset($this->children[$i]->x) || !isset($this->children[$i]->y)) {
160 // echo "<PRE>";print_r($this);exit;
162 $this->children[$i]->x += $x;
163 $this->children[$i]->y += $y;
174 function writePDF($pdf,$data) {
175 $this->childrenWritePDF($pdf,$data);
178 function childrenWritePDF(&$pdf,&$data) {
179 if (!@$this->children) {
182 foreach(array_keys($this->children) as $k) {
183 if (!$this->children[$k]) {
186 if (!method_exists($this->children[$k],'writePDF')) {
187 echo "OOPS unknown object? <PRE>" ; print_r($this->children[$k]); exit;
189 $this->children[$k]->writePDF($pdf,$data);
193 function shiftChildren($x,$y) {
194 if (!@$this->children) {
197 foreach(array_keys($this->children) as $k) {
198 if (!$this->children[$k]) {
201 $this->children[$k]->shift($x,$y);
205 function shift($x,$y) {
206 //XML_SvgToPDF::debug('shift');
207 //XML_SvgToPDF::debug(array($x,$y));
208 //XML_SvgToPDF::debug($this);
209 if (isset($this->x)) {
213 if (isset($this->y)) {
216 //XML_SvgToPDF::debug($this);
217 $this->shiftChildren($x,$y);
219 function calcPerPage() {
221 foreach($this->children as $n) {
225 if (!is_a($n, 'XML_SvgToPDF_G')) {
228 if (!isset($n->settings)) {
232 $rows = isset($n->settings['rows']) ? $n->settings['rows'] : 1;
233 $cols = isset($n->settings['cols']) ? $n->settings['cols'] : 1;
236 $ret[$n->settings['dynamic']] = $rows * $cols;
249 function toColor($color) {
250 if (!$color || ($color == 'none')) {
254 if ($color == 'black') {
259 hexdec(substr($color,1,2)),
260 hexdec(substr($color,3,2)),
261 hexdec(substr($color,5,2)));