pub mod autoshape;
pub mod base;
pub mod chartshape;
pub mod connector;
pub mod freeform;
pub mod group;
pub mod oleshape;
pub mod picture;
pub mod smartartshape;
pub mod table;
pub mod textbox;
pub use autoshape::AutoShape;
pub use base::Shape;
pub use chartshape::ChartShape;
pub use connector::Connector;
pub use freeform::{Freeform, FreeformBuilder, Point};
pub use group::{Group, GroupChild};
pub use oleshape::OleObjectShape;
pub use picture::Picture;
pub use smartartshape::SmartArtShape;
pub use table::{BorderSide, TableShape};
pub use textbox::TextBox;
pub use crate::oxml::simpletypes::{
Alignment, Cap, MsoAnchor, MsoAutoSize, MsoConnectorType, MsoShapeType, PresetGeometry,
TextDirection, TextWrapping, Underline,
};
use crate::oxml::SlideShape as OxmlSlideShape;
#[derive(Clone, Debug)]
pub enum ShapeKind {
TextBox(TextBox),
AutoShape(AutoShape),
Picture(Picture),
Group(Group),
Connector(Connector),
Table(TableShape),
Chart(ChartShape),
OleObject(OleObjectShape),
SmartArt(SmartArtShape),
Placeholder(PlaceholderShape),
}
#[derive(Clone, Debug)]
pub struct PlaceholderShape(
pub AutoShape,
);
impl ShapeKind {
pub fn shape_type(&self) -> &'static str {
match self {
ShapeKind::TextBox(_) => "text_box",
ShapeKind::AutoShape(_) => "auto_shape",
ShapeKind::Picture(_) => "picture",
ShapeKind::Group(_) => "group",
ShapeKind::Connector(_) => "connector",
ShapeKind::Table(_) => "table",
ShapeKind::Chart(_) => "chart",
ShapeKind::OleObject(_) => "ole_object",
ShapeKind::SmartArt(_) => "smart_art",
ShapeKind::Placeholder(_) => "placeholder",
}
}
pub fn name(&self) -> &str {
match self {
ShapeKind::TextBox(t) => t.name(),
ShapeKind::AutoShape(s) => s.name(),
ShapeKind::Picture(p) => p.name(),
ShapeKind::Group(g) => g.name(),
ShapeKind::Connector(c) => c.name(),
ShapeKind::Table(t) => t.name(),
ShapeKind::Chart(c) => c.name(),
ShapeKind::OleObject(o) => o.name(),
ShapeKind::SmartArt(s) => s.name(),
ShapeKind::Placeholder(p) => p.0.name(),
}
}
pub fn shape_id(&self) -> u32 {
match self {
ShapeKind::TextBox(t) => t.id(),
ShapeKind::AutoShape(s) => s.id(),
ShapeKind::Picture(p) => p.id(),
ShapeKind::Group(g) => g.id(),
ShapeKind::Connector(c) => c.id(),
ShapeKind::Table(t) => t.id(),
ShapeKind::Chart(c) => c.id(),
ShapeKind::OleObject(o) => o.id(),
ShapeKind::SmartArt(s) => s.id(),
ShapeKind::Placeholder(p) => p.0.id(),
}
}
pub fn left(&self) -> crate::units::Emu {
match self {
ShapeKind::TextBox(t) => t.left(),
ShapeKind::AutoShape(s) => s.left(),
ShapeKind::Picture(p) => p.left(),
ShapeKind::Group(g) => g.left(),
ShapeKind::Connector(c) => c.left(),
ShapeKind::Table(t) => t.left(),
ShapeKind::Chart(c) => c.left(),
ShapeKind::OleObject(o) => o.left(),
ShapeKind::SmartArt(s) => s.left(),
ShapeKind::Placeholder(p) => p.0.left(),
}
}
pub fn top(&self) -> crate::units::Emu {
match self {
ShapeKind::TextBox(t) => t.top(),
ShapeKind::AutoShape(s) => s.top(),
ShapeKind::Picture(p) => p.top(),
ShapeKind::Group(g) => g.top(),
ShapeKind::Connector(c) => c.top(),
ShapeKind::Table(t) => t.top(),
ShapeKind::Chart(c) => c.top(),
ShapeKind::OleObject(o) => o.top(),
ShapeKind::SmartArt(s) => s.top(),
ShapeKind::Placeholder(p) => p.0.top(),
}
}
pub fn width(&self) -> crate::units::Emu {
match self {
ShapeKind::TextBox(t) => t.width(),
ShapeKind::AutoShape(s) => s.width(),
ShapeKind::Picture(p) => p.width(),
ShapeKind::Group(g) => g.width(),
ShapeKind::Connector(c) => c.width(),
ShapeKind::Table(t) => t.width(),
ShapeKind::Chart(c) => c.width(),
ShapeKind::OleObject(o) => o.width(),
ShapeKind::SmartArt(s) => s.width(),
ShapeKind::Placeholder(p) => p.0.width(),
}
}
pub fn height(&self) -> crate::units::Emu {
match self {
ShapeKind::TextBox(t) => t.height(),
ShapeKind::AutoShape(s) => s.height(),
ShapeKind::Picture(p) => p.height(),
ShapeKind::Group(g) => g.height(),
ShapeKind::Connector(c) => c.height(),
ShapeKind::Table(t) => t.height(),
ShapeKind::Chart(c) => c.height(),
ShapeKind::OleObject(o) => o.height(),
ShapeKind::SmartArt(s) => s.height(),
ShapeKind::Placeholder(p) => p.0.height(),
}
}
}
pub fn name_of(oxml: &OxmlSlideShape) -> &str {
match oxml {
OxmlSlideShape::Sp(sp) => &sp.name,
OxmlSlideShape::Pic(p) => &p.name,
OxmlSlideShape::CxnSp(c) => &c.name,
OxmlSlideShape::Group(g) => &g.name,
OxmlSlideShape::GraphicFrame(g) => &g.name,
}
}
pub fn wrap(oxml: &OxmlSlideShape) -> ShapeKind {
match oxml {
OxmlSlideShape::Sp(sp) => {
if sp.c_nv_sp_pr_tx_box {
ShapeKind::TextBox(TextBox::from_sp(sp.clone()))
} else {
ShapeKind::AutoShape(AutoShape::from_sp(sp.clone()))
}
}
OxmlSlideShape::Pic(p) => ShapeKind::Picture(Picture::from_pic(p.clone())),
OxmlSlideShape::CxnSp(c) => ShapeKind::Connector(Connector::from_cxn(c.clone())),
OxmlSlideShape::Group(g) => {
let ng = Group {
group: (**g).clone(),
};
ShapeKind::Group(ng)
}
OxmlSlideShape::GraphicFrame(g) => match &g.graphic {
crate::oxml::shape::Graphic::Table(_) => {
ShapeKind::Table(TableShape::from_frame(g.clone()))
}
crate::oxml::shape::Graphic::Chart(_) => {
ShapeKind::Chart(ChartShape::from_frame(g.clone()))
}
crate::oxml::shape::Graphic::OleObject(_) => {
ShapeKind::OleObject(OleObjectShape::from_frame(g.clone()))
}
crate::oxml::shape::Graphic::SmartArt(_) => {
ShapeKind::SmartArt(SmartArtShape::from_frame(g.clone()))
}
},
}
}