[prev in list] [next in list] [prev in thread] [next in thread] 

List:       php-doc-cvs
Subject:    [DOC-CVS] cvs: phd /formats pdf.php  /themes/php phpbigpdf.php phppdf.php
From:       "Rudy Nappée" <loudi () php ! net>
Date:       2008-07-25 15:22:30
Message-ID: cvsloudi1216999350 () cvsserver
[Download RAW message or body]

loudi		Fri Jul 25 15:22:30 2008 UTC

  Modified files:              
    /phd/themes/php	phpbigpdf.php phppdf.php 
    /phd/formats	pdf.php 
  Log:
  * added "theorical" imagedata handling to PDF output
  * PDF output now uses compression (from ~40MB to ~20MB)
  * minor fixes
  
["loudi-20080725152230.txt" (text/plain)]

http://cvs.php.net/viewvc.cgi/phd/themes/php/phpbigpdf.php?r1=1.1&r2=1.2&diff_format=u
                
Index: phd/themes/php/phpbigpdf.php
diff -u phd/themes/php/phpbigpdf.php:1.1 phd/themes/php/phpbigpdf.php:1.2
--- phd/themes/php/phpbigpdf.php:1.1	Fri Jul 18 13:18:22 2008
+++ phd/themes/php/phpbigpdf.php	Fri Jul 25 15:22:30 2008
@@ -13,11 +13,19 @@
     public function format_root_set($open, $name, $attrs, $props) {
         if ($open) {
             $this->format->newChunk();
+            $this->cchunk = $this->dchunk;
             $pdfDoc = new PdfWriter();
+            try {
+                $pdfDoc->setCompressionMode(HaruDoc::COMP_ALL);
+            } catch (HaruException $e) { 
+                v("PDF Compression failed, you need to compile libharu with \
Zlib...", E_USER_WARNING); +            }
             $this->format->setPdfDoc($pdfDoc);
-            $this->cchunk = $this->dchunk;
+            
+            if (isset($attrs[PhDReader::XMLNS_XML]["base"]) && $base = \
$attrs[PhDReader::XMLNS_XML]["base"]) +                \
$this->format->setChunkInfo("xml-base", $base);  $id = \
                $attrs[PhDReader::XMLNS_XML]["id"];
-            $this->cchunk["id-to-outline"][$id] = 
+            $this->cchunk["root-outline"] = $this->cchunk["id-to-outline"][$id] = 
                 $pdfDoc->createOutline(PhDHelper::getDescription($id), null, true);
             $this->setIdToPage($id);
         } else {
http://cvs.php.net/viewvc.cgi/phd/themes/php/phppdf.php?r1=1.5&r2=1.6&diff_format=u
Index: phd/themes/php/phppdf.php
diff -u phd/themes/php/phppdf.php:1.5 phd/themes/php/phppdf.php:1.6
--- phd/themes/php/phppdf.php:1.5	Fri Jul 25 09:06:15 2008
+++ phd/themes/php/phppdf.php	Fri Jul 25 15:22:30 2008
@@ -87,6 +87,7 @@
         "toc-root"                  => null,
         "id-to-outline"             => array(),
         "id-to-page"                => array(),
+        "root-outline"              => null,
     );
     
     public function __construct(array $IDs, array $filenames, $format = "pdf", \
$chunked = true) { @@ -110,11 +111,19 @@
     public function format_book($open, $name, $attrs, $props) {
         if ($open) {
             $this->format->newChunk();
+            $this->cchunk = $this->dchunk;
             $pdfDoc = new PdfWriter();
+            try {
+                $pdfDoc->setCompressionMode(HaruDoc::COMP_ALL);
+            } catch (HaruException $e) { 
+                v("PDF Compression failed, you need to compile libharu with \
Zlib...", E_USER_WARNING); +            }
             $this->format->setPdfDoc($pdfDoc);
-            $this->cchunk = $this->dchunk;
+            if (isset($attrs[PhDReader::XMLNS_XML]["base"]) && $base = \
$attrs[PhDReader::XMLNS_XML]["base"]) +                \
$this->format->setChunkInfo("xml-base", $base); +                
             $id = $attrs[PhDReader::XMLNS_XML]["id"];
-            $this->cchunk["id-to-outline"][$id] = 
+            $this->cchunk["root-outline"] = $this->cchunk["id-to-outline"][$id] = 
                 $pdfDoc->createOutline(PhDHelper::getDescription($id), null, true);
             $this->setIdToPage($id);
         } else {
@@ -143,10 +152,19 @@
                 $this->format->getPdfDoc()->add(PdfWriter::PAGE);
             else 
                 $this->format->getPdfDoc()->add(PdfWriter::LINE_JUMP);
+            
+            if (isset($attrs[PhDReader::XMLNS_XML]["base"]) && $base = \
$attrs[PhDReader::XMLNS_XML]["base"]) +                \
$this->format->setChunkInfo("xml-base", $base); +                
             if (isset($attrs[PhDReader::XMLNS_XML]["id"]) && $id = \
$attrs[PhDReader::XMLNS_XML]["id"]) {  $parentId = PhDHelper::getParent($id);
-                $this->cchunk["id-to-outline"][$id] = \
                $this->format->getPdfDoc()->createOutline
-                    (PhDHelper::getDescription($id), \
$this->cchunk["id-to-outline"][$parentId], false); +                if \
(isset($this->cchunk["id-to-outline"][$parentId])) { +                    \
$this->cchunk["id-to-outline"][$id] = $this->format->getPdfDoc()->createOutline +     \
(PhDHelper::getDescription($id), $this->cchunk["id-to-outline"][$parentId], false); + \
} else { +                    $this->cchunk["id-to-outline"][$id] = \
$this->format->getPdfDoc()->createOutline +                        \
(PhDHelper::getDescription($id), $this->cchunk["root-outline"], false); +             \
}  $this->setIdToPage($id);
             }
         }
@@ -161,7 +179,7 @@
         return $this->format_tocnode($open, "reference", $attrs, $props, true);
     }    
     
-    // Convert the function name to a Unix valid filename
+    // Convert the book name to a Unix valid filename
     protected function toValidName($functionName) {
         return str_replace(array(":", "::", "->", "/", "\\", " "), array(".", ".", \
".", "-", "-", "-"), $functionName);  } 
http://cvs.php.net/viewvc.cgi/phd/formats/pdf.php?r1=1.5&r2=1.6&diff_format=u
Index: phd/formats/pdf.php
diff -u phd/formats/pdf.php:1.5 phd/formats/pdf.php:1.6
--- phd/formats/pdf.php:1.5	Thu Jul 24 17:05:29 2008
+++ phd/formats/pdf.php	Fri Jul 25 15:22:30 2008
@@ -5,8 +5,6 @@
         'abstract'              => 'format_suppressed_tags',
         'abbrev'                => 'format_suppressed_tags',
         'acronym'               => 'format_suppressed_tags',
-//        'article'               => false,
-//        'appendix'              => false,
         'alt'                   => 'format_suppressed_tags',
         'application'           => 'format_suppressed_tags',
         'author'                => array(
@@ -19,7 +17,6 @@
         'callout'               => 'format_callout',
         'calloutlist'           => 'format_calloutlist',
         'caution'               => 'format_admonition',
-//        'chapter'               => false,
         'citerefentry'          => 'format_suppressed_tags',
         'classname'             => array(
             /* DEFAULT */          'format_suppressed_tags',
@@ -49,6 +46,8 @@
         'function'              => 'format_suppressed_tags',
         'glossterm'             => 'format_suppressed_tags',
         'holder'                => 'format_suppressed_tags',
+        'imagedata'             => 'format_imagedata',
+        'imageobject'           => 'format_shifted_para',
         'index'                 => 'format_para',
         'indexdiv'              => 'format_para',
         'indexentry'            => 'format_shifted_line',
@@ -63,6 +62,7 @@
         'literal'               => 'format_italic',
         'literallayout'         => 'format_verbatim_inline',
         'manvolnum'             => 'format_manvolnum',
+        'mediaobject'           => 'format_suppressed_tags',
         'member'                => 'format_member',
         'note'                  => 'format_admonition',
         'option'                => 'format_italic',
@@ -76,7 +76,6 @@
             'listitem'          => 'format_suppressed_tags',
             'step'              => 'format_suppressed_tags',
         ),
-//        'part'                  => false,
         'partintro'             => 'format_para',
         'personname'            => 'format_suppressed_tags',
         'preface'               => 'format_suppressed_tags',
@@ -91,7 +90,6 @@
         'pubdate'               => 'format_para',
         'quote'                 => 'format_suppressed_tags',
         'refentrytitle'         => 'format_bold',
-//        'reference'             => false,
         'refname'               => 'format_title',
         'refnamediv'            => 'format_suppressed_tags',
         'refpurpose'            => 'format_refpurpose',
@@ -132,7 +130,6 @@
                 'informaltable' => 'format_title3',
                 'warning'           => 'format_title3',
             ),
-//            'indexdiv'          => false,
             'informaltable'     => 'format_title3',
             'legalnotice'       => 'format_title2',
             'note'              => 'format_title3',
@@ -153,10 +150,7 @@
         ), 
         'tip'                   => 'format_admonition',
         'titleabbrev'           => 'format_suppressed_tags',
-        'type'                  => array(
-            /* DEFAULT */          'format_suppressed_tags',
-//            'methodparam'       => false
-        ),
+        'type'                  => 'format_suppressed_tags',
         'userinput'             => 'format_bold',
         'variablelist'          => 'format_suppressed_tags',
         'varlistentry'          => 'format_newline',
@@ -229,13 +223,6 @@
             /* DEFAULT */         false,
             'fieldsynopsis'    => 'format_fieldsynopsis_modifier_text',
         ),
-//        'classname'            => array(
-//            /* DEFAULT */         false,
-//            'ooclass'          => array(
-//                /* DEFAULT */     false,
-//                'classsynopsis' => 'format_classsynopsis_ooclass_classname_text',
-//            ),
-//        ),
         'methodname'           => array(
             /* DEFAULT */         false,
             'constructorsynopsis' => array(
@@ -259,6 +246,7 @@
     protected $cchunk      = array();
     /* Default Chunk variables */
     protected $dchunk      = array(
+        "xml-base"              => "",
         "refsection"            => false,
         "examplenumber"         => 0,
         "href"                  => "",
@@ -304,7 +292,6 @@
     }
     
     public function __destruct() {
-        $this->pdfDoc->saveToFile("php_manual_en.pdf");
         unset($this->pdfDoc);
     }
     
@@ -715,6 +702,7 @@
     public function format_table($open, $name, $attrs, $props) {
         if ($open) {
             $this->cchunk["table"] = true;
+            $this->pdfDoc->add(PdfWriter::PARA);
         } else {
             $this->cchunk["table"] = false;
             $this->pdfDoc->add(PdfWriter::END_TABLE);
@@ -810,9 +798,7 @@
             }
 
             $rowspan = PhDFormat::rowspan($dbattrs);
-//            $moreattrs = self::parse_table_entry_attributes($dbattrs);
             $this->pdfDoc->add(PdfWriter::TABLE_ENTRY, array($colspan, $rowspan, \
                $align));
-//            return $retval. '<td colspan="' .((int)$colspan). '" rowspan="' \
.((int)$rowspan). '" ' .$moreattrs. '>';  } else {
             $this->pdfDoc->add(PdfWriter::TABLE_END_ENTRY);            
         }
@@ -998,35 +984,6 @@
         }
         return '';
     }
-
-
-//    public function format_classsynopsisinfo_ooclass_classname($open, $name, \
                $attrs) {
-//        if ($open) {
-//            if ($this->cchunk["classsynopsisinfo"]["ooclass"] === false) {
-//                $this->cchunk["classsynopsisinfo"]["ooclass"] = true;
-//                return ' class <b class="'.$name.'">';
-//            }
-//            return '<b class="'.$name.'"> ';
-//        }
-//        return "</b>";
-//    }
-//
-//    
-//    public function format_classsynopsis_ooclass_classname_text($value, $tag) {
-//        $this->cchunk["classsynopsis"]["classname"] = $value;
-//        return $this->TEXT($value);
-//    }
-    
-//    public function format_fieldsynopsis_varname($open, $name, $attrs) {
-//        if ($open) {
-//            if ($this->cchunk["fieldsynopsis"]["modifier"] === "const") {
-//                return '<var class="fieldsynopsis_varname">';
-//            }
-//            return '<var class="'.$name.'">$';
-//        }
-//        return '</var>';
-//    }
- 
     // }}} Synopsises
         
         
@@ -1091,9 +1048,6 @@
             $this->pdfDoc->add(PdfWriter::LINE_JUMP);
             $this->cchunk["co"] = 0;
         } else {
-//            foreach ($this->cchunk["corefs"] as $ref)
-//                foreach ($ref as $area)
-//                    $this->pdfDoc->resolveInternalLink($area[0], array($area[1], \
                $area[2], $area[3], $area[4]), $this->pdfDoc->getCurrentPage());
             $this->pdfDoc->add(PdfWriter::END_FRAMED_BLOCK, array(2)); // With Dash \
line  $this->cchunk["co"] = 0;
         }
@@ -1112,8 +1066,6 @@
                     $this->cchunk["links-to-resolve"][$ref][] = $area;
             }
             $this->pdfDoc->revertFont();
-            
-            //return '<tr><td><a \
href="#'.$attrs[PhDReader::XMLNS_DOCBOOK]["arearefs"].'">' .str_repeat("*", \
++$this->cchunk["callouts"]). '</a></td><td>';  } else {
             $this->pdfDoc->add(PdfWriter::LINE_JUMP);
         }
@@ -1171,6 +1123,17 @@
         $this->pdfDoc->vOffset("4");
         return '';
     }
+    
+    public function format_imagedata($open, $name, $attrs, $props) {
+        if ($props["empty"] && isset($this->cchunk["xml-base"]) && ($base = \
$this->cchunk["xml-base"]) && +            \
isset($attrs[PhDReader::XMLNS_DOCBOOK]["fileref"]) && ($fileref = \
$attrs[PhDReader::XMLNS_DOCBOOK]["fileref"])) { +            $imagePath = \
PhDConfig::xml_root() . DIRECTORY_SEPARATOR . $base . $fileref; +            if \
(file_exists($imagePath)) +                $this->pdfDoc->add(PdfWriter::IMAGE, \
$imagePath); +            
+        }
+        return '';
+    }
 
 }
 
@@ -1207,7 +1170,8 @@
     const TABLE_END_ENTRY = 0x24;
     const END_TABLE = 0x25;
     const TABLE_END_ROW = 0x26;
-    const ADD_NUMBER_ITEM = 0x27;    
+    const ADD_NUMBER_ITEM = 0x27;
+    const IMAGE = 0x28;    
     
     // Page format
     const VMARGIN = 56.7; // = 1 centimeter
@@ -1297,6 +1261,10 @@
         return $this->currentPage;
     }
     
+    public function setCompressionMode($mode) {
+        $this->haruDoc->setCompressionMode($mode);
+    }
+    
     // Append text into the current position
     public function appendText($text) {
 //        if ($this->vOffset > $this->current["charOffset"] + 3*LINE_SPACING + \
3*$this->currentFontSize) @@ -1543,6 +1511,9 @@
             case self::TABLE_END_ENTRY:
                 $this->endTableEntry();
                 break;
+            case self::IMAGE:
+                $this->addImage($option);
+                break;
             default:
                 trigger_error("Unknown object type : {$type}", E_USER_WARNING);
                 break;
@@ -1970,7 +1941,30 @@
         // Erase current properties
         $this->current["row"] = array();    
     }
+    
+    private function endsWith($str, $sub) {
+        return ( substr( $str, strlen( $str ) - strlen( $sub ) ) === $sub );
+    }
 
+    private function addImage($url) {
+        $image = null;
+        if ($this->endsWith(strtolower($url), ".png")) {
+            $image = $this->haruDoc->loadPNG($url);
+        } elseif ($this->endsWith(strtolower($url), ".jpg") || \
$this->endsWith(strtolower($url), ".jpeg")) { +            $image = \
$this->haruDoc->loadJPEG($url); +        }
+        if ($image) {
+            if ($this->PAGE_HEIGHT - $this->vOffset - 2*self::VMARGIN < \
$image->getHeight()) +                $this->nextPage();
+            $this->currentPage->drawImage($image,
+                self::HMARGIN + $this->permanentLeftSpacing + $this->hOffset,
+                $this->PAGE_HEIGHT - self::HMARGIN - $this->vOffset - \
$image->getHeight(), +                $image->getWidth(),
+                $image->getHeight());
+            
+            $this->hOffset = 0;
+            $this->vOffset += $image->getWidth();
+        }
+    }
 }
-
 ?>
\ No newline at end of file



-- 
PHP Documentation Commits Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic