Add a three-paragraph incremental article demo

This commit is contained in:
gloamxun committed 2026-10-20 19:04:48 +08:00
1 parent e05caa351b
commit 4de329c327
3 files changed
+44 -1

No files matched your search

+37
View File
@@ -0,0 +1,37 @@
//! M0 demo: a three-paragraph article whose middle paragraph is edited.
//!
//! Run with `cargo run -p texrra-tex-core --example incremental_article`.
//! It prints the page count before/after the edit and the pages that the
//! checkpoint replay had to rebuild.
use texrra_tex_core::{Document, Engine, ParagraphStyle, Unit};
fn paragraph(id: u64, marker: &str) -> Unit {
// Roughly one page of 10pt text at a 300pt page goal.
let text = format!("{} {}", marker, "alpha beta gamma delta ".repeat(80));
Unit::paragraph_with_style(id, text, ParagraphStyle::default())
}
fn main() {
let document = Document::new(
300,
vec![
paragraph(1, "ONE"),
paragraph(2, "TWO"),
paragraph(3, "THREE"),
],
);
let mut engine = Engine::layout(&document);
println!(
"initial: pages={} changed={:?}",
engine.pages().len(),
engine.changed_pages()
);
engine.edit(&document, 2, "TWO edited beta gamma delta ".repeat(60));
println!(
"after edit: pages={} changed={:?}",
engine.pages().len(),
engine.changed_pages()
);
}
+1 -1
View File
@@ -270,7 +270,7 @@ impl Page {
/// positive. A zero goal keeps insertion material in normal flow.
pub fn display_list_with_goal(&self, page_goal: i64) -> DisplayList {
let mut list = DisplayList::default();
let mut y = 0_i64;
let mut y;
let top_height: i64 = self
.floats
.iter()
+6
View File
@@ -268,3 +268,9 @@ M2 (partial): a 0.4pt rule at 40% of the body width is painted above insertion m
M2 (partial): top and bottom float placeholders are painted at the page edges in display lists; real float material and float-page fractions remain.
M3 (partial): Unit::halign normalizes column widths, intercolumn gaps, row heights and cell text widths to scaled points; the display-list painter uses a 10pt glyph size inside 12pt rows. Rules and spans are painted; tall tables split at row boundaries across pages (split_for_height) with column widths preserved.
### M0 incremental demo
builds a
three-paragraph article, edits the middle paragraph, and prints the pages that
checkpoint replay rebuilt (expected ).