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