From 1ff23cdd7780b4c147f2591f185cd3ced7cc99c0 Mon Sep 17 00:00:00 2001 From: Nathan Adams Date: Sat, 28 Oct 2023 00:50:10 +0200 Subject: [PATCH] swf: Fixed writing DefineFontInfo tags with wide chars --- swf/src/write.rs | 31 ++++++++++++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/swf/src/write.rs b/swf/src/write.rs index fdc4c063e4ec..bb5ea4112175 100644 --- a/swf/src/write.rs +++ b/swf/src/write.rs @@ -2165,7 +2165,9 @@ impl Writer { } fn write_define_font_info(&mut self, font_info: &FontInfo) -> Result<()> { - let use_wide_codes = self.version >= 6 || font_info.version >= 2; + let use_wide_codes = self.version >= 6 + || font_info.version >= 2 + || font_info.flags.contains(FontInfoFlag::HAS_WIDE_CODES); let len = font_info.name.len() + if use_wide_codes { 2 } else { 1 } * font_info.code_table.len() @@ -3030,4 +3032,31 @@ mod tests { assert_eq!(reread, Tag::DefineText2(Box::new(text))); } + + #[test] + fn write_define_font_info() { + use crate::read::Reader; + + let font_info = FontInfo { + id: 1, + version: 1, + name: SwfStr::from_bytes(b"Schauer"), + flags: FontInfoFlag::HAS_WIDE_CODES | FontInfoFlag::IS_BOLD, + language: Language::Unknown, + code_table: vec![ + 80, 108, 97, 121, 32, 109, 111, 118, 105, 101, 53, 48, 54, 75, 103, 115, 116, 74, + 65, 67, 83, 86, 71, 84, 89, 76, 69, 42, 104, 46, 73, 100, 87, 107, 110, 102, 117, + 99, 114, 63, 79, 39, 119, 44, 112, 33, 120, 72, 122, 58, 77, 45, 98, 40, 41, 70, + ], + }; + + let mut buf = Vec::new(); + let mut writer = Writer::new(&mut buf, 4); + writer.write_define_font_info(&font_info).unwrap(); + + let mut reader = Reader::new(&buf, 4); + let reread = reader.read_tag().unwrap(); + + assert_eq!(reread, Tag::DefineFontInfo(Box::new(font_info))); + } }