]> _ Git - fluidbook_tools.git/commitdiff
wait #5926 @0.75
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 9 May 2023 18:45:06 +0000 (20:45 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 9 May 2023 18:45:06 +0000 (20:45 +0200)
src/Links/DownloadPortionLink.php
src/Links/ZoomLink.php

index 1ca07f61386aa62276e272ad59b43a483b042a15..2a98b9cef0595b38bdb9e4d6f01006c96ef93101 100644 (file)
@@ -9,7 +9,7 @@ class DownloadPortionLink extends FileLink {
     public function getURL() {
         $attributes = $this->getZoomAttributes();
         if (!$this->rightClone) {
-            ZoomLink::generateImage($attributes, $this->compiler, 'downloadportion', 'downloadportion');
+            ZoomLink::generateImage($attributes, $this->compiler, 'downloadportion', 'downloadportion', true);
         }
         return 'data/links/downloadportion_' . $attributes['id'] . '.jpg';
     }
@@ -20,21 +20,49 @@ class DownloadPortionLink extends FileLink {
             $pdf = $this->compiler->getWorkingDir() . '/' . $pdf;
         }
 
-        $res = [
+        $x = $this->left;
+        $y = $this->top;
+        $w = $this->width;
+        $h = $this->height;
+
+
+        if ($x < 0) {
+            $w -= $x;
+            $x = 0;
+        }
+        if ($y < 0) {
+            $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);
+        }
+        if ($y + $h > $maxHeight) {
+            $h -= ($y + $h - $maxHeight);
+        }
+
+        return [
             'id' => $this->id,
             'page' => $this->page,
             'maxzoom' => $this->compiler->getSetting('downloadPortionZoom', '8'),
             'group' => '',
             'group-count' => 0,
-            'width' => round($this->width),
-            'height' => round($this->height),
-            'x' => round($this->left),
-            'y' => round($this->top),
+            'width' => round($w),
+            'height' => round($h),
+            'x' => round($x),
+            'y' => round($y),
             'pdf' => $pdf,
             'border' => $this->border,
             'borderColor' => $this->borderColor,
         ];
-        return $res;
     }
 
     public function getAdditionnalContent() {
index 53c70cb15eaa1426c06b715ede88117adcba8790..71c0a5080064686e13e8ecfb68da26875bbc82bf 100644 (file)
@@ -3,10 +3,8 @@
 namespace Fluidbook\Tools\Links;
 
 use Cubist\Util\CommandLine\Imagemagick;
-use Cubist\Util\Files\Files;
 use Cubist\Util\Graphics\PDF;
 use Cubist\Util\Text;
-use Fluidbook\Tools\Compiler\Compiler;
 use Fluidbook\Tools\Compiler\CompilerInterface;
 
 class ZoomLink extends NormalLink {
@@ -95,7 +93,7 @@ class ZoomLink extends NormalLink {
      * @param $save
      * @return void
      */
-    public static function generateImage($attributes, $compiler, $cachedir, $save) {
+    public static function generateImage($attributes, $compiler, $cachedir, $save, $trim = false) {
 
         $maxzoom = $attributes['maxzoom']; // Max zoom level might not always be set in the link editor
         $maxzoom = max(2, min($maxzoom, 20));
@@ -165,6 +163,14 @@ class ZoomLink extends NormalLink {
             $both = $leftfile;
         }
 
+        if ($trim) {
+            $trimmed = str_replace('.jpg', '.trim.jpg', $both);
+            if (!file_exists($trimmed) || filemtime($trimmed) < filemtime($both)) {
+                Imagemagick::trim($both, $trimmed);
+            }
+            $both = $trimmed;
+        }
+
         //                if (isset($attributes['border']) && $attributes['border'] > 0) {
         //                    $tmp = Files::tempnam() . '.jpg';
         //                    Imagemagick::addBorder($both, $tmp, $attributes['border'], $attributes['borderColor']);