📄 class.ezpdf.php
字号:
// then there is space to set them to this
foreach($aWidest as $colName){
$cols0[$colName] = $newWidestWidth;
}
$presentWidth=$neededWidth;
} else {
// there is not space, reduce the size of the widest ones down to the next size down, and we
// will go round again
foreach($aWidest as $colName){
$cols0[$colName] = $nWidest;
}
$presentWidth=$presentWidth-($widest-$nWidest)*count($aWidest);
}
}
}
// $cols0 now contains the new widths of the constrained columns.
// now need to update the $pos and $maxWidth arrays
$xq=0;
foreach($pos as $colName=>$p){
$pos[$colName]=$xq;
if (!isset($options['cols'][$colName]) || !isset($options['cols'][$colName]['width']) || $options['cols'][$colName]['width']<=0){
if (isset($cols0[$colName])){
$xq += $cols0[$colName] + $options['gap'];
$maxWidth[$colName]=$cols0[$colName];
}
} else {
if (isset($cols1[$colName])){
$xq += $cols1[$colName];
}
}
}
$t=$x+$options['width'];
$pos['_end_']=$t;
}
// now adjust the table to the correct location across the page
switch ($options['xPos']){
case 'left':
$xref = $this->ez['leftMargin'];
break;
case 'right':
$xref = $this->ez['pageWidth'] - $this->ez['rightMargin'];
break;
case 'centre':
case 'center':
$xref = $middle;
break;
default:
$xref = $options['xPos'];
break;
}
switch ($options['xOrientation']){
case 'left':
$dx = $xref-$t;
break;
case 'right':
$dx = $xref;
break;
case 'centre':
case 'center':
$dx = $xref-$t/2;
break;
}
foreach($pos as $k=>$v){
$pos[$k]=$v+$dx;
}
$x0=$x+$dx;
$x1=$t+$dx;
$baseLeftMargin = $this->ez['leftMargin'];
$basePos = $pos;
$baseX0 = $x0;
$baseX1 = $x1;
// ok, just about ready to make me a table
$this->setColor($options['textCol'][0],$options['textCol'][1],$options['textCol'][2]);
$this->setStrokeColor($options['shadeCol'][0],$options['shadeCol'][1],$options['shadeCol'][2]);
$middle = ($x1+$x0)/2;
// start a transaction which will be used to regress the table, if there are not enough rows protected
if ($options['protectRows']>0){
$this->transaction('start');
$movedOnce=0;
}
$abortTable = 1;
while ($abortTable){
$abortTable=0;
$dm = $this->ez['leftMargin']-$baseLeftMargin;
foreach($basePos as $k=>$v){
$pos[$k]=$v+$dm;
}
$x0=$baseX0+$dm;
$x1=$baseX1+$dm;
$middle = ($x1+$x0)/2;
// if the title is set, then do that
if (strlen($title)){
$w = $this->getTextWidth($options['titleFontSize'],$title);
$this->y -= $this->getFontHeight($options['titleFontSize']);
if ($this->y < $this->ez['bottomMargin']){
$this->ezNewPage();
// margins may have changed on the newpage
$dm = $this->ez['leftMargin']-$baseLeftMargin;
foreach($basePos as $k=>$v){
$pos[$k]=$v+$dm;
}
$x0=$baseX0+$dm;
$x1=$baseX1+$dm;
$middle = ($x1+$x0)/2;
$this->y -= $this->getFontHeight($options['titleFontSize']);
}
$this->addText($middle-$w/2,$this->y,$options['titleFontSize'],$title);
$this->y -= $options['titleGap'];
}
// margins may have changed on the newpage
$dm = $this->ez['leftMargin']-$baseLeftMargin;
foreach($basePos as $k=>$v){
$pos[$k]=$v+$dm;
}
$x0=$baseX0+$dm;
$x1=$baseX1+$dm;
$y=$this->y; // to simplify the code a bit
// make the table
$height = $this->getFontHeight($options['fontSize']);
$decender = $this->getFontDecender($options['fontSize']);
$y0=$y+$decender;
$dy=0;
if ($options['showHeadings']){
// this function will move the start of the table to a new page if it does not fit on this one
$headingHeight = $this->ezPrvtTableColumnHeadings($cols,$pos,$maxWidth,$height,$decender,$options['rowGap'],$options['fontSize'],$y,$options);
$y0 = $y+$headingHeight;
$y1 = $y;
$dm = $this->ez['leftMargin']-$baseLeftMargin;
foreach($basePos as $k=>$v){
$pos[$k]=$v+$dm;
}
$x0=$baseX0+$dm;
$x1=$baseX1+$dm;
} else {
$y1 = $y0;
}
$firstLine=1;
// open an object here so that the text can be put in over the shading
if ($options['shaded']){
$this->saveState();
$textObjectId = $this->openObject();
$this->closeObject();
$this->addObject($textObjectId);
$this->reopenObject($textObjectId);
}
$cnt=0;
$newPage=0;
foreach($data as $row){
$cnt++;
// the transaction support will be used to prevent rows being split
if ($options['splitRows']==0){
$pageStart = $this->ezPageCount;
if (isset($this->ez['columns']) && $this->ez['columns']['on']==1){
$columnStart = $this->ez['columns']['colNum'];
}
$this->transaction('start');
$row_orig = $row;
$y_orig = $y;
$y0_orig = $y0;
$y1_orig = $y1;
}
$ok=0;
$secondTurn=0;
while(!$abortTable && $ok == 0){
$mx=0;
$newRow=1;
while(!$abortTable && ($newPage || $newRow)){
$y-=$height;
if ($newPage || $y<$this->ez['bottomMargin'] || (isset($options['minRowSpace']) && $y<($this->ez['bottomMargin']+$options['minRowSpace'])) ){
// check that enough rows are with the heading
if ($options['protectRows']>0 && $movedOnce==0 && $cnt<=$options['protectRows']){
// then we need to move the whole table onto the next page
$movedOnce = 1;
$abortTable = 1;
}
$y2=$y-$mx+2*$height+$decender-$newRow*$height;
if ($options['showLines']){
if (!$options['showHeadings']){
$y0=$y1;
}
$this->ezPrvtTableDrawLines($pos,$options['gap'],$x0,$x1,$y0,$y1,$y2,$options['lineCol'],$options['innerLineThickness'],$options['outerLineThickness'],$options['showLines']);
}
if ($options['shaded']){
$this->closeObject();
$this->restoreState();
}
$this->ezNewPage();
// and the margins may have changed, this is due to the possibility of the columns being turned on
// as the columns are managed by manipulating the margins
$dm = $this->ez['leftMargin']-$baseLeftMargin;
foreach($basePos as $k=>$v){
$pos[$k]=$v+$dm;
}
// $x0=$x0+$dm;
// $x1=$x1+$dm;
$x0=$baseX0+$dm;
$x1=$baseX1+$dm;
if ($options['shaded']){
$this->saveState();
$textObjectId = $this->openObject();
$this->closeObject();
$this->addObject($textObjectId);
$this->reopenObject($textObjectId);
}
$this->setColor($options['textCol'][0],$options['textCol'][1],$options['textCol'][2],1);
$y = $this->ez['pageHeight']-$this->ez['topMargin'];
$y0=$y+$decender;
$mx=0;
if ($options['showHeadings']){
$this->ezPrvtTableColumnHeadings($cols,$pos,$maxWidth,$height,$decender,$options['rowGap'],$options['fontSize'],$y,$options);
$y1=$y;
} else {
$y1=$y0;
}
$firstLine=1;
$y -= $height;
}
$newRow=0;
// write the actual data
// if these cells need to be split over a page, then $newPage will be set, and the remaining
// text will be placed in $leftOvers
$newPage=0;
$leftOvers=array();
foreach($cols as $colName=>$colTitle){
$this->ezSetY($y+$height);
$colNewPage=0;
if (isset($row[$colName])){
if (isset($options['cols'][$colName]) && isset($options['cols'][$colName]['link']) && strlen($options['cols'][$colName]['link'])){
$lines = explode("\n",$row[$colName]);
if (isset($row[$options['cols'][$colName]['link']]) && strlen($row[$options['cols'][$colName]['link']])){
foreach($lines as $k=>$v){
$lines[$k]='<c:alink:'.$row[$options['cols'][$colName]['link']].'>'.$v.'</c:alink>';
}
}
} else {
$lines = explode("\n",$row[$colName]);
}
} else {
$lines = array();
}
$this->y -= $options['rowGap'];
foreach ($lines as $line){
$line = $this->ezProcessText($line);
$start=1;
while (strlen($line) || $start){
$start=0;
if (!$colNewPage){
$this->y=$this->y-$height;
}
if ($this->y < $this->ez['bottomMargin']){
// $this->ezNewPage();
$newPage=1; // whether a new page is required for any of the columns
$colNewPage=1; // whether a new page is required for this column
}
if ($colNewPage){
if (isset($leftOvers[$colName])){
$leftOvers[$colName].="\n".$line;
} else {
$leftOvers[$colName] = $line;
}
$line='';
} else {
if (isset($options['cols'][$colName]) && isset($options['cols'][$colName]['justification']) ){
$just = $options['cols'][$colName]['justification'];
} else {
$just='left';
}
$line=$this->addTextWrap($pos[$colName],$this->y,$maxWidth[$colName],$options['fontSize'],$line,$just);
}
}
}
$dy=$y+$height-$this->y+$options['rowGap'];
if ($dy-$height*$newPage>$mx){
$mx=$dy-$height*$newPage;
}
}
// set $row to $leftOvers so that they will be processed onto the new page
$row = $leftOvers;
// now add the shading underneath
if ($options['shaded'] && $cnt%2==0){
$this->closeObject();
$this->setColor($options['shadeCol'][0],$options['shadeCol'][1],$options['shadeCol'][2],1);
$this->filledRectangle($x0-$options['gap']/2,$y+$decender+$height-$mx,$x1-$x0,$mx);
$this->reopenObject($textObjectId);
}
if ($options['shaded']==2 && $cnt%2==1){
$this->closeObject();
$this->setColor($options['shadeCol2'][0],$options['shadeCol2'][1],$options['shadeCol2'][2],1);
$this->filledRectangle($x0-$options['gap']/2,$y+$decender+$height-$mx,$x1-$x0,$mx);
$this->reopenObject($textObjectId);
}
if ($options['showLines']>1){
// then draw a line on the top of each block
// $this->closeObject();
$this->saveState();
$this->setStrokeColor($options['lineCol'][0],$options['lineCol'][1],$options['lineCol'][2],1);
// $this->line($x0-$options['gap']/2,$y+$decender+$height-$mx,$x1-$x0,$mx);
if ($firstLine){
$this->setLineStyle($options['outerLineThickness']);
$firstLine=0;
} else {
$this->setLineStyle($options['innerLineThickness']);
}
$this->line($x0-$options['gap']/2,$y+$decender+$height,$x1-$options['gap']/2,$y+$decender+$height);
$this->restoreState();
// $this->reopenObject($textObjectId);
}
} // end of while
$y=$y-$mx+$height;
// checking row split over pages
if ($options['splitRows']==0){
if ( ( ($this->ezPageCount != $pageStart) || (isset($this->ez['columns']) && $this->ez['columns']['on']==1 && $columnStart != $this->ez['columns']['colNum'] )) && $secondTurn==0){
// then we need to go back and try that again !
$newPage=1;
$secondTurn=1;
$this->transaction('rewind');
$row = $row_orig;
$y = $y_orig;
$y0 = $y0_orig;
$y1 = $y1_orig;
$ok=0;
$dm = $this->ez['leftMargin']-$baseLeftMargin;
foreach($basePos as $k=>$v){
$pos[$k]=$v+$dm;
}
$x0=$baseX0+$dm;
$x1=$baseX1+$dm;
} else {
$this->transaction('commit');
$ok=1;
}
} else {
$ok=1; // don't go round the loop if splitting rows is allowed
}
} // end of while to check for row splitting
if ($abortTable){
if ($ok==0){
$this->transaction('abort');
}
// only the outer transaction should be operational
$this->transaction('rewind');
$this->ezNewPage();
break;
}
} // end of foreach ($data as $row)
} // end of while ($abortTable)
// table has been put on the page, the rows guarded as required, commit.
$this->transaction('commit');
$y2=$y+$decender;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -