Soft pagebreak

This commit is contained in:
Laurenz 2022-04-24 21:58:45 +02:00
parent 2f33ad0e0a
commit 7163b4a6c5
4 changed files with 31 additions and 8 deletions

View File

@ -164,8 +164,9 @@ pub struct PagebreakNode;
#[node]
impl PagebreakNode {
fn construct(_: &mut Context, _: &mut Args) -> TypResult<Content> {
Ok(Content::Pagebreak)
fn construct(_: &mut Context, args: &mut Args) -> TypResult<Content> {
let soft = args.named("soft")?.unwrap_or(false);
Ok(Content::Pagebreak(soft))
}
}

View File

@ -63,7 +63,7 @@ pub enum Content {
/// An item in an ordered list.
Enum(ListItem),
/// A page break.
Pagebreak,
Pagebreak(bool),
/// A page node.
Page(PageNode),
/// A node that can be realized with styles.
@ -262,7 +262,7 @@ impl Debug for Content {
f.write_str(". ")?;
item.body.fmt(f)
}
Self::Pagebreak => f.pad("Pagebreak"),
Self::Pagebreak(soft) => write!(f, "Pagebreak({soft})"),
Self::Page(page) => page.fmt(f),
Self::Show(node) => {
f.write_str("Show(")?;
@ -463,8 +463,8 @@ impl<'a> Builder<'a> {
staged: vec![],
});
}
Content::Pagebreak => {
self.finish_page(ctx, true, true, styles)?;
Content::Pagebreak(soft) => {
self.finish_page(ctx, !soft, !soft, styles)?;
}
Content::Page(page) => {
self.finish_page(ctx, false, false, styles)?;

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.1 KiB

After

Width:  |  Height:  |  Size: 8.4 KiB

View File

@ -2,18 +2,29 @@
---
// Just a pagebreak.
// Should result in two auto-sized pages.
// Should result in two pages.
#pagebreak()
---
// Pagebreak, empty with styles and then pagebreak
// Should result in one auto-sized page and two conifer-colored A11 pages.
// Should result in one auto-sized page and two conifer-colored 2cm wide pages.
#pagebreak()
#set page(width: 2cm, fill: conifer)
#pagebreak()
---
// Two text bodies separated with and surrounded by soft pagebreaks.
// Should result in two aqua-colored pages.
#set page(fill: aqua)
#pagebreak(soft: true)
First
#pagebreak(soft: true)
Second
#pagebreak(soft: true)
---
// Test a combination of pagebreaks, styled pages and pages with bodies.
// Should result in three five pages, with the fourth one being forest-colored.
#set page(width: 80pt, height: 30pt)
[#set page(width: 60pt); First]
#pagebreak()
@ -21,3 +32,14 @@
Third
#page(height: 20pt, fill: forest)[]
Fif[#set page();th]
---
// Test hard and soft pagebreak followed by page with body.
// Should result in three navy-colored pages.
#set page(fill: navy)
#set text(fill: white)
First
#pagebreak()
#page[Second]
#pagebreak(soft: true)
#page[Third]