]> _ Git - cubeextranet.git/commitdiff
fix #1547 @2
authorvincent@cubedesigners.com <vincent@cubedesigners.com@f5622870-0f3c-0410-866d-9cb505b7a8ef>
Thu, 6 Jul 2017 14:38:16 +0000 (14:38 +0000)
committervincent@cubedesigners.com <vincent@cubedesigners.com@f5622870-0f3c-0410-866d-9cb505b7a8ef>
Thu, 6 Jul 2017 14:38:16 +0000 (14:38 +0000)
inc/ws/Controlleur/class.ws.maintenance.php
inc/ws/Metier/class.ws.document.php
inc/ws/Util/html5/master/class.ws.html5.compiler.php

index 35da09b3c3f658172cfecc6dbc85543fd01b6cc1..6c27049aa4ef03223113398388e4ccf270f2f90d 100644 (file)
@@ -1262,5 +1262,33 @@ class wsMaintenance {
                echo 'error : ' . implode(', ', $error) . '<br />';
        }
 
+       public static function getSVGPage($args) {
+
+               global $core;
+               $fluidbook = $args[0];
+               $page = $args[1];
+               $dao = new wsDAOBook($core->con);
+               $pages = $dao->getPagesOfBook($fluidbook);
+               $p = $pages[$page];
+               ob_clean();
+               header('Content-type: image/svg+xml');
+               $svg = wsDocument::getDir($p['document_id']) . '/html/p' . $p['document_page'] . '.svg';
+
+               $pdftocairo = new cubeCommandLine('pdftocairo');
+               $pdftocairo->setPath(CONVERTER_PATH);
+               $pdftocairo->setArg('f', $p['document_page']);
+               $pdftocairo->setArg('l', $p['document_page']);
+               $pdftocairo->setArg(null, '-svg');
+               //$pdftocairo->setArg(null, '-cropbox');
+               $pdftocairo->setArg(null, wsDocument::getDir($p['document_id']) . 'crop.pdf');
+               $pdftocairo->setArg(null, $svg);
+               $pdftocairo->execute();
+
+               wsDocument::cleanSVG($svg);
+
+               echo file_get_contents(wsDocument::getDir($p['document_id']) . '/html/p' . $p['document_page'] . '.svg');
+               exit;
+       }
+
 
 }
index c85240ad13ee75cc3948e53846a01597428a47cc..c085ff54f68254c23ff1585703a49c81f00c2dd2 100644 (file)
@@ -613,7 +613,7 @@ class wsDocument extends cubeMetier {
                $pdftocairo->setArg(null, $svgFile);
                $pdftocairo->execute();
                $this->addToLog($pdftocairo, true, $page);
-               $this->_cleanSVG($svgFile);
+               $this->_cleanSVG($svgFile, $page);
 
                $svgFile = $this->out . '/html/m' . $page . '.svg';
 
@@ -623,10 +623,10 @@ class wsDocument extends cubeMetier {
                $mupdf->setArg('F', 'svg');
 
 
-               $this->_cleanSVG($svgFile);
+               $this->_cleanSVG($svgFile, $page);
        }
 
-       protected function _cleanSVG($svgFile) {
+       public static function cleanSVG($svgFile) {
                $svg = new DOMDocument();
                $svg->preserveWhiteSpace = false;
                $svg->load($svgFile);
@@ -639,10 +639,14 @@ class wsDocument extends cubeMetier {
                $xpath->registerPhpFunctions('has_not_text');
                $toDelete = array('//svg:defs/svg:clipPath',
                                  '//svg:defs/svg:image',
+                                 '//svg:defs/svg:path',
                                  '//svg:defs/svg:pattern',
+                                 '//svg:defs/svg:g[starts-with(@id, "surface")]//svg:path',
                                  '/svg:svg/svg:g/svg:g[not(svg:use[@xlink:href])]',
+                                 //'/svg:svg/svg:g/svg:g[not(svg:use[starts-with(@xlink:href, "#glyph")])]',
                                  '/svg:svg/svg:g/svg:path',
                                  '/svg:svg/svg:g/svg:rect',
+                                 '//svg:use[starts-with(@xlink:href, "#image")]'
                );
 
                global $svglog;
@@ -661,9 +665,15 @@ class wsDocument extends cubeMetier {
                                }
                        }
                }
+               file_put_contents($svgFile, $svg->saveXML());
+               return $svglog;
+       }
+
+       protected function _cleanSVG($svgFile, $page) {
+               $svglog = self::cleanSVG($svgFile);
 
                $this->addToLog(implode("\n", $svglog), false, $page);
-               file_put_contents($svgFile, $svg->saveXML());
+
        }
 
        protected function checkObjectsNumber($file, $maxObjects, $page) {
index 7b67d3e859006a057931d192037f6dae37c68189..1faa83c93a6614b456551250a8a47146b709e000 100644 (file)
@@ -144,7 +144,7 @@ class wsHTML5Compiler {
        protected $additionalConfig = array();
        protected $fontScale = 1;
        protected $cache = array();
-       protected $backgroundsPrefix = 'p';
+       protected $backgroundsPrefix = array();
        protected $svg = true;
        protected $config = array();
        protected $assets = '';
@@ -212,9 +212,19 @@ class wsHTML5Compiler {
                $this->book = $this->daoBook->selectById($book_id);
                $this->pages = $this->daoBook->getPagesOfBook($book_id);
 
-               if ($this->book->parametres->mobileVersion == 'html5-images') {
-                       $this->backgroundsPrefix = 't';
-                       $this->svg = false;
+               switch ($this->book->parametres->mobileVersion) {
+                       case 'html5-desktop':
+                               $this->backgroundsPrefix = array('t', 'p');
+                               $svg = true;
+                               break;
+                       case 'html5-images':
+                               $this->backgroundsPrefix = array('t');
+                               $svg = false;
+                               break;
+                       default:
+                               $this->backgroundsPrefix = array('p');
+                               $svg = true;
+                               break;
                }
 
                $daoTheme = new wsDAOTheme($core->con);
@@ -1091,10 +1101,7 @@ class wsHTML5Compiler {
                foreach ($this->getResolutions() as $r) {
                        mkdir($this->vdir . '/data/background/' . $r, 0777, true);
                }
-               $srcPrefix = $this->backgroundsPrefix;
-               if ($this->backgroundsPrefix == 'p') {
-                       $srcPrefix = 'h';
-               }
+
                $thumbs = array();
                foreach ($this->pages as $page => $infos) {
                        $docdir = wsDocument::getDir($infos['document_id']);
@@ -1111,10 +1118,16 @@ class wsHTML5Compiler {
                        }
 
                        foreach ($this->getResolutions() as $r) {
-                               $ok = $this->copy($docdir . 'html/' . $srcPrefix . $r . '-' . $infos['document_page'] . '.jpg', $this->vdir . '/data/background/' . $r . '/' . $this->backgroundsPrefix . $page . '.jpg');
+                               foreach ($this->backgroundsPrefix as $backgroundsPrefix) {
+                                       $srcPrefix = $backgroundsPrefix;
+                                       if ($backgroundsPrefix == 'p') {
+                                               $srcPrefix = 'h';
+                                       }
+                                       $ok = $this->copy($docdir . 'html/' . $srcPrefix . $r . '-' . $infos['document_page'] . '.jpg', $this->vdir . '/data/background/' . $r . '/' . $backgroundsPrefix . $page . '.jpg');
                                if (!$ok && $r = 300) {
                                        $this->maxRes = 150;
                                }
+                               }
                        $this->copy(WS_DOCS . '/' . $infos['document_id'] . '/p' . $infos['document_page'] . '.jpg', $this->vdir . '/data/thumbnails/p' . $page . '.jpg');
                        }