]> _ Git - fluidbook-toolbox.git/commitdiff
wip #6727 @0.75
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 14 Feb 2024 09:42:31 +0000 (10:42 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 14 Feb 2024 09:42:31 +0000 (10:42 +0100)
app/Fluidbook/Compiler/Compiler.php
app/Fluidbook/Compiler/Images.php
app/Models/FluidbookDocument.php
app/Models/Traits/ToolboxSettings.php

index dd67b77b6ed9da5037fd239cd45fb812224df97d..cd12ffbbaa4de4415fd1cf39742e84c5f4fa7f46 100644 (file)
@@ -491,6 +491,7 @@ class Compiler extends Base implements CompilerInterface, IVirtualDirectoryError
         $this->themeSettings->usePageEdges = false;
     }
 
+
     public function initConfig()
     {
         if (!$this->scormVariant) {
@@ -666,24 +667,6 @@ class Compiler extends Base implements CompilerInterface, IVirtualDirectoryError
         $this->pageLabels[$label] = $page;
     }
 
-    public function getResolutions()
-    {
-        return self::getBookResolutions($this->getFluidbook());
-    }
-
-
-    public static function getBookResolutions($book)
-    {
-        $maxRes = min(self::MAX_RES, $book->settings['maxResolution']);
-        $res = [];
-        if ($maxRes == self::MAX_RES) {
-            $res = [150, self::MAX_RES];
-        } else if ($maxRes <= 150) {
-            $res = [$maxRes];
-        }
-        return $res;
-    }
-
     public function getCssScale()
     {
         return $this->cssScale;
index 3eb7cfa6fc66b44e0e97db70d3e4026f90dfe0eb..d3ae5db285a169909e1b99fba176aab9a3d31791 100644 (file)
@@ -2,6 +2,7 @@
 
 namespace App\Fluidbook\Compiler;
 
+use App\Models\FluidbookPublication;
 use Cubist\Util\CommandLine;
 use Cubist\Util\Files\Files;
 use Cubist\Util\Graphics\Image;
@@ -9,6 +10,28 @@ use Cubist\Util\Graphics\Image;
 trait Images
 {
 
+    public function getResolutions()
+    {
+        return self::getBookResolutions($this->getFluidbook());
+    }
+
+
+    /**
+     * @param $book FluidbookPublication
+     * @return array
+     */
+    public static function getBookResolutions($book)
+    {
+        $maxRes = min(self::MAX_RES, $book->getSettings()->maxResolution);
+        $res = [];
+        if ($maxRes == self::MAX_RES) {
+            $res = [150, self::MAX_RES];
+        } else if ($maxRes <= 150) {
+            $res = [$maxRes];
+        }
+        return $res;
+    }
+
     protected function writeImages()
     {
         $compositionCached = $this->compositionCached();
index 232324041f5c7e9baefac4204d6ed6c9b4d0af2e..3914227df5405b14eac4d69004fd00683256e934 100644 (file)
@@ -199,7 +199,7 @@ class FluidbookDocument extends ToolboxModel
 
     public function fixPDF()
     {
-        return Farm::fixPDF($this->getPDFSource('original'), $this->getPDFSource('fixed'));
+        return Farm::fixPDF($this->getPDFSource('original'), $this->getPDFSource('fixed', false));
     }
 
     public function splitPDF()
@@ -462,24 +462,33 @@ class FluidbookDocument extends ToolboxModel
         return $this->_getTextBasePath($mode, $ignoreSeparators) . $prefix . $type . $page . '.txt';
     }
 
-    public function getPDFSource($type = 'crop'): string
+    public function getPDFSource($type = 'crop', $checkIfExists = true): string
     {
-        return $this->path() . $type . '.pdf';
+        $res = $this->path() . $type . '.pdf';
+        if ($checkIfExists && !file_exists($res)) {
+            if ($type === 'crop') {
+                $this->lnCrop();
+            } else if ($type === 'fixed') {
+                $this->fixPDF();
+            }
+        }
+
+        return $res;
     }
 
     public function cutDocument($mode)
     {
-        Farm::cutPDF($this->getPDFSource('fixed'), $mode, $this->getPDFSource());
+        Farm::cutPDF($this->getPDFSource('fixed'), $mode, $this->getPDFSource('crop', false));
     }
 
     public function trimDocument()
     {
-        Farm::trimPDF($this->getPDFSource('fixed'), $this->getPDFSource());
+        Farm::trimPDF($this->getPDFSource('fixed'), $this->getPDFSource('crop', false));
     }
 
     public function lnCrop()
     {
-        link($this->getPDFSource('fixed'), $this->getPDFSource());
+        link($this->getPDFSource('fixed'), $this->getPDFSource('crop', false));
     }
 
     protected function isCropped()
index 5232af65c7697192bcbb8929af2f675e738cb273..4cca4ce1fea6466a8046a9f948d4062b186fe449 100644 (file)
@@ -22,7 +22,6 @@ trait ToolboxSettings
     {
         if (null === $this->_settingsData) {
             $this->_settingsData = $this->getPageData();
-            $this->_settingsData->setOffsetPrefix('settings.');
         }
         return $this->_settingsData;
     }