]> _ Git - cubeextranet.git/commitdiff
wip #4720 @1
authorvincent@cubedesigners.com <vincent@cubedesigners.com@f5622870-0f3c-0410-866d-9cb505b7a8ef>
Thu, 30 Sep 2021 15:07:26 +0000 (15:07 +0000)
committervincent@cubedesigners.com <vincent@cubedesigners.com@f5622870-0f3c-0410-866d-9cb505b7a8ef>
Thu, 30 Sep 2021 15:07:26 +0000 (15:07 +0000)
inc/ws/Controlleur/class.ws.maintenance.php
inc/ws/Util/class.ws.pdf.convert.php

index b4d2399ab2f88651cc872d0a816fa61a12de9313..d7bfba1162a90b412780ae080055c81024680dd8 100644 (file)
@@ -860,7 +860,7 @@ class wsMaintenance
         echo '<pre>' . print_r($runs, true) . '</pre>';
     }
 
-    public static function resetPlayerVersion($from=null)
+    public static function resetPlayerVersion($from = null)
     {
         global $core;
         $dev = [10000, 10003, 15407, 15571, 15837, 16200];
@@ -876,7 +876,7 @@ class wsMaintenance
                     $skip[] = $r->book_id;
                     continue;
                 }
-                if($from!==null && stripos($parametres->mobileLVersion, $from) === false){
+                if ($from !== null && stripos($parametres->mobileLVersion, $from) === false) {
                     $skip[] = $r->book_id;
                     continue;
                 }
@@ -901,29 +901,24 @@ class wsMaintenance
     public static function getSVGPage($args)
     {
 
-        global $core;
+        global $core, $svglog;
         $fluidbook = $args[0];
         $page = $args[1];
+        $method = $args[2] ?? 'pdftocairo';
+        $onlytext = $args[3] && $args[3] === '1';
         $dao = new wsDAOBook($core->con);
         $pages = $dao->getPagesOfBook($fluidbook);
         $p = $pages[$page];
+
+        $svg = CubeIT_Files::tempnam() . 'svg';
+
         ob_clean();
         header('Content-type: image/svg+xml');
-        $svg = wsDocument::getDir($p['document_id']) . '/html/p' . $p['document_page'] . '.svg';
 
-        $pdftocairo = new cubeCommandLine(wsPDFConvert::PDFTOCAIRO);
-        $pdftocairo->setPath(CONVERTER_PATH);
-        $pdftocairo->setArg('f', $p['document_page']);
-        $pdftocairo->setArg('l', $p['document_page']);
-        $pdftocairo->setArg(null, '-svg');
-        //$pdftocairo->setArg(null, '-cropbox');
-        $pdftocairo->setArg(null, wsDocument::getDir($p['document_id']) . 'crop.pdf');
-        $pdftocairo->setArg(null, $svg);
-        $pdftocairo->execute();
+        wsPDFConvert::PDFToSVG(wsDocument::getDir($p['document_id']) . '/pdf/p' . $p['document_page'] . '.pdf', 1, $svg, $onlytext, $method, true);
 
-        wsDocument::cleanSVG($svg);
-
-        echo file_get_contents(wsDocument::getDir($p['document_id']) . '/html/p' . $p['document_page'] . '.svg');
+        echo file_get_contents($svg);
+        unlink($svg);
         exit;
     }
 
@@ -1496,7 +1491,7 @@ class wsMaintenance
         $eans = array_unique($eans);
         sort($eans);
 
-        $working =wsBook::getAssetDirOfBook($book,'/commerce/opt/');
+        $working = wsBook::getAssetDirOfBook($book, '/commerce/opt/');
         $res = [['EAN', 'front', 'angle', '360']];
         foreach ($eans as $ean) {
             $res[] = [$ean . " ", file_exists($working . '/' . $ean . '-front.jpg') ? 'Y' : 'N', file_exists($working . '/' . $ean . '-angle.jpg') ? 'Y' : 'N', file_exists($working . '/' . $ean . '-360.mp4') ? 'Y' : 'N'];
@@ -1511,8 +1506,9 @@ class wsMaintenance
         exit;
     }
 
-    public static function clearLocks(){
-        $dir=WS_BOOKS.'/locks/*';
+    public static function clearLocks()
+    {
+        $dir = WS_BOOKS . '/locks/*';
         `rm $dir`;
     }
 
@@ -1557,9 +1553,10 @@ class wsMaintenance
         }
     }
 
-    public static function test(){
+    public static function test()
+    {
         global $core;
-        $dao=new wsDAOTheme($core->con);
+        $dao = new wsDAOTheme($core->con);
         print_r($dao->selectById('3641'));
     }
 }
index ebac91d44b45e4bc783595aa059b44a95a5f2894..8754733977d91e9473cecf95ab0d7874b39ce3c3 100644 (file)
@@ -92,32 +92,79 @@ class wsPDFConvert
     }\r
 \r
 \r
-    public static function makeBaseSVGFile($in, $out, $page)\r
+    public static function makeBaseSVGFile($in, $out, $page, $method = 'pdftocairo')\r
     {\r
-//        if (stristr($in, '127174')) {\r
-//            // inkscape --pdf-page=1 --export-type=svg --export-filename=i12.svg ./pdf/p12.pdf\r
-//            $inkscape = new CubeIT_CommandLine('inkscape');\r
-//            $inkscape->setArg('pdf-page', '1');\r
-//            $inkscape->setArg('export-type', 'svg');\r
-//            $inkscape->setArg('export-filename', $out);\r
-//            $inkscape->setArg(null, $in);\r
-//            $inkscape->execute();\r
-//            return;\r
-//        }\r
-\r
-        $pdftocairo = new CubeIT_CommandLine(self::PDFTOCAIRO);\r
-        $pdftocairo->setPath(CONVERTER_PATH);\r
-        $pdftocairo->setArg('f', $page);\r
-        $pdftocairo->setArg('l', $page);\r
-        $pdftocairo->setArg('r', 300);\r
-        $pdftocairo->setArg(null, '-expand');\r
-        $pdftocairo->setArg(null, '-svg');\r
-        $pdftocairo->setArg(null, $in);\r
-        $pdftocairo->setArg(null, $out);\r
-        $pdftocairo->execute();\r
+        if ($method === 'pdftocairo') {\r
+            $pdftocairo = new CubeIT_CommandLine(self::PDFTOCAIRO);\r
+            $pdftocairo->setPath(CONVERTER_PATH);\r
+            $pdftocairo->setArg('f', $page);\r
+            $pdftocairo->setArg('l', $page);\r
+            $pdftocairo->setArg('r', 300);\r
+            $pdftocairo->setArg(null, '-expand');\r
+            $pdftocairo->setArg(null, '-svg');\r
+            $pdftocairo->setArg(null, $in);\r
+            $pdftocairo->setArg(null, $out);\r
+            $pdftocairo->execute();\r
+        } else if ($method === 'inkscape') {\r
+            // inkscape --pdf-page=1 --export-type=svg --export-filename=i12.svg ./pdf/p12.pdf\r
+            $inkscape = new CubeIT_CommandLine('inkscape');\r
+            $inkscape->setArg('pdf-page', $page);\r
+            $inkscape->setArg('export-type', 'svg');\r
+            $inkscape->setArg('export-filename', $out);\r
+            $inkscape->setArg(null, $in);\r
+            $inkscape->execute();\r
+            $inkscape->debug();\r
+        } else if ($method === 'mu') {\r
+            /*\r
+             *\r
+text=text\r
+    Emit text as elements (inaccurate fonts).\r
+text=path\r
+    Emit text as elements (accurate fonts).\r
+no-reuse-images\r
+    Do not reuse images using <symbol> definitions.\r
+             */\r
+\r
+            $mu = new CubeIT_CommandLine('mutool');\r
+            $mu->setArg(null, 'extract');\r
+            $mu->setArg(null, $in);\r
+            $mu->execute();\r
+            $mu->debug();\r
+\r
+            $mu = new CubeIT_CommandLine('mutool');\r
+            $mu->setArg(null, 'convert');\r
+            $mu->setArg('O', 'text=text');\r
+            $mu->setArg('F', 'svg');\r
+            $mu->setArg('o', $out);\r
+            $mu->setArg(null, $in);\r
+            $mu->setArg(null, '1');\r
+            $mu->execute();\r
+            $mu->debug();\r
+\r
+            copy(str_replace('.svg', '1.svg', $out), $out);\r
+        }\r
     }\r
 \r
-    public static function makeTextSVGFile($in, $out)\r
+\r
+\r
+    public static function PDFToSVG($in, $page, $out, $textsOnly = true, $method = 'pdftocairo', $clean = true)\r
+    {\r
+        $tmp = CubeIT_Files::tempnam() . '.svg';\r
+\r
+        self::makeBaseSVGFile($in, $tmp, $page, $method);\r
+        if ($textsOnly) {\r
+            self::makeTextSVGFile($tmp, $out, $method);\r
+            unlink($tmp);\r
+        } else {\r
+            copy($tmp, $out);\r
+        }\r
+\r
+        if ($clean) {\r
+            wsTools::_optimizeSVG($out, $out);\r
+        }\r
+    }\r
+\r
+    public static function makeTextSVGFile($in, $out, $method = 'pdftocairo')\r
     {\r
         $svg = new DOMDocument();\r
         $svg->preserveWhiteSpace = false;\r
@@ -128,7 +175,10 @@ class wsPDFConvert
         $xpath->registerNamespace('svg', 'http://www.w3.org/2000/svg');\r
         $xpath->registerNamespace('xlink', 'http://www.w3.org/1999/xlink');\r
         $xpath->registerNamespace("php", "http://php.net/xpath");\r
-        $toDelete = array(\r
+        $xpath->registerNamespace("inkscape", "http://www.inkscape.org/namespaces/inkscape");\r
+        $xpath->registerNamespace("sodipodi", "http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd");\r
+\r
+        $pdftocairo = array(\r
 //            '//svg:defs/svg:clipPath',\r
 //            '//svg:defs/svg:image',\r
 //            '//svg:defs/svg:path',\r
@@ -144,13 +194,25 @@ class wsPDFConvert
             //'//svg:image',\r
         );\r
 \r
-        //global $svglog;\r
-        //$svglog = array('XPATH : ' . print_r($xpath, true));\r
-        foreach ($toDelete as $q) {\r
+        $inkscape = [\r
+            '//svg:path',\r
+            '//svg:image',\r
+        ];\r
+\r
+        $mu = [\r
+//            '//svg:image',\r
+//            '//svg:path',\r
+        ];\r
+\r
+        $todelete = $$method;\r
+\r
+//        global $svglog;\r
+//        $svglog = array('XPATH : ' . print_r($xpath, true));\r
+        foreach ($todelete as $q) {\r
             $list = $xpath->query($q);\r
-            // $svglog[] = "Evaluate xpath query " . $q;\r
-            // $svglog[] = 'Give ' . $list->length . ' results';\r
-            // $svglog[] = 'Deleting Nodes in ' . print_r($list, true);\r
+//            $svglog[] = "Evaluate xpath query " . $q;\r
+//            $svglog[] = 'Give ' . $list->length . ' results';\r
+//            $svglog[] = 'Deleting Nodes in ' . print_r($list, true);\r
             if (count($list)) {\r
                 foreach ($list as $node) {\r
                     /* @var $node DOMNode */\r