Place late top floats on the current page when they fit
This commit is contained in:
1 parent
484375fa2b
commit
5b4eadb88f
2 files changed
+86
-6
No files matched your search
@@ -993,6 +993,22 @@ impl Engine {
|
|||||||
}
|
}
|
||||||
VerticalItem::Float(float) => {
|
VerticalItem::Float(float) => {
|
||||||
if float.placement == FloatPlacement::Top {
|
if float.placement == FloatPlacement::Top {
|
||||||
|
let existing_top: i64 = current
|
||||||
|
.floats
|
||||||
|
.iter()
|
||||||
|
.filter(|entry| entry.placement == FloatPlacement::Top)
|
||||||
|
.map(|entry| entry.height)
|
||||||
|
.sum();
|
||||||
|
let fits_on_current = !current.items.is_empty()
|
||||||
|
&& used + float.height <= document.page_goal - insertion_height
|
||||||
|
&& (existing_top + float.height) * 100
|
||||||
|
<= i64::from(document.top_fraction_percent)
|
||||||
|
* document.page_goal;
|
||||||
|
if fits_on_current {
|
||||||
|
used += float.height;
|
||||||
|
current.floats.push(float.clone());
|
||||||
|
continue;
|
||||||
|
}
|
||||||
if !current.items.is_empty() || !current.insertions.is_empty() {
|
if !current.items.is_empty() || !current.insertions.is_empty() {
|
||||||
pages.push(std::mem::replace(&mut current, Page::empty()));
|
pages.push(std::mem::replace(&mut current, Page::empty()));
|
||||||
used = document.top_skip;
|
used = document.top_skip;
|
||||||
@@ -1295,6 +1311,21 @@ impl Engine {
|
|||||||
}
|
}
|
||||||
VerticalItem::Float(float) => {
|
VerticalItem::Float(float) => {
|
||||||
if float.placement == FloatPlacement::Top {
|
if float.placement == FloatPlacement::Top {
|
||||||
|
let existing_top: i64 = current
|
||||||
|
.floats
|
||||||
|
.iter()
|
||||||
|
.filter(|entry| entry.placement == FloatPlacement::Top)
|
||||||
|
.map(|entry| entry.height)
|
||||||
|
.sum();
|
||||||
|
let fits_on_current = !current.items.is_empty()
|
||||||
|
&& used + float.height <= next.page_goal - insertion_height
|
||||||
|
&& (existing_top + float.height) * 100
|
||||||
|
<= i64::from(next.top_fraction_percent) * next.page_goal;
|
||||||
|
if fits_on_current {
|
||||||
|
used += float.height;
|
||||||
|
current.floats.push(float.clone());
|
||||||
|
continue;
|
||||||
|
}
|
||||||
if !current.items.is_empty() || !current.insertions.is_empty() {
|
if !current.items.is_empty() || !current.insertions.is_empty() {
|
||||||
pages.push(std::mem::replace(&mut current, Page::empty()));
|
pages.push(std::mem::replace(&mut current, Page::empty()));
|
||||||
used = next.top_skip;
|
used = next.top_skip;
|
||||||
@@ -1606,7 +1637,38 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn top_float_starts_a_new_page_when_it_arrives_late() {
|
fn top_float_starts_a_new_page_when_it_cannot_fit() {
|
||||||
|
let unit = Unit {
|
||||||
|
id: 0,
|
||||||
|
source: "float".to_owned(),
|
||||||
|
paragraph_style: None,
|
||||||
|
items: vec![
|
||||||
|
VerticalItem::Box(VerticalBox {
|
||||||
|
width: 10,
|
||||||
|
height: 10,
|
||||||
|
}),
|
||||||
|
VerticalItem::Float(Float {
|
||||||
|
placement: FloatPlacement::Top,
|
||||||
|
width: 40,
|
||||||
|
height: 95,
|
||||||
|
content: Vec::new(),
|
||||||
|
}),
|
||||||
|
VerticalItem::Box(VerticalBox {
|
||||||
|
width: 10,
|
||||||
|
height: 10,
|
||||||
|
}),
|
||||||
|
],
|
||||||
|
};
|
||||||
|
let engine = Engine::layout(&Document::new(100, vec![unit]));
|
||||||
|
assert_eq!(engine.layout.pages.len(), 3);
|
||||||
|
assert_eq!(engine.layout.pages[0].items.len(), 1);
|
||||||
|
assert_eq!(engine.layout.pages[1].floats.len(), 1);
|
||||||
|
assert_eq!(engine.layout.pages[1].items.len(), 0);
|
||||||
|
assert_eq!(engine.layout.pages[2].items.len(), 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn a_late_top_float_that_fits_joins_the_current_page() {
|
||||||
let unit = Unit {
|
let unit = Unit {
|
||||||
id: 0,
|
id: 0,
|
||||||
source: "float".to_owned(),
|
source: "float".to_owned(),
|
||||||
@@ -1629,10 +1691,9 @@ mod tests {
|
|||||||
],
|
],
|
||||||
};
|
};
|
||||||
let engine = Engine::layout(&Document::new(100, vec![unit]));
|
let engine = Engine::layout(&Document::new(100, vec![unit]));
|
||||||
assert_eq!(engine.layout.pages.len(), 2);
|
assert_eq!(engine.layout.pages.len(), 1);
|
||||||
assert_eq!(engine.layout.pages[0].items.len(), 1);
|
assert_eq!(engine.layout.pages[0].floats.len(), 1);
|
||||||
assert_eq!(engine.layout.pages[1].floats.len(), 1);
|
assert_eq!(engine.layout.pages[0].items.len(), 2);
|
||||||
assert_eq!(engine.layout.pages[1].items.len(), 1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -1737,6 +1798,25 @@ mod tests {
|
|||||||
assert_eq!(layout.pages()[1].insertions.len(), 1);
|
assert_eq!(layout.pages()[1].insertions.len(), 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn incremental_layout_places_a_fitting_late_top_float_the_same_way() {
|
||||||
|
let mut document = Document::new(
|
||||||
|
100,
|
||||||
|
vec![
|
||||||
|
Unit::paragraph(1, "body text"),
|
||||||
|
Unit::float(2, FloatPlacement::Top, 40, 20),
|
||||||
|
Unit::paragraph(3, "more text"),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
document.top_skip = 0;
|
||||||
|
let mut engine = Engine::layout(&document);
|
||||||
|
let full_pages = engine.pages().len();
|
||||||
|
let full_floats = engine.pages()[0].floats.len();
|
||||||
|
engine.edit(&document, 3, "changed text");
|
||||||
|
assert_eq!(engine.pages().len(), full_pages);
|
||||||
|
assert_eq!(engine.pages()[0].floats.len(), full_floats);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn a_large_top_float_gets_a_float_page() {
|
fn a_large_top_float_gets_a_float_page() {
|
||||||
let mut document = Document::new(100, Vec::new());
|
let mut document = Document::new(100, Vec::new());
|
||||||
|
|||||||
+1
-1
@@ -267,7 +267,7 @@ M3 (partial): `Unit::halign` normalizes column widths, intercolumn gaps, row hei
|
|||||||
|
|
||||||
Math coverage includes fractions/roots, scripts, `\left...\right` with body-scaled delimiters, `\middle`, `\big`/`\Big`/`\bigg`/`\Bigg` and their `l`/`r` forms, control-sequence delimiters, accents (dot/check/breve/acute/grave/ring), `\text`/`\mathrm`, `\overbrace`/`\underbrace`, `\overset`/`\underset`, `\binom`, `\cancel`/`\bcancel`/`\xcancel`, `\bmod`/`\pmod`, fence symbols, `\operatorname*` and `\mathop` limits.
|
Math coverage includes fractions/roots, scripts, `\left...\right` with body-scaled delimiters, `\middle`, `\big`/`\Big`/`\bigg`/`\Bigg` and their `l`/`r` forms, control-sequence delimiters, accents (dot/check/breve/acute/grave/ring), `\text`/`\mathrm`, `\overbrace`/`\underbrace`, `\overset`/`\underset`, `\binom`, `\cancel`/`\bcancel`/`\xcancel`, `\bmod`/`\pmod`, fence symbols, `\operatorname*` and `\mathop` limits.
|
||||||
|
|
||||||
The crate currently has 151 unit tests plus two route-D integration tests. Workspace verification: `cargo fmt --all -- --check`; `cargo test --workspace --offline` runs 249 tests (151 route-D unit, 2 route-D integration, 71 v1 integration, 19 server, 4 v1 unit, 1 core unit, 1 doctest). v1 remains the live server path.
|
The crate currently has 153 unit tests plus two route-D integration tests. Workspace verification: `cargo fmt --all -- --check`; `cargo test --workspace --offline` runs 251 tests (153 route-D unit, 2 route-D integration, 71 v1 integration, 19 server, 4 v1 unit, 1 core unit, 1 doctest). v1 remains the live server path.
|
||||||
|
|
||||||
### M0 incremental demo
|
### M0 incremental demo
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user