From: vincent@cubedesigners.com Date: Tue, 2 Mar 2010 08:44:19 +0000 (+0000) Subject: (no commit message) X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=c5b43c837ec52f1606090a8954160ba091c5ecca;p=cubeextranet.git --- diff --git a/inc/ws/Controlleur/class.ws.conversion.session.php b/inc/ws/Controlleur/class.ws.conversion.session.php index 61ca77761..d15820cb8 100644 --- a/inc/ws/Controlleur/class.ws.conversion.session.php +++ b/inc/ws/Controlleur/class.ws.conversion.session.php @@ -58,11 +58,13 @@ class wsConversionSession { foreach($this->documents as $doc) { $this->currentDoc = $doc; + $this->serialize(); + $this->currentDoc->globalOperations(); for($i = 1;$i <= $doc->generalInfos['pages'];$i++) { $this->currentDocPage = $i; $this->totalDocPage = $doc->generalInfos['pages']; $this->setProgress(($this->processedPages / $this->totalPages) * 100); - $doc->processOnePage($i); + $this->currentDoc->processOnePage($i); $this->processedPages++; } $doc = $dao->updateFromObject($doc); @@ -111,7 +113,7 @@ class wsConversionSession { public function destroy() { if (file_exists(self::getCachePath($this->guid))) { - //unlink(self::getCachePath($this->guid)); + // unlink(self::getCachePath($this->guid)); } } diff --git a/inc/ws/DAO/class.ws.dao.document.php b/inc/ws/DAO/class.ws.dao.document.php index 52ef5f355..3000a081e 100644 --- a/inc/ws/DAO/class.ws.dao.document.php +++ b/inc/ws/DAO/class.ws.dao.document.php @@ -1,7 +1,7 @@ 2, 100 => 2, 150 => 3, 200 => 3, 300 => 3, 450 => 4, 600 => 5); + public function init() { $this->out = ROOT . '/docs/' . $this->document_id . '/'; @@ -49,20 +47,16 @@ class wsDocument extends cubeMetier { $this->in = $this->out . 'original.pdf'; $this->uncompressed = $this->out . 'uncompressed.pdf'; $this->infos = $this->out . 'infos.txt'; - $this->textes = $this->out . 'textes.txt'; - $this->phperrors = $this->out . 'php.err'; if (!file_exists($this->out)) { mkdir($this->out, 0755, true); } $this->log_pointer = fopen($this->log, 'a'); - // $this->_memoErrorLog = ini_get('error_log'); - // ini_set('error_log', $this->phperrors); } public function copyOriginal($tmp_file) { move_uploaded_file($tmp_file, $this->in); - $this->uncompress(); + //$this->uncompress(); } public function uncompress() @@ -170,9 +164,14 @@ class wsDocument extends cubeMetier { return $this->generalInfos['pages']; } + public function globalOperations() + { + $this->getLinks(); + $this->getTexts(); + } + public function processOnePage($page) { - $this->getTexts($page); $this->makeMiniShot($page); $this->makeRealShot($page); $this->makeSWFFiles($page); @@ -193,19 +192,26 @@ class wsDocument extends cubeMetier { } } - public function getTexts($page) + public function getTexts() { + $temp = cubeFiles::tempnam(); $pdftotext = new cubeCommandLine('pdftotext', null, true); $pdftotext->setPath(CONVERTER_PATH); $pdftotext->setArg('q'); - $pdftotext->setArg('f', $page); - $pdftotext->setArg('l', $page); $pdftotext->setArg('-eol', 'unix'); $pdftotext->setArg('-enc', 'UTF-8'); $pdftotext->setArg(null, $this->in); - $pdftotext->setArg(null, $this->out . 'p' . $page . '.txt'); + $pdftotext->setArg(null, $temp); $pdftotext->execute(); $this->addToLog($pdftotext); + + $pages = preg_split("|\x{u000c}|", file_get_contents($temp)); + foreach($pages as $i => $page) { + $i++; + file_put_contents($this->out . 'p' . $i . '.txt', cubeText::removeAccents($page)); + } + + unlink($temp); } public function makeMiniShot($page) @@ -326,21 +332,21 @@ class wsDocument extends cubeMetier { } } - public function makeSWFFiles($page , $resolution = 150, $quality = 90, $storeAllChars = true, $maxObjects = 1800, $method = 0, &$muliply = 1) + public function makeSWFFiles($page , $resolution = 150, $quality = 90, $storeAllChars = true, $maxObjects = 1800, $method = 0) { if ($maxObjects <= 1) { $method = self::POLY2BITMAP; } - $out = $this->pdf2swf($page, $resolution, $quality, $storeAllChars, $method, $multiply); + $out = $this->pdf2swf($page, $resolution, $quality, $storeAllChars, $method); if ($method < self::BARBARE_PNM) { // Analyse de la sortie pour détecter des typos manquantes $overflow = false; $overflowObjects = false; $written = false; $missing_fonts = array(); - if (file_exists($out['outputfile'])) { - $fp = fopen($out['outputfile'], 'rb'); + if (file_exists($out)) { + $fp = fopen($out, 'rb'); while ($line = fgets($fp)) { if (preg_match('|Try putting a TTF version of that font \(named \"([A-Z-_0-9.]*)\"\)|Uui', trim($line), $matches)) { $missing_fonts[] = $matches[1]; @@ -356,20 +362,15 @@ class wsDocument extends cubeMetier { if (!is_null($page) && file_exists($this->out . 'p' . $page . '.swf')) { $written = true; } - if ($written && $method < self::BITMAP && !isset($this->_links[$page])) { - $this->_links[$page] = $this->extractLinks($page, $out['outputfile'], $out['multiply']); - } // On teste si le fichier est écrit et qu'il a été généré par le premier niveau if ($method < self::POLY2BITMAP && $written) { $overflowObjects = $this->checkObjectsNumber($this->out . 'p' . $page . '.swf', $maxObjects); } if (!$written || $overflow || $overflowObjects) { - return $this->makeSWFFiles($page, $resolution, $quality, $storeAllChars, $maxObjects, $method + 1, $multiply); + $this->makeSWFFiles($page, $resolution, $quality, $storeAllChars, $maxObjects, $method + 1); } } - - return $out; } protected function checkObjectsNumber($file, $maxObjects) @@ -388,6 +389,16 @@ class wsDocument extends cubeMetier { return false; } + /** + * wsDocument::pdf2swf() + * + * @param mixed $page + * @param integer $resolution + * @param integer $quality + * @param mixed $storeAllChars + * @param integer $method + * @return + */ protected function pdf2swf($page , $resolution = 150, $quality = 90, $storeAllChars = true, $method = 0) { /* @@ -467,8 +478,6 @@ disablelinks Disable links. } if ($method < self::BARBARE_PNM) { - $resolution2multiply = array(72 => 2, 100 => 2, 150 => 3, 200 => 3, 300 => 3, 450 => 4, 600 => 5); - $pdf2swf = new cubeCommandLine('pdf2swf', null, true); $pdf2swf->setPath(CONVERTER_PATH); @@ -483,17 +492,17 @@ disablelinks Disable links. } elseif ($method == self::POLY2BITMAP) { // Raster graphics, keep texts $pdf2swf->setArg('poly2bitmap'); - $multiply = $resolution2multiply[$resolution]; + $multiply = self::$resolution2multiply[$resolution]; $pdf2swf->setArg('multiply', $multiply); } elseif ($method == self::BITMAP) { // Raster all $pdf2swf->setArg('bitmap'); - $multiply = $resolution2multiply[$resolution]; + $multiply = self::$resolution2multiply[$resolution]; $pdf2swf->setArg('multiply', $multiply); } $pdf2swf->setArg('stop'); - $pdf2swf->setManualArg('-vvvv'); + $pdf2swf->setManualArg('-v'); $pdf2swf->setArg('T', 8); if ($storeAllChars) { $pdf2swf->setArg('fonts'); @@ -513,9 +522,8 @@ disablelinks Disable links. $pdf2swf->execute(); $this->addToLog($pdf2swf, true); - return array('outputfile' => $pdf2swf->outputfile, 'multiply' => $multiply, 'object' => $pdf2swf); } else { - return array('outputfile' => $this->pdf2swfBarbare($page, $resolution, $quality, $method), 'multiply' => 1); + $this->pdf2swfBarbare($page, $resolution, $quality, $method); } } @@ -536,6 +544,16 @@ disablelinks Disable links. $this->addToLog($swfcombine); } + protected function getLinks() + { + $fwstk = new cubeCommandLine('fwstk', 'C:\Users\Vincent\Desktop\out.txt', false); + $fwstk->setPath(CONVERTER_PATH); + $fwstk->setArg('--input ' . $this->in); + $fwstk->setArg('--extractLinks ' . $this->out . 'p%d.csv'); + $fwstk->execute(); + $this->addToLog($fwstk); + } + protected function pdf2swfBarbare($page, $resolution = 150, $quality = 85, $method = 4) { // Fabrique les images @@ -573,65 +591,11 @@ disablelinks Disable links. fwrite($this->log_pointer, $c); } - public function extractLinks($page, $outputfile, $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($outputfile, '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 wsLink($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"; - $this->addToLog($log); - fclose($fp); - - return $log; - } - public function __destruct() { if (isset($this->log_pointer) && is_resource($this->log_pointer)) { fclose($this->log_pointer); } - // ini_set('error_log', $this->_memoErrorLog); } }