use std::rc::Rc;
use crate::color::{Color, RgbaColor};
use crate::font::{
FontFamily, FontStretch, FontStyle, FontVariant, FontWeight, VerticalFontMetric,
};
use crate::geom::*;
use crate::layout::Paint;
use crate::paper::{PaperClass, PAPER_A4};
/// Defines an set of properties a template can be instantiated with.
#[derive(Debug, Clone, Eq, PartialEq, Hash)]
pub struct State {
/// The direction for text and other inline objects.
pub dirs: Gen
,
/// The alignments of layouts in their parents.
pub aligns: Gen,
/// The page settings.
pub page: Rc,
/// The paragraph settings.
pub par: Rc,
/// The font settings.
pub font: Rc,
}
impl State {
/// Access the `page` state mutably.
pub fn page_mut(&mut self) -> &mut PageState {
Rc::make_mut(&mut self.page)
}
/// Access the `par` state mutably.
pub fn par_mut(&mut self) -> &mut ParState {
Rc::make_mut(&mut self.par)
}
/// Access the `font` state mutably.
pub fn font_mut(&mut self) -> &mut FontState {
Rc::make_mut(&mut self.font)
}
/// The resolved line spacing.
pub fn line_spacing(&self) -> Length {
self.par.line_spacing.resolve(self.font.size)
}
/// The resolved paragraph spacing.
pub fn par_spacing(&self) -> Length {
self.par.par_spacing.resolve(self.font.size)
}
}
impl Default for State {
fn default() -> Self {
Self {
dirs: Gen::new(Dir::LTR, Dir::TTB),
aligns: Gen::splat(Align::Start),
page: Rc::new(PageState::default()),
par: Rc::new(ParState::default()),
font: Rc::new(FontState::default()),
}
}
}
/// Defines page properties.
#[derive(Debug, Copy, Clone, Eq, PartialEq, Hash)]
pub struct PageState {
/// The class of this page.
pub class: PaperClass,
/// The width and height of the page.
pub size: Size,
/// The amount of white space on each side of the page. If a side is set to
/// `None`, the default for the paper class is used.
pub margins: Sides