rhwp/wmf/parser/records/drawing/
poly_line.rs1use crate::wmf::imports::*;
2
3#[derive(Clone, Debug)]
6pub struct META_POLYLINE {
7 pub record_size: crate::wmf::parser::RecordSize,
11 pub record_function: u16,
15 pub number_of_points: i16,
18 pub a_points: Vec<crate::wmf::parser::PointS>,
21}
22
23impl META_POLYLINE {
24 #[cfg_attr(feature = "tracing", tracing::instrument(
25 level = tracing::Level::TRACE,
26 skip_all,
27 fields(
28 %record_size,
29 record_function = %format!("{record_function:#06X}"),
30 ),
31 err(level = tracing::Level::ERROR, Display),
32 ))]
33 pub fn parse<R: crate::wmf::Read>(
34 buf: &mut R,
35 mut record_size: crate::wmf::parser::RecordSize,
36 record_function: u16,
37 ) -> Result<Self, crate::wmf::parser::ParseError> {
38 crate::wmf::parser::records::check_lower_byte_matches(
39 record_function,
40 crate::wmf::parser::RecordType::META_POLYLINE,
41 )?;
42
43 let (number_of_points, number_of_points_bytes) =
44 crate::wmf::parser::read_i16_from_le_bytes(buf)?;
45 record_size.consume(number_of_points_bytes);
46
47 if number_of_points < 0 {
52 return Err(crate::wmf::parser::ParseError::UnexpectedPattern {
53 cause: format!(
54 "The number_of_points field `{number_of_points}` must not be negative"
55 ),
56 });
57 }
58 let mut a_points = Vec::with_capacity(number_of_points as usize);
59
60 for _ in 0..number_of_points {
61 let (v, c) = crate::wmf::parser::PointS::parse(buf)?;
62
63 record_size.consume(c);
64 a_points.push(v);
65 }
66
67 crate::wmf::parser::records::consume_remaining_bytes(buf, record_size)?;
68
69 Ok(Self {
70 record_size,
71 record_function,
72 number_of_points,
73 a_points,
74 })
75 }
76}