|
eZ Publish
[trunk]
|
00001 <?php 00002 /** 00003 * File containing the eZPDF class. 00004 * 00005 * @copyright Copyright (C) 1999-2012 eZ Systems AS. All rights reserved. 00006 * @license http://www.gnu.org/licenses/gpl-2.0.txt GNU General Public License v2 00007 * @version //autogentag// 00008 * @package lib 00009 */ 00010 00011 /*! 00012 \defgroup eZPDF PDF generator library 00013 */ 00014 00015 /*! 00016 \class eZPDF ezpdf.php 00017 \ingroup eZPDF 00018 \brief eZPDF provides template operators for dealing with pdf generation 00019 */ 00020 00021 class eZPDF 00022 { 00023 00024 /*! 00025 Initializes the object with the name $name, default is "attribute". 00026 */ 00027 function eZPDF( $name = "pdf" ) 00028 { 00029 $this->Operators = array( $name ); 00030 $this->Config = eZINI::instance( 'pdf.ini' ); 00031 } 00032 00033 /*! 00034 Returns the template operators. 00035 */ 00036 function operatorList() 00037 { 00038 return $this->Operators; 00039 } 00040 00041 /*! 00042 See eZTemplateOperator::namedParameterList() 00043 */ 00044 function namedParameterList() 00045 { 00046 return array( 'operation' => array( 'type' => 'string', 00047 'required' => true, 00048 'default' => '' ) ); 00049 } 00050 00051 /*! 00052 Display the variable. 00053 */ 00054 function modify( $tpl, $operatorName, $operatorParameters, $rootNamespace, $currentNamespace, &$operatorValue, $namedParameters, $placement ) 00055 { 00056 $config = eZINI::instance( 'pdf.ini' ); 00057 00058 switch ( $namedParameters['operation'] ) 00059 { 00060 case 'toc': 00061 { 00062 $operatorValue = '<C:callTOC'; 00063 00064 if ( count( $operatorParameters ) > 1 ) 00065 { 00066 $params = $tpl->elementValue( $operatorParameters[1], $rootNamespace, $currentNamespace ); 00067 00068 $operatorValue .= isset( $params['size'] ) ? ':size:'. implode(',', $params['size'] ) : ''; 00069 $operatorValue .= isset( $params['dots'] ) ? ':dots:'. $params['dots'] : ''; 00070 $operatorValue .= isset( $params['contentText'] ) ? ':contentText:'. $params['contentText'] : ''; 00071 $operatorValue .= isset( $params['indent'] ) ? ':indent:'. implode(',', $params['indent'] ) : ''; 00072 00073 } 00074 00075 $operatorValue .= '>'; 00076 eZDebug::writeNotice( 'PDF: Generating TOC', __METHOD__ ); 00077 } break; 00078 00079 case 'set_font': 00080 { 00081 $params = $tpl->elementValue( $operatorParameters[1], $rootNamespace, $currentNamespace ); 00082 00083 $operatorValue = '<ezCall:callFont'; 00084 00085 foreach ( $params as $key => $value ) 00086 { 00087 if ( $key == 'colorCMYK' ) 00088 { 00089 $operatorValue .= ':cmyk:' . implode( ',', $value ); 00090 } 00091 else if ( $key == 'colorRGB' ) 00092 { 00093 $operatorValue .= ':cmyk:' . implode( ',', eZMath::rgbToCMYK2( $value[0]/255, 00094 $value[1]/255, 00095 $value[2]/255 ) ); 00096 } 00097 else 00098 { 00099 $operatorValue .= ':' . $key . ':' . $value; 00100 } 00101 } 00102 $operatorValue .= '>'; 00103 00104 eZDebug::writeNotice( 'PDF: Changed font.' ); 00105 } break; 00106 00107 case 'table': 00108 { 00109 $operatorValue = '<ezGroup:callTable'; 00110 00111 if ( count( $operatorParameters > 2 ) ) 00112 { 00113 $tableSettings = $tpl->elementValue( $operatorParameters[2], $rootNamespace, $currentNamespace ); 00114 00115 if ( is_array( $tableSettings ) ) 00116 { 00117 foreach( array_keys( $tableSettings ) as $key ) 00118 { 00119 switch( $key ) 00120 { 00121 case 'headerCMYK': 00122 case 'cellCMYK': 00123 case 'textCMYK': 00124 case 'titleCellCMYK': 00125 case 'titleTextCMYK': 00126 { 00127 $operatorValue .= ':' . $key . ':' . implode( ',', $tableSettings[$key] ); 00128 } break; 00129 00130 default: 00131 { 00132 $operatorValue .= ':' . $key . ':' . $tableSettings[$key]; 00133 } break; 00134 } 00135 } 00136 } 00137 } 00138 00139 $operatorValue .= '>'; 00140 00141 $rows = $tpl->elementValue( $operatorParameters[1], $rootNamespace, $currentNamespace ); 00142 00143 $rows = str_replace( array( ' ', "\t", "\r\n", "\n" ), 00144 '', 00145 $rows ); 00146 $httpCharset = eZTextCodec::internalCharset(); 00147 $outputCharset = $config->hasVariable( 'PDFGeneral', 'OutputCharset' ) 00148 ? $config->variable( 'PDFGeneral', 'OutputCharset' ) 00149 : 'iso-8859-1'; 00150 $codec = eZTextCodec::instance( $httpCharset, $outputCharset ); 00151 // Convert current text to $outputCharset (by default iso-8859-1) 00152 $rows = $codec->convertString( $rows ); 00153 00154 $operatorValue .= urlencode( $rows ); 00155 00156 $operatorValue .= '</ezGroup:callTable><C:callNewLine>'; 00157 00158 eZDebug::writeNotice( 'PDF: Added table to PDF', __METHOD__ ); 00159 } break; 00160 00161 case 'header': 00162 { 00163 $header = $tpl->elementValue( $operatorParameters[1], $rootNamespace, $currentNamespace ); 00164 00165 $header['text'] = str_replace( array( ' ', "\t", "\r\n", "\n" ), 00166 '', 00167 $header['text'] ); 00168 00169 $operatorValue = '<ezCall:callHeader:level:'. $header['level'] .':size:'. $header['size']; 00170 00171 if ( isset( $header['align'] ) ) 00172 { 00173 $operatorValue .= ':justification:'. $header['align']; 00174 } 00175 00176 if ( isset( $header['font'] ) ) 00177 { 00178 $operatorValue .= ':fontName:'. $header['font']; 00179 } 00180 00181 $operatorValue .= ':label:'. rawurlencode( $header['text'] ); 00182 00183 $operatorValue .= '><C:callNewLine>'. $header['text'] .'</ezCall:callHeader><C:callNewLine>'; 00184 00185 eZDebug::writeNotice( 'PDF: Added header: '. $header['text'] .', size: '. $header['size'] . 00186 ', align: '. $header['align'] .', level: '. $header['level'], 00187 __METHOD__ ); 00188 } break; 00189 00190 case 'create': 00191 { 00192 $this->createPDF(); 00193 } break; 00194 00195 case 'new_line': 00196 case 'newline': // Deprecated 00197 { 00198 $operatorValue = '<C:callNewLine>'; 00199 } break; 00200 00201 case 'new_page': 00202 case 'newpage': // Deprecated 00203 { 00204 $operatorValue = '<C:callNewPage><C:callNewLine>'; 00205 00206 eZDebug::writeNotice( 'PDF: New page', __METHOD__ ); 00207 } break; 00208 00209 case 'image': 00210 { 00211 $image = $tpl->elementValue( $operatorParameters[1], $rootNamespace, $currentNamespace ); 00212 00213 $width = isset( $image['width'] ) ? $image['width']: 100; 00214 $height = isset( $image['height'] ) ? $image['height']: 100; 00215 00216 $operatorValue = '<C:callImage:src:'. rawurlencode( $image['src'] ) .':width:'. $width .':height:'. $height; 00217 00218 if ( isset( $image['static'] ) ) 00219 { 00220 $operatorValue .= ':static:' . $image['static']; 00221 } 00222 00223 if ( isset ( $image['x'] ) ) 00224 { 00225 $operatorValue .= ':x:' . $image['x']; 00226 } 00227 00228 if ( isset( $image['y'] ) ) 00229 { 00230 $operatorValue .= ':y:' . $image['y']; 00231 } 00232 00233 if ( isset( $image['dpi'] ) ) 00234 { 00235 $operatorValue .= ':dpi:' . $image['dpi']; 00236 } 00237 00238 if ( isset( $image['align'] ) ) // left, right, center, full 00239 { 00240 $operatorValue .= ':align:' . $image['align']; 00241 } 00242 00243 $operatorValue .= '>'; 00244 00245 eZDebug::writeNotice( 'PDF: Added Image '.$image['src'].' to PDF file', __METHOD__ ); 00246 } break; 00247 00248 case 'anchor': 00249 { 00250 $name = $tpl->elementValue( $operatorParameters[1], $rootNamespace, $currentNamespace ); 00251 00252 $operatorValue = '<C:callAnchor:'. $name['name'] .':FitH:>'; 00253 eZDebug::writeNotice( 'PDF: Added anchor: '.$name['name'], __METHOD__ ); 00254 } break; 00255 00256 case 'link': // external link 00257 { 00258 $link = $tpl->elementValue( $operatorParameters[1], $rootNamespace, $currentNamespace ); 00259 00260 $link['text'] = str_replace( '"', 00261 '"', 00262 $link['text'] ); 00263 00264 $operatorValue = '<c:alink:'. rawurlencode( $link['url'] ) .'>'. $link['text'] .'</c:alink>'; 00265 eZDebug::writeNotice( 'PDF: Added link: '. $link['text'] .', url: '.$link['url'], __METHOD__ ); 00266 } break; 00267 00268 case 'stream': 00269 { 00270 $this->PDF->ezStream(); 00271 } 00272 00273 case 'close': 00274 { 00275 $filename = $tpl->elementValue( $operatorParameters[1], $rootNamespace, $currentNamespace ); 00276 00277 eZDir::mkdir( eZDir::dirpath( $filename ), false, true ); 00278 00279 $file = eZClusterFileHandler::instance( $filename ); 00280 $file->storeContents( $this->PDF->ezOutput(), 'viewcache', 'pdf' ); 00281 00282 eZDebug::writeNotice( 'PDF file closed and saved to '. $filename, __METHOD__ ); 00283 } break; 00284 00285 case 'strike': 00286 { 00287 $text = $tpl->elementValue( $operatorParameters[1], $rootNamespace, $currentNamespace ); 00288 $operatorValue = '<c:strike>'. $text .'</c:strike>'; 00289 eZDebug::writeNotice( 'Striked text added to PDF: "'. $text .'"', __METHOD__ ); 00290 } break; 00291 00292 /* usage : execute/add text to pdf file, pdf(execute,<text>) */ 00293 case 'execute': 00294 { 00295 $text = $tpl->elementValue( $operatorParameters[1], $rootNamespace, $currentNamespace ); 00296 00297 if ( count ( $operatorParameters ) > 2 ) 00298 { 00299 $options = $tpl->elementValue( $operatorParameters[2], $rootNamespace, $currentNamespace ); 00300 00301 $size = isset( $options['size'] ) ? $options['size'] : $config->variable( 'PDFGeneral', 'Format' ); 00302 $orientation = isset( $options['orientation'] ) ? $options['orientation'] : $config->variable( 'PDFGeneral', 'Orientation' ); 00303 00304 $this->createPDF( $size, $orientation ); 00305 } 00306 else 00307 { 00308 $this->createPDF( $config->variable( 'PDFGeneral', 'Format' ), $config->variable( 'PDFGeneral', 'Orientation' ) ); 00309 } 00310 00311 $text = str_replace( array( ' ', "\n", "\t" ), '', $text ); 00312 $httpCharset = eZTextCodec::internalCharset(); 00313 $outputCharset = $config->hasVariable( 'PDFGeneral', 'OutputCharset' ) 00314 ? $config->variable( 'PDFGeneral', 'OutputCharset' ) 00315 : 'iso-8859-1'; 00316 $codec = eZTextCodec::instance( $httpCharset, $outputCharset ); 00317 // Convert current text to $outputCharset (by default iso-8859-1) 00318 $text = $codec->convertString( $text ); 00319 00320 $this->PDF->ezText( $text ); 00321 eZDebug::writeNotice( 'Execute text in PDF, length: "'. strlen( $text ) .'"', __METHOD__ ); 00322 } break; 00323 00324 case 'page_number': 00325 case 'pageNumber': 00326 { 00327 $numberDesc = $tpl->elementValue( $operatorParameters[1], $rootNamespace, $currentNamespace ); 00328 00329 if ( isset( $numberDesc['identifier'] ) ) 00330 { 00331 $identifier = $numberDesc['identifier']; 00332 } 00333 else 00334 { 00335 $identifier = 'main'; 00336 } 00337 00338 if ( isset( $numberDesc['start'] ) ) 00339 { 00340 $operatorValue = '<C:callStartPageCounter:start:'. $numberDesc['start'] .':identifier:'. $identifier .'>'; 00341 } 00342 else if ( isset( $numberDesc['stop'] ) ) 00343 { 00344 $operatorValue = '<C:callStartPageCounter:stop:1:identifier:'. $identifier .'>'; 00345 } 00346 } break; 00347 00348 /* usage {pdf( line, hash( x1, <x>, y1, <y>, x2, <x2>, y2, <y2>, pages, <all|current>, thickness, <1..100>, ) )} */ 00349 case 'line': 00350 { 00351 $lineDesc = $tpl->elementValue( $operatorParameters[1], $rootNamespace, $currentNamespace ); 00352 00353 if ( isset( $lineDesc['pages']) and 00354 $lineDesc['pages'] == 'all' ) 00355 { 00356 $operatorValue = '<ezGroup:callLine'; 00357 } 00358 else 00359 { 00360 $operatorValue = '<C:callDrawLine'; 00361 } 00362 00363 $operatorValue .= ':x1:' . $lineDesc['x1']; 00364 $operatorValue .= ':x2:' . $lineDesc['x2']; 00365 $operatorValue .= ':y1:' . $lineDesc['y1']; 00366 $operatorValue .= ':y2:' . $lineDesc['y2']; 00367 00368 $operatorValue .= ':thickness:' . ( isset( $lineDesc['thickness'] ) ? $lineDesc['thickness'] : '1' ); 00369 00370 $operatorValue .= '>'; 00371 00372 if ( $lineDesc['pages'] == 'all' ) 00373 { 00374 $operatorValue .= '___</ezGroup:callLine>'; 00375 } 00376 00377 return $operatorValue; 00378 } break; 00379 00380 case 'footer_block': 00381 case 'header_block': 00382 { 00383 $frameDesc = $tpl->elementValue( $operatorParameters[1], $rootNamespace, $currentNamespace ); 00384 00385 $operatorValue = '<ezGroup:callBlockFrame'; 00386 $operatorValue .= ':location:'. $namedParameters['operation']; 00387 $operatorValue .= '>'; 00388 00389 if ( isset( $frameDesc['block_code'] ) ) 00390 { 00391 $httpCharset = eZTextCodec::internalCharset(); 00392 $outputCharset = $config->hasVariable( 'PDFGeneral', 'OutputCharset' ) 00393 ? $config->variable( 'PDFGeneral', 'OutputCharset' ) 00394 : 'iso-8859-1'; 00395 $codec = eZTextCodec::instance( $httpCharset, $outputCharset ); 00396 // Convert current text to $outputCharset (by default iso-8859-1) 00397 $frameDesc['block_code'] = $codec->convertString( $frameDesc['block_code'] ); 00398 $operatorValue .= urlencode( $frameDesc['block_code'] ); 00399 } 00400 00401 $operatorValue .= '</ezGroup:callBlockFrame>'; 00402 00403 eZDebug::writeNotice( 'PDF: Added Block '.$namedParameters['operation'] .': '.$operatorValue, __METHOD__ ); 00404 return $operatorValue; 00405 00406 } break; 00407 00408 /* deprecated */ 00409 case 'footer': 00410 case 'frame_header': 00411 { 00412 $frameDesc = $tpl->elementValue( $operatorParameters[1], $rootNamespace, $currentNamespace ); 00413 00414 $operatorValue = '<ezGroup:callFrame'; 00415 $operatorValue .= ':location:'. $namedParameters['operation']; 00416 00417 if ( $namedParameters['operation'] == 'footer' ) 00418 { 00419 $frameType = 'Footer'; 00420 } 00421 else if( $namedParameters['operation'] == 'frame_header' ) 00422 { 00423 $frameType = 'Header'; 00424 } 00425 00426 if ( isset( $frameDesc['align'] ) ) 00427 { 00428 $operatorValue .= ':justification:'. $frameDesc['align']; 00429 } 00430 00431 if ( isset( $frameDesc['page'] ) ) 00432 { 00433 $operatorValue .= ':page:'. $frameDesc['page']; 00434 } 00435 else 00436 { 00437 $operatorValue .= ':page:all'; 00438 } 00439 00440 $operatorValue .= ':newline:' . ( isset( $frameDesc['newline'] ) ? $frameDesc['newline'] : 0 ); 00441 00442 $operatorValue .= ':pageOffset:'; 00443 if ( isset( $frameDesc['pageOffset'] ) ) 00444 { 00445 $operatorValue .= $frameDesc['pageOffset']; 00446 } 00447 else 00448 { 00449 $operatorValue .= $this->Config->variable( $frameType, 'PageOffset' ); 00450 } 00451 00452 if ( isset( $frameDesc['size'] ) ) 00453 { 00454 $operatorValue .= ':size:'. $frameDesc['size']; 00455 } 00456 00457 if ( isset( $frameDesc['font'] ) ) 00458 { 00459 $operatorValue .= ':font:'. $frameDesc['font']; 00460 } 00461 00462 $operatorValue .= '>'; 00463 00464 if ( isset( $frameDesc['text'] ) ) 00465 { 00466 $httpCharset = eZTextCodec::internalCharset(); 00467 $outputCharset = $config->hasVariable( 'PDFGeneral', 'OutputCharset' ) 00468 ? $config->variable( 'PDFGeneral', 'OutputCharset' ) 00469 : 'iso-8859-1'; 00470 $codec = eZTextCodec::instance( $httpCharset, $outputCharset ); 00471 // Convert current text to $outputCharset (by default iso-8859-1) 00472 $frameDesc['text'] = $codec->convertString( $frameDesc['text'] ); 00473 $operatorValue .= urlencode( $frameDesc['text'] ); 00474 } 00475 00476 $operatorValue .= '</ezGroup:callFrame>'; 00477 00478 if ( isset( $frameDesc['margin'] ) ) 00479 { 00480 $operatorValue .= '<C:callFrameMargins'; 00481 00482 $operatorValue .= ':identifier:'. $namedParameters['operation']; 00483 00484 $operatorValue .= ':topMargin:'; 00485 if ( isset( $frameDesc['margin']['top'] ) ) 00486 { 00487 $operatorValue .= $frameDesc['margin']['top']; 00488 } 00489 else 00490 { 00491 $operatorValue .= $this->Config->variable( $frameType, 'TopMargin' ); 00492 } 00493 00494 $operatorValue .= ':bottomMargin:'; 00495 if ( isset( $frameDesc['margin']['bottom'] ) ) 00496 { 00497 $operatorValue .= $frameDesc['margin']['bottom']; 00498 } 00499 else 00500 { 00501 $operatorValue .= $this->Config->variable( $frameType, 'BottomMargin' ); 00502 } 00503 00504 $operatorValue .= ':leftMargin:'; 00505 if ( isset( $frameDesc['margin']['left'] ) ) 00506 { 00507 $operatorValue .= $frameDesc['margin']['left']; 00508 } 00509 else 00510 { 00511 $operatorValue .= $this->Config->variable( $frameType, 'LeftMargin' ); 00512 } 00513 00514 $operatorValue .= ':rightMargin:'; 00515 if ( isset( $frameDesc['margin']['right'] ) ) 00516 { 00517 $operatorValue .= $frameDesc['margin']['right']; 00518 } 00519 else 00520 { 00521 $operatorValue .= $this->Config->variable( $frameType, 'RightMargin' ); 00522 } 00523 00524 $operatorValue .= ':height:'; 00525 if ( isset( $frameDesc['margin']['height'] ) ) 00526 { 00527 $operatorValue .= $frameDesc['margin']['height']; 00528 } 00529 else 00530 { 00531 $operatorValue .= $this->Config->variable( $frameType, 'Height' ); 00532 } 00533 00534 $operatorValue .= '>'; 00535 } 00536 00537 if ( isset( $frameDesc['line'] ) ) 00538 { 00539 $operatorValue .= '<C:callFrameLine'; 00540 $operatorValue .= ':location:'. $namedParameters['operation']; 00541 00542 $operatorValue .= ':margin:'; 00543 if( isset( $frameDesc['line']['margin'] ) ) 00544 { 00545 $operatorValue .= $frameDesc['line']['margin']; 00546 } 00547 else 00548 { 00549 $operatorValue .= $this->Config->variable( $frameType, 'LineMargin' ); 00550 } 00551 00552 if ( isset( $frameDesc['line']['leftMargin'] ) ) 00553 { 00554 $operatorValue .= ':leftMargin:'. $frameDesc['line']['leftMargin']; 00555 } 00556 if ( isset( $frameDesc['line']['rightMargin'] ) ) 00557 { 00558 $operatorValue .= ':rightMargin:'. $frameDesc['line']['rightMargin']; 00559 } 00560 00561 $operatorValue .= ':pageOffset:'; 00562 if ( isset( $frameDesc['line']['pageOffset'] ) ) 00563 { 00564 $operatorValue .= $frameDesc['line']['pageOffset']; 00565 } 00566 else 00567 { 00568 $operatorValue .= $this->Config->variable( $frameType, 'PageOffset' ); 00569 } 00570 00571 $operatorValue .= ':page:'; 00572 if ( isset( $frameDesc['line']['page'] ) ) 00573 { 00574 $operatorValue .= $frameDesc['line']['page']; 00575 } 00576 else 00577 { 00578 $operatorValue .= $this->Config->variable( $frameType, 'Page' ); 00579 } 00580 00581 $operatorValue .= ':thickness:'; 00582 if ( isset( $frameDesc['line']['thickness'] ) ) 00583 { 00584 $operatorValue .= $frameDesc['line']['thickness']; 00585 } 00586 else 00587 { 00588 $operatorValue .= $this->Config->variable( $frameType, 'LineThickness' ); 00589 } 00590 $operatorValue .= '>'; 00591 } 00592 00593 eZDebug::writeNotice( 'PDF: Added frame '.$frameType .': '.$operatorValue, __METHOD__ ); 00594 } break; 00595 00596 case 'frontpage': 00597 { 00598 $pageDesc = $tpl->elementValue( $operatorParameters[1], $rootNamespace, $currentNamespace ); 00599 00600 $align = isset( $pageDesc['align'] ) ? $pageDesc['align'] : 'center'; 00601 $text = isset( $pageDesc['text'] ) ? $pageDesc['text'] : ''; 00602 $top_margin = isset( $pageDesc['top_margin'] ) ? $pageDesc['top_margin'] : 100; 00603 00604 $operatorValue = '<ezGroup:callFrontpage:justification:'. $align .':top_margin:'. $top_margin; 00605 00606 if ( isset( $pageDesc['size'] ) ) 00607 { 00608 $operatorValue .= ':size:'. $pageDesc['size']; 00609 } 00610 00611 $text = str_replace( array( ' ', "\t", "\r\n", "\n" ), 00612 '', 00613 $text ); 00614 $httpCharset = eZTextCodec::internalCharset(); 00615 $outputCharset = $config->hasVariable( 'PDFGeneral', 'OutputCharset' ) 00616 ? $config->variable( 'PDFGeneral', 'OutputCharset' ) 00617 : 'iso-8859-1'; 00618 $codec = eZTextCodec::instance( $httpCharset, $outputCharset ); 00619 // Convert current text to $outputCharset (by default iso-8859-1) 00620 $text = $codec->convertString( $text ); 00621 00622 $operatorValue .= '>'. urlencode( $text ) .'</ezGroup:callFrontpage>'; 00623 00624 eZDebug::writeNotice( 'Added content to frontpage: '. $operatorValue, __METHOD__ ); 00625 } break; 00626 00627 /* usage: pdf(set_margin( hash( left, <left_margin>, 00628 right, <right_margin>, 00629 x, <x offset>, 00630 y, <y offset> ))) 00631 */ 00632 case 'set_margin': 00633 { 00634 $operatorValue = '<C:callSetMargin'; 00635 $options = $tpl->elementValue( $operatorParameters[1], $rootNamespace, $currentNamespace ); 00636 00637 foreach( array_keys( $options ) as $key ) 00638 { 00639 $operatorValue .= ':' . $key . ':' . $options[$key]; 00640 } 00641 00642 $operatorValue .= '>'; 00643 00644 eZDebug::writeNotice( 'Added new margin/offset setup: ' . $operatorValue ); 00645 00646 return $operatorValue; 00647 } break; 00648 00649 /* add keyword to pdf document */ 00650 case 'keyword': 00651 { 00652 $text = $tpl->elementValue( $operatorParameters[1], $rootNamespace, $currentNamespace ); 00653 00654 $text = str_replace( array( ' ', "\n", "\t" ), '', $text ); 00655 $httpCharset = eZTextCodec::internalCharset(); 00656 $outputCharset = $config->hasVariable( 'PDFGeneral', 'OutputCharset' ) 00657 ? $config->variable( 'PDFGeneral', 'OutputCharset' ) 00658 : 'iso-8859-1'; 00659 $codec = eZTextCodec::instance( $httpCharset, $outputCharset ); 00660 // Convert current text to $outputCharset (by default iso-8859-1) 00661 $text = $codec->convertString( $text ); 00662 00663 $operatorValue = '<C:callKeyword:'. rawurlencode( $text ) .'>'; 00664 } break; 00665 00666 /* add Keyword index to pdf document */ 00667 case 'createIndex': 00668 case 'create_index': 00669 { 00670 $operatorValue = '<C:callIndex>'; 00671 00672 eZDebug::writeNotice( 'Adding Keyword index to PDF', __METHOD__ ); 00673 } break; 00674 00675 case 'ul': 00676 { 00677 $text = $tpl->elementValue( $operatorParameters[1], $rootNamespace, $currentNamespace ); 00678 if ( count( $operatorParameters ) > 2 ) 00679 { 00680 $params = $tpl->elementValue( $operatorParameters[2], $rootNamespace, $currentNamespace ); 00681 } 00682 else 00683 { 00684 $params = array(); 00685 } 00686 00687 if ( isset( $params['rgb'] ) ) 00688 { 00689 $params['rgb'] = eZMath::normalizeColorArray( $params['rgb'] ); 00690 $params['cmyk'] = eZMath::rgbToCMYK2( $params['rgb'][0]/255, 00691 $params['rgb'][1]/255, 00692 $params['rgb'][2]/255 ); 00693 } 00694 00695 if ( !isset( $params['cmyk'] ) ) 00696 { 00697 $params['cmyk'] = eZMath::rgbToCMYK2( 0, 0, 0 ); 00698 } 00699 if ( !isset( $params['radius'] ) ) 00700 { 00701 $params['radius'] = 2; 00702 } 00703 if ( !isset ( $params['pre_indent'] ) ) 00704 { 00705 $params['pre_indent'] = 0; 00706 } 00707 if ( !isset ( $params['indent'] ) ) 00708 { 00709 $params['indent'] = 2; 00710 } 00711 if ( !isset ( $params['yOffset'] ) ) 00712 { 00713 $params['yOffset'] = -1; 00714 } 00715 00716 $operatorValue = '<C:callCircle' . 00717 ':pages:current' . 00718 ':x:-1' . 00719 ':yOffset:' . $params['yOffset'] . 00720 ':y:-1' . 00721 ':indent:' . $params['indent'] . 00722 ':pre_indent:' . $params['pre_indent'] . 00723 ':radius:' . $params['radius'] . 00724 ':cmyk:' . implode( ',', $params['cmyk'] ) . 00725 '>'; 00726 00727 $operatorValue .= '<C:callSetMargin' . 00728 ':delta_left:' . ( $params['indent'] + $params['radius'] * 2 + $params['pre_indent'] ) . 00729 '>'; 00730 00731 $operatorValue .= $text; 00732 00733 $operatorValue .= '<C:callSetMargin' . 00734 ':delta_left:' . -1 * ( $params['indent'] + $params['radius'] * 2 + $params['pre_indent'] ) . 00735 '>'; 00736 } break; 00737 00738 case 'filled_circle': 00739 { 00740 $operatorValue = ''; 00741 $options = $tpl->elementValue( $operatorParameters[1], $rootNamespace, $currentNamespace ); 00742 00743 if ( !isset( $options['pages'] ) ) 00744 { 00745 $options['pages'] = 'current'; 00746 } 00747 00748 if ( !isset( $options['x'] ) ) 00749 { 00750 $options['x'] = -1; 00751 } 00752 00753 if ( !isset( $options['y'] ) ) 00754 { 00755 $options['y'] = -1; 00756 } 00757 00758 if ( isset( $options['rgb'] ) ) 00759 { 00760 $options['rgb'] = eZMath::normalizeColorArray( $options['rgb'] ); 00761 $options['cmyk'] = eZMath::rgbToCMYK2( $options['rgb'][0]/255, 00762 $options['rgb'][1]/255, 00763 $options['rgb'][2]/255 ); 00764 } 00765 00766 $operatorValue = '<C:callCircle' . 00767 ':pages:' . $options['pages'] . 00768 ':x:' . $options['x'] . 00769 ':y:' . $options['y'] . 00770 ':radius:' . $options['radius']; 00771 00772 if ( isset( $options['cmyk'] ) ) 00773 { 00774 $operatorValue .= ':cmyk:' . implode( ',', $options['cmyk'] ); 00775 } 00776 00777 $operatorValue .= '>'; 00778 00779 eZDebug::writeNotice( 'PDF Added circle: ' . $operatorValue ); 00780 00781 return $operatorValue; 00782 } break; 00783 00784 case 'rectangle': 00785 { 00786 $operatorValue = ''; 00787 $options = $tpl->elementValue( $operatorParameters[1], $rootNamespace, $currentNamespace ); 00788 00789 if ( !isset( $options['pages'] ) ) 00790 { 00791 $options['pages'] = 'current'; 00792 } 00793 if ( !isset( $options['line_width'] ) ) 00794 { 00795 $options['line_width'] = 1; 00796 } 00797 if ( !isset( $options['round_corner'] ) ) 00798 { 00799 $options['round_corner'] = false; 00800 } 00801 00802 $operatorValue = '<C:callRectangle'; 00803 foreach ( $options as $key => $value ) 00804 { 00805 if ( $key == 'rgb' ) 00806 { 00807 $options['rgb'] = eZMath::normalizeColorArray( $options['rgb'] ); 00808 $operatorValue .= ':cmyk:' . implode( ',', eZMath::rgbToCMYK2( $options['rgb'][0]/255, 00809 $options['rgb'][1]/255, 00810 $options['rgb'][2]/255 ) ); 00811 } 00812 else if ( $key == 'cmyk' ) 00813 { 00814 $operatorValue .= ':cmyk:' . implode( ',', $value ); 00815 } 00816 else 00817 { 00818 $operatorValue .= ':' . $key . ':' . $value; 00819 } 00820 } 00821 $operatorValue .= '>'; 00822 00823 eZDebug::writeNotice( 'PDF Added rectangle: ' . $operatorValue ); 00824 00825 return $operatorValue; 00826 } break; 00827 00828 /* usage: pdf( filled_rectangle, hash( 'x', <x offset>, 'y' => <y offset>, 'width' => <width>, 'height' => <height>, 00829 'pages', <'all'|'current'|odd|even>, (supported, current) 00830 'rgb', array( <r>, <g>, <b> ), 00831 'cmyk', array( <c>, <m>, <y>, <k> ), 00832 'rgbTop', array( <r>, <b>, <g> ), 00833 'rgbBottom', array( <r>, <b>, <g> ), 00834 'cmykTop', array( <c>, <m>, <y>, <k> ), 00835 'cmykBottom', array( <c>, <m>, <y>, <k> ) ) ) */ 00836 case 'filled_rectangle': 00837 { 00838 $operatorValue = ''; 00839 $options = $tpl->elementValue( $operatorParameters[1], $rootNamespace, $currentNamespace ); 00840 00841 if ( !isset( $options['pages'] ) ) 00842 { 00843 $options['pages'] = 'current'; 00844 } 00845 00846 if ( isset( $options['rgb'] ) ) 00847 { 00848 $options['rgb'] = eZMath::normalizeColorArray( $options['rgb'] ); 00849 $options['cmyk'] = eZMath::rgbToCMYK2( $options['rgb'][0]/255, 00850 $options['rgb'][1]/255, 00851 $options['rgb'][2]/255 ); 00852 } 00853 00854 if ( isset( $options['cmyk'] ) ) 00855 { 00856 $options['cmykTop'] = $options['cmyk']; 00857 $options['cmykBottom'] = $options['cmyk']; 00858 } 00859 00860 if ( !isset( $options['cmykTop'] ) ) 00861 { 00862 if ( isset( $options['rgbTop'] ) ) 00863 { 00864 $options['rgbTop'] = eZMath::normalizeColorArray( $options['rgbTop'] ); 00865 $options['cmykTop'] = eZMath::rgbToCMYK2( $options['rgbTop'][0]/255, 00866 $options['rgbTop'][1]/255, 00867 $options['rgbTop'][2]/255 ); 00868 } 00869 else 00870 { 00871 $options['cmykTop'] = eZMath::rgbToCMYK2( 0, 0, 0 ); 00872 } 00873 } 00874 00875 if ( !isset( $options['cmykBottom'] ) ) 00876 { 00877 if ( isset( $options['rgbBottom'] ) ) 00878 { 00879 $options['rgbBottom'] = eZMath::normalizeColorArray( $options['rgbBottom'] ); 00880 $options['cmykBottom'] = eZMath::rgbToCMYK2( $options['rgbBottom'][0]/255, 00881 $options['rgbBottom'][1]/255, 00882 $options['rgbBottom'][2]/255 ); 00883 } 00884 else 00885 { 00886 $options['cmykBottom'] = eZMath::rgbToCMYK2( 0, 0, 0 ); 00887 } 00888 } 00889 00890 if ( !isset( $options['pages'] ) ) 00891 { 00892 $options['pages'] = 'current'; 00893 } 00894 00895 $operatorValue = '<C:callFilledRectangle' . 00896 ':pages:' . $options['pages'] . 00897 ':x:' . $options['x'] . 00898 ':y:' . $options['y'] . 00899 ':width:' . $options['width'] . 00900 ':height:' . $options['height'] . 00901 ':cmykTop:' . implode( ',', $options['cmykTop'] ) . 00902 ':cmykBottom:' . implode( ',', $options['cmykBottom'] ) . 00903 '>'; 00904 00905 eZDebug::writeNotice( 'Added rectangle: ' . $operatorValue ); 00906 } break; 00907 00908 /* usage : pdf(text, <text>, array( 'font' => <fontname>, 'size' => <fontsize> )) */ 00909 case 'text': 00910 { 00911 $text = $tpl->elementValue( $operatorParameters[1], $rootNamespace, $currentNamespace ); 00912 00913 $operatorValue = ''; 00914 $changeFont = false; 00915 00916 if ( count( $operatorParameters ) >= 3) 00917 { 00918 $textSettings = $tpl->elementValue( $operatorParameters[2], $rootNamespace, $currentNamespace ); 00919 00920 if ( isset( $textSettings ) ) 00921 { 00922 $operatorValue .= '<ezCall:callText'; 00923 $changeFont = true; 00924 00925 if ( isset( $textSettings['font'] ) ) 00926 { 00927 $operatorValue .= ':font:'. $textSettings['font']; 00928 } 00929 00930 if ( isset( $textSettings['size'] ) ) 00931 { 00932 $operatorValue .= ':size:'. $textSettings['size']; 00933 } 00934 00935 if ( isset( $textSettings['align'] ) ) 00936 { 00937 $operatorValue .= ':justification:'. $textSettings['align']; 00938 } 00939 00940 if ( isset( $textSettings['rgb'] ) ) 00941 { 00942 $textSettings['cmyk'] = eZMath::rgbToCMYK2( $textSettings['rgb'][0]/255, 00943 $textSettings['rgb'][1]/255, 00944 $textSettings['rgb'][2]/255 ); 00945 } 00946 00947 if ( isset( $textSettings['cmyk'] ) ) 00948 { 00949 $operatorValue .= ':cmyk:' . implode( ',', $textSettings['cmyk'] ); 00950 } 00951 00952 $operatorValue .= '>'; 00953 } 00954 } 00955 00956 $operatorValue .= $text; 00957 if ( $changeFont ) 00958 { 00959 $operatorValue .= '</ezCall:callText>'; 00960 } 00961 00962 } break; 00963 00964 case 'text_box': 00965 { 00966 $parameters = $tpl->elementValue( $operatorParameters[1], $rootNamespace, $currentNamespace ); 00967 00968 $operatorValue = '<ezGroup:callTextBox'; 00969 00970 foreach( array_keys( $parameters ) as $key ) 00971 { 00972 if ( $key != 'text' ) 00973 { 00974 $operatorValue .= ':' . $key . ':' . urlencode( $parameters[$key] ); 00975 } 00976 } 00977 00978 $httpCharset = eZTextCodec::internalCharset(); 00979 $outputCharset = $config->hasVariable( 'PDFGeneral', 'OutputCharset' ) 00980 ? $config->variable( 'PDFGeneral', 'OutputCharset' ) 00981 : 'iso-8859-1'; 00982 $codec = eZTextCodec::instance( $httpCharset, $outputCharset ); 00983 // Convert current text to $outputCharset (by default iso-8859-1) 00984 $parameters['text'] = $codec->convertString( $parameters['text'] ); 00985 00986 $operatorValue .= '>'; 00987 $operatorValue .= urlencode( $parameters['text'] ); 00988 $operatorValue .= '</ezGroup:callTextBox>'; 00989 00990 return $operatorValue; 00991 } break; 00992 00993 case 'text_frame': 00994 { 00995 $text = $tpl->elementValue( $operatorParameters[1], $rootNamespace, $currentNamespace ); 00996 00997 $operatorValue = ''; 00998 $changeFont = false; 00999 01000 if ( count( $operatorParameters ) >= 3) 01001 { 01002 $textSettings = $tpl->elementValue( $operatorParameters[2], $rootNamespace, $currentNamespace ); 01003 01004 if ( isset( $textSettings ) ) 01005 { 01006 $operatorValue .= '<ezGroup:callTextFrame'; 01007 $changeFont = true; 01008 01009 foreach ( array_keys( $textSettings ) as $key ) //settings, padding (left, right, top, bottom), textcmyk, framecmyk 01010 { 01011 if ( $key == 'frameCMYK' ) 01012 { 01013 $operatorValue .= ':frameCMYK:' . implode( ',', $textSettings['frameCMYK'] ); 01014 } 01015 else if ( $key == 'frameRGB' ) 01016 { 01017 $operatorValue .= ':frameCMYK:' . implode( ',', eZMath::rgbToCMYK2( $textSettings['frameRGB'][0]/255, 01018 $textSettings['frameRGB'][1]/255, 01019 $textSettings['frameRGB'][2]/255 ) ); 01020 } 01021 else if ( $key == 'textCMYK' ) 01022 { 01023 $operatorValue .= ':textCMYK:' . implode( ',', $textSettings['textCMYK'] ); 01024 } 01025 else if ( $key == 'textRGB' ) 01026 { 01027 $operatorValue .= ':textCMYK:' . implode( ',', eZMath::rgbToCMYK2( $textSettings['textRGB'][0]/255, 01028 $textSettings['textRGB'][1]/255, 01029 $textSettings['textRGB'][2]/255 ) ); 01030 } 01031 else 01032 { 01033 $operatorValue .= ':' . $key . ':' . $textSettings[$key]; 01034 } 01035 } 01036 01037 $httpCharset = eZTextCodec::internalCharset(); 01038 $outputCharset = $config->hasVariable( 'PDFGeneral', 'OutputCharset' ) 01039 ? $config->variable( 'PDFGeneral', 'OutputCharset' ) 01040 : 'iso-8859-1'; 01041 $codec = eZTextCodec::instance( $httpCharset, $outputCharset ); 01042 // Convert current text to $outputCharset (by default iso-8859-1) 01043 $text = $codec->convertString( $text ); 01044 01045 $operatorValue .= '>' . urlencode( $text ) . '</ezGroup::callTextFrame>'; 01046 01047 } 01048 } 01049 01050 eZDebug::writeNotice( 'Added TextFrame: ' . $operatorValue ); 01051 } break; 01052 01053 default: 01054 { 01055 eZDebug::writeError( 'PDF operation "'. $namedParameters['operation'] .'" undefined', __METHOD__ ); 01056 } 01057 01058 } 01059 01060 } 01061 01062 /* 01063 \private 01064 Create PDF object 01065 */ 01066 function createPDF( $paper = 'a4', $orientation = 'portrait' ) 01067 { 01068 $this->PDF = new eZPDFTable( $paper, $orientation ); 01069 $this->PDF->selectFont( 'lib/ezpdf/classes/fonts/Helvetica' ); 01070 eZDebug::writeNotice( 'PDF: File created' ); 01071 } 01072 01073 /// The array of operators, used for registering operators 01074 public $Operators; 01075 public $PDF; 01076 public $Config; 01077 } 01078 01079 01080 ?>