Apply bottom float fractions in incremental layout

This commit is contained in:
gloamxun committed 2026-10-20 23:44:22 +08:00
1 parent 48d10f901d
commit 93dd4e531b
3 files changed
+39 -4

No files matched your search

+3 -1
View File
@@ -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 float placement also mirrors `\bottomfraction`: Route-D top floats follow `\topfraction` as well: The same rule is applied by `Engine::edit`, so a body unit that starts after an oversized top float stays on the next page after an incremental edit.
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`: Route-D top floats follow `\topfraction` as well: `Engine::edit` also applies `text_fraction_percent` and `bottom_fraction_percent` when it meets a bottom float, so incremental layout matches full layout.
The same rule is applied by `Engine::edit`, so a body unit that starts after an oversized top float stays on the next page after an incremental edit.
`Document::top_fraction_percent` defaults to 70, so a top float taller than 70% of the page keeps the body on the next page.
+34 -1
View File
@@ -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(&current)
&& (used - next.top_skip - bottom_float_height(&current)) * 100
>= next.text_fraction_percent as i64 * next.page_goal
&& (float.height + bottom_float_height(&current)) * 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 {
+2 -2
View File
@@ -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`, respect `top_fraction_percent` (TeX `\topfraction`, default 70%) and `bottom_fraction_percent` (TeX `\bottomfraction`, default 30%), and can take a dedicated float page. The incremental edit path applies the same `top_fraction_percent` rule as full layout.
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 `top_fraction_percent` (TeX `\topfraction`, default 70%) and `bottom_fraction_percent` (TeX `\bottomfraction`, default 30%), and can take a dedicated float page. The incremental edit path applies the same `top_fraction_percent`, `text_fraction_percent`, and `bottom_fraction_percent` rules as full layout.
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 145 unit tests plus two route-D integration tests. Workspace verification: `cargo fmt --all -- --check`; `cargo test --workspace --offline` runs 242 tests (145 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 146 unit tests plus two route-D integration tests. Workspace verification: `cargo fmt --all -- --check`; `cargo test --workspace --offline` runs 243 tests (146 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