Honour bottomfraction when placing bottom floats
This commit is contained in:
1 parent
c2dbf405ab
commit
14a3775206
3 files changed
+49
-4
No files matched your search
@@ -465,7 +465,9 @@ variant for delimiters and large display operators, and builds taller glyphs
|
||||
from the font's MATH assembly parts. `\\left...\\right` target sizing follows
|
||||
the assignable TeX parameters `\\delimiterfactor` (default 901) and
|
||||
`\\delimitershortfall` (default 5pt), including local and global assignments.
|
||||
Route-D integration can also be checked against a real TeX page: `cargo test -p texrra-tex-core --test route_d` includes `route_d_page_matches_pdftex_raster_geometry`, which renders the route-D PDF and a pdfTeX page at the same geometry, rasterizes both with `pdftoppm`, and compares ink line and edge positions. It is skipped when `pdflatex`/`pdftoppm` are unavailable.
|
||||
Route-D integration can also be checked against a real TeX page: `cargo test -p texrra-tex-core --test route_d` includes `Route-D float placement also mirrors `\bottomfraction`: `Document::bottom_fraction_percent` defaults to 30, so a bottom float taller than 30% of the page moves to the following page.
|
||||
|
||||
route_d_page_matches_pdftex_raster_geometry`, which renders the route-D PDF and a pdfTeX page at the same geometry, rasterizes both with `pdftoppm`, and compares ink line and edge positions. It is skipped when `pdflatex`/`pdftoppm` are unavailable.
|
||||
|
||||
These glyphs are rasterized at
|
||||
600 dpi and shared by PDF and SVG. Ordinary math atom glyphs are rasterized from
|
||||
|
||||
@@ -533,6 +533,10 @@ pub struct Document {
|
||||
pub text_fraction_percent: u8,
|
||||
/// `\floatpagefraction` equivalent for dedicated float pages.
|
||||
pub float_page_fraction_percent: u8,
|
||||
/// Maximum percentage of a page that bottom floats may occupy (TeX's
|
||||
/// `\bottomfraction`, in percent).
|
||||
#[serde(default = "default_bottom_fraction")]
|
||||
pub bottom_fraction_percent: u8,
|
||||
/// Per-class insertion limits. Missing classes use the full page.
|
||||
#[serde(default)]
|
||||
pub insertion_classes: Vec<InsertionClass>,
|
||||
@@ -542,6 +546,10 @@ fn default_text_fraction() -> u8 {
|
||||
50
|
||||
}
|
||||
|
||||
fn default_bottom_fraction() -> u8 {
|
||||
30
|
||||
}
|
||||
|
||||
impl Document {
|
||||
pub fn new(page_goal: i64, units: Vec<Unit>) -> Self {
|
||||
Self {
|
||||
@@ -550,6 +558,7 @@ impl Document {
|
||||
top_skip: 0,
|
||||
text_fraction_percent: default_text_fraction(),
|
||||
float_page_fraction_percent: 50,
|
||||
bottom_fraction_percent: default_bottom_fraction(),
|
||||
insertion_classes: Vec::new(),
|
||||
}
|
||||
}
|
||||
@@ -934,6 +943,8 @@ impl Engine {
|
||||
- bottom_float_height(¤t)
|
||||
&& (used - document.top_skip - bottom_float_height(¤t)) * 100
|
||||
>= document.text_fraction_percent as i64 * document.page_goal
|
||||
&& (float.height + bottom_float_height(¤t)) * 100
|
||||
<= document.bottom_fraction_percent as i64 * document.page_goal
|
||||
{
|
||||
current.floats.push(float.clone());
|
||||
} else {
|
||||
@@ -1633,13 +1644,45 @@ mod tests {
|
||||
}),
|
||||
],
|
||||
};
|
||||
let engine = Engine::layout(&Document::new(60, vec![unit]));
|
||||
let mut document = Document::new(60, vec![unit]);
|
||||
document.bottom_fraction_percent = 100;
|
||||
let engine = Engine::layout(&document);
|
||||
assert_eq!(engine.layout.pages.len(), 2);
|
||||
assert_eq!(engine.layout.pages[0].floats.len(), 1);
|
||||
assert_eq!(engine.layout.pages[0].items.len(), 1);
|
||||
assert_eq!(engine.layout.pages[1].items.len(), 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn bottom_fraction_moves_a_tall_float_to_the_next_page() {
|
||||
let unit = Unit {
|
||||
id: 0,
|
||||
source: "tall bottom float".to_owned(),
|
||||
paragraph_style: None,
|
||||
items: vec![
|
||||
VerticalItem::Box(VerticalBox {
|
||||
width: 10,
|
||||
height: 80,
|
||||
}),
|
||||
VerticalItem::Float(Float {
|
||||
placement: FloatPlacement::Bottom,
|
||||
width: 40,
|
||||
height: 50,
|
||||
content: Vec::new(),
|
||||
}),
|
||||
],
|
||||
};
|
||||
let document = Document::new(100, vec![unit]);
|
||||
let engine = Engine::layout(&document);
|
||||
assert_eq!(
|
||||
engine.layout.pages.len(),
|
||||
2,
|
||||
"50% bottom float exceeds 30% limit"
|
||||
);
|
||||
assert!(engine.layout.pages[0].floats.is_empty());
|
||||
assert_eq!(engine.layout.pages[1].floats.len(), 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn edit_ignores_structural_units() {
|
||||
let rows = vec![HalignRow {
|
||||
|
||||
+2
-2
@@ -261,13 +261,13 @@ M5 (partial): display-list text carries `FontFace::{Roman,Bold,Italic,BoldItalic
|
||||
|
||||
M6 (partial): `DisplayItem::Image` becomes a PDF XObject; `DisplayItem::Link` becomes `/Annots /Subtype /Link /URI`; `DisplayItem::Special` injects raw content-stream operators. SVG previews show images as grey rectangles and specials as comments.
|
||||
|
||||
M2 (partial): `Page::display_list_with_goal(page_goal)` places insertion material at `page_goal - insertion_height`, adds a 0.4pt separator above footnotes, splits oversized insertions at item boundaries, and paints top/bottom floats from their vertical `content` at the page edges; empty floats keep a dimension rectangle. Floats also size themselves from content, respect `text_fraction_percent`, and can take a dedicated float page.
|
||||
M2 (partial): `Page::display_list_with_goal(page_goal)` places insertion material at `page_goal - insertion_height`, adds a 0.4pt separator above footnotes, splits oversized insertions at item boundaries, and paints top/bottom floats from their vertical `content` at the page edges; empty floats keep a dimension rectangle. Floats also size themselves from content, respect `text_fraction_percent`, respect `bottom_fraction_percent` (TeX `\bottomfraction`, default 30%), and can take a dedicated float page.
|
||||
|
||||
M3 (partial): `Unit::halign` normalizes column widths, intercolumn gaps, row heights and cell text widths to scaled points; the painter uses 10pt glyphs in 12pt rows. Rules and spans are painted; tall tables split at row boundaries (`Halign::split_for_height`) with column widths preserved.
|
||||
|
||||
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 142 unit tests plus two route-D integration tests. Workspace verification: `cargo fmt --all -- --check`; `cargo test --workspace --offline` runs 239 tests (142 route-D unit, 2 route-D integration, 71 v1 integration, 19 server, 4 v1 unit, 1 doctest). v1 remains the live server path.
|
||||
The crate currently has 143 unit tests plus two route-D integration tests. Workspace verification: `cargo fmt --all -- --check`; `cargo test --workspace --offline` runs 240 tests (143 route-D unit, 2 route-D integration, 71 v1 integration, 19 server, 4 v1 unit, 1 doctest). v1 remains the live server path.
|
||||
|
||||
### M0 incremental demo
|
||||
|
||||
|
||||
Reference in new issue
Block a user