From: Vincent Vanwaelscappel Date: Thu, 16 Sep 2021 18:29:44 +0000 (+0200) Subject: wip #4666 @0.5 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=24b61412d1301e60a2ee61fd0fcd8c9fce5837ae;p=fluidbook_tools.git wip #4666 @0.5 --- diff --git a/src/Compiler/Compiler.php b/src/Compiler/Compiler.php index 92790c4..a8a98ad 100644 --- a/src/Compiler/Compiler.php +++ b/src/Compiler/Compiler.php @@ -2,7 +2,6 @@ namespace Fluidbook\Tools\Compiler; -use Cubist\Util\Files\Files; use Cubist\Util\Files\VirtualDirectory; use Cubist\Util\PHP; use Exception; @@ -17,6 +16,7 @@ use Illuminate\Foundation\Bus\Dispatchable; use Illuminate\Queue\InteractsWithQueue; use Illuminate\Queue\Jobs\SyncJob; use Illuminate\Queue\SerializesModels; +use JsonException; use stdClass; class Compiler implements ShouldQueue, ShouldBeUnique @@ -46,6 +46,11 @@ class Compiler implements ShouldQueue, ShouldBeUnique */ protected $pages = []; + /** + * @var string + */ + protected $stub = ''; + public function addSource($document, $start = 1, $pages = null) { $source = new Source(new Document($document), $start, $pages); @@ -80,7 +85,6 @@ class Compiler implements ShouldQueue, ShouldBeUnique { start_measure('Process Pages'); foreach ($this->sources as $source) { - dd( $source->getRange()); $source->getDocument()->processPages($this->getProcessFiles(), $source->getRange(), $sync); } stop_measure('Process Pages'); @@ -120,7 +124,7 @@ class Compiler implements ShouldQueue, ShouldBeUnique $res = $files[$name]; if (null !== $page) { $sourcePage = $this->getSourceOfPage($page); - $res->setJob(new ProcessPage($sourcePage->getSource(), $sourcePage->getPage())); + $res->setJob(new ProcessPage($sourcePage->getSource()->getDocument(), $sourcePage->getPage())); } return $res; } @@ -158,7 +162,9 @@ class Compiler implements ShouldQueue, ShouldBeUnique start_measure('Compile fluidbook'); $this->vdir = new VirtualDirectory($this->out); - $this->vdir->copyDirectory($this->stub, '/'); + if ($this->stub !== '') { + $this->vdir->copyDirectory($this->stub, '/'); + } $this->compileContents(); $this->compileSearch(); @@ -227,8 +233,10 @@ class Compiler implements ShouldQueue, ShouldBeUnique protected function compileDimensions() { - $width = round($this->in->getWidth(), 8); - $height = round($this->in->getHeight(), 8); + $firstPageDoc = $this->getSourceOfPage(1)->getSource()->getDocument(); + + $width = round($firstPageDoc->getWidth(), 8); + $height = round($firstPageDoc->getHeight(), 8); $this->config->pageZoomFactor = 3; $this->config->optimalWidth = 567; @@ -240,7 +248,7 @@ class Compiler implements ShouldQueue, ShouldBeUnique $cssWidth = $width * $this->config->cssScale; $cssHeight = $height * $this->config->cssScale; - $this->config->pages = $this->in->getPages(); + $this->config->pages = $firstPageDoc->getPages(); $this->config->width = $cssWidth; $this->config->height = $cssHeight; @@ -252,20 +260,27 @@ class Compiler implements ShouldQueue, ShouldBeUnique $this->config->thumbWidth = $thumbDimensions[0]; $this->config->thumbHeight = $thumbDimensions[1]; - for ($i = 1; $i <= $this->in->getPages(); $i++) { + for ($i = 1; $i <= $firstPageDoc->getPages(); $i++) { $this->config->pagesDimensions[$i] = [$this->config->width, $this->config->height]; } } protected function compilePageNumbers() { - $this->config->numerotation = $this->in->getPageNumbers(); + + $this->config->numerotation = []; + foreach ($this->sources as $source) { + $this->config->numerotation += array_slice($source->getDocument()->getPageNumbers(), $source->getStart(), $source->getPages()); + } } protected function compileChapters() { $this->config->chaptersPagesNumber = 'physical'; - $this->config->chapters = $this->in->getChapters(); + $this->config->chapters = []; + foreach ($this->sources as $source) { + $this->config->chapters += $source->getDocument()->getChapters(); + } } diff --git a/src/Compiler/Source.php b/src/Compiler/Source.php index 6705e64..3bbe2e8 100644 --- a/src/Compiler/Source.php +++ b/src/Compiler/Source.php @@ -54,8 +54,6 @@ class Source public function getEnd(): int { - dd($this->start,$this->pages); - return $this->start + $this->pages - 1; } diff --git a/src/PDF/Document.php b/src/PDF/Document.php index 00433b0..11beea0 100644 --- a/src/PDF/Document.php +++ b/src/PDF/Document.php @@ -61,6 +61,9 @@ class Document return storage_path('fluidbook/convert/' . $this->getHash() . '/'); } + /** + * @throws \Exception + */ public function getInfos($force = false) { if (!$force && $this->pages > 0) { @@ -76,6 +79,9 @@ class Document if (preg_match('/Pages:\s*(\d+)/', $infos, $matches)) { $this->pages = (int)$matches[1]; + if ($this->pages <= 0) { + throw new \Exception('Unable to get pages number'); + } } if (preg_match('/Page 1 size:\s*([0-9.]+)[ptsx\s]+([0-9.]+)/', $infos, $matches)) { $this->width = (float)$matches[1];