Converters
[ class tree: Converters ] [ index: Converters ] [ all elements ]

Source for file PDFdefaultConverter.inc

Documentation is available at PDFdefaultConverter.inc

  1. <?php
  2. /**
  3.  * Outputs documentation in PDF format
  4.  *
  5.  * phpDocumentor :: automatic documentation generator
  6.  * 
  7.  * PHP versions 4 and 5
  8.  *
  9.  * Copyright (c) 2002-2006 Gregory Beaver
  10.  * 
  11.  * LICENSE:
  12.  * 
  13.  * This library is free software; you can redistribute it
  14.  * and/or modify it under the terms of the GNU Lesser General
  15.  * Public License as published by the Free Software Foundation;
  16.  * either version 2.1 of the License, or (at your option) any
  17.  * later version.
  18.  * 
  19.  * This library is distributed in the hope that it will be useful,
  20.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  21.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  22.  * Lesser General Public License for more details.
  23.  * 
  24.  * You should have received a copy of the GNU Lesser General Public
  25.  * License along with this library; if not, write to the Free Software
  26.  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  27.  *
  28.  * @package    Converters
  29.  * @subpackage PDFdefault
  30.  * @author     Greg Beaver <cellog@php.net>
  31.  * @copyright  2002-2006 Gregory Beaver
  32.  * @license    http://www.opensource.org/licenses/lgpl-license.php LGPL
  33.  * @version    CVS: $Id: PDFdefaultConverter.inc,v 1.7 2007/05/31 02:02:42 ashnazg Exp $
  34.  * @filesource
  35.  * @link       http://www.phpdoc.org
  36.  * @link       http://pear.php.net/PhpDocumentor
  37.  * @since      1.2
  38.  */
  39. /**
  40.  * The Cezpdf class library
  41.  */
  42. include_once('phpDocumentor/Converters/PDF/default/class.phpdocpdf.php');
  43. /**
  44.  * PDF output converter.
  45.  * This Converter takes output from the {@link Parser} and converts it to PDF-ready output for use with {@link Cezpdf}.
  46.  * This is now beta code
  47.  *
  48.  * @package Converters
  49.  * @subpackage PDFdefault
  50.  * @author Greg Beaver <cellog@php.net>
  51.  * @since 1.1
  52.  * @version $Id: PDFdefaultConverter.inc,v 1.7 2007/05/31 02:02:42 ashnazg Exp $
  53.  * @todo Implement links to conflicts/inheritance
  54.  */
  55. {
  56.     /**
  57.      * default PDF Converter wants elements sorted by type as well as alphabetically
  58.      * @see Converter::$sort_page_contents_by_type
  59.      * @var boolean 
  60.      */
  61.     var $sort_absolutely_everything = true;
  62.     var $leftindex = array('classes' => false'pages' => false'functions' => false'defines' => false'globals' => false);
  63.     var $pagepackage_pagenums = array();
  64.     var $classpackage_pagenums = array();
  65.     /** @var string always PDF */
  66.     var $outputformat = 'PDF';
  67.     /** @var string always default */
  68.     var $name = 'default';
  69.     var $curpagepackage = false;
  70.     var $curclasspackage = false;
  71.     var $smarty_dir;
  72.     /**
  73.      * @var Cezpdf 
  74.      */
  75.     var $pdf = false;
  76.     var $ric_set = array();
  77.     /**
  78.      * Source files for appendix C are stored here
  79.      *
  80.      * Format: array(array(package => packagename, code => array(highlightedsource code 1, ...)))
  81.      * @var array 
  82.      */
  83.     var $_sourcecode;
  84.     /**
  85.      * @see Converter::Converter()
  86.      */
  87.     function PDFdefaultConverter(&$allp&$packp&$classes&$procpages$po$pp$qm$targetDir$templateDir$title)
  88.     {
  89.         Converter::Converter($allp$packp$classes$procpages$po$pp$qm$targetDir$templateDir$title);
  90.         $this->pdf =new phpdocpdf($this$this->getConverterDir(PATH_DELIMITER .'templates/fonts/','letter');
  91.         $this->pdf->selectFont($this->getConverterDir(PATH_DELIMITER .'templates/fonts/Helvetica.afm');
  92. // put a line top and bottom on all the pages
  93.         $this->pdf->ezSetMargins(50,70,50,50);
  94.         $template &$this->newSmarty();
  95.         $this->pdf->ezText($template->fetch('footer.tpl'));
  96.         $template->assign('title',$title);
  97.         if (file_exists($this->templateDir . 'templates' PATH_DELIMITER 'media'PATH_DELIMITER .'logo.jpg'))
  98.         {
  99.             $template->assign('logo',$this->templateDir . 'templates' PATH_DELIMITER 'media'PATH_DELIMITER .'logo.jpg');
  100.         }
  101.         $this->pdf->ezText($template->fetch('title_page.tpl'));
  102.         unset($template);
  103.     }
  104.     
  105.     function writeSource($path$value)
  106.     {
  107.         $templ &$this->newSmarty();
  108.         $pathinfo $this->proceduralpages->getPathInfo($path$this);
  109.         $templ->assign('source',$value);
  110.         $templ->assign('package',$pathinfo['package']);
  111.         $templ->assign('subpackage',$pathinfo['subpackage']);
  112.         $templ->assign('name',$pathinfo['name']);
  113.         $templ->assign('source_loc',$pathinfo['source_loc']);
  114.         $templ->assign('docs',$pathinfo['docs']);
  115.         $templ->assign('dest'$this->getFileSourceName($path));
  116.         $this->setSourcePaths($path);
  117.         $this->_sourcecode[$pathinfo['package']][$templ->fetch('filesource.tpl');
  118.     }
  119.     
  120.     function postProcess($text)
  121.     {
  122.         return htmlspecialchars($text);
  123.     }
  124.     
  125.     function writeExample($title$path$source)
  126.     {
  127.         $templ &$this->newSmarty();
  128.         $templ->assign('source',$source);
  129.         if (empty($title))
  130.         {
  131.             $title 'example';
  132.             addWarning(PDERROR_EMPTY_EXAMPLE_TITLE$path$title);
  133.         }
  134.         $templ->assign('title',$title);
  135.         $templ->assign('file',$path);
  136.         $this->pdf->ezText($templ->fetch('examplesource.tpl'));
  137.     }
  138.     
  139.     function getExampleLink($path$title)
  140.     {
  141.         return '';
  142.         return $this->returnLink('../__examplesource' PATH_DELIMITER 'exsource_'.$path.'.html',$title);
  143.     }
  144.     
  145.     function getSourceLink($path)
  146.     {
  147. //        var_dump(htmlentities('<c:ilink:'.$this->getFileSourceName($path).'>Source Code for this file</c:ilink>'));
  148.         return '<c:ilink:'.$this->getFileSourceName($path).'>Source Code for this file</c:ilink>';
  149.     }
  150.     
  151.     function getFileSourceName($path$anchor '')
  152.     {
  153.         return urlencode($anchor parent::getFileSourceName($path));
  154.     }
  155.     
  156.     /**
  157.      * Retrieve a Converter-specific anchor to a segment of a source code file
  158.      * parsed via a {@tutorial tags.filesource.pkg} tag.
  159.      * @param string full path to source file
  160.      * @param string name of anchor
  161.      * @param string link text, if this is a link
  162.      * @param boolean returns either a link or a destination based on this
  163.      *                 parameter
  164.      * @return string link to an anchor, or the anchor
  165.      */
  166.     function getSourceAnchor($sourcefile,$anchor,$text '',$link false)
  167.     {
  168.         if ($link)
  169.         {
  170.             return '<c:ilink:' $this->getFileSourceName($sourcefile$anchor)'>' $text '</c:ilink>';
  171.         else
  172.         {
  173.             return '</text><pdffunction:addDestination arg="'.$this->getFileSourceName($sourcefile$anchor).'" arg="FitH" arg=$this->y /><text size="8">';
  174.         }
  175.     }
  176.     
  177.     /**
  178.      * Returns a bookmark using Cezpdf 009
  179.      *
  180.      * @param abstractLink a descendant of abstractlink should be passed, and never text
  181.      * @param string text to display in the link
  182.      */
  183.     function returnSee(&$element$eltext false)
  184.     {
  185.         if (!$elementreturn false;
  186.         if (!$eltext)
  187.         {
  188.             $eltext '';
  189.             switch($element->type)
  190.             {
  191.                 case 'tutorial' :
  192.                 $eltext $element->title;
  193.                 break;
  194.                 case 'method' :
  195.                 case 'var' :
  196.                 case 'const' :
  197.                 $eltext .= $element->class.'::';
  198.                 case 'page' :
  199.                 case 'define' :
  200.                 case 'class' :
  201.                 case 'function' :
  202.                 case 'global' :
  203.                 default :
  204.                 $eltext .= $element->name;
  205.                 if ($element->type == 'function' || $element->type == 'method'$eltext .= '()';
  206.                 break;
  207.             }
  208.         }
  209.         switch ($element->type)
  210.         {
  211.             case 'tutorial' :
  212.             return '<c:ilink:'.urlencode($element->type.$element->package.$element->subpackage.$element->name.$element->section).'>'.$eltext.'</c:ilink>';
  213.             case 'page' :
  214.             return '<c:ilink:'.urlencode($element->type.$element->package.$element->path).'>'.$eltext.'</c:ilink>';
  215.             case 'define' :
  216.             case 'global' :
  217.             case 'class' :
  218.             case 'function' :
  219.             return '<c:ilink:'.urlencode($element->type.$element->package.$element->name).'>'.$eltext.'</c:ilink>';
  220.             case 'method' :
  221.             case 'var' :
  222.             case 'const' :
  223.             return '<c:ilink:'.urlencode($element->type.$element->package.$element->class.'::'.$element->name).'>'.$eltext.'</c:ilink>';
  224.         }
  225.         return $element;
  226.     }
  227.     
  228.     /**
  229.      * @param string 
  230.      * @param string 
  231.      * @return string <c:alink:$link>$text</c:alink>
  232.      */
  233.     function returnLink($link,$text)
  234.     {
  235.         return "<c:alink:$link>$text</c:alink>";
  236.     }
  237.     
  238.     /**
  239.      * Convert README/INSTALL/CHANGELOG file contents to output format
  240.      * @param README|INSTALL|CHANGELOG
  241.      * @param string contents of the file
  242.      */
  243.     function Convert_RIC($name$contents)
  244.     {
  245.         $this->ric_set[$name$contents;
  246.     }
  247.  
  248.     function convertDocBlock(&$element)
  249.     {
  250.         if (!$element->docblockreturn;
  251.         $template &$this->newSmarty();
  252.         
  253.         $nopackage true;
  254.         if ($element->type == 'page' || $element->type == 'class'$nopackage false;
  255.         $tagses $element->docblock->listTags();
  256.         $tags array();
  257.         $names array('staticvar' => 'Static Variable','deprec' => 'Deprecated','abstract' => 'Abstract Element','todo' => 'TODO');
  258.         if (!$nopackage)
  259.         {
  260.             $tags[array('keyword' => 'Package','data' => $element->docblock->package);
  261.             if (!empty($element->docblock->subpackage)) $tags[array('keyword' => 'Sub-Package','data' => $element->docblock->subpackage);
  262.         }
  263.         if ($element->docblock->var)
  264.         {
  265.             $a $element->docblock->var->Convert($this);
  266.             if (!empty($a))
  267.             $tags[array('keyword' => 'Var''data' => $a);
  268.         }
  269.         if ($element->docblock->funcglobals)
  270.         foreach($element->docblock->funcglobals as $global => $val)
  271.         {
  272.             if ($a $this->getGlobalLink($global,$element->docblock->package))
  273.             {
  274.                 $global $a;
  275.             }
  276.             $b Converter::getLink($val[0]);
  277.             if (is_object($b&& phpDocumentor_get_class($b== 'classlink')
  278.             {
  279.                 $val[0$this->returnSee($b);
  280.             }
  281.             $tags[array('keyword' => 'Global Variable Used','data' => $val[0].' '.$global.': '.$val[1]->Convert($this));
  282.         }
  283.         if ($element->docblock->statics)
  284.         foreach($element->docblock->statics as $static => $val)
  285.         {
  286.             $a $val->Convert($this);
  287.             $tags[array('keyword' => 'Static Variable Used','data' => $val->converted_returnType.' '.$static.': '.$a);
  288.         }
  289.         if ($element->docblock->properties)
  290.         foreach($element->docblock->properties as $property => $val)
  291.         {
  292.             $a $val->Convert($this);
  293.             $tags[array('keyword' => ucfirst($val->keyword),'data' => $val->converted_returnType.' '.$property.': '.$a);
  294.         }
  295.         foreach($tagses as $tag)
  296.         {
  297.             if (isset($names[$tag->keyword])) $tag->keyword $names[$tag->keyword];
  298.             $tags[array("keyword" => ucfirst($tag->keyword),"data" => $tag->Convert($this));
  299.         }
  300.         $utags array();
  301.         foreach($element->docblock->unknown_tags as $keyword => $t)
  302.         {
  303.             foreach($t as $tag)
  304.             $utags[array('keyword' => $keyword'data' => $tag->Convert($this));
  305.         }
  306.         if ($element->type == 'packagepage'return;
  307.         $sdesc $element->docblock->getSDesc($this);
  308.         $desc $element->docblock->getDesc($this);
  309.         $template->assign('utags',$utags);
  310.         $template->assign('tags',$tags);
  311.         $template->assign('sdesc',$sdesc);
  312.         $template->assign('desc',$desc);
  313.         if (false// $element->type != 'page')
  314.         {
  315.             if ($element->type != 'var' && $element->type != 'method')
  316.             {
  317.                 $this->pdf->addDestination(urlencode($element->type.$element->docblock->package.$element->name),'FitH',$this->pdf->y);
  318.             else
  319.             {
  320.                 $this->pdf->addDestination(urlencode($element->type.$element->docblock->package.$element->class.'::'.$element->name),'FitH',$this->pdf->y);
  321.             }
  322.         elseif (false)
  323.         {
  324.             $this->pdf->addDestination(urlencode('page'.$element->parent->package.$element->parent->getPath()),'FitH',$this->pdf->y);
  325.         }
  326.         $this->convertParams($element);
  327.         $this->pdf->ezText($template->fetch('docblock.tpl'));
  328.     }
  329.     
  330.     function convertParams(&$element)
  331.     {
  332.         if ($element->type != 'function' && $element->type != 'method'return;
  333.         if (count($element->docblock->params))
  334.         {
  335.             $template &$this->newSmarty();
  336.             $params array();
  337.             if (count($element->docblock->params))
  338.             foreach($element->docblock->params as $param => $val)
  339.             {
  340.                 $a $val->Convert($this);
  341.                 $params[array("name" => $param,"type" => $val->converted_returnType,"description" => $a);
  342.             }
  343.             $template->assign('params',$params);
  344.             $this->pdf->ezText($template->fetch('params.tpl'));
  345.         }
  346.     }
  347.     
  348.     function convertGlobal(&$element)
  349.     {
  350.         $sdesc '';
  351.         if ($element->docblock->sdesc)
  352.         {
  353.             $sdesc $element->docblock->sdesc->Convert($this);
  354.         }
  355.         $template &$this->newSmarty();
  356.         $template->assign('linenumber',$element->getLineNumber());
  357.         if ($this->hasSourceCode($element->getPath()))
  358.         $template->assign('slink',$this->getSourceAnchor($element->getPath(),$element->getLineNumber(),$element->getLineNumber(),true));
  359.         else
  360.         $template->assign('slink'false);
  361.         $template->assign('dest'urlencode($element->type.$element->docblock->package.$element->name));
  362.         $template->assign('type',$element->getDataType($this));
  363.         $template->assign('name',$element->name);
  364.         $template->assign('value',$this->getGlobalValue($element->getValue()));
  365.         $template->assign('sdesc',$sdesc);
  366.         $this->pdf->ezText($template->fetch('global.tpl'));
  367.         $this->convertDocBlock($element);
  368.     }
  369.     
  370.     function getGlobalValue($value)
  371.     {
  372.         return parent::getGlobalValue(htmlspecialchars($value));
  373.     }
  374.     
  375.     function convertMethod(&$element)
  376.     {
  377.         $sdesc '';
  378.         if ($element->docblock->sdesc)
  379.         {
  380.             $sdesc $element->docblock->sdesc->Convert($this);
  381.         }
  382.         $params array();
  383.         if (count($element->docblock->params))
  384.         foreach($element->docblock->params as $param => $val)
  385.         {
  386.             $a $val->Convert($this);
  387.             $params[$paramarray("var" => $param,"datatype" => $val->converted_returnType,"data" => $a);
  388.         }
  389.         if ($element->docblock->return)
  390.         {
  391.             if (!$element->docblock->return->returnType$element->docblock->return->returnType 'void';
  392.         }
  393.         $template &$this->newSmarty();
  394.         $template->assign('class',$this->class);
  395.         $template->assign('constructor',$element->isConstructor);
  396.         $template->assign('dest'urlencode($element->type.$element->docblock->package.$element->class.'::'.$element->name));
  397.         $template->assign('linenumber',$element->getLineNumber());
  398.         if ($this->hasSourceCode($element->getPath()))
  399.         $template->assign('slink',$this->getSourceAnchor($element->getPath(),$element->getLineNumber(),$element->getLineNumber(),true));
  400.         else
  401.         $template->assign('slink',false