From: Vincent Vanwaelscappel Date: Thu, 16 Mar 2023 11:38:45 +0000 (+0100) Subject: wait #5811 @2 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=347bdc595bbdabe537b8565994f0f16e43e3c72b;p=fluidbook_tools.git wait #5811 @2 --- diff --git a/src/SVG/SVGTools.php b/src/SVG/SVGTools.php index 53f4512..4fe4d6c 100644 --- a/src/SVG/SVGTools.php +++ b/src/SVG/SVGTools.php @@ -2,10 +2,13 @@ namespace Fluidbook\Tools\SVG; +use Cubist\Util\CommandLine; use Cubist\Util\CommandLine\Inkscape; use Cubist\Util\Files\Files; +use Cubist\Util\Str; use Fluidbook\Tools\FluidbookTools; use Illuminate\Validation\Rules\In; +use ZipStream\File; class SVGTools { protected static $_r; @@ -25,16 +28,25 @@ class SVGTools { return self::_optimizeSVG($in, $out); } - public static function optimizeSVGStr($in, $strokeToPaths = false) { - $infile = Files::tempnam() . '.svg'; + public static function optimizeSVGStr($in, $fix = false) { + + $dir = Files::mkdir(sys_get_temp_dir() . '/svgopt'); + + + $infile = Files::tempnam($dir, 'svgopt') . '.svg'; file_put_contents($infile, $in); - $outfile = Files::tempnam() . '.svg'; + $outfile = Files::tempnam($dir, 'svgopt') . '.svg'; self::optimizeSVG($infile, $outfile); - if ($strokeToPaths) { - self::strokeToPaths($outfile); - } - $res = file_get_contents($outfile); unlink($infile); + if ($fix) { + $fixed = Files::mkdir(sys_get_temp_dir() . '/svgopt-fixed'); + self::fix($dir, $fixed); + $fixedFile = str_replace($dir, $fixed, $outfile); + $res = file_get_contents($fixedFile); + unlink($fixedFile); + } else { + $res = file_get_contents($outfile); + } unlink($outfile); return $res; } @@ -135,9 +147,10 @@ class SVGTools { return $res; } - public static function strokeToPaths($svgfile) { - $inkscape = new Inkscape(); - $inkscape->strokeToPath($svgfile); - $inkscape->execute(); + public static function fix($source, $dest) { + $cli = new CommandLine('oslllo-svg-fixer'); + $cli->setArg('s', $source); + $cli->setArg('d', $dest); + $cli->execute(); } }