Apply insertion class limits in incremental edits
This commit is contained in:
1 parent
68d2cef346
commit
506904bbdc
2 files changed
+49
-4
No files matched your search
@@ -1323,8 +1323,25 @@ impl Engine {
|
|||||||
} else {
|
} else {
|
||||||
0
|
0
|
||||||
};
|
};
|
||||||
let goal = next.page_goal - insertion_height;
|
let capacity = next
|
||||||
if !current.items.is_empty() && used + gap + insertion.height > goal {
|
.page_goal
|
||||||
|
.saturating_sub(next.top_skip)
|
||||||
|
.saturating_sub(gap)
|
||||||
|
.max(1);
|
||||||
|
let class_limit = next
|
||||||
|
.insertion_class_limit(insertion.class)
|
||||||
|
.min(capacity)
|
||||||
|
.max(1);
|
||||||
|
let class_height: i64 = current
|
||||||
|
.insertions
|
||||||
|
.iter()
|
||||||
|
.filter(|entry| entry.class == insertion.class)
|
||||||
|
.map(|entry| entry.height)
|
||||||
|
.sum();
|
||||||
|
let exceeds = class_height + insertion.height > class_limit
|
||||||
|
|| insertion_height + insertion.height > capacity
|
||||||
|
|| used + gap + insertion.height > next.page_goal;
|
||||||
|
if exceeds && !current.items.is_empty() {
|
||||||
pages.push(std::mem::replace(&mut current, Page::empty()));
|
pages.push(std::mem::replace(&mut current, Page::empty()));
|
||||||
used = next.top_skip;
|
used = next.top_skip;
|
||||||
insertion_height = 0;
|
insertion_height = 0;
|
||||||
@@ -1824,6 +1841,34 @@ mod tests {
|
|||||||
assert_eq!(layout.pages()[1].insertions.len(), 1);
|
assert_eq!(layout.pages()[1].insertions.len(), 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn incremental_layout_respects_insertion_class_limits() {
|
||||||
|
let rule = VerticalItem::Rule {
|
||||||
|
width: 65_536,
|
||||||
|
height: 200,
|
||||||
|
};
|
||||||
|
let mut document = Document::new(
|
||||||
|
1000,
|
||||||
|
vec![
|
||||||
|
Unit::paragraph(1, "body"),
|
||||||
|
Unit::insertion(2, 1, 200, vec![rule.clone()]),
|
||||||
|
Unit::insertion(3, 1, 200, vec![rule]),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
document.insertion_classes = vec![InsertionClass {
|
||||||
|
number: 1,
|
||||||
|
fraction_percent: 30,
|
||||||
|
max_height: None,
|
||||||
|
}];
|
||||||
|
let mut engine = Engine::layout(&document);
|
||||||
|
assert_eq!(engine.pages().len(), 2);
|
||||||
|
assert_eq!(engine.pages()[0].insertions.len(), 1);
|
||||||
|
engine.edit(&document, 1, "changed body");
|
||||||
|
assert_eq!(engine.pages().len(), 2);
|
||||||
|
assert_eq!(engine.pages()[0].insertions.len(), 1);
|
||||||
|
assert_eq!(engine.pages()[1].insertions.len(), 1);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn insertion_skip_reserves_space_before_the_first_insertion() {
|
fn insertion_skip_reserves_space_before_the_first_insertion() {
|
||||||
let insertion = || {
|
let insertion = || {
|
||||||
|
|||||||
+2
-2
@@ -263,13 +263,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`, `bottom_fraction_percent`, and `float_page_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`, `float_page_fraction_percent`, insertion-class limits and `insertion_skip` 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 154 unit tests plus three route-D integration tests. Workspace verification: `cargo fmt --all -- --check`; `cargo test --workspace --offline` runs 252 tests (154 route-D unit, 3 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 155 unit tests plus three route-D integration tests. Workspace verification: `cargo fmt --all -- --check`; `cargo test --workspace --offline` runs 253 tests (155 route-D unit, 3 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