Skip to main content

rs_docx/document/
pict.rs

1use hard_xml::{XmlRead, XmlWrite};
2use std::borrow::Cow;
3
4use crate::__xml_test_suites;
5
6/// VML Object (Legacy Image)
7#[derive(Debug, Default, XmlRead, XmlWrite, Clone)]
8#[cfg_attr(test, derive(PartialEq))]
9#[xml(tag = "w:pict")]
10pub struct Pict<'a> {
11    /// Specifies the content of the VML object
12    /// For now, we mainly care about v:shape -> v:imagedata accessing images
13    /// But parsing full VML is complex. We will try to capture raw children or specific known children.
14    /// hard_xml doesn't support "any child", so we define common VML shapes.
15
16    // Attempt to parse <v:shape>
17    #[xml(child = "v:shape")]
18    pub shape: Option<Shape<'a>>,
19
20    // Sometimes it's directly parseable? No, usually nested.
21    // Let's support v:rect too just in case.
22    #[xml(child = "v:rect")]
23    pub rect: Option<Rect<'a>>,
24}
25
26#[derive(Debug, Default, XmlRead, XmlWrite, Clone)]
27#[cfg_attr(test, derive(PartialEq))]
28#[xml(tag = "v:shape")]
29pub struct Shape<'a> {
30    #[xml(attr = "id")]
31    pub id: Option<Cow<'a, str>>,
32    #[xml(attr = "style")]
33    pub style: Option<Cow<'a, str>>,
34    #[xml(child = "v:imagedata")]
35    pub image_data: Option<ImageData<'a>>,
36}
37
38#[derive(Debug, Default, XmlRead, XmlWrite, Clone)]
39#[cfg_attr(test, derive(PartialEq))]
40#[xml(tag = "v:rect")]
41pub struct Rect<'a> {
42    #[xml(child = "v:imagedata")]
43    pub image_data: Option<ImageData<'a>>,
44}
45
46#[derive(Debug, Default, XmlRead, XmlWrite, Clone)]
47#[cfg_attr(test, derive(PartialEq))]
48#[xml(tag = "v:imagedata")]
49pub struct ImageData<'a> {
50    #[xml(attr = "r:id")]
51    pub id: Option<Cow<'a, str>>,
52    #[xml(attr = "o:title")]
53    pub title: Option<Cow<'a, str>>,
54}
55
56impl<'a> Pict<'a> {
57    // helpers if needed
58}
59
60__xml_test_suites!(Pict, Pict::default(), r#"<w:pict/>"#,);