use crate::visual::Color;
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum FontWeight {
Normal,
Bold,
}
impl FontWeight {
pub fn as_str(&self) -> &'static str {
match self {
FontWeight::Normal => "normal",
FontWeight::Bold => "bold",
}
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum FontStyle {
Normal,
Italic,
}
impl FontStyle {
pub fn as_str(&self) -> &'static str {
match self {
FontStyle::Normal => "normal",
FontStyle::Italic => "italic",
}
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum TextAlign {
Left,
Center,
Right,
Justify,
}
impl TextAlign {
pub fn as_str(&self) -> &'static str {
match self {
TextAlign::Left => "left",
TextAlign::Center => "center",
TextAlign::Right => "right",
TextAlign::Justify => "justify",
}
}
}
#[derive(Debug, Clone, Copy, PartialEq)]
#[derive(Default)]
pub enum PageBreak {
#[default]
Auto,
Always,
Avoid,
Left,
Right,
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum Display {
Block,
Inline,
InlineBlock,
None,
}
#[derive(Debug, Clone, Copy, PartialEq)]
pub enum ObjectFit {
Contain,
Cover,
Fill,
None,
}
#[derive(Debug, Clone)]
pub struct Style {
pub font_family: Vec<String>,
pub font_size_pt: f32,
pub font_weight: FontWeight,
pub font_style: FontStyle,
pub color: Color,
pub line_height_pt: f32,
pub letter_spacing: f32,
pub text_align: TextAlign,
pub display: Display,
pub margin_top_pt: f32,
pub margin_bottom_pt: f32,
pub margin_left_pt: f32,
pub margin_right_pt: f32,
pub padding_top_pt: f32,
pub padding_bottom_pt: f32,
pub padding_left_pt: f32,
pub padding_right_pt: f32,
pub width: Option<f32>,
pub height: Option<f32>,
pub object_fit: ObjectFit,
pub background_color: Option<Color>,
pub page_break_before: PageBreak,
pub page_break_after: PageBreak,
pub table_border_color: Color,
pub table_border_width_pt: f32,
pub table_cell_padding_h_pt: f32,
pub table_cell_padding_v_pt: f32,
pub table_header_bg: Option<Color>,
pub table_alt_row_bg: Option<Color>,
pub link_url: Option<String>,
pub list_indent_pt: Option<f32>,
}
impl Style {
pub fn inherit_from(parent: &Style) -> Self {
Self {
font_family: parent.font_family.clone(),
font_size_pt: parent.font_size_pt,
font_weight: parent.font_weight,
font_style: parent.font_style,
color: parent.color,
line_height_pt: parent.line_height_pt,
letter_spacing: parent.letter_spacing,
text_align: parent.text_align,
display: Display::Inline,
margin_top_pt: 0.0,
margin_bottom_pt: 0.0,
margin_left_pt: 0.0,
margin_right_pt: 0.0,
padding_top_pt: 0.0,
padding_bottom_pt: 0.0,
padding_left_pt: 0.0,
padding_right_pt: 0.0,
width: None,
height: None,
object_fit: ObjectFit::None,
background_color: None,
page_break_before: parent.page_break_before,
page_break_after: parent.page_break_after,
table_border_color: parent.table_border_color,
table_border_width_pt: parent.table_border_width_pt,
table_cell_padding_h_pt: parent.table_cell_padding_h_pt,
table_cell_padding_v_pt: parent.table_cell_padding_v_pt,
table_header_bg: parent.table_header_bg,
table_alt_row_bg: parent.table_alt_row_bg,
link_url: parent.link_url.clone(),
list_indent_pt: None,
}
}
}
impl Default for Style {
fn default() -> Self {
Self {
font_family: vec!["serif".to_string()],
font_size_pt: 10.5,
font_weight: FontWeight::Normal,
font_style: FontStyle::Normal,
color: Color::new(0, 0, 0),
line_height_pt: 15.75,
letter_spacing: 0.0,
text_align: TextAlign::Left,
display: Display::Block,
margin_top_pt: 0.0,
margin_bottom_pt: 12.0,
margin_left_pt: 0.0,
margin_right_pt: 0.0,
padding_top_pt: 0.0,
padding_bottom_pt: 0.0,
padding_left_pt: 0.0,
padding_right_pt: 0.0,
width: None,
height: None,
object_fit: ObjectFit::Contain,
background_color: None,
page_break_before: PageBreak::Auto,
page_break_after: PageBreak::Auto,
table_border_color: Color::new(180, 180, 180),
table_border_width_pt: 0.5,
table_cell_padding_h_pt: 4.0,
table_cell_padding_v_pt: 2.0,
table_header_bg: None,
table_alt_row_bg: None,
link_url: None,
list_indent_pt: None,
}
}
}
#[derive(Debug, Clone)]
pub struct PageConfig {
pub margin_top: Option<f32>,
pub margin_bottom: Option<f32>,
pub margin_left: Option<f32>,
pub margin_right: Option<f32>,
pub width: Option<f32>,
pub height: Option<f32>,
pub header: Option<String>,
pub footer: Option<String>,
pub header_font_size: Option<f32>,
pub footer_font_size: Option<f32>,
}
impl Default for PageConfig {
fn default() -> Self {
Self {
margin_top: None,
margin_bottom: None,
margin_left: None,
margin_right: None,
width: None,
height: None,
header: None,
footer: Some("- {page} -".to_string()),
header_font_size: None,
footer_font_size: None,
}
}
}