cvs: phd /formats pdf.php /themes/php phppdf.php

From: Date: Sun, 20 Jul 2008 18:00:00 +0000
Subject: cvs: phd /formats pdf.php /themes/php phppdf.php
Groups: php.doc.cvs 
Request: Send a blank email to doc-cvs+get-1878@lists.php.net to get a copy of this message
loudi Sun Jul 20 18:00:00 2008 UTC Modified files: /phd/formats pdf.php /phd/themes/php phppdf.php Log: * adds processing of tables, lists and some other db5 elements WARNING: the current PDF output isn't over and did not render all the db5 elements

http://cvs.php.net/viewvc.cgi/phd/formats/pdf.php?r1=1.3&r2=1.4&diff_format=u Index: phd/formats/pdf.php diff -u phd/formats/pdf.php:1.3 phd/formats/pdf.php:1.4 --- phd/formats/pdf.php:1.3 Fri Jul 18 13:18:23 2008 +++ phd/formats/pdf.php Sun Jul 20 18:00:00 2008 @@ -4,8 +4,8 @@ protected $elementmap = array( /* {{{ */ 'abstract' => 'format_suppressed_tags', 'acronym' => 'format_suppressed_tags', - 'article' => false, - 'appendix' => false, +// 'article' => false, +// 'appendix' => false, 'author' => array( /* DEFAULT */ 'format_newline', 'authorgroup' => 'format_authorgroup_author', @@ -15,14 +15,23 @@ 'book' => 'format_suppressed_tags', 'classsynopsis' => 'format_para', 'caution' => 'format_admonition', - 'chapter' => false, +// 'chapter' => false, + 'classname' => array( + /* DEFAULT */ 'format_suppressed_tags', + 'ooclass' => array( + /* DEFAULT */ 'format_bold', +// 'classsynopsisinfo' => false, + ), + ), 'command' => 'format_italic', + 'computeroutput' => 'format_suppressed_tags', 'constant' => 'format_bold', 'code' => 'format_verbatim_inline', 'copyright' => 'format_copyright', 'editor' => 'format_editor', 'example' => 'format_example', 'emphasis' => 'format_italic', + 'envar' => 'format_suppressed_tags', 'filename' => 'format_italic', 'firstname' => 'format_suppressed_tags', 'formalpara' => 'format_para', @@ -33,42 +42,58 @@ 'informalexample' => 'format_para', 'itemizedlist' => 'format_shifted_para', 'legalnotice' => 'format_suppressed_tags', - 'listitem' => 'format_listitem', + 'listitem' => array( + /* DEFAULT */ 'format_listitem', + 'varlistentry' => 'format_shifted_para', + ), 'literal' => 'format_italic', 'literallayout' => 'format_verbatim_inline', 'member' => 'format_member', 'methodname' => 'format_bold', 'note' => 'format_admonition', 'option' => 'format_italic', + 'optional' => 'format_suppressed_tags', 'orderedlist' => 'format_shifted_para', 'othercredit' => 'format_newline', 'othername' => 'format_suppressed_tags', 'para' => array( /* DEFAULT */ 'format_para', 'listitem' => 'format_suppressed_tags', + 'step' => 'format_suppressed_tags', ), 'parameter' => array( - /* DEFAULT */ false, - 'code' => 'format_italic', + /* DEFAULT */ 'format_italic', + 'methodparam' => 'format_foos', ), - 'part' => false, +// 'part' => false, + 'partintro' => 'format_para', 'personname' => 'format_suppressed_tags', 'preface' => 'format_suppressed_tags', + 'procedure' => 'format_procedure', + 'productname' => 'format_suppressed_tags', 'programlisting' => 'format_verbatim_block', 'pubdate' => 'format_para', + 'quote' => 'format_suppressed_tags', 'refentrytitle' => 'format_bold', - 'reference' => false, +// 'reference' => false, + 'refname' => 'format_title', + 'refnamediv' => 'format_suppressed_tags', + 'refpurpose' => 'format_refpurpose', + 'refsect1' => 'format_suppressed_tags', 'replaceable' => 'format_italic', 'screen' => 'format_verbatim_block', 'section' => 'format_suppressed_tags', 'set' => 'format_suppressed_tags', 'simpara' => array( /* DEFAULT */ 'format_para', - 'listitem' => false, + 'listitem' => 'format_suppressed_tags', + 'step' => 'format_suppressed_tags', ), 'simplelist' => 'format_shifted_para', 'surname' => 'format_suppressed_tags', - 'systemitem' => 'format_bold', + 'synopsis' => 'format_verbatim_block', + 'systemitem' => 'format_verbatim_inline', + 'term' => 'format_suppressed_tags', 'title' => array( /* DEFAULT */ 'format_title', 'example' => 'format_example_title', @@ -79,41 +104,67 @@ 'note' => 'format_title3', 'table' => 'format_title3', 'informaltable' => 'format_title3', + 'warning' => 'format_title3', ), - 'indexdiv' => false, +// 'indexdiv' => false, 'informaltable' => 'format_title3', 'legalnotice' => 'format_title2', 'note' => 'format_title3', 'preface' => 'format_title', 'procedure' => 'format_bold', - 'refsect1' => false, - 'refsect2' => false, - 'refsect3' => false, + 'refsect1' => 'format_title2', + 'refsect2' => 'format_title3', + 'refsect3' => 'format_title3', 'section' => 'format_title2', 'sect1' => 'format_title2', 'sect2' => 'format_title3', -// 'sect3' => 'format_title3', -// 'sect4' => 'format_title3', + 'sect3' => 'format_title3', + 'sect4' => 'format_title3', 'segmentedlist' => 'format_bold', - 'table' => 'format_title3', + 'table' => 'format_title3', 'variablelist' => 'format_bold', + 'warning' => 'format_title3', ), 'tip' => 'format_admonition', 'titleabbrev' => 'format_suppressed_tags', 'type' => array( /* DEFAULT */ 'format_suppressed_tags', - 'methodparam' => false +// 'methodparam' => false ), 'userinput' => 'format_bold', + 'variablelist' => 'format_suppressed_tags', + 'varlistentry' => 'format_newline', 'varname' => 'format_italic', 'warning' => 'format_admonition', 'xref' => 'format_link', 'year' => 'format_suppressed_tags', + // TABLES + 'informaltable' => 'format_table', + 'table' => 'format_table', + 'tgroup' => 'format_tgroup', + 'colspec' => 'format_colspec', + 'spanspec' => 'format_suppressed_tags', + 'thead' => 'format_thead', + 'tbody' => 'format_tbody', + 'row' => 'format_row', + 'entry' => array ( + /* DEFAULT */ 'format_entry', + 'row' => array( + /* DEFAULT */ 'format_entry', + 'thead' => 'format_th_entry', + 'tfoot' => 'format_th_entry', + 'tbody' => 'format_entry', + ), + ), +// 'footnote' => 'format_footnote', +// 'footnoteref' => 'format_footnoteref', ); /* }}} */ protected $textmap = array( 'function' => 'format_function_text', 'link' => 'format_link_text', + 'quote' => 'format_quote_text', + 'refname' => 'format_refname_text', 'titleabbrev' => 'format_suppressed_text', ); @@ -130,7 +181,23 @@ "links-to-resolve" => array( /* $id => array( $target ), */ ), + "refname" => "", "table" => false, + "verbatim-block" => false, + + /*"appendlater" => false, + "firstitem" => false, + "buffer" => array(), + "examplenumber" => 0, + "methodsynopsis" => array( + "params" => array(), + "firstsynopsis" => true, + ), + "open" => false, + "ooclass" => null, + "role" => null, + "segtitle" => array(), + "segindex" => 0,*/ ); private $pdfDoc; @@ -174,6 +241,11 @@ } public function TEXT($str) { + if ($this->cchunk["verbatim-block"]) { + $this->pdfDoc->appendText(utf8_decode($str)); + return ""; + } + $ret = utf8_decode(trim(ereg_replace( "[ \n\t]+", ' ', $str))); // No whitespace if current text value begins with ',', ';', ':', '.' if (strncmp($ret, ",", 1) && strncmp($ret, ";", 1) && strncmp($ret, ":", 1) && strncmp($ret, ".", 1)) @@ -316,10 +388,12 @@ public function format_verbatim_block($open, $name, $attrs, $props) { if ($open) { + $this->cchunk["verbatim-block"] = true; $this->pdfDoc->add(PdfWriter::VERBATIM_BLOCK); } else { $this->pdfDoc->add(PdfWriter::LINE_JUMP); $this->pdfDoc->revertFont(); + $this->cchunk["verbatim-block"] = false; } return ""; } @@ -451,6 +525,21 @@ return ""; } + public function format_procedure($open, $name, $attrs, $props) { + $this->cchunk["step"] = 0; + return $this->format_shifted_para($open, $name, $attrs, $props); + } + + public function format_step($open, $name, $attrs, $props) { + if ($open) { + $this->pdfDoc->add(PdfWriter::LINE_JUMP); + $this->pdfDoc->add(PdfWriter::ADD_NUMBER_ITEM, (++$this->cchunk["step"])."."); + } else { + $this->pdfDoc->add(PdfWriter::LINE_JUMP, 0.5); + } + return ""; + } + public function format_member($open, $name, $attrs, $props) { if ($open) { $this->pdfDoc->add(PdfWriter::LINE_JUMP); @@ -458,11 +547,142 @@ } return ""; } + + // Tables {{{ + public function format_table($open, $name, $attrs, $props) { + if ($open) { + $this->cchunk["table"] = true; + } else { + $this->cchunk["table"] = false; + $this->pdfDoc->add(PdfWriter::END_TABLE); + } + return ""; + } + + public function format_colspec($open, $name, $attrs) { + if ($open) { + PhDFormat::colspec($attrs[PhDReader::XMLNS_DOCBOOK]); + } + return ""; + } + public function format_thead($open, $name, $attrs) { + if ($open) { + $valign = PhDFormat::valign($attrs[PhDReader::XMLNS_DOCBOOK]); + $this->pdfDoc->setFont(PdfWriter::FONT_BOLD); + } else { + $this->pdfDoc->revertFont(); + } + return ""; + } + public function format_tbody($open, $name, $attrs) { + if ($open) { + $valign = PhDFormat::valign($attrs[PhDReader::XMLNS_DOCBOOK]); + } + return ""; + } + public function format_row($open, $name, $attrs) { + if ($open) { + PhDFormat::initRow(); + $valign = PhDFormat::valign($attrs[PhDReader::XMLNS_DOCBOOK]); + $colCount = PhDFormat::getColCount(); + $this->pdfDoc->add(PdfWriter::TABLE_ROW, array($colCount, $valign)); + } else { + $this->pdfDoc->add(PdfWriter::TABLE_END_ROW); + } + return ""; + } + public function format_th_entry($open, $name, $attrs, $props) { + $align = (isset($attrs["align"]) ? $attrs["align"] : "center"); + if ($props["empty"]) { + $this->pdfDoc->add(PdfWriter::TABLE_ENTRY, array(1, 1, $align)); + $this->pdfDoc->add(PdfWriter::TABLE_END_ENTRY); + } + if ($open) { + $dbattrs = PhDFormat::getColspec($attrs[PhDReader::XMLNS_DOCBOOK]); + $align = (isset($dbattrs["align"]) ? $dbattrs["align"] : $align); + $colspan = PhDFormat::colspan($attrs[PhDReader::XMLNS_DOCBOOK]); + $this->pdfDoc->add(PdfWriter::TABLE_ENTRY, array($colspan, 1, $align)); + } else { + $this->pdfDoc->add(PdfWriter::TABLE_END_ENTRY); + } + return ""; + } + public function format_entry($open, $name, $attrs, $props) { + $align = (isset($attrs["align"]) ? $attrs["align"] : "left"); + if ($props["empty"]) { + $this->pdfDoc->add(PdfWriter::TABLE_ENTRY, array(1, 1, $align)); + $this->pdfDoc->add(PdfWriter::TABLE_END_ENTRY); + return; + } + if ($open) { + $dbattrs = PhDFormat::getColspec($attrs[PhDReader::XMLNS_DOCBOOK]); + $align = (isset($dbattrs["align"]) ? $dbattrs["align"] : $align); + $retval = ""; + if (isset($dbattrs["colname"])) { + for($i=PhDFormat::getEntryOffset($dbattrs); $i>0; --$i) { + $this->pdfDoc->add(PdfWriter::TABLE_ENTRY, array(1, 1, $align)); + $this->pdfDoc->add(PdfWriter::TABLE_END_ENTRY); + } + } + + /* + * "colspan" is *not* an standard prop, only used to overwrite the + * colspan for <footnote>s in tables + */ + if (isset($props["colspan"])) { + $colspan = $props["colspan"]; + } else { + $colspan = PhDFormat::colspan($dbattrs); + } + + $rowspan = PhDFormat::rowspan($dbattrs); + $this->pdfDoc->add(PdfWriter::TABLE_ENTRY, array($colspan, $rowspan, $align)); + } else { + $this->pdfDoc->add(PdfWriter::TABLE_END_ENTRY); + } + return ""; + } + + public function format_tgroup($open, $name, $attrs, $props) { + if ($open) { + PhDFormat::tgroup($attrs[PhDReader::XMLNS_DOCBOOK]); + if (isset($attrs[PhDReader::XMLNS_DOCBOOK]["cols"])) + $this->pdfDoc->add(PdfWriter::TABLE, $attrs[PhDReader::XMLNS_DOCBOOK]["cols"]); + } else { + } + return ""; + } + + // }}} Tables + + public function format_quote_text($value, $tag) { + $value = trim(ereg_replace( "[ \n\t]+", ' ', $value)); + $this->pdfDoc->appendText(' "'.$value.'"'); + return ""; + } + + public function format_refname_text($value, $tag) { + $this->cchunk["refname"][] = $value; + $this->pdfDoc->appendText(trim(ereg_replace( "[ \n\t]+", ' ', $value))); + return ""; + } + + public function format_refpurpose($open, $tag, $attrs) { + if ($open) { + $this->pdfDoc->add(PdfWriter::PARA); + foreach($this->cchunk["refname"] as $refname) { + $this->pdfDoc->appendText(" " . $refname . " --"); + } + } else { + $this->pdfDoc->add(PdfWriter::LINE_JUMP); + $this->pdfDoc->revertFont(); + $this->cchunk["refname"] = array(); + } + return ""; + } + } -/* Haru PDF Wrapping class - * Includes text appending, auto line wrap, on-the-fly font change, tables, frames, ... - */ class PdfWriter { // Font type constants (for setFont()) const FONT_NORMAL = 0x01; @@ -493,7 +713,9 @@ const TABLE_ENTRY = 0x18; const TABLE_END_ENTRY = 0x19; const END_TABLE = 0x1A; - + const TABLE_END_ROW = 0x1B; + const ADD_NUMBER_ITEM = 0x1C; + // Page format const VMARGIN = 56.7; // = 1 centimeter const HMARGIN = 56.7; // = 1 centimeter @@ -505,7 +727,10 @@ private $PAGE_HEIGHT; // in points private $haruDoc; + private $pages = array(); private $currentPage; + private $currentPageNumber; + private $currentFont; private $currentFontSize; private $currentFontColor; @@ -515,24 +740,29 @@ private $vOffset = 0; private $hOffset = 0; + private $lastPage = array( + "vOffset" => 0, + "hOffset" => 0, + ); private $permanentLeftSpacing = 0; private $permanentRightSpacing = 0; private $current = array( "oldVPosition" => 0, "vOffset" => 0, + "newVOffset" => 0, "pages" => array(), - "row" => array( - "vSize" => 0, - "cellCount" => 0, - "activeCell" => 0, - ), + "row" => array(), + "align" => "", ); - function __construct($pageWidth = 210, $pageHeight = 297) { - //Initialization of properties + // To temporarily store $current(s) + private $old = array(); + + function __construct($pageWidth = 210, $pageHeight = 297) { + // Initialization of properties $this->haruDoc = new HaruDoc; - $this->haruDoc->addPageLabel(1, HaruPage::NUM_STYLE_DECIMAL, 1, "Page "); + $this->haruDoc->addPageLabel(1, HaruPage::NUM_STYLE_DECIMAL, 1, "Page "); $this->haruDoc->setPageMode(HaruDoc::PAGE_MODE_USE_OUTLINE); $this->haruDoc->setPagesConfiguration(2); @@ -552,8 +782,8 @@ $this->currentFont = $this->fonts["Helvetica"]; $this->currentFontSize = 12; $this->currentFontColor = array(0, 0, 0); // Black - $this->newPage(); - $this->haruDoc->addPageLabel(1, HaruPage::NUM_STYLE_DECIMAL, 1, "Page "); + $this->nextPage(); + $this->haruDoc->addPageLabel(1, HaruPage::NUM_STYLE_DECIMAL, 1, "Page "); } public function getCurrentPage() { @@ -598,15 +828,27 @@ $textToAppend = substr($text, 0, $nbCarac); $text = substr($text, $nbCarac); - // Append text (in a new page if needed) + // Append text (in a new page if needed) with align if ($this->PAGE_HEIGHT - (self::VMARGIN + $this->vOffset) < self::VMARGIN) { $this->currentPage->endText(); $this->current["pages"][] = $this->currentPage; - $this->newPage(); + $this->nextPage(); $this->currentPage->beginText(); } - $this->currentPage->textOut(self::HMARGIN + $this->hOffset + $this->permanentLeftSpacing, - $this->PAGE_HEIGHT - (self::VMARGIN + $this->vOffset), $textToAppend); + if ($this->current["align"] == "center") { + $spacing = $this->PAGE_WIDTH - 2*self::HMARGIN - + $this->permanentLeftSpacing - $this->permanentRightSpacing - $this->currentPage->getTextWidth($textToAppend); + $this->currentPage->textOut(self::HMARGIN + $this->hOffset + $this->permanentLeftSpacing + $spacing/2, + $this->PAGE_HEIGHT - (self::VMARGIN + $this->vOffset), $textToAppend); + } elseif ($this->current["align"] == "right") { + $spacing = $this->PAGE_WIDTH - 2*self::HMARGIN - + $this->permanentLeftSpacing - $this->permanentRightSpacing - $this->currentPage->getTextWidth($textToAppend); + $this->currentPage->textOut(self::HMARGIN + $this->hOffset + $this->permanentLeftSpacing + $spacing, + $this->PAGE_HEIGHT - (self::VMARGIN + $this->vOffset), $textToAppend); + } else { // left + $this->currentPage->textOut(self::HMARGIN + $this->hOffset + $this->permanentLeftSpacing, + $this->PAGE_HEIGHT - (self::VMARGIN + $this->vOffset), $textToAppend); + } // Offsets for next line if (!$isLastLine) { @@ -658,7 +900,7 @@ if ($this->PAGE_HEIGHT - (self::VMARGIN + $this->vOffset) < self::VMARGIN) { $this->currentPage->endText(); $this->current["pages"][] = $this->currentPage; - $this->newPage(); + $this->nextPage(); $this->currentPage->beginText(); } $this->currentPage->textOut(self::HMARGIN + $this->hOffset + $this->permanentLeftSpacing, @@ -706,7 +948,7 @@ else $this->lineJump(); break; case self::PAGE: - $this->newPage(); + $this->nextPage(); break; case self::ADMONITION: $this->beginAdmonition(); @@ -724,10 +966,15 @@ return $this->prepareInternalLinkAnnotation($option); break; case self::ADD_BULLET: - $this->indent(-self::INDENT_SPACING); + $this->indent(-self::INDENT_SPACING-$this->currentPage->getTextWidth(chr(149))); $this->appendText(chr(149)); // ANSI Bullet $this->indent(0); break; + case self::ADD_NUMBER_ITEM: + $this->indent(-self::INDENT_SPACING-$this->currentPage->getTextWidth($option)); + $this->appendText($option); + $this->indent(0); + break; case self::FRAMED_BLOCK: $this->beginFrame(); break; @@ -743,8 +990,11 @@ case self::TABLE_ROW: $this->newTableRow($option[0], $option[1]); break; + case self::TABLE_END_ROW: + $this->endTableRow(); + break; case self::TABLE_ENTRY: - $this->beginTableEntry($option[0], $option[1]); + $this->beginTableEntry($option[0], $option[1], $option[2]); break; case self::TABLE_END_ENTRY: $this->endTableEntry(); @@ -836,18 +1086,43 @@ $this->hOffset = $offset; } - // Jump to a new page - private function newPage() { - $this->currentPage = $this->haruDoc->addPage(); - $this->currentPage->setTextRenderingMode(HaruPage::FILL); + // Jump to next page (or create a new one if none exists) + private function nextPage() { + $this->lastPage = array( + "vOffset" => $this->vOffset, + "hOffset" => $this->hOffset, + ); + $this->currentPageNumber++; + if (isset($this->pages[$this->currentPageNumber])) { + $this->currentPage = $this->pages[$this->currentPageNumber]; + $this->vOffset = $this->currentFontSize; + $this->hOffset = 0; + } else { + $this->pages[$this->currentPageNumber] = $this->haruDoc->addPage(); + $this->currentPage = $this->pages[$this->currentPageNumber]; + $this->currentPage->setTextRenderingMode(HaruPage::FILL); + $this->vOffset = $this->currentFontSize; + $this->hOffset = ($this->hOffset ? $this->hOffset : 0); + } if ($this->currentFont && $this->currentFontSize && $this->currentFontColor) { $this->currentPage->setFontAndSize($this->currentFont, $this->currentFontSize); $this->setColor($this->currentFontColor[0], $this->currentFontColor[1], $this->currentFontColor[2]); } - $this->vOffset = $this->currentFontSize; - $this->hOffset = ($this->hOffset ? $this->hOffset : 0); } + // Set last page as the current page + private function lastPage() { + $this->currentPageNumber--; + $this->currentPage = $this->pages[$this->currentPageNumber]; + $this->vOffset = $this->lastPage["vOffset"]; + $this->hOffset = $this->lastPage["hOffset"]; + } + + // Returns true if a next page exists + private function isNextPage() { + return isset($this->pages[$this->currentPageNumber + 1]); + } + // Jump a line private function lineJump($nbLines = 1) { $this->vOffset += $nbLines * ($this->currentFontSize + self::LINE_SPACING); @@ -862,11 +1137,18 @@ } private function beginAdmonition() { + // If this admonition is inside another frame + array_push($this->old, $this->current); + $this->setFont(self::FONT_BOLD, 12); $this->lineJump(); + // If no space for admonition title + interleave + admonition first line on this page, then creates a new one + if (($this->PAGE_HEIGHT - 2*self::VMARGIN - $this->vOffset) < (3*$this->currentFontSize + 3*self::LINE_SPACING)) + $this->nextPage(); $this->current["vOffset"] = $this->vOffset; $this->lineJump(); $this->permanentLeftSpacing += self::INDENT_SPACING; + $this->permanentRightSpacing += self::INDENT_SPACING; $this->current["pages"] = array(); } @@ -875,13 +1157,18 @@ $this->current["vOffset"] = 0; $this->beginFrame(); $this->revertFont(); - $this->currentPage->rectangle(self::HMARGIN + ($this->permanentLeftSpacing - self::INDENT_SPACING), $this->PAGE_HEIGHT - self::VMARGIN - $this->vOffset, $this->PAGE_WIDTH - 2*self::HMARGIN - ($this->permanentLeftSpacing - self::INDENT_SPACING), $this->vOffset - $this->current["vOffset"]); + $this->currentPage->rectangle(self::HMARGIN + ($this->permanentLeftSpacing - self::INDENT_SPACING), + $this->PAGE_HEIGHT - self::VMARGIN - $this->vOffset, + $this->PAGE_WIDTH - 2*self::HMARGIN - ($this->permanentLeftSpacing - self::INDENT_SPACING) - $this->permanentRightSpacing, + $this->vOffset - $this->current["vOffset"]); $this->currentPage->stroke(); } private function endAdmonition() { $this->endFrame(); $this->permanentLeftSpacing -= self::INDENT_SPACING; + $this->permanentRightSpacing -= self::INDENT_SPACING; + $this->current = array_pop($this->old); } private function beginFrame() { @@ -892,12 +1179,18 @@ private function endFrame() { foreach ($this->current["pages"] as $page) { - $page->rectangle(self::HMARGIN + ($this->permanentLeftSpacing - self::INDENT_SPACING), self::VMARGIN, $this->PAGE_WIDTH - 2*self::HMARGIN - ($this->permanentLeftSpacing - self::INDENT_SPACING), ($this->PAGE_HEIGHT - self::VMARGIN - $this->current["newVOffset"]) - self::VMARGIN); + $page->rectangle(self::HMARGIN + ($this->permanentLeftSpacing - self::INDENT_SPACING), + self::VMARGIN, + $this->PAGE_WIDTH - 2*self::HMARGIN - ($this->permanentLeftSpacing - self::INDENT_SPACING) - $this->permanentRightSpacing, + ($this->PAGE_HEIGHT - self::VMARGIN - $this->current["newVOffset"]) - self::VMARGIN); $page->stroke(); $this->current["newVOffset"] = 0; } - $this->currentPage->rectangle(self::HMARGIN + ($this->permanentLeftSpacing - self::INDENT_SPACING), $this->PAGE_HEIGHT - self::VMARGIN - $this->vOffset, $this->PAGE_WIDTH - 2*self::HMARGIN - ($this->permanentLeftSpacing - self::INDENT_SPACING), $this->vOffset - $this->current["newVOffset"]); + $this->currentPage->rectangle(self::HMARGIN + ($this->permanentLeftSpacing - self::INDENT_SPACING), + $this->PAGE_HEIGHT - self::VMARGIN - $this->vOffset, + $this->PAGE_WIDTH - 2*self::HMARGIN - ($this->permanentLeftSpacing - self::INDENT_SPACING) - $this->permanentRightSpacing, + $this->vOffset - $this->current["newVOffset"]); $this->currentPage->stroke(); $this->lineJump(); $this->current["oldVPosition"] = 0; @@ -993,5 +1286,97 @@ $page->createLinkAnnotation($rectangle, $destPage->createDestination()) ->setBorderStyle(0, 0, 0); } + + public function addTable($colCount) { + $this->currentPage->moveTo(self::HMARGIN, $this->PAGE_HEIGHT - self::VMARGIN - $this->vOffset); + $this->currentPage->lineTo($this->PAGE_WIDTH - self::HMARGIN, $this->PAGE_HEIGHT - self::VMARGIN - $this->vOffset); + $this->currentPage->stroke(); + } + + public function endTable() { + $this->permanentLeftSpacing = 0; + $this->permanentRightSpacing = 0; + $this->lineJump(); + } + + public function newTableRow($colCount, $valign) { + $this->current["vOffset"] = $this->vOffset; + $this->current["row"]["cellCount"] = $colCount; + $this->current["row"]["activeCell"] = 0; + $this->current["row"]["hSize"] = ($this->PAGE_WIDTH - 2*self::HMARGIN) / $this->current["row"]["cellCount"]; + $this->current["row"]["vPosition"] = 0; + $this->current["row"]["pages"] = array(); + $this->current["row"]["cutPolicy"] = array(1); + $this->current["pages"] = array(); + } + + public function beginTableEntry($colspan, $rowspan, $align) { + $this->permanentLeftSpacing = ($this->current["row"]["activeCell"]++) * $this->current["row"]["hSize"] + self::LINE_SPACING; + $this->permanentRightSpacing = $this->PAGE_WIDTH - 2*self::HMARGIN - + ($this->current["row"]["activeCell"] + $colspan - 1) * $this->current["row"]["hSize"] + self::LINE_SPACING; + + foreach ($this->current["pages"] as $page) { + $this->lastPage(); + } + $this->current["pages"] = array(); + + $this->hOffset = 0; + $this->vOffset = $this->current["vOffset"] + $this->currentFontSize + self::LINE_SPACING; + $this->current["align"] = $align; + + array_push($this->current["row"]["cutPolicy"], $colspan); + } + + public function endTableEntry() { + $this->current["align"] = ""; + $newOffset = $this->vOffset + $this->currentFontSize + self::LINE_SPACING; + if ($newOffset + $this->PAGE_HEIGHT * count($this->current["pages"]) > $this->current["row"]["vPosition"]) { + $this->current["row"]["vPosition"] = $newOffset + $this->PAGE_HEIGHT * count($this->current["pages"]); + } + if (count($this->current["pages"]) > count($this->current["row"]["pages"])) { + $this->current["row"]["pages"] = $this->current["pages"]; + } + } + + public function endTableRow() { + $vOffset = $this->current["vOffset"]; + while($this->isNextPage()) + $this->nextPage(); + // Vertical lines + for ($i = 0, $x = self::HMARGIN; $i <= $this->current["row"]["cellCount"]; $i++, $x += $this->current["row"]["hSize"]) { + + // Don't trace vertical line if colspan + if (($cellCount = array_shift($this->current["row"]["cutPolicy"])) > 1) { + array_unshift($this->current["row"]["cutPolicy"], $cellCount - 1); + continue; + } + + foreach ($this->current["row"]["pages"] as $page) { + $page->setRGBStroke(0, 0, 0); + $page->moveTo($x, self::VMARGIN); + $page->lineTo($x, $this->PAGE_HEIGHT - self::VMARGIN - $this->current["vOffset"]); + $page->stroke(); + $this->current["vOffset"] = 0; + } + + $this->currentPage->moveTo($x, $this->PAGE_HEIGHT - self::VMARGIN - ($this->current["vOffset"])); + $this->currentPage->lineTo($x, $this->PAGE_HEIGHT - self::VMARGIN - ($this->current["row"]["vPosition"] % $this->PAGE_HEIGHT)); + $this->currentPage->stroke(); + $this->current["vOffset"] = $vOffset; + } + // Horizontal line + $this->currentPage->moveTo(self::HMARGIN, $this->PAGE_HEIGHT - self::VMARGIN - ($this->current["row"]["vPosition"] % $this->PAGE_HEIGHT)); + $this->currentPage->lineTo($this->PAGE_WIDTH - self::HMARGIN, + $this->PAGE_HEIGHT - self::VMARGIN - ($this->current["row"]["vPosition"] % $this->PAGE_HEIGHT)); + $this->currentPage->stroke(); + + // Store position + $this->vOffset = $this->current["row"]["vPosition"] % $this->PAGE_HEIGHT; + + // Erase current properties + $this->current["row"] = array(); + } + } + ?> \ No newline at end of file http://cvs.php.net/viewvc.cgi/phd/themes/php/phppdf.php?r1=1.1&r2=1.2&diff_format=u Index: phd/themes/php/phppdf.php diff -u phd/themes/php/phppdf.php:1.1 phd/themes/php/phppdf.php:1.2 --- phd/themes/php/phppdf.php:1.1 Fri Jul 18 13:18:22 2008 +++ phd/themes/php/phppdf.php Sun Jul 20 18:00:00 2008 @@ -54,6 +54,7 @@ 'set' => false, ), ), + 'type' => 'format_type_text', ); @@ -167,4 +168,52 @@ } } } + + public function format_type_text($type, $tagname) { + $type = trim(ereg_replace( "[ \n\t]+", ' ', $type)); + $t = strtolower($type); + $href = $fragment = ""; + + switch($t) { + case "bool": + $href = "language.types.boolean"; + break; + case "int": + $href = "language.types.integer"; + break; + case "double": + $href = "language.types.float"; + break; + case "boolean": + case "integer": + case "float": + case "string": + case "array": + case "object": + case "resource": + case "null": + $href = "language.types.$t"; + break; + case "mixed": + case "number": + case "callback": + $href = "language.pseudo-types"; + $fragment = "language.types.$t"; + break; + default: + /* Check if its a classname. */ + $href = PhDTheme::getFilename("class.$t"); + } + + $this->format->getPdfDoc()->setFont(PdfWriter::FONT_NORMAL, 12, array(0, 0, 1)); // blue + $linkAreas = $this->format->getPdfDoc()->add(PdfWriter::LINK_ANNOTATION, $type); + $linksToResolve = $this->format->getChunkInfo("links-to-resolve"); + if (!isset($linksToResolve[$href])) + $linksToResolve[$href] = array(); + foreach ($linkAreas as $area) + $linksToResolve[$href][] = $area; + $this->format->setChunkInfo("links-to-resolve", $linksToResolve); + $this->format->getPdfDoc()->revertFont(); + return ''; + } }
« previous php.doc.cvs (#1878) next »