]> _ Git - cubeextranet.git/commitdiff
(no commit message)
authorvincent@cubedesigners.com <vincent@cubedesigners.com@f5622870-0f3c-0410-866d-9cb505b7a8ef>
Sun, 18 Mar 2012 22:57:34 +0000 (22:57 +0000)
committervincent@cubedesigners.com <vincent@cubedesigners.com@f5622870-0f3c-0410-866d-9cb505b7a8ef>
Sun, 18 Mar 2012 22:57:34 +0000 (22:57 +0000)
inc/ws/Metier/class.ws.document.php
inc/ws/Util/html5/class.ws.html5.compiler.php

index 547341dbc3dfd4711b34549285e9122598c67a98..3705613fc119a019bc42352f87b3d0a011522159 100644 (file)
@@ -259,7 +259,6 @@ class wsDocument extends cubeMetier {
                if ($this->CropAndCut()) {\r
                        $this->getInfos($this->cropped, true);\r
                }\r
-               //$this->extractFonts();\r
                $this->getLinksAndTexts();\r
        }\r
 \r
@@ -331,14 +330,14 @@ class wsDocument extends cubeMetier {
                $fwstk->execute();\r
                $this->addToLog($fwstk);\r
 \r
-               /*$fwstk = new cubeCommandLine('fwstk');\r
-               $fwstk->setPath(CONVERTER_PATH);\r
-               $fwstk->setArg('--input ' . $this->cropped);\r
-               $fwstk->setArg('--layout ' . $this->html . 'p%d.layout');\r
-               $fwstk->setArg('--cmaps ' . $this->html);\r
-               $fwstk->setArg('--fonts' . $this->out . 'fonts/web/');\r
-               $fwstk->execute();\r
-               $this->addToLog($fwstk);*/\r
+               /* $fwstk = new cubeCommandLine('fwstk');\r
+                 $fwstk->setPath(CONVERTER_PATH);\r
+                 $fwstk->setArg('--input ' . $this->cropped);\r
+                 $fwstk->setArg('--layout ' . $this->html . 'p%d.layout');\r
+                 $fwstk->setArg('--cmaps ' . $this->html);\r
+                 $fwstk->setArg('--fonts' . $this->out . 'fonts/web/');\r
+                 $fwstk->execute();\r
+                 $this->addToLog($fwstk); */\r
        }\r
 \r
        public function makeMiniShot($page) {\r
@@ -543,6 +542,56 @@ class wsDocument extends cubeMetier {
                        $this->makeShotPNM($page, 'html/h' . $r . '-', $r, $q, 4, null, false);\r
                        $this->makeShotPNM($page, 'html/t' . $r . '-', $r, $q, 4, null, true);\r
                }\r
+\r
+               $this->makeSVGFile($page);\r
+       }\r
+\r
+       public function makeSVGFile($page) {\r
+               $svgFile = $this->out . '/html/p' . $page . '.svg';\r
+               $svgzFile = $this->out . '/html/p' . $page . '.svgz';\r
+\r
+               $pdf2svg = new cubeCommandLine('pdf2svg');\r
+               $pdf2svg->setPath(CONVERTER_PATH);\r
+               $pdf2svg->setArg(null, $this->cropped);\r
+               $pdf2svg->setArg(null, $svgFile);\r
+               $pdf2svg->setArg(null, $page);\r
+               $pdf2svg->execute();\r
+               $this->addToLog($pdf2svg, true, $page);\r
+\r
+               $svg = new DOMDocument();\r
+               $svg->preserveWhiteSpace=false;\r
+               $svg->load($svgFile);\r
+\r
+               // Operations to delete \r
+               $xpath = new DOMXPath($svg);\r
+               $xpath->registerNamespace('svg', 'http://www.w3.org/2000/svg');\r
+               $xpath->registerNamespace('xlink', 'http://www.w3.org/1999/xlink');\r
+               $xpath->registerNamespace("php", "http://php.net/xpath");\r
+               $xpath->registerPhpFunctions('has_not_text');\r
+               $toDelete = array('//svg:defs/svg:clipPath',\r
+                       '//svg:defs/svg:image',\r
+                       '//svg:defs/svg:pattern',\r
+                       '/svg:svg/svg:g/svg:g[not(svg:use[@xlink:href])]',\r
+                       '/svg:svg/svg:g/svg:path'\r
+               );\r
+\r
+               global $svglog;\r
+               $svglog = array('XPATH : ' . print_r($xpath, true));\r
+               foreach ($toDelete as $q) {\r
+                       $list = $xpath->query($q);\r
+                       $svglog[] = "Evaluate xpath query " . $q;\r
+                       $svglog[] = 'Give ' . $list->length . ' results';\r
+                       $svglog[] = 'Deleting Nodes in ' . print_r($list, true);\r
+                       foreach ($list as $node) {\r
+\r
+                               /* @var $node DOMNode */\r
+                               $parent = $node->parentNode;\r
+                               $parent->removeChild($node);\r
+                       }\r
+               }\r
+\r
+               $this->addToLog(implode("\n", $svglog), false, $page);\r
+               file_put_contents($svgFile, $svg->saveXML());\r
        }\r
 \r
        protected function checkObjectsNumber($file, $maxObjects, $page) {\r
@@ -705,10 +754,10 @@ class wsDocument extends cubeMetier {
                        $pdf2swf->setArg('set jpegquality', $quality);\r
                        $pdf2swf->setArg('set disablelinks');\r
                        $pdf2swf->setArg('set dots');\r
-                       /*if(file_exists($this->rgb)){\r
-                       $pdf2swf->setArg(null, $this->rgb);\r
-                       }else{*/\r
-                               $pdf2swf->setArg(null, $this->cropped);\r
+                       /* if(file_exists($this->rgb)){\r
+                         $pdf2swf->setArg(null, $this->rgb);\r
+                         }else{ */\r
+                       $pdf2swf->setArg(null, $this->cropped);\r
                        //}\r
                        $pdf2swf->setArg('output', $this->out . $prefix . '%.swf');\r
                        $pdf2swf->execute();\r
index a23cab9570d27761b57941f27889d81e2219a54b..da091c080c9397790fe752e15ba5b91a9be4c7d2 100644 (file)
@@ -58,12 +58,14 @@ class wsHTML5Compiler {
        protected $cssOneWidth;
        protected $cssOneHeight;
        protected $cssScale;
+       protected $cssSVGScale = 0.75;
        protected $optimalWidth = 567;
        protected $optimalHeight = 709;
        protected $additionalConfig = array();
        protected $fontScale = 1;
        protected $cache = array();
        protected $backgroundsPrefix = 'p';
+       protected $svg = true;
 
        function __construct($book_id) {
                global $core;
@@ -89,6 +91,7 @@ class wsHTML5Compiler {
 
                if ($this->book->parametres->mobileVersion == 'html5-images') {
                        $this->backgroundsPrefix = 't';
+                       $this->svg = false;
                }
 
                $daoTheme = new wsDAOTheme($core->con);
@@ -115,7 +118,7 @@ class wsHTML5Compiler {
                $this->cssOneWidth = $this->width * $this->cssOneScale;
                $this->cssOneHeight = $this->height * $this->cssOneScale;
 
-               $this->scale = 10;
+               $this->scale = 1;
                if ($this->book->parametres->zoomMode == 1) {
                        $this->multiply = $this->pdf2htmlRatio * $this->scale * $this->cssOneScale;
                } else {
@@ -448,13 +451,18 @@ class wsHTML5Compiler {
        }
 
        protected function writeImages() {
-
                foreach (self::$resolutions as $r) {
                        mkdir($this->vdir . '/data/background/' . $r, 0777, true);
                }
+               if ($this->backgroundsPrefix == 'p') {
+                       $srcPrefix = 'h';
+               }
                foreach ($this->pages as $page => $infos) {
+                       if ($this->svg) {
+                               $this->copy(WS_DOCS . '/' . $infos['document_id'] . '/html/p' . $infos['document_page'] . '.svg', $this->vdir . '/data/contents/p' . $page . '.svg');
+                       }
                        foreach (self::$resolutions as $r) {
-                               $this->copy(WS_DOCS . '/' . $infos['document_id'] . '/html/' . $this->backgroundsPrefix . $r . '-' . $infos['document_page'] . '.jpg', $this->vdir . '/data/background/' . $r . '/' . $this->backgroundsPrefix . $page . '.jpg');
+                               $this->copy(WS_DOCS . '/' . $infos['document_id'] . '/html/' . $srcPrefix . $r . '-' . $infos['document_page'] . '.jpg', $this->vdir . '/data/background/' . $r . '/' . $this->backgroundsPrefix . $page . '.jpg');
                        }
                        $this->copy(WS_DOCS . '/' . $infos['document_id'] . '/p' . $infos['document_page'] . '.jpg', $this->vdir . '/data/thumbnails/p' . $page . '.jpg');
                }
@@ -462,6 +470,7 @@ class wsHTML5Compiler {
 
        protected function copy($s, $t) {
                if (!file_exists($s)) {
+                       fb($s . ' dont exists');
                        return;
                }
                if (file_exists($t) && filemtime($t) >= filemtime($s) && filesize($s) == filesize($t)) {
@@ -520,9 +529,9 @@ class wsHTML5Compiler {
                        $res[] = $br;
                }
                $texts = '.texts{' . $this->writeCSSUA('transform-origin', 'top left') . ';';
-               $texts.=$this->writeCSSUA('transform', 'scale(' . round((1 / $this->multiply) * $cssScale, 2) . ')') . ';';
-               $texts.='width:' . $wm . '; max-width:' . $wm . ';';
-               $texts.='height:' . $hm . '; max-height:' . $hm . ';';
+               $texts.=$this->writeCSSUA('transform', 'scale(' . round((1 / $this->multiply) * $cssScale * $this->cssSVGScale, 2) . ')') . ';';
+               $texts.='width:' . ($wm/$this->cssSVGScale) . '; max-width:' . ($wm/$this->cssSVGScale). ';';
+               $texts.='height:' . ($hm/$this->cssSVGScale) . '; max-height:' . ($hm/$this->cssSVGScale) . ';';
                $texts.='}';
                $res[] = $texts;