mirror of
https://github.com/typst/typst
synced 2025-05-14 17:15:28 +08:00
Fix invisibles on final page (#2141)
This commit is contained in:
parent
f90701e132
commit
3dd12d13f8
@ -250,7 +250,7 @@ fn realize_root<'a>(
|
|||||||
|
|
||||||
let mut builder = Builder::new(vt, scratch, true);
|
let mut builder = Builder::new(vt, scratch, true);
|
||||||
builder.accept(content, styles)?;
|
builder.accept(content, styles)?;
|
||||||
builder.interrupt_page(Some(styles))?;
|
builder.interrupt_page(Some(styles), true)?;
|
||||||
let (pages, shared) = builder.doc.unwrap().pages.finish();
|
let (pages, shared) = builder.doc.unwrap().pages.finish();
|
||||||
Ok((DocumentElem::new(pages.to_vec()).pack(), shared))
|
Ok((DocumentElem::new(pages.to_vec()).pack(), shared))
|
||||||
}
|
}
|
||||||
@ -375,7 +375,7 @@ impl<'a, 'v, 't> Builder<'a, 'v, 't> {
|
|||||||
.to::<PagebreakElem>()
|
.to::<PagebreakElem>()
|
||||||
.map_or(false, |pagebreak| !pagebreak.weak(styles));
|
.map_or(false, |pagebreak| !pagebreak.weak(styles));
|
||||||
|
|
||||||
self.interrupt_page(keep.then_some(styles))?;
|
self.interrupt_page(keep.then_some(styles), false)?;
|
||||||
|
|
||||||
if let Some(doc) = &mut self.doc {
|
if let Some(doc) = &mut self.doc {
|
||||||
if doc.accept(content, styles) {
|
if doc.accept(content, styles) {
|
||||||
@ -424,7 +424,7 @@ impl<'a, 'v, 't> Builder<'a, 'v, 't> {
|
|||||||
if self.doc.is_none() {
|
if self.doc.is_none() {
|
||||||
bail!(span, "page configuration is not allowed inside of containers");
|
bail!(span, "page configuration is not allowed inside of containers");
|
||||||
}
|
}
|
||||||
self.interrupt_page(outer)?;
|
self.interrupt_page(outer, false)?;
|
||||||
} else if local.interruption::<ParElem>().is_some()
|
} else if local.interruption::<ParElem>().is_some()
|
||||||
|| local.interruption::<AlignElem>().is_some()
|
|| local.interruption::<AlignElem>().is_some()
|
||||||
{
|
{
|
||||||
@ -462,10 +462,14 @@ impl<'a, 'v, 't> Builder<'a, 'v, 't> {
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn interrupt_page(&mut self, styles: Option<StyleChain<'a>>) -> SourceResult<()> {
|
fn interrupt_page(
|
||||||
|
&mut self,
|
||||||
|
styles: Option<StyleChain<'a>>,
|
||||||
|
last: bool,
|
||||||
|
) -> SourceResult<()> {
|
||||||
self.interrupt_par()?;
|
self.interrupt_par()?;
|
||||||
let Some(doc) = &mut self.doc else { return Ok(()) };
|
let Some(doc) = &mut self.doc else { return Ok(()) };
|
||||||
if !self.flow.0.is_basically_empty() || (doc.keep_next && styles.is_some()) {
|
if (doc.keep_next && styles.is_some()) || self.flow.0.has_strong_elements(last) {
|
||||||
let (flow, shared) = mem::take(&mut self.flow).0.finish();
|
let (flow, shared) = mem::take(&mut self.flow).0.finish();
|
||||||
let styles = if shared == StyleChain::default() {
|
let styles = if shared == StyleChain::default() {
|
||||||
styles.unwrap_or_default()
|
styles.unwrap_or_default()
|
||||||
@ -588,7 +592,7 @@ struct ParBuilder<'a>(BehavedBuilder<'a>);
|
|||||||
impl<'a> ParBuilder<'a> {
|
impl<'a> ParBuilder<'a> {
|
||||||
fn accept(&mut self, content: &'a Content, styles: StyleChain<'a>) -> bool {
|
fn accept(&mut self, content: &'a Content, styles: StyleChain<'a>) -> bool {
|
||||||
if content.is::<MetaElem>() {
|
if content.is::<MetaElem>() {
|
||||||
if !self.0.is_basically_empty() {
|
if self.0.has_strong_elements(false) {
|
||||||
self.0.push(content.clone(), styles);
|
self.0.push(content.clone(), styles);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -32,10 +32,11 @@ impl<'a> BehavedBuilder<'a> {
|
|||||||
|
|
||||||
/// Whether the builder is empty except for some weak elements that will
|
/// Whether the builder is empty except for some weak elements that will
|
||||||
/// probably collapse.
|
/// probably collapse.
|
||||||
pub fn is_basically_empty(&self) -> bool {
|
pub fn has_strong_elements(&self, last: bool) -> bool {
|
||||||
self.builder.is_empty()
|
!self.builder.is_empty()
|
||||||
&& self.staged.iter().all(|(_, behaviour, _)| {
|
|| self.staged.iter().any(|(_, behaviour, _)| {
|
||||||
matches!(behaviour, Behaviour::Weak(_) | Behaviour::Invisible)
|
!matches!(behaviour, Behaviour::Weak(_) | Behaviour::Invisible)
|
||||||
|
|| (last && *behaviour == Behaviour::Invisible)
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BIN
tests/ref/bugs/pagebreak-bibliography.png
Normal file
BIN
tests/ref/bugs/pagebreak-bibliography.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.8 KiB |
5
tests/typ/bugs/pagebreak-bibliography.typ
Normal file
5
tests/typ/bugs/pagebreak-bibliography.typ
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
// Test weak pagebreak before bibliography.
|
||||||
|
|
||||||
|
---
|
||||||
|
#pagebreak(weak: true)
|
||||||
|
#bibliography("/files/works.bib")
|
Loading…
x
Reference in New Issue
Block a user