]> _ Git - fluidbook_tools.git/commitdiff
wip #4666 @3
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 7 Sep 2021 18:25:38 +0000 (20:25 +0200)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Tue, 7 Sep 2021 18:25:38 +0000 (20:25 +0200)
.idea/fluidbook_tools.iml
.idea/php.xml
composer.json
composer.lock
src/Jobs/ProcessPage.php
src/PDF/Document.php

index 04e40da2a9330178129f48a1d761cde400d5203c..c30c3f674adb421057fa93d34b47589bb9c0edfc 100644 (file)
@@ -64,6 +64,9 @@
       <excludeFolder url="file://$MODULE_DIR$/vendor/graham-campbell/result-type" />
       <excludeFolder url="file://$MODULE_DIR$/vendor/swiftmailer/swiftmailer" />
       <excludeFolder url="file://$MODULE_DIR$/vendor/tijsverkoyen/css-to-inline-styles" />
+      <excludeFolder url="file://$MODULE_DIR$/vendor/symfony/debug" />
+      <excludeFolder url="file://$MODULE_DIR$/vendor/maximebf/debugbar" />
+      <excludeFolder url="file://$MODULE_DIR$/vendor/barryvdh/laravel-debugbar" />
     </content>
     <orderEntry type="inheritedJdk" />
     <orderEntry type="sourceFolder" forTests="false" />
index e1f9a4d9f8c1076426785857499ab5c65e9c05c8..56f594b88b2447e79c6fa9eeb7b3a3499f46ad14 100644 (file)
@@ -62,6 +62,9 @@
       <path value="$PROJECT_DIR$/vendor/graham-campbell/result-type" />
       <path value="$PROJECT_DIR$/vendor/swiftmailer/swiftmailer" />
       <path value="$PROJECT_DIR$/vendor/tijsverkoyen/css-to-inline-styles" />
+      <path value="$PROJECT_DIR$/vendor/symfony/debug" />
+      <path value="$PROJECT_DIR$/vendor/maximebf/debugbar" />
+      <path value="$PROJECT_DIR$/vendor/barryvdh/laravel-debugbar" />
     </include_path>
   </component>
   <component name="PhpProjectSharedConfiguration" php_language_level="7" />
index edf97b3c1b7d9ef536bc4391385b3fd76b98ed76..34fc7cc4d49062c6fb1fbc6b30678e2bbf9afb05 100644 (file)
@@ -31,6 +31,7 @@
         "ext-iconv": "*",
         "ext-gd": "*",
         "laravel/framework": "~5.8|^6.0|^7.0|^8.0",
-        "cubist/util": "dev-master"
+        "cubist/util": "dev-master",
+        "barryvdh/laravel-debugbar": "^3.6"
     }
 }
index 7fb3133f315a4a10a1cb696d05f88ba38f1a7a6d..609a3951f34aa06b989d2cec8bca4eae920cfbd3 100644 (file)
@@ -4,8 +4,93 @@
         "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies",
         "This file is @generated automatically"
     ],
-    "content-hash": "84f69f8ecd17cfe2cb76a4623050f8ee",
+    "content-hash": "1edb8d7b03dad14ee29f7130f3eb088b",
     "packages": [
+        {
+            "name": "barryvdh/laravel-debugbar",
+            "version": "v3.6.2",
+            "source": {
+                "type": "git",
+                "url": "https://github.com/barryvdh/laravel-debugbar.git",
+                "reference": "70b89754913fd89fef16d0170a91dbc2a5cd633a"
+            },
+            "dist": {
+                "type": "zip",
+                "url": "https://api.github.com/repos/barryvdh/laravel-debugbar/zipball/70b89754913fd89fef16d0170a91dbc2a5cd633a",
+                "reference": "70b89754913fd89fef16d0170a91dbc2a5cd633a",
+                "shasum": ""
+            },
+            "require": {
+                "illuminate/routing": "^6|^7|^8",
+                "illuminate/session": "^6|^7|^8",
+                "illuminate/support": "^6|^7|^8",
+                "maximebf/debugbar": "^1.16.3",
+                "php": ">=7.2",
+                "symfony/debug": "^4.3|^5",
+                "symfony/finder": "^4.3|^5"
+            },
+            "require-dev": {
+                "mockery/mockery": "^1.3.3",
+                "orchestra/testbench-dusk": "^4|^5|^6",
+                "phpunit/phpunit": "^8.5|^9.0",
+                "squizlabs/php_codesniffer": "^3.5"
+            },
+            "type": "library",
+            "extra": {
+                "branch-alias": {
+                    "dev-master": "3.5-dev"
+                },
+                "laravel": {
+                    "providers": [
+                        "Barryvdh\\Debugbar\\ServiceProvider"
+                    ],
+                    "aliases": {
+                        "Debugbar": "Barryvdh\\Debugbar\\Facade"
+                    }
+                }
+            },
+            "autoload": {
+                "psr-4": {
+                    "Barryvdh\\Debugbar\\": "src/"
+                },
+                "files": [
+                    "src/helpers.php"
+                ]
+            },
+            "notification-url": "https://packagist.org/downloads/",
+            "license": [
+                "MIT"
+            ],
+            "authors": [
+                {
+                    "name": "Barry vd. Heuvel",
+                    "email": "barryvdh@gmail.com"
+                }
+            ],
+            "description": "PHP Debugbar integration for Laravel",
+            "keywords": [
+                "debug",
+                "debugbar",
+                "laravel",
+                "profiler",
+                "webprofiler"
+            ],
+            "support": {
+                "issues": "https://github.com/barryvdh/laravel-debugbar/issues",
+                "source": "https://github.com/barryvdh/laravel-debugbar/tree/v3.6.2"
+            },
+            "funding": [
+                {
+                    "url": "https://fruitcake.nl",
+                    "type": "custom"
+                },
+                {
+                    "url": "https://github.com/barryvdh",
+                    "type": "github"
+                }
+            ],
+            "time": "2021-06-14T14:29:26+00:00"
+        },
         {
             "name": "brick/math",
             "version": "0.9.3",
             ],
             "time": "2021-01-18T20:58:21+00:00"
         },
+        {
+            "name": "maximebf/debugbar",
+            "version": "dev-master",
+            "source": {
+                "type": "git",
+                "url": "https://github.com/maximebf/php-debugbar.git",
+                "reference": "0a3532556be0145603f8a9de23e76dc28eed7054"
+            },
+            "dist": {
+                "type": "zip",
+                "url": "https://api.github.com/repos/maximebf/php-debugbar/zipball/0a3532556be0145603f8a9de23e76dc28eed7054",
+                "reference": "0a3532556be0145603f8a9de23e76dc28eed7054",
+                "shasum": ""
+            },
+            "require": {
+                "php": "^7.1|^8",
+                "psr/log": "^1.0",
+                "symfony/var-dumper": "^2.6|^3|^4|^5"
+            },
+            "require-dev": {
+                "phpunit/phpunit": "^7.5.20 || ^9.4.2"
+            },
+            "suggest": {
+                "kriswallsmith/assetic": "The best way to manage assets",
+                "monolog/monolog": "Log using Monolog",
+                "predis/predis": "Redis storage"
+            },
+            "default-branch": true,
+            "type": "library",
+            "extra": {
+                "branch-alias": {
+                    "dev-master": "1.17-dev"
+                }
+            },
+            "autoload": {
+                "psr-4": {
+                    "DebugBar\\": "src/DebugBar/"
+                }
+            },
+            "notification-url": "https://packagist.org/downloads/",
+            "license": [
+                "MIT"
+            ],
+            "authors": [
+                {
+                    "name": "Maxime Bouroumeau-Fuseau",
+                    "email": "maxime.bouroumeau@gmail.com",
+                    "homepage": "http://maximebf.com"
+                },
+                {
+                    "name": "Barry vd. Heuvel",
+                    "email": "barryvdh@gmail.com"
+                }
+            ],
+            "description": "Debug bar in the browser for php application",
+            "homepage": "https://github.com/maximebf/php-debugbar",
+            "keywords": [
+                "debug",
+                "debugbar"
+            ],
+            "support": {
+                "issues": "https://github.com/maximebf/php-debugbar/issues",
+                "source": "https://github.com/maximebf/php-debugbar/tree/v1.17.1"
+            },
+            "time": "2021-08-01T09:19:02+00:00"
+        },
         {
             "name": "monolog/monolog",
             "version": "dev-main",
             ],
             "time": "2021-08-17T15:35:52+00:00"
         },
+        {
+            "name": "symfony/debug",
+            "version": "4.4.x-dev",
+            "source": {
+                "type": "git",
+                "url": "https://github.com/symfony/debug.git",
+                "reference": "2f9160e92eb64c95da7368c867b663a8e34e980c"
+            },
+            "dist": {
+                "type": "zip",
+                "url": "https://api.github.com/repos/symfony/debug/zipball/2f9160e92eb64c95da7368c867b663a8e34e980c",
+                "reference": "2f9160e92eb64c95da7368c867b663a8e34e980c",
+                "shasum": ""
+            },
+            "require": {
+                "php": ">=7.1.3",
+                "psr/log": "^1|^2|^3"
+            },
+            "conflict": {
+                "symfony/http-kernel": "<3.4"
+            },
+            "require-dev": {
+                "symfony/http-kernel": "^3.4|^4.0|^5.0"
+            },
+            "default-branch": true,
+            "type": "library",
+            "autoload": {
+                "psr-4": {
+                    "Symfony\\Component\\Debug\\": ""
+                },
+                "exclude-from-classmap": [
+                    "/Tests/"
+                ]
+            },
+            "notification-url": "https://packagist.org/downloads/",
+            "license": [
+                "MIT"
+            ],
+            "authors": [
+                {
+                    "name": "Fabien Potencier",
+                    "email": "fabien@symfony.com"
+                },
+                {
+                    "name": "Symfony Community",
+                    "homepage": "https://symfony.com/contributors"
+                }
+            ],
+            "description": "Provides tools to ease debugging PHP code",
+            "homepage": "https://symfony.com",
+            "support": {
+                "source": "https://github.com/symfony/debug/tree/v4.4.27"
+            },
+            "funding": [
+                {
+                    "url": "https://symfony.com/sponsor",
+                    "type": "custom"
+                },
+                {
+                    "url": "https://github.com/fabpot",
+                    "type": "github"
+                },
+                {
+                    "url": "https://tidelift.com/funding/github/packagist/symfony/symfony",
+                    "type": "tidelift"
+                }
+            ],
+            "time": "2021-07-22T07:21:39+00:00"
+        },
         {
             "name": "symfony/deprecation-contracts",
             "version": "dev-main",
         "ext-dom": "*",
         "ext-simplexml": "*",
         "ext-json": "*",
-        "ext-iconv": "*"
+        "ext-iconv": "*",
+        "ext-gd": "*"
     },
     "platform-dev": [],
     "plugin-api-version": "2.1.0"
index a4ed2022e44b451f209b904ac1d71c700e5acf29..85c384d5d824ad6e47dc6152de30947f3ba8f1a9 100644 (file)
@@ -10,7 +10,6 @@ use Illuminate\Contracts\Queue\ShouldQueue;
 use Illuminate\Foundation\Bus\Dispatchable;
 use Illuminate\Queue\InteractsWithQueue;
 use Illuminate\Queue\SerializesModels;
-use Illuminate\Contracts\Queue;
 use Cubist\Util\CommandLine;
 
 
@@ -48,9 +47,11 @@ class ProcessPage implements ShouldQueue
 
     public function handle()
     {
+        start_measure('Process page ' . $this->page);
         foreach ($this->files as $file) {
             $this->getFile($this->page, $file['format'], $file['resolution'], $file['withText'], $file['withGraphics'], 'html', false);
         }
+        stop_measure('Process page ' . $this->page);
     }
 
 
@@ -73,6 +74,7 @@ class ProcessPage implements ShouldQueue
 
         $dir = rtrim($this->out . $version, '/') . '/';
         $minsize = 1;
+        $file = '';
         if ($format === 'svg') {
             $prefix = $withGraphics ? 'f' : 't';
             $file = $dir . $prefix . 'o' . $page;
@@ -148,6 +150,16 @@ class ProcessPage implements ShouldQueue
         unlink($lock);
     }
 
+    public function getResolutionRatio()
+    {
+        return $this->document->getResolutionRatio();
+    }
+
+    public function getMobileFirstRatio()
+    {
+        return $this->document->getMobileFirstRatio();
+    }
+
     public function makeSVGFile($page, $force = false)
     {
         $svgFile = $this->out . '/html/fp' . $page . '.svg';
@@ -169,8 +181,8 @@ class ProcessPage implements ShouldQueue
     public function makeOptimizedSVGFile($page, $resolution, $out)
     {
         $in = $this->makeSVGFile($page);
-        wsTools::optimizeSVGImages($in, $out, $resolution);
-        wsTools::optimizeSVG($out, $out);
+        SVGTools::optimizeSVGImages($in, $out, $resolution);
+        SVGTools::optimizeSVG($out, $out);
     }
 
     protected function getSplittedPDFPage($page)
@@ -184,19 +196,19 @@ class ProcessPage implements ShouldQueue
 
     public function splitDoc()
     {
-        $this->addToLog('Split document');
-        if (!file_exists($this->out . '/pdf')) {
-            mkdir($this->out . '/pdf');
+        start_measure('Split PDF');
+
+        if (!file_exists($this->out . '/pdf') && !mkdir($concurrentDirectory = $this->out . '/pdf') && !is_dir($concurrentDirectory)) {
+            throw new \RuntimeException(sprintf('Directory "%s" was not created', $concurrentDirectory));
         }
-        $pdftk = new cubeCommandLine('pdftk');
-        $pdftk->setPath(CONVERTER_PATH);
-        $pdftk->setArg(null, $this->getCroppedPDF());
+        $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->execute();
-        $this->addToLog($pdftk);
+
 
         for ($i = 1; $i <= $this->getPagesNumber(); $i++) {
             // Remove annotations : https://gist.github.com/stefanschmidt/5248592
@@ -212,5 +224,19 @@ class ProcessPage implements ShouldQueue
                 }
             }
         }
+        stop_measure('Split PDF');
+    }
+
+    /**
+     * @return int
+     */
+    public function getPagesNumber()
+    {
+        return $this->document->getPages();
+    }
+
+    public function getPDFInput()
+    {
+        return $this->document->getPDFInput();
     }
 }
index daecb3a4a340861aec384565f784dc33e8642297..5224a4680d225b6ded2f2f6e56c0d262266bf9f8 100644 (file)
@@ -52,7 +52,7 @@ class Document
         }
 
         $fwstk = new CommandLine(FluidbookTools::tools_path('fwstk.sh'));
-        $fwstk->setArg('--input ' . $this->in);
+        $fwstk->setArg('--input ' . $this->getPDFInput());
         $fwstk->setArg('--infos');
         $fwstk->execute();
 
@@ -97,10 +97,10 @@ class Document
     /**
      * @param $dest string
      */
-    public function processPages($dest, $files)
+    public function processPages($dest, $files, $sync = false)
     {
         for ($i = 1; $i <= $this->getPages(); $i++) {
-            $this->processPage($i, $dest, $files);
+            $this->processPage($i, $dest, $files, $sync);
         }
     }
 
@@ -108,8 +108,27 @@ class Document
      * @param $i
      * @param $dest
      */
-    public function processPage($page, $dest, $files)
+    public function processPage($page, $dest, $files, $sync = false)
     {
-        dispatch(new ProcessPage($this, $page, $dest, $files));
+        $dispatchFunction = $sync ? 'dispatchSync' : 'dispatch';
+        ProcessPage::$dispatchFunction($this, $page, $dest, $files);
+    }
+
+    public function getResolutionRatio()
+    {
+        $a4surface = 500990; // en pt²
+        $docSurface = $this->getWidth() * $this->getHeight(); // en pt²
+        // to have the same surface resulting in px, we have to sqrt the ratio between the two surfaces defined above
+        return sqrt($a4surface / $docSurface);
+    }
+
+    public function getMobileFirstRatio()
+    {
+        return 620 / $this->getWidth();
+    }
+
+    public function getPDFInput()
+    {
+        return $this->in;
     }
 }