af5c77a4dd7143736882da0e624de73d1e2ca1de
[pear] / XML / SvgToPdf / Path.php
1 <?php
2
3 /* output a line
4
5 */
6
7 class XML_SvgToPDF_Path  extends XML_SvgToPDF_Base {
8     var $d; // stores the details of the path..
9     var $id;
10     
11     
12     function fromXmlNode($node) {
13         parent::fromXmlNode($node);
14         $d = explode(' ',trim($this->d));
15         $i=0;
16         $data = array();
17         
18         while ($i < count($d)) {
19             $action = $d[$i];
20             switch(strtolower($action)) {
21                 
22                 
23                 
24                 case 'c': // ????
25                    
26                     $data[] = array('L',$d[$i+3],$d[$i+4]);
27                     $i+=7;
28                     break;
29                 case 'm': // move
30                 case 'l': // line
31                     $data[] = array($action,$d[$i+1],$d[$i+2]);
32                     $i+=3;
33                     break;
34                 case 'h': // move horizontal
35                 case 'v': // move horizontal
36                     $data[] = array($action,$d[$i+1]);
37                     $i+=2;
38                     break;
39                 
40                 
41                 case 'z': // close path..
42                     $data[] = array($action);
43                     $i++;
44                     break;
45                 default:
46                     echo "oops found something odd in path? '$action'";
47                     echo $this->d;
48                     exit;
49                     break;
50             }
51         }
52         $this->d = $data;
53     }
54             
55             
56         // TODO!! - shift!!!
57             
58         
59         
60         
61         
62      function shift($x,$y) {
63         //XML_SvgToPDF::debug('shift');
64         //XML_SvgToPDF::debug(array($x,$y));
65         //XML_SvgToPDF::debug($this);
66         foreach($this->d as $i=>$a) {
67             if (count($a) < 2) {
68                 continue;
69             }
70             if ($a[0] == 'v') {
71                 $this->d[$i][1] -= $y;
72             } else {
73                 $this->d[$i][1] -= $x;
74                 if (isset($this->d[$i][2])) {
75                     $this->d[$i][2] -= $y;
76                 }
77             }
78         }
79         
80     }   
81         
82     
83     
84     function writePDF($pdf,$data) {
85         
86         $l = $this->toColor(@$this->style['stroke']);
87         if ($l) {
88             $pdf->setDrawColor($l[0],$l[1],$l[2]);
89         }
90         $pdf->setLineWidth($this->style['stroke-width']/ 3.543307);
91      
92         $c = array();
93         /*
94          *Not sure why this was added..
95         if (count($this->d) > 2) {
96             $cc = array();
97             foreach($this->d as $a) { 
98                  if (count($a) < 2) {
99                         continue;       
100                  }
101                  $x = $a[1] + @$this->xx;
102                  $y = $a[2] + @$this->yy;
103                  $cc[] = $x/ 3.543307;
104                  $cc[] = $y/ 3.543307;
105             }
106             $pdf->line($cc,0,0,0);
107             return;
108         }
109         */
110         
111
112         foreach($this->d as $a) {
113             switch($a[0]) {
114                 case 'M':
115                     $x = $a[1] + @$this->xx;
116                     $y = $a[2] + @$this->yy;
117                     $c = array($x,$y);
118                     break;
119                 
120                 case 'L':
121                     $x = $a[1] + @$this->xx;
122                     $y = $a[2] + @$this->yy;
123                     $pdf->line($c[0]/ 3.543307,$c[1]/ 3.543307,$x/ 3.543307,$y/ 3.543307);
124                     $c = array($x,$y);
125                     break;
126                 default:
127                     break;
128             }
129         }
130                 
131          
132     
133     
134     }
135      
136         
137     
138
139
140     function toColor($color) {
141         if (!$color || ($color == 'none')) {
142             return false;
143         }
144          return array(
145             hexdec(substr($color,1,2)),
146             hexdec(substr($color,3,2)),
147             hexdec(substr($color,5,2)));
148         
149     }
150
151
152
153 }