]> _ Git - cubeextranet.git/commitdiff
(no commit message)
authorvincent@cubedesigners.com <vincent@cubedesigners.com@f5622870-0f3c-0410-866d-9cb505b7a8ef>
Mon, 29 Aug 2011 02:06:26 +0000 (02:06 +0000)
committervincent@cubedesigners.com <vincent@cubedesigners.com@f5622870-0f3c-0410-866d-9cb505b7a8ef>
Mon, 29 Aug 2011 02:06:26 +0000 (02:06 +0000)
inc/ws/Util/html5/class.ws.html5.compiler.php

index b09b38e92ba92e057f9bacbe4293cfdc621e165c..d45c20cbea6387fae20a397ac52e1ca6d7262d5a 100644 (file)
@@ -66,7 +66,7 @@ class wsHTML5Compiler {
        protected $optimalWidth = 567;
        protected $optimalHeight = 709;
        protected $additionalConfig = array();
-       protected $fontScale = 1;
+       protected $fontScale = 0.9775;
 
        function __construct($book_id) {
                global $core;
@@ -130,7 +130,7 @@ class wsHTML5Compiler {
 
        protected function sortPage($layout) {
                $lines = array();
-               foreach ($layout->l as $line) {
+               foreach ($layout->line as $line) {
                        $lines[] = $line;
                }
                usort($lines, array($this, 'compareLines'));
@@ -227,7 +227,7 @@ class wsHTML5Compiler {
                $scripts[] = '<script type="text/javascript" src="data/datas.js"></script>';
                $script = implode("\n\t\t", $scripts);
 
-               $scripts=array();
+               $scripts = array();
                foreach (self::$testJsFiles as $js) {
                        $scripts[] = '<script type="text/javascript" src="' . $js . '"></script>';
                }
@@ -239,9 +239,9 @@ class wsHTML5Compiler {
                        $uhtml = str_replace('<!-- $' . $v . ' -->', $$v, $uhtml);
                }
 
-               $thtml=file_get_contents(WS_COMPILE_ASSETS . '/_html5/tester.html');
-               
-                               $vars = array('titre', 'credits', 'ga', 'style', 'script_test');
+               $thtml = file_get_contents(WS_COMPILE_ASSETS . '/_html5/tester.html');
+
+               $vars = array('titre', 'credits', 'ga', 'style', 'script_test');
                foreach ($vars as $v) {
                        $thtml = str_replace('<!-- $' . $v . ' -->', $$v, $thtml);
                }
@@ -467,8 +467,8 @@ class wsHTML5Compiler {
 
                $group['y'] = $this->getCSSY(($group['y'] + $line['y']) * $this->multiply);
                $group['x'] = $this->getCSSX(($group['x']) * $this->multiply);
-               $group['letterspacing'] = $this->getCSSLetterSpacing($group['letterspacing'] * $this->multiply);
-               $group['wordspacing'] = $this->getCSSWordSpacing($group['wordspacing'] * $this->multiply);
+               $group['letterspacing'] = $this->getCSSLetterSpacing($group['letterspacing'] );
+               $group['wordspacing'] = $this->getCSSWordSpacing($group['wordspacing']);
 
                $class = array('g');
                if (!is_null($group['color'])) {
@@ -690,11 +690,11 @@ class wsHTML5Compiler {
                }
 
                foreach ($this->cssLetterSpacing as $letterspacing => $index) {
-                       $res[] = '.l' . $index . '{letter-spacing:' . $letterspacing . 'px}';
+                       $res[] = '.l' . $index . '{letter-spacing:' . $letterspacing . 'em}';
                }
 
                foreach ($this->cssWordSpacing as $wordspacing => $index) {
-                       $res[] = '.w' . $index . '{word-spacing:' . $wordspacing . 'px}';
+                       $res[] = '.w' . $index . '{word-spacing:' . $wordspacing . 'em}';
                }
 
                foreach ($this->cssX as $x => $index) {
@@ -848,14 +848,14 @@ class wsHTML5Compiler {
 
                        $ws = floatval($group['wordspacing']);
                        $ls = floatval($group['letterspacing']);
-                       $size = floatval($group['size']);
+                       $size = floatval($group['size'])*$this->fontScale;
 
                        $res[] = array(
                                'color' => $this->getCSSColor($group['color']),
-                               'size' => $this->getCSSSize($group['size']),
+                               'size' => $this->getCSSSize($size),
                                'font' => $this->getCSSFont($group['font'], $document_id),
-                               'letterspacing' => $ls * $size,
-                               'wordspacing' => $ws * $size,
+                               'letterspacing' => $ls,
+                               'wordspacing' => $ws,
                                'y' => 0,
                                'x' => $x,
                                'text' => $text);
@@ -871,12 +871,7 @@ class wsHTML5Compiler {
                $nextX = 0;
                $x = 0;
 
-               $spaceWidth = $group['space'];
-               $size = floatval($group['size']);
-               $letterSpacing = floatval($group['letterspacing']) * $size;
-               $wordSpacing = floatval($group['wordspacing']) * $size + $letterSpacing;
-
-               $lastIsSpace = true;
+               $lastIsSpace = false;
 
                foreach ($group->s as $span) {
                        $char = (string) $span;
@@ -888,6 +883,12 @@ class wsHTML5Compiler {
                                $x = floatval($span['x']);
                                $first = false;
                        }
+
+                       if ($char == " ") {
+                               $lastIsSpace = true;
+                               continue;
+                       }
+
                        $sox = floatval($span['x']);
                        $sx = $sox - $x;
                        $sw = floatval($span['width']);
@@ -895,44 +896,18 @@ class wsHTML5Compiler {
                        $diff = $sx - $nextX;
 
                        $s = $char;
+                       $left = round($sx * $this->multiply, 2);
+                       $s = '<span style="left:' . $left . 'px;">' . $s . '</span>';
 
-                       if ($lastIsSpace) {
-                               if ($diff > $wordSpacing) {
-                                       $diff-=$wordSpacing;
-                                       $diff = round($diff * $this->multiply, 2);
-                                       if ($diff != 0) {
-                                               $s = '<span class="gap" style="margin-left:' . $diff . 'px">' . $s . '</span>';
-                                       }
-                               }
-                       } else {
-                               if ($diff < $letterSpacing) {
-                                       $diff-=$letterSpacing;
-                                       $diff = round($diff * $this->multiply, 2);
-                                       if ($diff != 0) {
-                                               $s = '<span class="gap" style="margin-left:' . $diff . 'px">' . $s . '</span>';
-                                       }
-                               } else if ($diff > $letterSpacing) {
-                                       $diff-=$letterSpacing;
-                                       $diff = round($diff * $this->multiply, 2);
-                                       if ($diff != 0) {
-                                               $s = '<span class="gap" style="margin-left:' . $diff . 'px">' . $s . '</span>';
-                                       }
-                               }
-                       }
 
                        $newSpan = array('text' => $s, 'x' => $sox);
                        $currentGroup['spans'][] = $newSpan;
-
-
-                       $nextX = $sx + $sw;
-                       $lastIsSpace = substr($char, -1) == " ";
                }
                $res[] = $currentGroup;
                return $res;
        }
 
-       protected function getCSSSize(
-       $size) {
+       protected function getCSSSize($size) {
                $size = $this->normalizeFloatValue($size);
                $size*=$this->multiply;
                return $this->getIndex($size, $this->cssSize);