use std::collections::BTreeMap;
use super::style::{Alignment, Color, ParagraphStyle, TextStyle};
#[derive(Debug, Clone)]
pub struct HeaderFooter {
pub paragraphs: Vec<HeaderFooterParagraph>,
}
#[derive(Debug, Clone)]
pub struct HeaderFooterParagraph {
pub style: ParagraphStyle,
pub elements: Vec<HFInline>,
}
#[derive(Debug, Clone)]
pub enum HFInline {
Run(Run),
PageNumber,
TotalPages,
}
#[derive(Debug, Clone)]
pub enum Block {
Paragraph(Paragraph),
Table(Table),
Image(ImageData),
FloatingImage(FloatingImage),
FloatingTextBox(FloatingTextBox),
List(List),
MathEquation(MathEquation),
Chart(Chart),
PageBreak,
ColumnBreak,
}
#[derive(Debug, Clone)]
pub struct Chart {
pub chart_type: ChartType,
pub title: Option<String>,
pub categories: Vec<String>,
pub series: Vec<ChartSeries>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum ChartType {
Bar,
Column,
Line,
Pie,
Area,
Scatter,
Other(String),
}
#[derive(Debug, Clone)]
pub struct ChartSeries {
pub name: Option<String>,
pub values: Vec<f64>,
}
#[derive(Debug, Clone)]
pub struct MathEquation {
pub content: String,
pub display: bool,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum WrapMode {
Square,
Tight,
TopAndBottom,
Behind,
InFront,
None,
}
#[derive(Debug, Clone)]
pub struct FloatingImage {
pub image: ImageData,
pub wrap_mode: WrapMode,
pub offset_x: f64,
pub offset_y: f64,
}
#[derive(Debug, Clone)]
pub struct FloatingTextBox {
pub content: Vec<Block>,
pub wrap_mode: WrapMode,
pub width: f64,
pub height: f64,
pub offset_x: f64,
pub offset_y: f64,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum TextBoxVerticalAlign {
#[default]
Top,
Center,
Bottom,
}
#[derive(Debug, Clone)]
pub struct TextBoxData {
pub content: Vec<Block>,
pub padding: Insets,
pub vertical_align: TextBoxVerticalAlign,
pub fill: Option<Color>,
pub opacity: Option<f64>,
pub stroke: Option<BorderSide>,
pub shape_kind: Option<ShapeKind>,
pub no_wrap: bool,
pub auto_fit: bool,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ListKind {
Ordered,
Unordered,
}
#[derive(Debug, Clone, PartialEq)]
pub struct ListLevelStyle {
pub kind: ListKind,
pub numbering_pattern: Option<String>,
pub full_numbering: bool,
pub marker_text: Option<String>,
pub marker_style: Option<TextStyle>,
}
#[derive(Debug, Clone)]
pub struct List {
pub kind: ListKind,
pub items: Vec<ListItem>,
pub level_styles: BTreeMap<u32, ListLevelStyle>,
}
#[derive(Debug, Clone)]
pub struct ListItem {
pub content: Vec<Paragraph>,
pub level: u32,
pub start_at: Option<u32>,
}
#[derive(Debug, Clone)]
pub struct Paragraph {
pub style: ParagraphStyle,
pub runs: Vec<Run>,
}
#[derive(Debug, Clone)]
pub struct Run {
pub text: String,
pub style: TextStyle,
pub href: Option<String>,
pub footnote: Option<String>,
}
#[derive(Debug, Clone, Default)]
pub struct Table {
pub rows: Vec<TableRow>,
pub column_widths: Vec<f64>,
pub header_row_count: usize,
pub alignment: Option<Alignment>,
pub default_cell_padding: Option<Insets>,
pub use_content_driven_row_heights: bool,
}
#[derive(Debug, Clone)]
pub struct TableRow {
pub cells: Vec<TableCell>,
pub height: Option<f64>,
}
#[derive(Debug, Clone)]
pub struct DataBarInfo {
pub color: Color,
pub fill_pct: f64,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum CellVerticalAlign {
Top,
Center,
Bottom,
}
#[derive(Debug, Clone, Copy, PartialEq, Default)]
pub struct Insets {
pub top: f64,
pub right: f64,
pub bottom: f64,
pub left: f64,
}
#[derive(Debug, Clone)]
pub struct TableCell {
pub content: Vec<Block>,
pub col_span: u32,
pub row_span: u32,
pub border: Option<CellBorder>,
pub background: Option<Color>,
pub data_bar: Option<DataBarInfo>,
pub icon_text: Option<String>,
pub vertical_align: Option<CellVerticalAlign>,
pub padding: Option<Insets>,
}
impl Default for TableCell {
fn default() -> Self {
Self {
content: Vec::new(),
col_span: 1,
row_span: 1,
border: None,
background: None,
data_bar: None,
icon_text: None,
vertical_align: None,
padding: None,
}
}
}
#[derive(Debug, Clone)]
pub struct CellBorder {
pub top: Option<BorderSide>,
pub bottom: Option<BorderSide>,
pub left: Option<BorderSide>,
pub right: Option<BorderSide>,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum BorderLineStyle {
#[default]
Solid,
Dashed,
Dotted,
DashDot,
DashDotDot,
Double,
None,
}
#[derive(Debug, Clone)]
pub struct BorderSide {
pub width: f64,
pub color: Color,
pub style: BorderLineStyle,
}
#[derive(Debug, Clone, Copy, PartialEq, Default)]
pub struct ImageCrop {
pub left: f64,
pub top: f64,
pub right: f64,
pub bottom: f64,
}
impl ImageCrop {
pub fn is_empty(&self) -> bool {
self.left == 0.0 && self.top == 0.0 && self.right == 0.0 && self.bottom == 0.0
}
}
#[derive(Debug, Clone)]
pub struct ImageData {
pub data: Vec<u8>,
pub format: ImageFormat,
pub width: Option<f64>,
pub height: Option<f64>,
pub crop: Option<ImageCrop>,
pub stroke: Option<BorderSide>,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum ImageFormat {
Png,
Jpeg,
Gif,
Bmp,
Tiff,
Svg,
}
impl ImageFormat {
pub fn extension(&self) -> &'static str {
match self {
Self::Png => "png",
Self::Jpeg => "jpeg",
Self::Gif => "gif",
Self::Bmp => "bmp",
Self::Tiff => "tiff",
Self::Svg => "svg",
}
}
}
#[derive(Debug, Clone, PartialEq)]
pub struct SmartArtNode {
pub text: String,
pub depth: usize,
}
#[derive(Debug, Clone)]
pub struct SmartArt {
pub items: Vec<SmartArtNode>,
}
#[derive(Debug, Clone)]
pub struct GradientStop {
pub position: f64,
pub color: Color,
}
#[derive(Debug, Clone)]
pub struct GradientFill {
pub stops: Vec<GradientStop>,
pub angle: f64,
}
#[derive(Debug, Clone)]
pub struct Shadow {
pub blur_radius: f64,
pub distance: f64,
pub direction: f64,
pub color: Color,
pub opacity: f64,
}
#[derive(Debug, Clone)]
pub struct Shape {
pub kind: ShapeKind,
pub fill: Option<Color>,
pub gradient_fill: Option<GradientFill>,
pub stroke: Option<BorderSide>,
pub rotation_deg: Option<f64>,
pub opacity: Option<f64>,
pub shadow: Option<Shadow>,
}
#[derive(Debug, Clone)]
pub enum ShapeKind {
Rectangle,
Ellipse,
Line {
x1: f64,
y1: f64,
x2: f64,
y2: f64,
head_end: ArrowHead,
tail_end: ArrowHead,
},
Polyline {
points: Vec<(f64, f64)>,
head_end: ArrowHead,
tail_end: ArrowHead,
},
RoundedRectangle {
radius_fraction: f64,
},
Polygon {
vertices: Vec<(f64, f64)>,
},
}
#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
pub enum ArrowHead {
#[default]
None,
Triangle,
}
#[cfg(test)]
#[path = "elements_tests.rs"]
mod tests;