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