From: vincent@cubedesigners.com Date: Thu, 30 Sep 2021 15:07:26 +0000 (+0000) Subject: wip #4720 @1 X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=5d44a74ae8097c564ab33e7a38b86990702d9da7;p=cubeextranet.git wip #4720 @1 --- diff --git a/inc/ws/Controlleur/class.ws.maintenance.php b/inc/ws/Controlleur/class.ws.maintenance.php index b4d2399ab..d7bfba116 100644 --- a/inc/ws/Controlleur/class.ws.maintenance.php +++ b/inc/ws/Controlleur/class.ws.maintenance.php @@ -860,7 +860,7 @@ class wsMaintenance echo '
' . print_r($runs, true) . '
'; } - 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')); } } diff --git a/inc/ws/Util/class.ws.pdf.convert.php b/inc/ws/Util/class.ws.pdf.convert.php index ebac91d44..875473397 100644 --- a/inc/ws/Util/class.ws.pdf.convert.php +++ b/inc/ws/Util/class.ws.pdf.convert.php @@ -92,32 +92,79 @@ class wsPDFConvert } - public static function makeBaseSVGFile($in, $out, $page) + public static function makeBaseSVGFile($in, $out, $page, $method = 'pdftocairo') { -// if (stristr($in, '127174')) { -// // inkscape --pdf-page=1 --export-type=svg --export-filename=i12.svg ./pdf/p12.pdf -// $inkscape = new CubeIT_CommandLine('inkscape'); -// $inkscape->setArg('pdf-page', '1'); -// $inkscape->setArg('export-type', 'svg'); -// $inkscape->setArg('export-filename', $out); -// $inkscape->setArg(null, $in); -// $inkscape->execute(); -// return; -// } - - $pdftocairo = new CubeIT_CommandLine(self::PDFTOCAIRO); - $pdftocairo->setPath(CONVERTER_PATH); - $pdftocairo->setArg('f', $page); - $pdftocairo->setArg('l', $page); - $pdftocairo->setArg('r', 300); - $pdftocairo->setArg(null, '-expand'); - $pdftocairo->setArg(null, '-svg'); - $pdftocairo->setArg(null, $in); - $pdftocairo->setArg(null, $out); - $pdftocairo->execute(); + if ($method === 'pdftocairo') { + $pdftocairo = new CubeIT_CommandLine(self::PDFTOCAIRO); + $pdftocairo->setPath(CONVERTER_PATH); + $pdftocairo->setArg('f', $page); + $pdftocairo->setArg('l', $page); + $pdftocairo->setArg('r', 300); + $pdftocairo->setArg(null, '-expand'); + $pdftocairo->setArg(null, '-svg'); + $pdftocairo->setArg(null, $in); + $pdftocairo->setArg(null, $out); + $pdftocairo->execute(); + } else if ($method === 'inkscape') { + // inkscape --pdf-page=1 --export-type=svg --export-filename=i12.svg ./pdf/p12.pdf + $inkscape = new CubeIT_CommandLine('inkscape'); + $inkscape->setArg('pdf-page', $page); + $inkscape->setArg('export-type', 'svg'); + $inkscape->setArg('export-filename', $out); + $inkscape->setArg(null, $in); + $inkscape->execute(); + $inkscape->debug(); + } else if ($method === 'mu') { + /* + * +text=text + Emit text as elements (inaccurate fonts). +text=path + Emit text as elements (accurate fonts). +no-reuse-images + Do not reuse images using definitions. + */ + + $mu = new CubeIT_CommandLine('mutool'); + $mu->setArg(null, 'extract'); + $mu->setArg(null, $in); + $mu->execute(); + $mu->debug(); + + $mu = new CubeIT_CommandLine('mutool'); + $mu->setArg(null, 'convert'); + $mu->setArg('O', 'text=text'); + $mu->setArg('F', 'svg'); + $mu->setArg('o', $out); + $mu->setArg(null, $in); + $mu->setArg(null, '1'); + $mu->execute(); + $mu->debug(); + + copy(str_replace('.svg', '1.svg', $out), $out); + } } - public static function makeTextSVGFile($in, $out) + + + public static function PDFToSVG($in, $page, $out, $textsOnly = true, $method = 'pdftocairo', $clean = true) + { + $tmp = CubeIT_Files::tempnam() . '.svg'; + + self::makeBaseSVGFile($in, $tmp, $page, $method); + if ($textsOnly) { + self::makeTextSVGFile($tmp, $out, $method); + unlink($tmp); + } else { + copy($tmp, $out); + } + + if ($clean) { + wsTools::_optimizeSVG($out, $out); + } + } + + public static function makeTextSVGFile($in, $out, $method = 'pdftocairo') { $svg = new DOMDocument(); $svg->preserveWhiteSpace = false; @@ -128,7 +175,10 @@ class wsPDFConvert $xpath->registerNamespace('svg', 'http://www.w3.org/2000/svg'); $xpath->registerNamespace('xlink', 'http://www.w3.org/1999/xlink'); $xpath->registerNamespace("php", "http://php.net/xpath"); - $toDelete = array( + $xpath->registerNamespace("inkscape", "http://www.inkscape.org/namespaces/inkscape"); + $xpath->registerNamespace("sodipodi", "http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"); + + $pdftocairo = array( // '//svg:defs/svg:clipPath', // '//svg:defs/svg:image', // '//svg:defs/svg:path', @@ -144,13 +194,25 @@ class wsPDFConvert //'//svg:image', ); - //global $svglog; - //$svglog = array('XPATH : ' . print_r($xpath, true)); - foreach ($toDelete as $q) { + $inkscape = [ + '//svg:path', + '//svg:image', + ]; + + $mu = [ +// '//svg:image', +// '//svg:path', + ]; + + $todelete = $$method; + +// global $svglog; +// $svglog = array('XPATH : ' . print_r($xpath, true)); + foreach ($todelete as $q) { $list = $xpath->query($q); - // $svglog[] = "Evaluate xpath query " . $q; - // $svglog[] = 'Give ' . $list->length . ' results'; - // $svglog[] = 'Deleting Nodes in ' . print_r($list, true); +// $svglog[] = "Evaluate xpath query " . $q; +// $svglog[] = 'Give ' . $list->length . ' results'; +// $svglog[] = 'Deleting Nodes in ' . print_r($list, true); if (count($list)) { foreach ($list as $node) { /* @var $node DOMNode */