]> _ Git - fluidbook_tools.git/commitdiff
wait #6115 @0.5
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 6 Jul 2023 16:07:42 +0000 (18:07 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 6 Jul 2023 16:07:42 +0000 (18:07 +0200)
src/Compiler/Compiler.php
src/Compiler/CompilerInterface.php
src/Compiler/DummyCompiler.php
src/Links/ContentLink.php
src/Links/ImageLink.php
src/Links/Link.php
src/Links/ZoomLink.php

index 852fa50accf89393caaf202826720f66e56c6cc0..5329da035c4e9cbf4b1e9460d9851da390f5a033 100644 (file)
@@ -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();
     }
 
 
index 0f2bf4fed850ddc5ee7466e559913add8d9c8289..0747b22841de63215f579dc5bb9ba2618088e371 100644 (file)
@@ -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;
 }
index 67dca410f791dbbdc62fdb5bec91768e9be5b5a2..8f4ba1c1e4935f0c74b0ff4a875ae739ce4874da 100644 (file)
@@ -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.
     }
 
index 91d535f981eb4726e4073fa48e6d83ceff45fcbb..bc8120e1b36ce575dc03e87ea19f5e55ca6c02af 100644 (file)
@@ -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 ';
index 9448e8e6f7b2d5418abbaef7ae7fb343b911fb63..a75e72dcd298eed2573a5fd7902e5210533003d0 100644 (file)
@@ -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 '<div class="img" style="background-image:url(' . $this->getImageUrl() . ');"></div>';
         } else {
             return '<img src="' . $this->getImageUrl() . '" />';
index 1e6543bd40a567c4723f797896aaee2d2398282c..0812e3abfe5a49fc2fcca59bff3608ab29a30d69 100644 (file)
@@ -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() {
index 1c0216539c3eef278beaf8875e0d5dcffc5ec265..caff860a2350078ccc541ffde2a36663ac97b0e5 100644 (file)
@@ -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);
     }