+++ /dev/null
-<?php\r
-\r
-include_once('class.pdf.php');\r
-\r
-class Cezpdf extends Cpdf {\r
-//==============================================================================\r
-// this class will take the basic interaction facilities of the Cpdf class\r
-// and make more useful functions so that the user does not have to\r
-// know all the ins and outs of pdf presentation to produce something pretty.\r
-//\r
-// IMPORTANT NOTE\r
-// there is no warranty, implied or otherwise with this software.\r
-//\r
-// version 009 (versioning is linked to class.pdf.php)\r
-//\r
-// released under a public domain licence.\r
-//\r
-// Wayne Munro, R&OS Ltd, http://www.ros.co.nz/pdf\r
-//==============================================================================\r
-\r
-var $ez=array('fontSize'=>10); // used for storing most of the page configuration parameters\r
-var $y; // this is the current vertical positon on the page of the writing point, very important\r
-var $ezPages=array(); // keep an array of the ids of the pages, making it easy to go back and add page numbers etc.\r
-var $ezPageCount=0;\r
-\r
-// ------------------------------------------------------------------------------\r
-\r
-function Cezpdf($paper='a4',$orientation='portrait'){\r
- // Assuming that people don't want to specify the paper size using the absolute coordinates\r
- // allow a couple of options:\r
- // orientation can be 'portrait' or 'landscape'\r
- // or, to actually set the coordinates, then pass an array in as the first parameter.\r
- // the defaults are as shown.\r
- //\r
- // -------------------------\r
- // 2002-07-24 - Nicola Asuni (info@tecnick.com):\r
- // Added new page formats (45 standard ISO paper formats and 4 american common formats)\r
- // paper cordinates are calculated in this way: (inches * 72) where 1 inch = 2.54 cm\r
- //\r
- // Now you may also pass a 2 values array containing the page width and height in centimeters\r
- // -------------------------\r
-\r
- if (!is_array($paper)){\r
- switch (strtoupper($paper)){\r
- case '4A0': {$size = array(0,0,4767.87,6740.79); break;}\r
- case '2A0': {$size = array(0,0,3370.39,4767.87); break;}\r
- case 'A0': {$size = array(0,0,2383.94,3370.39); break;}\r
- case 'A1': {$size = array(0,0,1683.78,2383.94); break;}\r
- case 'A2': {$size = array(0,0,1190.55,1683.78); break;}\r
- case 'A3': {$size = array(0,0,841.89,1190.55); break;}\r
- case 'A4': default: {$size = array(0,0,595.28,841.89); break;}\r
- case 'A5': {$size = array(0,0,419.53,595.28); break;}\r
- case 'A6': {$size = array(0,0,297.64,419.53); break;}\r
- case 'A7': {$size = array(0,0,209.76,297.64); break;}\r
- case 'A8': {$size = array(0,0,147.40,209.76); break;}\r
- case 'A9': {$size = array(0,0,104.88,147.40); break;}\r
- case 'A10': {$size = array(0,0,73.70,104.88); break;}\r
- case 'B0': {$size = array(0,0,2834.65,4008.19); break;}\r
- case 'B1': {$size = array(0,0,2004.09,2834.65); break;}\r
- case 'B2': {$size = array(0,0,1417.32,2004.09); break;}\r
- case 'B3': {$size = array(0,0,1000.63,1417.32); break;}\r
- case 'B4': {$size = array(0,0,708.66,1000.63); break;}\r
- case 'B5': {$size = array(0,0,498.90,708.66); break;}\r
- case 'B6': {$size = array(0,0,354.33,498.90); break;}\r
- case 'B7': {$size = array(0,0,249.45,354.33); break;}\r
- case 'B8': {$size = array(0,0,175.75,249.45); break;}\r
- case 'B9': {$size = array(0,0,124.72,175.75); break;}\r
- case 'B10': {$size = array(0,0,87.87,124.72); break;}\r
- case 'C0': {$size = array(0,0,2599.37,3676.54); break;}\r
- case 'C1': {$size = array(0,0,1836.85,2599.37); break;}\r
- case 'C2': {$size = array(0,0,1298.27,1836.85); break;}\r
- case 'C3': {$size = array(0,0,918.43,1298.27); break;}\r
- case 'C4': {$size = array(0,0,649.13,918.43); break;}\r
- case 'C5': {$size = array(0,0,459.21,649.13); break;}\r
- case 'C6': {$size = array(0,0,323.15,459.21); break;}\r
- case 'C7': {$size = array(0,0,229.61,323.15); break;}\r
- case 'C8': {$size = array(0,0,161.57,229.61); break;}\r
- case 'C9': {$size = array(0,0,113.39,161.57); break;}\r
- case 'C10': {$size = array(0,0,79.37,113.39); break;}\r
- case 'RA0': {$size = array(0,0,2437.80,3458.27); break;}\r
- case 'RA1': {$size = array(0,0,1729.13,2437.80); break;}\r
- case 'RA2': {$size = array(0,0,1218.90,1729.13); break;}\r
- case 'RA3': {$size = array(0,0,864.57,1218.90); break;}\r
- case 'RA4': {$size = array(0,0,609.45,864.57); break;}\r
- case 'SRA0': {$size = array(0,0,2551.18,3628.35); break;}\r
- case 'SRA1': {$size = array(0,0,1814.17,2551.18); break;}\r
- case 'SRA2': {$size = array(0,0,1275.59,1814.17); break;}\r
- case 'SRA3': {$size = array(0,0,907.09,1275.59); break;}\r
- case 'SRA4': {$size = array(0,0,637.80,907.09); break;}\r
- case 'LETTER': {$size = array(0,0,612.00,792.00); break;}\r
- case 'LEGAL': {$size = array(0,0,612.00,1008.00); break;}\r
- case 'EXECUTIVE': {$size = array(0,0,521.86,756.00); break;}\r
- case 'FOLIO': {$size = array(0,0,612.00,936.00); break;}\r
- }\r
- switch (strtolower($orientation)){\r
- case 'landscape':\r
- $a=$size[3];\r
- $size[3]=$size[2];\r
- $size[2]=$a;\r
- break;\r
- }\r
- } else {\r
- if (count($paper)>2) {\r
- // then an array was sent it to set the size\r
- $size = $paper;\r
- }\r
- else { //size in centimeters has been passed\r
- $size[0] = 0;\r
- $size[1] = 0;\r
- $size[2] = ( $paper[0] / 2.54 ) * 72;\r
- $size[3] = ( $paper[1] / 2.54 ) * 72;\r
- }\r
- }\r
- $this->Cpdf($size);\r
- $this->ez['pageWidth']=$size[2];\r
- $this->ez['pageHeight']=$size[3];\r
-\r
- // also set the margins to some reasonable defaults\r
- $this->ez['topMargin']=30;\r
- $this->ez['bottomMargin']=30;\r
- $this->ez['leftMargin']=30;\r
- $this->ez['rightMargin']=30;\r
-\r
- // set the current writing position to the top of the first page\r
- $this->y = $this->ez['pageHeight']-$this->ez['topMargin'];\r
- // and get the ID of the page that was created during the instancing process.\r
- $this->ezPages[1]=$this->getFirstPageId();\r
- $this->ezPageCount=1;\r
-}\r
-\r
-// ------------------------------------------------------------------------------\r
-// 2002-07-24: Nicola Asuni (info@tecnick.com)\r
-// Set Margins in centimeters\r
-function ezSetCmMargins($top,$bottom,$left,$right){\r
- $top = ( $top / 2.54 ) * 72;\r
- $bottom = ( $bottom / 2.54 ) * 72;\r
- $left = ( $left / 2.54 ) * 72;\r
- $right = ( $right / 2.54 ) * 72;\r
- $this->ezSetMargins($top,$bottom,$left,$right);\r
-}\r
-// ------------------------------------------------------------------------------\r
-\r
-\r
-function ezColumnsStart($options=array()){\r
- // start from the current y-position, make the set number of columne\r
- if (isset($this->ez['columns']) && $this->ez['columns']==1){\r
- // if we are already in a column mode then just return.\r
- return;\r
- }\r
- $def=array('gap'=>10,'num'=>2);\r
- foreach($def as $k=>$v){\r
- if (!isset($options[$k])){\r
- $options[$k]=$v;\r
- }\r
- }\r
- // setup the columns\r
- $this->ez['columns']=array('on'=>1,'colNum'=>1);\r
-\r
- // store the current margins\r
- $this->ez['columns']['margins']=array(\r
- $this->ez['leftMargin']\r
- ,$this->ez['rightMargin']\r
- ,$this->ez['topMargin']\r
- ,$this->ez['bottomMargin']\r
- );\r
- // and store the settings for the columns\r
- $this->ez['columns']['options']=$options;\r
- // then reset the margins to suit the new columns\r
- // safe enough to assume the first column here, but start from the current y-position\r
- $this->ez['topMargin']=$this->ez['pageHeight']-$this->y;\r
- $width=($this->ez['pageWidth']-$this->ez['leftMargin']-$this->ez['rightMargin']-($options['num']-1)*$options['gap'])/$options['num'];\r
- $this->ez['columns']['width']=$width;\r
- $this->ez['rightMargin']=$this->ez['pageWidth']-$this->ez['leftMargin']-$width;\r
-\r
-}\r
-// ------------------------------------------------------------------------------\r
-function ezColumnsStop(){\r
- if (isset($this->ez['columns']) && $this->ez['columns']['on']==1){\r
- $this->ez['columns']['on']=0;\r
- $this->ez['leftMargin']=$this->ez['columns']['margins'][0];\r
- $this->ez['rightMargin']=$this->ez['columns']['margins'][1];\r
- $this->ez['topMargin']=$this->ez['columns']['margins'][2];\r
- $this->ez['bottomMargin']=$this->ez['columns']['margins'][3];\r
- }\r
-}\r
-// ------------------------------------------------------------------------------\r
-function ezInsertMode($status=1,$pageNum=1,$pos='before'){\r
- // puts the document into insert mode. new pages are inserted until this is re-called with status=0\r
- // by default pages wil be inserted at the start of the document\r
- switch($status){\r
- case '1':\r
- if (isset($this->ezPages[$pageNum])){\r
- $this->ez['insertMode']=1;\r
- $this->ez['insertOptions']=array('id'=>$this->ezPages[$pageNum],'pos'=>$pos);\r
- }\r
- break;\r
- case '0':\r
- $this->ez['insertMode']=0;\r
- break;\r
- }\r
-}\r
-// ------------------------------------------------------------------------------\r
-\r
-function ezNewPage(){\r
- $pageRequired=1;\r
- if (isset($this->ez['columns']) && $this->ez['columns']['on']==1){\r
- // check if this is just going to a new column\r
- // increment the column number\r
-//echo 'HERE<br>';\r
- $this->ez['columns']['colNum']++;\r
-//echo $this->ez['columns']['colNum'].'<br>';\r
- if ($this->ez['columns']['colNum'] <= $this->ez['columns']['options']['num']){\r
- // then just reset to the top of the next column\r
- $pageRequired=0;\r
- } else {\r
- $this->ez['columns']['colNum']=1;\r
- $this->ez['topMargin']=$this->ez['columns']['margins'][2];\r
- }\r
-\r
- $width = $this->ez['columns']['width'];\r
- $this->ez['leftMargin']=$this->ez['columns']['margins'][0]+($this->ez['columns']['colNum']-1)*($this->ez['columns']['options']['gap']+$width);\r
- $this->ez['rightMargin']=$this->ez['pageWidth']-$this->ez['leftMargin']-$width;\r
- }\r
-//echo 'left='.$this->ez['leftMargin'].' right='.$this->ez['rightMargin'].'<br>';\r
-\r
- if ($pageRequired){\r
- // make a new page, setting the writing point back to the top\r
- $this->y = $this->ez['pageHeight']-$this->ez['topMargin'];\r
- // make the new page with a call to the basic class.\r
- $this->ezPageCount++;\r
- if (isset($this->ez['insertMode']) && $this->ez['insertMode']==1){\r
- $id = $this->ezPages[$this->ezPageCount] = $this->newPage(1,$this->ez['insertOptions']['id'],$this->ez['insertOptions']['pos']);\r
- // then manipulate the insert options so that inserted pages follow each other\r
- $this->ez['insertOptions']['id']=$id;\r
- $this->ez['insertOptions']['pos']='after';\r
- } else {\r
- $this->ezPages[$this->ezPageCount] = $this->newPage();\r
- }\r
- } else {\r
- $this->y = $this->ez['pageHeight']-$this->ez['topMargin'];\r
- }\r
-}\r
-\r
-// ------------------------------------------------------------------------------\r
-\r
-function ezSetMargins($top,$bottom,$left,$right){\r
- // sets the margins to new values\r
- $this->ez['topMargin']=$top;\r
- $this->ez['bottomMargin']=$bottom;\r
- $this->ez['leftMargin']=$left;\r
- $this->ez['rightMargin']=$right;\r
- // check to see if this means that the current writing position is outside the\r
- // writable area\r
- if ($this->y > $this->ez['pageHeight']-$top){\r
- // then move y down\r
- $this->y = $this->ez['pageHeight']-$top;\r
- }\r
- if ( $this->y < $bottom){\r
- // then make a new page\r
- $this->ezNewPage();\r
- }\r
-}\r
-\r
-// ------------------------------------------------------------------------------\r
-\r
-function ezGetCurrentPageNumber(){\r
- // return the strict numbering (1,2,3,4..) number of the current page\r
- return $this->ezPageCount;\r
-}\r
-\r
-// ------------------------------------------------------------------------------\r
-\r
-function ezStartPageNumbers($x,$y,$size,$pos='left',$pattern='{PAGENUM} of {TOTALPAGENUM}',$num=''){\r
- // put page numbers on the pages from here.\r
- // place then on the 'pos' side of the coordinates (x,y).\r
- // pos can be 'left' or 'right'\r
- // use the given 'pattern' for display, where (PAGENUM} and {TOTALPAGENUM} are replaced\r
- // as required.\r
- // if $num is set, then make the first page this number, the number of total pages will\r
- // be adjusted to account for this.\r
- // Adjust this function so that each time you 'start' page numbers then you effectively start a different batch\r
- // return the number of the batch, so that they can be stopped in a different order if required.\r
- if (!$pos || !strlen($pos)){\r
- $pos='left';\r
- }\r
- if (!$pattern || !strlen($pattern)){\r
- $pattern='{PAGENUM} of {TOTALPAGENUM}';\r
- }\r
- if (!isset($this->ez['pageNumbering'])){\r
- $this->ez['pageNumbering']=array();\r
- }\r
- $i = count($this->ez['pageNumbering']);\r
- $this->ez['pageNumbering'][$i][$this->ezPageCount]=array('x'=>$x,'y'=>$y,'pos'=>$pos,'pattern'=>$pattern,'num'=>$num,'size'=>$size);\r
- return $i;\r
-}\r
-\r
-// ------------------------------------------------------------------------------\r
-\r
-function ezWhatPageNumber($pageNum,$i=0){\r
- // given a particular generic page number (ie, document numbered sequentially from beginning),\r
- // return the page number under a particular page numbering scheme ($i)\r
- $num=0;\r
- $start=1;\r
- $startNum=1;\r
- if (!isset($this->ez['pageNumbering']))\r
- {\r
- $this->addMessage('WARNING: page numbering called for and wasn\'t started with ezStartPageNumbers');\r
- return 0;\r
- }\r
- foreach($this->ez['pageNumbering'][$i] as $k=>$v){\r
- if ($k<=$pageNum){\r
- if (is_array($v)){\r
- // start block\r
- if (strlen($v['num'])){\r
- // a start was specified\r
- $start=$v['num'];\r
- $startNum=$k;\r
- $num=$pageNum-$startNum+$start;\r
- }\r
- } else {\r
- // stop block\r
- $num=0;\r
- }\r
- }\r
- }\r
- return $num;\r
-}\r
-\r
-// ------------------------------------------------------------------------------\r
-\r
-function ezStopPageNumbers($stopTotal=0,$next=0,$i=0){\r
- // if stopTotal=1 then the totalling of pages for this number will stop too\r
- // if $next=1, then do this page, but not the next, else do not do this page either\r
- // if $i is set, then stop that particular pagenumbering sequence.\r
- if (!isset($this->ez['pageNumbering'])){\r
- $this->ez['pageNumbering']=array();\r
- }\r
- if ($next && isset($this->ez['pageNumbering'][$i][$this->ezPageCount]) && is_array($this->ez['pageNumbering'][$i][$this->ezPageCount])){\r
- // then this has only just been started, this will over-write the start, and nothing will appear\r
- // add a special command to the start block, telling it to stop as well\r
- if ($stopTotal){\r
- $this->ez['pageNumbering'][$i][$this->ezPageCount]['stoptn']=1;\r
- } else {\r
- $this->ez['pageNumbering'][$i][$this->ezPageCount]['stopn']=1;\r
- }\r
- } else {\r
- if ($stopTotal){\r
- $this->ez['pageNumbering'][$i][$this->ezPageCount]='stopt';\r
- } else {\r
- $this->ez['pageNumbering'][$i][$this->ezPageCount]='stop';\r
- }\r
- if ($next){\r
- $this->ez['pageNumbering'][$i][$this->ezPageCount].='n';\r
- }\r
- }\r
-}\r
-\r
-// ------------------------------------------------------------------------------\r
-\r
-function ezPRVTpageNumberSearch($lbl,&$tmp){\r
- foreach($tmp as $i=>$v){\r
- if (is_array($v)){\r
- if (isset($v[$lbl])){\r
- return $i;\r
- }\r
- } else {\r
- if ($v==$lbl){\r
- return $i;\r
- }\r
- }\r
- }\r
- return 0;\r
-}\r
-\r
-// ------------------------------------------------------------------------------\r
-\r
-function ezPRVTaddPageNumbers(){\r
- // this will go through the pageNumbering array and add the page numbers are required\r
- if (isset($this->ez['pageNumbering'])){\r
- $totalPages1 = $this->ezPageCount;\r
- $tmp1=$this->ez['pageNumbering'];\r
- $status=0;\r
- foreach($tmp1 as $i=>$tmp){\r
- // do each of the page numbering systems\r
- // firstly, find the total pages for this one\r
- $k = $this->ezPRVTpageNumberSearch('stopt',$tmp);\r
- if ($k && $k>0){\r
- $totalPages = $k-1;\r
- } else {\r
- $l = $this->ezPRVTpageNumberSearch('stoptn',$tmp);\r
- if ($l && $l>0){\r
- $totalPages = $l;\r
- } else {\r
- $totalPages = $totalPages1;\r
- }\r
- }\r
- foreach ($this->ezPages as $pageNum=>$id){\r
- if (isset($tmp[$pageNum])){\r
- if (is_array($tmp[$pageNum])){\r
- // then this must be starting page numbers\r
- $status=1;\r
- $info = $tmp[$pageNum];\r
- $info['dnum']=$info['num']-$pageNum;\r
- // also check for the special case of the numbering stopping and starting on the same page\r
- if (isset($info['stopn']) || isset($info['stoptn']) ){\r
- $status=2;\r
- }\r
- } else if ($tmp[$pageNum]=='stop' || $tmp[$pageNum]=='stopt'){\r
- // then we are stopping page numbers\r
- $status=0;\r
- } else if ($status==1 && ($tmp[$pageNum]=='stoptn' || $tmp[$pageNum]=='stopn')){\r
- // then we are stopping page numbers\r
- $status=2;\r
- }\r
- }\r
- if ($status){\r
- // then add the page numbering to this page\r
- if (strlen($info['num'])){\r
- $num=$pageNum+$info['dnum'];\r
- } else {\r
- $num=$pageNum;\r
- }\r
- $total = $totalPages+$num-$pageNum;\r
- $pat = str_replace('{PAGENUM}',$num,$info['pattern']);\r
- $pat = str_replace('{TOTALPAGENUM}',$total,$pat);\r
- $this->reopenObject($id);\r
- switch($info['pos']){\r
- case 'right':\r
- $this->addText($info['x'],$info['y'],$info['size'],$pat);\r
- break;\r
- default:\r
- $w=$this->getTextWidth($info['size'],$pat);\r
- $this->addText($info['x']-$w,$info['y'],$info['size'],$pat);\r
- break;\r
- }\r
- $this->closeObject();\r
- }\r
- if ($status==2){\r
- $status=0;\r
- }\r
- }\r
- }\r
- }\r
-}\r
-\r
-// ------------------------------------------------------------------------------\r
-\r
-function ezPRVTcleanUp(){\r
- $this->ezPRVTaddPageNumbers();\r
-}\r
-\r
-// ------------------------------------------------------------------------------\r
-\r
-function ezStream($options=''){\r
- $this->ezPRVTcleanUp();\r
- $this->stream($options);\r
-}\r
-\r
-// ------------------------------------------------------------------------------\r
-\r
-function ezOutput($options=0){\r
- $this->ezPRVTcleanUp();\r
- return $this->output($options);\r
-}\r
-\r
-// ------------------------------------------------------------------------------\r
-\r
-function ezSetY($y){\r
- // used to change the vertical position of the writing point.\r
- $this->y = $y;\r
- if ( $this->y < $this->ez['bottomMargin']){\r
- // then make a new page\r
- $this->ezNewPage();\r
- }\r
-}\r
-\r
-// ------------------------------------------------------------------------------\r
-\r
-function ezSetDy($dy,$mod=''){\r
- // used to change the vertical position of the writing point.\r
- // changes up by a positive increment, so enter a negative number to go\r
- // down the page\r
- // if $mod is set to 'makeSpace' and a new page is forced, then the pointed will be moved\r
- // down on the new page, this will allow space to be reserved for graphics etc.\r
- $this->y += $dy;\r
- if ( $this->y < $this->ez['bottomMargin']){\r
- // then make a new page\r
- $this->ezNewPage();\r
- if ($mod=='makeSpace'){\r
- $this->y += $dy;\r
- }\r
- }\r
-}\r
-\r
-// ------------------------------------------------------------------------------\r
-\r
-function ezPrvtTableDrawLines($pos,$gap,$x0,$x1,$y0,$y1,$y2,$col,$inner,$outer,$opt=1){\r
- $x0=1000;\r
- $x1=0;\r
- $this->setStrokeColor($col[0],$col[1],$col[2]);\r
- $cnt=0;\r
- $n = count($pos);\r
- foreach($pos as $x){\r
- $cnt++;\r
- if ($cnt==1 || $cnt==$n){\r
- $this->setLineStyle($outer);\r
- } else {\r
- $this->setLineStyle($inner);\r
- }\r
- $this->line($x-$gap/2,$y0,$x-$gap/2,$y2);\r
- if ($x>$x1){ $x1=$x; };\r
- if ($x<$x0){ $x0=$x; };\r
- }\r
- $this->setLineStyle($outer);\r
- $this->line($x0-$gap/2-$outer/2,$y0,$x1-$gap/2+$outer/2,$y0);\r
- // only do the second line if it is different to the first, AND each row does not have\r
- // a line on it.\r
- if ($y0!=$y1 && $opt<2){\r
- $this->line($x0-$gap/2,$y1,$x1-$gap/2,$y1);\r
- }\r
- $this->line($x0-$gap/2-$outer/2,$y2,$x1-$gap/2+$outer/2,$y2);\r
-}\r
-\r
-// ------------------------------------------------------------------------------\r
-\r
-function ezPrvtTableColumnHeadings($cols,$pos,$maxWidth,$height,$decender,$gap,$size,&$y,$optionsAll=array()){\r
- // uses ezText to add the text, and returns the height taken by the largest heading\r
- // this page will move the headings to a new page if they will not fit completely on this one\r
- // transaction support will be used to implement this\r
-\r
- if (isset($optionsAll['cols'])){\r
- $options = $optionsAll['cols'];\r
- } else {\r
- $options = array();\r
- }\r
-\r
- $mx=0;\r
- $startPage = $this->ezPageCount;\r
- $secondGo=0;\r
-\r
- // $y is the position at which the top of the table should start, so the base\r
- // of the first text, is $y-$height-$gap-$decender, but ezText starts by dropping $height\r
-\r
- // the return from this function is the total cell height, including gaps, and $y is adjusted\r
- // to be the postion of the bottom line\r
-\r
- // begin the transaction\r
- $this->transaction('start');\r
- $ok=0;\r
-// $y-=$gap-$decender;\r
- $y-=$gap;\r
- while ($ok==0){\r
- foreach($cols as $colName=>$colHeading){\r
- $this->ezSetY($y);\r
- if (isset($options[$colName]) && isset($options[$colName]['justification'])){\r
- $justification = $options[$colName]['justification'];\r
- } else {\r
- $justification = 'left';\r
- }\r
- $this->ezText($colHeading,$size,array('aleft'=> $pos[$colName],'aright'=>($maxWidth[$colName]+$pos[$colName]),'justification'=>$justification));\r
- $dy = $y-$this->y;\r
- if ($dy>$mx){\r
- $mx=$dy;\r
- }\r
- }\r
- $y = $y - $mx - $gap + $decender;\r
-// $y -= $mx-$gap+$decender;\r
-\r
- // now, if this has moved to a new page, then abort the transaction, move to a new page, and put it there\r
- // do not check on the second time around, to avoid an infinite loop\r
- if ($this->ezPageCount != $startPage && $secondGo==0){\r
- $this->transaction('rewind');\r
- $this->ezNewPage();\r
- $y = $this->y - $gap-$decender;\r
- $ok=0;\r
- $secondGo=1;\r
-// $y = $store_y;\r
- $mx=0;\r
-\r
- } else {\r
- $this->transaction('commit');\r
- $ok=1;\r
- }\r
- }\r
-\r
- return $mx+$gap*2-$decender;\r
-}\r
-\r
-// ------------------------------------------------------------------------------\r
-\r
-function ezPrvtGetTextWidth($size,$text){\r
- // will calculate the maximum width, taking into account that the text may be broken\r
- // by line breaks.\r
- $mx=0;\r
- $lines = explode("\n",$text);\r
- foreach ($lines as $line){\r
- $w = $this->getTextWidth($size,$line);\r
- if ($w>$mx){\r
- $mx=$w;\r
- }\r
- }\r
- return $mx;\r
-}\r
-\r
-// ------------------------------------------------------------------------------\r
-\r
-function ezTable(&$data,$cols='',$title='',$options=''){\r
- // add a table of information to the pdf document\r
- // $data is a two dimensional array\r
- // $cols (optional) is an associative array, the keys are the names of the columns from $data\r
- // to be presented (and in that order), the values are the titles to be given to the columns\r
- // $title (optional) is the title to be put on the top of the table\r
- //\r
- // $options is an associative array which can contain:\r
- // 'showLines'=> 0,1,2, default is 1 (show outside and top lines only), 2=> lines on each row\r
- // 'showHeadings' => 0 or 1\r
- // 'shaded'=> 0,1,2,3 default is 1 (1->alternate lines are shaded, 0->no shading, 2-> both shaded, second uses shadeCol2)\r
- // 'shadeCol' => (r,g,b) array, defining the colour of the shading, default is (0.8,0.8,0.8)\r
- // 'shadeCol2' => (r,g,b) array, defining the colour of the shading of the other blocks, default is (0.7,0.7,0.7)\r
- // 'fontSize' => 10\r
- // 'textCol' => (r,g,b) array, text colour\r
- // 'titleFontSize' => 12\r
- // 'rowGap' => 2 , the space added at the top and bottom of each row, between the text and the lines\r
- // 'colGap' => 5 , the space on the left and right sides of each cell\r
- // 'lineCol' => (r,g,b) array, defining the colour of the lines, default, black.\r
- // 'xPos' => 'left','right','center','centre',or coordinate, reference coordinate in the x-direction\r
- // 'xOrientation' => 'left','right','center','centre', position of the table w.r.t 'xPos'\r
- // 'width'=> <number> which will specify the width of the table, if it turns out to not be this\r
- // wide, then it will stretch the table to fit, if it is wider then each cell will be made\r
- // proportionalty smaller, and the content may have to wrap.\r
- // 'maxWidth'=> <number> similar to 'width', but will only make table smaller than it wants to be\r
- // 'options' => array(<colname>=>array('justification'=>'left','width'=>100,'link'=>linkDataName),<colname>=>....)\r
- // allow the setting of other paramaters for the individual columns\r
- // 'minRowSpace'=> the minimum space between the bottom of each row and the bottom margin, in which a new row will be started\r
- // if it is less, then a new page would be started, default=-100\r
- // 'innerLineThickness'=>1\r
- // 'outerLineThickness'=>1\r
- // 'splitRows'=>0, 0 or 1, whether or not to allow the rows to be split across page boundaries\r
- // 'protectRows'=>number, the number of rows to hold with the heading on page, ie, if there less than this number of\r
- // rows on the page, then move the whole lot onto the next page, default=1\r
- //\r
- // note that the user will have had to make a font selection already or this will not\r
- // produce a valid pdf file.\r
-\r
- if (!is_array($data)){\r
- return;\r
- }\r
-\r
- if (!is_array($cols)){\r
- // take the columns from the first row of the data set\r
- reset($data);\r
- list($k,$v)=each($data);\r
- if (!is_array($v)){\r
- return;\r
- }\r
- $cols=array();\r
- foreach($v as $k1=>$v1){\r
- $cols[$k1]=$k1;\r
- }\r
- }\r
-\r
- if (!is_array($options)){\r
- $options=array();\r
- }\r
-\r
- $defaults = array(\r
- 'shaded'=>1,'showLines'=>1,'shadeCol'=>array(0.8,0.8,0.8),'shadeCol2'=>array(0.7,0.7,0.7),'fontSize'=>10,'titleFontSize'=>12\r
- ,'titleGap'=>5,'lineCol'=>array(0,0,0),'gap'=>5,'xPos'=>'centre','xOrientation'=>'centre'\r
- ,'showHeadings'=>1,'textCol'=>array(0,0,0),'width'=>0,'maxWidth'=>0,'cols'=>array(),'minRowSpace'=>-100,'rowGap'=>2,'colGap'=>5\r
- ,'innerLineThickness'=>1,'outerLineThickness'=>1,'splitRows'=>0,'protectRows'=>1\r
- );\r
-\r
- foreach($defaults as $key=>$value){\r
- if (is_array($value)){\r
- if (!isset($options[$key]) || !is_array($options[$key])){\r
- $options[$key]=$value;\r
- }\r
- } else {\r
- if (!isset($options[$key])){\r
- $options[$key]=$value;\r
- }\r
- }\r
- }\r
- $options['gap']=2*$options['colGap'];\r
-\r
- $middle = ($this->ez['pageWidth']-$this->ez['rightMargin'])/2+($this->ez['leftMargin'])/2;\r
- // figure out the maximum widths of the text within each column\r
- $maxWidth=array();\r
- foreach($cols as $colName=>$colHeading){\r
- $maxWidth[$colName]=0;\r
- }\r
- // find the maximum cell widths based on the data\r
- foreach($data as $row){\r
- foreach($cols as $colName=>$colHeading){\r
- $w = $this->ezPrvtGetTextWidth($options['fontSize'],(string)$row[$colName])*1.01;\r
- if ($w > $maxWidth[$colName]){\r
- $maxWidth[$colName]=$w;\r
- }\r
- }\r
- }\r
- // and the maximum widths to fit in the headings\r
- foreach($cols as $colName=>$colTitle){\r
- $w = $this->ezPrvtGetTextWidth($options['fontSize'],(string)$colTitle)*1.01;\r
- if ($w > $maxWidth[$colName]){\r
- $maxWidth[$colName]=$w;\r
- }\r
- }\r
-\r
- // calculate the start positions of each of the columns\r
- $pos=array();\r
- $x=0;\r
- $t=$x;\r
- $adjustmentWidth=0;\r
- $setWidth=0;\r
- foreach($maxWidth as $colName => $w){\r
- $pos[$colName]=$t;\r
- // if the column width has been specified then set that here, also total the\r
- // width avaliable for adjustment\r
- if (isset($options['cols'][$colName]) && isset($options['cols'][$colName]['width']) && $options['cols'][$colName]['width']>0){\r
- $t=$t+$options['cols'][$colName]['width'];\r
- $maxWidth[$colName] = $options['cols'][$colName]['width']-$options['gap'];\r
- $setWidth += $options['cols'][$colName]['width'];\r
- } else {\r
- $t=$t+$w+$options['gap'];\r
- $adjustmentWidth += $w;\r
- $setWidth += $options['gap'];\r
- }\r
- }\r
- $pos['_end_']=$t;\r
-\r
- // if maxWidth is specified, and the table is too wide, and the width has not been set,\r
- // then set the width.\r
- if ($options['width']==0 && $options['maxWidth'] && ($t-$x)>$options['maxWidth']){\r
- // then need to make this one smaller\r
- $options['width']=$options['maxWidth'];\r
- }\r
-\r
- if ($options['width'] && $adjustmentWidth>0 && $setWidth<$options['width']){\r
- // first find the current widths of the columns involved in this mystery\r
- $cols0 = array();\r
- $cols1 = array();\r
- $xq=0;\r
- $presentWidth=0;\r
- $last='';\r
- foreach($pos as $colName=>$p){\r
- if (!isset($options['cols'][$last]) || !isset($options['cols'][$last]['width']) || $options['cols'][$last]['width']<=0){\r
- if (strlen($last)){\r
- $cols0[$last]=$p-$xq -$options['gap'];\r
- $presentWidth += ($p-$xq - $options['gap']);\r
- }\r
- } else {\r
- $cols1[$last]=$p-$xq;\r
- }\r
- $last=$colName;\r
- $xq=$p;\r
- }\r
- // $cols0 contains the widths of all the columns which are not set\r
- $neededWidth = $options['width']-$setWidth;\r
- // if needed width is negative then add it equally to each column, else get more tricky\r
- if ($presentWidth<$neededWidth){\r
- foreach($cols0 as $colName=>$w){\r
- $cols0[$colName]+= ($neededWidth-$presentWidth)/count($cols0);\r
- }\r
- } else {\r
-\r
- $cnt=0;\r
- while ($presentWidth>$neededWidth && $cnt<100){\r
- $cnt++; // insurance policy\r
- // find the widest columns, and the next to widest width\r
- $aWidest = array();\r
- $nWidest=0;\r
- $widest=0;\r
- foreach($cols0 as $colName=>$w){\r
- if ($w>$widest){\r
- $aWidest=array($colName);\r
- $nWidest = $widest;\r
- $widest=$w;\r
- } else if ($w==$widest){\r
- $aWidest[]=$colName;\r
- }\r
- }\r
- // then figure out what the width of the widest columns would have to be to take up all the slack\r
- $newWidestWidth = $widest - ($presentWidth-$neededWidth)/count($aWidest);\r
- if ($newWidestWidth > $nWidest){\r
- // then there is space to set them to this\r
- foreach($aWidest as $colName){\r
- $cols0[$colName] = $newWidestWidth;\r
- }\r
- $presentWidth=$neededWidth;\r
- } else {\r
- // there is not space, reduce the size of the widest ones down to the next size down, and we\r
- // will go round again\r
- foreach($aWidest as $colName){\r
- $cols0[$colName] = $nWidest;\r
- }\r
- $presentWidth=$presentWidth-($widest-$nWidest)*count($aWidest);\r
- }\r
- }\r
- }\r
- // $cols0 now contains the new widths of the constrained columns.\r
- // now need to update the $pos and $maxWidth arrays\r
- $xq=0;\r
- foreach($pos as $colName=>$p){\r
- $pos[$colName]=$xq;\r
- if (!isset($options['cols'][$colName]) || !isset($options['cols'][$colName]['width']) || $options['cols'][$colName]['width']<=0){\r
- if (isset($cols0[$colName])){\r
- $xq += $cols0[$colName] + $options['gap'];\r
- $maxWidth[$colName]=$cols0[$colName];\r
- }\r
- } else {\r
- if (isset($cols1[$colName])){\r
- $xq += $cols1[$colName];\r
- }\r
- }\r
- }\r
-\r
- $t=$x+$options['width'];\r
- $pos['_end_']=$t;\r
- }\r
-\r
- // now adjust the table to the correct location across the page\r
- switch ($options['xPos']){\r
- case 'left':\r
- $xref = $this->ez['leftMargin'];\r
- break;\r
- case 'right':\r
- $xref = $this->ez['pageWidth'] - $this->ez['rightMargin'];\r
- break;\r
- case 'centre':\r
- case 'center':\r
- $xref = $middle;\r
- break;\r
- default:\r
- $xref = $options['xPos'];\r
- break;\r
- }\r
- switch ($options['xOrientation']){\r
- case 'left':\r
- $dx = $xref-$t;\r
- break;\r
- case 'right':\r
- $dx = $xref;\r
- break;\r
- case 'centre':\r
- case 'center':\r
- $dx = $xref-$t/2;\r
- break;\r
- }\r
-\r
-\r
- foreach($pos as $k=>$v){\r
- $pos[$k]=$v+$dx;\r
- }\r
- $x0=$x+$dx;\r
- $x1=$t+$dx;\r
-\r
- $baseLeftMargin = $this->ez['leftMargin'];\r
- $basePos = $pos;\r
- $baseX0 = $x0;\r
- $baseX1 = $x1;\r
-\r
- // ok, just about ready to make me a table\r
- $this->setColor($options['textCol'][0],$options['textCol'][1],$options['textCol'][2]);\r
- $this->setStrokeColor($options['shadeCol'][0],$options['shadeCol'][1],$options['shadeCol'][2]);\r
-\r
- $middle = ($x1+$x0)/2;\r
-\r
- // start a transaction which will be used to regress the table, if there are not enough rows protected\r
- if ($options['protectRows']>0){\r
- $this->transaction('start');\r
- $movedOnce=0;\r
- }\r
- $abortTable = 1;\r
- while ($abortTable){\r
- $abortTable=0;\r
-\r
- $dm = $this->ez['leftMargin']-$baseLeftMargin;\r
- foreach($basePos as $k=>$v){\r
- $pos[$k]=$v+$dm;\r
- }\r
- $x0=$baseX0+$dm;\r
- $x1=$baseX1+$dm;\r
- $middle = ($x1+$x0)/2;\r
-\r
-\r
- // if the title is set, then do that\r
- if (strlen($title)){\r
- $w = $this->getTextWidth($options['titleFontSize'],$title);\r
- $this->y -= $this->getFontHeight($options['titleFontSize']);\r
- if ($this->y < $this->ez['bottomMargin']){\r
- $this->ezNewPage();\r
- // margins may have changed on the newpage\r
- $dm = $this->ez['leftMargin']-$baseLeftMargin;\r
- foreach($basePos as $k=>$v){\r
- $pos[$k]=$v+$dm;\r
- }\r
- $x0=$baseX0+$dm;\r
- $x1=$baseX1+$dm;\r
- $middle = ($x1+$x0)/2;\r
- $this->y -= $this->getFontHeight($options['titleFontSize']);\r
- }\r
- $this->addText($middle-$w/2,$this->y,$options['titleFontSize'],$title);\r
- $this->y -= $options['titleGap'];\r
- }\r
-\r
- // margins may have changed on the newpage\r
- $dm = $this->ez['leftMargin']-$baseLeftMargin;\r
- foreach($basePos as $k=>$v){\r
- $pos[$k]=$v+$dm;\r
- }\r
- $x0=$baseX0+$dm;\r
- $x1=$baseX1+$dm;\r
-\r
- $y=$this->y; // to simplify the code a bit\r
-\r
- // make the table\r
- $height = $this->getFontHeight($options['fontSize']);\r
- $decender = $this->getFontDecender($options['fontSize']);\r
-\r
-\r
-\r
- $y0=$y+$decender;\r
- $dy=0;\r
- if ($options['showHeadings']){\r
- // this function will move the start of the table to a new page if it does not fit on this one\r
- $headingHeight = $this->ezPrvtTableColumnHeadings($cols,$pos,$maxWidth,$height,$decender,$options['rowGap'],$options['fontSize'],$y,$options);\r
- $y0 = $y+$headingHeight;\r
- $y1 = $y;\r
-\r
-\r
- $dm = $this->ez['leftMargin']-$baseLeftMargin;\r
- foreach($basePos as $k=>$v){\r
- $pos[$k]=$v+$dm;\r
- }\r
- $x0=$baseX0+$dm;\r
- $x1=$baseX1+$dm;\r
-\r
- } else {\r
- $y1 = $y0;\r
- }\r
- $firstLine=1;\r
-\r
-\r
- // open an object here so that the text can be put in over the shading\r
- if ($options['shaded']){\r
- $this->saveState();\r
- $textObjectId = $this->openObject();\r
- $this->closeObject();\r
- $this->addObject($textObjectId);\r
- $this->reopenObject($textObjectId);\r
- }\r
-\r
- $cnt=0;\r
- $newPage=0;\r
- foreach($data as $row){\r
- $cnt++;\r
- // the transaction support will be used to prevent rows being split\r
- if ($options['splitRows']==0){\r
- $pageStart = $this->ezPageCount;\r
- if (isset($this->ez['columns']) && $this->ez['columns']['on']==1){\r
- $columnStart = $this->ez['columns']['colNum'];\r
- }\r
- $this->transaction('start');\r
- $row_orig = $row;\r
- $y_orig = $y;\r
- $y0_orig = $y0;\r
- $y1_orig = $y1;\r
- }\r
- $ok=0;\r
- $secondTurn=0;\r
- while(!$abortTable && $ok == 0){\r
-\r
- $mx=0;\r
- $newRow=1;\r
- while(!$abortTable && ($newPage || $newRow)){\r
-\r
- $y-=$height;\r
- if ($newPage || $y<$this->ez['bottomMargin'] || (isset($options['minRowSpace']) && $y<($this->ez['bottomMargin']+$options['minRowSpace'])) ){\r
- // check that enough rows are with the heading\r
- if ($options['protectRows']>0 && $movedOnce==0 && $cnt<=$options['protectRows']){\r
- // then we need to move the whole table onto the next page\r
- $movedOnce = 1;\r
- $abortTable = 1;\r
- }\r
-\r
- $y2=$y-$mx+2*$height+$decender-$newRow*$height;\r
- if ($options['showLines']){\r
- if (!$options['showHeadings']){\r
- $y0=$y1;\r
- }\r
- $this->ezPrvtTableDrawLines($pos,$options['gap'],$x0,$x1,$y0,$y1,$y2,$options['lineCol'],$options['innerLineThickness'],$options['outerLineThickness'],$options['showLines']);\r
- }\r
- if ($options['shaded']){\r
- $this->closeObject();\r
- $this->restoreState();\r
- }\r
- $this->ezNewPage();\r
- // and the margins may have changed, this is due to the possibility of the columns being turned on\r
- // as the columns are managed by manipulating the margins\r
-\r
- $dm = $this->ez['leftMargin']-$baseLeftMargin;\r
- foreach($basePos as $k=>$v){\r
- $pos[$k]=$v+$dm;\r
- }\r
-// $x0=$x0+$dm;\r
-// $x1=$x1+$dm;\r
- $x0=$baseX0+$dm;\r
- $x1=$baseX1+$dm;\r
-\r
- if ($options['shaded']){\r
- $this->saveState();\r
- $textObjectId = $this->openObject();\r
- $this->closeObject();\r
- $this->addObject($textObjectId);\r
- $this->reopenObject($textObjectId);\r
- }\r
- $this->setColor($options['textCol'][0],$options['textCol'][1],$options['textCol'][2],1);\r
- $y = $this->ez['pageHeight']-$this->ez['topMargin'];\r
- $y0=$y+$decender;\r
- $mx=0;\r
- if ($options['showHeadings']){\r
- $this->ezPrvtTableColumnHeadings($cols,$pos,$maxWidth,$height,$decender,$options['rowGap'],$options['fontSize'],$y,$options);\r
- $y1=$y;\r
- } else {\r
- $y1=$y0;\r
- }\r
- $firstLine=1;\r
- $y -= $height;\r
- }\r
- $newRow=0;\r
- // write the actual data\r
- // if these cells need to be split over a page, then $newPage will be set, and the remaining\r
- // text will be placed in $leftOvers\r
- $newPage=0;\r
- $leftOvers=array();\r
-\r
- foreach($cols as $colName=>$colTitle){\r
- $this->ezSetY($y+$height);\r
- $colNewPage=0;\r
- if (isset($row[$colName])){\r
- if (isset($options['cols'][$colName]) && isset($options['cols'][$colName]['link']) && strlen($options['cols'][$colName]['link'])){\r
-\r
- $lines = explode("\n",$row[$colName]);\r
- if (isset($row[$options['cols'][$colName]['link']]) && strlen($row[$options['cols'][$colName]['link']])){\r
- foreach($lines as $k=>$v){\r
- $lines[$k]='<c:alink:'.$row[$options['cols'][$colName]['link']].'>'.$v.'</c:alink>';\r
- }\r
- }\r
- } else {\r
- $lines = explode("\n",$row[$colName]);\r
- }\r
- } else {\r
- $lines = array();\r
- }\r
- $this->y -= $options['rowGap'];\r
- foreach ($lines as $line){\r
- $line = $this->ezProcessText($line);\r
- $start=1;\r
-\r
- while (strlen($line) || $start){\r
- $start=0;\r
- if (!$colNewPage){\r
- $this->y=$this->y-$height;\r
- }\r
- if ($this->y < $this->ez['bottomMargin']){\r
- // $this->ezNewPage();\r
- $newPage=1; // whether a new page is required for any of the columns\r
- $colNewPage=1; // whether a new page is required for this column\r
- }\r
- if ($colNewPage){\r
- if (isset($leftOvers[$colName])){\r
- $leftOvers[$colName].="\n".$line;\r
- } else {\r
- $leftOvers[$colName] = $line;\r
- }\r
- $line='';\r
- } else {\r
- if (isset($options['cols'][$colName]) && isset($options['cols'][$colName]['justification']) ){\r
- $just = $options['cols'][$colName]['justification'];\r
- } else {\r
- $just='left';\r
- }\r
-\r
- $line=$this->addTextWrap($pos[$colName],$this->y,$maxWidth[$colName],$options['fontSize'],$line,$just);\r
- }\r
- }\r
- }\r
-\r
- $dy=$y+$height-$this->y+$options['rowGap'];\r
- if ($dy-$height*$newPage>$mx){\r
- $mx=$dy-$height*$newPage;\r
- }\r
- }\r
- // set $row to $leftOvers so that they will be processed onto the new page\r
- $row = $leftOvers;\r
- // now add the shading underneath\r
- if ($options['shaded'] && $cnt%2==0){\r
- $this->closeObject();\r
- $this->setColor($options['shadeCol'][0],$options['shadeCol'][1],$options['shadeCol'][2],1);\r
- $this->filledRectangle($x0-$options['gap']/2,$y+$decender+$height-$mx,$x1-$x0,$mx);\r
- $this->reopenObject($textObjectId);\r
- }\r
-\r
- if ($options['shaded']==2 && $cnt%2==1){\r
- $this->closeObject();\r
- $this->setColor($options['shadeCol2'][0],$options['shadeCol2'][1],$options['shadeCol2'][2],1);\r
- $this->filledRectangle($x0-$options['gap']/2,$y+$decender+$height-$mx,$x1-$x0,$mx);\r
- $this->reopenObject($textObjectId);\r
- }\r
-\r
- if ($options['showLines']>1){\r
- // then draw a line on the top of each block\r
-// $this->closeObject();\r
- $this->saveState();\r
- $this->setStrokeColor($options['lineCol'][0],$options['lineCol'][1],$options['lineCol'][2],1);\r
-// $this->line($x0-$options['gap']/2,$y+$decender+$height-$mx,$x1-$x0,$mx);\r
- if ($firstLine){\r
- $this->setLineStyle($options['outerLineThickness']);\r
- $firstLine=0;\r
- } else {\r
- $this->setLineStyle($options['innerLineThickness']);\r
- }\r
- $this->line($x0-$options['gap']/2,$y+$decender+$height,$x1-$options['gap']/2,$y+$decender+$height);\r
- $this->restoreState();\r
-// $this->reopenObject($textObjectId);\r
- }\r
- } // end of while\r
- $y=$y-$mx+$height;\r
-\r
- // checking row split over pages\r
- if ($options['splitRows']==0){\r
- if ( ( ($this->ezPageCount != $pageStart) || (isset($this->ez['columns']) && $this->ez['columns']['on']==1 && $columnStart != $this->ez['columns']['colNum'] )) && $secondTurn==0){\r
- // then we need to go back and try that again !\r
- $newPage=1;\r
- $secondTurn=1;\r
- $this->transaction('rewind');\r
- $row = $row_orig;\r
- $y = $y_orig;\r
- $y0 = $y0_orig;\r
- $y1 = $y1_orig;\r
- $ok=0;\r
-\r
- $dm = $this->ez['leftMargin']-$baseLeftMargin;\r
- foreach($basePos as $k=>$v){\r
- $pos[$k]=$v+$dm;\r
- }\r
- $x0=$baseX0+$dm;\r
- $x1=$baseX1+$dm;\r
-\r
- } else {\r
- $this->transaction('commit');\r
- $ok=1;\r
- }\r
- } else {\r
- $ok=1; // don't go round the loop if splitting rows is allowed\r
- }\r
-\r
- } // end of while to check for row splitting\r
- if ($abortTable){\r
- if ($ok==0){\r
- $this->transaction('abort');\r
- }\r
- // only the outer transaction should be operational\r
- $this->transaction('rewind');\r
- $this->ezNewPage();\r
- break;\r
- }\r
-\r
- } // end of foreach ($data as $row)\r
-\r
- } // end of while ($abortTable)\r
-\r
- // table has been put on the page, the rows guarded as required, commit.\r
- $this->transaction('commit');\r
-\r
- $y2=$y+$decender;\r
- if ($options['showLines']){\r
- if (!$options['showHeadings']){\r
- $y0=$y1;\r
- }\r
- $this->ezPrvtTableDrawLines($pos,$options['gap'],$x0,$x1,$y0,$y1,$y2,$options['lineCol'],$options['innerLineThickness'],$options['outerLineThickness'],$options['showLines']);\r
- }\r
-\r
- // close the object for drawing the text on top\r
- if ($options['shaded']){\r
- $this->closeObject();\r
- $this->restoreState();\r
- }\r
-\r
- $this->y=$y;\r
- return $y;\r
-}\r
-\r
-// ------------------------------------------------------------------------------\r
-function ezProcessText($text){\r
- // this function will intially be used to implement underlining support, but could be used for a range of other\r
- // purposes\r
- $search = array('<u>','<U>','</u>','</U>');\r
- $replace = array('<c:uline>','<c:uline>','</c:uline>','</c:uline>');\r
- return str_replace($search,$replace,$text);\r
-}\r
-\r
-// ------------------------------------------------------------------------------\r
-\r
-function ezText($text,$size=0,$options=array(),$test=0){\r
- // this will add a string of text to the document, starting at the current drawing\r
- // position.\r
- // it will wrap to keep within the margins, including optional offsets from the left\r
- // and the right, if $size is not specified, then it will be the last one used, or\r
- // the default value (12 I think).\r
- // the text will go to the start of the next line when a return code "\n" is found.\r
- // possible options are:\r
- // 'left'=> number, gap to leave from the left margin\r
- // 'right'=> number, gap to leave from the right margin\r
- // 'aleft'=> number, absolute left position (overrides 'left')\r
- // 'aright'=> number, absolute right position (overrides 'right')\r
- // 'justification' => 'left','right','center','centre','full'\r
-\r
- // only set one of the next two items (leading overrides spacing)\r
- // 'leading' => number, defines the total height taken by the line, independent of the font height.\r
- // 'spacing' => a real number, though usually set to one of 1, 1.5, 2 (line spacing as used in word processing)\r
-\r
- // 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\r
-\r
- // apply the filtering which will make the underlining function.\r
- $text = $this->ezProcessText($text);\r
-\r
- $newPage=false;\r
- $store_y = $this->y;\r
-\r
- if (is_array($options) && isset($options['aleft'])){\r
- $left=$options['aleft'];\r
- } else {\r
- $left = $this->ez['leftMargin'] + ((is_array($options) && isset($options['left']))?$options['left']:0);\r
- }\r
- if (is_array($options) && isset($options['aright'])){\r
- $right=$options['aright'];\r
- } else {\r
- $right = $this->ez['pageWidth'] - $this->ez['rightMargin'] - ((is_array($options) && isset($options['right']))?$options['right']:0);\r
- }\r
- if ($size<=0){\r
- $size = $this->ez['fontSize'];\r
- } else {\r
- $this->ez['fontSize']=$size;\r
- }\r
-\r
- if (is_array($options) && isset($options['justification'])){\r
- $just = $options['justification'];\r
- } else {\r
- $just = 'left';\r
- }\r
-\r
- // modifications to give leading and spacing based on those given by Craig Heydenburg 1/1/02\r
- if (is_array($options) && isset($options['leading'])) { ## use leading instead of spacing\r
- $height = $options['leading'];\r
- } else if (is_array($options) && isset($options['spacing'])) {\r
- $height = $this->getFontHeight($size) * $options['spacing'];\r
- } else {\r
- $height = $this->getFontHeight($size);\r
- }\r
-\r
-\r
- $lines = explode("\n",$text);\r
- foreach ($lines as $line){\r
- $start=1;\r
- while (strlen($line) || $start){\r
- $start=0;\r
- $this->y=$this->y-$height;\r
- if ($this->y < $this->ez['bottomMargin']){\r
- if ($test){\r
- $newPage=true;\r
- } else {\r
- $this->ezNewPage();\r
- // and then re-calc the left and right, in case they have changed due to columns\r
- }\r
- }\r
- if (is_array($options) && isset($options['aleft'])){\r
- $left=$options['aleft'];\r
- } else {\r
- $left = $this->ez['leftMargin'] + ((is_array($options) && isset($options['left']))?$options['left']:0);\r
- }\r
- if (is_array($options) && isset($options['aright'])){\r
- $right=$options['aright'];\r
- } else {\r
- $right = $this->ez['pageWidth'] - $this->ez['rightMargin'] - ((is_array($options) && isset($options['right']))?$options['right']:0);\r
- }\r
- $line=$this->addTextWrap($left,$this->y,$right-$left,$size,$line,$just,0,$test);\r
- }\r
- }\r
-\r
- if ($test){\r
- $this->y=$store_y;\r
- return $newPage;\r
- } else {\r
- return $this->y;\r
- }\r
-}\r
-\r
-// ------------------------------------------------------------------------------\r
-\r
-function ezImage($image,$pad = 5,$width = 0,$resize = 'full',$just = 'center',$border = ''){\r
- //beta ezimage function\r
- if (stristr($image,'://'))//copy to temp file\r
- {\r
- $fp = @fopen($image,"rb");\r
- while(!feof($fp))\r
- {\r
- $cont.= fread($fp,1024);\r
- }\r
- fclose($fp);\r
- $image = tempnam ("/tmp", "php-pdf");\r
- $fp2 = @fopen($image,"w");\r
- fwrite($fp2,$cont);\r
- fclose($fp2);\r
- $temp = true;\r
- }\r
-\r
- if (!(file_exists($image))) return false; //return immediately if image file does not exist\r
- $imageInfo = getimagesize($image);\r
- switch ($imageInfo[2]){\r
- case 2:\r
- $type = "jpeg";\r
- break;\r
- case 3:\r
- $type = "png";\r
- break;\r
- default:\r
- return false; //return if file is not jpg or png\r
- }\r
- if ($width == 0) $width = $imageInfo[0]; //set width\r
- $ratio = $imageInfo[0]/$imageInfo[1];\r
-\r
- //get maximum width of image\r
- if (isset($this->ez['columns']) && $this->ez['columns']['on'] == 1)\r
- {\r
- $bigwidth = $this->ez['columns']['width'] - ($pad * 2);\r
- }\r
- else\r
- {\r
- $bigwidth = $this->ez['pageWidth'] - ($pad * 2);\r
- }\r
- //fix width if larger than maximum or if $resize=full\r
- if ($resize == 'full' || $resize == 'width' || $width > $bigwidth)\r
- {\r
- $width = $bigwidth;\r
-\r
- }\r
-\r
- $height = ($width/$ratio); //set height\r
-\r
- //fix size if runs off page\r
- if ($height > ($this->y - $this->ez['bottomMargin'] - ($pad * 2)))\r
- {\r
- if ($resize != 'full')\r
- {\r
- $this->ezNewPage();\r
- }\r
- else\r
- {\r
- $height = ($this->y - $this->ez['bottomMargin'] - ($pad * 2)); //shrink height\r
- $width = ($height*$ratio); //fix width\r
- }\r
- }\r
-\r
- //fix x-offset if image smaller than bigwidth\r
- if ($width < $bigwidth)\r
- {\r
- //center if justification=center\r
- if ($just == 'center')\r
- {\r
- $offset = ($bigwidth - $width) / 2;\r
- }\r
- //move to right if justification=right\r
- if ($just == 'right')\r
- {\r
- $offset = ($bigwidth - $width);\r
- }\r
- //leave at left if justification=left\r
- if ($just == 'left')\r
- {\r
- $offset = 0;\r
- }\r
- }\r
-\r
-\r
- //call appropriate function\r
- if ($type == "jpeg"){\r
- $this->addJpegFromFile($image,$this->ez['leftMargin'] + $pad + $offset, $this->y + $this->getFontHeight($this->ez['fontSize']) - $pad - $height,$width);\r
- }\r
-\r
- if ($type == "png"){\r
- $this->addPngFromFile($image,$this->ez['leftMargin'] + $pad + $offset, $this->y + $this->getFontHeight($this->ez['fontSize']) - $pad - $height,$width);\r
- }\r
- //draw border\r
- if ($border != '')\r
- {\r
- if (!(isset($border['color'])))\r
- {\r
- $border['color']['red'] = .5;\r
- $border['color']['blue'] = .5;\r
- $border['color']['green'] = .5;\r
- }\r
- if (!(isset($border['width']))) $border['width'] = 1;\r
- if (!(isset($border['cap']))) $border['cap'] = 'round';\r
- if (!(isset($border['join']))) $border['join'] = 'round';\r
-\r
-\r
- $this->setStrokeColor($border['color']['red'],$border['color']['green'],$border['color']['blue']);\r
- $this->setLineStyle($border['width'],$border['cap'],$border['join']);\r
- $this->rectangle($this->ez['leftMargin'] + $pad + $offset, $this->y + $this->getFontHeight($this->ez['fontSize']) - $pad - $height,$width,$height);\r
-\r
- }\r
- // move y below image\r
- $this->y = $this->y - $pad - $height;\r
- //remove tempfile for remote images\r
- if ($temp == true) unlink($image);\r
-\r
-}\r
-// ------------------------------------------------------------------------------\r
-\r
-// note that templating code is still considered developmental - have not really figured\r
-// out a good way of doing this yet.\r
-function loadTemplate($templateFile){\r
- // this function will load the requested template ($file includes full or relative pathname)\r
- // the code for the template will be modified to make it name safe, and then stored in\r
- // an array for later use\r
- // The id of the template will be returned for the user to operate on it later\r
- if (!file_exists($templateFile)){\r
- return -1;\r
- }\r
-\r
- $code = implode('',file($templateFile));\r
- if (!strlen($code)){\r
- return;\r
- }\r
-\r
- $code = trim($code);\r
- if (substr($code,0,5)=='<?php'){\r
- $code = substr($code,5);\r
- }\r
- if (substr($code,-2)=='?>'){\r
- $code = substr($code,0,strlen($code)-2);\r
- }\r
- if (isset($this->ez['numTemplates'])){\r
- $newNum = $this->ez['numTemplates'];\r
- $this->ez['numTemplates']++;\r
- } else {\r
- $newNum=0;\r
- $this->ez['numTemplates']=1;\r
- $this->ez['templates']=array();\r
- }\r
-\r
- $this->ez['templates'][$newNum]['code']=$code;\r
-\r
- return $newNum;\r
-}\r
-\r
-// ------------------------------------------------------------------------------\r
-\r
-function execTemplate($id,$data=array(),$options=array()){\r
- // execute the given template on the current document.\r
- if (!isset($this->ez['templates'][$id])){\r
- return;\r
- }\r
- eval($this->ez['templates'][$id]['code']);\r
-}\r
-\r
-// ------------------------------------------------------------------------------\r
-function ilink($info){\r
- $this->alink($info,1);\r
-}\r
-\r
-function alink($info,$internal=0){\r
- // a callback function to support the formation of clickable links within the document\r
- $lineFactor=0.05; // the thickness of the line as a proportion of the height. also the drop of the line.\r
- switch($info['status']){\r
- case 'start':\r
- case 'sol':\r
- // the beginning of the link\r
- // this should contain the URl for the link as the 'p' entry, and will also contain the value of 'nCallback'\r
- if (!isset($this->ez['links'])){\r
- $this->ez['links']=array();\r
- }\r
- $i = $info['nCallback'];\r
- $this->ez['links'][$i] = array('x'=>$info['x'],'y'=>$info['y'],'angle'=>$info['angle'],'decender'=>$info['decender'],'height'=>$info['height'],'url'=>$info['p']);\r
- if ($internal==0){\r
- $this->saveState();\r
- $this->setColor(0,0,1);\r
- $this->setStrokeColor(0,0,1);\r
- $thick = $info['height']*$lineFactor;\r
- $this->setLineStyle($thick);\r
- }\r
- break;\r
- case 'end':\r
- case 'eol':\r
- // the end of the link\r
- // assume that it is the most recent opening which has closed\r
- $i = $info['nCallback'];\r
- $start = $this->ez['links'][$i];\r
- // add underlining\r
- if ($internal){\r
- $this->addInternalLink($start['url'],$start['x'],$start['y']+$start['decender'],$info['x'],$start['y']+$start['decender']+$start['height']);\r
- } else {\r
- $a = deg2rad((float)$start['angle']-90.0);\r
- $drop = $start['height']*$lineFactor*1.5;\r
- $dropx = cos($a)*$drop;\r
- $dropy = -sin($a)*$drop;\r
- $this->line($start['x']-$dropx,$start['y']-$dropy,$info['x']-$dropx,$info['y']-$dropy);\r
- $this->addLink($start['url'],$start['x'],$start['y']+$start['decender'],$info['x'],$start['y']+$start['decender']+$start['height']);\r
- $this->restoreState();\r
- }\r
- break;\r
- }\r
-}\r
-\r
-// ------------------------------------------------------------------------------\r
-\r
-function uline($info){\r
- // a callback function to support underlining\r
- $lineFactor=0.05; // the thickness of the line as a proportion of the height. also the drop of the line.\r
- switch($info['status']){\r
- case 'start':\r
- case 'sol':\r
-\r
- // the beginning of the underline zone\r
- if (!isset($this->ez['links'])){\r
- $this->ez['links']=array();\r
- }\r
- $i = $info['nCallback'];\r
- $this->ez['links'][$i] = array('x'=>$info['x'],'y'=>$info['y'],'angle'=>$info['angle'],'decender'=>$info['decender'],'height'=>$info['height']);\r
- $this->saveState();\r
- $thick = $info['height']*$lineFactor;\r
- $this->setLineStyle($thick);\r
- break;\r
- case 'end':\r
- case 'eol':\r
- // the end of the link\r
- // assume that it is the most recent opening which has closed\r
- $i = $info['nCallback'];\r
- $start = $this->ez['links'][$i];\r
- // add underlining\r
- $a = deg2rad((float)$start['angle']-90.0);\r
- $drop = $start['height']*$lineFactor*1.5;\r
- $dropx = cos($a)*$drop;\r
- $dropy = -sin($a)*$drop;\r
- $this->line($start['x']-$dropx,$start['y']-$dropy,$info['x']-$dropx,$info['y']-$dropy);\r
- $this->restoreState();\r
- break;\r
- }\r
-}\r
-\r
-// ------------------------------------------------------------------------------\r
-\r
-}\r
-?>
\ No newline at end of file