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..
16 function fromXmlNode($node)
18 // print_r("G:fromXmlNode");
19 parent::fromXmlNode($node);
22 if (empty($this->dynamic)) {
26 'rows' => $this->rows,
27 'cols' => $this->cols,
28 'dynamic' => $this->dynamic
32 //look for the bounding box..
34 //echo "<PRE>";print_r($this->children);exit;
35 foreach(array_keys($this->children) as $k) {
36 if (!is_a($this->children[$k], 'XML_SvgToPDF_Rect')) {
39 if (empty($this->children[$k]->nonprintable) || ($this->children[$k]->nonprintable != 'true')) {
42 // echo "SETTING BOUNDING BOX"; exit;
43 $boundingbox = clone($this->children[$k]);
44 // box will be rendered..
45 $this->children[$k]->style['fill'] = 'none';
46 // unset($this->children[$k]);
52 //echo "<PRE>";print_r($boundingbox ); exit;
54 $this->boundingbox = $boundingbox ;
55 $this->settings = $settings;
57 // change the X/Y values of all the child elements..
60 $this->shiftChildren(-1* $this->boundingbox->x,-1 * $this->boundingbox->y);
61 //$this->shiftChildren($this->boundingbox->x,$this->boundingbox->y);
65 // not sure why this is done twice?
67 function fromNode($node) {
68 parent::fromNode($node);
71 //----------- applyDynamic...
74 if (empty($this->children)) {
78 if (empty($this->dynamic)) {
82 'rows' => $this->rows,
83 'cols' => $this->cols,
84 'dynamic' => $this->dynamic
89 //look for the bounding box..
91 foreach(array_keys($this->children) as $k) {
92 if (!is_a($this->children[$k], 'XML_SvgToPDF_Rect')) {
95 if (@$this->children[$k]->nonprintable == 'true') {
96 $boundingbox = clone($this->children[$k]);
97 $this->children[$k]->style['fill'] = 'none';
98 // unset($this->children[$k]);
104 //echo "<PRE>";print_r($boundingbox );
106 $this->boundingbox = $boundingbox ;
107 $this->settings = $settings;
108 $this->shiftChildren($this->boundingbox->x,$this->boundingbox->y);
111 function shift($x,$y) {
113 if ($this->boundingbox) {
117 $this->shiftChildren($x,$y);
123 function writePDF($pdf,$data) {
124 // g group = does it have a
126 if (empty($this->children)) {
130 // not dynamic.. -> just dump..
131 if (empty($this->settings)) {
132 return $this->childrenWritePDF($pdf,$data);
136 if (substr($this->settings['dynamic'],-2,2) == '()') {
138 $use = $data->{substr($this->settings['dynamic'],0,-2)}();
141 $use = empty($data[$this->settings['dynamic']]) ? '' : $data[$this->settings['dynamic']];
148 // if use is a value - make it an array with a single element, so that the bounding box
150 if (!is_array($use)) {
154 // echo "<PRE>";print_r($boundingbox );
157 $this->x = $x = $this->boundingbox->x;
158 $this->y =$y = $this->boundingbox->y;
159 $w = $this->boundingbox->width;
160 $h = $this->boundingbox->height;
163 //echo '<PRE>';print_r($this);exit;
164 // shift... ** this does not handle groups!!!
167 $keys = array_keys($use);
169 $kmax = count($keys);
170 //XML_SvgToPDF::debug(array($x,$y,$w,$h));
171 //XML_SvgToPDF::debug($keys);
172 XML_SvgToPDF::debug($this->settings);
176 for($r=0;$r<$this->settings['rows'];$r++) {
177 $record = $use[$keys[$kpos]];
180 for($c=0;$c<$this->settings['cols'];$c++) {
182 $record = $use[$keys[$kpos]];
185 XML_SvgToPDF::debug(array($xx,$yy));
186 foreach(array_keys($this->children) as $k) {
187 if (!$this->children[$k]) {
191 // if (is_object($use[$keys[$kpos]]) && method_exists($use[$keys[$kpos]], 'loadSvg')) {
192 // // set the defaults, as we cant do it in the thing now..
193 // $use[$keys[$kpos]]->loadSvg();
197 $this->children[$k]->xx = $xx;
198 $this->children[$k]->yy = $yy;
199 $this->children[$k]->maxWidth = $w - 20;
200 $this->children[$k]->writePDF($pdf,$use[$keys[$kpos]]);
203 if ($kpos >= $kmax) {
207 $yy += !empty($record->userows) ? ($record->userows) * $h : $h;