]> _ Git - cubeextranet.git/commitdiff
(no commit message)
authorvincent@cubedesigners.com <vincent@cubedesigners.com@f5622870-0f3c-0410-866d-9cb505b7a8ef>
Tue, 2 Mar 2010 08:44:19 +0000 (08:44 +0000)
committervincent@cubedesigners.com <vincent@cubedesigners.com@f5622870-0f3c-0410-866d-9cb505b7a8ef>
Tue, 2 Mar 2010 08:44:19 +0000 (08:44 +0000)
inc/ws/Controlleur/class.ws.conversion.session.php
inc/ws/DAO/class.ws.dao.document.php
inc/ws/Metier/class.ws.document.php

index 61ca777618651d906efdb6cfa0207cd105285ebc..d15820cb8f9818c5f6b6d06ac4d3c3c4188916fb 100644 (file)
@@ -58,11 +58,13 @@ class wsConversionSession {
 \r
                foreach($this->documents as $doc) {\r
                        $this->currentDoc = $doc;\r
+                       $this->serialize();\r
+                       $this->currentDoc->globalOperations();\r
                        for($i = 1;$i <= $doc->generalInfos['pages'];$i++) {\r
                                $this->currentDocPage = $i;\r
                                $this->totalDocPage = $doc->generalInfos['pages'];\r
                                $this->setProgress(($this->processedPages / $this->totalPages) * 100);\r
-                               $doc->processOnePage($i);\r
+                               $this->currentDoc->processOnePage($i);\r
                                $this->processedPages++;\r
                        }\r
                        $doc = $dao->updateFromObject($doc);\r
@@ -111,7 +113,7 @@ class wsConversionSession {
        public function destroy()\r
        {\r
                if (file_exists(self::getCachePath($this->guid))) {\r
-                       //unlink(self::getCachePath($this->guid));\r
+                       // unlink(self::getCachePath($this->guid));\r
                }\r
        }\r
 \r
index 52ef5f3554f8ab90daa02cb072d4e68eb5c4e2b4..3000a081e36497d97ba77c7fdad62719acd9347d 100644 (file)
@@ -1,7 +1,7 @@
 <?php\r
 class wsDAODocument extends extranetDAO {\r
        public static $normal = array('document_id', 'file', 'proprietaire', 'pages', 'date');\r
-       public static $complex = array('localInfos', 'bookmarks', 'generalInfos', 'numberSections', 'links', 'trim');\r
+       public static $complex = array('localInfos', 'bookmarks', 'generalInfos', 'numberSections', 'trim');\r
 \r
        public function singleton($r)\r
        {\r
index 16eea751855499c4bf0df63487fe0a1cd8a624da..091dd932d928d48e6d401d75b922ea2f09612ed6 100644 (file)
@@ -27,13 +27,9 @@ class wsDocument extends cubeMetier {
        protected $log;\r
        protected $log_pointer;\r
        protected $infos;\r
-       protected $textes;\r
-       protected $phperrors;\r
 \r
        private $_basicInfos = null;\r
        private $_advancedInfos = null;\r
-       private $_links = array();\r
-       private $_memoErrorLog;\r
 \r
        const NORMAL = 0;\r
        const FLATTEN = 1;\r
@@ -42,6 +38,8 @@ class wsDocument extends cubeMetier {
        const BARBARE_PNM = 4;\r
        const BARBARE_GS = 5;\r
 \r
+       protected static $resolution2multiply = array(72 => 2, 100 => 2, 150 => 3, 200 => 3, 300 => 3, 450 => 4, 600 => 5);\r
+\r
        public function init()\r
        {\r
                $this->out = ROOT . '/docs/' . $this->document_id . '/';\r
@@ -49,20 +47,16 @@ class wsDocument extends cubeMetier {
                $this->in = $this->out . 'original.pdf';\r
                $this->uncompressed = $this->out . 'uncompressed.pdf';\r
                $this->infos = $this->out . 'infos.txt';\r
-               $this->textes = $this->out . 'textes.txt';\r
-               $this->phperrors = $this->out . 'php.err';\r
                if (!file_exists($this->out)) {\r
                        mkdir($this->out, 0755, true);\r
                }\r
                $this->log_pointer = fopen($this->log, 'a');\r
-               // $this->_memoErrorLog = ini_get('error_log');\r
-               // ini_set('error_log', $this->phperrors);\r
        }\r
 \r
        public function copyOriginal($tmp_file)\r
        {\r
                move_uploaded_file($tmp_file, $this->in);\r
-               $this->uncompress();\r
+               //$this->uncompress();\r
        }\r
 \r
        public function uncompress()\r
@@ -170,9 +164,14 @@ class wsDocument extends cubeMetier {
                return $this->generalInfos['pages'];\r
        }\r
 \r
+       public function globalOperations()\r
+       {\r
+               $this->getLinks();\r
+               $this->getTexts();\r
+       }\r
+\r
        public function processOnePage($page)\r
        {\r
-               $this->getTexts($page);\r
                $this->makeMiniShot($page);\r
                $this->makeRealShot($page);\r
                $this->makeSWFFiles($page);\r
@@ -193,19 +192,26 @@ class wsDocument extends cubeMetier {
                }\r
        }\r
 \r
-       public function getTexts($page)\r
+       public function getTexts()\r
        {\r
+               $temp = cubeFiles::tempnam();\r
                $pdftotext = new cubeCommandLine('pdftotext', null, true);\r
                $pdftotext->setPath(CONVERTER_PATH);\r
                $pdftotext->setArg('q');\r
-               $pdftotext->setArg('f', $page);\r
-               $pdftotext->setArg('l', $page);\r
                $pdftotext->setArg('-eol', 'unix');\r
                $pdftotext->setArg('-enc', 'UTF-8');\r
                $pdftotext->setArg(null, $this->in);\r
-               $pdftotext->setArg(null, $this->out . 'p' . $page . '.txt');\r
+               $pdftotext->setArg(null, $temp);\r
                $pdftotext->execute();\r
                $this->addToLog($pdftotext);\r
+\r
+               $pages = preg_split("|\x{u000c}|", file_get_contents($temp));\r
+               foreach($pages as $i => $page) {\r
+                       $i++;\r
+                       file_put_contents($this->out . 'p' . $i . '.txt', cubeText::removeAccents($page));\r
+               }\r
+\r
+               unlink($temp);\r
        }\r
 \r
        public function makeMiniShot($page)\r
@@ -326,21 +332,21 @@ class wsDocument extends cubeMetier {
                }\r
        }\r
 \r
-       public function makeSWFFiles($page , $resolution = 150, $quality = 90, $storeAllChars = true, $maxObjects = 1800, $method = 0, &$muliply = 1)\r
+       public function makeSWFFiles($page , $resolution = 150, $quality = 90, $storeAllChars = true, $maxObjects = 1800, $method = 0)\r
        {\r
                if ($maxObjects <= 1) {\r
                        $method = self::POLY2BITMAP;\r
                }\r
 \r
-               $out = $this->pdf2swf($page, $resolution, $quality, $storeAllChars, $method, $multiply);\r
+               $out = $this->pdf2swf($page, $resolution, $quality, $storeAllChars, $method);\r
                if ($method < self::BARBARE_PNM) {\r
                        // Analyse de la sortie pour détecter des typos manquantes\r
                        $overflow = false;\r
                        $overflowObjects = false;\r
                        $written = false;\r
                        $missing_fonts = array();\r
-                       if (file_exists($out['outputfile'])) {\r
-                               $fp = fopen($out['outputfile'], 'rb');\r
+                       if (file_exists($out)) {\r
+                               $fp = fopen($out, 'rb');\r
                                while ($line = fgets($fp)) {\r
                                        if (preg_match('|Try putting a TTF version of that font \(named \"([A-Z-_0-9.]*)\"\)|Uui', trim($line), $matches)) {\r
                                                $missing_fonts[] = $matches[1];\r
@@ -356,20 +362,15 @@ class wsDocument extends cubeMetier {
                        if (!is_null($page) && file_exists($this->out . 'p' . $page . '.swf')) {\r
                                $written = true;\r
                        }\r
-                       if ($written && $method < self::BITMAP && !isset($this->_links[$page])) {\r
-                               $this->_links[$page] = $this->extractLinks($page, $out['outputfile'], $out['multiply']);\r
-                       }\r
                        // On teste si le fichier est écrit et qu'il a été généré par le premier niveau\r
                        if ($method < self::POLY2BITMAP && $written) {\r
                                $overflowObjects = $this->checkObjectsNumber($this->out . 'p' . $page . '.swf', $maxObjects);\r
                        }\r
 \r
                        if (!$written || $overflow || $overflowObjects) {\r
-                               return $this->makeSWFFiles($page, $resolution, $quality, $storeAllChars, $maxObjects, $method + 1, $multiply);\r
+                               $this->makeSWFFiles($page, $resolution, $quality, $storeAllChars, $maxObjects, $method + 1);\r
                        }\r
                }\r
-\r
-               return $out;\r
        }\r
 \r
        protected function checkObjectsNumber($file, $maxObjects)\r
@@ -388,6 +389,16 @@ class wsDocument extends cubeMetier {
                return false;\r
        }\r
 \r
+       /**\r
+        * wsDocument::pdf2swf()\r
+        *\r
+        * @param mixed $page\r
+        * @param integer $resolution\r
+        * @param integer $quality\r
+        * @param mixed $storeAllChars\r
+        * @param integer $method\r
+        * @return\r
+        */\r
        protected function pdf2swf($page , $resolution = 150, $quality = 90, $storeAllChars = true, $method = 0)\r
        {\r
                /*\r
@@ -467,8 +478,6 @@ disablelinks                Disable links.
                }\r
 \r
                if ($method < self::BARBARE_PNM) {\r
-                       $resolution2multiply = array(72 => 2, 100 => 2, 150 => 3, 200 => 3, 300 => 3, 450 => 4, 600 => 5);\r
-\r
                        $pdf2swf = new cubeCommandLine('pdf2swf', null, true);\r
                        $pdf2swf->setPath(CONVERTER_PATH);\r
 \r
@@ -483,17 +492,17 @@ disablelinks                Disable links.
                        } elseif ($method == self::POLY2BITMAP) {\r
                                // Raster graphics, keep texts\r
                                $pdf2swf->setArg('poly2bitmap');\r
-                               $multiply = $resolution2multiply[$resolution];\r
+                               $multiply = self::$resolution2multiply[$resolution];\r
                                $pdf2swf->setArg('multiply', $multiply);\r
                        } elseif ($method == self::BITMAP) {\r
                                // Raster all\r
                                $pdf2swf->setArg('bitmap');\r
-                               $multiply = $resolution2multiply[$resolution];\r
+                               $multiply = self::$resolution2multiply[$resolution];\r
                                $pdf2swf->setArg('multiply', $multiply);\r
                        }\r
 \r
                        $pdf2swf->setArg('stop');\r
-                       $pdf2swf->setManualArg('-vvvv');\r
+                       $pdf2swf->setManualArg('-v');\r
                        $pdf2swf->setArg('T', 8);\r
                        if ($storeAllChars) {\r
                                $pdf2swf->setArg('fonts');\r
@@ -513,9 +522,8 @@ disablelinks                Disable links.
                        $pdf2swf->execute();\r
 \r
                        $this->addToLog($pdf2swf, true);\r
-                       return array('outputfile' => $pdf2swf->outputfile, 'multiply' => $multiply, 'object' => $pdf2swf);\r
                } else {\r
-                       return array('outputfile' => $this->pdf2swfBarbare($page, $resolution, $quality, $method), 'multiply' => 1);\r
+                       $this->pdf2swfBarbare($page, $resolution, $quality, $method);\r
                }\r
        }\r
 \r
@@ -536,6 +544,16 @@ disablelinks                Disable links.
                $this->addToLog($swfcombine);\r
        }\r
 \r
+       protected function getLinks()\r
+       {\r
+               $fwstk = new cubeCommandLine('fwstk', 'C:\Users\Vincent\Desktop\out.txt', false);\r
+               $fwstk->setPath(CONVERTER_PATH);\r
+               $fwstk->setArg('--input ' . $this->in);\r
+               $fwstk->setArg('--extractLinks ' . $this->out . 'p%d.csv');\r
+               $fwstk->execute();\r
+               $this->addToLog($fwstk);\r
+       }\r
+\r
        protected function pdf2swfBarbare($page, $resolution = 150, $quality = 85, $method = 4)\r
        {\r
                // Fabrique les images\r
@@ -573,65 +591,11 @@ disablelinks                Disable links.
                fwrite($this->log_pointer, $c);\r
        }\r
 \r
-       public function extractLinks($page, $outputfile, $multiply = 1)\r
-       {\r
-               /*\r
-DEBUG   drawlink\r
-TRACE   drawlink 122.00/579.00 236.00/579.00 236.00/527.00 122.00/527.00\r
-DEBUG   |     moveTo 122.00 579.00\r
-DEBUG   |     lineTo 236.00 579.00\r
-DEBUG   |     lineTo 236.00 527.00\r
-DEBUG   |     lineTo 122.00 527.00\r
-DEBUG   |     lineTo 122.00 579.00\r
-TRACE   drawlink action=3\r
-TRACE   drawlink s=http://www.ladocumentationfrancaise.fr/\r
-*/\r
-\r
-               $fp = fopen($outputfile, 'rb');\r
-               $log = 'BEGIN extracting link' . "\n";\r
-               $link = null;\r
-               while ($line = fgets($fp)) {\r
-                       $line = trim($line);\r
-                       if (preg_match('|TRACE   drawlink(( [-0-9\./]+)+)|', $line, $matches)) {\r
-                               $log .= 'FOUND a link' . "\n";\r
-                               $link = new wsLink($multiply);\r
-                               $log .= 'SETTING POINTS ' . $matches[1] . "\n";\r
-                               $points = explode(' ', trim($matches[1]));\r
-                               foreach($points as $point) {\r
-                                       $p = explode('/', $point);\r
-                                       $log .= 'SET POINT ' . $p[0] . ' ' . $p[1] . "\n";\r
-                                       $link->addPoint($p);\r
-                               }\r
-                       } elseif (preg_match('|TRACE   drawlink action=(.*)|', $line, $matches)) {\r
-                               $log .= 'SETTING ACTION ' . $matches[1] . "\n";\r
-                               if (is_null($link)) {\r
-                                       continue;\r
-                               }\r
-                               $link->setAction($matches[1]);\r
-                       } elseif (preg_match('|TRACE   drawlink s=(.*)|', $line, $matches)) {\r
-                               $log .= 'SETTING LINK ' . $matches[1] . "\n";\r
-                               if (is_null($link)) {\r
-                                       continue;\r
-                               }\r
-                               $link->setLink($matches[1]);\r
-                               $this->links[$page][] = $link->toArray();\r
-                               $log .= 'SAVE LINK' . print_r($link->toArray(), true) . "\n";\r
-                               $link = null;\r
-                       }\r
-               }\r
-               $log .= 'END OF EXTRACTING' . "\n";\r
-               $this->addToLog($log);\r
-               fclose($fp);\r
-\r
-               return $log;\r
-       }\r
-\r
        public function __destruct()\r
        {\r
                if (isset($this->log_pointer) && is_resource($this->log_pointer)) {\r
                        fclose($this->log_pointer);\r
                }\r
-               // ini_set('error_log', $this->_memoErrorLog);\r
        }\r
 }\r
 \r