Model float page fractions in route-D output
This commit is contained in:
1 parent
867bace1c9
commit
2431f3a479
1 file changed
+26
-1
@@ -522,6 +522,8 @@ pub struct Document {
|
||||
/// float is allowed onto the page (TeX's `\textfraction`, in percent).
|
||||
#[serde(default = "default_text_fraction")]
|
||||
pub text_fraction_percent: u8,
|
||||
/// `\floatpagefraction` equivalent for dedicated float pages.
|
||||
pub float_page_fraction_percent: u8,
|
||||
}
|
||||
|
||||
fn default_text_fraction() -> u8 {
|
||||
@@ -535,6 +537,7 @@ impl Document {
|
||||
page_goal,
|
||||
top_skip: 0,
|
||||
text_fraction_percent: default_text_fraction(),
|
||||
float_page_fraction_percent: 50,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -694,7 +697,7 @@ impl Engine {
|
||||
) && current.items.is_empty()
|
||||
&& !current.floats.is_empty()
|
||||
&& document.page_goal - used
|
||||
< document.text_fraction_percent as i64 * document.page_goal / 100
|
||||
< document.float_page_fraction_percent as i64 * document.page_goal / 100
|
||||
{
|
||||
pages.push(std::mem::replace(&mut current, Page::empty()));
|
||||
used = document.top_skip;
|
||||
@@ -1361,6 +1364,28 @@ mod tests {
|
||||
assert_eq!(engine.layout.pages[1].items.len(), 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn float_page_fraction_can_keep_body_and_float_together() {
|
||||
let mut document = Document::new(
|
||||
100,
|
||||
vec![
|
||||
Unit::float(1, FloatPlacement::Top, 10, 50),
|
||||
Unit::vertical(
|
||||
2,
|
||||
vec![VerticalItem::Box(VerticalBox {
|
||||
width: 10,
|
||||
height: 10,
|
||||
})],
|
||||
),
|
||||
],
|
||||
);
|
||||
document.float_page_fraction_percent = 60;
|
||||
document.text_fraction_percent = 10;
|
||||
assert_eq!(Engine::layout(&document).pages().len(), 2);
|
||||
document.float_page_fraction_percent = 10;
|
||||
assert_eq!(Engine::layout(&document).pages().len(), 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_large_top_float_gets_a_float_page() {
|
||||
let mut document = Document::new(100, Vec::new());
|
||||
|
||||
Reference in new issue
Block a user