1pub mod autoshape;
38pub mod base;
39pub mod chartshape;
40pub mod connector;
41pub mod freeform;
42pub mod group;
43pub mod oleshape;
44pub mod picture;
45pub mod smartartshape;
46pub mod table;
47pub mod textbox;
48
49pub use autoshape::AutoShape;
50pub use base::Shape;
51pub use chartshape::ChartShape;
52pub use connector::Connector;
53pub use freeform::{Freeform, FreeformBuilder, Point};
54pub use group::{Group, GroupChild};
55pub use oleshape::OleObjectShape;
56pub use picture::Picture;
57pub use smartartshape::SmartArtShape;
58pub use table::{BorderSide, TableShape};
59pub use textbox::TextBox;
60
61pub use crate::oxml::simpletypes::{
63 Alignment, Cap, MsoAnchor, MsoAutoSize, MsoConnectorType, MsoShapeType, PresetGeometry,
64 TextDirection, TextWrapping, Underline,
65};
66
67use crate::oxml::SlideShape as OxmlSlideShape;
68
69#[derive(Clone, Debug)]
74pub enum ShapeKind {
75 TextBox(TextBox),
77 AutoShape(AutoShape),
79 Picture(Picture),
81 Group(Group),
83 Connector(Connector),
85 Table(TableShape),
87 Chart(ChartShape),
89 OleObject(OleObjectShape),
91 SmartArt(SmartArtShape),
93 Placeholder(PlaceholderShape),
95}
96
97#[derive(Clone, Debug)]
103pub struct PlaceholderShape(
104 pub AutoShape,
106);
107
108impl ShapeKind {
109 pub fn shape_type(&self) -> &'static str {
111 match self {
112 ShapeKind::TextBox(_) => "text_box",
113 ShapeKind::AutoShape(_) => "auto_shape",
114 ShapeKind::Picture(_) => "picture",
115 ShapeKind::Group(_) => "group",
116 ShapeKind::Connector(_) => "connector",
117 ShapeKind::Table(_) => "table",
118 ShapeKind::Chart(_) => "chart",
119 ShapeKind::OleObject(_) => "ole_object",
120 ShapeKind::SmartArt(_) => "smart_art",
121 ShapeKind::Placeholder(_) => "placeholder",
122 }
123 }
124
125 pub fn name(&self) -> &str {
127 match self {
128 ShapeKind::TextBox(t) => t.name(),
129 ShapeKind::AutoShape(s) => s.name(),
130 ShapeKind::Picture(p) => p.name(),
131 ShapeKind::Group(g) => g.name(),
132 ShapeKind::Connector(c) => c.name(),
133 ShapeKind::Table(t) => t.name(),
134 ShapeKind::Chart(c) => c.name(),
135 ShapeKind::OleObject(o) => o.name(),
136 ShapeKind::SmartArt(s) => s.name(),
137 ShapeKind::Placeholder(p) => p.0.name(),
138 }
139 }
140
141 pub fn shape_id(&self) -> u32 {
143 match self {
144 ShapeKind::TextBox(t) => t.id(),
145 ShapeKind::AutoShape(s) => s.id(),
146 ShapeKind::Picture(p) => p.id(),
147 ShapeKind::Group(g) => g.id(),
148 ShapeKind::Connector(c) => c.id(),
149 ShapeKind::Table(t) => t.id(),
150 ShapeKind::Chart(c) => c.id(),
151 ShapeKind::OleObject(o) => o.id(),
152 ShapeKind::SmartArt(s) => s.id(),
153 ShapeKind::Placeholder(p) => p.0.id(),
154 }
155 }
156
157 pub fn left(&self) -> crate::units::Emu {
159 match self {
160 ShapeKind::TextBox(t) => t.left(),
161 ShapeKind::AutoShape(s) => s.left(),
162 ShapeKind::Picture(p) => p.left(),
163 ShapeKind::Group(g) => g.left(),
164 ShapeKind::Connector(c) => c.left(),
165 ShapeKind::Table(t) => t.left(),
166 ShapeKind::Chart(c) => c.left(),
167 ShapeKind::OleObject(o) => o.left(),
168 ShapeKind::SmartArt(s) => s.left(),
169 ShapeKind::Placeholder(p) => p.0.left(),
170 }
171 }
172 pub fn top(&self) -> crate::units::Emu {
174 match self {
175 ShapeKind::TextBox(t) => t.top(),
176 ShapeKind::AutoShape(s) => s.top(),
177 ShapeKind::Picture(p) => p.top(),
178 ShapeKind::Group(g) => g.top(),
179 ShapeKind::Connector(c) => c.top(),
180 ShapeKind::Table(t) => t.top(),
181 ShapeKind::Chart(c) => c.top(),
182 ShapeKind::OleObject(o) => o.top(),
183 ShapeKind::SmartArt(s) => s.top(),
184 ShapeKind::Placeholder(p) => p.0.top(),
185 }
186 }
187 pub fn width(&self) -> crate::units::Emu {
189 match self {
190 ShapeKind::TextBox(t) => t.width(),
191 ShapeKind::AutoShape(s) => s.width(),
192 ShapeKind::Picture(p) => p.width(),
193 ShapeKind::Group(g) => g.width(),
194 ShapeKind::Connector(c) => c.width(),
195 ShapeKind::Table(t) => t.width(),
196 ShapeKind::Chart(c) => c.width(),
197 ShapeKind::OleObject(o) => o.width(),
198 ShapeKind::SmartArt(s) => s.width(),
199 ShapeKind::Placeholder(p) => p.0.width(),
200 }
201 }
202 pub fn height(&self) -> crate::units::Emu {
204 match self {
205 ShapeKind::TextBox(t) => t.height(),
206 ShapeKind::AutoShape(s) => s.height(),
207 ShapeKind::Picture(p) => p.height(),
208 ShapeKind::Group(g) => g.height(),
209 ShapeKind::Connector(c) => c.height(),
210 ShapeKind::Table(t) => t.height(),
211 ShapeKind::Chart(c) => c.height(),
212 ShapeKind::OleObject(o) => o.height(),
213 ShapeKind::SmartArt(s) => s.height(),
214 ShapeKind::Placeholder(p) => p.0.height(),
215 }
216 }
217}
218
219pub fn name_of(oxml: &OxmlSlideShape) -> &str {
223 match oxml {
224 OxmlSlideShape::Sp(sp) => &sp.name,
225 OxmlSlideShape::Pic(p) => &p.name,
226 OxmlSlideShape::CxnSp(c) => &c.name,
227 OxmlSlideShape::Group(g) => &g.name,
228 OxmlSlideShape::GraphicFrame(g) => &g.name,
229 }
230}
231
232pub fn wrap(oxml: &OxmlSlideShape) -> ShapeKind {
236 match oxml {
237 OxmlSlideShape::Sp(sp) => {
238 if sp.c_nv_sp_pr_tx_box {
239 ShapeKind::TextBox(TextBox::from_sp(sp.clone()))
240 } else {
241 ShapeKind::AutoShape(AutoShape::from_sp(sp.clone()))
244 }
245 }
246 OxmlSlideShape::Pic(p) => ShapeKind::Picture(Picture::from_pic(p.clone())),
247 OxmlSlideShape::CxnSp(c) => ShapeKind::Connector(Connector::from_cxn(c.clone())),
248 OxmlSlideShape::Group(g) => {
249 let ng = Group {
251 group: (**g).clone(),
252 };
253 ShapeKind::Group(ng)
254 }
255 OxmlSlideShape::GraphicFrame(g) => match &g.graphic {
256 crate::oxml::shape::Graphic::Table(_) => {
257 ShapeKind::Table(TableShape::from_frame(g.clone()))
258 }
259 crate::oxml::shape::Graphic::Chart(_) => {
260 ShapeKind::Chart(ChartShape::from_frame(g.clone()))
261 }
262 crate::oxml::shape::Graphic::OleObject(_) => {
263 ShapeKind::OleObject(OleObjectShape::from_frame(g.clone()))
264 }
265 crate::oxml::shape::Graphic::SmartArt(_) => {
266 ShapeKind::SmartArt(SmartArtShape::from_frame(g.clone()))
267 }
268 },
269 }
270}