source: trunk/client/modules/Elezioni/grafici/jpgraph_table.php@ 404

Last change on this file since 404 was 266, checked in by roby, 6 years ago
File size: 47.2 KB
RevLine 
[266]1<?php
2/*=======================================================================
3 // File: JPGRAPH_TABLE.PHP
4 // Description: Classes to create basic tables of data
5 // Created: 2006-01-25
6 // Ver: $Id: jpgraph_table.php 1514 2009-07-07 11:15:58Z ljp $
7 //
8 // Copyright (c) Asial Corporation. All rights reserved.
9 //========================================================================
10 */
11
12// Style of grid lines in table
13DEFINE('TGRID_SINGLE',1);
14DEFINE('TGRID_DOUBLE',2);
15DEFINE('TGRID_DOUBLE2',3);
16
17// Type of constrain for image constrain
18DEFINE('TIMG_WIDTH',1);
19DEFINE('TIMG_HEIGHT',2);
20
21//---------------------------------------------------------------------
22// CLASS GTextTableCell
23// Description:
24// Internal class that represents each cell in the table
25//---------------------------------------------------------------------
26class GTextTableCell {
27 public $iColSpan=1,$iRowSpan=1;
28 public $iMarginLeft=5,$iMarginRight=5,$iMarginTop=5,$iMarginBottom=5;
29 public $iVal=NULL;
30 private $iBGColor='', $iFontColor='black';
31 private $iFF=FF_FONT1,$iFS=FS_NORMAL,$iFSize=10;
32 private $iRow=0, $iCol=0;
33 private $iVertAlign = 'bottom', $iHorAlign = 'left';
34 private $iMerged=FALSE,$iPRow=NULL,$iPCol=NULL;
35 private $iTable=NULL;
36 private $iGridColor=array('darkgray','darkgray','darkgray','darkgray');
37 private $iGridWeight=array(1,1,0,0); // left,top,bottom,right;
38 private $iGridStyle=array(TGRID_SINGLE,TGRID_SINGLE,TGRID_SINGLE,TGRID_SINGLE); // left,top,bottom,right;
39 private $iNumberFormat=null;
40 private $iIcon=null, $iIconConstrain=array();
41 private $iCSIMtarget = '',$iCSIMwintarget = '', $iCSIMalt = '', $iCSIMArea = '';
42
43 function __construct($aVal='',$aRow=0,$aCol=0) {
44 $this->iVal = new Text($aVal);
45 $this->iRow = $aRow;
46 $this->iCol = $aCol;
47 $this->iPRow = $aRow; // Initialiy each cell is its own parent
48 $this->iPCol = $aCol;
49 $this->iIconConstrain = array(-1,-1);
50 }
51
52 function Init($aTable) {
53 $this->iTable = $aTable;
54 }
55
56 function SetCSIMTarget($aTarget,$aAlt='',$aWinTarget='') {
57 $this->iCSIMtarget = $aTarget;
58 $this->iCSIMwintarget = $aWinTarget;
59 $this->iCSIMalt = $aAlt;
60 }
61
62 function GetCSIMArea() {
63 if( $this->iCSIMtarget !== '' )
64 return $this->iCSIMArea;
65 else
66 return '';
67 }
68
69 function SetImageConstrain($aType,$aVal) {
70 if( !in_array($aType,array(TIMG_WIDTH, TIMG_HEIGHT)) ) {
71 JpGraphError::RaiseL(27015);
72 }
73 $this->iIconConstrain = array($aType,$aVal);
74 }
75
76 function SetCountryFlag($aFlag,$aScale=1.0,$aMix=100,$aStdSize=3) {
77 $this->iIcon = new IconPlot();
78 $this->iIcon->SetCountryFlag($aFlag,0,0,$aScale,$aMix,$aStdSize);
79 }
80
81 function SetImage($aFile,$aScale=1.0,$aMix=100) {
82 $this->iIcon = new IconPlot($aFile,0,0,$aScale,$aMix);
83 }
84
85 function SetImageFromString($aStr,$aScale=1.0,$aMix=100) {
86 $this->iIcon = new IconPlot("",0,0,$aScale,$aMix);
87 $this->iIcon->CreateFromString($aStr);
88 }
89
90 function SetRowColSpan($aRowSpan,$aColSpan) {
91 $this->iRowSpan = $aRowSpan;
92 $this->iColSpan = $aColSpan;
93 $this->iMerged = true;
94 }
95
96 function SetMerged($aPRow,$aPCol,$aFlg=true) {
97 $this->iMerged = $aFlg;
98 $this->iPRow=$aPRow;
99 $this->iPCol=$aPCol;
100 }
101
102 function IsMerged() {
103 return $this->iMerged;
104 }
105
106 function SetNumberFormat($aF) {
107 $this->iNumberFormat = $aF;
108 }
109
110 function Set($aTxt) {
111 $this->iVal->Set($aTxt);
112 }
113
114 function SetFont($aFF,$aFS,$aFSize) {
115 $this->iFF = $aFF;
116 $this->iFS = $aFS;
117 $this->iFSize = $aFSize;
118 $this->iVal->SetFont($aFF,$aFS,$aFSize);
119 }
120
121 function SetFillColor($aColor) {
122 $this->iBGColor=$aColor;
123 }
124
125 function SetFontColor($aColor) {
126 $this->iFontColor=$aColor;
127 }
128
129 function SetGridColor($aLeft,$aTop=null,$aBottom=null,$aRight=null) {
130 if( $aLeft !== null ) $this->iGridColor[0] = $aLeft;
131 if( $aTop !== null ) $this->iGridColor[1] = $aTop;
132 if( $aBottom !== null ) $this->iGridColor[2] = $aBottom;
133 if( $aRight !== null )$this->iGridColor[3] = $aRight;
134 }
135
136 function SetGridStyle($aLeft,$aTop=null,$aBottom=null,$aRight=null) {
137 if( $aLeft !== null ) $this->iGridStyle[0] = $aLeft;
138 if( $aTop !== null ) $this->iGridStyle[1] = $aTop;
139 if( $aBottom !== null ) $this->iGridStyle[2] = $aBottom;
140 if( $aRight !== null )$this->iGridStyle[3] = $aRight;
141 }
142
143 function SetGridWeight($aLeft=null,$aTop=null,$aBottom=null,$aRight=null) {
144 $weight_arr = array($aLeft, $aTop, $aBottom, $aRight);
145 for ($i = 0; $i < count($weight_arr); $i++) {
146 if ($weight_arr[$i] === "") {
147 $weight_arr[$i] = 0;
148 }
149 }
150 if( $aLeft !== null ) $this->iGridWeight[0] = $weight_arr[0];
151 if( $aTop !== null ) $this->iGridWeight[1] = $weight_arr[1];
152 if( $aBottom !== null ) $this->iGridWeight[2] = $weight_arr[2];
153 if( $aRight !== null ) $this->iGridWeight[3] = $weight_arr[3];
154 }
155
156 function SetMargin($aLeft,$aRight,$aTop,$aBottom) {
157 $this->iMarginLeft=$aLeft;
158 $this->iMarginRight=$aRight;
159 $this->iMarginTop=$aTop;
160 $this->iMarginBottom=$aBottom;
161 }
162
163 function GetWidth($aImg) {
164 if( $this->iIcon !== null ) {
165 if( $this->iIconConstrain[0] == TIMG_WIDTH ) {
166 $this->iIcon->SetScale(1);
167 $tmp = $this->iIcon->GetWidthHeight();
168 $this->iIcon->SetScale($this->iIconConstrain[1]/$tmp[0]);
169 }
170 elseif( $this->iIconConstrain[0] == TIMG_HEIGHT ) {
171 $this->iIcon->SetScale(1);
172 $tmp = $this->iIcon->GetWidthHeight();
173 $this->iIcon->SetScale($this->iIconConstrain[1]/$tmp[1]);
174 }
175 $tmp = $this->iIcon->GetWidthHeight();
176 $iwidth = $tmp[0];
177 }
178 else {
179 $iwidth=0;
180 }
181 if( $this->iTable->iCells[$this->iPRow][$this->iPCol]->iVal->dir == 0 ) {
182 $pwidth = $this->iTable->iCells[$this->iPRow][$this->iPCol]->iVal->GetWidth($aImg);
183 }
184 elseif( $this->iTable->iCells[$this->iPRow][$this->iPCol]->iVal->dir == 90 ) {
185 $pwidth = $this->iTable->iCells[$this->iPRow][$this->iPCol]->iVal->GetFontHeight($aImg)+2;
186 }
187 else {
188 $pwidth = $this->iTable->iCells[$this->iPRow][$this->iPCol]->iVal->GetWidth($aImg)+2;
189 }
190
191 $pcolspan = $this->iTable->iCells[$this->iPRow][$this->iPCol]->iColSpan;
192 return round(max($iwidth,$pwidth)/$pcolspan) + $this->iMarginLeft + $this->iMarginRight;
193 }
194
195 function GetHeight($aImg) {
196 if( $this->iIcon !== null ) {
197 if( $this->iIconConstrain[0] == TIMG_WIDTH ) {
198 $this->iIcon->SetScale(1);
199 $tmp = $this->iIcon->GetWidthHeight();
200 $this->iIcon->SetScale($this->iIconConstrain[1]/$tmp[0]);
201 }
202 elseif( $this->iIconConstrain[0] == TIMG_HEIGHT ) {
203 $this->iIcon->SetScale(1);
204 $tmp = $this->iIcon->GetWidthHeight();
205 $this->iIcon->SetScale($this->iIconConstrain[1]/$tmp[1]);
206 }
207 $tmp = $this->iIcon->GetWidthHeight();
208 $iheight = $tmp[1];
209 }
210 else {
211 $iheight = 0;
212 }
213 if( $this->iTable->iCells[$this->iPRow][$this->iPCol]->iVal->dir == 0 ) {
214 $pheight = $this->iTable->iCells[$this->iPRow][$this->iPCol]->iVal->GetHeight($aImg);
215 }
216 else {
217 $pheight = $this->iTable->iCells[$this->iPRow][$this->iPCol]->iVal->GetHeight($aImg)+1;
218 }
219 $prowspan = $this->iTable->iCells[$this->iPRow][$this->iPCol]->iRowSpan;
220 return round(max($iheight,$pheight)/$prowspan) + $this->iMarginTop + $this->iMarginBottom;
221 }
222
223 function SetAlign($aHorAlign='left',$aVertAlign='bottom') {
224 $aHorAlign = strtolower($aHorAlign);
225 $aVertAlign = strtolower($aVertAlign);
226 $chk = array('left','right','center','bottom','top','middle');
227 if( !in_array($aHorAlign,$chk) || !in_array($aVertAlign,$chk) ) {
228 JpGraphError::RaiseL(27011,$aHorAlign,$aVertAlign);
229 }
230 $this->iVertAlign = $aVertAlign;
231 $this->iHorAlign = $aHorAlign;
232 }
233
234 function AdjustMarginsForGrid() {
235 if( $this->iCol > 0 ) {
236 switch( $this->iGridStyle[0] ) {
237 case TGRID_SINGLE: $wf=1; break;
238 case TGRID_DOUBLE: $wf=3; break;
239 case TGRID_DOUBLE2: $wf=4; break;
240 }
241 $this->iMarginLeft += $this->iGridWeight[0]*$wf;
242 }
243 if( $this->iRow > 0 ) {
244 switch( $this->iGridStyle[1] ) {
245 case TGRID_SINGLE: $wf=1; break;
246 case TGRID_DOUBLE: $wf=3; break;
247 case TGRID_DOUBLE2: $wf=4; break;
248 }
249 $this->iMarginTop += $this->iGridWeight[1]*$wf;
250 }
251 if( $this->iRow+$this->iRowSpan-1 < $this->iTable->iSize[0]-1 ) {
252 switch( $this->iGridStyle[2] ) {
253 case TGRID_SINGLE: $wf=1; break;
254 case TGRID_DOUBLE: $wf=3; break;
255 case TGRID_DOUBLE2: $wf=4; break;
256 }
257 $this->iMarginBottom += $this->iGridWeight[2]*$wf;
258 }
259 if( $this->iCol+$this->iColSpan-1 < $this->iTable->iSize[1]-1 ) {
260 switch( $this->iGridStyle[3] ) {
261 case TGRID_SINGLE: $wf=1; break;
262 case TGRID_DOUBLE: $wf=3; break;
263 case TGRID_DOUBLE2: $wf=4; break;
264 }
265 $this->iMarginRight += $this->iGridWeight[3]*$wf;
266 }
267 }
268
269 function StrokeVGrid($aImg,$aX,$aY,$aWidth,$aHeight,$aDir=1) {
270 // Left or right grid line
271 // For the right we increase the X-pos and for the right we decrease it. This is
272 // determined by the direction argument.
273 $idx = $aDir==1 ? 0 : 3;
274
275 // We don't stroke the grid lines that are on the edge of the table since this is
276 // the place of the border.
277 if( ( ($this->iCol > 0 && $idx==0) || ($this->iCol+$this->iColSpan-1 < $this->iTable->iSize[1]-1 && $idx==3) )
278 && $this->iGridWeight[$idx] > 0 ) {
279 $x = $aDir==1 ? $aX : $aX + $aWidth-1;
280 $y = $aY+$aHeight-1;
281 $aImg->SetColor($this->iGridColor[$idx]);
282 switch( $this->iGridStyle[$idx] ) {
283 case TGRID_SINGLE:
284 for( $i=0; $i < $this->iGridWeight[$idx]; ++$i )
285 $aImg->Line($x+$i*$aDir,$aY, $x+$i*$aDir,$y);
286 break;
287
288 case TGRID_DOUBLE:
289 for( $i=0; $i < $this->iGridWeight[$idx]; ++$i )
290 $aImg->Line($x+$i*$aDir,$aY, $x+$i*$aDir,$y);
291 $x += $this->iGridWeight[$idx]*2;
292 for( $i=0; $i < $this->iGridWeight[$idx]; ++$i )
293 $aImg->Line($x+$i*$aDir,$aY, $x+$i*$aDir,$y);
294 break;
295
296 case TGRID_DOUBLE2:
297 for( $i=0; $i < $this->iGridWeight[$idx]*2; ++$i )
298 $aImg->Line($x+$i*$aDir,$aY,$x+$i*$aDir,$y);
299 $x += $this->iGridWeight[$idx]*3;
300 for( $i=0; $i < $this->iGridWeight[$idx]; ++$i )
301 $aImg->Line($x+$i*$aDir,$aY, $x+$i*$aDir,$y);
302 break;
303 }
304 }
305 }
306
307 function StrokeHGrid($aImg,$aX,$aY,$aWidth,$aHeight,$aDir=1) {
308 // Top or bottom grid line
309 // For the left we increase the X-pos and for the right we decrease it. This is
310 // determined by the direction argument.
311 $idx = $aDir==1 ? 1 : 2;
312
313 // We don't stroke the grid lines that are on the edge of the table since this is
314 // the place of the border.
315 if( ( ($this->iRow > 0 && $idx==1) || ($this->iRow+$this->iRowSpan-1 < $this->iTable->iSize[0]-1 && $idx==2) )
316 && $this->iGridWeight[$idx] > 0) {
317 $y = $aDir==1 ? $aY : $aY+$aHeight-1;
318 $x = $aX+$aWidth-1;
319 $aImg->SetColor($this->iGridColor[$idx]);
320 switch( $this->iGridStyle[$idx] ) {
321 case TGRID_SINGLE:
322 for( $i=0; $i < $this->iGridWeight[$idx]; ++$i )
323 $aImg->Line($aX,$y+$i, $x,$y+$i);
324 break;
325
326 case TGRID_DOUBLE:
327 for( $i=0; $i < $this->iGridWeight[$idx]; ++$i )
328 $aImg->Line($aX,$y+$i, $x,$y+$i);
329 $y += $this->iGridWeight[$idx]*2;
330 for( $i=0; $i < $this->iGridWeight[$idx]; ++$i )
331 $aImg->Line($aX,$y+$i, $x,$y+$i);
332 break;
333
334 case TGRID_DOUBLE2:
335 for( $i=0; $i < $this->iGridWeight[$idx]*2; ++$i )
336 $aImg->Line($aX,$y+$i, $x,$y+$i);
337 $y += $this->iGridWeight[$idx]*3;
338 for( $i=0; $i < $this->iGridWeight[$idx]; ++$i )
339 $aImg->Line($aX,$y+$i, $x,$y+$i);
340 break;
341 }
342 }
343 }
344
345 function Stroke($aImg,$aX,$aY,$aWidth,$aHeight) {
346 // If this is a merged cell we only stroke if it is the parent cell.
347 // The parent cell holds the merged cell block
348 if( $this->iMerged && ($this->iRow != $this->iPRow || $this->iCol != $this->iPCol) ) {
349 return;
350 }
351
352 if( $this->iBGColor != '' ) {
353 $aImg->SetColor($this->iBGColor);
354 $aImg->FilledRectangle($aX,$aY,$aX+$aWidth-1,$aY+$aHeight-1);
355 }
356
357 $coords = $aX.','.$aY.','.($aX+$aWidth-1).','.$aY.','.($aX+$aWidth-1).','.($aY+$aHeight-1).','.$aX.','.($aY+$aHeight-1);
358 if( ! empty($this->iCSIMtarget) ) {
359 $this->iCSIMArea = '<area shape="poly" coords="'.$coords.'" href="'.$this->iCSIMtarget.'"';
360 if( ! empty($this->iCSIMwintarget) ) {
361 $this->iCSIMArea .= " target=\"".$this->iCSIMwintarget."\"";
362 }
363 if( ! empty($this->iCSIMalt) ) {
364 $this->iCSIMArea .= ' alt="'.$this->iCSIMalt.'" title="'.$this->iCSIMalt."\" ";
365 }
366 $this->iCSIMArea .= " />\n";
367 }
368
369 $this->StrokeVGrid($aImg,$aX,$aY,$aWidth,$aHeight);
370 $this->StrokeVGrid($aImg,$aX,$aY,$aWidth,$aHeight,-1);
371 $this->StrokeHGrid($aImg,$aX,$aY,$aWidth,$aHeight);
372 $this->StrokeHGrid($aImg,$aX,$aY,$aWidth,$aHeight,-1);
373
374 if( $this->iIcon !== null ) {
375 switch( $this->iHorAlign ) {
376 case 'left':
377 $x = $aX+$this->iMarginLeft;
378 $hanchor='left';
379 break;
380 case 'center':
381 case 'middle':
382 $x = $aX+$this->iMarginLeft+round(($aWidth-$this->iMarginLeft-$this->iMarginRight)/2);
383 $hanchor='center';
384 break;
385 case 'right':
386 $x = $aX+$aWidth-$this->iMarginRight-1;
387 $hanchor='right';
388 break;
389 default:
390 JpGraphError::RaiseL(27012,$this->iHorAlign);
391 }
392
393 switch( $this->iVertAlign ) {
394 case 'top':
395 $y = $aY+$this->iMarginTop;
396 $vanchor='top';
397 break;
398 case 'center':
399 case 'middle':
400 $y = $aY+$this->iMarginTop+round(($aHeight-$this->iMarginTop-$this->iMarginBottom)/2);
401 $vanchor='center';
402 break;
403 case 'bottom':
404 $y = $aY+$aHeight-1-$this->iMarginBottom;
405 $vanchor='bottom';
406 break;
407 default:
408 JpGraphError::RaiseL(27012,$this->iVertAlign);
409 }
410 $this->iIcon->SetAnchor($hanchor,$vanchor);
411 $this->iIcon->_Stroke($aImg,$x,$y);
412 }
413 $this->iVal->SetColor($this->iFontColor);
414 $this->iVal->SetFont($this->iFF,$this->iFS,$this->iFSize);
415 switch( $this->iHorAlign ) {
416 case 'left':
417 $x = $aX+$this->iMarginLeft;
418 break;
419 case 'center':
420 case 'middle':
421 $x = $aX+$this->iMarginLeft+round(($aWidth-$this->iMarginLeft-$this->iMarginRight)/2);
422 break;
423 case 'right':
424 $x = $aX+$aWidth-$this->iMarginRight-1;
425 break;
426 default:
427 JpGraphError::RaiseL(27012,$this->iHorAlign);
428 }
429 // A workaround for the shortcomings in the TTF font handling in GD
430 // The anchor position for rotated text (=90) is to "short" so we add
431 // an offset based on the actual font size
432 if( $this->iVal->dir != 0 && $this->iVal->font_family >= 10 ) {
433 $aY += 4 + round($this->iVal->font_size*0.8);
434 }
435 switch( $this->iVertAlign ) {
436 case 'top':
437 $y = $aY+$this->iMarginTop;
438 break;
439 case 'center':
440 case 'middle':
441 $y = $aY+$this->iMarginTop+round(($aHeight-$this->iMarginTop-$this->iMarginBottom)/2);
442 //$y -= round($this->iVal->GetFontHeight($aImg)/2);
443 $y -= round($this->iVal->GetHeight($aImg)/2);
444 break;
445 case 'bottom':
446 //$y = $aY+$aHeight-1-$this->iMarginBottom-$this->iVal->GetFontHeight($aImg);
447 $y = $aY+$aHeight-$this->iMarginBottom-$this->iVal->GetHeight($aImg);
448 break;
449 default:
450 JpGraphError::RaiseL(27012,$this->iVertAlign);
451 }
452 $this->iVal->SetAlign($this->iHorAlign,'top');
453 if( $this->iNumberFormat !== null && is_numeric($this->iVal->t) ) {
454 $this->iVal->t = sprintf($this->iNumberFormat,$this->iVal->t);
455 }
456 $this->iVal->Stroke($aImg,$x,$y);
457 }
458}
459
460//---------------------------------------------------------------------
461// CLASS GTextTable
462// Description:
463// Graphic text table
464//---------------------------------------------------------------------
465class GTextTable {
466 public $iCells = array(), $iSize=array(0,0); // Need to be public since they are used by the cell
467 private $iWidth=0, $iHeight=0;
468 private $iColWidth=NULL,$iRowHeight=NULL;
469 private $iImg=NULL;
470 private $iXPos=0, $iYPos=0;
471 private $iScaleXPos=null,$iScaleYPos=null;
472 private $iBGColor='';
473 private $iBorderColor='black',$iBorderWeight=1;
474 private $iInit=false;
475 private $iYAnchor='top',$iXAnchor='left';
476 /*-----------------------------------------------------------------
477 * First and second phase constructors
478 *-----------------------------------------------------------------
479 */
480 function __construct() {
481 // Empty
482 }
483
484 function Init($aRows=0,$aCols=0,$aFillText='') {
485 $this->iSize[0] = $aRows;
486 $this->iSize[1] = $aCols;
487 for($i=0; $i < $this->iSize[0]; ++$i) {
488 for($j=0; $j < $this->iSize[1]; ++$j) {
489 $this->iCells[$i][$j] = new GTextTableCell($aFillText,$i,$j);
490 $this->iCells[$i][$j]->Init($this);
491 }
492 }
493 $this->iInit=true;
494 }
495
496 /*-----------------------------------------------------------------
497 * Outer border of table
498 *-----------------------------------------------------------------
499 */
500 function SetBorder($aWeight=1,$aColor='black') {
501 $this->iBorderColor=$aColor;
502 $this->iBorderWeight = $aWeight;
503 }
504
505
506 /*-----------------------------------------------------------------
507 * Position in graph of table
508 *-----------------------------------------------------------------
509 */
510 function SetPos($aX,$aY) {
511 $this->iXPos = $aX;
512 $this->iYPos = $aY;
513 }
514
515 function SetScalePos($aX,$aY) {
516 $this->iScaleXPos = $aX;
517 $this->iScaleYPos = $aY;
518 }
519
520 function SetAnchorPos($aXAnchor,$aYAnchor='top') {
521 $this->iXAnchor = $aXAnchor;
522 $this->iYAnchor = $aYAnchor;
523 }
524
525 /*-----------------------------------------------------------------
526 * Setup country flag in a cell
527 *-----------------------------------------------------------------
528 */
529 function SetCellCountryFlag($aRow,$aCol,$aFlag,$aScale=1.0,$aMix=100,$aStdSize=3) {
530 $this->_chkR($aRow);
531 $this->_chkC($aCol);
532 $this->iCells[$aRow][$aCol]->SetCountryFlag($aFlag,$aScale,$aMix,$aStdSize);
533
534 }
535
536 /*-----------------------------------------------------------------
537 * Setup image in a cell
538 *-----------------------------------------------------------------
539 */
540 function SetCellImage($aRow,$aCol,$aFile,$aScale=1.0,$aMix=100) {
541 $this->_chkR($aRow);
542 $this->_chkC($aCol);
543 $this->iCells[$aRow][$aCol]->SetImage($aFile,$aScale,$aMix);
544 }
545
546 function SetRowImage($aRow,$aFile,$aScale=1.0,$aMix=100) {
547 $this->_chkR($aRow);
548 for($j=0; $j < $this->iSize[1]; ++$j) {
549 $this->iCells[$aRow][$j]->SetImage($aFile,$aScale,$aMix);
550 }
551 }
552
553 function SetColImage($aCol,$aFile,$aScale=1.0,$aMix=100) {
554 $this->_chkC($aCol);
555 for($j=0; $j < $this->iSize[0]; ++$j) {
556 $this->iCells[$j][$aCol]->SetImage($aFile,$aScale,$aMix);
557 }
558 }
559
560 function SetImage($aFileR1,$aScaleC1=null,$aMixR2=null,$aC2=null,$aFile=null,$aScale=1.0,$aMix=100) {
561 if( $aScaleC1 !== null && $aMixR2!==null && $aC2!==null && $aFile!==null ) {
562 $this->_chkR($aArgR1); $this->_chkC($aC1);
563 $this->_chkR($aR2); $this->_chkC($aC2);
564 }
565 else {
566 if( $aScaleC1 !== null ) $aScale = $aScaleC1;
567 if( $aMixR2 !== null ) $aMix = $aMixR2;
568 $aFile = $aFileR1;
569 $aMixR2 = $this->iSize[0]-1; $aFileR1 = 0;
570 $aC2 = $this->iSize[1]-1; $aScaleC1 = 0;
571 }
572 for($i=$aArgR1; $i <= $aR2; ++$i) {
573 for($j=$aC1; $j <= $aC2; ++$j) {
574 $this->iCells[$i][$j]->SetImage($aFile,$aScale,$aMix);
575 }
576 }
577 }
578
579 function SetCellImageConstrain($aRow,$aCol,$aType,$aVal) {
580 $this->_chkR($aRow);
581 $this->_chkC($aCol);
582 $this->iCells[$aRow][$aCol]->SetImageConstrain($aType,$aVal);
583 }
584
585 /*-----------------------------------------------------------------
586 * Generate a HTML version of the table
587 *-----------------------------------------------------------------
588 */
589 function toString() {
590 $t = '<table border=1 cellspacing=0 cellpadding=0>';
591 for($i=0; $i < $this->iSize[0]; ++$i) {
592 $t .= '<tr>';
593 for($j=0; $j < $this->iSize[1]; ++$j) {
594 $t .= '<td>';
595 if( $this->iCells[$i][$j]->iMerged )
596 $t .= 'M ';
597 $t .= 'val='.$this->iCells[$i][$j]->iVal->t;
598 $t .= ' (cs='.$this->iCells[$i][$j]->iColSpan.
599 ', rs='.$this->iCells[$i][$j]->iRowSpan.')';
600 $t .= '</td>';
601 }
602 $t .= '</tr>';
603 }
604 $t .= '</table>';
605 return $t;
606 }
607
608 /*-----------------------------------------------------------------
609 * Specify data for table
610 *-----------------------------------------------------------------
611 */
612 function Set($aArg1,$aArg2=NULL,$aArg3=NULL) {
613 if( $aArg2===NULL && $aArg3===NULL ) {
614 if( is_array($aArg1) ) {
615 if( is_array($aArg1[0]) ) {
616 $m = count($aArg1);
617 // Find the longest row
618 $n=0;
619 for($i=0; $i < $m; ++$i)
620 $n = max(count($aArg1[$i]),$n);
621 for($i=0; $i < $m; ++$i) {
622 for($j=0; $j < $n; ++$j) {
623 if( isset($aArg1[$i][$j]) ){
624 $this->_setcell($i,$j,(string)$aArg1[$i][$j]);
625 }
626 else {
627 $this->_setcell($i,$j);
628 }
629 }
630 }
631 $this->iSize[0] = $m;
632 $this->iSize[1] = $n;
633 $this->iInit=true;
634 }
635 else {
636 JpGraphError::RaiseL(27001);
637 //('Illegal argument to GTextTable::Set(). Array must be 2 dimensional');
638 }
639 }
640 else {
641 JpGraphError::RaiseL(27002);
642 //('Illegal argument to GTextTable::Set()');
643 }
644 }
645 else {
646 // Must be in the form (row,col,val)
647 $this->_chkR($aArg1);
648 $this->_chkC($aArg2);
649 $this->_setcell($aArg1,$aArg2,(string)$aArg3);
650 }
651 }
652
653 /*---------------------------------------------------------------------
654 * Cell margin setting
655 *---------------------------------------------------------------------
656 */
657 function SetPadding($aArgR1,$aC1=null,$aR2=null,$aC2=null,$aPad=null) {
658 if( $aC1 !== null && $aR2!==null && $aC2!==null && $aPad!==null ) {
659 $this->_chkR($aArgR1); $this->_chkC($aC1);
660 $this->_chkR($aR2); $this->_chkC($aC2);
661 }
662 else {
663 $aPad = $aArgR1;
664 $aR2 = $this->iSize[0]-1; $aArgR1 = 0;
665 $aC2 = $this->iSize[1]-1; $aC1 = 0;
666 }
667 for($i=$aArgR1; $i <= $aR2; ++$i) {
668 for($j=$aC1; $j <= $aC2; ++$j) {
669 $this->iCells[$i][$j]->SetMargin($aPad,$aPad,$aPad,$aPad);
670 }
671 }
672 }
673
674 function SetRowPadding($aRow,$aPad) {
675 $this->_chkR($aRow);
676 for($j=0; $j < $this->iSize[1]; ++$j) {
677 $this->iCells[$aRow][$j]->SetMargin($aPad,$aPad,$aPad,$aPad);
678 }
679 }
680
681 function SetColPadding($aCol,$aPad) {
682 $this->_chkC($aCol);
683 for($j=0; $j < $this->iSize[0]; ++$j) {
684 $this->iCells[$j][$aCol]->SetMargin($aPad,$aPad,$aPad,$aPad);
685 }
686 }
687
688 function SetCellPadding($aRow,$aCol,$aPad) {
689 $this->_chkR($aRow);
690 $this->_chkC($aCol);
691 $this->iCells[$aRow][$aCol]->SetMargin($aPad,$aPad,$aPad,$aPad);
692 }
693
694
695 /*---------------------------------------------------------------------
696 * Cell text orientation setting
697 *---------------------------------------------------------------------
698 */
699 function SetTextOrientation($aArgR1,$aC1=null,$aR2=null,$aC2=null,$aO=null) {
700 if( $aC1 !== null && $aR2!==null && $aC2!==null && $aPad!==null ) {
701 $this->_chkR($aArgR1); $this->_chkC($aC1);
702 $this->_chkR($aR2); $this->_chkC($aC2);
703 }
704 else {
705 $aO = $aArgR1;
706 $aR2 = $this->iSize[0]-1; $aArgR1 = 0;
707 $aC2 = $this->iSize[1]-1; $aC1 = 0;
708 }
709 for($i=$aArgR1; $i <= $aR2; ++$i) {
710 for($j=$aC1; $j <= $aC2; ++$j) {
711 $this->iCells[$i][$j]->iVal->SetOrientation($aO);
712 }
713 }
714 }
715
716 function SetRowTextOrientation($aRow,$aO) {
717 $this->_chkR($aRow);
718 for($j=0; $j < $this->iSize[1]; ++$j) {
719 $this->iCells[$aRow][$j]->iVal->SetOrientation($aO);
720 }
721 }
722
723 function SetColTextOrientation($aCol,$aO) {
724 $this->_chkC($aCol);
725 for($j=0; $j < $this->iSize[0]; ++$j) {
726 $this->iCells[$j][$aCol]->iVal->SetOrientation($aO);
727 }
728 }
729
730 function SetCellTextOrientation($aRow,$aCol,$aO) {
731 $this->_chkR($aRow);
732 $this->_chkC($aCol);
733 $this->iCells[$aRow][$aCol]->iVal->SetOrientation($aO);
734 }
735
736
737
738
739 /*---------------------------------------------------------------------
740 * Font color setting
741 *---------------------------------------------------------------------
742 */
743
744 function SetColor($aArgR1,$aC1=null,$aR2=null,$aC2=null,$aArg=null) {
745 if( $aC1 !== null && $aR2!==null && $aC2!==null && $aArg!==null ) {
746 $this->_chkR($aArgR1); $this->_chkC($aC1);
747 $this->_chkR($aR2); $this->_chkC($aC2);
748 }
749 else {
750 $aArg = $aArgR1;
751 $aR2 = $this->iSize[0]-1; $aArgR1 = 0;
752 $aC2 = $this->iSize[1]-1; $aC1 = 0;
753 }
754 for($i=$aArgR1; $i <= $aR2; ++$i) {
755 for($j=$aC1; $j <= $aC2; ++$j) {
756 $this->iCells[$i][$j]->SetFontColor($aArg);
757 }
758 }
759 }
760
761 function SetRowColor($aRow,$aColor) {
762 $this->_chkR($aRow);
763 for($j=0; $j < $this->iSize[1]; ++$j) {
764 $this->iCells[$aRow][$j]->SetFontColor($aColor);
765 }
766 }
767
768 function SetColColor($aCol,$aColor) {
769 $this->_chkC($aCol);
770 for($i=0; $i < $this->iSize[0]; ++$i) {
771 $this->iCells[$i][$aCol]->SetFontColor($aColor);
772 }
773 }
774
775 function SetCellColor($aRow,$aCol,$aColor) {
776 $this->_chkR($aRow);
777 $this->_chkC($aCol);
778 $this->iCells[$aRow][$aCol]->SetFontColor($aColor);
779 }
780
781 /*---------------------------------------------------------------------
782 * Fill color settings
783 *---------------------------------------------------------------------
784 */
785
786 function SetFillColor($aArgR1,$aC1=null,$aR2=null,$aC2=null,$aArg=null) {
787 if( $aC1 !== null && $aR2!==null && $aC2!==null && $aArg!==null ) {
788 $this->_chkR($aArgR1); $this->_chkC($aC1);
789 $this->_chkR($aR2); $this->_chkC($aC2);
790 for($i=$aArgR1; $i <= $aR2; ++$i) {
791 for($j=$aC1; $j <= $aC2; ++$j) {
792 $this->iCells[$i][$j]->SetFillColor($aArg);
793 }
794 }
795 }
796 else {
797 $this->iBGColor = $aArgR1;
798 }
799 }
800
801 function SetRowFillColor($aRow,$aColor) {
802 $this->_chkR($aRow);
803 for($j=0; $j < $this->iSize[1]; ++$j) {
804 $this->iCells[$aRow][$j]->SetFillColor($aColor);
805 }
806 }
807
808 function SetColFillColor($aCol,$aColor) {
809 $this->_chkC($aCol);
810 for($i=0; $i < $this->iSize[0]; ++$i) {
811 $this->iCells[$i][$aCol]->SetFillColor($aColor);
812 }
813 }
814
815 function SetCellFillColor($aRow,$aCol,$aColor) {
816 $this->_chkR($aRow);
817 $this->_chkC($aCol);
818 $this->iCells[$aRow][$aCol]->SetFillColor($aColor);
819 }
820
821 /*---------------------------------------------------------------------
822 * Font family setting
823 *---------------------------------------------------------------------
824 */
825 function SetFont() {
826 $numargs = func_num_args();
827 if( $numargs == 2 || $numargs == 3 ) {
828 $aFF = func_get_arg(0);
829 $aFS = func_get_arg(1);
830 if( $numargs == 3 )
831 $aFSize=func_get_arg(2);
832 else
833 $aFSize=10;
834 $aR2 = $this->iSize[0]-1; $aR1 = 0;
835 $aC2 = $this->iSize[1]-1; $aC1 = 0;
836
837 }
838 elseif($numargs == 6 || $numargs == 7 ) {
839 $aR1 = func_get_arg(0); $aC1 = func_get_arg(1);
840 $aR2 = func_get_arg(2); $aC2 = func_get_arg(3);
841 $aFF = func_get_arg(4); $aFS = func_get_arg(5);
842 if( $numargs == 7 )
843 $aFSize=func_get_arg(6);
844 else
845 $aFSize=10;
846 }
847 else {
848 JpGraphError::RaiseL(27003);
849 //('Wrong number of arguments to GTextTable::SetColor()');
850 }
851 $this->_chkR($aR1); $this->_chkC($aC1);
852 $this->_chkR($aR2); $this->_chkC($aC2);
853 for($i=$aR1; $i <= $aR2; ++$i) {
854 for($j=$aC1; $j <= $aC2; ++$j) {
855 $this->iCells[$i][$j]->SetFont($aFF,$aFS,$aFSize);
856 }
857 }
858 }
859
860 function SetRowFont($aRow,$aFF,$aFS,$aFSize=10) {
861 $this->_chkR($aRow);
862 for($j=0; $j < $this->iSize[1]; ++$j) {
863 $this->iCells[$aRow][$j]->SetFont($aFF,$aFS,$aFSize);
864 }
865 }
866
867 function SetColFont($aCol,$aFF,$aFS,$aFSize=10) {
868 $this->_chkC($aCol);
869 for($i=0; $i < $this->iSize[0]; ++$i) {
870 $this->iCells[$i][$aCol]->SetFont($aFF,$aFS,$aFSize);
871 }
872 }
873
874 function SetCellFont($aRow,$aCol,$aFF,$aFS,$aFSize=10) {
875 $this->_chkR($aRow);
876 $this->_chkC($aCol);
877 $this->iCells[$aRow][$aCol]->SetFont($aFF,$aFS,$aFSize);
878 }
879
880 /*---------------------------------------------------------------------
881 * Cell align settings
882 *---------------------------------------------------------------------
883 */
884
885 function SetAlign($aR1HAlign=null,$aC1VAlign=null,$aR2=null,$aC2=null,$aHArg=null,$aVArg='center') {
886 if( $aC1VAlign !== null && $aR2!==null && $aC2!==null && $aHArg!==null ) {
887 $this->_chkR($aR1HAlign); $this->_chkC($aC1VAlign);
888 $this->_chkR($aR2); $this->_chkC($aC2);
889 }
890 else {
891 if( $aR1HAlign === null ) {
892 JpGraphError::RaiseL(27010);
893 }
894 if( $aC1VAlign === null ) {
895 $aC1VAlign = 'center';
896 }
897 $aHArg = $aR1HAlign;
898 $aVArg = $aC1VAlign === null ? 'center' : $aC1VAlign ;
899 $aR2 = $this->iSize[0]-1; $aR1HAlign = 0;
900 $aC2 = $this->iSize[1]-1; $aC1VAlign = 0;
901 }
902 for($i=$aR1HAlign; $i <= $aR2; ++$i) {
903 for($j=$aC1VAlign; $j <= $aC2; ++$j) {
904 $this->iCells[$i][$j]->SetAlign($aHArg,$aVArg);
905 }
906 }
907 }
908
909 function SetCellAlign($aRow,$aCol,$aHorAlign,$aVertAlign='bottom') {
910 $this->_chkR($aRow);
911 $this->_chkC($aCol);
912 $this->iCells[$aRow][$aCol]->SetAlign($aHorAlign,$aVertAlign);
913 }
914
915 function SetRowAlign($aRow,$aHorAlign,$aVertAlign='bottom') {
916 $this->_chkR($aRow);
917 for($j=0; $j < $this->iSize[1]; ++$j) {
918 $this->iCells[$aRow][$j]->SetAlign($aHorAlign,$aVertAlign);
919 }
920 }
921
922 function SetColAlign($aCol,$aHorAlign,$aVertAlign='bottom') {
923 $this->_chkC($aCol);
924 for($i=0; $i < $this->iSize[0]; ++$i) {
925 $this->iCells[$i][$aCol]->SetAlign($aHorAlign,$aVertAlign);
926 }
927 }
928
929 /*---------------------------------------------------------------------
930 * Cell number format
931 *---------------------------------------------------------------------
932 */
933
934 function SetNumberFormat($aArgR1,$aC1=null,$aR2=null,$aC2=null,$aArg=null) {
935 if( $aC1 !== null && $aR2!==null && $aC2!==null && $aArg!==null ) {
936 $this->_chkR($aArgR1); $this->_chkC($aC1);
937 $this->_chkR($aR2); $this->_chkC($aC2);
938 }
939 else {
940 $aArg = $aArgR1;
941 $aR2 = $this->iSize[0]-1; $aArgR1 = 0;
942 $aC2 = $this->iSize[1]-1; $aC1 = 0;
943 }
944 if( !is_string($aArg) ) {
945 JpGraphError::RaiseL(27013); // argument must be a string
946 }
947 for($i=$aArgR1; $i <= $aR2; ++$i) {
948 for($j=$aC1; $j <= $aC2; ++$j) {
949 $this->iCells[$i][$j]->SetNumberFormat($aArg);
950 }
951 }
952 }
953
954 function SetRowNumberFormat($aRow,$aF) {
955 $this->_chkR($aRow);
956 if( !is_string($aF) ) {
957 JpGraphError::RaiseL(27013); // argument must be a string
958 }
959 for($j=0; $j < $this->iSize[1]; ++$j) {
960 $this->iCells[$aRow][$j]->SetNumberFormat($aF);
961 }
962 }
963
964 function SetColNumberFormat($aCol,$aF) {
965 $this->_chkC($aCol);
966 if( !is_string($aF) ) {
967 JpGraphError::RaiseL(27013); // argument must be a string
968 }
969 for($i=0; $i < $this->iSize[0]; ++$i) {
970 $this->iCells[$i][$aCol]->SetNumberFormat($aF);
971 }
972 }
973
974 function SetCellNumberFormat($aRow,$aCol,$aF) {
975 $this->_chkR($aRow); $this->_chkC($aCol);
976 if( !is_string($aF) ) {
977 JpGraphError::RaiseL(27013); // argument must be a string
978 }
979 $this->iCells[$aRow][$aCol]->SetNumberFormat($aF);
980 }
981
982 /*---------------------------------------------------------------------
983 * Set row and column min size
984 *---------------------------------------------------------------------
985 */
986
987 function SetMinColWidth($aColWidth,$aWidth=null) {
988 // If there is only one argument this means that all
989 // columns get set to the same width
990 if( $aWidth===null ) {
991 for($i=0; $i < $this->iSize[1]; ++$i) {
992 $this->iColWidth[$i] = $aColWidth;
993 }
994 }
995 else {
996 $this->_chkC($aColWidth);
997 $this->iColWidth[$aColWidth] = $aWidth;
998 }
999 }
1000
1001 function SetMinRowHeight($aRowHeight,$aHeight=null) {
1002 // If there is only one argument this means that all
1003 // rows get set to the same height
1004 if( $aHeight===null ) {
1005 for($i=0; $i < $this->iSize[0]; ++$i) {
1006 $this->iRowHeight[$i] = $aRowHeight;
1007 }
1008 }
1009 else {
1010 $this->_chkR($aRowHeight);
1011 $this->iRowHeight[$aRowHeight] = $aHeight;
1012 }
1013 }
1014
1015 /*---------------------------------------------------------------------
1016 * Grid line settings
1017 *---------------------------------------------------------------------
1018 */
1019
1020 function SetGrid($aWeight=1,$aColor='black',$aStyle=TGRID_SINGLE) {
1021 $rc = $this->iSize[0];
1022 $cc = $this->iSize[1];
1023 for($i=0; $i < $rc; ++$i) {
1024 for($j=0; $j < $cc; ++$j) {
1025 $this->iCells[$i][$j]->SetGridColor($aColor,$aColor);
1026 $this->iCells[$i][$j]->SetGridWeight($aWeight,$aWeight);
1027 $this->iCells[$i][$j]->SetGridStyle($aStyle);
1028 }
1029 }
1030 }
1031
1032 function SetColGrid($aCol,$aWeight=1,$aColor='black',$aStyle=TGRID_SINGLE) {
1033 $this->_chkC($aCol);
1034 for($i=0; $i < $this->iSize[0]; ++$i) {
1035 $this->iCells[$i][$aCol]->SetGridWeight($aWeight);
1036 $this->iCells[$i][$aCol]->SetGridColor($aColor);
1037 $this->iCells[$i][$aCol]->SetGridStyle($aStyle);
1038 }
1039 }
1040
1041 function SetRowGrid($aRow,$aWeight=1,$aColor='black',$aStyle=TGRID_SINGLE) {
1042 $this->_chkR($aRow);
1043 for($j=0; $j < $this->iSize[1]; ++$j) {
1044 $this->iCells[$aRow][$j]->SetGridWeight(NULL,$aWeight);
1045 $this->iCells[$aRow][$j]->SetGridColor(NULL,$aColor);
1046 $this->iCells[$aRow][$j]->SetGridStyle(NULL,$aStyle);
1047 }
1048 }
1049
1050 /*---------------------------------------------------------------------
1051 * Merge cells
1052 *---------------------------------------------------------------------
1053 */
1054
1055 function MergeRow($aRow,$aHAlign='center',$aVAlign='center') {
1056 $this->_chkR($aRow);
1057 $this->MergeCells($aRow,0,$aRow,$this->iSize[1]-1,$aHAlign,$aVAlign);
1058 }
1059
1060 function MergeCol($aCol,$aHAlign='center',$aVAlign='center') {
1061 $this->_chkC($aCol);
1062 $this->MergeCells(0,$aCol,$this->iSize[0]-1,$aCol,$aHAlign,$aVAlign);
1063 }
1064
1065 function MergeCells($aR1,$aC1,$aR2,$aC2,$aHAlign='center',$aVAlign='center') {
1066 if( $aR1 > $aR2 || $aC1 > $aC2 ) {
1067 JpGraphError::RaiseL(27004);
1068 //('GTextTable::MergeCells(). Specified cell range to be merged is not valid.');
1069 }
1070 $this->_chkR($aR1); $this->_chkC($aC1);
1071 $this->_chkR($aR2); $this->_chkC($aC2);
1072 $rspan = $aR2-$aR1+1;
1073 $cspan = $aC2-$aC1+1;
1074 // Setup the parent cell for this merged group
1075 if( $this->iCells[$aR1][$aC1]->IsMerged() ) {
1076 JpGraphError::RaiseL(27005,$aR1,$aC1,$aR2,$aC2);
1077 //("Cannot merge already merged cells in the range ($aR1,$aC1), ($aR2,$aC2)");
1078 }
1079 $this->iCells[$aR1][$aC1]->SetRowColSpan($rspan,$cspan);
1080 $this->iCells[$aR1][$aC1]->SetAlign($aHAlign,$aVAlign);
1081 for($i=$aR1; $i <= $aR2; ++$i) {
1082 for($j=$aC1; $j <= $aC2; ++$j) {
1083 if( ! ($i == $aR1 && $j == $aC1) ) {
1084 if( $this->iCells[$i][$j]->IsMerged() ) {
1085 JpGraphError::RaiseL(27005,$aR1,$aC1,$aR2,$aC2);
1086 //("Cannot merge already merged cells in the range ($aR1,$aC1), ($aR2,$aC2)");
1087 }
1088 $this->iCells[$i][$j]->SetMerged($aR1,$aC1,true);
1089 }
1090 }
1091 }
1092 }
1093
1094
1095 /*---------------------------------------------------------------------
1096 * CSIM methods
1097 *---------------------------------------------------------------------
1098 */
1099
1100 function SetCSIMTarget($aTarget,$aAlt=null,$aAutoTarget=false) {
1101 $m = $this->iSize[0];
1102 $n = $this->iSize[1];
1103 $csim = '';
1104 for($i=0; $i < $m; ++$i) {
1105 for($j=0; $j < $n; ++$j) {
1106 if( $aAutoTarget )
1107 $t = $aTarget."?row=$i&col=$j";
1108 else
1109 $t = $aTarget;
1110 $this->iCells[$i][$j]->SetCSIMTarget($t,$aAlt);
1111 }
1112 }
1113 }
1114
1115 function SetCellCSIMTarget($aRow,$aCol,$aTarget,$aAlt=null) {
1116 $this->_chkR($aRow);
1117 $this->_chkC($aCol);
1118 $this->iCells[$aRow][$aCol]->SetCSIMTarget($aTarget,$aAlt);
1119 }
1120
1121 /*---------------------------------------------------------------------
1122 * Private methods
1123 *---------------------------------------------------------------------
1124 */
1125
1126 function GetCSIMAreas() {
1127 $m = $this->iSize[0];
1128 $n = $this->iSize[1];
1129 $csim = '';
1130 for($i=0; $i < $m; ++$i) {
1131 for($j=0; $j < $n; ++$j) {
1132 $csim .= $this->iCells[$i][$j]->GetCSIMArea();
1133 }
1134 }
1135 return $csim;
1136 }
1137
1138 function _chkC($aCol) {
1139 if( ! $this->iInit ) {
1140 JpGraphError::Raise(27014); // Table not initialized
1141 }
1142 if( $aCol < 0 || $aCol >= $this->iSize[1] )
1143 JpGraphError::RaiseL(27006,$aCol);
1144 //("GTextTable:\nColumn argument ($aCol) is outside specified table size.");
1145 }
1146
1147 function _chkR($aRow) {
1148 if( ! $this->iInit ) {
1149 JpGraphError::Raise(27014); // Table not initialized
1150 }
1151 if( $aRow < 0 || $aRow >= $this->iSize[0] )
1152 JpGraphError::RaiseL(27007,$aRow);
1153 //("GTextTable:\nRow argument ($aRow) is outside specified table size.");
1154 }
1155
1156 function _getScalePos() {
1157 if( $this->iScaleXPos === null || $this->iScaleYPos === null ) {
1158 return false;
1159 }
1160 return array($this->iScaleXPos, $this->iScaleYPos);
1161 }
1162
1163 function _autoSizeTable($aImg) {
1164 // Get maximum column width and row height
1165 $m = $this->iSize[0];
1166 $n = $this->iSize[1];
1167 $w=1;$h=1;
1168
1169 // Get maximum row height per row
1170 for($i=0; $i < $m; ++$i) {
1171 $h=0;
1172 for($j=0; $j < $n; ++$j) {
1173 $h = max($h,$this->iCells[$i][$j]->GetHeight($aImg));
1174 }
1175 if( isset($this->iRowHeight[$i]) ) {
1176 $this->iRowHeight[$i] = max($h,$this->iRowHeight[$i]);
1177 }
1178 else
1179 $this->iRowHeight[$i] = $h;
1180 }
1181
1182 // Get maximum col width per columns
1183 for($j=0; $j < $n; ++$j) {
1184 $w=0;
1185 for($i=0; $i < $m; ++$i) {
1186 $w = max($w,$this->iCells[$i][$j]->GetWidth($aImg));
1187 }
1188 if( isset($this->iColWidth[$j]) ) {
1189 $this->iColWidth[$j] = max($w,$this->iColWidth[$j]);
1190 }
1191 else
1192 $this->iColWidth[$j] = $w;
1193 }
1194 }
1195
1196 function _setcell($aRow,$aCol,$aVal='') {
1197 if( isset($this->iCells[$aRow][$aCol]) ) {
1198 $this->iCells[$aRow][$aCol]->Set($aVal);
1199 }
1200 else {
1201 $this->iCells[$aRow][$aCol] = new GTextTableCell((string)$aVal,$aRow,$aCol);
1202 $this->iCells[$aRow][$aCol]->Init($this);
1203 }
1204 }
1205
1206 function StrokeWithScale($aImg,$aXScale,$aYScale) {
1207 if( is_numeric($this->iScaleXPos) && is_numeric($this->iScaleYPos) ) {
1208 $x = round($aXScale->Translate($this->iScaleXPos));
1209 $y = round($aYScale->Translate($this->iScaleYPos));
1210 $this->Stroke($aImg,$x,$y);
1211 }
1212 else {
1213 $this->Stroke($aImg);
1214 }
1215 }
1216
1217 function Stroke($aImg,$aX=NULL,$aY=NULL) {
1218 if( $aX !== NULL && $aY !== NULL ) {
1219 $this->iXPos = $aX;
1220 $this->iYPos = $aY;
1221 }
1222
1223 $rc = $this->iSize[0]; // row count
1224 $cc = $this->iSize[1]; // column count
1225
1226 if( $rc == 0 || $cc == 0 ) {
1227 JpGraphError::RaiseL(27009);
1228 }
1229
1230 // Adjust margins of each cell based on the weight of the grid. Each table grid line
1231 // is actually occupying the left side and top part of each cell.
1232 for($j=0; $j < $cc; ++$j) {
1233 $this->iCells[0][$j]->iMarginTop += $this->iBorderWeight;
1234 }
1235 for($i=0; $i < $rc; ++$i) {
1236 $this->iCells[$i][0]->iMarginLeft += $this->iBorderWeight;
1237 }
1238 for($i=0; $i < $rc; ++$i) {
1239 for($j=0; $j < $cc; ++$j) {
1240 $this->iCells[$i][$j]->AdjustMarginsForGrid();
1241 }
1242 }
1243
1244 // adjust row and column size depending on cell content
1245 $this->_autoSizeTable($aImg);
1246
1247 if( $this->iSize[1] != count($this->iColWidth) || $this->iSize[0] != count($this->iRowHeight) ) {
1248 JpGraphError::RaiseL(27008);
1249 //('Column and row size arrays must match the dimesnions of the table');
1250 }
1251
1252 // Find out overall table size
1253 $width=0;
1254 for($i=0; $i < $cc; ++$i) {
1255 $width += $this->iColWidth[$i];
1256 }
1257 $height=0;
1258 for($i=0; $i < $rc; ++$i) {
1259 $height += $this->iRowHeight[$i];
1260 }
1261
1262 // Adjust the X,Y position to alway be at the top left corner
1263 // The anchor position, i.e. how the client want to interpret the specified
1264 // x and y coordinate must be taken into account
1265 switch( strtolower($this->iXAnchor) ) {
1266 case 'left' :
1267 break;
1268 case 'center':
1269 $this->iXPos -= round($width/2);
1270 break;
1271 case 'right':
1272 $this->iXPos -= $width;
1273 break;
1274 }
1275 switch( strtolower($this->iYAnchor) ) {
1276 case 'top' :
1277 break;
1278 case 'center':
1279 case 'middle':
1280 $this->iYPos -= round($height/2);
1281 break;
1282 case 'bottom':
1283 $this->iYPos -= $height;
1284 break;
1285 }
1286
1287 // Set the overall background color of the table if set
1288 if( $this->iBGColor !== '' ) {
1289 $aImg->SetColor($this->iBGColor);
1290 $aImg->FilledRectangle($this->iXPos,$this->iYPos,$this->iXPos+$width,$this->iYPos+$height);
1291 }
1292
1293 // Stroke all cells
1294 $rpos=$this->iYPos;
1295 for($i=0; $i < $rc; ++$i) {
1296 $cpos=$this->iXPos;
1297 for($j=0; $j < $cc; ++$j) {
1298 // Calculate width and height of this cell if it is spanning
1299 // more than one column or row
1300 $cwidth=0;
1301 for( $k=0; $k < $this->iCells[$i][$j]->iColSpan; ++$k ) {
1302 $cwidth += $this->iColWidth[$j+$k];
1303 }
1304 $cheight=0;
1305 for( $k=0; $k < $this->iCells[$i][$j]->iRowSpan; ++$k ) {
1306 $cheight += $this->iRowHeight[$i+$k];
1307 }
1308
1309 $this->iCells[$i][$j]->Stroke($aImg,$cpos,$rpos,$cwidth,$cheight);
1310 $cpos += $this->iColWidth[$j];
1311 }
1312 $rpos += $this->iRowHeight[$i];
1313 }
1314
1315 // Stroke outer border
1316 $aImg->SetColor($this->iBorderColor);
1317 if( $this->iBorderWeight == 1 )
1318 $aImg->Rectangle($this->iXPos,$this->iYPos,$this->iXPos+$width,$this->iYPos+$height);
1319 else {
1320 for( $i=0; $i < $this->iBorderWeight; ++$i )
1321 $aImg->Rectangle($this->iXPos+$i,$this->iYPos+$i,
1322 $this->iXPos+$width-1+$this->iBorderWeight-$i,
1323 $this->iYPos+$height-1+$this->iBorderWeight-$i);
1324 }
1325 }
1326}
1327
1328/*
1329 EOF
1330 */
1331?>
Note: See TracBrowser for help on using the repository browser.