From c2bdcb08621577cf6cd97c8f5001e30904730125 Mon Sep 17 00:00:00 2001 From: "vincent@cubedesigners.com" Date: Fri, 27 Sep 2019 13:08:54 +0000 Subject: [PATCH] b --- inc/ws/Metier/class.ws.document.php | 51 +++++++++++++++++-- .../html5/master/class.ws.html5.compiler.php | 26 ++++++---- 2 files changed, 64 insertions(+), 13 deletions(-) diff --git a/inc/ws/Metier/class.ws.document.php b/inc/ws/Metier/class.ws.document.php index adab7979b..0941132da 100644 --- a/inc/ws/Metier/class.ws.document.php +++ b/inc/ws/Metier/class.ws.document.php @@ -34,6 +34,7 @@ class wsDocument extends cubeMetier protected $out; protected $in; protected $html; + protected $mf; protected $uncompressed; protected $log; protected $common_log_pointer; @@ -65,6 +66,7 @@ class wsDocument extends cubeMetier $this->out = wsDocument::getDir($this->document_id); $this->log = $this->out . '/logs/'; $this->html = $this->out . '/html/'; + $this->mf = $this->out . '/mf/'; $this->in = $this->out . 'original.pdf'; $this->uncompressed = $this->out . 'uncompressed.pdf'; $this->infos = $this->out . 'infos.txt'; @@ -75,10 +77,14 @@ class wsDocument extends cubeMetier if (!file_exists($this->html)) { mkdir($this->html, 0755); } + if (!file_exists($this->mf)) { + mkdir($this->mf, 0777); + } + $this->cropped = $this->out . 'crop.pdf'; $this->pages_log_pointers = array(); - if (is_null($this->conversionInfos)) { + if ($this->conversionInfos === null) { $this->conversionInfos = new wsDocumentConversionInfos(); } } @@ -379,7 +385,6 @@ class wsDocument extends cubeMetier $this->addToLog('Processing page #' . $page); $this->makeMiniShot($page); $this->makeSWFFiles($page); - $this->makeHTML5Files($page); } } @@ -428,6 +433,11 @@ class wsDocument extends cubeMetier return sqrt($a4surface / $docSurface); } + public function getMobileFirstRatio() + { + return 0.48 * (620 / $this->generalInfos['size'][0]); + } + public function makeMiniShot($page) { $this->makeShotFixedWidth($page, 'p', 500, 65, 4, 'PNM'); @@ -454,7 +464,7 @@ class wsDocument extends cubeMetier public function makeShot($page, $prefix = '', $resolution = 72, $quality = 90, $antialiasing = 4, $method = 'PNM', $in = null) { $error = false; - if (is_null($in)) { + if ($in === null) { $in = $this->getCroppedPDF(); } // Delete all old files @@ -658,6 +668,17 @@ class wsDocument extends cubeMetier $this->makeSVGFile($page); } + public function makeMobileFirstFiles($page) + { + // Then make HD background shots + $resolutions = array(300 => 85, 150 => 85, 36 => 85); + $rratio = $this->getMobileFirstRatio(); + foreach ($resolutions as $r => $q) { + $this->makeShotPNM($page, 'mf/h' . $r . '-', $r * $rratio, $q, 4, null, false); + $this->makeShotPNM($page, 'mf/t' . $r . '-', $r * $rratio, $q, 4, null, true); + } + } + public function makeSVGFile($page) { $svgFile = $this->out . '/html/fp' . $page . '.svg'; @@ -1074,4 +1095,28 @@ class wsDocument extends cubeMetier self::$_docsDir[$id] = $new; return $new; } + + public static function makeHTML5FilesIfNotExists($document_id, $document_page) + { + global $core; + + $path = self::getDir($document_id) . '/html/h150-' . $document_page . '.jpg'; + if (!file_exists($path)) { + $dao = new wsDAODocument($core->con); + $doc = $dao->selectById($document_id); + $doc->makeHTML5Files($document_page); + } + } + + public static function makeMobileFirstFilesIfNotExists($document_id, $document_page) + { + global $core; + + $path = self::getDir($document_id) . '/mf/h150-' . $document_page . '.jpg'; + if (!file_exists($path)) { + $dao = new wsDAODocument($core->con); + $doc = $dao->selectById($document_id); + $doc->makeMobileFirstFiles($document_page); + } + } } \ No newline at end of file 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 ce4e3a33f..2da83b6af 100644 --- a/inc/ws/Util/html5/master/class.ws.html5.compiler.php +++ b/inc/ws/Util/html5/master/class.ws.html5.compiler.php @@ -276,7 +276,10 @@ class wsHTML5Compiler $this->width = round($size[0], 3); $this->height = round($size[1], 3); - $imagesize = CubeIT_Image::getimagesize(wsDocument::getDir($this->pages[1]['document_id']) . 'html/h150-' . $this->pages[1]['document_page'] . '.jpg'); + wsDocument::makeHTML5FilesIfNotExists($this->pages[1]['document_id'], $this->pages[1]['document_page']); + $firstJpeg = wsDocument::getDir($this->pages[1]['document_id']) . 'html/h150-' . $this->pages[1]['document_page'] . '.jpg'; + + $imagesize = CubeIT_Image::getimagesize($firstJpeg); $this->pdf2htmlRatio = round(($imagesize[0] * 0.48) / $this->width, 3); $this->cssScale = $this->z * min($this->optimalWidth / $this->width, $this->optimalHeight / $this->height); @@ -1608,6 +1611,14 @@ class wsHTML5Compiler $rasterizePages = $this->config->rasterizePages; $this->config->pagesDimensions = []; + if ($this->book->parametres->mobileNavigationType === 'mobilefirst') { + $makeFunction = 'makeMobileFirstFilesIfNotExists'; + $imdir = 'mf'; + } else { + $makeFunction = 'makeHTML5FilesIfNotExists'; + $imdir = 'html'; + } + $thumbs = array(); foreach ($this->pages as $page => $infos) { $docdir = wsDocument::getDir($infos['document_id']); @@ -1616,20 +1627,15 @@ class wsHTML5Compiler $thisimagesvg = !$thisrasterize && $this->svg; $thisbackgroundPrefix = $thisrasterize ? ['t'] : $this->backgroundsPrefix; + wsDocument::$makeFunction($infos['document_id'], $infos['document_page']); + foreach ($this->getResolutions() as $r) { foreach ($thisbackgroundPrefix as $backgroundsPrefix) { $srcPrefix = $backgroundsPrefix; - if ($backgroundsPrefix == 'p') { + 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']); - } + $source = $docdir . $imdir . '/' . $srcPrefix . $r . '-' . $infos['document_page'] . '.jpg'; if ($r == 150 && file_exists($source)) { $d = getimagesize($source); $this->config->pagesDimensions[$page] = array($this->cssWidth, $d[1] * ($this->cssWidth / $d[0])); -- 2.39.5