CWIS Developer Documentation

- Home
- Main Page
- Classes
- Files

- File List
- File Members

Axis--PSTable.php
Go to the documentation of this file.
1 <?PHP
2
3 #
4 # Axis--PSTable.php
5 # A PHP Object for Adding a Table to a PostScript Document (PSDocument)
6 #
7 # Copyright 1999-2001 Axis Data
8 # This code is free software that can be used or redistributed under the
9 # terms of Version 2 of the GNU General Public License, as published by the
10 # Free Software Foundation (http://www.fsf.org).
11 #
12 # Author: Edward Almasy (almasy@axisdata.com)
13 #
14 # Part of the AxisPHP library v1.2.4
15 # For more information see http://www.axisdata.com/AxisPHP/
16 #
17
18
19 class PSTable {
20
21 # ---- PUBLIC INTERFACE --------------------------------------------------
22
23 # object constructor
24 function PSTable(&$Document)
25 {
26 # save pointer to document we use for output
27 $this->Doc = &$Document;
28 }
29
30 # table parameter access functions
31 function XOrigin($NewXOrigin = -1) { if ($NewXOrigin != -1) { $this->XOrigin = $NewXOrigin; } return (int)$this->XOrigin; }
32 function YOrigin($NewYOrigin = -1) { if ($NewYOrigin != -1) { $this->YOrigin = $NewYOrigin; } return (int)$this->YOrigin; }
33 function XSize($NewXSize = -1) { if ($NewXSize != -1) { $this->XSize = $NewXSize; $this->RecalcActualColumnWidths(); } return (int)$this->XSize; }
34 function YSize($NewYSize = -1) { if ($NewYSize != -1) { $this->YSize = $NewYSize; $this->RecalcActualRowHeights(); } return (int)$this->YSize; }
35 function NumCols($NewNumCols = -1) { if ($NewNumCols != -1) { $this->NumCols = $NewNumCols; $this->RecalcActualColumnWidths(); } return (int)$this->NumCols; }
36 function NumRows($NewNumRows = -1) { if ($NewNumRows != -1) { $this->NumRows = $NewNumRows; $this->RecalcActualRowHeights(); } return (int)$this->NumRows; }
37 function ShadeColumnHeadings($NewShadeColumnHeadings = -1) { if ($NewShadeColumnHeadings != -1) { $this->ShadeColumnHeadings = $NewShadeColumnHeadings; } return (int)$this->ShadeColumnHeadings; }
38
39 # return position of table cell on page
40 function CellXPos($Col) { return $this->XOrigin + $this->ColumnStartPoints[$Col]; }
41 function CellYPos($Row) { return $this->YOrigin - $this->RowStartPoints[$Row]; }
42
43 # set/get column/row width/height
44 function ColWidth($Col, $Width = -1)
45 {
46 # if column width specified
47 if ($Width >= 0)
48 {
49 # set requested column width
50 $this->RequestedColumnWidths[$Col] = $Width;
51
52 # recalculate actual column widths
53 $this->RecalcActualColumnWidths();
54 }
55
56 # return actual column width to caller
57 return (int)$this->ColumnWidths[$Col];
58 }
59 function RowHeight($Row, $Width = -1)
60 {
61 # if row width specified
62 if ($Width >= 0)
63 {
64 # set requested row width
65 $this->RequestedRowHeights[$Row] = $Width;
66
67 # recalculate actual row widths
68 $this->RecalcActualRowHeights();
69 }
70
71 # return actual row width to caller
72 return (int)$this->RowHeights[$Row];
73 }
74
75 function PrintTextInCell($Row, $Col, $TextToPrint)
76 {
77 # distance that text is printed from edge of cell
78 $CellPadding = 3;
79
80 if ($this->Doc->TextAngle() == 90)
81 {
82 $this->Doc->PrintTextAt(
83 ($this->CellXPos($Col + 1) - $CellPadding),
84 ($this->CellYPos($Row) - $CellPadding),
85 $TextToPrint);
86 }
87 else
88 {
89 $this->Doc->PrintTextAt(
90 ($this->CellXPos($Col) + $CellPadding),
91 ($this->CellYPos($Row) - $CellPadding),
92 $TextToPrint);
93 }
94 }
95
96 # print table on document
97 function PrintTable()
98 {
99 # write comment on what we're doing
100 $this->Doc->PrintRaw(sprintf("
101 %% PSTable->Print()
102 %% XOrigin=%3s YOrigin=%3s
103 %% NumCols=%3s NumRows=%3s
104 %% XSize=%3s YSize=%3s
105 %% AdjXSize=%3s AdjYSize=%3s
106 ",
107 $this->XOrigin, $this->YOrigin,
108 $this->NumCols, $this->NumRows,
109 $this->XSize, $this->YSize,
110 $this->AdjXSize,$this->AdjYSize));
111
112 # move to start point
113 $this->Doc->PrintRaw(sprintf("
114 %s %s moveto
115 ", (int)$this->XOrigin, (int)$this->YOrigin));
116
117 # start in positive direction (going right on page)
118 $DirMult = 1;
119
120 # for each row
121 for ($Index = 0; $Index <= $this->NumRows; $Index++)
122 {
123 # draw horizontal line and move to next row
124 $this->Doc->PrintRaw(sprintf("
125 %s 0 rlineto
126 0 %s rmoveto
127 ",
128 ($this->AdjXSize * $DirMult),
129 (0 - $this->RowHeight($Index + 1))));
130
131 # switch directions
132 $DirMult = 0 - $DirMult;
133 }
134
135 # move to start point
136 $this->Doc->PrintRaw(sprintf("
137 %s %s moveto
138 ", (int)$this->XOrigin, (int)$this->YOrigin));
139
140 # start in negative direction (going down on page)
141 $DirMult = -1;
142
143 # for each column
144 for ($Index = 0; $Index <= $this->NumCols; $Index++)
145 {
146 # draw vertical line and move to next column
147 $this->Doc->PrintRaw(sprintf("
148 0 %s rlineto
149 %s 0 rmoveto
150 ",
151 ($this->AdjYSize * $DirMult),
152 $this->ColWidth($Index + 1)));
153
154 # switch directions
155 $DirMult = 0 - $DirMult;
156 }
157
158 # shade column heading cells if requested
159 if ($this->ShadeColumnHeadings == "TRUE")
160 {
161 $this->Doc->PrintRaw(sprintf("
162 0.90 setgray
163 %% rectfill: X Y Width Height
164 %d %d %d %d rectfill
165 0.00 setgray
166 ",
167 $this->XOrigin, $this->CellYPos(2),
168 $this->AdjXSize, $this->RowHeight(1)));
169 }
170
171 # realize table
172 $this->Doc->PrintRaw("
173 stroke
174 ");
175 }
176
177
178 # ---- PRIVATE INTERFACE -------------------------------------------------
179
180 # recalculate row heights and positions
181 function RecalcActualRowHeights()
182 {
183 # total up requested height values
184 $TotalHeight = 0;
185 $NumSizedRows = 0;
186 for ($Row = 1; $Row <= $this->NumRows; $Row++)
187 {
188 if ($this->RequestedRowHeights[$Row] > 0)
189 {
190 $TotalHeight += $this->RequestedRowHeights[$Row];
191 $NumSizedRows++;
192 }
193 }
194
195 # calculate size of remaining rows
196 if ($this->NumRows == $NumSizedRows)
197 {
198 $HeightOfRemainingRows = 1;
199 }
200 else
201 {
202 $HeightOfRemainingRows = (int)(($this->YSize - $TotalHeight)
203 / ($this->NumRows - $NumSizedRows));
204 }
205
206 # set actual row heights and row begin points
207 $CurrentStartPoint = $this->YSize;
208 $this->AdjYSize = 0;
209 for ($Row = 1; $Row <= $this->NumRows; $Row++)
210 {
211 if ($this->RequestedRowHeights[$Row] > 0)
212 {
213 $this->RowHeights[$Row] = $this->RequestedRowHeights[$Row];
214 }
215 else
216 {
217 $this->RowHeights[$Row] = $HeightOfRemainingRows;
218 }
219
220 $CurrentStartPoint -= $this->RowHeights[$Row];
221 $this->RowStartPoints[$Row] = $this->AdjYSize;
222 $this->AdjYSize += $this->RowHeights[$Row];
223 }
224 }
225
226 # recalculate column widths and positions
227 function RecalcActualColumnWidths()
228 {
229 # total up requested width values
230 $TotalWidth = 0;
231 $NumSizedColumns = 0;
232 for ($Col = 1; $Col <= $this->NumCols; $Col++)
233 {
234 if ($this->RequestedColumnWidths[$Col] > 0)
235 {
236 $TotalWidth += $this->RequestedColumnWidths[$Col];
237 $NumSizedColumns++;
238 }
239 }
240
241 # calculate size of remaining columns
242 $WidthOfRemainingColumns = (int)(($this->XSize - $TotalWidth)
243 / ($this->NumCols - $NumSizedColumns));
244
245 # set actual column widths and column begin points
246 $CurrentStartPoint = 0;
247 $this->AdjXSize = 0;
248 for ($Col = 1; $Col <= $this->NumCols; $Col++)
249 {
250 if ($this->RequestedColumnWidths[$Col] > 0)
251 {
252 $this->ColumnWidths[$Col] = $this->RequestedColumnWidths[$Col];
253 }
254 else
255 {
256 $this->ColumnWidths[$Col] = $WidthOfRemainingColumns;
257 }
258
259 $this->ColumnStartPoints[$Col] = $CurrentStartPoint;
260 $CurrentStartPoint += $this->ColumnWidths[$Col];
261 $this->AdjXSize += $this->ColumnWidths[$Col];
262 }
263
264 # save start point of one column beyond table so we'll have
265 # it available for text positioning
266 $this->ColumnStartPoints[$Col] = $CurrentStartPoint;
267 }
268
269 # table size in points
270 var $XSize = 300;
271 var $YSize = 300;
272
273 # table size in points (adjusted to accomodate even row/column sizes)
274 var $AdjXSize = 300;
275 var $AdjYSize = 300;
276
277 # number of columns and rows
278 var $NumCols = 3;
279 var $NumRows = 3;
280
281 # requested column and row sizes
282 var $RequestedColumnWidths;
283 var $RequestedRowHeights;
284
285 # actual column and row sizes
286 var $ColumnWidths;
287 var $RowHeights;
288
289 # column and row start points
290 var $ColumnStartPoints;
291 var $RowStartPoints;
292
293 # table origin on page
294 var $XOrigin = 100;
295 var $YOrigin = 400;
296
297 # document to use for output
298 var $Doc;
299
300 # whether to give column headings a grey background
301 var $ShadeColumnHeadings = "FALSE";
302 }
303
304
305 ?>
PSTable\$Doc
$Doc
Definition: Axis--PSTable.php:298
PSTable\NumCols
NumCols($NewNumCols=-1)
Definition: Axis--PSTable.php:35
PSTable\CellXPos
CellXPos($Col)
Definition: Axis--PSTable.php:40
PSTable\ColWidth
ColWidth($Col, $Width=-1)
Definition: Axis--PSTable.php:44
PSTable\RowHeight
RowHeight($Row, $Width=-1)
Definition: Axis--PSTable.php:59
PSTable\RecalcActualRowHeights
RecalcActualRowHeights()
Definition: Axis--PSTable.php:181
PSTable\$ShadeColumnHeadings
$ShadeColumnHeadings
Definition: Axis--PSTable.php:301
PSTable
Definition: Axis--PSTable.php:19
PSTable\$XSize
$XSize
Definition: Axis--PSTable.php:270
PSTable\$ColumnStartPoints
$ColumnStartPoints
Definition: Axis--PSTable.php:290
PSTable\$RowHeights
$RowHeights
Definition: Axis--PSTable.php:287
PSTable\$AdjXSize
$AdjXSize
Definition: Axis--PSTable.php:274
PSTable\$NumCols
$NumCols
Definition: Axis--PSTable.php:278
PSTable\ShadeColumnHeadings
ShadeColumnHeadings($NewShadeColumnHeadings=-1)
Definition: Axis--PSTable.php:37
PSTable\$RowStartPoints
$RowStartPoints
Definition: Axis--PSTable.php:291
PHP
PHP
Definition: OAIClient.php:39
PSTable\$XOrigin
$XOrigin
Definition: Axis--PSTable.php:294
PSTable\XSize
XSize($NewXSize=-1)
Definition: Axis--PSTable.php:33
PSTable\$ColumnWidths
$ColumnWidths
Definition: Axis--PSTable.php:286
PSTable\CellYPos
CellYPos($Row)
Definition: Axis--PSTable.php:41
PSTable\XOrigin
XOrigin($NewXOrigin=-1)
Definition: Axis--PSTable.php:31
PSTable\RecalcActualColumnWidths
RecalcActualColumnWidths()
Definition: Axis--PSTable.php:227
PSTable\$YOrigin
$YOrigin
Definition: Axis--PSTable.php:295
PSTable\$RequestedRowHeights
$RequestedRowHeights
Definition: Axis--PSTable.php:283
PSTable\NumRows
NumRows($NewNumRows=-1)
Definition: Axis--PSTable.php:36
PSTable\$RequestedColumnWidths
$RequestedColumnWidths
Definition: Axis--PSTable.php:282
PSTable\YSize
YSize($NewYSize=-1)
Definition: Axis--PSTable.php:34
PSTable\PrintTable
PrintTable()
Definition: Axis--PSTable.php:97
PSTable\YOrigin
YOrigin($NewYOrigin=-1)
Definition: Axis--PSTable.php:32
PSTable\$YSize
$YSize
Definition: Axis--PSTable.php:271
PSTable\$AdjYSize
$AdjYSize
Definition: Axis--PSTable.php:275
PSTable\$NumRows
$NumRows
Definition: Axis--PSTable.php:279
PSTable\PrintTextInCell
PrintTextInCell($Row, $Col, $TextToPrint)
Definition: Axis--PSTable.php:75
PSTable\PSTable
PSTable(&$Document)
Definition: Axis--PSTable.php:24