]> _ Git - fluidbook_tools.git/commitdiff
wip #4666 @1
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 16 Sep 2021 17:17:22 +0000 (19:17 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 16 Sep 2021 17:17:22 +0000 (19:17 +0200)
.gitignore
.idea/fluidbook_tools.iml
src/Compiler/Compiler.php
src/Compiler/Source.php
src/Jobs/ProcessFile.php
src/Jobs/ProcessPage.php
src/PDF/Document.php

index 1e01c5e615f76c16c9535719c09904adc871f28a..299cf40ef7d131326f62198e8fd360423c02cbd5 100644 (file)
@@ -24,4 +24,3 @@ Homestead.json
 .phpunit.result.cache
 
 resources/tools/fwstk/bin
-resources/tools/fwstk/out
index 0ad947ca14ac24c12fbbca9fd9cb6f8328f34f7f..792cd4f0dc8850b8f0da99e7cbc2f264c22f8988 100644 (file)
@@ -70,7 +70,6 @@
       <excludeFolder url="file://$MODULE_DIR$/vendor/maximebf/debugbar" />
       <excludeFolder url="file://$MODULE_DIR$/vendor/barryvdh/laravel-debugbar" />
       <excludeFolder url="file://$MODULE_DIR$/resources/tools/fwstk/bin" />
-      <excludeFolder url="file://$MODULE_DIR$/resources/tools/fwstk/out" />
     </content>
     <orderEntry type="inheritedJdk" />
     <orderEntry type="sourceFolder" forTests="false" />
index 928890b537eb48fbedc423b4ca4592acc42fd5b9..92790c400f0f8aad69979a5fc537e89eab16182f 100644 (file)
@@ -8,6 +8,7 @@ use Cubist\Util\PHP;
 use Exception;
 use Fluidbook\Tools\Jobs\ProcessFile;
 use Fluidbook\Tools\Jobs\ProcessPage;
+use Fluidbook\Tools\PDF\Document;
 use Fluidbook\Tools\Search\SearchIndex;
 use Illuminate\Bus\Queueable;
 use Illuminate\Contracts\Queue\ShouldBeUnique;
@@ -47,7 +48,7 @@ class Compiler implements ShouldQueue, ShouldBeUnique
 
     public function addSource($document, $start = 1, $pages = null)
     {
-        $source = new Source($document,$this, $start );
+        $source = new Source(new Document($document), $start, $pages);
         $this->sources[] = $source;
         foreach ($source->getRange() as $sourcePage) {
             $this->pages[] = new SourcePage($source, $sourcePage);
@@ -79,6 +80,7 @@ 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');
index 3bbe2e848d24a599f2de3724365e61b77f0bc8bc..6705e6499339ff56dcaf486d9a9935ef668c3d1c 100644 (file)
@@ -54,6 +54,8 @@ class Source
 
     public function getEnd(): int
     {
+        dd($this->start,$this->pages);
+
         return $this->start + $this->pages - 1;
     }
 
index f1147a204051be7e2baa5730a58a4a412a0138df..8dfed35bfd0f4613ef8f732f540c6baba9459e49 100644 (file)
@@ -120,7 +120,7 @@ class ProcessFile
      */
     public function getOut()
     {
-        return $this->job->getSource()->getSource()->getDocument()->getConvertPath();
+        return $this->job->getOut();
     }
 
 
index 3effbfa07b559e23a30780397a7b66bd76eeca65..37d3627be34a18f262192b695282453883d78b85 100644 (file)
@@ -3,7 +3,6 @@
 namespace Fluidbook\Tools\Jobs;
 
 use Cubist\Util\Files\Files;
-use Fluidbook\Tools\Compiler\SourcePage;
 use Fluidbook\Tools\PDF\Document;
 use Illuminate\Bus\Queueable;
 use Illuminate\Contracts\Queue\ShouldQueue;
@@ -18,83 +17,107 @@ class ProcessPage implements ShouldQueue
     use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
 
     /**
-     * @var ProcessFile[]
+     * @var Document
      */
-    protected $files = [];
+    protected $document;
+
+    /**
+     * @var integer
+     */
+    protected $page;
 
     /**
-     * @var SourcePage
+     * @var ProcessFile[]
      */
-    protected $source;
+    protected $files = [];
 
     /**
-     * @param $source SourcePage
+     * @param $document Document
+     * @param $page integer
      * @param ProcessFile[] $files
      */
-    public function __construct($source, $files = [])
+    public function __construct($document, $page, $files = [])
     {
-        $this->source = $source;
+        $this->document = $document;
+        $this->page = $page;
         $this->files = $files;
     }
 
+    /**
+     * @param int $page
+     */
+    public function setPage(int $page): void
+    {
+        $this->page = $page;
+    }
+
     /**
      * @return int
      */
     public function getPage(): int
     {
-        return $this->source->getPage();
+        return $this->page;
+    }
+
+    /**
+     * @return string
+     */
+    public function getOut(): string
+    {
+        return $this->document->getConvertPath();
     }
 
     public function handle()
     {
-        start_measure('Process page ' . $this->source->getPage());
+        start_measure('Process page ' . $this->page);
         foreach ($this->files as $file) {
-            $this->getFile($file, false);
+            $this->getFile($this->page, $file, false);
         }
-        stop_measure('Process page ' . $this->source->getPage());
+        stop_measure('Process page ' . $this->page);
     }
 
 
     /**
-     * @p
+     * @param $page
      * @param $file ProcessFile
      * @param false $force
      * @return string
      */
-    public function getFile($file, $force = false)
+    public function getFile($page, $file, $force = false)
     {
+        $this->setPage($page);
         $file->setJob($this);
         return $file->getPath($force);
     }
 
     public function getResolutionRatio()
     {
-        return $this->source->getSource()->getDocument()->getResolutionRatio();
+        return $this->document->getResolutionRatio();
     }
 
     public function getMobileFirstRatio()
     {
-        return $this->source->getSource()->getDocument()->getMobileFirstRatio();
+        return $this->document->getMobileFirstRatio();
     }
 
     public function splitDoc()
     {
         start_measure('Split PDF');
 
-        Files::mkdir($this->out . '/pdf');
+        Files::mkdir($this->getOut() . '/pdf');
         $pdftk = new CommandLine('pdftk');
         $pdftk->setArg(null, $this->getPDFInput());
         $pdftk->setArg(null, 'burst');
         $pdftk->setArg(null, 'uncompress');
         $pdftk->setArg(null, 'output');
-        $pdftk->setArg(null, $this->out . 'pdf/p%d.pdf');
+        $pdftk->setArg(null, $this->getOut() . 'pdf/p%d.pdf');
         $pdftk->execute();
 
 
         for ($i = 1; $i <= $this->getPagesNumber(); $i++) {
             // Remove annotations : https://gist.github.com/stefanschmidt/5248592
-            $file = sprintf($this->out . 'pdf/p%d.pdf', $i);
-            $to = sprintf($this->out . 'pdf/s%d.pdf', $i);
+            $file = sprintf($this->getOut() . 'pdf/p%d.pdf', $i);
+            $to = sprintf($this->getOut() . 'pdf/s%d.pdf', $i);
             `LANG=C LC_CTYPE=C sed -n '/^\/Annots/!p' $file > $to`;
             if (file_exists($to)) {
                 if (filesize($to) > 0) {
@@ -113,19 +136,11 @@ class ProcessPage implements ShouldQueue
      */
     public function getPagesNumber()
     {
-        return $this->source->getSource()->getDocument()->getPages();
+        return $this->document->getPages();
     }
 
     public function getPDFInput()
     {
-        return $this->source->getSource()->getDocument()->getPDFInput();
-    }
-
-    /**
-     * @return SourcePage
-     */
-    public function getSource(): SourcePage
-    {
-        return $this->source;
+        return $this->document->getPDFInput();
     }
 }
index 07ac15f3f0728cd732d75e0dc83ccbc1602a9784..00433b087ff0ff889efa77a64374fb72f2752233 100644 (file)
@@ -2,10 +2,8 @@
 
 namespace Fluidbook\Tools\PDF;
 
-use Cubist\Util\CommandLine;
 use Cubist\Util\Text;
 use Fluidbook\Tools\CommandLine\FWSTK;
-use Fluidbook\Tools\FluidbookTools;
 use Fluidbook\Tools\Jobs\ProcessFile;
 use Fluidbook\Tools\Jobs\ProcessPage;
 
@@ -58,7 +56,7 @@ class Document
         return $this->hash;
     }
 
-    public function getConvertPath()
+    public function getConvertPath(): string
     {
         return storage_path('fluidbook/convert/' . $this->getHash() . '/');
     }
@@ -76,7 +74,6 @@ class Document
 
         $infos = $fwstk->getOutput();
 
-
         if (preg_match('/Pages:\s*(\d+)/', $infos, $matches)) {
             $this->pages = (int)$matches[1];
         }
@@ -161,7 +158,7 @@ class Document
     public function processPage($page, $files, $sync = false)
     {
         $dispatchFunction = $sync ? 'dispatchSync' : 'dispatch';
-        ProcessPage::$dispatchFunction($this, $page, $this->getConvertPath(), $files);
+        ProcessPage::$dispatchFunction($this, $page, $files);
     }
 
     public function processLinks()