From 8f1d71ee9dde16b97de4a8c4673ba1109408d39a Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Wed, 14 Feb 2024 10:42:31 +0100 Subject: [PATCH] wip #6727 @0.75 --- app/Fluidbook/Compiler/Compiler.php | 19 +------------------ app/Fluidbook/Compiler/Images.php | 23 +++++++++++++++++++++++ app/Models/FluidbookDocument.php | 21 +++++++++++++++------ app/Models/Traits/ToolboxSettings.php | 1 - 4 files changed, 39 insertions(+), 25 deletions(-) diff --git a/app/Fluidbook/Compiler/Compiler.php b/app/Fluidbook/Compiler/Compiler.php index dd67b77b6..cd12ffbba 100644 --- a/app/Fluidbook/Compiler/Compiler.php +++ b/app/Fluidbook/Compiler/Compiler.php @@ -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; diff --git a/app/Fluidbook/Compiler/Images.php b/app/Fluidbook/Compiler/Images.php index 3eb7cfa6f..d3ae5db28 100644 --- a/app/Fluidbook/Compiler/Images.php +++ b/app/Fluidbook/Compiler/Images.php @@ -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(); diff --git a/app/Models/FluidbookDocument.php b/app/Models/FluidbookDocument.php index 232324041..3914227df 100644 --- a/app/Models/FluidbookDocument.php +++ b/app/Models/FluidbookDocument.php @@ -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() diff --git a/app/Models/Traits/ToolboxSettings.php b/app/Models/Traits/ToolboxSettings.php index 5232af65c..4cca4ce1f 100644 --- a/app/Models/Traits/ToolboxSettings.php +++ b/app/Models/Traits/ToolboxSettings.php @@ -22,7 +22,6 @@ trait ToolboxSettings { if (null === $this->_settingsData) { $this->_settingsData = $this->getPageData(); - $this->_settingsData->setOffsetPrefix('settings.'); } return $this->_settingsData; } -- 2.39.5