From ffdada91c5f1a566153a7031c87c3703aecbaa0b Mon Sep 17 00:00:00 2001 From: "vincent@cubedesigners.com" Date: Wed, 14 Mar 2012 13:49:26 +0000 Subject: [PATCH] --- inc/ws/Metier/class.ws.document.php | 51 +++++++++++++++++++++++++---- 1 file changed, 44 insertions(+), 7 deletions(-) diff --git a/inc/ws/Metier/class.ws.document.php b/inc/ws/Metier/class.ws.document.php index fd1713f8a..4cb48bdeb 100644 --- a/inc/ws/Metier/class.ws.document.php +++ b/inc/ws/Metier/class.ws.document.php @@ -40,6 +40,7 @@ class wsDocument extends cubeMetier { protected $infos; protected $cropped; protected $uncropped; + protected $rgb; const NORMAL = 0; const FLATTEN = 1; @@ -47,9 +48,7 @@ class wsDocument extends cubeMetier { const BITMAP = 3; const BARBARE_PNM = 4; const BARBARE_GS = 5; - const MAX = 5; - const PNM_FILL = 2; protected static $resolution2multiply = array(72 => 2, 100 => 2, 150 => 3, 200 => 3, 300 => 3, 450 => 4, 600 => 5); @@ -74,6 +73,7 @@ class wsDocument extends cubeMetier { mkdir($this->html, 0755); } $this->cropped = $this->out . 'crop.pdf'; + $this->rgb = $this->out . 'rgb.pdf'; $this->uncropped = $this->out . 'uncrop.pdf'; $this->pages_log_pointers = array(); @@ -201,7 +201,7 @@ class wsDocument extends cubeMetier { $this->addToLog('Detect Spreads : Manual cut ' . $this->manualcut . ' ; Auto cut : ' . $this->autocut); } - public static function compareSizes($x, $y, $tolerance=0.9) { + public static function compareSizes($x, $y, $tolerance = 0.9) { return cubeMath::compare($x[0], $y[0], $tolerance) && cubeMath::compare($x[1], $y[1], $tolerance); } @@ -264,10 +264,43 @@ class wsDocument extends cubeMetier { if ($this->CropAndCut()) { $this->getInfos($this->cropped, true); } + $this->performColorTransformations(); $this->extractFonts(); $this->getLinksAndTexts(); } + public function performColorTransformations() { + $out = $this->out . '/rgb.pdf'; + + $gs = new cubeCommandLine('gs', null, true); + $gs->setPath(CONVERTER_PATH); + $gs->setEnv('GS_FONTPATH', FONT_PATH); + $gs->setArg('-dBATCH'); + $gs->setArg('-dNOPAUSE'); + $gs->setArg('-dNOPROMPT'); + // Device + $gs->setArg('-sDEVICE=pdfwrite'); + // + $gs->setArg('-dDownsampleColorImages=false'); + $gs->setArg('-dDownsampleGrayImages=false'); + $gs->setArg('-dDownsampleMonoImages=false'); + // Dispotion & colors + $gs->setArg('-dConvertCMYKImagesToRGB=true'); + $gs->setArg('-dAutoRotatePages=/None'); + $gs->setArg('-dUseCropBox'); + $gs->setArg('-dShowAnnots=false'); + // Performances + $gs->setArg('-dNumRenderingThreads=4'); + // Page range + // Files + $gs->setArg('-sOutputFile=' . $out); + + $gs->setArg(null, $this->cropped); + $gs->execute(); + + $this->addToLog($gs); + } + public function CropAndCut() { if (!$this->isCropped()) { copy($this->in, $this->cropped); @@ -509,7 +542,7 @@ class wsDocument extends cubeMetier { return $this->autocrop || $this->manualcrop || $this->autocut || $this->manualcut; } - public function makeSWFFiles($page, $resolution = null, $quality = null, $storeAllChars = null, $maxObjects = null, $method = null, $version=null) { + public function makeSWFFiles($page, $resolution = null, $quality = null, $storeAllChars = null, $maxObjects = null, $method = null, $version = null) { $conversionSettings = $this->conversionInfos->pages[$page]; if (is_null($storeAllChars)) { $storeAllChars = true; @@ -626,7 +659,7 @@ class wsDocument extends cubeMetier { * @param integer $method * @return */ - protected function pdf2swf($page, $resolution = 150, $quality = 90, $storeAllChars = true, $method = 0, $prefix = 'p', $version='stable') { + protected function pdf2swf($page, $resolution = 150, $quality = 90, $storeAllChars = true, $method = 0, $prefix = 'p', $version = 'stable') { /* -h , --help Print short help message and exit -V , --version Print version info and exit @@ -750,7 +783,11 @@ class wsDocument extends cubeMetier { $pdf2swf->setArg('set jpegquality', $quality); $pdf2swf->setArg('set disablelinks'); $pdf2swf->setArg('set dots'); - $pdf2swf->setArg(null, $this->cropped); + if(file_exists($this->rgb)){ + $pdf2swf->setArg(null, $this->rgb); + }else{ + $pdf2swf->setArg(null, $this->cropped); + } $pdf2swf->setArg('output', $this->out . $prefix . '%.swf'); $pdf2swf->execute(); @@ -833,7 +870,7 @@ class wsDocument extends cubeMetier { } public function resetLog() { - file_put_contents($this->log . '/commons.log', ''); + unlink($this->log . '/commons.log.gz'); } public function addToLog($cl, $output = true, $page = null) { -- 2.39.5