Implement SymbolClass tag

This commit is contained in:
Mike Welsh 2016-09-10 16:55:09 -07:00
parent 8e88789994
commit 00a0086a96
6 changed files with 40 additions and 2 deletions

View File

@ -358,7 +358,7 @@ impl<R: Read> Reader<R> {
}
Tag::ImportAssets { url: url, imports: imports }
},
Some(TagCode::SetBackgroundColor) => {
Tag::SetBackgroundColor(try!(tag_reader.read_rgb()))
},
@ -379,6 +379,18 @@ impl<R: Read> Reader<R> {
tab_index: try!(tag_reader.read_u16()),
},
Some(TagCode::SymbolClass) => {
let num_symbols = try!(tag_reader.read_u16());
let mut symbols = Vec::with_capacity(num_symbols as usize);
for _ in 0..num_symbols {
symbols.push(SymbolClassLink {
id: try!(tag_reader.read_u16()),
class_name: try!(tag_reader.read_c_string()),
});
}
Tag::SymbolClass(symbols)
},
Some(TagCode::ExportAssets) => {
let num_exports = try!(tag_reader.read_u16());
let mut exports = Vec::with_capacity(num_exports as usize);

View File

@ -335,6 +335,15 @@ pub fn tag_tests() -> Vec<TagTestData> { vec![
(1, Tag::ShowFrame, vec![0b01_000000, 0]),
(
9,
Tag::SymbolClass(vec![
SymbolClassLink { id: 2, class_name: "foo.Test".to_string() },
SymbolClassLink { id: 0, class_name: "DocumentTest".to_string() },
]),
read_tag_bytes_from_file("tests/swfs/symbolclass.swf", TagCode::SymbolClass)
),
(1, Tag::Unknown { tag_code: 512, data: vec![] }, vec![0b00_000000, 0b10000000]),
(1, Tag::Unknown { tag_code: 513, data: vec![1, 2] }, vec![0b01_000010, 0b10000000, 1, 2]),
(

View File

@ -284,7 +284,7 @@ pub enum Tag {
ImportAssets { url: String, imports: Vec<ExportedAsset> },
SetBackgroundColor(Color),
SetTabIndex { depth: Depth, tab_index: u16 },
SymbolClass(Vec<SymbolClassLink>),
PlaceObject(Box<PlaceObject>),
RemoveObject { depth: Depth, character_id: Option<CharacterId> },
@ -305,6 +305,12 @@ pub struct ExportedAsset {
pub name: String,
}
#[derive(Debug,PartialEq,Clone)]
pub struct SymbolClassLink {
pub id: CharacterId,
pub class_name: String
}
#[derive(Debug,PartialEq)]
pub struct Shape {
pub version: u8,

View File

@ -405,6 +405,17 @@ impl<W: Write> Writer<W> {
try!(self.write_i16(depth));
},
&Tag::SymbolClass(ref symbols) => {
let len = symbols.iter().map(|e| e.class_name.len() as u32 + 3).sum::<u32>()
+ 2;
try!(self.write_tag_header(TagCode::SymbolClass, len));
try!(self.write_u16(symbols.len() as u16));
for &SymbolClassLink {id, ref class_name} in symbols {
try!(self.write_u16(id));
try!(self.write_c_string(class_name));
}
},
&Tag::FileAttributes(ref attributes) => {
try!(self.write_tag_header(TagCode::FileAttributes, 4));
let mut flags = 0u32;

BIN
tests/swfs/symbolclass.fla Normal file

Binary file not shown.

BIN
tests/swfs/symbolclass.swf Normal file

Binary file not shown.