From: Vincent Vanwaelscappel Date: Tue, 9 May 2023 18:45:06 +0000 (+0200) Subject: wait #5926 @0.75 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=2f6fa0a9a7039df6aba6d7635ec84f51c31902d8;p=fluidbook_tools.git wait #5926 @0.75 --- diff --git a/src/Links/DownloadPortionLink.php b/src/Links/DownloadPortionLink.php index 1ca07f6..2a98b9c 100644 --- a/src/Links/DownloadPortionLink.php +++ b/src/Links/DownloadPortionLink.php @@ -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() { diff --git a/src/Links/ZoomLink.php b/src/Links/ZoomLink.php index 53c70cb..71c0a50 100644 --- a/src/Links/ZoomLink.php +++ b/src/Links/ZoomLink.php @@ -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']);