Support absolute insertion class height limits
This commit is contained in:
1 parent
12d8ae805b
commit
484375fa2b
2 files changed
+36
-2
No files matched your search
@@ -518,6 +518,10 @@ impl Unit {
|
|||||||
pub struct InsertionClass {
|
pub struct InsertionClass {
|
||||||
pub number: u8,
|
pub number: u8,
|
||||||
pub fraction_percent: u8,
|
pub fraction_percent: u8,
|
||||||
|
/// TeX's `\dimen<number>`: an absolute cap on this class's height on one
|
||||||
|
/// page. `None` uses only the percentage share.
|
||||||
|
#[serde(default)]
|
||||||
|
pub max_height: Option<i64>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
|
#[derive(Clone, Debug, PartialEq, Eq, serde::Serialize, serde::Deserialize)]
|
||||||
@@ -578,7 +582,10 @@ impl Document {
|
|||||||
.iter()
|
.iter()
|
||||||
.find(|entry| entry.number == class)
|
.find(|entry| entry.number == class)
|
||||||
.map_or(self.page_goal, |entry| {
|
.map_or(self.page_goal, |entry| {
|
||||||
self.page_goal * i64::from(entry.fraction_percent) / 100
|
let fraction = self.page_goal * i64::from(entry.fraction_percent) / 100;
|
||||||
|
entry
|
||||||
|
.max_height
|
||||||
|
.map_or(fraction, |absolute| fraction.min(absolute))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
pub fn with_top_skip(mut self, top_skip: i64) -> Self {
|
pub fn with_top_skip(mut self, top_skip: i64) -> Self {
|
||||||
@@ -1666,6 +1673,7 @@ mod tests {
|
|||||||
document.insertion_classes = vec![InsertionClass {
|
document.insertion_classes = vec![InsertionClass {
|
||||||
number: 1,
|
number: 1,
|
||||||
fraction_percent: 30,
|
fraction_percent: 30,
|
||||||
|
max_height: None,
|
||||||
}];
|
}];
|
||||||
let layout = Engine::layout(&document);
|
let layout = Engine::layout(&document);
|
||||||
assert_eq!(layout.pages().len(), 2);
|
assert_eq!(layout.pages().len(), 2);
|
||||||
@@ -1691,10 +1699,12 @@ mod tests {
|
|||||||
InsertionClass {
|
InsertionClass {
|
||||||
number: 1,
|
number: 1,
|
||||||
fraction_percent: 60,
|
fraction_percent: 60,
|
||||||
|
max_height: None,
|
||||||
},
|
},
|
||||||
InsertionClass {
|
InsertionClass {
|
||||||
number: 2,
|
number: 2,
|
||||||
fraction_percent: 60,
|
fraction_percent: 60,
|
||||||
|
max_height: None,
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
let layout = Engine::layout(&document);
|
let layout = Engine::layout(&document);
|
||||||
@@ -1703,6 +1713,30 @@ mod tests {
|
|||||||
assert_eq!(layout.pages()[1].insertions.len(), 1);
|
assert_eq!(layout.pages()[1].insertions.len(), 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn insertion_class_absolute_limit_caps_the_class_height() {
|
||||||
|
let rule = VerticalItem::Rule {
|
||||||
|
width: 65_536,
|
||||||
|
height: 100,
|
||||||
|
};
|
||||||
|
let mut document = Document::new(
|
||||||
|
1000,
|
||||||
|
vec![
|
||||||
|
Unit::insertion(1, 1, 100, vec![rule.clone()]),
|
||||||
|
Unit::insertion(2, 1, 100, vec![rule]),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
document.insertion_classes = vec![InsertionClass {
|
||||||
|
number: 1,
|
||||||
|
fraction_percent: 100,
|
||||||
|
max_height: Some(150),
|
||||||
|
}];
|
||||||
|
let layout = Engine::layout(&document);
|
||||||
|
assert_eq!(layout.pages().len(), 2);
|
||||||
|
assert_eq!(layout.pages()[0].insertions.len(), 1);
|
||||||
|
assert_eq!(layout.pages()[1].insertions.len(), 1);
|
||||||
|
}
|
||||||
|
|
||||||
#[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 150 unit tests plus two route-D integration tests. Workspace verification: `cargo fmt --all -- --check`; `cargo test --workspace --offline` runs 248 tests (150 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 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.
|
||||||
|
|
||||||
### M0 incremental demo
|
### M0 incremental demo
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user