From dded1dc8972c1fd11a6bb57c3d7826abd44fc4ca Mon Sep 17 00:00:00 2001 From: "vincent@cubedesigners.com" Date: Mon, 22 Feb 2010 13:34:18 +0000 Subject: [PATCH] --- .../class.ws.conversion.session.php | 4 + inc/extranet/Metier/class.ws.document.php | 278 +++++++++++++----- 2 files changed, 207 insertions(+), 75 deletions(-) diff --git a/inc/extranet/Controlleur/class.ws.conversion.session.php b/inc/extranet/Controlleur/class.ws.conversion.session.php index 89a990b18..913495e69 100644 --- a/inc/extranet/Controlleur/class.ws.conversion.session.php +++ b/inc/extranet/Controlleur/class.ws.conversion.session.php @@ -37,6 +37,10 @@ class wsConversionSession { $this->processing = true; $this->initDocuments(); + foreach($this->documents as $doc){ + $doc->getTextes(); + } + $this->complete = true; $this->processing = false; } diff --git a/inc/extranet/Metier/class.ws.document.php b/inc/extranet/Metier/class.ws.document.php index 3b3196092..3f7d093f5 100644 --- a/inc/extranet/Metier/class.ws.document.php +++ b/inc/extranet/Metier/class.ws.document.php @@ -139,12 +139,40 @@ class wsDocument extends cubeMetier { return $this->generalInfos['pages']; } - public function getTexts() + public function processOnePage($page) + { + $this->getTexts($page); + $this->makeMiniShot($page); + $this->makeRealShot($page); + $out = $this->makeSWFFiles($page); + $this->extractLinks($page,$out,$multiply); + } + + public function processAllPages() + { + for($i = 1;$i <= $this->generalInfos['pages'];$i++) { + $this->processOnePage($i); + } + } + + public function processRange($range) + { + foreach($pages as $i) { + $this->processOnePage($i); + } + } + + public function getTexts($page = null) { $pdftotext = new cubeCommandLine('pdftotext', null, true); $pdftotext->setArg('q'); - $pdftotext->setArg('f', 1); - $pdftotext->setArg('l', 10000); + if (is_null($page)) { + $pdftotext->setArg('f', 1); + $pdftotext->setArg('l', 10000); + } else { + $pdftotext->setArg('f', $page); + $pdftotext->setArg('l', $page); + } $pdftotext->setArg('-eol', 'unix'); $pdftotext->setArg('-enc', 'UTF-8'); $pdftotext->setArg(null, $this->in); @@ -153,26 +181,26 @@ class wsDocument extends cubeMetier { $this->addToLog($pdftotext); } - public function makeMiniShot() + public function makeMiniShot($page = null) { - $this->makeShotFixedWidth('p', 300, 70, 4, 'GS'); + $this->makeShotFixedWidth($page, 'p', 100, 70, 4, 'GS'); } - public function makeRealShot() + public function makeRealShot($page = null) { - $this->makeShot('te', 72); + $this->makeShot($page, 'te', 72); } - public function makeShotFixedWidth($prefix, $w, $quality = 90, $antialiasing = 4, $method = 'GS') + public function makeShotFixedWidth($page = null, $prefix = '', $w = 100, $quality = 90, $antialiasing = 4, $method = 'GS') { // Make thumbs of $w width // resolution 72 make 1pt=1px $width = $this->generalInfos['size'][0]; $ratio = $width / $w; - $this->makeShot($prefix, round(72 / $ratio, 2), $quality, $antialiasing, $method); + $this->makeShot($page, $prefix, round(72 / $ratio, 2), $quality, $antialiasing, $method); } - public function makeShotFixedHeight($prefix, $h, $quality = 90, $antialiasing = 4, $method = 'GS') + public function makeShotFixedHeight($page = null, $prefix = '', $h = '', $quality = 90, $antialiasing = 4, $method = 'GS') { // Make thumbs of $w height // resolution 72 make 1pt=1px @@ -181,7 +209,7 @@ class wsDocument extends cubeMetier { $this->makeShot($prefix, round(72 / $ratio, 2), $quality, $antialiasing, $method); } - public function makeShot($prefix, $resolution = 72, $quality = 90, $antialiasing = 4, $method = 'GS') + public function makeShot($page = null, $prefix = '', $resolution = 72, $quality = 90, $antialiasing = 4, $method = 'GS') { // Delete all old files for($i = 1;$i <= $this->generalInfos['pages'];$i++) { @@ -190,13 +218,16 @@ class wsDocument extends cubeMetier { } } if ($method == 'GS') { - $this->makeShotGS($prefix, $resolution, $quality, $antialiasing); + $this->makeShotGS($page, $prefix, $resolution, $quality, $antialiasing); } elseif ($method == 'PNM') { - $this->makeShotPNM($prefix, $resolution, $quality, $antialiasing); + $this->makeShotPNM($page, $prefix, $resolution, $quality, $antialiasing); } // Test the result by checking all files $error = false; - for($i = 1;$i <= $this->generalInfos['pages'];$i++) { + $startpage = is_null($page)?1:$page; + $endpage = is_null($page)?$this->generalInfos['pages']:$page; + + for($i = $startpage;$i <= $endpage;$i++) { if (!file_exists($this->out . $prefix . $i . '.jpg')) { $error = true; break; @@ -205,14 +236,14 @@ class wsDocument extends cubeMetier { // If error, we try to make thumbs with other method if ($error) { if ($method == 'GS') { - $this->makeShotPNM($prefix, $resolution, $quality, $antialiasing); + $this->makeShotPNM($page, $prefix, $resolution, $quality, $antialiasing); } elseif ($method == 'PNM') { - $this->makeShotGS($prefix, $resolution, $quality, $antialiasing); + $this->makeShotGS($page, $prefix, $resolution, $quality, $antialiasing); } } } - protected function makeShotGS($prefix, $resolution = 72, $quality = 90, $antialiasing = 4) + protected function makeShotGS($page = null, $prefix = null, $resolution = 72, $quality = 90, $antialiasing = 4) { // Fabrication des thumbanails avec ghostscript $gs = new cubeCommandLine('gs', null, true); @@ -227,6 +258,10 @@ class wsDocument extends cubeMetier { $gs->setArg('-dTextAlphaBits=' . $antialiasing); $gs->setArg('-dGraphicsAlphaBits=' . $antialiasing); // $gs->setArg('-dUseCropBox'); + if (!is_null($page)) { + $gs->setArg('-dStartPage=' . $page); + $gs->setArg('-dEndPage=' . $page); + } $gs->setArg('-sOutputFile=' . $this->out . '/' . $prefix . '%d.jpg'); $gs->setArg('-dAutoRotatePages=/None'); $gs->setArg(null, $this->in); @@ -234,14 +269,19 @@ class wsDocument extends cubeMetier { $this->addToLog($gs); } - protected function makeShotPNM($prefix, $resolution = 72, $quality = 90, $antialiasing = 4) + protected function makeShotPNM($page = null, $prefix = '', $resolution = 72, $quality = 90, $antialiasing = 4) { $antialiasing = $antialiasing?'yes':'no'; $resolution = round($resolution); // Exporte les fichiers $pdftoppm = new cubeCommandLine('pdftoppm', null, true); - $pdftoppm->setArg('f', 1); - $pdftoppm->setArg('l', 10000); + if (is_null($page)) { + $pdftoppm->setArg('f', 1); + $pdftoppm->setArg('l', 10000); + } else { + $pdftoppm->setArg('f', $page); + $pdftoppm->setArg('l', $page); + } $pdftoppm->setArg('-freetype yes'); $pdftoppm->setArg('-aa ' . $antialiasing); @@ -255,7 +295,9 @@ class wsDocument extends cubeMetier { $pdftoppm->execute(); $this->addToLog($pdftoppm); - for($i = 1;true;$i++) { + $startpage = is_null($page)?1:$page; + + for($i = $startpage;true;$i++) { $ppmfile = $this->out . 'ppm-' . cubeMath::fill($i, 6) . '.ppm'; $jpegfile = $this->out . $prefix . $i . '.jpg'; if (!file_exists($ppmfile)) { @@ -272,13 +314,13 @@ class wsDocument extends cubeMetier { } } - public function makeSWFFiles($resolution = 150, $quality = 90, $storeAllChars = true, $maxObjects = 1800, $method = 'flatten') + public function makeSWFFiles($page = null, $resolution = 150, $quality = 90, $storeAllChars = true, $maxObjects = 1800, $method = 'normal') { if ($maxObjects <= 1) { $method = 'poly2bitmap'; } - $out = $this->pdf2swf($resolution, $quality, $storeAllChars, $method); + $out = $this->pdf2swf($page, $resolution, $quality, $storeAllChars, $method); // Analyse de la sortie pour détecter des typos manquantes $overflow = false; $overflowObjects = false; @@ -312,14 +354,16 @@ class wsDocument extends cubeMetier { if (!$written && !$overflow) { // Si le fichier n'a pas été généré et que il était en plus n'était pas en overflow, // on tente directement la méthode de barbare + $out = $this->pdf2swf($page, $resolution, $quality, false, 'barbare'); } elseif ($overflow || $overflowObjects) { // Si le nombre d'objets max ou définis par l'utilisateur est trop important // On écrase les graphismes. - $out = $this->pdf2swf($resolution, $quality, $storeAllChars, 'poly2bitmap'); + $out = $this->pdf2swf($page, $resolution, $quality, $storeAllChars, 'poly2bitmap'); } + return $out; } - protected function pdf2swf($resolution = 150, $quality = 90, $storeAllChars = true, $method = 'flatten') + protected function pdf2swf($page = null, $resolution = 150, $quality = 90, $storeAllChars = true, $method = 'normal') { /* -h , --help Print short help message and exit @@ -393,65 +437,97 @@ splinequality= Set the quality of spline convertion to value (0-100 disablelinks Disable links. */ - $resolution2multiply = array(72 => 2, 100 => 2, 150 => 3, 200 => 3, 300 => 3, 450 => 4, 600 => 5); - - $pdf2swf = new cubeCommandLine('pdf2swf', null, true); - if ($method == 'flatten') { - // Default - $pdf2swf->setArg('flatten'); - $multiply = 1; - } elseif ($method == 'poly2bitmap') { - // Raster graphics, keep texts - $pdf2swf->setArg('poly2bitmap'); - $multiply = $resolution2multiply[$resolution]; - $pdf2swf->setArg('multiply', $multiply); - } elseif ($method == 'bitmap') { - // Raster all - $pdf2swf->setArg('bitmap'); - $multiply = $resolution2multiply[$resolution]; - $pdf2swf->setArg('multiply', $multiply); - } + if ($method != 'barbare') { + $resolution2multiply = array(72 => 2, 100 => 2, 150 => 3, 200 => 3, 300 => 3, 450 => 4, 600 => 5); - $pdf2swf->setArg('stop'); - $pdf2swf->setManualArg('-vvvv'); - $pdf2swf->setArg('T', 9); - if ($storeAllChars) { - $pdf2swf->setArg('fonts'); - } - if (DEV) { - $pdf2swf->setArg('F', 'C:/Windows/Fonts'); - } else { - $pdf2swf->setArg('F', '/home/typo/fonts'); - } - $pdf2swf->setArg('set subpixels', $resolution / 72); - $pdf2swf->setArg('set jpegquality', $quality); - $pdf2swf->setArg('set disablelinks'); - $pdf2swf->setArg('set dots'); + $pdf2swf = new cubeCommandLine('pdf2swf', null, true); + if (!is_null($page)) { + $pdf2swf->setArg('p', $page); + } + if ($method == 'normal') { + // Default + $multiply=1; + } elseif ($method == 'flatten') { + $pdf2swf->setArg('flatten'); + $multiply=1; + } elseif ($method == 'poly2bitmap') { + // Raster graphics, keep texts + $pdf2swf->setArg('poly2bitmap'); + $multiply = $resolution2multiply[$resolution]; + $pdf2swf->setArg('multiply', $multiply); + } elseif ($method == 'bitmap') { + // Raster all + $pdf2swf->setArg('bitmap'); + $multiply = $resolution2multiply[$resolution]; + $pdf2swf->setArg('multiply', $multiply); + } + + $pdf2swf->setArg('stop'); + $pdf2swf->setManualArg('-vvvv'); + $pdf2swf->setArg('T', 8); + if ($storeAllChars) { + $pdf2swf->setArg('fonts'); + } + if (DEV) { + $pdf2swf->setArg('F', 'C:/Windows/Fonts'); + } else { + $pdf2swf->setArg('F', '/home/typo/fonts'); + } + $pdf2swf->setArg('set subpixels', $resolution / 72); + $pdf2swf->setArg('set jpegquality', $quality); + $pdf2swf->setArg('set disablelinks'); + $pdf2swf->setArg('set dots'); - $pdf2swf->setArg(null, $this->in); - $pdf2swf->setArg('output', $this->out . 'p%.swf'); - $pdf2swf->execute(); + $pdf2swf->setArg(null, $this->in); + $pdf2swf->setArg('output', $this->out . 'p%.swf'); + $pdf2swf->execute(); - $this->addToLog($pdf2swf, true); + $this->addToLog($pdf2swf, true); + return $pdf2swf->outputfile; + } else { + return $this->pdf2swfBarbare($page, $resolution, $quality); + } + } - return $pdf2swf->outputfile; + protected function makeAS3($swffile) + { + $swfcombine = new cubeCommandLine('swfcombine'); + $swfcombine->setEnv('PATH', self::$path); + $swfcombine->setArg('merge'); + $swfcombine->setArg('stack1'); + $swfcombine->setArg('z'); + $swfcombine->setManualArg('-vvvv'); + $swfcombine->setArg('o', $swffile); + $swfcombine->setArg(null, ROOT . '/swf/as3Container.swf'); + $swfcombine->setManualArg('content=' . $swffile); + $swfcombine->execute(); + $this->addToLog($swfcombine); } - protected function pdf2swfBarbare($resolution, $quality, $page = 'all') + protected function pdf2swfBarbare($page = null, $resolution = 150, $quality = 85) { // Fabrique les images - $this->makeShot('barbare', $resolution, $quality, 'PNM'); + $this->makeShot($page, 'barbare', $resolution, $quality, 'PNM'); // A partir des images, on crée les swf - $jpeg2swf = new cubeCommandLine('jpeg2swf'); - $jpeg2swf->setArg('q', $quality); - $jpeg2swf->setArg('o', $this->out . 'p' . $i . '.swf'); - $jpeg2swf->setArg('f'); - $jpeg2swf->setArg('T', 9); - $jpeg2swf->setArg(null, $this->out . 'barbare' . $i . '.jpg'); - $jpeg2swf->execute(); - $this->addToLog($jpeg2swf); - // Suppression du jpeg - @unlink($this->out . '/barbare' . $page . '.jpg') ; + if (is_null($page)) { + $startpage = 1; + $endpage = $this->generalInfos['pages']; + } else { + $startpage = $endpage = $page; + } + + for($i = $startpage;$i <= $endpage;$i++) { + $jpeg2swf = new cubeCommandLine('jpeg2swf'); + $jpeg2swf->setArg('q', $quality); + $jpeg2swf->setArg('o', $this->out . 'p' . $i . '.swf'); + $jpeg2swf->setArg('f'); + $jpeg2swf->setArg(null, $this->out . 'barbare' . $i . '.jpg'); + $jpeg2swf->execute(); + $this->addToLog($jpeg2swf); + // Suppression du jpeg + @unlink($this->out . '/barbare' . $i . '.jpg') ; + } + return ''; } public function addToLog($cl, $output = true) @@ -463,6 +539,58 @@ disablelinks Disable links. fwrite($this->log_pointer, $c); } + public function extractLinks($page, $logfile, $multiply = 1) + { + /* +DEBUG drawlink +TRACE drawlink 122.00/579.00 236.00/579.00 236.00/527.00 122.00/527.00 +DEBUG | moveTo 122.00 579.00 +DEBUG | lineTo 236.00 579.00 +DEBUG | lineTo 236.00 527.00 +DEBUG | lineTo 122.00 527.00 +DEBUG | lineTo 122.00 579.00 +TRACE drawlink action=3 +TRACE drawlink s=http://www.ladocumentationfrancaise.fr/ +*/ + + $fp = fopen($logfile, 'rb'); + $log = 'BEGIN extracting link' . "\n"; + $link = null; + while ($line = fgets($fp)) { + $line = trim($line); + if (preg_match('|TRACE drawlink(( [-0-9\./]+)+)|', $line, $matches)) { + $log .= 'FOUND a link' . "\n"; + $link = new fwsLink($multiply); + $log .= 'SETTING POINTS ' . $matches[1] . "\n"; + $points = explode(' ', trim($matches[1])); + foreach($points as $point) { + $p = explode('/', $point); + $log .= 'SET POINT ' . $p[0] . ' ' . $p[1] . "\n"; + $link->addPoint($p); + } + } elseif (preg_match('|TRACE drawlink action=(.*)|', $line, $matches)) { + $log .= 'SETTING ACTION ' . $matches[1] . "\n"; + if (is_null($link)) { + continue; + } + $link->setAction($matches[1]); + } elseif (preg_match('|TRACE drawlink s=(.*)|', $line, $matches)) { + $log .= 'SETTING LINK ' . $matches[1] . "\n"; + if (is_null($link)) { + continue; + } + $link->setLink($matches[1]); + $this->links[$page][] = $link->toArray(); + $log .= 'SAVE LINK' . print_r($link->toArray(), true) . "\n"; + $link = null; + } + } + $log .= 'END OF EXTRACTING' . "\n"; + fclose($fp); + + return $log; + } + public function __destruct() { if (isset($this->log_pointer)) { -- 2.39.5