/usr/local/miolo2/classes/ezpdf/class.ezpdf.php

Go to the documentation of this file.
00001 <?php
00002 include_once ('class.pdf.php');
00003 
00004 class Cezpdf extends Cpdf
00005 {
00006     //==============================================================================
00007     // this class will take the basic interaction facilities of the Cpdf class
00008     // and make more useful functions so that the user does not have to 
00009     // know all the ins and outs of pdf presentation to produce something pretty.
00010     //
00011     // IMPORTANT NOTE
00012     // there is no warranty, implied or otherwise with this software.
00013     // 
00014     // version 009 (versioning is linked to class.pdf.php)
00015     //
00016     // released under a public domain licence.
00017     //
00018     // Wayne Munro, R&OS Ltd, http://www.ros.co.nz/pdf
00019     //==============================================================================
00020 
00021     var $ez = array('fontSize' => 10); // used for storing most of the page configuration parameters
00022     var $y = 0.0;                      // this is the current vertical positon on the page of the writing point, very important
00023     var $ezPages = array(
00024         );                             // keep an array of the ids of the pages, making it easy to go back and add page numbers etc.
00025 
00026     var $ezPageCount = 0;
00027 
00028     // ------------------------------------------------------------------------------
00029 
00030     function Cezpdf($paper = 'a4', $orientation = 'portrait')
00031     {
00032         // Assuming that people don't want to specify the paper size using the absolute coordinates
00033         // allow a couple of options:
00034         // orientation can be 'portrait' or 'landscape'
00035         // or, to actually set the coordinates, then pass an array in as the first parameter.
00036         // the defaults are as shown.
00037         // 
00038         // -------------------------
00039         // 2002-07-24 - Nicola Asuni (info@tecnick.com):
00040         // Added new page formats (45 standard ISO paper formats and 4 american common formats)
00041         // paper cordinates are calculated in this way: (inches * 72) where 1 inch = 2.54 cm
00042         // 
00043         // Now you may also pass a 2 values array containing the page width and height in centimeters
00044         // -------------------------
00045 
00046         if (!is_array($paper))
00047         {
00048             switch (strtoupper($paper))
00049                 {
00050                 case '4A0':
00051                     {
00052                         $size = array
00053                             (
00054                             0,
00055                             0,
00056                             4767.87,
00057                             6740.79
00058                             );
00059 
00060                         break;
00061                     }
00062 
00063                 case '2A0':
00064                     {
00065                         $size = array
00066                             (
00067                             0,
00068                             0,
00069                             3370.39,
00070                             4767.87
00071                             );
00072 
00073                         break;
00074                     }
00075 
00076                 case 'A0':
00077                     {
00078                         $size = array
00079                             (
00080                             0,
00081                             0,
00082                             2383.94,
00083                             3370.39
00084                             );
00085 
00086                         break;
00087                     }
00088 
00089                 case 'A1':
00090                     {
00091                         $size = array
00092                             (
00093                             0,
00094                             0,
00095                             1683.78,
00096                             2383.94
00097                             );
00098 
00099                         break;
00100                     }
00101 
00102                 case 'A2':
00103                     {
00104                         $size = array
00105                             (
00106                             0,
00107                             0,
00108                             1190.55,
00109                             1683.78
00110                             );
00111 
00112                         break;
00113                     }
00114 
00115                 case 'A3':
00116                     {
00117                         $size = array
00118                             (
00119                             0,
00120                             0,
00121                             841.89,
00122                             1190.55
00123                             );
00124 
00125                         break;
00126                     }
00127 
00128                 case 'A4':
00129                 default:
00130                     {
00131                         $size = array
00132                             (
00133                             0,
00134                             0,
00135                             595.28,
00136                             841.89
00137                             );
00138 
00139                         break;
00140                     }
00141 
00142                 case 'A5':
00143                     {
00144                         $size = array
00145                             (
00146                             0,
00147                             0,
00148                             419.53,
00149                             595.28
00150                             );
00151 
00152                         break;
00153                     }
00154 
00155                 case 'A6':
00156                     {
00157                         $size = array
00158                             (
00159                             0,
00160                             0,
00161                             297.64,
00162                             419.53
00163                             );
00164 
00165                         break;
00166                     }
00167 
00168                 case 'A7':
00169                     {
00170                         $size = array
00171                             (
00172                             0,
00173                             0,
00174                             209.76,
00175                             297.64
00176                             );
00177 
00178                         break;
00179                     }
00180 
00181                 case 'A8':
00182                     {
00183                         $size = array
00184                             (
00185                             0,
00186                             0,
00187                             147.40,
00188                             209.76
00189                             );
00190 
00191                         break;
00192                     }
00193 
00194                 case 'A9':
00195                     {
00196                         $size = array
00197                             (
00198                             0,
00199                             0,
00200                             104.88,
00201                             147.40
00202                             );
00203 
00204                         break;
00205                     }
00206 
00207                 case 'A10':
00208                     {
00209                         $size = array
00210                             (
00211                             0,
00212                             0,
00213                             73.70,
00214                             104.88
00215                             );
00216 
00217                         break;
00218                     }
00219 
00220                 case 'B0':
00221                     {
00222                         $size = array
00223                             (
00224                             0,
00225                             0,
00226                             2834.65,
00227                             4008.19
00228                             );
00229 
00230                         break;
00231                     }
00232 
00233                 case 'B1':
00234                     {
00235                         $size = array
00236                             (
00237                             0,
00238                             0,
00239                             2004.09,
00240                             2834.65
00241                             );
00242 
00243                         break;
00244                     }
00245 
00246                 case 'B2':
00247                     {
00248                         $size = array
00249                             (
00250                             0,
00251                             0,
00252                             1417.32,
00253                             2004.09
00254                             );
00255 
00256                         break;
00257                     }
00258 
00259                 case 'B3':
00260                     {
00261                         $size = array
00262                             (
00263                             0,
00264                             0,
00265                             1000.63,
00266                             1417.32
00267                             );
00268 
00269                         break;
00270                     }
00271 
00272                 case 'B4':
00273                     {
00274                         $size = array
00275                             (
00276                             0,
00277                             0,
00278                             708.66,
00279                             1000.63
00280                             );
00281 
00282                         break;
00283                     }
00284 
00285                 case 'B5':
00286                     {
00287                         $size = array
00288                             (
00289                             0,
00290                             0,
00291                             498.90,
00292                             708.66
00293                             );
00294 
00295                         break;
00296                     }
00297 
00298                 case 'B6':
00299                     {
00300                         $size = array
00301                             (
00302                             0,
00303                             0,
00304                             354.33,
00305                             498.90
00306                             );
00307 
00308                         break;
00309                     }
00310 
00311                 case 'B7':
00312                     {
00313                         $size = array
00314                             (
00315                             0,
00316                             0,
00317                             249.45,
00318                             354.33
00319                             );
00320 
00321                         break;
00322                     }
00323 
00324                 case 'B8':
00325                     {
00326                         $size = array
00327                             (
00328                             0,
00329                             0,
00330                             175.75,
00331                             249.45
00332                             );
00333 
00334                         break;
00335                     }
00336 
00337                 case 'B9':
00338                     {
00339                         $size = array
00340                             (
00341                             0,
00342                             0,
00343                             124.72,
00344                             175.75
00345                             );
00346 
00347                         break;
00348                     }
00349 
00350                 case 'B10':
00351                     {
00352                         $size = array
00353                             (
00354                             0,
00355                             0,
00356                             87.87,
00357                             124.72
00358                             );
00359 
00360                         break;
00361                     }
00362 
00363                 case 'C0':
00364                     {
00365                         $size = array
00366                             (
00367                             0,
00368                             0,
00369                             2599.37,
00370                             3676.54
00371                             );
00372 
00373                         break;
00374                     }
00375 
00376                 case 'C1':
00377                     {
00378                         $size = array
00379                             (
00380                             0,
00381                             0,
00382                             1836.85,
00383                             2599.37
00384                             );
00385 
00386                         break;
00387                     }
00388 
00389                 case 'C2':
00390                     {
00391                         $size = array
00392                             (
00393                             0,
00394                             0,
00395                             1298.27,
00396                             1836.85
00397                             );
00398 
00399                         break;
00400                     }
00401 
00402                 case 'C3':
00403                     {
00404                         $size = array
00405                             (
00406                             0,
00407                             0,
00408                             918.43,
00409                             1298.27
00410                             );
00411 
00412                         break;
00413                     }
00414 
00415                 case 'C4':
00416                     {
00417                         $size = array
00418                             (
00419                             0,
00420                             0,
00421                             649.13,
00422                             918.43
00423                             );
00424 
00425                         break;
00426                     }
00427 
00428                 case 'C5':
00429                     {
00430                         $size = array
00431                             (
00432                             0,
00433                             0,
00434                             459.21,
00435                             649.13
00436                             );
00437 
00438                         break;
00439                     }
00440 
00441                 case 'C6':
00442                     {
00443                         $size = array
00444                             (
00445                             0,
00446                             0,
00447                             323.15,
00448                             459.21
00449                             );
00450 
00451                         break;
00452                     }
00453 
00454                 case 'C7':
00455                     {
00456                         $size = array
00457                             (
00458                             0,
00459                             0,
00460                             229.61,
00461                             323.15
00462                             );
00463 
00464                         break;
00465                     }
00466 
00467                 case 'C8':
00468                     {
00469                         $size = array
00470                             (
00471                             0,
00472                             0,
00473                             161.57,
00474                             229.61
00475                             );
00476 
00477                         break;
00478                     }
00479 
00480                 case 'C9':
00481                     {
00482                         $size = array
00483                             (
00484                             0,
00485                             0,
00486                             113.39,
00487                             161.57
00488                             );
00489 
00490                         break;
00491                     }
00492 
00493                 case 'C10':
00494                     {
00495                         $size = array
00496                             (
00497                             0,
00498                             0,
00499                             79.37,
00500                             113.39
00501                             );
00502 
00503                         break;
00504                     }
00505 
00506                 case 'RA0':
00507                     {
00508                         $size = array
00509                             (
00510                             0,
00511                             0,
00512                             2437.80,
00513                             3458.27
00514                             );
00515 
00516                         break;
00517                     }
00518 
00519                 case 'RA1':
00520                     {
00521                         $size = array
00522                             (
00523                             0,
00524                             0,
00525                             1729.13,
00526                             2437.80
00527                             );
00528 
00529                         break;
00530                     }
00531 
00532                 case 'RA2':
00533                     {
00534                         $size = array
00535                             (
00536                             0,
00537                             0,
00538                             1218.90,
00539                             1729.13
00540                             );
00541 
00542                         break;
00543                     }
00544 
00545                 case 'RA3':
00546                     {
00547                         $size = array
00548                             (
00549                             0,
00550                             0,
00551                             864.57,
00552                             1218.90
00553                             );
00554 
00555                         break;
00556                     }
00557 
00558                 case 'RA4':
00559                     {
00560                         $size = array
00561                             (
00562                             0,
00563                             0,
00564                             609.45,
00565                             864.57
00566                             );
00567 
00568                         break;
00569                     }
00570 
00571                 case 'SRA0':
00572                     {
00573                         $size = array
00574                             (
00575                             0,
00576                             0,
00577                             2551.18,
00578                             3628.35
00579                             );
00580 
00581                         break;
00582                     }
00583 
00584                 case 'SRA1':
00585                     {
00586                         $size = array
00587                             (
00588                             0,
00589                             0,
00590                             1814.17,
00591                             2551.18
00592                             );
00593 
00594                         break;
00595                     }
00596 
00597                 case 'SRA2':
00598                     {
00599                         $size = array
00600                             (
00601                             0,
00602                             0,
00603                             1275.59,
00604                             1814.17
00605                             );
00606 
00607                         break;
00608                     }
00609 
00610                 case 'SRA3':
00611                     {
00612                         $size = array
00613                             (
00614                             0,
00615                             0,
00616                             907.09,
00617                             1275.59
00618                             );
00619 
00620                         break;
00621                     }
00622 
00623                 case 'SRA4':
00624                     {
00625                         $size = array
00626                             (
00627                             0,
00628                             0,
00629                             637.80,
00630                             907.09
00631                             );
00632 
00633                         break;
00634                     }
00635 
00636                 case 'LETTER':
00637                     {
00638                         $size = array
00639                             (
00640                             0,
00641                             0,
00642                             612.00,
00643                             792.00
00644                             );
00645 
00646                         break;
00647                     }
00648 
00649                 case 'LEGAL':
00650                     {
00651                         $size = array
00652                             (
00653                             0,
00654                             0,
00655                             612.00,
00656                             1008.00
00657                             );
00658 
00659                         break;
00660                     }
00661 
00662                 case 'EXECUTIVE':
00663                     {
00664                         $size = array
00665                             (
00666                             0,
00667                             0,
00668                             521.86,
00669                             756.00
00670                             );
00671 
00672                         break;
00673                     }
00674 
00675                 case 'FOLIO':
00676                     {
00677                         $size = array
00678                             (
00679                             0,
00680                             0,
00681                             612.00,
00682                             936.00
00683                             );
00684 
00685                         break;
00686                     }
00687                 }
00688 
00689             switch (strtolower($orientation))
00690                 {
00691                 case 'landscape':
00692                     $a = $size[3];
00693 
00694                     $size[3] = $size[2];
00695                     $size[2] = $a;
00696                     break;
00697                 }
00698         }
00699         else
00700         {
00701             if (count($paper) > 2)
00702             {
00703                 // then an array was sent it to set the size
00704                 $size = $paper;
00705             }
00706             else
00707             { //size in centimeters has been passed
00708                 $size[0] = 0;
00709                 $size[1] = 0;
00710                 $size[2] = ($paper[0] / 2.54) * 72;
00711                 $size[3] = ($paper[1] / 2.54) * 72;
00712             }
00713         }
00714 
00715         $this->Cpdf($size);
00716         $this->ez['pageWidth'] = $size[2];
00717         $this->ez['pageHeight'] = $size[3];
00718 
00719         // also set the margins to some reasonable defaults
00720         $this->ez['topMargin'] = 30;
00721         $this->ez['bottomMargin'] = 30;
00722         $this->ez['leftMargin'] = 30;
00723         $this->ez['rightMargin'] = 30;
00724 
00725         // set the current writing position to the top of the first page
00726         $this->y = $this->ez['pageHeight'] - $this->ez['topMargin'];
00727         // and get the ID of the page that was created during the instancing process.
00728         $this->ezPages[1] = $this->getFirstPageId();
00729         $this->ezPageCount = 1;
00730     }
00731 
00732     // ------------------------------------------------------------------------------
00733     // 2002-07-24: Nicola Asuni (info@tecnick.com)
00734     // Set Margins in centimeters
00735     function ezSetCmMargins($top, $bottom, $left, $right)
00736     {
00737         $top = ($top / 2.54) * 72;
00738         $bottom = ($bottom / 2.54) * 72;
00739         $left = ($left / 2.54) * 72;
00740         $right = ($right / 2.54) * 72;
00741         $this->ezSetMargins($top, $bottom, $left, $right);
00742     }
00743     // ------------------------------------------------------------------------------
00744 
00745     function ezColumnsStart($options = array(
00746         ))
00747     {
00748         // start from the current y-position, make the set number of columne
00749         if (isset($this->ez['columns']) && $this->ez['columns'] == 1)
00750         {
00751             // if we are already in a column mode then just return.
00752             return;
00753         }
00754 
00755         $def = array
00756             (
00757             'gap' => 10,
00758             'num' => 2
00759             );
00760 
00761         foreach ($def as $k => $v)
00762         {
00763             if (!isset($options[$k]))
00764             {
00765                 $options[$k] = $v;
00766             }
00767         }
00768 
00769         // setup the columns
00770         $this->ez['columns'] = array
00771             (
00772             'on' => 1,
00773             'colNum' => 1
00774             );
00775 
00776         // store the current margins
00777         $this->ez['columns']['margins'] = array
00778             (
00779             $this->ez['leftMargin'],
00780             $this->ez['rightMargin'],
00781             $this->ez['topMargin'],
00782             $this->ez['bottomMargin']
00783             );
00784 
00785         // and store the settings for the columns
00786         $this->ez['columns']['options'] = $options;
00787         // then reset the margins to suit the new columns
00788         // safe enough to assume the first column here, but start from the current y-position
00789         $this->ez['topMargin'] = $this->ez['pageHeight'] - $this->y;
00790         $width = ($this->ez['pageWidth'] - $this->ez['leftMargin'] - $this->ez['rightMargin'] - ($options['num'] - 1)
00791                      * $options['gap']) / $options['num'];
00792         $this->ez['columns']['width'] = $width;
00793         $this->ez['rightMargin'] = $this->ez['pageWidth'] - $this->ez['leftMargin'] - $width;
00794     }
00795 
00796     // ------------------------------------------------------------------------------
00797     function ezColumnsStop()
00798     {
00799         if (isset($this->ez['columns']) && $this->ez['columns']['on'] == 1)
00800         {
00801             $this->ez['columns']['on'] = 0;
00802             $this->ez['leftMargin'] = $this->ez['columns']['margins'][0];
00803             $this->ez['rightMargin'] = $this->ez['columns']['margins'][1];
00804             $this->ez['topMargin'] = $this->ez['columns']['margins'][2];
00805             $this->ez['bottomMargin'] = $this->ez['columns']['margins'][3];
00806         }
00807     }
00808 
00809     // ------------------------------------------------------------------------------
00810     function ezInsertMode($status = 1, $pageNum = 1, $pos = 'before')
00811     {
00812         // puts the document into insert mode. new pages are inserted until this is re-called with status=0
00813         // by default pages wil be inserted at the start of the document
00814         switch ($status)
00815             {
00816             case '1':
00817                 if (isset($this->ezPages[$pageNum]))
00818                 {
00819                     $this->ez['insertMode'] = 1;
00820                     $this->ez['insertOptions'] = array
00821                         (
00822                         'id' => $this->ezPages[$pageNum],
00823                         'pos' => $pos
00824                         );
00825                 }
00826 
00827                 break;
00828 
00829             case '0':
00830                 $this->ez['insertMode'] = 0;
00831 
00832                 break;
00833             }
00834     }
00835     // ------------------------------------------------------------------------------
00836 
00837     function ezNewPage()
00838     {
00839         $pageRequired = 1;
00840 
00841         if (isset($this->ez['columns']) && $this->ez['columns']['on'] == 1)
00842         {
00843             // check if this is just going to a new column
00844             // increment the column number
00845             //echo 'HERE<br>';
00846             $this->ez['columns']['colNum']++;
00847 
00848             //echo $this->ez['columns']['colNum'].'<br>';
00849             if ($this->ez['columns']['colNum'] <= $this->ez['columns']['options']['num'])
00850             {
00851                 // then just reset to the top of the next column
00852                 $pageRequired = 0;
00853             }
00854             else
00855             {
00856                 $this->ez['columns']['colNum'] = 1;
00857                 $this->ez['topMargin'] = $this->ez['columns']['margins'][2];
00858             }
00859 
00860             $width = $this->ez['columns']['width'];
00861             $this->ez['leftMargin'] = $this->ez['columns']['margins'][0] + ($this->ez['columns']['colNum'] - 1)
00862                                           * ($this->ez['columns']['options']['gap'] + $width);
00863             $this->ez['rightMargin'] = $this->ez['pageWidth'] - $this->ez['leftMargin'] - $width;
00864         }
00865         //echo 'left='.$this->ez['leftMargin'].'   right='.$this->ez['rightMargin'].'<br>';
00866 
00867         if ($pageRequired)
00868         {
00869             // make a new page, setting the writing point back to the top
00870             $this->y = $this->ez['pageHeight'] - $this->ez['topMargin'];
00871             // make the new page with a call to the basic class.
00872             $this->ezPageCount++;
00873 
00874             if (isset($this->ez['insertMode']) && $this->ez['insertMode'] == 1)
00875             {
00876                 $id = $this->ezPages[$this->ezPageCount] = $this->newPage(1, $this->ez['insertOptions']['id'],
00877                                                                           $this->ez['insertOptions']['pos']);
00878                 // then manipulate the insert options so that inserted pages follow each other
00879                 $this->ez['insertOptions']['id'] = $id;
00880                 $this->ez['insertOptions']['pos'] = 'after';
00881             }
00882             else
00883             {
00884                 $this->ezPages[$this->ezPageCount] = $this->newPage();
00885             }
00886         }
00887         else
00888         {
00889             $this->y = $this->ez['pageHeight'] - $this->ez['topMargin'];
00890         }
00891     }
00892 
00893     // ------------------------------------------------------------------------------
00894 
00895     function ezSetMargins($top, $bottom, $left, $right)
00896     {
00897         // sets the margins to new values
00898         $this->ez['topMargin'] = $top;
00899         $this->ez['bottomMargin'] = $bottom;
00900         $this->ez['leftMargin'] = $left;
00901         $this->ez['rightMargin'] = $right;
00902 
00903         // check to see if this means that the current writing position is outside the 
00904         // writable area
00905         if ($this->y > $this->ez['pageHeight'] - $top)
00906         {
00907             // then move y down
00908             $this->y = $this->ez['pageHeight'] - $top;
00909         }
00910 
00911         if ($this->y < $bottom)
00912         {
00913             // then make a new page
00914             $this->ezNewPage();
00915         }
00916     }
00917 
00918     // ------------------------------------------------------------------------------
00919 
00920     function ezGetCurrentPageNumber()
00921     {
00922         // return the strict numbering (1,2,3,4..) number of the current page
00923         return $this->ezPageCount;
00924     }
00925 
00926     // ------------------------------------------------------------------------------
00927 
00928     function ezStartPageNumbers($x, $y, $size, $pos = 'left', $pattern = '{PAGENUM} of {TOTALPAGENUM}', $num = '')
00929     {
00930         // put page numbers on the pages from here.
00931         // place then on the 'pos' side of the coordinates (x,y).
00932         // pos can be 'left' or 'right'
00933         // use the given 'pattern' for display, where (PAGENUM} and {TOTALPAGENUM} are replaced
00934         // as required.
00935         // if $num is set, then make the first page this number, the number of total pages will
00936         // be adjusted to account for this.
00937         // Adjust this function so that each time you 'start' page numbers then you effectively start a different batch
00938         // return the number of the batch, so that they can be stopped in a different order if required.
00939         if (!$pos || !strlen($pos))
00940         {
00941             $pos = 'left';
00942         }
00943 
00944         if (!$pattern || !strlen($pattern))
00945         {
00946             $pattern = '{PAGENUM} of {TOTALPAGENUM}';
00947         }
00948 
00949         if (!isset($this->ez['pageNumbering']))
00950         {
00951             $this->ez['pageNumbering'] = array(
00952                 );
00953         }
00954 
00955         $i = count($this->ez['pageNumbering']);
00956         $this->ez['pageNumbering'][$i][$this->ezPageCount] = array
00957             (
00958             'x' => $x,
00959             'y' => $y,
00960             'pos' => $pos,
00961             'pattern' => $pattern,
00962             'num' => $num,
00963             'size' => $size
00964             );
00965 
00966         return $i;
00967     }
00968 
00969     // ------------------------------------------------------------------------------
00970 
00971     function ezWhatPageNumber($pageNum, $i = 0)
00972     {
00973         // given a particular generic page number (ie, document numbered sequentially from beginning),
00974         // return the page number under a particular page numbering scheme ($i)
00975         $num = 0;
00976         $start = 1;
00977         $startNum = 1;
00978 
00979         if (!isset($this->ez['pageNumbering']))
00980         {
00981             $this->addMessage('WARNING: page numbering called for and wasn\'t started with ezStartPageNumbers');
00982             return 0;
00983         }
00984 
00985         foreach ($this->ez['pageNumbering'][$i] as $k => $v)
00986         {
00987             if ($k <= $pageNum)
00988             {
00989                 if (is_array($v))
00990                 {
00991                     // start block
00992                     if (strlen($v['num']))
00993                     {
00994                         // a start was specified
00995                         $start = $v['num'];
00996                         $startNum = $k;
00997                         $num = $pageNum - $startNum + $start;
00998                     }
00999                 }
01000                 else
01001                 {
01002                     // stop block
01003                     $num = 0;
01004                 }
01005             }
01006         }
01007 
01008         return $num;
01009     }
01010 
01011     // ------------------------------------------------------------------------------
01012 
01013     function ezStopPageNumbers($stopTotal = 0, $next = 0, $i = 0)
01014     {
01015         // if stopTotal=1 then the totalling of pages for this number will stop too
01016         // if $next=1, then do this page, but not the next, else do not do this page either
01017         // if $i is set, then stop that particular pagenumbering sequence.
01018         if (!isset($this->ez['pageNumbering']))
01019         {
01020             $this->ez['pageNumbering'] = array(
01021                 );
01022         }
01023 
01024         if ($next && isset($this->ez['pageNumbering'][$i][$this->ezPageCount]) && is_array(
01025                                                                                       $this->ez['pageNumbering'][$i][$this->ezPageCount]))
01026         {
01027             // then this has only just been started, this will over-write the start, and nothing will appear
01028             // add a special command to the start block, telling it to stop as well
01029             if ($stopTotal)
01030             {
01031                 $this->ez['pageNumbering'][$i][$this->ezPageCount]['stoptn'] = 1;
01032             }
01033             else
01034             {
01035                 $this->ez['pageNumbering'][$i][$this->ezPageCount]['stopn'] = 1;
01036             }
01037         }
01038         else
01039         {
01040             if ($stopTotal)
01041             {
01042                 $this->ez['pageNumbering'][$i][$this->ezPageCount] = 'stopt';
01043             }
01044             else
01045             {
01046                 $this->ez['pageNumbering'][$i][$this->ezPageCount] = 'stop';
01047             }
01048 
01049             if ($next)
01050             {
01051                 $this->ez['pageNumbering'][$i][$this->ezPageCount] .= 'n';
01052             }
01053         }
01054     }
01055 
01056     // ------------------------------------------------------------------------------
01057 
01058     function ezPRVTpageNumberSearch($lbl, &$tmp)
01059     {
01060         foreach ($tmp as $i => $v)
01061         {
01062             if (is_array($v))
01063             {
01064                 if (isset($v[$lbl]))
01065                 {
01066                     return $i;
01067                 }
01068             }
01069             else
01070             {
01071                 if ($v == $lbl)
01072                 {
01073                     return $i;
01074                 }
01075             }
01076         }
01077 
01078         return 0;
01079     }
01080 
01081     // ------------------------------------------------------------------------------
01082 
01083     function ezPRVTaddPageNumbers()
01084     {
01085         // this will go through the pageNumbering array and add the page numbers are required
01086         if (isset($this->ez['pageNumbering']))
01087         {
01088             $totalPages1 = $this->ezPageCount;
01089             $tmp1 = $this->ez['pageNumbering'];
01090             $status = 0;
01091 
01092             foreach ($tmp1 as $i => $tmp)
01093             {
01094                 // do each of the page numbering systems
01095                 // firstly, find the total pages for this one
01096                 $k = $this->ezPRVTpageNumberSearch('stopt', $tmp);
01097 
01098                 if ($k && $k > 0)
01099                 {
01100                     $totalPages = $k - 1;
01101                 }
01102                 else
01103                 {
01104                     $l = $this->ezPRVTpageNumberSearch('stoptn', $tmp);
01105 
01106                     if ($l && $l > 0)
01107                     {
01108                         $totalPages = $l;
01109                     }
01110                     else
01111                     {
01112                         $totalPages = $totalPages1;
01113                     }
01114                 }
01115 
01116                 foreach ($this->ezPages as $pageNum => $id)
01117                 {
01118                     if (isset($tmp[$pageNum]))
01119                     {
01120                         if (is_array($tmp[$pageNum]))
01121                         {
01122                             // then this must be starting page numbers
01123                             $status = 1;
01124                             $info = $tmp[$pageNum];
01125                             $info['dnum'] = $info['num'] - $pageNum;
01126 
01127                             // also check for the special case of the numbering stopping and starting on the same page
01128                             if (isset($info['stopn']) || isset($info['stoptn']))
01129                             {
01130                                 $status = 2;
01131                             }
01132                         }
01133                         else if ($tmp[$pageNum] == 'stop' || $tmp[$pageNum] == 'stopt')
01134                         {
01135                             // then we are stopping page numbers
01136                             $status = 0;
01137                         }
01138                         else if ($status == 1 && ($tmp[$pageNum] == 'stoptn' || $tmp[$pageNum] == 'stopn'))
01139                         {
01140                             // then we are stopping page numbers
01141                             $status = 2;
01142                         }
01143                     }
01144 
01145                     if ($status)
01146                     {
01147                         // then add the page numbering to this page
01148                         if (strlen($info['num']))
01149                         {
01150                             $num = $pageNum + $info['dnum'];
01151                         }
01152                         else
01153                         {
01154                             $num = $pageNum;
01155                         }
01156 
01157                         $total = $totalPages + $num - $pageNum;
01158                         $pat = str_replace('{PAGENUM}', $num, $info['pattern']);
01159                         $pat = str_replace('{TOTALPAGENUM}', $total, $pat);
01160                         $this->reopenObject($id);
01161 
01162                         switch ($info['pos'])
01163                             {
01164                             case 'right':
01165                                 $this->addText($info['x'], $info['y'], $info['size'], $pat);
01166 
01167                                 break;
01168 
01169                             default:
01170                                 $w = $this->getTextWidth($info['size'], $pat);
01171 
01172                                 $this->addText($info['x'] - $w, $info['y'], $info['size'], $pat);
01173                                 break;
01174                             }
01175 
01176                         $this->closeObject();
01177                     }
01178 
01179                     if ($status == 2)
01180                     {
01181                         $status = 0;
01182                     }
01183                 }
01184             }
01185         }
01186     }
01187 
01188     // ------------------------------------------------------------------------------
01189 
01190     function ezPRVTcleanUp()
01191     {
01192         $this->ezPRVTaddPageNumbers();
01193     }
01194 
01195     // ------------------------------------------------------------------------------
01196 
01197     function ezStream($options = '')
01198     {
01199         $this->ezPRVTcleanUp();
01200         $this->stream($options);
01201     }
01202 
01203     // ------------------------------------------------------------------------------
01204 
01205     function ezOutput($options = 0)
01206     {
01207         $this->ezPRVTcleanUp();
01208         return $this->output($options);
01209     }
01210 
01211     // ------------------------------------------------------------------------------
01212 
01213     function ezSetY($y)
01214     {
01215         // used to change the vertical position of the writing point.
01216         $this->y = $y;
01217 
01218         if ($this->y < $this->ez['bottomMargin'])
01219         {
01220             // then make a new page
01221             $this->ezNewPage();
01222         }
01223     }
01224 
01225     // ------------------------------------------------------------------------------
01226 
01227     function ezSetDy($dy, $mod = '')
01228     {
01229         // used to change the vertical position of the writing point.
01230         // changes up by a positive increment, so enter a negative number to go
01231         // down the page
01232         // if $mod is set to 'makeSpace' and a new page is forced, then the pointed will be moved 
01233         // down on the new page, this will allow space to be reserved for graphics etc.
01234         $this->y += $dy;
01235 
01236         if ($this->y < $this->ez['bottomMargin'])
01237         {
01238             // then make a new page
01239             $this->ezNewPage();
01240 
01241             if ($mod == 'makeSpace')
01242             {
01243                 $this->y += $dy;
01244             }
01245         }
01246     }
01247 
01248     // ------------------------------------------------------------------------------
01249 
01250     function ezPrvtTableDrawLines($pos, $gap, $x0, $x1, $y0, $y1, $y2, $col, $inner, $outer, $opt = 1)
01251     {
01252         $x0 = 1000;
01253         $x1 = 0;
01254         $this->setStrokeColor($col[0], $col[1], $col[2]);
01255         $cnt = 0;
01256         $n = count($pos);
01257 
01258         foreach ($pos as $x)
01259         {
01260             $cnt++;
01261 
01262             if ($cnt == 1 || $cnt == $n)
01263             {
01264                 $this->setLineStyle($outer);
01265             }
01266             else
01267             {
01268                 $this->setLineStyle($inner);
01269             }
01270 
01271             $this->line($x - $gap / 2, $y0, $x - $gap / 2, $y2);
01272 
01273             if ($x > $x1)
01274             {
01275                 $x1 = $x;
01276             }
01277 
01278             ;
01279 
01280             if ($x < $x0)
01281             {
01282                 $x0 = $x;
01283             }
01284 
01285             ;
01286         }
01287 
01288         $this->setLineStyle($outer);
01289         $this->line($x0 - $gap / 2 - $outer / 2, $y0, $x1 - $gap / 2 + $outer / 2, $y0);
01290 
01291         // only do the second line if it is different to the first, AND each row does not have
01292         // a line on it.
01293         if ($y0 != $y1 && $opt < 2)
01294         {
01295             $this->line($x0 - $gap / 2, $y1, $x1 - $gap / 2, $y1);
01296         }
01297 
01298         $this->line($x0 - $gap / 2 - $outer / 2, $y2, $x1 - $gap / 2 + $outer / 2, $y2);
01299     }
01300 
01301     // ------------------------------------------------------------------------------
01302 
01303     function ezPrvtTableColumnHeadings($cols, $pos, $maxWidth, $height, $decender, $gap, $size, &$y,
01304                                        $optionsAll = array(
01305         ))
01306     {
01307         // uses ezText to add the text, and returns the height taken by the largest heading
01308         // this page will move the headings to a new page if they will not fit completely on this one
01309         // transaction support will be used to implement this
01310 
01311         if (isset($optionsAll['cols']))
01312         {
01313             $options = $optionsAll['cols'];
01314         }
01315         else
01316         {
01317             $options = array(
01318                 );
01319         }
01320 
01321         $mx = 0;
01322         $startPage = $this->ezPageCount;
01323         $secondGo = 0;
01324 
01325         // $y is the position at which the top of the table should start, so the base
01326         // of the first text, is $y-$height-$gap-$decender, but ezText starts by dropping $height
01327 
01328         // the return from this function is the total cell height, including gaps, and $y is adjusted
01329         // to be the postion of the bottom line
01330 
01331         // begin the transaction
01332         $this->transaction('start');
01333         $ok = 0;
01334         //  $y-=$gap-$decender;
01335         $y -= $gap;
01336 
01337         while ($ok == 0)
01338         {
01339             foreach ($cols as $colName => $colHeading)
01340             {
01341                 $this->ezSetY($y);
01342 
01343                 if (isset($options[$colName]) && isset($options[$colName]['justification']))
01344                 {
01345                     $justification = $options[$colName]['justification'];
01346                 }
01347                 else
01348                 {
01349                     $justification = 'left';
01350                 }
01351 
01352                 $this->ezText($colHeading,
01353                               $size,
01354                               array('aleft' => $pos[$colName], 'aright' => ($maxWidth[$colName] + $pos[$colName]),
01355                                     'justification' => $justification));
01356                 $dy = $y - $this->y;
01357 
01358                 if ($dy > $mx)
01359                 {
01360                     $mx = $dy;
01361                 }
01362             }
01363 
01364             $y = $y - $mx - $gap + $decender;
01365 
01366             //    $y -= $mx-$gap+$decender;
01367 
01368             // now, if this has moved to a new page, then abort the transaction, move to a new page, and put it there
01369             // do not check on the second time around, to avoid an infinite loop
01370             if ($this->ezPageCount != $startPage && $secondGo == 0)
01371             {
01372                 $this->transaction('rewind');
01373                 $this->ezNewPage();
01374                 $y = $this->y - $gap - $decender;
01375                 $ok = 0;
01376                 $secondGo = 1;
01377                 //      $y = $store_y;
01378                 $mx = 0;
01379             }
01380             else
01381             {
01382                 $this->transaction('commit');
01383                 $ok = 1;
01384             }
01385         }
01386 
01387         return $mx + $gap * 2 - $decender;
01388     }
01389 
01390     // ------------------------------------------------------------------------------
01391 
01392     function ezPrvtGetTextWidth($size, $text)
01393     {
01394         // will calculate the maximum width, taking into account that the text may be broken
01395         // by line breaks.
01396         $mx = 0;
01397         $lines = explode("\n", $text);
01398 
01399         foreach ($lines as $line)
01400         {
01401             $w = $this->getTextWidth($size, $line);
01402 
01403             if ($w > $mx)
01404             {
01405                 $mx = $w;
01406             }
01407         }
01408 
01409         return $mx;
01410     }
01411 
01412     // ------------------------------------------------------------------------------
01413 
01414     function ezTable(&$data, $cols = '', $title = '', $options = '')
01415     {
01416         // add a table of information to the pdf document
01417         // $data is a two dimensional array
01418         // $cols (optional) is an associative array, the keys are the names of the columns from $data
01419         // to be presented (and in that order), the values are the titles to be given to the columns
01420         // $title (optional) is the title to be put on the top of the table
01421         //
01422         // $options is an associative array which can contain:
01423         // 'showLines'=> 0,1,2, default is 1 (show outside and top lines only), 2=> lines on each row
01424         // 'showHeadings' => 0 or 1
01425         // 'shaded'=> 0,1,2,3 default is 1 (1->alternate lines are shaded, 0->no shading, 2-> both shaded, second uses shadeCol2)
01426         // 'shadeCol' => (r,g,b) array, defining the colour of the shading, default is (0.8,0.8,0.8)
01427         // 'shadeCol2' => (r,g,b) array, defining the colour of the shading of the other blocks, default is (0.7,0.7,0.7)
01428         // 'fontSize' => 10
01429         // 'textCol' => (r,g,b) array, text colour
01430         // 'titleFontSize' => 12
01431         // 'rowGap' => 2 , the space added at the top and bottom of each row, between the text and the lines
01432         // 'colGap' => 5 , the space on the left and right sides of each cell
01433         // 'lineCol' => (r,g,b) array, defining the colour of the lines, default, black.
01434         // 'xPos' => 'left','right','center','centre',or coordinate, reference coordinate in the x-direction
01435         // 'xOrientation' => 'left','right','center','centre', position of the table w.r.t 'xPos' 
01436         // 'width'=> <number> which will specify the width of the table, if it turns out to not be this
01437         //    wide, then it will stretch the table to fit, if it is wider then each cell will be made
01438         //    proportionalty smaller, and the content may have to wrap.
01439         // 'maxWidth'=> <number> similar to 'width', but will only make table smaller than it wants to be
01440         // 'options' => array(<colname>=>array('justification'=>'left','width'=>100,'link'=>linkDataName),<colname>=>....)
01441         //             allow the setting of other paramaters for the individual columns
01442         // 'minRowSpace'=> the minimum space between the bottom of each row and the bottom margin, in which a new row will be started
01443         //                  if it is less, then a new page would be started, default=-100
01444         // 'innerLineThickness'=>1
01445         // 'outerLineThickness'=>1
01446         // 'splitRows'=>0, 0 or 1, whether or not to allow the rows to be split across page boundaries
01447         // 'protectRows'=>number, the number of rows to hold with the heading on page, ie, if there less than this number of
01448         //                rows on the page, then move the whole lot onto the next page, default=1
01449         //
01450         // note that the user will have had to make a font selection already or this will not 
01451         // produce a valid pdf file.
01452 
01453         if (!is_array($data))
01454         {
01455             return;
01456         }
01457 
01458         if (!is_array($cols))
01459         {
01460             // take the columns from the first row of the data set
01461             reset ($data);
01462             list($k, $v) = each($data);
01463 
01464             if (!is_array($v))
01465             {
01466                 return;
01467             }
01468 
01469             $cols = array(
01470                 );
01471 
01472             foreach ($v as $k1 => $v1)
01473             {
01474                 $cols[$k1] = $k1;
01475             }
01476         }
01477 
01478         if (!is_array($options))
01479         {
01480             $options = array(
01481                 );
01482         }
01483 
01484         $defaults = array
01485             (
01486             'shaded' => 1,
01487             'showLines' => 1,
01488             'shadeCol' => array(0.8, 0.8, 0.8),
01489             'shadeCol2' => array(0.7, 0.7, 0.7),
01490             'fontSize' => 10,
01491             'titleFontSize' => 12,
01492             'titleGap' => 5,
01493             'lineCol' => array(0, 0, 0),
01494             'gap' => 5,
01495             'xPos' => 'centre',
01496             'xOrientation' => 'centre',
01497             'showHeadings' => 1,
01498             'textCol' => array(0, 0, 0),
01499             'width' => 0,
01500             'maxWidth' => 0,
01501             'cols' => array(
01502                 ),
01503             'minRowSpace' => -100,
01504             'rowGap' => 2,
01505             'colGap' => 5,
01506             'innerLineThickness' => 1,
01507             'outerLineThickness' => 1,
01508             'splitRows' => 0,
01509             'protectRows' => 1
01510             );
01511 
01512         foreach ($defaults as $key => $value)
01513         {
01514             if (is_array($value))
01515             {
01516                 if (!isset($options[$key]) || !is_array($options[$key]))
01517                 {
01518                     $options[$key] = $value;
01519                 }
01520             }
01521             else
01522             {
01523                 if (!isset($options[$key]))
01524                 {
01525                     $options[$key] = $value;
01526                 }
01527             }
01528         }
01529 
01530         $options['gap'] = 2 * $options['colGap'];
01531 
01532         $middle = ($this->ez['pageWidth'] - $this->ez['rightMargin']) / 2 + ($this->ez['leftMargin']) / 2;
01533         // figure out the maximum widths of the text within each column
01534         $maxWidth = array(
01535             );
01536 
01537         foreach ($cols as $colName => $colHeading)
01538         {
01539             $maxWidth[$colName] = 0;
01540         }
01541 
01542         // find the maximum cell widths based on the data
01543         foreach ($data as $row)
01544         {
01545             foreach ($cols as $colName => $colHeading)
01546             {
01547                 $w = $this->ezPrvtGetTextWidth($options['fontSize'], (string)$row[$colName]) * 1.01;
01548 
01549                 if ($w > $maxWidth[$colName])
01550                 {
01551                     $maxWidth[$colName] = $w;
01552                 }
01553             }
01554         }
01555 
01556         // and the maximum widths to fit in the headings
01557         foreach ($cols as $colName => $colTitle)
01558         {
01559             $w = $this->ezPrvtGetTextWidth($options['fontSize'], (string)$colTitle) * 1.01;
01560 
01561             if ($w > $maxWidth[$colName])
01562             {
01563                 $maxWidth[$colName] = $w;
01564             }
01565         }
01566 
01567         // calculate the start positions of each of the columns
01568         $pos = array(
01569             );
01570 
01571         $x = 0;
01572         $t = $x;
01573         $adjustmentWidth = 0;
01574         $setWidth = 0;
01575 
01576         foreach ($maxWidth as $colName => $w)
01577         {
01578             $pos[$colName] = $t;
01579 
01580             // if the column width has been specified then set that here, also total the
01581             // width avaliable for adjustment
01582             if (isset($options['cols'][$colName]) && isset($options['cols'][$colName]['width'])
01583                 && $options['cols'][$colName]['width'] > 0)
01584             {
01585                 $t = $t + $options['cols'][$colName]['width'];
01586                 $maxWidth[$colName] = $options['cols'][$colName]['width'] - $options['gap'];
01587                 $setWidth += $options['cols'][$colName]['width'];
01588             }
01589             else
01590             {
01591                 $t = $t + $w + $options['gap'];
01592                 $adjustmentWidth += $w;
01593                 $setWidth += $options['gap'];
01594             }
01595         }
01596 
01597         $pos['_end_'] = $t;
01598 
01599         // if maxWidth is specified, and the table is too wide, and the width has not been set,
01600         // then set the width.
01601         if ($options['width'] == 0 && $options['maxWidth'] && ($t - $x) > $options['maxWidth'])
01602         {
01603             // then need to make this one smaller
01604             $options['width'] = $options['maxWidth'];
01605         }
01606 
01607         if ($options['width'] && $adjustmentWidth > 0 && $setWidth < $options['width'])
01608         {
01609             // first find the current widths of the columns involved in this mystery
01610             $cols0 = array(
01611                 );
01612 
01613             $cols1 = array(
01614                 );
01615 
01616             $xq = 0;
01617             $presentWidth = 0;
01618             $last = '';
01619 
01620             foreach ($pos as $colName => $p)
01621             {
01622                 if (!isset($options['cols'][$last]) || !isset($options['cols'][$last]['width'])
01623                                                            || $options['cols'][$last]['width'] <= 0)
01624                 {
01625                     if (strlen($last))
01626                     {
01627                         $cols0[$last] = $p - $xq - $options['gap'];
01628                         $presentWidth += ($p - $xq - $options['gap']);
01629                     }
01630                 }
01631                 else
01632                 {
01633                     $cols1[$last] = $p - $xq;
01634                 }
01635 
01636                 $last = $colName;
01637                 $xq = $p;
01638             }
01639 
01640             // $cols0 contains the widths of all the columns which are not set
01641             $neededWidth = $options['width'] - $setWidth;
01642 
01643             // if needed width is negative then add it equally to each column, else get more tricky
01644             if ($presentWidth < $neededWidth)
01645             {
01646                 foreach ($cols0 as $colName => $w)
01647                 {
01648                     $cols0[$colName] += ($neededWidth - $presentWidth) / count($cols0);
01649                 }
01650             }
01651             else
01652             {
01653                 $cnt = 0;
01654 
01655                 while ($presentWidth > $neededWidth && $cnt < 100)
01656                 {
01657                     $cnt++; // insurance policy
01658                     // find the widest columns, and the next to widest width
01659                     $aWidest = array(
01660                         );
01661 
01662                     $nWidest = 0;
01663                     $widest = 0;
01664 
01665                     foreach ($cols0 as $colName => $w)
01666                     {
01667                         if ($w > $widest)
01668                         {
01669                             $aWidest = array($colName);
01670                             $nWidest = $widest;
01671                             $widest = $w;
01672                         }
01673                         else if ($w == $widest)
01674                         {
01675                             $aWidest[] = $colName;
01676                         }
01677                     }
01678 
01679                     // then figure out what the width of the widest columns would have to be to take up all the slack
01680                     $newWidestWidth = $widest - ($presentWidth - $neededWidth) / count($aWidest);
01681 
01682                     if ($newWidestWidth > $nWidest)
01683                     {
01684                         // then there is space to set them to this
01685                         foreach ($aWidest as $colName)
01686                         {
01687                             $cols0[$colName] = $newWidestWidth;
01688                         }
01689 
01690                         $presentWidth = $neededWidth;
01691                     }
01692                     else
01693                     {
01694                         // there is not space, reduce the size of the widest ones down to the next size down, and we
01695                         // will go round again
01696                         foreach ($aWidest as $colName)
01697                         {
01698                             $cols0[$colName] = $nWidest;
01699                         }
01700 
01701                         $presentWidth = $presentWidth - ($widest - $nWidest) * count($aWidest);
01702                     }
01703                 }
01704             }
01705 
01706             // $cols0 now contains the new widths of the constrained columns.
01707             // now need to update the $pos and $maxWidth arrays
01708             $xq = 0;
01709 
01710             foreach ($pos as $colName => $p)
01711             {
01712                 $pos[$colName] = $xq;
01713 
01714                 if (!isset($options['cols'][$colName]) || !isset($options['cols'][$colName]['width'])
01715                                                               || $options['cols'][$colName]['width'] <= 0)
01716                 {
01717                     if (isset($cols0[$colName]))
01718                     {
01719                         $xq += $cols0[$colName] + $options['gap'];
01720                         $maxWidth[$colName] = $cols0[$colName];
01721                     }
01722                 }
01723                 else
01724                 {
01725                     if (isset($cols1[$colName]))
01726                     {
01727                         $xq += $cols1[$colName];
01728                     }
01729                 }
01730             }
01731 
01732             $t = $x + $options['width'];
01733             $pos['_end_'] = $t;
01734         }
01735 
01736         // now adjust the table to the correct location across the page
01737         switch ($options['xPos'])
01738             {
01739             case 'left':
01740                 $xref = $this->ez['leftMargin'];
01741 
01742                 break;
01743 
01744             case 'right':
01745                 $xref = $this->ez['pageWidth'] - $this->ez['rightMargin'];
01746 
01747                 break;
01748 
01749             case 'centre':
01750             case 'center':
01751                 $xref = $middle;
01752 
01753                 break;
01754 
01755             default:
01756                 $xref = $options['xPos'];
01757 
01758                 break;
01759             }
01760 
01761         switch ($options['xOrientation'])
01762             {
01763             case 'left':
01764                 $dx = $xref - $t;
01765 
01766                 break;
01767 
01768             case 'right':
01769                 $dx = $xref;
01770 
01771                 break;
01772 
01773             case 'centre':
01774             case 'center':
01775                 $dx = $xref - $t / 2;
01776 
01777                 break;
01778             }
01779 
01780         foreach ($pos as $k => $v)
01781         {
01782             $pos[$k] = $v + $dx;
01783         }
01784 
01785         $x0 = $x + $dx;
01786         $x1 = $t + $dx;
01787 
01788         $baseLeftMargin = $this->ez['leftMargin'];
01789         $basePos = $pos;
01790         $baseX0 = $x0;
01791         $baseX1 = $x1;
01792 
01793         // ok, just about ready to make me a table
01794         $this->setColor($options['textCol'][0], $options['textCol'][1], $options['textCol'][2]);
01795         $this->setStrokeColor($options['shadeCol'][0], $options['shadeCol'][1], $options['shadeCol'][2]);
01796 
01797         $middle = ($x1 + $x0) / 2;
01798 
01799         // start a transaction which will be used to regress the table, if there are not enough rows protected
01800         if ($options['protectRows'] > 0)
01801         {
01802             $this->transaction('start');
01803             $movedOnce = 0;
01804         }
01805 
01806         $abortTable = 1;
01807 
01808         while ($abortTable)
01809         {
01810             $abortTable = 0;
01811 
01812             $dm = $this->ez['leftMargin'] - $baseLeftMargin;
01813 
01814             foreach ($basePos as $k => $v)
01815             {
01816                 $pos[$k] = $v + $dm;
01817             }
01818 
01819             $x0 = $baseX0 + $dm;
01820             $x1 = $baseX1 + $dm;
01821             $middle = ($x1 + $x0) / 2;
01822 
01823             // if the title is set, then do that
01824             if (strlen($title))
01825             {
01826                 $w = $this->getTextWidth($options['titleFontSize'], $title);
01827                 $this->y -= $this->getFontHeight($options['titleFontSize']);
01828 
01829                 if ($this->y < $this->ez['bottomMargin'])
01830                 {
01831                     $this->ezNewPage();
01832                     // margins may have changed on the newpage
01833                     $dm = $this->ez['leftMargin'] - $baseLeftMargin;
01834 
01835                     foreach ($basePos as $k => $v)
01836                     {
01837                         $pos[$k] = $v + $dm;
01838                     }
01839 
01840                     $x0 = $baseX0 + $dm;
01841                     $x1 = $baseX1 + $dm;
01842                     $middle = ($x1 + $x0) / 2;
01843                     $this->y -= $this->getFontHeight($options['titleFontSize']);
01844                 }
01845 
01846                 $this->addText($middle - $w / 2, $this->y, $options['titleFontSize'], $title);
01847                 $this->y -= $options['titleGap'];
01848             }
01849 
01850             // margins may have changed on the newpage
01851             $dm = $this->ez['leftMargin'] - $baseLeftMargin;
01852 
01853             foreach ($basePos as $k => $v)
01854             {
01855                 $pos[$k] = $v + $dm;
01856             }
01857 
01858             $x0 = $baseX0 + $dm;
01859             $x1 = $baseX1 + $dm;
01860 
01861             $y = $this->y; // to simplify the code a bit
01862 
01863             // make the table
01864             $height = $this->getFontHeight($options['fontSize']);
01865             $decender = $this->getFontDecender($options['fontSize']);
01866 
01867             $y0 = $y + $decender;
01868             $dy = 0;
01869 
01870             if ($options['showHeadings'])
01871             {
01872                 if ($options['shaded'])
01873                 {
01874                     $this->saveState();
01875                     $textObjectId = $this->openObject();
01876                 }
01877 
01878                 // this function will move the start of the table to a new page if it does not fit on this one
01879                 $headingHeight = $this->ezPrvtTableColumnHeadings(
01880                                      $cols,                $pos, $maxWidth, $height, $decender, $options['rowGap'],
01881                                      $options['fontSize'], $y,   $options);
01882                 $y0 = $y + $headingHeight;
01883                 $y1 = $y;
01884 
01885                 $dm = $this->ez['leftMargin'] - $baseLeftMargin;
01886 
01887                 foreach ($basePos as $k => $v)
01888                 {
01889                     $pos[$k] = $v + $dm;
01890                 }
01891 
01892                 $x0 = $baseX0 + $dm;
01893                 $x1 = $baseX1 + $dm;
01894 
01895                 if ($options['shaded'])
01896                 {
01897                     $this->closeObject();
01898                     $this->setColor($options['shadeCol'][0], $options['shadeCol'][1], $options['shadeCol'][2], 1);
01899                     $this->filledRectangle($x0 - $options['gap'] / 2, $y1, $x1 - $x0, $headingHeight);
01900                     $this->addObject($textObjectId);
01901                     $this->closeObject();
01902                     $this->restoreState();
01903                 }
01904             }
01905             else
01906             {
01907                 $y1 = $y0;
01908             }
01909 
01910             $firstLine = 1;
01911 
01912             // open an object here so that the text can be put in over the shading
01913             if ($options['shaded'])
01914             {
01915                 $this->saveState();
01916                 $textObjectId = $this->openObject();
01917                 $this->closeObject();
01918 
01919                 //         $this->setColor($options['shadeCol'][0],$options['shadeCol'][1],$options['shadeCol'][2],1);
01920                 //         $this->filledRectangle($x0-$options['gap']/2,$y1,$x1-$x0,$headingHeight);
01921 
01922                 //         $this->setColor($options['shadeCol'][0],$options['shadeCol'][1],$options['shadeCol'][2],1);
01923                 //         $this->filledRectangle($x0-$options['gap']/2,$y0,$x1-$x0,$y0+$dm);
01924                 //         $this->filledRectangle($x0-$options['gap']/2,$y+$decender+$height-$mx,$x1-$x0,$mx);
01925                 //         $this->filledRectangle($x0-$options['gap']/2,$y0-12,$x1-$x0,$y0);
01926 
01927                 $this->addObject($textObjectId);
01928 
01929                 //         $this->setColor($options['shadeCol'][0],$options['shadeCol'][1],$options['shadeCol'][2],1);
01930                 //         $this->filledRectangle($x0-$options['gap']/2,$y1,$x1-$x0,$headingHeight);
01931 
01932                 $this->reopenObject($textObjectId);
01933             }
01934 
01935             $cnt = 0;
01936             $newPage = 0;
01937 
01938             foreach ($data as $row)
01939             {
01940                 $cnt++;
01941 
01942                 // the transaction support will be used to prevent rows being split
01943                 if ($options['splitRows'] == 0)
01944                 {
01945                     $pageStart = $this->ezPageCount;
01946 
01947                     if (isset($this->ez['columns']) && $this->ez['columns']['on'] == 1)
01948                     {
01949                         $columnStart = $this->ez['columns']['colNum'];
01950                     }
01951 
01952                     $this->transaction('start');
01953                     $row_orig = $row;
01954                     $y_orig = $y;
01955                     $y0_orig = $y0;
01956                     $y1_orig = $y1;
01957                 }
01958 
01959                 $ok = 0;
01960                 $secondTurn = 0;
01961 
01962                 while (!$abortTable && $ok == 0)
01963                 {
01964                     $mx = 0;
01965                     $newRow = 1;
01966 
01967                     while (!$abortTable && ($newPage || $newRow))
01968                     {
01969                         $y -= $height;
01970 
01971                         if ($newPage || $y < $this->ez['bottomMargin'] || (isset($options['minRowSpace']) && $y
01972                                                                                                                  < ($this->ez['bottomMargin']
01973                                                                                                                        + $options['minRowSpace'])))
01974                         {
01975                             // check that enough rows are with the heading
01976                             if ($options['protectRows'] > 0 && $movedOnce == 0 && $cnt <= $options['protectRows'])
01977                             {
01978                                 // then we need to move the whole table onto the next page
01979                                 $movedOnce = 1;
01980                                 $abortTable = 1;
01981                             }
01982 
01983                             $y2 = $y - $mx + 2 * $height + $decender - $newRow * $height;
01984 
01985                             if ($options['showLines'])
01986                             {
01987                                 if (!$options['showHeadings'])
01988                                 {
01989                                     $y0 = $y1;
01990                                 }
01991 
01992                                 $this->ezPrvtTableDrawLines($pos,
01993                                                             $options['gap'],
01994                                                             $x0,
01995                                                             $x1,
01996                                                             $y0,
01997                                                             $y1,
01998                                                             $y2,
01999                                                             $options['lineCol'],
02000                                                             $options['innerLineThickness'],
02001                                                             $options['outerLineThickness'],
02002                                                             $options['showLines']);
02003                             }
02004 
02005                             if ($options['shaded'])
02006                             {
02007                                 $this->closeObject();
02008                                 $this->restoreState();
02009                             }
02010 
02011                             $this->ezNewPage();
02012                             // and the margins may have changed, this is due to the possibility of the columns being turned on
02013                             // as the columns are managed by manipulating the margins
02014 
02015                             $dm = $this->ez['leftMargin'] - $baseLeftMargin;
02016 
02017                             foreach ($basePos as $k => $v)
02018                             {
02019                                 $pos[$k] = $v + $dm;
02020                             }
02021 
02022                             //        $x0=$x0+$dm;
02023                             //        $x1=$x1+$dm;
02024                             $x0 = $baseX0 + $dm;
02025                             $x1 = $baseX1 + $dm;
02026 
02027                             if ($options['shaded'])
02028                             {
02029                                 $this->saveState();
02030                                 $textObjectId = $this->openObject();
02031                                 $this->closeObject();
02032                                 $this->addObject($textObjectId);
02033                                 $this->reopenObject($textObjectId);
02034                             }
02035 
02036                             $this->setColor($options['textCol'][0], $options['textCol'][1], $options['textCol'][2], 1);
02037                             $y = $this->ez['pageHeight'] - $this->ez['topMargin'];
02038                             $y0 = $y + $decender;
02039                             $mx = 0;
02040 
02041                             if ($options['showHeadings'])
02042                             {
02043                                 $this->ezPrvtTableColumnHeadings(
02044                                     $cols,                $pos, $maxWidth, $height, $decender, $options['rowGap'],
02045                                     $options['fontSize'], $y,   $options);
02046                                 $y1 = $y;
02047                             }
02048                             else
02049                             {
02050                                 $y1 = $y0;
02051                             }
02052 
02053                             $firstLine = 1;
02054                             $y -= $height;
02055                         }
02056 
02057                         $newRow = 0;
02058                         // write the actual data
02059                         // if these cells need to be split over a page, then $newPage will be set, and the remaining
02060                         // text will be placed in $leftOvers
02061                         $newPage = 0;
02062                         $leftOvers = array(
02063                             );
02064 
02065                         foreach ($cols as $colName => $colTitle)
02066                         {
02067                             $this->ezSetY($y + $height);
02068                             $colNewPage = 0;
02069 
02070                             if (isset($row[$colName]))
02071                             {
02072                                 if (isset($options['cols'][$colName]) && isset($options['cols'][$colName]['link'])
02073                                     && strlen($options['cols'][$colName]['link']))
02074                                 {
02075                                     $lines = explode("\n", $row[$colName]);
02076 
02077                                     if (isset($row[$options['cols'][$colName]['link']])
02078                                         && strlen($row[$options['cols'][$colName]['link']]))
02079                                     {
02080                                         foreach ($lines as $k => $v)
02081                                         {
02082                                             $lines[$k]
02083                                                 = '<c:alink:' . $row[$options['cols'][$colName]['link']] . '>' . $v
02084                                                       . '</c:alink>';
02085                                         }
02086                                     }
02087                                 }
02088                                 else
02089                                 {
02090                                     $lines = explode("\n", $row[$colName]);
02091                                 }
02092                             }
02093                             else
02094                             {
02095                                 $lines = array(
02096                                     );
02097                             }
02098 
02099                             $this->y -= $options['rowGap'];
02100 
02101                             foreach ($lines as $line)
02102                             {
02103                                 $line = $this->ezProcessText($line);
02104                                 $start = 1;
02105 
02106                                 while (strlen($line) || $start)
02107                                 {
02108                                     $start = 0;
02109 
02110                                     if (!$colNewPage)
02111                                     {
02112                                         $this->y = $this->y - $height;
02113                                     }
02114 
02115                                     if ($this->y < $this->ez['bottomMargin'])
02116                                     {
02117                                         //                        $this->ezNewPage();
02118                                         $newPage = 1;    // whether a new page is required for any of the columns
02119                                         $colNewPage = 1; // whether a new page is required for this column
02120                                     }
02121 
02122                                     if ($colNewPage)
02123                                     {
02124                                         if (isset($leftOvers[$colName]))
02125                                         {
02126                                             $leftOvers[$colName] .= "\n" . $line;
02127                                         }
02128                                         else
02129                                         {
02130                                             $leftOvers[$colName] = $line;
02131                                         }
02132 
02133                                         $line = '';
02134                                     }
02135                                     else
02136                                     {
02137                                         if (isset($options['cols'][$colName]) && isset(
02138                                                                                      $options['cols'][$colName]['justification']))
02139                                         {
02140                                             $just = $options['cols'][$colName]['justification'];
02141                                         }
02142                                         else
02143                                         {
02144                                             $just = 'left';
02145                                         }
02146 
02147                                         $line = $this->addTextWrap(
02148                                                     $pos[$colName], $this->y, $maxWidth[$colName], $options['fontSize'],
02149                                                     $line,          $just);
02150                                     }
02151                                 }
02152                             }
02153 
02154                             $dy = $y + $height - $this->y + $options['rowGap'];
02155 
02156                             if ($dy - $height * $newPage > $mx)
02157                             {
02158                                 $mx = $dy - $height * $newPage;
02159                             }
02160                         }
02161 
02162                         // set $row to $leftOvers so that they will be processed onto the new page
02163                         $row = $leftOvers;
02164 
02165                         // now add the shading underneath
02166                         if ($options['shaded'] && $cnt % 2 == 0)
02167                         {
02168                             $this->closeObject();
02169                             $this->setColor($options['shadeCol'][0], $options['shadeCol'][1], $options['shadeCol'][2],
02170                                             1);
02171                             $this->filledRectangle($x0 - $options['gap'] / 2, $y + $decender + $height - $mx, $x1 - $x0,
02172                                                    $mx);
02173                             $this->reopenObject($textObjectId);
02174                         }
02175 
02176                         if ($options['shaded'] == 2 && $cnt % 2 == 1)
02177                         {
02178                             $this->closeObject();
02179                             $this->setColor($options['shadeCol2'][0], $options['shadeCol2'][1],
02180                                             $options['shadeCol2'][2], 1);
02181                             $this->filledRectangle($x0 - $options['gap'] / 2, $y + $decender + $height - $mx, $x1 - $x0,
02182                                                    $mx);
02183                             $this->reopenObject($textObjectId);
02184                         }
02185 
02186                         if ($options['showLines'] > 1)
02187                         {
02188                             // then draw a line on the top of each block
02189                             //   $this->closeObject();
02190                             $this->saveState();
02191                             $this->setStrokeColor($options['lineCol'][0], $options['lineCol'][1],
02192                                                   $options['lineCol'][2], 1);
02193 
02194                             //             $this->line($x0-$options['gap']/2,$y+$decender+$height-$mx,$x1-$x0,$mx);
02195                             if ($firstLine)
02196                             {
02197                                 $this->setLineStyle($options['outerLineThickness']);
02198                                 $firstLine = 0;
02199                             }
02200                             else
02201                             {
02202                                 $this->setLineStyle($options['innerLineThickness']);
02203                             }
02204 
02205                             $this->line($x0 - $options['gap'] / 2, $y + $decender + $height, $x1 - $options['gap'] / 2,
02206                                         $y + $decender + $height);
02207                             $this->restoreState();
02208                         //            $this->reopenObject($textObjectId);
02209                         }
02210                     } // end of while 
02211 
02212                     $y = $y - $mx + $height;
02213 
02214                     // checking row split over pages
02215                     if ($options['splitRows'] == 0)
02216                     {
02217                         if ((($this->ezPageCount != $pageStart) || (isset($this->ez['columns'])
02218                                                                        && $this->ez['columns']['on'] == 1
02219                                                                        && $columnStart
02220                                                                               != $this->ez['columns']['colNum']))
02221                             && $secondTurn == 0)
02222                         {
02223                             // then we need to go back and try that again !
02224                             $newPage = 1;
02225                             $secondTurn = 1;
02226                             $this->transaction('rewind');
02227                             $row = $row_orig;
02228                             $y = $y_orig;
02229                             $y0 = $y0_orig;
02230                             $y1 = $y1_orig;
02231                             $ok = 0;
02232 
02233                             $dm = $this->ez['leftMargin'] - $baseLeftMargin;
02234 
02235                             foreach ($basePos as $k => $v)
02236                             {
02237                                 $pos[$k] = $v + $dm;
02238                             }
02239 
02240                             $x0 = $baseX0 + $dm;
02241                             $x1 = $baseX1 + $dm;
02242                         }
02243                         else
02244                         {
02245                             $this->transaction('commit');
02246                             $ok = 1;
02247                         }
02248                     }
02249                     else
02250                     {
02251                         $ok = 1; // don't go round the loop if splitting rows is allowed
02252                     }
02253                 }                // end of while to check for row splitting
02254 
02255                 if ($abortTable)
02256                 {
02257                     if ($ok == 0)
02258                     {
02259                         $this->transaction('abort');
02260                     }
02261 
02262                     // only the outer transaction should be operational
02263                     $this->transaction('rewind');
02264                     $this->ezNewPage();
02265                     break;
02266                 }
02267             } // end of foreach ($data as $row)
02268         }     // end of while ($abortTable)
02269 
02270         // table has been put on the page, the rows guarded as required, commit.
02271         $this->transaction('commit');
02272 
02273         $y2 = $y + $decender;
02274 
02275         if ($options['showLines'])
02276         {
02277             if (!$options['showHeadings'])
02278             {
02279                 $y0 = $y1;
02280             }
02281 
02282             $this->ezPrvtTableDrawLines($pos,                           $options['gap'],
02283                                         $x0,                            $x1,
02284                                         $y0,                            $y1,
02285                                         $y2,                            $options['lineCol'],
02286                                         $options['innerLineThickness'], $options['outerLineThickness'],
02287                                         $options['showLines']);
02288         }
02289 
02290         // close the object for drawing the text on top
02291         if ($options['shaded'])
02292         {
02293             $this->closeObject();
02294             $this->restoreState();
02295         }
02296 
02297         $this->y = $y;
02298         return $y;
02299     }
02300 
02301     // ------------------------------------------------------------------------------
02302     function ezProcessText($text)
02303     {
02304         // this function will intially be used to implement underlining support, but could be used for a range of other
02305         // purposes
02306         $search = array
02307             (
02308             '<u>',
02309             '<U>',
02310             '</u>',
02311             '</U>'
02312             );
02313 
02314         $replace = array
02315             (
02316             '<c:uline>',
02317             '<c:uline>',
02318             '</c:uline>',
02319             '</c:uline>'
02320             );
02321 
02322         return str_replace($search, $replace, $text);
02323     }
02324 
02325     // ------------------------------------------------------------------------------
02326 
02327     function ezText($text, $size = 0, $options = array(
02328         ),          $test = 0)
02329     {
02330         // this will add a string of text to the document, starting at the current drawing
02331         // position.
02332         // it will wrap to keep within the margins, including optional offsets from the left
02333         // and the right, if $size is not specified, then it will be the last one used, or
02334         // the default value (12 I think).
02335         // the text will go to the start of the next line when a return code "\n" is found.
02336         // possible options are:
02337         // 'left'=> number, gap to leave from the left margin
02338         // 'right'=> number, gap to leave from the right margin
02339         // 'aleft'=> number, absolute left position (overrides 'left')
02340         // 'aright'=> number, absolute right position (overrides 'right')
02341         // 'justification' => 'left','right','center','centre','full'
02342 
02343         // only set one of the next two items (leading overrides spacing)
02344         // 'leading' => number, defines the total height taken by the line, independent of the font height.
02345         // 'spacing' => a real number, though usually set to one of 1, 1.5, 2 (line spacing as used in word processing)
02346 
02347         // if $test is set then this should just check if the text is going to flow onto a new page or not, returning true or false
02348 
02349         // apply the filtering which will make the underlining function.
02350         $text = $this->ezProcessText($text);
02351 
02352         $newPage = false;
02353         $store_y = $this->y;
02354 
02355         if (is_array($options) && isset($options['aleft']))
02356         {
02357             $left = $options['aleft'];
02358         }
02359         else
02360         {
02361             $left = $this->ez['leftMargin'] + ((is_array($options) && isset($options['left'])) ? $options['left'] : 0);
02362         }
02363 
02364         if (is_array($options) && isset($options['aright']))
02365         {
02366             $right = $options['aright'];
02367         }
02368         else
02369         {
02370             $right = $this->ez['pageWidth'] - $this->ez['rightMargin'] - ((is_array(
02371                                                                                $options) && isset($options['right']))
02372                                                                              ? $options['right'] : 0);
02373         }
02374 
02375         if ($size <= 0)
02376         {
02377             $size = $this->ez['fontSize'];
02378         }
02379         else
02380         {
02381             $this->ez['fontSize'] = $size;
02382         }
02383 
02384         if (is_array($options) && isset($options['justification']))
02385         {
02386             $just = $options['justification'];
02387         }
02388         else
02389         {
02390             $just = 'left';
02391         }
02392 
02393         // modifications to give leading and spacing based on those given by Craig Heydenburg 1/1/02
02394         if (is_array($options) && isset($options['leading']))
02395         { ## use leading instead of spacing
02396             $height = $options['leading'];
02397         }
02398         else if (is_array($options) && isset($options['spacing']))
02399         {
02400             $height = $this->getFontHeight($size) * $options['spacing'];
02401         }
02402         else
02403         {
02404             $height = $this->getFontHeight($size);
02405         }
02406 
02407         $lines = explode("\n", $text);
02408 
02409         foreach ($lines as $line)
02410         {
02411             $start = 1;
02412 
02413             while (strlen($line) || $start)
02414             {
02415                 $start = 0;
02416                 $this->y = $this->y - $height;
02417 
02418                 if ($this->y < $this->ez['bottomMargin'])
02419                 {
02420                     if ($test)
02421                     {
02422                         $newPage = true;
02423                     }
02424                     else
02425                     {
02426                         $this->ezNewPage();
02427                     // and then re-calc the left and right, in case they have changed due to columns
02428                     }
02429                 }
02430 
02431                 if (is_array($options) && isset($options['aleft']))
02432                 {
02433                     $left = $options['aleft'];
02434                 }
02435                 else
02436                 {
02437                     $left = $this->ez['leftMargin'] + ((is_array(
02438                                                             $options) && isset(
02439                                                                              $options['left'])) ? $options['left'] : 0);
02440                 }
02441 
02442                 if (is_array($options) && isset($options['aright']))
02443                 {
02444                     $right = $options['aright'];
02445                 }
02446                 else
02447                 {
02448                     $right = $this->ez['pageWidth'] - $this->ez['rightMargin'] - ((is_array($options)
02449                                                                                       && isset($options['right']))
02450                                                                                      ? $options['right'] : 0);
02451                 }
02452 
02453                 $line = $this->addTextWrap($left, $this->y, $right - $left, $size, $line, $just, 0, $test);
02454             }
02455         }
02456 
02457         if ($test)
02458         {
02459             $this->y = $store_y;
02460             return $newPage;
02461         }
02462         else
02463         {
02464             return $this->y;
02465         }
02466     }
02467 
02468     // ------------------------------------------------------------------------------
02469 
02470     function ezImage($image, $pad = 5, $width = 0, $resize = 'full', $just = 'center', $border = '')
02471     {
02472         //beta ezimage function
02473         if (stristr($image, '://')) //copy to temp file
02474         {
02475             $fp = @fopen($image, "rb");
02476 
02477             while (!feof($fp))
02478             {
02479                 $cont .= fread($fp, 1024);
02480             }
02481 
02482             fclose ($fp);
02483             $image = tempnam("/tmp", "php-pdf");
02484             $fp2 = @fopen($image, "w");
02485             fwrite($fp2, $cont);
02486             fclose ($fp2);
02487             $temp = true;
02488         }
02489 
02490         if (!(file_exists($image)))
02491             return false; //return immediately if image file does not exist
02492 
02493         $imageInfo = getimagesize($image);
02494 
02495         switch ($imageInfo[2])
02496             {
02497             case 2:
02498                 $type = "jpeg";
02499 
02500                 break;
02501 
02502             case 3:
02503                 $type = "png";
02504 
02505                 break;
02506 
02507             default: return false; //return if file is not jpg or png
02508             }
02509 
02510         if ($width == 0)
02511             $width = $imageInfo[0]; //set width
02512 
02513         $ratio = $imageInfo[0] / $imageInfo[1];
02514 
02515         //get maximum width of image
02516         if (isset($this->ez['columns']) && $this->ez['columns']['on'] == 1)
02517         {
02518             $bigwidth = $this->ez['columns']['width'] - ($pad * 2);
02519         }
02520         else
02521         {
02522             $bigwidth = $this->ez['pageWidth'] - ($pad * 2);
02523         }
02524 
02525         //fix width if larger than maximum or if $resize=full
02526         if ($resize == 'full' || $resize == 'width' || $width > $bigwidth)
02527         {
02528             $width = $bigwidth;
02529         }
02530 
02531         $height = ($width / $ratio); //set height
02532 
02533         //fix size if runs off page
02534         if ($height > ($this->y - $this->ez['bottomMargin'] - ($pad * 2)))
02535         {
02536             if ($resize != 'full')
02537             {
02538                 $this->ezNewPage();
02539             }
02540             else
02541             {
02542                 $height = ($this->y - $this->ez['bottomMargin'] - ($pad * 2)); //shrink height
02543                 $width = ($height * $ratio);                                   //fix width
02544             }
02545         }
02546 
02547         //fix x-offset if image smaller than bigwidth
02548         if ($width < $bigwidth)
02549         {
02550             //center if justification=center
02551             if ($just == 'center')
02552             {
02553                 $offset = ($bigwidth - $width) / 2;
02554             }
02555 
02556             //move to right if justification=right
02557             if ($just == 'right')
02558             {
02559                 $offset = ($bigwidth - $width);
02560             }
02561 
02562             //leave at left if justification=left
02563             if ($just == 'left')
02564             {
02565                 $offset = 0;
02566             }
02567         }
02568 
02569         //call appropriate function
02570         if ($type == "jpeg")
02571         {
02572             $this->addJpegFromFile($image,
02573                                    $this->ez['leftMargin'] + $pad + $offset,
02574                                    $this->y + $this->getFontHeight($this->ez['fontSize']) - $pad - $height,
02575                                    $width);
02576         }
02577 
02578         if ($type == "png")
02579         {
02580             $this->addPngFromFile($image,
02581                                   $this->ez['leftMargin'] + $pad + $offset,
02582                                   $this->y + $this->getFontHeight($this->ez['fontSize']) - $pad - $height,
02583                                   $width);
02584         }
02585 
02586         //draw border
02587         if ($border != '')
02588         {
02589             if (!(isset($border['color'])))
02590             {
02591                 $border['color']['red'] = .5;
02592                 $border['color']['blue'] = .5;
02593                 $border['color']['green'] = .5;
02594             }
02595 
02596             if (!(isset($border['width'])))
02597                 $border['width'] = 1;
02598 
02599             if (!(isset($border['cap'])))
02600                 $border['cap'] = 'round';
02601 
02602             if (!(isset($border['join'])))
02603                 $border['join'] = 'round';
02604 
02605             $this->setStrokeColor($border['color']['red'], $border['color']['green'], $border['color']['blue']);
02606             $this->setLineStyle($border['width'], $border['cap'], $border['join']);
02607             $this->rectangle($this->ez['leftMargin'] + $pad + $offset,
02608                              $this->y + $this->getFontHeight($this->ez['fontSize']) - $pad - $height,
02609                              $width,
02610                              $height);
02611         }
02612 
02613         // move y below image
02614         $this->y = $this->y - $pad - $height;
02615 
02616         //remove tempfile for remote images
02617         if ($temp == true)
02618             unlink ($image);
02619     }
02620 
02621     // ------------------------------------------------------------------------------
02622 
02623     // note that templating code is still considered developmental - have not really figured
02624     // out a good way of doing this yet.
02625     function loadTemplate($templateFile)
02626     {
02627         // this function will load the requested template ($file includes full or relative pathname)
02628         // the code for the template will be modified to make it name safe, and then stored in 
02629         // an array for later use
02630         // The id of the template will be returned for the user to operate on it later
02631         if (!file_exists($templateFile))
02632         {
02633             return -1;
02634         }
02635 
02636         $code = implode('', file($templateFile));
02637 
02638         if (!strlen($code))
02639         {
02640             return;
02641         }
02642 
02643         $code = trim($code);
02644 
02645         if (substr($code, 0, 5) == '<?php')
02646         {
02647             $code = substr($code, 5);
02648         }
02649 
02650         if (substr($code, -2) == '?>')
02651         {
02652             $code = substr($code, 0, strlen($code) - 2);
02653         }
02654 
02655         if (isset($this->ez['numTemplates']))
02656         {
02657             $newNum = $this->ez['numTemplates'];
02658             $this->ez['numTemplates']++;
02659         }
02660         else
02661         {
02662             $newNum = 0;
02663             $this->ez['numTemplates'] = 1;
02664             $this->ez['templates'] = array(
02665                 );
02666         }
02667 
02668         $this->ez['templates'][$newNum]['code'] = $code;
02669 
02670         return $newNum;
02671     }
02672 
02673     // ------------------------------------------------------------------------------
02674 
02675     function execTemplate($id, $data = array(
02676         ),                $options = array(
02677         ))
02678     {
02679         // execute the given template on the current document.
02680         if (!isset($this->ez['templates'][$id]))
02681         {
02682             return;
02683         }
02684 
02685         eval ($this->ez['templates'][$id]['code']);
02686     }
02687 
02688     // ------------------------------------------------------------------------------
02689     function ilink($info)
02690     {
02691         $this->alink($info, 1);
02692     }
02693 
02694     function alink($info, $internal = 0)
02695     {
02696         // a callback function to support the formation of clickable links within the document
02697         $lineFactor = 0.05; // the thickness of the line as a proportion of the height. also the drop of the line.
02698 
02699         switch ($info['status'])
02700             {
02701             case 'start':
02702             case 'sol':
02703                 // the beginning of the link
02704                 // this should contain the URl for the link as the 'p' entry, and will also contain the value of 'nCallback'
02705                 if (!isset($this->ez['links']))
02706                 {
02707                     $this->ez['links'] = array(
02708                         );
02709                 }
02710 
02711                 $i = $info['nCallback'];
02712                 $this->ez['links'][$i] = array
02713                     (
02714                     'x' => $info['x'],
02715                     'y' => $info['y'],
02716                     'angle' => $info['angle'],
02717                     'decender' => $info['decender'],
02718                     'height' => $info['height'],
02719                     'url' => $info['p']
02720                     );
02721 
02722                 if ($internal == 0)
02723                 {
02724                     $this->saveState();
02725                     $this->setColor(0, 0, 1);
02726                     $this->setStrokeColor(0, 0, 1);
02727                     $thick = $info['height'] * $lineFactor;
02728                     $this->setLineStyle($thick);
02729                 }
02730 
02731                 break;
02732 
02733             case 'end':
02734             case 'eol':
02735                 // the end of the link
02736                 // assume that it is the most recent opening which has closed
02737                 $i = $info['nCallback'];
02738 
02739                 $start = $this->ez['links'][$i];
02740 
02741                 // add underlining
02742                 if ($internal)
02743                 {
02744                     $this->addInternalLink($start['url'], $start['x'], $start['y'] + $start['decender'], $info['x'],
02745                                            $start['y'] + $start['decender'] + $start['height']);
02746                 }
02747                 else
02748                 {
02749                     $a = deg2rad((float)$start['angle'] - 90.0);
02750                     $drop = $start['height'] * $lineFactor * 1.5;
02751                     $dropx = cos($a) * $drop;
02752                     $dropy = -sin($a) * $drop;
02753                     $this->line($start['x'] - $dropx, $start['y'] - $dropy, $info['x'] - $dropx, $info['y'] - $dropy);
02754                     $this->addLink($start['url'], $start['x'], $start['y'] + $start['decender'], $info['x'],
02755                                    $start['y'] + $start['decender'] + $start['height']);
02756                     $this->restoreState();
02757                 }
02758 
02759                 break;
02760             }
02761     }
02762 
02763     // ------------------------------------------------------------------------------
02764 
02765     function uline($info)
02766     {
02767         // a callback function to support underlining
02768         $lineFactor = 0.05; // the thickness of the line as a proportion of the height. also the drop of the line.
02769 
02770         switch ($info['status'])
02771             {
02772             case 'start':
02773             case 'sol':
02774 
02775                 // the beginning of the underline zone
02776                 if (!isset($this->ez['links']))
02777                 {
02778                     $this->ez['links'] = array(
02779                         );
02780                 }
02781 
02782                 $i = $info['nCallback'];
02783                 $this->ez['links'][$i] = array
02784                     (
02785                     'x' => $info['x'],
02786                     'y' => $info['y'],
02787                     'angle' => $info['angle'],
02788                     'decender' => $info['decender'],
02789                     'height' => $info['height']
02790                     );
02791 
02792                 $this->saveState();
02793                 $thick = $info['height'] * $lineFactor;
02794                 $this->setLineStyle($thick);
02795                 break;
02796 
02797             case 'end':
02798             case 'eol':
02799                 // the end of the link
02800                 // assume that it is the most recent opening which has closed
02801                 $i = $info['nCallback'];
02802 
02803                 $start = $this->ez['links'][$i];
02804                 // add underlining
02805                 $a = deg2rad((float)$start['angle'] - 90.0);
02806                 $drop = $start['height'] * $lineFactor * 1.5;
02807                 $dropx = cos($a) * $drop;
02808                 $dropy = -sin($a) * $drop;
02809                 $this->line($start['x'] - $dropx, $start['y'] - $dropy, $info['x'] - $dropx, $info['y'] - $dropy);
02810                 $this->restoreState();
02811                 break;
02812             }
02813     }
02814 
02815 // ------------------------------------------------------------------------------
02816 
02817 }
02818 ?>
CopyLeft (L) 2001-2006 - [MIOLO Development Team] SOLIS - Cooperativa de Soluções Livres - Lajeado/RS - Brasil