6886c1d440635687a98f6f417c67ccbcdfdac213
[pear] / XML / SvgToPdf / G.php
1 <?php
2
3 /* code that deals with svg groups
4 it does alot of smart stuff to handle 'dynamic' blocks
5
6 */
7
8
9 class XML_SvgToPDF_G     extends XML_SvgToPDF_Base
10
11     var $boundingbox = false; // for repeats...
12     var $settings = array();  // cols/rows..
13
14     function fromXmlNode($node)
15     {
16        // print_r("G:fromXmlNode");
17         parent::fromXmlNode($node);
18  
19         
20         if (empty($this->dynamic)) {
21             return;
22         }
23         $settings = array(
24             'rows' => $this->rows,
25             'cols' => $this->cols,
26             'dynamic' => $this->dynamic
27         );
28         
29         
30          //look for the bounding box..
31         $boundingbox = false;
32 //echo "<PRE>";print_r($this->children);exit;
33         foreach(array_keys($this->children) as $k) {
34             if (!is_a($this->children[$k], 'XML_SvgToPDF_Rect')) {
35                continue;
36             }
37             if (empty($this->children[$k]->nonprintable) || ($this->children[$k]->nonprintable != 'true')) {
38                 continue;
39             }
40  //           echo "SETTING BOUNDING BOX"; exit; 
41             $boundingbox = clone($this->children[$k]);
42             // box will be rendered..
43             $this->children[$k]->style['fill'] = 'none';
44                // unset($this->children[$k]);
45           
46         }
47         if (!$boundingbox) {
48             return;
49         }
50         //echo "<PRE>";print_r($boundingbox ); exit;
51         
52         $this->boundingbox =  $boundingbox ;
53         $this->settings = $settings;
54         
55         // change the X/Y values of all the child elements..
56          
57         
58         $this->shiftChildren(-1* $this->boundingbox->x,-1 * $this->boundingbox->y);
59         //$this->shiftChildren($this->boundingbox->x,$this->boundingbox->y);
60       
61     }
62
63     // not sure why this is done twice?
64
65     function fromNode($node) {
66         parent::fromNode($node);
67         
68     
69 //----------- applyDynamic...        
70         
71           // look for 
72         if (empty($this->children)) {
73             return;
74         }
75         
76         if (empty($this->dynamic)) {
77             return;
78         }
79         $settings = array(
80             'rows' => $this->rows,
81             'cols' => $this->cols,
82             'dynamic' => $this->dynamic
83         );
84          
85         
86         
87          //look for the bounding box..
88         $boundingbox = false;
89         foreach(array_keys($this->children) as $k) {
90             if (!is_a($this->children[$k], 'XML_SvgToPDF_Rect')) {
91                continue;
92             }
93             if (@$this->children[$k]->nonprintable == 'true') {
94                 $boundingbox = clone($this->children[$k]);
95                 $this->children[$k]->style['fill'] = 'none';
96                // unset($this->children[$k]);
97             }
98         }
99         if (!$boundingbox) {
100             return;
101         }
102         //echo "<PRE>";print_r($boundingbox );
103         
104         $this->boundingbox =  $boundingbox ;
105         $this->settings = $settings;
106         $this->shiftChildren($this->boundingbox->x,$this->boundingbox->y);
107     }
108     
109     function shift($x,$y) {
110         
111         if ($this->boundingbox) {
112             return;
113         }
114         
115         $this->shiftChildren($x,$y);
116     
117     }
118
119
120
121     function writePDF($pdf,$data) {
122         // g group = does it have a 
123         // look for 
124         if (empty($this->children)) {
125             return;
126         }
127          
128         // not dynamic.. -> just dump..
129         if (empty($this->settings)) {
130             return $this->childrenWritePDF($pdf,$data);
131         }
132         
133         $use = false;
134         if (substr($this->settings['dynamic'],-2,2) == '()') {
135         
136             $use = $data->{substr($this->settings['dynamic'],0,-2)}();
137             
138         } else {
139             $use = empty($data[$this->settings['dynamic']]) ? ''  : $data[$this->settings['dynamic']];
140         }
141         
142             
143         if (empty($use)) {
144             return;
145         }
146         // if use is a value  - make it an array with a single element, so that the bounding box
147         // additions apply..
148         if (!is_array($use)) {
149             $use = array($use);
150         }
151         
152         // echo "<PRE>";print_r($boundingbox );
153         
154         
155         $this->x = $x = $this->boundingbox->x;
156         $this->y =$y = $this->boundingbox->y;
157         $w = $this->boundingbox->width;
158         $h = $this->boundingbox->height; 
159         
160         
161         //echo '<PRE>';print_r($this);exit;
162         // shift... ** this does not handle groups!!!
163       
164         //print_R($use);
165         $keys = array_keys($use);
166         $kpos = 0;
167         $kmax = count($keys);
168         //XML_SvgToPDF::debug(array($x,$y,$w,$h));
169         //XML_SvgToPDF::debug($keys);
170         XML_SvgToPDF::debug($this->settings);
171         
172         $yy = $y;
173         
174         for($r=0;$r<$this->settings['rows'];$r++) {
175             $record = $use[$keys[$kpos]];
176             
177             
178             for($c=0;$c<$this->settings['cols'];$c++) {
179                 
180                 $record = $use[$keys[$kpos]];
181                 
182                 $xx = $x + ($c*$w);
183                 XML_SvgToPDF::debug(array($xx,$yy));
184                 foreach(array_keys($this->children) as $k) {
185                     if (!$this->children[$k]) {
186                         continue;
187                     }
188                     
189                    //  if (is_object($use[$keys[$kpos]]) && method_exists($use[$keys[$kpos]], 'loadSvg')) {
190                    //     // set the defaults, as we cant do it in the thing now..
191                    //     $use[$keys[$kpos]]->loadSvg();
192                    // }
193                     
194                     
195                     $this->children[$k]->xx = $xx;
196                     $this->children[$k]->yy = $yy;
197                     $this->children[$k]->maxWidth = $w - 20; 
198                     $this->children[$k]->writePDF($pdf,$use[$keys[$kpos]]);
199                 }
200                 $kpos++;
201                 if ($kpos >= $kmax) {
202                     break 2;
203                 }
204             }
205             $yy += !empty($record->userows) ? ($record->userows) * $h : $h;
206
207             
208         }
209         
210         
211         
212     }
213
214
215
216
217 }