dxfscan 0.1.0

Binary DXF parser with typed entity data and lookup indices
Documentation
// SPDX-License-Identifier: ISC
use crate::value::GroupValue;

/// A parsed STYLE table entry.
#[derive(Debug, Clone, Copy)]
pub struct Style<'a> {
    /// Style name.
    pub name: &'a [u8],
    /// Style flags.
    ///
    /// `0b1` = shape file (not a text style),
    /// `0b100` = vertically oriented text.
    pub flags: i16,
    /// Text height.
    ///
    /// Zero means the height is variable (set per entity).
    pub height: f64,
    /// Width factor.
    ///
    /// Defaults to 1.0.
    pub width_factor: f64,
    /// Oblique angle in degrees.
    pub oblique_angle: f64,
    /// Text generation flags.
    ///
    /// `0b10` = backward (mirrored in X),
    /// `0b100` = upside down (mirrored in Y).
    pub text_generation_flags: i16,
    /// Primary font file name.
    pub primary_font_file: &'a [u8],
    /// Big font file name.
    ///
    /// Used for CJK and other extended character sets.
    pub big_font_file: &'a [u8],
}

impl<'a> Default for Style<'a> {
    fn default() -> Self {
        Self {
            name: b"",
            flags: 0,
            height: 0.0,
            width_factor: 1.0,
            oblique_angle: 0.0,
            text_generation_flags: 0,
            primary_font_file: b"",
            big_font_file: b"",
        }
    }
}

impl<'a> Style<'a> {
    pub(crate) fn feed(&mut self, code: u16, val: &GroupValue<'a>) {
        match code {
            2 => {
                if let Some(v) = val.as_str_bytes() {
                    self.name = v;
                }
            }
            3 => {
                if let Some(v) = val.as_str_bytes() {
                    self.primary_font_file = v;
                }
            }
            4 => {
                if let Some(v) = val.as_str_bytes() {
                    self.big_font_file = v;
                }
            }
            70 => {
                if let Some(v) = val.as_i16() {
                    self.flags = v;
                }
            }
            71 => {
                if let Some(v) = val.as_i16() {
                    self.text_generation_flags = v;
                }
            }
            _ => {
                if let Some(v) = val.as_f64() {
                    match code {
                        40 => self.height = v,
                        41 => self.width_factor = v,
                        50 => self.oblique_angle = v,
                        _ => {}
                    }
                }
            }
        }
    }
}