Class: SwfRuby::Swf::Tag
- Inherits:
-
Object
- Object
- SwfRuby::Swf::Tag
- Defined in:
- lib/swf_ruby/swf/tag.rb
Instance Attribute Summary collapse
-
#character_id ⇒ Object
readonly
Returns the value of attribute character_id.
-
#code ⇒ Object
readonly
Returns the value of attribute code.
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#length ⇒ Object
readonly
Returns the value of attribute length.
-
#long_header ⇒ Object
readonly
Returns the value of attribute long_header.
-
#rawdata ⇒ Object
readonly
Returns the value of attribute rawdata.
-
#refer_bitmap_offsets_to_ids ⇒ Object
readonly
Returns the value of attribute refer_bitmap_offsets_to_ids.
-
#refer_character_id ⇒ Object
readonly
Returns the value of attribute refer_character_id.
-
#refer_character_id_offset ⇒ Object
readonly
Returns the value of attribute refer_character_id_offset.
-
#refer_character_inst_name ⇒ Object
readonly
Returns the value of attribute refer_character_inst_name.
Instance Method Summary collapse
- #define_tag? ⇒ Boolean
-
#initialize(swf) ⇒ Tag
constructor
A new instance of Tag.
-
#rawdata_with_define_character_id(idmap, character_id) ⇒ Object
Define系タグの冒頭のcharacter_id参照を指定のIDに書き換える.
- #rawdata_with_refer_character_id(character_id) ⇒ Object
Constructor Details
#initialize(swf) ⇒ Tag
Returns a new instance of Tag.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/swf_ruby/swf/tag.rb', line 17 def initialize(swf) swf.force_encoding("ASCII-8BIT") if swf.respond_to? :force_encoding record_header = swf[0, 2].unpack("v").first # tag type @code = (record_header >> 6) & 1023 # tag length (including record header) @length = record_header & 63 @long_header = false @data = nil if @length == 63 len = swf[2, 4].unpack("i").first @data = swf[6, len] @length = len + 6 @long_header = true else @data = swf[2, @length] @length += 2 end @character_id = nil if self.define_tag? @character_id = @data[0, 2].unpack("v").first end @refer_character_id = nil @refer_character_id_offset = nil @refer_character_inst_name = nil data_offset = @long_header ? 6 : 2 case Swf::TAG_TYPE[@code] when "PlaceObject" @refer_character_id_offset = data_offset @refer_character_id = @data[0, 2].unpack("v").first when "PlaceObject2" flags = @data[0, 1].unpack("C").first offset = 3 if flags & 2 == 2 @refer_character_id_offset = data_offset + offset @refer_character_id = @data[offset, 2].unpack("v").first offset += 2 end if flags & 32 == 32 if flags & 4 == 4 matrix = SwfRuby::Swf::Matrix.new(@data[offset..-1]) offset += matrix.length end if flags & 8 == 8 cxtfm = SwfRuby::Swf::Cxformwithalpha.new(@data[offset..-1]) offset += cxtfm.length end offset += 2 if flags & 16 == 16 @refer_character_inst_name = SwfRuby::Swf::SwfString.new(@data[offset..-1]).string end when "PlaceObject3" flags = @data[0, 2].unpack("n").first offset = 4 if flags & 8 == 8 class_name = SwfRuby::Swf::SwfString.new(@data[offset..-1]) offset += class_name.length end if flags & 512 == 512 @refer_character_id_offset = data_offset + offset @refer_character_id = @data[offset, 2].unpack("v").first end if flags & 8192 == 8192 if flags & 1024 == 1024 matrix = SwfRuby::Swf::Matrix.new(@data[offset..-1]) offset += matrix.length end if flags & 2048 == 2048 cxtfm = SwfRuby::Swf::Cxformwithalpha.new(@data[offset..-1]) offset += cxtfm.length end offset += 2 if flags & 4096 == 4096 @refer_character_inst_name = SwfRuby::Swf::SwfString.new(@data[offset..-1]).string end when "RemoveObject" @refer_character_id_offset = data_offset @refer_character_id = @data[0, 2].unpack("v").first when "DefineShape" when "DefineShape2" when "DefineShape3" version = Swf::TAG_TYPE[@code][-1].to_i version = 1 if version == 0 @refer_bitmap_offsets_to_ids = {} rect = SwfRuby::Swf::Rectangle.new(@data[2..-1]) offset = 2+rect.length shapewithstyle = SwfRuby::Swf::Shapewithstyle.new(@data[offset..-1], version) shapewithstyle.fill_styles_with_offset.each do |fs_offset, fs| if fs.bitmap_id o = offset + fs_offset + fs.bitmap_id_offset o += @long_header ? 6 : 2 @refer_bitmap_offsets_to_ids[o] = fs.bitmap_id end end when "DefineShape4" version = 4 @refer_bitmap_offsets_to_ids = {} shape_rect = SwfRuby::Swf::Rectangle.new(@data[2..-1]) offset = 2+shape_rect.length edge_rect = SwfRuby::Swf::Rectangle.new(@data[offset..-1]) offset += edge_rect.length offset += 1 shapewithstyle = SwfRuby::Swf::Shapewithstyle.new(@data[offset..-1], version) shapewithstyle.fill_styles_with_offset.each do |fs_offset, fs| if fs.bitmap_id o = offset + fs_offset + fs.bitmap_id_offset o += @long_header ? 6 : 2 @refer_bitmap_offsets_to_ids[o] = fs.bitmap_id end end else # do nothing. end @rawdata = swf[0, @length] self end |
Instance Attribute Details
#character_id ⇒ Object (readonly)
Returns the value of attribute character_id.
11 12 13 |
# File 'lib/swf_ruby/swf/tag.rb', line 11 def character_id @character_id end |
#code ⇒ Object (readonly)
Returns the value of attribute code.
7 8 9 |
# File 'lib/swf_ruby/swf/tag.rb', line 7 def code @code end |
#data ⇒ Object (readonly)
Returns the value of attribute data.
10 11 12 |
# File 'lib/swf_ruby/swf/tag.rb', line 10 def data @data end |
#length ⇒ Object (readonly)
Returns the value of attribute length.
8 9 10 |
# File 'lib/swf_ruby/swf/tag.rb', line 8 def length @length end |
#long_header ⇒ Object (readonly)
Returns the value of attribute long_header.
9 10 11 |
# File 'lib/swf_ruby/swf/tag.rb', line 9 def long_header @long_header end |
#rawdata ⇒ Object (readonly)
Returns the value of attribute rawdata.
6 7 8 |
# File 'lib/swf_ruby/swf/tag.rb', line 6 def rawdata @rawdata end |
#refer_bitmap_offsets_to_ids ⇒ Object (readonly)
Returns the value of attribute refer_bitmap_offsets_to_ids.
15 16 17 |
# File 'lib/swf_ruby/swf/tag.rb', line 15 def refer_bitmap_offsets_to_ids @refer_bitmap_offsets_to_ids end |
#refer_character_id ⇒ Object (readonly)
Returns the value of attribute refer_character_id.
12 13 14 |
# File 'lib/swf_ruby/swf/tag.rb', line 12 def refer_character_id @refer_character_id end |
#refer_character_id_offset ⇒ Object (readonly)
Returns the value of attribute refer_character_id_offset.
13 14 15 |
# File 'lib/swf_ruby/swf/tag.rb', line 13 def refer_character_id_offset @refer_character_id_offset end |
#refer_character_inst_name ⇒ Object (readonly)
Returns the value of attribute refer_character_inst_name.
14 15 16 |
# File 'lib/swf_ruby/swf/tag.rb', line 14 def refer_character_inst_name @refer_character_inst_name end |
Instance Method Details
#define_tag? ⇒ Boolean
150 151 152 |
# File 'lib/swf_ruby/swf/tag.rb', line 150 def define_tag? Swf::TAG_TYPE[@code] =~ /^Define/ end |
#rawdata_with_define_character_id(idmap, character_id) ⇒ Object
Define系タグの冒頭のcharacter_id参照を指定のIDに書き換える. 内部にBitmapIDの参照を含む場合、渡されたidmapから読み替える値を参照し、書き換える.
134 135 136 137 138 139 140 141 142 143 |
# File 'lib/swf_ruby/swf/tag.rb', line 134 def rawdata_with_define_character_id(idmap, character_id) if self.define_tag? offset = @long_header ? 6 : 2 @rawdata[offset, 2] = [character_id].pack("v") @refer_bitmap_offsets_to_ids.each do |bitmap_id_offset, bitmap_id| @rawdata[bitmap_id_offset, 2] = [idmap[bitmap_id]].pack("v") end if @refer_bitmap_offsets_to_ids end @rawdata end |
#rawdata_with_refer_character_id(character_id) ⇒ Object
145 146 147 148 |
# File 'lib/swf_ruby/swf/tag.rb', line 145 def rawdata_with_refer_character_id(character_id) @rawdata[@refer_character_id_offset, 2] = [character_id].pack("v") if @refer_character_id_offset @rawdata end |