Skip to main content

ifc_style/
text_style.rs

1//! Text presentation style projections.
2
3use ifc_model::{EntityId, Value};
4
5use crate::error::StyleResult;
6use crate::view::Record;
7
8/// Borrowed projection of `IfcTextStyle`.
9#[derive(Debug, Clone, Copy)]
10pub struct TextStyle<'m, 's> {
11    record: Record<'m, 's>,
12}
13
14impl<'m, 's> TextStyle<'m, 's> {
15    pub(crate) fn from_record(record: Record<'m, 's>) -> Self {
16        Self { record }
17    }
18
19    /// The entity id of this `IfcTextStyle`.
20    pub fn id(&self) -> EntityId {
21        self.record.id
22    }
23
24    /// The `Name` attribute, when authored.
25    pub fn name(&self) -> StyleResult<Option<&'m str>> {
26        self.record.optional_text("Name")
27    }
28
29    /// The `TextCharacterAppearance` attribute, when authored.
30    pub fn text_character_appearance(&self) -> StyleResult<Option<EntityId>> {
31        self.record
32            .optional_ref("TextCharacterAppearance", "IfcTextStyleForDefinedFont")
33    }
34
35    /// The `TextStyle` attribute (`IfcTextStyleSelect`: model or box-characteristics text
36    /// style), when authored.
37    pub fn text_style(&self) -> StyleResult<Option<EntityId>> {
38        self.record.optional_ref_select(
39            "TextStyle",
40            "IfcTextStyleSelect",
41            &[
42                "IfcTextStyleTextModel",
43                "IfcTextStyleWithBoxCharacteristics",
44            ],
45        )
46    }
47
48    /// The `TextFontStyle` attribute (`IfcTextFontSelect`: externally defined
49    /// or predefined text font). Mandatory.
50    pub fn text_font_style(&self) -> StyleResult<EntityId> {
51        self.record.required_ref_select(
52            "TextFontStyle",
53            "IfcTextFontSelect",
54            &["IfcExternallyDefinedTextFont", "IfcPreDefinedTextFont"],
55        )
56    }
57
58    /// The `ModelOrDraughting` flag: `true` for model-space geometry,
59    /// `false` for a draughting/annotation text style, `None` if unauthored.
60    pub fn model_or_draughting(&self) -> StyleResult<Option<bool>> {
61        self.record.optional_bool("ModelOrDraughting")
62    }
63}
64
65/// Borrowed projection of `IfcTextStyleFontModel`.
66#[derive(Debug, Clone, Copy)]
67pub struct TextStyleFontModel<'m, 's> {
68    record: Record<'m, 's>,
69}
70
71impl<'m, 's> TextStyleFontModel<'m, 's> {
72    pub(crate) fn from_record(record: Record<'m, 's>) -> Self {
73        Self { record }
74    }
75
76    /// The `Name` attribute. Mandatory.
77    pub fn name(&self) -> StyleResult<&'m str> {
78        self.record.required_text("Name")
79    }
80
81    /// The `FontFamily` attribute (a list of candidate family names), when authored.
82    pub fn font_family(&self) -> StyleResult<Option<&'m Value>> {
83        self.record.optional_raw("FontFamily")
84    }
85
86    /// The `FontStyle` attribute (e.g. normal/italic/oblique), when authored.
87    pub fn font_style(&self) -> StyleResult<Option<&'m Value>> {
88        self.record.optional_raw("FontStyle")
89    }
90
91    /// The `FontVariant` attribute (e.g. normal/small-caps), when authored.
92    pub fn font_variant(&self) -> StyleResult<Option<&'m Value>> {
93        self.record.optional_raw("FontVariant")
94    }
95
96    /// The `FontWeight` attribute, when authored.
97    pub fn font_weight(&self) -> StyleResult<Option<&'m Value>> {
98        self.record.optional_raw("FontWeight")
99    }
100
101    /// The `FontSize` attribute (an `IfcSizeSelect`). Mandatory.
102    pub fn font_size(&self) -> StyleResult<&'m Value> {
103        self.record.value("FontSize")
104    }
105}