diff options
| author | LU Jialin <luxxxlucy@gmail.com> | 2023-09-25 20:13:54 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-09-25 14:13:54 +0200 |
| commit | 079ccd5e5b8558b177c8b583948c60d75e3f547f (patch) | |
| tree | c505cfd8c04961929b0b5f03e69a43aa93ebf47b /crates | |
| parent | 98e5d9750923fa05ff2ab39a55e3b48ddd5b9ed8 (diff) | |
Fixing the styling issues of the empty pages caused by pagebreak (#2182)
Diffstat (limited to 'crates')
| -rw-r--r-- | crates/typst-library/src/layout/page.rs | 10 | ||||
| -rw-r--r-- | crates/typst-library/src/meta/document.rs | 13 |
2 files changed, 15 insertions, 8 deletions
diff --git a/crates/typst-library/src/layout/page.rs b/crates/typst-library/src/layout/page.rs index 05d0731d..19184d22 100644 --- a/crates/typst-library/src/layout/page.rs +++ b/crates/typst-library/src/layout/page.rs @@ -310,7 +310,6 @@ pub struct PageElem { pub body: Content, /// Whether the page should be aligned to an even or odd page. - /// Not part of the public API for now. #[internal] pub clear_to: Option<Parity>, } @@ -328,6 +327,7 @@ impl PageElem { vt: &mut Vt, styles: StyleChain, page_counter: &mut ManualPageCounter, + extend_to: Option<Parity>, ) -> SourceResult<Fragment> { tracing::info!("Page layout"); @@ -378,12 +378,10 @@ impl PageElem { let mut frames = child.layout(vt, styles, regions)?.into_frames(); // Align the child to the pagebreak's parity. - if self - .clear_to(styles) - .is_some_and(|p| !p.matches(page_counter.physical().get())) - { + if extend_to.is_some_and(|p| p.matches(page_counter.physical().get())) { + // Insert empty page after the current pages. let size = area.map(Abs::is_finite).select(area, Size::zero()); - frames.insert(0, Frame::new(size)); + frames.push(Frame::new(size)); } let fill = self.fill(styles); diff --git a/crates/typst-library/src/meta/document.rs b/crates/typst-library/src/meta/document.rs index 01095dc9..200b5d9d 100644 --- a/crates/typst-library/src/meta/document.rs +++ b/crates/typst-library/src/meta/document.rs @@ -48,7 +48,10 @@ impl LayoutRoot for DocumentElem { let mut pages = vec![]; let mut page_counter = ManualPageCounter::new(); - for mut child in &self.children() { + let children = self.children(); + let mut iter = children.iter().peekable(); + + while let Some(mut child) = iter.next() { let outer = styles; let mut styles = styles; if let Some((elem, local)) = child.to_styled() { @@ -57,7 +60,13 @@ impl LayoutRoot for DocumentElem { } if let Some(page) = child.to::<PageElem>() { - let fragment = page.layout(vt, styles, &mut page_counter)?; + let extend_to = iter.peek().and_then(|&next| { + next.to_styled() + .map_or(next, |(elem, _)| elem) + .to::<PageElem>()? + .clear_to(styles) + }); + let fragment = page.layout(vt, styles, &mut page_counter, extend_to)?; pages.extend(fragment); } else { bail!(child.span(), "unexpected document child"); |
