From 6bff7ce28157a12f2d15bed577b7db915ee3cb7d Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Thu, 6 Jul 2023 18:07:42 +0200 Subject: [PATCH] wait #6115 @0.5 --- src/Compiler/Compiler.php | 14 +++++++------- src/Compiler/CompilerInterface.php | 10 +++++----- src/Compiler/DummyCompiler.php | 4 ++-- src/Links/ContentLink.php | 4 ++-- src/Links/ImageLink.php | 21 +++++++++------------ src/Links/Link.php | 8 ++++++++ src/Links/ZoomLink.php | 14 ++++++++++++-- 7 files changed, 45 insertions(+), 30 deletions(-) diff --git a/src/Compiler/Compiler.php b/src/Compiler/Compiler.php index 852fa50..5329da0 100644 --- a/src/Compiler/Compiler.php +++ b/src/Compiler/Compiler.php @@ -284,12 +284,12 @@ class Compiler implements ShouldQueue, ShouldBeUnique, CompilerInterface { return $this->getWidth() * $this->getHeight(); } - public function getWidth() { - return $this->getSourceOfPage(1)->getSource()->getDocument()->getWidth(); + public function getWidth($page = 1) { + return $this->getSourceOfPage($page)->getSource()->getDocument()->getWidth(); } - public function getHeight() { - return $this->getSourceOfPage(1)->getSource()->getDocument()->getHeight(); + public function getHeight($page = 1) { + return $this->getSourceOfPage($page)->getSource()->getDocument()->getHeight(); } public function addVideoJs() { @@ -363,12 +363,12 @@ class Compiler implements ShouldQueue, ShouldBeUnique, CompilerInterface { // TODO: Implement pushSetting() method. } - public function getWidthForLinks() { + public function getWidthForLinks($page = 1) { return $this->getWidth() / $this->getLinkScale(); } - public function getHeightForLinks() { - return $this->getHeight() / $this->getLinkScale(); + public function getHeightForLinks($page = 1) { + return $this->getHeight($page) / $this->getLinkScale(); } diff --git a/src/Compiler/CompilerInterface.php b/src/Compiler/CompilerInterface.php index 0f2bf4f..0747b22 100644 --- a/src/Compiler/CompilerInterface.php +++ b/src/Compiler/CompilerInterface.php @@ -36,13 +36,13 @@ interface CompilerInterface { public function page_path($page, $path = ''): string; - public function getWidth(); + public function getWidth($page = 1); - public function getWidthForLinks(); + public function getWidthForLinks($page = 1); - public function getHeight(); + public function getHeight($page = 1); - public function getHeightForLinks(); + public function getHeightForLinks($page = 1); public function virtualToPhysical($virtual); @@ -66,5 +66,5 @@ interface CompilerInterface { public function getPageNumber(): int; - public function getQuality():int; + public function getQuality(): int; } diff --git a/src/Compiler/DummyCompiler.php b/src/Compiler/DummyCompiler.php index 67dca41..8f4ba1c 100644 --- a/src/Compiler/DummyCompiler.php +++ b/src/Compiler/DummyCompiler.php @@ -116,11 +116,11 @@ class DummyCompiler implements CompilerInterface { // TODO: Implement addSEOArticle() method. } - public function getWidthForLinks() { + public function getWidthForLinks($page=1) { // TODO: Implement getWidthForLinks() method. } - public function getHeightForLinks() { + public function getHeightForLinks($page=1) { // TODO: Implement getHeightForLinks() method. } diff --git a/src/Links/ContentLink.php b/src/Links/ContentLink.php index 91d535f..bc8120e 100644 --- a/src/Links/ContentLink.php +++ b/src/Links/ContentLink.php @@ -15,7 +15,7 @@ class ContentLink extends Link { public function getAdditionnalContent() { $res = parent::getAdditionnalContent(); if ($this->allowsAnimation) { - $animations = self::parseAnimations($this->image_rollover); + $animations = self::parseAnimations($this->image_rollover ?? 'none'); foreach ($animations as $animation) { if (isset($animation['blendmode'])) { $this->blendmode = $animation['blendmode']; @@ -28,7 +28,7 @@ class ContentLink extends Link { $this->addzindex = $animation['addzindex']; } } - if($animations) { + if ($animations) { $res .= ' data-animations="' . htmlspecialchars(json_encode($animations), ENT_QUOTES) . '" '; if ($this->_isHiddenFirst($animations)) { $res .= ' data-animation-hide '; diff --git a/src/Links/ImageLink.php b/src/Links/ImageLink.php index 9448e8e..a75e72d 100644 --- a/src/Links/ImageLink.php +++ b/src/Links/ImageLink.php @@ -2,33 +2,30 @@ namespace Fluidbook\Tools\Links; -class ImageLink extends ContentLink -{ +class ImageLink extends ContentLink { - public function getImageUrl() - { + public function getImageUrl() { return Link::getUniversalLocation($this->to, false); } - public function getCSS() - { + public function getCSS() { $res = parent::getCSS(); $this->copyExternalFile($this->to); return $res; } - public function getAdditionnalContent() - { + public function getAdditionnalContent() { $res = parent::getAdditionnalContent(); $res .= ' data-image="' . $this->getImageUrl() . '"'; - $res .= ' data-rollover="' . $this->image_rollover . '"'; + if (isset($this->image_rollover)) { + $res .= ' data-rollover="' . $this->image_rollover . '"'; + } return $res; } - public function getHTMLContent() - { + public function getHTMLContent() { // For zoomin & zoomout animations - if (stristr($this->image_rollover, 'type=zoom')) { + if (isset($this->image_rollover) && stristr($this->image_rollover, 'type=zoom')) { return '
'; } else { return ''; diff --git a/src/Links/Link.php b/src/Links/Link.php index 1e6543b..0812e3a 100644 --- a/src/Links/Link.php +++ b/src/Links/Link.php @@ -295,6 +295,14 @@ class Link { $a[$k] = floatval($v); } } + if ($a['width'] < 0) { + $a['left'] += $a['width']; + $a['width'] *= -1; + } + if ($a['height'] < 0) { + $a['top'] += $a['height']; + $a['height'] *= -1; + } } public function getSurface() { diff --git a/src/Links/ZoomLink.php b/src/Links/ZoomLink.php index 1c02165..caff860 100644 --- a/src/Links/ZoomLink.php +++ b/src/Links/ZoomLink.php @@ -8,6 +8,7 @@ use Cubist\Util\Graphics\PDF; use Cubist\Util\Text; use Fluidbook\Tools\Compiler\CompilerInterface; use Fluidbook\Tools\SVG\SVGTools; +use Illuminate\Support\Facades\Log; class ZoomLink extends NormalLink { protected $maxzoom_default = 2; @@ -138,6 +139,9 @@ class ZoomLink extends NormalLink { $extractPage = $attributes['page']; } + $extractOptions['texts'] = true; + $extractOptions['background'] = true; + $extractOptions['format'] = 'jpeg'; $ext = 'jpg'; if (isset($attributes['layer'])) { @@ -156,8 +160,8 @@ class ZoomLink extends NormalLink { $cache = $compiler->getCacheDir("zoomarea/" . $cachedir); - $leftHeight = min($h, $compiler->getHeightForLinks() - $y); - $leftWidth = min($w, $compiler->getWidthForLinks() - $x); + $leftHeight = min($h, $compiler->getHeightForLinks($attributes['page']) - $y); + $leftWidth = min($w, $compiler->getWidthForLinks($attributes['page']) - $x); $leftArea = ['x' => $x, 'y' => $y, 'width' => $leftWidth, 'height' => $leftHeight]; @@ -165,6 +169,9 @@ class ZoomLink extends NormalLink { $extractPage, $leftArea, null, $extractOptions, $cache); + if (!file_exists($leftfile)) { + throw new \Exception('Failed to generate image with ' . json_encode($attributes)); + } if ($attributes['page'] % 2 === 0 && ($x + $w) > ($bookwidth + 1) && $compiler->isDoublePage() && $attributes['page'] + 1 <= $compiler->getPageNumber()) { if (!isset($attributes['pdf']) || !$attributes['pdf']) { @@ -217,6 +224,9 @@ class ZoomLink extends NormalLink { // dd($both); + if (!file_exists($both)) { + Log::error('Failed generate image ' . json_encode($attributes)); + } $dest = 'data/links/' . $save . '_' . $attributes['id'] . '.' . $ext; $compiler->simpleCopyLinkFile($both, $dest); } -- 2.39.5