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

index 799cc8b717e5edae83974d6d97b5878deb3d0232..094ec2ab8cfbf2229c99f8710fa91e81fca37067 100644 (file)
@@ -10,6 +10,8 @@ class wsPackagerHTML5 extends wsPackager {
        protected $cssWordSpacing = array();\r
        protected $cssLetterSpacing = array();\r
        protected $cssRotation = array();\r
+       protected $cssX = array();\r
+       protected $cssY = array();\r
        protected $pdf2htmlRatio;\r
        protected $scale;\r
        protected $multiply;\r
@@ -56,12 +58,12 @@ class wsPackagerHTML5 extends wsPackager {
                mkdir($this->vdir . '/contents', 0777, true);\r
                mkdir($this->vdir . '/images', 0777, true);\r
 \r
-               file_put_contents($this->vdir . '/style/style.css', $this->writeCSS());\r
                foreach ($this->div as $n => $page) {\r
                        file_put_contents($this->vdir . '/contents/p' . $n . '.html', $this->writePage($page));\r
                }\r
                $this->writeFonts();\r
                $this->writeImages();\r
+               file_put_contents($this->vdir . '/style/style.css', $this->writeCSS());\r
        }\r
 \r
        protected function writeFonts() {\r
@@ -95,16 +97,23 @@ class wsPackagerHTML5 extends wsPackager {
        }\r
 \r
        protected function writeLine($line) {\r
+               $line['x'] = $this->getCSSX($line['x'] * $this->multiply);\r
+               $line['y'] = $this->getCSSY($line['y'] * $this->multiply);\r
+\r
                $class = array('l');\r
                if (!is_null($line['rotation'])) {\r
                        $class[] = 'r' . $line['rotation'];\r
                }\r
+               if (!is_null($line['x'])) {\r
+                       $class[] = 'x' . $line['x'];\r
+               }\r
+               if (!is_null($line['y'])) {\r
+                       $class[] = 'y' . $line['y'];\r
+               }\r
                $class = implode(' ', $class);\r
 \r
-               $left = round($line['x'] * $this->multiply, 2);\r
-               $top = round($line['y'] * $this->multiply, 2);\r
 \r
-               $res = '<div style="top:' . $top . 'px;left:' . $left . 'px" class="' . $class . '">';\r
+               $res = '<div class="' . $class . '">';\r
                foreach ($line['groups'] as $group) {\r
                        $res.=$this->writeGroup($group);\r
                }\r
@@ -117,6 +126,8 @@ class wsPackagerHTML5 extends wsPackager {
                        return '';\r
                }\r
 \r
+               $group['y'] = $this->getCSSY($group['y'] * $this->multiply);\r
+\r
                $class = array('g');\r
                if (!is_null($group['color'])) {\r
                        $class[] = 'c' . $group['color'];\r
@@ -127,11 +138,12 @@ class wsPackagerHTML5 extends wsPackager {
                if (!is_null($group['font'])) {\r
                        $class[] = 'f' . $group['font'];\r
                }\r
+               if (!is_null($group['y'])) {\r
+                       $class[] = 'y' . $group['y'];\r
+               }\r
                $class = implode(' ', $class);\r
 \r
-               $top = round($group['x'] * $this->multiply, 2);\r
-\r
-               $res = '<div class="' . $class . '" style="top:' . $top . 'px">';\r
+               $res = '<div class="' . $class . '">';\r
                foreach ($group['spans'] as $span) {\r
                        $res.=$this->writeSpan($span);\r
                }\r
@@ -146,19 +158,24 @@ class wsPackagerHTML5 extends wsPackager {
 \r
                $class = array();\r
 \r
+               $span['x'] = $this->getCSSX($span['x'] * $this->multiply);\r
+\r
+               if (!is_null($span['x'])) {\r
+                       $class[] = 'x' . $span['x'];\r
+               }\r
                if (!is_null($span['letterspacing'])) {\r
                        $class[] = 'l' . $span['letterspacing'];\r
                }\r
 \r
                if (count($class)) {\r
                        $class = ' class="' . implode(' ', $class) . '"';\r
+               } else {\r
+                       $class = "";\r
                }\r
 \r
-               $left = round($span['x'] * $this->multiply, 2);\r
-\r
-               $res = '<span style="left:' . $left . 'px"' . $class . '>';\r
+               $res = '<p' . $class . '>';\r
                $res .= self::escapeHTML($span['text']);\r
-               $res .= '</span>';\r
+               $res .= '</p>';\r
                return $res;\r
        }\r
 \r
@@ -169,7 +186,6 @@ class wsPackagerHTML5 extends wsPackager {
                }\r
 \r
                foreach ($this->cssSize as $size => $index) {\r
-                       $size*=$this->multiply;\r
                        $res[] = '.s' . $index . '{font-size:' . $size . 'px}';\r
                }\r
 \r
@@ -183,6 +199,14 @@ class wsPackagerHTML5 extends wsPackager {
                        $res[] = '.w' . $index . '{word-spacing:' . $wordspacing . 'px}';\r
                }\r
 \r
+               foreach ($this->cssX as $x => $index) {\r
+                       $res[] = '.x' . $index . '{left:' . $x . 'px}';\r
+               }\r
+\r
+               foreach ($this->cssY as $y => $index) {\r
+                       $res[] = '.y' . $index . '{top:' . $y . 'px}';\r
+               }\r
+\r
                foreach ($this->cssRotation as $rotation => $index) {\r
                        $rotation*= - 1;\r
 \r
@@ -200,7 +224,7 @@ class wsPackagerHTML5 extends wsPackager {
 \r
                foreach ($this->cssFont as $font => $index) {\r
                        list($font, $document_id) = explode('//', $font);\r
-                       $res[] = "@font-face{font-family:F" . $index . ";src:url('F" . $index . ".eot');src:url('F" . $index . ".eot?#iefix') format('eot'),url('F" . $index . ".woff') format('woff'),url('F" . $index . ".ttf') format('truetype'),url('F" . $index . ".svgz#" . $font . "') format('svgz'),url('F" . $index . ".svg#" . $font . "') format('svg')}";\r
+                       $res[] = "@font-face{font-family:F" . $index . ";src:url('F" . $index . ".eot');src:url('F" . $index . ".eot?#iefix') format('eot'),url('F" . $index . ".ttf') format('truetype'),url('F" . $index . ".svgz#" . $font . "') format('svgz'),url('F" . $index . ".svg#" . $font . "') format('svg')}";\r
                        $res[] = '.f' . $index . '{font-family:F' . $index . ',Arial,Helvetica}';\r
                }\r
                return implode("\n", $res);\r
@@ -227,11 +251,7 @@ class wsPackagerHTML5 extends wsPackager {
 \r
                foreach ($group->s as $span) {\r
                        $newSpan = $this->addSpan($span, $document_id);\r
-                       if (count($res) > 0) {\r
-                               $lastSpan = array_pop($res);\r
-                               $lastSpan['letterspacing'] = $this->getCSSLetterSpacing($newSpan['x'] - $lastSpan['x'] - $lastSpan['width']);\r
-                               array_push($res, $lastspan);\r
-                       }\r
+\r
                        array_push($res, $newSpan);\r
                }\r
 \r
@@ -239,7 +259,7 @@ class wsPackagerHTML5 extends wsPackager {
                        'color' => $this->getCSSColor($group['color']),\r
                        'size' => $this->getCSSSize($group['size']),\r
                        'font' => $this->getCSSFont($group['font'], $document_id),\r
-                       'x' => $group['size'] / -1.2,\r
+                       'y' => ($group['size']) / -1.2,\r
                        'spans' => $res);\r
        }\r
 \r
@@ -252,17 +272,16 @@ class wsPackagerHTML5 extends wsPackager {
                return array('text' => $text,\r
                        'x' => $this->normalizeFloatValue($span['x']),\r
                        'width' => $this->normalizeFloatValue($span['width']),\r
-                       'letterspacing' => 0);\r
+                       'letterspacing' => null);\r
        }\r
 \r
        protected function getCSSSize(&$size) {\r
                $size/=1.05;\r
-               $size = $this->normalizeFloatValue($size);\r
-               return $this->getIndex($size, $this->cssSize);\r
+               $sizer = round($size * $this->multiply);\r
+               return $this->getIndex($sizer, $this->cssSize);\r
        }\r
 \r
        protected function getCSSFont($font, $document_id) {\r
-\r
                return $this->getIndex($font . "//" . $document_id, $this->cssFont);\r
        }\r
 \r
@@ -301,6 +320,22 @@ class wsPackagerHTML5 extends wsPackager {
                return $this->getIndex($rotation, $this->cssRotation);\r
        }\r
 \r
+       protected function getCSSX($x) {\r
+               $x = round($x);\r
+               if ($x == 0) {\r
+                       return null;\r
+               }\r
+               return $this->getIndex($x, $this->cssX);\r
+       }\r
+\r
+       protected function getCSSY($y) {\r
+               $y = round($y);\r
+               if ($y == 0) {\r
+                       return null;\r
+               }\r
+               return $this->getIndex($y, $this->cssY);\r
+       }\r
+\r
        protected function getIndex($value, &$tab) {\r
                $value = (string) $value;\r
                if (isset($tab[$value])) {\r
@@ -331,8 +366,8 @@ class wsPackagerHTML5 extends wsPackager {
        }\r
 \r
        public static function escapeHTML($in) {\r
-               $in = str_replace(' ', '&nbsp;', $in);\r
-               $in = str_replace("\x2009", "&nbsp;", $in);\r
+               $in = htmlentities($in, ENT_NOQUOTES, "UTF-8");\r
+               $in = str_replace('&thinsp;', '', $in);\r
 \r
 \r
                return $in;\r