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
172
173
174
175
176
use serde::{Deserialize, Serialize};
use crate::ids::{DrawParamId, FontId, ImageId, ObjectId};
use crate::primitives::{Color, Ctm, PathData, Rect};
/// Shape kind for Shape annotations and composite primitives.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
pub enum ShapeKind {
Rect,
Ellipse,
Arrow,
Line,
Polygon,
PolyLine,
}
/// Sticky-note icon variant.
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default, Serialize, Deserialize)]
pub enum NoteIcon {
#[default]
Note,
Comment,
Help,
Key,
}
#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
pub struct TextCode {
pub glyph_ids: Vec<u32>,
/// Per-glyph (dx, dy) deltas. Length == glyph_ids.len() (or text char count when glyph_ids empty).
pub deltas: Vec<(f32, f32)>,
/// The TextCode element's text content (e.g. "Hello"). v1: glyph_ids may be empty;
/// renderers shape this string to obtain glyph IDs.
pub text: String,
/// Absolute pen origin (page-local, mm) for the first glyph, from the
/// TextCode element's `X`/`Y` attributes. Subsequent glyphs advance by
/// `deltas`. Defaults to (0, 0) when absent.
pub x: f64,
pub y: f64,
}
#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
pub struct TextObject {
pub id: ObjectId,
pub boundary: Rect,
pub ctm: Option<Ctm>,
pub font: FontId,
pub size: f64,
pub fill: Option<Color>,
pub codes: Vec<TextCode>,
/// `DrawParam` attribute (GB/T 33190): id of a `DrawParam` in `Resources`
/// supplying fallback fill/stroke/line_width when inline colors are absent.
pub draw_param: Option<DrawParamId>,
/// Object-level clip (GB/T 33190): the object renders clipped to this
/// path (page-local mm). `None` = no clip element (spec 2026-11-12 D14).
#[serde(default)]
pub clip: Option<PathData>,
/// Unmodelled attributes on the element, verbatim (passthrough,
/// spec 2026-11-11 D3).
#[serde(default)]
pub raw_attrs: Vec<(String, String)>,
}
#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
pub struct ImageObject {
pub id: ObjectId,
pub boundary: Rect,
pub ctm: Option<Ctm>,
pub image: ImageId,
/// Object-level clip (GB/T 33190), page-local mm (spec 2026-11-12 D14).
#[serde(default)]
pub clip: Option<PathData>,
/// Unmodelled attributes on the element, verbatim (passthrough).
#[serde(default)]
pub raw_attrs: Vec<(String, String)>,
}
#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
pub struct PathObject {
pub id: ObjectId,
pub boundary: Rect,
pub ctm: Option<Ctm>,
pub fill: Option<Color>,
pub stroke: Option<Color>,
pub line_width: f64,
pub data: PathData,
/// `DrawParam` attribute: fallback fill/stroke/line_width source.
pub draw_param: Option<DrawParamId>,
/// `Stroke` attribute (GB/T 33190 表35): whether the path is stroked.
/// `None` = attribute absent - the spec default is `true` (resolved at
/// render time, not baked in here, so the model stays faithful to the file).
pub stroke_enabled: Option<bool>,
/// `Fill` attribute (GB/T 33190 表35): whether the path is filled.
/// `None` = attribute absent - the spec default is `false`.
pub fill_enabled: Option<bool>,
/// Object-level clip (GB/T 33190), page-local mm (spec 2026-11-12 D14).
#[serde(default)]
pub clip: Option<PathData>,
/// Unmodelled attributes on the element, verbatim (passthrough).
#[serde(default)]
pub raw_attrs: Vec<(String, String)>,
}
#[derive(Debug, Clone, PartialEq, Default, Serialize, Deserialize)]
pub struct CompositeObject {
pub id: ObjectId,
pub boundary: Rect,
pub ctm: Option<Ctm>,
/// Reference to a reusable composite unit (v1: unresolved, stored as-is).
pub unit: String,
/// Unmodelled attributes on the element, verbatim (passthrough).
#[serde(default)]
pub raw_attrs: Vec<(String, String)>,
}
#[derive(Debug, Clone, PartialEq, Serialize, Deserialize)]
pub enum PageObject {
Text(TextObject),
Image(ImageObject),
Path(PathObject),
Composite(CompositeObject),
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn text_object_default_and_clone() {
let t = TextObject {
id: ObjectId::new("t1"),
boundary: Rect::default(),
ctm: None,
font: FontId::new("F1"),
size: 12.0,
fill: None,
codes: vec![],
draw_param: None,
clip: None,
raw_attrs: Vec::new(),
};
let _clone = t.clone();
assert_eq!(t.size, 12.0);
}
#[test]
fn page_object_enum_variants() {
let p = PageObject::Path(PathObject {
id: ObjectId::new("p1"),
boundary: Rect::default(),
ctm: None,
fill: None,
stroke: Some(Color::Rgb(0, 0, 0)),
line_width: 1.0,
data: PathData::default(),
draw_param: None,
stroke_enabled: None,
fill_enabled: None,
clip: None,
raw_attrs: Vec::new(),
});
assert!(matches!(p, PageObject::Path(_)));
}
#[test]
fn textcode_carries_text() {
let tc = TextCode {
glyph_ids: vec![],
deltas: vec![],
text: "Hello".into(),
x: 0.0,
y: 0.0,
};
assert_eq!(tc.text, "Hello");
}
}