From 7b7b6a926ecdf6258bbcc5dce091115f61f824fe Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Tue, 7 Sep 2021 20:25:38 +0200 Subject: [PATCH] wip #4666 @3 --- .idea/fluidbook_tools.iml | 3 + .idea/php.xml | 3 + composer.json | 3 +- composer.lock | 225 +++++++++++++++++++++++++++++++++++++- src/Jobs/ProcessPage.php | 46 ++++++-- src/PDF/Document.php | 29 ++++- 6 files changed, 291 insertions(+), 18 deletions(-) diff --git a/.idea/fluidbook_tools.iml b/.idea/fluidbook_tools.iml index 04e40da..c30c3f6 100644 --- a/.idea/fluidbook_tools.iml +++ b/.idea/fluidbook_tools.iml @@ -64,6 +64,9 @@ + + + diff --git a/.idea/php.xml b/.idea/php.xml index e1f9a4d..56f594b 100644 --- a/.idea/php.xml +++ b/.idea/php.xml @@ -62,6 +62,9 @@ + + + diff --git a/composer.json b/composer.json index edf97b3..34fc7cc 100644 --- a/composer.json +++ b/composer.json @@ -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" } } diff --git a/composer.lock b/composer.lock index 7fb3133..609a395 100644 --- a/composer.lock +++ b/composer.lock @@ -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", @@ -1094,6 +1179,72 @@ ], "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", @@ -2190,6 +2341,75 @@ ], "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", @@ -4585,7 +4805,8 @@ "ext-dom": "*", "ext-simplexml": "*", "ext-json": "*", - "ext-iconv": "*" + "ext-iconv": "*", + "ext-gd": "*" }, "platform-dev": [], "plugin-api-version": "2.1.0" diff --git a/src/Jobs/ProcessPage.php b/src/Jobs/ProcessPage.php index a4ed202..85c384d 100644 --- a/src/Jobs/ProcessPage.php +++ b/src/Jobs/ProcessPage.php @@ -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(); } } diff --git a/src/PDF/Document.php b/src/PDF/Document.php index daecb3a..5224a46 100644 --- a/src/PDF/Document.php +++ b/src/PDF/Document.php @@ -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; } } -- 2.39.5