]> _ Git - fluidbook_tools.git/commitdiff
wip #4666 @1
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 15 Sep 2021 15:24:08 +0000 (17:24 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Wed, 15 Sep 2021 15:24:08 +0000 (17:24 +0200)
src/Jobs/ProcessFile.php
src/Jobs/ProcessPage.php
src/PDF/Document.php

index a9b58fea8a61d15430a53f60d22b3c3ed24da74f..8dfed35bfd0f4613ef8f732f540c6baba9459e49 100644 (file)
@@ -160,6 +160,7 @@ class ProcessFile
     public function setJob(ProcessPage $job)
     {
         $this->job = $job;
+        return $this;
     }
 
     public function getPath($force = false)
@@ -182,27 +183,16 @@ class ProcessFile
                 $res = $dir . 'p' . $this->getPage() . '.' . $this->getFormat();
             } else {
                 $res = $dir . $prefix . $this->getPage() . '-' . $this->getResolution() . '.' . $this->getFormat();
-                $alt = $dir . $prefix . $this->getResolution() . '-' . $this->getPage() . '.' . $this->getFormat();
             }
         } else if ($this->getFormat() === 'swf') {
             $res = $dir . 'p' . $this->getPage() . '.' . $this->getFormat();
         }
 
         $do = false;
-        if (!file_exists($res)) {
-            if (isset($alt) && file_exists($alt) && filesize($alt) > $minsize) {
-                rename($alt, $res);
-                $do = false;
-            } else {
-                $do = true;
-            }
-        } else if (filesize($res) < $minsize) {
+        if (!file_exists($res) || filesize($res) < $minsize) {
             $do = true;
         } else if (isset($reffile) && filemtime($res) < filemtime($reffile)) {
             $do = true;
-        } else if ($this->getFormat() === 'svg') {
-            $t = filemtime($res);
-            $do = $t < 1603181003 && $t > 1602662603;
         }
 
         if ($do || $force) {
@@ -237,6 +227,9 @@ class ProcessFile
             PDFTools::makeSWF($this->getSplittedPDFPage(), $file, 1, $this->getResolution(), 80);
         }
         unlink($lock);
+        if (!file_exists($file)) {
+            throw new \Exception(sprintf('Failed to generate %s', $file));
+        }
     }
 
     public function makeSVGFile($force = false)
index d333f62ef59eb4631b4ee657faf27cefb75c338d..89ec3a6e86865c6dae35d3006285acf0e4c9a8a9 100644 (file)
@@ -52,6 +52,14 @@ class ProcessPage implements ShouldQueue
         $this->files = $files;
     }
 
+    /**
+     * @param int $page
+     */
+    public function setPage(int $page): void
+    {
+        $this->page = $page;
+    }
+
     /**
      * @return int
      */
index bd2cc9529eb2b59c97d6701f605b4ba602ef5bc9..7f1d39a999db1ee2ad531642aba8ad836f9c47cf 100644 (file)
@@ -3,6 +3,7 @@
 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;
@@ -31,6 +32,16 @@ class Document
      */
     protected $height;
 
+    /**
+     * @var array
+     */
+    protected $pageNumbers = [];
+
+    /**
+     * @var array
+     */
+    protected $chapters = [];
+
     public function __construct($in)
     {
         $this->in = $in;
@@ -60,6 +71,7 @@ class Document
 
         $infos = $fwstk->getOutput();
 
+
         if (preg_match('/Pages:\s*(\d+)/', $infos, $matches)) {
             $this->pages = (int)$matches[1];
         }
@@ -67,6 +79,32 @@ class Document
             $this->width = (float)$matches[1];
             $this->height = (float)$matches[2];
         }
+
+        if (preg_match('/NumberSections:\s*(.*)/', $infos, $matches)) {
+            $this->pageNumbers = explode(',', $matches[1]);
+        } else {
+            $this->pageNumbers = range(1, $this->pages);
+        }
+
+        $lines = Text::explodeNewLines($infos);
+        $bookmark_id = -1;
+
+
+        foreach ($lines as $line) {
+            $line = trim($line);
+            [$k, $v] = explode(':', $line);
+            $k = trim($k);
+            $v = trim($v);
+
+            if ($k === 'BookmarkTitle') {
+                $bookmark_id++;
+                $this->chapters[$bookmark_id] = array('label' => str_replace('&#13;', '', $v));
+            } elseif ($k === 'BookmarkLevel') {
+                $this->chapters[$bookmark_id]['level'] = (int)$v - 1;
+            } elseif ($k === 'BookmarkPage') {
+                $this->chapters[$bookmark_id]['page'] = $v;
+            }
+        }
     }
 
     /**
@@ -139,10 +177,24 @@ class Document
         stop_measure('Compile search index');
     }
 
-    public function compileSearchIndex($dest){
+    public function getPageNumbers()
+    {
+        $this->getInfos();
+        return $this->pageNumbers;
+    }
+
+    public function getChapters()
+    {
+        $this->getInfos();
+        return $this->chapters;
+    }
+
+    public function compileSearchIndex($dest)
+    {
 
     }
 
+
     public function getResolutionRatio()
     {
         $a4surface = 500990; // en pt²