From 88c6cc68f030230245a5b3bd37a8279344927f3b Mon Sep 17 00:00:00 2001 From: "vincent@cubedesigners.com" Date: Mon, 9 May 2011 22:49:02 +0000 Subject: [PATCH] --- .../Util/packager/class.ws.packager.html5.php | 85 +++++++++++++------ 1 file changed, 60 insertions(+), 25 deletions(-) diff --git a/inc/ws/Util/packager/class.ws.packager.html5.php b/inc/ws/Util/packager/class.ws.packager.html5.php index 799cc8b71..094ec2ab8 100644 --- a/inc/ws/Util/packager/class.ws.packager.html5.php +++ b/inc/ws/Util/packager/class.ws.packager.html5.php @@ -10,6 +10,8 @@ class wsPackagerHTML5 extends wsPackager { protected $cssWordSpacing = array(); protected $cssLetterSpacing = array(); protected $cssRotation = array(); + protected $cssX = array(); + protected $cssY = array(); protected $pdf2htmlRatio; protected $scale; protected $multiply; @@ -56,12 +58,12 @@ class wsPackagerHTML5 extends wsPackager { mkdir($this->vdir . '/contents', 0777, true); mkdir($this->vdir . '/images', 0777, true); - file_put_contents($this->vdir . '/style/style.css', $this->writeCSS()); foreach ($this->div as $n => $page) { file_put_contents($this->vdir . '/contents/p' . $n . '.html', $this->writePage($page)); } $this->writeFonts(); $this->writeImages(); + file_put_contents($this->vdir . '/style/style.css', $this->writeCSS()); } protected function writeFonts() { @@ -95,16 +97,23 @@ class wsPackagerHTML5 extends wsPackager { } protected function writeLine($line) { + $line['x'] = $this->getCSSX($line['x'] * $this->multiply); + $line['y'] = $this->getCSSY($line['y'] * $this->multiply); + $class = array('l'); if (!is_null($line['rotation'])) { $class[] = 'r' . $line['rotation']; } + if (!is_null($line['x'])) { + $class[] = 'x' . $line['x']; + } + if (!is_null($line['y'])) { + $class[] = 'y' . $line['y']; + } $class = implode(' ', $class); - $left = round($line['x'] * $this->multiply, 2); - $top = round($line['y'] * $this->multiply, 2); - $res = '
'; + $res = '
'; foreach ($line['groups'] as $group) { $res.=$this->writeGroup($group); } @@ -117,6 +126,8 @@ class wsPackagerHTML5 extends wsPackager { return ''; } + $group['y'] = $this->getCSSY($group['y'] * $this->multiply); + $class = array('g'); if (!is_null($group['color'])) { $class[] = 'c' . $group['color']; @@ -127,11 +138,12 @@ class wsPackagerHTML5 extends wsPackager { if (!is_null($group['font'])) { $class[] = 'f' . $group['font']; } + if (!is_null($group['y'])) { + $class[] = 'y' . $group['y']; + } $class = implode(' ', $class); - $top = round($group['x'] * $this->multiply, 2); - - $res = '
'; + $res = '
'; foreach ($group['spans'] as $span) { $res.=$this->writeSpan($span); } @@ -146,19 +158,24 @@ class wsPackagerHTML5 extends wsPackager { $class = array(); + $span['x'] = $this->getCSSX($span['x'] * $this->multiply); + + if (!is_null($span['x'])) { + $class[] = 'x' . $span['x']; + } if (!is_null($span['letterspacing'])) { $class[] = 'l' . $span['letterspacing']; } if (count($class)) { $class = ' class="' . implode(' ', $class) . '"'; + } else { + $class = ""; } - $left = round($span['x'] * $this->multiply, 2); - - $res = ''; + $res = ''; $res .= self::escapeHTML($span['text']); - $res .= ''; + $res .= '

'; return $res; } @@ -169,7 +186,6 @@ class wsPackagerHTML5 extends wsPackager { } foreach ($this->cssSize as $size => $index) { - $size*=$this->multiply; $res[] = '.s' . $index . '{font-size:' . $size . 'px}'; } @@ -183,6 +199,14 @@ class wsPackagerHTML5 extends wsPackager { $res[] = '.w' . $index . '{word-spacing:' . $wordspacing . 'px}'; } + foreach ($this->cssX as $x => $index) { + $res[] = '.x' . $index . '{left:' . $x . 'px}'; + } + + foreach ($this->cssY as $y => $index) { + $res[] = '.y' . $index . '{top:' . $y . 'px}'; + } + foreach ($this->cssRotation as $rotation => $index) { $rotation*= - 1; @@ -200,7 +224,7 @@ class wsPackagerHTML5 extends wsPackager { foreach ($this->cssFont as $font => $index) { list($font, $document_id) = explode('//', $font); - $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')}"; + $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')}"; $res[] = '.f' . $index . '{font-family:F' . $index . ',Arial,Helvetica}'; } return implode("\n", $res); @@ -227,11 +251,7 @@ class wsPackagerHTML5 extends wsPackager { foreach ($group->s as $span) { $newSpan = $this->addSpan($span, $document_id); - if (count($res) > 0) { - $lastSpan = array_pop($res); - $lastSpan['letterspacing'] = $this->getCSSLetterSpacing($newSpan['x'] - $lastSpan['x'] - $lastSpan['width']); - array_push($res, $lastspan); - } + array_push($res, $newSpan); } @@ -239,7 +259,7 @@ class wsPackagerHTML5 extends wsPackager { 'color' => $this->getCSSColor($group['color']), 'size' => $this->getCSSSize($group['size']), 'font' => $this->getCSSFont($group['font'], $document_id), - 'x' => $group['size'] / -1.2, + 'y' => ($group['size']) / -1.2, 'spans' => $res); } @@ -252,17 +272,16 @@ class wsPackagerHTML5 extends wsPackager { return array('text' => $text, 'x' => $this->normalizeFloatValue($span['x']), 'width' => $this->normalizeFloatValue($span['width']), - 'letterspacing' => 0); + 'letterspacing' => null); } protected function getCSSSize(&$size) { $size/=1.05; - $size = $this->normalizeFloatValue($size); - return $this->getIndex($size, $this->cssSize); + $sizer = round($size * $this->multiply); + return $this->getIndex($sizer, $this->cssSize); } protected function getCSSFont($font, $document_id) { - return $this->getIndex($font . "//" . $document_id, $this->cssFont); } @@ -301,6 +320,22 @@ class wsPackagerHTML5 extends wsPackager { return $this->getIndex($rotation, $this->cssRotation); } + protected function getCSSX($x) { + $x = round($x); + if ($x == 0) { + return null; + } + return $this->getIndex($x, $this->cssX); + } + + protected function getCSSY($y) { + $y = round($y); + if ($y == 0) { + return null; + } + return $this->getIndex($y, $this->cssY); + } + protected function getIndex($value, &$tab) { $value = (string) $value; if (isset($tab[$value])) { @@ -331,8 +366,8 @@ class wsPackagerHTML5 extends wsPackager { } public static function escapeHTML($in) { - $in = str_replace(' ', ' ', $in); - $in = str_replace("\x2009", " ", $in); + $in = htmlentities($in, ENT_NOQUOTES, "UTF-8"); + $in = str_replace(' ', '', $in); return $in; -- 2.39.5