From 18e588f8b5e8b194400da25880561761bdfdfb11 Mon Sep 17 00:00:00 2001 From: "vincent@cubedesigners.com" Date: Sun, 17 Apr 2011 18:30:43 +0000 Subject: [PATCH] --- inc/ws/Metier/class.ws.document.php | 13 ++++-- inc/ws/Util/class.ws.swf2html.php | 1 + .../Util/packager/class.ws.packager.html5.php | 42 ++++++++++++++++--- 3 files changed, 46 insertions(+), 10 deletions(-) diff --git a/inc/ws/Metier/class.ws.document.php b/inc/ws/Metier/class.ws.document.php index 28d5c3eb7..5307b4b50 100644 --- a/inc/ws/Metier/class.ws.document.php +++ b/inc/ws/Metier/class.ws.document.php @@ -518,12 +518,13 @@ class wsDocument extends cubeMetier { $this->addToLog($gs, true, $page); } - protected function makeShotPNM($page, $prefix = '', $resolution = 72, $quality = 90, $antialiasing = 4, $in = null) + protected function makeShotPNM($page, $prefix = '', $resolution = 72, $quality = 90, $antialiasing = 4, $in = null, $texts = true) { if (is_null($in)) { $in = $this->cropped; } $antialiasing = $antialiasing?'yes':'no'; + $freetype = $texts?'yes':'no'; $resolution = round($resolution); // Exporte les fichiers $pdftoppm = new cubeCommandLine('pdftoppm', null, true); @@ -533,7 +534,7 @@ class wsDocument extends cubeMetier { $pdftoppm->setArg('l', $page); $pdftoppm->setArg('-cropbox'); - $pdftoppm->setArg('-freetype yes'); + $pdftoppm->setArg('-freetype ' . $freetype); $pdftoppm->setArg('-jpeg'); $pdftoppm->setArg('-aa ' . $antialiasing); $pdftoppm->setArg('-aaVector ' . $antialiasing); @@ -626,15 +627,19 @@ class wsDocument extends cubeMetier { public function makeHTML5Files($page) { // First, make swf with polytobitmap to rasterize bitmap & vectors - $this->pdf2swf($page, 150, 90, true, self::POLY2BITMAP, 'h'); + $this->pdf2swf($page, 72, 80, true, self::POLY2BITMAP, 'h'); // Then get the special unicode dump $dump = $this->dumpSWF($page, 'h'); // Then, process it $swf2html = new wsSWF2HTML($dump); $swf2html->process(); $this->addToLog(print_r($swf2html, true), true, $page); - file_put_contents($this->html . '/p' . $page . '.obj', serialize($swf2html)); + // Then make HD background shots + $resolutions = array(36 => 80, 72 => 70, 150 => 50); + foreach($resolutions as $r => $q) { + $this->makeShotPNM($page, 'html/h' . $r . '-', $r, $q, 4, null, false); + } } protected function checkObjectsNumber($file, $maxObjects, $page) diff --git a/inc/ws/Util/class.ws.swf2html.php b/inc/ws/Util/class.ws.swf2html.php index 6280de9a2..f87f3d82d 100644 --- a/inc/ws/Util/class.ws.swf2html.php +++ b/inc/ws/Util/class.ws.swf2html.php @@ -2,6 +2,7 @@ class wsSWF2HTML { const FONT_TAG = '04b'; const TEXT_TAG = '021'; + const IMAGE_TAG=''; public $lines; public $tags = array(); diff --git a/inc/ws/Util/packager/class.ws.packager.html5.php b/inc/ws/Util/packager/class.ws.packager.html5.php index 1c180ff24..d54f3e147 100644 --- a/inc/ws/Util/packager/class.ws.packager.html5.php +++ b/inc/ws/Util/packager/class.ws.packager.html5.php @@ -58,6 +58,12 @@ class wsPackagerHTML5 extends wsPackager { foreach($this->div as $n => $page) { file_put_contents($this->vdir . '/contents/p' . $n . '.html', $this->writePage($page)); } + $this->writeFonts(); + $this->writeImages(); + } + + protected function writeFonts() + { $fext = array('ttf', 'eot', 'svg', 'svgz', 'woff'); foreach($this->fonts as $font) { if (!$font['embed']) { @@ -69,6 +75,19 @@ class wsPackagerHTML5 extends wsPackager { } } + protected function writeImages() + { + $resolutions = array(36, 72, 150); + foreach($resolutions as $r) { + mkdir($this->vdir . '/images/' . $r, 0777); + } + foreach($this->pages as $page => $infos) { + foreach($resolutions as $r) { + copy(WS_DOCS . '/' . $infos['document_id'] . '/html/h' . $r . '-' . $infos['document_page'] . '.jpg', $this->vdir . '/images/' . $r . '/p' . $page . '.jpg'); + } + } + } + protected function writePage($page) { $res = ''; @@ -80,7 +99,7 @@ class wsPackagerHTML5 extends wsPackager { protected function writeDiv($div) { - $res = '
'; + $res = '
'; foreach($div['span'] as $span) { $res .= $this->writeSpan($span); } @@ -91,7 +110,7 @@ class wsPackagerHTML5 extends wsPackager { protected function writeSpan($span) { $res = 'cssColor as $color => $index) { $res[] = '.c' . $index . '{color:' . $color . ';}'; } + foreach($this->cssSize as $size => $index) { - $res[] = '.s' . $index . '{font-size:' . $size . 'px;}'; + $size /= 100; + $res[] = '.s' . $index . '{font-size:' . $size . 'em;}'; } foreach($this->fonts as $id => $font) { @@ -116,7 +137,7 @@ class wsPackagerHTML5 extends wsPackager { $svgid = $f['id']; break; } - $res[] = "@font-face{font-family:'" . $font['name'] . "';src:url('" . $font['name'] . ".eot');src:url('" . $font['name'] . ".eot?#iefix') format('eot'),url('" . $font['name'] . ".woff') format('woff'),url('" . $font['name'] . ".ttf') format('truetype'),url('" . $font['name'] . ".svgz#" . $svgid . "') format('svgz'),url('" . $font['name'] . ".svg#" . $svgid . "') format('svg');font-weight:normal;font-style:normal;}"; + $res[] = "@font-face{font-family:'" . $font['name'] . "';src:url('" . $font['url'] . ".eot');src:url('" . $font['url'] . ".eot?#iefix') format('eot'),url('" . $font['url'] . ".woff') format('woff'),url('" . $font['url'] . ".ttf') format('truetype'),url('" . $font['url'] . ".svgz#" . $svgid . "') format('svgz'),url('" . $font['url'] . ".svg#" . $svgid . "') format('svg');font-weight:normal;font-style:normal;}"; $res[] = '.f' . $font['index'] . '{font-family:' . $font['name'] . ',Arial,Helvetica;}'; } else { $res[] = '.f' . $font['index'] . '{font-family:' . $font['realname'] . ',Arial,Helvetica;}'; @@ -134,7 +155,7 @@ class wsPackagerHTML5 extends wsPackager { $index = $this->fontsCount; $file = WS_DOCS . '/' . $infos['document_id'] . '/fonts/web/' . $tag->name; $embed = file_exists($file . '.ttf'); - $this->fonts[$tag->name] = array('index' => $index, 'realname' => $tag->name, 'name' => 'FB' . $index, 'file' => $file, 'embed' => $embed); + $this->fonts[$tag->name] = array('index' => $index, 'realname' => $tag->name, 'name' => 'FB' . $index, 'file' => $file, 'embed' => $embed, 'url' => '../fonts/FB' . $index); $this->fontsCount++; } @@ -142,13 +163,21 @@ class wsPackagerHTML5 extends wsPackager { { $d = array('span' => array(), 'left' => $tag->left, 'top' => $tag->top); foreach($tag->textes as $text) { - $d['span'][] = $this->addCSSText($text, $page); + $s = $this->addCSSText($text, $page); + if ($s === false) { + continue; + } + $d['span'][] = $s; } $div[] = $d; } protected function addCSSText($text, $page) { + $alpha = intval(substr($text->color, -2), 16); + if ($alpha == 0) { + return false; + } return array('text' => $text->text, 'color' => $this->getCSSColor($text->color), 'size' => $this->getCSSSize($text->size), @@ -179,6 +208,7 @@ class wsPackagerHTML5 extends wsPackager { protected function getIndex($value, &$tab) { + $value = (string)$value; if (isset($tab[$value])) { return $tab[$value]; } -- 2.39.5