Place insertion material at the page bottom
This commit is contained in:
1 parent
159bb6a386
commit
493180125a
3 files changed
+79
-11
No files matched your search
@@ -1371,6 +1371,37 @@ mod tests {
|
|||||||
crate::render::DisplayItem::Rule { width, .. } if *width == 100 * 65_536
|
crate::render::DisplayItem::Rule { width, .. } if *width == 100 * 65_536
|
||||||
)));
|
)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn insertion_material_sits_at_the_page_bottom() {
|
||||||
|
let page = Page {
|
||||||
|
items: vec![
|
||||||
|
VerticalItem::Box(VerticalBox {
|
||||||
|
width: 100 * 65_536,
|
||||||
|
height: 100 * 65_536,
|
||||||
|
}),
|
||||||
|
VerticalItem::Insertion(Insertion {
|
||||||
|
class: 0,
|
||||||
|
height: 20 * 65_536,
|
||||||
|
items: vec![VerticalItem::Rule {
|
||||||
|
width: 100 * 65_536,
|
||||||
|
height: 2 * 65_536,
|
||||||
|
}],
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
insertions: Vec::new(),
|
||||||
|
marks: Vec::new(),
|
||||||
|
floats: Vec::new(),
|
||||||
|
sources: Vec::new(),
|
||||||
|
hash: 0,
|
||||||
|
};
|
||||||
|
let list = page.display_list_with_goal(700 * 65_536);
|
||||||
|
let rule = list.items.iter().find_map(|item| match item {
|
||||||
|
crate::render::DisplayItem::Rule { y, .. } => Some(*y),
|
||||||
|
_ => None,
|
||||||
|
});
|
||||||
|
assert!(rule.expect("insertion rule") >= 697 * 65_536);
|
||||||
|
}
|
||||||
#[test]
|
#[test]
|
||||||
fn link_rectangles_become_pdf_annotations() {
|
fn link_rectangles_become_pdf_annotations() {
|
||||||
use crate::render::DisplayList;
|
use crate::render::DisplayList;
|
||||||
|
|||||||
@@ -230,14 +230,26 @@ impl Page {
|
|||||||
/// Paint the page's vertical material. Paragraph text is not yet part of
|
/// Paint the page's vertical material. Paragraph text is not yet part of
|
||||||
/// the route-D box model, so opaque boxes advance the cursor only.
|
/// the route-D box model, so opaque boxes advance the cursor only.
|
||||||
pub fn display_list(&self) -> DisplayList {
|
pub fn display_list(&self) -> DisplayList {
|
||||||
|
self.display_list_with_goal(0)
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Paint the page, placing insertion material at `page_goal` when it is
|
||||||
|
/// positive. A zero goal keeps insertion material in normal flow.
|
||||||
|
pub fn display_list_with_goal(&self, page_goal: i64) -> DisplayList {
|
||||||
let mut list = DisplayList::default();
|
let mut list = DisplayList::default();
|
||||||
let mut y = 0_i64;
|
let mut y = 0_i64;
|
||||||
let items: Vec<VerticalItem> = self
|
let items: Vec<VerticalItem> = self
|
||||||
|
.items
|
||||||
|
.iter()
|
||||||
|
.filter(|item| !matches!(item, VerticalItem::Insertion(_)))
|
||||||
|
.cloned()
|
||||||
|
.collect();
|
||||||
|
let insertion_items: Vec<VerticalItem> = self
|
||||||
.items
|
.items
|
||||||
.iter()
|
.iter()
|
||||||
.flat_map(|item| match item {
|
.flat_map(|item| match item {
|
||||||
VerticalItem::Insertion(insertion) => insertion.items.clone(),
|
VerticalItem::Insertion(insertion) => insertion.items.clone(),
|
||||||
_ => vec![item.clone()],
|
_ => Vec::new(),
|
||||||
})
|
})
|
||||||
.collect();
|
.collect();
|
||||||
for item in &items {
|
for item in &items {
|
||||||
@@ -307,16 +319,39 @@ impl Page {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
list.width = self
|
if !insertion_items.is_empty() {
|
||||||
.items
|
let insertion_page = Page {
|
||||||
.iter()
|
items: insertion_items,
|
||||||
.map(|item| match item {
|
insertions: Vec::new(),
|
||||||
VerticalItem::Halign(halign) => halign.width,
|
marks: Vec::new(),
|
||||||
VerticalItem::Rule { width, .. } => *width,
|
floats: Vec::new(),
|
||||||
_ => 0,
|
sources: Vec::new(),
|
||||||
})
|
hash: 0,
|
||||||
.max()
|
};
|
||||||
.unwrap_or(0);
|
let mut insertion_list = insertion_page.display_list();
|
||||||
|
let top = if page_goal > 0 {
|
||||||
|
(page_goal - insertion_list.height).max(y)
|
||||||
|
} else {
|
||||||
|
y
|
||||||
|
};
|
||||||
|
insertion_list.place(0, top);
|
||||||
|
let width = insertion_list.width.max(list.width);
|
||||||
|
y = top + insertion_list.height;
|
||||||
|
list.items.extend(insertion_list.items);
|
||||||
|
list.images.extend(insertion_list.images);
|
||||||
|
list.width = list.width.max(width);
|
||||||
|
}
|
||||||
|
list.width = list.width.max(
|
||||||
|
self.items
|
||||||
|
.iter()
|
||||||
|
.map(|item| match item {
|
||||||
|
VerticalItem::Halign(halign) => halign.width,
|
||||||
|
VerticalItem::Rule { width, .. } => *width,
|
||||||
|
_ => 0,
|
||||||
|
})
|
||||||
|
.max()
|
||||||
|
.unwrap_or(0),
|
||||||
|
);
|
||||||
list.height = y;
|
list.height = y;
|
||||||
list
|
list
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -259,3 +259,5 @@ M6 (partial): display-list Link rectangles become PDF /Annots /Subtype /Link /UR
|
|||||||
M7 (partial): DisplayList::special injects raw PDF content-stream operators; SVG previews show a comment. Driver-level \special parsing and coordinate transforms remain.
|
M7 (partial): DisplayList::special injects raw PDF content-stream operators; SVG previews show a comment. Driver-level \special parsing and coordinate transforms remain.
|
||||||
|
|
||||||
M2 (partial): insertion material is expanded into the page display list at its reserved position, so footnote/float material is no longer dropped by the painter; page-bottom placement and rules remain to be modelled.
|
M2 (partial): insertion material is expanded into the page display list at its reserved position, so footnote/float material is no longer dropped by the painter; page-bottom placement and rules remain to be modelled.
|
||||||
|
|
||||||
|
M2 (partial): Page::display_list_with_goal places insertion material at page_goal minus its height; page builders can pass the real goal. Footnote rules and float-page policy remain.
|
||||||
Reference in new issue
Block a user