swf: Number enum FontThickness

This commit is contained in:
relrelb 2021-06-06 00:00:20 +03:00 committed by Mike Welsh
parent 88b6632188
commit a45fdba4d1
3 changed files with 17 additions and 15 deletions

View File

@ -1164,12 +1164,8 @@ impl<'a> Reader<'a> {
fn read_define_font_align_zones(&mut self) -> Result<Tag<'a>> {
let id = self.read_character_id()?;
let thickness = match self.read_u8()? {
0b00_000000 => FontThickness::Thin,
0b01_000000 => FontThickness::Medium,
0b10_000000 => FontThickness::Thick,
_ => return Err(Error::invalid_data("Invalid font thickness type.")),
};
let thickness = FontThickness::from_u8(self.read_u8()? >> 6)
.ok_or_else(|| Error::invalid_data("Invalid font thickness type."))?;
let mut zones = vec![];
while let Ok(zone) = self.read_font_align_zone() {
zones.push(zone);

View File

@ -1398,11 +1398,21 @@ pub struct FontAlignZone {
pub height: i16,
}
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[derive(Clone, Copy, Debug, PartialEq, Eq, FromPrimitive, ToPrimitive)]
pub enum FontThickness {
Thin,
Medium,
Thick,
Thin = 0,
Medium = 1,
Thick = 2,
}
impl FontThickness {
pub fn from_u8(n: u8) -> Option<Self> {
num_traits::FromPrimitive::from_u8(n)
}
pub fn to_u8(self) -> u8 {
num_traits::ToPrimitive::to_u8(&self).unwrap()
}
}
#[derive(Clone, Debug, PartialEq)]

View File

@ -685,11 +685,7 @@ impl<W: Write> Writer<W> {
} => {
self.write_tag_header(TagCode::DefineFontAlignZones, 3 + 10 * zones.len() as u32)?;
self.write_character_id(id)?;
self.write_u8(match thickness {
FontThickness::Thin => 0b00_000000,
FontThickness::Medium => 0b01_000000,
FontThickness::Thick => 0b10_000000,
})?;
self.write_u8(thickness.to_u8() << 6)?;
for zone in zones {
self.write_u8(2)?; // Always 2 dimensions.
self.write_i16(zone.left)?;