From abc03bacea43bc3628ebb925565d544df0384e7a Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Wed, 8 Sep 2021 17:51:36 +0200 Subject: [PATCH] wip #4666 @0.5 --- .idea/php.xml | 2 +- composer.json | 2 +- src/Jobs/ProcessFile.php | 32 ++++++++++---------------------- src/Jobs/ProcessPage.php | 6 +++--- src/PDF/Document.php | 7 +++++-- src/PDF/PDFTools.php | 5 +++-- 6 files changed, 23 insertions(+), 31 deletions(-) diff --git a/.idea/php.xml b/.idea/php.xml index 56f594b..592710e 100644 --- a/.idea/php.xml +++ b/.idea/php.xml @@ -67,5 +67,5 @@ - + \ No newline at end of file diff --git a/composer.json b/composer.json index 34fc7cc..26548a7 100644 --- a/composer.json +++ b/composer.json @@ -22,7 +22,7 @@ } ], "require": { - "php": ">=7.0.0", + "php": ">=8.0", "ext-libxml": "*", "ext-mbstring": "*", "ext-dom": "*", diff --git a/src/Jobs/ProcessFile.php b/src/Jobs/ProcessFile.php index 7a498eb..f72f35c 100644 --- a/src/Jobs/ProcessFile.php +++ b/src/Jobs/ProcessFile.php @@ -2,6 +2,7 @@ namespace Fluidbook\Tools\Jobs; +use Cubist\Util\Files\Files; use Fluidbook\Tools\PDF\PDFTools; use Fluidbook\Tools\SVG\SVGTools; @@ -9,7 +10,7 @@ class ProcessFile { protected $format = 'jpg'; /** - * @var int + * @var int|string */ protected $resolution = 150; /** @@ -24,14 +25,7 @@ class ProcessFile * @var string */ protected $version = 'html'; - /** - * @var int - */ - protected $page = 0; - /** - * @var string - */ - protected $out; + /** * @var ProcessPage */ @@ -66,17 +60,17 @@ class ProcessFile } /** - * @param int $resolution + * @param int|string $resolution */ - public function setResolution(int $resolution) + public function setResolution(int|string $resolution) { $this->resolution = $resolution; } /** - * @return int + * @return int|string */ - public function getResolution(): int + public function getResolution(): int|string { return $this->resolution; } @@ -129,13 +123,6 @@ class ProcessFile return $this->job->getOut(); } - /** - * @param mixed $out - */ - public function setOut($out) - { - $this->out = $out; - } /** * @return string @@ -231,6 +218,7 @@ class ProcessFile sleep(10); return $this->getPath(); } + Files::mkdir(dirname($lock)); touch($lock); if ($this->getFormat() === 'svg') { if ($this->isWithGraphics()) { @@ -253,7 +241,7 @@ class ProcessFile public function makeSVGFile($force = false) { - $svgFile = $this->out . '/html/fp' . $this->getPage() . '.svg'; + $svgFile = $this->getOut() . '/html/fp' . $this->getPage() . '.svg'; if (!$force && file_exists($svgFile) && filesize($svgFile) > 0) { return $svgFile; } @@ -278,7 +266,7 @@ class ProcessFile protected function getSplittedPDFPage() { - $res = $this->out . 'pdf/p' . $this->getPage() . '.pdf'; + $res = $this->getOut() . 'pdf/p' . $this->getPage() . '.pdf'; if (!file_exists($res)) { $this->getJob()->splitDoc(); } diff --git a/src/Jobs/ProcessPage.php b/src/Jobs/ProcessPage.php index 601840f..d333f62 100644 --- a/src/Jobs/ProcessPage.php +++ b/src/Jobs/ProcessPage.php @@ -2,6 +2,7 @@ namespace Fluidbook\Tools\Jobs; +use Cubist\Util\Files\Files; use Fluidbook\Tools\PDF\Document; use Fluidbook\Tools\PDF\PDFTools; use Fluidbook\Tools\SVG\SVGTools; @@ -41,6 +42,7 @@ class ProcessPage implements ShouldQueue * @param $document Document * @param $page integer * @param $out string + * @param ProcessFile[] $files */ public function __construct($document, $page, $out, $files = []) { @@ -102,9 +104,7 @@ class ProcessPage implements ShouldQueue { 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)); - } + Files::mkdir($this->out . '/pdf'); $pdftk = new CommandLine('pdftk'); $pdftk->setArg(null, $this->getPDFInput()); $pdftk->setArg(null, 'burst'); diff --git a/src/PDF/Document.php b/src/PDF/Document.php index d9f99bf..31c5deb 100644 --- a/src/PDF/Document.php +++ b/src/PDF/Document.php @@ -4,6 +4,7 @@ namespace Fluidbook\Tools\PDF; use Cubist\Util\CommandLine; use Fluidbook\Tools\FluidbookTools; +use Fluidbook\Tools\Jobs\ProcessFile; use Fluidbook\Tools\Jobs\ProcessPage; class Document @@ -108,8 +109,10 @@ class Document } /** - * @param $i - * @param $dest + * @param $page int + * @param $dest string + * @param $files ProcessFile[] + * @param false $sync */ public function processPage($page, $dest, $files, $sync = false) { diff --git a/src/PDF/PDFTools.php b/src/PDF/PDFTools.php index d7fba2c..0318704 100644 --- a/src/PDF/PDFTools.php +++ b/src/PDF/PDFTools.php @@ -3,6 +3,7 @@ namespace Fluidbook\Tools\PDF; use Cubist\Util\CommandLine; +use Cubist\Util\Files\Files; use DOMDocument; use DOMNode; use DOMXPath; @@ -169,7 +170,7 @@ class PDFTools protected static function makeShotGS($in, $out, $page, $prefix = '', $resolution = 72, $quality = 90, $antialiasing = 4, $width = null, $height = null, $format = 'jpg') { - // Fabrication des thumbanails avec ghostscript + // Fabrication des thumbnails avec ghostscript $gs = new CommandLine('gs', null, true); $gs->setArg('-dBATCH'); $gs->setArg('-dNOPAUSE'); @@ -204,7 +205,7 @@ class PDFTools public static function makeShotPNM($in, $out, $page, $prefix = '', $resolution = 72, $quality = 90, $antialiasing = 4, $texts = true, $width = null, $height = null, $format = 'jpg') { - $tmp = cubeFiles::tempnam(); + $tmp =Files::tempnam(); $antialiasing = $antialiasing ? 'yes' : 'no'; $freetype = $texts ? 'yes' : 'no'; -- 2.39.5