From 3d4356e6879d285e432f2fbcdac1ba35f6946848 Mon Sep 17 00:00:00 2001 From: "vincent@cubedesigners.com" Date: Sun, 3 Apr 2011 15:32:15 +0000 Subject: [PATCH] --- inc/ws/Controlleur/_common.php | 1 - inc/ws/Metier/class.ws.document.php | 14 +- inc/ws/Util/_common.php | 11 ++ .../class.ws.secure.swf.php | 0 inc/ws/Util/class.ws.swf2html.php | 179 ++++++++++++++++++ inc/ws/_common.php | 1 + 6 files changed, 197 insertions(+), 9 deletions(-) create mode 100644 inc/ws/Util/_common.php rename inc/ws/{Controlleur => Util}/class.ws.secure.swf.php (100%) create mode 100644 inc/ws/Util/class.ws.swf2html.php diff --git a/inc/ws/Controlleur/_common.php b/inc/ws/Controlleur/_common.php index 43fe49fd3..81b221831 100644 --- a/inc/ws/Controlleur/_common.php +++ b/inc/ws/Controlleur/_common.php @@ -9,7 +9,6 @@ $__autoload['wsConversionSession'] = dirname(__FILE__) . '/class.ws.conversion.s $__autoload['wsStats'] = dirname(__FILE__) . '/class.ws.stats.php'; $__autoload['wsServices'] = dirname(__FILE__) . '/class.ws.services.php'; $__autoload['wsUsersTree'] = dirname(__FILE__) . '/class.ws.users.tree.php'; -$__autoload['wsSecureSWF'] = dirname(__FILE__) . '/class.ws.secure.swf.php'; $__autoload['wsMaintenance'] = dirname(__FILE__) . '/class.ws.maintenance.php'; ?> \ No newline at end of file diff --git a/inc/ws/Metier/class.ws.document.php b/inc/ws/Metier/class.ws.document.php index cb83d90b4..33d947641 100644 --- a/inc/ws/Metier/class.ws.document.php +++ b/inc/ws/Metier/class.ws.document.php @@ -96,7 +96,7 @@ class wsDocument extends cubeMetier { if (!file_exists($out)) { mkdir($out, 0777, true); } - + // Extract fonts from PDF $gs = new cubeCommandLine('gs'); $gs->setPath(CONVERTER_PATH); $gs->cd($out); @@ -132,16 +132,16 @@ class wsDocument extends cubeMetier { $ttf2eot->setPath(CONVERTER_PATH); $ttf2eot->setManualArg('< ' . $this->out . '/fonts/web/' . $fname . '.ttf'); $ttf2eot->execute(); + $this->addToLog($ttf2eot); } else { $fontforge = new cubeCommandLine('convert.pe'); $fontforge->setPath(CONVERTER_PATH); $fontforge->setArg(null, $out . '/' . $file); $fontforge->setArg(null, $this->out . '/fonts/web/' . $fname . '.' . $format); $fontforge->execute(); + $this->addToLog($fontforge); } } - - $this->addToLog($fontforge); } } @@ -624,12 +624,10 @@ class wsDocument extends cubeMetier { // First, make swf with polytobitmap to rasterize bitmap & vectors $this->pdf2swf($page, 150, 90, true, self::POLY2BITMAP, 'h'); $dump = $this->dumpSWF($page, 'h'); - // Analyse du dump - $fonts = array(); + $swf2html = new wsSWF2HTML($dump); + $swf2html->process(); - $lines = explode("\n", $dump); - foreach($lines as $line) { - } + $this->addToLog(print_r($swf2html, true), true, $page); } protected function checkObjectsNumber($file, $maxObjects, $page) diff --git a/inc/ws/Util/_common.php b/inc/ws/Util/_common.php new file mode 100644 index 000000000..4bfccf57e --- /dev/null +++ b/inc/ws/Util/_common.php @@ -0,0 +1,11 @@ + \ No newline at end of file diff --git a/inc/ws/Controlleur/class.ws.secure.swf.php b/inc/ws/Util/class.ws.secure.swf.php similarity index 100% rename from inc/ws/Controlleur/class.ws.secure.swf.php rename to inc/ws/Util/class.ws.secure.swf.php diff --git a/inc/ws/Util/class.ws.swf2html.php b/inc/ws/Util/class.ws.swf2html.php new file mode 100644 index 000000000..dff7881d7 --- /dev/null +++ b/inc/ws/Util/class.ws.swf2html.php @@ -0,0 +1,179 @@ +lines = explode("\n", $dump); + $this->lastIndex = count($this->lines)-1; + } + + public function process() + { + if ($this->processed) { + return; + } + + foreach($lines as $line) { + if (preg_match('|^\[([0-9A-Z]{3})\]\s+(.*)$|i', $line, $matches)) { + $currentTag = $this->addTag($matches[1], $matches[2]); + } else { + $currentTag->addLine($line); + } + } + } + + protected function addTag($tag, $line) + { + $tag = wsSWF2HTMLTag::factory($tag, $line); + $this->tags[] = $tag; + return $tag; + } + + public function getHTML() + { + $this->process(); + } + + public function getCSS() + { + $this->process(); + } +} + +class wsSWF2HTMLTag { + public static function factory($tag, $line) + { + if ($tag == wsSWF2HTML::FONT_TAG) { + return new wsSWF2HTMLFont($line); + } else if ($tag == wsSWF2HTML::TEXT_TAG) { + return new wsSWF2HTMLParagraph($line); + } else { + return new wsSWF2HTMLTag($line); + } + } + public $complete = false; + + public function __construct($line) + { + $this->addLine($line); + } + + public function addLine($line) + { + $line = trim($line); + return $line; + } +} + +class wsSWF2HTMLFont extends wsSWF2HTMLTag { + public $id = null; + public $name = null; + + public function __construct($line) + { + parent::__construct($line); + } + + public function addLine($line) + { + $line = parent::addLine($line); + $e = explode(':', $line); + if (count($e) < 2) { + return; + } + if ($e[0] == 'ID') { + $this->id = trim($e[1]); + $this->testComplete(); + } elseif ($e[0] == 'name') { + $ef = explode('-', trim($e[1])); + array_pop($ef); + array_pop($ef); + $this->name = implode('-', $ef); + $this->testComplete(); + } + } + + protected function testComplete() + { + $this->complete = !is_null($this->id) && !is_null($this->name); + } +} + +class wsSWF2HTMLParagraph extends wsSWF2HTMLTag { + public $matrix; + public $textes = array(); + + public function __construct($line) + { + $this->matrix = new wsSWF2HTMLMatrix(); + parent::__construct($line); + } + + public function addLine($line) + { + $line = parent::addLine($line); + if (substr($line, 0, 1) == '|') { + if (preg_match('|^\|\s([0-9.]*)\s([0-9.]*)\s([0-9.]*)$|i', $line, $m)) { + if (is_null($this->matrix->a)) { + $this->matrix->a = parseFloat($m[1]); + $this->matrix->c = parseFloat($m[2]); + $this->matrix->tx = parseFloat($m[3]); + } else { + $this->matrix->b = parseFloat($m[1]); + $this->matrix->d = parseFloat($m[2]); + $this->matrix->ty = parseFloat($m[3]); + } + } + } else if (substr($line, 0, 1) == '<') { + $text = new wsSWF2HTMLText($line); + if ($text->valid) { + $this->textes[] = $text; + } + } + } +} + +class wsSWF2HTMLText { + public $x; + public $y; + public $color; + public $font; + public $size; + public $text; + + public $valid = false; + public function __construct($line) + { + if (preg_match('|^\<\d+ glyphs in font (\d+) size (\d+), color (#[0-9a-f]+) at ([0-9.]+),([0-9.]+)\>\s(.*)|i', $line, $matches)) { + $this->font = intval($matches[1]); + $this->size = intval($matches[2]); + $this->color = $matches[3]; + $this->x = floatval($matches[4]); + $this->y = floatval($matches[5]); + $this->text = $matches[6]; + $this->valid = true; + } else { + $this->valid = false; + } + } +} + +class wsSWF2HTMLMatrix { + public $a = null; + public $b = null; + public $c = null; + public $d = null; + public $tx = null; + public $ty = null; +} + +?> \ No newline at end of file diff --git a/inc/ws/_common.php b/inc/ws/_common.php index c8c7ba435..a4f1758c4 100644 --- a/inc/ws/_common.php +++ b/inc/ws/_common.php @@ -3,6 +3,7 @@ require_once(dirname(__FILE__) . '/Metier/_common.php'); require_once(dirname(__FILE__) . '/Controlleur/_common.php'); require_once(dirname(__FILE__) . '/DAO/_common.php'); +require_once(dirname(__FILE__) . '/Util/_common.php'); $GLOBALS['ajaxClasses'][] = 'wsAjax'; -- 2.39.5