From 8853c6f717ee607070764047c18e2eaccc863785 Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Tue, 21 Dec 2021 12:07:06 +0100 Subject: [PATCH] wip #4969 @0.5 --- src/Compiler/Compiler.php | 80 ++++++++++++++++----------------------- 1 file changed, 32 insertions(+), 48 deletions(-) diff --git a/src/Compiler/Compiler.php b/src/Compiler/Compiler.php index a3921be..23b49d2 100644 --- a/src/Compiler/Compiler.php +++ b/src/Compiler/Compiler.php @@ -20,8 +20,7 @@ use Illuminate\Queue\SerializesModels; use JsonException; use stdClass; -class Compiler implements ShouldQueue, ShouldBeUnique -{ +class Compiler implements ShouldQueue, ShouldBeUnique { use Dispatchable, InteractsWithQueue, Queueable, SerializesModels; use Links; @@ -60,8 +59,12 @@ class Compiler implements ShouldQueue, ShouldBeUnique */ protected $stub = ''; - public function addSource($document, $start = 1, $pages = null) - { + /** + * @var int[] + */ + protected $resolutions = [150, 300]; + + public function addSource($document, $start = 1, $pages = null) { $source = new Source(new Document($document), $start, $pages); $this->sources[] = $source; foreach ($source->getRange() as $sourcePage) { @@ -69,8 +72,7 @@ class Compiler implements ShouldQueue, ShouldBeUnique } } - public function getVirtualDirectory() - { + public function getVirtualDirectory() { return $this->vdir; } @@ -80,8 +82,7 @@ class Compiler implements ShouldQueue, ShouldBeUnique * * @return void */ - public function handle() - { + public function handle() { $sync = ($this->job instanceof SyncJob); if ($sync) { PHP::neverStop(false); @@ -94,8 +95,7 @@ class Compiler implements ShouldQueue, ShouldBeUnique stop_measure('Process Fluidbook'); } - public function processPages($sync = false) - { + public function processPages($sync = false) { start_measure('Process Pages'); foreach ($this->sources as $source) { $source->getDocument()->processPages($this->getProcessFiles(), $source->getRange(), $sync); @@ -103,8 +103,7 @@ class Compiler implements ShouldQueue, ShouldBeUnique stop_measure('Process Pages'); } - public function getTexts() - { + public function getTexts() { start_measure('Process texts'); foreach ($this->sources as $source) { $source->getDocument()->processTexts(); @@ -115,13 +114,14 @@ class Compiler implements ShouldQueue, ShouldBeUnique /** * @return ProcessFile[] */ - public function getProcessFiles() - { - return [ + public function getProcessFiles() { + $res = [ 'thumb' => new ProcessFile('jpg', 'thumb'), - 'back150' => new ProcessFile('jpg', 150, true, false), 'text' => new ProcessFile('svg', 150, false, true), ]; + foreach ($this->resolutions as $resolution) { + $res['back' . $resolution] = new ProcessFile('jpg', $resolution, true, false), + } } /** @@ -130,8 +130,7 @@ class Compiler implements ShouldQueue, ShouldBeUnique * @return ProcessFile * @throws Exception */ - public function getProcessFile($name, $page = null) - { + public function getProcessFile($name, $page = null) { $files = $this->getProcessFiles(); if (isset($files[$name])) { $res = $files[$name]; @@ -149,8 +148,7 @@ class Compiler implements ShouldQueue, ShouldBeUnique * @return SourcePage * @throws Exception */ - public function getSourceOfPage($page) - { + public function getSourceOfPage($page) { if (isset($this->pages[$page - 1])) { return $this->pages[$page - 1]; } @@ -160,8 +158,7 @@ class Compiler implements ShouldQueue, ShouldBeUnique /** * @throws JsonException */ - protected function compileFluidbook() - { + protected function compileFluidbook() { start_measure('Compile fluidbook'); if ($this->wdir === '') { @@ -181,15 +178,13 @@ class Compiler implements ShouldQueue, ShouldBeUnique stop_measure('Compile fluidbook'); } - public function prepareStub() - { + public function prepareStub() { if ($this->stub !== '') { $this->vdir->copyDirectory($this->stub, '/'); } } - public function compileContents() - { + public function compileContents() { for ($i = 1; $i <= $this->getPageCount(); $i++) { $this->vdir->copy($this->getProcessFile('back150', $i)->getPath(), 'data/background/150/p' . $i . '.jpg'); @@ -198,8 +193,7 @@ class Compiler implements ShouldQueue, ShouldBeUnique } } - public function getPageCount() - { + public function getPageCount() { $res = 0; foreach ($this->sources as $source) { $res += $source->getPages(); @@ -211,8 +205,7 @@ class Compiler implements ShouldQueue, ShouldBeUnique /** * @throws \JsonException */ - public function compileSearch() - { + public function compileSearch() { $index = new SearchIndex(); foreach ($this->pages as $i => $page) { @@ -226,8 +219,7 @@ class Compiler implements ShouldQueue, ShouldBeUnique /** * @throws JsonException */ - public function compileConfig() - { + public function compileConfig() { $settings = mb_substr(file_get_contents($this->stub . '/data/datas.js'), 13, -2); $this->config = json_decode($settings, false, 512, JSON_THROW_ON_ERROR); $this->config->maxResolution = 150; @@ -241,8 +233,7 @@ class Compiler implements ShouldQueue, ShouldBeUnique $this->vdir->file_put_contents('data/datas.js', $c); } - protected function compileDimensions() - { + protected function compileDimensions() { $firstPageDoc = $this->getSourceOfPage(1)->getSource()->getDocument(); $width = round($firstPageDoc->getWidth(), 8); @@ -275,8 +266,7 @@ class Compiler implements ShouldQueue, ShouldBeUnique } } - protected function compilePageNumbers() - { + protected function compilePageNumbers() { $this->config->numerotation = []; foreach ($this->sources as $source) { @@ -284,8 +274,7 @@ class Compiler implements ShouldQueue, ShouldBeUnique } } - protected function compileChapters() - { + protected function compileChapters() { $this->config->chaptersPagesNumber = 'physical'; $this->config->chapters = []; foreach ($this->sources as $source) { @@ -293,28 +282,23 @@ class Compiler implements ShouldQueue, ShouldBeUnique } } - public function getBookSurface() - { + public function getBookSurface() { return $this->getWidth() * $this->getHeight(); } - public function getWidth() - { + public function getWidth() { return $this->getSourceOfPage(1)->getSource()->getDocument()->getWidth(); } - public function getHeight() - { + public function getHeight() { return $this->getSourceOfPage(1)->getSource()->getDocument()->getHeight(); } - public function addVideoJs() - { + public function addVideoJs() { $this->addLess('videojs/videojs'); } - public function addSlideshowLibrary($inline = true) - { + public function addSlideshowLibrary($inline = true) { $l = ($inline ? $this->config->inlineSlideshowLibrary : $this->config->popupSlideshowLibrary); $this->addLess('slideshow/' . $l); } -- 2.39.5