From 5109260f96802cf12d70fde26faf365957b984f6 Mon Sep 17 00:00:00 2001 From: "vincent@cubedesigners.com" Date: Fri, 25 Aug 2017 14:57:01 +0000 Subject: [PATCH] fix #1622 @1.5 --- fluidbook/tools/fwstk/.idea/workspace.xml | 5 +- fluidbook/tools/scour.php | 19 ------ inc/ws/Metier/class.ws.document.php | 34 ++++------- inc/ws/Util/class.ws.tools.php | 19 +++++- .../html5/master/class.ws.html5.compiler.php | 60 ++++++++++++------- 5 files changed, 72 insertions(+), 65 deletions(-) delete mode 100644 fluidbook/tools/scour.php diff --git a/fluidbook/tools/fwstk/.idea/workspace.xml b/fluidbook/tools/fwstk/.idea/workspace.xml index e7d5a8aee..cf8bfa501 100644 --- a/fluidbook/tools/fwstk/.idea/workspace.xml +++ b/fluidbook/tools/fwstk/.idea/workspace.xml @@ -1178,7 +1178,7 @@ - + 1487172253077 @@ -1212,11 +1212,10 @@ - - diff --git a/fluidbook/tools/scour.php b/fluidbook/tools/scour.php deleted file mode 100644 index edb0a7f54..000000000 --- a/fluidbook/tools/scour.php +++ /dev/null @@ -1,19 +0,0 @@ -#!/usr/bin/php -generalInfos['pages']; $i++) { $this->processOnePage($i); } - $this->optimizeSVG(); - } - - public function optimizeSVG() { - $scour = new cubeCommandLine('scour.php'); - $scour->setPath(CONVERTER_PATH); - $scour->setNohup(true); - $scour->setArg(null, $this->html); - $scour->execute(); } public function processRange($pages) { foreach ($pages as $i) { $this->processOnePage($i); } - //$this->optimizeSVG(); } public function getLinksAndTexts() { @@ -615,11 +605,14 @@ class wsDocument extends cubeMetier { $pdftocairo->setArg(null, $svgFile); $pdftocairo->execute(); $this->addToLog($pdftocairo, true, $page); - copy($svgFile, $this->out . '/html/tp' . $page . '.svg'); - $this->_cleanSVG($svgFile, $page); } - public static function cleanSVG($svgFile, $debug = false) { + public static function extractTexts($svgFile, $textFile, $force = false) { + $do = $force || !file_exists($textFile) || filemtime($svgFile) > filemtime($textFile) || filemtime($textFile) < filemtime(__FILE__); + if (!$do) { + return; + } + $svg = new DOMDocument(); $svg->preserveWhiteSpace = false; $svg->load($svgFile, LIBXML_PARSEHUGE); @@ -640,24 +633,23 @@ class wsDocument extends cubeMetier { '//svg:use[starts-with(@xlink:href, "#image")]' ); - global $svglog; - $svglog = array('XPATH : ' . print_r($xpath, true)); + //global $svglog; + //$svglog = array('XPATH : ' . print_r($xpath, true)); foreach ($toDelete as $q) { $list = $xpath->query($q); - $svglog[] = "Evaluate xpath query " . $q; - $svglog[] = 'Give ' . $list->length . ' results'; - $svglog[] = 'Deleting Nodes in ' . print_r($list, true); + // $svglog[] = "Evaluate xpath query " . $q; + // $svglog[] = 'Give ' . $list->length . ' results'; + // $svglog[] = 'Deleting Nodes in ' . print_r($list, true); if (count($list)) { foreach ($list as $node) { - /* @var $node DOMNode */ $parent = $node->parentNode; $parent->removeChild($node); } } } - file_put_contents($svgFile, $svg->saveXML()); - return $svglog; + file_put_contents($textFile, $svg->saveXML()); + //return $svglog; } protected function _cleanSVG($svgFile, $page) { diff --git a/inc/ws/Util/class.ws.tools.php b/inc/ws/Util/class.ws.tools.php index a5042f774..a19475506 100644 --- a/inc/ws/Util/class.ws.tools.php +++ b/inc/ws/Util/class.ws.tools.php @@ -84,7 +84,7 @@ class wsTools { // SVG - $time=max(filemtime(__FILE__),filemtime($svgRef)); + $time = max(filemtime(__FILE__), filemtime($svgRef)); if (!file_exists($svgColorized) || filemtime($svgColorized) <= $time) { $svg = file_get_contents($svgRef); // Colorize it @@ -108,7 +108,7 @@ class wsTools { // PNG $png = $dirColorized . '/' . $icon . '.png'; - $time=max(filemtime(__FILE__),filemtime($svgColorized)); + $time = max(filemtime(__FILE__), filemtime($svgColorized)); if (!file_exists($png) || filemtime($png) <= $time) { $svg = simplexml_load_file($svgColorized); $w = (string)$svg['width']; @@ -136,6 +136,21 @@ class wsTools { } } + public static function optimizeSVG($original, $optimized, $force = false) { + if (!file_exists($original)) { + return; + } + + $optimize = $force || + !file_exists($optimized) || + filemtime($optimized) < filemtime('/usr/local/bin/svgcleaner') || + filemtime($optimized) < filemtime($original); + + if ($optimize) { + `/usr/local/bin/svgcleaner $original $optimized --paths-coordinates-precision 3 --copy-on-error`; + } + } + public static function copy($source, $dest) { if (!file_exists($source)) { return; 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 72c63ffba..0856d4f9d 100644 --- a/inc/ws/Util/html5/master/class.ws.html5.compiler.php +++ b/inc/ws/Util/html5/master/class.ws.html5.compiler.php @@ -216,15 +216,15 @@ class wsHTML5Compiler { switch ($this->book->parametres->mobileVersion) { case 'html5-desktop': $this->backgroundsPrefix = array('t', 'p'); - $svg = true; + $this->svg = true; break; case 'html5-images': $this->backgroundsPrefix = array('t'); - $svg = false; + $this->svg = false; break; default: $this->backgroundsPrefix = array('p'); - $svg = true; + $this->svg = true; break; } @@ -1104,6 +1104,7 @@ class wsHTML5Compiler { } protected function writeImages() { + global $core; foreach ($this->getResolutions() as $r) { mkdir($this->vdir . '/data/background/' . $r, 0777, true); } @@ -1112,15 +1113,21 @@ class wsHTML5Compiler { foreach ($this->pages as $page => $infos) { $docdir = wsDocument::getDir($infos['document_id']); if ($this->svg) { + $full = $docdir . 'html/fp' . $infos['document_page'] . '.svg'; $orig = $docdir . 'html/tp' . $infos['document_page'] . '.svg'; $opt = $docdir . 'html/to' . $infos['document_page'] . '.svg'; - $svg = $orig; - if (file_exists($opt) && filesize($opt) > 0) { - $svg = $opt; + if (!file_exists($full) || filemtime($full) < 1503671520) { + if (!isset($doc) || $doc->document_id != $infos['document_id']) { + $dao = new wsDAODocument($core->con); + $doc = $dao->selectById($infos['document_id']); + } + $doc->makeSVGFile($infos['document_page']); } + wsDocument::extractTexts($full, $orig); + wsTools::optimizeSVG($orig, $opt); - $this->copy($svg, $this->vdir . '/data/contents/p' . $page . '.svg'); + $this->copy($opt, $this->vdir . '/data/contents/p' . $page . '.svg'); } foreach ($this->getResolutions() as $r) { @@ -1155,7 +1162,8 @@ class wsHTML5Compiler { } } - public function makeThumbSprites(array $thumbs) { + public + function makeThumbSprites(array $thumbs) { $cols = 10; $rows = 10; $perSprite = $cols * $rows; @@ -1192,7 +1200,8 @@ class wsHTML5Compiler { return $res; } - protected function _makeCover($orig) { + protected + function _makeCover($orig) { $size = getimagesize($orig); $w = $size[0]; $h = $size[1]; @@ -1216,7 +1225,8 @@ class wsHTML5Compiler { unlink($tmp); } - protected function copy($s, $t) { + protected + function copy($s, $t) { if (!file_exists($s)) { fb($s . ' dont exists'); return false; @@ -1233,11 +1243,13 @@ class wsHTML5Compiler { return true; } - protected function _lessBoolean($val) { + protected + function _lessBoolean($val) { return $val ? 'true' : 'false'; } - protected function writeCSS($file, $links) { + protected + function writeCSS($file, $links) { $res = array(); $lessVariables = array(); @@ -1436,7 +1448,8 @@ class wsHTML5Compiler { return count($res); } - protected function _writeLess($variables) { + protected + function _writeLess($variables) { if ($this->widget) { $this->lessFiles[] = 'widget'; } @@ -1498,7 +1511,8 @@ class wsHTML5Compiler { } } - protected function _cssBackground() { + protected + function _cssBackground() { $body = '#background,#splash{'; $body .= 'background-color:#' . $this->theme->parametres->backgroundColor . ';'; switch ($this->theme->parametres->repeat) { @@ -1559,7 +1573,8 @@ class wsHTML5Compiler { return $body; } - public static function writeCSSUA($property, $value) { + public + static function writeCSSUA($property, $value) { $res = array(); foreach (self::$uaPrefixes as $prefix) { $res[] = $prefix . $property . ':' . $value; @@ -1567,7 +1582,8 @@ class wsHTML5Compiler { return implode(';', $res); } - protected function base62($val) { + protected + function base62($val) { $chars = '0123456789abcdefghijklmnopqrstuvwxyz'; $base = strlen($chars); $str = ''; @@ -1579,11 +1595,13 @@ class wsHTML5Compiler { return $str; } - public function copyLinkDir($source, $dest) { + public + function copyLinkDir($source, $dest) { `cp -a $source $this->vdir/$dest`; } - public function simpleCopyLinkFile($source, $dest, $addVdir = true) { + public + function simpleCopyLinkFile($source, $dest, $addVdir = true) { if ($addVdir) { $dest = $this->vdir . '/' . $dest; } @@ -1597,7 +1615,8 @@ class wsHTML5Compiler { $this->copy($source, $dest); } - public function copyLinkFile($source, $dest, $video = false) { + public + function copyLinkFile($source, $dest, $video = false) { if ($video && $this->book->parametres->mobileVideosPath != '') { } @@ -1628,7 +1647,8 @@ class wsHTML5Compiler { } } - public function __destruct() { + public + function __destruct() { } -- 2.39.5