From c65e44ab869189f9cf4863f2ebb66d1cefd5cc89 Mon Sep 17 00:00:00 2001 From: "vincent@cubedesigners.com" Date: Mon, 3 Dec 2018 17:23:26 +0000 Subject: [PATCH] fix #2389 @1 --- inc/ws/Metier/class.ws.document.php | 24 ++++++++------ inc/ws/Util/class.ws.tools.php | 3 -- .../html5/master/class.ws.html5.compiler.php | 33 ++++++++++++------- 3 files changed, 35 insertions(+), 25 deletions(-) diff --git a/inc/ws/Metier/class.ws.document.php b/inc/ws/Metier/class.ws.document.php index 75b9d96d8..7ec94035e 100644 --- a/inc/ws/Metier/class.ws.document.php +++ b/inc/ws/Metier/class.ws.document.php @@ -83,6 +83,13 @@ class wsDocument extends cubeMetier } } + public function getCroppedPDF(){ + if(!file_exists($this->cropped)){ + return $this->in; + } + return $this->cropped; + } + public function copyOriginalFromUpload($tmp_file) { move_uploaded_file($tmp_file, $this->in); @@ -315,7 +322,7 @@ class wsDocument extends cubeMetier mkdir($this->out . '/pdf'); $pdftk = new cubeCommandLine('pdftk'); $pdftk->setPath(CONVERTER_PATH); - $pdftk->setArg(null, $this->cropped); + $pdftk->setArg(null, $this->getCroppedPDF()); $pdftk->setArg(null, 'burst'); $pdftk->setArg(null, 'output'); $pdftk->setArg(null, $this->out . 'pdf/p%d.pdf'); @@ -393,7 +400,7 @@ class wsDocument extends cubeMetier { $fwstk = new cubeCommandLine('fwstk.sh'); $fwstk->setPath(CONVERTER_PATH); - $fwstk->setArg('--input ' . $this->cropped); + $fwstk->setArg('--input ' . $this->getCroppedPDF()); $fwstk->setArg('--extractLinks ' . $this->out . 'p%d.csv'); $fwstk->setArg('--threads 1'); $fwstk->execute(); @@ -404,7 +411,7 @@ class wsDocument extends cubeMetier { $fwstk = new cubeCommandLine('fwstk.sh'); $fwstk->setPath(CONVERTER_PATH); - $fwstk->setArg('--input ' . $this->cropped); + $fwstk->setArg('--input ' . $this->getCroppedPDF()); $fwstk->setArg('--layout ' . $this->html . 'p%d.fby'); $fwstk->setArg('--cmaps ' . $this->html); $fwstk->setArg('--fonts' . $this->out . 'fonts/web/'); @@ -447,7 +454,7 @@ class wsDocument extends cubeMetier { $error = false; if (is_null($in)) { - $in = $this->cropped; + $in = $this->getCroppedPDF(); } // Delete all old files $res = $this->out . $prefix . $page . '.jpg'; @@ -477,7 +484,7 @@ class wsDocument extends cubeMetier protected function makeShotGS($page, $prefix = '', $resolution = 72, $quality = 90, $antialiasing = 4, $in = null) { if (is_null($in)) { - $in = $this->cropped; + $in = $this->getCroppedPDF(); } // Fabrication des thumbanails avec ghostscript $gs = new cubeCommandLine('gs', null, true); @@ -515,7 +522,7 @@ class wsDocument extends cubeMetier protected function makeShotPNM($page, $prefix = '', $resolution = 72, $quality = 90, $antialiasing = 4, $in = null, $texts = true) { if (is_null($in)) { - $in = $this->cropped; + $in = $this->getCroppedPDF(); } $tmp = cubeFiles::tempnam(); @@ -653,10 +660,7 @@ class wsDocument extends cubeMetier public function makeSVGFile($page) { $svgFile = $this->out . '/html/fp' . $page . '.svg'; - $source = $this->cropped; - if (!file_exists($this->cropped)) { - $source = $this->in; - } + $source = $this->getCroppedPDF(); $pdftocairo = new cubeCommandLine('pdftocairo'); $pdftocairo->setPath(CONVERTER_PATH); diff --git a/inc/ws/Util/class.ws.tools.php b/inc/ws/Util/class.ws.tools.php index 548fb5a24..dfb2dbca2 100644 --- a/inc/ws/Util/class.ws.tools.php +++ b/inc/ws/Util/class.ws.tools.php @@ -182,7 +182,6 @@ class wsTools self::$_r = $resolution; $osvg = preg_replace_callback('|\]*)\>|', 'wsTools::optimizeRaster', $svg); $ofname = sprintf($optimized, '-' . $resolution); - echo $ofname . "\n"; file_put_contents($ofname, $osvg); } } @@ -207,11 +206,9 @@ class wsTools preg_match_all('/([\d\-\.]+)/', $attrs['transform'], $ma); $values = $ma[0]; $scale = max($values[0], $values[1]); - } $resolutionScale = ($iw / $attrs['width']) * $scale * (self::$_r / 72); - echo $resolutionScale . "\n"; $dw = round($resolutionScale * $iw); $dh = round($resolutionScale * $ih); 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 a776002bc..bd43ced8d 100644 --- a/inc/ws/Util/html5/master/class.ws.html5.compiler.php +++ b/inc/ws/Util/html5/master/class.ws.html5.compiler.php @@ -1422,6 +1422,27 @@ class wsHTML5Compiler $thisimagesvg = !$thisrasterize && $this->svg; $thisbackgroundPrefix = $thisrasterize ? ['t'] : $this->backgroundsPrefix; + foreach ($this->getResolutions() as $r) { + foreach ($thisbackgroundPrefix as $backgroundsPrefix) { + $srcPrefix = $backgroundsPrefix; + if ($backgroundsPrefix == 'p') { + $srcPrefix = 'h'; + } + $source = $docdir . 'html/' . $srcPrefix . $r . '-' . $infos['document_page'] . '.jpg'; + if (!file_exists($source)) { + if (!isset($doc) || $doc->document_id != $infos['document_id']) { + $dao = new wsDAODocument($core->con); + $doc = $dao->selectById($infos['document_id']); + } + $doc->makeHTML5Files($infos['document_page']); + } + $ok = $this->vdir->copy($source, 'data/background/' . $r . '/' . $backgroundsPrefix . $page . '.jpg'); + if (!$ok && $r = 300) { + $this->maxRes = 150; + } + } + } + if ($thisimagesvg) { $full = $docdir . 'html/fp' . $infos['document_page'] . '.svg'; $fullopt = $docdir . 'html/fo' . $infos['document_page'] . '%s.svg'; @@ -1446,18 +1467,6 @@ class wsHTML5Compiler } } - foreach ($this->getResolutions() as $r) { - foreach ($thisbackgroundPrefix as $backgroundsPrefix) { - $srcPrefix = $backgroundsPrefix; - if ($backgroundsPrefix == 'p') { - $srcPrefix = 'h'; - } - $ok = $this->vdir->copy($docdir . 'html/' . $srcPrefix . $r . '-' . $infos['document_page'] . '.jpg', 'data/background/' . $r . '/' . $backgroundsPrefix . $page . '.jpg'); - if (!$ok && $r = 300) { - $this->maxRes = 150; - } - } - } $thumb = false; if ($this->book->parametres->pdfThumbnails) { -- 2.39.5