powered by nequal
Home » IO_SWF » Timeline » 2879

Changeset 2879 -- 2012-02-20 23:15:02

Author
よや
Comment
package released (2.1.8-stable) (@yoya)

Diffs

IO_SWF/tags/2.1.8-stable-20120220231502/sample/swflistaction.php

@@ -0,0 +1,61 @@
+<?php
+
+require 'IO/SWF/Editor.php';
+
+if ($argc != 2) {
+    echo "Usage: php swflistaction.php <swf_file>\n";
+    echo "ex) php swflistaction.php test.swf\n";
+    exit(1);
+}
+
+assert(is_readable($argv[1]));
+
+$swfdata = file_get_contents($argv[1]);
+
+$swf = new IO_SWF_Editor();
+
+$swf->parse($swfdata);
+
+$currentFrame = 1;
+
+foreach ($swf->_tags as $idx => $tag) {
+    $tag_code = $tag->code;
+    if ($tag_code == 1) { // ShowFrame
+        $currentFrame++;
+        continue;
+    }
+    if (($tag_code == 12) || ($tag_code == 59)) { // DoAction, DoInitAction
+        if ($tag->parseTagContent() === false) {
+            echo "Unknown Action Tag\n";
+            exit(1);
+        }
+        $action_num = count($tag->tag->_actions);
+        echo "0:$currentFrame => $action_num\n";
+    }
+    if ($tag_code == 39) { // DefineSprite
+        if ($tag->parseTagContent() === false) {
+            echo "Unknown DefineSprite!!!\n";
+            exit(1);
+        }
+        $spriteId = $tag->tag->_spriteId;
+        $currentFrameInSprite = 1;
+        foreach ($tag->tag->_controlTags as $tag_in_sprite) {
+            $tag_code_in_sprite = $tag_in_sprite->code;
+            if ($tag_code_in_sprite == 1) { // ShowFrame
+                $currentFrameInSprite++;
+                continue;
+            }
+            if (($tag_code_in_sprite == 12) || ($tag_code_in_sprite == 59)) { // DoAction, DoInitAction
+                if ($tag_in_sprite->parseTagContent() === false) {
+                    echo "Unknown Action Tag\n";
+                    exit(1);
+                }
+                $action_num = count($tag_in_sprite->tag->_actions);
+                echo "$spriteId:$currentFrameInSprite => $action_num\n";
+            }
+        }
+    }
+
+}
+
+exit(0);
属性に変更があったパス: IO_SWF/tags/2.1.8-stable-20120220231502/sample/swflistaction.php
___________________________________________________________________
追加: svn:keywords
+ Id
追加: svn:eol-style
+ native

IO_SWF/tags/2.1.8-stable-20120220231502/sample/swfcopy.php

@@ -0,0 +1,22 @@
+<?php
+
+require 'IO/SWF.php';
+// require dirname(__FILE__).'/../IO/SWF.php';
+
+if ($argc != 2) {
+    echo "Usage: php swfcopy.php <swf_file>\n";
+    echo "ex) php swfdopy.php test.swf\n";
+    exit(1);
+}
+
+assert(is_readable($argv[1]));
+
+$swfdata = file_get_contents($argv[1]);
+
+$swf = new IO_SWF();
+
+$swf->parse($swfdata);
+
+echo $swf->build();
+
+exit(0);

IO_SWF/tags/2.1.8-stable-20120220231502/sample/swfgeteditstring.php

@@ -0,0 +1,22 @@
+<?php
+
+require_once 'IO/SWF/Editor.php';
+
+if ($argc != 3) {
+    echo "Usage: php swfgeteditstring.php <swf_file> <id>\n";
+    echo "ex) php swfgeteditstring.php test.swf 1\n";
+    echo "ex) php swfgeteditstring.php test.swf foo\n";
+    exit(1);
+}
+
+assert(is_readable($argv[1]));
+
+$swfdata = file_get_contents($argv[1]);
+$id = $argv[2];
+
+$swf = new IO_SWF_Editor();
+$swf->parse($swfdata);
+
+echo $swf->getEditString($id) . "\n";
+
+exit(0);
属性に変更があったパス: IO_SWF/tags/2.1.8-stable-20120220231502/sample/swfgeteditstring.php
___________________________________________________________________
追加: svn:keywords
+ Id
追加: svn:eol-style
+ native

IO_SWF/tags/2.1.8-stable-20120220231502/sample/swfselectbycids.php

@@ -0,0 +1,28 @@
+<?php
+
+require_once 'IO/SWF/Editor.php';
+
+if (($argc < 3)) {
+    echo "Usage: php swfselectbycids.php <swf_file> <cid> [<cid2> [...]]\n";
+    echo "ex) php swfselectbycids.php negimiku2_mcnest.swf 1\n";
+    exit(1);
+}
+
+assert(is_readable($argv[1]));
+assert(isset($argv[2]));
+
+$swfdata = file_get_contents($argv[1]);
+$cids = array_slice($argv, 2);
+
+$swf = new IO_SWF_Editor();
+$swf->parse($swfdata);
+
+$ret = $swf->selectByCIDs($cids);
+if ($ret === false) {
+    echo "selectByCIDs(Array(".join(',', $cids).")) failed\n";
+    exit(1);
+}
+
+echo $ret;
+
+exit(0);
属性に変更があったパス: IO_SWF/tags/2.1.8-stable-20120220231502/sample/swfselectbycids.php
___________________________________________________________________
追加: svn:keywords
+ Id
追加: svn:eol-style
+ native

IO_SWF/tags/2.1.8-stable-20120220231502/sample/swfwireframe.php

@@ -0,0 +1,77 @@
+<?php
+
+require 'IO/SWF/Editor.php';
+
+if ($argc != 2) {
+    echo "Usage: php swfwireframe.php <swf_file>\n";
+    echo "ex) php swfwireframe.php test.swf\n";
+    exit(1);
+}
+
+assert(is_readable($argv[1]));
+
+$swfdata = file_get_contents($argv[1]);
+
+$swf = new IO_SWF_Editor();
+
+$swf->parse($swfdata);
+
+$opts = array('Version' => $swf->_headers['Version']); // for parser
+foreach ($swf->_tags as $idx => &$tag) {
+    $tag_code = $tag->code;
+    if (($tag_code == 2) || ($tag_code == 22) || ($tag_code == 32)) { // Shape
+        $opts['tagCode'] = $tag_code;
+        if ($tag->parseTagContent($opts) === false) {
+            throw new IO_SWF_Exception("Can't parseTagContent tag_code=$tag_code");
+        }
+        $transTable = swfwireframe($tag->tag->_fillStyles, $tag->tag->_lineStyles);
+        foreach ($tag->tag->_shapeRecords as &$record) {
+            if ($record['TypeFlag'] == 0 && (isset($record['EndOfShape']) === false)) {
+                if (isset($record['FillStyles'])) {
+                    $transTable = swfwireframe($record['FillStyles'], $record['LineStyles']);
+                }
+                if ($record['LineStyle'] == 0) {
+                    if ($record['FillStyle0']) {
+                        $record['LineStyle'] = $transTable[$record['FillStyle0']];
+                    } else if ($record['FillStyle1']) {
+                        $record['LineStyle'] = $transTable[$record['FillStyle1']];
+                    } else {
+                        $record['LineStyle'] = 1; // XXX
+                    }
+                    $record['FillStyle0'] = 0;
+                    $record['FillStyle1'] = 0;
+                }
+            }
+        }
+        $tag->content = null;
+    }
+}
+
+function swfwireframe(&$fillStyles, &$lineStyles) {
+    $transTable = array();
+    $lineStylesIdx = count($lineStyles);
+    foreach ($fillStyles as $idx => $fillStyle) {
+        switch ($fillStyle['FillStyleType']) {
+          case 0: //fill
+            $color = $fillStyle['Color'];
+            break;
+          default:
+            $color = array("Red"   => 128,
+                           "Green" => 128,
+                           "Blue"  => 128,
+                           "Alpha" => 255);
+            break;
+        }
+        $lineStyle = array("Width" => 2,
+                           "Color" => $color);
+        $lineStyles []= $lineStyle;
+        $transTable[$idx+1] = $lineStylesIdx+1; // 1 origin
+        $lineStylesIdx++;
+    }
+    $fillStyles = array();
+    return $transTable;
+}
+
+echo $swf->build();
+
+exit(0);
属性に変更があったパス: IO_SWF/tags/2.1.8-stable-20120220231502/sample/swfwireframe.php
___________________________________________________________________
追加: svn:keywords
+ Id
追加: svn:eol-style
+ native

IO_SWF/tags/2.1.8-stable-20120220231502/sample/swfcountshapeedges.php

@@ -0,0 +1,28 @@
+<?php
+
+require 'IO/SWF/Editor.php';
+// require dirname(__FILE__).'/../IO/SWF/Editor.php';
+
+if ($argc != 2) {
+    echo "Usage: php swfcountshapeedges.php <swf_file>\n";
+    echo "ex) php swfcountshapeedges.php test.swf\n";
+    exit(1);
+}
+
+$swfdata = file_get_contents($argv[1]);
+
+$swf = new IO_SWF_Editor();
+
+$swf->parse($swfdata);
+
+$count_table = $swf->countShapeEdges();
+if ($count_table === false) {
+    printf("countShapeEdges return false\n");
+    exit(1);
+}
+
+foreach ($count_table as $shape_id => $count) {
+   echo "shape_id: $shape_id => edges_count: $count\n";
+}
+
+exit(0);
属性に変更があったパス: IO_SWF/tags/2.1.8-stable-20120220231502/sample/swfcountshapeedges.php
___________________________________________________________________
追加: svn:keywords
+ Id
追加: svn:eol-style
+ native

IO_SWF/tags/2.1.8-stable-20120220231502/sample/swfsetactionvariables.php

@@ -0,0 +1,28 @@
+<?php
+
+require 'IO/SWF/Editor.php';
+// require dirname(__FILE__).'/../IO/SWF/Editor.php';
+
+if ($argc != 4) {
+    fprintf(STDERR, "Usage: php swfsetactiovaribles.phpp <swf_file> <from_str> <to_str>\n");
+    fprintf(STDERR, "ex) php swfactionvariables.php test.swf foo baa\n");
+    exit(1);
+}
+
+assert(is_readable($argv[1]));
+assert(isset($argv[2]));
+assert(isset($argv[3]));
+
+$swfdata = file_get_contents($argv[1]);
+$from_str = $argv[2];
+$to_str = $argv[3];
+
+$swf = new IO_SWF_Editor();
+
+$swf->parse($swfdata);
+
+$swf->setActionVariables($from_str, $to_str);
+
+echo $swf->build();
+
+exit(0);

IO_SWF/tags/2.1.8-stable-20120220231502/sample/swfreplacemovieclip.php

@@ -0,0 +1,31 @@
+<?php
+
+require_once 'IO/SWF/Editor.php';
+// require dirname(__FILE__).'/../IO/SWF/Editor.php';
+
+if (($argc != 4)) {
+    echo "Usage: php swfreplacemovieclip.php <swf_file> <target_path> <mc_swf_file>\n";
+    echo "ex) php swfreplacemovieclip.php negimiku2_mcnest.swf miku/negi saitama3.swf\n";
+    exit(1);
+}
+
+assert(is_readable($argv[1]));
+assert(isset($argv[2]));
+assert(is_readable($argv[3]));
+
+$swfdata = file_get_contents($argv[1]);
+$target_path = $argv[2];
+$mc_swfdata = file_get_contents($argv[3]);
+
+$swf = new IO_SWF_Editor();
+$swf->parse($swfdata);
+
+$ret = $swf->replaceMovieClip($target_path, $mc_swfdata);
+if ($ret === false) {
+    echo "replaceMovieClip($target_path, mc_swfdata) failed\n";;
+    exit(1);
+}
+
+echo $swf->build();
+
+exit(0);

IO_SWF/tags/2.1.8-stable-20120220231502/sample/swfreplaceactionstrings.php

@@ -0,0 +1,28 @@
+<?php
+
+require 'IO/SWF/Editor.php';
+// require dirname(__FILE__).'/../IO/SWF/Editor.php';
+
+if ($argc != 4) {
+    fprintf(STDERR, "Usage: php swfreplaceactionstrings.php <swf_file> <from_str> <to_str>\n");
+    fprintf(STDERR, "ex) php swfreplaceactionstrings.php test.swf foo baa\n");
+    exit(1);
+}
+
+assert(is_readable($argv[1]));
+assert(isset($argv[2]));
+assert(isset($argv[3]));
+
+$swfdata = file_get_contents($argv[1]);
+$from_str = $argv[2];
+$to_str = $argv[3];
+
+$swf = new IO_SWF_Editor();
+
+$swf->parse($swfdata);
+
+$swf->replaceActionStrings($from_str, $to_str);
+
+echo $swf->build();
+
+exit(0);
属性に変更があったパス: IO_SWF/tags/2.1.8-stable-20120220231502/sample/swfreplaceactionstrings.php
___________________________________________________________________
追加: svn:mergeinfo

IO_SWF/tags/2.1.8-stable-20120220231502/sample/swflistmovieclip.php

@@ -0,0 +1,42 @@
+<?php
+
+require 'IO/SWF/Editor.php';
+// require dirname(__FILE__).'/../IO/SWF.php';
+
+$options = getopt("f:h");
+
+if ($argc != 2) {
+    echo "Usage: php swflistmovieclip.php <swf_file>\n";
+    exit(1);
+}
+
+$swfdata = file_get_contents($argv[1]);
+
+$swf = new IO_SWF_Editor();
+
+$swf->parse($swfdata);
+
+$mc_list = $swf->listMovieClip();
+if ($mc_list === false) {
+    echo "mc_list === false\n";
+    exit(1);
+}
+
+foreach ($mc_list as $spriteId => $mc) {
+    echo "SpriteId:$spriteId FrameCount:{$mc['FrameCount']} TagCount:{$mc['TagCount']}";
+    if (isset($mc['name'])) {
+            echo ' name:'.$mc['name'];
+    }
+    echo PHP_EOL;
+    if (isset($mc['path_list'])) {
+        foreach ($mc['path_list'] as $path) {
+            echo "\t".$path['path'];
+            if (count($path['parent_cids']) > 0) {
+                echo ' ('.implode(',', $path['parent_cids']).')';
+            }
+            echo PHP_EOL;
+        }
+    }
+}
+
+exit(0);
属性に変更があったパス: IO_SWF/tags/2.1.8-stable-20120220231502/sample/swflistmovieclip.php
___________________________________________________________________
追加: svn:keywords
+ Id
追加: svn:eol-style
+ native

IO_SWF/tags/2.1.8-stable-20120220231502/sample/swfactioneditor.php

@@ -0,0 +1,30 @@
+<?php
+
+require 'IO/SWF.php';
+// require dirname(__FILE__).'/../IO/SWF/ActionEditor.php';
+
+if ($argc != 2) {
+    echo "Usage: php swfactioneditor.php <swf_file>\n";
+    echo "ex) php swfactioneditor.php test.swf\n";
+    exit(1);
+}
+
+assert(is_readable($argv[1]));
+
+$swfdata = file_get_contents($argv[1]);
+$swf = new IO_SWF_ActionEditor();
+$swf->parse($swfdata);
+
+$opts = array();
+$swf->parseAllTagContent($opts);
+
+// Insert simple trace at main time line, frame 1, line 1.
+$swf->insertSimpleTrace(0, 1, 1, "(^_^)/ Hello, world.");
+
+// Insert trace which shows value of i at sprite1, frame 2, line 4.
+$swf->insertVarDumpTrace(1, 2, 4, "i");
+
+$swf->rebuild();
+echo $swf->build();
+
+exit(0);

IO_SWF/tags/2.1.8-stable-20120220231502/sample/swfrebuild.php

@@ -0,0 +1,23 @@
+<?php
+
+require 'IO/SWF/Editor.php';
+
+if ($argc != 2) {
+    echo "Usage: php swfrebuild.php <swf_file>\n";
+    echo "ex) php swfrebuild.php test.swf\n";
+    exit(1);
+}
+
+assert(is_readable($argv[1]));
+
+$swfdata = file_get_contents($argv[1]);
+
+$swf = new IO_SWF_Editor();
+
+$swf->parse($swfdata);
+
+$swf->rebuild();
+
+echo $swf->build();
+
+exit(0);

IO_SWF/tags/2.1.8-stable-20120220231502/sample/get_bitmapsize.php

@@ -0,0 +1,16 @@
+<?php
+
+require_once 'IO/SWF/Bitmap.php';
+// require_once './IO/SWF/Bitmap.php';
+
+if ($argc != 2) {
+    echo "Usage: php get_bitmapsize.php <bitmap_file>\n";
+    echo "ex) php get_bitmapsize.php test.jpg\n";
+    exit(1);
+}
+
+$bitmap_data = file_get_contents($argv[1]);
+
+$ret = IO_SWF_Bitmap::get_bitmapsize($bitmap_data);
+
+echo "width:{$ret['width']} height:{$ret['height']}\n";

IO_SWF/tags/2.1.8-stable-20120220231502/sample/swfgetmovieclip.php

@@ -0,0 +1,28 @@
+<?php
+
+require_once 'IO/SWF/Editor.php';
+
+if (($argc != 3)) {
+    echo "Usage: php swfgetmovieclip.php <swf_file> <target_path>\n";
+    echo "ex) php swfgetmovieclip.php negimiku2_mcnest.swf miku/negi\n";
+    exit(1);
+}
+
+assert(is_readable($argv[1]));
+assert(isset($argv[2]));
+
+$swfdata = file_get_contents($argv[1]);
+$target_path = $argv[2];
+
+$swf = new IO_SWF_Editor();
+$swf->parse($swfdata);
+
+$ret = $swf->getMovieClip($target_path);
+if ($ret === false) {
+    echo "getMovieClip($target_path) failed\n";;
+    exit(1);
+}
+
+echo $ret;
+
+exit(0);
属性に変更があったパス: IO_SWF/tags/2.1.8-stable-20120220231502/sample/swfgetmovieclip.php
___________________________________________________________________
追加: svn:keywords
+ Id
追加: svn:eol-style
+ native

IO_SWF/tags/2.1.8-stable-20120220231502/sample/swfheader.php

@@ -0,0 +1,57 @@
+<?php
+
+require 'IO/SWF/Editor.php';
+
+if ($argc < 2) {
+    echo "Usage: php swfheader.php <swf_file> [<key>=<vakue> [<key2>=<value2> [...]]]\n";
+    echo "ex) php swfheader.php test.swf\n";
+    echo "ex) php swfheader.php test.swf FrameRate=512\n";
+    exit(1);
+}
+
+assert(is_readable($argv[1]));
+
+$swfdata = file_get_contents($argv[1]);
+
+$swf = new IO_SWF_Editor();
+
+$swf->parse($swfdata);
+
+$headers = $swf->_headers;
+
+if ($argc == 2) {
+    echo "SWF Headers:\n";
+    foreach ($headers as $key => $value) {
+        if (is_array($value)) {
+            foreach ($value as $key2 => $value2) {
+                echo "   $key.$key2:$value2\n";
+            }
+        } else {
+            echo "   $key:$value\n";
+        }
+    }
+} else {
+    $params = array_slice($argv, 2);
+    foreach ($params as $param) {
+        list ($key, $value) = explode('=', $param);
+        $keys = explode('.', $key);
+        if (is_array($keys) && (count($keys) > 1)) {
+            list ($key1, $key2) = $keys;
+            if (array_key_exists($key2, $headers[$key1])) {
+                $swf->_headers[$key1][$key2] = $value;
+            } else {
+                echo "Header key not exists ($key)\n";
+                exit (1);
+            }
+        }
+        if (array_key_exists($key, $headers)) {
+            $swf->_headers[$key] = $value;
+        } else {
+            echo "Header key not exists ($key)\n";
+            exit (1);
+        }
+    }
+    echo $swf->build();
+}
+
+exit(0);
属性に変更があったパス: IO_SWF/tags/2.1.8-stable-20120220231502/sample/swfheader.php
___________________________________________________________________
追加: svn:keywords
+ Id
追加: svn:eol-style
+ native

IO_SWF/tags/2.1.8-stable-20120220231502/sample/swfconvlossless2pngjpeg.php

@@ -0,0 +1,62 @@
+<?php
+
+require 'IO/SWF/Editor.php';
+
+if ($argc != 2) {
+    echo "Usage: php swfconvlossless2pngjpeg.php <swf_file>\n";
+    echo "ex) php swfconvlossless2pngjpeg.php test.swf\n";
+    exit(1);
+}
+
+assert(is_readable($argv[1]));
+
+$swfdata = file_get_contents($argv[1]);
+
+$swf = new IO_SWF_Editor();
+
+$swf->parse($swfdata);
+
+foreach ($swf->_tags as &$tag) {
+    $tag_code = $tag->code;
+    if (($tag_code == 20) || // DefineBitsLossless
+        ($tag_code == 36)) { // DefineBitsLossless2
+        if ($tag->parseTagContent()) {
+            $cid = $tag->tag->_CharacterID;
+            $format = $tag->tag->_BitmapFormat;
+            $width =  $tag->tag->_BitmapWidth;
+            $height = $tag->tag->_BitmapHeight;
+            $lossless_bitmap_data = gzuncompress($tag->tag->_ZlibBitmapData);
+            if ($format == 3) {
+                $palette_num = $tag->tag->_BitmapColorTableSize;
+                if ($tag_code == 20) { // DefineBisLossless
+                    $palette_bytesize = 3 * $palette_num;
+                } else {
+                    $palette_bytesize = 4 * $palette_num;
+                }
+                $palette_data = substr($lossless_bitmap_data, 0, $palette_bytesize);
+                $lossless_bitmap_data = substr($lossless_bitmap_data, $palette_bytesize);
+            } else {
+                $palette_num = 0;
+                $palette_data = null;
+            }
+            $png_data = IO_SWF_Lossless::Lossless2PNG($tag_code, $format,
+                                                      $width, $height,
+                                                      $palette_num,
+                                                      $palette_data,
+                                                      $lossless_bitmap_data);
+            $jpeg_tag = new IO_SWF_Tag_Jpeg();
+            $jpeg_tag->code = 21; // DefineBitsJPEG2
+            $jpeg_tag->_CharacterID = $cid;
+            $jpeg_tag->_JPEGData = $png_data; // SWF8 spec
+
+            $tag->code = 21; // DefineBitsJPEG2
+            $tag->tag = $jpeg_tag;
+
+            $tag->content = null;
+        }
+    }
+}
+
+echo $swf->build();
+
+exit(0);
属性に変更があったパス: IO_SWF/tags/2.1.8-stable-20120220231502/sample/swfconvlossless2pngjpeg.php
___________________________________________________________________
追加: svn:keywords
+ Id
追加: svn:mergeinfo
追加: svn:eol-style
+ native

IO_SWF/tags/2.1.8-stable-20120220231502/sample/jpeg_dump.php

@@ -0,0 +1,34 @@
+<?php
+
+require_once 'IO/SWF/JPEG.php';
+
+function usage() {
+    echo "Usage: php jpeg_dump.php <dump|jpegtables|imagedata>".PHP_EOL;
+}
+
+if ($argc != 3) {
+    usage();
+    exit(1);
+}
+
+$jpegdata = file_get_contents($argv[2]);
+
+$jpeg = new IO_SWF_JPEG();
+$jpeg->input($jpegdata);
+
+switch($argv[1]) {
+  case 'dump':
+    $jpeg->dumpChunk();
+    break;
+  case 'jpegtables':
+    echo $jpeg->getEncodingTables();
+    break;
+  case 'imagedata':
+    echo $jpeg->getImageData();
+    break;
+  default:
+    usage();
+    exit(1);
+}
+
+exit(0);

IO_SWF/tags/2.1.8-stable-20120220231502/sample/swfdeleteaction.php

@@ -0,0 +1,43 @@
+<?php
+
+require 'IO/SWF/Editor.php';
+
+if ($argc != 2) {
+    echo "Usage: php swfdeleteaction.php <swf_file>\n";
+    echo "ex) php swfdeleteaction.php test.swf\n";
+    exit(1);
+}
+
+assert(is_readable($argv[1]));
+
+$swfdata = file_get_contents($argv[1]);
+
+$swf = new IO_SWF_Editor();
+
+$swf->parse($swfdata);
+
+foreach ($swf->_tags as $idx => &$tag) {
+    $tag_code = $tag->code;
+    if (($tag_code == 12) || ($tag_code == 59)) { // DoAction, DoInitAction
+        unset($swf->_tags[$idx]);
+    }
+    if ($tag_code == 39) { // DefineSprite
+        if ($tag->parseTagContent() === false) {
+            echo "Unknown DefineSprite!!!\n";
+            exit(1);
+        }
+        foreach ($tag->tag->_controlTags as $idx_in_sprite => &$tag_in_sprite) {
+            $tag_code_in_sprite = $tag_in_sprite->code;
+            // DoAction, DoInitAction
+            if (($tag_code_in_sprite == 12) || ($tag_code_in_sprite == 59)) {
+                unset($tag->tag->_controlTags->_tags[$idx_in_sprite]);
+                $tag_in_sprite->content = null;
+                $tag->content = null;
+            }
+        }
+    }
+}
+
+echo $swf->build();
+
+exit(0);
属性に変更があったパス: IO_SWF/tags/2.1.8-stable-20120220231502/sample/swfdeleteaction.php
___________________________________________________________________
追加: svn:keywords
+ Id
追加: svn:eol-style
+ native

IO_SWF/tags/2.1.8-stable-20120220231502/sample/swfdecompile.php

@@ -0,0 +1,28 @@
+<?php
+
+// require 'IO/SWF.php';
+require dirname(__FILE__).'/../IO/SWF/Decompiler.php';
+
+$options = getopt("f:h");
+
+if (is_readable($options['f']) === false) {
+    echo "Usage: php swfdecompile.php -f <swf_file> [-h]\n";
+    echo "ex) php swfdecompile.php -f test.swf -h \n";
+    exit(1);
+}
+
+$swfdata = file_get_contents($options['f']);
+
+$swf = new IO_SWF_Decompiler();
+
+$swf->parse($swfdata);
+
+$opts = array();
+if (isset($options['h'])) {
+    $opts['hexdump'] = true;
+}
+$opts['addlabel'] = true;
+
+$swf->dump($opts);
+
+exit(0);
属性に変更があったパス: IO_SWF/tags/2.1.8-stable-20120220231502/sample/swfdecompile.php
___________________________________________________________________
追加: svn:executable
+ *
追加: svn:keywords
+ Id
追加: svn:eol-style
+ native

IO_SWF/tags/2.1.8-stable-20120220231502/sample/swfdeformeshape.php

@@ -0,0 +1,26 @@
+<?php
+
+require 'IO/SWF/Editor.php';
+// require dirname(__FILE__).'/../IO/SWF/Editor.php';
+
+if ($argc != 3) {
+    fprintf(STDERR, "Usage: php swfdeformeshape.php <swf_file> <threshold>\n");
+    fprintf(STDERR, "ex) php swfdeformeshape.php test.swf 10 \n");
+    exit(1);
+}
+
+assert(is_readable($argv[1]));
+assert(is_numeric($argv[2]));
+
+$swfdata = file_get_contents($argv[1]);
+$threshold = $argv[2];
+
+$swf = new IO_SWF_Editor();
+
+$swf->parse($swfdata);
+
+$swf->deformeShape($threshold);
+
+echo $swf->build();
+
+exit(0);

IO_SWF/tags/2.1.8-stable-20120220231502/sample/swfreplacebitmapdata.php

@@ -0,0 +1,36 @@
+<?php
+
+require_once 'IO/SWF/Editor.php';
+// require dirname(__FILE__).'/../IO/SWF/Editor.php';
+
+if (($argc != 4) && ($argc != 5)) {
+    echo "Usage: php swfreplacebitmapdata.php <swf_file> <bitmap_id> <bitmap_file> [<alpha_file>]\n";
+    echo "ex) php swfreplacebitmapdata.php test.swf 1 test.jpg test.alpha\n";
+    echo "ex) php swfreplacebitmapdata.php test.swf 1 test.png\n";
+    echo "ex) php swfreplacebitmapdata.php test.swf 1 test.git\n";
+    exit(1);
+}
+
+assert(is_readable($argv[1]));
+assert(is_numeric($argv[2]));
+assert(is_readable($argv[3]));
+
+$swfdata = file_get_contents($argv[1]);
+$bitmap_id = (int) $argv[2];
+$bitmapdata = file_get_contents($argv[3]);
+if (isset($argv[4])) { // with jpeg alphadata
+    assert(is_readable($argv[4]));
+    $jpeg_alphadata = file_get_contents($argv[4]);
+} else {
+    $jpeg_alphadata = null;
+}
+
+$swf = new IO_SWF_Editor();
+$swf->parse($swfdata);
+
+// $swf->setShapeAdjustMode(IO_SWF_Editor::SHAPE_BITMAP_RECT_RESIZE);
+$ret = $swf->replaceBitmapData($bitmap_id, $bitmapdata, $jpeg_alphadata);
+
+echo $swf->build();
+
+exit(0);
属性に変更があったパス: IO_SWF/tags/2.1.8-stable-20120220231502/sample/swfreplacebitmapdata.php
___________________________________________________________________
追加: svn:mergeinfo

IO_SWF/tags/2.1.8-stable-20120220231502/sample/swfsetbgcolor.php

@@ -0,0 +1,27 @@
+<?php
+
+require 'IO/SWF/Editor.php';
+
+if ($argc != 5) {
+    echo "Usage: php swfsetbgcolor.php <swf_file> <red> <green> <blue>\n";
+    echo "ex) php swfsetbgcolor.php test.swf 0 0 255\n";
+    exit(1);
+}
+
+assert(is_readable($argv[1]));
+assert(is_numeric($argv[2]));
+assert(is_numeric($argv[3]));
+assert(is_numeric($argv[4]));
+
+$swfdata = file_get_contents($argv[1]);
+
+$swf = new IO_SWF_Editor();
+
+$swf->parse($swfdata);
+
+$color = pack('CCC', $argv[2], $argv[3], $argv[4]);
+$swf->replaceTagContent(9, $color);
+
+echo $swf->build();
+
+exit(0);

IO_SWF/tags/2.1.8-stable-20120220231502/sample/swfdump.php

@@ -0,0 +1,30 @@
+<?php
+
+require 'IO/SWF.php';
+// require dirname(__FILE__).'/../IO/SWF.php';
+
+$options = getopt("f:hl");
+
+if (is_readable($options['f']) === false) {
+    echo "Usage: php swfdump.php -f <swf_file> [-h]\n";
+    echo "ex) php swfdump.php -f test.swf -h \n";
+    exit(1);
+}
+
+$swfdata = file_get_contents($options['f']);
+
+$swf = new IO_SWF();
+
+$swf->parse($swfdata);
+
+$opts = array();
+if (isset($options['h'])) {
+    $opts['hexdump'] = true;
+}
+if (isset($options['l'])) {
+    $opts['addlabel'] = true;
+}
+
+$swf->dump($opts);
+
+exit(0);

IO_SWF/tags/2.1.8-stable-20120220231502/sample/swfframerate.php

@@ -0,0 +1,26 @@
+<?php
+
+require 'IO/SWF/Editor.php';
+
+if (($argc != 2) && ($argc != 3)) {
+    echo "Usage: php swfframerate.php <swf_file> [<frame_rate>]\n";
+    echo "ex) php swfframerate.php test.swf 12\n";
+    exit(1);
+}
+
+assert(is_readable($argv[1]));
+
+$swfdata = file_get_contents($argv[1]);
+
+$swf = new IO_SWF_Editor();
+
+$swf->parse($swfdata);
+
+if ($argc === 2) {
+    echo "FrameRate:".($swf->_headers['FrameRate'] / 0x100).PHP_EOL;
+} else {
+    $swf->_headers['FrameRate'] = $argv[2] * 0x100;
+    echo $swf->build();
+}
+
+exit(0);
属性に変更があったパス: IO_SWF/tags/2.1.8-stable-20120220231502/sample/swfframerate.php
___________________________________________________________________
追加: svn:keywords
+ Id
追加: svn:eol-style
+ native

IO_SWF/tags/2.1.8-stable-20120220231502/sample/swfreplaceeditstring.php

@@ -0,0 +1,31 @@
+<?php
+
+require_once 'IO/SWF/Editor.php';
+// require dirname(__FILE__).'/../IO/SWF/Editor.php';
+
+if ($argc != 4) {
+    echo "Usage: php swfreplaceeditstring.php <swf_file> <id> <initial_text>\n";
+    echo "ex) php swfreplaceeditstring.php test.swf 1 baa\n";
+    echo "ex) php swfreplaceeditstring.php test.swf foo baa\n";
+    exit(1);
+}
+
+assert(is_readable($argv[1]));
+
+$swfdata = file_get_contents($argv[1]);
+$id = $argv[2];
+$initialText = $argv[3];
+
+$swf = new IO_SWF_Editor();
+$swf->parse($swfdata);
+
+$ret = $swf->replaceEditString($id, $initialText);
+
+if ($ret === false) {
+    echo "failed to replaceEditString($id, $initialText)\n";
+    exit(1);
+}
+
+echo $swf->build();
+
+exit(0);
属性に変更があったパス: IO_SWF/tags/2.1.8-stable-20120220231502/sample/swfreplaceeditstring.php
___________________________________________________________________
追加: svn:mergeinfo

IO_SWF/tags/2.1.8-stable-20120220231502/IO/SWF/Former.php

@@ -0,0 +1,32 @@
+<?php
+
+/*
+ * 2010/8/12- (c) yoya@awm.jp
+ */
+
+require_once dirname(__FILE__).'/../SWF.php';
+
+class IO_SWF_Former extends IO_SWF {
+    // var $_headers = array(); // protected
+    // var $_tags = array();    // protected
+
+    function form() {
+        foreach ($this->_tags as $idx => $tag) {
+            switch ($tag['Code']) {
+                case 26: // PlaceObject2
+                    $this->_form_26($tag);
+                    break;
+            }
+        }
+    }
+    function _form_26($tag) { // PlaceObject2
+        $reader = new IO_Bit();
+        $reader->input($tab['Content']);
+        $placeFlag = $reader->getUI8();
+        $depth = $reader->getUI16LE();
+        if ($placeFlag & 0x02) {
+            $characterId = $reader->getUI16LE();
+        }
+        //
+    }
+}

IO_SWF/tags/2.1.8-stable-20120220231502/IO/SWF/Tag.php

@@ -0,0 +1,336 @@
+<?php
+
+require_once dirname(__FILE__).'/../SWF.php';
+require_once dirname(__FILE__).'/../SWF/Tag/Shape.php';
+
+class IO_SWF_Tag {
+    var $swfInfo;
+    var $code = 0;
+    var $content = null;
+    var $tag = null;
+    var $byte_offset, $byte_size;
+    function __construct($swfInfo) {
+        $this->swfInfo = $swfInfo;
+    }
+    function getTagInfo($tagCode, $label) {
+        static $tagMap = array(
+         // code => array(name , klass)
+             0 => array('name' => 'End'),
+             1 => array('name' => 'ShowFrame'),
+             2 => array('name' => 'DefineShape',  'klass' => 'Shape'),
+//             3 => array('name' => 'FreeCharacter'), // ???
+             4 => array('name' => 'PlaceObject', 'klass' => 'Place'),
+             5 => array('name' => 'RemoveObject', 'klass' => 'Remove'),
+             6 => array('name' => 'DefineBits', 'klass' => 'Jpeg'),
+             7 => array('name' => 'DefineButton', 'klass' => 'Button'),
+             8 => array('name' => 'JPEGTables', 'klass' => 'Jpeg'),
+             9 => array('name' => 'SetBackgroundColor', 'klass' => 'BGColor'),
+            10 => array('name' => 'DefineFont'),
+            11 => array('name' => 'DefineText', 'klass' => 'Text'),
+            12 => array('name' => 'DoAction', 'klass' => 'Action'),
+            13 => array('name' => 'DefineFontInfo'),
+            14 => array('name' => 'DefineSound'),
+            15 => array('name' => 'StartSound'),
+            // 16 missing
+            17 => array('name' => 'DefineButtonSound'),
+            18 => array('name' => 'SoundStreamHead'),
+            19 => array('name' => 'SoundStreamBlock'),
+            20 => array('name' => 'DefineBitsLossless', 'klass' => 'Lossless'),
+            21 => array('name' => 'DefineBitsJPEG2', 'klass' => 'Jpeg'),
+            22 => array('name' => 'DefineShape2', 'klass' => 'Shape'),
+            24 => array('name' => 'Protect'),
+            // 25 missing
+            26 => array('name' => 'PlaceObject2', 'klass' => 'Place'),
+            // 27 missing
+            28 => array('name' => 'RemoveObject2', 'klass' => 'Remove'),
+            // 29,30,31 missing
+            32 => array('name' => 'DefineShape3', 'klass' => 'Shape'),
+            33 => array('name' => 'DefineText2', 'klass' => 'Text'),
+            34 => array('name' => 'DefineButton2', 'klass' => 'Button'),
+            35 => array('name' => 'DefineBitsJPEG3', 'klass' => 'Jpeg'),
+            36 => array('name' => 'DefineBitsLossless2', 'klass' => 'Lossless'),
+            37 => array('name' => 'DefineEditText', 'klass' => 'EditText'),
+            // 38 missing
+            39 => array('name' => 'DefineSprite', 'klass' => 'Sprite'),
+            // 40,41,42 missing
+            43 => array('name' => 'FrameLabel', 'klass' => 'FrameLabel'),
+            // 44 missing
+            45 => array('name' => 'SoundStreamHead2'),
+            46 => array('name' => 'DefineMorphShape', 'klass' => 'Shape'),
+            48 => array('name' => 'DefineFont2', 'klass' => 'Font'),
+            56 => array('name' => 'Export'),
+            57 => array('name' => ''),
+            58 => array('name' => ''),
+            59 => array('name' => 'DoInitAction', 'klass' => 'Action'),
+            //
+            60 => array('name' => 'DefineVideoStream'),
+            61 => array('name' => 'videoFrame'),
+            62 => array('name' => 'DefineFontInfo2'),
+            // 63 missing
+            64 => array('name' => 'EnableDebugger2'),
+            65 => array('name' => 'ScriptLimits'),
+            66 => array('name' => 'SetTabIndex'),
+            // 67,68 missing
+            69 => array('name' => 'FileAttributes'),
+            70 => array('name' => 'PlaceObject3'),
+            71 => array('name' => 'ImportAssets2'),
+            // 72 missing
+            73 => array('name' => 'DefineFontAlignZones'),
+            74 => array('name' => 'CSMTextSettings'),
+            75 => array('name' => 'DefineFont3'),
+            76 => array('name' => 'SymbolClass'),
+            77 => array('name' => 'MetaData'),
+            78 => array('name' => 'DefineScalingGrid'),
+            // 79,80,81 missing
+            82 => array('name' => 'DoABC'),
+            83 => array('name' => 'DefineShape4', 'klass' => 'Shape'),
+            84 => array('name' => 'DefineMorphShape2'),
+            // 85 missing
+            86 => array('name' => 'DefineSceneAndFrameLabelData'),
+            87 => array('name' => 'DefineBinaryData'),
+            88 => array('name' => 'DefineFontName'),
+            89 => array('name' => 'StartSound2'),
+            90 => array('name' => 'DefineBitsJPEG4'),
+            91 => array('name' => 'DefineFont4'),
+            777 => array('name' => 'Reflex'), // swftools ?
+        );
+        if (isset($tagMap[$tagCode][$label])) {
+           return $tagMap[$tagCode][$label];
+        }
+        return false;
+    }
+    function parse(&$reader, $opts = array()) {
+        list($this->byte_offset, $dummy) = $reader->getOffset();
+        $tagAndLength = $reader->getUI16LE();
+        $this->code = $tagAndLength >> 6;
+        $length = $tagAndLength & 0x3f;
+        if ($length == 0x3f) { // long format
+            $length = $reader->getUI32LE();
+        }
+        $this->content = $reader->getData($length);
+        list($byte_offset, $dummy) = $reader->getOffset();
+        $this->byte_size = $byte_offset - $this->byte_offset;
+    }
+    function dump($opts = array()) {
+        $code = $this->code;
+        $name = $this->getTagInfo($code, 'name');
+        if ($name === false) {
+           $name = 'unknown';
+        }
+        $length = strlen($this->content);
+        echo "Code: $code($name)  Length: $length".PHP_EOL;
+        $opts['Version'] = $this->swfInfo['Version'];
+        $opts['tagCode'] = $code;
+        if ($this->parseTagContent($opts)) {
+            $this->tag->dumpContent($code, $opts);
+        }
+        if (empty($opts['hexdump']) === false) {
+           $bitio =& $opts['bitio'];
+           $bitio->hexdump($this->byte_offset, $this->byte_size);
+        }
+    }
+    function build($opts = array()) {
+        $code = $this->code;
+        if (is_null($this->content)) {
+            $this->content = $this->buildTagContent();
+        }
+        $length = strlen($this->content);
+        $writer = new IO_Bit();
+        switch ($code) {
+          case 6:  // DefineBitsJPEG
+          case 21: // DefineBitsJPEG2
+          case 35: // DefineBitsJPEG3
+          case 20: // DefineBitsLossless
+          case 36: // DefineBitsLossless2
+          case 19: // SoundStreamBlock
+            $longFormat = true;
+            break;
+          default:
+            $longFormat = false;
+            break;
+        }
+        if (($longFormat === false) && ($length < 0x3f)) {
+            $tagAndLength = ($code << 6) | $length;
+            $writer->putUI16LE($tagAndLength);
+        } else {
+            $tagAndLength = ($code << 6) | 0x3f;
+            $writer->putUI16LE($tagAndLength);
+            $writer->putUI32LE($length);
+        }
+        return $writer->output() . $this->content;
+    }
+    function parseTagContent($opts = array()) {
+        if (is_null($this->tag) === false) {
+            return true;
+        }
+        if (is_null($this->content)) {
+            throw new IO_SWF_Exception("no tag and no content in ".var_export($this, true));
+        }
+        $code = $this->code;
+        $klass = self::getTagInfo($code, 'klass');
+        if ($klass === false) {
+            return false; // no parse
+        }
+        require_once dirname(__FILE__)."/Tag/$klass.php";
+        $klass = "IO_SWF_Tag_$klass";
+        $obj = new $klass($this->swfInfo);
+        $opts['Version'] = $this->swfInfo['Version'];
+        $opts['tagCode'] = $code;
+        $obj->parseContent($code, $this->content, $opts);
+        $this->tag = $obj;
+        return true;
+    }
+    function buildTagContent() {
+            if ((is_null($this->content) === false)) {
+            return $this->content;
+        }
+        if (is_null($this->tag)) {
+            return false; // throw Exception!
+        }
+        $code = $this->code;
+        $opts['Version'] = $this->swfInfo['Version'];
+        $opts['tagCode'] = $code;
+        $this->content = $this->tag->buildContent($code, $opts); // XXX
+        return $this->content;
+    }
+
+    function bitmapSize() {
+        $code = $this->code;
+        if ($this->parseTagContent() === false) {
+            throw new IO_SWF_Exception("failed to parseTagContent");
+        }
+        switch ($code) {
+        case 6:  // DefineBitsJPEG
+        case 21: // DefineBitsJPEG2
+        case 35: // DefineBitsJPEG3
+            ;
+            break;
+        case 20: // DefineBitsLossless
+        case 36: // DefineBitsLossless2
+            break;
+        default:
+            break;
+        }
+    }
+    function replaceCharacterId($trans_table) {
+        $new_cid = $trans_table[$this->characterId];
+        if ($new_cid == $this->characterId) {
+            return true; // no change
+        }
+        $this->characterId = $new_cid;
+        if (isset($this->content)) {
+            $this->content[0] = chr($new_cid & 0xff);
+            $this->content[1] = chr($new_cid >> 8);
+        }
+        if (isset($this->tag)) {
+            switch ($this->code) {
+              case 2: // DefineShape (ShapeId)
+              case 6: // DefineBits
+              case 7: // DefineButton
+              case 10: // DefineFont (FontID)
+              case 11: // DefineText
+              case 13: // DefineFontInfo (FontID)
+              case 14: // DefineSound
+              case 17: // DefineButtonSound
+              case 18: // SoundStreamHead"
+              case 19: // SoundStreamBlock
+              case 20: // DefineBitsLossless
+              case 21: // DefineBitsJPEG2
+              case 22: // DefineShape2 (ShapeId)
+              case 32: // DefineShape3 (ShapeId)
+              case 33: // DefineText2
+              case 34: // DefineButton2
+              case 35: // DefineBitsJPEG3
+              case 36: // DefineBitsLossless2
+              case 37: // DefineEditText
+              case 39: // DefineSprite (SpriteId)
+              case 46: // DefineMorphShape
+              case 48: // DefineFont2 (FontID)
+              case 73: // DefineFontAlignZones (FontID)
+              case 75: // DefineFont3 (FontID)
+              case 83: // DefineShape4 (ShapeId)
+              case 84: // DefineMorphShape2 (ShapeId)
+              case 88: // DefineFontName (FontID)
+                  foreach (array('_CharacterID', '_spriteId', '_shapeId', 'CharacterID', '_buttonId') as $id_prop_name) {
+                    if (isset($this->tag->$id_prop_name)) {
+                        $this->tag->$id_prop_name = $new_cid;
+                        break;
+                    }
+                }
+                break;
+            }
+        }
+        return true;
+    }
+    function replaceReferenceId($trans_table) {
+        if ($this->parseTagContent() === false) {
+            new IO_SWF_Exception("parseTagContent failed");
+        }
+        switch ($this->code) {
+          case 4:  // PlaceObject
+          case 5:  // RemoveObject
+          case 26: // PlaceObject2 (Shape Reference)
+          case 34: // DefineButton2
+            if (isset($this->tag->_characterId)) {
+                $new_cid = $trans_table[$this->tag->_characterId];
+                if ($this->tag->_characterId != $new_cid) {
+                    $this->tag->_characterId = $new_cid;
+                    $this->content = null;
+                }
+            } else if (isset($this->tag->_buttonId)) {
+                $new_cid = $trans_table[$this->tag->_buttonId];
+                if ($this->tag->_buttonId != $new_cid) {
+                    $this->tag->_buttonId = $new_cid;
+                    $this->content = null;
+                }
+            }
+            break;
+          case 2:  // DefineShape   (Bitmap ReferenceId)
+          case 22: // DefineShape2  (Bitmap ReferenceId)
+          case 32: // DefineShape3    (Bitmap ReferenceId)
+          case 46: // DefineMorphShape (Bitmap ReferenceId)
+            if ($this->parseTagContent() === false) {
+                new IO_SWF_Exception("parseTagContent failed");
+            }
+            if ($this->parseTagContent() === false) {
+                throw new IO_SWF_Exception("failed to parseTagContent");
+            }
+            $modified = false;
+            if (is_null($this->tag->_fillStyles) === false) {
+                foreach ($this->tag->_fillStyles as &$fillStyle) {
+                    if (isset($fillStyle['BitmapId'])) {
+                        if ($fillStyle['BitmapId'] != 65535) {
+                            $new_id = $trans_table[$fillStyle['BitmapId']];
+                            if ($fillStyle['BitmapId'] != $new_id) {
+                                $modified = true;
+                                $fillStyle['BitmapId'] = $new_id;
+                            }
+                        }
+                    }
+                }
+            }
+            if (is_null($this->tag->_shapeRecords) === false) {
+                foreach ($this->tag->_shapeRecords as &$shapeRecord) {
+                    if (isset($shapeRecord['FillStyles'])) {
+                        foreach ($shapeRecord['FillStyles'] as &$fillStyle) {
+                            if (isset($fillStyle['BitmapId'])) {
+                                if ($fillStyle['BitmapId'] != 65535) {
+                                    $new_id = $trans_table[$fillStyle['BitmapId']];
+                                    if ($fillStyle['BitmapId'] != $new_id) {
+                                        $modified = true;
+                                        $fillStyle['BitmapId'] = $new_id;
+                                    }
+                                }
+                            }
+                        }
+                    }
+                }
+            }
+            if ($modified) {
+                $this->content = null;
+            }
+            break;
+        }
+        return true;
+    }
+}
属性に変更があったパス: IO_SWF/tags/2.1.8-stable-20120220231502/IO/SWF/Tag.php
___________________________________________________________________
追加: svn:keywords
+ Id
追加: svn:eol-style
+ native

IO_SWF/tags/2.1.8-stable-20120220231502/IO/SWF/Type/KERNINGRECORD.php

@@ -0,0 +1,39 @@
+<?php
+
+/*
+ * 2011/4/15- (c) yoya@awm.jp
+ */
+
+require_once 'IO/Bit.php';
+require_once dirname(__FILE__).'/../Type.php';
+
+class IO_SWF_Type_KERNINGRECORD extends IO_SWF_Type {
+    static function parse(&$reader, $opts = array()) {
+    	$kerningrecord = array();
+        if ($opts['FontFlagsWideCodes']) {
+            $kerningrecord['FontKerningCode1'] = $reader->getUI16LE();
+            $kerningrecord['FontKerningCode2'] = $reader->getUI16LE();
+        } else {
+            $kerningrecord['FontKerningCode1'] = $reader->getUI8();
+            $kerningrecord['FontKerningCode2'] = $reader->getUI8();
+        }
+    	$kerningrecord['FontKerningAdjustment'] = $reader->getSI16LE();
+    	return $kerningrecord;
+    }
+    static function build(&$writer, $kerningrecord, $opts = array()) {
+        if ($opts['FontFlagsWideCodes']) {
+            $writer->getUI16LE($kerningrecord['FontKerningCode1']);
+            $writer->getUI16LE($kerningrecord['FontKerningCode2']);
+        } else {
+            $writer->getUI8($kerningrecord['FontKerningCode1']);
+            $writer->getUI8($kerningrecord['FontKerningCode2']);
+        }
+        $writer->getSI16LE($kerningrecord['FontKerningAdjustment']);
+    }
+    static function string($kerningrecord, $opts = array()) {
+        $text = "FontKerningCode1: {$kerningrecord['FontKerningCode1']}";
+        $text .= " FontKerningCode2: {$kerningrecord['FontKerningCode2']}";
+        $text .= " FontKerningAdjustment: {$kerningrecord['FontKerningAdjustment']}";
+        return $text;
+    }
+}

IO_SWF/tags/2.1.8-stable-20120220231502/IO/SWF/Type/RECT.php

@@ -0,0 +1,44 @@
+<?php
+
+/*
+ * 2011/4/15- (c) yoya@awm.jp
+ */
+
+require_once 'IO/Bit.php';
+require_once dirname(__FILE__).'/../Type.php';
+
+class IO_SWF_Type_RECT extends IO_SWF_Type {
+    static function parse(&$reader, $opts = array()) {
+        $frameSize = array();
+        $reader->byteAlign();
+        $nBits = $reader->getUIBits(5);
+        $frameSize['Xmin'] = $reader->getSIBits($nBits);
+        $frameSize['Xmax'] = $reader->getSIBits($nBits);
+        $frameSize['Ymin'] = $reader->getSIBits($nBits);
+        $frameSize['Ymax'] = $reader->getSIBits($nBits) ;
+    	return $frameSize;
+    }
+    static function build(&$writer, $frameSize, $opts = array()) {
+        $nBits = 0;
+    	foreach ($frameSize as $size) {
+	        if ($size == 0){
+	            $bits = 0;
+    	    } else {
+	            $bits = $writer->need_bits_signed($size);
+	        }
+    	    $nBits = max($nBits, $bits);
+    	}
+        $writer->byteAlign();
+	    $writer->putUIBits($nBits, 5);
+        $writer->putSIBits($frameSize['Xmin'], $nBits);
+        $writer->putSIBits($frameSize['Xmax'], $nBits);
+        $writer->putSIBits($frameSize['Ymin'], $nBits);
+        $writer->putSIBits($frameSize['Ymax'], $nBits);
+    }
+    static function string($rect, $opts = array()) {
+        return "Xmin: ".($rect['Xmin'] / 20).
+               " Xmax: ".($rect['Xmax'] / 20).
+               " Ymin: ".($rect['Ymin'] / 20).
+               " Ymax: ".($rect['Ymax'] / 20);
+    }
+}
属性に変更があったパス: IO_SWF/tags/2.1.8-stable-20120220231502/IO/SWF/Type/RECT.php
___________________________________________________________________
追加: svn:keywords
+ Id
追加: svn:eol-style
+ native

IO_SWF/tags/2.1.8-stable-20120220231502/IO/SWF/Type/CXFORM.php

@@ -0,0 +1,86 @@
+<?php
+
+/*
+ * 2011/7/9- (c) yoya@awm.jp
+ */
+
+require_once 'IO/Bit.php';
+require_once dirname(__FILE__).'/../Type.php';
+
+class IO_SWF_Type_CXFORM extends IO_SWF_Type {
+    static function parse(&$reader, $opts = array()) {
+    	$cxform = array();
+    	$reader->byteAlign();
+    	$hasAddTerms = $reader->getUIBit();
+    	$hasMultiTerms = $reader->getUIBit();
+    	$cxform['HasAddTerms'] = $hasAddTerms;
+    	$cxform['HasMultiTerms'] = $hasMultiTerms;
+        $nbits = $reader->getUIBits(4);
+        if ($hasMultiTerms) {
+            $cxform['RedMultiTerm']   = $reader->getSIBits($nbits);
+            $cxform['GreenMultiTerm'] = $reader->getSIBits($nbits);
+            $cxform['BlueMultiTerm']  = $reader->getSIBits($nbits);
+        }
+        if ($hasAddTerms) {
+            $cxform['RedAddTerm']   = $reader->getSIBits($nbits);
+            $cxform['GreenAddTerm'] = $reader->getSIBits($nbits);
+            $cxform['BlueAddTerm']  = $reader->getSIBits($nbits);
+        }
+    	return $cxform;
+    }
+    static function build(&$writer, $cxform, $opts = array()) {
+        $nbits = 0;
+        $hasAddTerms = 0;
+        $hasMultiTerms = 0;
+        $multi_term_list = array('RedMultiTerm', 'GreenMultiTerm', 'BlueMultiTerm');
+        $writer->byteAlign();
+        foreach ($multi_term_list as $term) {
+            if (isset($cxform[$term])) {
+                $hasMultiTerms = 1;
+                $need_bits = $writer->need_bits_signed($cxform[$term]);
+                if ($nbits < $need_bits){
+                    $nbits = $need_bits;
+                }
+	    }
+	}
+	$add_term_list = array('RedAddTerm', 'GreenAddTerm', 'BlueAddTerm');
+	foreach ($add_term_list as $term) {
+	    if (isset($cxform[$term])) {
+	        $hasAddTerms = 1;
+            $need_bits = $writer->need_bits_signed($cxform[$term]);
+            if ($nbits < $need_bits){
+                $nbits = $need_bits;
+            }
+	    }
+	}
+	$writer->putUIBit($hasAddTerms);
+	$writer->putUIBit($hasMultiTerms);
+	$writer->putUIBits($nbits, 4);
+	if ($hasMultiTerms) {
+	    $writer->putSIBits($cxform['RedMultiTerm'],   $nbits);
+	    $writer->putSIBits($cxform['GreenMultiTerm'], $nbits);
+	    $writer->putSIBits($cxform['BlueMultiTerm'],  $nbits);
+	}
+	if ($hasAddTerms) {
+	  $writer->putSIBits($cxform['RedAddTerm'],   $nbits);
+	  $writer->putSIBits($cxform['GreenAddTerm'], $nbits);
+	  $writer->putSIBits($cxform['BlueAddTerm'],  $nbits);
+	}
+    }
+    static function string($cxform, $opts = array()) {
+        if (($cxform['HasMultiTerms'] == 0) && ($cxform['HasAddTerms'] == 0)) {
+            return '(No Data: CXFORM)';
+        }
+        $text = '';
+        if ($cxform['HasMultiTerms']) {
+            $text .= sprintf("MultiTerms:(%d,%d,%d)", $cxform['RedMultiTerm'], $cxform['GreenMultiTerm'], $cxform['BlueMultiTerm']);
+        }
+        if ($cxform['HasAddTerms']) {
+            if ($cxform['HasMultiTerms']) {
+                $text .= ' ';
+            }
+            $text .= sprintf("AddTerms:(%d,%d,%d)", $cxform['RedAddTerm'], $cxform['GreenAddTerm'], $cxform['BlueAddTerm']);
+        }
+        return $text;
+    }
+}
属性に変更があったパス: IO_SWF/tags/2.1.8-stable-20120220231502/IO/SWF/Type/CXFORM.php
___________________________________________________________________
追加: svn:keywords
+ Id
追加: svn:eol-style
+ native

IO_SWF/tags/2.1.8-stable-20120220231502/IO/SWF/Type/SHAPE.php

@@ -0,0 +1,347 @@
+<?php
+
+/*
+ * 2011/4/15- (c) yoya@awm.jp
+ */
+
+require_once 'IO/Bit.php';
+require_once dirname(__FILE__).'/../Type.php';
+require_once dirname(__FILE__).'/../Type/FILLSTYLEARRAY.php';
+require_once dirname(__FILE__).'/../Type/LINESTYLEARRAY.php';
+
+class IO_SWF_Type_SHAPE extends IO_SWF_Type {
+    static function parse(&$reader, $opts = array()) {
+        $tagCode = $opts['tagCode'];
+        $shapeRecords = array();
+
+    	$reader->byteAlign();
+    	// 描画スタイルを参照するインデックスのビット幅
+    	$numFillBits = $reader->getUIBits(4);
+	    $numLineBits = $reader->getUIBits(4);
+
+    	$currentDrawingPositionX = 0;
+    	$currentDrawingPositionY = 0;
+    	$currentFillStyle0 = 0;
+    	$currentFillStyle1 = 0;
+    	$currentLineStyle = 0;
+    	$done = false;
+
+    	// ShapeRecords
+    	while ($done === false) {
+    	    $shapeRecord = array();
+            $typeFlag = $reader->getUIBit();
+            $shapeRecord['TypeFlag'] = $typeFlag;
+            if ($typeFlag == 0) {
+                $endOfShape = $reader->getUIBits(5);
+               if ($endOfShape == 0) {
+                    // EndShapeRecord
+                    $shapeRecord['EndOfShape'] = $endOfShape;
+                    $done = true;
+               } else {
+                    // StyleChangeRecord
+                    $reader->incrementOffset(0, -5);
+                    $stateNewStyles = $reader->getUIBit();
+                    $stateLineStyle = $reader->getUIBit();
+                    $stateFillStyle1 = $reader->getUIBit();
+                    $stateFillStyle0 = $reader->getUIBit();
+
+                    $stateMoveTo = $reader->getUIBit();
+                    if ($stateMoveTo) {
+                    $moveBits = $reader->getUIBits(5);
+//                        $shapeRecord['(MoveBits)'] = $moveBits;
+                        $moveDeltaX = $reader->getSIBits($moveBits);
+                        $moveDeltaY = $reader->getSIBits($moveBits);
+//                        $currentDrawingPositionX += $moveDeltaX;
+//                        $currentDrawingPositionY += $moveDeltaY;
+                        $currentDrawingPositionX = $moveDeltaX;
+                        $currentDrawingPositionY = $moveDeltaY;
+                        $shapeRecord['MoveX'] = $currentDrawingPositionX;
+                        $shapeRecord['MoveY'] = $currentDrawingPositionY;
+                    }
+                    $shapeRecord['MoveX'] = $currentDrawingPositionX;
+                    $shapeRecord['MoveY'] = $currentDrawingPositionY;
+
+                    if ($stateFillStyle0) {
+                        $currentFillStyle0 = $reader->getUIBits($numFillBits);
+                    }
+                    if ($stateFillStyle1) {
+                        $currentFillStyle1 = $reader->getUIBits($numFillBits);
+                    }
+                    if ($stateLineStyle) {
+                        $currentLineStyle = $reader->getUIBits($numLineBits);
+                    }
+                    $shapeRecord['FillStyle0'] = $currentFillStyle0;
+                    $shapeRecord['FillStyle1'] = $currentFillStyle1;
+                    $shapeRecord['LineStyle']  = $currentLineStyle;
+                    if ($stateNewStyles) {
+                        $opts = array('tagCode' => $tagCode);
+                        $shapeRecord['FillStyles'] = IO_SWF_TYPE_FILLSTYLEARRAY::parse($reader, $opts);
+                        $shapeRecord['LineStyles'] = IO_SWF_TYPE_LINESTYLEARRAY::parse($reader, $opts);
+                        $reader->byteAlign();
+                        $numFillBits = $reader->getUIBits(4);
+                        $numLineBits = $reader->getUIBits(4);
+                    }
+                }
+            } else { // Edge records
+                $shapeRecord['StraightFlag'] = $reader->getUIBit();
+                if ($shapeRecord['StraightFlag']) {
+                    // StraightEdgeRecord
+                    $numBits = $reader->getUIBits(4);
+//                    $shapeRecord['(NumBits)'] = $numBits;
+                     $generalLineFlag = $reader->getUIBit();
+                    if ($generalLineFlag == 0) {
+                        $vertLineFlag = $reader->getUIBit();
+                    }
+                    if ($generalLineFlag || ($vertLineFlag == 0)) {
+                        $deltaX = $reader->getSIBits($numBits + 2);
+                        $currentDrawingPositionX += $deltaX;
+                    }
+                    if ($generalLineFlag || $vertLineFlag) {
+                        $deltaY = $reader->getSIBits($numBits + 2);
+                        $currentDrawingPositionY += $deltaY;
+                    }
+                    $shapeRecord['X'] = $currentDrawingPositionX;
+                    $shapeRecord['Y'] = $currentDrawingPositionY;
+                } else {
+                    // CurvedEdgeRecord
+                    $numBits = $reader->getUIBits(4);
+//                    $shapeRecord['(NumBits)'] = $numBits;
+
+                    $controlDeltaX = $reader->getSIBits($numBits + 2);
+                    $controlDeltaY = $reader->getSIBits($numBits + 2);
+                    $anchorDeltaX = $reader->getSIBits($numBits + 2);
+                    $anchorDeltaY = $reader->getSIBits($numBits + 2);
+
+                    $currentDrawingPositionX += $controlDeltaX;
+                    $currentDrawingPositionY += $controlDeltaY;
+                    $shapeRecord['ControlX'] = $currentDrawingPositionX;
+                    $shapeRecord['ControlY'] = $currentDrawingPositionY;
+
+                    $currentDrawingPositionX += $anchorDeltaX;
+                    $currentDrawingPositionY += $anchorDeltaY;
+                    $shapeRecord['AnchorX'] = $currentDrawingPositionX;
+                    $shapeRecord['AnchorY'] = $currentDrawingPositionY;
+                }
+            }
+            $shapeRecords []= $shapeRecord;
+       }
+    	return $shapeRecords;
+    }
+    static function build(&$writer, $shapeRecords, $opts = array()) {
+        $tagCode = $opts['tagCode'];
+        $fillStyleCount = $opts['fillStyleCount'];
+        $lineStyleCount = $opts['lineStyleCount'];
+        if ($fillStyleCount == 0) {
+            $numFillBits = 0;
+        } else {
+            // $fillStyleCount == fillStyle MaxValue because 'undefined' use 0
+            $numFillBits = $writer->need_bits_unsigned($fillStyleCount);
+        }
+        if ($lineStyleCount == 0) {
+            $numLineBits = 0;
+        } else {
+            // $lineStyleCount == lineStyle MaxValue because 'undefined' use 0
+            $numLineBits = $writer->need_bits_unsigned($lineStyleCount);
+        }
+
+        $writer->byteAlign();
+        $writer->putUIBits($numFillBits, 4);
+        $writer->putUIBits($numLineBits, 4);
+        $currentDrawingPositionX = 0;
+        $currentDrawingPositionY = 0;
+        $currentFillStyle0 = 0;
+        $currentFillStyle1 = 0;
+        $currentLineStyle = 0;
+        foreach ($shapeRecords as $shapeRecordIndex => $shapeRecord) {
+            $typeFlag = $shapeRecord['TypeFlag'];
+            $writer->putUIBit($typeFlag);
+            if($typeFlag == 0) {
+                if (isset($shapeRecord['EndOfShape']) && ($shapeRecord['EndOfShape']) == 0) {
+                    // EndShapeRecord
+                    $writer->putUIBits(0, 5);
+                } else {
+                    // StyleChangeRecord
+                    if (isset($shapeRecord['FillStyles'])) {
+                        $stateNewStyles = 1;
+                        $fillStyleCount = count($shapeRecord['FillStyles']);
+                        if ($fillStyleCount == 0) {
+                            $numFillBits = 0;
+                        } else {
+                            // $fillStyleCount == fillStyle MaxValue because 'undefined' use 0
+                            $numFillBits = $writer->need_bits_unsigned($fillStyleCount);
+                        }
+                        $lineStyleCount = count($shapeRecord['LineStyles']);
+                        if ($lineStyleCount == 0) {
+                            $numLineBits = 0;
+                        } else {
+                            // $lineStyleCount == lineStyle MaxValue because 'undefined' use 0
+                            $numLineBits = $writer->need_bits_unsigned($lineStyleCount);
+                        }
+                    } else {
+                        $stateNewStyles = 0;
+                    }
+                    $stateLineStyle = ($shapeRecord['LineStyle'] != $currentLineStyle)?1:0;
+                    $stateFillStyle1 = ($shapeRecord['FillStyle1'] != $currentFillStyle1)?1:0;
+                    $stateFillStyle0 = ($shapeRecord['FillStyle0'] != $currentFillStyle0)?1:0;
+
+                    $writer->putUIBit($stateNewStyles);
+                    $writer->putUIBit($stateLineStyle);
+                    $writer->putUIBit($stateFillStyle1);
+                    $writer->putUIBit($stateFillStyle0);
+
+                    if (($shapeRecord['MoveX'] != $currentDrawingPositionX) || ($shapeRecord['MoveY'] != $currentDrawingPositionY)) {
+                        $stateMoveTo = true;
+                    } else {
+                        $stateMoveTo = false;
+                    }
+                    $writer->putUIBit($stateMoveTo);
+                    if ($stateMoveTo) {
+                        $moveX = $shapeRecord['MoveX'];
+                        $moveY = $shapeRecord['MoveY'];
+                        $currentDrawingPositionX = $moveX;
+                        $currentDrawingPositionY = $moveY;
+                        if ($moveX | $moveY) {
+                            $XmoveBits = $writer->need_bits_signed($moveX);
+                            $YmoveBits = $writer->need_bits_signed($moveY);
+                            $moveBits = max($XmoveBits, $YmoveBits);
+                        } else {
+                            $moveBits = 0;
+                        }
+                        $writer->putUIBits($moveBits, 5);
+                        $writer->putSIBits($moveX, $moveBits);
+                        $writer->putSIBits($moveY, $moveBits);
+                    }
+                    if ($stateFillStyle0) {
+                        $currentFillStyle0 = $shapeRecord['FillStyle0'];
+                        $writer->putUIBits($currentFillStyle0, $numFillBits);
+                    }
+                    if ($stateFillStyle1) {
+                        $currentFillStyle1 = $shapeRecord['FillStyle1'];
+                        $writer->putUIBits($currentFillStyle1, $numFillBits);
+                    }
+                    if ($stateLineStyle) {
+                        $currentLineStyle = $shapeRecord['LineStyle'];
+                        $writer->putUIBits($currentLineStyle, $numLineBits);
+                    }
+                    if ($stateNewStyles) {
+                        $opts = array('tagCode' => $tagCode);
+                        IO_SWF_Type_FILLSTYLEARRAY::build($writer, $shapeRecord['FillStyles'], $opts);
+                        IO_SWF_Type_LINESTYLEARRAY::build($writer, $shapeRecord['LineStyles'], $opts);
+                        $writer->byteAlign();
+                        $writer->putUIBits($numFillBits, 4);
+                        $writer->putUIBits($numLineBits, 4);
+                    }
+                }
+            } else {
+                $straightFlag = $shapeRecord['StraightFlag'];
+                $writer->putUIBit($straightFlag);
+                if ($straightFlag) {
+                    $deltaX = $shapeRecord['X'] - $currentDrawingPositionX;
+                    $deltaY = $shapeRecord['Y'] - $currentDrawingPositionY;
+                    if ($deltaX | $deltaY) {
+                       $XNumBits = $writer->need_bits_signed($deltaX);
+                       $YNumBits = $writer->need_bits_signed($deltaY);
+                       $numBits = max($XNumBits, $YNumBits);
+                    } else {
+                        $numBits = 0;
+                    }
+                    if ($numBits < 2) {
+                        $numBits = 2;
+                    }
+                    $writer->putUIBits($numBits - 2, 4);
+                    if ($deltaX && $deltaY) {
+                        $writer->putUIBit(1); // GeneralLineFlag
+                        $writer->putSIBits($deltaX, $numBits);
+                        $writer->putSIBits($deltaY, $numBits);
+                    } else {
+                        $writer->putUIBit(0); // GeneralLineFlag
+                        if ($deltaX) {
+                           $writer->putUIBit(0); // VertLineFlag
+                           $writer->putSIBits($deltaX, $numBits);
+                        } else {
+                           $writer->putUIBit(1); // VertLineFlag
+                           $writer->putSIBits($deltaY, $numBits);
+                        }
+                    }
+                    $currentDrawingPositionX = $shapeRecord['X'];
+                    $currentDrawingPositionY = $shapeRecord['Y'];
+                } else {
+                    $controlDeltaX = $shapeRecord['ControlX'] - $currentDrawingPositionX;
+                    $controlDeltaY = $shapeRecord['ControlY'] - $currentDrawingPositionY;
+                    $currentDrawingPositionX = $shapeRecord['ControlX'];
+                    $currentDrawingPositionY = $shapeRecord['ControlY'];
+                    $anchorDeltaX = $shapeRecord['AnchorX'] - $currentDrawingPositionX;
+                    $anchorDeltaY = $shapeRecord['AnchorY'] - $currentDrawingPositionY;
+                    $currentDrawingPositionX = $shapeRecord['AnchorX'];
+                    $currentDrawingPositionY = $shapeRecord['AnchorY'];
+
+                    $numBitsControlDeltaX = $writer->need_bits_signed($controlDeltaX);
+                    $numBitsControlDeltaY = $writer->need_bits_signed($controlDeltaY);
+                    $numBitsAnchorDeltaX = $writer->need_bits_signed($anchorDeltaX);
+                    $numBitsAnchorDeltaY = $writer->need_bits_signed($anchorDeltaY);
+                    $numBits = max($numBitsControlDeltaX, $numBitsControlDeltaY, $numBitsAnchorDeltaX, $numBitsAnchorDeltaY);
+                    if ($numBits < 2) {
+                       $numBits = 2;
+                    }
+                    $writer->putUIBits($numBits - 2, 4);
+                    $writer->putSIBits($controlDeltaX, $numBits);
+                    $writer->putSIBits($controlDeltaY, $numBits);
+                    $writer->putSIBits($anchorDeltaX, $numBits);
+                    $writer->putSIBits($anchorDeltaY, $numBits);
+                }
+            }
+        }
+        return true;
+    }
+    static function string($shapeRecords, $opts = array()) {
+        $tagCode = $opts['tagCode'];
+        if (isset($opts['indent'])) {
+            $indent_text = '';
+            for ($i = 0 ; $i < $opts['indent'] ; $i++) {
+                $indent_text .= "\t"; // str_pad? str_repeat ?
+            }
+        } else {
+            $indent_text = "\t";
+        }
+        $text = '';
+        foreach ($shapeRecords as $shapeRecord) {
+            $text .= $indent_text;
+            $typeFlag = $shapeRecord['TypeFlag'];
+            if ($typeFlag == 0) {
+               if (isset($shapeRecord['EndOfShape'])) {
+                   $text .= "EndOfShape";
+               } else {
+                   $moveX = $shapeRecord['MoveX'] / 20;
+                   $moveY = $shapeRecord['MoveY'] / 20;
+                   $text .= "ChangeStyle: MoveTo: ($moveX, $moveY)";
+                   $style_list = array('FillStyle0', 'FillStyle1', 'LineStyle');
+                   $text .= "  FillStyle: ".$shapeRecord['FillStyle0']."|".$shapeRecord['FillStyle1'];
+                   $text .= "  LineStyle: ".$shapeRecord['LineStyle'];
+                   if (isset($shapeRecord['FillStyles'])) {
+                       $text .= "    FillStyles:";
+                       $text .= IO_SWF_Type_FILLSTYLEARRAY::string($shapeRecord['FillStyles'], $opts);
+                   }
+                   if (isset($shapeRecord['LineStyles'])) {
+                       $text .= "    LineStyles:";
+                       $text .= IO_SWF_Type_LINESTYLEARRAY::string($shapeRecord['LineStyles'], $opts);
+                   }
+               }
+            } else {
+                $straightFlag = $shapeRecord['StraightFlag'];
+                if ($straightFlag) {
+                    $x = $shapeRecord['X'] / 20;
+                    $y = $shapeRecord['Y'] / 20;
+                    $text .= "StraightEdge: MoveTo: ($x, $y)";
+                } else {
+                    $controlX = $shapeRecord['ControlX'] / 20;
+                    $controlY = $shapeRecord['ControlY'] / 20;
+                    $anchorX = $shapeRecord['AnchorX'] / 20;
+                    $anchorY = $shapeRecord['AnchorY'] / 20;
+                    $text .=  "CurvedEdge: MoveTo: Control($controlX, $controlY) Anchor($anchorX, $anchorY)";
+                }
+            }
+            $text .= PHP_EOL;
+        }
+        return $text;
+    }
+}
属性に変更があったパス: IO_SWF/tags/2.1.8-stable-20120220231502/IO/SWF/Type/SHAPE.php
___________________________________________________________________
追加: svn:keywords
+ Id
追加: svn:eol-style
+ native

IO_SWF/tags/2.1.8-stable-20120220231502/IO/SWF/Type/CXFORMWITHALPHA.php

@@ -0,0 +1,90 @@
+<?php
+
+/*
+ * 2011/7/9- (c) yoya@awm.jp
+ */
+
+require_once 'IO/Bit.php';
+require_once dirname(__FILE__).'/../Type.php';
+
+class IO_SWF_Type_CXFORMWITHALPHA extends IO_SWF_Type {
+    static function parse(&$reader, $opts = array()) {
+    	$cxform = array();
+    	$reader->byteAlign();
+    	$hasAddTerms = $reader->getUIBit();
+    	$hasMultiTerms = $reader->getUIBit();
+    	$cxform['HasAddTerms'] = $hasAddTerms;
+    	$cxform['HasMultiTerms'] = $hasMultiTerms;
+        $nbits = $reader->getUIBits(4);
+        if ($hasMultiTerms) {
+            $cxform['RedMultiTerm']   = $reader->getSIBits($nbits);
+            $cxform['GreenMultiTerm'] = $reader->getSIBits($nbits);
+            $cxform['BlueMultiTerm']  = $reader->getSIBits($nbits);
+            $cxform['AlphaMultiTerm'] = $reader->getSIBits($nbits);
+        }
+        if ($hasAddTerms) {
+            $cxform['RedAddTerm']   = $reader->getSIBits($nbits);
+            $cxform['GreenAddTerm'] = $reader->getSIBits($nbits);
+            $cxform['BlueAddTerm']  = $reader->getSIBits($nbits);
+            $cxform['AlphaAddTerm'] = $reader->getSIBits($nbits);
+        }
+    	return $cxform;
+    }
+    static function build(&$writer, $cxform, $opts = array()) {
+        $nbits = 0;
+        $hasAddTerms = 0;
+        $hasMultiTerms = 0;
+        $multi_term_list = array('RedMultiTerm', 'GreenMultiTerm', 'BlueMultiTerm', 'AlphaMultiTerm');
+        $writer->byteAlign();
+        foreach ($multi_term_list as $term) {
+            if (isset($cxform[$term])) {
+                $hasMultiTerms = 1;
+                $need_bits = $writer->need_bits_signed($cxform[$term]);
+                if ($nbits < $need_bits){
+                    $nbits = $need_bits;
+                }
+            }
+        }
+        $add_term_list = array('RedAddTerm', 'GreenAddTerm', 'BlueAddTerm', 'AlphaAddTerm');
+        foreach ($add_term_list as $term) {
+            if (isset($cxform[$term])) {
+                $hasAddTerms = 1;
+                $need_bits = $writer->need_bits_signed($cxform[$term]);
+                if ($nbits < $need_bits){
+                    $nbits = $need_bits;
+                }
+            }
+        }
+        $writer->putUIBit($hasAddTerms);
+        $writer->putUIBit($hasMultiTerms);
+        $writer->putUIBits($nbits, 4);
+        if ($hasMultiTerms) {
+            $writer->putSIBits($cxform['RedMultiTerm']  , $nbits);
+            $writer->putSIBits($cxform['GreenMultiTerm'], $nbits);
+            $writer->putSIBits($cxform['BlueMultiTerm'] , $nbits);
+            $writer->putSIBits($cxform['AlphaMultiTerm'], $nbits);
+        }
+        if ($hasAddTerms) {
+            $writer->putSIBits($cxform['RedAddTerm']  , $nbits);
+            $writer->putSIBits($cxform['GreenAddTerm'], $nbits);
+            $writer->putSIBits($cxform['BlueAddTerm'] , $nbits);
+            $writer->putSIBits($cxform['AlphaAddTerm'], $nbits);
+        }
+    }
+    static function string($cxform, $opts = array()) {
+        if (($cxform['HasMultiTerms'] == 0) && ($cxform['HasAddTerms'] == 0)) {
+            return '(No Data: CXFORMWITHALPHA)';
+        }
+        $text = '';
+        if ($cxform['HasMultiTerms']) {
+            $text .= sprintf("MultiTerms:(%d,%d,%d,%d)", $cxform['RedMultiTerm'], $cxform['GreenMultiTerm'], $cxform['BlueMultiTerm'], $cxform['AlphaMultiTerm']);
+        }
+        if ($cxform['HasAddTerms']) {
+            if ($cxform['HasMultiTerms']) {
+                $text .= ' ';
+            }
+            $text .= sprintf("AddTerms:(%d,%d,%d,%d)", $cxform['RedAddTerm'], $cxform['GreenAddTerm'], $cxform['BlueAddTerm'], $cxform['AlphaAddTerm']);
+        }
+        return $text;
+    }
+}
属性に変更があったパス: IO_SWF/tags/2.1.8-stable-20120220231502/IO/SWF/Type/CXFORMWITHALPHA.php
___________________________________________________________________
追加: svn:keywords
+ Id
追加: svn:eol-style
+ native

IO_SWF/tags/2.1.8-stable-20120220231502/IO/SWF/Type/MATRIX.php

@@ -0,0 +1,103 @@
+<?php
+
+/*
+ * 2011/4/15- (c) yoya@awm.jp
+ */
+
+require_once 'IO/Bit.php';
+require_once dirname(__FILE__).'/../Type.php';
+
+class IO_SWF_Type_MATRIX extends IO_SWF_Type {
+    static function parse(&$reader, $opts = array()) {
+    	$matrix = array();
+
+        $reader->byteAlign();
+        $hasScale = $reader->getUIBit();
+    	if ($hasScale) {
+    	    $nScaleBits = $reader->getUIBits(5);
+//  	    $matrix['(NScaleBits)'] = $nScaleBits;
+    	    $matrix['ScaleX'] = $reader->getSIBits($nScaleBits);
+    	    $matrix['ScaleY'] = $reader->getSIBits($nScaleBits);
+    	} else {
+    	    $matrix['ScaleX'] = 0x10000;
+    	    $matrix['ScaleY'] = 0x10000;
+    	}
+        $hasRotate = $reader->getUIBit();
+    	if ($hasRotate) {
+    	    $nRotateBits = $reader->getUIBits(5);
+//	        $matrix['(NRotateBits)'] = $nRotateBits;
+    	    $matrix['RotateSkew0'] = $reader->getSIBits($nRotateBits);
+    	    $matrix['RotateSkew1'] = $reader->getSIBits($nRotateBits);
+    	} else  {
+    	    $matrix['RotateSkew0'] = 0;
+    	    $matrix['RotateSkew1'] = 0;
+    	}
+        $nTranslateBits = $reader->getUIBits(5);
+    	$matrix['TranslateX'] = $reader->getSIBits($nTranslateBits);
+    	$matrix['TranslateY'] = $reader->getSIBits($nTranslateBits);
+    	return $matrix;
+    }
+    static function build(&$writer, $matrix, $opts = array()) {
+        $writer->byteAlign();
+        if (($matrix['ScaleX'] != 0x10000) || ($matrix['ScaleY'] != 0x10000)) {
+	        $writer->putUIBit(1); // HasScale;
+    	    if ($matrix['ScaleX'] | $matrix['ScaleY']) {
+    	        $xNBits = $writer->need_bits_signed($matrix['ScaleX']);
+    	        $yNBits = $writer->need_bits_signed($matrix['ScaleY']);
+    	        $nScaleBits = max($xNBits, $yNBits);
+    	    } else {
+    	        $nScaleBits = 0;
+    	    }
+    	    $writer->putUIBits($nScaleBits, 5);
+    	    $writer->putSIBits($matrix['ScaleX'], $nScaleBits);
+    	    $writer->putSIBits($matrix['ScaleY'], $nScaleBits);
+       	} else {
+    	    $writer->putUIBit(0); // HasScale;
+       	}
+    	if ($matrix['RotateSkew0'] | $matrix['RotateSkew1']) {
+    	    $writer->putUIBit(1); // HasRotate
+    	    if ($matrix['RotateSkew0'] | $matrix['RotateSkew1']) {
+    	        $rs0NBits = $writer->need_bits_signed($matrix['RotateSkew0']);
+    	        $rs1NBits = $writer->need_bits_signed($matrix['RotateSkew1']);
+    	        $nRotateBits = max($rs0NBits, $rs1NBits);
+    	    } else {
+	            $nRotateBits = 0;
+    	    }
+    	    $writer->putUIBits($nRotateBits, 5);
+    	    $writer->putSIBits($matrix['RotateSkew0'], $nRotateBits);
+    	    $writer->putSIBits($matrix['RotateSkew1'], $nRotateBits);
+    	} else {
+    	    $writer->putUIBit(0); // HasRotate
+        }
+    	if ($matrix['TranslateX'] | $matrix['TranslateY']) {
+    	    $xNTranslateBits = $writer->need_bits_signed($matrix['TranslateX']);
+    	    $yNTranslateBits = $writer->need_bits_signed($matrix['TranslateY']);
+    	    $nTranslateBits = max($xNTranslateBits, $yNTranslateBits);
+    	} else {
+    	    $nTranslateBits = 0;
+    	}
+    	$writer->putUIBits($nTranslateBits, 5);
+    	$writer->putSIBits($matrix['TranslateX'], $nTranslateBits);
+    	$writer->putSIBits($matrix['TranslateY'], $nTranslateBits);
+    }
+
+    static function string($matrix, $opts = array()) {
+        $indent = 0;
+        if (isset($opts['indent'])) {
+            $indent = $opts['indent'];
+        }
+	   $text_fmt = <<< EOS
+%s| %3.3f %3.3f |  %3.2f
+%s| %3.3f %3.3f |  %3.2f
+EOS;
+	return 	sprintf($text_fmt,
+		str_repeat("\t", $indent),
+        $matrix['ScaleX'] / 0x10000,
+        $matrix['RotateSkew0'] / 0x10000,
+		$matrix['TranslateX'] / 20,
+		str_repeat("\t", $indent),
+		$matrix['RotateSkew1'] / 0x10000,
+		$matrix['ScaleY'] / 0x10000,
+		$matrix['TranslateY'] / 20);
+    }
+}
属性に変更があったパス: IO_SWF/tags/2.1.8-stable-20120220231502/IO/SWF/Type/MATRIX.php
___________________________________________________________________
追加: svn:keywords
+ Id
追加: svn:eol-style
+ native

IO_SWF/tags/2.1.8-stable-20120220231502/IO/SWF/Type/Float.php

@@ -0,0 +1,23 @@
+<?php
+
+/*
+ * 2011/6/27- (c) yoya@awm.jp
+ */
+
+require_once 'IO/Bit.php';
+require_once dirname(__FILE__).'/../Type.php';
+
+class IO_SWF_Type_Float extends IO_SWF_Type {
+    static function parse(&$reader, $opts = array()) {
+        $data = $reader->getData(4);
+	$unpacked_data = unpack('f', $data);
+    	return (float)$unpacked_data[1];
+    }
+    static function build(&$writer, $value, $opts = array()) {
+        $data = pack('f', (float)$value);
+    	$writer->putData($data, 4);
+    }
+    static function string($value, $opts = array()) {
+    	return sprintf("(Float)%f", $value);
+    }
+}

IO_SWF/tags/2.1.8-stable-20120220231502/IO/SWF/Type/GLYPHENTRY.php

@@ -0,0 +1,24 @@
+<?php
+
+/*
+ * 2011/8/22- (c) yoya@awm.jp
+ */
+
+require_once 'IO/Bit.php';
+require_once dirname(__FILE__).'/../Type.php';
+
+class IO_SWF_Type_GLYPHENTRY extends IO_SWF_Type {
+    static function parse(&$reader, $opts = array()) {
+    	$glyphentry = array();
+    	$glyphentry['GlyphIndex'] = $reader->getUIBits($opts['GlyphBits']);
+        $glyphentry['GlyphAdvance'] = $reader->getUIBits($opts['AdvanceBits']);
+    	return $glyphentry;
+    }
+    static function build(&$writer, $glyphentry, $opts = array()) {
+    	$writer->putUIBits($glyphentry['GlyphIndex'], $opts['GlyphBits']);
+    	$writer->putUIBits($glyphentry['GlyphAdvance'], $opts['AdvanceBits']);
+    }
+    static function string($glyphentry, $opts = array()) {
+    	return "GlyphIndex: {$glyphentry['GlyphIndex']} GlyphAdvance: {$glyphentry['GlyphAdvance']}";
+    }
+}
属性に変更があったパス: IO_SWF/tags/2.1.8-stable-20120220231502/IO/SWF/Type/GLYPHENTRY.php
___________________________________________________________________
追加: svn:keywords
+ Id
追加: svn:eol-style
+ native

IO_SWF/tags/2.1.8-stable-20120220231502/IO/SWF/Type/String.php

@@ -0,0 +1,30 @@
+<?php
+
+/*
+ * 2011/4/15- (c) yoya@awm.jp
+ */
+
+require_once 'IO/Bit.php';
+require_once dirname(__FILE__).'/../Type.php';
+
+class IO_SWF_Type_String extends IO_SWF_Type {
+    static function parse(&$reader, $opts = array()) {
+        $str = '';
+        while ($reader->hasNextData(1)) {
+            $c = $reader->getData(1);
+            if ($c === "\0") {
+                break;
+            }
+            $str .= $c;
+        }
+    	return $str;
+    }
+    static function build(&$writer, $str, $opts = array()) {
+        $strs = explode("\0", $str);
+        $str = $strs[0];
+        $writer->putData($str."\0", strlen($str) + 1);
+    }
+    static function string($str, $opts = array()) {
+    	return $str;
+    }
+}

IO_SWF/tags/2.1.8-stable-20120220231502/IO/SWF/Type/CLIPEVENTFLAGS.php

@@ -0,0 +1,56 @@
+<?php
+
+/*
+ * 2011/7/11- (c) yoya@awm.jp
+ */
+
+require_once 'IO/Bit.php';
+require_once dirname(__FILE__).'/../Type.php';
+
+class IO_SWF_Type_CLIPEVENTFLAGS extends IO_SWF_Type {
+    static $clipevent_list =  array(
+            'KeyUp', 'KeyDown', 'MouseUp', 'MouseDown', 'MouseMove',
+            'Unload', 'EnterFrame', 'Load', 'DragOver',
+            'RollOut', 'RollOver',
+            'ReleaseOutside', 'Release', 'Press', 'Initialize', 'Data');
+    static function parse(&$reader, $opts = array()) {
+    	$clipeventflags = array();
+        foreach (self::$clipevent_list as $key) {
+            $clipeventflags['ClipEvent'.$key] = $reader->getUIBit();
+        }
+        if ($opts['Version'] >= 6) {
+            $clipeventflags['Reserved'] = $reader->getUIBits(5);
+            $clipeventflags['ClipEventKeyConstruct'] = $reader->getUIBit();
+            $clipeventflags['ClipEventKeyPress'] = $reader->getUIBit();
+            $clipeventflags['ClipEventDragOut'] = $reader->getUIBit();
+            $clipeventflags['Reserved2'] = $reader->getUIBits(8);
+        }
+    	return $clipeventflags;
+    }
+    static function build(&$writer, $clipeventflags, $opts = array()) {
+        foreach (self::$clipevent_list as $key) {
+            $writer->putUIBit($clipeventflags['ClipEvent'.$key]);
+        }
+        if ($opts['Version'] >= 6) {
+            $writer->putUIBits($clipeventflags['Reserved'], 5);
+            $writer->putUIBit($clipeventflags['ClipEventConstruct']);
+            $writer->putUIBit($clipeventflags['ClipEventKeyPress']);
+            $writer->putUIBit($clipeventflags['ClipEventDragOut']);
+            $writer->putUIBits($clipeventflags['Reserved2'], 8);
+        }
+    }
+    static function string($clipeventflags, $opts = array()) {
+        $text = "ClipEvent: ";
+        if ($opts['Version'] <= 5) {
+            $clipevent_list = self::$clipevent_list;
+        } else {
+            $clipevent_list = self::$clipevent_list + array('Construct', 'KeyPress', 'DragOut');
+        }
+        foreach ($clipevent_list as $key) {
+            if ($clipeventflags['ClipEvent'.$key] == 1) {
+                $text .= $key.' ';
+            }
+        }
+    	return $text;
+    }
+}

IO_SWF/tags/2.1.8-stable-20120220231502/IO/SWF/Type/FILLSTYLEARRAY.php

@@ -0,0 +1,52 @@
+<?php
+
+/*
+ * 2011/4/15- (c) yoya@awm.jp
+ */
+
+require_once 'IO/Bit.php';
+require_once dirname(__FILE__).'/../Type.php';
+require_once dirname(__FILE__).'/FILLSTYLE.php';
+
+class IO_SWF_Type_FILLSTYLEARRAY extends IO_SWF_Type {
+    static function parse(&$reader, $opts = array()) {
+        $tagCode = $opts['tagCode'];
+        $fillStyles = array();
+
+        // FillStyle
+        $fillStyleCount = $reader->getUI8();
+        if (($tagCode > 2) && ($fillStyleCount == 0xff)) {
+           // DefineShape2 以降は 0xffff サイズまで扱える
+           $fillStyleCount = $reader->getUI16LE();
+        }
+        for ($i = 0 ; $i < $fillStyleCount ; $i++) {
+            $fillStyles[] = IO_SWF_Type_FILLSTYLE::parse($reader, $opts);
+        }
+        return $fillStyles;
+    }
+    static function build(&$writer, $fillStyles, $opts = array()) {
+        $tagCode = $opts['tagCode'];
+        $fillStyleCount = count($fillStyles);
+        if ($fillStyleCount < 0xff) {
+            $writer->putUI8($fillStyleCount);
+        } else {
+            $writer->putUI8(0xff);
+            if ($tagCode > 2) {
+                $writer->putUI16LE($fillStyleCount);
+            } else {
+                $fillStyleCount = 0xff; // DefineShape(1)
+            }
+        }
+        foreach ($fillStyles as $fillStyle) {
+            IO_SWF_Type_FILLSTYLE::build($writer, $fillStyle, $opts);
+        }
+        return true;
+    }
+    static function string($fillStyles, $opts = array()) {
+        $text = '';
+        foreach ($fillStyles as $fillStyle) {
+            $text .= IO_SWF_Type_FILLSTYLE::string($fillStyle, $opts);
+        }
+        return $text;
+    }
+}
属性に変更があったパス: IO_SWF/tags/2.1.8-stable-20120220231502/IO/SWF/Type/FILLSTYLEARRAY.php
___________________________________________________________________
追加: svn:keywords
+ Id
追加: svn:eol-style
+ native

IO_SWF/tags/2.1.8-stable-20120220231502/IO/SWF/Type/LINESTYLEARRAY.php

@@ -0,0 +1,53 @@
+<?php
+
+/*
+ * 2011/4/15- (c) yoya@awm.jp
+ */
+
+require_once 'IO/Bit.php';
+require_once dirname(__FILE__).'/../Type.php';
+require_once dirname(__FILE__).'/LINESTYLE.php';
+
+
+class IO_SWF_Type_LINESTYLEARRAY extends IO_SWF_Type {
+    static function parse(&$reader, $opts = array()) {
+        $tagCode = $opts['tagCode'];
+        $lineStyles = array();
+        // LineStyle
+        $lineStyleCount = $reader->getUI8();
+        if (($tagCode > 2) && ($lineStyleCount == 0xff)) {
+            // DefineShape2 以降は 0xffff サイズまで扱える
+            $lineStyleCount = $reader->getUI16LE();
+        }
+        for ($i = 0 ; $i < $lineStyleCount ; $i++) {
+            $lineStyles[] = IO_SWF_Type_LINESTYLE::parse($reader, $opts);
+        }
+        return $lineStyles;
+    }
+    static function build(&$writer, $lineStyles, $opts = array()) {
+        $tagCode = $opts['tagCode'];
+        $lineStyleCount = count($lineStyles);
+        if ($lineStyleCount < 0xff) {
+            $writer->putUI8($lineStyleCount);
+        } else {
+            $writer->putUI8(0xff);
+            if ($tagCode > 2) {
+                $writer->putUI16LE($lineStyleCount);
+            } else {
+                $lineStyleCount = 0xff; // DefineShape(1)
+            }
+        }
+        foreach ($lineStyles as $lineStyle) {
+            IO_SWF_Type_LINESTYLE::build($writer, $lineStyle, $opts);
+        }
+        return true;
+    }
+    static function string($lineStyles, $opts = array()) {
+        $tagCode = $opts['tagCode'];
+        $text = '';
+        foreach ($lineStyles as $lineStyle) {
+            $text .= IO_SWF_Type_LINESTYLE::string($lineStyle, $opts);
+        }
+        return $text;
+    }
+}
属性に変更があったパス: IO_SWF/tags/2.1.8-stable-20120220231502/IO/SWF/Type/LINESTYLEARRAY.php
___________________________________________________________________
追加: svn:keywords
+ Id
追加: svn:eol-style
+ native

IO_SWF/tags/2.1.8-stable-20120220231502/IO/SWF/Type/FILLSTYLE.php

@@ -0,0 +1,256 @@
+<?php
+
+/*
+ * 2011/4/15- (c) yoya@awm.jp
+ */
+
+require_once 'IO/Bit.php';
+require_once dirname(__FILE__).'/../Type.php';
+require_once dirname(__FILE__).'/../Exception.php';
+require_once dirname(__FILE__).'/../Type/MATRIX.php';
+require_once dirname(__FILE__).'/../Type/RGB.php';
+require_once dirname(__FILE__).'/../Type/RGBA.php';
+
+class IO_SWF_Type_FILLSTYLE extends IO_SWF_Type {
+    static function parse(&$reader, $opts = array()) {
+        $tagCode = $opts['tagCode'];
+        $isMorph = ($tagCode == 46) || ($tagCode == 84);
+
+        $fillStyle = array();
+        $fillStyleType = $reader->getUI8();
+        $fillStyle['FillStyleType'] = $fillStyleType;
+        switch ($fillStyleType) {
+          case 0x00: // solid fill
+            if ($isMorph === false) {
+                if ($tagCode < 32 ) { // 32:DefineShape3
+                    $fillStyle['Color'] = IO_SWF_Type_RGB::parse($reader);
+                } else {
+                    $fillStyle['Color'] = IO_SWF_Type_RGBA::parse($reader);
+                }
+            } else {
+                    $fillStyle['StartColor'] = IO_SWF_Type_RGBA::parse($reader);
+                    $fillStyle['EndColor'] = IO_SWF_Type_RGBA::parse($reader);
+            }
+            break;
+          case 0x10: // linear gradient fill
+          case 0x12: // radial gradient fill
+          case 0x13: // focal gradient fill // 8 and later
+            if ($isMorph === false) {
+                $fillStyle['GradientMatrix'] = IO_SWF_Type_MATRIX::parse($reader);
+            } else {
+                $fillStyle['StartGradientMatrix'] = IO_SWF_Type_MATRIX::parse($reader);
+                $fillStyle['EndGradientMatrix'] = IO_SWF_Type_MATRIX::parse($reader);
+            }
+            $reader->byteAlign();
+            if ($isMorph === false) {
+                $fillStyle['SpreadMode'] = $reader->getUIBits(2);
+                $fillStyle['InterpolationMode'] = $reader->getUIBits(2);
+                $numGradients = $reader->getUIBits(4);
+            } else {
+                $numGradients = $reader->getUI8();
+            }
+            $fillStyle['GradientRecords'] = array();
+            for ($j = 0 ; $j < $numGradients ; $j++) {
+                $gradientRecord = array();
+                if ($isMorph === false) {
+                    $gradientRecord['Ratio'] = $reader->getUI8();
+                    if ($tagCode < 32 ) { // 32:DefineShape3
+                        $gradientRecord['Color'] = IO_SWF_Type_RGB::parse($reader);
+                    } else {
+                        $gradientRecord['Color'] = IO_SWF_Type_RGBA::parse($reader);
+                    }
+                } else { // Morph
+                    $gradientRecord['StartRatio'] = $reader->getUI8();
+                    $gradientRecord['StartColor'] = IO_SWF_Type_RGBA::parse($reader);
+                    $gradientRecord['EndRatio'] = $reader->getUI8();
+                    $gradientRecord['EndColor'] = IO_SWF_Type_RGBA::parse($reader);
+                }
+                $fillStyle['GradientRecords'] []= $gradientRecord;
+            }
+            if ($fillStyleType == 0x13) { // focal gradient fill // 8 and later
+                $gradientRecord['FocalPoint'] = $reader->getUI8();
+            }
+            break;
+          case 0x40: // repeating bitmap fill
+          case 0x41: // clipped bitmap fill
+          case 0x42: // non-smoothed repeating bitmap fill
+          case 0x43: // non-smoothed clipped bitmap fill
+                $fillStyle['BitmapId'] = $reader->getUI16LE();
+            if ($isMorph === false) {
+                $fillStyle['BitmapMatrix'] = IO_SWF_Type_MATRIX::parse($reader);
+            } else {
+                $fillStyle['StartBitmapMatrix'] = IO_SWF_Type_MATRIX::parse($reader);
+                $fillStyle['EndBitmapMatrix'] = IO_SWF_Type_MATRIX::parse($reader);
+            }
+            break;
+          default:
+            throw new IO_SWF_Exception("Unknown FillStyleType=$fillStyleType tagCode=$tagCode");
+        }
+        return $fillStyle;
+    }
+    static function build(&$writer, $fillStyle, $opts = array()) {
+        $tagCode = $opts['tagCode'];
+        $isMorph = ($tagCode == 46) || ($tagCode == 84);
+
+        $fillStyleType = $fillStyle['FillStyleType'];
+        $writer->putUI8($fillStyleType);
+        switch ($fillStyleType) {
+          case 0x00: // solid fill
+            if ($isMorph === false) {
+                if ($tagCode < 32 ) { // 32:DefineShape3
+                    IO_SWF_Type_RGB::build($writer, $fillStyle['Color']);
+                } else {
+                    IO_SWF_Type_RGBA::build($writer, $fillStyle['Color']);
+                }
+            } else {
+                IO_SWF_Type_RGBA::build($writer, $fillStyle['StartColor']);
+                IO_SWF_Type_RGBA::build($writer, $fillStyle['EndColor']);
+            }
+            break;
+          case 0x10: // linear gradient fill
+          case 0x12: // radial gradient fill
+          case 0x13: // focal gradient fill // 8 and later
+            if ($isMorph === false) {
+                IO_SWF_Type_MATRIX::build($writer, $fillStyle['GradientMatrix']);
+            } else {
+                IO_SWF_Type_MATRIX::build($writer, $fillStyle['StartGradientMatrix']);
+                IO_SWF_Type_MATRIX::build($writer, $fillStyle['EndGradientMatrix']);
+            }
+            $writer->byteAlign();
+            if ($isMorph === false) {
+                $writer->putUIBits($fillStyle['SpreadMode'], 2);
+                $writer->putUIBits($fillStyle['InterpolationMode'], 2);
+                $numGradients = count($fillStyle['GradientRecords']);
+                $writer->putUIBits($numGradients , 4);
+            } else {
+                $numGradients = count($fillStyle['GradientRecords']);
+                $writer->putUI8($numGradients);
+            }
+            foreach ($fillStyle['GradientRecords'] as $gradientRecord) {
+                if ($isMorph === false) {
+                    $writer->putUI8($gradientRecord['Ratio']);
+                    if ($tagCode < 32 ) { // 32:DefineShape3
+                        IO_SWF_Type_RGB::build($writer, $gradientRecord['Color']);
+                    } else {
+                        IO_SWF_Type_RGBA::build($writer, $gradientRecord['Color']);
+                    }
+                } else {
+                    $writer->putUI8($gradientRecord['StartRatio']);
+                    IO_SWF_Type_RGBA::build($writer, $gradientRecord['StartColor']);
+                    $writer->putUI8($gradientRecord['EndRatio']);
+                    IO_SWF_Type_RGBA::build($writer, $gradientRecord['EndColor']);
+                }
+            }
+            if ($fillStyleType == 0x13) { // focal gradient fill // 8 and later
+                $writer->putUI8($gradientRecord['FocalPoint']);
+            }
+          break;
+          // case 0x13: // focal gradient fill // 8 and later
+          // break;
+          case 0x40: // repeating bitmap fill
+          case 0x41: // clipped bitmap fill
+          case 0x42: // non-smoothed repeating bitmap fill
+          case 0x43: // non-smoothed clipped bitmap fill
+            $writer->putUI16LE($fillStyle['BitmapId']);
+            if ($isMorph === false) {
+                IO_SWF_Type_MATRIX::build($writer, $fillStyle['BitmapMatrix']);
+            } else {
+                IO_SWF_Type_MATRIX::build($writer, $fillStyle['StartBitmapMatrix']);
+                IO_SWF_Type_MATRIX::build($writer, $fillStyle['EndBitmapMatrix']);
+            }
+            break;
+          default:
+            throw new IO_SWF_Exception("Unknown FillStyleType=$fillStyleType tagCode=$tagCode");
+        }
+        return true;
+    }
+    static function string($fillStyle, $opts = array()) {
+        $tagCode = $opts['tagCode'];
+        $isMorph = ($tagCode == 46) || ($tagCode == 84);
+
+        $text = '';
+        $fillStyleType = $fillStyle['FillStyleType'];
+        switch ($fillStyleType) {
+          case 0x00: // solid fill
+            if ($isMorph === false) {
+                $color = $fillStyle['Color'];
+                if ($tagCode < 32 ) { // 32:DefineShape3
+                    $color_str = IO_SWF_Type_RGB::string($color);
+                } else {
+                    $color_str = IO_SWF_Type_RGBA::string($color);
+                }
+                $text .= "\tsolid fill: $color_str\n";
+            } else{
+                $startColor = $fillStyle['StartColor'];
+                $endColor = $fillStyle['EndColor'];
+                $startColor_str = IO_SWF_Type_RGBA::string($startColor);
+                $endColor_str = IO_SWF_Type_RGBA::string($endColor);
+                $text .= "\tsolid fill: $startColor_str => $endColor_str\n";
+            }
+            break;
+          case 0x10: // linear gradient fill
+          case 0x12: // radial gradient fill
+            if ($fillStyleType == 0x10) {
+                $text .= "\tlinear gradient fill\n";
+            } else {
+                $text .= "\tradial gradient fill\n";
+            }
+            $opts = array('indent' => 2);
+            if ($isMorph === false) {
+                $matrix_str = IO_SWF_Type_MATRIX::string($fillStyle['GradientMatrix'], $opts);
+                $text .= $matrix_str . "\n";
+                $spreadMode = $fillStyle['SpreadMode'];
+                $interpolationMode = $fillStyle['InterpolationMode'];
+            } else {
+                $matrix_str = IO_SWF_Type_MATRIX::string($fillStyle['StartGradientMatrix'], $opts);
+                $matrix_str = IO_SWF_Type_MATRIX::string($fillStyle['EndGradientMatrix'], $opts);
+                $text .= $matrix_str . "\n";
+            }
+
+            foreach ($fillStyle['GradientRecords'] as $gradientRecord) {
+                if ($isMorph === false) {
+                    $ratio = $gradientRecord['Ratio'];
+                    $color = $gradientRecord['Color'];
+                    if ($tagCode < 32 ) { // 32:DefineShape3
+                        $color_str = IO_SWF_Type_RGB::string($color);
+                    } else {
+                        $color_str = IO_SWF_Type_RGBA::string($color);
+                    }
+                    $text .= "\t\tRatio: $ratio Color:$color_str\n";
+                } else {
+                    $startRatio = $gradientRecord['StartRatio'];
+                    $startColorStr = IO_SWF_Type_RGBA::string($gradientRecord['StartColor']);
+                    $endRatio   = $gradientRecord['EndRatio'];
+
+                    $endColorStr = IO_SWF_Type_RGBA::string($gradientRecord['EndColor']);
+                    $text .= "\t\tStart: Ratio:$startRatio Color:$startColorStr => End: Ratio:$endRatio Color:$endColorStr\n";
+                }
+            }
+            break;
+          case 0x40: // repeating bitmap fill
+          case 0x41: // clipped bitmap fill
+          case 0x42: // non-smoothed repeating bitmap fill
+          case 0x43: // non-smoothed clipped bitmap fill
+            $text .= "\tBigmap($fillStyleType): ";
+            $text .= "  BitmapId: ".$fillStyle['BitmapId']."\n";
+            if ($isMorph === false) {
+                $text .= "\tBitmapMatrix:\n";
+                $opts = array('indent' => 2);
+                $matrix_str = IO_SWF_Type_MATRIX::string($fillStyle['BitmapMatrix'], $opts);
+                $text .= $matrix_str . "\n";
+            } else {
+                $opts = array('indent' => 2);
+                $text .= "\tStartBitmapMatrix:\n";
+                $matrix_str = IO_SWF_Type_MATRIX::string($fillStyle['StartBitmapMatrix'], $opts);
+                $text .= $matrix_str . "\n";
+                $text .= "\tEndBitmapMatrix:\n";
+                $matrix_str = IO_SWF_Type_MATRIX::string($fillStyle['EndBitmapMatrix'], $opts);
+                $text .= $matrix_str . "\n";
+            }
+            break;
+          default:
+            $text .= "Unknown FillStyleType($fillStyleType)\n";
+        }
+        return $text;
+    }
+}
属性に変更があったパス: IO_SWF/tags/2.1.8-stable-20120220231502/IO/SWF/Type/FILLSTYLE.php
___________________________________________________________________
追加: svn:keywords
+ Id
追加: svn:eol-style
+ native

IO_SWF/tags/2.1.8-stable-20120220231502/IO/SWF/Type/LINESTYLE.php

@@ -0,0 +1,127 @@
+<?php
+
+/*
+ * 2011/4/15- (c) yoya@awm.jp
+ */
+
+require_once 'IO/Bit.php';
+require_once dirname(__FILE__).'/../Type.php';
+require_once dirname(__FILE__).'/../Type/RGB.php';
+require_once dirname(__FILE__).'/../Type/RGBA.php';
+
+class IO_SWF_Type_LINESTYLE extends IO_SWF_Type {
+    static function parse(&$reader, $opts = array()) {
+        $tagCode = $opts['tagCode'];
+        $isMorph = ($tagCode == 46) || ($tagCode == 84);
+        $lineStyle = array();
+        if ($isMorph === false) {
+            $lineStyle['Width'] = $reader->getUI16LE();
+            if ($tagCode == 83) { // DefineShape4
+                $lineStyle['StartCapStyle'] = $reader->getUIBits(2);
+                $lineStyle['JoinStyle'] = $reader->getUIBits(2);
+                $lineStyle['HasFillFlag'] = $reader->getUIBit();
+                $lineStyle['NoHScaleFlag'] = $reader->getUIBit();
+                $lineStyle['NoVScaleFlag'] = $reader->getUIBit();
+                $lineStyle['PixelHintingFlag'] = $reader->getUIBit();
+                // ----
+                $lineStyle['(Reserved)'] = $reader->getUIBits(5);
+                $lineStyle['NoClose'] = $reader->getUIBit();
+                $lineStyle['EndCapStyle'] = $reader->getUIBits(2);
+                if ($lineStyle['JoinStyle'] == 2) {
+                    $lineStyle['MiterLimitFactor'] = $reader->getUI16LE();
+                }
+            }
+            if ($tagCode < 32 ) { // DefineShape1,2
+                $lineStyle['Color'] = IO_SWF_Type_RGB::parse($reader);
+            } else if ($tagCode == 32) { // DefineShape3
+                $lineStyle['Color'] = IO_SWF_Type_RGBA::parse($reader);
+            } else { // DefineShape4
+                if ($lineStyle['HasFillFlag'] == 0) {
+                    $lineStyle['Color'] = IO_SWF_Type_RGBA::parse($reader);
+                } else {
+                    $lineStyle['FillType'] = IO_SWF_Type_FILLSTYLE::parse($reader, $opts);
+                }
+            }
+        } else {
+            $lineStyle['StartWidth'] = $reader->getUI16LE();
+            $lineStyle['EndWidth']   = $reader->getUI16LE();
+            $lineStyle['StartColor'] = IO_SWF_Type_RGBA::parse($reader);
+            $lineStyle['EndColor']   = IO_SWF_Type_RGBA::parse($reader);
+        }
+        return  $lineStyle;
+    }
+    static function build(&$writer, $lineStyle, $opts = array()) {
+        $tagCode = $opts['tagCode'];
+        $isMorph = ($tagCode == 46) || ($tagCode == 84);
+        if ($isMorph === false) {
+            $writer->putUI16LE($lineStyle['Width']);
+            if ($tagCode == 83) { // DefineShape4
+                $writer->putUIBits($lineStyle['StartCapStyle'], 2);
+                $writer->putUIBits($lineStyle['JoinStyle'], 2);
+                $writer->putUIBit($lineStyle['HasFillFlag']);
+                $writer->putUIBit($lineStyle['NoHScaleFlag']);
+                $writer->putUIBit($lineStyle['NoVScaleFlag']);
+                $writer->putUIBit($lineStyle['PixelHintingFlag']);
+                // ----
+                $writer->putUIBits(0, 5); //Reserved
+                $writer->putUIBit($lineStyle['NoClose']);
+                $writer->putUIBits($lineStyle['EndCapStyle'], 2);
+                if ($lineStyle['JoinStyle'] == 2) {
+                    $writer->putUI16LE($lineStyle['MiterLimitFactor']);
+                }
+            }
+            if ($tagCode < 32 ) { // DefineShape1,2
+                IO_SWF_Type_RGB::build($writer, $lineStyle['Color']);
+            } else if ($tagCode == 32) { // DefineShape3
+                IO_SWF_Type_RGBA::build($writer, $lineStyle['Color']);
+            } else { // DefineShape4
+                if ($lineStyle['HasFillFlag'] == 0) {
+                    IO_SWF_Type_RGBA::build($writer, $lineStyle['Color']);
+                } else {
+                    IO_SWF_Type_FILLSTYLE::build($writer, $lineStyle['FillType'], $opts);
+                }
+            }
+        } else {
+            $writer->putUI16LE($lineStyle['StartWidth']);
+            $writer->putUI16LE($lineStyle['EndWidth']);
+            IO_SWF_Type_RGBA::build($writer, $lineStyle['StartColor']);
+            IO_SWF_Type_RGBA::build($writer, $lineStyle['EndColor']);
+        }
+        return true;
+    }
+    static function string($lineStyle, $opts = array()) {
+        $tagCode = $opts['tagCode'];
+        $isMorph = ($tagCode == 46) || ($tagCode == 84);
+        $text = '';
+
+        if ($isMorph === false) {
+            $text .= "\tWidth:{$lineStyle['Width']}\n";
+            if ($tagCode == 83) { // DefineShape4
+                $text .= "\tStartCapStyle:{$lineStyle['StartCapStyle']} JoinStyle:{$lineStyle['JoinStyle']}\n";
+                $text .= "\tHasFillFlag:{$lineStyle['HasFillFlag']} NoHScaleFlag:{$lineStyle['NoHScaleFlag']} NoVScaleFlag:{$lineStyle['NoVScaleFlag']} PixelHintingFlag:{$lineStyle['PixelHintingFlag']}\n";
+            }
+            if ($tagCode < 32 ) { // DefineShape1,2
+                $color_str = IO_SWF_Type_RGB::string($lineStyle['Color']);
+                $text .= "Color: $color_str\n";
+            } else if ($tagCode == 32 ) { // DefineShape3
+                $color_str = IO_SWF_Type_RGBA::string($lineStyle['Color']);
+                $text .= "Color: $color_str\n";
+            } else { // DefineShape4
+                if ($lineStyle['HasFillFlag'] == 0) {
+                    $color_str = IO_SWF_Type_RGBA::string($lineStyle['Color']);
+                    $text .= "\tColor: $color_str\n";
+                } else {
+                    $filltype_str = IO_SWF_Type_FILLSTYLE::string($lineStyle['FillType']);
+                    $text .= "\tFillType: ".$filltype_str;
+                }
+            }
+        } else {
+            $startWidth = $lineStyle['StartWidth'];
+            $endWidth = $lineStyle['EndWidth'];
+            $startColorStr = IO_SWF_Type_RGBA::string($lineStyle['StartColor']);
+            $endColorStr = IO_SWF_Type_RGBA::string($lineStyle['EndColor']);
+            $text .= "\tWidth: $startWidth => $endWidth Color: $startColorStr => $endColorStr\n";
+        }
+        return $text;
+    }
+}
属性に変更があったパス: IO_SWF/tags/2.1.8-stable-20120220231502/IO/SWF/Type/LINESTYLE.php
___________________________________________________________________
追加: svn:keywords
+ Id
追加: svn:eol-style
+ native

IO_SWF/tags/2.1.8-stable-20120220231502/IO/SWF/Type/CLIPACTIONS.php

@@ -0,0 +1,57 @@
+<?php
+
+/*
+ * 2011/7/11- (c) yoya@awm.jp
+ */
+
+require_once 'IO/Bit.php';
+require_once dirname(__FILE__).'/../Type.php';
+require_once dirname(__FILE__).'/CLIPEVENTFLAGS.php';
+require_once dirname(__FILE__).'/CLIPACTIONRECORD.php';
+
+class IO_SWF_Type_CLIPACTIONS extends IO_SWF_Type {
+    static function parse(&$reader, $opts = array()) {
+    	$clipactions = array();
+        $clipactions['Reserved'] = $reader->getUI16LE(); // must be 0
+        $clipactions['AllEventFlags'] = IO_SWF_Type_CLIPEVENTFLAGS::parse($reader, $opts);
+        $clipActionRecords = array();
+        while (true) {
+            if ($opts['Version'] <= 5) {
+                if ($reader->getUI16LE() == 0) {
+                    break;
+                }
+                $reader->incrementOffset(-2, 0); // 2 bytes back
+            } else {
+                if ($reader->getUI32LE() == 0) {
+                    break;
+                }
+                $reader->incrementOffset(-4, 0); // 4 bytes back
+            }
+            $clipActionRecords []= IO_SWF_Type_CLIPACTIONRECORD::parse($reader, $opts);
+        }
+        $clipactions['ClipActionRecords'] = $clipActionRecords;
+    	return $clipactions;
+    }
+    static function build(&$writer, $clipactions, $opts = array()) {
+    	$writer->putUI16LE($clipactions['Reserved']); // must be 0
+        IO_SWF_Type_CLIPEVENTFLAGS::build($writer, $clipactions['AllEventFlags'], $opts);
+        foreach ($clipactions['ClipActionRecords'] as $clipActionRecord) {
+            IO_SWF_Type_CLIPACTIONRECORD::build($writer, $clipActionRecord, $opts);
+        }
+        if ($opts['Version'] <= 5) {
+            $writer->putUI16LE(0); // ClipActionEndFlag
+        } else {
+            $writer->putUI32LE(0); // ClipActionEndFlag
+        }
+    }
+    static function string($clipactions, $opts = array()) {
+        $text = 'ALLEventFlags: ';
+        $text .= IO_SWF_Type_CLIPEVENTFLAGS::string($clipactions['AllEventFlags'], $opts);
+        $text .= "\n";
+        $text .= "\tClipActionRecords:\n";
+        foreach ($clipactions['ClipActionRecords'] as $clipActionRecord) {
+            $text .= "\t".IO_SWF_Type_CLIPACTIONRECORD::string($clipActionRecord, $opts)."\n";
+        }
+    	return $text;
+    }
+}

IO_SWF/tags/2.1.8-stable-20120220231502/IO/SWF/Type/Double.php

@@ -0,0 +1,23 @@
+<?php
+
+/*
+ * 2011/6/27- (c) yoya@awm.jp
+ */
+
+require_once 'IO/Bit.php';
+require_once dirname(__FILE__).'/../Type.php';
+
+class IO_SWF_Type_Double extends IO_SWF_Type {
+    static function parse(&$reader, $opts = array()) {
+        $data = $reader->getData(8);
+	$unpacked_data = unpack('d', $data);
+    	return (double)$unpacked_data[1];
+    }
+    static function build(&$writer, $value, $opts = array()) {
+        $data = pack('d', (double)$value);
+    	$writer->putData($data, 8);
+    }
+    static function string($value, $opts = array()) {
+    	return sprintf("(Double)%d", $value);
+    }
+}

IO_SWF/tags/2.1.8-stable-20120220231502/IO/SWF/Type/BUTTONRECORD.php

@@ -0,0 +1,107 @@
+<?php
+
+/*
+ * 2011/7/9- (c) yoya@awm.jp
+ */
+
+require_once 'IO/Bit.php';
+require_once dirname(__FILE__).'/../Type.php';
+require_once dirname(__FILE__).'/CXFORM.php';
+require_once dirname(__FILE__).'/CXFORMWITHALPHA.php';
+require_once dirname(__FILE__).'/FILTERLIST.php';
+
+class IO_SWF_Type_BUTTONRECORD extends IO_SWF_Type {
+    static function parse(&$reader, $opts = array()) {
+    	$buttonrecord = array();
+        $reader->byteAlign();
+        $buttonrecord['ButtonReserved'] = $reader->getUIBits(2); // must be 0
+        $buttonHasBlendMode = $reader->getUIBit();
+        $buttonHasFilterList = $reader->getUIBit();
+        $buttonrecord['ButtonHasBlandMode'] = $buttonHasBlendMode;
+        $buttonrecord['ButtonHasFilterList'] = $buttonHasFilterList;
+
+        $buttonrecord['ButtonStateHitTest'] = $reader->getUIBit();
+        $buttonrecord['ButtonStateDown'] = $reader->getUIBit();
+        $buttonrecord['ButtonStateOver'] = $reader->getUIBit();
+        $buttonrecord['ButtonStateUp'] = $reader->getUIBit();
+
+        $buttonrecord['CharacterID'] = $reader->getUI16LE();
+        $buttonrecord['PlaceDepth'] = $reader->getUI16LE();
+        $buttonrecord['PlaceMatrix'] = IO_SWF_Type_MATRIX::parse($reader);
+        if ($opts['tagCode'] == 34) { // DefineButton2
+            $buttonrecord['ColorTransform'] = IO_SWF_Type_CXFORMWITHALPHA::parse($reader);
+        } else {
+            $buttonrecord['ColorTransform'] = IO_SWF_Type_CXFORM::parse($reader);
+        }
+        if (($opts['tagCode'] == 34) && ($opts['Version'] >= 8)) {
+            // DefineButton2 & SWF8 later
+            if ($buttonHasFilterList == 1) {
+                $buttonrecord['FilterList'] = IO_SWF_Type_FILTERLIST::parse($reader);
+            }
+            if ($buttonHasBlendMode == 1) {
+                $buttonrecord['BlendMode'] = $reader->getUI8();
+            }
+        }
+    	return $buttonrecord;
+    }
+
+    static function build(&$writer, $buttonrecord, $opts = array()) {
+        $writer->byteAlign();
+        $writer->putUIBits(0, 2); // ButtonReserved
+        $buttonHasBlendMode = $buttonrecord['ButtonHasBlandMode'];
+        $buttonHasFilterList = $buttonrecord['ButtonHasFilterList'];
+        $writer->putUIBit($buttonHasBlendMode);
+        $writer->putUIBit($buttonHasFilterList);
+        $writer->putUIBit($buttonrecord['ButtonStateHitTest']);
+        $writer->putUIBit($buttonrecord['ButtonStateDown']);
+        $writer->putUIBit($buttonrecord['ButtonStateOver']);
+        $writer->putUIBit($buttonrecord['ButtonStateUp']);
+        //
+        $writer->putUI16LE($buttonrecord['CharacterID']);
+        $writer->putUI16LE($buttonrecord['PlaceDepth']);
+        IO_SWF_Type_MATRIX::build($writer, $buttonrecord['PlaceMatrix']);
+        if ($opts['tagCode'] == 34) { // DefineButton2
+            IO_SWF_Type_CXFORMWITHALPHA::build($writer, $buttonrecord['ColorTransform']);
+        } else {
+            IO_SWF_Type_CXFORM::build($writer, $buttonrecord['ColorTransform']);
+        }
+        if (($opts['tagCode'] == 34) && ($opts['Version'] >= 8)) {
+            // DefineButton2 & SWF8 later
+            if ($buttonHasFilterList == 1) {
+                IO_SWF_Type_FILTERLIST::build($writer, $buttonrecord['FilterList']);
+            }
+            if ($buttonHasBlendMode == 1) {
+                $writer->putUI8($buttonrecord['BlendMode']);
+            }
+        }
+    }
+    static function string($buttonrecord, $opts = array()) {
+        $text = '';
+        $buttonHasBlendMode = $buttonrecord['ButtonHasBlandMode'];
+        $buttonHasFilterList = $buttonrecord['ButtonHasFilterList'];
+        $text .= "HasBlandMode:".$buttonrecord['ButtonHasBlandMode'].' HasFilterList:'. $buttonrecord['ButtonHasFilterList']."\n\t\t";
+        foreach (array('StateHitTest', 'StateDown', 'StateOver', 'StateUp') as $label) {
+            $text .= $label.':'.$buttonrecord['Button'.$label].' ';
+        }
+        $text .= "\n\t\t";
+        $text .= "CharacterID:{$buttonrecord['CharacterID']} PlaceDepth:{$buttonrecord['PlaceDepth']}";
+        $text .= "\n";
+        $opts['indent']++;
+        $text .= IO_SWF_Type_MATRIX::string($buttonrecord['PlaceMatrix'], $opts)."\n";
+        if ($opts['tagCode'] == 34) { // DefineButton2
+            $text .= "\t\tColorTransform:". IO_SWF_Type_CXFORMWITHALPHA::string($buttonrecord['ColorTransform']).' ';
+        } else {
+            $text .= 'ColorTransform:'.IO_SWF_Type_CXFORM::string($buttonrecord['ColorTransform']).' ';
+        }
+        if (($opts['tagCode'] == 34) && ($opts['Version'] >= 8)) {
+            // DefineButton2 & SWF8 later
+            if ($buttonHasFilterList == 1) {
+                $text .= 'FilterList:'.IO_SWF_Type_FILTERLIST::string($buttonrecord['FilterList'])."\n";
+            }
+            if ($buttonHasBlendMode == 1) {
+                $text .= 'BlendMode:'.$buttonrecord['BlendMode']."\n";
+            }
+        }
+        return $text;
+    }
+}
属性に変更があったパス: IO_SWF/tags/2.1.8-stable-20120220231502/IO/SWF/Type/BUTTONRECORD.php
___________________________________________________________________
追加: svn:keywords
+ Id
追加: svn:eol-style
+ native

IO_SWF/tags/2.1.8-stable-20120220231502/IO/SWF/Type/RGB.php

@@ -0,0 +1,26 @@
+<?php
+
+/*
+ * 2011/4/15- (c) yoya@awm.jp
+ */
+
+require_once 'IO/Bit.php';
+require_once dirname(__FILE__).'/../Type.php';
+
+class IO_SWF_Type_RGB extends IO_SWF_Type {
+    static function parse(&$reader, $opts = array()) {
+    	$rgb = array();
+    	$rgb['Red'] = $reader->getUI8();
+    	$rgb['Green'] = $reader->getUI8();
+    	$rgb['Blue'] = $reader->getUI8();
+    	return $rgb;
+    }
+    static function build(&$writer, $rgb, $opts = array()) {
+    	$writer->putUI8($rgb['Red']);
+    	$writer->putUI8($rgb['Green']);
+    	$writer->putUI8($rgb['Blue']);
+    }
+    static function string($color, $opts = array()) {
+    	return sprintf("#%02x%02x%02x", $color['Red'], $color['Green'], $color['Blue']);
+    }
+}
属性に変更があったパス: IO_SWF/tags/2.1.8-stable-20120220231502/IO/SWF/Type/RGB.php
___________________________________________________________________
追加: svn:keywords
+ Id
追加: svn:eol-style
+ native

IO_SWF/tags/2.1.8-stable-20120220231502/IO/SWF/Type/RGBA.php

@@ -0,0 +1,28 @@
+<?php
+
+/*
+ * 2011/4/15- (c) yoya@awm.jp
+ */
+
+require_once 'IO/Bit.php';
+require_once dirname(__FILE__).'/../Type.php';
+
+class IO_SWF_Type_RGBA extends IO_SWF_Type {
+    static function parse(&$reader, $opts = array()) {
+    	$rgba = array();
+    	$rgba['Red'] = $reader->getUI8();
+    	$rgba['Green'] = $reader->getUI8();
+    	$rgba['Blue'] = $reader->getUI8();
+    	$rgba['Alpha'] = $reader->getUI8();
+    	return $rgba;
+    }
+    static function build(&$writer, $rgba, $opts = array()) {
+    	$writer->putUI8($rgba['Red']);
+	    $writer->putUI8($rgba['Green']);
+    	$writer->putUI8($rgba['Blue']);
+    	$writer->putUI8($rgba['Alpha']);
+    }
+    static function string($color, $opts = array()) {
+    	return sprintf("#%02x%02x%02x(%02x)", $color['Red'], $color['Green'], $color['Blue'], $color['Alpha']);
+    }
+}
属性に変更があったパス: IO_SWF/tags/2.1.8-stable-20120220231502/IO/SWF/Type/RGBA.php
___________________________________________________________________
追加: svn:keywords
+ Id
追加: svn:eol-style
+ native

IO_SWF/tags/2.1.8-stable-20120220231502/IO/SWF/Type/LANGCODE.php

@@ -0,0 +1,37 @@
+<?php
+
+/*
+ * 2011/4/15- (c) yoya@awm.jp
+ */
+
+require_once 'IO/Bit.php';
+require_once dirname(__FILE__).'/../Type.php';
+
+class IO_SWF_Type_LANGCODE extends IO_SWF_Type {
+    static function parse(&$reader, $opts = array()) {
+    	$langcode = array();
+    	$langcode['LanguageCode'] = $reader->getUI8();
+    	return $langcode;
+    }
+    static function build(&$writer, $langcode, $opts = array()) {
+    	$writer->putUI8($langcode['LanguageCode']);
+    }
+    static function string($langcode, $opts = array()) {
+        $languageCode = $langcode['LanguageCode'];
+        switch ($languageCode) {
+        case 1:
+            $language = 'Latin';
+        case 2:
+            $language = 'Japanese';
+        case 3:
+            $language = 'Korean';
+        case 4:
+            $language = 'Simplified Chinese';
+        case 5:
+            $language = 'Traditional Chinese';
+        default:
+            $language = 'Unknown';
+        }
+        return "$languageCode($language)";
+    }
+}
属性に変更があったパス: IO_SWF/tags/2.1.8-stable-20120220231502/IO/SWF/Type/LANGCODE.php
___________________________________________________________________
追加: svn:keywords
+ Id
追加: svn:eol-style
+ native

IO_SWF/tags/2.1.8-stable-20120220231502/IO/SWF/Type/BUTTONCONDACTION.php

@@ -0,0 +1,68 @@
+<?php
+
+/*
+ * 2011/4/15- (c) yoya@awm.jp
+ */
+
+require_once 'IO/Bit.php';
+require_once dirname(__FILE__).'/../Type.php';
+
+class IO_SWF_Type_BUTTONCONDACTION extends IO_SWF_Type {
+    static $buttoncond_list =  array(
+        'IdleToOverDown', 'OutDownToIdle', 'OutDownToOverDown',
+        'OverDownToOutDown', 'OverDownToOverUp', 'OverUpToOverDown',
+        'OverUpToIdle', 'IdleToOverUp');
+    static function parse(&$reader, $opts = array()) {
+        $condAction = array();
+        $condAction['CondActionSize'] = $reader->getUI16LE();
+        foreach (self::$buttoncond_list as $key) {
+            $condAction['Cond'.$key] = $reader->getUIBit();
+        }
+        $condAction['CondKeyPress'] = $reader->getUIBits(7);
+        $condAction['CondOverDownToIdle'] = $reader->getUIBit();
+        if ($reader->hasNextData()) { // XXX (depends on ActionOffset
+            $actions = array();
+            while ($reader->getUI8() != 0) {
+                $reader->incrementOffset(-1, 0); // 1 byte back
+                $actions []= IO_SWF_Type_Action::parse($reader);
+            }
+            $condAction['Actions'] = $actions;
+        }
+    	return $condAction;
+    }
+    static function build(&$writer, $condAction, $opts = array()) {
+        list($offset_condAction, $dummy) = $writer->getOffset();
+        $writer->putUI16LE(0);
+        foreach (self::$buttoncond_list as $key) {
+            $writer->putUIBit($condAction['Cond'.$key]);
+        }
+        $writer->putUIBits($condAction['CondKeyPress'], 7);
+        $writer->putUIBit($condAction['CondOverDownToIdle']);
+        foreach ($condAction['Actions'] as $action) {
+            IO_SWF_Type_Action::build($writer, $action);
+        }
+        $writer->putUI8(0); // terminate
+        if ($opts['lastAction'] === false) {
+            list($offset_next, $dummy) = $writer->getOffset();
+            $writer->setUI16LE($offset_next - $offset_condAction, $offset_condAction);
+        }
+        return true;
+    }
+    static function string($condAction, $opts = array()) {
+        $text = "\tBUTTONCONDACTION (CondActionSize:{$condAction['CondActionSize']})\n";
+
+        $text .= "\t\tCondAction: ";
+        foreach (self::$buttoncond_list as $key) {
+            $text .= " $key:".$condAction['Cond'.$key];
+        }
+        $text .= "\n";
+        $text .= "\t\tCondKeyPress:".$condAction['CondKeyPress']." CondOverDownToIdle:".$condAction['CondOverDownToIdle']."\n";
+
+
+        $text .= "\t\tActions:\n";
+        foreach ($condAction['Actions'] as $action) {
+            $text .= "\t\t\t".IO_SWF_Type_Action::string($action, $opts)."\n";
+        }
+        return $text;
+    }
+}
属性に変更があったパス: IO_SWF/tags/2.1.8-stable-20120220231502/IO/SWF/Type/BUTTONCONDACTION.php
___________________________________________________________________
追加: svn:keywords
+ Id
追加: svn:eol-style
+ native

IO_SWF/tags/2.1.8-stable-20120220231502/IO/SWF/Type/Action.php

@@ -0,0 +1,467 @@
+<?php
+
+/*
+ * 2011/06/03- (c) yoya@awm.jp
+ */
+
+require_once 'IO/Bit.php';
+require_once dirname(__FILE__).'/../Type.php';
+require_once dirname(__FILE__).'/String.php';
+require_once dirname(__FILE__).'/Float.php';
+require_once dirname(__FILE__).'/Double.php';
+
+class IO_SWF_Type_Action extends IO_SWF_Type {
+    static $action_code_table = array(
+        //
+        // ActionCode only
+        //
+        0x04 => 'NextFrame',
+        0x05 => 'PreviousFrame',
+        0x06 => 'Play',
+        0x07 => 'Stop',
+        0x08 => 'ToggleQuality',
+        0x09 => 'StopSounds',
+        //
+        0x0A => 'Add',
+        0x0B => 'Subtract',
+        0x0C => 'Multiply',
+        0x0D => 'Divide',
+        0x0E => 'Equals',
+        0x0F => 'Less',
+        0x10 => 'And',
+        0x11 => 'Or',
+        0x12 => 'Not',
+        0x13 => 'StringEquals',
+        0x14 => 'StringLength',
+        0x15 => 'StringExtract',
+        //
+        0x17 => 'Pop',
+        0x18 => 'ToInteger',
+        //
+        0x1C => 'GetVariable',
+        0x1D => 'SetVariable',
+        //
+        0x20 => 'SetTarget2',
+        0x21 => 'StringAdd',
+        0x22 => 'GetProperty',
+        0x23 => 'SetProperty',
+        0x24 => 'CloneSprite',
+        0x25 => 'RemoveSprite',
+        0x26 => 'Trace',
+        //
+        0x2D => 'FSCommand2',// Flash Lite
+        //
+        0x27 => 'StartDrag',
+        0x28 => 'EndDrag',
+        0x29 => 'StringLess',
+        //
+        0x30 => 'RandomNumber',
+        0x31 => 'MBStringLength',
+        0x32 => 'CharToAscii',
+        0x33 => 'AsciiToChar',
+        0x34 => 'GetTime',
+        0x35 => 'MBStringExtract',
+        0x36 => 'MBCharToAscii',
+        0x37 => 'MBAsciiToChar',
+        //
+        0x3A => 'Delete', // SWF 5
+        0x3B => 'Delete2', // SWF 5
+        0x3C => 'DefineLocal', // SWF 5
+        0x3D => 'CallFunction', // SWF 5
+        0x3E => 'Return', // SWF 5
+        0x3F => 'Modulo', // SWF 5
+        0x40 => 'NewObject', // SWF 5
+        0x41 => 'DefineLocal2', // SWF 5
+        0x42 => 'InitArray', // SWF 5
+        0x43 => 'InitObject', // SWF 5
+        0x44 => 'TypeOf', // SWF 5
+        0x45 => 'TargetPath', // SWF 5
+        0x46 => 'Enumerate', // SWF 5
+        0x47 => 'Add2', // SWF 5
+        0x48 => 'Less2', // SWF 5
+        0x49 => 'Equals2', // SWF 5
+        0x4A => 'ToNumber', // SWF 5
+        0x4B => 'ToString', // SWF 5
+        0x4C => 'PushDuplicate', // SWF 5
+        0x4D => 'StackSwap', // SWF 5
+        0x4E => 'GetMember', // SWF 5
+        0x4F => 'SetMember', // SWF 5
+        0x50 => 'Increment', // SWF 5
+        0x51 => 'Decrement', // SWF 5
+        0x52 => 'CallMethod', // SWF 5
+        0x53 => 'NewMethod', // SWF 5
+        0x54 => 'InstanceOf', // SWF 6
+        0x55 => 'Enumerate2', // SWF 6
+	//
+        0x60 => 'BitAnd', // SWF 5
+        0x61 => 'BitOr', // SWF 5
+        0x62 => 'BitXOr', // SWF 5
+        0x63 => 'BitShift', // SWF 5
+        0x64 => 'BitURShift', // SWF 5
+	//
+        0x66 => 'StrictEquals', // SWF 6
+        0x67 => 'Greater', // SWF 6
+        0x68 => 'StringGreater', // SWF 6
+        //
+        // has Data Payload
+        //
+        0x81 => 'GotoFrame',
+        0x83 => 'GetURL',
+        0x87 => 'StoreRegister', // SWF 5
+        0x88 => 'ConstantPool', // SWF 5
+        0x8A => 'WaitForFrame',
+        0x8B => 'SetTarget',
+        0x8C => 'GoToLabel',
+        0x8D => 'WaitForFrame2',
+        //
+        0x94 => 'With', // SWF 5
+        0x96 => 'Push',
+        //
+        0x99 => 'Jump',
+        0x9A => 'GetURL2',
+        0x9B => 'DefineFunction', // SWF 5
+        //
+        0x9D => 'If',
+        0x9E => 'Call', // why it >=0x80 ?
+        0x9F => 'GotoFrame2',
+        );
+    static function getCodeName($code) {
+        if (isset(self::$action_code_table[$code])) {
+            return self::$action_code_table[$code];
+        } else {
+            return "Unknown";
+        }
+    }
+    static function parse(&$reader, $opts = array()) {
+            $action = array();
+        $code = $reader->getUI8();
+        $action['Code'] = $code;
+        if ($code >= 0x80) {
+            $length = $reader->getUI16LE();
+            $action['Length'] = $length;
+            switch ($code) {
+              case 0x81: // ActionGotoFrame
+                $action['Frame'] = $reader->getUI16LE();
+                break;
+              case 0x83: // ActionGetURL
+                $data = $reader->getData($length);
+                $strs = explode("\0", $data, 2+1);
+                $action['UrlString'] = $strs[0];
+                $action['TargetString'] = $strs[1];
+                break;
+              case 0x88: // ActionConstantPool
+                $count = $reader->getUI16LE();
+                $action['Count'] = $count;
+                $data = $reader->getData($length - 2);
+                $strs = explode("\0", $data, $count+1);
+                $action['ConstantPool'] = array_splice($strs, 0, $count);
+                break;
+              case 0x8A: // ActionWaitForFrame
+                $action['Frame'] = $reader->getUI16LE();
+                $action['SkipCount'] = $reader->getUI8();
+                break;
+              case 0x8B: // ActionSetTarget
+                $data = $reader->getData($length);
+                $strs = explode("\0", $data, 1+1);
+                $action['TargetName'] = $strs[0];
+                break;
+              case 0x8C: // ActionSetTarget
+                $data = $reader->getData($length);
+                $strs = explode("\0", $data, 1+1);
+                $action['Label'] = $strs[0];
+                break;
+              case 0x8D: // ActionWaitForFrame2
+                $action['Frame'] = $reader->getUI16LE();
+                $action['SkipCount'] = $reader->getUI8();
+                break;
+              case 0x96: // ActionPush
+                $data = $reader->getData($length);
+                $values = array();
+                $values_reader = new IO_Bit();
+                $values_reader->input($data);
+                while ($values_reader->hasNextData()) {
+                    $value = array();
+                    $type = $values_reader->getUI8();
+                    $value['Type'] = $type;
+                    switch ($type) {
+                      case 0: // STRING
+                        $value['String'] = IO_SWF_Type_String::parse($values_reader);
+                        break;
+                      case 1: // Float
+                        $value['Float'] = IO_SWF_Type_Float::parse($values_reader);
+                        break;
+                      case 2: // null
+                      $value['null'] = null;
+                        break;
+                      case 3: // undefined
+                      $value['undefined'] = null;
+                        break;
+                      case 4: // RegisterNumber
+                        $value['RegisterNumber'] = $values_reader->getUI8();
+                        break;
+                      case 5: // Boolean
+                        $value['Boolean'] = $values_reader->getUI8();
+                        break;
+                      case 6: // Double
+                        $value['Double'] = IO_SWF_Type_Double::parse($values_reader);
+                        break;
+                      case 7: // Integer
+                        $value['Integer'] = $values_reader->getUI32LE();
+                        break;
+                      case 8: // Constant8
+                        $value['Constant8'] = $values_reader->getUI8();
+                        break;
+                      case 9: // Constant16
+                        $value['Constant16'] = $values_reader->getUI16LE();
+                        break;
+                      default:
+                        throw new IO_SWF_Exception("Illegal ActionPush value's type($type)");
+                    }
+                    $values[] = $value;
+                }
+                $action['Values'] = $values;
+                break;
+              case 0x99: // ActionJump
+                $action['BranchOffset'] = $reader->getSI16LE();
+                break;
+              case 0x9A: // ActionGetURL2
+//                $action['SendVarsMethod'] = $reader->getUIBits(2);
+//                $action['(Reserved)'] = $reader->getUIBits(4);
+//                $action['LoadTargetFlag'] = $reader->getUIBit();
+//                $action['LoadVariablesFlag'] = $reader->getUIBit();
+                // swf_file_format_spec_v10 bug, field reverse.
+                $action['LoadVariablesFlag'] = $reader->getUIBit();
+                $action['LoadTargetFlag'] = $reader->getUIBit();
+                $action['(Reserved)'] = $reader->getUIBits(4);
+                $action['SendVarsMethod'] = $reader->getUIBits(2);
+                break;
+              case 0x9D: // ActionIf
+                $action['Offset'] = $reader->getSI16LE();
+                break;
+              case 0x9F: // ActionGotoFrame2
+                $action['(Reserved)'] = $reader->getUIBits(6);
+                $sceneBlasFlag = $reader->getUIBit();
+                $action['SceneBlasFlag'] = $sceneBlasFlag;
+                $action['PlayFlag'] =  $reader->getUIBit();
+                if ($sceneBlasFlag == 1) {
+                    $action['SceneBias'] = $reader->getUI16LE();
+                }
+                break;
+              default:
+                if ($length > 0) {
+                    $action['Data'] =  $reader->getData($length);
+                }
+                break;
+            }
+        }
+            return $action;
+    }
+    static function build(&$writer, $action, $opts = array()) {
+        $code = $action['Code'];
+            $writer->putUI8($code);
+        if (0x80 <= $code) {
+            switch ($code) {
+              case 0x81: // ActionGotoFrame
+                $writer->putUI16LE(2);
+                $writer->putUI16LE($action['Frame']);
+                break;
+              case 0x83: // ActionGetURL
+                $data = $action['UrlString']."\0".$action['TargetString']."\0";
+                $writer->putUI16LE(strlen($data));
+                $writer->putData($data);
+                break;
+              case 0x88: // ActionConstantPool
+                $count = count($action['ConstantPool']);
+                $data = implode("\0", $action['ConstantPool'])."\0";
+                $writer->putUI16LE(strlen($data) + 2);
+                $writer->putUI16LE($count);
+                $writer->putData($data);
+                break;
+              case 0x8A: // ActionWaitForFrame
+                $writer->putUI16LE($action['Frame']);
+                $writer->putUI8($action['SkipCount']);
+                break;
+              case 0x8B: // ActionSetTarget
+                $data = $action['TargetName']."\0";
+                $writer->putUI16LE(strlen($data));
+                $writer->putData($data);
+                break;
+              case 0x8C: // ActionGoToLabel
+                $data = $action['Label']."\0";
+                $writer->putUI16LE(strlen($data));
+                $writer->putData($data);
+                break;
+              case 0x8D: // ActionWaitForFrame2
+                $writer->putUI16LE($action['Frame']);
+                $writer->putUI8($action['SkipCount']);
+                break;
+              case 0x96: // ActionPush
+                $values_writer = new IO_Bit();
+                foreach ($action['Values'] as $value) {
+                    $type = $value['Type'];
+                    $values_writer->putUI8($type);
+                    switch ($type) {
+                      case 0: // STRING
+                        $str = $value['String'];
+                        $pos = strpos($str, "\0");
+                        if ($pos === false) {
+                            $str .= "\0";
+                        } else {
+                            $str = substr($str, 0, $pos + 1);
+                        }
+                        $values_writer->putData($str);
+                        break;
+                      case 1: // Float
+                        IO_SWF_Type_Float::build($values_writer, $value['Float']);
+                        break;
+                      case 2: // null
+                        // nothing to do.
+                        break;
+                      case 3: // undefined
+                        // nothing to do.
+                        break;
+                      case 4: // RegisterNumber
+                        $values_writer->putUI8($value['RegisterNumber']);
+                        break;
+                      case 5: // Boolean
+                        $values_writer->putUI8($value['Boolean']);
+                        break;
+                      case 6: // Double
+                        IO_SWF_Type_Double::build($values_writer, $value['Double']);
+                        break;
+                      case 7: // Integer
+                        $values_writer->putUI32LE($value['Integer']);
+                        break;
+                      case 8: // Constant8
+                        $values_writer->putUI8($value['Constant8']);
+                        break;
+                      case 9: // Constant16
+                        $values_writer->putUI16LE($value['Constant16']);
+                        break;
+                      default:
+                        throw new IO_SWF_Exception("Illegal ActionPush value's type($type)");
+                        break;
+                    }
+                }
+                $values_data = $values_writer->output();
+                $writer->putUI16LE(strlen($values_data));
+                $writer->putData($values_data);
+                break;
+              case 0x99: // ActionJump
+                $writer->putUI16LE(2);
+                $writer->putSI16LE($action['BranchOffset']);
+                break;
+              case 0x9A: // ActionGetURL2
+                $writer->putUI16LE(1);
+//                $writer->putUIBits($action['SendVarsMethod'], 2);
+//                $writer->putUIBits(0, 4); // Reserved
+//                $writer->putUIBit($action['LoadTargetFlag']);
+//                $writer->putUIBit($action['LoadVariablesFlag']);
+                // swf_file_format_spec_v10 bug, field reverse.
+                $writer->putUIBit($action['LoadVariablesFlag']);
+                $writer->putUIBit($action['LoadTargetFlag']);
+                $writer->putUIBits(0, 4); // Reserved
+                $writer->putUIBits($action['SendVarsMethod'], 2);
+                break;
+              case 0x9D: // ActionIf
+                $writer->putUI16LE(2);
+                $writer->putSI16LE($action['Offset']);
+                break;
+              case 0x9F: // ActionGotoFrame2
+                if (isset($action['SceneBias'])) {
+                    $sceneBlasFlag = 1;
+                    $writer->putUI16LE(3);
+                } else {
+                    $sceneBlasFlag = 0;
+                    $writer->putUI16LE(1);
+                }
+                $writer->putUIBits(0, 6); // Reserved
+                $writer->putUIBit($sceneBlasFlag);
+                $writer->putUIBit($action['PlayFlag']);
+                if ($sceneBlasFlag) {
+                    $writer->putUI16LE($action['SceneBias']);
+                }
+                break;
+              default:
+                if (isset($action['Data'])) {
+                    $data = $action['Data'];
+                    $writer->putUI16LE(strlen($data));
+                    $writer->putData($data);
+                } else {
+                    $writer->putUI16LE(0);
+                }
+                break;
+            }
+        }
+    }
+    static function string($action, $opts = array()) {
+        $code = $action['Code'];
+        $str = sprintf('%s(Code:0x%02X)', self::getCodeName($code), $code);
+        if (isset($action['Length'])) {
+            $str .= " (Length:{$action['Length']})";
+            switch ($code) {
+              case 0x88: // ActonConstantPool
+                $str .= " Count=".$action['Count'].PHP_EOL;
+                foreach ($action['ConstantPool'] as $idx => $c) {
+                    $str .= "\t[$idx] $c".PHP_EOL;
+                }
+                break;
+              case 0x96: // ActonPush
+                foreach ($action['Values'] as $value) {
+                  unset($value['Type']);
+                  list($type_name) = array_keys($value);
+                  $str .= " ($type_name)".$value[$type_name];
+                }
+                break;
+              default:
+                $data_keys = array_diff(array_keys($action), array('Code', 'Length'));
+                if (count($data_keys) > 0) {
+                    foreach ($data_keys as $key) {
+                        $value = $action[$key];
+                        if (is_array($value)) {
+                            $new_value = array();
+                            foreach ($value as $k => $v) {
+                                $new_value[] = "$k:$v";
+                            }
+                            $value = implode(' ', $new_value);
+                        }
+                        $str .= " " ."$key=$value";
+                    }
+                }
+                break;
+            }
+        }
+        return $str;
+    }
+    function replaceActionString(&$action, $trans_table) {
+        switch($action['Code']) {
+          case 0x83: // ActionGetURL
+            ;
+            if (isset($trans_table[$action['UrlString']])) {
+                $action['UrlString'] = $trans_table[$action['UrlString']];
+            }
+            if (isset($trans_table[$action['TargetString']])) {
+                $action['TargetString'] = $trans_table[$action['TargetString']];
+            }
+            break;
+          case 0x88: // ActionConstantPool
+            foreach ($action['ConstantPool'] as $idx_cp => $cp) {
+                if (isset($trans_table[$cp])) {
+                    $action['ConstantPool'][$idx_cp] = $trans_table[$cp];
+                }
+            }
+            break;
+          case 0x96: // ActionPush
+            foreach ($action['Values'] as &$value) {
+                if ($value['Type'] == 0) { // Type String
+                    if (isset($trans_table[$value['String']])) {
+                        $value['String'] = $trans_table[$value['String']];
+                    }
+                }
+            }
+            unset($value);
+            break;
+        }
+        return true;
+    }
+}

IO_SWF/tags/2.1.8-stable-20120220231502/IO/SWF/Type/FILTERLIST.php

@@ -0,0 +1,37 @@
+<?php
+
+/*
+ * 2011/9/9- (c) yoya@awm.jp
+ */
+
+require_once 'IO/Bit.php';
+require_once dirname(__FILE__).'/../Type.php';
+require_once dirname(__FILE__).'/FILTER.php';
+
+class IO_SWF_Type_FILTERLIST extends IO_SWF_Type {
+    static function parse(&$reader, $opts = array()) {
+    	$filterlist = array();
+    	$NumberOfFilters = $reader->getUI8();
+    	$filterlist['NumberOfFilters'] = $NumberOfFilters;
+        $filter = array();
+        for ($i = 0 ; $i < $NumberOfFilters ; $i++) {
+            $filter []= IO_SWF_Type_FILTER::parse($reader, $opts);
+        }
+        $filterlist['Filter'] = $filter;
+    	return $filterlist;
+    }
+    static function build(&$writer, $filterlist, $opts = array()) {
+        $NumberOfFilters = count($filterlist['Filter']);
+    	$writer->putUI8($NumberOfFilters);
+        foreach ($filterlist['Filter'] as $filter_entry) {
+            IO_SWF_Type_FILTER::build($writer, $filter_entry, $opts);
+        }
+    }
+    static function string($filterlist, $opts = array()) {
+        $text = "\tNumberOfFilters:{$filterlist['NumberOfFilters']}\n";
+        foreach ($filterlist['Filter'] as $filter_entry) {
+            $text .= "\t\t".IO_SWF_Type_FILTER::string($$filter_entry, $opts);
+        }
+    	return $text;
+    }
+}
属性に変更があったパス: IO_SWF/tags/2.1.8-stable-20120220231502/IO/SWF/Type/FILTERLIST.php
___________________________________________________________________
追加: svn:keywords
+ Id
追加: svn:eol-style
+ native

IO_SWF/tags/2.1.8-stable-20120220231502/IO/SWF/Type/TEXTRECORD.php

@@ -0,0 +1,126 @@
+<?php
+
+/*
+ * 2011/8/22- (c) yoya@awm.jp
+ */
+
+require_once 'IO/Bit.php';
+require_once dirname(__FILE__).'/../Type.php';
+require_once dirname(__FILE__).'/RGB.php';
+require_once dirname(__FILE__).'/RGBA.php';
+require_once dirname(__FILE__).'/GLYPHENTRY.php';
+
+
+class IO_SWF_Type_TEXTRECORD extends IO_SWF_Type {
+    static function parse(&$reader, $opts = array()) {
+    	$textrecord = array();
+        $reader->byteAlign();
+        $textrecord['TextRecordType'] = $reader->getUIBit();
+        $textrecord['StyleFlagsReserved'] = $reader->getUIBits(3);
+        $styleFlagsHasFont = $reader->getUIBit();
+        $styleFlagsHasColor = $reader->getUIBit();
+        $styleFlagsHasYOffeet = $reader->getUIBit();
+        $styleFlagsHasXOffeet = $reader->getUIBit();
+        $textrecord['StyleFlagsHasFont'] = $styleFlagsHasFont;
+        $textrecord['StyleFlagsHasColor'] = $styleFlagsHasColor;
+        $textrecord['StyleFlagsHasYOffeet'] = $styleFlagsHasYOffeet;
+        $textrecord['StyleFlagsHasXOffeet'] = $styleFlagsHasXOffeet;
+        //
+        if ($styleFlagsHasFont) {
+            $textrecord['FontID'] = $reader->getUI16LE();
+        }
+        if ($styleFlagsHasColor) {
+            if ($opts['tagCode'] == 11) {// DefintText
+                $textrecord['TextColor'] = IO_SWF_Type_RGB::parse($reader);
+            } else { // DefineText2
+                $textrecord['TextColor'] = IO_SWF_Type_RGBA::parse($reader);
+            }
+        }
+        if ($styleFlagsHasXOffeet) {
+            $textrecord['XOffset'] = $reader->getUI16LE();
+        }
+        if ($styleFlagsHasYOffeet) {
+            $textrecord['YOffset'] = $reader->getUI16LE();
+        }
+        if ($styleFlagsHasFont) {
+            $textrecord['TextHeight'] = $reader->getUI16LE();
+        }
+        $glyphCount = $reader->getUI8();
+        $textrecord['GlyphCount'] = $glyphCount;
+        $glyphEntries = array();
+        for ($i = 0 ; $i < $glyphCount; $i++) {
+            $glyphEntries []= IO_SWF_Type_GLYPHENTRY::parse($reader, $opts);
+        }
+        $textrecord['GlyphEntries'] = $glyphEntries;
+    	return $textrecord;
+    }
+    static function build(&$writer, $textrecord, $opts = array()) {
+        $writer->byteAlign();
+        $writer->putUIBit($textrecord['TextRecordType']);
+        $writer->putUIBits($textrecord['StyleFlagsReserved'], 3);
+
+        $styleFlagsHasFont = $textrecord['StyleFlagsHasFont'];
+        $styleFlagsHasColor = $textrecord['StyleFlagsHasColor'];
+        $styleFlagsHasYOffeet = $textrecord['StyleFlagsHasYOffeet'];
+        $styleFlagsHasXOffeet = $textrecord['StyleFlagsHasXOffeet'];
+        $writer->putUIBit($styleFlagsHasFont);
+        $writer->putUIBit($styleFlagsHasColor);
+        $writer->putUIBit($styleFlagsHasYOffeet);
+        $writer->putUIBit($styleFlagsHasXOffeet);
+        //
+        if ($styleFlagsHasFont) {
+            $writer->putUI16LE($textrecord['FontID']);
+        }
+        if ($styleFlagsHasColor) {
+            if ($opts['tagCode'] == 11) {// DefintText
+                IO_SWF_Type_RGB::build($writer, $textrecord['TextColor']);
+            } else { // DefineText2
+                IO_SWF_Type_RGBA::build($writer, $textrecord['TextColor']);
+            }
+        }
+        if ($styleFlagsHasXOffeet) {
+            $writer->putUI16LE($textrecord['XOffset']);
+        }
+        if ($styleFlagsHasYOffeet) {
+            $writer->putUI16LE($textrecord['YOffset']);
+        }
+        if ($styleFlagsHasFont) {
+            $writer->putUI16LE($textrecord['TextHeight']);
+        }
+        $glyphCount = count($textrecord['GlyphEntries']);
+        $writer->putUI8($glyphCount);
+        foreach ($textrecord['GlyphEntries'] as $glyphEntrie) {
+            IO_SWF_Type_GLYPHENTRY::build($writer, $glyphEntrie, $opts);
+        }
+    }
+    static function string($textrecord, $opts = array()) {
+        $text = '';
+        if ($textrecord['StyleFlagsHasFont']) {
+            $text .= "FontID: {$textrecord['FontID']} TextHeight: {$textrecord['TextHeight']} ";
+        }
+        if ($textrecord['StyleFlagsHasColor']) {
+            if ($opts['tagCode'] == 11) {// DefintText
+                $color_str = IO_SWF_Type_RGB::string($textrecord['TextColor']);
+            } else { // DefineText2
+                $color_str = IO_SWF_Type_RGBA::string($textrecord['TextColor']);
+            }
+            $text .= "TextColor: $color_str ";
+        }
+        if ($textrecord['StyleFlagsHasXOffeet']) {
+            $text .= "XOffset: {$textrecord['XOffset']}";
+        }
+        if ($textrecord['StyleFlagsHasYOffeet']) {
+            $text .= "YOffset: {$textrecord['YOffset']}";
+        }
+        if ($text != '') {
+            $text .= "\n\t";
+        }
+
+        $text .= "GryphEntries:";
+        foreach ($textrecord['GlyphEntries'] as $glyphEntrie) {
+            $text .= "\n\t\t".IO_SWF_Type_GLYPHENTRY::string($glyphEntrie, $opts);
+        }
+        $text .= "\n";
+        return $text;
+    }
+}
属性に変更があったパス: IO_SWF/tags/2.1.8-stable-20120220231502/IO/SWF/Type/TEXTRECORD.php
___________________________________________________________________
追加: svn:keywords
+ Id
追加: svn:eol-style
+ native

IO_SWF/tags/2.1.8-stable-20120220231502/IO/SWF/Type/CLIPACTIONRECORD.php

@@ -0,0 +1,54 @@
+<?php
+
+/*
+ * 2011/7/11- (c) yoya@awm.jp
+ */
+
+require_once 'IO/Bit.php';
+require_once dirname(__FILE__).'/../Type.php';
+require_once dirname(__FILE__).'/Action.php';
+require_once dirname(__FILE__).'/CLIPEVENTFLAGS.php';
+
+class IO_SWF_Type_CLIPACTIONRECORD extends IO_SWF_Type {
+    static function parse(&$reader, $opts = array()) {
+        $clipactionrecord = array();
+        $clipactionrecord['EventFlags'] = IO_SWF_Type_CLIPEVENTFLAGS::parse($reader, $opts);
+        $clipactionrecord['ActionRecordSize'] = $reader->getUI32LE();
+        if ($clipactionrecord['EventFlags']['ClipEventKeyPress'] == 1) {
+            $clipactionrecord['KeyCode'] = $reader->getUI8();
+        }
+        $actions = array();
+        while ($reader->getUI8() != 0) {
+            $reader->incrementOffset(-1, 0); // 1 byte back
+            $action = IO_SWF_Type_Action::parse($reader);
+            $actions [] = $action;
+        }
+        $clipactionrecord['Actions'] = $actions;
+    	return $clipactionrecord;
+    }
+    static function build(&$writer, $clipactionrecord, $opts = array()) {
+        IO_SWF_Type_CLIPEVENTFLAGS::build($writer, $clipactionrecord['EventFlags'], $opts);
+        $actionRecordSize = $clipactionrecord['ActionRecordSize']; // XXX
+        $writer->putUI32LE($actionRecordSize);
+        if ($clipactionrecord['EventFlags']['ClipEventKeyPress'] == 1) {
+            $writer->putUI8($clipactionrecord['KeyCode']);
+        }
+        $actions = array();
+        foreach ($clipactionrecord['Actions'] as $action) {
+            IO_SWF_Type_Action::build($writer, $action);
+        }
+        $writer->putUI8(0); // ActionEndFlag
+    }
+    static function string($clipactionrecord, $opts = array()) {
+        $text = '';
+        $text .= IO_SWF_Type_CLIPEVENTFLAGS::string($clipactionrecord['EventFlags'], $opts);
+        $text .= "\n";
+        $text .= "\tActions:\n";
+        foreach ($clipactionrecord['Actions'] as $action) {
+            $text .= "\t";
+            $text .= IO_SWF_Type_Action::string($action, $opts);
+            $text .= "\n";
+        }
+    	return $text;
+    }
+}

IO_SWF/tags/2.1.8-stable-20120220231502/IO/SWF/Type/FILTER.php

@@ -0,0 +1,154 @@
+<?php
+
+/*
+ * 2011/9/9- (c) yoya@awm.jp
+ */
+
+require_once 'IO/Bit.php';
+require_once dirname(__FILE__).'/../Type.php';
+require_once dirname(__FILE__).'/RGBA.php';
+require_once dirname(__FILE__).'/Float.php';
+
+class IO_SWF_Type_FILTER extends IO_SWF_Type {
+    static function parse(&$reader, $opts = array()) {
+    	$filter = array();
+    	$filterID = $reader->getUI8();
+    	$filter['FilterID'] = $filterID;
+        switch ($filterID) {
+        case 0: // DropShadowFilter
+            $dropshadowfilter = array();
+            $dropshadowfilter['DefaultColor'] = IO_SWF_Type_RGBA::parse($reader, $opts);
+            $dropshadowfilter['BlurX'] = $reader->getUI32LE(); // 16.16 FIXED
+            $dropshadowfilter['BlurY'] = $reader->getUI32LE(); // 16.16 FIXED
+            $dropshadowfilter['Angle'] = $reader->getUI32LE(); // 16.16 FIXED
+            $dropshadowfilter['Distance'] = $reader->getUI32LE(); // 16.16 FIXED
+            $dropshadowfilter['Strength'] = $reader->getUI16LE(); // 8.8 FIXED
+            $dropshadowfilter['InnerShadow'] = $reader->getUIBit();
+            $dropshadowfilter['Knockout'] = $reader->getUIBit();
+            $dropshadowfilter['CompositeSource'] = $reader->getUIBit();
+            $dropshadowfilter['Passed'] = $reader->getUIBits(5);
+            $filter['DropShadowFilter'] = $dropshadowfilter;
+            break;
+        case 1: // BlurFilter
+            $blurfilter = array();
+            $blurfilter['BlurX'] = $reader->getUI32LE(); // 16.16 FIXED
+            $blurfilter['BlurY'] = $reader->getUI32LE(); // 16.16 FIXED
+            $blurfilter['Passes'] = $reader->getUIBits(5);
+            $blurfilter['Reserved'] = $reader->getUIBits(3);
+            $filter['BlurFilter'] = $blurfilter;
+            break;
+        case 2: // GlowFilter
+            $glowfilter = array();
+            $glowfilter['GlowColor'] = IO_SWF_Type_RGBA::parse($reader, $opts);
+            $glowfilter['BlurX'] = $reader->getUI32LE(); // 16.16 FIXED
+            $glowfilter['BlurY'] = $reader->getUI32LE(); // 16.16 FIXED
+            $glowfilter['Strength'] = $reader->getUI16LE(); // 8.8 FIXED
+            $glowfilter['InnerGlow'] = $reader->getUIBit();
+            $glowfilter['Knockout'] = $reader->getUIBit();
+            $glowfilter['CompositeSource'] = $reader->getUIBit();
+            $glowfilter['Passed'] = $reader->getUIBits(5);
+            $filte['GlowFilter'] = $glowfilter;
+            break;
+        case 3: // BevelFilter
+            $bevelfilter = array();
+            $bevelfilter['ShadowColor'] = IO_SWF_Type_RGBA::parse($reader, $opts);
+            $bevelfilter['HighlightColor'] = IO_SWF_Type_RGBA::parse($reader, $opts);
+            $bevelfilter['BlurX'] = $reader->getUI32LE(); // 16.16 FIXED
+            $bevelfilter['BlurY'] = $reader->getUI32LE(); // 16.16 FIXED
+            $bevelfilter['Angle'] = $reader->getUI32LE(); // 16.16 FIXED
+            $bevelfilter['Distance'] = $reader->getUI32LE(); // 16.16 FIXED
+            $bevelfilter['Strength'] = $reader->getUI16LE(); // 8.8 FIXED
+            $bevelfilter['InnerShadow'] = $reader->getUIBit();
+            $bevelfilter['Knockout'] = $reader->getUIBit();
+            $bevelfilter['CompositeSource'] = $reader->getUIBit();
+            $bevelfilter['OnTop'] = $reader->getUIBit();
+            $bevelfilter['Passed'] = $reader->getUIBits(4);
+            $filter['BevelFilter'] = $bevelfilter;
+            break;
+        case 4: // GradientFilter
+            $gradientfilter = array();
+            $numColors = $reader->getUI8();
+            $gradientfilter['NumColors'] = $numColors;
+            $gradientColors = array();
+            for ($i = 0 ; $i < $numColors ; $i++) {
+                $gradientColors []= IO_SWF_Type_RGBA::parse($reader, $opts);
+            }
+            $gradientfilter['GradientColors'] = $gradientColors;
+            $gradientRatio = array();
+            for ($i = 0 ; $i < $numColors ; $i++) {
+                $gradientRatio []= $reader->getUI8();
+            }
+            $gradientfilter['GradientRatio'] = $gradientRatio;
+            $filter['GradientFilter'] = $gradientfilter;
+            break;
+        case 5: // ConvolutionFilter
+            $convfilter = array();
+            $matrixX = $reader->getUI8();
+            $matrixY = $reader->getUI8();
+            $convfilter['MatrixX'] = $matrixX;
+            $convfilter['MatrixY'] = $matrixY;
+            $convfilter['Divisor'] = IO_SWF_Type_Float($reader);
+            $convfilter['Bios'] = IO_SWF_Type_Float($reader);
+            $matrix_mn = array();
+            $mn = $marixX * $matrixY;
+            for ($i = 0 ; $i < $mn ; $i++) {
+                $matrix_mn []= IO_SWF_Type_Float($reader);
+            }
+            $convfilter['Matrix'] = $matrix_mn;
+            $convfilter['DefaultColor'] = IO_SWF_Type_RGBA::parse($reader, $opts);
+            $convfilter['Reserved'] = $reader->getUIBits(6);
+            $convfilter['Clamp'] = $reader->getUIBit();
+            $convfilter['PreserveAlpha'] = $reader->getUIBit();
+            $filter['ColorMatrixFilter'] = $convfilter;
+            break;
+        case 6: // ColorMatrixFilter
+            $matrix_20 = array();
+            for ($i = 0 ; $i < 20 ; $i++) {
+                $matrix_20 []= IO_SWF_Type_Float($reader);
+            }
+            $filter['ColorMatrixFilter'] = array('Matrix' => $matrix_20);
+            break;
+        case 7: // GradientBevelFilter
+            $gradientbevelfilter = array();
+            $numColors = $reader->getUI8();
+            $gradientbevelfilter['NumColors'] = $numColors;
+            $gradientColors = array();
+            for ($i = 0 ; $i < $numColors ; $i++) {
+                $gradientColors []= IO_SWF_Type_RGBA::parse($reader, $opts);
+            }
+            $gradientbevelfilter['GradientColors'] = $gradientColors;
+            $gradientRatio = array();
+            for ($i = 0 ; $i < $numColors ; $i++) {
+                $gradientRatio []= $reader->getUI8();
+            }
+            $gradientbevelfilter['GradientRatio'] = $gradientRatio;
+            $gradientbevelfilter['BlurX'] = $reader->getUI32LE(); // 16.16 FIXED
+            $gradientbevelfilter['BlurY'] = $reader->getUI32LE(); // 16.16 FIXED
+            $gradientbevelfilter['Angle'] = $reader->getUI32LE(); // 16.16 FIXED
+            $gradientbevelfilter['Distance'] = $reader->getUI32LE(); // 16.16 FIXED
+            $gradientbevelfilter['Strength'] = $reader->getUI16LE(); // 8.8 FIXED
+            $gradientbevelfilter['InnerShadow'] = $reader->getUIBit();
+            $gradientbevelfilter['Knockout'] = $reader->getUIBit();
+            $gradientbevelfilter['CompositeSource'] = $reader->getUIBit();
+            $gradientbevelfilter['OnTop'] = $reader->getUIBit();
+            $gradientbevelfilter['Passed'] = $reader->getUIBits(4);
+            $filter['GradientBevelFilter'] = $gradientbevelfilter;
+            break;
+        }
+    	return $filter;
+    }
+    static function build(&$writer, $filterlist, $opts = array()) {
+        $NumberOfFilters = count($filterlist['Filter']);
+    	$writer->putUI8($NumberOfFilters);
+        foreach ($filterlist['Filter'] as $filter_entry) {
+            IO_SWF_Type_FILTER::build($writer, $filter_entry, $opts);
+        }
+    }
+    static function string($filterlist, $opts = array()) {
+        $text = "\tNumberOfFilters:{$filterlist['NumberOfFilters']}\n";
+        foreach ($filterlist['Filter'] as $filter_entry) {
+            $text .= "\t\t".IO_SWF_Type_FILTER::string($$filter_entry, $opts);
+        }
+    	return $text;
+    }
+}
属性に変更があったパス: IO_SWF/tags/2.1.8-stable-20120220231502/IO/SWF/Type/FILTER.php
___________________________________________________________________
追加: svn:keywords
+ Id
追加: svn:eol-style
+ native

IO_SWF/tags/2.1.8-stable-20120220231502/IO/SWF/Bitmap.php

@@ -0,0 +1,99 @@
+<?php
+
+/*
+ * Bitmap Utility Routine
+ */
+
+require_once 'IO/Bit.php';
+require_once dirname(__FILE__).'/Exception.php';
+
+class IO_SWF_Bitmap {
+    const FORMAT_UNKNOW = 0;
+    const FORMAT_JPEG = 1;
+    const FORMAT_PNG = 2;
+    const FORMAT_GIF = 4;
+    static function detect_bitmap_format($bitmap_data) {
+        if (strncmp($bitmap_data, "\xff\xd8\xff", 3) == 0) {
+            return self::FORMAT_JPEG;
+        } else if (strncmp($bitmap_data, "\x89PNG", 4) == 0) {
+            return self::FORMAT_PNG;
+        } else if (strncmp($bitmap_data, 'GIF', 3) == 0) {
+            return self::FORMAT_GIF;
+        }
+        return self::FORMAT_UNKNOWN;
+    }
+    static function get_jpegsize($jpegdata) {
+        $chunk_length = 0;
+        $jpegdata_len = strlen($jpegdata);
+        for ($idx = 0 ; (($idx + 8) < $jpegdata_len) ; $idx += $chunk_length) {
+            $marker1 = ord($jpegdata[$idx]);
+            if ($marker1 != 0xFF) {
+                break;
+            }
+            $marker2 = ord($jpegdata[$idx + 1]);
+            switch ($marker2) {
+              case 0xD8: // SOI (Start of Image)
+              case 0xD9: // EOI (End of Image)
+                $chunk_length = 2;
+                break;
+              case 0xDA: // SOS
+                throw new IO_SWF_Exception("encounter SOS before SOF");
+              case 0xC0: // SOF0
+              case 0xC1: // SOF1
+              case 0xC2: // SOF2
+              case 0xC3: // SOF3
+              case 0xC5: // SOF5
+              case 0xC6: // SOF6
+              case 0xC7: // SOF7
+              case 0xC9: // SOF9
+              case 0xCA: // SOF10
+              case 0xCB: // SOF11
+              case 0xCD: // SOF13
+              case 0xCE: // SOF14
+              case 0xCF: // SOF15
+                $width  = 0x100 * ord($jpegdata[$idx + 7]) + ord($jpegdata[$idx + 8]);
+                $height = 0x100 * ord($jpegdata[$idx + 5]) + ord($jpegdata[$idx + 6]);
+                return array($width, $height); // success
+              default:
+                $chunk_length = 0x100 * ord($jpegdata[$idx + 2]) + ord($jpegdata[$idx + 3]) + 2;
+                if ($chunk_length == 0) { // fail safe;
+                    break;
+                }
+            }
+        }
+        return false; // NG
+    }
+
+    static function get_pngsize($pngdata) {
+        $pngdata_len = strlen($pngdata);
+        if ($pngdata_len< 24) {
+            fprintf(stderr, "IO_SWF_Bitmap::get_pngsize: data_len(%lu) < 16\n", $pngdata_len);
+            return 1;
+        }
+        $width = (((ord($pngdata[16])*0x100) + ord($pngdata[17]))*0x100 + ord($pngdata[18]))*0x100 + ord($pngdata[19]);
+        $height =(((ord($pngdata[20])*0x100) + ord($pngdata[21]))*0x100 + ord($pngdata[22]))*0x100 + ord($pngdata[23]);
+        return array('width' => $width, 'height' => $height); // success
+    }
+
+    static function get_gifsize($gifdata) {
+        $gifdata_len = strlen($gifdata);
+        if ($gifdata_len < 10) {
+            fprintf(stderr, "IO_SWF_Bitmap::get_gifsize: data_len(%lu) < 10\n", $gifdata_len);
+            return false;
+        }
+        $width  = 0x100 * ord($gifdata[7]) + ord($gifdata[6]);
+        $height = 0x100 * ord($gifdata[9]) + ord($gifdata[8]);
+        return array('width' => $width, 'height' => $height); // success
+    }
+
+    static function get_bitmapsize($bitmapdata) {
+        if (strncmp($bitmapdata, "\xff\xd8\xff", 3) == 0) { // JPEG
+            return self::get_jpegsize($bitmapdata);
+        } elseif (strncmp($bitmapdata,"\x89PNG", 4) == 0) { // PNG
+            return self::get_pngsize($bitmapdata);
+        } elseif (strncmp($bitmapdata, 'GIF', 3) == 0) { // GIF
+            return self::get_gifsize($bitmapdata);
+        }
+        return false; // NG
+    }
+  }
\ No newline at end of file

IO_SWF/tags/2.1.8-stable-20120220231502/IO/SWF/Exception.php

@@ -0,0 +1,3 @@
+<?php
+
+class IO_SWF_Exception extends Exception { }
属性に変更があったパス: IO_SWF/tags/2.1.8-stable-20120220231502/IO/SWF/Exception.php
___________________________________________________________________
追加: svn:keywords
+ Id
追加: svn:eol-style
+ native

IO_SWF/tags/2.1.8-stable-20120220231502/IO/SWF/Type.php

@@ -0,0 +1,13 @@
+<?php
+
+/*
+ * 2011/1/25- (c) yoya@awm.jp
+ */
+
+// require_once 'IO/Bit.php';
+
+abstract class IO_SWF_Type {
+    abstract static function parse(&$reader, $opts = array());
+    abstract static function build(&$writer, $data, $opts = array());
+    abstract static function string($data, $opts = array());
+}

IO_SWF/tags/2.1.8-stable-20120220231502/IO/SWF/Decompiler.php

@@ -0,0 +1,405 @@
+<?php
+
+/*
+ * 2011/10/06 - (c) takebe@cityfujisawa.ne.jp
+ */
+
+require_once dirname(__FILE__).'/Exception.php';
+require_once dirname(__FILE__).'/../SWF.php';
+require_once dirname(__FILE__).'/Tag/Shape.php';
+require_once dirname(__FILE__).'/Tag/Action.php';
+require_once dirname(__FILE__).'/Tag/Sprite.php';
+require_once dirname(__FILE__).'/Lossless.php';
+require_once dirname(__FILE__).'/../SWF/Bitmap.php';
+
+class IO_SWF_Decompiler extends IO_SWF {
+    static function getNPushPop($action) {
+        switch ($action['Code']) {
+        case 0x81:  // GotoFrame
+        case 0x82:  // GetURL
+        case 0x04:  // NextFrame
+        case 0x05:  // PreviousFrame
+        case 0x06:  // Play
+        case 0x07:  // Stop
+        case 0x08:  // ToggleQuality
+        case 0x09:  // StopSounds
+        case 0x8A:  // WaitForFrame
+        case 0x8B:  // SetTarget
+        case 0x8C:  // GoToLabel
+            return array(0, 0);
+
+        case 0x96:  // Push
+            return array(count($action['Values']), 0);
+
+        case 0x17:  // Pop
+        case 0x9E:  // Call
+        case 0x20:  // SetTarget2
+        case 0x26:  // Trace
+        case 0x9F:  // GotoFrame2
+            return array(0, 1);
+
+        case 0x0A:  // Add
+        case 0x0B:  // Subtract
+        case 0x0C:  // Multiply
+        case 0x0D:  // Divide
+        case 0x0E:  // Equals
+        case 0x0F:  // Less
+        case 0x10:  // And
+        case 0x11:  // Or
+        case 0x13:  // StringEquals
+        case 0x21:  // StringAdd
+        case 0x22:  // GetProperty
+            return array(1, 2);
+
+        case 0x12:  // Not
+        case 0x14:  // StringLength
+        case 0x18:  // ToInteger
+        case 0x1C:  // GetVariable
+        case 0x30:  // RandomNumber
+            return array(1, 1);
+
+        case 0x1D:  // SetVariable
+            return array(0, 2);
+
+        case 0x15:  // StringExtract
+            return array(1, 3);
+
+        case 0x23:  // SetProperty
+        case 0x24:  // CloneSprite
+            return array(0, 3);
+
+        case 0x34:  // GetTime
+            return array(1, 0);
+
+        default:
+            return array(0, 0);
+        }
+    }
+
+    static function treeToString($tree, $is_top_level = 0) {
+        $action_str = IO_SWF_Type_Action::getCodeName($tree[0]['Code']);
+
+        switch ($tree[0]['Code']) {
+        case 0x81:  // GotoFrame
+            $action_str .= " " . $tree[0]['Frame'];
+            break;
+        case 0x8B:  // SetTarget
+            $action_str .= ' "' . $tree[0]['TargetName'] . '"';
+            break;
+        case 0x8C:  // GoToLabel
+            $action_str .= ' "' . $tree[0]['Label'] . '"';
+            break;
+        case 0x96:  // Push
+            if ($is_top_level == 0
+                && count($tree[0]['Values']) == 1
+                && $tree[0]['Values'][0]['Type'] == 0) {  // String
+                    return '"' . $tree[0]['Values'][0]['String'] . '"';
+            } else {
+                foreach ($tree[0]['Values'] as $value) {
+                    unset($value['Type']);
+                    list($type_name) = array_keys($value);
+                    $action_str .= " " . $value[$type_name];
+                }
+            }
+            break;
+        case 0x1C:  // GetVariable
+            if (count($tree[1]) == 1
+                && $is_top_level == 0
+                && $tree[1][0][0]['Code'] == 0x96) {  // Push
+                if (count($tree[1][0][0]['Values']) == 1) {
+                    return $tree[1][0][0]['Values'][0]['String'];
+                }
+            }
+            break;
+
+        case 0x1D:  // SetVariable
+            if (count($tree[1]) == 2
+                && $tree[1][1][0]['Code'] == 0x96) {  // Push
+                if (count($tree[1][1][0]['Values']) == 1
+                    && count($tree[1]) == 2) {
+                    return $tree[1][1][0]['Values'][0]['String']
+                        . " = "
+                        . self::treeToString($tree[1][0]);
+                }
+            }
+        }
+
+        $str = "";
+        $delim = "";
+
+        for ($i = 0; $i < count($tree[1]); $i++) {
+            $str = self::treeToString($tree[1][$i])
+                . $delim . $str;
+            $delim = ", ";
+        }
+
+        if (count($tree[1]) > 0) {
+            return $action_str . "(" . $str . ")";
+        } else {
+            return $action_str;
+        }
+    }
+
+    function reorderPush(&$actions, $index, $push_index) {
+        // move a push at $push_index to $index
+        $push = array_splice($actions, $push_index, 1);
+        array_splice($actions, $index, 0, $push);
+
+        return $actions;
+    }
+
+    function makeActionTree($index, &$actions) {
+        // echo "makeActionTree: $index\n";
+
+        $idx = $index;
+        $action1 = $actions[$index--];
+
+        $n_push_pop = self::getNPushPop($action1);
+        $n_push = $n_push_pop[0];
+        $n_pop = $n_push_pop[1];
+
+        $action_trees = array();
+
+        /*
+        if ($n_pop != 0) {
+            $subtree_index = $index;
+            do {
+                // skip subtree of n_push == 0
+                $tree = self::makeActionTree($subtree_index, $actions);
+                $subtree_index = $tree['index'];
+            } while ($tree['n_push'] == 0);
+            self::reorderPush($actions, $index, $tree['index']);
+            exit();
+        }
+        */
+
+        for ($i = 0; $i < $n_pop && $index >= 0; ) {
+            $tree = self::makeActionTree($index, $actions);
+
+            if ($tree['n_push'] != 1) {
+                return array(
+                    'n_push' => $n_push,
+                    'action_tree' => array($action1, array()),
+                    'index' => $idx - 1
+                    );
+            }
+
+            $action_tree1 = $tree['action_tree'];
+            $index = $tree['index'];
+
+            $action_trees[] = $action_tree1;
+
+            $i += $tree['n_push'];
+        }
+
+        return array(
+            'n_push' => $n_push,
+            'action_tree' => array($action1, $action_trees),
+            'index' => $index
+            );
+    }
+
+    static function dumpBasicBlock($actions, $end, $opts) {
+        // echo "\tBEGIN BLOCK\n";
+
+        $str = "";
+        $index = count($actions) - 1;
+        $start = $end - $index;
+        while ($index >= 0) {
+            $result = self::makeActionTree($index, $actions);
+            $tree = $result['action_tree'];
+            $tree_str = self::treeToString($tree, 1);
+            $index = $result['index'];
+            $pc = $start + $index + 1;
+            $str = "$pc\t$tree_str\n" . $str;
+        }
+
+        echo $str;
+
+        // echo "\tEND BLOCK\n";
+    }
+
+    static function decomposePush($tag) {
+        $count = count($tag->tag->_actions);
+        $actions = array();
+        $labels = array();
+        $branches = array();
+        $offset = 0;
+
+        for ($i = 0; $i < $count; $i++) {
+            $action = $tag->tag->_actions[$i];
+            if ($action['Code'] == 0x96) {
+                for ($j = 0; $j < count($action['Values']); $j++) {
+                    $new_action = array();
+                    $new_action['Code'] = $action['Code'];
+                    $new_action['Length'] = 2 + strlen($action['Values'][$j]['String']);
+                    $new_action['Values'] = array();
+                    $new_action['Values'][0] = array();
+                    $new_action['Values'][0]['Type'] = $action['Values'][$j]['Type'];
+                    $new_action['Values'][0]['String'] = $action['Values'][$j]['String'];
+                    $actions[] = $new_action;
+                }
+                $offset += count($action['Values']) - 1;
+            } else {
+                $actions[] = $action;
+            }
+            if (isset($tag->tag->_labels[$i])) {
+                $labels[$i + $offset] = $tag->tag->_labels[$i];
+            }
+            if (isset($tag->tag->_branches[$i])) {
+                $branches[$i + $offset] = $tag->tag->_branches[$i];
+            }
+        }
+
+        $tag->tag->_actions = $actions;
+        $tag->tag->_branches = $branches;
+        $tag->tag->_labels = $labels;
+    }
+
+    static function dumpActionTag($tag, $frame, $opts) {
+        echo "    Actions: (in frame $frame)";
+        if ($tag->code == 59) {  // DoInitAction
+            echo " SpriteID=".$tag->tag->_spriteId;
+        }
+        echo "\n";
+
+        $basic_block = array();
+
+        // self::decomposePush($tag);
+
+        for ($i = 0; $i < count($tag->tag->_actions); $i++) {
+            $action = $tag->tag->_actions[$i];
+            if (isset($tag->tag->_labels[$i])) {
+                self::dumpBasicBlock($basic_block, $i, $opts);
+                $basic_block = array();
+                echo "    (LABEL" . $tag->tag->_labels[$i] . "):\n";
+            }
+            $action_str = IO_SWF_Type_Action::getCodeName($action['Code']);
+            if (isset($tag->tag->_branches[$i])) {
+                self::dumpBasicBlock($basic_block, $i, $opts);
+                $basic_block = array();
+                echo "\t$action_str";
+                echo " (LABEL" . $tag->tag->_branches[$i] . ")\n";
+            } else {
+                $basic_block[] = $action;
+            }
+        }
+        if (count($basic_block) != 0) {
+            self::dumpBasicBlock($basic_block, $i, $opts);
+        }
+        if (isset($tag->tag->_labels[$i])) {
+            echo "    (LABEL" . $tag->tag->_labels[$i] . "):\n";
+        }
+    }
+
+    static function dumpSpriteTag($tag, $opts) {
+        $code = $tag->code;
+        $name = $tag->getTagInfo($code, 'name');
+        if ($name === false) {
+            $name = 'unknown';
+        }
+        $length = strlen($tag->content);
+        echo "Code: $code($name)  Length: $length".PHP_EOL;
+        echo "\tSprite: SpriteID={$tag->tag->_spriteId} FrameCount={$tag->tag->_frameCount}\n";
+
+        $frame_num = 1;
+        for ($i = 0; $i < count($tag->tag->_controlTags); $i++) {
+            $control_tag = $tag->tag->_controlTags[$i];
+            switch ($control_tag->code) {
+            case 39:  // Sprite
+                self::dumpSpriteTag($control_tag, $opts);
+                break;
+
+            case 12:  // Action
+            case 59:  // InitAction
+                self::dumpActionTag($control_tag, $frame_num, $opts);
+                break;
+
+            case 1:   // ShowFrame
+                $frame_num++;
+                break;
+
+            case 43:  // FrameLabel
+                $control_tag->dump();
+                break;
+
+            default:
+                break;
+            }
+        }
+    }
+
+    static function parseTagContent($tag, $opts) {
+        $code = $tag->code;
+        $name = $tag->getTagInfo($code, 'name');
+        if ($name === false) {
+            $name = 'unknown';
+        }
+        $length = strlen($tag->content);
+        $opts['Version'] = $tag->swfInfo['Version'];
+        $tag->parseTagContent($opts);
+
+        if ($code == 39) {  // Sprite
+            foreach ($tag->tag->_controlTags as $control_tag) {
+                self::parseTagContent($control_tag, $opts);
+            }
+        }
+    }
+
+    function dump($opts = array()) {
+        if (empty($opts['hexdump']) === false) {
+            $bitio = new IO_Bit();
+            $bitio->input($this->_swfdata);
+        }
+        /* SWF Header */
+        echo 'Signature: '.$this->_headers['Signature'].PHP_EOL;
+        echo 'Version: '.$this->_headers['Version'].PHP_EOL;
+        echo 'FileLength: '.$this->_headers['FileLength'].PHP_EOL;
+        echo 'FrameSize: '. IO_SWF_Type_RECT::string($this->_headers['FrameSize'])."\n";
+        echo 'FrameRate: '.($this->_headers['FrameRate'] / 0x100).PHP_EOL;
+        echo 'FrameCount: '.$this->_headers['FrameCount'].PHP_EOL;
+
+        if (empty($opts['hexdump']) === false) {
+            $bitio->hexdump(0, $this->_header_size);
+            $opts['bitio'] =& $bitio; // for tag
+        }
+        $opts['indent'] = 0;
+        /* SWF Tags */
+
+        echo 'Tags:'.PHP_EOL;
+        foreach ($this->_tags as $tag) {
+            self::parseTagContent($tag, $opts);
+        }
+
+        $frame_num = 1;
+        $sprite_tags = array();
+        for ($i = 0; $i < count($this->_tags); $i++) {
+            $tag = $this->_tags[$i];
+            switch ($tag->code) {
+            case 39:  // Sprite
+                $sprite_tags[] = $tag;
+                break;
+
+            case 12:  // Action
+            case 59:  // InitAction
+                self::dumpActionTag($tag, $frame_num, $opts);
+                break;
+
+            case 1:   // ShowFrame
+                $frame_num++;
+                break;
+
+            case 43:  // FrameLabel
+                $tag->dump();
+                break;
+
+            default:
+                break;
+            }
+        }
+
+        foreach ($sprite_tags as $tag) {
+            self::dumpSpriteTag($tag, $opts);
+        }
+    }
+}
属性に変更があったパス: IO_SWF/tags/2.1.8-stable-20120220231502/IO/SWF/Decompiler.php
___________________________________________________________________
追加: svn:executable
+ *
追加: svn:keywords
+ Id
追加: svn:eol-style
+ native

IO_SWF/tags/2.1.8-stable-20120220231502/IO/SWF/ActionEditor.php

@@ -0,0 +1,167 @@
+<?php
+
+/*
+ * 2011/10/06 - (c) takebe@cityfujisawa.ne.jp
+ */
+
+require_once dirname(__FILE__).'/Exception.php';
+require_once dirname(__FILE__).'/../SWF.php';
+require_once dirname(__FILE__).'/Tag/Shape.php';
+require_once dirname(__FILE__).'/Tag/Action.php';
+require_once dirname(__FILE__).'/Tag/Sprite.php';
+require_once dirname(__FILE__).'/Lossless.php';
+require_once dirname(__FILE__).'/../SWF/Bitmap.php';
+
+class IO_SWF_ActionEditor extends IO_SWF {
+    static function parseTagContent($tag, $opts) {
+        $code = $tag->code;
+        $name = $tag->getTagInfo($code, 'name');
+        if ($name === false) {
+            $name = 'unknown';
+        }
+        $length = strlen($tag->content);
+        $opts['Version'] = $tag->swfInfo['Version'];
+        if ($code == 12 || $code == 59) {
+            $tag->parseTagContent($opts);
+            $tag->content = null;  // remove original binary
+        }
+        if ($code == 39) {  // Sprite
+            $tag->parseTagContent($opts);
+            $tag->content = null;  // remove original binary
+            foreach ($tag->tag->_controlTags as $control_tag) {
+                self::parseTagContent($control_tag, $opts);
+            }
+        }
+    }
+
+    function parseAllTagContent($opts) {
+        foreach ($this->_tags as $tag) {
+            self::parseTagContent($tag, $opts);
+        }
+    }
+
+    function findActionTagInTags($frame, $tags) {
+        $frame_num = 1;
+        foreach ($tags as $tag) {
+            if ($frame_num == $frame && ($tag->code == 12 || $tag->code == 59)) {
+                return $tag;
+            }
+            if ($tag->code == 1) {  // ShowFrame
+                $frame_num++;
+            }
+        }
+        return null;
+    }
+
+    function findSpriteInTags($sprite_id, $tags) {
+        foreach ($tags as $tag) {
+            if ($tag->code == 39) {  // Sprite
+                if ($tag->tag->_spriteId == $sprite_id) {
+                    return $tag;
+                } else {
+                    $result = $this->findSpriteInTags($sprite_id, $tag->tag->_controlTags);
+                    if ($result) {
+                        return $result;
+                    }
+                }
+            }
+        }
+        return null;
+    }
+
+    function findSprite($sprite_id) {
+        if ($sprite_id == 0) {
+            return null;
+        } else {
+            return $this->findSpriteInTags($sprite_id, $this->_tags);
+        }
+    }
+
+    function insertAction($sprite_id, $frame, $pos, $action) {
+        if ($sprite_id == 0) {
+            $tags = $this->_tags;
+        } else {
+            $sprite = $this->findSprite($sprite_id);
+            if (!$sprite) {
+                return null;
+            }
+            $tags = $sprite->tag->_controlTags;
+        }
+        $action_tag = $this->findActionTagInTags($frame, $tags);
+        if (!$action_tag) {
+            return null;
+        }
+
+        $action_tag->tag->insertAction($pos, $action);
+
+        return true;
+    }
+
+    function insertSimpleTrace($sprite_id, $frame, $pos, $str) {
+        $push_str = array(
+            'Code' => 0x96,
+            'Length' => strlen($str) + 2,
+            'Values' => array(
+                array(
+                    'Type' => 0,
+                    'String' => $str
+                    )
+                )
+            );
+        $this->insertAction($sprite_id, $frame, $pos, $push_str);
+
+        $trace = array(
+            'Code' => 0x26,
+            'Length' => 0
+            );
+        $this->insertAction($sprite_id, $frame, $pos + 1, $trace);
+    }
+
+    function insertVarDumpTrace($sprite_id, $frame, $pos, $var) {
+        $str = "(^_^)/ $var = ";
+        $push_str = array(
+            'Code' => 0x96,
+            'Length' => strlen($str) + 2,
+            'Values' => array(
+                array(
+                    'Type' => 0,
+                    'String' => $str
+                    )
+                )
+            );
+        $this->insertAction($sprite_id, $frame, $pos, $push_str);
+        $str = $var;
+        $push_str = array(
+            'Code' => 0x96,
+            'Length' => strlen($str) + 2,
+            'Values' => array(
+                array(
+                    'Type' => 0,
+                    'String' => $str
+                    )
+                )
+            );
+        $this->insertAction($sprite_id, $frame, $pos + 1, $push_str);
+        $get_variable = array(
+            'Code' => 0x1c,
+            'Length' => 0
+            );
+        $this->insertAction($sprite_id, $frame, $pos + 2, $get_variable);
+        $string_add = array(
+            'Code' => 0x21,
+            'Length' => 0
+            );
+        $this->insertAction($sprite_id, $frame, $pos + 3, $string_add);
+        $trace = array(
+            'Code' => 0x26,
+            'Length' => 0
+            );
+        $this->insertAction($sprite_id, $frame, $pos + 4, $trace);
+    }
+
+    function rebuild() {
+        foreach ($this->_tags as $tag) {
+            $tag->buildTagContent();
+        }
+    }
+}

IO_SWF/tags/2.1.8-stable-20120220231502/IO/SWF/JPEG.php

@@ -0,0 +1,145 @@
+<?php
+
+require_once 'IO/Bit.php';
+
+class IO_SWF_JPEG {
+    var $marker_name_table = array(
+        0xD8 => 'SOI',
+        0xE0 => 'APP0',  0xE1 => 'APP1',  0xE2 => 'APP2',  0xE3 => 'APP3',
+        0xE4 => 'APP4',  0xE5 => 'APP5',  0xE6 => 'APP6',  0xE7 => 'APP7',
+        0xE8 => 'APP8',  0xE9 => 'APP9',  0xEA => 'APP10', 0xEB => 'APP11',
+        0xEC => 'APP12', 0xED => 'APP13', 0xEE => 'APP14', 0xEF => 'APP15',
+        0xFE => 'COM',
+        0xDB => 'DQT',
+        0xC0 => 'SOF0', 0xC1 => 'SOF1',  0xC2 => 'SOF2',  0xC3 => 'SOF3',
+        0xC5 => 'SOF5', 0xC6 => 'SOF6',  0xC7 => 'SOF7',
+        0xC8 => 'JPG',  0xC9 => 'SOF9',  0xCA => 'SOF10', 0xCB => 'SOF11',
+        0xCC => 'DAC',  0xCD => 'SOF13', 0xCE => 'SOF14', 0xCF => 'SOF15',
+        0xC4 => 'DHT',
+        0xDA => 'SOS',
+        0xD0 => 'RST0', 0xD1 => 'RST1', 0xD2 => 'RST2', 0xD3 => 'RST3',
+        0xD4 => 'RST4', 0xD5 => 'RST5', 0xD6 => 'RST6', 0xD7 => 'RST7',
+        0xDD => 'DRI',
+        0xD9 => 'EOI',
+        0xDC => 'DNL',   0xDE => 'DHP',  0xDF => 'EXP',
+        0xF0 => 'JPG0',  0xF1 => 'JPG1', 0xF2 => 'JPG2',  0xF3 => 'JPG3',
+        0xF4 => 'JPG4',  0xF5 => 'JPG5', 0xF6 => 'JPG6',  0xF7 => 'JPG7',
+        0xF8 => 'JPG8',  0xF9 => 'JPG9', 0xFA => 'JPG10', 0xFB => 'JPG11',
+        0xFC => 'JPG12', 0xFD => 'JPG13'
+        );
+    var $_jpegdata = null;
+    var $_jpegChunk = array();
+    function input($jpegdata) {
+        $this->_jpegdata = $jpegdata;
+    }
+    function _splitChunk() {
+        $bitin = new IO_Bit();
+        $bitin->input($this->_jpegdata);
+        while ($marker1 = $bitin->getUI8()) {
+            if ($marker1 != 0xFF) {
+                fprintf(STDERR, "dumpChunk: marker1=0x%02X", $marker1);
+                return false;
+            }
+            $marker2 = $bitin->getUI8();
+            switch ($marker2) {
+            case 0xD8: // SOI (Start of Image)
+                $this->_jpegChunk[] = array('marker' => $marker2, 'data' => null, 'length' => null);
+                continue;
+            case 0xD9: // EOE (End of Image)
+                $this->_jpegChunk[] = array('marker' => $marker2, 'data' => null, 'length' => null);
+                break 2; // while break;
+            case 0xDA: // SOS
+            case 0xD0: case 0xD1: case 0xD2: case 0xD3: // RST
+            case 0xD4: case 0xD5: case 0xD6: case 0xD7: // RST
+                list($chunk_data_offset, $dummy) = $bitin->getOffset();
+                while (true) {
+                    $next_marker1 = $bitin->getUI8();
+                    if ($next_marker1 != 0xFF) {
+                        continue;
+                    }
+                    $next_marker2 = $bitin->getUI8();
+                    if ($next_marker2 == 0x00) {
+                        continue;
+                    }
+
+                    $bitin->incrementOffset(-2, 0); // back from next marker
+                    list($next_chunk_offset, $dummy) = $bitin->getOffset();
+                    $length = $next_chunk_offset - $chunk_data_offset;
+                    $bitin->setOffset($chunk_data_offset, 0);
+                    $this->_jpegChunk[] = array('marker' => $marker2, 'data' => $bitin->getData($length), 'length' => null);
+                    break;
+                }
+                break;
+            default:
+                $length = $bitin->getUI16BE();
+                $this->_jpegChunk[] = array('marker' => $marker2, 'data' => $bitin->getData($length - 2), 'length' => $length);
+                continue;
+            }
+        }
+    }
+    // from: SOI APP* DQT SOF* DHT SOS EOI
+    // to:  SOI APP* SOF* SOS EOI
+    function getImageData() {
+        if (count($this->_jpegChunk) == 0) {
+            $this->_splitChunk();
+        }
+        $bitout = new IO_Bit();
+        foreach ($this->_jpegChunk as $chunk) {
+            $marker = $chunk['marker'];
+            if (($marker == 0xDB) || ($marker == 0xC4)) {
+                continue;  // skip DQT(0xDB) or DHT(0xC4)
+            }
+            $bitout->putUI8(0xFF);
+            $bitout->putUI8($marker);
+            if (is_null($chunk['data'])) { // SOI or EOI
+                ; // nothing to do
+            } else {
+                if (! is_null($chunk['length'])) {
+                    $bitout->putUI16BE($chunk['length']);
+                }
+                $bitout->putData($chunk['data']);
+            }
+        }
+        return $bitout->output();
+    }
+    // from: SOI APP* DQT SOF* DHT SOS EOI
+    // to:   SOI DQT DHT EOI
+    function getEncodingTables() {
+        if (count($this->_jpegChunk) == 0) {
+            $this->_splitChunk();
+        }
+        $bitout = new IO_Bit();
+        $bitout->putUI8(0xFF);
+        $bitout->putUI8(0xD8); // SOI;
+        foreach ($this->_jpegChunk as $chunk) {
+            $marker = $chunk['marker'];
+            if (($marker != 0xDB) && ($marker != 0xC4)) {
+                continue;  // skip not ( DQT(0xDB) or DHT(0xC4) )
+            }
+            $bitout->putUI8(0xFF);
+            $bitout->putUI8($marker);
+            $bitout->putUI16BE($chunk['length']);
+            $bitout->putData($chunk['data']);
+        }
+        $bitout->putUI8(0xFF);
+        $bitout->putUI8(0xD9); // EOI;
+        return $bitout->output();
+
+    }
+    function dumpChunk() { // for debug
+        if (count($this->_jpegChunk) == 0) {
+            $this->_splitChunk();
+        }
+        foreach ($this->_jpegChunk as $chunk) {
+            $marker = $chunk['marker'];
+            $marker_name = $this->marker_name_table{$marker};
+            if (is_null($chunk['data'])) {
+                echo "$marker_name:".PHP_EOL;
+            } else {
+                $length = strlen($chunk['data']);
+                $md5 = md5($chunk['data']);
+                echo "$marker_name: length=$length md5=$md5".PHP_EOL;
+            }
+        }
+    }
+}

IO_SWF/tags/2.1.8-stable-20120220231502/IO/SWF/Tag/Base.php

@@ -0,0 +1,11 @@
+<?php
+
+abstract class IO_SWF_Tag_Base {
+    var $swfInfo;
+    function __construct($swfInfo = null) {
+        $this->swfInfo = $swfInfo;
+    }
+    abstract function parseContent($tagCode, $content, $opts = array());
+    abstract function dumpContent($tagCode, $opts = array());
+    abstract function buildContent($tagCode, $opts = array());
+}

IO_SWF/tags/2.1.8-stable-20120220231502/IO/SWF/Tag/EditText.php

@@ -0,0 +1,154 @@
+<?php
+
+require_once 'IO/Bit.php';
+require_once dirname(__FILE__).'/Base.php';
+require_once dirname(__FILE__).'/../Type/RECT.php';
+require_once dirname(__FILE__).'/../Type/RGBA.php';
+require_once dirname(__FILE__).'/../Type/String.php';
+
+class IO_SWF_Tag_EditText extends IO_SWF_Tag_Base {
+   var $CharacterID;
+   var $Bounds;
+   var $WordWrap, $Multiline, $Password, $ReadOnly;
+   var $AutoSize, $NoSelect, $Border, $WasStatic, $HTML, $UseOutlines;
+   var $FontID = null, $FontClass = null, $FontHeight = null;
+   var $TextColor = null, $MaxLength = null;
+   var $Align = null, $LeftMargin, $RightMargin, $Indent, $Leading;
+   var $VariableName, $InitialText = null;
+   function parseContent($tagCode, $content, $opts = array()) {
+        $reader = new IO_Bit();
+    	$reader->input($content);
+        $this->CharacterID = $reader->getUI16LE();
+        $this->Bounds = IO_SWF_Type_RECT::parse($reader);
+        // ----
+        $reader->byteAlign();
+        $hasText         = $reader->getUIBit();
+        $this->WordWrap  = $reader->getUIBit();
+        $this->Multiline = $reader->getUIBit();
+        $this->Password  = $reader->getUIBit();
+        $this->ReadOnly  = $reader->getUIBit();
+        $hasTextColor    = $reader->getUIBit();
+        $hasMaxLength    = $reader->getUIBit();
+        $hasFont         = $reader->getUIBit();
+        // ----
+        $hasFontClass      = $reader->getUIBit();
+        $this->AutoSize    = $reader->getUIBit();
+        $hasLayout         = $reader->getUIBit();
+        $this->NoSelect    = $reader->getUIBit();
+        $this->Border      = $reader->getUIBit();
+        $this->WasStatic   = $reader->getUIBit();
+        $this->HTML        = $reader->getUIBit();
+        $this->UseOutlines = $reader->getUIBit();
+        if ($hasFont) {
+            $this->FontID = $reader->getUI16LE();
+        }
+        if ($hasFontClass) {
+            $this->FontClass = IO_SWF_Type_String::parse($reader);
+        }
+        if ($hasFont) {
+            $this->FontHeight = $reader->getUI16LE();
+        }
+        if ($hasTextColor) {
+            $this->TextColor = IO_SWF_Type_RGBA::parse($reader);
+        }
+        if ($hasMaxLength) {
+            $this->MaxLength = $reader->getUI16LE();
+        }
+        if ($hasLayout) {
+            $this->Align       = $reader->getUI8();
+            $this->LeftMargin  = $reader->getUI16LE();
+            $this->RightMargin = $reader->getUI16LE();
+            $this->Indent      = $reader->getUI16LE();
+            $this->Leading     = $reader->getSI16LE();
+        }
+
+        $this->VariableName = IO_SWF_Type_String::parse($reader);
+        if ($hasText) {
+            $this->InitialText = IO_SWF_Type_String::parse($reader);
+        }
+    }
+
+    function dumpContent($tagCode, $opts = array()) {
+        echo "\tCharacterID:{$this->CharacterID}\n";
+        echo "\t".IO_SWF_Type_RECT::string($this->Bounds)."\n";
+        echo "\tWordWrap:{$this->WordWrap} Multiline:{$this->Multiline} Password:{$this->Password} ReadOnly:{$this->ReadOnly}\n";
+        if (is_null($this->FontID) === false) {
+            echo "\tFontID:{$this->FontID} FontHeight:".($this->FontHeight/20)."\n";
+        }
+        if (is_null($this->FontClass) === false) {
+            echo "\tFontClass:{$this->FontClass}({".bin2hex($this->FontClass).")\n";
+        }
+        if (is_null($this->TextColor) === false) {
+            echo "\tTextColor".IO_SWF_Type_RGBA::string($this->TextColor)."\n";
+        }
+        if (is_null($this->MaxLength) === false) {
+            echo "\tMaxLength:{$this->MaxLength}\n";
+        }
+        if (is_null($this->Align) === false) {
+            echo "\tAlign:{$this->Align} LeftMargin:{$this->LeftMargin} RightMargin:{$this->RightMargin} Indent:{$this->Indent} Leading:".($this->Leading/20)."\n";
+        }
+        echo "\tVariableName:{$this->VariableName}\n";
+        if (is_null($this->InitialText) == false) {
+            echo "\tInitialText:{$this->InitialText}\n";
+        }
+    }
+
+    function buildContent($tagCode, $opts = array()) {
+        $writer = new IO_Bit();
+        $writer->putUI16LE($this->CharacterID);
+        IO_SWF_Type_RECT::build($writer, $this->Bounds);
+        // ----
+        $hasText = is_null($this->InitialText)?0:1;
+        $hasTextColor = is_null($this->TextColor)?0:1;
+        $hasMaxLength = is_null($this->MaxLength)?0:1;
+        $hasFont = is_null($this->FontID)?0:1;
+        $hasFontClass = is_null($this->FontClass)?0:1;
+        $hasLayout = is_null($this->Align)?0:1;
+        // ----
+        $writer->byteAlign();
+        $writer->putUIBit($hasText);
+        $writer->putUIBit($this->WordWrap);
+        $writer->putUIBit($this->Multiline);
+        $writer->putUIBit($this->Password);
+        $writer->putUIBit($this->ReadOnly);
+        $writer->putUIBit($hasTextColor);
+        $writer->putUIBit($hasMaxLength);
+        $writer->putUIBit($hasFont);
+        // ----
+        $writer->putUIBit($hasFontClass);
+        $writer->putUIBit($this->AutoSize);
+        $writer->putUIBit($hasLayout);
+        $writer->putUIBit($this->NoSelect);
+        $writer->putUIBit($this->Border);
+        $writer->putUIBit($this->WasStatic);
+        $writer->putUIBit($this->HTML);
+        $writer->putUIBit($this->UseOutlines);
+        if ($hasFont) {
+            $writer->putUI16LE($this->FontID);
+        }
+        if ($hasFontClass) {
+            IO_SWF_Type_String::build($writer, $this->FontClass);
+        }
+        if ($hasFont) {
+            $writer->putUI16LE($this->FontHeight);
+        }
+        if ($hasTextColor) {
+            IO_SWF_Type_RGBA::build($writer, $this->TextColor);
+        }
+        if ($hasMaxLength) {
+            $writer->putUI16LE($this->MaxLength);
+        }
+        if ($hasLayout) {
+            $writer->putUI8($this->Align);
+            $writer->putUI16LE($this->LeftMargin);
+            $writer->putUI16LE($this->RightMargin);
+            $writer->putUI16LE($this->Indent);
+            $writer->putSI16LE($this->Leading);
+        }
+        IO_SWF_Type_String::build($writer, $this->VariableName);
+        if ($hasText) {
+            IO_SWF_Type_String::build($writer, $this->InitialText);
+        }
+    	return $writer->output();
+    }
+}

IO_SWF/tags/2.1.8-stable-20120220231502/IO/SWF/Tag/FrameLabel.php

@@ -0,0 +1,26 @@
+<?php
+
+require_once 'IO/Bit.php';
+require_once dirname(__FILE__).'/Base.php';
+require_once dirname(__FILE__).'/../Type/String.php';
+
+class IO_SWF_Tag_FrameLabel extends IO_SWF_Tag_Base {
+    var $_label;
+
+    function parseContent($tagCode, $content, $opts = array()) {
+        $reader = new IO_Bit();
+    	$reader->input($content);
+        $this->_label = IO_SWF_Type_String::parse($reader);
+    }
+
+    function dumpContent($tagCode, $opts = array()) {
+        $label_str = IO_SWF_Type_String::string($this->_label);
+        echo "\tLabel: $label_str\n";
+    }
+
+    function buildContent($tagCode, $opts = array()) {
+        $writer = new IO_Bit();
+        IO_SWF_Type_String::build($writer, $this->_label);
+    	return $writer->output();
+    }
+}
属性に変更があったパス: IO_SWF/tags/2.1.8-stable-20120220231502/IO/SWF/Tag/FrameLabel.php
___________________________________________________________________
追加: svn:executable
+ *

IO_SWF/tags/2.1.8-stable-20120220231502/IO/SWF/Tag/Button.php

@@ -0,0 +1,133 @@
+<?php
+
+require_once 'IO/Bit.php';
+require_once dirname(__FILE__).'/Base.php';
+require_once dirname(__FILE__).'/../Tag.php';
+require_once dirname(__FILE__).'/../Type/BUTTONRECORD.php';
+require_once dirname(__FILE__).'/../Type/BUTTONCONDACTION.php';
+require_once dirname(__FILE__).'/../Type/Action.php';
+
+class IO_SWF_Tag_Button extends IO_SWF_Tag_Base {
+    var $_buttonId = null;
+    var $_reservedFlags = null;
+    var $_trackAsMenu = null;
+    var $_actionOffset = null;
+    var $_characters = null;
+    var $_actions = null;
+    function parseContent($tagCode, $content, $opts = array()) {
+        $reader = new IO_Bit();
+    	$reader->input($content);
+        $this->_buttonId = $reader->getUI16LE();
+        $opts['tagCode'] = $tagCode;
+        if ($tagCode == 34) { // DefineButton2
+            $this->_reservedFlags = $reader->getUIBits(7);
+            $this->_trackAsMenu = $reader->getUIBit();
+            list($offset_actionOffset, $dummy) = $reader->getOffset();
+            $this->_actionOffset = $reader->getUI16LE();
+        }
+        $characters = array();
+        while ($reader->getUI8() != 0) {
+            $reader->incrementOffset(-1, 0); // 1 byte back
+            $characters []= IO_SWF_Type_BUTTONRECORD::parse($reader, $opts);
+        }
+        $this->_characters = $characters;
+        if ($tagCode == 34) { // DefineButton2
+            // TODO: skip ActionOffset - CurrentOffsetUntilCharactersField
+            $actions = array();
+            if ($this->_actionOffset > 0) {
+                list($offset_buttonCondition, $dummy) = $reader->getOffset();
+                if ($offset_actionOffset + $this->_actionOffset != $offset_buttonCondition) {
+                    // TODO: warning
+                    $reader->setOffset($offset_actionOffset + $this->_actionOffset, 0);
+                }
+                while (true) {
+                    $action  = IO_SWF_Type_BUTTONCONDACTION::parse($reader, $opts);
+                    $actions []= $action;
+                    if ($action['CondActionSize'] == 0) {
+                        break; // last action
+                    }
+                }
+                $this->_actions = $actions;
+            } else {
+                $this->_actions = null;
+            }
+        } else {
+            $actions = array();
+            while ($reader->getUI8() != 0) {
+                $reader->incrementOffset(-1, 0); // 1 byte back
+                $actions []= IO_SWF_Type_Action::parse($reader);
+            }
+            $this->_actions = $actions;
+        }
+        return true;
+    }
+
+    function dumpContent($tagCode, $opts = array()) {
+        $opts['tagCode'] = $tagCode;
+        echo "\tButtonID:{$this->_buttonId} TrackAsMenu:{$this->_trackAsMenu} (ActionOffset:{$this->_actionOffset})\n";
+        echo "\t    Characters:\n";
+        $opts['indent']++;
+        foreach ($this->_characters as $character) {
+            $buttonrecord_str = IO_SWF_Type_BUTTONRECORD::string($character, $opts);
+            echo "\t\t$buttonrecord_str\n";
+        }
+        echo "\t    Actions:\n";
+        if ($tagCode == 34) { // DefineButton2
+            if (is_null($this->_actions)) {
+                echo "\t\t(no actions)\n";
+            } else {
+                foreach ($this->_actions as $action) {
+                    $action_str = IO_SWF_Type_BUTTONCONDACTION::string($action, $opts);
+                    echo "\t\t$action_str\n";
+                }
+            }
+        } else {
+            if (is_null($this->_actions)) {
+                echo "\t\t(no actions)\n";
+            } else {
+                foreach ($this->_actions as $action) {
+                    $action_str = IO_SWF_Type_Action::string($action, $opts);
+                    echo "\t\t$action_str\n";
+                }
+            }
+        }
+    }
+
+    function buildContent($tagCode, $opts = array()) {
+        $writer = new IO_Bit();
+        $writer->putUI16LE($this->_buttonId);
+        $opts['tagCode'] = $tagCode;        ;
+        if ($tagCode == 34) { // DefineButton2
+            $writer->putUIBits($this->_reservedFlags, 7);
+            $writer->putUIBit($this->_trackAsMenu);
+            list($offset_actionOffset, $dummy) = $writer->getOffset();
+            $writer->putUI16LE(0); // dummy;
+        }
+        foreach ($this->_characters as $character) {
+            IO_SWF_Type_BUTTONRECORD::build($writer, $character, $opts);
+        }
+        $writer->putUI8(0); // terminater of button record
+        if ($tagCode == 34) { // DefineButton2
+            $actions = array();
+            if (is_null($this->_actions) === false) {
+                list($offset_buttonCondition, $dummy) = $writer->getOffset();
+                $writer->setUI16LE($offset_buttonCondition - $offset_actionOffset, $offset_actionOffset);
+                foreach ($this->_actions as $idx => $action) {
+                    if (isset($this->_actions[$idx + 1]) === false) {
+                        $opts['lastAction'] = true;
+                    } else {
+                        $opts['lastAction'] = false;
+                    }
+                    IO_SWF_Type_BUTTONCONDACTION::build($writer, $action, $opts);
+                }
+            }
+        } else {
+            foreach ($this->_actions as $action) {
+                IO_SWF_Type_Action::build($writer, $action);
+            }
+            $writer->putUI8(0); // terminator of actions
+
+        }
+    	return $writer->output();
+    }
+}
属性に変更があったパス: IO_SWF/tags/2.1.8-stable-20120220231502/IO/SWF/Tag/Button.php
___________________________________________________________________
追加: svn:keywords
+ Id
追加: svn:eol-style
+ native

IO_SWF/tags/2.1.8-stable-20120220231502/IO/SWF/Tag/Action.php

@@ -0,0 +1,174 @@
+<?php
+
+/*
+ * 2011/06/03- (c) yoya@awm.jp
+ */
+
+require_once 'IO/Bit.php';
+require_once dirname(__FILE__).'/Base.php';
+require_once dirname(__FILE__).'/../Type/Action.php';
+require_once dirname(__FILE__).'/../Tag/Button.php';
+
+class IO_SWF_Tag_Action extends IO_SWF_Tag_Base {
+    var $_actions = array();
+    var $_spriteId = null; // DoInitAction
+    var $_labels = array();
+    var $_branches = array();
+    var $_byteOffsetTable = array();
+    var $_byteSizeTable = array();
+
+    static function actionLength($action) {
+        $length = 1;
+        if ($action['Code'] >= 0x80) {
+            $length += 2 + $action['Length'];
+        }
+        return $length;
+    }
+
+    function parseContent($tagCode, $content, $opts = array()) {
+        $reader = new IO_Bit();
+    	$reader->input($content);
+        if ($tagCode == 59) { // DoInitAction
+            $this->_spriteId = $reader->getUI16LE();
+        }
+        $i = 0;
+        while ($reader->getUI8() != 0) {
+            $reader->incrementOffset(-1, 0); // 1 byte back
+            list($byteOffset, $dummy) = $reader->getOffset();
+            $action = IO_SWF_Type_Action::parse($reader);
+            list($nextByteOffset, $dummy) = $reader->getOffset();
+            //
+            $this->_byteOffsetTable[$i] = $byteOffset;
+            $this->_byteSizeTable[$i] = $nextByteOffset - $byteOffset;
+            $recordOffsetToByteOffset[$i] = $byteOffset;
+            $byteOffsetToRecordOffset[$byteOffset] = $i;
+            //
+            $this->_actions [] = $action;
+            $i++;
+        }
+        if ($i > 0) {
+            $recordOffsetToByteOffset[$i] = $nextByteOffset;
+            $byteOffsetToRecordOffset[$nextByteOffset] = $i;
+            $byteOffsetToRecordOffset[$nextByteOffset] = $i;
+        }
+
+        $label_num = 0;
+        foreach ($this->_actions as $i => $action) {
+            if ($action['Code'] == 0x99) {  // Jump
+                $branch_offset = $action['BranchOffset'];
+            } else if ($action['Code'] == 0x9D) {  // If
+                $branch_offset = $action['Offset'];
+            } else {
+                continue;
+            }
+            $targetByteOffset = $recordOffsetToByteOffset[$i + 1] + $branch_offset;
+            if (isset($byteOffsetToRecordOffset[$targetByteOffset])) {
+                $targetRecordOffset = $byteOffsetToRecordOffset[$targetByteOffset];
+                if (isset($this->_labels[$targetRecordOffset]) === false) {
+                    $this->_labels[$targetRecordOffset] = $targetRecordOffset;
+                }
+                $this->_branches[$i] = $this->_labels[$targetRecordOffset];
+            }
+        }
+    }
+
+    function dumpContent($tagCode, $opts = array()) {
+        echo "    Actions:";
+        if ($tagCode == 59) { // DoInitAction
+            echo " SpriteID=".$this->_spriteId;
+        }
+        echo "\n";
+        foreach ($this->_actions as $i => $action) {
+            if (isset($opts['addlabel']) && $opts['addlabel']
+                && isset($this->_labels[$i])) {
+                echo "    (LABEL: " . $this->_labels[$i] . "):\n";
+            }
+            $action_str = IO_SWF_Type_Action::string($action);
+            if (isset($opts['addlabel']) && $opts['addlabel']
+                && isset($this->_branches[$i])) {
+                echo "\t[$i] $action_str (LABEL: " . $this->_branches[$i] . ")\n";
+            } else {
+                echo "\t[$i] $action_str\n";
+            }
+        }
+        if (isset($opts['addlabel']) && $opts['addlabel']
+            && isset($this->_labels[$i])) {
+            echo "    (LABEL" . $this->_labels[$i] . "):\n";
+        }
+    }
+
+    function buildContent($tagCode, $opts = array()) {
+        $writer = new IO_Bit();
+        if ($tagCode == 59) { // DoInitAction
+            $writer->putUI16LE($this->_spriteId);
+        }
+        for ($i = 0; $i < count($this->_actions); $i++) {
+            $action = $this->_actions[$i];
+            if ($action['Code'] == 0x99 || $action['Code'] == 0x9D) {  // Jump
+                // Find label to jump
+                for ($j = 0; $j <= count($this->_actions); $j++) {
+                    if (isset($this->_labels[$j])
+                        && $this->_labels[$j] == $this->_branches[$i]) {
+                        break;
+                    }
+                }
+
+                // Calculate new offset
+                $branch_offset = 0;
+                if ($i < $j) {
+                    for ($k = $i + 1; $k < $j; $k++) {
+                        $branch_offset += IO_SWF_Tag_Action::actionLength(
+                            $this->_actions[$k]);
+                    }
+                } else {
+                    for ($k = $i; $k >= $j; $k--) {
+                        $branch_offset -= IO_SWF_Tag_Action::actionLength(
+                            $this->_actions[$k]);
+                    }
+                }
+                if ($action['Code'] == 0x99) {  // Jump
+                    $action['BranchOffset'] = $branch_offset;
+                }
+                if ($action['Code'] == 0x9D) {  // If
+                    $action['Offset'] = $branch_offset;
+                }
+            }
+            IO_SWF_Type_Action::build($writer, $action);
+        }
+        $writer->putUI8(0); // ActionEndFlag
+    	return $writer->output();
+    }
+
+    function replaceActionStrings($trans_table) {
+        foreach ($this->_actions as &$action) {
+            IO_SWF_Type_Action::replaceActionString($action, $trans_table);
+        }
+        unset($action);
+        return true;
+    }
+
+    function insertAction($pos, $action) {
+        array_splice($this->_actions, $pos, 0, array($action));
+
+        $labels = array();
+        $branches = array();
+
+        foreach ($this->_labels as $key => $value) {
+            if ($key < $pos) {
+                $labels[$key] = $value;
+            } else {
+                $labels[$key + 1] = $value;
+            }
+        }
+        $this->_labels = $labels;
+
+        foreach ($this->_branches as $key => $value) {
+            if ($key < $pos) {
+                $branches[$key] = $value;
+            } else {
+                $branches[$key + 1] = $value;
+            }
+        }
+        $this->_branches = $branches;
+    }
+}

IO_SWF/tags/2.1.8-stable-20120220231502/IO/SWF/Tag/Remove.php

@@ -0,0 +1,47 @@
+<?php
+
+require_once 'IO/Bit.php';
+require_once dirname(__FILE__).'/Base.php';
+
+class IO_SWF_Tag_Remove extends IO_SWF_Tag_Base {
+    var $_characterId = null;
+    var $_depth;
+
+    function parseContent($tagCode, $content, $opts = array()) {
+        $reader = new IO_Bit();
+    	$reader->input($content);
+        switch ($tagCode) {
+        case 5:   // RemoveObject
+            $this->_characterId = $reader->getUI16LE();
+            $this->_depth = $reader->getUI16LE();
+            break;
+        case 28:  // RemoveObject2
+            $this->_depth = $reader->getUI16LE();
+            break;
+        }
+        return true;
+    }
+
+    function dumpContent($tagCode, $opts = array()) {
+        if (is_null($this->_characterId) === false) {
+            echo "\tCharacterId: ".$this->_characterId."\n";
+        }
+        if (is_null($this->_depth) === false) {
+            echo "\tDepth: ".$this->_depth."\n";
+        }
+    }
+
+    function buildContent($tagCode, $opts = array()) {
+        $writer = new IO_Bit();
+        switch ($tagCode) {
+        case 5:   // RemoveObject
+            $writer->putUI16LE($this->_characterId);
+            $writer->putUI16LE($this->_depth);
+            break;
+        case 28:  // RemoveObject2
+            $writer->putUI16LE($this->_depth);
+            break;
+        }
+    	return $writer->output();
+    }
+}

IO_SWF/tags/2.1.8-stable-20120220231502/IO/SWF/Tag/Shape.php

@@ -0,0 +1,362 @@
+<?php
+
+require_once 'IO/Bit.php';
+require_once dirname(__FILE__).'/Base.php';
+require_once dirname(__FILE__).'/../Type/RECT.php';
+require_once dirname(__FILE__).'/../Type/FILLSTYLEARRAY.php';
+require_once dirname(__FILE__).'/../Type/LINESTYLEARRAY.php';
+require_once dirname(__FILE__).'/../Type/SHAPE.php';
+
+class IO_SWF_Tag_Shape extends IO_SWF_Tag_Base {
+    var $_shapeId = null;
+    // DefineShape, DefineShape2, DefineShape3
+    var $_shapeBounds;
+    var $_fillStyles, $_lineStyles;
+    var $_shapeRecords;
+    // DefineMorphShape
+    var $_startBounds, $_endBounds;
+    var $_offset;
+    var $_morphFillStyles, $_morphLineStyles;
+    var $_startEdge, $_endEdges;
+
+   function parseContent($tagCode, $content, $opts = array()) {
+       // DefineMorphShape, DefineMorphShape2
+        $isMorph = ($tagCode == 46) || ($tagCode == 84);
+
+        $reader = new IO_Bit();
+    	$reader->input($content);
+        $this->_shapeId = $reader->getUI16LE();
+
+        $opts = array('tagCode' => $tagCode, 'isMorph' => $isMorph);
+
+        if ($isMorph === false) {
+        	// 描画スタイル
+            $this->_shapeBounds = IO_SWF_TYPE_RECT::parse($reader);
+            if ($tagCode == 83) { // DefineShape4
+                $this->_edgeBounds = IO_SWF_TYPE_RECT::parse($reader);
+                $this->_reserved = $reader->getUIBits(6);
+                $this->_usesNonScalingStrokes = $reader->getUIBit();
+                $this->_UsesScalingStrokes = $reader->getUIBit();
+            }
+            $this->_fillStyles = IO_SWF_TYPE_FILLSTYLEARRAY::parse($reader, $opts);
+        	$this->_lineStyles = IO_SWF_TYPE_LINESTYLEARRAY::parse($reader, $opts);
+        	// 描画枠
+            $this->_shapeRecords = IO_SWF_Type_SHAPE::parse($reader, $opts);
+        } else {
+            $this->_startBounds = IO_SWF_TYPE_RECT::parse($reader);
+            $this->_endBounds = IO_SWF_TYPE_RECT::parse($reader);
+            list($offset_offset, $dummy) = $reader->getOffset();
+            $this->_offset = $reader->getUI32LE();
+        	// 描画スタイル
+            $this->_morphFillStyles = IO_SWF_TYPE_FILLSTYLEARRAY::parse($reader, $opts);
+        	$this->_morphLineStyles = IO_SWF_TYPE_LINESTYLEARRAY::parse($reader, $opts);
+        	// 描画枠
+            $this->_startEdge = IO_SWF_Type_SHAPE::parse($reader, $opts);
+            list($end_edge_offset, $dummy) = $reader->getOffset();
+            if ($offset_offset + $this->_offset + 4 != $end_edge_offset) {
+                trigger_error("offset_offset($offset_offset) + this->_offset({$this->_offset}) + 4 != end_edge_offset($end_edge_offset)", E_USER_WARNING);
+                $reader->setOffset($offset_offset + $this->_offset + 4, 0);
+            }
+            $this->_endEdge   = IO_SWF_Type_SHAPE::parse($reader, $opts);
+        }
+    }
+
+    function dumpContent($tagCode, $opts = array()) {
+        $isMorph = ($tagCode == 46) || ($tagCode == 84);
+        if (is_null($this->_shapeId) === false) {
+            echo "    ShapeId: {$this->_shapeId}\n";
+        }
+        $opts = array('tagCode' => $tagCode, 'isMorph' => $isMorph);
+
+        if ($isMorph === false) {
+            echo "    ShapeBounds: ". IO_SWF_Type_RECT::string($this->_shapeBounds)."\n";
+            echo "    FillStyles:\n";
+            echo IO_SWF_Type_FILLSTYLEARRAY::string($this->_fillStyles, $opts);
+            echo "    LineStyles:\n";
+            echo IO_SWF_Type_LINESTYLEARRAY::string($this->_lineStyles, $opts);
+
+            echo "    ShapeRecords:\n";
+            echo IO_SWF_Type_SHAPE::string($this->_shapeRecords, $opts);
+        } else {
+            echo "    StartBounds: ". IO_SWF_Type_RECT::string($this->_startBounds)."\n";
+            echo "    EndBounds: ". IO_SWF_Type_RECT::string($this->_endBounds)."\n";
+            echo "    Offset:{$this->_offset}\n";
+            echo "    FillStyles:\n";
+            echo IO_SWF_Type_FILLSTYLEARRAY::string($this->_morphFillStyles, $opts);
+            echo "    LineStyles:\n";
+            echo IO_SWF_Type_LINESTYLEARRAY::string($this->_morphLineStyles, $opts);
+
+            echo "    StartEdge:\n";
+            echo IO_SWF_Type_SHAPE::string($this->_startEdge, $opts);
+            echo "    endEdge:\n";
+            echo IO_SWF_Type_SHAPE::string($this->_endEdge, $opts);
+        }
+    }
+
+    function buildContent($tagCode, $opts = array()) {
+        $isMorph = ($tagCode == 46) || ($tagCode == 84);
+        $writer = new IO_Bit();
+        if (empty($opts['noShapeId'])) {
+            $writer->putUI16LE($this->_shapeId);
+        }
+        $opts = array('tagCode' => $tagCode);
+
+        if ($isMorph === false) {
+            IO_SWF_Type_RECT::build($writer, $this->_shapeBounds);
+            // 描画スタイル
+            IO_SWF_Type_FILLSTYLEARRAY::build($writer, $this->_fillStyles, $opts);
+            IO_SWF_Type_LINESTYLEARRAY::build($writer, $this->_lineStyles, $opts);
+        	// 描画枠
+            $opts['fillStyleCount'] = count($this->_fillStyles);
+            $opts['lineStyleCount'] = count($this->_lineStyles);
+            IO_SWF_Type_SHAPE::build($writer, $this->_shapeRecords, $opts);
+        } else {
+            IO_SWF_Type_RECT::build($writer, $this->_startBounds);
+            IO_SWF_Type_RECT::build($writer, $this->_endBounds);
+
+            $writer->byteAlign();
+            list($offset_offset, $dummy) = $writer->getOffset();
+            $this->_offset = $writer->putUI32LE(0); // at first, write dummy
+
+            // 描画スタイル
+            IO_SWF_Type_FILLSTYLEARRAY::build($writer, $this->_morphFillStyles, $opts);
+            IO_SWF_Type_LINESTYLEARRAY::build($writer, $this->_morphLineStyles, $opts);
+        	// 描画枠
+            $opts['fillStyleCount'] = count($this->_morphFillStyles);
+            $opts['lineStyleCount'] = count($this->_morphLineStyles);
+
+            // StartEdge
+            IO_SWF_Type_SHAPE::build($writer, $this->_startEdge, $opts);
+
+            // EndEdge
+            $writer->byteAlign();
+            list($end_edge_offset, $dummy) = $writer->getOffset();
+            $this->_offset = $end_edge_offset - $offset_offset - 4;
+            $writer->setUI32LE($this->_offset, $offset_offset);
+
+            IO_SWF_Type_SHAPE::build($writer, $this->_endEdge, $opts);
+        }
+        return $writer->output();
+    }
+
+    function deforme($threshold) {
+        $startIndex = null;
+        foreach ($this->_shapeRecords as $shapeRecordIndex => $shapeRecord) {
+            if (($shapeRecord['TypeFlag'] == 0) && (isset($shapeRecord['EndOfShape']) === false)) {
+                // StyleChangeRecord
+                $endIndex = $shapeRecordIndex - 1;
+                if (is_null($startIndex) === false) {
+                    $this->deformeShapeRecordUnit($threshold, $startIndex, $endIndex);
+                }
+                $startIndex = $shapeRecordIndex;
+            }
+            if (isset($shapeRecord['EndOfShape']) && ($shapeRecord['EndOfShape']) == 0) {
+                // EndShapeRecord
+                $endIndex = $shapeRecordIndex - 1;
+               $this->deformeShapeRecordUnit($threshold, $startIndex, $endIndex);
+            }
+        }
+        $this->_shapeRecords = array_values($this->_shapeRecords);
+    }
+
+    function deformeShapeRecordUnit($threshold, $startIndex, $endIndex) {
+//        return $this->deformeShapeRecordUnit_1($threshold, $startIndex, $endIndex);
+        return $this->deformeShapeRecordUnit_2($threshold, $startIndex, $endIndex);
+    }
+    function deformeShapeRecordUnit_1($threshold, $startIndex, $endIndex) {
+        $threshold_2 = $threshold * $threshold;
+        $shapeRecord = $this->_shapeRecords[$startIndex];
+        $prevIndex = null;
+        $currentDrawingPositionX = $shapeRecord['MoveX'];
+        $currentDrawingPositionY = $shapeRecord['MoveY'];
+        for ($i = $startIndex + 1 ;$i <= $endIndex; $i++) {
+            $shapeRecord = & $this->_shapeRecords[$i];
+            if ($shapeRecord['StraightFlag'] == 0) {
+                // 曲線に対する処理
+                $diff_x = $shapeRecord['ControlX'] - $currentDrawingPositionX;
+                $diff_y = $shapeRecord['ControlY'] - $currentDrawingPositionY;
+                $distance_2_control = $diff_x * $diff_x + $diff_y * $diff_y;
+                $diff_x = $shapeRecord['AnchorX'] - $currentDrawingPositionX;
+                $diff_y = $shapeRecord['AnchorY'] - $currentDrawingPositionY;
+                $distance_2_anchor = $diff_x * $diff_x + $diff_y * $diff_y;
+//                if (max($distance_2_control, $distance_2_anchor) > $threshold_2) {
+                if (($distance_2_control +  $distance_2_anchor) > $threshold_2) {
+                    // 何もしない
+                    $prevIndex = $i;
+                    $prevDrawingPositionX = $currentDrawingPositionX;
+                    $prevDrawingPositionY = $currentDrawingPositionY;
+                    $currentDrawingPositionX = $shapeRecord['AnchorX'];
+                    $currentDrawingPositionY = $shapeRecord['AnchorY'];
+                    continue; // skip
+                }
+                // 直線に変換する
+                $shapeRecord['StraightFlag'] = 1; // to Straight
+                $shapeRecord['X'] = $shapeRecord['AnchorX'];
+                $shapeRecord['Y'] = $shapeRecord['AnchorY'];
+                unset($shapeRecord['ControlX'], $shapeRecord['ControlY']);
+                unset($shapeRecord['AnchorX'], $shapeRecord['AnchorY']);
+            }
+            if (is_null($prevIndex)) {
+                // 何もしない
+                $prevIndex = $i;
+                $prevDrawingPositionX = $currentDrawingPositionX;
+                $prevDrawingPositionY = $currentDrawingPositionY;
+                $currentDrawingPositionX = $shapeRecord['X'];
+                $currentDrawingPositionY = $shapeRecord['Y'];
+                continue; // skip
+            }
+            $diff_x = $shapeRecord['X'] - $prevDrawingPositionX;
+            $diff_y = $shapeRecord['Y'] - $prevDrawingPositionY;
+            $distance_2 = $diff_x * $diff_x + $diff_y * $diff_y;
+            if ($distance_2 > $threshold_2) {
+                // 何もしない
+                $prevIndex = $i;
+                $prevDrawingPositionX = $currentDrawingPositionX;
+                $prevDrawingPositionY = $currentDrawingPositionY;
+                $currentDrawingPositionX = $shapeRecord['X'];
+                $currentDrawingPositionY = $shapeRecord['Y'];
+                continue; // skip
+            }
+            // 前の直線にくっつける。
+            $prevShapeRecord = & $this->_shapeRecords[$prevIndex];
+            $prevShapeRecord['X'] = $shapeRecord['X'];
+            $prevShapeRecord['Y'] = $shapeRecord['Y'];
+            $currentDrawingPositionX = $shapeRecord['X'];
+            $currentDrawingPositionY = $shapeRecord['Y'];
+            unset($this->_shapeRecords[$i]);
+        }
+    }
+
+    function deformeShapeRecordUnit_2($threshold, $startIndex, $endIndex) {
+        $this->deformeShapeRecordUnit_2_curve($threshold, $startIndex, $endIndex);
+        while ($this->deformeShapeRecordUnit_2_line($threshold, $startIndex, $endIndex));
+    }
+
+    function deformeShapeRecordUnit_2_curve($threshold, $startIndex, $endIndex) {
+        $threshold_2 = $threshold * $threshold;
+        $shapeRecord = $this->_shapeRecords[$startIndex];
+        $currentDrawingPositionX = $shapeRecord['MoveX'];
+        $currentDrawingPositionY = $shapeRecord['MoveY'];
+        for ($i = $startIndex + 1 ;$i <= $endIndex; $i++) {
+            $shapeRecord = & $this->_shapeRecords[$i];
+            if ($shapeRecord['StraightFlag'] == 0) {
+            // 曲線に対する処理
+                $diff_x = $shapeRecord['ControlX'] - $currentDrawingPositionX;
+                $diff_y = $shapeRecord['ControlY'] - $currentDrawingPositionY;
+                $distance_2_control = $diff_x * $diff_x + $diff_y * $diff_y;
+                $diff_x = $shapeRecord['AnchorX'] - $currentDrawingPositionX;
+                $diff_y = $shapeRecord['AnchorY'] - $currentDrawingPositionY;
+                $distance_2_anchor = $diff_x * $diff_x + $diff_y * $diff_y;
+                if (($distance_2_control +  $distance_2_anchor) > $threshold_2) {
+                    // 何もしない
+                    $currentDrawingPositionX = $shapeRecord['AnchorX'];
+                    $currentDrawingPositionY = $shapeRecord['AnchorY'];
+                    continue; // skip
+                }
+                // 直線に変換する
+                $shapeRecord['StraightFlag'] = 1; // to Straight
+                $shapeRecord['X'] = $shapeRecord['AnchorX'];
+                $shapeRecord['Y'] = $shapeRecord['AnchorY'];
+                unset($shapeRecord['ControlX'], $shapeRecord['ControlY']);
+                unset($shapeRecord['AnchorX'], $shapeRecord['AnchorY']);
+                $currentDrawingPositionX = $shapeRecord['X'];
+                $currentDrawingPositionY = $shapeRecord['Y'];
+            }
+        }
+    }
+
+    function deformeShapeRecordUnit_2_line($threshold, $startIndex, $endIndex) {
+        $threshold_2 = $threshold * $threshold;
+        $shapeRecord = $this->_shapeRecords[$startIndex];
+        $prevIndex = null;
+        $currentDrawingPositionX = $shapeRecord['MoveX'];
+        $currentDrawingPositionY = $shapeRecord['MoveY'];
+        $distance_list_short = array();
+        $distance_table_all = array();
+        for ($i = $startIndex + 1 ;$i <= $endIndex; $i++) {
+            $shapeRecord = & $this->_shapeRecords[$i];
+            if ($shapeRecord['StraightFlag'] == 0) {
+                $diff_x = $shapeRecord['ControlX'] - $currentDrawingPositionX;
+                $diff_y = $shapeRecord['ControlY'] - $currentDrawingPositionY;
+                $distance_2_control = $diff_x * $diff_x + $diff_y * $diff_y;
+                $diff_x = $shapeRecord['AnchorX'] - $currentDrawingPositionX;
+                $diff_y = $shapeRecord['AnchorY'] - $currentDrawingPositionY;
+                $distance_2_anchor = $diff_x * $diff_x + $diff_y * $diff_y;
+//                $distance_list[$i] = $distance_2_control +  $distance_2_anchor;
+                $distance_table_all[$i] = $distance_2_control +  $distance_2_anchor;
+                $currentDrawingPositionX = $shapeRecord['AnchorX'];
+                $currentDrawingPositionY = $shapeRecord['AnchorY'];
+            } else {
+                $diff_x = $shapeRecord['X'] - $currentDrawingPositionX;
+                $diff_y = $shapeRecord['Y'] - $currentDrawingPositionY;
+            $distance_2 = $diff_x * $diff_x + $diff_y * $diff_y;
+            if ($distance_2 < $threshold_2) {
+               $distance_list_short[] = $i;
+            }
+            $distance_table_all[$i] = $distance_2;
+            $currentDrawingPositionX = $shapeRecord['X'];
+            $currentDrawingPositionY = $shapeRecord['Y'];
+        }
+    }
+    sort($distance_list_short);
+    $deforme_number = 0;
+    foreach ($distance_list_short as $i) {
+        $distance_2 = $distance_table_all[$i];
+        if ($distance_2 > $threshold_2) {
+            continue; // 一定距離以上の線分は処理しない
+        }
+        if (empty($distance_list_all[$i-1]) && empty($distance_list_all[$i+1])) {
+            // 隣の線分が吸収され済みor曲線の場合は処理しない
+
+        }
+        $index_to_merge;
+        if (empty($distance_list_all[$i-1])) {
+            if (empty($distance_list_all[$i+1])) {
+                // 隣の線分が吸収されている場合は処理しない
+                continue;
+            } else {
+                $index_to_merge = $i+1;
+            }
+        } else {
+            if (empty($distance_list_all[$i+1])) {
+                $index_to_merge = $i-1;
+            } else {
+                $index_to_merge = $i-1; // XXX 後で選択する処理を入れる
+            }
+        }
+        // line merge 処理
+        $shapeRecord = $this->_shapeRecords[$i];
+        $shapeRecord_toMerge = & $this->_shapeRecords[$index_to_merge];
+        if ($i > $index_to_merge) {
+            if ($shapeRecord['StraightFlag']) {
+                $shapeRecord_toMerge['X'] = $shapeRecord['X'];
+                $shapeRecord_toMerge['Y'] = $shapeRecord['Y'];
+            } else {
+                $shapeRecord_toMerge['AnchorX'] = $shapeRecord['X'];
+                $shapeRecord_toMerge['AnchorY'] = $shapeRecord['Y'];
+            }
+        }
+        $distance_list_all[$index_to_merge] += $distance_list_all[$i];
+//        unset($distance_list_all[$i]);
+          unset($this->_shapeRecords[$i]);
+          $deforme_number += 1;
+        }
+        return $deforme_number;
+    }
+    function countEdges() {
+        $edges_count = 0;
+	if (isset($this->_shapeRecords)) {
+	    $shapeRecords = $this->_shapeRecords;
+	} elseif (isset($this->_startEdge)) {
+	    $shapeRecords = $this->_startEdge;
+	} else {
+	    $shapeRecords = array(); // nothing to do.
+	}
+	foreach ($shapeRecords as $shapeRecordIndex => $shapeRecord) {
+	    if (isset($shapeRecord['StraightFlag'])) { // XXX
+	        $edges_count++;
+	    }
+	}
+	return array($this->_shapeId, $edges_count);
+    }
+}
属性に変更があったパス: IO_SWF/tags/2.1.8-stable-20120220231502/IO/SWF/Tag/Shape.php
___________________________________________________________________
追加: svn:mergeinfo

IO_SWF/tags/2.1.8-stable-20120220231502/IO/SWF/Tag/Place.php

@@ -0,0 +1,187 @@
+<?php
+
+require_once 'IO/Bit.php';
+require_once dirname(__FILE__).'/Base.php';
+require_once dirname(__FILE__).'/../Tag.php';
+require_once dirname(__FILE__).'/../Type/String.php';
+require_once dirname(__FILE__).'/../Type/CXFORM.php';
+require_once dirname(__FILE__).'/../Type/CXFORMWITHALPHA.php';
+require_once dirname(__FILE__).'/../Type/CLIPACTIONS.php';
+
+class IO_SWF_Tag_Place extends IO_SWF_Tag_Base {
+    var $_characterId = null; // refid
+    var $_depth = null;
+    var $_matrix = null;
+    var $_colorTransform = null;
+    var $_ratio = null;
+    var $_name = null;
+    var $_clipDepth = null;
+    var $_clipActions = null;
+    function parseContent($tagCode, $content, $opts = array()) {
+        $reader = new IO_Bit();
+    	$reader->input($content);
+        switch ($tagCode) {
+          case 4: // PlaceObject
+            $this->_characterId = $reader->getUI16LE();
+            $this->_depth = $reader->getUI16LE();
+            $this->_matrix = IO_SWF_Type_MATRIX::parse($reader);
+            if ($reader->hasNextData()) { // optional
+                $this->_colorTransform = IO_SWF_Type_CXFORM::parse($reader);
+            }
+            break;
+          case 26: // PlaceObject2
+            // placeFlag
+            $this->_placeFlagHasClipActions = $reader->getUIBit();
+            $this->_placeFlagHasClipDepth = $reader->getUIBit();
+            $this->_placeFlagHasName = $reader->getUIBit();
+            $this->_placeFlagHasRatio = $reader->getUIBit();
+            $this->_placeFlagHasColorTransform = $reader->getUIBit();
+            $this->_placeFlagHasMatrix = $reader->getUIBit();
+            $this->_placeFlagHasCharacter = $reader->getUIBit();
+            $this->_placeFlagMove = $reader->getUIBit();
+            //
+            $this->_depth = $reader->getUI16LE();
+            if ($this->_placeFlagHasCharacter) {
+                $this->_characterId = $reader->getUI16LE();
+            }
+            if ($this->_placeFlagHasMatrix) {
+                $this->_matrix = IO_SWF_Type_MATRIX::parse($reader);
+            }
+            if ($this->_placeFlagHasColorTransform) {
+                $this->_colorTransform = IO_SWF_Type_CXFORMWITHALPHA::parse($reader);
+            }
+            if ($this->_placeFlagHasRatio) {
+                $this->_ratio =  $reader->getUI16LE();
+            }
+            if ($this->_placeFlagHasName) {
+                $this->_name = IO_SWF_Type_String::parse($reader);
+            }
+            if ($this->_placeFlagHasClipDepth) {
+                $this->_clipDepth =  $reader->getUI16LE();
+            }
+            if ($this->_placeFlagHasClipActions) {
+                $this->_clipActions = IO_SWF_Type_CLIPACTIONS::parse($reader, $opts);
+            }
+            break;
+        }
+        return true;
+    }
+
+    function dumpContent($tagCode, $opts = array()) {
+        if (is_null($this->_characterId) === false) {
+            echo "\tCharacterId: ".$this->_characterId."\n";
+        }
+        if (is_null($this->_depth) === false) {
+            echo "\tDepth: ".$this->_depth."\n";
+        }
+        if (is_null($this->_matrix) === false) {
+            $opts['indent'] = 2;
+            echo "\tMatrix:\n".IO_SWF_Type_MATRIX::string($this->_matrix, $opts)."\n";
+        }
+        if (is_null($this->_colorTransform) === false) {
+            if ($tagCode == 4) { // PlaceObject
+                echo "\tColorTransform: ".IO_SWF_Type_CXFORM::string($this->_colorTransform)."\n";
+            } else {
+                echo "\tColorTransform: ".IO_SWF_Type_CXFORMWITHALPHA::string($this->_colorTransform)."\n";
+            }
+        }
+        if (is_null($this->_ratio) === false) {
+            echo "\tRatio: ".$this->_ratio."\n";
+        }
+        if (is_null($this->_name) === false) {
+            echo "\tName:".$this->_name."\n";
+        }
+        if (is_null($this->_clipDepth) === false) {
+            echo "\tClipDepth:".$this->_clipDepth."\n";
+        }
+        if (is_null($this->_clipActions) === false) {
+            echo "\tClipActions:\n";
+            echo "\t".IO_SWF_Type_CLIPACTIONS::string($this->_clipActions, $opts)."\n";
+        }
+    }
+
+    function buildContent($tagCode, $opts = array()) {
+        $writer = new IO_Bit();
+        switch ($tagCode) {
+          case 4: // PlaceObject
+            $this->_characterId = $writer->getUI16LE();
+            $this->_depth = $writer->getUI16LE();
+            $this->_matrix = IO_SWF_Type_MATRIX::parse($writer);
+            if ($writer->hasNextData()) { // optional
+                $this->_colorTransform = IO_SWF_Type_CXFORM::parse($writer);
+            }
+            break;
+          case 26: // PlaceObject2
+            //
+            if (is_null($this->_characterId) === false) {
+                $this->_placeFlagHasCharacter = 1;
+            } else {
+                $this->_placeFlagHasCharacter = 0;
+            }
+            if (is_null($this->_matrix) === false) {
+                $this->_placeFlagHasMatrix = 1;
+            } else {
+                $this->_placeFlagHasMatrix = 0;
+            }
+            if (is_null($this->_colorTransform) === false) {
+                $this->_placeFlagHasColorTransform = 1;
+            } else {
+                $this->_placeFlagHasColorTransform = 0;
+            }
+            if (is_null($this->_ratio) === false) {
+                $this->_placeFlagHasRatio = 1;
+            } else {
+                $this->_placeFlagHasRatio = 0;
+            }
+            if (is_null($this->_name) === false) {
+                $this->_placeFlagHasName = 1;
+            } else {
+                $this->_placeFlagHasName = 0;
+            }
+            if (is_null($this->_clipDepth) === false) {
+                $this->_placeFlagHasClipDepth = 1;
+            } else {
+                $this->_placeFlagHasClipDepth = 0;
+            }
+            if (is_null($this->_clipActions) === false) {
+                $this->_placeFlagHasClipActions = 1;
+            } else {
+                $this->_placeFlagHasClipActions = 0;
+            }
+            // placeFlag
+            $writer->putUIBit($this->_placeFlagHasClipActions);
+            $writer->putUIBit($this->_placeFlagHasClipDepth);
+            $writer->putUIBit($this->_placeFlagHasName);
+            $writer->putUIBit($this->_placeFlagHasRatio);
+            $writer->putUIBit($this->_placeFlagHasColorTransform);
+            $writer->putUIBit($this->_placeFlagHasMatrix);
+            $writer->putUIBit($this->_placeFlagHasCharacter);
+            $writer->putUIBit($this->_placeFlagMove);
+            //
+            $writer->putUI16LE($this->_depth);
+            if ($this->_placeFlagHasCharacter) {
+                $writer->putUI16LE($this->_characterId);
+            }
+            if ($this->_placeFlagHasMatrix) {
+                IO_SWF_Type_MATRIX::build($writer, $this->_matrix);
+            }
+            if ($this->_placeFlagHasColorTransform) {
+                IO_SWF_Type_CXFORMWITHALPHA::build($writer, $this->_colorTransform);
+            }
+            if ($this->_placeFlagHasRatio) {
+                $writer->putUI16LE($this->_ratio);
+            }
+            if ($this->_placeFlagHasName) {
+                IO_SWF_Type_String::build($writer, $this->_name);
+            }
+            if ($this->_placeFlagHasClipDepth) {
+                $writer->putUI16LE($this->_clipDepth);
+            }
+            if ($this->_placeFlagHasClipActions) {
+                IO_SWF_Type_CLIPACTIONS::build($writer, $this->_clipActions, $opts);
+            }
+            break;
+        }
+    	return $writer->output();
+    }
+}
属性に変更があったパス: IO_SWF/tags/2.1.8-stable-20120220231502/IO/SWF/Tag/Place.php
___________________________________________________________________
追加: svn:keywords
+ Id
追加: svn:eol-style
+ native

IO_SWF/tags/2.1.8-stable-20120220231502/IO/SWF/Tag/Text.php

@@ -0,0 +1,84 @@
+<?php
+
+  /*
+   * 2011/8/22- (c) yoya@awm.jp
+   */
+
+
+require_once 'IO/Bit.php';
+
+require_once dirname(__FILE__).'/Base.php';
+require_once dirname(__FILE__).'/../Type/RECT.php';
+require_once dirname(__FILE__).'/../Type/MATRIX.php';
+require_once dirname(__FILE__).'/../Type/TEXTRECORD.php';
+
+class IO_SWF_Tag_Text extends IO_SWF_Tag_Base {
+    var $_CharacterID;
+    var $_TextBounds;
+    var $_TextMatrix;
+    var $_GlyphBits;
+    var $_AdvanceBits;
+    function parseContent($tagCode, $content, $opts = array()) {
+        $opts['tagCode'] = $tagCode;
+        $reader = new IO_Bit();
+    	$reader->input($content);
+        $this->_CharacterID = $reader->getUI16LE();
+        $this->_TextBounds = IO_SWF_TYPE_RECT::parse($reader);
+        $this->_TextMatrix = IO_SWF_Type_MATRIX::parse($reader);
+        $glyphBits = $reader->getUI8();
+        $advanceBits = $reader->getUI8();
+        $this->_GlyphBits = $glyphBits;
+        $this->_AdvanceBits = $advanceBits;
+        $textRecords = array();
+        $opts['GlyphBits'] = $glyphBits;
+        $opts['AdvanceBits'] = $advanceBits;
+        while ($reader->getUI8() != 0) {
+            $reader->incrementOffset(-1, 0); // 1 byte back
+            $textRecords []= IO_SWF_Type_TEXTRECORD::parse($reader, $opts);
+        }
+        $this->_TextRecords = $textRecords;
+    }
+
+    function dumpContent($tagCode, $opts = array()) {
+        $opts['tagCode'] = $tagCode;
+        echo "    CharacterID: {$this->_CharacterID}\n";
+        echo "    TextBounds:\n";
+        $rect_str = IO_SWF_Type_RECT::string($this->_TextBounds, $opts);
+        echo "\t$rect_str\n";
+        $opts['indent'] = 1;
+        $matrix_str = IO_SWF_Type_MATRIX::string($this->_TextMatrix, $opts);
+        echo "    TextMatrix:\n";
+        echo "$matrix_str\n";
+        echo "    GlyphBits: {$this->_GlyphBits} AdvanceBits: {$this->_AdvanceBits}\n";
+        if (count($this->_TextRecords) == 0) {
+            echo "    (TEXTRECORD empty)\n";
+        } else {
+            echo "    TextRecords:\n";
+            foreach ($this->_TextRecords as $idx => $textRecord) {
+                echo "      [$idx]:\n";
+                echo "\t".IO_SWF_Type_TEXTRECORD::string($textRecord, $opts);
+            }
+        }
+    }
+
+    function buildContent($tagCode, $opts = array()) {
+        $opts['tagCode'] = $tagCode;
+        $writer = new IO_Bit();
+        $writer->putUI16LE($this->_CharacterID);
+        IO_SWF_TYPE_RECT::build($writer, $this->_TextBounds);
+        IO_SWF_Type_MATRIX::build($writer, $this->_TextMatrix);
+
+        $glyphBits = $this->_GlyphBits; // XXX
+        $advanceBits = $this->_AdvanceBits; // XXX
+        $writer->putUI8($glyphBits);
+        $writer->putUI8($advanceBits);
+
+        $opts['GlyphBits'] = $glyphBits;
+        $opts['AdvanceBits'] = $advanceBits;
+        foreach ($this->_TextRecords as $textRecord) {
+            IO_SWF_Type_TEXTRECORD::build($writer, $textRecord, $opts);
+        }
+        $writer->putUI8(0); // TEXTRECORD TERMINATER
+    	return $writer->output();
+    }
+}
属性に変更があったパス: IO_SWF/tags/2.1.8-stable-20120220231502/IO/SWF/Tag/Text.php
___________________________________________________________________
追加: svn:keywords
+ Id
追加: svn:eol-style
+ native

IO_SWF/tags/2.1.8-stable-20120220231502/IO/SWF/Tag/Jpeg.php

@@ -0,0 +1,55 @@
+<?php
+
+require_once 'IO/Bit.php';
+require_once dirname(__FILE__).'/Base.php';
+
+class IO_SWF_Tag_Jpeg extends IO_SWF_Tag_Base {
+    var $_CharacterID;
+    var $_AlphaDataOffset = null;
+    var $_JPEGData;
+    var $_ZlibBitmapAlphaData = null;
+    function parseContent($tagCode, $content, $opts = array()) {
+        $reader = new IO_Bit();
+    	$reader->input($content);
+        if ($tagCode != 8) { // ! JPEGTable
+            $this->_CharacterID = $reader->getUI16LE();
+        }
+        if ($tagCode == 35) { // DefgineBitsJPEG3
+            $alphaDataOffset = $reader->getUI32LE();
+            $this->_AlphaDataOffset = $alphaDataOffset;
+        }
+        if ($tagCode != 35) { // ! DefgineBitsJPEG3
+            $this->_JPEGData = $reader->getDataUntil(false);
+        } else {
+            $this->_JPEGData = $reader->getData($alphaDataOffset);
+            $this->_ZlibBitmapAlphaData = $reader->getDataUntil(false);
+        }
+    }
+
+    function dumpContent($tagCode, $opts = array()) {
+        if ($tagCode != 8) { // ! JPEGTables
+            echo "\tCharacterID:{$this->_CharacterID}\n";
+        }
+        if ($tagCode == 35) { // DefineBitsJPEG3
+            echo "\tAlphaDataOffset:{$this->_AlphaDataOffset}\n";
+        }
+    }
+
+    function buildContent($tagCode, $opts = array()) {
+        $writer = new IO_Bit();
+        if ($tagCode != 8) { // ! JPEGTablesa
+            $writer->putUI16LE($this->_CharacterID);
+        }
+        if ($tagCode == 35) { // DefgineBitsJPEG3
+            $this->_AlphaDataOffset = strlen($this->_JPEGData);
+            $writer->putUI32LE($this->_AlphaDataOffset);
+        }
+        if ($tagCode != 35) { // ! DefgineBitsJPEG3
+            $writer->putData($this->_JPEGData);
+        } else {
+            $writer->putData($this->_JPEGData);
+            $writer->putData($this->_ZlibBitmapAlphaData);
+        }
+    	return $writer->output();
+    }
+}

IO_SWF/tags/2.1.8-stable-20120220231502/IO/SWF/Tag/Font.php

@@ -0,0 +1,247 @@
+<?php
+
+require_once 'IO/Bit.php';
+require_once dirname(__FILE__).'/Base.php';
+require_once dirname(__FILE__).'/../Type/LANGCODE.php';
+require_once dirname(__FILE__).'/../Type/SHAPE.php';
+require_once dirname(__FILE__).'/../Type/KERNINGRECORD.php';
+
+class IO_SWF_Tag_Font extends IO_SWF_Tag_Base {
+    var $FontID;
+    var $FontFlagsShiftJIS;
+    var $FontFlagsSmallText;
+    var $FontflagsANSI;
+    var $FontFlagsWideOffsets;
+    var $FontFlagsWideCodes;
+    var $FontFlagsItalic;
+    var $FontFlagsBold;
+    var $LanguageCode;
+    var $FontName;
+    var $OffsetTable = array();
+    var $GlyphShapeTable = array();
+    var $CodeTable = array();
+    // Layout Information
+    var $FontAscent;
+    var $FontDescent;
+    var $FontLeading;
+    var $FontAdvanceTable;
+    var $FontBoundsTable;
+    var $FontKerningTable;
+    function parseContent($tagCode, $content, $opts = array()) {
+        $reader = new IO_Bit();
+    	$reader->input($content);
+        $this->FontID = $reader->getUI16LE();
+        $fontFlagsHasLayout = $reader->getUIBit();
+        $this->FontFlagsShiftJIS = $reader->getUIBit();
+        $this->FontFlagsSmallText = $reader->getUIBit();
+        $this->FontFlagsANSI = $reader->getUIBit();
+        $this->FontFlagsWideOffsets = $reader->getUIBit();
+        $this->FontFlagsWideCodes = $reader->getUIBit();
+        $this->FontFlagsItalic = $reader->getUIBit();
+        $this->FontFlagsBold = $reader->getUIBit();
+        $this->LanguageCode = IO_SWF_Type_LANGCODE::parse($reader);
+        $fontNameLen = $reader->getUI8();
+        $this->FontName = $reader->getData($fontNameLen);
+        $numGlyphs = $reader->getUI16LE();
+        if ($numGlyphs === 0) {
+            return ; // no glyphs field.
+        }
+        list($startOfOffsetTable, $dummy) = $reader->getOffset();
+        if ($this->FontFlagsWideOffsets) {
+            for ($i = 0 ; $i < $numGlyphs ; $i++) {
+                $this->OffsetTable []= $reader->getUI32LE();
+            }
+        } else {
+            for ($i = 0 ; $i < $numGlyphs ; $i++) {
+                $this->OffsetTable []= $reader->getUI16LE();
+            }
+        }
+        if ($this->FontFlagsWideOffsets) {
+            $codeTableOffset  = $reader->getUI32LE();
+        } else {
+            $codeTableOffset  = $reader->getUI16LE();
+        }
+        for ($i = 0 ; $i < $numGlyphs ; $i++) {
+            $reader->setOffset($startOfOffsetTable + $this->OffsetTable[$i], 0);
+            $this->GlyphShapeTable []= IO_SWF_Type_SHAPE::parse($reader, $opts);
+            $reader->byteAlign();
+        }
+        list($startOfOffsetCodeTable, $dummy) = $reader->getOffset();
+        if ($startOfOffsetCodeTable != $startOfOffsetTable + $codeTableOffset) {
+            trigger_error("startOfOffsetCodeTable:$startOfOffsetCodeTable != startOfOffsetTable:$startOfOffsetTable + codeTableOffset:$codeTableOffset", E_USER_WARNING);
+        }
+        $reader->setOffset($startOfOffsetTable + $codeTableOffset, 0);
+        if ($this->FontFlagsWideCodes) {
+            for ($i = 0 ; $i < $numGlyphs ; $i++) {
+                $this->CodeTable []= $reader->getUI16LE();
+            }
+        } else {
+            for ($i = 0 ; $i < $numGlyphs ; $i++) {
+                $this->CodeTable []= $reader->getUI8();
+            }
+        }
+        if ($fontFlagsHasLayout) {
+            $this->FontAscent = $reader->getSI16LE();
+            $this->FontDescent = $reader->getSI16LE();
+            $this->FontLeading = $reader->getSI16LE();
+            $this->FontAdvanceTable[] = array();
+            for ($i = 0 ; $i < $numGlyphs ; $i++) {
+                $this->FontAdvanceTable[] = $reader->getSI16LE();
+            }
+            $this->FontBoundsTable = array();
+            for ($i = 0 ; $i < $numGlyphs ; $i++) {
+                $this->FontBoundsTable[] = IO_SWF_TYPE_RECT::parse($reader);
+            }
+            $kerningCount =  $reader->getUI16LE();
+            if ($kerningCount > 0) {
+                $this->FontKerningTable = array();
+                $opts['FontFlagsWideCodes'] = $this->FontFlagsWideCodes;
+                for ($i = 0 ; $i < $kerningCount ; $i++) {
+                    $this->FontKerningTable[] = IO_SWF_TYPE_KERNINGRECORD::parse($reader, $opts);
+                }
+            }
+        }
+    }
+
+    function dumpContent($tagCode, $opts = array()) {
+        echo "    FontID: {$this->FontID}".PHP_EOL;
+        $fontFlagsHasLayout = is_null($this->FontAscent)?0:1;
+        echo "FontFlagsHasLayout: $fontFlagsHasLayout FontFlagsShiftJIS: {$this->FontFlagsShiftJIS} FontFlagsSmallText: {$this->FontFlagsSmallText} FontFlagsANSI: {$this->FontFlagsANSI}".PHP_EOL;
+        echo "FontFlagsWideOffsets: {$this->FontFlagsWideOffsets} FontFlagsWideCodes: {$this->FontFlagsWideCodes}".PHP_EOL;
+
+        echo "    LanguageCode: ".IO_SWF_Type_LANGCODE::string($this->LanguageCode)."FontName: {$this->FontName}".PHP_EOL;
+        echo "    OffsetTable:";
+        foreach ($this->OffsetTable as $idx => $offset) {
+            echo " [$idx]$offset";
+        }
+        echo PHP_EOL;
+        echo "    GlyphShapeTable:".PHP_EOL;
+        $opts['indent'] = 1;
+        foreach ($this->GlyphShapeTable as $idx => $glyph)
+        {
+            echo "      [$idx]".PHP_EOL;
+            echo IO_SWF_Type_SHAPE::string($glyph, $opts);
+        }
+        echo "    CodeTable:";
+        foreach ($this->CodeTable as $idx => $c) {
+            echo " [$idx]$c";
+        }
+        echo PHP_EOL;
+        if ($this->FontAscent) {
+            echo "    FontAscent: {$this->FontAscent} FontDescent: {$this->FontDescent} FontLeading: {$this->FontLeading}".PHP_EOL;
+            foreach ($this->FontAdvanceTable as $idx => $advance) {
+                echo " [$idx]$advance";
+            }
+            echo PHP_EOL;
+            echo "    FontBoundsTable:";
+            foreach ($this->FontBoundsTable as $idx => $fontBounds) {
+                echo "\t[$idx]".IO_SWF_TYPE_RECT::string($fontBounds).PHP_EOL;
+            }
+        } else {
+            echo "    (FontFlagsHasLayout is false)".PHP_EOL;
+        }
+        if ($this->FontKerningTable) {
+            echo "    FontKerningTable:".PHP_EOL;
+            foreach ($this->FontKerningTable as $fontKerning) {
+                echo "\t".IO_SWF_Type_KERNINGRECORD::string($fontkerning).PHP_EOL;
+            }
+        } else {
+            echo "\t(FontKerningTable is null)".PHP_EOL;
+        }
+    }
+
+    function buildContent($tagCode, $opts = array()) {
+        $writer = new IO_Bit();
+        $writer->putUI16LE($this->FontID);
+        //
+        $fontFlagsHasLayout = is_null($this->FontAscent)?0:1;
+        //
+        $writer->putUIBit($fontFlagsHasLayout);
+        $writer->putUIBit($this->FontFlagsShiftJIS);
+        $writer->putUIBit($this->FontFlagsSmallText);
+        $writer->putUIBit($this->FontFlagsANSI);
+        $writer->putUIBit($this->FontFlagsWideOffsets);
+        $writer->putUIBit($this->FontFlagsWideCodes);
+        $writer->putUIBit($this->FontFlagsItalic);
+        $writer->putUIBit($this->FontFlagsBold);
+        IO_SWF_Type_LANGCODE::build($writer, $this->LanguageCode);
+        $fontNameLen = strlen($this->FontName);
+        $writer->putUI8($fontNameLen);
+        $writer->putData($this->FontName);
+        $numGlyphs = count($this->OffsetTable);
+        $writer->putUI16LE($numGlyphs);
+        if ($numGlyphs === 0) {
+            return $writer->output(); // no glyphs field.
+        }
+        list($startOfOffsetTable, $dummy) = $writer->getOffset();
+        $startOfOffsetTable2 = array();
+        if ($this->FontFlagsWideOffsets) {
+            foreach ($this->OffsetTable as $idx => $offset) {
+                list($startOfOffsetTables[$idx], $dummy) = $writer->getOffset();
+                $writer->putUI32LE(0); // dummy
+            }
+        } else {
+            foreach ($this->OffsetTable as $idx => $offset) {
+                list($startOfOffsetTables[$idx], $dummy) = $writer->getOffset();
+                $writer->putUI16LE(0); // dummy
+            }
+        }
+        list($startOfcodeTableOffset, $dummy) = $writer->getOffset();
+        if ($this->FontFlagsWideOffsets) {
+            $writer->putUI32LE(0); // dummy
+        } else {
+            $writer->putUI16LE(0); // dummy
+        }
+        $opts['fillStyleCount'] = 1;
+        $opts['lineStyleCount'] = 0;
+        foreach ($this->GlyphShapeTable as $idx => $glyphShape) {
+            list($startOfGlyphShape, $dummy) = $writer->getOffset();
+            if ($this->FontFlagsWideOffsets) {
+                $writer->setUI32LE($startOfGlyphShape - $startOfOffsetTable, $startOfOffsetTables[$idx]);
+            } else {
+                $writer->setUI16LE($startOfGlyphShape - $startOfOffsetTable, $startOfOffsetTables[$idx]);
+            }
+            IO_SWF_Type_SHAPE::build($writer, $glyphShape, $opts);
+            $writer->byteAlign();
+        }
+        //
+        list($startOfCodeTable, $dummy) = $writer->getOffset();
+        $codeTableOffset  = $startOfCodeTable - $startOfOffsetTable;
+        if ($this->FontFlagsWideOffsets) {
+            $writer->setUI32LE($codeTableOffset, $startOfcodeTableOffset);
+        } else {
+            $writer->setUI16LE($codeTableOffset, $startOfcodeTableOffset);
+        }
+        if ($this->FontFlagsWideCodes) {
+            foreach ($this->CodeTable as $c) {
+                $writer->putUI16LE($c);
+            }
+        } else {
+            foreach ($this->CodeTable as $c) {
+                $writer->putUI8($c);
+            }
+        }
+        if ($fontFlagsHasLayout) {
+            $writer->putSI16LE($this->FontAscent );
+            $writer->putSI16LE($this->FontDescent);
+            $writer->putSI16LE($this->FontLeading);
+            foreach ($this->FontAdvanceTable as $fontAdvance) {
+                $writer->putSI16LE($fontAdvance);
+            }
+            foreach ($this->FontBoundsTable as $fontBounds) {
+                IO_SWF_TYPE_RECT::build($writer, $fontBounds);
+            }
+            if (is_null($this->FontKerningTable)) {
+                $writer->putUI16LE(0);
+            } else {
+                $kerningCount = count($this->FontKerningTable);
+                $writer->putUI16LE($kerningCount);
+                $opts['FontFlagsWideCodes'] = $this->FontFlagsWideCodes;
+                foreach ($this->FontKerningTable as $fontKerning) {
+                    IO_SWF_TYPE_KERNINGRECORD::build($writer, $fontKerning, $opts);
+                }
+            }
+        }
+    	return $writer->output();
+    }
+}
属性に変更があったパス: IO_SWF/tags/2.1.8-stable-20120220231502/IO/SWF/Tag/Font.php
___________________________________________________________________
追加: svn:keywords
+ Id
追加: svn:eol-style
+ native

IO_SWF/tags/2.1.8-stable-20120220231502/IO/SWF/Tag/Sprite.php

@@ -0,0 +1,49 @@
+<?php
+
+require_once 'IO/Bit.php';
+require_once dirname(__FILE__).'/Base.php';
+require_once dirname(__FILE__).'/../Tag.php';
+
+class IO_SWF_Tag_Sprite extends IO_SWF_Tag_Base {
+    var $_spriteId = null;
+    var $_frameCount = null;
+    var $_controlTags = array();
+    function parseContent($tagCode, $content, $opts = array()) {
+        $reader = new IO_Bit();
+    	$reader->input($content);
+
+        $this->_spriteId = $reader->getUI16LE();
+        $this->_frameCount = $reader->getUI16LE();
+        /* SWF Tags */
+        while (true) {
+            $tag = new IO_SWF_Tag($this->swfInfo);
+            $tag->parse($reader);
+            $this->_controlTags[] = $tag;
+            if ($tag->code == 0) { // END Tag
+                break;
+            }
+        }
+        return true;
+    }
+
+    function dumpContent($tagCode, $opts = array()) {
+        echo "\tSprite: SpriteID={$this->_spriteId} FrameCount={$this->_frameCount}\n";
+        foreach ($this->_controlTags as $tag) {
+            echo "  ";
+            $tag->dump($opts);
+        }
+    }
+
+    function buildContent($tagCode, $opts = array()) {
+        $writer = new IO_Bit();
+        $writer->putUI16LE($this->_spriteId);
+        $writer->putUI16LE($this->_frameCount);
+        foreach ($this->_controlTags as $tag) {
+            $tagData = $tag->build();
+            if ($tagData != false) {
+                $writer->putData($tag->build());
+            }
+        }
+    	return $writer->output();
+    }
+}

IO_SWF/tags/2.1.8-stable-20120220231502/IO/SWF/Tag/BGColor.php

@@ -0,0 +1,26 @@
+<?php
+
+require_once 'IO/Bit.php';
+require_once dirname(__FILE__).'/Base.php';
+require_once dirname(__FILE__).'/../Type/RGB.php';
+
+class IO_SWF_Tag_BGColor extends IO_SWF_Tag_Base {
+    var $_color;
+
+   function parseContent($tagCode, $content, $opts = array()) {
+        $reader = new IO_Bit();
+    	$reader->input($content);
+        $this->_color = IO_SWF_Type_RGB::parse($reader);
+    }
+
+    function dumpContent($tagCode, $opts = array()) {
+        $color_str = IO_SWF_Type_RGB::string($this->_color);
+        echo "\tColor: $color_str\n";
+    }
+
+    function buildContent($tagCode, $opts = array()) {
+        $writer = new IO_Bit();
+        IO_SWF_Type_RGB::build($writer, $this->_color);
+    	return $writer->output();
+    }
+}

IO_SWF/tags/2.1.8-stable-20120220231502/IO/SWF/Tag/Lossless.php

@@ -0,0 +1,49 @@
+<?php
+
+require_once 'IO/Bit.php';
+require_once dirname(__FILE__).'/Base.php';
+
+class IO_SWF_Tag_Lossless extends IO_SWF_Tag_Base {
+    var $_CharacterID;
+    var $_BitmapFormat;
+    var $_BitmapWidth;
+    var $_BitmapHeight;
+    var $_BitmapColorTableSize = null;
+    var $_ZlibBitmapData;
+   function parseContent($tagCode, $content, $opts = array()) {
+        $reader = new IO_Bit();
+    	$reader->input($content);
+        $this->_CharacterID = $reader->getUI16LE();
+        $bitmapFormat = $reader->getUI8();
+        $this->_BitmapFormat = $bitmapFormat;
+        $this->_BitmapWidth = $reader->getUI16LE();
+        $this->_BitmapHeight = $reader->getUI16LE();
+        if ($bitmapFormat == 3) {
+            $this->_BitmapColorTableSize = $reader->getUI8() + 1;
+        }
+        $this->_ZlibBitmapData = $reader->getDataUntil(false);
+    }
+
+    function dumpContent($tagCode, $opts = array()) {
+        $bitmapFormat = $this->_BitmapFormat;
+        echo "\tCharacterID:{$this->_CharacterID} BitmapFormat={$bitmapFormat}\n";
+        echo "\tBitmapWidth:{$this->_BitmapWidth} BitmapHeight:{$this->_BitmapHeight}\n";
+        if ($bitmapFormat == 3) {
+            echo "\tBitmapColorTableSize:{$this->_BitmapColorTableSize}\n";
+        }
+    }
+
+    function buildContent($tagCode, $opts = array()) {
+        $writer = new IO_Bit();
+        $writer->putUI16LE($this->_CharacterID);
+        $bitmapFormat = $this->_BitmapFormat;
+        $writer->putUI8($bitmapFormat);
+        $writer->putUI16LE($this->_BitmapWidth);
+        $writer->putUI16LE($this->_BitmapHeight);
+        if ($bitmapFormat == 3) {
+            $writer->putUI8($this->_BitmapColorTableSize - 1);
+        }
+        $writer->putData($this->_ZlibBitmapData);
+    	return $writer->output();
+    }
+}

IO_SWF/tags/2.1.8-stable-20120220231502/IO/SWF/Editor.php

@@ -0,0 +1,963 @@
+<?php
+
+/*
+ * 2010/8/12- (c) yoya@awm.jp
+ */
+
+require_once dirname(__FILE__).'/Exception.php';
+require_once dirname(__FILE__).'/../SWF.php';
+require_once dirname(__FILE__).'/Tag/Shape.php';
+require_once dirname(__FILE__).'/Tag/Action.php';
+require_once dirname(__FILE__).'/Tag/Sprite.php';
+require_once dirname(__FILE__).'/Lossless.php';
+require_once dirname(__FILE__).'/../SWF/Bitmap.php';
+
+class IO_SWF_Editor extends IO_SWF {
+    // var $_headers = array(); // protected
+    // var $_tags = array();    // protected
+    var $shape_adjust_mode = self::SHAPE_BITMAP_NONE;
+
+    const SHAPE_BITMAP_NONE           = 0;
+    const SHAPE_BITMAP_MATRIX_RESCALE = 1;
+    const SHAPE_BITMAP_RECT_RESIZE    = 2;
+    const SHAPE_BITMAP_TYPE_TILED     = 4;
+
+    var $setCharacterIdDone = false;
+    var $setReferenceIdDone = false;
+
+    function rebuild() {
+        foreach ($this->_tags as &$tag) {
+            if ($tag->parseTagContent()) {
+                $tag->content = null;
+            }
+        }
+    }
+
+    function setCharacterId() {
+        if ($this->setCharacterIdDone) {
+            return ;
+        }
+        foreach ($this->_tags as &$tag) {
+            if (is_null($tag->content)) {
+                throw IO_SWF_Exception("setCharacterId method must be called at next of parse");
+            }
+            $content_reader = new IO_Bit();
+            $content_reader->input($tag->content);
+            switch ($tag->code) {
+              case 6:  // DefineBits
+              case 21: // DefineBitsJPEG2
+              case 35: // DefineBitsJPEG3
+              case 20: // DefineBitsLossless
+              case 36: // DefineBitsLossless2
+              case 2:  // DefineShape (ShapeId)
+              case 22: // DefineShape2 (ShapeId)
+              case 32: // DefineShape3 (ShapeId)
+              case 83: // DefineShape4 (ShapeId)
+              case 46: // DefineMorphShape (ShapeId)
+              case 10: // DefineFont
+              case 48: // DefineFont2
+              case 75: // DefineFont3
+              case 13: // DefineFontInfo
+              case 73: // DefineFontAlignZones
+              case 11: // DefineText
+              case 33: // DefineText2
+              case 37: // DefineTextEdit
+              case 39: // DefineSprite
+              case 34: // DefineButton2
+                $tag->characterId = $content_reader->getUI16LE();
+                break;
+            }
+        }
+        $this->setCharacterIdDone = true;
+    }
+
+    function _setReferenceId(&$tag) {
+        $content_reader = new IO_Bit();
+        $content_reader->input($tag->content);
+        switch ($tag->code) {
+        case 4:  // PlaceObject
+        case 5:  // RemoveObject
+            $tag->referenceId = $content_reader->getUI16LE();
+            break;
+        case 26: // PlaceObject2 (Shape Reference)
+            $tag->placeFlag = $content_reader->getUI8();
+            if ($tag->placeFlag & 0x02) {
+                $content_reader->getUI16LE(); // depth
+                $tag->referenceId = $content_reader->getUI16LE();
+            }
+            break;
+        case 2:  // DefineShape  (Bitmap ReferenceId)
+        case 22: // DefineShape2 (Bitmap ReferenceId)
+        case 32: // DefineShape3   (Bitmap ReferenceId)
+        case 83: // DefineShape4    (Bitmap ReferenceId)
+        case 46: // DefineMorphShape (Bitmap ReferenceId)
+            $refIds = array();
+            if ($tag->parseTagContent() === false) {
+                throw new IO_SWF_Exception("failed to parseTagContent");
+            }
+            if (is_null($tag->tag->_fillStyles) === false) {
+                foreach ($tag->tag->_fillStyles as $fillStyle) {
+                    if (isset($fillStyle['BitmapId'])) {
+                        if ($fillStyle['BitmapId'] != 65535) {
+                            $refIds []= $fillStyle['BitmapId'];
+                        }
+                    }
+                }
+                $tag->referenceId = $refIds;
+            }
+            if (is_null($tag->tag->_shapeRecords) === false) {
+                foreach ($tag->tag->_shapeRecords as $shapeRecord) {
+                    if (isset($shapeRecord['FillStyles'])) {
+                        foreach ($shapeRecord['FillStyles'] as $fillStyle) {
+                            if (isset($fillStyle['BitmapId'])) {
+                                if ($fillStyle['BitmapId'] != 65535) {
+                                    $refIds []= $fillStyle['BitmapId'];
+                                }
+                            }
+                        }
+                    }
+                }
+                $tag->referenceId = $refIds;
+            }
+            break;
+        case 34: // DefineButton2
+            $refIds = array();
+            if ($tag->parseTagContent() === false) {
+                throw new IO_SWF_Exception("failed to parseTagContent");
+            }
+            if (is_null($tag->tag->_characters) === false) {
+                foreach ($tag->tag->_characters as $character) {
+                    $refIds []= $character['CharacterID'];
+                }
+                $tag->referenceId = $refIds;
+            }
+            break;
+        case 11: // DefineText
+        case 33: // DefineText2
+            if ($tag->parseTagContent() === false) {
+                throw new IO_SWF_Exception("failed to parseTagContent");
+            }
+            if (is_null($tag->tag->_TextRecords) === false) {
+                $refIds = array();
+                foreach ($tag->tag->_TextRecords as $textRecord) {
+                    if (isset($textRecord['FontID'])) {
+                        $refIds []= $textRecord['FontID'];
+                    }
+                }
+                if (count($refIds) > 0) {
+                    $tag->referenceId = $refIds;
+                }
+            }
+            break;
+        }
+        return true;
+    }
+    function setReferenceId() {
+        if ($this->setReferenceIdDone) {
+            return ;
+        }
+        foreach ($this->_tags as &$tag) {
+            if ($tag->code == 39) { // DefineSprite
+                if ($tag->parseTagContent() === false) {
+                    throw new IO_SWF_Exception("failed to parseTagContent");
+                }
+                $refIds = array();
+                foreach ($tag->tag->_controlTags as &$tag_in_sprite) {
+                    $this->_setReferenceId($tag_in_sprite);
+                    if (isset($tag_in_sprite->referenceId)) {
+                        $refIds_in_sprite = $tag_in_sprite->referenceId;
+                        if (is_array($refIds_in_sprite)) {
+                            $refIds += $refIds_in_sprite;
+                        } else {
+                            $refIds []= $refIds_in_sprite;
+                        }
+                    }
+                }
+                if (count($refIds) > 0) {
+                    $tag->referenceId = $refIds;
+                }
+            } else {
+                $this->_setReferenceId($tag);
+            }
+        }
+        $this->setReferenceIdDone = true;
+    }
+
+    function replaceTagContent($tagCode, $content, $limit = 1) {
+        $count = 0;
+        foreach ($this->_tags as &$tag) {
+            if ($tag->code == $tagCode) {
+                $tag->content = $content;
+                $count += 1;
+                if ($limit <= $count) {
+                    break;
+                }
+            }
+        }
+        return $count;
+    }
+    function getTagContent($tagCode) {
+        $count = 0;
+        foreach ($this->_tags as &$tag) {
+            if ($tag->code == $tagCode) {
+                return $tag->content;
+            }
+        }
+        return null;
+    }
+
+    function replaceTagContentByCharacterId($tagCode, $characterId, $content_after_character_id) {
+        if (! is_array($tagCode)) {
+            $tagCode = array($tagCode);
+        }
+        $ret = false;
+        foreach ($this->_tags as &$tag) {
+            if (in_array($tag->code, $tagCode) && isset($tag->characterId)) {
+                if ($tag->characterId == $characterId) {
+                    $tag->content = pack('v', $characterId).$content_after_character_id;
+                    $ret = true;
+                    break;
+                }
+            }
+        }
+        return $ret;
+    }
+
+    function replaceTagByCharacterId($tagCode, $characterId, $replaceTag) {
+        if (! is_array($tagCode)) {
+            $tagCode = array($tagCode);
+        }
+        $ret = 0;
+        foreach ($this->_tags as &$tag) {
+            if (in_array($tag->code, $tagCode) && isset($tag->characterId)) {
+                if ($tag->characterId == $characterId) {
+                    if (isset($replaceTag['Code'])) {
+                        $tag->code = $replaceTag['Code'];
+                    }
+                    $tag->length = strlen($replaceTag['Content']);
+                    $tag->content = $replaceTag['Content'];
+                    $ret = 1;
+                    break;
+                }
+            }
+        }
+        return $ret;
+    }
+
+    function replaceBitmapTagByCharacterId($tagCode, $characterId, $replaceTag) {
+        if (! is_array($tagCode)) {
+            $tagCode = array($tagCode);
+        }
+        $ret = 0;
+        foreach ($this->_tags as &$tag) {
+            if (in_array($tag->code, $tagCode) && isset($tag->characterId)) {
+                if ($tag->characterId == $characterId) {
+                    if (isset($replaceTag['Code'])) {
+                        $tag->code = $replaceTag['Code'];
+                    }
+                    $tag->length = strlen($replaceTag['Content']);
+                    $tag->content = $replaceTag['Content'];
+                    $ret = 1;
+                    break;
+                }
+            }
+        }
+        return $ret;
+    }
+
+    function getTagContentByCharacterId($tagCode, $characterId) {
+        foreach ($this->_tags as $tag) {
+            if (($tag->code == $tagCode) && isset($tag->characterId)) {
+                if ($tag->characterId == $characterId) {
+                    return $tag->content;
+                    break;
+                }
+            }
+        }
+        return null;
+    }
+
+    function deformeShape($threshold) {
+        foreach ($this->_tags as &$tag) {
+            $code = $tag->code;
+            switch($code) {
+              case 2: // DefineShape
+              case 22: // DefineShape2
+              case 32: // DefineShape3
+                $shape = new IO_SWF_Tag_Shape();
+                $shape->parseContent($code, $tag->content);
+                $shape->deforme($threshold);
+                $tag->content = $shape->buildContent($code); // XXX
+                break;
+            }
+        }
+    }
+
+    function setActionVariables($trans_table_or_key_str, $value_str = null) {
+        if(is_array($trans_table_or_key_str)) {
+            $trans_table = $trans_table_or_key_str;
+        } else {
+            $trans_table = array($trans_table_or_key_str => $value_str);
+        }
+        foreach ($this->_tags as $tagidx => &$tag) {
+            $code = $tag->code;
+            switch($code) {
+              case 12: // DoAction
+              case 59: // DoInitAction
+                  $action = new IO_SWF_Tag_Action();
+                  $action->parseContent($code, $tag->content);
+                break 2;
+              case 1: // ShowFrame
+                break 2;
+            }
+        }
+        if (isset($action) === false) {
+            // 1 frame 目に Action タグがないので新規作成
+            $bytecode = '';
+            foreach ($trans_table as $key_str => $value_str) {
+                $key_strs   = explode("\0", $key_str);   // \0 除去
+                $value_strs = explode("\0", $value_str); // \0 除去
+                $key_data   = chr(0).$key_strs[0]."\0";
+                $value_data = chr(0).$value_strs[0]."\0";
+                // Push
+                $bytecode .= chr(0x96).pack('v', strlen($key_data)).$key_data;
+                // Push
+                $bytecode .= chr(0x96).pack('v', strlen($value_data)).$value_data;
+                // SetVarables
+                $bytecode .= chr(0x1d);
+                // End
+                $bytecode .= chr(0);
+            }
+            $tag_action = new IO_SWF_Tag();
+            $tag_action->code = 12; // DoAction
+            $tag_action->content = $bytecode;
+            // 新規タグ挿入
+            array_splice($this->_tags, $tagidx, 0, array($tag_action));
+        } else { // 既にある Action タグに bytecode 追加。
+            foreach ($trans_table as $key_str => $value_str) {
+                $action_rec = array('Code' => 0x96, // Push
+                                      'Values' => array(
+                                          array('Type' => 0,
+                                                'String' => $key_str)));
+                $action->insertAction(0, $action_rec);
+                $action_rec = array('Code' => 0x96, // Push
+                                      'Values' => array(
+                                          array('Type' => 0,
+                                                'String' => $value_str)));
+                $action->insertAction(1, $action_rec);
+                $action_rec = array('Code' => 0x1d); // SetVariable
+                $action->insertAction(2, $action_rec);
+            }
+            $tag->content = $action->buildContent($code);
+//            $tag->content = null;
+        }
+    }
+
+    function replaceActionStrings($trans_table_or_from_str, $to_str = null) {
+        $opts = array('Version' => $this->_headers['Version']); // for parser
+        if(is_array($trans_table_or_from_str)) {
+            $trans_table = $trans_table_or_from_str;
+        } else {
+            $trans_table = array($trans_table_or_from_str => $to_str);
+        }
+        foreach ($this->_tags as &$tag) {
+            $code = $tag->code;
+            switch($code) {
+              case 12: // DoAction
+              case 59: // DoInitAction
+                $tag->parseTagContent($opts);
+                if ($tag->tag->replaceActionStrings($trans_table)) {
+                    $tag->content = null;
+                }
+                break;
+              case 34: // DefineButton2
+                $tag->parseTagContent($opts);
+                if (is_null($tag->tag->_actions) === false) {
+                    foreach ($tag->tag->_actions as &$buttoncondaction) {
+                        if (isset($buttoncondaction['Actions'])) {
+                            foreach ($buttoncondaction['Actions'] as &$action) {
+                                IO_SWF_Type_Action::replaceActionString($action, $trans_table);
+                            }
+                            unset($action);
+                        }
+                    }
+                    unset($buttoncondaction);
+                }
+                $tag->content = null;
+                break;
+              case 39: // Sprite
+                $tag->parseTagContent($opts);
+                foreach ($tag->tag->_controlTags as &$tag_in_sprite) {
+                    $code_in_sprite = $tag_in_sprite->code;
+                    switch ($code_in_sprite) {
+                      case 12: // DoAction
+                      case 59: // DoInitAction
+                        $action_in_sprite = new IO_SWF_Tag_Action();
+                        $action_in_sprite->parseContent($code_in_sprite, $tag_in_sprite->content);
+                        $action_in_sprite->replaceActionStrings($trans_table);
+                        $tag_in_sprite->content = null;
+                        break;
+                    }
+                }
+                unset($tag_in_sprite);
+                $tag->content = null;
+                break;
+            }
+        }
+    }
+
+    function replaceBitmapData($bitmap_id, $bitmap_data, $jpeg_alphadata = null) {
+        $this->setCharacterId();
+        // TODO: 後で IO_SWF_Bitmap::detect_bitmap_format を使うよう書き換える
+        if ((strncmp($bitmap_data, 'GIF', 3) == 0) ||
+            (strncmp($bitmap_data, "\x89PNG", 4) == 0)) {
+            $tag = IO_SWF_Lossless::BitmapData2Lossless($bitmap_id, $bitmap_data);
+            $new_width = $tag['width'];
+            $new_height = $tag['height'];
+        } else if (strncmp($bitmap_data, "\xff\xd8\xff", 3) == 0) {
+            $erroneous_header = pack('CCCC', 0xFF, 0xD9, 0xFF, 0xD8);
+            if (is_null($jpeg_alphadata)) {
+                // 21: DefineBitsJPEG2
+                $content = pack('v', $bitmap_id).$erroneous_header.$bitmap_data;
+                $tag = array('Code' => 21,
+                             'Content' => $content);
+            } else {
+                // 35: DefineBitsJPEG3
+                $jpeg_data = $erroneous_header.$bitmap_data;
+                $compressed_alphadata = gzcompress($jpeg_alphadata);
+                $content = pack('v', $bitmap_id).pack('V', strlen($jpeg_data)).$jpeg_data.$compressed_alphadata;
+                $tag = array('Code' => 35,
+                             'Content' => $content);
+            }
+            list($new_width, $new_height) = IO_SWF_Bitmap::get_jpegsize($bitmap_data);
+        } else {
+            throw new IO_SWF_Exception("Unknown Bitmap Format: ".bin2hex(substr($bitmap_data, 0, 4)));
+        }
+        if ($this->shape_adjust_mode > 0) {
+            $ret = $this->applyShapeAdjustModeByRefId($bitmap_id, $new_width, $new_height);
+        }
+        // DefineBits,DefineBitsJPEG2,3, DefineBitsLossless,DefineBitsLossless2
+        $tag_code = array(6, 21, 35, 20, 36);
+        if ($this->shape_adjust_mode > 0) {
+            $tag['shape_adjust_mode'] = $this->shape_adjust_mode;
+        }
+        $ret = $this->replaceBitmapTagByCharacterId($tag_code, $bitmap_id, $tag);
+//        $ret = $this->replaceTagByCharacterId($tag_code, $bitmap_id, $tag);
+        return $ret;
+    }
+    function applyShapeAdjustModeByRefId($bitmap_id, $new_height, $old_height) {
+        $shape_adjust_mode = $this->shape_adjust_mode;
+        switch ($shape_adjust_mode) {
+          case self::SHAPE_BITMAP_NONE:
+            return false;
+          case self::SHAPE_BITMAP_MATRIX_RESCALE:
+          case self::SHAPE_BITMAP_RECT_RESIZE:
+
+          case self::SHAPE_BITMAP_TYPE_TYLED:
+            break ;
+          default:
+            trigger_error("Illegal shape_adjust_mode($shape_adjust_mode)");
+            return false;
+        }
+
+        switch ($shape_adjust_mode) {
+          case self::SHAPE_BITMAP_MATRIX_RESCALE:
+            break ;
+          case self::SHAPE_BITMAP_RECT_RESIZE:
+            break ;
+          case self::SHAPE_BITMAP_TYPE_TYLED:
+            break ;
+          default:
+            trigger_error("Illegal shape_adjust_mode($shape_adjust_mode)");
+            return false;
+        }
+        return true;
+    }
+
+    function countShapeEdges($opts = array()) {
+        $count_table = array();
+        foreach ($this->_tags as $tag) {
+            $code = $tag->code;
+            switch ($code) {
+              case 2: // DefineShape
+              case 22: // DefineShape2
+              case 32: // DefineShape3
+              case 46: // DefineMorphShape
+                $shape = new IO_SWF_Tag_Shape();
+                $shape->parseContent($code, $tag->content);
+                list($shape_id, $edges_count) = $shape->countEdges();
+                $count_table[$shape_id] = $edges_count;
+            }
+        }
+        return $count_table;
+    }
+    function setShapeAdjustMode($mode) {
+        $this->shape_adjust_mode = $mode;
+    }
+
+    function searchMovieClipTagByCID($cid, $opts) {
+        foreach ($this->_tags as $tag_idx => $tag) {
+            if ($tag->code == 39) { // DefineSprite
+                if ($tag->parseTagContent($opts)) {
+                    if ($tag->tag->_spriteId == $cid) {
+                        return $tag_idx;
+                    }
+                }
+            }
+        }
+        return false;
+    }
+    function searchMovieClipTagByTargetPath($target_path, $opts) {
+        /*
+         * scanning for target sprite tag
+         */
+        $target_sprite_tag_idx = false;
+        $target_path_list = explode('/', $target_path);
+        $tag_scan_state = 1; // 1:scan for name 2: scan for character id
+        $tag_scan_character_id = -1;
+        foreach (array_reverse(array_keys($this->_tags)) as $tag_idx) {
+            $tag = $this->_tags[$tag_idx];
+            $code = $tag->code;
+            switch($tag_scan_state) {
+              case 1: // scan for name
+                if ($code == 26) { // PlaceObject2
+                    if ($tag->parseTagContent($opts) &&
+                        isset($tag->tag->_name) &&
+                        ($tag->tag->_name == $target_path_list[0])) {
+                        array_shift($target_path_list);
+                        $tag_scan_character_id = $tag->tag->_characterId;
+                        $tag_scan_state = 2; // scan for character id
+                    }
+                }
+                break;
+              case 2: // scan for character id
+                if ($code == 39) { // DefineSprite
+                    if (isset($tag->characterId) && ($tag->characterId == $tag_scan_character_id)) {
+                        if (count($target_path_list) === 0) {
+                            $target_sprite_tag_idx = $tag_idx;
+                            break; // sprite tag found !!
+                        }
+                        if ($tag->parseTagContent($opts)) {
+                            foreach ($tag->tag->_controlTags as $tag_in_sprite) {
+                                // PlaceObject2 in DefineSprite
+                                if ($tag_in_sprite->code == 26) {
+                                    if ($tag_in_sprite->parseTagContent($opts) &&
+                                        isset($tag_in_sprite->tag->_name) &&
+                                        ($tag_in_sprite->tag->_name == $target_path_list[0])) {
+                                        array_shift($target_path_list);
+                                        $tag_scan_character_id = $tag_in_sprite->tag->_characterId;
+                                    }
+                                }
+                            }
+                        }
+                    }
+                }
+            }
+            if ($target_sprite_tag_idx !== false) {
+                break; // target sprite found
+            }
+        }
+        return $target_sprite_tag_idx;
+    }
+
+    function replaceMovieClip($target_path, $mc_swfdata) {
+        $this->setCharacterId();
+        $mc_tag_idx = null;
+        if ($target_path === '') {
+            trigger_error('target_path is null string');
+            return false;
+        }
+        $opts = array('Version' => $this->_headers['Version']); // for parser
+        if (is_numeric($target_path)) {
+            $cid = $target_path;
+            $target_sprite_tag_idx = $this->searchMovieClipTagByCID($cid, $opts);
+        } else {
+            $target_sprite_tag_idx = $this->searchMovieClipTagByTargetPath($target_path, $opts);
+        }
+        if ($target_sprite_tag_idx === false) {
+            trigger_error("target_path symbol not found($target_path)");
+            return false;
+        }
+
+        /*
+         * base swf character id check
+         */
+        $used_character_id_table = array();
+        foreach ($this->_tags as $tag) {
+            if (isset($tag->characterId)) {
+                $used_character_id_table[$tag->characterId] = true;
+            }
+        }
+        /*
+         * new sprite tag character id renumbering
+         */
+        $character_id_trans_table = array();
+        $mc_swf = new IO_SWF_Editor();
+        $mc_swf->parse($mc_swfdata);
+        $mc_swf->setCharacterId();
+        $mc_swf->setReferenceId();
+        $mc_character_tag_list = array();
+        foreach ($mc_swf->_tags as $tag_idx => &$tag) {
+            switch ($tag->code) {
+              case 8: //JPEGTables
+              case 9: // SetBackgroundColor
+              case 69: // FileAttributes
+                unset($mc_swf->_tags[$tag_idx]); // delete
+                continue;
+            }
+            if (isset($tag->characterId)) {
+//                echo "code={$tag->code}\n";
+                $cid = $tag->characterId;
+                if (isset($used_character_id_table[$cid]) &&
+                    (isset($character_id_trans_table[$cid]) === false)) {
+                    $new_cid = $cid;
+                    while (isset($used_character_id_table[$new_cid])) {
+                        $new_cid++;
+                    }
+                    $character_id_trans_table[$cid] = $new_cid;
+                    $used_character_id_table[$new_cid] = true;
+                }
+                if (isset($character_id_trans_table[$cid])) {
+                    $tag->replaceCharacterId($character_id_trans_table);
+                }
+                $mc_character_tag_list[] = $tag;
+                unset($mc_swf->_tags[$tag_idx]); // delete
+            }
+            if (isset($tag->referenceId)) {
+                $tag->replaceReferenceId($character_id_trans_table);
+            }
+            if ($tag->code == 39) { // DefineSprite
+                if ($tag->parseTagContent()) {
+                    foreach ($tag->tag->_controlTags as &$tag_in_sprite) {
+                        $tag_in_sprite->replaceReferenceId($character_id_trans_table);
+                    }
+                    $tag->content = null;
+                }
+            }
+        }
+        unset($tag);
+        /*
+         * replace
+         */
+        $sprite_tag_ref =& $this->_tags[$target_sprite_tag_idx];
+        if ($sprite_tag_ref->parseTagContent() === false) {
+            return false;
+        }
+        $frameCount = 0;
+        $controlTags = array_values($mc_swf->_tags);
+        foreach ($controlTags as $tag) {
+            if ($tag->code == 1) {
+                $frameCount++;
+            }
+        }
+        $sprite_tag_ref->tag->_frameCount = $frameCount;
+        $sprite_tag_ref->tag->_controlTags = $controlTags;
+        $sprite_tag_ref->content = null;
+        /*
+         * character tag insert
+         */
+        array_splice($this->_tags, $target_sprite_tag_idx, 0, $mc_character_tag_list);
+        return true;
+    }
+    function getMovieClip($target_path) {
+        return $this->getOrGrepMovieClip($target_path, false);
+    }
+    function grepMovieClip($target_path) {
+        return $this->getOrGrepMovieClip($target_path, true);
+    }
+    function getOrGrepMovieClip($target_path, $is_grep) {
+        $this->setCharacterId();
+        $mc_tag_idx = null;
+        if ($target_path === '') {
+            trigger_error('target_path is null string');
+            return false;
+        }
+        $opts = array('Version' => $this->_headers['Version']); // for parser
+        if (is_numeric($target_path)) {
+            $cid = $target_path;
+            $target_sprite_tag_idx = $this->searchMovieClipTagByCID($cid, $opts);
+        } else {
+            $target_sprite_tag_idx = $this->searchMovieClipTagByTargetPath($target_path, $opts);
+        }
+        if ($target_sprite_tag_idx === false) {
+            trigger_error("target_path symbol not found($target_path)");
+            return false;
+        }
+        $target_sprite_tag = $this->_tags[$target_sprite_tag_idx];
+        if ($target_sprite_tag->parseTagContent($opts) === false) {
+            trigger_error("target_sprite_tag parse failed");
+            return false;
+        }
+        $new_main_tags = array();
+        foreach ($this->_tags as $tag_idx => $tag) {
+            if ($tag_idx <= $target_sprite_tag_idx) {
+                switch ($tag->code) {
+                case 1: // ShowFrame
+                case 4: // PlaceObject
+                case 5: // RemoveObject
+                case 9: // SetBackgroundColor
+                case 12: // DoAction
+                case 26: // PlaceObject2
+                case 28: // RemoveObject2
+                case 43: // FrameLabel
+                case 59: // DoInitAction
+                    break; // skip non Define Tags;
+                default:
+                    $new_main_tags []= $tag;
+                }
+            } else {
+                break;
+            }
+        }
+        if ($is_grep) { // is grep
+            $new_main_tags []= $target_sprite_tag;
+            foreach ($this->_tags as $tag_idx => $tag) {
+                if ($tag_idx <= $target_sprite_tag_idx) {
+                    continue;
+                }
+                if ($tag->code == 26) { // PlaceObject
+                    if (($tag->parseTagContent($opts) === false) ||
+                        is_null($tag->tag->_characterId) === false) {
+                        continue;
+                    }
+                    if ($tag->tag->_characterId == $target_sprite_tag->tag->_spriteId) {
+                        $new_main_tags []= $tag;
+                        $end_tag = new IO_SWF_Tag();
+                        $end_tag->code = 0;
+                        $new_main_tags []= $end_tag;
+                        break;
+                    }
+                }
+            }
+        } else { // is get
+            // movieclip to maintimeline
+            foreach ($target_sprite_tag->tag->_controlTags as $tag_in_sprite) {
+                $new_main_tags []= $tag_in_sprite;
+            }
+        }
+        $swf = clone $this;
+        $swf->_tags = $new_main_tags;
+        $swf->purgeUselessContents();
+        return $swf->build();
+    }
+    function listMovieClip_r($prefix, $characterId, $name, $parent_cids, &$spriteTable) {
+        $spriteId = $characterId;
+        $spriteTable[$spriteId]['name'] = $name;
+        if (is_null($prefix)) {
+            $path = $name;
+        } else {
+            $path = $prefix.'/'.$name;
+        }
+        if (isset($spriteTable[$spriteId]['path_list']) === false) {
+            $spriteTable[$spriteId]['path_list'] = array();
+        }
+        $spriteTable[$spriteId]['path_list'] []= array('path' => $path, 'parent_cids' => $parent_cids);
+        foreach ($spriteTable[$spriteId]['Places'] as $place) {
+            $this->listMovieClip_r($path, $place['cid'], $place['name'], array_merge($parent_cids, array($spriteId)), $spriteTable);
+        }
+        return true;
+    }
+    function listMovieClip() {
+        $spriteTable = array();
+        foreach ($this->_tags as $tag) {
+            $opts = array();
+            switch ($tag->code) {
+            case 26: //  PlaceObject2
+                $tag->parseTagContent($opts);
+                if (is_null($tag->tag->_name) === false) {
+                    $cid = $tag->tag->_characterId;
+                    $name = $tag->tag->_name;
+                    $mc_list = $this->listMovieClip_r(null, $cid, $name, array(), $spriteTable);
+                }
+                break;
+            case 39: // DefineSprite
+                $tag->parseTagContent($opts);
+                $spriteId = $tag->tag->_spriteId;
+                $spriteTable[$spriteId] = array('FrameCount' => $tag->tag->_frameCount, 'TagCount' => count($tag->tag->_controlTags), 'Places' => array());
+                foreach ($tag->tag->_controlTags as &$tag_in_sprite) {
+                    if ($tag_in_sprite->code == 26) { // PlaceObject2
+                        $tag_in_sprite->parseTagContent();
+                        if (is_null($tag_in_sprite->tag->_name) === false) {
+                            $cid = $tag_in_sprite->tag->_characterId;
+                            $name = $tag_in_sprite->tag->_name;
+                            if (isset($spriteTable[$spriteId]['name'])) {
+                                $parent_name = $spriteTable[$spriteId]['name'];
+                            } else {
+                                $parent_name = '*';
+                            }
+                            $this->listMovieClip_r($parent_name, $cid, $name, array($spriteId), $spriteTable);
+                            $spriteTable[$spriteId]['Places'][]= array('cid' => $cid, 'name' => $name);
+                        }
+                    }
+                }
+                unset($tag_in_sprite);
+                break;
+            }
+        }
+        unset($tag);
+        return $spriteTable;
+    }
+    function selectByCIDs($cids) {
+        $cid_table = array();
+        foreach ($cids as $cid) {
+            $cid_table[$cid] = true;
+        }
+        $this->setCharacterId();
+        $this->setReferenceId();
+
+        $swf = clone $this;
+
+        foreach ($swf->_tags as $idx => &$tag) {
+            $tag_keep = true;
+            if (isset($tag->referenceId)) {
+                $tag_keep = false;
+                $refid = $tag->referenceId;
+                if (is_array($refid)) {
+                    foreach ($refid as $id) {
+                        if (isset($cid_table[$id])) {
+                            $tag_keep = true;
+                        }
+                    }
+                } else {
+                    if (isset($cid_table[$refid])) {
+                        $tag_keep = true;
+                    }
+                }
+                if ($tag_keep && isset($tag->characterId)) {
+                    $cid_table[$tag->characterId] = true;
+                }
+            } else if ($tag->code == 26) { // PlaceObject
+                $tag_keep = false;
+            }
+            if ($tag->code == 39) { // DefineSprite
+                if ($tag->parseTagContent() === false) {
+                    throw new IO_SWF_Exception("failed to parseTagContent");
+                }
+                foreach ($tag->tag->_controlTags as $idx_in_sprite => &$tag_in_sprite) {
+                    $tag_in_sprite_keep = true;
+                    if (isset($tag_in_sprite->referenceId)) {
+                        $refid = $tag_in_sprite->referenceId;
+                        if (is_array($refid)) {
+                            foreach ($refid as $id) {
+                                if (isset($cid_table[$id])) {
+                                    $tag_in_sprite_keep = true;
+                                }
+                            }
+                        } else {
+                            if (isset($cid_table[$refid])) {
+                                $tag_in_sprite_keep = true;
+                            }
+                        }
+                        if ($tag_keep && isset($tag_in_sprite->characterId)) {
+                            $cid_table[$tag_in_sprite->characterId] = true;
+                        }
+                    } else if ($tag_in_sprite->code == 26) { // PlaceObject2
+                        $tag_in_sprite_keep = false;
+                    } else if ($tag_in_sprite->code == 5 || $tag_in_sprite->code == 28) { // RemoveObject
+                        $tag_in_sprite_keep = false;
+                    }
+                    if ($tag_in_sprite_keep === false) {
+                        unset($tag->tag->_controlTags[$idx_in_sprite]);
+                        $tag->content = null; // XXX
+                    }
+                }
+                unset($tag_in_sprite);
+            } else if (isset($tag->characterId)) {
+                if (isset($cid_table[$tag->characterId])) {
+                    $tag_keep = true;
+                } else {
+                    $tag_keep = false;
+                }
+            }
+            if ($tag->code == 5 || $tag->code == 28) { // RemoveObject
+                $tag_keep = false;
+            }
+            if ($tag_keep === false) {
+                unset($swf->_tags[$idx]);
+            }
+        }
+        unset($tag);
+        // $swf->purgeUselessContents();
+        return $swf->build();
+    }
+    function purgeUselessContents() {
+        $this->setCharacterId();
+        $this->setReferenceId();
+        $used_character_id_table = array();
+        foreach (array_reverse(array_keys($this->_tags)) as $tag_idx) {
+            $tag = $this->_tags[$tag_idx];
+            if (isset($tag->characterId)) {
+                $cid = $tag->characterId;
+                if (isset($used_character_id_table[$cid]) === false) {
+                    unset($this->_tags[$tag_idx]);
+                }
+            }
+            if (isset($this->_tags[$tag_idx]) && isset($tag->referenceId)) {
+                $refid = $tag->referenceId;
+                if (is_array($refid)) {
+                    foreach ($refid as $id) {
+                        $used_character_id_table[$id] = true;
+                    }
+                } else {
+                    $used_character_id_table[$refid] = true;
+                }
+            }
+        }
+    }
+    function replaceEditString($id, $initialText) {
+        $this->setCharacterId();
+        foreach ($this->_tags as &$tag) {
+            if ($tag->code == 37) { // DefineEditText
+                if ($tag->characterId === (int) $id) {
+                    if ($tag->parseTagContent() === false) {
+                        return false;
+                    }
+                    $tag->tag->initialText = $initialText;
+                    $tag->content = null;
+                    return true;
+                } else {
+                    if ($tag->parseTagContent() === false) {
+                        return false;
+                    }
+                    if ($tag->tag->VariableName === $id) {
+                        $tag->tag->InitialText = $initialText;
+                        $tag->content = null;
+                        return true;
+                    }
+                }
+            }
+        }
+        trigger_error("Can't found EditText($id)");
+        return false;
+    }
+    function getEditString($id) {
+        $this->setCharacterId();
+        foreach ($this->_tags as &$tag) {
+            if ($tag->code == 37) { // DefineEditText
+                if ($tag->characterId === (int) $id) {
+                    if ($tag->parseTagContent() === false) {
+                        return false;
+                    }
+                    if (isset($tag->tag->initialText)) {
+                        return $tag->tag->initialText;
+                    } else {
+                        return null;
+                    }
+                } else {
+                    if ($tag->parseTagContent() === false) {
+                        return false;
+                    }
+                    if ($tag->tag->VariableName === $id) {
+                        if (isset($tag->tag->initialText)) {
+                            return $tag->tag->initialText;
+                        } else {
+                            return null;
+                        }
+                    }
+                }
+            }
+        }
+        trigger_error("Can't found EditText($id)");
+        return false;
+    }
+}

IO_SWF/tags/2.1.8-stable-20120220231502/IO/SWF/Lossless.php

@@ -0,0 +1,207 @@
+<?php
+
+require ('IO/SWF/Tag/Jpeg.php');
+
+class IO_SWF_Lossless {
+    /* PNG と GIF の Bitmap データを Lossless 形式に変換する
+     * return array('Code' => ..., 'Content' => ...)
+     */
+    function BitmapData2Lossless($bitmap_id, $bitmap_data) {
+        $im = imagecreatefromstring($bitmap_data);
+        if ($im === false) {
+            throw new IO_SWF_Exception("not Bitmap Image");
+        }
+
+        $colortable_size = imagecolorstotal($im);
+
+        if ((imageistruecolor($im) === false) && ($colortable_size <= 256)) {
+            $format = 3; // palette format
+            $transparent_exists = false;
+            for ($i = 0 ; $i < $colortable_size ; $i++) {
+                $rgba = imagecolorsforindex($im, $i);
+                if (array_key_exists('alpha', $rgba) && ($rgba['alpha'] > 0)) {
+                    $transparent_exists = true;
+                    break;
+                }
+            }
+            $colortable = '';
+            if ($transparent_exists == false) {
+                for ($i = 0 ; $i < $colortable_size ; $i++) {
+                    $rgb = imagecolorsforindex($im, $i);
+                    $colortable .= chr($rgb['red']);
+                    $colortable .= chr($rgb['green']);
+                    $colortable .= chr($rgb['blue']);
+                }
+            } else {
+                for ($i = 0 ; $i < $colortable_size ; $i++) {
+                    $rgba = imagecolorsforindex($im, $i);
+                    $alpha = $rgba['alpha'];
+                    $alpha = 2 * (127 - $alpha);
+                    $colortable .= chr($rgba['red']  * $alpha / 255);
+                    $colortable .= chr($rgba['green']* $alpha / 255);
+                    $colortable .= chr($rgba['blue'] * $alpha / 255);
+                    $colortable .= chr($alpha);
+                }
+            }
+
+            $pixeldata = '';
+            $i = 0;
+            $width  = imagesx($im);
+            $height = imagesy($im);
+
+            for ($y = 0 ; $y < $height ; $y++) {
+                for ($x = 0 ; $x < $width ; $x++) {
+                    $pixeldata .= chr(imagecolorat($im, $x, $y));
+                    $i++;
+                }
+                while (($i % 4) != 0) {
+                    $pixeldata .= chr(0);
+                    $i++;
+                }
+            }
+        } else { // truecolor
+            $format = 5; // trurcolor format
+            $transparent_exists = false;
+
+            $width  = imagesx($im);
+            $height = imagesy($im);
+            for ($y = 0 ; $y < $height ; $y++) {
+                for ($x = 0 ; $x < $width ; $x++) {
+                    $i = imagecolorat($im, $x, $y);
+                    $rgba = imagecolorsforindex($im, $i);
+                    if (array_key_exists('alpha', $rgba) && ($rgba['alpha'] > 0)) {
+                        $transparent_exists = true;
+                        break;
+                    }
+                }
+            }
+            $pixeldata = '';
+            if ($transparent_exists === false) {
+                for ($y = 0 ; $y < $height ; $y++) {
+                    for ($x = 0 ; $x < $width ; $x++) {
+                        $i = imagecolorat($im, $x, $y);
+                        $rgb = imagecolorsforindex($im, $i);
+                        $pixeldata .= 0; // Always 0
+                        $pixeldata .= chr($rgb['red']);
+                        $pixeldata .= chr($rgb['green']);
+                        $pixeldata .= chr($rgb['blue']);
+                    }
+                }
+            } else {
+                for ($y = 0 ; $y < $height ; $y++) {
+                    for ($x = 0 ; $x < $width ; $x++) {
+                        $i = imagecolorat($im, $x, $y);
+                        $rgba = imagecolorsforindex($im, $i);
+                        $alpha = $rgba['alpha'];
+                        $alpha = 2 * (127 - $alpha);
+                        $pixeldata .= chr($alpha);
+                        $pixeldata .= chr($rgba['red']  * $alpha / 255);
+                        $pixeldata .= chr($rgba['green']* $alpha / 255);
+                        $pixeldata .= chr($rgba['blue'] * $alpha / 255);
+                    }
+                }
+            }
+        }
+
+        imagedestroy($im);
+        $content = pack('v', $bitmap_id).chr($format).pack('v', $width).pack('v', $height);
+        if ($format == 3) {
+            $content .= chr($colortable_size - 1).gzcompress($colortable.$pixeldata);
+        } else {
+            $content .= gzcompress($pixeldata);
+        }
+
+        if ($transparent_exists === false) {
+            $tagCode = 20; // DefineBitsLossless
+        } else {
+            $tagCode = 36; // DefineBitsLossless2
+        }
+        $tag = array('Code' => $tagCode,
+                     'width' => $width,
+                     'height' => $height,
+                     'Content' => $content);
+        return $tag;
+    }
+
+    /* Lossless 形式のデータ PNG データに変換する (一時ファイルを作ります)
+     * return (string) $pngdata;
+     */
+    function Lossless2PNG($tagCode, $format, $width, $height,
+                          $palette_num, $palette_data,
+                          $lossless_bitmap_data) {
+        if ($format == 3) {
+            $im = imagecreate($width, $height);
+            $gd_palette = array();
+            $padding = 0;
+            if ($tagCode == 20) { // DefineBitsLossless
+                $palette_bytesize = 3 * $palette_num;
+                for ($i = 0, $j = 0; $i <  $palette_num; $i++) {
+                    $red   = ord($palette_data[$j++]);
+                    $green = ord($palette_data[$j++]);
+                    $blue  = ord($palette_data[$j++]);
+                    $gd_palette []= imagecolorallocate($im, $red, $green, $blue);
+                }
+            } else { // DefineBitsLossless2
+                for ($i = 0, $j = 0; $i <  $palette_num; $i++) {
+                    $red   = ord($palette_data[$j++]);
+                    $green = ord($palette_data[$j++]);
+                    $blue  = ord($palette_data[$j++]);
+                    $alpha = ord($palette_data[$j++]);
+                    $alpha = 127 - $alpha / 2;
+                    $gd_palette []= imagecolorallocatealpha($im, $red, $green, $blue, $alpha);
+                }
+            }
+            if ($width % 4) {
+                $padding = 4 - ($width % 4);
+            }
+            $i = 0;
+            for ($y = 0 ; $y < $height ; $y++) {
+                for ($x = 0 ; $x < $width ; $x++) {
+                    $color_index = ord($lossless_bitmap_data[$i++]);
+                    imagesetpixel($im, $x, $y, $gd_palette[$color_index]);
+                }
+                $i += $padding;
+            }
+        } else if ($format == 4) {
+            ;
+        } else { // format 5
+            $im = imagecreatetruecolor($width, $height);
+            if ($tagCode == 20) { // DefineBitsLossless
+                $i = 0;
+                for ($y = 0 ; $y < $height ; $y++) {
+                    for ($x = 0 ; $x < $width ; $x++) {
+                        $i++; // reserved X of XRGB
+                        $red   = ord($lossless_bitmap_data[$i++]);
+                        $green = ord($lossless_bitmap_data[$i++]);
+                        $blue  = ord($lossless_bitmap_data[$i++]);
+                        $color = imagecolorallocate($im, $red, $green, $blue);
+                        imagesetpixel($im, $x, $y, $color);
+                    }
+                }
+            } else { // DefineBitsLossless2
+                $i = 0;
+                for ($y = 0 ; $y < $height ; $y++) {
+                    for ($x = 0 ; $x < $width ; $x++) {
+                        $alpha = ord($lossless_bitmap_data[$i++]);
+                        $alpha = 127 - $alpha / 2;
+                        $red   = ord($lossless_bitmap_data[$i++]);
+                        $green = ord($lossless_bitmap_data[$i++]);
+                        $blue  = ord($lossless_bitmap_data[$i++]);
+                        $color = imagecolorallocatealpha($im, $red, $green, $blue, $alpha);
+                        imagesetpixel($im, $x, $y, $color);
+                    }
+                }
+            }
+        }
+        if ($tagCode == 36) { // DefineBitsLossless2
+            imagesavealpha($im, true);
+        }
+        $filename = tempnam("/tmp", "swfcl2p");
+        if (imagepng($im, $filename) === false) {
+            return false;
+        }
+        $png_data = file_get_contents($filename);
+        unlink($filename);
+        return $png_data;
+    }
+}

IO_SWF/tags/2.1.8-stable-20120220231502/IO/SWF.php

@@ -0,0 +1,130 @@
+<?php
+
+/*
+ * 2010/8/11- (c) yoya@awm.jp
+ */
+
+require_once 'IO/Bit.php';
+require_once dirname(__FILE__).'/SWF/Type/RECT.php';
+require_once dirname(__FILE__).'/SWF/Type/MATRIX.php';
+require_once dirname(__FILE__).'/SWF/Tag.php';
+
+class IO_SWF {
+    // instance variable
+    var $_headers = array(); // protected
+    var $_header_size; // XXX
+    var $_tags = array();    // protected
+    // for debug
+    var $_swfdata = null;
+
+    function parse($swfdata) {
+        $reader = new IO_Bit();
+        $reader->input($swfdata);
+        $this->_swfdata  = $swfdata;
+        /* SWF Header */
+        $this->_headers['Signature'] = $reader->getData(3);
+        $this->_headers['Version'] = $reader->getUI8();
+        $this->_headers['FileLength'] = $reader->getUI32LE();
+        if ($this->_headers['Signature']{0} == 'C') {
+            // CWS の場合、FileLength の後ろが zlib 圧縮されている
+            $uncompressed_data = gzuncompress(substr($swfdata, 8));
+            if ($uncompressed_data === false) {
+                return false;
+            }
+            list($byte_offset, $dummy) = $reader->getOffset();
+            $reader->setOffset(0, 0);
+            $swfdata = $reader->getData($byte_offset) . $uncompressed_data;
+            $reader = new IO_Bit();
+            $reader->input($swfdata);
+            $this->_swfdata  = $swfdata;
+            $reader->setOffset($byte_offset, 0);
+        }
+        /* SWF Movie Header */
+        $this->_headers['FrameSize'] = IO_SWF_Type_RECT::parse($reader);
+        $reader->byteAlign();
+        $this->_headers['FrameRate'] = $reader->getUI16LE();
+        $this->_headers['FrameCount'] = $reader->getUI16LE();
+
+        list($this->_header_size, $dummy) = $reader->getOffset();
+
+        /* SWF Tags */
+        while (true) {
+	    $swfInfo = array('Version' => $this->_headers['Version']);
+      	    $tag = new IO_SWF_Tag($swfInfo);
+            $tag->parse($reader);
+            $this->_tags[] = $tag;
+            if ($tag->code == 0) { // END Tag
+                break;
+            }
+        }
+        return true;
+    }
+
+    function build() {
+        $writer_head = new IO_Bit();
+        $writer = new IO_Bit();
+
+        /* SWF Header */
+        $writer_head->putData($this->_headers['Signature']);
+        $writer_head->putUI8($this->_headers['Version']);
+        $writer_head->putUI32LE($this->_headers['FileLength']);
+
+        /* SWF Movie Header */
+        IO_SWF_Type_RECT::build($writer, $this->_headers['FrameSize']);
+        $writer->byteAlign();
+        $writer->putUI16LE($this->_headers['FrameRate']);
+        $writer->putUI16LE($this->_headers['FrameCount']);
+
+        /* SWF Tags */
+        foreach ($this->_tags as $idx => $tag) {
+            $tagData = $tag->build();
+            if ($tagData != false) {
+                $writer->putData($tagData);
+            } else {
+                throw new IO_SWF_Exception("tag build failed (tag idx=$idx)");
+            }
+        }
+        list($fileLength, $bit_offset_dummy) = $writer->getOffset();
+        $fileLength += 8; // swf header
+        $this->_headers['FileLength'] = $fileLength;
+        $writer_head->setUI32LE($fileLength, 4);
+        if ($this->_headers['Signature']{0} == 'C') {
+            return $writer_head->output() . gzcompress($writer->output());
+        }
+        return $writer_head->output().$writer->output();
+    }
+
+    function dump($opts = array()) {
+        if (empty($opts['hexdump']) === false) {
+            $bitio = new IO_Bit();
+            $bitio->input($this->_swfdata);
+        }
+        /* SWF Header */
+        echo 'Signature: '.$this->_headers['Signature'].PHP_EOL;
+        echo 'Version: '.$this->_headers['Version'].PHP_EOL;
+        echo 'FileLength: '.$this->_headers['FileLength'].PHP_EOL;
+        echo 'FrameSize: '. IO_SWF_Type_RECT::string($this->_headers['FrameSize'])."\n";
+        echo 'FrameRate: '.($this->_headers['FrameRate'] / 0x100).PHP_EOL;
+        echo 'FrameCount: '.$this->_headers['FrameCount'].PHP_EOL;
+
+        if (empty($opts['hexdump']) === false) {
+            $bitio->hexdump(0, $this->_header_size);
+            $opts['bitio'] =& $bitio; // for tag
+        }
+        $opts['indent'] = 0;
+        /* SWF Tags */
+
+        if ($this->_headers['Version'] < 6) {
+            ob_start('mb_convert_encoding_from_sjis');
+        }
+        echo 'Tags:'.PHP_EOL;
+        foreach ($this->_tags as $tag) {
+    	    $tag->dump($opts);
+            ob_flush();
+        }
+    }
+}
+
+function mb_convert_encoding_from_sjis($a) {
+    return mb_convert_encoding($a, 'UTF-8', 'SJIS-win');
+}