From 3b905041432713cd47ad232e2c2a06564ebddfa7 Mon Sep 17 00:00:00 2001 From: "vincent@cubedesigners.com" Date: Thu, 6 Jul 2017 14:38:16 +0000 Subject: [PATCH] fix #1547 @2 --- inc/ws/Controlleur/class.ws.maintenance.php | 28 +++++++++++++++++ inc/ws/Metier/class.ws.document.php | 18 ++++++++--- .../html5/master/class.ws.html5.compiler.php | 31 +++++++++++++------ 3 files changed, 64 insertions(+), 13 deletions(-) diff --git a/inc/ws/Controlleur/class.ws.maintenance.php b/inc/ws/Controlleur/class.ws.maintenance.php index 35da09b3c..6c27049aa 100644 --- a/inc/ws/Controlleur/class.ws.maintenance.php +++ b/inc/ws/Controlleur/class.ws.maintenance.php @@ -1262,5 +1262,33 @@ class wsMaintenance { echo 'error : ' . implode(', ', $error) . '
'; } + 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; + } + } diff --git a/inc/ws/Metier/class.ws.document.php b/inc/ws/Metier/class.ws.document.php index c85240ad1..c085ff54f 100644 --- a/inc/ws/Metier/class.ws.document.php +++ b/inc/ws/Metier/class.ws.document.php @@ -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) { diff --git a/inc/ws/Util/html5/master/class.ws.html5.compiler.php b/inc/ws/Util/html5/master/class.ws.html5.compiler.php index 7b67d3e85..1faa83c93 100644 --- a/inc/ws/Util/html5/master/class.ws.html5.compiler.php +++ b/inc/ws/Util/html5/master/class.ws.html5.compiler.php @@ -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'); } -- 2.39.5