]> _ Git - cubeextranet.git/commitdiff
fix #1622 @1.5
authorvincent@cubedesigners.com <vincent@cubedesigners.com@f5622870-0f3c-0410-866d-9cb505b7a8ef>
Fri, 25 Aug 2017 14:57:01 +0000 (14:57 +0000)
committervincent@cubedesigners.com <vincent@cubedesigners.com@f5622870-0f3c-0410-866d-9cb505b7a8ef>
Fri, 25 Aug 2017 14:57:01 +0000 (14:57 +0000)
fluidbook/tools/fwstk/.idea/workspace.xml
fluidbook/tools/scour.php [deleted file]
inc/ws/Metier/class.ws.document.php
inc/ws/Util/class.ws.tools.php
inc/ws/Util/html5/master/class.ws.html5.compiler.php

index e7d5a8aee934520956d4ccaffe268c11be23e3ef..cf8bfa5018ce5a962636be9ad62d194705987b49 100644 (file)
       <workItem from="1503492135605" duration="9205000" />
       <workItem from="1503572393130" duration="1293000" />
       <workItem from="1503582869459" duration="2692000" />
-      <workItem from="1503667361871" duration="357000" />
+      <workItem from="1503667361871" duration="440000" />
     </task>
     <task id="LOCAL-00001" summary="wip #1111 @0.5">
       <created>1487172253077</created>
     <servers />
   </component>
   <component name="TimeTrackingManager">
-    <option name="totallyTimeSpent" value="41503000" />
+    <option name="totallyTimeSpent" value="41586000" />
   </component>
   <component name="ToolWindowManager">
     <frame x="-8" y="-8" width="1936" height="1056" extended-state="6" />
-    <editor active="true" />
     <layout>
       <window_info id="Palette" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="3" side_tool="false" content_ui="tabs" />
       <window_info id="TODO" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" show_stripe_button="true" weight="0.33" sideWeight="0.5" order="6" side_tool="false" content_ui="tabs" />
diff --git a/fluidbook/tools/scour.php b/fluidbook/tools/scour.php
deleted file mode 100644 (file)
index edb0a7f..0000000
+++ /dev/null
@@ -1,19 +0,0 @@
-#!/usr/bin/php
-<?php
-$dir = $argv[1];
-$dr = opendir($dir);
-while ($file = readdir($dr)) {
-       $f = $dir . '/' . $file;
-       if (preg_match('|tp([0-9]*)\.svg|i', $file, $matches)) {
-               $d = $dir . '/to' . $matches[1] . '.svg';
-       } else if (preg_match('|fp([0-9]*)\.svg|i', $file, $matches)) {
-               $d = $dir . '/fo' . $matches[1] . '.svg';
-       } else {
-               continue;
-       }
-       
-       $cmd = "/usr/local/bin/svgcleaner --paths-coordinates-precision 3 --copy-on-error true $f $d";
-
-       echo $cmd . "\n";
-       echo `$cmd` . "\n";
-}
index ec261bf832c556f92b5d8d14d18c02864f7cfc01..0991b9dc3522b14dfc5e1e4f78a2612d2fb73b2d 100644 (file)
@@ -334,22 +334,12 @@ class wsDocument extends cubeMetier {
                for ($i = 1; $i <= $this->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) {
index a5042f77438249100446d9451ef2707fd96c1ee2..a19475506ca779edd689345ddc2d9615ba4e7a93 100644 (file)
@@ -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;
index 72c63ffbaa703b2e7a2c8c28d97c2868a96a1db6..0856d4f9d197563013c6f734b1b3baa48d104540 100644 (file)
@@ -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() {
 
        }