Search:

# CWIS Developers Documentation

- Main Page
- Classes
- Files

- Search for |

- File List
- File Members

# Axis--PSTable.php

Go to the documentation of this file.

    00001 <?PHP
    00002
    00003 #
    00004 #   Axis--PSTable.php
    00005 #   A PHP Object for Adding a Table to a PostScript Document (PSDocument)
    00006 #
    00007 #   Copyright 1999-2001 Axis Data
    00008 #   This code is free software that can be used or redistributed under the
    00009 #   terms of Version 2 of the GNU General Public License, as published by the
    00010 #   Free Software Foundation (http://www.fsf.org).
    00011 #
    00012 #   Author:  Edward Almasy (almasy@axisdata.com)
    00013 #
    00014 #   Part of the AxisPHP library v1.2.4
    00015 #   For more information see http://www.axisdata.com/AxisPHP/
    00016 #
    00017
    00018
    00019 class PSTable {
    00020
    00021     # ---- PUBLIC INTERFACE --------------------------------------------------
    00022
    00023     # object constructor
    00024     function PSTable(&$Document)
    00025     {
    00026         # save pointer to document we use for output
    00027         $this->Doc = &$Document;
    00028     }
    00029
    00030     # table parameter access functions
    00031     function XOrigin($NewXOrigin = -1) {  if ($NewXOrigin != -1) {  $this->XOrigin = $NewXOrigin;  }  return (int)$this->XOrigin;  }
    00032     function YOrigin($NewYOrigin = -1) {  if ($NewYOrigin != -1) {  $this->YOrigin = $NewYOrigin;  }  return (int)$this->YOrigin;  }
    00033     function XSize($NewXSize = -1) {  if ($NewXSize != -1) {  $this->XSize = $NewXSize;  $this->RecalcActualColumnWidths();  }  return (int)$this->XSize;  }
    00034     function YSize($NewYSize = -1) {  if ($NewYSize != -1) {  $this->YSize = $NewYSize;  $this->RecalcActualRowHeights();  }  return (int)$this->YSize;  }
    00035     function NumCols($NewNumCols = -1) {  if ($NewNumCols != -1) {  $this->NumCols = $NewNumCols;  $this->RecalcActualColumnWidths();  }  return (int)$this->NumCols;  }
    00036     function NumRows($NewNumRows = -1) {  if ($NewNumRows != -1) {  $this->NumRows = $NewNumRows;  $this->RecalcActualRowHeights();  }  return (int)$this->NumRows;  }
    00037     function ShadeColumnHeadings($NewShadeColumnHeadings = -1) {  if ($NewShadeColumnHeadings != -1) {  $this->ShadeColumnHeadings = $NewShadeColumnHeadings;  }  return (int)$this->ShadeColumnHeadings;  }
    00038
    00039     # return position of table cell on page
    00040     function CellXPos($Col) {  return $this->XOrigin + $this->ColumnStartPoints[$Col];  }
    00041     function CellYPos($Row) {  return $this->YOrigin - $this->RowStartPoints[$Row];  }
    00042
    00043     # set/get column/row width/height
    00044     function ColWidth($Col, $Width = -1)
    00045     {
    00046         # if column width specified
    00047         if ($Width >= 0)
    00048         {
    00049             # set requested column width
    00050             $this->RequestedColumnWidths[$Col] = $Width;
    00051
    00052             # recalculate actual column widths
    00053             $this->RecalcActualColumnWidths();
    00054         }
    00055
    00056         # return actual column width to caller
    00057         return (int)$this->ColumnWidths[$Col];
    00058     }
    00059     function RowHeight($Row, $Width = -1)
    00060     {
    00061         # if row width specified
    00062         if ($Width >= 0)
    00063         {
    00064             # set requested row width
    00065             $this->RequestedRowHeights[$Row] = $Width;
    00066
    00067             # recalculate actual row widths
    00068             $this->RecalcActualRowHeights();
    00069         }
    00070
    00071         # return actual row width to caller
    00072         return (int)$this->RowHeights[$Row];
    00073     }
    00074
    00075     function PrintTextInCell($Row, $Col, $TextToPrint)
    00076     {
    00077         # distance that text is printed from edge of cell
    00078         $CellPadding = 3;
    00079
    00080         if ($this->Doc->TextAngle() == 90)
    00081         {
    00082             $this->Doc->PrintTextAt(
    00083                     ($this->CellXPos($Col + 1) - $CellPadding),
    00084                     ($this->CellYPos($Row) - $CellPadding),
    00085                     $TextToPrint);
    00086         }
    00087         else
    00088         {
    00089             $this->Doc->PrintTextAt(
    00090                     ($this->CellXPos($Col) + $CellPadding),
    00091                     ($this->CellYPos($Row) - $CellPadding),
    00092                     $TextToPrint);
    00093         }
    00094     }
    00095
    00096     # print table on document
    00097     function PrintTable()
    00098     {
    00099         # write comment on what we're doing
    00100         $this->Doc->PrintRaw(sprintf("
    00101                 %% PSTable->Print()
    00102                 %%     XOrigin=%3s   YOrigin=%3s
    00103                 %%     NumCols=%3s   NumRows=%3s
    00104                 %%       XSize=%3s     YSize=%3s
    00105                 %%    AdjXSize=%3s  AdjYSize=%3s
    00106                 ",
    00107                 $this->XOrigin, $this->YOrigin,
    00108                 $this->NumCols, $this->NumRows,
    00109                 $this->XSize,   $this->YSize,
    00110                 $this->AdjXSize,$this->AdjYSize));
    00111
    00112         # move to start point
    00113         $this->Doc->PrintRaw(sprintf("
    00114                 %s %s moveto
    00115                 ", (int)$this->XOrigin, (int)$this->YOrigin));
    00116
    00117         # start in positive direction (going right on page)
    00118         $DirMult = 1;
    00119
    00120         # for each row
    00121         for ($Index = 0;  $Index <= $this->NumRows;  $Index++)
    00122         {
    00123             # draw horizontal line and move to next row
    00124             $this->Doc->PrintRaw(sprintf("
    00125                     %s 0 rlineto
    00126                     0 %s rmoveto
    00127                     ",
    00128                     ($this->AdjXSize * $DirMult),
    00129                     (0 - $this->RowHeight($Index + 1))));
    00130
    00131             # switch directions
    00132             $DirMult = 0 - $DirMult;
    00133         }
    00134
    00135         # move to start point
    00136         $this->Doc->PrintRaw(sprintf("
    00137                 %s %s moveto
    00138                 ", (int)$this->XOrigin, (int)$this->YOrigin));
    00139
    00140         # start in negative direction (going down on page)
    00141         $DirMult = -1;
    00142
    00143         # for each column
    00144         for ($Index = 0;  $Index <= $this->NumCols;  $Index++)
    00145         {
    00146             # draw vertical line and move to next column
    00147             $this->Doc->PrintRaw(sprintf("
    00148                     0 %s rlineto
    00149                     %s 0 rmoveto
    00150                     ",
    00151                     ($this->AdjYSize * $DirMult),
    00152                     $this->ColWidth($Index + 1)));
    00153
    00154             # switch directions
    00155             $DirMult = 0 - $DirMult;
    00156         }
    00157
    00158         # shade column heading cells if requested
    00159         if ($this->ShadeColumnHeadings == "TRUE")
    00160         {
    00161             $this->Doc->PrintRaw(sprintf("
    00162                     0.90 setgray
    00163                     %% rectfill: X Y Width Height
    00164                     %d %d %d %d rectfill
    00165                     0.00 setgray
    00166                     ",
    00167                     $this->XOrigin,  $this->CellYPos(2),
    00168                     $this->AdjXSize, $this->RowHeight(1)));
    00169         }
    00170
    00171         # realize table
    00172         $this->Doc->PrintRaw("
    00173                 stroke
    00174                 ");
    00175     }
    00176
    00177
    00178     # ---- PRIVATE INTERFACE -------------------------------------------------
    00179
    00180     # recalculate row heights and positions
    00181     function RecalcActualRowHeights()
    00182     {
    00183         # total up requested height values
    00184         $TotalHeight = 0;
    00185         $NumSizedRows = 0;
    00186         for ($Row = 1;  $Row <= $this->NumRows;  $Row++)
    00187         {
    00188             if ($this->RequestedRowHeights[$Row] > 0)
    00189             {
    00190                 $TotalHeight += $this->RequestedRowHeights[$Row];
    00191                 $NumSizedRows++;
    00192             }
    00193         }
    00194
    00195         # calculate size of remaining rows
    00196         if ($this->NumRows == $NumSizedRows)
    00197         {
    00198             $HeightOfRemainingRows = 1;
    00199         }
    00200         else
    00201         {
    00202             $HeightOfRemainingRows = (int)(($this->YSize - $TotalHeight)
    00203                     / ($this->NumRows - $NumSizedRows));
    00204         }
    00205
    00206         # set actual row heights and row begin points
    00207         $CurrentStartPoint = $this->YSize;
    00208         $this->AdjYSize = 0;
    00209         for ($Row = 1;  $Row <= $this->NumRows;  $Row++)
    00210         {
    00211             if ($this->RequestedRowHeights[$Row] > 0)
    00212             {
    00213                 $this->RowHeights[$Row] = $this->RequestedRowHeights[$Row];
    00214             }
    00215             else
    00216             {
    00217                 $this->RowHeights[$Row] = $HeightOfRemainingRows;
    00218             }
    00219
    00220             $CurrentStartPoint -= $this->RowHeights[$Row];
    00221             $this->RowStartPoints[$Row] = $this->AdjYSize;
    00222             $this->AdjYSize += $this->RowHeights[$Row];
    00223         }
    00224     }
    00225
    00226     # recalculate column widths and positions
    00227     function RecalcActualColumnWidths()
    00228     {
    00229         # total up requested width values
    00230         $TotalWidth = 0;
    00231         $NumSizedColumns = 0;
    00232         for ($Col = 1;  $Col <= $this->NumCols;  $Col++)
    00233         {
    00234             if ($this->RequestedColumnWidths[$Col] > 0)
    00235             {
    00236                 $TotalWidth += $this->RequestedColumnWidths[$Col];
    00237                 $NumSizedColumns++;
    00238             }
    00239         }
    00240
    00241         # calculate size of remaining columns
    00242         $WidthOfRemainingColumns = (int)(($this->XSize - $TotalWidth)
    00243                 / ($this->NumCols - $NumSizedColumns));
    00244
    00245         # set actual column widths and column begin points
    00246         $CurrentStartPoint = 0;
    00247         $this->AdjXSize = 0;
    00248         for ($Col = 1;  $Col <= $this->NumCols;  $Col++)
    00249         {
    00250             if ($this->RequestedColumnWidths[$Col] > 0)
    00251             {
    00252                 $this->ColumnWidths[$Col] = $this->RequestedColumnWidths[$Col];
    00253             }
    00254             else
    00255             {
    00256                 $this->ColumnWidths[$Col] = $WidthOfRemainingColumns;
    00257             }
    00258
    00259             $this->ColumnStartPoints[$Col] = $CurrentStartPoint;
    00260             $CurrentStartPoint += $this->ColumnWidths[$Col];
    00261             $this->AdjXSize += $this->ColumnWidths[$Col];
    00262         }
    00263
    00264         # save start point of one column beyond table so we'll have
    00265         #       it available for text positioning
    00266         $this->ColumnStartPoints[$Col] = $CurrentStartPoint;
    00267     }
    00268
    00269     # table size in points
    00270     var $XSize = 300;
    00271     var $YSize = 300;
    00272
    00273     # table size in points (adjusted to accomodate even row/column sizes)
    00274     var $AdjXSize = 300;
    00275     var $AdjYSize = 300;
    00276
    00277     # number of columns and rows
    00278     var $NumCols = 3;
    00279     var $NumRows = 3;
    00280
    00281     # requested column and row sizes
    00282     var $RequestedColumnWidths;
    00283     var $RequestedRowHeights;
    00284
    00285     # actual column and row sizes
    00286     var $ColumnWidths;
    00287     var $RowHeights;
    00288
    00289     # column and row start points
    00290     var $ColumnStartPoints;
    00291     var $RowStartPoints;
    00292
    00293     # table origin on page
    00294     var $XOrigin = 100;
    00295     var $YOrigin = 400;
    00296
    00297     # document to use for output
    00298     var $Doc;
    00299
    00300     # whether to give column headings a grey background
    00301     var $ShadeColumnHeadings = "FALSE";
    00302 }
    00303
    00304
    00305 ?>

Copyright 2009 Internet Scout