docx_rust/document/
drawing.rs

1#![allow(unused_must_use)]
2
3use std::borrow::Cow;
4
5use derive_more::From;
6use hard_xml::{XmlRead, XmlWrite};
7
8use crate::{__define_enum, __string_enum};
9
10#[derive(Debug, Default, XmlRead, XmlWrite, Clone)]
11#[cfg_attr(test, derive(PartialEq))]
12#[xml(tag = "w:drawing")]
13pub struct Drawing<'a> {
14    /// comment
15    #[xml(child = "wp:anchor")]
16    pub anchor: Option<Anchor<'a>>,
17    #[xml(child = "wp:inline")]
18    pub inline: Option<Inline<'a>>,
19}
20
21#[derive(Debug, Default, XmlRead, XmlWrite, Clone)]
22#[cfg_attr(test, derive(PartialEq))]
23#[xml(tag = "wp:anchor")]
24pub struct Anchor<'a> {
25    #[xml(attr = "distT")]
26    pub dist_t: Option<isize>,
27    #[xml(attr = "distB")]
28    pub dist_b: Option<isize>,
29    #[xml(attr = "distL")]
30    pub dist_l: Option<isize>,
31    #[xml(attr = "distR")]
32    pub dist_r: Option<isize>,
33    #[xml(attr = "simplePos")]
34    pub simple_pos_attr: Option<isize>,
35    #[xml(attr = "relativeHeight")]
36    pub relative_height: Option<isize>,
37    #[xml(attr = "behindDoc")]
38    pub behind_doc: Option<bool>,
39    #[xml(attr = "locked")]
40    pub locked: Option<bool>,
41    #[xml(attr = "layoutInCell")]
42    pub layout_in_cell: Option<bool>,
43    #[xml(attr = "allowOverlap")]
44    pub allow_overlap: Option<bool>,
45
46    #[xml(child = "wp:simplePos")]
47    pub simple_pos: Option<SimplePos>,
48    #[xml(child = "wp:positionH")]
49    pub position_horizontal: Option<PositionHorizontal>,
50    #[xml(child = "wp:positionV")]
51    pub position_vertical: Option<PositionVertical>,
52    #[xml(child = "wp:extent")]
53    pub extent: Option<Extent>,
54    #[xml(
55        child = "wp:wrapNone",
56        child = "wp:wrapSquare",
57        child = "wp:wrapTight",
58        child = "wp:wrapThrough",
59        child = "wp:wrapTopAndBottom"
60    )]
61    pub wrap: Option<Wrap>,
62    #[xml(child = "wp:docPr")]
63    pub doc_property: DocPr<'a>,
64    #[xml(child = "a:graphic")]
65    pub graphic: Option<Graphic<'a>>,
66}
67
68#[derive(Debug, From, XmlRead, XmlWrite, Clone)]
69#[cfg_attr(test, derive(PartialEq))]
70pub enum Wrap {
71    #[xml(tag = "wp:wrapNone")]
72    None(WrapNone),
73    #[xml(tag = "wp:wrapSquare")]
74    Square(WrapSquare),
75    #[xml(tag = "wp:wrapTight")]
76    Tight(WrapTight),
77    #[xml(tag = "wp:wrapThrough")]
78    Through(WrapThrough),
79    #[xml(tag = "wp:wrapTopAndBottom")]
80    TopAndBottom(WrapTopAndBottom),
81}
82
83#[derive(Debug, Default, XmlRead, XmlWrite, Clone)]
84#[cfg_attr(test, derive(PartialEq))]
85#[xml(tag = "wp:wrapNone")]
86pub struct WrapNone {}
87
88#[derive(Debug, Default, XmlRead, XmlWrite, Clone)]
89#[cfg_attr(test, derive(PartialEq))]
90#[xml(tag = "wp:wrapSquare")]
91pub struct WrapSquare {}
92
93#[derive(Debug, Default, XmlRead, XmlWrite, Clone)]
94#[cfg_attr(test, derive(PartialEq))]
95#[xml(tag = "wp:wrapTight")]
96pub struct WrapTight {
97    #[xml(attr = "wrapText")]
98    pub wrap_text: WrapTextType,
99    #[xml(child = "wp:wrapPolygon")]
100    pub wrap_polygon: WrapPolygon,
101}
102
103#[derive(Debug, Default, XmlRead, XmlWrite, Clone)]
104#[cfg_attr(test, derive(PartialEq))]
105#[xml(tag = "wp:wrapPolygon")]
106pub struct WrapPolygon {
107    #[xml(attr = "edited")]
108    pub edited: Option<bool>,
109    #[xml(child = "wp:start")]
110    pub start: WrapPolygonStart,
111    #[xml(child = "wp:lineTo")]
112    pub lineto: Vec<WrapPolygonLineTo>,
113}
114
115#[derive(Debug, Default, XmlRead, XmlWrite, Clone)]
116#[cfg_attr(test, derive(PartialEq))]
117#[xml(tag = "wp:start")]
118pub struct WrapPolygonStart {
119    #[xml(attr = "x")]
120    pub x: Option<isize>,
121    #[xml(attr = "y")]
122    pub y: Option<isize>,
123}
124
125#[derive(Debug, Default, XmlRead, XmlWrite, Clone)]
126#[cfg_attr(test, derive(PartialEq))]
127#[xml(tag = "wp:lineTo")]
128pub struct WrapPolygonLineTo {
129    #[xml(attr = "x")]
130    pub x: Option<isize>,
131    #[xml(attr = "y")]
132    pub y: Option<isize>,
133}
134
135#[derive(Debug, Clone, Default)]
136#[cfg_attr(test, derive(PartialEq))]
137pub enum WrapTextType {
138    #[default]
139    Both,
140}
141
142__string_enum! {
143    WrapTextType {
144    Both = "bothSides",
145}}
146
147#[derive(Debug, Default, XmlRead, XmlWrite, Clone)]
148#[cfg_attr(test, derive(PartialEq))]
149#[xml(tag = "wp:wrapThrough")]
150pub struct WrapThrough {}
151
152#[derive(Debug, Default, XmlRead, XmlWrite, Clone)]
153#[cfg_attr(test, derive(PartialEq))]
154#[xml(tag = "wp:wrapTopAndBottom")]
155pub struct WrapTopAndBottom {}
156
157#[derive(Debug, Default, XmlRead, XmlWrite, Clone)]
158#[cfg_attr(test, derive(PartialEq))]
159#[xml(tag = "wp:positionH")]
160pub struct PositionHorizontal {
161    #[xml(attr = "relativeFrom")]
162    pub relative_from: Option<RelativeFromH>,
163    #[xml(flatten_text = "wp:posOffset")]
164    pub pos_offset: Option<isize>,
165}
166
167#[derive(Debug, Default, XmlRead, XmlWrite, Clone)]
168#[cfg_attr(test, derive(PartialEq))]
169#[xml(tag = "wp:positionV")]
170pub struct PositionVertical {
171    #[xml(attr = "relativeFrom")]
172    pub relative_from: Option<RelativeFromV>,
173    #[xml(flatten_text = "wp:posOffset")]
174    pub pos_offset: Option<isize>,
175}
176
177__define_enum! {
178    RelativeFromH {
179        Margin= "margin",	//Page Margin
180        Page = "page",//	Page Edge
181        Column= "column",//	Column
182        Character= "character",//	Character
183        LeftMargin= "leftMargin",//	Left Margin
184        RightMargin= "rightMargin",//	Right Margin
185        InsideMargin= "insideMargin",//	Inside Margin
186        OUtsideMargin= "outsideMargin",//	Outside Margin
187    }
188}
189
190__define_enum! {
191    RelativeFromV {
192        Margin= "margin",	//Page Margin
193        Page = "page",//	Page Edge
194        Paragraph= "paragraph",//	Paragraph
195        Line= "line",//	Line
196        TopMargin= "topMargin",//	Left Margin
197        BottomMargin= "bottomMargin",//	Right Margin
198        InsideMargin= "insideMargin",//	Inside Margin
199        OUtsideMargin= "outsideMargin",//	Outside Margin
200    }
201}
202
203#[derive(Debug, Default, XmlRead, XmlWrite, Clone)]
204#[cfg_attr(test, derive(PartialEq))]
205#[xml(tag = "wp:inline")]
206pub struct Inline<'a> {
207    #[xml(attr = "distT")]
208    pub dist_t: Option<isize>,
209    #[xml(attr = "distB")]
210    pub dist_b: Option<isize>,
211    #[xml(attr = "distL")]
212    pub dist_l: Option<isize>,
213    #[xml(attr = "distR")]
214    pub dist_r: Option<isize>,
215    #[xml(attr = "simplePossimplePos")]
216    pub simple_pos_attr: Option<isize>,
217    #[xml(attr = "relativeHeight")]
218    pub relative_height: Option<isize>,
219    #[xml(attr = "behindDoc")]
220    pub behind_doc: Option<bool>,
221    #[xml(attr = "locked")]
222    pub locked: Option<bool>,
223    #[xml(attr = "layoutInCell")]
224    pub layout_in_cell: Option<bool>,
225    #[xml(attr = "allowOverlap")]
226    pub allow_overlap: Option<bool>,
227
228    #[xml(child = "wp:simplePos")]
229    pub simple_pos: Option<SimplePos>,
230    #[xml(child = "wp:positionH")]
231    pub position_horizontal: Option<PositionHorizontal>,
232    #[xml(child = "wp:positionV")]
233    pub position_vertical: Option<PositionVertical>,
234    #[xml(child = "wp:extent")]
235    pub extent: Option<Extent>,
236    #[xml(child = "wp:docPr")]
237    pub doc_property: DocPr<'a>,
238    #[xml(child = "a:graphic")]
239    pub graphic: Option<Graphic<'a>>,
240}
241
242#[derive(Debug, Default, XmlRead, XmlWrite, Clone)]
243#[cfg_attr(test, derive(PartialEq))]
244#[xml(tag = "wp:docPr")]
245pub struct DocPr<'a> {
246    #[xml(attr = "id")]
247    pub id: Option<isize>,
248    #[xml(attr = "name")]
249    pub name: Option<Cow<'a, str>>,
250    #[xml(attr = "descr")]
251    pub descr: Option<Cow<'a, str>>,
252}
253
254#[derive(Debug, Default, XmlRead, XmlWrite, Clone)]
255#[cfg_attr(test, derive(PartialEq))]
256#[xml(tag = "a:graphic")]
257pub struct Graphic<'a> {
258    #[xml(default, attr = "xmlns:a")]
259    pub a: Cow<'a, str>,
260    #[xml(default, child = "a:graphicData")]
261    pub data: GraphicData<'a>,
262}
263
264#[derive(Debug, Default, XmlRead, XmlWrite, Clone)]
265#[cfg_attr(test, derive(PartialEq))]
266#[xml(tag = "a:graphicData")]
267pub struct GraphicData<'a> {
268    #[xml(default, attr = "uri")]
269    pub uri: Cow<'a, str>,
270    // graphic data can have any element in any namespace as a child
271    #[xml(child = "pic:pic")]
272    pub children: Vec<Picture<'a>>,
273}
274
275#[derive(Debug, Default, XmlRead, XmlWrite, Clone)]
276#[cfg_attr(test, derive(PartialEq))]
277#[xml(tag = "pic:pic")]
278pub struct Picture<'a> {
279    #[xml(default, attr = "xmlns:pic")]
280    pub a: Cow<'a, str>,
281    #[xml(child = "pic:nvPicPr")]
282    pub nv_pic_pr: NvPicPr<'a>,
283    #[xml(child = "pic:blipFill")]
284    pub fill: BlipFill<'a>,
285    #[xml(child = "pic:spPr")]
286    pub sp_pr: SpPr<'a>,
287}
288
289#[derive(Debug, Default, XmlRead, XmlWrite, Clone)]
290#[cfg_attr(test, derive(PartialEq))]
291#[xml(tag = "pic:spPr")]
292pub struct SpPr<'a> {
293    #[xml(child = "a:xfrm")]
294    pub xfrm: Option<Xfrm>,
295    #[xml(child = "a:prstGeom")]
296    pub prst_geom: Option<PrstGeom<'a>>,
297}
298
299#[derive(Debug, Default, XmlRead, XmlWrite, Clone)]
300#[cfg_attr(test, derive(PartialEq))]
301#[xml(tag = "a:prstGeom")]
302pub struct PrstGeom<'a> {
303    #[xml(attr = "prst")]
304    pub prst: Option<Cow<'a, str>>,
305    #[xml(child = "a:avLst")]
306    pub av_lst: Option<AvList>,
307}
308
309#[derive(Debug, Default, XmlRead, XmlWrite, Clone)]
310#[cfg_attr(test, derive(PartialEq))]
311#[xml(tag = "a:avLst")]
312pub struct AvList {}
313
314#[derive(Debug, Default, XmlRead, XmlWrite, Clone)]
315#[cfg_attr(test, derive(PartialEq))]
316#[xml(tag = "a:xfrm")]
317pub struct Xfrm {
318    #[xml(child = "a:off")]
319    pub offset: Option<Offset>,
320    #[xml(child = "a:ext")]
321    pub ext: Option<Ext>,
322}
323
324#[derive(Debug, Default, XmlRead, XmlWrite, Clone)]
325#[cfg_attr(test, derive(PartialEq))]
326#[xml(tag = "a:ext")]
327pub struct Ext {
328    #[xml(attr = "cx")]
329    pub cx: Option<isize>,
330    #[xml(attr = "cy")]
331    pub cy: Option<isize>,
332}
333
334#[derive(Debug, Default, XmlRead, XmlWrite, Clone)]
335#[cfg_attr(test, derive(PartialEq))]
336#[xml(tag = "a:off")]
337pub struct Offset {
338    #[xml(attr = "x")]
339    pub x: Option<isize>,
340    #[xml(attr = "y")]
341    pub y: Option<isize>,
342}
343
344#[derive(Debug, Default, XmlRead, XmlWrite, Clone)]
345#[cfg_attr(test, derive(PartialEq))]
346#[xml(tag = "wp:simplePos")]
347pub struct SimplePos {
348    #[xml(attr = "x")]
349    pub x: Option<isize>,
350    #[xml(attr = "y")]
351    pub y: Option<isize>,
352}
353
354#[derive(Debug, Default, XmlRead, XmlWrite, Clone)]
355#[cfg_attr(test, derive(PartialEq))]
356#[xml(tag = "pic:nvPicPr")]
357pub struct NvPicPr<'a> {
358    #[xml(child = "pic:cNvPr")]
359    pub c_nv_pr: Option<CNvPr<'a>>,
360    #[xml(child = "pic:cNvPicPr")]
361    pub c_nv_pic_pr: Option<CNvPicPr>,
362}
363
364#[derive(Debug, Default, XmlRead, XmlWrite, Clone)]
365#[cfg_attr(test, derive(PartialEq))]
366#[xml(tag = "pic:cNvPr")]
367pub struct CNvPr<'a> {
368    #[xml(attr = "id")]
369    pub id: Option<isize>,
370    #[xml(attr = "name")]
371    pub name: Option<Cow<'a, str>>,
372    #[xml(attr = "descr")]
373    pub descr: Option<Cow<'a, str>>,
374}
375
376#[derive(Debug, Default, XmlRead, XmlWrite, Clone)]
377#[cfg_attr(test, derive(PartialEq))]
378#[xml(tag = "pic:cNvPicPr")]
379pub struct CNvPicPr {}
380
381#[derive(Debug, Default, XmlRead, XmlWrite, Clone)]
382#[cfg_attr(test, derive(PartialEq))]
383#[xml(tag = "pic:blipFill")]
384pub struct BlipFill<'a> {
385    #[xml(default, child = "a:blip")]
386    pub blip: Blip<'a>,
387    #[xml(child = "a:stretch")]
388    pub stretch: Option<Stretch>,
389}
390
391#[derive(Debug, Default, XmlRead, XmlWrite, Clone)]
392#[cfg_attr(test, derive(PartialEq))]
393#[xml(tag = "a:blip")]
394pub struct Blip<'a> {
395    #[xml(default, attr = "r:embed")]
396    pub embed: Cow<'a, str>,
397    #[xml(default, attr = "cstate")]
398    pub cstate: Option<Cow<'a, str>>,
399}
400
401#[derive(Debug, Default, XmlRead, XmlWrite, Clone)]
402#[cfg_attr(test, derive(PartialEq))]
403#[xml(tag = "a:stretch")]
404pub struct Stretch {
405    #[xml(child = "a:fillRect")]
406    pub fill_rect: Option<FillRect>,
407}
408
409#[derive(Debug, Default, XmlRead, XmlWrite, Clone)]
410#[cfg_attr(test, derive(PartialEq))]
411#[xml(tag = "a:fillRect")]
412pub struct FillRect {}
413
414#[derive(Debug, Default, XmlRead, XmlWrite, Clone)]
415#[cfg_attr(test, derive(PartialEq))]
416#[xml(tag = "wp:extent")]
417pub struct Extent {
418    #[xml(default, attr = "cx")]
419    pub cx: u64,
420
421    #[xml(default, attr = "cy")]
422    pub cy: u64,
423}