Skip to main content

excelize_rs/xml/
decode_drawing.rs

1//! Decode-only drawing part helpers (`xl/drawings/drawingN.xml`).
2//!
3//! Ported from Go `xmlDecodeDrawing.go`.
4
5use serde::{Deserialize, Serialize};
6
7use super::common::XlsxInnerXml;
8
9/// Directly maps the `oneCellAnchor` (One Cell Anchor Shape Size) and
10/// `twoCellAnchor` (Two Cell Anchor Shape Size). This element specifies a two
11/// cell anchor placeholder for a group, a shape, or a drawing element. It moves
12/// with cells and its extents are in EMU units.
13#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)]
14pub struct DecodeCellAnchor {
15    #[serde(rename = "@editAs", default)]
16    pub edit_as: Option<String>,
17    #[serde(rename = "from", default)]
18    pub from: Option<DecodeFrom>,
19    #[serde(rename = "to", default)]
20    pub to: Option<DecodeTo>,
21    #[serde(rename = "ext", default)]
22    pub ext: Option<DecodePositiveSize2D>,
23    #[serde(rename = "sp", default)]
24    pub sp: Option<DecodeSp>,
25    #[serde(rename = "pic", default)]
26    pub pic: Option<DecodePic>,
27    #[serde(rename = "graphicFrame", default)]
28    pub graphic_frame: Option<super::drawing::XlsxGraphicFrame>,
29    #[serde(rename = "clientData", default)]
30    pub client_data: Option<DecodeClientData>,
31    #[serde(rename = "AlternateContent", default)]
32    pub alternate_content: Vec<XlsxAlternateContent>,
33}
34
35/// Defines the structure used to deserialize the cell anchor for adjust drawing
36/// object on inserting/deleting column/rows.
37#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)]
38pub struct DecodeCellAnchorPos {
39    #[serde(rename = "@editAs", default)]
40    pub edit_as: Option<String>,
41    #[serde(rename = "from", default)]
42    pub from: Option<XlsxFrom>,
43    #[serde(rename = "to", default)]
44    pub to: Option<XlsxTo>,
45    #[serde(rename = "pos", default)]
46    pub pos: Option<XlsxInnerXml>,
47    #[serde(rename = "ext", default)]
48    pub ext: Option<XlsxPositiveSize2D>,
49    #[serde(rename = "sp", default)]
50    pub sp: Option<XlsxSp>,
51    #[serde(rename = "grpSp", default)]
52    pub grp_sp: Option<XlsxInnerXml>,
53    #[serde(rename = "graphicFrame", default)]
54    pub graphic_frame: Option<XlsxInnerXml>,
55    #[serde(rename = "cxnSp", default)]
56    pub cxn_sp: Option<XlsxInnerXml>,
57    #[serde(rename = "pic", default)]
58    pub pic: Option<XlsxInnerXml>,
59    #[serde(rename = "contentPart", default)]
60    pub content_part: Option<XlsxInnerXml>,
61    #[serde(rename = "AlternateContent", default)]
62    pub alternate_content: Vec<XlsxAlternateContent>,
63    #[serde(rename = "clientData", default)]
64    pub client_data: Option<XlsxInnerXml>,
65}
66
67/// Defines the structure used to deserialize the `mc:Choice` element.
68#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)]
69#[serde(rename = "Choice")]
70pub struct DecodeChoice {
71    #[serde(rename = "@a14", default)]
72    pub xmlns_a14: Option<String>,
73    #[serde(rename = "@sle15", default)]
74    pub xmlns_sle15: Option<String>,
75    #[serde(rename = "@Requires", default)]
76    pub requires: Option<String>,
77    #[serde(rename = "graphicFrame", default)]
78    pub graphic_frame: DecodeGraphicFrame,
79}
80
81/// Defines the structure used to deserialize the `xdr:graphicFrame` element.
82#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)]
83#[serde(rename = "graphicFrame")]
84pub struct DecodeGraphicFrame {
85    #[serde(rename = "@macro", default)]
86    pub macro_name: String,
87    #[serde(rename = "nvGraphicFramePr", default)]
88    pub nv_graphic_frame_pr: DecodeNvGraphicFramePr,
89}
90
91/// Defines the structure used to deserialize the `xdr:nvGraphicFramePr` element.
92#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)]
93#[serde(rename = "nvGraphicFramePr")]
94pub struct DecodeNvGraphicFramePr {
95    #[serde(rename = "cNvPr", default)]
96    pub c_nv_pr: DecodeCNvPr,
97}
98
99/// Defines the structure used to deserialize the `sp` element.
100#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)]
101#[serde(rename = "sp")]
102pub struct DecodeSp {
103    #[serde(rename = "@macro", default)]
104    pub macro_name: Option<String>,
105    #[serde(rename = "@textlink", default)]
106    pub text_link: Option<String>,
107    #[serde(rename = "@fLocksText", default)]
108    pub f_locks_text: bool,
109    #[serde(rename = "@fPublished", default)]
110    pub f_published: Option<bool>,
111    #[serde(rename = "nvSpPr", default)]
112    pub nv_sp_pr: Option<DecodeNvSpPr>,
113    #[serde(rename = "spPr", default)]
114    pub sp_pr: Option<DecodeSpPr>,
115}
116
117/// Non-Visual Properties for a Shape. This element specifies all non-visual
118/// properties for a shape.
119#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)]
120#[serde(rename = "nvSpPr")]
121pub struct DecodeNvSpPr {
122    #[serde(rename = "cNvPr", default)]
123    pub c_nv_pr: Option<DecodeCNvPr>,
124    #[serde(rename = "extLst", default)]
125    pub ext_lst: Option<DecodePositiveSize2D>,
126    #[serde(rename = "cNvSpPr", default)]
127    pub c_nv_sp_pr: Option<DecodeCNvSpPr>,
128}
129
130/// Connection Non-Visual Shape Properties. This element specifies the set of
131/// non-visual properties for a connection shape.
132#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)]
133#[serde(rename = "cNvSpPr")]
134pub struct DecodeCNvSpPr {
135    #[serde(rename = "@txBox", default)]
136    pub tx_box: bool,
137}
138
139/// Directly maps the root element for a part of this content type shall `wsDr`.
140/// In order to solve the problem that the label structure is changed after
141/// serialization and deserialization, two different structures are defined.
142/// `DecodeWsDr` is just for deserialization.
143#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)]
144#[serde(rename = "xdr:wsDr")]
145pub struct DecodeWsDr {
146    #[serde(rename = "@xmlns:a", default)]
147    pub a: String,
148    #[serde(rename = "@xmlns:xdr", default)]
149    pub xdr: String,
150    #[serde(rename = "@xmlns:r", default)]
151    pub r: String,
152    #[serde(rename = "AlternateContent", default)]
153    pub alternate_content: Vec<XlsxInnerXml>,
154    #[serde(rename = "oneCellAnchor", default)]
155    pub one_cell_anchor: Vec<DecodeCellAnchor>,
156    #[serde(rename = "twoCellAnchor", default)]
157    pub two_cell_anchor: Vec<DecodeCellAnchor>,
158}
159
160/// Directly maps the `cNvPr` (Non-Visual Drawing Properties). This element
161/// specifies non-visual canvas properties.
162#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)]
163#[serde(rename = "cNvPr")]
164pub struct DecodeCNvPr {
165    #[serde(rename = "@id", default)]
166    pub id: i32,
167    #[serde(rename = "@name", default)]
168    pub name: String,
169    #[serde(rename = "@descr", default)]
170    pub descr: String,
171    #[serde(rename = "@title", default)]
172    pub title: Option<String>,
173    #[serde(rename = "hlinkClick", default)]
174    pub hlink_click: Option<DecodeHlinkClick>,
175}
176
177/// Directly maps the `hlinkClick` (Hyperlink Click). This element specifies the
178/// on-click hyperlink information to be applied to a run of text. When the
179/// hyperlink text is clicked the link is fetched.
180#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)]
181#[serde(rename = "hlinkClick")]
182pub struct DecodeHlinkClick {
183    #[serde(rename = "@id", default)]
184    pub id: Option<String>,
185    #[serde(rename = "@invalidUrl", default)]
186    pub invalid_url: Option<String>,
187    #[serde(rename = "@action", default)]
188    pub action: Option<String>,
189    #[serde(rename = "@tgtFrame", default)]
190    pub tgt_frame: Option<String>,
191    #[serde(rename = "@tooltip", default)]
192    pub tooltip: Option<String>,
193    #[serde(rename = "@history", default)]
194    pub history: bool,
195    #[serde(rename = "@highlightClick", default)]
196    pub highlight_click: bool,
197    #[serde(rename = "@endSnd", default)]
198    pub end_snd: bool,
199}
200
201/// Directly maps the `picLocks` (Picture Locks). This element specifies all
202/// locking properties for a graphic frame.
203#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)]
204#[serde(rename = "picLocks")]
205pub struct DecodePicLocks {
206    #[serde(rename = "@noAdjustHandles", default)]
207    pub no_adjust_handles: bool,
208    #[serde(rename = "@noChangeArrowheads", default)]
209    pub no_change_arrowheads: bool,
210    #[serde(rename = "@noChangeAspect", default)]
211    pub no_change_aspect: bool,
212    #[serde(rename = "@noChangeShapeType", default)]
213    pub no_change_shape_type: bool,
214    #[serde(rename = "@noCrop", default)]
215    pub no_crop: bool,
216    #[serde(rename = "@noEditPoints", default)]
217    pub no_edit_points: bool,
218    #[serde(rename = "@noGrp", default)]
219    pub no_grp: bool,
220    #[serde(rename = "@noMove", default)]
221    pub no_move: bool,
222    #[serde(rename = "@noResize", default)]
223    pub no_resize: bool,
224    #[serde(rename = "@noRot", default)]
225    pub no_rot: bool,
226    #[serde(rename = "@noSelect", default)]
227    pub no_select: bool,
228}
229
230/// Specifies the existence of an image (binary large image or picture) and
231/// contains a reference to the image data.
232#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)]
233#[serde(rename = "blip")]
234pub struct DecodeBlip {
235    #[serde(rename = "@embed", default)]
236    pub embed: String,
237    #[serde(rename = "@cstate", default)]
238    pub cstate: Option<String>,
239    #[serde(rename = "@r", default)]
240    pub r: String,
241}
242
243/// Directly maps the `stretch` element. This element specifies that a BLIP
244/// should be stretched to fill the target rectangle.
245#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)]
246#[serde(rename = "stretch")]
247pub struct DecodeStretch {
248    #[serde(rename = "fillRect", default)]
249    pub fill_rect: String,
250}
251
252/// Directly maps the `colOff` and `rowOff` element. This element is used to
253/// specify the column offset within a cell.
254#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)]
255#[serde(rename = "off")]
256pub struct DecodeOff {
257    #[serde(rename = "@x", default)]
258    pub x: i64,
259    #[serde(rename = "@y", default)]
260    pub y: i64,
261}
262
263/// Directly maps the `a:ext` element.
264#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)]
265#[serde(rename = "ext")]
266pub struct DecodePositiveSize2D {
267    #[serde(rename = "@cx", default)]
268    pub cx: i64,
269    #[serde(rename = "@cy", default)]
270    pub cy: i64,
271}
272
273/// Directly maps the `prstGeom` (Preset geometry). This element specifies when
274/// a preset geometric shape should be used instead of a custom geometric shape.
275#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)]
276#[serde(rename = "prstGeom")]
277pub struct DecodePrstGeom {
278    #[serde(rename = "@prst", default)]
279    pub prst: String,
280}
281
282/// Directly maps the `xfrm` (2D Transform for Graphic Frame). This element
283/// specifies the transform to be applied to the corresponding graphic frame.
284#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)]
285#[serde(rename = "xfrm")]
286pub struct DecodeXfrm {
287    #[serde(rename = "off", default)]
288    pub off: DecodeOff,
289    #[serde(rename = "ext", default)]
290    pub ext: DecodePositiveSize2D,
291}
292
293/// Directly maps the `cNvPicPr` (Non-Visual Picture Drawing Properties). This
294/// element specifies the non-visual properties for the picture canvas.
295#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)]
296#[serde(rename = "cNvPicPr")]
297pub struct DecodeCNvPicPr {
298    #[serde(rename = "picLocks", default)]
299    pub pic_locks: DecodePicLocks,
300}
301
302/// Directly maps the `nvPicPr` (Non-Visual Properties for a Picture). This
303/// element specifies all non-visual properties for a picture.
304#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)]
305#[serde(rename = "nvPicPr")]
306pub struct DecodeNvPicPr {
307    #[serde(rename = "cNvPr", default)]
308    pub c_nv_pr: DecodeCNvPr,
309    #[serde(rename = "cNvPicPr", default)]
310    pub c_nv_pic_pr: DecodeCNvPicPr,
311}
312
313/// Directly maps the `blipFill` (Picture Fill). This element specifies the kind
314/// of picture fill that the picture object has.
315#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)]
316#[serde(rename = "blipFill")]
317pub struct DecodeBlipFill {
318    #[serde(rename = "blip", default)]
319    pub blip: DecodeBlip,
320    #[serde(rename = "stretch", default)]
321    pub stretch: DecodeStretch,
322}
323
324/// Directly maps the `spPr` (Shape Properties). This element specifies the
325/// visual shape properties that can be applied to a picture.
326#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)]
327#[serde(rename = "spPr")]
328pub struct DecodeSpPr {
329    #[serde(rename = "xfrm", default)]
330    pub xfrm: DecodeXfrm,
331    #[serde(rename = "prstGeom", default)]
332    pub prst_geom: DecodePrstGeom,
333}
334
335/// Encompass the definition of pictures within the DrawingML framework. While
336/// pictures are in many ways very similar to shapes they have specific
337/// properties that are unique in order to optimize for picture-specific
338/// scenarios.
339#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)]
340#[serde(rename = "pic")]
341pub struct DecodePic {
342    #[serde(rename = "nvPicPr", default)]
343    pub nv_pic_pr: DecodeNvPicPr,
344    #[serde(rename = "blipFill", default)]
345    pub blip_fill: DecodeBlipFill,
346    #[serde(rename = "spPr", default)]
347    pub sp_pr: DecodeSpPr,
348}
349
350/// Specifies the starting anchor.
351#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)]
352#[serde(rename = "from")]
353pub struct DecodeFrom {
354    #[serde(rename = "col", default)]
355    pub col: i32,
356    #[serde(rename = "colOff", default)]
357    pub col_off: i64,
358    #[serde(rename = "row", default)]
359    pub row: i32,
360    #[serde(rename = "rowOff", default)]
361    pub row_off: i64,
362}
363
364/// Directly specifies the ending anchor.
365#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)]
366#[serde(rename = "to")]
367pub struct DecodeTo {
368    #[serde(rename = "col", default)]
369    pub col: i32,
370    #[serde(rename = "colOff", default)]
371    pub col_off: i64,
372    #[serde(rename = "row", default)]
373    pub row: i32,
374    #[serde(rename = "rowOff", default)]
375    pub row_off: i64,
376}
377
378/// Directly maps the `clientData` element. An empty element which specifies
379/// (via attributes) certain properties related to printing and selection of the
380/// drawing object.
381#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)]
382#[serde(rename = "clientData")]
383pub struct DecodeClientData {
384    #[serde(rename = "@fLocksWithSheet", default)]
385    pub f_locks_with_sheet: bool,
386    #[serde(rename = "@fPrintsWithSheet", default)]
387    pub f_prints_with_sheet: bool,
388}
389
390/// Directly maps the Kingsoft WPS Office embedded cell images.
391#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)]
392#[serde(rename = "cellImages")]
393pub struct DecodeCellImages {
394    #[serde(rename = "cellImage", default)]
395    pub cell_image: Vec<DecodeCellImage>,
396}
397
398/// Defines the structure used to deserialize the Kingsoft WPS Office embedded
399/// cell images.
400#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)]
401#[serde(rename = "cellImage")]
402pub struct DecodeCellImage {
403    #[serde(rename = "pic", default)]
404    pub pic: DecodePic,
405}
406
407// ------------------------------------------------------------------
408// Types referenced from `xmlDrawing.go` / `xmlWorkbook.go` that are used by
409// `DecodeCellAnchorPos`. They are duplicated here so this module stays
410// self-contained until the corresponding modules are ported.
411// ------------------------------------------------------------------
412
413/// Container for a sequence of multiple representations of a given piece of
414/// content. The program reading the file should only process one of these, and
415/// the one chosen should be based on which conditions match.
416#[derive(Debug, Default, Clone, PartialEq, Eq, Serialize, Deserialize)]
417#[serde(rename = "AlternateContent")]
418pub struct XlsxAlternateContent {
419    #[serde(rename = "@xmlns:mc", default)]
420    pub xmlns_mc: Option<String>,
421    #[serde(rename = "$value", default)]
422    pub content: XlsxInnerXml,
423}
424
425/// Specifies the starting anchor (drawing variant).
426#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)]
427#[serde(rename = "from")]
428pub struct XlsxFrom {
429    #[serde(rename = "col", default)]
430    pub col: i32,
431    #[serde(rename = "colOff", default)]
432    pub col_off: i64,
433    #[serde(rename = "row", default)]
434    pub row: i32,
435    #[serde(rename = "rowOff", default)]
436    pub row_off: i64,
437}
438
439/// Directly specifies the ending anchor (drawing variant).
440#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)]
441#[serde(rename = "to")]
442pub struct XlsxTo {
443    #[serde(rename = "col", default)]
444    pub col: i32,
445    #[serde(rename = "colOff", default)]
446    pub col_off: i64,
447    #[serde(rename = "row", default)]
448    pub row: i32,
449    #[serde(rename = "rowOff", default)]
450    pub row_off: i64,
451}
452
453/// Directly maps the `a:ext` element (drawing variant).
454#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)]
455#[serde(rename = "ext")]
456pub struct XlsxPositiveSize2D {
457    #[serde(rename = "@cx", default)]
458    pub cx: i64,
459    #[serde(rename = "@cy", default)]
460    pub cy: i64,
461}
462
463/// Shape. This element specifies the existence of a single shape.
464#[derive(Debug, Default, Clone, PartialEq, Serialize, Deserialize)]
465#[serde(rename = "sp")]
466pub struct XlsxSp {
467    #[serde(rename = "@macro", default)]
468    pub macro_name: Option<String>,
469    #[serde(rename = "@textlink", default)]
470    pub text_link: Option<String>,
471    #[serde(rename = "@fLocksText", default)]
472    pub f_locks_text: bool,
473    #[serde(rename = "@fPublished", default)]
474    pub f_published: Option<bool>,
475    #[serde(rename = "$value", default)]
476    pub content: XlsxInnerXml,
477}