3 /* code that deals with svg groups
4 it does alot of smart stuff to handle 'dynamic' blocks
9 class XML_SvgToPDF_G extends XML_SvgToPDF_Base
11 var $boundingbox = false; // for repeats...
12 var $settings = array(); // cols/rows..
18 function fromXmlNode($node)
20 // print_r("G:fromXmlNode");
21 parent::fromXmlNode($node);
24 if (empty($this->dynamic)) {
28 $setting_cols = !empty($this->cols) ? $this->cols : '';
29 $setting_rows = !empty($this->rows) ? $this->rows : '';
30 $setting_dynamic = !empty($this->dynamic) ? $this->dynamic : '';
33 'rows' => $setting_rows,
34 'cols' => $setting_cols,
35 'dynamic' => $setting_dynamic
39 //look for the bounding box..
41 //echo "<PRE>";print_r($this->children);exit;
42 foreach(array_keys($this->children) as $k) {
43 if (!is_a($this->children[$k], 'XML_SvgToPDF_Rect')) {
46 if (empty($this->children[$k]->nonprintable) || ($this->children[$k]->nonprintable != 'true')) {
49 // echo "SETTING BOUNDING BOX"; exit;
50 $boundingbox = clone($this->children[$k]);
51 // box will be rendered..
52 $this->children[$k]->style['fill'] = 'none';
53 // unset($this->children[$k]);
59 //echo "<PRE>";print_r($boundingbox ); exit;
61 if(is_string($boundingbox)) {
62 $bits = explode(',', $boundingbox);
63 $boundingbox = (object) array('x'=> $boundingbox[0], 'y'=> $boundingbox[1]);
65 $this->boundingbox = $boundingbox ;
66 $this->settings = $settings;
68 // change the X/Y values of all the child elements..
70 //var_dump($boundingbox);
71 $this->shiftChildren(-1* $this->boundingbox->x,-1 * $this->boundingbox->y);
72 //$this->shiftChildren($this->boundingbox->x,$this->boundingbox->y);
76 // not sure why this is done twice?
78 function fromNode($node) {
79 parent::fromNode($node);
82 //----------- applyDynamic...
85 if (empty($this->children)) {
89 if (empty($this->dynamic)) {
93 'rows' => $this->rows,
94 'cols' => $this->cols,
95 'dynamic' => $this->dynamic
100 //look for the bounding box..
101 $boundingbox = false;
102 foreach(array_keys($this->children) as $k) {
103 if (!is_a($this->children[$k], 'XML_SvgToPDF_Rect')) {
106 if (@$this->children[$k]->nonprintable == 'true') {
107 $boundingbox = clone($this->children[$k]);
108 $this->children[$k]->style['fill'] = 'none';
109 // unset($this->children[$k]);
115 //echo "<PRE>";print_r($boundingbox );
117 $this->boundingbox = $boundingbox ;
118 $this->settings = $settings;
119 $this->shiftChildren($this->boundingbox->x,$this->boundingbox->y);
122 function shift($x,$y) {
124 if ($this->boundingbox) {
128 $this->shiftChildren($x,$y);
134 function writePDF($pdf,$data) {
135 // g group = does it have a
137 if (empty($this->children)) {
141 // not dynamic.. -> just dump..
142 if (empty($this->settings)) {
143 return $this->childrenWritePDF($pdf,$data);
147 if (substr($this->settings['dynamic'],-2,2) == '()') {
149 $use = $data->{substr($this->settings['dynamic'],0,-2)}();
152 $use = empty($data[$this->settings['dynamic']]) ? '' : $data[$this->settings['dynamic']];
159 // if use is a value - make it an array with a single element, so that the bounding box
161 if (!is_array($use)) {
165 // echo "<PRE>";print_r($boundingbox );
168 $this->x = $x = $this->boundingbox->x;
169 $this->y =$y = $this->boundingbox->y;
170 $w = $this->boundingbox->width;
171 $h = $this->boundingbox->height;
174 //echo '<PRE>';print_r($this);exit;
175 // shift... ** this does not handle groups!!!
178 $keys = array_keys($use);
180 $kmax = count($keys);
181 //XML_SvgToPDF::debug(array($x,$y,$w,$h));
182 //XML_SvgToPDF::debug($keys);
183 XML_SvgToPDF::debug($this->settings);
187 for($r=0;$r<$this->settings['rows'];$r++) {
188 $record = $use[$keys[$kpos]];
191 for($c=0;$c<$this->settings['cols'];$c++) {
193 $record = $use[$keys[$kpos]];
196 XML_SvgToPDF::debug(array($xx,$yy));
197 foreach(array_keys($this->children) as $k) {
198 if (!$this->children[$k]) {
202 // if (is_object($use[$keys[$kpos]]) && method_exists($use[$keys[$kpos]], 'loadSvg')) {
203 // // set the defaults, as we cant do it in the thing now..
204 // $use[$keys[$kpos]]->loadSvg();
208 $this->children[$k]->xx = $xx;
209 $this->children[$k]->yy = $yy;
210 $this->children[$k]->maxWidth = $w - 20;
211 $this->children[$k]->writePDF($pdf,$use[$keys[$kpos]]);
214 if ($kpos >= $kmax) {
218 $yy += !empty($record->userows) ? ($record->userows) * $h : $h;