]> _ Git - cubeextranet.git/commitdiff
(no commit message)
authorvincent@cubedesigners.com <vincent@cubedesigners.com@f5622870-0f3c-0410-866d-9cb505b7a8ef>
Tue, 2 Mar 2010 12:46:11 +0000 (12:46 +0000)
committervincent@cubedesigners.com <vincent@cubedesigners.com@f5622870-0f3c-0410-866d-9cb505b7a8ef>
Tue, 2 Mar 2010 12:46:11 +0000 (12:46 +0000)
inc/ws/Metier/_common.php
inc/ws/Metier/class.ws.box.php [new file with mode: 0644]
inc/ws/Metier/class.ws.document.php

index f9f0fda47b8686b9bd5196f09ece1e90d818808d..d146463aac0177ebd10d554df4936888030ec378 100644 (file)
@@ -7,5 +7,6 @@ $__autoload['wsLangueTextes'] = dirname(__FILE__) . '/class.ws.langue.textes.php
 $__autoload['wsDocument'] = dirname(__FILE__) . '/class.ws.document.php';\r
 $__autoload['wsLink'] = dirname(__FILE__) . '/class.ws.link.php';\r
 $__autoload['wsDocumentLocalInfos'] = dirname(__FILE__) . '/class.ws.document.localinfos.php';\r
+$__autoload['wsBox'] = dirname(__FILE__) . '/class.ws.box.php';\r
 \r
 ?>
\ No newline at end of file
diff --git a/inc/ws/Metier/class.ws.box.php b/inc/ws/Metier/class.ws.box.php
new file mode 100644 (file)
index 0000000..4ba23a8
--- /dev/null
@@ -0,0 +1,22 @@
+<?php\r
+class wsBox extends cubeMetier {\r
+       protected $top;\r
+       protected $left;\r
+       protected $right;\r
+       protected $bottom;\r
+       protected $width;\r
+       protected $height;\r
+\r
+       public function __construct($top, $left, $right, $bottom)\r
+       {\r
+               $this->top = $top;\r
+               $this->left = $left;\r
+               $this->right = $right;\r
+               $this->bottom = $bottom;\r
+\r
+               $this->width = $this->right - $this->left;\r
+               $this->height = $this->bottom - $this->top;\r
+       }\r
+}\r
+\r
+?>
\ No newline at end of file
index 091dd932d928d48e6d401d75b922ea2f09612ed6..72fad252713dc96844bbac619fd806085d63bdc1 100644 (file)
@@ -20,6 +20,7 @@ class wsDocument extends cubeMetier {
        protected $bookmarks;\r
        protected $numberSections;\r
        protected $links;\r
+       protected $crop;\r
 \r
        protected $out;\r
        protected $in;\r
@@ -27,6 +28,8 @@ class wsDocument extends cubeMetier {
        protected $log;\r
        protected $log_pointer;\r
        protected $infos;\r
+       protected $cropped;\r
+       protected $uncropped;\r
 \r
        private $_basicInfos = null;\r
        private $_advancedInfos = null;\r
@@ -50,22 +53,15 @@ class wsDocument extends cubeMetier {
                if (!file_exists($this->out)) {\r
                        mkdir($this->out, 0755, true);\r
                }\r
+               $this->cropped = $this->out . 'crop.pdf';\r
+               $this->uncropped = $this->out . 'uncrop.pdf';\r
                $this->log_pointer = fopen($this->log, 'a');\r
        }\r
 \r
        public function copyOriginal($tmp_file)\r
        {\r
                move_uploaded_file($tmp_file, $this->in);\r
-               //$this->uncompress();\r
-       }\r
-\r
-       public function uncompress()\r
-       {\r
-               $pdftk = new cubeCommandLine('pdftk');\r
-               $pdftk->setPath(CONVERTER_PATH);\r
-               $pdftk->setManualArg($this->in . ' output ' . $this->uncompressed . ' uncompress ');\r
-               $pdftk->execute();\r
-               $this->addToLog($pdftk);\r
+               $this->uncropDocument();\r
        }\r
 \r
        public function getInfos()\r
@@ -76,6 +72,81 @@ class wsDocument extends cubeMetier {
                $this->parseInfos($pdfinfo . $pdftk);\r
 \r
                file_put_contents($this->infos, $pdfinfo . $pdftk);\r
+               $this->crop = $this->findCutDisposition();\r
+       }\r
+\r
+       public function findCutDisposition()\r
+       {\r
+               $spreads = $this->detectSpreads();\r
+               if ($spreads) {\r
+                       return $spreads;\r
+               }\r
+               return $this->detectPageDifferences();\r
+       }\r
+\r
+       protected function detectPageDifferences()\r
+       {\r
+               // Vérifie si la cropbox et la trimbox sont identiques pour toutes les pages\r
+               $difference = false;\r
+               foreach($this->generalInfos['page'] as $page => $infos) {\r
+                       if ($infos['crop'] != $infos['trim']) {\r
+                               $difference = true;\r
+                       }\r
+               }\r
+               if (!$difference) {\r
+                       return false;\r
+               }\r
+               // Vérifie si la trimbox définie toutes les pages de la même taille\r
+               $heights = array();\r
+               $widths = array();\r
+               foreach($this->generalInfos['page'] as $page => $infos) {\r
+                       $heights[] = round($infos['trim']->height);\r
+                       $widths[] = round($infos['trim']->width);\r
+               }\r
+               $heights = array_unique($heights);\r
+               $widths = array_unique($widths);\r
+               if (count($heights) == 1 && count($widths) == 1) {\r
+                       return 'TTRIM';\r
+               } else {\r
+                       return 'TMANUEL';\r
+               }\r
+       }\r
+\r
+       protected function detectSpreads()\r
+       {\r
+               $spread = false;\r
+               // Détection des spreads\r
+               foreach($this->generalInfos['page'] as $page => $infos) {\r
+                       if ($page == 1) {\r
+                               $first = $infos['size'];\r
+                       } elseif ($page == $this->generalInfos['pages']) {\r
+                               $last = $infos['size'];\r
+                       } elseif ($page == 2) {\r
+                               $second = $infos['size'];\r
+                       }\r
+               }\r
+\r
+               if ($first == $last && $last == $second) {\r
+                       $ratio = $first[0] / $first[1];\r
+                       if ($ratio <= 1) {\r
+                               return false;\r
+                       } elseif ($ratio >= 6) {\r
+                               return 'CSL8';\r
+                       } elseif ($ratio >= 3) {\r
+                               return 'CSL4';\r
+                       } elseif ($ratio >= 2) {\r
+                               return 'CSL3';\r
+                       } else {\r
+                               return 'CS-14-23';\r
+                       }\r
+               }\r
+\r
+               if ($first == $last && round($first[0] * 2) == round($second[0])) {\r
+                       return 'C1-23-4';\r
+               }\r
+               if (round($first[0] * 2) == round($second[0]) && $last == $second) {\r
+                       return 'C1-23';\r
+               }\r
        }\r
 \r
        public function getBasicInfos()\r
@@ -132,7 +203,7 @@ class wsDocument extends cubeMetier {
                        if ($k == 'Pages' || $k == 'NumberOfPages') {\r
                                $this->pages = $this->generalInfos['pages'] = $v;\r
                        } elseif (preg_match('|Page ([0-9]+) (.*)Box: ([0-9.]*) ([0-9.]*) ([0-9.]*) ([0-9.]*)|iu', $line, $m)) {\r
-                               $this->generalInfos['page'][$m[1]][strtolower($m[2])] = array($m[3], $m[4], $m[5], $m[6]);\r
+                               $this->generalInfos['page'][$m[1]][strtolower($m[2])] = new wsBox($m[3], $m[4], $m[5], $m[6]);\r
                        } elseif (preg_match('|Page ([0-9]+) size: ([0-9.]*)([\sx]+)([0-9.]*)(.*)|iu', $line, $m)) {\r
                                $this->generalInfos['page'][$m[1]]['size'] = array($m[2], $m[4]);\r
                                $this->generalInfos['size'][0] = max($this->generalInfos['size'][0], $m[2]);\r
@@ -155,6 +226,7 @@ class wsDocument extends cubeMetier {
                                $this->numberSections[] = $section;\r
                        }\r
                }\r
+\r
                return $res;\r
        }\r
 \r
@@ -166,15 +238,48 @@ class wsDocument extends cubeMetier {
 \r
        public function globalOperations()\r
        {\r
+               $this->getInfos();\r
+               $this->Crop();\r
                $this->getLinks();\r
                $this->getTexts();\r
        }\r
 \r
+       public function Crop()\r
+       {\r
+               if ($this->crop == 'TTRIM') {\r
+                       $this->trimDocument();\r
+               } else {\r
+                       copy($this->in, $this->cropped);\r
+               }\r
+       }\r
+\r
+       public function trimDocument()\r
+       {\r
+               $fwstk = new cubeCommandLine('fwstk');\r
+               $fwstk->setPath(CONVERTER_PATH);\r
+               $fwstk->setArg('--input ' . $this->in);\r
+               $fwstk->setArg('--trim');\r
+               $fwstk->setArg('--output ' . $this->cropped);\r
+               $fwstk->execute();\r
+               $this->addToLog($fwstk);\r
+       }\r
+\r
+       public function uncropDocument()\r
+       {\r
+               $fwstk = new cubeCommandLine('fwstk');\r
+               $fwstk->setPath(CONVERTER_PATH);\r
+               $fwstk->setArg('--input ' . $this->in);\r
+               $fwstk->setArg('--reset');\r
+               $fwstk->setArg('--output ' . $this->uncropped);\r
+               $fwstk->execute();\r
+               $this->addToLog($fwstk);\r
+       }\r
+\r
        public function processOnePage($page)\r
        {\r
                $this->makeMiniShot($page);\r
                $this->makeRealShot($page);\r
-               $this->makeSWFFiles($page);\r
+               $this->makeSWFFiles($page, 150, 90, true, 1800, 1);\r
                $this->makeAS3($page);\r
        }\r
 \r
@@ -200,15 +305,19 @@ class wsDocument extends cubeMetier {
                $pdftotext->setArg('q');\r
                $pdftotext->setArg('-eol', 'unix');\r
                $pdftotext->setArg('-enc', 'UTF-8');\r
-               $pdftotext->setArg(null, $this->in);\r
+               $pdftotext->setArg(null, $this->cropped);\r
                $pdftotext->setArg(null, $temp);\r
                $pdftotext->execute();\r
                $this->addToLog($pdftotext);\r
 \r
-               $pages = preg_split("|\x{u000c}|", file_get_contents($temp));\r
+               $pages = explode("\f", 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
+                       $txt = mb_strtolower($page);\r
+                       $txt = cubeText::removeAccents($txt);\r
+                       $txt = trim($txt);\r
+\r
+                       file_put_contents($this->out . 'p' . $i . '.txt', $txt);\r
                }\r
 \r
                unlink($temp);\r
@@ -216,12 +325,12 @@ class wsDocument extends cubeMetier {
 \r
        public function makeMiniShot($page)\r
        {\r
-               $this->makeShotFixedWidth($page, 'p', 100, 70, 4, 'GS');\r
+               $this->makeShotFixedWidth($page, 'p', 100, 90, 4, 'GS');\r
        }\r
 \r
        public function makeRealShot($page)\r
        {\r
-               $this->makeShot($page, 'te', 72);\r
+               $this->makeShot($page, 'te', 150, 60, 4, 'GS', $this->uncropped);\r
        }\r
 \r
        public function makeShotFixedWidth($page , $prefix = '', $w = 100, $quality = 90, $antialiasing = 4, $method = 'GS')\r
@@ -242,13 +351,16 @@ class wsDocument extends cubeMetier {
                $this->makeShot($page, $prefix, round(72 / $ratio, 2), $quality, $antialiasing, $method);\r
        }\r
 \r
-       public function makeShot($page , $prefix = '', $resolution = 72, $quality = 90, $antialiasing = 4, $method = 'GS')\r
+       public function makeShot($page , $prefix = '', $resolution = 72, $quality = 90, $antialiasing = 4, $method = 'GS', $in = null)\r
        {\r
+               if (is_null($in)) {\r
+                       $in = $this->cropped;\r
+               }\r
                // Delete all old files\r
                if ($method == 'GS') {\r
-                       $this->makeShotGS($page, $prefix, $resolution, $quality, $antialiasing);\r
+                       $this->makeShotGS($page, $prefix, $resolution, $quality, $antialiasing, $in);\r
                } elseif ($method == 'PNM') {\r
-                       $this->makeShotPNM($page, $prefix, $resolution, $quality, $antialiasing);\r
+                       $this->makeShotPNM($page, $prefix, $resolution, $quality, $antialiasing, $in);\r
                }\r
                // Test the result by checking all files\r
                if (!file_exists($this->out . $prefix . $page . '.jpg')) {\r
@@ -257,15 +369,18 @@ class wsDocument extends cubeMetier {
                // If error, we try to make thumbs with other method\r
                if ($error) {\r
                        if ($method == 'GS') {\r
-                               $this->makeShotPNM($page, $prefix, $resolution, $quality, $antialiasing);\r
+                               $this->makeShotPNM($page, $prefix, $resolution, $quality, $antialiasing, $in);\r
                        } elseif ($method == 'PNM') {\r
-                               $this->makeShotGS($page, $prefix, $resolution, $quality, $antialiasing);\r
+                               $this->makeShotGS($page, $prefix, $resolution, $quality, $antialiasing, $in);\r
                        }\r
                }\r
        }\r
 \r
-       protected function makeShotGS($page, $prefix = '', $resolution = 72, $quality = 90, $antialiasing = 4)\r
+       protected function makeShotGS($page, $prefix = '', $resolution = 72, $quality = 90, $antialiasing = 4, $in = null)\r
        {\r
+               if (is_null($in)) {\r
+                       $in = $this->cropped;\r
+               }\r
                // Fabrication des thumbanails avec ghostscript\r
                $gs = new cubeCommandLine('gs', null, true);\r
                $gs->setPath(CONVERTER_PATH);\r
@@ -274,23 +389,34 @@ class wsDocument extends cubeMetier {
                $gs->setArg('-dNOPAUSE');\r
                $gs->setArg('-dNOPROMPT');\r
                $gs->setArg('-sDEVICE=jpeg');\r
+               // Dispotion & colors\r
                $gs->setArg('-dUseCIEColor');\r
+               $gs->setArg('-dAutoRotatePages=/None');\r
+               // Resolution & Quality\r
                $gs->setArg('-r' . $resolution);\r
                $gs->setArg('-dJPEGQ=' . $quality);\r
+               // Antialias\r
+               $gs->setArg('-dDOINTERPOLATE');\r
                $gs->setArg('-dTextAlphaBits=' . $antialiasing);\r
                $gs->setArg('-dGraphicsAlphaBits=' . $antialiasing);\r
-               // $gs->setArg('-dUseCropBox');\r
+               // Performances\r
+               $gs->setArg('-dNumRenderingThreads=4');\r
+               // Page range\r
                $gs->setArg('-dFirstPage=' . $page);\r
                $gs->setArg('-dLastPage=' . $page);\r
-               $gs->setArg('-sOutputFile=' . $this->out . '/' . $prefix . '%d.jpg');\r
-               $gs->setArg('-dAutoRotatePages=/None');\r
-               $gs->setArg(null, $this->in);\r
+               // Files\r
+               $gs->setArg('-sOutputFile=' . $this->out . '/' . $prefix . $page . '.jpg');\r
+\r
+               $gs->setArg(null, $in);\r
                $gs->execute();\r
                $this->addToLog($gs);\r
        }\r
 \r
-       protected function makeShotPNM($page, $prefix = '', $resolution = 72, $quality = 90, $antialiasing = 4)\r
+       protected function makeShotPNM($page, $prefix = '', $resolution = 72, $quality = 90, $antialiasing = 4, $in = null)\r
        {\r
+               if (is_null($in)) {\r
+                       $in = $this->crop;\r
+               }\r
                $antialiasing = $antialiasing?'yes':'no';\r
                $resolution = round($resolution);\r
                // Exporte les fichiers\r
@@ -307,7 +433,7 @@ class wsDocument extends cubeMetier {
                        $pdftoppm->setArg('-t1lib yes');\r
                }\r
                $pdftoppm->setArg('r', $resolution);\r
-               $pdftoppm->setArg(null, $this->in);\r
+               $pdftoppm->setArg(null, $in);\r
                $pdftoppm->setArg(null, $this->out . 'ppm');\r
                $pdftoppm->execute();\r
                $this->addToLog($pdftoppm);\r
@@ -337,6 +463,11 @@ class wsDocument extends cubeMetier {
                if ($maxObjects <= 1) {\r
                        $method = self::POLY2BITMAP;\r
                }\r
+               // Pour les fichiers croppés, on utilise la méthode flatten qui ne prends\r
+               // pas en compte les objets hors de la box\r
+               if ($this->crop) {\r
+                       $method = max($method, self::FLATTEN);\r
+               }\r
 \r
                $out = $this->pdf2swf($page, $resolution, $quality, $storeAllChars, $method);\r
                if ($method < self::BARBARE_PNM) {\r
@@ -502,7 +633,7 @@ disablelinks                Disable links.
                        }\r
 \r
                        $pdf2swf->setArg('stop');\r
-                       $pdf2swf->setManualArg('-v');\r
+                       // $pdf2swf->setManualArg('-v');\r
                        $pdf2swf->setArg('T', 8);\r
                        if ($storeAllChars) {\r
                                $pdf2swf->setArg('fonts');\r
@@ -517,7 +648,7 @@ disablelinks                Disable links.
                        $pdf2swf->setArg('set disablelinks');\r
                        $pdf2swf->setArg('set dots');\r
 \r
-                       $pdf2swf->setArg(null, $this->in);\r
+                       $pdf2swf->setArg(null, $this->cropped);\r
                        $pdf2swf->setArg('output', $this->out . 'p%.swf');\r
                        $pdf2swf->execute();\r
 \r
@@ -536,7 +667,7 @@ disablelinks                Disable links.
                $swfcombine->setArg('merge');\r
                $swfcombine->setArg('stack1');\r
                $swfcombine->setArg('z');\r
-               $swfcombine->setManualArg('-vvvv');\r
+               $swfcombine->setManualArg('-v');\r
                $swfcombine->setArg('o', $swffile);\r
                $swfcombine->setArg(null, ROOT . '/swf/as3Container.swf');\r
                $swfcombine->setManualArg('content=' . $swffile);\r
@@ -546,7 +677,7 @@ disablelinks                Disable links.
 \r
        protected function getLinks()\r
        {\r
-               $fwstk = new cubeCommandLine('fwstk', 'C:\Users\Vincent\Desktop\out.txt', false);\r
+               $fwstk = new cubeCommandLine('fwstk');\r
                $fwstk->setPath(CONVERTER_PATH);\r
                $fwstk->setArg('--input ' . $this->in);\r
                $fwstk->setArg('--extractLinks ' . $this->out . 'p%d.csv');\r