00001 <?php
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033 include_once( 'lib/ezpdf/classes/class.ezpdf.php' );
00034
00035 define( 'EZ_PDF_LIB_NEWLINE', '<C:callNewLine>' );
00036 define( 'EZ_PDF_LIB_SPACE', '<C:callSpace>' );
00037 define( 'EZ_PDF_LIB_TAB', '<C:callTab>' );
00038
00039 define( 'EZ_PDF_LIB_PAGENUM', '#page' );
00040 define( 'EZ_PDF_LIB_TOTAL_PAGENUM', '#total' );
00041 define( 'EZ_PDF_LIB_HEADER_LEVEL', '#level' );
00042 define( 'EZ_PDF_LIB_HEADER_LEVEL_INDEX', '#indexLevel' );
00043
00044
00045
00046
00047
00048
00049
00050 class eZPDFTable extends Cezpdf
00051 {
00052
00053
00054
00055
00056 function eZPDFTable($paper='a4',$orientation='portrait')
00057 {
00058 $this->Cezpdf($paper, $orientation);
00059 $this->TOC = array();
00060 $this->KeywordArray = array();
00061 $this->PageCounter = array();
00062 $this->initFrameMargins();
00063
00064 $this->ez['textStack'] = array();
00065
00066 $this->PreStack = array();
00067 $this->DocSpecification = array();
00068 $this->pushStack();
00069 $this->FrontpageID = null;
00070 }
00071
00072
00073
00074
00075
00076 function initFrameMargins()
00077 {
00078 $this->ezFrame = array();
00079
00080 $config =& eZINI::instance( 'pdf.ini' );
00081
00082 $this->ezFrame['header'] = array( 'y0' => $this->ez['pageHeight'],
00083 'leftMargin' => $config->variable( 'Header', 'LeftMargin' ),
00084 'rightMargin' => $config->variable( 'Header', 'RightMargin' ),
00085 'topMargin' => $config->variable( 'Header', 'TopMargin' ),
00086 'bottomMargin' => $config->variable( 'Header', 'BottomMargin' ) );
00087 $this->ezFrame['footer'] = array( 'y0' => $this->ez['bottomMargin'],
00088 'leftMargin' => $config->variable( 'Footer', 'LeftMargin' ),
00089 'rightMargin' => $config->variable( 'Footer', 'RightMargin' ),
00090 'topMargin' => $config->variable( 'Footer', 'TopMargin' ),
00091 'bottomMargin' => $config->variable( 'Footer', 'BottomMargin' ) );
00092 }
00093
00094
00095
00096
00097 function yOffset()
00098 {
00099 return $this->y;
00100 }
00101
00102
00103
00104
00105 function xOffset()
00106 {
00107 $xOffset = $this->ez['xOffset'];
00108 if ( $xOffset == 0 ||
00109 $this->leftMargin() > $this->ez['xOffset'] )
00110 {
00111 $xOffset = $this->leftMargin();
00112 }
00113 return $xOffset;
00114 }
00115
00116 function setYOffset( $yOffset )
00117 {
00118 $this->y = $yOffset;
00119 }
00120
00121 function setXOffset( $xOffset )
00122 {
00123 if ( $xOffset > $this->ez['pageWidth'] - $this->rightMargin() )
00124 {
00125 $this->ez['xOffset'] = 0;
00126 }
00127 else
00128 {
00129 $this->ez['xOffset'] = $xOffset;
00130 }
00131 }
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177 function ezTable(&$data,$cols='',$title='',$options='')
00178 {
00179 include_once( 'lib/ezutils/classes/ezmath.php' );
00180
00181 if (!is_array($data)){
00182 return;
00183 }
00184
00185 $tableStartY = $this->y;
00186
00187
00188 if (!is_array($cols)){
00189
00190 reset($data);
00191 list($k,$v)=each($data);
00192 if (!is_array($v)){
00193 return;
00194 }
00195 $cols=array();
00196
00197 $realCount = 0;
00198 for ( $c = 0; $c < count($v); $c++ )
00199 {
00200 if ( isset( $options['cellData'][$realCount.',0']['size'] ) )
00201 {
00202 $incCount = $options['cellData'][$realCount.',0']['size'];
00203 for ( $innerCount = 0; $innerCount < $incCount; ++$innerCount )
00204 {
00205 $cols[$realCount] = $realCount++;
00206 }
00207 }
00208 else
00209 {
00210 $cols[$realCount] = $realCount++;
00211 }
00212 }
00213 }
00214
00215 if (!is_array($options)){
00216 $options=array();
00217 }
00218
00219 $defaults = array(
00220 'cellPadding' => 0,
00221 'shaded' => 0,
00222 'showLines' => 1,
00223 'shadeCol' => eZMath::rgbToCMYK2( 0.8, 0.8, 0.8 ),
00224 'shadeCol2' => eZMath::rgbToCMYK2( 0.7, 0.7, 0.7 ),
00225 'repeatTableHeader' => 0,
00226 'fontSize' => 10,
00227 'titleFontSize' => 12,
00228 'titleGap' => 5,
00229 'lineCol' => array( 0, 0, 0 ),
00230 'gap' => 5,
00231 'xPos' => 'centre',
00232 'xOrientation' => 'centre',
00233 'showHeadings' => 1,
00234 'textCol' => eZMath::rgbToCMYK2( 0, 0, 0 ),
00235 'titleTextCMYK' => eZMath::rgbToCMYK2( 0, 0, 0 ),
00236 'width' => 0,
00237 'maxWidth' => 0,
00238 'cols' => array(),
00239 'minRowSpace' => -100,
00240 'rowGap' => 2,
00241 'colGap' => 5,
00242 'innerLineThickness' => 1,
00243 'outerLineThickness' => 1,
00244 'splitRows' => 0,
00245 'protectRows'=> 1,
00246 'firstRowTitle' => false,
00247 'titleFontSize' => 10,
00248 'test' => 0,
00249 'yBottom' => 0 );
00250
00251 foreach($defaults as $key=>$value){
00252 if (is_array($value)){
00253 if (!isset($options[$key]) || !is_array($options[$key])){
00254 $options[$key]=$value;
00255 }
00256 } else {
00257 if (!isset($options[$key])){
00258 $options[$key]=$value;
00259 }
00260 }
00261 }
00262 $options['gap']=2*$options['colGap'];
00263 $middle = ($this->ez['pageWidth']- $this->rightMargin() - $this->leftMargin() )/2+$this->leftMargin();
00264
00265 $maxWidth = array();
00266 $minWidth = array();
00267
00268 $maxRowCount = 0;
00269
00270 foreach ( $data as $rowCount=>$row)
00271 {
00272 $realColCount = 0;
00273 for( $columnCount = 0; $columnCount < count( $row ); $columnCount++ )
00274 {
00275 $wMax = 0;
00276 $wMix = 0;
00277 $data[$rowCount][$columnCount] = $this->fixupTableCellText( $row[$columnCount] );
00278 $row[$columnCount] = $data[$rowCount][$columnCount];
00279
00280 $colSpan = 1;
00281 if ( isset( $options['cellData'][$realColCount.','.$rowCount]['size'] ) )
00282 {
00283 $colSpan = $options['cellData'][$realColCount.','.$rowCount]['size'];
00284 }
00285
00286
00287 if ( ( $rowCount == 0 && $options['firstRowTitle'] ) ||
00288 ( isset( $options['cellData'][$realColCount.','.$rowCount]['title'] ) && $options['cellData'][$realColCount.','.$rowCount]['title'] ) )
00289 {
00290 $wMax = $this->ezPrvtGetTextWidth( $options['titleFontSize'], (string)$row[$columnCount] ) * 1.01;
00291 $wMin = $this->eZGetMaxWordWidth( $options['titleFontSize'], (string)$row[$columnCount] ) * 1.01;
00292 $options['cellData'][$realColCount.','.$rowCount]['title'] = true;
00293 }
00294 else
00295 {
00296 $wMax = $this->ezPrvtGetTextWidth( $options['fontSize'], (string)$row[$columnCount] ) * 1.01;
00297 $wMin = $this->eZGetMaxWordWidth( $options['fontSize'], (string)$row[$columnCount] ) * 1.01;
00298 }
00299
00300 if ( isset( $maxWidth[$colSpan][$realColCount] ) )
00301 {
00302 if ( $wMax > $maxWidth[$colSpan][$realColCount] )
00303 {
00304 $maxWidth[$colSpan][$realColCount] = $wMax;
00305 }
00306 }
00307 else
00308 {
00309 if ( !isset( $maxWidth[$colSpan] ) )
00310 {
00311 $maxWidth[$colSpan] = array();
00312 }
00313 $maxWidth[$colSpan][$realColCount] = $wMax;
00314 }
00315
00316 if ( isset( $minWidth[$colSpan][$realColCount] ) )
00317 {
00318 if ( $wMin > $minWidth[$colSpan][$realColCount] )
00319 {
00320 $minWidth[$colSpan][$realColCount] = $wMin;
00321 }
00322 }
00323 else
00324 {
00325 if ( !isset( $minWidth[$colSpan] ) )
00326 {
00327 $minWidth[$colSpan] = array();
00328 }
00329 $minWidth[$colSpan][$realColCount] = $wMin;
00330 }
00331
00332 $realColCount += $colSpan;
00333
00334 if ( $realColCount > $maxRowCount )
00335 {
00336 $maxRowCount = $realColCount;
00337 }
00338 }
00339 }
00340
00341
00342
00343 for ( $columnCount = 0; $columnCount < count( $cols ); $columnCount++ ){
00344 if ( isset( $options['cols'][$columnCount] ) && isset($options['cols'][$columnCount]['width']) && $options['cols'][$colName]['width']>0)
00345 {
00346 $colSpan = 1;
00347 if ( isset( $options['cellData'][$realColCount.',0']['size'] ) )
00348 {
00349 $colSpan = $options['cellData'][$realColCount.',0']['size'];
00350 }
00351
00352 $maxWidth[$colSpan][$columnCount] = $options['cols'][$colName]['width'] - $options['gap'] - 2*$options['cellPadding'];
00353 }
00354 }
00355
00356
00357 $pos=array();
00358 $columnWidths = array();
00359 $minWidthArray = array();
00360 for ( $offset = 0; $offset < count( $cols ); ++$offset )
00361 {
00362 $columnWidths[$offset] = 0;
00363 $minWidthArray[$offset] = 0;
00364 }
00365 $x=0;
00366 $t=$x;
00367 $adjustmentWidth=0;
00368 $setWidth=0;
00369 foreach ( $maxWidth as $span => $tmp1 )
00370 {
00371 foreach ( $maxWidth[$span] as $offset => $tmp2 )
00372 {
00373 $currentWidth = 0;
00374 $currentMinWidth = 0;
00375 for ( $innerCount = 0; $innerCount < $span; $innerCount++ )
00376 {
00377 $currentWidth += $columnWidths[$offset+$innerCount];
00378 $currentMinWidth += $minWidthArray[$offset + $innerCount];
00379 }
00380 if ( $maxWidth[$span][$offset] > $currentWidth )
00381 {
00382 if ( $currentWidth == 0 )
00383 {
00384 for ( $i = 0; $i < $span; $i++ )
00385 {
00386 $columnWidths[$offset + $i] = ceil( $maxWidth[$span][$offset] / $span );
00387 $minWidthArray[$offset + $i] = ceil( $minWidth[$span][$offset] / $span );
00388 }
00389 }
00390 else
00391 {
00392 for ( $i = 0; $i < $span; $i++ )
00393 {
00394 $columnWidths[$offset + $i] = ceil( $maxWidth[$span][$offset] / $currentWidth * $columnWidths[$offset+$i] );
00395 $minWidthArray[$offset + $i] = ceil( $minWidth[$span][$offset] / $currentMinWidth * $minWidthArray[$offset+$i] );
00396 }
00397 }
00398 }
00399 }
00400 }
00401
00402 $t = 0;
00403 foreach ( $columnWidths as $count => $width )
00404 {
00405 $pos[$count]=$t;
00406
00407 $t += $width + $options['gap'] + 2*$options['cellPadding'];
00408 $adjustmentWidth += $width;
00409 $setWidth += $options['gap'] + 2*$options['cellPadding'];
00410 $pos[$count+1]=$t;
00411 }
00412 $pos['_end_'] = $t;
00413
00414
00415
00416 if ($options['width']==0 && $options['maxWidth'] && $pos['_end_']>$options['maxWidth']){
00417
00418 $options['width']=$options['maxWidth'];
00419 }
00420
00421
00422 $totalTableWidth = 0;
00423 foreach ( array_keys( $columnWidths ) as $idx ){
00424 $totalTableWidth += $columnWidths[$idx];
00425 }
00426
00427 if ( $options['width'] == 0 &&
00428 $totalTableWidth > $this->ez['pageWidth'] - $this->leftMargin() - $this->rightMargin() )
00429 {
00430 $options['width'] = $this->ez['pageWidth'] - $this->leftMargin() - $this->rightMargin();
00431 }
00432
00433
00434 $newColumnSize = $this->eZCalculateColumnWidth( $columnWidths, $options, $setWidth, $minWidthArray, $adjustmentWidth );
00435 if ( $newColumnSize !== false )
00436 {
00437 $pos = $newColumnSize;
00438 $t = $pos['_end_'];
00439 }
00440
00441
00442 foreach ( array_keys ( $maxWidth ) as $colspan )
00443 {
00444 foreach ( array_keys( $maxWidth[$colspan] ) as $offset )
00445 {
00446 $maxWidth[$colspan][$offset] = 0;
00447 for ( $columnCount = $offset; $columnCount < $offset + $colspan; $columnCount ++ )
00448 {
00449 if ( $maxWidth[$colspan][$offset] == 0 )
00450 {
00451 $maxWidth[$colspan][$offset] -= ( $options['gap'] + 2*$options['cellPadding'] );
00452 }
00453 $maxWidth[$colspan][$offset] += ( $pos[$columnCount + 1] - $pos[$columnCount] );
00454 }
00455 }
00456 }
00457
00458
00459 switch ($options['xPos']){
00460 case 'left':
00461 $xref = $this->leftMargin();
00462 break;
00463 case 'right':
00464 $xref = $this->ez['pageWidth'] - $this->rightMargin();
00465 break;
00466 case 'centre':
00467 case 'center':
00468 $xref = $middle;
00469 break;
00470 default:
00471 $xref = $options['xPos'];
00472 break;
00473 }
00474 switch ($options['xOrientation']){
00475 case 'left':
00476 case 'right':
00477 $dx = $xref;
00478 break;
00479 case 'centre':
00480 case 'center':
00481 $dx = $xref-$t/2;
00482 break;
00483 }
00484
00485 foreach($pos as $key=>$value){
00486 $pos[$key] += $dx + $options['gap']/2;
00487 }
00488 $x0=$x+$dx + $options['gap']/2;
00489 $x1=$t+$dx + $options['gap']/2;
00490
00491 $baseLeftMargin = $this->leftMargin();
00492 $basePos = $pos;
00493 $baseX0 = $x0;
00494 $baseX1 = $x1;
00495
00496
00497 $this->setColor( $options['textCol'] );
00498
00499 $middle = ($x1+$x0)/2;
00500
00501
00502 if ($options['protectRows']>0){
00503 $this->transaction('start');
00504 $movedOnce=0;
00505 }
00506 $abortTable = 1;
00507
00508 if ( $options['yBottom'] > 0 )
00509 {
00510 $options['test'] = 1;
00511 }
00512
00513 while ($abortTable){
00514 $abortTable=0;
00515
00516 $dm = $this->ez['leftMargin']-$baseLeftMargin;
00517 foreach($basePos as $key=>$value){
00518 $pos[$key] += $dm;
00519 }
00520 $x0=$baseX0+$dm;
00521 $x1=$baseX1+$dm;
00522 $middle = ($x1+$x0)/2;
00523
00524
00525 $dm = $this->ez['leftMargin']-$baseLeftMargin;
00526 foreach($basePos as $key => $value){
00527 $pos[$key] += $dm;
00528 }
00529 $x0=$baseX0+$dm;
00530 $x1=$baseX1+$dm;
00531
00532 $y=$this->y;
00533 $startY = $y;
00534
00535
00536 $height = $this->getFontHeight($options['fontSize']);
00537 $decender = $this->getFontDecender($options['fontSize']);
00538
00539 $y0=$y+$decender;
00540 $dy=0;
00541 if ($options['showHeadings']){
00542
00543 $headingHeight = $this->ezPrvtTableColumnHeadings($cols,$pos,$maxWidth,$height,$decender,$options['rowGap'],$options['fontSize'],$y,$options);
00544 $y0 = $y+$headingHeight;
00545 $y1 = $y;
00546
00547 $dm = $this->leftMargin()-$baseLeftMargin;
00548 foreach($basePos as $k=>$v){
00549 $pos[$k]=$v+$dm;
00550 }
00551 $x0=$baseX0+$dm;
00552 $x1=$baseX1+$dm;
00553
00554 } else {
00555 $y1 = $y0;
00556 }
00557 $firstLine=1;
00558
00559
00560 $isHelperObjectNeeded = ( !$options['test'] && ( $options['shaded'] || isset( $options['titleCellCMYK'] ) ) );
00561
00562 if ( $isHelperObjectNeeded ){
00563 $this->saveState();
00564 $textObjectId = $this->openObject();
00565 $this->closeObject();
00566 $this->addObject($textObjectId);
00567 $this->reopenObject($textObjectId);
00568 }
00569
00570 $cnt=0;
00571 $newPage=0;
00572 $newPageLine = 0;
00573 $tableHeaderRow = array();
00574 $maxRowCount = count( $data );
00575 $oldRowCount = -1;
00576
00577 $leftOvers=array();
00578
00579 for ( $rowCount = 0; $rowCount < $maxRowCount; ++$rowCount )
00580 {
00581 if ( $oldRowCount != -1)
00582 {
00583 $rowCount = $oldRowCount;
00584 $oldRowCount = -1;
00585 }
00586
00587 $row = $data[$rowCount];
00588
00589 $cnt++;
00590
00591 if ($options['splitRows']==0){
00592 $pageStart = $this->ezPageCount;
00593 if (isset($this->ez['columns']) && $this->ez['columns']['on']==1){
00594 $columnStart = $this->ez['columns']['colNum'];
00595 }
00596 if ( !$options['test'] )
00597 {
00598 $this->transaction('start');
00599 }
00600 $row_orig = $data[$rowCount];
00601 $y_orig = $y;
00602 $y0_orig = $y0;
00603 $y1_orig = $y1;
00604 }
00605 $ok=0;
00606 $secondTurn=0;
00607 while(!$abortTable && $ok == 0){
00608
00609 $maxRowHeight=0;
00610 $newRow=1;
00611 while(!$abortTable && ($newPage || $newRow)){
00612
00613 $resetLeftOvers = true;
00614 if ( count( $leftOvers ) > 0 )
00615 $row = $leftOvers;
00616
00617 if ($newPage || $y<$this->ez['bottomMargin'] || (isset($options['minRowSpace']) && $y<($this->ez['bottomMargin']+$options['minRowSpace'])) ){
00618
00619 if ($options['protectRows']>0 && $movedOnce==0 && $cnt<=$options['protectRows']){
00620
00621 $movedOnce = 1;
00622 $abortTable = 1;
00623 }
00624
00625 $y2=$y-$maxRowHeight+2*$height+$decender-$newRow*$height;
00626 if ($options['showLines']){
00627 if (!$options['showHeadings']){
00628 $y0=$y1;
00629 }
00630 }
00631 if ( $isHelperObjectNeeded )
00632 {
00633 $this->closeObject();
00634 $this->restoreState();
00635 }
00636 $this->ezNewPage();
00637
00638
00639
00640 $dm = $this->leftMargin()-$baseLeftMargin;
00641 foreach($basePos as $k=>$v){
00642 $pos[$k]=$v+$dm;
00643 }
00644
00645 $x0=$baseX0+$dm;
00646 $x1=$baseX1+$dm;
00647
00648 if ( $isHelperObjectNeeded )
00649 {
00650 $this->saveState();
00651 $textObjectId = $this->openObject();
00652 $this->closeObject();
00653 $this->addObject($textObjectId);
00654 $this->reopenObject($textObjectId);
00655 }
00656 $this->setColor( $options['textCol'], 1 );
00657 $y = $this->ez['pageHeight']-$this->ez['topMargin'];
00658 $y0=$y+$decender;
00659 $maxRowHeight=0;
00660 if ($options['showHeadings']){
00661 $this->ezPrvtTableColumnHeadings($cols,$pos,$maxWidth,$height,$decender,$options['rowGap'],$options['fontSize'],$y,$options);
00662 $y1=$y;
00663 } else {
00664 $y1=$y0;
00665 }
00666 $firstLine=1;
00667 $y -= $height;
00668
00669 if ( $options['repeatTableHeader'] && $oldRowCount == -1)
00670 {
00671 $oldRowCount = $rowCount;
00672 $rowCount = 0;
00673 $row = $data[$rowCount];
00674 $resetLeftOvers = false;
00675 }
00676 }
00677
00678 $newRow=0;
00679
00680
00681
00682 $newPage=0;
00683 if ( $resetLeftOvers )
00684 $leftOvers=array();
00685
00686 $realColumnCount = 0;
00687
00688 $bgTitleX = 2147483647;
00689 $bgTitleY = -2147483647;
00690 $bgTitleW = 0;
00691 $bgTitleH = 0;
00692
00693 for ( $columnCount = 0; $columnCount < count ( $row ); $columnCount++ )
00694 {
00695
00696 if ( isset( $options['cellData'][$realColumnCount.','.$rowCount]['size'] ) )
00697 {
00698 $colSpan = $options['cellData'][$realColumnCount.','.$rowCount]['size'];
00699 }
00700 else
00701 {
00702 $colSpan = 1;
00703 }
00704
00705 $this->ezSetY($y+$height);
00706 $colNewPage=0;
00707
00708 $row[$columnCount] = $this->fixWhitespace( $row[$columnCount] );
00709 $lines = explode("\n",$row[$columnCount]);
00710 $this->y -= $options['rowGap'] + $options['cellPadding'];
00711 $this->setXOffset( $pos[$realColumnCount] );
00712 $leftMargin = $this->ez['leftMargin'];
00713 $this->ez['leftMargin'] = $pos[$realColumnCount];
00714
00715 foreach ($lines as $line)
00716 {
00717 $line = $this->ezProcessText($line);
00718 $start=1;
00719
00720 while (strlen($line) || $start){
00721 $start=0;
00722 if (!$colNewPage){
00723 $this->y-=$height;
00724 }
00725 if ($this->y < $this->ez['bottomMargin']){
00726 $newPage=1;
00727 $newPageLine = 1;
00728 $colNewPage=1;
00729 }
00730 if ($colNewPage){
00731 if (isset($leftOvers[$realColumnCount])){
00732 $leftOvers[$realColumnCount].="\n".$line;
00733 } else {
00734 $leftOvers[$realColumnCount] = $line;
00735 }
00736 $line='';
00737 } else {
00738 if (isset($options['cols'][$realColumnCount]) && isset($options['cols'][$realColumnCount]['justification']) ){
00739 $just = $options['cols'][$realColumnCount]['justification'];
00740 } else {
00741 $just='left';
00742 }
00743 $storeY = $this->y;
00744 if ( isset( $options['cellData'][$realColumnCount.','.$rowCount] ) &&
00745 $options['cellData'][$realColumnCount.','.$rowCount]['title'] === true )
00746 {
00747 $this->setColor( $options['titleTextCMYK'] );
00748 $fontSize = $options['titleFontSize'];
00749 }
00750 else
00751 {
00752 $this->setColor( $options['textCol'], 1 );
00753 $fontSize = $options['fontSize'];
00754 }
00755
00756 $textInfo = $this->addTextWrap( $pos[$realColumnCount],
00757 $this->y,
00758 $maxWidth[$colSpan][$realColumnCount],
00759 $fontSize,
00760 $line,
00761 $just,
00762 0,
00763 $options['test'] );
00764
00765 $this->y = $storeY;
00766 if ( isset( $textInfo['text'] ) )
00767 $line = $textInfo['text'];
00768 else
00769 $line = '';
00770
00771 if ( $line == '' )
00772 {
00773 if ( isset( $textInfo['height'] ) )
00774 $this->y -= $textInfo['height'];
00775 }
00776 }
00777 }
00778 }
00779 $this->ez['leftMargin'] = $leftMargin;
00780
00781 $dy=$y-$this->y+$options['rowGap']+$options['cellPadding'];
00782 if ($dy>$maxRowHeight)
00783 {
00784 $maxRowHeight=$dy;
00785 }
00786
00787
00788
00789
00790 if ( isset( $options['cellData'][$realColumnCount.','.$rowCount] ) &&
00791 $options['cellData'][$realColumnCount.','.$rowCount]['title'] === true &&
00792 isset( $options['titleCellCMYK'] ) )
00793 {
00794 $cellX = $pos[$realColumnCount] - $options['gap']/2;
00795 $cellY = $y+$decender+$height;
00796 $cellW = $maxWidth[$colSpan][$realColumnCount] + $options['gap'];
00797 $cellH = -$maxRowHeight;
00798
00799 if ( $bgTitleX > $cellX )
00800 $bgTitleX = $cellX;
00801
00802 if ( $bgTitleY < $cellY )
00803 $bgTitleY = $cellY;
00804
00805 $bgTitleW += $cellW;
00806
00807 if ( $bgTitleH > $cellH )
00808 $bgTitleH = $cellH;
00809 }
00810
00811
00812 $realColumnCount += $colSpan;
00813
00814 }
00815
00816 if ( !$options['test'] )
00817 {
00818
00819
00820
00821 if( $bgTitleW != 0 && $bgTitleH != 0 )
00822 {
00823
00824 $this->closeObject();
00825 $this->setColor( $options['titleCellCMYK'], true );
00826 $this->filledRectangle( $bgTitleX, $bgTitleY, $bgTitleW, $bgTitleH );
00827 $this->reopenObject($textObjectId);
00828 }
00829
00830
00831 if ( isset( $options['cellData'][$realColumnCount.','.$rowCount] ) &&
00832 $options['cellData'][$realColumnCount.','.$rowCount]['title'] === true )
00833 {
00834 $shadeCol = $options['titleCellCMYK'];
00835 }
00836 else
00837 {
00838 if( $cnt % 2 == 0 )
00839 {
00840 $shadeCol = $options['shadeCol'];
00841 }
00842 else
00843 {
00844 $shadeCol = $options['shadeCol2'];
00845 }
00846 }
00847
00848 $rowHeight = $maxRowHeight;
00849 $realColumnCount = 0;
00850 for ( $columnCount = 0; $realColumnCount < $maxRowCount; $columnCount++ )
00851 {
00852 if ( isset( $options['cellData'][$realColumnCount.','.$rowCount]['size'] ) )
00853 {
00854 $colSpan = $options['cellData'][$realColumnCount.','.$rowCount]['size'];
00855 }
00856 else
00857 {
00858 $colSpan = 1;
00859 }
00860
00861 if ( $options['shaded'] && $cnt % 2 == 0 )
00862 {
00863 $this->closeObject();
00864 $this->setColor( $shadeCol );
00865 $this->filledRectangle($pos[$realColumnCount] - $options['cellPadding'],
00866 $y,
00867 $maxWidth[$colSpan][$realColumnCount] + 2*$options['cellPadding'],
00868 -$rowHeight );
00869 $this->reopenObject($textObjectId);
00870 }
00871
00872 if ($options['shaded']==2 && $cnt%2==1){
00873 $this->closeObject();
00874 $this->setColor( $shadeCol );
00875 $this->filledRectangle($pos[$realColumnCount] - $options['cellPadding'],
00876 $y,
00877 $maxWidth[$colSpan][$realColumnCount] + 2*$options['cellPadding'],
00878 -$rowHeight );
00879 $this->reopenObject($textObjectId);
00880 }
00881
00882 $realColumnCount += $colSpan;
00883 }
00884
00885
00886
00887 if ( $options['showLines'] > 0 )
00888 {
00889 $this->saveState();
00890 $this->setStrokeColorRGB($options['lineCol'][0],$options['lineCol'][1],$options['lineCol'][2],1);
00891
00892 if ( $rowCount == 0 || $newPageLine == 1 )
00893 {
00894 $this->line( $x0-$options['gap']/2, $y+$decender+$height, $x1-$options['gap']/2, $y+$decender+$height );
00895 }
00896 $this->line( $x0-$options['gap']/2, $y+$decender+$height, $x0-$options['gap']/2, $y+$decender+$height-$maxRowHeight );
00897 $this->line( $x1-$options['gap']/2, $y+$decender+$height, $x1-$options['gap']/2, $y+$decender+$height-$maxRowHeight );
00898
00899 if ( $options['showLines'] > 1 )
00900 {
00901
00902 $this->line( $x0-$options['gap']/2, $y+$decender+$height-$maxRowHeight, $x1-$options['gap']/2, $y+$decender+$height-$maxRowHeight );
00903
00904 for ( $posOffset = 0; $posOffset < count( $pos ) - 2; )
00905 {
00906 $colSpan = 1;
00907 if ( isset( $options['cellData'][$posOffset.','.$rowCount]['size'] ) )
00908 {
00909 $colSpan = $options['cellData'][$posOffset.','.$rowCount]['size'];
00910 }
00911 $this->line( $pos[$posOffset+$colSpan]-$options['gap']/2, $y+$decender+$height,
00912 $pos[$posOffset+$colSpan]-$options['gap']/2, $y+$decender+$height-$maxRowHeight );
00913 $posOffset += $colSpan;
00914 }
00915 }
00916 else if ( $rowCount == count( $data ) - 1 )
00917 {
00918 $this->line( $x0-$options['gap']/2, $y+$decender+$height-$maxRowHeight, $x1-$options['gap']/2, $y+$decender+$height-$maxRowHeight );
00919 }
00920 $this->restoreState();
00921 }
00922 if ($options['showLines']>1){
00923 $this->saveState();
00924 $this->setStrokeColorRGB($options['lineCol'][0],$options['lineCol'][1],$options['lineCol'][2],1);
00925
00926 if ($firstLine){
00927 $this->setLineStyle($options['outerLineThickness']);
00928 $firstLine=0;
00929 } else {
00930 $this->setLineStyle($options['innerLineThickness']);
00931 }
00932 $this->line($x0-$options['gap']/2,$y+$decender+$height-$maxRowHeight,$x1-$options['gap']/2,$y+$decender+$height-$maxRowHeight);
00933 $this->restoreState();
00934 }
00935 }
00936 }
00937 $y=$y-$maxRowHeight;
00938
00939
00940 if ( $options['splitRows'] == 0 )
00941 {
00942 if ( ( ($this->ezPageCount != $pageStart) || (isset($this->ez['columns']) && $this->ez['columns']['on']==1 && $columnStart != $this->ez['columns']['colNum'] )) && $secondTurn==0){
00943
00944 $newPage=1;
00945 $newPageLine = 1;
00946 $secondTurn=1;
00947 $this->transaction('rewind');
00948 $row = $row_orig;
00949 $y = $y_orig;
00950 $y0 = $y0_orig;
00951 $y1 = $y1_orig;
00952 $ok=0;
00953
00954 $dm = $this->leftMargin()-$baseLeftMargin;
00955 foreach($basePos as $k=>$v){
00956 $pos[$k]=$v+$dm;
00957 }
00958 $x0=$baseX0+$dm;
00959 $x1=$baseX1+$dm;
00960
00961 } else {
00962 $this->transaction('commit');
00963 $ok=1;
00964 }
00965 }
00966 else
00967 {
00968 $ok=1;
00969 }
00970
00971 }
00972 if ($abortTable){
00973 if ($ok==0){
00974 $this->transaction('abort');
00975 }
00976
00977 $this->transaction('rewind');
00978 $this->ezNewPage();
00979 break;
00980 }
00981
00982 }
00983
00984 if ( isset ( $options['yBottom'] ) && $options['yBottom'] > 0 )
00985 {
00986 $tableHeight = $startY - $y;
00987 $this->y = $options['yBottom'] + $tableHeight;
00988 $yBottom = $options['yBottom'];
00989 unset( $options['yBottom'] );
00990 $options['test'] = 0;
00991 $this->transaction('rewind');
00992
00993 $abortTable = 1;
00994 continue;
00995 }
00996
00997 }
00998
00999
01000 $this->transaction('commit');
01001
01002 $y2=$y+$decender;
01003 if ($options['showLines']){
01004 if (!$options['showHeadings']){
01005 $y0=$y1;
01006 }
01007
01008 }
01009
01010
01011 if ( $isHelperObjectNeeded ){
01012 $this->closeObject();
01013 $this->restoreState();
01014 }
01015
01016 if ( $options['overwrite'] > 0 )
01017 {
01018 $this->y=$tableStartY;
01019 }
01020 else
01021 {
01022 $this->y=$y;
01023 }
01024
01025 return $this->y;
01026 }
01027
01028
01029
01030
01031
01032
01033
01034
01035
01036
01037
01038
01039
01040 function eZCalculateColumnWidth( $columnWidthArray,
01041 $options,
01042 $marginWidth,
01043 $minWidthArray,
01044 $totalWidth,
01045 $fixedSizeArray = array() )
01046 {
01047 $newWidth = 0;
01048 if ( $options['width'] && $totalWidth>0 ){
01049 $newCleanWidth = $options['width'] - $marginWidth;
01050 $t = 0;
01051 $pos = array();
01052 foreach ( $columnWidthArray as $count => $width )
01053 {
01054 $pos[$count] = $t;
01055
01056 if ( isset( $fixedSizeArray[(string)$count] ) )
01057 {
01058 $t += $fixedSizeArray[(string)$count] + $options['gap'] + 2*$options['cellPadding'];
01059 continue;
01060 }
01061
01062 $newWidth = round( $newCleanWidth/$totalWidth * $columnWidthArray[$count] );
01063
01064 if ( $newWidth < $minWidthArray[$count] &&
01065 count( $fixedSizeArray ) < count( $columnWidthArray ) )
01066 {
01067 $fixedSizeArray[(string)$count] = $minWidthArray[$count];
01068
01069 return $this->eZCalculateColumnWidth( $columnWidthArray,
01070 $options,
01071 $marginWidth + $minWidthArray[$count],
01072 $minWidthArray,
01073 $totalWidth - $minWidthArray[$count],
01074 $fixedSizeArray );
01075 }
01076 $t += $newWidth + $options['gap'] + 2*$options['cellPadding'];
01077 }
01078 $pos[]=$t;
01079 $pos['_end_']=$t;
01080 return $pos;
01081 }
01082
01083 return false;
01084 }
01085
01086 function ezPrvtTableDrawLines($pos,$gap,$x0,$x1,$y0,$y1,$y2,$col,$inner,$outer,$opt=1){
01087 $x0=1000;
01088 $x1=0;
01089 $this->setStrokeColorRGB($col[0],$col[1],$col[2]);
01090 $cnt=0;
01091 $n = count($pos);
01092 foreach($pos as $x){
01093 $cnt++;
01094 if ($cnt==1 || $cnt==$n){
01095 $this->setLineStyle($outer);
01096 } else {
01097 $this->setLineStyle($inner);
01098 }
01099 $this->line($x-$gap/2,$y0,$x-$gap/2,$y2);
01100 if ($x>$x1){ $x1=$x; };
01101 if ($x<$x0){ $x0=$x; };
01102 }
01103 $this->setLineStyle($outer);
01104 $this->line($x0-$gap/2-$outer/2,$y0,$x1-$gap/2+$outer/2,$y0);
01105
01106
01107 if ($y0!=$y1 && $opt<2){
01108 $this->line($x0-$gap/2,$y1,$x1-$gap/2,$y1);
01109 }
01110 $this->line($x0-$gap/2-$outer/2,$y2,$x1-$gap/2+$outer/2,$y2);
01111 }
01112
01113
01114
01115
01116 function callAnchor( $info )
01117 {
01118 $paramArray = explode( ':', $info['p'] );
01119
01120 $this->addDestination( $paramArray[0], $paramArray[1], $this->yOffset() + $this->getFontHeight( $this->fontSize ) );
01121 }
01122
01123
01124
01125
01126 function callHeader( $params )
01127 {
01128 $options = array();
01129
01130 if ( isset( $params['size'] ) )
01131 {
01132 $options['fontSize'] = $params['size'];
01133 }
01134
01135 if ( isset( $params['justification'] ) )
01136 {
01137 $options['justification'] = $params['justification'];
01138 }
01139
01140 if ( isset( $params['fontName'] ) )
01141 {
01142 $options['fontName'] = 'lib/ezpdf/classes/fonts/'. $params['fontName'];
01143 }
01144
01145 $this->addToPreStack( $options );
01146
01147 $label = $params['label'];
01148 $level = $params['level'];
01149
01150 return '<C:callInsertTOC:'. $label .','. $level .'>';
01151 }
01152
01153
01154
01155
01156 function callImage( $info )
01157 {
01158 $params = array();
01159 $leftMargin = false;
01160 $rightMargin = false;
01161
01162 eZPDFTable::extractParameters( $info['p'], 0, $params, true );
01163
01164 $filename = rawurldecode( $params['src'] );
01165
01166 include_once( 'lib/ezutils/classes/ezmimetype.php' );
01167 $mimetype = eZMimeType::findByFileContents( $filename );
01168
01169 $this->transaction( 'start' );
01170
01171 if ( !isset( $params['static'] ) )
01172 {
01173 $params['static'] = false;
01174 }
01175
01176 if ( $this->yOffset()-$params['height'] < $this->ez['bottomMargin'] )
01177 {
01178 $this->ezNewPage();
01179 }
01180
01181 if ( isset( $params['dpi'] ) )
01182 {
01183 include_once( 'kernel/common/image.php' );
01184
01185 $newWidth = (int)( $params['width'] * ( (int)$params['dpi'] / 72 ) );
01186 $newHeight = (int)( $params['height'] * ( (int)$params['dpi'] / 72 ) );
01187 $newFilename = eZSys::cacheDirectory() . '/' . md5( mt_rand() ) . '.jpg';
01188 while( file_exists( $newFilename ) )
01189 {
01190 $newFilename = eZSys::cacheDirectory() . '/' . md5( mt_rand() ) . '.jpg';
01191 }
01192 $img =& imageInit();
01193 $newImg = $img->convert( $filename,
01194 $newFilename,
01195 false,
01196 array( 'filters' => array( array( 'name' => 'geometry/scaledownonly',
01197 'data' => array( $newWidth, $newHeight ) ) ) ) );
01198 $filename = $newFilename['url'];
01199 }
01200
01201 $drawableAreaWidth = $this->ez['pageWidth'] - $this->ez['leftMargin'] - $this->ez['rightMargin'];
01202
01203 switch( $params['align'] )
01204 {
01205 case 'right':
01206 {
01207 $xOffset = $this->ez['pageWidth'] - ( $this->rightMargin() + $params['width'] );
01208 $rightMargin = $this->rightMargin() + $params['width'];
01209 if ( $rightMargin > ( $drawableAreaWidth + $this->rightMargin() ) )
01210 {
01211
01212
01213 $rightMargin = false;
01214 }
01215 } break;
01216
01217 case 'center':
01218 {
01219 $xOffset = ( $this->ez['pageWidth'] - $this->rightMargin() - $this->leftMargin() ) / 2 + $this->leftMargin() - $params['width'] / 2;
01220 } break;
01221
01222 case 'left':
01223 default:
01224 {
01225 $xOffset = $this->leftMargin();
01226 $leftMargin = $this->leftMargin() + $params['width'];
01227 if ( $leftMargin > ( $drawableAreaWidth + $this->leftMargin() ) )
01228 {
01229
01230
01231 $leftMargin = false;
01232 }
01233
01234 } break;
01235 }
01236
01237 if ( isset( $params['x'] ) )
01238 {
01239 $xOffset = $params['x'];
01240 $leftMargin = false;
01241 $rightMargin = false;
01242 }
01243
01244 $yOffset = $this->yOffset();
01245 $whileCount = 0;
01246
01247 if ( $params['width'] < $drawableAreaWidth )
01248 {
01249 while ( $this->leftMargin( $yOffset ) > $xOffset &&
01250 ++$whileCount < 100 )
01251 {
01252 $yOffset -= 10;
01253 }
01254 }
01255
01256 $yOffset -= $params['height'];
01257 $yOffset += $this->lineHeight()/2;
01258 if ( isset( $params['y'] ) )
01259 {
01260 $yOffset = $params['y'];
01261 }
01262
01263 if ( $leftMargin !== false )
01264 {
01265 $this->setLimitedLeftMargin( $yOffset - 7, $yOffset + $params['height'] + 7, $leftMargin + 7 );
01266 }
01267 if ( $rightMargin !== false )
01268 {
01269 $this->setLimitedRightMargin( $yOffset- 7, $yOffset + $params['height'] + 7, $rightMargin + 7 );
01270 }
01271
01272 switch( $mimetype['name'] )
01273 {
01274 case 'image/gif':
01275 {
01276 $newFilename = eZSys::cacheDirectory() . '/' . md5( mt_rand() ) . '.jpg';
01277 while( file_exists( $newFilename ) )
01278 {
01279 $newFilename = eZSys::cacheDirectory() . '/' . md5( mt_rand() ) . '.jpg';
01280 }
01281 $newMimetype = eZMimeType::findByURL( $newFilename );
01282
01283 $img =& imageInit();
01284 $newImg = $img->convert( $mimetype,
01285 $newMimetype,
01286 false,
01287 array() );
01288 $this->addJpegFromFile( $newMimetype['url'],
01289 $xOffset,
01290 $yOffset,
01291 $params['width'],
01292 $params['height'] );
01293 } break;
01294
01295 case 'image/jpeg':
01296 {
01297 $this->addJpegFromFile( $filename,
01298 $xOffset,
01299 $yOffset,
01300 $params['width'],
01301 $params['height'] );
01302 } break;
01303
01304 case 'image/png':
01305 {
01306 if ( $this->addPngFromFile( $filename,
01307 $xOffset,
01308 $yOffset,
01309 $params['width'],
01310 $params['height'] ) === false )
01311 {
01312 $this->transaction('abort');
01313 return;
01314 }
01315 } break;
01316
01317 default:
01318 {
01319 eZDebug::writeError( 'Unsupported image file type, '. $mimetype['name'], 'eZPDFTable::callImage' );
01320 $this->transaction( 'abort' );
01321 return;
01322 } break;
01323 }
01324
01325 $this->transaction( 'commit' );
01326
01327 if ( !$leftMargin && !$rightMargin && !$params['static'] )
01328 {
01329 $this->y -= $params['height'] + $this->lineHeight();
01330 }
01331
01332 return array( 'y' => $params['height'] + $this->lineHeight() );
01333 }
01334
01335
01336
01337
01338
01339 function callKeyword( $info )
01340 {
01341 $keyWord = $this->fixWhitespace( rawurldecode( $info['p'] ) );
01342 $page = $this->ezWhatPageNumber($this->ezGetCurrentPageNumber());
01343
01344 if ( !isset( $this->KeywordArray[$keyWord] ) )
01345 {
01346 $this->KeywordArray[$keyWord] = array();
01347 }
01348
01349 if ( !isset( $this->KeywordArray[$keyWord][(string)$page] ) )
01350 {
01351 $label = $info['p'] .':'. $page;
01352 $this->KeywordArray[$keyWord][(string)$page] = array( 'label' => $label );
01353
01354 $this->addDestination( 'keyword:'.$label,
01355 'FitH',
01356 $this->yOffset() );
01357 }
01358 }
01359
01360
01361
01362
01363 function callInsertTOC( $info )
01364 {
01365 $params = explode( ',', $info['p'] );
01366
01367 $label = $params[0];
01368 $level = $params[1];
01369
01370 $tocCount = count( $this->TOC );
01371 $this->TOC[] = array( 'label' => $this->fixWhitespace( rawurldecode( $label ) ),
01372 'localPageNumber' => $this->ezWhatPageNumber( $this->ezGetCurrentPageNumber() ),
01373 'level' => $level,
01374 'pageNumber' => $this->ezGetCurrentPageNumber() );
01375 $this->addDestination( 'toc'. $tocCount,
01376 'FitH',
01377 $this->yOffset() + $this->getFontHeight( $this->fontSize() ) );
01378 }
01379
01380
01381
01382
01383 function callTOC( $info )
01384 {
01385 $params = array();
01386
01387 eZPDFTable::extractParameters( $info['p'], 0, $params, true );
01388
01389 $sizes = isset( $params['size'] ) ? explode( ',', $params['size'] ) : '';
01390 $indents = isset( $params['indent'] ) ? explode( ',', $params['indent'] ) : '';
01391 $dots = isset( $params['dots'] ) ? $params['dots'] : '';
01392 $contentText = isset( $params['contentText'] ) ? $params['contentText'] : ezi18n( 'lib/ezpdf/classes', 'Contents', 'Table of contents' );
01393
01394 $this->insertTOC( $sizes, $indents, $dots, $contentText );
01395 }
01396
01397
01398
01399
01400 function callNewPage( $info )
01401 {
01402 $this->ezNewPage();
01403 }
01404
01405 function callIndex( $info )
01406 {
01407 $this->ezNewPage();
01408 $fontSize = $this->fontSize();
01409 Cezpdf::ezText( ezi18n( 'lib/ezpdf/classes', 'Index', 'Keyword index name' ) . '<C:callInsertTOC:Index,1>'."\n", 26, array('justification'=>'centre'));
01410
01411 if ( count( $this->KeywordArray ) == 0 )
01412 return;
01413
01414 ksort( $this->KeywordArray );
01415 reset( $this->KeywordArray );
01416
01417 $this->ezColumnsStart( array( 'num' => 2 ) );
01418
01419 foreach( array_keys( $this->KeywordArray ) as $keyWord )
01420 {
01421 Cezpdf::ezText( $keyWord,
01422 $fontSize,
01423 array( 'justification' => 'left' ) );
01424
01425 foreach( array_keys( $this->KeywordArray[$keyWord] ) as $page )
01426 {
01427 Cezpdf::ezText( '<c:ilink:keyword:'. $this->KeywordArray[$keyWord][$page]['label'] .'> '. $page .'</c:ilink>',
01428 $fontSize,
01429 array( 'justification' => 'right' ) );
01430 }
01431 }
01432
01433 $this->ezColumnsStop();
01434 $this->setFontSize( $fontSize );
01435 }
01436
01437
01438
01439
01440
01441
01442
01443
01444
01445
01446 function insertTOC( $sizeArray = array( 20, 18, 16, 14, 12 ),
01447 $indentArray = array( 0, 4, 6, 8, 10 ),
01448 $dots = true,
01449 $contentText = '',
01450 $level = 3 )
01451 {
01452 $fontSize = $this->fontSize();
01453 $this->ezStopPageNumbers(1,1);
01454
01455 $this->ezInsertMode(1,1,'before');
01456 $this->ezNewPage();
01457 Cezpdf::ezText( $contentText ."\n", 26, array('justification'=>'centre'));
01458
01459 foreach($this->TOC as $k=>$v){
01460 if ( $v['level'] <= $level )
01461 {
01462 if ( $dots )
01463 {
01464 Cezpdf::ezText( '<c:ilink:toc'. $k .'>'. $v['label'] .'</c:ilink>',
01465 $sizeArray[$v['level']-1],
01466 array( 'left' => $indentArray[$v['level']-1],
01467 'right' => 100 ) );
01468 Cezpdf::ezText( '<C:dots:'. $sizeArray[$v['level']-1].$v['localPageNumber'] .'>',
01469 $sizeArray[$v['level']-1] );
01470 Cezpdf::ezText( "\n", $sizeArray[$v['level']-1] );
01471 }
01472 else
01473 {
01474 Cezpdf::ezText( '<c:ilink:toc'. $k .'>'.$v['label'].'</c:ilink>',
01475 $sizeArray[$v['level']-1],
01476 array( 'left' => $indentArray[$v['level']-1] ) );
01477 Cezpdf::ezText( '<c:ilink:toc'. $k .'>'. $v['localPageNumber'] .'</c:ilink>',
01478 $sizeArray[$v['level']-1],
01479 array( 'justification' => 'right' ) );
01480 }
01481 }
01482 }
01483
01484 $this->setFontSize( $fontSize );
01485 $this->ezInsertMode(0);
01486 }
01487
01488 function dots($info)
01489 {
01490
01491 $tmp = $info['p'];
01492 $size = substr($tmp, 0, 2);
01493 $thick=1;
01494 $lbl = substr($tmp,2);
01495 $xpos = $this->ez['pageWidth'] - $this->rightMargin() - $this->leftMargin();
01496
01497 $this->saveState();
01498 $this->setLineStyle($thick,'round','',array(0,10));
01499 $this->line($xpos,$info['y'],$info['x']+5,$info['y']);
01500 $this->restoreState();
01501 $this->addText($xpos+5,$info['y'],$size,$lbl);
01502 $this->setXOffset( $xpos+5+$this->getTextWidth($lbl, $size) );
01503 }
01504
01505
01506
01507
01508 function callFont( $params )
01509 {
01510 $options = array();
01511
01512 $keyArray = array ( 'c', 'm', 'y', 'k' );
01513 if ( isset( $params['cmyk'] ) )
01514 {
01515 $params['cmyk'] = explode( ',', $params['cmyk'] );
01516 foreach ( array_keys( $params['cmyk'] ) as $key )
01517 {
01518 $options['cmyk'][$keyArray[$key]] = $params['cmyk'][$key];
01519 }
01520 $this->setStrokeColor( $params['cmyk'] );
01521 }
01522
01523 if ( isset( $params['name'] ) )
01524 {
01525 $options['fontName'] = 'lib/ezpdf/classes/fonts/'. $params['name'];
01526 }
01527
01528 if ( isset( $params['size'] ) )
01529 {
01530 $options['fontSize'] = $params['size'];
01531 }
01532
01533 if ( isset( $params['justification'] ) )
01534 {
01535 $options['justification'] = $params['justification'];
01536 }
01537
01538 $this->addToPreStack( $options );
01539
01540 return '';
01541 }
01542
01543 function &fixWhitespace( &$text )
01544 {
01545 $text = str_replace( array( EZ_PDF_LIB_SPACE,
01546 EZ_PDF_LIB_TAB,
01547 EZ_PDF_LIB_NEWLINE ),
01548 array( ' ',
01549 "\t",
01550 "\n" ),
01551 $text );
01552 return $text;
01553 }
01554
01555
01556
01557
01558 function ezText( $text, $size=0, $options=array(), $test=0)
01559 {
01560 $text = eZPDFTable::fixWhitespace( $text );
01561
01562 $textLen = strlen( $text );
01563 $newText = '';
01564 for ( $offSet = 0; $offSet < $textLen; $offSet++ )
01565 {
01566 if ( $text[$offSet] == '<' )
01567 {
01568 if ( strcmp( substr($text, $offSet+1, strlen( 'ezCall' ) ), 'ezCall' ) == 0 )
01569 {
01570 $newTextLength = strlen( $newText );
01571 if ( $newTextLength > 0 && $newText[$newTextLength - 1] == "\n" )
01572 {
01573 unset( $newText[$newTextLength - 1] );
01574 $this->addDocSpecification( $newText );
01575 $newText = "\n";
01576 }
01577 else
01578 {
01579 $this->addDocSpecification( $newText );
01580 $newText = '';
01581 }
01582
01583 $params = array();
01584 $funcName = '';
01585
01586 $offSet = eZPDFTable::extractFunction( $text, $offSet, $funcName, $params, 'ezCall' );
01587
01588 $newText .= $this->$funcName( $params );
01589
01590 continue;
01591 }
01592 else if ( strcmp( substr($text, $offSet+1, strlen( '/ezCall' ) ), '/ezCall' ) == 0 )
01593 {
01594 $this->addDocSpecification( $newText );
01595 array_pop( $this->PreStack );
01596 $offSet = strpos( $text, '>', $offSet );
01597 $newText = '';
01598 continue;
01599 }
01600 else if ( strcmp( substr($text, $offSet+1, strlen( 'ezGroup' ) ), 'ezGroup' ) == 0 )
01601 {
01602 $newTextLength = strlen( $newText );
01603 if ( $newTextLength > 0 && $newText[$newTextLength - 1] == "\n" )
01604 {
01605 unset( $newText[$newTextLength - 1] );
01606 $this->addDocSpecification( $newText );
01607 $newText = "\n";
01608 }
01609 else
01610 {
01611 $this->addDocSpecification( $newText );
01612 $newText = '';
01613 }
01614
01615 $params = array();
01616 $funcName = '';
01617
01618 $offSet = eZPDFTable::extractFunction( $text, $offSet, $funcName, $params, 'ezGroup' );
01619 $offSet++;
01620 $endGroup = strpos( $text, '</ezGroup:', $offSet );
01621 $groupText = substr( $text, $offSet, $endGroup - $offSet );
01622 $groupText = urldecode( $groupText );
01623
01624 $this->$funcName( $params, $groupText );
01625
01626 $offSet = strpos( $text, '>', $endGroup );
01627 continue;
01628 }
01629 }
01630 $newText .= $text[$offSet];
01631 }
01632 if ( strlen( $newText ) > 0 )
01633 {
01634 $this->addDocSpecification( $newText );
01635 }
01636
01637 $this->outputDocSpecification();
01638 }
01639
01640
01641
01642
01643
01644
01645
01646
01647
01648 function fixupTableCellText( $text )
01649 {
01650 $text = preg_replace( "/^" . EZ_PDF_LIB_NEWLINE . "/i", "", $text );
01651 $text = preg_replace( "/" . EZ_PDF_LIB_NEWLINE . "$/i", "", $text );
01652 return preg_replace( "'<[\/]*?ezCall:[^<>]*?>'si", "", $text );
01653 }
01654
01655
01656
01657
01658
01659
01660 function callRectangle( $info )
01661 {
01662 $params = array();
01663
01664 eZPDFTable::extractParameters( $info['p'], 0, $params, true );
01665
01666 $keyArray = array ( 'c', 'm', 'y', 'k' );
01667 $cmykColor = explode( ',', $params['cmyk'] );
01668
01669 foreach ( array_keys( $cmykColor ) as $key )
01670 {
01671 $cmykColor[$keyArray[$key]] = $cmykColor[$key];
01672 unset( $cmykColor[$key] );
01673 }
01674
01675 $stackColor = $this->currentStrokeColour;
01676 $this->setStrokeColor( $cmykColor );
01677
01678 if ( isset( $params['x'] ) )
01679 {
01680 $x1 = $params['x'];
01681 $x2 = $x1 + $params['width'];
01682 }
01683 if ( isset( $params['y'] ) )
01684 {
01685 $y1 = $params['y'];
01686 $y2 = $y1 + $params['height'];
01687 }
01688
01689 if ( isset( $params['topY'] ) )
01690 {
01691 $y2 = $params['topY'];
01692 if ( $params['height'] > 0 )
01693 {
01694 $y1 = $params['topY'] - $params['height'];
01695 }
01696 else
01697 {
01698 $y1 = $this->yOffset() + $params['height'];
01699 }
01700 }
01701
01702 $this->setLineStyle( $params['line_width'] );
01703
01704 if ( $params['corner'] )
01705 {
01706 $factor = $params['corner'];
01707 $degree = 0;
01708
01709 $this->line( $x1 + $factor, $y1, $x2 - $factor, $y1 );
01710 $this->line( $x2, $y1 + $factor, $x2, $y2 - $factor );
01711 $this->line( $x2 - $factor, $y2, $x1 + $factor, $y2 );
01712 $this->line( $x1, $y2 - $factor, $x1, $y1 + $factor );
01713
01714 $this->curve( $x2 - $factor, $y1,
01715 $x2, $y1 - $degree * $factor,
01716 $x2 + $degree * $factor, $y1,
01717 $x2, $y1 + $factor );
01718 $this->curve( $x2, $y2 - $factor,
01719 $x2 + $degree * $factor, $y2,
01720 $x2, $y2 + $degree * $factor,
01721 $x2 - $factor, $y2 );
01722 $this->curve( $x1 + $factor, $y2,
01723 $x1, $y2 + $degree * $factor,
01724 $x1 - $degree * $factor, $y2,
01725 $x1, $y2 - $factor );
01726 $this->curve( $x1, $y1 + $factor,
01727 $x1 - $degree * $factor, $y1,
01728 $x1, $y1 - $degree * $factor,
01729 $x1 + $factor, $y1 );
01730 }
01731 else
01732 {
01733 $this->rectangle( $x1, $y1, $params['width'], $params['height'] );
01734 }
01735
01736 $this->setColor( $stackColor );
01737 }
01738
01739
01740
01741
01742 function callSetMargin( $info )
01743 {
01744 $options = array();
01745
01746 eZPDFTable::extractParameters( $info['p'], 0, $options, true );
01747
01748 if ( isset( $options['left'] ) )
01749 {
01750 $this->ez['leftMargin'] = (float)$options['left'];
01751 }
01752
01753 if ( isset( $options['delta_left'] ) )
01754 {
01755 $this->ez['leftMargin'] += $options['delta_left'];
01756 }
01757
01758 if ( isset( $options['right'] ) )
01759 {
01760 $this->ez['rightMargin'] = (float)$options['right'];
01761 }
01762
01763 if ( isset( $options['delta_right'] ) )
01764 {
01765 $this->ez['rightMargin'] += $options['delta_right'];
01766 }
01767
01768 if ( isset( $options['bottom'] ) )
01769 {
01770 $this->ez['bottomMargin'] = (float)$options['bottom'];
01771 }
01772
01773 if ( isset( $options['line_space'] ) )
01774 {
01775 $this->ez['lineSpace'] = (float)$options['line_space'];
01776 }
01777
01778 if ( isset( $options['top'] ) )
01779 {
01780 $this->ez['topMargin'] = (float)$options['top'];
01781 if ( $this->yOffset() < $this->ez['topMargin'] )
01782 {
01783 $this->ez['yOffset'] = (float)$options['y'];
01784 $this->y = (float)$options['y'];
01785 }
01786 }
01787
01788 if ( isset( $options['x'] ) )
01789 {
01790 $this->setXOffset( (float)$options['x'] );
01791 }
01792
01793 if ( isset( $options['y'] ) )
01794 {
01795 $this->ez['yOffset'] = (float)$options['y'];
01796 $this->y = (float)$options['y'];
01797 }
01798
01799 return array( 'x' => $this->xOffset() );
01800 }
01801
01802
01803
01804
01805 function callCircle( $info )
01806 {
01807 $params = array();
01808 $forceYPos = true;
01809
01810 eZPDFTable::extractParameters( $info['p'], 0, $params, true );
01811
01812 $keyArray = array ( 'c', 'm', 'y', 'k' );
01813 $cmykColor = explode( ',', $params['cmyk'] );
01814
01815 foreach ( array_keys( $cmykColor ) as $key )
01816 {
01817 $cmykColor[$keyArray[$key]] = $cmykColor[$key];
01818 unset( $cmykColor[$key] );
01819 }
01820
01821 $strokeStackColor = $this->currentStrokeColour;
01822 $this->setStrokeColor( $cmykColor );
01823 $stackColor = $this->currentColour;
01824 $this->setColor( $cmykColor );
01825
01826 if ( $params['x'] == -1 )
01827 {
01828 $params['x'] = $this->xOffset() + $params['radius'];
01829 }
01830 if ( $params['y'] == -1 )
01831 {
01832 $forceYPos = false;
01833 $params['y'] = $this->yOffset();
01834 }
01835 if ( isset( $params['yOffset'] ) )
01836 {
01837 if ( $params['yOffset'] == -1 )
01838 {
01839 $params['y'] += $this->getFontHeight( $this->fontSize() )/2 - $params['radius'];
01840 }
01841 else
01842 {
01843 $params['y'] += $params['yOffset'];
01844 }
01845 }
01846
01847 if ( $params['y'] - $this->getFontHeight( $this->fontSize() ) < $this->ez['bottomMargin'] &&
01848 !$forceYPos )
01849 {
01850 $this->ezNewPage();
01851 return $this->callCircle( $info );
01852 }
01853
01854 $params['x'] += $params['pre_indent'];
01855
01856 $this->filledEllipse( $params['x'], $params['y'], $params['radius'] );
01857
01858 $this->setStrokeColor( $strokeStackColor );
01859 $this->setColor( $stackColor );
01860
01861 if ( isset( $params['indent'] ) )
01862 {
01863 return array( 'x' => $params['x'] + $params['radius'] * 2 + $params['indent'] );
01864 }
01865 else
01866 {
01867 return array( 'x' => $params['x'] + $params['radius'] * 2 );
01868 }
01869
01870 }
01871
01872
01873
01874
01875
01876
01877 function callFilledRectangle( $info )
01878 {
01879 $params = array();
01880
01881 eZPDFTable::extractParameters( $info['p'], 0, $params, true );
01882
01883 $keyArray = array ( 'c', 'm', 'y', 'k' );
01884 $cmykTop = explode( ',', $params['cmykTop'] );
01885 $cmykBottom = explode( ',', $params['cmykBottom'] );
01886
01887 foreach ( array_keys( $cmykBottom ) as $key )
01888 {
01889 $cmykBottom[$keyArray[$key]] = $cmykBottom[$key];
01890 unset( $cmykBottom[$key] );
01891 $cmykTop[$keyArray[$key]] = $cmykTop[$key];
01892 unset( $cmykTop[$key] );
01893 }
01894
01895 $this->ezShadedRectangle( $params['x'], $params['y'], $params['width'], $params['height'], $cmykTop, $cmykBottom );
01896 }
01897
01898
01899
01900
01901
01902
01903
01904 function callBlockFrame( $params, $text )
01905 {
01906 if ( strlen( $text ) > 0 )
01907 {
01908 $this->addDocSpecFunction( 'ezInsertBlockFrame', array( $text, $params) );
01909 }
01910 }
01911
01912
01913
01914
01915
01916
01917
01918 function callFrame( $params, $text )
01919 {
01920 if ( strlen( $text ) > 0 )
01921 {
01922 $this->addDocSpecFunction( 'ezInsertFrame', array( $this->fixWhitespace( $text ), $params) );
01923 }
01924 }
01925
01926
01927
01928
01929 function callLine( $params, $text )
01930 {
01931 $this->addDocSpecFunction( 'ezInsertLine', array( $params ) );
01932 }
01933
01934
01935
01936
01937 function callDrawLine( $info )
01938 {
01939 $params = array();
01940 eZPDFTable::extractParameters( $info['p'], 0, $params, true );
01941
01942 $this->setLineStyle( $params['thickness'] );
01943 $this->line( $params['x1'], $params['y1'], $params['x2'], $params['y2'] );
01944 }
01945
01946
01947
01948
01949
01950
01951 function callFrameMargins( $info )
01952 {
01953 $params = array();
01954 eZPDFTable::extractParameters( $info['p'], 0, $params, true );
01955
01956 if( isset( $this->ezFrame[$params['identifier']] ) )
01957 {
01958 $this->ezFrame[$params['identifier']] = array_merge( $this->ezFrame[$params['identifier']],
01959 $params );
01960 }
01961 else
01962 {
01963 $this->ezFrame[$params['identifier']] = $params;
01964 }
01965 }
01966
01967
01968
01969
01970
01971
01972 function ezInsertLine( $params )
01973 {
01974 reset( $this->ezPages );
01975 foreach ( $this->ezPages as $pageNum => $pageID )
01976 {
01977 $this->reopenObject($pageID);
01978 $this->line( $params['x1'], $params['y1'], $params['x2'], $params['y2'] );
01979 $this->closeObject();
01980 }
01981 reset( $this->ezPages );
01982 }
01983
01984
01985
01986
01987
01988
01989
01990 function ezInsertBlockFrame( $text, $textParameters )
01991 {
01992 $header = false;
01993 switch( $textParameters['location'] )
01994 {
01995 case 'footer_block':
01996 {
01997 $frameCoords = $this->ezFrame['footer'];
01998 } break;
01999
02000 case 'header_block':
02001 {
02002 $header = true;
02003 $frameCoords = $this->ezFrame['header'];
02004 } break;
02005 }
02006
02007 $text = str_replace( array( ' ', "\t", "\r\n", "\n" ),
02008 '',
02009 urldecode( $text ) );
02010
02011 foreach ( $this->ezPages as $pageNum => $pageID )
02012 {
02013 $this->pushStack();
02014
02015 if ( $header )
02016 {
02017 foreach( $frameCoords as $key => $value )
02018 {
02019 $this->ez[$key] = $value;
02020 }
02021 $this->setYOffset( $this->ez['pageHeight'] - $this->ez['topMargin'] );
02022 }
02023 else
02024 {
02025 $this->ez['topMargin'] = $this->ez['pageHeight'] - $this->ez['bottomMargin'] + $frameCoords['topMargin'];
02026 foreach( $frameCoords as $key => $value )
02027 {
02028 if ( $key != 'topMargin' )
02029 {
02030 $this->ez[$key] = $value;
02031 }
02032 }
02033 }
02034
02035 $this->setXOffset( 0 );
02036
02037 $frameText = $text;
02038 if( $textParameters['page'] == 'even' &&
02039 $pageNum % 2 == 1 )
02040 continue;
02041 else if ( $textParameters['page'] == 'odd' &&
02042 $pageNum % 2 == 0 )
02043 continue;
02044
02045 if ( strstr( $frameText, EZ_PDF_LIB_PAGENUM ) !== false )
02046 {
02047 foreach ( array_keys( $this->PageCounter ) as $identifier )
02048 {
02049 if ( $this->PageCounter[$identifier]['start'] <= $pageNum &&
02050 $this->PageCounter[$identifier]['stop'] >= $pageNum )
02051 {
02052 $frameText = str_replace( EZ_PDF_LIB_PAGENUM,
02053 $this->ezWhatPageNumber( $pageNum, $identifier ),
02054 $frameText );
02055
02056 if ( strstr( $frameText, EZ_PDF_LIB_TOTAL_PAGENUM ) !== false )
02057 {
02058 $frameText = str_replace( EZ_PDF_LIB_TOTAL_PAGENUM,
02059 $this->PageCounter[$identifier]['stop'] - $this->PageCounter[$identifier]['start'] + 1,
02060 $frameText );
02061 }
02062 }
02063 }
02064 }
02065
02066 for( $levelCount = 0; $levelCount < 9; $levelCount++ )
02067 {
02068 if ( strstr( $frameText, EZ_PDF_LIB_HEADER_LEVEL.$levelCount ) !== false )
02069 {
02070 $frameText = str_replace( EZ_PDF_LIB_HEADER_LEVEL.$levelCount,
02071 $this->headerLabel( $pageNum, $levelCount ),
02072 $frameText );
02073 }
02074
02075 if ( strstr( $frameText, EZ_PDF_LIB_HEADER_LEVEL_INDEX.$levelCount ) !== false )
02076 {
02077 $frameText = str_replace( EZ_PDF_LIB_HEADER_LEVEL_INDEX.$levelCount,
02078 $this->headerIndex( $pageNum, $levelCount ),
02079 $frameText );
02080 }
02081 }
02082
02083 $this->reopenObject($pageID);
02084 $this->ezText( $frameText );
02085 $this->closeObject();
02086 $this->popStack();
02087 }
02088 }
02089
02090
02091
02092
02093
02094
02095
02096 function ezInsertFrame( $text, $textParameters )
02097 {
02098 $size = $this->fontSize();
02099 if ( isset( $textParameters['size'] ) )
02100 {
02101 $size = $textParameters['size'];
02102 }
02103
02104 $previousFont = $this->currentFont();
02105 if ( isset( $textParameters['font'] ) )
02106 {
02107 $this->selectFont( $textParameters['font'] );
02108 }
02109
02110 $justification = $this->justification();
02111 if ( isset( $textParameters['justification'] ) )
02112 {
02113 $justification = $textParameters['justification'];
02114 }
02115
02116 switch( $textParameters['location'] )
02117 {
02118 case 'footer':
02119 {
02120 $frameCoords =& $this->ezFrame['footer'];
02121 } break;
02122
02123 case 'frame_header':
02124 {
02125 $frameCoords =& $this->ezFrame['header'];
02126 } break;
02127
02128 default:
02129 {
02130 $frameCoords =& $this->ezFrame[0];
02131 } break;
02132 }
02133
02134 foreach ( $this->ezPages as $pageNum => $pageID )
02135 {
02136 if ( $pageNum < $textParameters['pageOffset'] )
02137 continue;
02138
02139 $frameText = $text;
02140 if( $textParameters['page'] == 'even' &&
02141 $pageNum % 2 == 1 )
02142 continue;
02143 else if ( $textParameters['page'] == 'odd' &&
02144 $pageNum % 2 == 0 )
02145 continue;
02146
02147 $countIdentifier = '';
02148 if ( strstr( $frameText, EZ_PDF_LIB_PAGENUM ) !== false )
02149 {
02150 foreach ( array_keys( $this->PageCounter ) as $identifier )
02151 {
02152 if ( $this->PageCounter[$identifier]['start'] <= $pageNum &&
02153 $this->PageCounter[$identifier]['stop'] >= $pageNum )
02154 {
02155 $frameText = str_replace( EZ_PDF_LIB_PAGENUM,
02156 $this->ezWhatPageNumber( $pageNum, $identifier ),
02157 $frameText );
02158
02159 if ( strstr( $frameText, EZ_PDF_LIB_TOTAL_PAGENUM ) !== false )
02160 {
02161 $frameText = str_replace( EZ_PDF_LIB_TOTAL_PAGENUM,
02162 $this->PageCounter[$identifier]['stop'] - $this->PageCounter[$identifier]['start'] + 1,
02163 $frameText );
02164 }
02165 }
02166 }
02167 }
02168
02169 for( $levelCount = 0; $levelCount < 9; $levelCount++ )
02170 {
02171 if ( strstr( $frameText, EZ_PDF_LIB_HEADER_LEVEL.$levelCount ) !== false )
02172 {
02173 $frameText = str_replace( EZ_PDF_LIB_HEADER_LEVEL.$levelCount,
02174 $this->headerLabel( $pageNum, $levelCount ),
02175 $frameText );
02176 }
02177
02178 if ( strstr( $frameText, EZ_PDF_LIB_HEADER_LEVEL_INDEX.$levelCount ) !== false )
02179 {
02180 $frameText = str_replace( EZ_PDF_LIB_HEADER_LEVEL_INDEX.$levelCount,
02181 $this->headerIndex( $pageNum, $levelCount ),
02182 $frameText );
02183 }
02184 }
02185
02186 $yOffset = $frameCoords['y0'] - $frameCoords['topMargin'];
02187 if ( $textParameters['newline'] )
02188 {
02189 $yOffset -= $this->getFontHeight( $size );
02190 }
02191
02192 $yOffset -= $this->getFontHeight( $size );
02193 $xOffset = $frameCoords['leftMargin'];
02194 $pageWidth = $this->ez['pageWidth'] - $frameCoords['leftMargin'] - $frameCoords['rightMargin'];
02195
02196 $this->reopenObject($pageID);
02197
02198 $lines = explode( "\n", $frameText );
02199 foreach ( array_keys( $lines ) as $key )
02200 {
02201 $start=1;
02202 $line = $lines[$key];
02203 while (strlen($line) || $start){
02204 $start = 0;
02205 $textInfo = $this->addTextWrap( $xOffset, $yOffset, $pageWidth, $size, $line, $justification );
02206 $line = $textInfo['text'];
02207
02208 if ( strlen( $line ) )
02209 {
02210 $yOffset -= $this->getFontHeight( $size );
02211 }
02212 }
02213 }
02214
02215 $this->closeObject();
02216 }
02217
02218 $this->selectFont( $previousFont );
02219 }
02220
02221
02222
02223
02224
02225
02226
02227 function callFrontpage( $params, $text )
02228 {
02229 $this->addDocSpecFunction( 'insertFrontpage', array( $params, $text ) );
02230 }
02231
02232
02233
02234
02235 function insertFrontpage( $params, $text )
02236 {
02237 $this->saveState();
02238 $closeObject = false;
02239 if ( $this->FrontpageID == null )
02240 {
02241 $this->ezInsertMode(1,1,'before');
02242 $this->ezNewPage();
02243 $this->FrontpageID = $this->currentPage;
02244 }
02245 else if( $this->currentPage != $this->FrontpageID )
02246 {
02247 $this->reopenObject( $this->FrontpageID );
02248 $closeObject = true;
02249 }
02250
02251 $fontSize = $this->fontSize();
02252
02253 $text = $this->fixWhitespace( $text );
02254 $this->setXOffset( 0 );
02255
02256 Cezpdf::ezText( $text, $params['size'], array( 'justification' => $params['justification'],
02257 'top_margin' => $params['top_margin'] ) );
02258
02259 $this->setFontSize( $fontSize );
02260
02261 if ( $closeObject )
02262 {
02263 $this->closeObject();
02264 }
02265 $this->restoreState();
02266 }
02267
02268
02269
02270
02271
02272
02273
02274 function callTable( $params, $text )
02275 {
02276 $textLen = strlen( $text );
02277 $tableData = array();
02278 $cellData = array();
02279 $showLines = 2;
02280 $rowCount = 0;
02281 $columnCount = 0;
02282
02283 $columnText = '';
02284
02285 $keyArray = array ( 'c', 'm', 'y', 'k' );
02286 if ( isset( $params['titleCellCMYK'] ) )
02287 {
02288 $params['titleCellCMYK'] = explode( ',', $params['titleCellCMYK'] );
02289 foreach ( array_keys( $params['titleCellCMYK'] ) as $key )
02290 {
02291 $params['titleCellCMYK'][$keyArray[$key]] = $params['titleCellCMYK'][$key];
02292 unset( $params['titleCellCMYK'][$key] );
02293 }
02294 }
02295
02296 if ( isset( $params['cellCMYK'] ) )
02297 {
02298 $params['cellCMYK'] = explode( ',', $params['cellCMYK'] );
02299 foreach ( array_keys( $params['cellCMYK'] ) as $key )
02300 {
02301 $params['cellCMYK'][$keyArray[$key]] = $params['cellCMYK'][$key];
02302 unset( $params['cellCMYK'][$key] );
02303 }
02304 $params['shaded'] = 2;
02305 $params['shadeCol'] = $params['cellCMYK'];
02306 $params['shadeCol2'] = $params['cellCMYK'];
02307 }
02308
02309 if ( isset( $params['textCMYK'] ) )
02310 {
02311 $params['textCMYK'] = explode( ',', $params['textCMYK'] );
02312 foreach ( array_keys( $params['textCMYK'] ) as $key )
02313 {
02314 $params['textCMYK'][$keyArray[$key]] = $params['textCMYK'][$key];
02315 unset( $params['textCMYK'][$key] );
02316 }
02317 $params['textCol'] = $params['textCMYK'];
02318 }
02319
02320 if ( isset( $params['titleTextCMYK'] ) )
02321 {
02322 $params['titleTextCMYK'] = explode( ',', $params['titleTextCMYK'] );
02323 foreach ( array_keys( $params['titleTextCMYK'] ) as $key )
02324 {
02325 $params['titleTextCMYK'][$keyArray[$key]] = $params['titleTextCMYK'][$key];
02326 unset( $params['titleTextCMYK'][$key] );
02327 }
02328 $params['titleTextCMYK'] = $params['titleTextCMYK'];
02329 }
02330
02331 if ( isset( $params['showLines'] ) )
02332 {
02333 $showLines = $params['showLines'];
02334 }
02335
02336 for ( $offSet = 0; $offSet < $textLen; $offSet++ )
02337 {
02338 if ( $text[$offSet] == '<' )
02339 {
02340 if ( strcmp( substr($text, $offSet+1, strlen( 'tr' ) ), 'tr' ) == 0 )
02341 {
02342 $tableData[] = array();
02343 $offSet++;
02344 $offSet += strlen( 'tr' );
02345 continue;
02346 }
02347 else if ( strcmp( substr($text, $offSet+1, strlen( 'td' ) ), 'td' ) == 0 )
02348 {
02349 $tdParams = array();
02350 $offSet++;
02351 $offSet += strlen( 'td' );
02352 $offSet = eZPDFTable::extractParameters( $text, $offSet, $tdParams );
02353
02354 if ( count( $tdParams ) > 0 )
02355 {
02356 $cellData[$columnCount. ',' .$rowCount] = array();
02357 if ( isset( $tdParams['colspan'] ) )
02358 {
02359 $cellData[$columnCount. ',' .$rowCount]['size'] = (int)$tdParams['colspan'];
02360 }
02361 if ( isset( $tdParams['align'] ) )
02362 {
02363 $cellData[$columnCount. ',' .$rowCount]['justification'] = $tdParams['align'];
02364 }
02365 if ( isset( $tdParams['width'] ) )
02366 {
02367 $cellData[$columnCount. ',' .$rowCount]['width'] = $tdParams['width'];
02368 }
02369 }
02370 continue;
02371 }
02372 else if ( strcmp( substr($text, $offSet+1, strlen( 'th' ) ), 'th' ) == 0 )
02373 {
02374 $thParams = array();
02375 $offSet++;
02376 $offSet += strlen( 'th' );
02377 $offSet = eZPDFTable::extractParameters( $text, $offSet, $thParams );
02378
02379 $cellData[$columnCount. ',' .$rowCount] = array();
02380 $cellData[$columnCount.','.$rowCount]['title'] = true;
02381 if ( isset( $thParams['colspan'] ) )
02382 {
02383 $cellData[$columnCount. ',' .$rowCount]['size'] = (int)$thParams['colspan'];
02384 }
02385 if ( isset( $thParams['align'] ) )
02386 {
02387 $cellData[$columnCount. ',' .$rowCount]['justification'] = $thParams['align'];
02388 }
02389 if ( isset( $thParams['width'] ) )
02390 {
02391 $cellData[$columnCount. ',' .$rowCount]['width'] = $thParams['width'];
02392 }
02393 continue;
02394 }
02395 else if ( strcmp( substr($text, $offSet+1, strlen( '/tr' ) ), '/tr' ) == 0 )
02396 {
02397 $rowCount++;
02398 $columnCount = 0;
02399 $offSet++;
02400 $offSet += strlen( '/tr' );
02401 continue;
02402 }
02403 else if ( strcmp( substr($text, $offSet+1, strlen( '/td' ) ), '/td' ) == 0 )
02404 {
02405 if ( $columnCount == 0 )
02406 {
02407 $tableData[$rowCount] = array();
02408 }
02409 $tableData[$rowCount][$columnCount] = $columnText;
02410 $columnText = '';
02411 $columnCount++;
02412 $offSet++;
02413 $offSet += strlen( '/td' );
02414 continue;
02415 }
02416 else if ( strcmp( substr($text, $offSet+1, strlen( '/th' ) ), '/th' ) == 0 )
02417 {
02418 if ( $columnCount == 0 )
02419 {
02420 $tableData[$rowCount] = array();
02421 }
02422 $tableData[$rowCount][$columnCount] = $columnText;
02423 $columnText = '';
02424 $columnCount++;
02425 $offSet++;
02426 $offSet += strlen( '/th' );
02427 continue;
02428 }
02429 }
02430 $columnText .= $text[$offSet];
02431 }
02432 $this->addDocSpecFunction( 'ezTable', array( $tableData, '', '', array_merge( array( 'cellData' => $cellData,
02433 'showLines' => $showLines ),
02434 $params ) ) );
02435 }
02436
02437
02438
02439
02440
02441
02442
02443
02444
02445
02446
02447 function extractFunction( &$text, $offSet, &$functionName, &$parameters, $type='ezCall' )
02448 {
02449 $offSet++;
02450 $offSet += strlen( $type.':' );
02451 $funcEnd = strpos( $text, ':', $offSet );
02452 if ( $funcEnd === false || strpos( $text, '>', $offSet ) < $funcEnd )
02453 {
02454 $funcEnd = strpos( $text, '>', $offSet );
02455 }
02456 $functionName = substr( $text, $offSet, $funcEnd - $offSet );
02457
02458 return eZPDFTable::extractParameters( $text, $funcEnd, $parameters );
02459 }
02460
02461
02462
02463
02464
02465
02466
02467
02468
02469
02470 function extractParameters( &$text, $offSet, &$parameters, $skipFirstChar=false )
02471 {
02472 $endOffset = strpos( $text, '>', $offSet );
02473 if ( $endOffset === false )
02474 {
02475 $endOffset = strlen( $text );
02476 }
02477
02478 if ( $skipFirstChar === false )
02479 $offSet++;
02480 while ( $offSet < $endOffset )
02481 {
02482 $nameEnd = strpos( $text, ':', $offSet );
02483 $valueEnd = strpos( $text, ':', $nameEnd+1 );
02484 if ( $valueEnd > $endOffset || $valueEnd === false )
02485 {
02486 $valueEnd = $endOffset;
02487 }
02488 $paramName = substr( $text, $offSet, $nameEnd-$offSet);
02489 ++$nameEnd;
02490 $paramValue = substr( $text, $nameEnd, $valueEnd-$nameEnd );
02491 $parameters[$paramName] = $paramValue;
02492 $offSet = ++$valueEnd;
02493 }
02494
02495 return $endOffset;
02496 }
02497
02498
02499
02500
02501
02502
02503 function outputDocSpecification()
02504 {
02505 foreach( array_keys( $this->DocSpecification ) as $key )
02506 {
02507 $outputElement =& $this->DocSpecification[$key];
02508
02509 $documentSpec =& $outputElement['docSpec'];
02510
02511 if ( isset( $documentSpec['fontName'] ) )
02512 {
02513 $this->selectFont( $documentSpec['fontName'] );
02514 }
02515
02516 if ( isset( $documentSpec['fontSize'] ) )
02517 {
02518 $size = $documentSpec['fontSize'];
02519 }
02520 else
02521 {
02522 $size = $this->fontSize();
02523 }
02524
02525 if ( isset( $documentSpec['cmyk'] ) )
02526 {
02527 $this->setColor( $documentSpec['cmyk'] );
02528 }
02529
02530 if ( isset( $outputElement['isFunction'] ) && $outputElement['isFunction'] === true )
02531 {
02532 $return = call_user_func_array( array( &$this, $outputElement['functionName'] ), $outputElement['parameters'] );
02533 }
02534 else
02535 {
02536 $return = Cezpdf::ezText( $outputElement['text'],
02537 $size,
02538 array( 'justification' => $documentSpec['justification'] ) );
02539 }
02540 }
02541 return $return;
02542 }
02543
02544
02545
02546
02547 function callTextBox( $params, $text )
02548 {
02549 $this->addDocSpecFunction( 'insertTextBox', array( $params, $text ) );
02550 }
02551
02552 function insertTextBox( $params, $text )
02553 {
02554 $this->pushStack();
02555
02556 $this->setYOffset( $params['y'] );
02557 $this->setXOffset( $params['x'] );
02558
02559 $marginText = '<C:callSetMargin';
02560 $marginText .= ':left:' . ( $params['x'] );
02561 $marginText .= ':right:' . ( $this->ez['pageWidth'] - $params['width'] - $params['x'] );
02562 $marginText .= '>';
02563 $marginText .= '<ezCall:callText';
02564 $marginText .= ':size:' . ( isset( $params['size'] ) ? $params['size'] : $this->fontSize() );
02565 $marginText .= ':justification:' . ( isset( $params['align'] ) ? $params['align'] : 'left' );
02566 $marginText .= '>';
02567
02568 $this->ezText( $marginText . $text . '</ezCall:callText>' );
02569
02570 $this->popStack();
02571 }
02572
02573
02574
02575
02576 function callTextFrame( $params, $text )
02577 {
02578 $this->addDocSpecFunction( 'insertTextFrame', array( $params, $text ) );
02579 }
02580
02581
02582
02583
02584 function insertTextFrame( $params, $text )
02585 {
02586 $prevColor = $this->currentColour;
02587 $prevFontSize = $this->fontSize();
02588 $prevFont = $this->currentFont();
02589
02590 if ( isset( $params['fontSize'] ) )
02591 {
02592 $this->setFontSize( $params['fontSize'] );
02593 }
02594
02595 if ( isset( $params['fontName'] ) )
02596 {
02597 $this->selectFont( $params['fontName'] );
02598 }
02599
02600 $cmykKeys = array( 'c', 'm', 'y', 'k' );
02601 if ( isset( $params ['frameCMYK'] ) )
02602 {
02603 $params['frameCMYK'] = explode( ',', $params['frameCMYK'] );
02604 foreach ( $cmykKeys as $oldKey => $newKey )
02605 {
02606 $params['frameCMYK'][$newKey] = $params['frameCMYK'][$oldKey];
02607 unset( $params['frameCMYK'][$oldKey] );
02608 }
02609 }
02610 if ( isset( $params['textCMYK'] ) )
02611 {
02612 $params['textCMYK'] = explode( ',', $params['textCMYK'] );
02613 foreach ( $cmykKeys as $oldKey => $newKey )
02614 {
02615 $params['textCMYK'][$newKey] = $params['textCMYK'][$oldKey];
02616 unset( $params['textCMYK'][$oldKey] );
02617 }
02618 }
02619
02620 $padding = 0;
02621 if ( isset( $params['padding'] ) )
02622 {
02623 $padding = $params['padding'];
02624 }
02625
02626 $leftPadding = $padding;
02627 $rightPadding = $padding;
02628 $topPadding = $padding;
02629 $bottomPadding = $padding;
02630
02631 if ( isset( $params['leftPadding'] ) )
02632 {
02633 $leftPadding = $params['leftPadding'];
02634 }
02635 if ( isset( $params['rightPadding'] ) )
02636 {
02637 $rightPadding = $params['rightPadding'];
02638 }
02639 if ( isset( $params['topPadding'] ) )
02640 {
02641 $topPadding = $params['topPadding'];
02642 }
02643 if ( isset( $params['bottomPadding'] ) )
02644 {
02645 $bottomPadding = $params['bottomPadding'];
02646 }
02647
02648 $yOffset = $this->yOffset();
02649 $xOffset = $this->xOffset();
02650
02651 $fontHeight = $this->getFontHeight( $this->ez['fontSize'] );
02652 $fontDecender = $this->getFontDecender( $this->ez['fontSize'] );
02653 $textWidth = $this->getTextWidth( $this->ez['fontSize'], $text );
02654
02655 $totalHeight = $fontHeight + $topPadding;
02656 $totalWidth = $textWidth + $leftPadding + $rightPadding;
02657
02658 if ( $rightPadding == -1 )
02659 {
02660 $totalWidth = $leftPadding + $this->ez['pageWidth'] - $xOffset + 10;
02661 }
02662
02663 if ( isset( $params['frameCMYK'] ) )
02664 {
02665 $this->setColor( $params['frameCMYK'] );
02666 }
02667 $this->filledRectangle( $xOffset - $leftPadding,
02668 $yOffset - $bottomPadding,
02669 $totalWidth,
02670 $totalHeight );
02671
02672 if ( isset( $params['roundEnds'] ) )
02673 {
02674 if ( $rightPadding != -1 )
02675 {
02676 $this->filledEllipse( $xOffset + $textWidth + $rightPadding, $yOffset - $bottomPadding + ( $totalHeight / 2 ), $totalHeight / 2 );
02677 }
02678 if ( $leftPadding != -1 )
02679 {
02680 $this->filledEllipse( $xOffset - $leftPadding, $yOffset - $bottomPadding + ( $totalHeight / 2 ), $totalHeight / 2 );
02681 }
02682 }
02683
02684 if ( isset( $params['textCMYK'] ) )
02685 {
02686 $this->setColor( $params['textCMYK'] );
02687 }
02688 else
02689 {
02690 $this->setColor( $prevColor );
02691 }
02692 $this->addText( $xOffset, $yOffset, $this->fontSize(), $text );
02693
02694 $this->setColor( $prevColor );
02695 $this->setFontSize( $prevFontSize );
02696 $this->selectFont( $prevFont );
02697 }
02698
02699
02700
02701
02702 function callText( $params )
02703 {
02704 $options = array();
02705
02706 if ( isset( $params['font'] ) )
02707 {
02708 $options['fontName'] = 'lib/ezpdf/classes/fonts/'. $params['font'];
02709 }
02710
02711 if ( isset( $params['size'] ) )
02712 {
02713 $options['fontSize'] = $params['size'];
02714 }
02715
02716 if ( isset( $params['justification'] ) )
02717 {
02718 $options['justification'] = $params['justification'];
02719 }
02720
02721 if ( isset( $params['cmyk'] ) )
02722 {
02723 $keyArray = array ( 'c', 'm', 'y', 'k' );
02724 $options['cmyk'] = array();
02725 $params['cmyk'] = explode( ',', $params['cmyk'] );
02726 foreach ( array_keys( $params['cmyk'] ) as $key )
02727 {
02728 $options['cmyk'][$keyArray[$key]] = $params['cmyk'][$key];
02729 }
02730 }
02731
02732 $this->addToPreStack( $options );
02733
02734 return '';
02735 }
02736
02737
02738
02739
02740
02741
02742 function pushStack( $continous = true)
02743 {
02744 include_once( 'lib/ezutils/classes/ezmath.php' );
02745 $docSpecArray = array( 'DocSpec' => $this->DocSpecification,
02746 'PreStack' => $this->PreStack,
02747 'LeftMarginArray' => $this->LeftMarginArray,
02748 'RightMarginArray' => $this->RightMarginArray,
02749 'LeftMargin' => $this->ez['leftMargin'],
02750 'RightMargin' => $this->ez['rightMargin'],
02751 'TopMargin' => $this->ez['topMargin'],
02752 'BottomMargin' => $this->ez['bottomMargin'],
02753 'LineSpace' => $this->ez['lineSpace'],
02754 'Continous' => $continous,
02755 'FontSize' => $this->fontSize(),
02756 'Justification' => $this->justification() );
02757 if ( $continous )
02758 {
02759 $docSpecArray['YPos'] = $this->yOffset();
02760 $docSpecArray['XPos'] = $this->xOffset();
02761 }
02762
02763 $this->DocSpecStack[] = $docSpecArray;
02764
02765 $this->PreStack = array( array( 'justification' => $this->justification(),
02766 'fontSize' => $this->fontSize(),
02767 'fontName' => 'lib/ezpdf/classes/fonts/Helvetica',
02768 'cmyk' => eZMath:: rgbToCMYK2( 0, 0, 0 ) ) );
02769 $this->DocSpecification = array();
02770 }
02771
02772
02773
02774
02775 function popStack()
02776 {
02777 $stackArray = array_pop( $this->DocSpecStack );
02778 $this->DocSpecification = $stackArray['DocSpec'];
02779 $this->PreStack = $stackArray['PreStack'];
02780 $this->LeftMarginArray = $stackArray['LeftMarginArray'];
02781 $this->RightMarginArray = $stackArray['RightMarginArray'];
02782 $this->ez['leftMargin'] = $stackArray['LeftMargin'];
02783 $this->ez['rightMargin'] = $stackArray['RightMargin'];
02784 $this->ez['topMargin'] = $stackArray['TopMargin'];
02785 $this->ez['bottomMargin'] = $stackArray['BottomMargin'];
02786 $this->ez['lineSpace'] = $stackArray['LineSpace'];
02787 $this->setFontSize( $stackArray['FontSize'] );
02788 $this->setJustification( $stackArray['justification'] );
02789
02790 if ( $stackArray['continous'] )
02791 {
02792 $this->setYOffset( $stackArray['YPos'] );
02793 $this->setXOffset( $stackArray['XPos'] );
02794 }
02795 }
02796
02797
02798
02799
02800
02801
02802 function addDocSpecification( $text )
02803 {
02804 $docSpec = array_pop( $this->PreStack );
02805 $this->DocSpecification[] = array ( 'docSpec' => $docSpec,
02806 'text' => $text );
02807 $this->PreStack[] = $docSpec;
02808 }
02809
02810
02811
02812
02813
02814
02815 function addDocSpecFunction( $functionName, $parameters )
02816 {
02817 $docSpec = array_pop( $this->PreStack );
02818 $this->DocSpecification[] = array ( 'docSpec' => $docSpec,
02819 'isFunction' => true,
02820 'functionName' => $functionName,
02821 'parameters' => $parameters );
02822 $this->PreStack[] = $docSpec;
02823 }
02824
02825
02826
02827
02828
02829
02830
02831
02832
02833
02834 function addToPreStack( $options=array() )
02835 {
02836 $currentElement = array();
02837
02838 $prevElement = array_pop( $this->PreStack );
02839
02840 if ( isset( $options['justification'] ) )
02841 {
02842 $currentElement['justification'] = $options['justification'];
02843 }
02844 else
02845 {
02846 $currentElement['justification'] = $prevElement['justification'];
02847 }
02848
02849 if ( isset( $options['fontSize'] ) )
02850 {
02851 $currentElement['fontSize'] = $options['fontSize'];
02852 }
02853 else
02854 {
02855 $currentElement['fontSize'] = $prevElement['fontSize'];
02856 }
02857
02858 if ( isset( $options['fontName'] ) )
02859 {
02860 $currentElement['fontName'] = $options['fontName'];
02861 }
02862 else
02863 {
02864 $currentElement['fontName'] = $prevElement['fontName'];
02865 }
02866
02867 if ( isset( $options['cmyk'] ) )
02868 {
02869 $currentElement['cmyk'] = $options['cmyk'];
02870 }
02871 else
02872 {
02873 $currentElement['cmyk'] = $prevElement['cmyk'];
02874 }
02875
02876 $this->PreStack[] = $prevElement;
02877 $this->PreStack[] = $currentElement;
02878 }
02879
02880
02881
02882
02883 function callFrameLine( $info )
02884 {
02885 $parameters = array();
02886 eZPDFTable::extractParameters( $info['p'], 0, $parameters, true );
02887
02888 $location = $parameters['location'];
02889 $yOffset = $parameters['margin'];
02890 if ( $location == 'frame_header' )
02891 {
02892 $yOffset = $this->ez['pageHeight'] - $parameters['margin'];
02893 }
02894
02895 $rightMargin = $this->rightMargin( $yOffset );
02896 if ( isset( $parameters['rightMargin'] ) )
02897 {
02898 $rightMargin = $parameters['rightMargin'];
02899 }
02900
02901 $leftMargin = $this->leftMargin( $yOffset );
02902 if ( isset( $parameters['leftMargin'] ) )
02903 {
02904 $leftMargin = $parameters['leftMargin'];
02905 }
02906
02907 $this->setLineStyle( $parameters['thickness'] );
02908
02909 reset( $this->ezPages );
02910 foreach ( $this->ezPages as $pageNum => $pageID )
02911 {
02912 if( $pageNum < $parameters['pageOffset'] )
02913 continue;
02914
02915 if ( $parameters['page'] == 'odd' &&
02916 $pageNum % 2 == 0 )
02917 continue;
02918
02919 if ( $parameters['page'] == 'even' &&
02920 $pageNum % 2 == 1 )
02921 continue;
02922
02923 $this->reopenObject( $pageID );
02924 $this->line( $leftMargin, $yOffset, $this->ez['pageWidth'] - $rightMargin, $yOffset );
02925 $this->closeObject();
02926 }
02927
02928 $this->setLineStyle( 1 );
02929 }
02930
02931
02932
02933
02934
02935
02936 function callStartPageCounter( $info )
02937 {
02938 $params = array();
02939
02940 eZPDFTable::extractParameters( $info['p'], 0, $params, true );
02941
02942 $identifier = 'main';
02943 if ( isset( $params['identifier'] ) )
02944 {
02945 $identifier = $params['identifier'];
02946 }
02947
02948 if ( isset( $params['start'] ) )
02949 {
02950 $this->PageCounter[$identifier] = array();
02951 $this->PageCounter[$identifier]['start'] = $this->ezGetCurrentPageNumber();
02952 }
02953 if ( isset( $params['stop'] ) )
02954 {
02955 $this->PageCounter[$identifier]['stop'] = $this->ezGetCurrentPageNumber();
02956 }
02957 }
02958
02959
02960
02961
02962
02963
02964
02965 function ezWhatPageNumber( $pageNum, $identifier = false )
02966 {
02967 if ( $identifier === false )
02968 {
02969 foreach ( array_keys( $this->PageCounter ) as $identifier )
02970 {
02971 if ( isset( $this->PageCounter[$identifier]['start'] ) &&
02972 $this->PageCounter[$identifier]['start'] <= $pageNum &&
02973 ( !isset( $this->PageCounter[$identifier]['stop'] ) || $this->PageCounter[$identifier]['stop'] >= $pageNum ) )
02974 return $pageNum - $this->PageCounter[$identifier]['start'] + 1;
02975 }
02976 }
02977 else
02978 return $pageNum - $this->PageCounter[$identifier]['start'] + 1;
02979 }
02980
02981
02982
02983
02984
02985
02986
02987
02988
02989 function headerLabel( $page, $level )
02990 {
02991 $headerLabel = '';
02992 foreach ( array_keys( $this->TOC ) as $key )
02993 {
02994 $header = $this->TOC[$key];
02995 if ( $header['pageNumber'] > $page )
02996 return $headerLabel;
02997
02998 if ( $header['level'] == $level )
02999 {
03000 $headerLabel = $header['label'];
03001 }
03002 else if ( $header['level'] < $level )
03003 {
03004 $headerLabel = '';
03005 }
03006 }
03007
03008 return $headerLabel;
03009 }
03010
03011
03012
03013
03014
03015
03016
03017
03018
03019 function headerIndex( $page, $level )
03020 {
03021 $headerIndex = 0;
03022 foreach ( array_keys( $this->TOC ) as $key )
03023 {
03024 $header = $this->TOC[$key];
03025 if ( $header['pageNumber'] > $page )
03026 return ( $headerIndex != 0 ? $headerIndex : '' );
03027
03028 if ( $header['level'] == $level )
03029 {
03030 $headerIndex++;
03031 }
03032 else if ( $header['level'] < $level )
03033 {
03034 $headerLabel = 0;
03035 }
03036 }
03037
03038 return ( $headerIndex != 0 ? $headerIndex : '' );
03039 }
03040
03041 var $TOC;
03042 var $KeywordArray;
03043 var $PageCounter;
03044
03045 var $FrontpageID;
03046
03047 var $ezFrame;
03048
03049
03050 var $PreStack;
03051 var $DocSpecification;
03052
03053
03054 var $DocSpecStack = array();
03055 }
03056
03057
03058 ?>