PageRenderTime 55ms CodeModel.GetById 10ms RepoModel.GetById 0ms app.codeStats 0ms

/xampp/php/PEAR/PhpDocumentor/phpDocumentor/Converters/PDF/default/class.phpdocpdf.php

https://github.com/edmondscommerce/XAMPP-Magento-Demo-Site
PHP | 353 lines | 260 code | 26 blank | 67 comment | 24 complexity | 5190b95cae2ae0f762abb89815a5cf7e MD5 | raw file
  1. <?php
  2. /**
  3. * Cezpdf callback class customized for phpDocumentor
  4. *
  5. * phpDocumentor :: automatic documentation generator
  6. *
  7. * PHP versions 4 and 5
  8. *
  9. * Copyright (c) 2000-2006 Joshua Eichorn, 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 2000-2006 Joshua Eichorn, Gregory Beaver
  32. * @license http://www.opensource.org/licenses/lgpl-license.php LGPL
  33. * @version CVS: $Id: class.phpdocpdf.php,v 1.4 2006/04/30 22:18:14 cellog Exp $
  34. * @filesource
  35. * @link http://www.phpdoc.org
  36. * @link http://pear.php.net/PhpDocumentor
  37. * @since 1.2
  38. */
  39. /** ezPdf libraries */
  40. include_once 'phpDocumentor/Converters/PDF/default/class.ezpdf.php';
  41. include_once 'phpDocumentor/Converters/PDF/default/ParserPDF.inc';
  42. // define a class extension to allow the use of a callback to get the table of
  43. // contents, and to put the dots in the toc
  44. /**
  45. * @package Converters
  46. * @subpackage PDFdefault
  47. */
  48. class phpdocpdf extends Cezpdf
  49. {
  50. var $reportContents = array();
  51. var $indexContents = array();
  52. var $indents = array();
  53. var $font_dir = false;
  54. var $set_pageNumbering = false;
  55. var $converter;
  56. var $_save = '';
  57. var $listType = 'ordered';
  58. var $_colorStack = array();
  59. function phpdocpdf(&$pdfconverter,$fontdir,$paper='a4',$orientation='portrait')
  60. {
  61. Cezpdf::Cezpdf($paper,$orientation);
  62. $this->converter = $pdfconverter;
  63. $this->font_dir = $fontdir;
  64. }
  65. /**
  66. * This really should be in the parent class
  67. */
  68. function getColor()
  69. {
  70. return $this->currentColour;
  71. }
  72. function setColorArray($color)
  73. {
  74. $this->setColor($color['r'], $color['g'], $color['b']);
  75. }
  76. /**
  77. * Extract Pdfphp-format color from html-format color
  78. * @return array
  79. * @access private
  80. */
  81. function _extractColor($htmlcolor)
  82. {
  83. 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);
  84. if (count($color) != 4)
  85. {
  86. return false;
  87. }
  88. $red = hexdec($color[1]) / hexdec('FF');
  89. $green = hexdec($color[2]) / hexdec('FF');
  90. $blue = hexdec($color[3]) / hexdec('FF');
  91. return array('r' => $red, 'g' => $green, 'b' => $blue);
  92. }
  93. function validHTMLColor($color)
  94. {
  95. return $this->_extractColor($htmlcolor);
  96. }
  97. function setHTMLColor($color)
  98. {
  99. fancy_debug('toplevel setting to', $color);
  100. $this->setColor($color['r'], $color['g'], $color['b']);
  101. }
  102. function textcolor($info)
  103. {
  104. if ($info['status'] == 'start')
  105. {
  106. array_push($this->_colorStack, $this->getColor());
  107. $color = $this->_extractColor($info['p']);
  108. if ($color)
  109. {
  110. // fancy_debug('set color to ',$info['p'],$color, $this->_colorStack);
  111. $this->setColorArray($color);
  112. } else
  113. {
  114. array_pop($this->_colorStack);
  115. }
  116. } elseif ($info['status'] == 'end')
  117. {
  118. // debug('unsetting');
  119. $this->setColorArray(array_pop($this->_colorStack));
  120. }
  121. }
  122. function rf($info)
  123. {
  124. $tmp = $info['p'];
  125. $lvl = $tmp[0];
  126. $lbl = rawurldecode(substr($tmp,1));
  127. $num=$this->ezWhatPageNumber($this->ezGetCurrentPageNumber());
  128. $this->reportContents[] = array($lbl,$num,$lvl );
  129. $this->addDestination('toc'.(count($this->reportContents)-1),'FitH',$info['y']+$info['height']);
  130. }
  131. function index($info)
  132. {
  133. $res = explode('|||',rawurldecode($info['p']));
  134. $name = $res[0];
  135. $descrip = $res[1];
  136. $letter = $name[0];
  137. if ($letter == '$') $letter = $name[1];
  138. $this->indexContents[strtoupper($letter)][] = array($name,$descrip,$this->ezWhatPageNumber($this->ezGetCurrentPageNumber()),count($this->reportContents) - 1);
  139. }
  140. function IndexLetter($info)
  141. {
  142. $letter = $info['p'];
  143. $this->transaction('start');
  144. $ok=0;
  145. while (!$ok){
  146. $thisPageNum = $this->ezPageCount;
  147. $this->saveState();
  148. $this->setColor(0.9,0.9,0.9);
  149. $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));
  150. $this->restoreState();
  151. $this->_ezText($letter,18,array('justification'=>'left'));
  152. if ($this->ezPageCount==$thisPageNum){
  153. $this->transaction('commit');
  154. $ok=1;
  155. } else {
  156. // then we have moved onto a new page, bad bad, as the background colour will be on the old one
  157. $this->transaction('rewind');
  158. $this->ezNewPage();
  159. }
  160. }
  161. }
  162. function dots($info)
  163. {
  164. // draw a dotted line over to the right and put on a page number
  165. $tmp = $info['p'];
  166. $lvl = $tmp[0];
  167. $lbl = substr($tmp,1);
  168. $xpos = 520;
  169. switch($lvl)
  170. {
  171. case '1':
  172. $size=16;
  173. $thick=1;
  174. break;
  175. case '2':
  176. $size=14;
  177. $thick=1;
  178. break;
  179. case '3':
  180. $size=12;
  181. $thick=1;
  182. break;
  183. case '4':
  184. $size=11;
  185. $thick=1;
  186. break;
  187. }
  188. $adjust = 0;
  189. if ($size != 16) $adjust = 1;
  190. $this->saveState();
  191. $this->setLineStyle($thick,'round','',array(0,10));
  192. $this->line($xpos - (5*$adjust),$info['y'],$info['x']+5,$info['y']);
  193. $this->restoreState();
  194. $this->addText($xpos - (5*$adjust)+5,$info['y'],$size,$lbl);
  195. }
  196. /**
  197. * @uses PDFParser extracts all meta-tags and processes text for output
  198. */
  199. function ezText($text,$size=0,$options=array(),$test=0)
  200. {
  201. $text = str_replace("\t"," ",$text);
  202. // paragraph breaks
  203. $text = str_replace("<##P##>","\n ",$text);
  204. $text = str_replace("<<c:i",'< <c:i',$text);
  205. $text = str_replace("ilink>>","ilink> >",$text);
  206. $this->_save .= $text;
  207. }
  208. function setupTOC()
  209. {
  210. $parser = new PDFParser;
  211. $parser->parse($this->_save,$this->font_dir,$this);
  212. $this->_save = '';
  213. }
  214. function ezOutput($debug = false, $template)
  215. {
  216. if ($debug) return $this->_save;
  217. $this->setupTOC();
  218. if ($template)
  219. {
  220. uksort($this->indexContents,'strnatcasecmp');
  221. $xpos = 520;
  222. $z = 0;
  223. foreach($this->indexContents as $letter => $contents)
  224. {
  225. if ($z++/50 == 0) {phpDocumentor_out('.');flush();}
  226. uksort($this->indexContents[$letter],array($this->converter,'mystrnatcasecmp'));
  227. }
  228. $template->assign('indexcontents',$this->indexContents);
  229. $this->ezText($template->fetch('index.tpl'));
  230. $this->setupTOC();
  231. }
  232. return parent::ezOutput();
  233. }
  234. function _ezText($text,$size=0,$options=array(),$test=0)
  235. {
  236. return parent::ezText($text,$size,$options,$test);
  237. }
  238. function getYPlusOffset($offset)
  239. {
  240. return $this->y + $offset;
  241. }
  242. function addMessage($message)
  243. {
  244. return parent::addMessage($message);
  245. phpDocumentor_out($message."\n");
  246. flush();
  247. }
  248. function ezProcessText($text){
  249. // this function will intially be used to implement underlining support, but could be used for a range of other
  250. // purposes
  251. $text = parent::ezProcessText($text);
  252. $text = str_replace(array('<UL>','</UL>','<LI>','</LI>','<OL>','</OL>','</ol>','<blockquote>','</blockquote>'),
  253. array('<ul>','</ul>','<li>','</li>','<ol>','</ul>','</ul>',"<C:indent:20>\n","<C:indent:-20>"),$text);
  254. // $text = str_replace("<ul>\n","<ul>",$text);
  255. $text = preg_replace("/\n+\s*(<ul>|<ol>)/", "\n\\1", $text);
  256. // some problemos fixed here - hack
  257. $text = preg_replace('/<text [^]]+>/', '', $text);
  258. $text = str_replace("<li>\n","<li>",$text);
  259. $text = preg_replace("/\n+\s*<li>/", "<li>", $text);
  260. $text = str_replace("<mybr>","\n",$text);
  261. $text = str_replace('</li></ul>','</ul>',$text);
  262. $text = preg_replace("/^\n(\d+\s+.*)/", '\\1', $text);
  263. $search = array('<ul>','</ul>','<ol>','<li>','</li>');
  264. $replace = array("<C:indent:20>\n","\n<C:indent:-20>","\n<C:indent:20:ordered>\n",'<C:bullet>',"\n");
  265. $text = str_replace($search,$replace,$text);
  266. $text = preg_replace("/([^\n])<C:bullet/", "\\1\n<C:bullet", $text);
  267. if (false) {
  268. $fp = @fopen("C:/Documents and Settings/Owner/Desktop/pdfsourceorig.txt",'a');
  269. if ($fp)
  270. {
  271. fwrite($fp, $text);
  272. fclose($fp);
  273. }
  274. }
  275. return $text;
  276. }
  277. function indent($info)
  278. {
  279. $stuff = explode(':', $info['p']);
  280. $margin = $stuff[0];
  281. if (count($stuff) - 1)
  282. {
  283. $this->listType = 'ordered';
  284. $this->listIndex = 1;
  285. } else
  286. {
  287. if ($margin > 0)
  288. {
  289. $this->listIndex = 1;
  290. }
  291. $this->listType = 'unordered';
  292. }
  293. $this->ez['leftMargin'] += $margin;
  294. }
  295. /**
  296. * @author Murray Shields
  297. */
  298. function bullet($Data)
  299. {
  300. if ($this->listType == 'ordered')
  301. {
  302. return $this->orderedBullet($Data);
  303. }
  304. $D = abs($Data["decender"]);
  305. $X = $Data["x"] - ($D * 2) - 10;
  306. $Y = $Data["y"] + ($D * 1.5);
  307. $this->setLineStyle($D, "butt", "miter", array());
  308. $this->setColor(0,0,0);
  309. $this->ellipse($X, $Y, 1);
  310. }
  311. function orderedBullet($info)
  312. {
  313. $this->addText($info['x']-20, $info['y']-1, 10, $this->listIndex++ . '.');
  314. }
  315. function ezNewPage($debug=false)
  316. {
  317. parent::ezNewPage();
  318. if (!$this->set_pageNumbering)
  319. {
  320. $template = $this->converter->newSmarty();
  321. $parser = new PDFParser;
  322. $parser->parse($template->fetch('pagenumbering.tpl'),$this->font_dir,$this);
  323. }
  324. $this->set_pageNumbering = true;
  325. }
  326. }
  327. ?>