From 0a9e3c667d55515de5080fc4b350f3c0a57ccef4 Mon Sep 17 00:00:00 2001 From: "vincent@cubedesigners.com" Date: Wed, 21 Mar 2012 16:46:51 +0000 Subject: [PATCH] --- inc/config.inc.php | 2 +- inc/ws/Metier/class.ws.document.php | 17 ++++++++-- inc/ws/Util/html5/class.ws.html5.compiler.php | 34 ++++++++++++------- 3 files changed, 37 insertions(+), 16 deletions(-) diff --git a/inc/config.inc.php b/inc/config.inc.php index ad7916d0b..f953cc453 100644 --- a/inc/config.inc.php +++ b/inc/config.inc.php @@ -10,7 +10,7 @@ define('SITE_PATH', WEBROOT . '/'); define('FONT_PATH', ROOT . '/fluidbook/fonts/'); define('FTPROOT', '/home/extranet/ftp/'); define('WINDOWS', false); -define('CONVERTER_PATH', '/bin:/usr/bin:/usr/local/bin:/home/extranet/www/fluidbook/tools:/usr/local/flex:/usr/local/secureSWF'); +define('CONVERTER_PATH', '/bin:/usr/bin:/usr/local/bin:/home/extranet/www/fluidbook/tools:/usr/local/flex:/usr/local/secureSWF:/usr/local/scour'); define('MXMLC_PATH', '/usr/local/flex/bin/mxmlc'); define('MXMLC_PATH_3', '/usr/local/flex_sdk_3.6/bin/mxmlc'); define('AS3_SOURCES', '/home/ws/sources/as3'); diff --git a/inc/ws/Metier/class.ws.document.php b/inc/ws/Metier/class.ws.document.php index 3705613fc..376aacb20 100644 --- a/inc/ws/Metier/class.ws.document.php +++ b/inc/ws/Metier/class.ws.document.php @@ -548,7 +548,7 @@ class wsDocument extends cubeMetier { public function makeSVGFile($page) { $svgFile = $this->out . '/html/p' . $page . '.svg'; - $svgzFile = $this->out . '/html/p' . $page . '.svgz'; + $svgOpt = $this->out . '/html/o' . $page . '.svg'; $pdf2svg = new cubeCommandLine('pdf2svg'); $pdf2svg->setPath(CONVERTER_PATH); @@ -559,7 +559,7 @@ class wsDocument extends cubeMetier { $this->addToLog($pdf2svg, true, $page); $svg = new DOMDocument(); - $svg->preserveWhiteSpace=false; + $svg->preserveWhiteSpace = false; $svg->load($svgFile); // Operations to delete @@ -572,7 +572,8 @@ class wsDocument extends cubeMetier { '//svg:defs/svg:image', '//svg:defs/svg:pattern', '/svg:svg/svg:g/svg:g[not(svg:use[@xlink:href])]', - '/svg:svg/svg:g/svg:path' + '/svg:svg/svg:g/svg:path', + '/svg:svg/svg:g/rect:path', ); global $svglog; @@ -592,6 +593,16 @@ class wsDocument extends cubeMetier { $this->addToLog(implode("\n", $svglog), false, $page); file_put_contents($svgFile, $svg->saveXML()); + + $scour = new cubeCommandLine('scour.py'); + $scour->setArg('shorten-ids'); + $scour->setArg('set-precision', '3'); + $scour->setArg('indent', 'none'); + $scour->setArg('create-groups'); + $scour->setArg('i', $svgFile); + $scour->setArg('o', $svgOpt); + $scour->setNohup(true); + $scour->execute(); } protected function checkObjectsNumber($file, $maxObjects, $page) { diff --git a/inc/ws/Util/html5/class.ws.html5.compiler.php b/inc/ws/Util/html5/class.ws.html5.compiler.php index 755ad37ad..a0741877c 100644 --- a/inc/ws/Util/html5/class.ws.html5.compiler.php +++ b/inc/ws/Util/html5/class.ws.html5.compiler.php @@ -58,7 +58,7 @@ class wsHTML5Compiler { protected $cssOneWidth; protected $cssOneHeight; protected $cssScale; - protected $cssSVGScale = 0.75; + protected $cssSVGScale; protected $optimalWidth = 567; protected $optimalHeight = 709; protected $additionalConfig = array(); @@ -102,12 +102,12 @@ class wsHTML5Compiler { $firstDoc = $daoDoc->selectById($this->pages[1]['document_id']); $size = $firstDoc->generalInfos['size']; - $this->width = round($size[0], 2); - $this->height = round($size[1], 2); + $this->width = round($size[0], 3); + $this->height = round($size[1], 3); $imagesize = getimagesize(WS_DOCS . '/' . $this->pages[1]['document_id'] . '/html/h150-' . $this->pages[1]['document_page'] . '.jpg'); - $this->pdf2htmlRatio = round(($imagesize[0] * 0.48) / $this->width, 2); + $this->pdf2htmlRatio = round(($imagesize[0] * 0.48) / $this->width, 3); $this->cssScale = min($this->optimalWidth / $this->width, $this->optimalHeight / $this->height); $this->cssOneScale = min(($this->optimalWidth * 2) / $this->width, $this->optimalHeight / $this->height); @@ -117,6 +117,8 @@ class wsHTML5Compiler { $this->cssOneWidth = $this->width * $this->cssOneScale; $this->cssOneHeight = $this->height * $this->cssOneScale; + + $this->cssSVGScale=0.75/2; $this->scale = 1; if ($this->book->parametres->zoomMode == 1) { @@ -454,13 +456,21 @@ class wsHTML5Compiler { foreach (self::$resolutions as $r) { mkdir($this->vdir . '/data/background/' . $r, 0777, true); } - $srcPrefix=$this->backgroundsPrefix; + $srcPrefix = $this->backgroundsPrefix; 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'); + $orig = WS_DOCS . '/' . $infos['document_id'] . '/html/p' . $infos['document_page'] . '.svg'; + $opt = WS_DOCS . '/' . $infos['document_id'] . '/html/o' . $infos['document_page'] . '.svg'; + + $svg = $orig; + if (file_exists($opt) && filesize($opt) > 0) { + $svg = $opt; + } + + $this->copy($svg, $this->vdir . '/data/contents/p' . $page . '.svg'); } foreach (self::$resolutions as $r) { $this->copy(WS_DOCS . '/' . $infos['document_id'] . '/html/' . $srcPrefix . $r . '-' . $infos['document_page'] . '.jpg', $this->vdir . '/data/background/' . $r . '/' . $this->backgroundsPrefix . $page . '.jpg'); @@ -496,9 +506,9 @@ class wsHTML5Compiler { $wm = ($this->width * $this->multiply) . 'px'; $hm = ($this->height * $this->multiply) . 'px'; $w = $cssWidth . 'px'; - $offsetLeft = round(($this->optimalWidth - $cssWidth) / 2, 2); + $offsetLeft = round(($this->optimalWidth - $cssWidth) / 2, 3); $offsetLeft2 = $offsetLeft * 2; - $offsetTop = round(($this->optimalHeight - $cssHeight) / 2, 2); + $offsetTop = round(($this->optimalHeight - $cssHeight) / 2, 3); $navTop = ($cssHeight - 40 - 100) / 2; $res[] = '#fluidbook{left:' . $offsetLeft . 'px;top:' . $offsetTop . 'px;}'; @@ -517,7 +527,7 @@ class wsHTML5Compiler { $res[] = '.background{' . $this->writeCSSUA('transform-origin', 'top left') . ';}'; foreach (self::$resolutions as $r) { - $ratio = round(72 / $r, 2) * $cssScale; + $ratio = round(72 / $r, 3) * $cssScale; $wr = $cssWidth / $ratio; $hr = $cssHeight / $ratio; @@ -530,9 +540,9 @@ class wsHTML5Compiler { $res[] = $br; } $texts = '.texts{' . $this->writeCSSUA('transform-origin', 'top left') . ';'; - $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.=$this->writeCSSUA('transform', 'scale(' . round((1 / $this->multiply) * $cssScale * $this->cssSVGScale, 3) . ')') . ';'; + $texts.='width:' . ($wm / $this->cssSVGScale) . '; max-width:' . ($wm / $this->cssSVGScale) . ';'; + $texts.='height:' . ($hm / $this->cssSVGScale) . '; max-height:' . ($hm / $this->cssSVGScale) . ';'; $texts.='}'; $res[] = $texts; -- 2.39.5