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
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
}\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
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
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
\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
}\r
\r
foreach ($this->cssSize as $size => $index) {\r
- $size*=$this->multiply;\r
$res[] = '.s' . $index . '{font-size:' . $size . 'px}';\r
}\r
\r
$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
\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
\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
'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
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
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
}\r
\r
public static function escapeHTML($in) {\r
- $in = str_replace(' ', ' ', $in);\r
- $in = str_replace("\x2009", " ", $in);\r
+ $in = htmlentities($in, ENT_NOQUOTES, "UTF-8");\r
+ $in = str_replace(' ', '', $in);\r
\r
\r
return $in;\r