Apply bottom float fractions in incremental layout
This commit is contained in:
1 parent
48d10f901d
commit
93dd4e531b
3 files changed
+39
-4
No files matched your search
@@ -1282,7 +1282,7 @@ impl Engine {
|
||||
if float.placement == FloatPlacement::Top {
|
||||
if !current.items.is_empty() || !current.insertions.is_empty() {
|
||||
pages.push(std::mem::replace(&mut current, Page::empty()));
|
||||
used = document.top_skip;
|
||||
used = next.top_skip;
|
||||
insertion_height = 0;
|
||||
}
|
||||
used += float.height;
|
||||
@@ -1290,6 +1290,10 @@ impl Engine {
|
||||
} else if !current.items.is_empty()
|
||||
&& used + float.height
|
||||
<= next.page_goal - insertion_height - bottom_float_height(¤t)
|
||||
&& (used - next.top_skip - bottom_float_height(¤t)) * 100
|
||||
>= next.text_fraction_percent as i64 * next.page_goal
|
||||
&& (float.height + bottom_float_height(¤t)) * 100
|
||||
<= next.bottom_fraction_percent as i64 * next.page_goal
|
||||
{
|
||||
current.floats.push(float.clone());
|
||||
} else {
|
||||
@@ -1837,6 +1841,35 @@ mod tests {
|
||||
assert!(engine.pages()[0].items.is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn edited_layout_respects_bottom_fraction() {
|
||||
let document = {
|
||||
let mut document = Document::new(
|
||||
100,
|
||||
vec![
|
||||
Unit::paragraph(0, "body text"),
|
||||
Unit::float(1, FloatPlacement::Bottom, 40, 50),
|
||||
],
|
||||
);
|
||||
document.top_skip = 0;
|
||||
document.text_fraction_percent = 0;
|
||||
document.bottom_fraction_percent = 30;
|
||||
document.float_page_fraction_percent = 10;
|
||||
document
|
||||
};
|
||||
let mut engine = Engine::layout(&document);
|
||||
assert_eq!(engine.pages().len(), 2);
|
||||
assert!(engine.pages()[0].floats.is_empty());
|
||||
engine.edit(&document, 0, "edited body text".to_string());
|
||||
assert_eq!(
|
||||
engine.pages().len(),
|
||||
2,
|
||||
"edited layout must keep bottomfraction"
|
||||
);
|
||||
assert!(engine.pages()[0].floats.is_empty());
|
||||
assert_eq!(engine.pages()[1].floats.len(), 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn edit_ignores_structural_units() {
|
||||
let rows = vec![HalignRow {
|
||||
|
||||
Reference in new issue
Block a user