From 98dbe6f0d2edfff3a1f5785504504b4a6e5dd4eb Mon Sep 17 00:00:00 2001 From: "ctrlaltca@gmail.com" <> Date: Sat, 19 Nov 2011 11:33:31 +0000 Subject: updating phpDocumentor, part 2: add new version --- .../Converters/PDF/default/class.phpdocpdf.php | 353 +++++++++++++++++++++ 1 file changed, 353 insertions(+) create mode 100755 buildscripts/PhpDocumentor/phpDocumentor/Converters/PDF/default/class.phpdocpdf.php (limited to 'buildscripts/PhpDocumentor/phpDocumentor/Converters/PDF/default/class.phpdocpdf.php') diff --git a/buildscripts/PhpDocumentor/phpDocumentor/Converters/PDF/default/class.phpdocpdf.php b/buildscripts/PhpDocumentor/phpDocumentor/Converters/PDF/default/class.phpdocpdf.php new file mode 100755 index 00000000..ea3b2fdf --- /dev/null +++ b/buildscripts/PhpDocumentor/phpDocumentor/Converters/PDF/default/class.phpdocpdf.php @@ -0,0 +1,353 @@ + + * @copyright 2000-2006 Joshua Eichorn, Gregory Beaver + * @license http://www.opensource.org/licenses/lgpl-license.php LGPL + * @version CVS: $Id: class.phpdocpdf.php 212211 2006-04-30 22:18:14Z cellog $ + * @filesource + * @link http://www.phpdoc.org + * @link http://pear.php.net/PhpDocumentor + * @since 1.2 + */ + +/** ezPdf libraries */ +include_once 'phpDocumentor/Converters/PDF/default/class.ezpdf.php'; +include_once 'phpDocumentor/Converters/PDF/default/ParserPDF.inc'; + +// define a class extension to allow the use of a callback to get the table of +// contents, and to put the dots in the toc +/** + * @package Converters + * @subpackage PDFdefault + */ +class phpdocpdf extends Cezpdf +{ + var $reportContents = array(); + var $indexContents = array(); + var $indents = array(); + var $font_dir = false; + var $set_pageNumbering = false; + var $converter; + var $_save = ''; + var $listType = 'ordered'; + var $_colorStack = array(); + + function phpdocpdf(&$pdfconverter,$fontdir,$paper='a4',$orientation='portrait') + { + Cezpdf::Cezpdf($paper,$orientation); + $this->converter = $pdfconverter; + $this->font_dir = $fontdir; + } + + /** + * This really should be in the parent class + */ + function getColor() + { + return $this->currentColour; + } + + function setColorArray($color) + { + $this->setColor($color['r'], $color['g'], $color['b']); + } + + /** + * Extract Pdfphp-format color from html-format color + * @return array + * @access private + */ + function _extractColor($htmlcolor) + { + preg_match('/#([a-fA-F0-9][a-fA-F0-9])([a-fA-F0-9][a-fA-F0-9])([a-fA-F0-9][a-fA-F0-9])/', $htmlcolor, $color); + if (count($color) != 4) + { + return false; + } + $red = hexdec($color[1]) / hexdec('FF'); + $green = hexdec($color[2]) / hexdec('FF'); + $blue = hexdec($color[3]) / hexdec('FF'); + return array('r' => $red, 'g' => $green, 'b' => $blue); + } + + function validHTMLColor($color) + { + return $this->_extractColor($htmlcolor); + } + + function setHTMLColor($color) + { + fancy_debug('toplevel setting to', $color); + $this->setColor($color['r'], $color['g'], $color['b']); + } + + function textcolor($info) + { + if ($info['status'] == 'start') + { + array_push($this->_colorStack, $this->getColor()); + $color = $this->_extractColor($info['p']); + if ($color) + { +// fancy_debug('set color to ',$info['p'],$color, $this->_colorStack); + $this->setColorArray($color); + } else + { + array_pop($this->_colorStack); + } + } elseif ($info['status'] == 'end') + { +// debug('unsetting'); + $this->setColorArray(array_pop($this->_colorStack)); + } + } + + function rf($info) + { + $tmp = $info['p']; + $lvl = $tmp[0]; + $lbl = rawurldecode(substr($tmp,1)); + $num=$this->ezWhatPageNumber($this->ezGetCurrentPageNumber()); + $this->reportContents[] = array($lbl,$num,$lvl ); + $this->addDestination('toc'.(count($this->reportContents)-1),'FitH',$info['y']+$info['height']); + } + + function index($info) + { + $res = explode('|||',rawurldecode($info['p'])); + $name = $res[0]; + $descrip = $res[1]; + $letter = $name[0]; + if ($letter == '$') $letter = $name[1]; + $this->indexContents[strtoupper($letter)][] = array($name,$descrip,$this->ezWhatPageNumber($this->ezGetCurrentPageNumber()),count($this->reportContents) - 1); + } + + function IndexLetter($info) + { + $letter = $info['p']; + $this->transaction('start'); + $ok=0; + while (!$ok){ + $thisPageNum = $this->ezPageCount; + $this->saveState(); + $this->setColor(0.9,0.9,0.9); + $this->filledRectangle($this->ez['leftMargin'],$this->y-$this->getFontHeight(18)+$this->getFontDecender(18),$this->ez['pageWidth']-$this->ez['leftMargin']-$this->ez['rightMargin'],$this->getFontHeight(18)); + $this->restoreState(); + $this->_ezText($letter,18,array('justification'=>'left')); + if ($this->ezPageCount==$thisPageNum){ + $this->transaction('commit'); + $ok=1; + } else { + // then we have moved onto a new page, bad bad, as the background colour will be on the old one + $this->transaction('rewind'); + $this->ezNewPage(); + } + } + } + + function dots($info) + { + // draw a dotted line over to the right and put on a page number + $tmp = $info['p']; + $lvl = $tmp[0]; + $lbl = substr($tmp,1); + $xpos = 520; + + switch($lvl) + { + case '1': + $size=16; + $thick=1; + break; + case '2': + $size=14; + $thick=1; + break; + case '3': + $size=12; + $thick=1; + break; + case '4': + $size=11; + $thick=1; + break; + } + + $adjust = 0; + if ($size != 16) $adjust = 1; + $this->saveState(); + $this->setLineStyle($thick,'round','',array(0,10)); + $this->line($xpos - (5*$adjust),$info['y'],$info['x']+5,$info['y']); + $this->restoreState(); + $this->addText($xpos - (5*$adjust)+5,$info['y'],$size,$lbl); + } + + /** + * @uses PDFParser extracts all meta-tags and processes text for output + */ + function ezText($text,$size=0,$options=array(),$test=0) + { + $text = str_replace("\t"," ",$text); + // paragraph breaks + $text = str_replace("<##P##>","\n ",$text); + $text = str_replace("<>","ilink> >",$text); + $this->_save .= $text; + } + + function setupTOC() + { + $parser = new PDFParser; + $parser->parse($this->_save,$this->font_dir,$this); + $this->_save = ''; + } + + function ezOutput($debug = false, $template) + { + if ($debug) return $this->_save; + $this->setupTOC(); + if ($template) + { + uksort($this->indexContents,'strnatcasecmp'); + $xpos = 520; + $z = 0; + foreach($this->indexContents as $letter => $contents) + { + if ($z++/50 == 0) {phpDocumentor_out('.');flush();} + uksort($this->indexContents[$letter],array($this->converter,'mystrnatcasecmp')); + } + $template->assign('indexcontents',$this->indexContents); + $this->ezText($template->fetch('index.tpl')); + $this->setupTOC(); + } + return parent::ezOutput(); + } + + function _ezText($text,$size=0,$options=array(),$test=0) + { + return parent::ezText($text,$size,$options,$test); + } + + function getYPlusOffset($offset) + { + return $this->y + $offset; + } + + function addMessage($message) + { + return parent::addMessage($message); + phpDocumentor_out($message."\n"); + flush(); + } + + function ezProcessText($text){ + // this function will intially be used to implement underlining support, but could be used for a range of other + // purposes + $text = parent::ezProcessText($text); + $text = str_replace(array('','
  • ','
  • ','
      ','
    ','','
    ','
    '), + array('','
  • ','
  • ','
      ','','',"\n",""),$text); +// $text = str_replace("
        \n","
          ",$text); + $text = preg_replace("/\n+\s*(
            |
              )/", "\n\\1", $text); + // some problemos fixed here - hack + $text = preg_replace('//', '', $text); + $text = str_replace("
            1. \n","
            2. ",$text); + $text = preg_replace("/\n+\s*
            3. /", "
            4. ", $text); + $text = str_replace("","\n",$text); + $text = str_replace('
          ','
        ',$text); + $text = preg_replace("/^\n(\d+\s+.*)/", '\\1', $text); + $search = array('
          ','
        ','
          ','
        1. ','
        2. '); + $replace = array("\n","\n","\n\n",'',"\n"); + $text = str_replace($search,$replace,$text); + $text = preg_replace("/([^\n])listType = 'ordered'; + $this->listIndex = 1; + } else + { + if ($margin > 0) + { + $this->listIndex = 1; + } + $this->listType = 'unordered'; + } + $this->ez['leftMargin'] += $margin; + } + + /** + * @author Murray Shields + */ + function bullet($Data) + { + if ($this->listType == 'ordered') + { + return $this->orderedBullet($Data); + } + $D = abs($Data["decender"]); + $X = $Data["x"] - ($D * 2) - 10; + $Y = $Data["y"] + ($D * 1.5); + $this->setLineStyle($D, "butt", "miter", array()); + $this->setColor(0,0,0); + $this->ellipse($X, $Y, 1); + } + + function orderedBullet($info) + { + $this->addText($info['x']-20, $info['y']-1, 10, $this->listIndex++ . '.'); + } + + function ezNewPage($debug=false) + { + parent::ezNewPage(); + if (!$this->set_pageNumbering) + { + $template = $this->converter->newSmarty(); + $parser = new PDFParser; + $parser->parse($template->fetch('pagenumbering.tpl'),$this->font_dir,$this); + } + $this->set_pageNumbering = true; + } +} +?> -- cgit v1.2.3