From: vincent@cubedesigners.com Date: Tue, 23 Feb 2010 09:05:41 +0000 (+0000) Subject: (no commit message) X-Git-Url: http://git.cubedesigners.com/?a=commitdiff_plain;h=17a595a3a28a3c74c744fa00ff91061b0e2002e8;p=cubeextranet.git --- diff --git a/inc/extranet/Controlleur/class.ws.conversion.session.php b/inc/extranet/Controlleur/class.ws.conversion.session.php index 913495e69..6c0accbfa 100644 --- a/inc/extranet/Controlleur/class.ws.conversion.session.php +++ b/inc/extranet/Controlleur/class.ws.conversion.session.php @@ -6,8 +6,10 @@ class wsConversionSession { protected $guid; protected $progress = 0; protected $processing = false; + protected $inited=false; protected $complete = false; protected $totalPages = null; + protected $processedPages = 0; public function __construct($guid) { @@ -28,21 +30,28 @@ class wsConversionSession { $this->totalPages = 0; foreach($this->documents as $doc) { - $this->totalPages += $doc->getPagesNumber; + $this->totalPages += $doc->getPagesNumber(); } + $inited=true; } public function process() { $this->processing = true; $this->initDocuments(); + $this->serialize(); - foreach($this->documents as $doc){ - $doc->getTextes(); + foreach($this->documents as $doc) { + for($i = 1;$i <= $doc->generalInfos['pages'];$i++) { + $doc->processOnePage($i); + $this->processedPages++; + $this->setProgress(($this->processedPages / $this->totalPages) * 100); + } } $this->complete = true; $this->processing = false; + $this->setProgress(100); } public function getProgress() @@ -56,6 +65,16 @@ class wsConversionSession { $this->serialize(); } + public function getTotalPages() + { + return $this->totalPages; + } + + public function getProcessedPages() + { + return $this->processedPages; + } + public function serialize() { file_put_contents(self::getCachePath($this->guid), serialize($this)); @@ -63,7 +82,7 @@ class wsConversionSession { public function __destruct() { - $this->serialize(); + //$this->serialize(); } public static function openFromGUID($guid) diff --git a/inc/extranet/Controlleur/class.ws.flash.php b/inc/extranet/Controlleur/class.ws.flash.php index 05f60190d..096fc428e 100644 --- a/inc/extranet/Controlleur/class.ws.flash.php +++ b/inc/extranet/Controlleur/class.ws.flash.php @@ -71,6 +71,7 @@ class wsFlash extends cubeFlashGateway { $_SESSION['sessionConversionGUID'] = $sessionConversionGUID = uniqid('conversion_', true); $session = new wsConversionSession($sessionConversionGUID); $session->setDocuments($_SESSION['conversionSession']); + unset($_SESSION['conversionSession']); $session->serialize(); $http = new cubeHTTP($_SERVER['HTTP_HOST']); @@ -94,6 +95,8 @@ class wsFlash extends cubeFlashGateway { set_time_limit(1); $session = wsConversionSession::openFromGUID($_SESSION['sessionConversionGUID']); $this->xml->addChild('progress', $session->getProgress()); + $this->xml->addChild('totalPages',$session->getTotalPages()); + $this->xml->addChild('processedPages',$session->getProcessedPages()); } } diff --git a/inc/extranet/DAO/class.ws.dao.document.php b/inc/extranet/DAO/class.ws.dao.document.php index b3276a494..918987093 100644 --- a/inc/extranet/DAO/class.ws.dao.document.php +++ b/inc/extranet/DAO/class.ws.dao.document.php @@ -4,6 +4,7 @@ class wsDAODocument extends extranetDAO { { $document = new wsDocument(); $document->document_id = $r->document_id; + $document->init(); $document->file = $r->file; $document->proprietaire = $r->proprietaire; $document->pages = $r->pages; diff --git a/inc/extranet/Metier/_common.php b/inc/extranet/Metier/_common.php index 0501d9c39..af70ffc83 100644 --- a/inc/extranet/Metier/_common.php +++ b/inc/extranet/Metier/_common.php @@ -19,6 +19,7 @@ $__autoload['wsThemeParametres'] = dirname(__FILE__) . '/class.ws.theme.parametr $__autoload['wsBookParametres'] = dirname(__FILE__) . '/class.ws.book.parametres.php'; $__autoload['wsLangueTextes'] = dirname(__FILE__) . '/class.ws.langue.textes.php'; $__autoload['wsDocument'] = dirname(__FILE__) . '/class.ws.document.php'; +$__autoload['wsLink'] = dirname(__FILE__) . '/class.ws.link.php'; $__autoload['wsDocumentLocalInfos'] = dirname(__FILE__) . '/class.ws.document.localinfos.php'; ?> \ No newline at end of file diff --git a/inc/extranet/Metier/class.ws.document.php b/inc/extranet/Metier/class.ws.document.php index 3f7d093f5..3b1218052 100644 --- a/inc/extranet/Metier/class.ws.document.php +++ b/inc/extranet/Metier/class.ws.document.php @@ -30,8 +30,15 @@ class wsDocument extends cubeMetier { private $_basicInfos = null; private $_advancedInfos = null; + private $_links = array(); - public function copyOriginal($tmp_file) + const NORMAL = 0; + const FLATTEN = 1; + const POLY2BITMAP = 2; + const BITMAP = 3; + const BARBARE = 4; + + public function init() { $this->out = ROOT . '/docs/' . $this->document_id . '/'; $this->log = $this->out . 'log.txt'; @@ -42,6 +49,10 @@ class wsDocument extends cubeMetier { mkdir($this->out, 0755, true); } $this->log_pointer = fopen($this->log, 'a'); + } + + public function copyOriginal($tmp_file) + { move_uploaded_file($tmp_file, $this->in); } @@ -59,6 +70,7 @@ class wsDocument extends cubeMetier { { if (is_null($this->_basicInfos)) { $pdfinfo = new cubeCommandLine('pdfinfo', null, false); + $pdfinfo->setPath(CONVERTER_PATH); $pdfinfo->setArg('-box'); $pdfinfo->setArg('f', 1); $pdfinfo->setArg('l', 10000); @@ -75,6 +87,7 @@ class wsDocument extends cubeMetier { { if (is_null($this->_advancedInfos)) { $pdftk = new cubeCommandLine('pdftk', null, true); + $pdftk->setPath(CONVERTER_PATH); $pdftk->setArg(null, $this->in); $pdftk->setArg(null, 'dump_data'); $pdftk->execute(); @@ -144,8 +157,7 @@ class wsDocument extends cubeMetier { $this->getTexts($page); $this->makeMiniShot($page); $this->makeRealShot($page); - $out = $this->makeSWFFiles($page); - $this->extractLinks($page,$out,$multiply); + $this->makeSWFFiles($page); } public function processAllPages() @@ -165,6 +177,7 @@ class wsDocument extends cubeMetier { public function getTexts($page = null) { $pdftotext = new cubeCommandLine('pdftotext', null, true); + $pdftotext->setPath(CONVERTER_PATH); $pdftotext->setArg('q'); if (is_null($page)) { $pdftotext->setArg('f', 1); @@ -206,7 +219,7 @@ class wsDocument extends cubeMetier { // resolution 72 make 1pt=1px $height = $this->generalInfos['size'][1]; $ratio = $height / $h; - $this->makeShot($prefix, round(72 / $ratio, 2), $quality, $antialiasing, $method); + $this->makeShot($page, $prefix, round(72 / $ratio, 2), $quality, $antialiasing, $method); } public function makeShot($page = null, $prefix = '', $resolution = 72, $quality = 90, $antialiasing = 4, $method = 'GS') @@ -243,11 +256,12 @@ class wsDocument extends cubeMetier { } } - protected function makeShotGS($page = null, $prefix = null, $resolution = 72, $quality = 90, $antialiasing = 4) + protected function makeShotGS($page = null, $prefix = '', $resolution = 72, $quality = 90, $antialiasing = 4) { // Fabrication des thumbanails avec ghostscript $gs = new cubeCommandLine('gs', null, true); - // $gs->setEnv('GS_FONTPATH', '/home/typo/fonts'); + $gs->setPath(CONVERTER_PATH); + $gs->setEnv('GS_FONTPATH', FONT_PATH); $gs->setArg('-dBATCH'); $gs->setArg('-dNOPAUSE'); $gs->setArg('-dNOPROMPT'); @@ -275,6 +289,7 @@ class wsDocument extends cubeMetier { $resolution = round($resolution); // Exporte les fichiers $pdftoppm = new cubeCommandLine('pdftoppm', null, true); + $pdftoppm->setPath(CONVERTER_PATH); if (is_null($page)) { $pdftoppm->setArg('f', 1); $pdftoppm->setArg('l', 10000); @@ -304,6 +319,7 @@ class wsDocument extends cubeMetier { break; } $pnmtojpeg = new cubeCommandLine('pnmtojpeg', $jpegfile, false); + $pnmtojpeg->setPath(CONVERTER_PATH); $pnmtojpeg->setArg('-quality=' . $quality); $pnmtojpeg->setArg('-density=' . $resolution . 'x' . $resolution . 'dpi'); $pnmtojpeg->setManualArg($ppmfile); @@ -314,56 +330,70 @@ class wsDocument extends cubeMetier { } } - public function makeSWFFiles($page = null, $resolution = 150, $quality = 90, $storeAllChars = true, $maxObjects = 1800, $method = 'normal') + public function makeSWFFiles($page = null, $resolution = 150, $quality = 90, $storeAllChars = true, $maxObjects = 1800, $method = 0, &$muliply = 1) { if ($maxObjects <= 1) { - $method = 'poly2bitmap'; + $method = self::POLY2BITMAP; } - $out = $this->pdf2swf($page, $resolution, $quality, $storeAllChars, $method); - // Analyse de la sortie pour détecter des typos manquantes - $overflow = false; - $overflowObjects = false; - $written = false; - $missing_fonts = array(); - $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]; - } elseif (stristr($line, 'ID Table overflow')) { - $overflow = true; - } elseif (stristr($line, 'NOTICE SWF written')) { - $written = true; - } elseif (stristr($line, 'NOTICE Writing SWF file')) { + $out = $this->pdf2swf($page, $resolution, $quality, $storeAllChars, $method, $multiply); + if ($method < self::BARBARE) { + // 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'); + 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]; + } elseif (stristr($line, 'ID Table overflow')) { + $overflow = true; + } elseif (stristr($line, 'NOTICE SWF written')) { + $written = true; + } elseif (stristr($line, 'NOTICE Writing SWF file')) { + $written = true; + } + } + } + if (!is_null($page) && file_exists($this->out . 'p' . $page . '.swf')) { $written = true; } - } - // On teste si le fichier est écrit et qu'il a été généré par le premier niveau - if ($method == 'flatten' && $written) { - $swfstrings = new cubeCommandLine($this->swftools . '/swfdump', null, true); - $swfstrings->setArg('t'); - $swfstrings->setArg(null, $this->out . '/temp.swf'); - $swfstrings->execute(); - - str_replace('[01a]', '', $swfstrings->output, $nbObjects); - if ($nbObjects > $maxObjects) { - $overflowObjects = true; + if ($written && $method < self::BITMAP && !isset($this->_links[$page])) { + file_put_contents(ROOT . '/test.txt', print_r($out, true)); + $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); } } - // On traite les erreurs - 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($page, $resolution, $quality, $storeAllChars, 'poly2bitmap'); - } + return $out; } - protected function pdf2swf($page = null, $resolution = 150, $quality = 90, $storeAllChars = true, $method = 'normal') + protected function checkObjectsNumber($file, $maxObjects) + { + $swfdump = new cubeCommandLine('swfdump', null, true); + $swfdump->setPath(CONVERTER_PATH); + $swfdump->setArg('t'); + $swfdump->setArg(null, $file); + $swfdump->execute(); + $this->addToLog($swfdump); + + str_replace('[01a]', '', $swfdump->output, $nbObjects); + if ($nbObjects > $maxObjects) { + return true; + } + return false; + } + + protected function pdf2swf($page = null, $resolution = 150, $quality = 90, $storeAllChars = true, $method = 0) { /* -h , --help Print short help message and exit @@ -437,25 +467,30 @@ splinequality= Set the quality of spline convertion to value (0-100 disablelinks Disable links. */ - if ($method != 'barbare') { + if (!is_null($page) && file_exists($this->out . 'p' . $page . '.swf')) { + unlink($this->out . 'p' . $page . '.swf'); + } + + if ($method < self::BARBARE) { $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); if (!is_null($page)) { $pdf2swf->setArg('p', $page); } - if ($method == 'normal') { + if ($method == self::NORMAL) { // Default - $multiply=1; - } elseif ($method == 'flatten') { + $multiply = 1; + } elseif ($method == self::FLATTEN) { $pdf2swf->setArg('flatten'); - $multiply=1; - } elseif ($method == 'poly2bitmap') { + $multiply = 1; + } elseif ($method == self::POLY2BITMAP) { // Raster graphics, keep texts $pdf2swf->setArg('poly2bitmap'); $multiply = $resolution2multiply[$resolution]; $pdf2swf->setArg('multiply', $multiply); - } elseif ($method == 'bitmap') { + } elseif ($method == self::BITMAP) { // Raster all $pdf2swf->setArg('bitmap'); $multiply = $resolution2multiply[$resolution]; @@ -483,16 +518,16 @@ disablelinks Disable links. $pdf2swf->execute(); $this->addToLog($pdf2swf, true); - return $pdf2swf->outputfile; + return array('outputfile' => $pdf2swf->outputfile, 'multiply' => $multiply, 'object' => $pdf2swf); } else { - return $this->pdf2swfBarbare($page, $resolution, $quality); + return array('outputfile' => $this->pdf2swfBarbare($page, $resolution, $quality), 'multiply' => 1); } } protected function makeAS3($swffile) { $swfcombine = new cubeCommandLine('swfcombine'); - $swfcombine->setEnv('PATH', self::$path); + $swfcombine->setPath(CONVERTER_PATH); $swfcombine->setArg('merge'); $swfcombine->setArg('stack1'); $swfcombine->setArg('z'); @@ -507,7 +542,7 @@ disablelinks Disable links. protected function pdf2swfBarbare($page = null, $resolution = 150, $quality = 85) { // Fabrique les images - $this->makeShot($page, 'barbare', $resolution, $quality, 'PNM'); + $this->makeShot($page, 'barbare', $resolution, $quality, 4, 'PNM'); // A partir des images, on crée les swf if (is_null($page)) { $startpage = 1; @@ -518,6 +553,7 @@ disablelinks Disable links. for($i = $startpage;$i <= $endpage;$i++) { $jpeg2swf = new cubeCommandLine('jpeg2swf'); + $jpeg2swf->setPath(CONVERTER_PATH); $jpeg2swf->setArg('q', $quality); $jpeg2swf->setArg('o', $this->out . 'p' . $i . '.swf'); $jpeg2swf->setArg('f'); @@ -532,14 +568,18 @@ disablelinks Disable links. public function addToLog($cl, $output = true) { - $c = '--- Exécuté en ' . $cl->execTime . " s\n" . $cl->commande . "\n\n"; - if ($output) { - $c .= $cl->output . "\n\n"; + if ($cl instanceof cubeCommandLine) { + $c = '--- Exécuté en ' . $cl->execTime . " s\n" . $cl->commande . "\n\n"; + if ($output) { + $c .= $cl->output . "\n\n"; + } + } elseif (is_string($cl)) { + $c = $cl; } fwrite($this->log_pointer, $c); } - public function extractLinks($page, $logfile, $multiply = 1) + public function extractLinks($page, $outputfile, $multiply = 1) { /* DEBUG drawlink @@ -553,14 +593,14 @@ TRACE drawlink action=3 TRACE drawlink s=http://www.ladocumentationfrancaise.fr/ */ - $fp = fopen($logfile, 'rb'); + $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 fwsLink($multiply); + $link = new wsLink($multiply); $log .= 'SETTING POINTS ' . $matches[1] . "\n"; $points = explode(' ', trim($matches[1])); foreach($points as $point) { @@ -586,6 +626,7 @@ TRACE drawlink s=http://www.ladocumentationfrancaise.fr/ } } $log .= 'END OF EXTRACTING' . "\n"; + $this->addToLog($log); fclose($fp); return $log; @@ -593,7 +634,7 @@ TRACE drawlink s=http://www.ladocumentationfrancaise.fr/ public function __destruct() { - if (isset($this->log_pointer)) { + if (isset($this->log_pointer) && is_resource($this->log_pointer)) { fclose($this->log_pointer); } } diff --git a/inc/extranet/Metier/class.ws.link.php b/inc/extranet/Metier/class.ws.link.php new file mode 100644 index 000000000..db7221228 --- /dev/null +++ b/inc/extranet/Metier/class.ws.link.php @@ -0,0 +1,62 @@ +origine = array(); + $this->points = array(); + $this->action = null; + $this->link = null; + $this->multiply = $multiply; + } + + public function addPoint($point = array()) + { + $point[0] = (float)$point[0] / $this->multiply; + $point[1] = (float)$point[1] / $this->multiply; + if ($this->origine == null) { + $this->origine = $point; + } else { + $this->points[] = $point; + } + } + + public function setAction($action) + { + $this->action = $action; + } + + public function setLink($link) + { + $this->link = $link; + } + + public function toArray() + { + if (is_null($this->link)) { + return false; + } + + $res = array(); + $res['left'] = $this->origine[0]; + $res['top'] = $this->origine[1]; + + $res['width'] = $this->points[1][0] - $this->origine[0]; + $res['height'] = $this->points[1][1] - $this->origine[1]; + + if ($this->action == 0) { + $res['href'] = 'temp.html#' . $this->link; + } elseif ($this->action == 3) { + $res['href'] = $this->link; + } + + return $res; + } +} + +?> \ No newline at end of file