From e10e172a49da0e46081586ab02eb911b85bb34d4 Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Wed, 10 May 2023 12:23:00 +0200 Subject: [PATCH] wait #5925 @1 --- src/Compiler/CompilerInterface.php | 4 +++ src/Compiler/DummyCompiler.php | 8 ++++++ src/Links/DownloadPortionLink.php | 40 ++++++++++++++++++------------ src/Links/ZoomLink.php | 24 +++++++++++------- 4 files changed, 51 insertions(+), 25 deletions(-) diff --git a/src/Compiler/CompilerInterface.php b/src/Compiler/CompilerInterface.php index 7739e43..6bcb4fd 100644 --- a/src/Compiler/CompilerInterface.php +++ b/src/Compiler/CompilerInterface.php @@ -52,6 +52,10 @@ interface CompilerInterface { public function isOnePage(): bool; + public function isSinglePage(): bool; + + public function isDoublePage(): bool; + public function simpleCopyLinkFile($source, $dest); public function unzipFile($file, $moveAssets = false, $baseDir = null, $junkPaths = false); diff --git a/src/Compiler/DummyCompiler.php b/src/Compiler/DummyCompiler.php index 39bbe01..017e438 100644 --- a/src/Compiler/DummyCompiler.php +++ b/src/Compiler/DummyCompiler.php @@ -123,4 +123,12 @@ class DummyCompiler implements CompilerInterface { public function getHeightForLinks() { // TODO: Implement getHeightForLinks() method. } + + public function isSinglePage(): bool { + return $this->isOnePage(); + } + + public function isDoublePage(): bool { + return !$this->isSinglePage(); + } } diff --git a/src/Links/DownloadPortionLink.php b/src/Links/DownloadPortionLink.php index 2a98b9c..40678a4 100644 --- a/src/Links/DownloadPortionLink.php +++ b/src/Links/DownloadPortionLink.php @@ -24,24 +24,29 @@ class DownloadPortionLink extends FileLink { $y = $this->top; $w = $this->width; $h = $this->height; + $page = $this->page; + $maxWidth = $this->compiler->getWidthForLinks(); + if ($this->compiler->isDoublePage() && $x >= $maxWidth && $page % 2 === 0) { + $x -= $maxWidth; + $page++; + } + + if ($this->page % 2 === 0 && $this->compiler->isDoublePage()) { + $maxWidth *= 2; + } + + $maxHeight = $this->compiler->getHeightForLinks(); if ($x < 0) { - $w -= $x; + $w += $x; $x = 0; } if ($y < 0) { - $h -= $y; + $h += $y; $y = 0; } - $maxWidth = $this->compiler->getWidthForLinks(); - - if ($this->page % 2 === 0 && !$this->compiler->isOnePage()) { - $maxWidth *= 2; - } - $maxHeight = $this->compiler->getHeightForLinks(); - if ($x + $w > $maxWidth) { $w -= ($x + $w - $maxWidth); } @@ -49,20 +54,23 @@ class DownloadPortionLink extends FileLink { $h -= ($y + $h - $maxHeight); } - return [ - 'id' => $this->id, - 'page' => $this->page, + $res = [ + 'id' => $this->uid, + 'page' => $page, 'maxzoom' => $this->compiler->getSetting('downloadPortionZoom', '8'), 'group' => '', 'group-count' => 0, - 'width' => round($w), - 'height' => round($h), - 'x' => round($x), - 'y' => round($y), + 'width' => $w, + 'height' => $h, + 'x' => $x, + 'y' => $y, 'pdf' => $pdf, 'border' => $this->border, 'borderColor' => $this->borderColor, + 'quality' => 80, ]; + + return $res; } public function getAdditionnalContent() { diff --git a/src/Links/ZoomLink.php b/src/Links/ZoomLink.php index 71c0a50..08d86b5 100644 --- a/src/Links/ZoomLink.php +++ b/src/Links/ZoomLink.php @@ -3,6 +3,7 @@ namespace Fluidbook\Tools\Links; use Cubist\Util\CommandLine\Imagemagick; +use Cubist\Util\CommandLine\Poppler; use Cubist\Util\Graphics\PDF; use Cubist\Util\Text; use Fluidbook\Tools\Compiler\CompilerInterface; @@ -105,17 +106,22 @@ class ZoomLink extends NormalLink { // The Poppler::extractArea function accepts a resolution setting and uses that to determine the // scale factor on the extracted images. It does so by dividing by 72, so we can pass our own scale // factor by setting the resolution to 72 * $maxzoom - 'resolution' => 72 * 2 * $maxzoom + 'resolution' => Poppler::RESOLUTION_FACTOR * 2 * $maxzoom, ]; + if (isset($attributes['quality'])) { + $extractOptions['quality'] = $attributes['quality']; + } - // Round all link co-ordinates because there seems to be a problem with the the Workshop link editor - // where link "left" values (and maybe others) change fractionally upon saves. This causes problems later when - // extracting the zoom images from the PDF because it causes a cache-miss and the images are regenerated again. $x = $attributes['x']; $y = $attributes['y']; $w = $attributes['width']; $h = $attributes['height']; - $bookwidth = round($compiler->getWidthForLinks()); + $bookwidth = $compiler->getWidthForLinks(); + + if ($compiler->isDoublePage() && $x >= $bookwidth) { + $x -= $bookwidth; + $attributes['page']++; + } if (!isset($attributes['pdf']) || !$attributes['pdf']) { $pdfpath = $compiler->getPagePDFSource($attributes['page']); @@ -127,13 +133,13 @@ class ZoomLink extends NormalLink { $cache = $compiler->getCacheDir("zoomarea/" . $cachedir); + $leftArea = ['x' => $x, 'y' => $y, 'width' => $w, 'height' => $h]; $leftfile = PDF::extractArea($pdfpath, $extractPage, - array('x' => $x, 'y' => $y, 'width' => $w, 'height' => $h), + $leftArea, null, $extractOptions, $cache); - - if (($x + $w) > $bookwidth && !$compiler->isOnePage()) { + if (($x + $w) >= $bookwidth && $compiler->isDoublePage()) { if (!isset($attributes['pdf']) || !$attributes['pdf']) { $pdfpath = $compiler->getPagePDFSource($attributes['page'] + 1); $extractPage = 1; @@ -145,7 +151,7 @@ class ZoomLink extends NormalLink { $diff = ($w + $x) - $bookwidth; $rightfile = PDF::extractArea($pdfpath, $extractPage, - array('x' => 0, 'y' => $y, 'width' => $diff, 'height' => $h), + ['x' => 0, 'y' => $y, 'width' => $diff, 'height' => $h], null, $extractOptions, $cache); if (!file_exists($rightfile)) { -- 2.39.5