From 4de329c327d35500927453e89a495ae097f68143 Mon Sep 17 00:00:00 2001 From: GloamXun Date: Tue, 20 Oct 2026 19:04:48 +0800 Subject: [PATCH] Add a three-paragraph incremental article demo --- .../examples/incremental_article.rs | 37 +++++++++++++++++++ crates/texrra-tex-core/src/render.rs | 2 +- docs/TEX_CORE.md | 6 +++ 3 files changed, 44 insertions(+), 1 deletion(-) create mode 100755 crates/texrra-tex-core/examples/incremental_article.rs diff --git a/crates/texrra-tex-core/examples/incremental_article.rs b/crates/texrra-tex-core/examples/incremental_article.rs new file mode 100755 index 0000000..0e3d0b7 --- /dev/null +++ b/crates/texrra-tex-core/examples/incremental_article.rs @@ -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() + ); +} diff --git a/crates/texrra-tex-core/src/render.rs b/crates/texrra-tex-core/src/render.rs index fc94942..962bf01 100755 --- a/crates/texrra-tex-core/src/render.rs +++ b/crates/texrra-tex-core/src/render.rs @@ -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() diff --git a/docs/TEX_CORE.md b/docs/TEX_CORE.md index e719569..13e8926 100755 --- a/docs/TEX_CORE.md +++ b/docs/TEX_CORE.md @@ -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 ).