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
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
use super::{
audiovideo::EmbeddedWAVAudioFile,
coordsys::{GroupTransform2D, Transform2D},
shapedefs::Geometry,
shapeprops::{
EffectProperties, FillProperties, LineDashProperties, LineEndProperties, LineFillProperties, LineJoinProperties,
},
simpletypes::{
AnimationChartBuildType, AnimationDgmBuildType, BlackWhiteMode, ChartBuildStep, CompoundLine, DgmBuildStep,
DrawingElementId, Guid, LineCap, LineWidth, PenAlignment,
},
styles::{FontReference, StyleMatrixReference},
text::{bodyformatting::TextBodyProperties, bullet::TextListStyle, paragraphs::TextParagraph},
};
use crate::{
error::{MissingAttributeError, MissingChildNodeError, NotGroupMemberError},
shared::relationship::RelationshipId,
xml::{parse_xml_bool, XmlNode},
xsdtypes::{XsdChoice, XsdType},
};
use std::error::Error;
pub type Result<T> = ::std::result::Result<T, Box<dyn Error>>;
#[derive(Debug, Clone, PartialEq)]
pub enum AnimationGraphicalObjectBuildProperties {
/// This element specifies how to build the animation for a diagram.
///
/// # Xml example
///
/// Consider having a diagram appear as on entity as opposed to by section. The bldDgm element should
/// be used as follows:
/// ```xml
/// <p:bdldLst>
/// <p:bldGraphic spid="4" grpId="0">
/// <p:bldSub>
/// <a:bldDgm bld="one"/>
/// </p:bldSub>
/// </p:bldGraphic>
/// </p:bldLst>
/// ```
BuildDiagram(AnimationDgmBuildProperties),
/// This element specifies how to build the animation for a diagram.
///
/// # Xml example
///
/// Consider the following example where a chart is specified to be animated by category rather than as
/// one entity. Thus, the bldChart element should be used as follows:
/// ```xml
/// <p:bdldLst>
/// <p:bldGraphic spid="4" grpId="0">
/// <p:bldSub>
/// <a:bldChart bld="category"/>
/// </p:bldSub>
/// </p:bldGraphic>
/// </p:bldLst>
/// ```
BuildChart(AnimationChartBuildProperties),
}
impl XsdType for AnimationGraphicalObjectBuildProperties {
fn from_xml_element(xml_node: &XmlNode) -> Result<Self> {
match xml_node.local_name() {
"bldDgm" => Ok(AnimationGraphicalObjectBuildProperties::BuildDiagram(
AnimationDgmBuildProperties::from_xml_element(xml_node)?,
)),
"bldChart" => Ok(AnimationGraphicalObjectBuildProperties::BuildChart(
AnimationChartBuildProperties::from_xml_element(xml_node)?,
)),
_ => Err(Box::new(NotGroupMemberError::new(
xml_node.name.clone(),
"CT_AnimationGraphicalObjectBuildProperties",
))),
}
}
}
impl XsdChoice for AnimationGraphicalObjectBuildProperties {
fn is_choice_member<T>(name: T) -> bool
where
T: AsRef<str>,
{
match name.as_ref() {
"bldDgm" | "bldChart" => true,
_ => false,
}
}
}
#[derive(Default, Debug, Clone, PartialEq)]
pub struct AnimationDgmBuildProperties {
/// Specifies how the chart is built. The animation animates the sub-elements in the
/// container in the particular order defined by this attribute.
///
/// Defaults to AnimationDgmBuildType::AllAtOnce
pub build_type: Option<AnimationDgmBuildType>,
/// Specifies whether the animation of the objects in this diagram should be reversed or not.
/// If this attribute is not specified, a value of false is assumed.
///
/// Defaults to false
pub reverse: Option<bool>,
}
impl AnimationDgmBuildProperties {
pub fn from_xml_element(xml_node: &XmlNode) -> Result<Self> {
xml_node
.attributes
.iter()
.try_fold(Default::default(), |mut instance: Self, (attr, value)| {
match attr.as_str() {
"bld" => instance.build_type = Some(value.parse()?),
"rev" => instance.reverse = Some(parse_xml_bool(value)?),
_ => (),
}
Ok(instance)
})
}
}
#[derive(Default, Debug, Clone, PartialEq)]
pub struct AnimationChartBuildProperties {
/// Specifies how the chart is built. The animation animates the sub-elements in the
/// container in the particular order defined by this attribute.
///
/// Defaults to AnimationChartBuildType::AllAtOnce
pub build_type: Option<AnimationChartBuildType>,
/// Specifies whether or not the chart background elements should be animated as well.
///
/// Defaults to true
///
/// # Note
///
/// An example of background elements are grid lines and the chart legend.
pub animate_bg: Option<bool>,
}
impl AnimationChartBuildProperties {
pub fn from_xml_element(xml_node: &XmlNode) -> Result<Self> {
xml_node
.attributes
.iter()
.try_fold(Default::default(), |mut instance: Self, (attr, value)| {
match attr.as_str() {
"bld" => instance.build_type = Some(value.parse()?),
"animBg" => instance.animate_bg = Some(parse_xml_bool(value)?),
_ => (),
}
Ok(instance)
})
}
}
#[derive(Debug, Clone, PartialEq)]
pub enum AnimationElementChoice {
/// This element specifies a reference to a diagram that should be animated within a sequence of slide animations.
/// In addition to simply acting as a reference to a diagram there is also animation build steps defined.
Diagram(AnimationDgmElement),
/// This element specifies a reference to a chart that should be animated within a sequence of slide animations. In
/// addition to simply acting as a reference to a chart there is also animation build steps defined.
Chart(AnimationChartElement),
}
impl XsdType for AnimationElementChoice {
fn from_xml_element(xml_node: &XmlNode) -> Result<Self> {
match xml_node.local_name() {
"dgm" => Ok(AnimationElementChoice::Diagram(AnimationDgmElement::from_xml_element(
xml_node,
)?)),
"chart" => Ok(AnimationElementChoice::Chart(AnimationChartElement::from_xml_element(
xml_node,
)?)),
_ => Err(Box::new(NotGroupMemberError::new(
xml_node.name.clone(),
"CT_AnimationElementChoice",
))),
}
}
}
impl XsdChoice for AnimationElementChoice {
fn is_choice_member<T>(name: T) -> bool
where
T: AsRef<str>,
{
match name.as_ref() {
"dgm" | "chart" => true,
_ => false,
}
}
}
#[derive(Default, Debug, Clone, PartialEq)]
pub struct AnimationDgmElement {
/// Specifies the GUID of the shape for this build step in the animation.
///
/// Defaults to {00000000-0000-0000-0000-000000000000}
pub id: Option<Guid>,
/// Specifies which step this part of the diagram should be built using. For instance the
/// diagram can be built as one object meaning it is animated as a single graphic.
/// Alternatively the diagram can be animated, or built as separate pieces.
///
/// Defaults to DgmBuildStep::Shape
pub build_step: Option<DgmBuildStep>,
}
impl AnimationDgmElement {
pub fn from_xml_element(xml_node: &XmlNode) -> Result<Self> {
xml_node
.attributes
.iter()
.try_fold(Default::default(), |mut instance: Self, (attr, value)| {
match attr.as_str() {
"id" => instance.id = Some(value.clone()),
"bldStep" => instance.build_step = Some(value.parse()?),
_ => (),
}
Ok(instance)
})
}
}
#[derive(Debug, Clone, PartialEq)]
pub struct AnimationChartElement {
/// Specifies the index of the series within the corresponding chart that should be animated.
///
/// Defaults to -1
pub series_index: Option<i32>,
/// Specifies the index of the category within the corresponding chart that should be
/// animated.
///
/// Defaults to -1
pub category_index: Option<i32>,
/// Specifies which step this part of the chart should be built using. For instance the chart can
/// be built as one object meaning it is animated as a single graphic. Alternatively the chart
/// can be animated, or built as separate pieces.
pub build_step: ChartBuildStep,
}
impl AnimationChartElement {
pub fn from_xml_element(xml_node: &XmlNode) -> Result<Self> {
let mut series_index = None;
let mut category_index = None;
let mut build_step = None;
for (attr, value) in &xml_node.attributes {
match attr.as_ref() {
"seriesIdx" => series_index = Some(value.parse()?),
"categoryIdx" => category_index = Some(value.parse()?),
"bldStep" => build_step = Some(value.parse()?),
_ => (),
}
}
let build_step = build_step.ok_or_else(|| MissingAttributeError::new(xml_node.name.clone(), "bldStep"))?;
Ok(Self {
series_index,
category_index,
build_step,
})
}
}
#[derive(Default, Debug, Clone, PartialEq)]
pub struct NonVisualConnectorProperties {
/// This element specifies all locking properties for a connection shape. These properties inform the generating
/// application about specific properties that have been previously locked and thus should not be changed.
pub connector_locks: Option<ConnectorLocking>,
/// This element specifies the starting connection that should be made by the corresponding connector shape. This
/// connects the head of the connector to the first shape.
pub start_connection: Option<Connection>,
/// This element specifies the ending connection that should be made by the corresponding connector shape. This
/// connects the end tail of the connector to the final destination shape.
pub end_connection: Option<Connection>,
}
impl NonVisualConnectorProperties {
pub fn from_xml_element(xml_node: &XmlNode) -> Result<Self> {
xml_node
.child_nodes
.iter()
.try_fold(Default::default(), |mut instance: Self, child_node| {
match child_node.local_name() {
"cxnSpLocks" => instance.connector_locks = Some(ConnectorLocking::from_xml_element(child_node)?),
"stCxn" => instance.start_connection = Some(Connection::from_xml_element(child_node)?),
"endCxn" => instance.end_connection = Some(Connection::from_xml_element(child_node)?),
_ => (),
}
Ok(instance)
})
}
}
#[derive(Default, Debug, Clone, PartialEq)]
pub struct NonVisualGraphicFrameProperties {
/// This element specifies all locking properties for a graphic frame. These properties inform the generating
/// application about specific properties that have been previously locked and thus should not be changed.
pub graphic_frame_locks: Option<GraphicalObjectFrameLocking>,
}
impl NonVisualGraphicFrameProperties {
pub fn from_xml_element(xml_node: &XmlNode) -> Result<Self> {
let graphic_frame_locks = xml_node
.child_nodes
.iter()
.find(|child_node| child_node.local_name() == "graphicFrameLocks")
.map(GraphicalObjectFrameLocking::from_xml_element)
.transpose()?;
Ok(Self { graphic_frame_locks })
}
}
#[derive(Debug, Clone, PartialEq)]
pub struct ContentPartLocking {
pub locking: Locking,
}
impl ContentPartLocking {
pub fn from_xml_element(xml_node: &XmlNode) -> Result<Self> {
let locking = Locking::from_xml_element(xml_node)?;
Ok(Self { locking })
}
}
#[derive(Default, Debug, Clone, PartialEq)]
pub struct NonVisualContentPartProperties {
pub locking: Option<ContentPartLocking>,
pub is_comment: Option<bool>, // default=true
}
impl NonVisualContentPartProperties {
pub fn from_xml_element(xml_node: &XmlNode) -> Result<Self> {
let is_comment = xml_node.attributes.get("isComment").map(parse_xml_bool).transpose()?;
let locking = xml_node
.child_nodes
.iter()
.find(|child_node| child_node.local_name() == "cpLocks")
.map(ContentPartLocking::from_xml_element)
.transpose()?;
Ok(Self { locking, is_comment })
}
}
#[derive(Default, Debug, Clone, PartialEq)]
pub struct NonVisualGroupDrawingShapeProps {
pub locks: Option<GroupLocking>,
}
impl NonVisualGroupDrawingShapeProps {
pub fn from_xml_element(xml_node: &XmlNode) -> Result<Self> {
let locks = xml_node
.child_nodes
.iter()
.find(|child_node| child_node.local_name() == "grpSpLocks")
.map(GroupLocking::from_xml_element)
.transpose()?;
Ok(Self { locks })
}
}
#[derive(Default, Debug, Clone, PartialEq)]
pub struct NonVisualPictureProperties {
/// Specifies if the user interface should show the resizing of the picture based on the
/// picture's current size or its original size. If this attribute is set to true, then scaling is
/// relative to the original picture size as opposed to the current picture size.
///
/// Defaults to true
///
/// # Example
///
/// Consider the case where a picture has been resized within a document and is
/// now 50% of the originally inserted picture size. Now if the user chooses to make a later
/// adjustment to the size of this picture within the generating application, then the value of
/// this attribute should be checked.
///
/// If this attribute is set to true then a value of 50% is shown. Similarly, if this attribute is set
/// to false, then a value of 100% should be shown because the picture has not yet been
/// resized from its current (smaller) size.
pub prefer_relative_resize: Option<bool>,
pub picture_locks: Option<PictureLocking>,
}
impl NonVisualPictureProperties {
pub fn from_xml_element(xml_node: &XmlNode) -> Result<Self> {
let prefer_relative_resize = xml_node
.attributes
.get("preferRelativeResize")
.map(parse_xml_bool)
.transpose()?;
let picture_locks = xml_node
.child_nodes
.iter()
.find(|child_node| child_node.local_name() == "picLocks")
.map(PictureLocking::from_xml_element)
.transpose()?;
Ok(Self {
prefer_relative_resize,
picture_locks,
})
}
}
#[derive(Default, Debug, Clone, PartialEq)]
pub struct NonVisualDrawingShapeProps {
pub shape_locks: Option<ShapeLocking>,
/// Specifies that the corresponding shape is a text box and thus should be treated as such
/// by the generating application. If this attribute is omitted then it is assumed that the
/// corresponding shape is not specifically a text box.
///
/// Defaults to false
pub is_text_box: Option<bool>,
}
impl NonVisualDrawingShapeProps {
pub fn from_xml_element(xml_node: &XmlNode) -> Result<Self> {
let is_text_box = xml_node.attributes.get("txBox").map(parse_xml_bool).transpose()?;
let shape_locks = xml_node
.child_nodes
.iter()
.find(|child_node| child_node.local_name() == "spLocks")
.map(ShapeLocking::from_xml_element)
.transpose()?;
Ok(Self {
is_text_box,
shape_locks,
})
}
}
/// ```xml example
/// <docPr id="1" name="Object name" descr="Some description" title="Title of the object">
/// <a:hlinkClick r:id="rId2" tooltip="Some Sample Text"/>
/// <a:hlinkHover r:id="rId2" tooltip="Some Sample Text"/>
/// </docPr>
/// ```
#[derive(Debug, Clone, PartialEq)]
pub struct NonVisualDrawingProps {
/// Specifies a unique identifier for the current DrawingML object within the current
/// document. This ID can be used to assist in uniquely identifying this object so that it can
/// be referred to by other parts of the document.
///
/// If multiple objects within the same document share the same id attribute value, then the
/// document shall be considered non-conformant.
///
/// # Example
///
/// Consider a DrawingML object defined as follows:
///
/// <… id="10" … >
///
/// The id attribute has a value of 10, which is the unique identifier for this DrawingML
/// object.
pub id: DrawingElementId,
/// Specifies the name of the object.
///
/// # Note
///
/// Typically, this is used to store the original file name of a picture object.
///
/// # Example
///
/// Consider a DrawingML object defined as follows:
///
/// < … name="foo.jpg" >
///
/// The name attribute has a value of foo.jpg, which is the name of this DrawingML object.
pub name: String,
/// Specifies alternative text for the current DrawingML object, for use by assistive
/// technologies or applications which do not display the current object.
///
/// If this element is omitted, then no alternative text is present for the parent object.
///
/// # Example
///
/// Consider a DrawingML object defined as follows:
///
/// <… descr="A picture of a bowl of fruit">
///
/// The descr attribute contains alternative text which can be used in place of the actual
/// DrawingML object.
pub description: Option<String>,
/// Specifies whether this DrawingML object is displayed. When a DrawingML object is
/// displayed within a document, that object can be hidden (i.e., present, but not visible).
/// This attribute determines whether the object is rendered or made hidden. [Note: An
/// application can have settings which allow this object to be viewed. end note]
///
/// If this attribute is omitted, then the parent DrawingML object shall be displayed (i.e., not
/// hidden).
///
/// Defaults to false
///
/// # Example
///
/// Consider an inline DrawingML object which must be hidden within the
/// document's content. This setting would be specified as follows:
///
/// <… hidden="true" />
///
/// The hidden attribute has a value of true, which specifies that the DrawingML object is
/// hidden and not displayed when the document is displayed.
pub hidden: Option<bool>,
/// Specifies the title (caption) of the current DrawingML object.
///
/// If this attribute is omitted, then no title text is present for the parent object.
///
/// # Example
///
/// Consider a DrawingML object defined as follows:
///
/// <… title="Process Flow Diagram">
pub title: Option<String>,
/// Specifies the hyperlink information to be activated when the user click's over the corresponding object.
pub hyperlink_click: Option<Box<Hyperlink>>,
/// This element specifies the hyperlink information to be activated when the user's mouse is hovered over the
/// corresponding object. The operation of the hyperlink is to have the specified action be activated when the
/// mouse of the user hovers over the object. When this action is activated then additional attributes can be used to
/// specify other tasks that should be performed along with the action.
pub hyperlink_hover: Option<Box<Hyperlink>>,
}
impl NonVisualDrawingProps {
pub fn from_xml_element(xml_node: &XmlNode) -> Result<Self> {
let mut opt_id = None;
let mut opt_name = None;
let mut description = None;
let mut hidden = None;
let mut title = None;
let mut hyperlink_click = None;
let mut hyperlink_hover = None;
for (attr, value) in &xml_node.attributes {
match attr.as_str() {
"id" => opt_id = Some(value.parse()?),
"name" => opt_name = Some(value.clone()),
"descr" => description = Some(value.clone()),
"hidden" => hidden = Some(parse_xml_bool(value)?),
"title" => title = Some(value.clone()),
_ => (),
}
}
for child_node in &xml_node.child_nodes {
match child_node.local_name() {
"hlinkClick" => hyperlink_click = Some(Box::new(Hyperlink::from_xml_element(child_node)?)),
"hlinkHover" => hyperlink_hover = Some(Box::new(Hyperlink::from_xml_element(child_node)?)),
_ => (),
}
}
let id = opt_id.ok_or_else(|| MissingAttributeError::new(xml_node.name.clone(), "id"))?;
let name = opt_name.ok_or_else(|| MissingAttributeError::new(xml_node.name.clone(), "name"))?;
Ok(Self {
id,
name,
description,
hidden,
title,
hyperlink_click,
hyperlink_hover,
})
}
}
#[derive(Default, Debug, Clone, PartialEq)]
pub struct Locking {
/// Specifies that the generating application should not allow shape grouping for the
/// corresponding connection shape. That is it cannot be combined within other shapes to
/// form a group of shapes. If this attribute is not specified, then a value of false is assumed.
///
/// Defaults to false
pub no_grouping: Option<bool>,
/// Specifies that the generating application should not allow selecting of the corresponding
/// connection shape. That means also that no picture, shapes or text attached to this
/// connection shape can be selected if this attribute has been specified. If this attribute is
/// not specified, then a value of false is assumed.
///
/// Defaults to false
pub no_select: Option<bool>,
/// Specifies that the generating application should not allow shape rotation changes for the
/// corresponding connection shape. If this attribute is not specified, then a value of false is
/// assumed.
///
/// Defaults to false
pub no_rotate: Option<bool>,
/// Specifies that the generating application should not allow aspect ratio changes for the
/// corresponding connection shape. If this attribute is not specified, then a value of false is
/// assumed.
///
/// Defaults to false
pub no_change_aspect_ratio: Option<bool>,
/// Specifies that the generating application should not allow position changes for the
/// corresponding connection shape. If this attribute is not specified, then a value of false is
/// assumed.
///
/// Defaults to false
pub no_move: Option<bool>,
/// Specifies that the generating application should not allow size changes for the
/// corresponding connection shape. If this attribute is not specified, then a value of false is
/// assumed.
///
/// Defaults to false
pub no_resize: Option<bool>,
/// Specifies that the generating application should not allow shape point changes for the
/// corresponding connection shape. If this attribute is not specified, then a value of false is
/// assumed.
///
/// Defaults to false
pub no_edit_points: Option<bool>,
/// Specifies that the generating application should not show adjust handles for the
/// corresponding connection shape. If this attribute is not specified, then a value of false is
/// assumed.
///
/// Defaults to false
pub no_adjust_handles: Option<bool>,
/// Specifies that the generating application should not allow arrowhead changes for the
/// corresponding connection shape. If this attribute is not specified, then a value of false is
/// assumed.
///
/// Defaults to false
pub no_change_arrowheads: Option<bool>,
/// Specifies that the generating application should not allow shape type changes for the
/// corresponding connection shape. If this attribute is not specified, then a value of false is
/// assumed.
///
/// Defaults to false
pub no_change_shape_type: Option<bool>,
}
impl Locking {
pub fn from_xml_element(xml_node: &XmlNode) -> Result<Self> {
xml_node
.attributes
.iter()
.try_fold(Default::default(), Self::try_update_from_xml_attribute)
}
pub fn try_update_from_xml_attribute(mut self, (attr, value): (&String, &String)) -> Result<Self> {
match attr.as_ref() {
"noGrp" => self.no_grouping = Some(parse_xml_bool(value)?),
"noSelect" => self.no_select = Some(parse_xml_bool(value)?),
"noRot" => self.no_rotate = Some(parse_xml_bool(value)?),
"noChangeAspect" => self.no_change_aspect_ratio = Some(parse_xml_bool(value)?),
"noMove" => self.no_move = Some(parse_xml_bool(value)?),
"noResize" => self.no_resize = Some(parse_xml_bool(value)?),
"noEditPoints" => self.no_edit_points = Some(parse_xml_bool(value)?),
"noAdjustHandles" => self.no_adjust_handles = Some(parse_xml_bool(value)?),
"noChangeArrowheads" => self.no_change_arrowheads = Some(parse_xml_bool(value)?),
"noChangeShapeType" => self.no_change_shape_type = Some(parse_xml_bool(value)?),
_ => (),
}
Ok(self)
}
}
#[derive(Default, Debug, Clone, PartialEq)]
pub struct ShapeLocking {
pub locking: Locking,
/// Specifies that the generating application should not allow editing of the shape text for
/// the corresponding shape. If this attribute is not specified, then a value of false is
/// assumed.
///
/// Defaults to false
pub no_text_edit: Option<bool>,
}
impl ShapeLocking {
pub fn from_xml_element(xml_node: &XmlNode) -> Result<Self> {
xml_node
.attributes
.iter()
.try_fold(Default::default(), |mut instance: Self, (attr, value)| {
match attr.as_ref() {
"noTextEdit" => instance.no_text_edit = Some(parse_xml_bool(value)?),
_ => instance.locking = instance.locking.try_update_from_xml_attribute((attr, value))?,
}
Ok(instance)
})
}
}
#[derive(Default, Debug, Clone, PartialEq)]
pub struct GroupLocking {
/// Specifies that the corresponding group shape cannot be grouped. That is it cannot be
/// combined within other shapes to form a group of shapes. If this attribute is not specified,
/// then a value of false is assumed.
///
/// Defaults to false
pub no_grouping: Option<bool>,
/// Specifies that the generating application should not show adjust handles for the
/// corresponding connection shape. If this attribute is not specified, then a value of false is
/// assumed.
///
/// Defaults to false
pub no_ungrouping: Option<bool>,
/// Specifies that the corresponding group shape cannot have any part of it be selected. That
/// means that no picture, shapes or attached text can be selected either if this attribute has
/// been specified. If this attribute is not specified, then a value of false is assumed.
///
/// Defaults to false
pub no_select: Option<bool>,
/// Specifies that the corresponding group shape cannot be rotated Objects that reside
/// within the group can still be rotated unless they also have been locked. If this attribute is
/// not specified, then a value of false is assumed.
///
/// Defaults to false
pub no_rotate: Option<bool>,
/// Specifies that the generating application should not allow aspect ratio changes for the
/// corresponding connection shape. If this attribute is not specified, then a value of false is
/// assumed.
///
/// Defaults to false
pub no_change_aspect_ratio: Option<bool>,
/// Specifies that the corresponding graphic frame cannot be moved. Objects that reside
/// within the graphic frame can still be moved unless they also have been locked. If this
/// attribute is not specified, then a value of false is assumed.
///
/// Defaults to false
pub no_move: Option<bool>,
/// Specifies that the corresponding group shape cannot be resized. If this attribute is not
/// specified, then a value of false is assumed.
///
/// Defaults to false
pub no_resize: Option<bool>,
}
impl GroupLocking {
pub fn from_xml_element(xml_node: &XmlNode) -> Result<Self> {
xml_node
.attributes
.iter()
.try_fold(Default::default(), |mut instance: Self, (attr, value)| {
match attr.as_ref() {
"noGrp" => instance.no_grouping = Some(parse_xml_bool(value)?),
"noUngrp" => instance.no_ungrouping = Some(parse_xml_bool(value)?),
"noSelect" => instance.no_select = Some(parse_xml_bool(value)?),
"noRot" => instance.no_rotate = Some(parse_xml_bool(value)?),
"noChangeAspect" => instance.no_change_aspect_ratio = Some(parse_xml_bool(value)?),
"noMove" => instance.no_move = Some(parse_xml_bool(value)?),
"noResize" => instance.no_resize = Some(parse_xml_bool(value)?),
_ => (),
}
Ok(instance)
})
}
}
#[derive(Default, Debug, Clone, PartialEq)]
pub struct GraphicalObjectFrameLocking {
/// Specifies that the generating application should not allow shape grouping for the
/// corresponding graphic frame. That is it cannot be combined within other shapes to form
/// a group of shapes. If this attribute is not specified, then a value of false is assumed.
///
/// Defaults to false
pub no_grouping: Option<bool>,
/// Specifies that the generating application should not allow selecting of objects within the
/// corresponding graphic frame but allow selecting of the graphic frame itself. If this
/// attribute is not specified, then a value of false is assumed.
///
/// Defaults to false
pub no_drilldown: Option<bool>,
/// Specifies that the generating application should not allow selecting of the corresponding
/// picture. That means also that no picture, shapes or text attached to this picture can be
/// selected if this attribute has been specified. If this attribute is not specified, then a value
/// of false is assumed.
///
/// Defaults to false
///
/// # Note
///
/// If this attribute is specified to be true then the graphic frame cannot be selected
/// and the objects within the graphic frame cannot be selected as well. That is the entire
/// graphic frame including all sub-parts are considered un-selectable.
pub no_select: Option<bool>,
/// Specifies that the generating application should not allow aspect ratio changes for the
/// corresponding graphic frame. If this attribute is not specified, then a value of false is
/// assumed.
///
/// Defaults to false
pub no_change_aspect: Option<bool>,
/// Specifies that the corresponding graphic frame cannot be moved. Objects that reside
/// within the graphic frame can still be moved unless they also have been locked. If this
/// attribute is not specified, then a value of false is assumed.
///
/// Defaults to false
pub no_move: Option<bool>,
/// Specifies that the generating application should not allow size changes for the
/// corresponding graphic frame. If this attribute is not specified, then a value of false is
/// assumed.
///
/// Defaults to false
pub no_resize: Option<bool>,
}
impl GraphicalObjectFrameLocking {
pub fn from_xml_element(xml_node: &XmlNode) -> Result<Self> {
xml_node
.attributes
.iter()
.try_fold(Default::default(), |mut instance: Self, (attr, value)| {
match attr.as_ref() {
"noGrp" => instance.no_grouping = Some(parse_xml_bool(value)?),
"noDrilldown" => instance.no_drilldown = Some(parse_xml_bool(value)?),
"noSelect" => instance.no_select = Some(parse_xml_bool(value)?),
"noChangeAspect" => instance.no_change_aspect = Some(parse_xml_bool(value)?),
"noMove" => instance.no_move = Some(parse_xml_bool(value)?),
"noResize" => instance.no_resize = Some(parse_xml_bool(value)?),
_ => (),
}
Ok(instance)
})
}
}
#[derive(Default, Debug, Clone, PartialEq)]
pub struct ConnectorLocking {
pub locking: Locking,
}
impl ConnectorLocking {
pub fn from_xml_element(xml_node: &XmlNode) -> Result<Self> {
let locking = Locking::from_xml_element(xml_node)?;
Ok(Self { locking })
}
}
#[derive(Default, Debug, Clone, PartialEq)]
pub struct PictureLocking {
pub locking: Locking,
/// Specifies that the generating application should not allow cropping for the corresponding
/// picture. If this attribute is not specified, then a value of false is assumed.
///
/// Defaults to false
pub no_crop: Option<bool>,
}
impl PictureLocking {
pub fn from_xml_element(xml_node: &XmlNode) -> Result<Self> {
xml_node
.attributes
.iter()
.try_fold(Default::default(), |mut instance: Self, (attr, value)| {
match attr.as_ref() {
"noCrop" => instance.no_crop = Some(parse_xml_bool(value)?),
_ => instance.locking = instance.locking.try_update_from_xml_attribute((attr, value))?,
}
Ok(instance)
})
}
}
#[derive(Debug, Clone, PartialEq)]
pub struct Connection {
/// Specifies the id of the shape to make the final connection to.
pub id: DrawingElementId,
/// Specifies the index into the connection site table of the final connection shape. That is
/// there are many connection sites on a shape and it shall be specified which connection
/// site the corresponding connector shape should connect to.
pub shape_index: u32,
}
impl Connection {
pub fn from_xml_element(xml_node: &XmlNode) -> Result<Self> {
let mut id = None;
let mut shape_index = None;
for (attr, value) in &xml_node.attributes {
match attr.as_str() {
"id" => id = Some(value.parse()?),
"idx" => shape_index = Some(value.parse()?),
_ => (),
}
}
let id = id.ok_or_else(|| MissingAttributeError::new(xml_node.name.clone(), "id"))?;
let shape_index = shape_index.ok_or_else(|| MissingAttributeError::new(xml_node.name.clone(), "idx"))?;
Ok(Self { id, shape_index })
}
}
#[derive(Debug, Clone, PartialEq)]
pub struct GraphicalObject {
/// This element specifies the reference to a graphic object within the document. This graphic object is provided
/// entirely by the document authors who choose to persist this data within the document.
///
/// # Note
///
/// Depending on the kind of graphical object used not every generating application that supports the
/// OOXML framework has the ability to render the graphical object.
pub graphic_data: GraphicalObjectData,
}
impl GraphicalObject {
pub fn from_xml_element(xml_node: &XmlNode) -> Result<Self> {
let graphic_data = xml_node
.child_nodes
.iter()
.find(|child_node| child_node.local_name() == "graphicData")
.ok_or_else(|| Box::<dyn Error>::from(MissingChildNodeError::new(xml_node.name.clone(), "graphicData")))
.and_then(GraphicalObjectData::from_xml_element)?;
Ok(Self { graphic_data })
}
}
#[derive(Debug, Clone, PartialEq)]
pub struct GraphicalObjectData {
// TODO implement
//pub graphic_object: Vec<Any>,
/// Specifies the URI, or uniform resource identifier that represents the data stored under
/// this tag. The URI is used to identify the correct 'server' that can process the contents of
/// this tag.
pub uri: String,
}
impl GraphicalObjectData {
pub fn from_xml_element(xml_node: &XmlNode) -> Result<Self> {
let uri = xml_node
.attributes
.get("uri")
.ok_or_else(|| Box::<dyn Error>::from(MissingAttributeError::new(xml_node.name.clone(), "uri")))?
.clone();
Ok(Self { uri })
}
}
#[derive(Default, Debug, Clone, PartialEq)]
pub struct GroupShapeProperties {
/// Specifies that the group shape should be rendered using only black and white coloring.
/// That is the coloring information for the group shape should be converted to either black
/// or white when rendering the corresponding shapes.
///
/// No gray is to be used in rendering this image, only stark black and stark white.
///
/// # Note
///
/// This does not mean that the group shapes themselves are stored with only black
/// and white color information. This attribute instead sets the rendering mode that the
/// shapes use when rendering.
pub black_and_white_mode: Option<BlackWhiteMode>,
/// This element is nearly identical to the representation of 2-D transforms for ordinary shapes. The only
/// addition is a member to represent the Child offset and the Child extents.
pub transform: Option<Box<GroupTransform2D>>,
/// Specifies the fill properties for this group shape.
pub fill_properties: Option<FillProperties>,
/// Specifies the effect that should be applied to this group shape.
pub effect_properties: Option<EffectProperties>,
// TODO implement
//pub scene_3d: Option<Scene3D>,
}
impl GroupShapeProperties {
pub fn from_xml_element(xml_node: &XmlNode) -> Result<Self> {
let black_and_white_mode = xml_node
.attributes
.get("bwMode")
.map(|value| value.parse())
.transpose()?;
xml_node.child_nodes.iter().try_fold(
Self {
black_and_white_mode,
..Default::default()
},
|mut instance, child_node| {
match child_node.local_name() {
"xfrm" => instance.transform = Some(Box::new(GroupTransform2D::from_xml_element(child_node)?)),
child_name if FillProperties::is_choice_member(child_name) => {
instance.fill_properties = Some(FillProperties::from_xml_element(child_node)?)
}
child_name if EffectProperties::is_choice_member(child_name) => {
instance.effect_properties = Some(EffectProperties::from_xml_element(child_node)?)
}
_ => (),
}
Ok(instance)
},
)
}
}
/// This element specifies an outline style that can be applied to a number of different objects such as shapes and
/// text. The line allows for the specifying of many different types of outlines including even line dashes and bevels.
#[derive(Default, Debug, Clone, PartialEq)]
pub struct LineProperties {
/// Specifies the width to be used for the underline stroke. If this attribute is omitted, then a
/// value of 0 is assumed.
pub width: Option<LineWidth>,
/// Specifies the ending caps that should be used for this line. If this attribute is omitted, than a value of
/// square is assumed.
///
/// # Note
///
/// Examples of cap types are rounded, flat, etc.
pub cap: Option<LineCap>,
/// Specifies the compound line type to be used for the underline stroke. If this attribute is
/// omitted, then a value of CompoundLine::Single is assumed.
pub compound: Option<CompoundLine>,
/// Specifies the alignment to be used for the underline stroke.
pub pen_alignment: Option<PenAlignment>,
/// Specifies the fill properties for this line.
pub fill_properties: Option<LineFillProperties>,
/// Specifies the dash properties for this line.
pub dash_properties: Option<LineDashProperties>,
/// Specifies the join properties for this line.
pub join_properties: Option<LineJoinProperties>,
/// This element specifies decorations which can be added to the head of a line.
pub head_end: Option<LineEndProperties>,
/// This element specifies decorations which can be added to the tail of a line.
pub tail_end: Option<LineEndProperties>,
}
impl LineProperties {
pub fn from_xml_element(xml_node: &XmlNode) -> Result<LineProperties> {
xml_node
.attributes
.iter()
.try_fold(Default::default(), |mut instance: Self, (attr, value)| {
match attr.as_ref() {
"w" => instance.width = Some(value.parse()?),
"cap" => instance.cap = Some(value.parse()?),
"cmpd" => instance.compound = Some(value.parse()?),
"algn" => instance.pen_alignment = Some(value.parse()?),
_ => (),
}
Ok(instance)
})
.and_then(|instance| {
xml_node
.child_nodes
.iter()
.try_fold(instance, |mut instance, child_node| {
match child_node.local_name() {
"headEnd" => instance.head_end = Some(LineEndProperties::from_xml_element(child_node)?),
"tailEnd" => instance.tail_end = Some(LineEndProperties::from_xml_element(child_node)?),
child_name if LineFillProperties::is_choice_member(child_name) => {
instance.fill_properties = Some(LineFillProperties::from_xml_element(child_node)?)
}
child_name if LineDashProperties::is_choice_member(child_name) => {
instance.dash_properties = Some(LineDashProperties::from_xml_element(child_node)?)
}
child_name if LineJoinProperties::is_choice_member(child_name) => {
instance.join_properties = Some(LineJoinProperties::from_xml_element(child_node)?)
}
_ => (),
}
Ok(instance)
})
})
}
}
#[derive(Default, Debug, Clone, PartialEq)]
pub struct ShapeProperties {
/// Specifies that the picture should be rendered using only black and white coloring. That is
/// the coloring information for the picture should be converted to either black or white
/// when rendering the picture.
///
/// No gray is to be used in rendering this image, only stark black and stark white.
///
/// # Note
///
/// This does not mean that the picture itself that is stored within the file is
/// necessarily a black and white picture. This attribute instead sets the rendering mode that
/// the picture has applied to when rendering.
pub black_and_white_mode: Option<BlackWhiteMode>,
/// This element represents 2-D transforms for ordinary shapes.
pub transform: Option<Box<Transform2D>>,
/// Specifies the geometry of this shape
pub geometry: Option<Geometry>,
/// Specifies the fill properties of this shape
pub fill_properties: Option<FillProperties>,
/// Specifies the outline properties of this shape.
pub line_properties: Option<Box<LineProperties>>,
/// Specifies the effect that should be applied to this shape.
pub effect_properties: Option<EffectProperties>,
// TODO implement
//pub scene_3d: Option<Scene3D>,
//pub shape_3d: Option<Shape3D>,
}
impl ShapeProperties {
pub fn from_xml_element(xml_node: &XmlNode) -> Result<Self> {
let black_and_white_mode = xml_node
.attributes
.get("bwMode")
.map(|value| value.parse())
.transpose()?;
xml_node.child_nodes.iter().try_fold(
Self {
black_and_white_mode,
..Default::default()
},
|mut instance, child_node| {
match child_node.local_name() {
"xfrm" => instance.transform = Some(Box::new(Transform2D::from_xml_element(child_node)?)),
"ln" => instance.line_properties = Some(Box::new(LineProperties::from_xml_element(child_node)?)),
child_name if Geometry::is_choice_member(child_name) => {
instance.geometry = Some(Geometry::from_xml_element(child_node)?)
}
child_name if FillProperties::is_choice_member(child_name) => {
instance.fill_properties = Some(FillProperties::from_xml_element(child_node)?)
}
child_name if EffectProperties::is_choice_member(child_name) => {
instance.effect_properties = Some(EffectProperties::from_xml_element(child_node)?)
}
_ => (),
}
Ok(instance)
},
)
}
}
#[derive(Debug, Clone, PartialEq)]
pub struct ShapeStyle {
/// This element represents a reference to a line properties.
pub line_reference: StyleMatrixReference,
/// This element represents a reference to a fill properties.
pub fill_reference: StyleMatrixReference,
/// This element represents a reference to an effect properties.
pub effect_reference: StyleMatrixReference,
/// This element represents a reference to a themed font. When used it specifies which themed font to use along
/// with a choice of color.
///
/// # Xml example
///
/// ```xml
/// <fontRef idx="minor">
/// <schemeClr val="tx1"/>
/// </fontRef>
/// ```
pub font_reference: FontReference,
}
impl ShapeStyle {
pub fn from_xml_element(xml_node: &XmlNode) -> Result<Self> {
let mut line_reference = None;
let mut fill_reference = None;
let mut effect_reference = None;
let mut font_reference = None;
for child_node in &xml_node.child_nodes {
match child_node.local_name() {
"lnRef" => line_reference = Some(StyleMatrixReference::from_xml_element(child_node)?),
"fillRef" => fill_reference = Some(StyleMatrixReference::from_xml_element(child_node)?),
"effectRef" => effect_reference = Some(StyleMatrixReference::from_xml_element(child_node)?),
"fontRef" => font_reference = Some(FontReference::from_xml_element(child_node)?),
_ => (),
}
}
let line_reference =
line_reference.ok_or_else(|| MissingChildNodeError::new(xml_node.name.clone(), "lnRef"))?;
let fill_reference =
fill_reference.ok_or_else(|| MissingChildNodeError::new(xml_node.name.clone(), "fillRef"))?;
let effect_reference =
effect_reference.ok_or_else(|| MissingChildNodeError::new(xml_node.name.clone(), "effectRef"))?;
let font_reference =
font_reference.ok_or_else(|| MissingChildNodeError::new(xml_node.name.clone(), "fontRef"))?;
Ok(Self {
line_reference,
fill_reference,
effect_reference,
font_reference,
})
}
}
#[derive(Debug, Clone, PartialEq)]
pub struct TextBody {
/// Specifies the properties of this text body.
pub body_properties: Box<TextBodyProperties>,
/// Specifies the list style of this text body.
pub list_style: Option<Box<TextListStyle>>,
/// This element specifies the presence of a paragraph of text within the containing text body. The paragraph is the
/// highest level text separation mechanism within a text body. A paragraph can contain text paragraph properties
/// associated with the paragraph. If no properties are listed then properties specified in the defPPr element are
/// used.
///
/// # Xml example
///
/// Consider the case where the user would like to describe a text body that contains two paragraphs.
/// The requirement for these paragraphs is that one be right aligned and the other left aligned. The following
/// DrawingML would specify a text body such as this.
///
/// ```xml
/// <p:txBody>
/// …
/// <a:p>
/// <a:pPr algn="r">
/// </a:pPr>
/// …
/// <a:t>Some text</a:t>
/// …
/// </a:p>
/// <a:p>
/// <a:pPr algn="l">
/// </a:pPr>
/// …
/// <a:t>Some text</a:t>
/// …
/// </a:p>
/// </p:txBody>
/// ```
pub paragraph_array: Vec<TextParagraph>,
}
impl TextBody {
pub fn from_xml_element(xml_node: &XmlNode) -> Result<Self> {
let mut body_properties = None;
let mut list_style = None;
let mut paragraph_array = Vec::new();
for child_node in &xml_node.child_nodes {
match child_node.local_name() {
"bodyPr" => body_properties = Some(Box::new(TextBodyProperties::from_xml_element(child_node)?)),
"lstStyle" => list_style = Some(Box::new(TextListStyle::from_xml_element(child_node)?)),
"p" => paragraph_array.push(TextParagraph::from_xml_element(child_node)?),
_ => (),
}
}
let body_properties =
body_properties.ok_or_else(|| MissingChildNodeError::new(xml_node.name.clone(), "bodyPr"))?;
Ok(Self {
body_properties,
list_style,
paragraph_array,
})
}
}
#[derive(Default, Debug, Clone, PartialEq)]
pub struct Hyperlink {
/// Specifies the relationship id that when looked up in this slides relationship file contains
/// the target of this hyperlink. This attribute cannot be omitted.
pub relationship_id: Option<RelationshipId>,
/// Specifies the URL when it has been determined by the generating application that the
/// URL is invalid. That is the generating application can still store the URL but it is known
/// that this URL is not correct.
pub invalid_url: Option<String>,
/// Specifies an action that is to be taken when this hyperlink is activated. This can be used to
/// specify a slide to be navigated to or a script of code to be run.
pub action: Option<String>,
/// Specifies the target frame that is to be used when opening this hyperlink. When the
/// hyperlink is activated this attribute is used to determine if a new window is launched for
/// viewing or if an existing one can be used. If this attribute is omitted, than a new window
/// is opened.
pub target_frame: Option<String>,
/// Specifies the tooltip that should be displayed when the hyperlink text is hovered over
/// with the mouse. If this attribute is omitted, than the hyperlink text itself can be
/// displayed.
pub tooltip: Option<String>,
/// Specifies whether to add this URI to the history when navigating to it. This allows for the
/// viewing of this presentation without the storing of history information on the viewing
/// machine. If this attribute is omitted, then a value of 1 or true is assumed.
///
/// Defaults to true
pub history: Option<bool>,
/// Specifies if this attribute has already been used within this document. That is when a
/// hyperlink has already been visited that this attribute would be utilized so the generating
/// application can determine the color of this text. If this attribute is omitted, then a value
/// of 0 or false is implied.
///
/// Defaults to false
pub highlight_click: Option<bool>,
/// Specifies if the URL in question should stop all sounds that are playing when it is clicked.
///
/// Defaults to false
pub end_sound: Option<bool>,
pub sound: Option<EmbeddedWAVAudioFile>,
}
impl Hyperlink {
pub fn from_xml_element(xml_node: &XmlNode) -> Result<Self> {
let sound = xml_node
.child_nodes
.iter()
.find(|child_node| child_node.local_name() == "snd")
.map(EmbeddedWAVAudioFile::from_xml_element)
.transpose()?;
xml_node.attributes.iter().try_fold(
Self {
sound,
..Default::default()
},
|mut instance, (attr, value)| {
match attr.as_str() {
"r:id" => instance.relationship_id = Some(value.clone()),
"invalidUrl" => instance.invalid_url = Some(value.clone()),
"action" => instance.action = Some(value.clone()),
"tgtFrame" => instance.target_frame = Some(value.clone()),
"tooltip" => instance.tooltip = Some(value.clone()),
"history" => instance.history = Some(parse_xml_bool(value)?),
"highlightClick" => instance.highlight_click = Some(parse_xml_bool(value)?),
"endSnd" => instance.end_sound = Some(parse_xml_bool(value)?),
_ => (),
}
Ok(instance)
},
)
}
}