Implement DefineFontInfo tag
This commit is contained in:
parent
56f8376cd8
commit
fe2e09083c
34
src/read.rs
34
src/read.rs
|
@ -474,6 +474,7 @@ impl<R: Read> Reader<R> {
|
||||||
}))
|
}))
|
||||||
},
|
},
|
||||||
Some(TagCode::DefineFont) => try!(tag_reader.read_define_font()),
|
Some(TagCode::DefineFont) => try!(tag_reader.read_define_font()),
|
||||||
|
Some(TagCode::DefineFontInfo) => tag_reader.read_define_font_info()?,
|
||||||
Some(TagCode::DefineShape) => try!(tag_reader.read_define_shape(1)),
|
Some(TagCode::DefineShape) => try!(tag_reader.read_define_shape(1)),
|
||||||
Some(TagCode::DefineShape2) => try!(tag_reader.read_define_shape(2)),
|
Some(TagCode::DefineShape2) => try!(tag_reader.read_define_shape(2)),
|
||||||
Some(TagCode::DefineShape3) => try!(tag_reader.read_define_shape(3)),
|
Some(TagCode::DefineShape3) => try!(tag_reader.read_define_shape(3)),
|
||||||
|
@ -896,6 +897,39 @@ impl<R: Read> Reader<R> {
|
||||||
)))
|
)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn read_define_font_info(&mut self) -> Result<Tag> {
|
||||||
|
let id = self.read_u16()?;
|
||||||
|
|
||||||
|
let font_name_len = self.read_u8()?;
|
||||||
|
let mut font_name = String::with_capacity(font_name_len as usize);
|
||||||
|
self.input.by_ref().take(font_name_len as u64).read_to_string(&mut font_name)?;
|
||||||
|
|
||||||
|
let flags = self.read_u8()?;
|
||||||
|
let use_wide_codes = flags & 0b1 != 0;
|
||||||
|
let mut code_table = vec![];
|
||||||
|
if use_wide_codes {
|
||||||
|
while let Ok(code) = self.read_u16() {
|
||||||
|
code_table.push(code);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
while let Ok(code) = self.read_u8() {
|
||||||
|
code_table.push(code as u16);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// SWF19 has ANSI and Shift-JIS backwards?
|
||||||
|
Ok(Tag::DefineFontInfo(Box::new(FontInfo {
|
||||||
|
id: id,
|
||||||
|
name: font_name,
|
||||||
|
is_small_text: flags & 0b100000 != 0,
|
||||||
|
is_ansi: flags & 0b10000 != 0,
|
||||||
|
is_shift_jis: flags & 0b1000 != 0,
|
||||||
|
is_italic: flags & 0b100 != 0,
|
||||||
|
is_bold: flags & 0b10 != 0,
|
||||||
|
code_table: code_table,
|
||||||
|
})))
|
||||||
|
}
|
||||||
|
|
||||||
fn read_define_shape(&mut self, version: u8) -> Result<Tag> {
|
fn read_define_shape(&mut self, version: u8) -> Result<Tag> {
|
||||||
let id = try!(self.read_u16());
|
let id = try!(self.read_u16());
|
||||||
let shape_bounds = try!(self.read_rectangle());
|
let shape_bounds = try!(self.read_rectangle());
|
||||||
|
|
|
@ -265,6 +265,21 @@ pub fn tag_tests() -> Vec<TagTestData> { vec![
|
||||||
read_tag_bytes_from_file("tests/swfs/DefineFont-MX.swf", TagCode::DefineFont)
|
read_tag_bytes_from_file("tests/swfs/DefineFont-MX.swf", TagCode::DefineFont)
|
||||||
),
|
),
|
||||||
|
|
||||||
|
(
|
||||||
|
1,
|
||||||
|
Tag::DefineFontInfo(Box::new(FontInfo {
|
||||||
|
id: 1,
|
||||||
|
name: "Verdana".to_string(),
|
||||||
|
is_small_text: false,
|
||||||
|
is_ansi: true,
|
||||||
|
is_shift_jis: false,
|
||||||
|
is_italic: false,
|
||||||
|
is_bold: false,
|
||||||
|
code_table: vec![45, 95],
|
||||||
|
})),
|
||||||
|
read_tag_bytes_from_file("tests/swfs/DefineFont-MX.swf", TagCode::DefineFontInfo)
|
||||||
|
),
|
||||||
|
|
||||||
(
|
(
|
||||||
8,
|
8,
|
||||||
Tag::DefineScalingGrid {
|
Tag::DefineScalingGrid {
|
||||||
|
|
13
src/types.rs
13
src/types.rs
|
@ -300,6 +300,7 @@ pub enum Tag {
|
||||||
DefineButtonColorTransform { id: CharacterId, color_transforms: Vec<ColorTransform> },
|
DefineButtonColorTransform { id: CharacterId, color_transforms: Vec<ColorTransform> },
|
||||||
DefineButtonSound(Box<ButtonSounds>),
|
DefineButtonSound(Box<ButtonSounds>),
|
||||||
DefineFont(Box<Font>),
|
DefineFont(Box<Font>),
|
||||||
|
DefineFontInfo(Box<FontInfo>),
|
||||||
DefineScalingGrid { id: CharacterId, splitter_rect: Rectangle },
|
DefineScalingGrid { id: CharacterId, splitter_rect: Rectangle },
|
||||||
DefineShape(Shape),
|
DefineShape(Shape),
|
||||||
DefineSound(Box<Sound>),
|
DefineSound(Box<Sound>),
|
||||||
|
@ -611,4 +612,16 @@ pub struct Font {
|
||||||
pub glyphs: Vec<Glyph>,
|
pub glyphs: Vec<Glyph>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug, PartialEq)]
|
||||||
|
pub struct FontInfo {
|
||||||
|
pub id: CharacterId,
|
||||||
|
pub name: String,
|
||||||
|
pub is_small_text: bool,
|
||||||
|
pub is_shift_jis: bool,
|
||||||
|
pub is_ansi: bool,
|
||||||
|
pub is_bold: bool,
|
||||||
|
pub is_italic: bool,
|
||||||
|
pub code_table: Vec<u16>,
|
||||||
|
}
|
||||||
|
|
||||||
type Glyph = Vec<ShapeRecord>;
|
type Glyph = Vec<ShapeRecord>;
|
30
src/write.rs
30
src/write.rs
|
@ -508,6 +508,36 @@ impl<W: Write> Writer<W> {
|
||||||
self.output.write_all(&buf)?;
|
self.output.write_all(&buf)?;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
&Tag::DefineFontInfo(ref font_info) => {
|
||||||
|
let use_wide_codes = self.version >= 6;
|
||||||
|
|
||||||
|
let len = font_info.name.len() +
|
||||||
|
if use_wide_codes { 2 } else { 1 } * font_info.code_table.len() +
|
||||||
|
4;
|
||||||
|
|
||||||
|
self.write_tag_header(TagCode::DefineFontInfo, len as u32)?;
|
||||||
|
self.write_u16(font_info.id)?;
|
||||||
|
|
||||||
|
// SWF19 has ANSI and Shift-JIS backwards?
|
||||||
|
self.write_u8(font_info.name.len() as u8)?;
|
||||||
|
self.output.write_all(font_info.name.as_bytes())?;
|
||||||
|
self.write_u8(
|
||||||
|
if font_info.is_small_text { 0b100000 } else { 0 } |
|
||||||
|
if font_info.is_ansi { 0b10000 } else { 0 } |
|
||||||
|
if font_info.is_shift_jis { 0b1000 } else { 0 } |
|
||||||
|
if font_info.is_italic { 0b100 } else { 0 } |
|
||||||
|
if font_info.is_bold { 0b10 } else { 0 } |
|
||||||
|
if use_wide_codes { 0b1 } else { 0 }
|
||||||
|
)?;
|
||||||
|
for &code in &font_info.code_table {
|
||||||
|
if use_wide_codes {
|
||||||
|
self.write_u16(code)?;
|
||||||
|
} else {
|
||||||
|
self.write_u8(code as u8)?;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
&Tag::DefineScalingGrid { id, ref splitter_rect } => {
|
&Tag::DefineScalingGrid { id, ref splitter_rect } => {
|
||||||
let mut buf = Vec::new();
|
let mut buf = Vec::new();
|
||||||
{
|
{
|
||||||
|
|
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue