]> _ Git - fluidbook_tools.git/commitdiff
wip #5084 @0.5
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 17 Feb 2022 09:43:51 +0000 (10:43 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 17 Feb 2022 09:43:51 +0000 (10:43 +0100)
.idea/deployment.xml
src/Compiler/Compiler.php
src/Jobs/ProcessFile.php
src/Links/ZoomLink.php

index 5d9a0bbd7ad13de6ba3410b7f518bec7d460186a..2b6ae2213823f5edda334413bcd3a5ee5f2c3802 100644 (file)
@@ -2,7 +2,14 @@
 <project version="4">
   <component name="PublishConfigData" autoUpload="Always" serverName="odl.paris.cubedesigners.com" remoteFilesAllowedToDisappearOnAutoupload="false" autoUploadExternalChanges="true" showAutoUploadSettingsWarning="false">
     <serverData>
-      <paths name="apps.fluidbook.com">
+      <paths name="batman.cubedesigners.com">
+        <serverdata>
+          <mappings>
+            <mapping local="$PROJECT_DIR$" web="/" />
+          </mappings>
+        </serverdata>
+      </paths>
+      <paths name="ccv-montpellier.fr">
         <serverdata>
           <mappings>
             <mapping local="$PROJECT_DIR$" web="/" />
           </mappings>
         </serverdata>
       </paths>
+      <paths name="dev.extranet.cubedesigners.com">
+        <serverdata>
+          <mappings>
+            <mapping local="$PROJECT_DIR$" web="/" />
+          </mappings>
+        </serverdata>
+      </paths>
       <paths name="dev.fluidbook.com">
         <serverdata>
           <mappings>
           </mappings>
         </serverdata>
       </paths>
+      <paths name="dev.pm-instrumentation.com">
+        <serverdata>
+          <mappings>
+            <mapping local="$PROJECT_DIR$" web="/" />
+          </mappings>
+        </serverdata>
+      </paths>
       <paths name="dev.rbcmobilier.com">
         <serverdata>
           <mappings>
           </mappings>
         </serverdata>
       </paths>
+      <paths name="odl.cube">
+        <serverdata>
+          <mappings>
+            <mapping local="$PROJECT_DIR$" web="/" />
+          </mappings>
+        </serverdata>
+      </paths>
       <paths name="odl.paris.cubedesigners.com">
         <serverdata>
           <mappings>
-            <mapping deploy="/www/vendor/fluidbook/tools" local="$PROJECT_DIR$" web="/" />
+            <mapping deploy="/vendor/fluidbook/tools" local="$PROJECT_DIR$" web="/" />
           </mappings>
           <excludedPaths>
             <excludedPath local="true" path="$PROJECT_DIR$/vendor" />
           </mappings>
         </serverdata>
       </paths>
+      <paths name="preview.cubedesigners.com">
+        <serverdata>
+          <mappings>
+            <mapping local="$PROJECT_DIR$" web="/" />
+          </mappings>
+        </serverdata>
+      </paths>
       <paths name="pro.cubjeans.com">
         <serverdata>
           <mappings>
           </mappings>
         </serverdata>
       </paths>
-      <paths name="vm.hf-customercare.com">
+      <paths name="stats3.fluidbook.com">
         <serverdata>
           <mappings>
             <mapping local="$PROJECT_DIR$" web="/" />
           </mappings>
         </serverdata>
       </paths>
-      <paths name="wheel02.hf-customercare.com">
+      <paths name="toolbox.fluidbook.com">
         <serverdata>
           <mappings>
             <mapping local="$PROJECT_DIR$" web="/" />
           </mappings>
         </serverdata>
       </paths>
+      <paths name="www.hf-customercare.com">
+        <serverdata>
+          <mappings>
+            <mapping local="$PROJECT_DIR$" web="/" />
+          </mappings>
+        </serverdata>
+      </paths>
       <paths name="www.kadreo.com">
         <serverdata>
           <mappings>
           </mappings>
         </serverdata>
       </paths>
+      <paths name="www.pm-instrumentation.com">
+        <serverdata>
+          <mappings>
+            <mapping local="$PROJECT_DIR$" web="/" />
+          </mappings>
+        </serverdata>
+      </paths>
       <paths name="www.preventicom.com">
         <serverdata>
           <mappings>
index 980885251818e9cd6f207eeaec837889afd60624..57fd9df5470049b5212f47f73330134c2886f251 100644 (file)
@@ -20,7 +20,8 @@ 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;
@@ -64,7 +65,8 @@ class Compiler implements ShouldQueue, ShouldBeUnique {
      */
     protected $resolutions = [150, 300];
 
-    public function addSource($document, $start = 1, $pages = null) {
+    public function addSource($document, $start = 1, $pages = null)
+    {
         $source = new Source(new Document($document), $start, $pages);
         $this->sources[] = $source;
         foreach ($source->getRange() as $sourcePage) {
@@ -72,7 +74,8 @@ class Compiler implements ShouldQueue, ShouldBeUnique {
         }
     }
 
-    public function getVirtualDirectory() {
+    public function getVirtualDirectory()
+    {
         return $this->vdir;
     }
 
@@ -82,7 +85,8 @@ class Compiler implements ShouldQueue, ShouldBeUnique {
      *
      * @return void
      */
-    public function handle() {
+    public function handle()
+    {
         $sync = ($this->job instanceof SyncJob);
         if ($sync) {
             PHP::neverStop(false);
@@ -95,7 +99,8 @@ 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,7 +108,8 @@ 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();
@@ -111,10 +117,12 @@ class Compiler implements ShouldQueue, ShouldBeUnique {
         start_measure('Process texts');
     }
 
+
     /**
      * @return ProcessFile[]
      */
-    public function getProcessFiles() {
+    public function getProcessFiles()
+    {
         $res = [
             'thumb' => new ProcessFile('jpg', 'thumb'),
             'text' => new ProcessFile('svg', 150, false, true),
@@ -131,7 +139,8 @@ 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,7 +158,8 @@ 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];
         }
@@ -159,7 +169,8 @@ class Compiler implements ShouldQueue, ShouldBeUnique {
     /**
      * @throws JsonException
      */
-    protected function compileFluidbook() {
+    protected function compileFluidbook()
+    {
         start_measure('Compile fluidbook');
 
         if ($this->wdir === '') {
@@ -179,13 +190,15 @@ 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++) {
 
             foreach ($this->resolutions as $resolution) {
@@ -196,7 +209,13 @@ class Compiler implements ShouldQueue, ShouldBeUnique {
         }
     }
 
-    public function getPageCount() {
+    public function getPagePDFSource($page)
+    {
+        return $this->getProcessFile('back300', $page)->getSplittedPDFPage();
+    }
+
+    public function getPageCount()
+    {
         $res = 0;
         foreach ($this->sources as $source) {
             $res += $source->getPages();
@@ -208,7 +227,8 @@ class Compiler implements ShouldQueue, ShouldBeUnique {
     /**
      * @throws \JsonException
      */
-    public function compileSearch() {
+    public function compileSearch()
+    {
         $index = new SearchIndex();
 
         foreach ($this->pages as $i => $page) {
@@ -222,7 +242,8 @@ 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 = 300;
@@ -236,7 +257,8 @@ 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);
@@ -269,7 +291,8 @@ class Compiler implements ShouldQueue, ShouldBeUnique {
         }
     }
 
-    protected function compilePageNumbers() {
+    protected function compilePageNumbers()
+    {
 
         $this->config->numerotation = [];
         foreach ($this->sources as $source) {
@@ -277,7 +300,8 @@ class Compiler implements ShouldQueue, ShouldBeUnique {
         }
     }
 
-    protected function compileChapters() {
+    protected function compileChapters()
+    {
         $this->config->chaptersPagesNumber = 'physical';
         $this->config->chapters = [];
         foreach ($this->sources as $source) {
@@ -285,23 +309,28 @@ 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);
     }
index 6ae1049c944bd26fce1898a489757034d35c02c1..f421e94e91ac69c0b6084d08cbd6a5887f0f3787 100644 (file)
@@ -257,7 +257,7 @@ class ProcessFile
         SVGTools::optimizeSVG($out, $out);
     }
 
-    protected function getSplittedPDFPage()
+    public function getSplittedPDFPage()
     {
         $res = $this->getOut() . 'pdf/p' . $this->getPage() . '.pdf';
         if (!file_exists($res)) {
index 1c49c84561d9322e1e8f24e1517948eec7af7b28..044760635c8ba43fc63dae7bb367a2e7c22a6e8f 100644 (file)
@@ -6,6 +6,7 @@ use Cubist\Util\CommandLine\Imagemagick;
 use Cubist\Util\Files\Files;
 use Cubist\Util\Graphics\PDF;
 use Cubist\Util\Text;
+use Fluidbook\Tools\Compiler\Compiler;
 
 class ZoomLink extends NormalLink
 {
@@ -88,6 +89,13 @@ class ZoomLink extends NormalLink
         ];
     }
 
+    /**
+     * @param $attributes
+     * @param $compiler Compiler
+     * @param $cachedir
+     * @param $save
+     * @return void
+     */
     public static function generateImage($attributes, $compiler, $cachedir, $save)
     {
 
@@ -113,29 +121,30 @@ class ZoomLink extends NormalLink
         $y = $attributes['y'];
         $w = $attributes['width'];
         $h = $attributes['height'];
-        $bookwidth = round($compiler->width);
+        $bookwidth = round($compiler->config->width);
 
         //error_log("--- Book Width: $bookwidth ---");
 
         if (!isset($attributes['pdf']) || !$attributes['pdf']) {
-            $p = wsDAOBook::getDocumentPage($compiler->book_id, $attributes['page']);
-            $pdfpath = wsDocument::getDir($p['document_id']) . '/pdf/p' . $p['document_page'] . '.pdf';
+            $pdfpath = $compiler->getPagePDFSource($attributes['page']);
             $extractPage = 1;
         } else {
             $pdfpath = $attributes['pdf'];
             $extractPage = $attributes['page'];
         }
 
+        $cache=storage_path('fluidbook/cache/zoomarea');
+
         $left = Files::tempnam();
         $leftfile = PDF::extractArea($pdfpath,
             $extractPage,
             array('x' => $x, 'y' => $y, 'width' => $w, 'height' => $h),
-            $left, $extractOptions, storage_path('cache/' . $cachedir . '/' . $compiler->book_id . '/'));
+            $left, $extractOptions,$cache);
 
         if (($x + $w) > $bookwidth) {
             if (!isset($attributes['pdf']) || !$attributes['pdf']) {
-                $p = wsDAOBook::getDocumentPage($compiler->book_id, $attributes['page'] + 1);
-                $pdfpath = wsDocument::getDir($p['document_id']) . '/pdf/p' . $p['document_page'] . '.pdf';
+
+                $pdfpath = $compiler->getPagePDFSource($attributes['page'] + 1);
                 $extractPage = 1;
             } else {
                 $pdfpath = $attributes['pdf'];
@@ -147,7 +156,7 @@ class ZoomLink extends NormalLink
             $rightfile = PDF::extractArea($pdfpath,
                 $extractPage,
                 array('x' => 0, 'y' => $y, 'width' => $diff, 'height' => $h),
-                $right, $extractOptions, storage_path('cache/' . $cachedir . '/' . $compiler->book_id . '/'));
+                $right, $extractOptions,$cache);
 
             if (!file_exists($rightfile)) {
                 die('Error generating right part ' . $rightfile);
@@ -165,7 +174,7 @@ class ZoomLink extends NormalLink
         if (isset($attributes['border']) && $attributes['border'] > 0) {
             $tmp = Files::tempnam() . '.jpg';
             Imagemagick::addBorder($both, $tmp, $attributes['border'], $attributes['borderColor']);
-            $compiler->vdir->addTemp($both);
+            $compiler->getVirtualDirectory()->addTemp($both);
             $both = $tmp;
         }
 
@@ -175,7 +184,7 @@ class ZoomLink extends NormalLink
         $files_to_delete = ['left', 'leftfile', 'right', 'rightfile', 'both'];
         foreach ($files_to_delete as $file) {
             if (isset($$file)) {
-                $compiler->vdir->addTemp($$file);
+                $compiler->getVirtualDirectory()->addTemp($$file);
             }
         }
     }