summaryrefslogtreecommitdiff
path: root/src/library/structure/doc.rs
blob: d3fc0b3911e9d83638db100d83df16da84e04d0c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
use crate::library::layout::PageNode;
use crate::library::prelude::*;

/// A sequence of page runs.
#[derive(Hash)]
pub struct DocNode(pub StyleVec<PageNode>);

impl DocNode {
    /// Layout the document into a sequence of frames, one per page.
    pub fn layout(
        &self,
        ctx: &mut Context,
        styles: StyleChain,
    ) -> TypResult<Vec<Arc<Frame>>> {
        let mut frames = vec![];
        for (page, map) in self.0.iter() {
            let number = 1 + frames.len();
            frames.extend(page.layout(ctx, number, map.chain(&styles))?);
        }
        Ok(frames)
    }
}

impl Debug for DocNode {
    fn fmt(&self, f: &mut Formatter) -> fmt::Result {
        f.write_str("Doc ")?;
        self.0.fmt(f)
    }
}