]> _ Git - fluidbook_tools.git/commitdiff
wait #5925 @1
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 10 May 2023 10:23:00 +0000 (12:23 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 10 May 2023 10:23:00 +0000 (12:23 +0200)
src/Compiler/CompilerInterface.php
src/Compiler/DummyCompiler.php
src/Links/DownloadPortionLink.php
src/Links/ZoomLink.php

index 7739e43b093cf06ba3651cd7e21f8b9d12a749cb..6bcb4fdac009b10f105399fbfd88c6d4aaa9c63a 100644 (file)
@@ -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);
index 39bbe0169f48542e5e92f7714e278f81ed938fd2..017e438a45c08e9b08a48d8b03051261ffb24419 100644 (file)
@@ -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();
+    }
 }
index 2a98b9cef0595b38bdb9e4d6f01006c96ef93101..40678a44d8fb9b875e5cc6aceeb5745638469b1f 100644 (file)
@@ -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() {
index 71c0a5080064686e13e8ecfb68da26875bbc82bf..08d86b5618ef873e1c84ee7ff59749cbe5c0f951 100644 (file)
@@ -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)) {