From 1b019d42480475daaf890e771321d3bd5ade9920 Mon Sep 17 00:00:00 2001 From: "vincent@cubedesigners.com" Date: Sat, 27 Aug 2011 11:54:35 +0000 Subject: [PATCH] --- inc/ws/DAO/class.ws.dao.book.php | 2 +- inc/ws/Metier/class.ws.document.php | 6 +- inc/ws/Util/html5/class.ws.html5.compiler.php | 84 +++++++++++++++++-- 3 files changed, 81 insertions(+), 11 deletions(-) diff --git a/inc/ws/DAO/class.ws.dao.book.php b/inc/ws/DAO/class.ws.dao.book.php index 8deb027ee..b9d50160f 100644 --- a/inc/ws/DAO/class.ws.dao.book.php +++ b/inc/ws/DAO/class.ws.dao.book.php @@ -536,7 +536,7 @@ class wsDAOBook extends commonDAO { return false; } - $checks = array($r->changedate, cubeFiles::filemtimeRecursive(WS_COMPILE_ASSETS . '/_html5')); + $checks = array($r->changedate, cubeFiles::filemtimeRecursive(WS_COMPILE_ASSETS . '/_html5'), cubeFiles::filemtimeRecursive(ROOT.'/inc/ws/Util/html5')); $reffile = WS_BOOKS . '/html5/' . $book_id; if (!file_exists($reffile)) { diff --git a/inc/ws/Metier/class.ws.document.php b/inc/ws/Metier/class.ws.document.php index f1c9835c7..7e4e4a82a 100644 --- a/inc/ws/Metier/class.ws.document.php +++ b/inc/ws/Metier/class.ws.document.php @@ -632,11 +632,13 @@ class wsDocument extends cubeMetier { public function makeHTML5Files($page) { // Then make HD background shots - $resolutions = array(36 => 80, 72 => 70, 150 => 50); + $resolutions = array(36 => 90, 72 => 80, 150 => 75); foreach ($resolutions as $r => $q) { $texts = false; $this->makeShotPNM($page, 'html/h' . $r . '-', $r, $q, 4, null, $texts); } + // Then get layout infos from swf + file_put_contents($this->out . '/html/s' . $page . '.layout', $this->dumpSWF($page)); } protected function checkObjectsNumber($file, $maxObjects, $page) { @@ -793,7 +795,7 @@ class wsDocument extends cubeMetier { $pdf2swf->setArg('set jpegquality', $quality); $pdf2swf->setArg('set disablelinks'); $pdf2swf->setArg('set dots'); - // $pdf2swf->setManualArg('-vvv'); + $pdf2swf->setManualArg('-vvv'); $pdf2swf->setArg(null, $this->cropped); $pdf2swf->setArg('output', $this->out . $prefix . '%.swf'); $pdf2swf->execute(); diff --git a/inc/ws/Util/html5/class.ws.html5.compiler.php b/inc/ws/Util/html5/class.ws.html5.compiler.php index 5eac66138..49a8c184d 100644 --- a/inc/ws/Util/html5/class.ws.html5.compiler.php +++ b/inc/ws/Util/html5/class.ws.html5.compiler.php @@ -104,7 +104,7 @@ class wsHTML5Compiler { $this->cssWidth = $this->width * $this->cssScale; $this->cssHeight = $this->height * $this->cssScale; - $this->scale = 4; + $this->scale = 10; $this->multiply = $this->pdf2htmlRatio * $this->scale * $this->cssScale; $this->numerotation = explode(',', $this->book->numerotation); } @@ -333,8 +333,6 @@ class wsHTML5Compiler { $fontforge->setArg(null, '-'); $fontforge->setArg(null, $this->vdir . '/data/style/F' . $index . '.' . $format); $fontforge->execute(); - - fb($fontforge->commande); } } } @@ -453,6 +451,7 @@ class wsHTML5Compiler { $wm = ($this->width * $this->multiply) . 'px'; $hm = ($this->height * $this->multiply) . 'px'; $offsetLeft = round(($this->optimalWidth - $this->cssWidth) / 2, 2); + $offsetLeft2 = $offsetLeft * 2; $offsetTop = round(($this->optimalHeight - $this->cssHeight) / 2, 2); $navTop = ($this->cssHeight - 40 - 100) / 2; @@ -460,6 +459,7 @@ class wsHTML5Compiler { $res[] = '#fluidbook{left:' . $offsetLeft . 'px;top:' . $offsetTop . 'px;}'; + $res[] = '.landscape #fluidbook{left:' . $offsetLeft2 . 'px;}'; $res[] = '.portrait #pages,.portrait .doublePage.page,.page,.portrait #shadow,#shadow.single,.page .links{width:' . $w . ';max-width:' . $w . ';height:' . $h . ';max-height:' . $h . '}'; $res[] = '.background{' . $this->writeCSSUA('transform-origin', 'top left') . ';}'; foreach (self::$resolutions as $r) { @@ -515,11 +515,11 @@ class wsHTML5Compiler { $body.='background-image:url(../images/' . $this->theme->parametres->backgroundImage . ');'; $body.='background-position:'; - if(file_exists($this->themeRoot . '/' . $this->theme->parametres->backgroundImage)){ - $dim=getimagesize($this->themeRoot . '/' . $this->theme->parametres->backgroundImage); - $this->additionalConfig['backgroundRatio']=$dim[0]/$dim[1]; - }else{ - $this->additionalConfig['backgroundRatio']=1; + if (file_exists($this->themeRoot . '/' . $this->theme->parametres->backgroundImage)) { + $dim = getimagesize($this->themeRoot . '/' . $this->theme->parametres->backgroundImage); + $this->additionalConfig['backgroundRatio'] = $dim[0] / $dim[1]; + } else { + $this->additionalConfig['backgroundRatio'] = 1; } switch ($this->theme->parametres->backgroundVAlign) { @@ -668,6 +668,9 @@ class wsHTML5Compiler { protected function addLine($line, $document_id) { $res = array(); + if (count($line->a) > 1) { + $line = $this->sortLine($line); + } foreach ($line->a as $group) { $res = array_merge($res, $this->addGroup($group, $document_id)); } @@ -677,6 +680,71 @@ class wsHTML5Compiler { "groups" => $res); } + protected function sortLine($line) { + $debug = rand(1, 20) == 5; + + + // Copy the current line to a new one + $l = simplexml_load_string(''); + foreach ($line->attributes() as $k => $v) { + $l->addAttribute($k, $v); + } + + // Get the s elements and sort them by x + $tab = array(); + $allSpans = $line->xpath("a/s"); + foreach ($allSpans as $span) { + $tab[] = $span; + } + + usort($tab, array('wsHTML5Compiler', 'sortSpans')); + if ($debug) { + //fb($tab); + } + + $currentGroup = null; + $lastParent = null; + foreach ($tab as $span) { + $parents = $span->xpath(".."); + $parent = array_pop($parents); + if ($parent == $lastParent) { + cubeXML::append($currentGroup, $span); + continue; + } + if (!is_null($currentGroup)) { + cubeXML::append($l, $currentGroup); + } + + $lastParent = $parent; + $currentGroup = simplexml_load_string(''); + foreach ($parent->attributes() as $k => $v) { + $currentGroup->addAttribute($k, $v); + } + cubeXML::append($currentGroup, $span); + } + + if (!is_null($currentGroup)) { + cubeXML::append($l, $currentGroup); + } + + if ($debug) { + fb($l); + } + return $l; + } + + protected static function sortSpans($a, $b) { + $xa = floatval((string) $a['x']); + $xb = floatval((string) $b['x']); + + if ($xa > $xb) { + return 1; + } else if ($xa < $xb) { + return -1; + } + return 0; + } + protected function addGroup($group, $document_id) { $alpha = intval(substr($group['color'], 1, 2), 16); if ($alpha == 0) { -- 2.39.5