ferri-pdf 0.2.1

HTML and CSS to PDF renderer for print, in pure Rust
Documentation
use crate::dom::ElementId;
use crate::style::{
    CaptionSide, Display, GeneratedContent, Page, Position, PseudoElement, Quotes, StyleError,
    WhiteSpaceCollapse,
};

#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq)]
pub(crate) struct PageStyleTarget {
    pub element: ElementId,
    pub pseudo: Option<PseudoElement>,
}

/// On-demand computed values used by generated-box first-page selection.
pub(crate) trait PageSelection {
    fn display(&self, target: PageStyleTarget) -> Result<Display, StyleError>;
    fn position(&self, target: PageStyleTarget) -> Result<Position, StyleError>;
    fn page(&self, target: PageStyleTarget) -> Result<Page, StyleError>;
    fn break_before(
        &self,
        target: PageStyleTarget,
    ) -> Result<crate::style::BreakBetween, StyleError>;
    fn progression_rtl(&self) -> Result<bool, StyleError>;
    fn order(&self, target: PageStyleTarget) -> Result<i32, StyleError>;
    fn caption_side(&self, target: PageStyleTarget) -> Result<CaptionSide, StyleError>;
    fn white_space_collapse(
        &self,
        target: PageStyleTarget,
    ) -> Result<WhiteSpaceCollapse, StyleError>;
    fn content(&self, target: PageStyleTarget) -> Result<Option<GeneratedContent>, StyleError>;
    fn bookmark_label(
        &self,
        target: PageStyleTarget,
    ) -> Result<Option<GeneratedContent>, StyleError>;
    fn string_set(
        &self,
        target: PageStyleTarget,
    ) -> Result<std::sync::Arc<[crate::style::StringAssignment]>, StyleError>;
    fn counter_scopes(
        &self,
        target: PageStyleTarget,
    ) -> Result<crate::style::CounterScopes, StyleError>;
    fn counters(
        &self,
        target: PageStyleTarget,
    ) -> Result<crate::style::CounterProperties, StyleError>;
    fn quotes(&self, target: PageStyleTarget) -> Result<Quotes, StyleError>;
    /// Whether the target's style containment scopes its descendants' counters.
    fn style_containment(&self, target: PageStyleTarget) -> Result<bool, StyleError>;
    fn inline_edges(
        &self,
        target: PageStyleTarget,
        continued: [bool; 2],
    ) -> Result<bool, StyleError>;
    fn tab_size(&self, target: PageStyleTarget) -> Result<crate::style::TabSize, StyleError>;
    fn inside_marker(&self, target: PageStyleTarget) -> Result<bool, StyleError>;
}

/// The first page's used name and the page groups its content starts there (CSS GCPM 3
/// ยง3.2), outermost first.
#[derive(Debug, Default)]
pub(crate) struct FirstPageStart {
    pub name: Option<std::sync::Arc<str>>,
    pub groups: Vec<std::sync::Arc<str>>,
}

/// Selects the first page's start; the page groups only when the flag requests them.
pub(crate) type SelectFirstPageName<'a> =
    dyn Fn(&dyn PageSelection, bool) -> Result<FirstPageStart, StyleError> + 'a;
pub(crate) type SelectFirstPageSide<'a> =
    dyn Fn(&dyn PageSelection) -> Result<crate::style::PageSide, StyleError> + 'a;