Skip to main content

rhwp/wmf/parser/records/state/
scale_window_ext.rs

1/// The META_SCALEWINDOWEXT Record scales the horizontal and vertical extents of
2/// the output window that is defined in the playback device context by using
3/// the ratios formed by specified multiplicands and divisors.
4#[derive(Clone, Debug)]
5pub struct META_SCALEWINDOWEXT {
6    /// RecordSize (4 bytes): A 32-bit unsigned integer that defines the number
7    /// of WORD structures, defined in [MS-DTYP] section 2.2.61, in the WMF
8    /// record.
9    pub record_size: crate::wmf::parser::RecordSize,
10    /// RecordFunction (2 bytes): A 16-bit unsigned integer that defines this
11    /// WMF record type. The lower byte MUST match the lower byte of the
12    /// RecordType Enumeration table value META_SCALEWINDOWEXT.
13    pub record_function: u16,
14    /// yDenom (2 bytes): A 16-bit signed integer that defines the amount by
15    /// which to divide the result of multiplying the current y-extent by the
16    /// value of the yNum member.
17    pub y_denom: i16,
18    /// yNum (2 bytes): A 16-bit signed integer that defines the amount by
19    /// which to multiply the current y-extent.
20    pub y_num: i16,
21    /// xDenom (2 bytes): A 16-bit signed integer that defines the amount by
22    /// which to divide the result of multiplying the current x-extent by the
23    /// value of the xNum member.
24    pub x_denom: i16,
25    /// xNum (2 bytes): A 16-bit signed integer that defines the amount by
26    /// which to multiply the current x-extent.
27    pub x_num: i16,
28}
29
30impl META_SCALEWINDOWEXT {
31    #[cfg_attr(feature = "tracing", tracing::instrument(
32        level = tracing::Level::TRACE,
33        skip_all,
34        fields(
35            %record_size,
36            record_function = %format!("{record_function:#06X}"),
37        ),
38        err(level = tracing::Level::ERROR, Display),
39    ))]
40    pub fn parse<R: crate::wmf::Read>(
41        buf: &mut R,
42        mut record_size: crate::wmf::parser::RecordSize,
43        record_function: u16,
44    ) -> Result<Self, crate::wmf::parser::ParseError> {
45        crate::wmf::parser::records::check_lower_byte_matches(
46            record_function,
47            crate::wmf::parser::RecordType::META_SCALEWINDOWEXT,
48        )?;
49
50        let (
51            (y_denom, y_denom_bytes),
52            (y_num, y_num_bytes),
53            (x_denom, x_denom_bytes),
54            (x_num, x_num_bytes),
55        ) = (
56            crate::wmf::parser::read_i16_from_le_bytes(buf)?,
57            crate::wmf::parser::read_i16_from_le_bytes(buf)?,
58            crate::wmf::parser::read_i16_from_le_bytes(buf)?,
59            crate::wmf::parser::read_i16_from_le_bytes(buf)?,
60        );
61        record_size.consume(y_denom_bytes + y_num_bytes + x_denom_bytes + x_num_bytes);
62
63        crate::wmf::parser::records::consume_remaining_bytes(buf, record_size)?;
64
65        Ok(Self {
66            record_size,
67            record_function,
68            y_denom,
69            y_num,
70            x_denom,
71            x_num,
72        })
73    }
74}