]> _ Git - fluidbook_tools.git/commitdiff
wip #4666 @0.5
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 16 Sep 2021 18:29:44 +0000 (20:29 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 16 Sep 2021 18:29:44 +0000 (20:29 +0200)
src/Compiler/Compiler.php
src/Compiler/Source.php
src/PDF/Document.php

index 92790c400f0f8aad69979a5fc537e89eab16182f..a8a98ad932d6e529a6a9e3ff2411c089bfbeaaaa 100644 (file)
@@ -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();
+        }
     }
 
 
index 6705e6499339ff56dcaf486d9a9935ef668c3d1c..3bbe2e848d24a599f2de3724365e61b77f0bc8bc 100644 (file)
@@ -54,8 +54,6 @@ class Source
 
     public function getEnd(): int
     {
-        dd($this->start,$this->pages);
-
         return $this->start + $this->pages - 1;
     }
 
index 00433b087ff0ff889efa77a64374fb72f2752233..11beea008cef7c085ff551f187bd0a74b6d97951 100644 (file)
@@ -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];