Source for file PDFdefaultConverter.inc
Documentation is available at PDFdefaultConverter.inc
* Outputs documentation in PDF format
* phpDocumentor :: automatic documentation generator
* Copyright (c) 2002-2006 Gregory Beaver
* This library is free software; you can redistribute it
* and/or modify it under the terms of the GNU Lesser General
* Public License as published by the Free Software Foundation;
* either version 2.1 of the License, or (at your option) any
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
* @copyright 2002-2006 Gregory Beaver
* @license http://www.opensource.org/licenses/lgpl-license.php LGPL
* @version CVS: $Id: PDFdefaultConverter.inc 317560 2011-09-30 22:54:26Z ashnazg $
* @link http://www.phpdoc.org
* @link http://pear.php.net/PhpDocumentor
* The Cezpdf class library
include_once('phpDocumentor/Converters/PDF/default/class.phpdocpdf.php');
* This Converter takes output from the {@link Parser} and converts it to PDF-ready output for use with {@link Cezpdf}.
* @version $Id: PDFdefaultConverter.inc 317560 2011-09-30 22:54:26Z ashnazg $
* @todo Implement links to conflicts/inheritance
* default PDF Converter wants elements sorted by type as well as alphabetically
* @see Converter::$sort_page_contents_by_type
var $leftindex =
array('classes' =>
false, 'pages' =>
false, 'functions' =>
false, 'defines' =>
false, 'globals' =>
false);
/** @var string always PDF */
/** @var string always default */
* Source files for appendix C are stored here
* Format: array(array(package => packagename, code => array(highlightedsource code 1, ...)))
* @see Converter::Converter()
function PDFdefaultConverter(&$allp, &$packp, &$classes, &$procpages, $po, $pp, $qm, $targetDir, $templateDir, $title)
Converter::Converter($allp, $packp, $classes, $procpages, $po, $pp, $qm, $targetDir, $templateDir, $title);
// put a line top and bottom on all the pages
$this->pdf->ezSetMargins(50,70,50,50);
$this->pdf->ezText($template->fetch('footer.tpl'));
$template->assign('title',$title);
$this->pdf->ezText($template->fetch('title_page.tpl'));
$pathinfo =
$this->proceduralpages->getPathInfo($path, $this);
$templ->assign('source',$value);
$templ->assign('package',$pathinfo['package']);
$templ->assign('subpackage',$pathinfo['subpackage']);
$templ->assign('name',$pathinfo['name']);
$templ->assign('source_loc',$pathinfo['source_loc']);
$templ->assign('docs',$pathinfo['docs']);
$this->_sourcecode[$pathinfo['package']][] =
$templ->fetch('filesource.tpl');
$templ->assign('source',$source);
$templ->assign('title',$title);
$templ->assign('file',$path);
$this->pdf->ezText($templ->fetch('examplesource.tpl'));
// var_dump(htmlentities('<c:ilink:'.$this->getFileSourceName($path).'>Source Code for this file</c:ilink>'));
return '<c:ilink:'.
$this->getFileSourceName($path).
'>Source Code for this file</c:ilink>';
* Retrieve a Converter-specific anchor to a segment of a source code file
* parsed via a {@tutorial tags.filesource.pkg} tag.
* @param string full path to source file
* @param string name of anchor
* @param string link text, if this is a link
* @param boolean returns either a link or a destination based on this
* @return string link to an anchor, or the anchor
return '<c:ilink:' .
$this->getFileSourceName($sourcefile, $anchor).
'>' .
$text .
'</c:ilink>';
return '</text><pdffunction:addDestination arg="'.
$this->getFileSourceName($sourcefile, $anchor).
'" arg="FitH" arg=$this->y /><text size="8">';
* Returns a bookmark using Cezpdf 009
* @param abstractLink a descendant of abstractlink should be passed, and never text
* @param string text to display in the link
function returnSee(&$element, $eltext =
false)
if (!$element) return false;
$eltext =
$element->title;
$eltext .=
$element->class.
'::';
$eltext .=
$element->name;
if ($element->type ==
'function' ||
$element->type ==
'method') $eltext .=
'()';
return '<c:ilink:'.
urlencode($element->type.
$element->package.
$element->subpackage.
$element->name.
$element->section).
'>'.
$eltext.
'</c:ilink>';
return '<c:ilink:'.
urlencode($element->type.
$element->package.
$element->path).
'>'.
$eltext.
'</c:ilink>';
return '<c:ilink:'.
urlencode($element->type.
$element->package.
$element->name).
'>'.
$eltext.
'</c:ilink>';
return '<c:ilink:'.
urlencode($element->type.
$element->package.
$element->class.
'::'.
$element->name).
'>'.
$eltext.
'</c:ilink>';
* @return string <c:alink:$link>$text</c:alink>
return "<c:alink:$link>$text</c:alink>";
* Convert README/INSTALL/CHANGELOG file contents to output format
* @param README|INSTALL|CHANGELOG
* @param string contents of the file
if (!$element->docblock) return;
if ($element->type ==
'page' ||
$element->type ==
'class') $nopackage =
false;
$tagses =
$element->docblock->listTags();
$names =
array('staticvar' =>
'Static Variable','deprec' =>
'Deprecated','abstract' =>
'Abstract Element','todo' =>
'TODO');
$tags[] =
array('keyword' =>
'Package','data' =>
$element->docblock->package);
if (!empty($element->docblock->subpackage)) $tags[] =
array('keyword' =>
'Sub-Package','data' =>
$element->docblock->subpackage);
if ($element->docblock->var)
$a =
$element->docblock->var->Convert($this);
$tags[] =
array('keyword' =>
'Var', 'data' =>
$a);
if ($element->docblock->funcglobals)
foreach($element->docblock->funcglobals as $global =>
$val)
if ($a =
$this->getGlobalLink($global,$element->docblock->package))
$tags[] =
array('keyword' =>
'Global Variable Used','data' =>
$val[0].
' '.
$global.
': '.
$val[1]->Convert($this));
if ($element->docblock->statics)
foreach($element->docblock->statics as $static =>
$val)
$a =
$val->Convert($this);
$tags[] =
array('keyword' =>
'Static Variable Used','data' =>
$val->converted_returnType.
' '.
$static.
': '.
$a);
if ($element->docblock->properties)
foreach($element->docblock->properties as $property =>
$val)
$a =
$val->Convert($this);
$tags[] =
array('keyword' =>
ucfirst($val->keyword),'data' =>
$val->converted_returnType.
' '.
$property.
': '.
$a);
if (isset
($names[$tag->keyword])) $tag->keyword =
$names[$tag->keyword];
$tags[] =
array("keyword" =>
ucfirst($tag->keyword),"data" =>
$tag->Convert($this));
foreach($element->docblock->unknown_tags as $keyword =>
$t)
$utags[] =
array('keyword' =>
$keyword, 'data' =>
$tag->Convert($this));
if ($element->type ==
'packagepage') return;
$sdesc =
$element->docblock->getSDesc($this);
$desc =
$element->docblock->getDesc($this);
$template->assign('utags',$utags);
$template->assign('tags',$tags);
$template->assign('sdesc',$sdesc);
$template->assign('desc',$desc);
if (false) // $element->type != 'page')
if ($element->type !=
'var' &&
$element->type !=
'method')
$this->pdf->addDestination(urlencode($element->type.
$element->docblock->package.
$element->name),'FitH',$this->pdf->y);
$this->pdf->addDestination(urlencode($element->type.
$element->docblock->package.
$element->class.
'::'.
$element->name),'FitH',$this->pdf->y);
$this->pdf->addDestination(urlencode('page'.
$element->parent->package.
$element->parent->getPath()),'FitH',$this->pdf->y);
$this->pdf->ezText($template->fetch('docblock.tpl'));
if ($element->type !=
'function' &&
$element->type !=
'method') return;
if (count($element->docblock->params))
if (count($element->docblock->params))
foreach($element->docblock->params as $param =>
$val)
$a =
$val->Convert($this);
$params[] =
array("name" =>
$param,"type" =>
$val->converted_returnType,"description" =>
$a);
$template->assign('params',$params);
$this->pdf->ezText($template->fetch('params.tpl'));
if ($element->docblock->sdesc)
$sdesc =
$element->docblock->sdesc->Convert($this);
$template->assign('linenumber',$element->getLineNumber());
$template->assign('slink',$this->getSourceAnchor($element->getPath(),$element->getLineNumber(),$element->getLineNumber(),true));
$template->assign('slink', false);
$template->assign('dest', urlencode($element->type.
$element->docblock->package.
$element->name));
$template->assign('type',$element->getDataType($this));
$template->assign('name',$element->name);
$template->assign('value',$this->getGlobalValue($element->getValue()));
$template->assign('sdesc',$sdesc);
$this->pdf->ezText($template->fetch('global.tpl'));
if ($element->docblock->sdesc)
$sdesc =
$element->docblock->sdesc->Convert($this);
if (count($element->docblock->params))
foreach($element->docblock->params as $param =>
$val)
$a =
$val->Convert($this);
$params[$param] =
array("var" =>
$param,"datatype" =>
$val->converted_returnType,"data" =>
$a);
if ($element->docblock->return)
if (!$element->docblock->return->returnType) $element->docblock->return->returnType =
'void';
$template->assign('class',$this->class);
$template->assign('constructor',$element->isConstructor);
$template->assign('dest', urlencode($element->type.
$element->docblock->package.
$element->class.
'::'.
$element->name));
$template->assign('linenumber',$element->getLineNumber());
$template->assign('slink',$this->getSourceAnchor($element->getPath(),$element->getLineNumber(),$element->getLineNumber(),true));
$template->assign('slink',false);
if ($element->docblock->return)
$ret =
$element->docblock->return->returnType;
$template->assign('return',$ret);
$template->assign('functioncall',$element->getFunctionCall());
$template->assign('intricatefunctioncall',$element->getIntricateFunctionCall($this,$params));
$template->assign('sdesc',$sdesc);
$this->pdf->ezText($template->fetch('method.tpl'));
if ($element->docblock->sdesc)
$sdesc =
$element->docblock->sdesc->Convert($this);
$template->assign('class',$this->class);
$template->assign('linenumber',$element->getLineNumber());
$template->assign('slink',$this->getSourceAnchor($element->getPath(),$element->getLineNumber(),$element->getLineNumber(),true));
$template->assign('slink',false);
$template->assign('type',$element->docblock->var->returnType);
$template->assign('name',$element->name);
$template->assign('dest', urlencode($element->type.
$element->docblock->package.
$element->class.
'::'.
$element->name));
$template->assign('value',$element->value);
$template->assign('sdesc',$sdesc);
$this->pdf->ezText($template->fetch('var.tpl'));
if ($element->docblock->sdesc)
$sdesc =
$element->docblock->sdesc->Convert($this);
$template->assign('class',$this->class);
$template->assign('linenumber',$element->getLineNumber());
$template->assign('slink',$this->getSourceAnchor($element->getPath(),$element->getLineNumber(),$element->getLineNumber(),true));
$template->assign('slink',false);
$template->assign('name',$element->name);
$template->assign('dest', urlencode($element->type.
$element->docblock->package.
$element->class.
'::'.
$element->name));
$template->assign('value',$element->value);
$template->assign('sdesc',$sdesc);
$this->pdf->ezText($template->fetch('const.tpl'));
$template->assign('includeheader',true);
if (isset
($this->package_pages[$element->docblock->package]))
$template->assign('ppage',$this->package_pages[$element->docblock->package]);
$template->assign('isclass',true);
unset
($this->package_pages[$element->docblock->package]);
$template->assign('classeslink',rawurlencode("Package ".
$element->docblock->package.
" Classes"));
if ($element->docblock->sdesc)
$sdesc =
$element->docblock->sdesc->Convert($this);
$template->assign('dest', urlencode($element->type.
$element->docblock->package.
$element->name));
$template->assign('package',$element->docblock->package);
$template->assign('linenumber',$element->getLineNumber());
$template->assign('slink',$this->getSourceAnchor($element->getPath(),$element->getLineNumber(),$element->getLineNumber(),true));
$template->assign('slink',false);
$template->assign('name',$element->name);
$template->assign('sdesc',$sdesc);
$this->pdf->ezText($template->fetch('class.tpl'));
$template->assign('linenumber',$element->getLineNumber());
$template->assign('slink',$this->getSourceAnchor($element->getPath(),$element->getLineNumber(),$element->getLineNumber(),true));
$template->assign('slink',false);
$template->assign('name',$element->name);
$template->assign('value',$this->getIncludeValue($element->getValue(), $element->getPath()));
$this->pdf->ezText($template->fetch('include.tpl'));
if ($element->docblock->sdesc)
$sdesc =
$element->docblock->sdesc->Convert($this);
if (count($element->docblock->params))
foreach($element->docblock->params as $param =>
$val)
$a =
$val->Convert($this);
$params[$param] =
array("var" =>
$param,"datatype" =>
$val->converted_returnType,"data" =>
$a);
if (!$element->docblock->return)
$element->docblock->return->returnType =
'void';
$template->assign('dest', urlencode($element->type.
$element->docblock->package.
$element->name));
$template->assign('linenumber',$element->getLineNumber());
$template->assign('slink',$this->getSourceAnchor($element->getPath(),$element->getLineNumber(),$element->getLineNumber(),true));
$template->assign('slink',false);
$template->assign('return',$element->docblock->return->returnType);
$template->assign('functioncall',$element->getFunctionCall());
$template->assign('intricatefunctioncall',$element->getIntricateFunctionCall($this,$params));
$template->assign('sdesc',$sdesc);
$this->pdf->ezText($template->fetch('function.tpl'));
if ($element->docblock->sdesc)
$sdesc =
$element->docblock->sdesc->Convert($this);
$template->assign('linenumber',$element->getLineNumber());
$template->assign('slink',$this->getSourceAnchor($element->getPath(),$element->getLineNumber(),$element->getLineNumber(),true));
$template->assign('slink',false);
$template->assign('name',$element->name);
$template->assign('dest', urlencode($element->type.
$element->docblock->package.
$element->name));
$template->assign('value',$element->value);
$template->assign('sdesc',$sdesc);
$this->pdf->ezText($template->fetch('define.tpl'));
$template->assign('includeheader',false);
if ($element->docblock->sdesc)
$sdesc =
$element->docblock->sdesc->Convert($this);
if (count($element->elements) ||
($sdesc) ||
count($element->docblock->tags))
$template->assign('includeheader',true);
if (isset
($this->package_pages[$element->parent->package]))
$template->assign('ppage',$this->package_pages[$element->parent->package]);
unset
($this->package_pages[$element->parent->package]);
$template->assign('dest', urlencode('page'.
$element->parent->package.
$element->parent->getPath()));
$template->assign('sdesc',$sdesc);
$template->assign('package',$element->parent->package);
$template->assign('name',$element->parent->file);
$this->pdf->ezText($template->fetch('page.tpl'));
* Used to translate an XML DocBook tag from a tutorial by reading the
* options.ini file for the template.
* @param string any attributes Format: array(name => value)
* @param string the tag contents, if any
* @param string the tag contents, if any, unpost-processed
if ($name ==
'example' &&
@$attr['role'] ==
'html')
if ($name ==
'programlisting' &&
@$attr['role'] ==
'php')
$a =
parent::TranslateTag($name, $attr, $cdata, $unconvertedcdata);
// var_dump(htmlspecialchars($cdata), htmlspecialchars($unconvertedcdata), htmlspecialchars($a));
return parent::TranslateTag($name, $attr, $cdata, $unconvertedcdata);
return $element->parent->getName();
return 'tutorial'.
$package.
$subpackage.
$tutorial.
$id;
return str_replace(array('<c:','<C:'),array("<c:","<C:"),$value);
* @deprecated html package pages just don't work with PDF, use {@tutorial tutorials.pkg}
$x =
$element->Convert($this);
$x =
$element->Convert($this, true);
$template->assign('package',$element->package);
$template->assign('subpackage',$element->subpackage);
$template->assign('contents',$x);
$template->assign('title',$element->getTitle($this));
$template->assign('child',$element->parent);
if (isset
($element->parent->parent)) $template->assign('hasparent',$element->parent->parent);
$template->assign('element',$element);
$this->pdf->ezText($template->fetch('tutorial.tpl'));
* returns a template-enabled array of class trees
* @param string $package package to generate a class tree for
* @see $roots, getRootTree()
if (!isset
($this->roots[$package])) return array();
$roots =
$trees =
array();
$roots =
$this->roots[$package];
for($i=
0;$i<
count($roots);$i++
)
* return formatted class tree for the Class Trees page
* @param array $tree output from {@link getSortedClassTreeFromClass()}
* @see Classes::$definitechild, generateFormattedClassTrees()
if (isset
($tree[$cur]['parent']) &&
$tree[$cur]['parent'])
// debug("parent ".$tree[$cur]['parent']." not found");
$my_tree .=
'<li>' .
$tree[$cur]['parent'] .
'<ul>';
// debug("parent ".$this->returnSee($tree[$cur]['parent'], false, false)." in other package");
$my_tree .=
'<li>' .
$this->returnSee($tree[$cur]['parent'], false, false);
if ($tree[$cur]['parent']->package !=
$package) $my_tree .=
' <b>(Different package)</b><ul>';
// fancy_debug($cur,$lastcur,$kids);
if (count($tree[$cur]['children']))
// debug("$cur has children");
// debug("set $cur kids");
$my_tree .=
'<li>'.
$this->returnSee($tree[$cur]['link'], false, false);
list
(,$cur) =
each($tree[$cur]['children']);
// var_dump('listed',$cur);
$cur =
$cur['package'] .
'#' .
$cur['class'];
// debug("set cur to child $cur");
// $my_tree .= '<li>'.$this->returnSee($tree[$cur]['link'], false, false);
// debug("end of children for $cur");
$cur =
array_pop($lastcur); // will fall into infinite loop if this second array_pop() is removed
$my_tree .=
'</ul></li>'.
"\n";
// debug("$cur has no children");
$my_tree .=
'<li>'.
$this->returnSee($tree[$cur]['link'], false, false).
"</li>";
$my_tree .=
'</ul></li>'.
"\n";
* calls {@link Cezpdf::ezOutput()} and writes documentation.pdf to targetDir
function Output($title =
'Generated Documentation')
$this->pdf->ezText($template->fetch('appendix_title_page.tpl'));
$a['package'] =
$package;
$template->assign('trees',$trees);
$this->pdf->ezText($template->fetch('classtree.tpl'));
$this->pdf->ezText($template->fetch('ric_title_page.tpl'));
foreach($this->ric_set as $name =>
$contents)
$template->assign('contents',$contents);
$template->assign('name',$name);
$this->pdf->ezText($template->fetch('ric.tpl'));
$this->pdf->ezText($template->fetch('source_title_page.tpl'));
$this->pdf->ezText($template->fetch('source_loop.tpl'));
foreach($this->todoList as $package =>
$alltodos)
foreach($alltodos as $todos)
$converted['link'] =
$this->returnSee($todos[0]);
$converted['todos'][] =
$todos[1]->Convert($this);
foreach($todos[1] as $todo)
$converted['todos'][] =
$todo->Convert($this);
$todolist[$package][] =
$converted;
$template->assign('todos',$todolist);
$this->pdf->ezText($template->fetch('todolist.tpl'));
$fp =
@fopen("C:/Documents and Settings/Owner/Desktop/pdfsourceorig.txt",'w');
$a =
$this->pdf->ezOutput(true); // debug
$template->assign('contents',$this->pdf->reportContents);
$this->pdf->ezText($template->fetch('toc.tpl'));
$x =
$this->pdf->ezOutput(false, $template);
$this->writeFile("documentation.pdf", $x, true);
* @param string name of class
* @param string package name
* @param string full path to look in (used in index generation)
* @return mixed false if not found, or an html a link to the class's documentation
* @see parent::getClassLink()
function getClassLink($expr,$package, $file =
false,$text =
false)
* @param string name of function
* @param string package name
* @param string full path to look in (used in index generation)
* @param boolean deprecated
* @return mixed false if not found, or an html a link to the function's documentation
* @see parent::getFunctionLink()
* @param string name of define
* @param string package name
* @param string full path to look in (used in index generation)
* @param boolean deprecated
* @return mixed false if not found, or an html a link to the define's documentation
* @see parent::getDefineLink()
function getDefineLink($expr,$package, $file =
false,$text =
false)
* @param string name of global variable
* @param string package name
* @param string full path to look in (used in index generation)
* @param boolean deprecated
* @return mixed false if not found, or an html a link to the global variable's documentation
* @see parent::getGlobalLink()
function getGlobalLink($expr,$package, $file =
false,$text =
false)
* @param string name of procedural page
* @param string package name
* @param string full path to look in (used in index generation)
* @param boolean deprecated
* @return mixed false if not found, or an html a link to the procedural page's documentation
* @see parent::getPageLink()
function getPageLink($expr,$package, $path =
false,$text =
false)
* @param string name of method
* @param string class containing method
* @param string package name
* @param string full path to look in (used in index generation)
* @param boolean deprecated
* @return mixed false if not found, or an html a link to the method's documentation
* @see parent::getMethodLink()
function getMethodLink($expr,$class,$package, $file =
false,$text =
false)
* @param string name of var
* @param string class containing var
* @param string package name
* @param string full path to look in (used in index generation)
* @param boolean deprecated
* @param boolean return just the URL, or enclose it in an html a tag
* @return mixed false if not found, or an html a link to the var's documentation
* @see parent::getVarLink()
function getVarLink($expr,$class,$package, $file =
false,$text =
false)
* @param string name of class constant
* @param string class containing class constant
* @param string package name
* @param string full path to look in (used in index generation)
* @param boolean deprecated
* @param boolean return just the URL, or enclose it in an html a tag
* @return mixed false if not found, or an html a link to the var's documentation
* @see parent::getConstLink()
function getConstLink($expr,$class,$package, $file =
false,$text =
false)
/** @return 1 always the same */
* @see parent::unmangle()
// $source = str_replace("\n","<mybr>",$source);
Documentation generated on Mon, 05 Dec 2011 21:40:16 -0600 by phpDocumentor 1.4.4