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