1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
// SPDX-License-Identifier: ISC
use super::MText;
use crate::point::Point3;
use crate::value::GroupValue;
/// An ATTDEF (block attribute definition) entity.
#[derive(Debug, Clone, Default)]
pub struct AttDef<'a> {
/// Default text value.
pub value: &'a [u8],
/// Embedded MTEXT sub-entity.
pub mtext: Option<MText<'a>>,
/// Prompt string shown when inserting the block.
pub prompt: &'a [u8],
/// Tag name.
pub tag: &'a [u8],
/// Insertion point.
pub location: Point3,
/// Second alignment point.
///
/// Used for all non-default justifications. When `h_justify` or
/// `v_justify` is nonzero, this point (not `location`) determines
/// the text's actual position.
pub second_alignment_point: Point3,
/// Text height.
pub height: f64,
/// Extrusion thickness.
pub thickness: f64,
/// Rotation angle in degrees.
pub rotation: f64,
/// Text style name.
pub style_name: &'a [u8],
/// Horizontal text justification.
///
/// | Value | Meaning |
/// |------:|---------|
/// | 0 | Left |
/// | 1 | Center |
/// | 2 | Right |
/// | 3 | Aligned |
/// | 4 | Middle |
/// | 5 | Fit |
pub h_justify: i16,
/// Vertical text justification.
///
/// | Value | Meaning |
/// |------:|----------|
/// | 0 | Baseline |
/// | 1 | Bottom |
/// | 2 | Middle |
/// | 3 | Top |
pub v_justify: i16,
/// Relative X scale 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,
/// Attribute definition flags.
///
/// `0b1` = invisible, `0b10` = constant.
pub flags: i16,
/// Whether we're inside the embedded AcDbMText subclass.
in_mtext: bool,
}
impl<'a> AttDef<'a> {
pub(crate) fn feed(&mut self, code: u16, val: &GroupValue<'a>) {
if code == 100 {
if let Some(s) = val.as_str_bytes()
&& s == b"AcDbMText"
{
self.in_mtext = true;
self.mtext = Some(MText::default());
}
return;
}
if self.in_mtext {
if let Some(ref mut mt) = self.mtext {
mt.feed(code, val);
}
return;
}
match code {
1 => {
if let Some(s) = val.as_str_bytes() {
self.value = s;
}
}
2 => {
if let Some(s) = val.as_str_bytes() {
self.tag = s;
}
}
3 => {
if let Some(s) = val.as_str_bytes() {
self.prompt = s;
}
}
7 => {
if let Some(s) = val.as_str_bytes() {
self.style_name = s;
}
}
70 => {
if let Some(v) = val.as_i16() {
self.flags = v;
}
}
71 => {
if let Some(v) = val.as_i16() {
self.text_generation_flags = v;
}
}
72 => {
if let Some(v) = val.as_i16() {
self.h_justify = v;
}
}
74 => {
if let Some(v) = val.as_i16() {
self.v_justify = v;
}
}
_ => {
if let Some(v) = val.as_f64() {
match code {
10 => self.location.x = v,
20 => self.location.y = v,
30 => self.location.z = v,
11 => self.second_alignment_point.x = v,
21 => self.second_alignment_point.y = v,
31 => self.second_alignment_point.z = v,
39 => self.thickness = v,
40 => self.height = v,
41 => self.width_factor = v,
50 => self.rotation = v,
51 => self.oblique_angle = v,
_ => {}
}
}
}
}
}
}