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..
14 function fromXmlNode($node)
16 // print_r("G:fromXmlNode");
17 parent::fromXmlNode($node);
20 if (empty($this->dynamic)) {
24 'rows' => $this->rows,
25 'cols' => $this->cols,
26 'dynamic' => $this->dynamic
30 //look for the bounding box..
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')) {
37 if (empty($this->children[$k]->nonprintable) || ($this->children[$k]->nonprintable != 'true')) {
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]);
50 //echo "<PRE>";print_r($boundingbox ); exit;
52 $this->boundingbox = $boundingbox ;
53 $this->settings = $settings;
55 // change the X/Y values of all the child elements..
58 $this->shiftChildren(-1* $this->boundingbox->x,-1 * $this->boundingbox->y);
59 //$this->shiftChildren($this->boundingbox->x,$this->boundingbox->y);
63 // not sure why this is done twice?
65 function fromNode($node) {
66 parent::fromNode($node);
69 //----------- applyDynamic...
72 if (empty($this->children)) {
76 if (empty($this->dynamic)) {
80 'rows' => $this->rows,
81 'cols' => $this->cols,
82 'dynamic' => $this->dynamic
87 //look for the bounding box..
89 foreach(array_keys($this->children) as $k) {
90 if (!is_a($this->children[$k], 'XML_SvgToPDF_Rect')) {
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]);
102 //echo "<PRE>";print_r($boundingbox );
104 $this->boundingbox = $boundingbox ;
105 $this->settings = $settings;
106 $this->shiftChildren($this->boundingbox->x,$this->boundingbox->y);
109 function shift($x,$y) {
111 if ($this->boundingbox) {
115 $this->shiftChildren($x,$y);
121 function writePDF($pdf,$data) {
122 // g group = does it have a
124 if (empty($this->children)) {
128 // not dynamic.. -> just dump..
129 if (empty($this->settings)) {
130 return $this->childrenWritePDF($pdf,$data);
134 if (substr($this->settings['dynamic'],-2,2) == '()') {
136 $use = $data->{substr($this->settings['dynamic'],0,-2)}();
139 $use = empty($data[$this->settings['dynamic']]) ? '' : $data[$this->settings['dynamic']];
146 // if use is a value - make it an array with a single element, so that the bounding box
148 if (!is_array($use)) {
152 // echo "<PRE>";print_r($boundingbox );
155 $this->x = $x = $this->boundingbox->x;
156 $this->y =$y = $this->boundingbox->y;
157 $w = $this->boundingbox->width;
158 $h = $this->boundingbox->height;
161 //echo '<PRE>';print_r($this);exit;
162 // shift... ** this does not handle groups!!!
165 $keys = array_keys($use);
167 $kmax = count($keys);
168 //XML_SvgToPDF::debug(array($x,$y,$w,$h));
169 //XML_SvgToPDF::debug($keys);
170 XML_SvgToPDF::debug($this->settings);
174 for($r=0;$r<$this->settings['rows'];$r++) {
175 $record = $use[$keys[$kpos]];
178 for($c=0;$c<$this->settings['cols'];$c++) {
180 $record = $use[$keys[$kpos]];
183 XML_SvgToPDF::debug(array($xx,$yy));
184 foreach(array_keys($this->children) as $k) {
185 if (!$this->children[$k]) {
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();
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]]);
201 if ($kpos >= $kmax) {
205 $yy += !empty($record->userows) ? ($record->userows) * $h : $h;