From e035c1352d58ad9593e5f7381b09a26527983fcf Mon Sep 17 00:00:00 2001 From: "vincent@cubedesigners.com" Date: Mon, 4 Apr 2011 06:37:03 +0000 Subject: [PATCH] --- .htaccess | 78 ++++++++++++++++------------- inc/ws/Metier/class.ws.document.php | 5 +- inc/ws/Util/class.ws.swf2html.php | 78 ++++++++++++++++++++--------- testSWF2HTML.php | 12 +++++ 4 files changed, 112 insertions(+), 61 deletions(-) create mode 100644 testSWF2HTML.php diff --git a/.htaccess b/.htaccess index d861e72a2..f54024048 100644 --- a/.htaccess +++ b/.htaccess @@ -1,40 +1,46 @@ Options +FollowSymlinks -RewriteEngine on -RewriteBase / +#Charset +AddDefaultCharset UTF-8 +AddCharset UTF-8 log # Static -ExpiresActive On -ExpiresDefault "modification plus 1 month" -#RequestHeader edit "If-None-Match" "^(.*)-gzip$" "$1" -#Header edit "ETag" "^(.*[^g][^z][^i][^p])$" "$1-gzip" - -# Favicon -RewriteCond %{HTTP_HOST} cubedesigners -RewriteRule ^favicon.ico$ images/extranet/favicon.ico [L] - -RewriteCond %{HTTP_HOST} fluidbook -RewriteRule ^favicon.ico$ images/ws/favicon.ico [L] - -# Skip -RewriteRule ^phpMyAdmin - [L] -#RewriteRule ^books - [L] -#RewriteRule ^docs - [L] - -RewriteRule ^ajax/supprimeFichier/([0-9]+)/(.*)$ index.php/ajax/supprimeFichier/$1/$2 [L] -RewriteRule ^telecharger/([0-9]+)/(.*)$ index.php/telecharger/$1/$2 [L] -RewriteRule ^([-_a-zA-Z0-9/]+)$ index.php/$1 [L] - -RewriteRule ^viewer/([0-9]+)_([0-9a-fA-F]+)_([0-9]+)/index.html$ viewer/$1_$2_$3/index [L] -RewriteRule ^viewer/([0-9]+)_([0-9a-fA-F]+)_([0-9]+)/index.swf$ fluidbook/compile/index.swf [L] -RewriteRule ^viewer/([0-9]+)_([0-9a-fA-F]+)_([0-9]+)/player.swf$ fluidbook/compile/player.swf [L] -RewriteRule ^viewer/([0-9]+)_([0-9a-fA-F]+)_([0-9]+)/(.+)$ fluidbook/books/final/$1/$4 [L] - -RewriteRule ^vieweru/([0-9]+)_([0-9a-fA-F]+)_([0-9]+)/index.html$ vieweru/$1_$2_$3/index [L] -RewriteRule ^vieweru/([0-9]+)_([0-9a-fA-F]+)_([0-9]+)/index.swf$ fluidbook/compile/_unprotected/index.swf [L] -RewriteRule ^vieweru/([0-9]+)_([0-9a-fA-F]+)_([0-9]+)/player.swf$ fluidbook/compile/_unprotected/player.swf [L] -RewriteRule ^vieweru/([0-9]+)_([0-9a-fA-F]+)_([0-9]+)/(.+)$ fluidbook/books/final/$1/$4 [L] - -RewriteRule ^viewerp/([0-9]+)_([0-9a-fA-F]+)_([0-9]+)/index.html$ viewerp/$1_$2_$3/index [L] -RewriteRule ^viewerp/([0-9]+)_([0-9a-fA-F]+)_([0-9]+)/index.swf$ fluidbook/compile/_standalone/player.swf [L] -RewriteRule ^viewerp/([0-9]+)_([0-9a-fA-F]+)_([0-9]+)/(.+)$ fluidbook/books/final/$1/$4 [L] \ No newline at end of file + + ExpiresActive On + ExpiresDefault "modification plus 1 month" + + + + RewriteEngine on + RewriteBase / + + # Favicon + RewriteCond %{HTTP_HOST} cubedesigners + RewriteRule ^favicon.ico$ images/extranet/favicon.ico [L] + + RewriteCond %{HTTP_HOST} fluidbook + RewriteRule ^favicon.ico$ images/ws/favicon.ico [L] + + # Skip + RewriteRule ^phpMyAdmin - [L] + #RewriteRule ^books - [L] + #RewriteRule ^docs - [L] + + RewriteRule ^ajax/supprimeFichier/([0-9]+)/(.*)$ index.php/ajax/supprimeFichier/$1/$2 [L] + RewriteRule ^telecharger/([0-9]+)/(.*)$ index.php/telecharger/$1/$2 [L] + RewriteRule ^([-_a-zA-Z0-9/]+)$ index.php/$1 [L] + + RewriteRule ^viewer/([0-9]+)_([0-9a-fA-F]+)_([0-9]+)/index.html$ viewer/$1_$2_$3/index [L] + RewriteRule ^viewer/([0-9]+)_([0-9a-fA-F]+)_([0-9]+)/index.swf$ fluidbook/compile/index.swf [L] + RewriteRule ^viewer/([0-9]+)_([0-9a-fA-F]+)_([0-9]+)/player.swf$ fluidbook/compile/player.swf [L] + RewriteRule ^viewer/([0-9]+)_([0-9a-fA-F]+)_([0-9]+)/(.+)$ fluidbook/books/final/$1/$4 [L] + + RewriteRule ^vieweru/([0-9]+)_([0-9a-fA-F]+)_([0-9]+)/index.html$ vieweru/$1_$2_$3/index [L] + RewriteRule ^vieweru/([0-9]+)_([0-9a-fA-F]+)_([0-9]+)/index.swf$ fluidbook/compile/_unprotected/index.swf [L] + RewriteRule ^vieweru/([0-9]+)_([0-9a-fA-F]+)_([0-9]+)/player.swf$ fluidbook/compile/_unprotected/player.swf [L] + RewriteRule ^vieweru/([0-9]+)_([0-9a-fA-F]+)_([0-9]+)/(.+)$ fluidbook/books/final/$1/$4 [L] + + RewriteRule ^viewerp/([0-9]+)_([0-9a-fA-F]+)_([0-9]+)/index.html$ viewerp/$1_$2_$3/index [L] + RewriteRule ^viewerp/([0-9]+)_([0-9a-fA-F]+)_([0-9]+)/index.swf$ fluidbook/compile/_standalone/player.swf [L] + RewriteRule ^viewerp/([0-9]+)_([0-9a-fA-F]+)_([0-9]+)/(.+)$ fluidbook/books/final/$1/$4 [L] + \ 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 33d947641..1b1082a8a 100644 --- a/inc/ws/Metier/class.ws.document.php +++ b/inc/ws/Metier/class.ws.document.php @@ -68,7 +68,7 @@ class wsDocument extends cubeMetier { } $this->cropped = $this->out . 'crop.pdf'; $this->uncropped = $this->out . 'uncrop.pdf'; - $this->common_log_pointer = fopen($this->log . '/commons.log', 'a'); + $this->common_log_pointer = fopen($this->log . '/commons.log', 'ab'); $this->pages_log_pointers = array(); if (is_null($this->conversionInfos)) { @@ -649,6 +649,7 @@ class wsDocument extends cubeMetier { { $swfdump = new cubeCommandLine('swfdump', null, true); $swfdump->setPath(CONVERTER_PATH); + $swfdump->setLang('en_US.UTF-8'); $swfdump->setArg('t'); $swfdump->setArg('p'); $swfdump->setArg('F'); @@ -857,7 +858,7 @@ disablelinks Disable links. if (isset($this->pages_log_pointers[$page]) && is_resource($this->pages_log_pointers[$page])) { $pointer = $this->pages_log_pointers[$page]; } else { - $pointer = fopen($this->log . '/p' . $page . '.log', 'w'); + $pointer = fopen($this->log . '/p' . $page . '.log', 'wb'); $this->pages_log_pointers[$page] = $pointer; } } diff --git a/inc/ws/Util/class.ws.swf2html.php b/inc/ws/Util/class.ws.swf2html.php index 42ed1c330..e97a47d80 100644 --- a/inc/ws/Util/class.ws.swf2html.php +++ b/inc/ws/Util/class.ws.swf2html.php @@ -5,6 +5,7 @@ class wsSWF2HTML { public $lines; public $tags = array(); + public $fonts = array(); protected $currentTag; protected $processed = false; @@ -22,6 +23,8 @@ class wsSWF2HTML { foreach($this->lines as $line) { if (preg_match('|^\[([0-9A-Z]{3})\]\s+(.*)$|i', $line, $matches)) { + $this->rangeCurrentTag(); + $this->currentTag = $this->addTag($matches[1], $matches[2]); } elseif (!is_null($this->currentTag)) { $this->currentTag->addLine($line); @@ -31,9 +34,20 @@ class wsSWF2HTML { $this->lines = null; } + protected function rangeCurrentTag() + { + if (is_null($this->currentTag)) { + return; + } + + if ($this->currentTag instanceof wsSWF2HTMLFont) { + $this->fonts[$this->currentTag->id] = $this->currentTag; + } + } + protected function addTag($tag, $line) { - $tag = wsSWF2HTMLTag::factory($tag, $line); + $tag = wsSWF2HTMLTag::factory($tag, $line, $this); if (!is_null($tag)) { $this->tags[] = $tag; } @@ -52,20 +66,22 @@ class wsSWF2HTML { } class wsSWF2HTMLTag { - public static function factory($tag, $line) + public static function factory($tag, $line, &$converter) { if ($tag == wsSWF2HTML::FONT_TAG) { - return new wsSWF2HTMLFont($line); + return new wsSWF2HTMLFont($line, $converter); } else if ($tag == wsSWF2HTML::TEXT_TAG) { - return new wsSWF2HTMLParagraph($line); + return new wsSWF2HTMLParagraph($line, $converter); } else { return null; } } public $complete = false; + public $converter; - public function __construct($line) + public function __construct($line, &$converter) { + $this->converter = $converter; $this->addLine($line); } @@ -78,34 +94,41 @@ class wsSWF2HTMLTag { class wsSWF2HTMLFont extends wsSWF2HTMLTag { public $id = null; public $name = null; + public $chars = array(); - public function __construct($line) + public function __construct($line, &$converter) { - parent::__construct($line); + parent::__construct($line, $converter); } 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(); + } else if (substr($e[0], 0, 2) == '==') { + fb($line); + if (preg_match('|== Glyph \d+: advance=\d+ encoding=(\d+) \'(.*)\' ==|i', $line, $m)) { + $this->addChar($m[1], $m[2]); + } } } - protected function testComplete() + public function addChar($encoding, $char) { - $this->complete = !is_null($this->id) && !is_null($this->name); + $e = cubeText::uchr($encoding); + $c = $char; + if ($e == $c) { + return; + } + $this->chars[$c] = $e; } } @@ -113,17 +136,17 @@ class wsSWF2HTMLParagraph extends wsSWF2HTMLTag { public $matrix; public $textes = array(); - public function __construct($line) + public function __construct($line, &$converter) { + parent::__construct($line, $converter); $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 (preg_match('|\|\s+([0-9.-]+)\s+([0-9.-]+)\s+([0-9.-]+)|i', $line, $m)) { if (is_null($this->matrix->a)) { $this->matrix->a = floatval($m[1]); $this->matrix->c = floatval($m[2]); @@ -133,11 +156,9 @@ class wsSWF2HTMLParagraph extends wsSWF2HTMLTag { $this->matrix->d = floatval($m[2]); $this->matrix->ty = floatval($m[3]); } - }else{ - fb($line); } } else if (substr($line, 0, 1) == '<') { - $text = new wsSWF2HTMLText($line); + $text = new wsSWF2HTMLText($line, $this->converter); if ($text->valid) { $this->textes[] = $text; } @@ -146,29 +167,40 @@ class wsSWF2HTMLParagraph extends wsSWF2HTMLTag { } class wsSWF2HTMLText { + public $converter; + public $x; public $y; public $color; public $font; public $size; + public $origText; public $text; + public $readableText; public $valid = false; - public function __construct($line) + public function __construct($line, &$converter) { + $this->converter = $converter; if (preg_match('|^\<\s?\d+ glyphs in font (\d+) size (\d+), color (#[0-9a-f]+) at ([0-9.-]+),([0-9.-]+)\>\s(.*)|ui', $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->origText=$matches[6]; + $this->text = preg_replace_callback('|\\\\x([0-9a-f]{2})|i', array($this, 'replaceUnicode') , $matches[6]); + $this->readableText = strtr($this->text, $this->converter->fonts[$this->font]->chars); $this->valid = true; } else { $this->valid = false; - fb($line,'invalid text'); } } + + protected function replaceUnicode($m) + { + return cubeText::uchr(hexdec($m[1])); + } } class wsSWF2HTMLMatrix { diff --git a/testSWF2HTML.php b/testSWF2HTML.php new file mode 100644 index 000000000..16b62fc03 --- /dev/null +++ b/testSWF2HTML.php @@ -0,0 +1,12 @@ +process(); + +echo '
';
+print_r($swf2html);
+echo '
'; +?> \ No newline at end of file -- 2.39.5