Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
  • Loading branch information
DESKTOP-U434MT0\hiro committed Jun 10, 2024
1 parent eac7240 commit c0bc0b6
Show file tree
Hide file tree
Showing 22 changed files with 347 additions and 80 deletions.
3 changes: 3 additions & 0 deletions src/structs/drawing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -263,3 +263,6 @@ pub use self::rotation::*;

mod extension_list;
pub use self::extension_list::*;

mod blip_fill;
pub use self::blip_fill::*;
26 changes: 23 additions & 3 deletions src/structs/drawing/blip.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// a:blip
use helper::const_str::*;
use quick_xml::events::BytesStart;
use quick_xml::events::{BytesStart, Event};
use quick_xml::Reader;
use quick_xml::Writer;
use reader::driver::*;
Expand Down Expand Up @@ -40,9 +40,10 @@ impl Blip {

pub(crate) fn set_attributes<R: std::io::BufRead>(
&mut self,
_reader: &mut Reader<R>,
reader: &mut Reader<R>,
e: &BytesStart,
drawing_relationships: &RawRelationships,
empty_flag: bool,
) {
if let Some(v) = get_attribute(e, b"cstate") {
self.set_cstate(v);
Expand All @@ -54,10 +55,29 @@ impl Blip {
.set_image_name(relationship.get_raw_file().get_file_name());
self.get_image_mut()
.set_image_data(relationship.get_raw_file().get_file_data().clone());

if empty_flag {
return;
}

xml_read_loop!(
reader,
Event::End(ref e) => {
if e.name().into_inner() == b"a:blip" {
return
}
},
Event::Eof => panic!("Error not find {} end element", "a:blip")
);
}

pub(crate) fn write_to(&self, writer: &mut Writer<Cursor<Vec<u8>>>, r_id: &i32) {
pub(crate) fn write_to(
&self,
writer: &mut Writer<Cursor<Vec<u8>>>,
rel_list: &mut Vec<(String, String)>,
) {
// a:blip
let r_id = self.image.get_rid(rel_list);
let r_id_str = format!("rId{}", r_id);
let mut attributes: Vec<(&str, &str)> = Vec::new();
attributes.push(("xmlns:r", REL_OFC_NS));
Expand Down
141 changes: 141 additions & 0 deletions src/structs/drawing/blip_fill.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
// a:blipFill
use super::super::super::BooleanValue;
use super::Blip;
use super::SourceRectangle;
use super::Stretch;
use quick_xml::events::{BytesStart, Event};
use quick_xml::Reader;
use quick_xml::Writer;
use reader::driver::*;
use std::io::Cursor;
use structs::raw::RawRelationships;
use writer::driver::*;

#[derive(Clone, Default, Debug)]
pub struct BlipFill {
rotate_with_shape: BooleanValue,
blip: Blip,
source_rectangle: Option<SourceRectangle>,
stretch: Stretch,
}

impl BlipFill {
pub fn get_rotate_with_shape(&self) -> &bool {
self.rotate_with_shape.get_value()
}

pub fn set_rotate_with_shape(&mut self, value: bool) -> &mut BlipFill {
self.rotate_with_shape.set_value(value);
self
}

pub fn get_source_rectangle(&self) -> Option<&SourceRectangle> {
self.source_rectangle.as_ref()
}

pub fn get_source_rectangle_mut(&mut self) -> Option<&mut SourceRectangle> {
self.source_rectangle.as_mut()
}

pub fn set_source_rectangle(&mut self, value: SourceRectangle) -> &mut BlipFill {
self.source_rectangle = Some(value);
self
}

pub fn get_blip(&self) -> &Blip {
&self.blip
}

pub fn get_blip_mut(&mut self) -> &mut Blip {
&mut self.blip
}

pub fn set_blip(&mut self, value: Blip) -> &mut BlipFill {
self.blip = value;
self
}

pub fn get_stretch(&self) -> &Stretch {
&self.stretch
}

pub fn get_stretch_mut(&mut self) -> &mut Stretch {
&mut self.stretch
}

pub fn set_stretch(&mut self, value: Stretch) -> &mut BlipFill {
self.stretch = value;
self
}

pub(crate) fn set_attributes<R: std::io::BufRead>(
&mut self,
reader: &mut Reader<R>,
e: &BytesStart,
drawing_relationships: Option<&RawRelationships>,
) {
set_string_from_xml!(self, e, rotate_with_shape, "rotWithShape");

xml_read_loop!(
reader,
Event::Start(ref e) => {
match e.name().into_inner() {
b"a:blip" => {
self.blip
.set_attributes(reader, e, drawing_relationships.unwrap(), false);
}
b"a:stretch" => {
self.stretch.set_attributes(reader, e);
}
_ => (),
}
},
Event::Empty(ref e) => {
match e.name().into_inner() {
b"a:blip" => {
self.blip
.set_attributes(reader, e, drawing_relationships.unwrap(), true);
}
b"a:srcRect" => {
let mut source_rectangle = SourceRectangle::default();
source_rectangle.set_attributes(reader, e);
self.set_source_rectangle(source_rectangle);
}
_ => (),
}
},
Event::End(ref e) => {
if e.name().into_inner() == b"a:blipFill" {
return;
}
},
Event::Eof => panic!("Error not find {} end element", "a:blipFill")
);
}

pub(crate) fn write_to(
&self,
writer: &mut Writer<Cursor<Vec<u8>>>,
rel_list: &mut Vec<(String, String)>,
) {
// a:blipFill
let mut attributes: Vec<(&str, &str)> = Vec::new();
if self.rotate_with_shape.has_value() {
attributes.push(("rotWithShape", self.rotate_with_shape.get_value_string()))
}
write_start_tag(writer, "a:blipFill", attributes, false);

// a:blip
let _ = &self.blip.write_to(writer, rel_list);

// a:srcRect
if let Some(v) = &self.source_rectangle {
v.write_to(writer);
}

// a:stretch
let _ = &self.stretch.write_to(writer);

write_end_tag(writer, "a:blipFill");
}
}
8 changes: 6 additions & 2 deletions src/structs/drawing/graphic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,16 @@ impl Graphic {
);
}

pub(crate) fn write_to(&self, writer: &mut Writer<Cursor<Vec<u8>>>, r_id: &i32) {
pub(crate) fn write_to(
&self,
writer: &mut Writer<Cursor<Vec<u8>>>,
rel_list: &mut Vec<(String, String)>,
) {
// a:graphic
write_start_tag(writer, "a:graphic", vec![], false);

// a:graphicData
let _ = &self.graphic_data.write_to(writer, r_id);
let _ = &self.graphic_data.write_to(writer, rel_list);

write_end_tag(writer, "a:graphic");
}
Expand Down
9 changes: 7 additions & 2 deletions src/structs/drawing/graphic_data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@ impl GraphicData {
);
}

pub(crate) fn write_to(&self, writer: &mut Writer<Cursor<Vec<u8>>>, r_id: &i32) {
pub(crate) fn write_to(
&self,
writer: &mut Writer<Cursor<Vec<u8>>>,
rel_list: &mut Vec<(String, String)>,
) {
// a:graphicData
write_start_tag(
writer,
Expand All @@ -65,13 +69,14 @@ impl GraphicData {
);

// c:chart
rel_list.push((String::from("CHART"), String::from("")));
write_start_tag(
writer,
"c:chart",
vec![
("xmlns:c", DRAWINGML_CHART_NS),
("xmlns:r", REL_OFC_NS),
("r:id", format!("rId{}", r_id).as_str()),
("r:id", format!("rId{}", rel_list.len()).as_str()),
],
true,
);
Expand Down
12 changes: 8 additions & 4 deletions src/structs/drawing/spreadsheet/blip_fill.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ impl BlipFill {
match e.name().into_inner() {
b"a:blip" => {
self.blip
.set_attributes(reader, e, drawing_relationships.unwrap());
.set_attributes(reader, e, drawing_relationships.unwrap(), false);
}
b"a:stretch" => {
self.stretch.set_attributes(reader, e);
Expand All @@ -94,7 +94,7 @@ impl BlipFill {
match e.name().into_inner() {
b"a:blip" => {
self.blip
.set_attributes(reader, e, drawing_relationships.unwrap());
.set_attributes(reader, e, drawing_relationships.unwrap(), true);
}
b"a:srcRect" => {
let mut source_rectangle = SourceRectangle::default();
Expand All @@ -113,7 +113,11 @@ impl BlipFill {
);
}

pub(crate) fn write_to(&self, writer: &mut Writer<Cursor<Vec<u8>>>, r_id: &i32) {
pub(crate) fn write_to(
&self,
writer: &mut Writer<Cursor<Vec<u8>>>,
rel_list: &mut Vec<(String, String)>,
) {
// xdr:blipFill
let mut attributes: Vec<(&str, &str)> = Vec::new();
if self.rotate_with_shape.has_value() {
Expand All @@ -122,7 +126,7 @@ impl BlipFill {
write_start_tag(writer, "xdr:blipFill", attributes, false);

// a:blip
let _ = &self.blip.write_to(writer, r_id);
let _ = &self.blip.write_to(writer, rel_list);

// a:srcRect
if let Some(v) = &self.source_rectangle {
Expand Down
12 changes: 9 additions & 3 deletions src/structs/drawing/spreadsheet/connection_shape.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use quick_xml::Reader;
use quick_xml::Writer;
use reader::driver::*;
use std::io::Cursor;
use structs::raw::RawRelationships;
use writer::driver::*;

#[derive(Clone, Default, Debug)]
Expand Down Expand Up @@ -78,6 +79,7 @@ impl ConnectionShape {
&mut self,
reader: &mut Reader<R>,
_e: &BytesStart,
drawing_relationships: Option<&RawRelationships>,
) {
xml_read_loop!(
reader,
Expand All @@ -88,7 +90,7 @@ impl ConnectionShape {
.set_attributes(reader, e);
}
b"xdr:spPr" => {
self.shape_properties.set_attributes(reader, e);
self.shape_properties.set_attributes(reader, e, drawing_relationships);
}
b"xdr:style" => {
self.shape_style.set_attributes(reader, e);
Expand All @@ -105,15 +107,19 @@ impl ConnectionShape {
);
}

pub(crate) fn write_to(&self, writer: &mut Writer<Cursor<Vec<u8>>>) {
pub(crate) fn write_to(
&self,
writer: &mut Writer<Cursor<Vec<u8>>>,
rel_list: &mut Vec<(String, String)>,
) {
// xdr:cxnSp
write_start_tag(writer, "xdr:cxnSp", vec![("macro", "")], false);

// xdr:nvCxnSpPr
let _ = &self.non_visual_connection_shape_properties.write_to(writer);

// xdr:spPr
let _ = &self.shape_properties.write_to(writer);
let _ = &self.shape_properties.write_to(writer, rel_list);

// xdr:style
let _ = &self.shape_style.write_to(writer);
Expand Down
8 changes: 6 additions & 2 deletions src/structs/drawing/spreadsheet/graphic_frame.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,11 @@ impl GraphicFrame {
);
}

pub(crate) fn write_to(&self, writer: &mut Writer<Cursor<Vec<u8>>>, r_id: &i32) {
pub(crate) fn write_to(
&self,
writer: &mut Writer<Cursor<Vec<u8>>>,
rel_list: &mut Vec<(String, String)>,
) {
// xdr:graphicFrame
write_start_tag(
writer,
Expand All @@ -125,7 +129,7 @@ impl GraphicFrame {
let _ = &self.transform.write_to(writer);

// a:graphic
let _ = &self.graphic.write_to(writer, r_id);
let _ = &self.graphic.write_to(writer, rel_list);

write_end_tag(writer, "xdr:graphicFrame");
}
Expand Down
13 changes: 8 additions & 5 deletions src/structs/drawing/spreadsheet/one_cell_anchor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ impl OneCellAnchor {
}
b"xdr:sp" => {
let mut obj = Shape::default();
obj.set_attributes(reader, e);
obj.set_attributes(reader, e, drawing_relationships);
self.set_shape(obj);
}
b"xdr:pic" => {
Expand All @@ -132,7 +132,11 @@ impl OneCellAnchor {
);
}

pub(crate) fn write_to(&self, writer: &mut Writer<Cursor<Vec<u8>>>, r_id: &mut i32) {
pub(crate) fn write_to(
&self,
writer: &mut Writer<Cursor<Vec<u8>>>,
rel_list: &mut Vec<(String, String)>,
) {
// xdr:oneCellAnchor
write_start_tag(writer, "xdr:oneCellAnchor", vec![], false);

Expand All @@ -144,13 +148,12 @@ impl OneCellAnchor {

// xdr:sp
if let Some(v) = &self.shape {
v.write_to(writer, &0)
v.write_to(writer, rel_list, &0);
}

// xdr:pic
if let Some(v) = &self.picture {
v.write_to(writer, r_id);
*r_id += 1i32;
v.write_to(writer, rel_list);
}

// xdr:clientData
Expand Down
Loading

0 comments on commit c0bc0b6

Please sign in to comment.