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
// SPDX-License-Identifier: ISC
use crate::point::Point3;
use crate::value::GroupValue;
/// A TEXT (single-line text) entity.
#[derive(Debug, Clone, Copy)]
pub struct Text<'a> {
/// Text string.
pub value: &'a [u8],
/// Insertion point.
pub insertion_point: Point3,
/// Text height.
pub height: f64,
/// Rotation angle in degrees.
pub rotation: f64,
/// Relative X scale factor.
///
/// Defaults to 1.0.
pub width_factor: f64,
/// Text style name.
pub style_name: &'a [u8],
/// Second alignment point.
///
/// Used for all non-default justifications. When `h_justify` or
/// `v_justify` is nonzero, this point (not `insertion_point`)
/// determines the text's actual position.
pub second_alignment_point: Point3,
/// 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,
/// Oblique angle in degrees.
pub oblique_angle: f64,
/// Extrusion thickness.
pub thickness: f64,
/// Text generation flags.
///
/// `0b10` = backward (mirrored in X),
/// `0b100` = upside down (mirrored in Y).
pub text_generation_flags: i16,
}
impl<'a> Default for Text<'a> {
fn default() -> Self {
Self {
value: b"",
insertion_point: Point3::default(),
height: 0.0,
rotation: 0.0,
width_factor: 1.0,
style_name: b"",
second_alignment_point: Point3::default(),
h_justify: 0,
v_justify: 0,
oblique_angle: 0.0,
thickness: 0.0,
text_generation_flags: 0,
}
}
}
impl<'a> Text<'a> {
pub(crate) fn feed(&mut self, code: u16, val: &GroupValue<'a>) {
match code {
1 => {
if let Some(s) = val.as_str_bytes() {
self.value = s;
}
}
7 => {
if let Some(s) = val.as_str_bytes() {
self.style_name = s;
}
}
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;
}
}
73 => {
if let Some(v) = val.as_i16() {
self.v_justify = 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.second_alignment_point.x = v,
21 => self.second_alignment_point.y = v,
31 => self.second_alignment_point.z = v,
40 => self.height = v,
41 => self.width_factor = v,
39 => self.thickness = v,
50 => self.rotation = v,
51 => self.oblique_angle = v,
_ => {}
}
}
}
}
}
}