Apply float-page fraction in incremental layout

This commit is contained in:
gloamxun committed 2026-10-21 01:02:04 +08:00
1 parent 93dd4e531b
commit ff97f386da
3 files changed
+36 -10

No files matched your search

+5 -6
View File
@@ -465,15 +465,14 @@ variant for delimiters and large display operators, and builds taller glyphs
from the font's MATH assembly parts. `\\left...\\right` target sizing follows from the font's MATH assembly parts. `\\left...\\right` target sizing follows
the assignable TeX parameters `\\delimiterfactor` (default 901) and the assignable TeX parameters `\\delimiterfactor` (default 901) and
`\\delimitershortfall` (default 5pt), including local and global assignments. `\\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: `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. 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.
`Document::top_fraction_percent` defaults to 70, so a top float taller than 70% of the page keeps the body on the next page. Route-D float placement mirrors TeX fractions:
`Document::bottom_fraction_percent` defaults to 30, so a bottom float taller than 30% of the page moves to the following page. - `Document::top_fraction_percent` defaults to 70 (`\topfraction`); a taller top float keeps body text off its page.
- `Document::bottom_fraction_percent` defaults to 30 (`\bottomfraction`); a taller bottom float moves to the next 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. - `Engine::edit` applies `top_fraction_percent`, `text_fraction_percent`, `bottom_fraction_percent`, and `float_page_fraction_percent`, so incremental layout matches full layout.
These glyphs are rasterized at These glyphs are rasterized at
600 dpi and shared by PDF and SVG. Ordinary math atom glyphs are rasterized from 600 dpi and shared by PDF and SVG. Ordinary math atom glyphs are rasterized from
+29 -2
View File
@@ -1137,8 +1137,8 @@ impl Engine {
| VerticalItem::Insertion(_) | VerticalItem::Insertion(_)
) && current.items.is_empty() ) && current.items.is_empty()
&& !current.floats.is_empty() && !current.floats.is_empty()
&& document.page_goal - used && next.page_goal - used
< document.text_fraction_percent as i64 * document.page_goal / 100 < next.float_page_fraction_percent as i64 * next.page_goal / 100
{ {
pages.push(std::mem::replace(&mut current, Page::empty())); pages.push(std::mem::replace(&mut current, Page::empty()));
used = document.top_skip; used = document.top_skip;
@@ -1870,6 +1870,33 @@ mod tests {
assert_eq!(engine.pages()[1].floats.len(), 1); assert_eq!(engine.pages()[1].floats.len(), 1);
} }
#[test]
fn edited_layout_respects_float_page_fraction() {
let document = {
let mut document = Document::new(
100,
vec![
Unit::float(0, FloatPlacement::Top, 40, 60),
Unit::paragraph(1, "body text"),
],
);
document.top_skip = 0;
document.text_fraction_percent = 0;
document.float_page_fraction_percent = 60;
document
};
let mut engine = Engine::layout(&document);
assert_eq!(engine.pages().len(), 2);
assert!(engine.pages()[0].items.is_empty());
engine.edit(&document, 1, "edited body text".to_string());
assert_eq!(
engine.pages().len(),
2,
"edited layout must keep float-page fraction"
);
assert!(engine.pages()[0].items.is_empty());
}
#[test] #[test]
fn edit_ignores_structural_units() { fn edit_ignores_structural_units() {
let rows = vec![HalignRow { 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. 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`, `text_fraction_percent`, and `bottom_fraction_percent` rules 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`, `bottom_fraction_percent`, and `float_page_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. 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. 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 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. The crate currently has 147 unit tests plus two route-D integration tests. Workspace verification: `cargo fmt --all -- --check`; `cargo test --workspace --offline` runs 244 tests (147 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 ### M0 incremental demo