Cap page depth at Document max_depth
This commit is contained in:
1 parent
9599982b91
commit
169119a48d
5 files changed
+66
-10
No files matched your search
@@ -557,6 +557,10 @@ pub struct Document {
|
||||
/// TeX-like `\topskip`: distance from the page top to the first baseline.
|
||||
#[serde(default)]
|
||||
pub top_skip: i64,
|
||||
/// TeX-like `\maxdepth`: depth a page box keeps below the baseline. Deeper
|
||||
/// material moves into the page height, as in TeX's page builder.
|
||||
#[serde(default)]
|
||||
pub max_depth: i64,
|
||||
/// Minimum percentage of the page that text must occupy before a bottom
|
||||
/// float is allowed onto the page (TeX's `\textfraction`, in percent).
|
||||
#[serde(default = "default_text_fraction")]
|
||||
@@ -646,6 +650,7 @@ impl Document {
|
||||
units,
|
||||
page_goal,
|
||||
top_skip: 0,
|
||||
max_depth: 0,
|
||||
text_fraction_percent: default_text_fraction(),
|
||||
float_page_fraction_percent: 50,
|
||||
bottom_fraction_percent: default_bottom_fraction(),
|
||||
@@ -1390,7 +1395,7 @@ impl Engine {
|
||||
let builder = PageBuilder {
|
||||
page_goal: document.page_goal,
|
||||
top_skip: document.top_skip,
|
||||
max_depth: 0,
|
||||
max_depth: document.max_depth,
|
||||
};
|
||||
let mut pages = Vec::new();
|
||||
for fragment in builder.build(&nodes) {
|
||||
@@ -4368,6 +4373,37 @@ mod tests {
|
||||
assert!(engine.pages().iter().all(|page| page.hash != 0));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn paged_layout_limits_page_depth() {
|
||||
let math = Unit {
|
||||
id: 1,
|
||||
source: String::new(),
|
||||
items: vec![VerticalItem::Math {
|
||||
atom: crate::math::MathAtom::Symbol('x'),
|
||||
width: 10,
|
||||
height: 70,
|
||||
depth: 30,
|
||||
}],
|
||||
paragraph_style: None,
|
||||
};
|
||||
let mut document =
|
||||
Document::new(100, vec![math, Unit::vskip(2, 0), Unit::rule(3, 100, 20)]);
|
||||
let deep = Engine::layout_paged(&document).expect("math is page-buildable");
|
||||
assert_eq!(
|
||||
deep.pages().len(),
|
||||
2,
|
||||
"depth beyond maxdepth pushes the rule onto its own page"
|
||||
);
|
||||
|
||||
document.max_depth = 30;
|
||||
let capped = Engine::layout_paged(&document).expect("math is page-buildable");
|
||||
assert_eq!(
|
||||
capped.pages().len(),
|
||||
1,
|
||||
"allowed depth keeps the rule on the first page"
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn paged_layout_refuses_floats_and_insertions() {
|
||||
let floated = Document::new(100, vec![Unit::float(1, FloatPlacement::Top, 100, 20)]);
|
||||
|
||||
Reference in new issue
Block a user