]> _ Git - fluidbook_tools.git/commitdiff
wait #5811 @2
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 16 Mar 2023 11:38:45 +0000 (12:38 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Thu, 16 Mar 2023 11:38:45 +0000 (12:38 +0100)
src/SVG/SVGTools.php

index 53f4512b3fcd840afd25ed0fd3538ed5987d6e52..4fe4d6ce426e8c50a638d0912dc0efaea21ddca9 100644 (file)
@@ -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();
     }
 }