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
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
// SPDX-License-Identifier: ISC
use crate::point::Point3;
use crate::value::GroupValue;
use alloc::vec::Vec;
/// An MTEXT (multi-line text) entity.
///
/// MTEXT supports rich formatting via inline codes in the text string
/// (e.g. `\P` for newline, `\fArial;` for font changes).
#[derive(Debug, Clone, Default)]
pub struct MText<'a> {
/// Text string.
pub text: &'a [u8],
/// Extended text chunks.
///
/// Concatenated with `text` to form the full string.
pub extended_text: Vec<&'a [u8]>,
/// Insertion point.
pub insertion_point: Point3,
/// Initial text height.
pub height: f64,
/// Reference rectangle width.
pub reference_rect_width: f64,
/// Defined annotation height.
pub defined_height: f64,
/// Attachment point.
///
/// | Value | Meaning |
/// |------:|---------------|
/// | 1 | Top-left |
/// | 2 | Top-center |
/// | 3 | Top-right |
/// | 4 | Middle-left |
/// | 5 | Middle-center |
/// | 6 | Middle-right |
/// | 7 | Bottom-left |
/// | 8 | Bottom-center |
/// | 9 | Bottom-right |
pub attachment_point: i16,
/// Drawing direction.
///
/// | Value | Meaning |
/// |------:|----------------|
/// | 1 | Left to right |
/// | 3 | Top to bottom |
/// | 5 | By style |
pub drawing_direction: i16,
/// Rotation angle in radians.
///
/// When the X-axis direction vector is also present, the direction
/// vector takes precedence.
pub rotation_angle: f64,
/// X-axis direction vector.
///
/// Defines the horizontal direction for the text. When present,
/// this takes precedence over `rotation_angle`.
pub x_axis_direction: Point3,
/// Text style name.
pub style_name: &'a [u8],
/// Line spacing style.
///
/// | Value | Meaning |
/// |------:|----------|
/// | 1 | At least |
/// | 2 | Exact |
pub line_spacing_style: i16,
/// Line spacing factor.
///
/// Multiplier applied to the default line spacing. Defaults to 1.0.
pub line_spacing_factor: f64,
/// Background fill box scale factor.
pub fill_box_scale: f64,
/// Column type.
///
/// | Value | Meaning |
/// |------:|---------|
/// | 0 | None |
/// | 1 | Static |
/// | 2 | Dynamic |
pub column_type: i16,
/// Number of columns.
pub column_count: i16,
/// Column width.
pub column_width: f64,
/// Column gutter width.
///
/// The spacing between adjacent columns.
pub column_gutter_width: f64,
/// Column flow reversed flag.
pub column_flow_reversed: i16,
/// Column autoheight flag.
pub column_autoheight: i16,
}
impl<'a> MText<'a> {
pub(crate) fn feed(&mut self, code: u16, val: &GroupValue<'a>) {
match code {
1 => {
if let Some(s) = val.as_str_bytes() {
self.text = s;
}
}
3 => {
if let Some(s) = val.as_str_bytes() {
self.extended_text.push(s);
}
}
7 => {
if let Some(s) = val.as_str_bytes() {
self.style_name = s;
}
}
71 => {
if let Some(v) = val.as_i16() {
self.attachment_point = v;
}
}
72 => {
if let Some(v) = val.as_i16() {
self.drawing_direction = v;
}
}
73 => {
if let Some(v) = val.as_i16() {
self.line_spacing_style = v;
}
}
75 => {
if let Some(v) = val.as_i16() {
self.column_type = v;
}
}
76 => {
if let Some(v) = val.as_i16() {
self.column_count = v;
}
}
78 => {
if let Some(v) = val.as_i16() {
self.column_flow_reversed = v;
}
}
79 => {
if let Some(v) = val.as_i16() {
self.column_autoheight = v;
}
}
_ => {
if let Some(v) = val.as_f64() {
match code {
10 => self.insertion_point.x = v,
20 => self.insertion_point.y = v,
30 => self.insertion_point.z = v,
11 => self.x_axis_direction.x = v,
21 => self.x_axis_direction.y = v,
31 => self.x_axis_direction.z = v,
40 => self.height = v,
41 => self.reference_rect_width = v,
44 => self.line_spacing_factor = v,
45 => self.fill_box_scale = v,
46 => self.defined_height = v,
48 => self.column_width = v,
49 => self.column_gutter_width = v,
50 => self.rotation_angle = v,
_ => {}
}
}
}
}
}
}