]> _ Git - fluidbook_tools.git/commitdiff
wip #6781 @1
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 8 Mar 2024 15:16:53 +0000 (16:16 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Fri, 8 Mar 2024 15:16:53 +0000 (16:16 +0100)
src/Jobs/ProcessFile.php

index 867a0a86f335e4f23a56b622f63a787f459c9547..4bd729aa9b148ea81a5b72df877301fb9f405d41 100644 (file)
@@ -4,6 +4,7 @@ namespace Fluidbook\Tools\Jobs;
 
 use Cubist\Util\Files\Files;
 use Cubist\PDF\PDFTools;
+use DOMDocument;
 use Fluidbook\Tools\SVG\SVGTools;
 
 class ProcessFile
@@ -262,13 +263,21 @@ class ProcessFile
     public function makeSVGFile($force = false)
     {
         $svgFile = $this->getOut() . '/html/fp' . $this->getPage() . '.svg';
-        if (!$force && file_exists($svgFile) && filesize($svgFile) > 0) {
+        if (!$force && file_exists($svgFile) && filesize($svgFile) > 0 && $this->_isSVGValid($svgFile)) {
             return $svgFile;
         }
         PDFTools::makeBaseSVGFile($this->getSplittedPDFPage(), $svgFile, 1);
         return $svgFile;
     }
 
+    protected function _isSVGValid($file)
+    {
+        $svg = new DOMDocument();
+        $svg->preserveWhiteSpace = false;
+        $svg->load($file, LIBXML_PARSEHUGE);
+        return $svg->validate();
+    }
+
     public function makeTextSVGFile($out)
     {
         $in = $this->makeSVGFile();
@@ -306,7 +315,6 @@ class ProcessFile
     }
 
 
-
     /**
      * @return int
      */