From d2de3d963e7d4f5b678be9a354cd4449986a389a Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Mon, 26 Jun 2023 09:50:41 +0200 Subject: [PATCH] wip #6076 @0.5 --- src/Links/ZoomLink.php | 14 ++++++++++++-- src/SVG/SVGTools.php | 10 ++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/Links/ZoomLink.php b/src/Links/ZoomLink.php index c10b8b2..90a2880 100644 --- a/src/Links/ZoomLink.php +++ b/src/Links/ZoomLink.php @@ -7,6 +7,7 @@ use Cubist\Util\CommandLine\Poppler; use Cubist\Util\Graphics\PDF; use Cubist\Util\Text; use Fluidbook\Tools\Compiler\CompilerInterface; +use Fluidbook\Tools\SVG\SVGTools; class ZoomLink extends NormalLink { protected $maxzoom_default = 2; @@ -152,7 +153,12 @@ class ZoomLink extends NormalLink { $cache = $compiler->getCacheDir("zoomarea/" . $cachedir); - $leftArea = ['x' => $x, 'y' => $y, 'width' => $w, 'height' => $h]; + + $leftHeight = min($h, $compiler->getHeightForLinks() - $y); + $leftWidth = min($w, $compiler->getWidthForLinks() - $x); + + $leftArea = ['x' => $x, 'y' => $y, 'width' => $leftWidth, 'height' => $leftHeight]; + $leftfile = PDF::extractArea($pdfpath, $extractPage, $leftArea, @@ -179,7 +185,11 @@ class ZoomLink extends NormalLink { $both = $cache . hash('sha256', $leftfile . $rightfile) . '.' . $ext; if (!file_exists($both)) { - Imagemagick::append(array($leftfile, $rightfile), $both, 'horizontal'); + if ($ext === 'svg') { + SVGTools::append($leftfile, $rightfile, $both, 'h'); + } else { + Imagemagick::append(array($leftfile, $rightfile), $both, 'horizontal'); + } } if (!file_exists($both)) { throw new \Exception('Error glueing ' . $leftfile . ' and ' . $rightfile); diff --git a/src/SVG/SVGTools.php b/src/SVG/SVGTools.php index 240233c..a948022 100644 --- a/src/SVG/SVGTools.php +++ b/src/SVG/SVGTools.php @@ -162,4 +162,14 @@ class SVGTools { $cli->dd(); } } + + public static function append($first, $second, $dest, $direction = 'h') { + $cli = new CommandLine('python3'); + $cli->setArg(null, '/usr/local/svg_stack/svg_stack.py'); + $cli->setArg('direction', $direction); + $cli->setArg(null, $first); + $cli->setArg(null, $second); + $cli->execute(); + file_put_contents($dest, $cli->getOutput()); + } } -- 2.39.5