diff --git a/ROADMAP.md b/ROADMAP.md index 6ef9e2c369..4724211b36 100644 --- a/ROADMAP.md +++ b/ROADMAP.md @@ -1,5 +1,7 @@ # PdfCraft roadmap +> **Last reviewed:** 2026-11-04 | **Last updated:** 2026-11-04 | **Change:** minor (M7: paragraph boundaries respect row typography and page-wide filled panels; estimates unchanged) + > **Last reviewed:** 2026-11-03 | **Last updated:** 2026-11-03 | **Change:** patch (M5 #5850 review: indirect typewriter intent and composer edits preserve outer whitespace; movement regression commits by outside click; estimates unchanged) > **Last reviewed:** 2026-11-03 | **Last updated:** 2026-11-03 | **Change:** patch (M5 #5850: Enter adds Fill & Sign line breaks; outside clicks commit, Escape cancels, and saved multiline appearances retain their text and height; estimates unchanged) @@ -223,6 +225,8 @@ Ranked; detail and the full milestone table in [docs/roadmap.md](docs/roadmap.md ## Progress log +- **2026-11-04 (M7, paragraph boundaries):** Editable paragraphs separate across large row-size changes, font-family changes and filled rectangular panel boundaries, while compatible multiline text and inline style runs stay together. Panel identity is page-wide across content streams and transformed form invocations; rectangle construction/fill splits retain their transforms and path semantics. Synthetic regressions cover isolated-panel edits through save/reopen and preserve the delayed-background rewrite checks for #2377. Estimates unchanged. + - **2026-11-03 (M11, shared JBIG2 dictionary):** With Monochrome Images set to JBIG2, Optimize has up to 16 JBIG2 images share one symbol dictionary (`/JBIG2Globals`), the letters found on more than one page stored once, when that is smaller (`pdfcraft_filters::encode_jbig2_shared`). Eight pages of 10 pt text rendered at 300 dpi take 41% less in Helvetica and 42% in Times than coded alone, 10% in Courier; groups of 16 save 45%, of 32 only 47%. Only images redaction can store again without the dictionary share one (image masks and DeviceGray named directly, at most 64 Mi pixels), and redacting one stores the rest of its group so, which the group bounds to 15. - **2026-11-03 (M5, #5850 review):** Resolve indirect IT when recognizing typewriter contents and Fill & Sign marks. Comment listing and property lookup retain their existing direct-Subtype behavior. A real double-click Edit composer preserves the typewriter’s text as written; ordinary comment edits keep trimming. Regressions cover direct Subtype with indirect intent, save/reopen, raw posted contents and same-index comments on different pages. The existing live-movement test now commits its setup with an outside click rather than Enter. Estimates unchanged. diff --git a/crates/edit/src/paragraph_grouping_tests.rs b/crates/edit/src/paragraph_grouping_tests.rs new file mode 100644 index 0000000000..f9d6f51d54 --- /dev/null +++ b/crates/edit/src/paragraph_grouping_tests.rs @@ -0,0 +1,347 @@ +use super::*; + +fn page(content: &str, second_face: &str) -> Document { + let mut doc = text_page(content); + doc.update_dict(pdfcraft_cos::ObjRef::new(6, 0), |font| { + *font = Dict::new(); + font.set(b"Type".to_vec(), Object::name("Font")); + font.set(b"Subtype".to_vec(), Object::name("Type1")); + font.set(b"BaseFont".to_vec(), Object::name(second_face)); + font.set(b"Encoding".to_vec(), Object::name("WinAnsiEncoding")); + }) + .unwrap(); + doc +} + +fn multi_stream_page(contents: &[&str]) -> Document { + let mut doc = page("", "Helvetica"); + let streams = + contents.iter().map(|content| Object::Ref(doc.add(Object::Stream(Stream::from_raw(Dict::new(), content.as_bytes().to_vec()))))).collect(); + set_page_contents(&mut doc, Object::Array(streams), None); + doc +} + +fn panel_form(doc: &mut Document, content: &str, matrix: [i64; 6]) { + let mut dict = Dict::new(); + dict.set(b"Subtype".to_vec(), Object::name("Form")); + dict.set(b"BBox".to_vec(), Object::Array([0, 0, 600, 800].map(Object::Int).to_vec())); + dict.set(b"Matrix".to_vec(), Object::Array(matrix.map(Object::Int).to_vec())); + let form = doc.add(Object::Stream(Stream::from_raw(dict, content.as_bytes().to_vec()))); + let page = pdfcraft_model::pages(doc)[0].obj; + doc.update_dict(page, |page| { + let mut resources = page.get(b"Resources").and_then(Object::as_dict).cloned().unwrap(); + let mut xobjects = Dict::new(); + xobjects.set(b"Panel".to_vec(), Object::Ref(form)); + resources.set(b"XObject".to_vec(), Object::Dict(xobjects)); + page.set(b"Resources".to_vec(), Object::Dict(resources)); + }) + .unwrap(); +} + +#[test] +fn separates_rows_when_background_is_in_a_separate_stream() { + let doc = multi_stream_page(&["q 60 690 200 25 re f Q", "BT /F1 12 Tf 72 700 Td (Panel) Tj 0 -18 Td (Outside) Tj ET"]); + + let blocks = text::text_blocks(&doc, 0).unwrap(); + + assert_eq!(blocks.iter().map(|b| b.text.as_str()).collect::>(), ["Panel", "Outside"]); +} + +#[test] +fn separates_rows_when_distinct_panels_are_in_separate_streams() { + let doc = + multi_stream_page(&["60 690 200 25 re f BT /F1 12 Tf 72 700 Td (Upper) Tj ET", "60 670 200 20 re f BT /F1 12 Tf 72 682 Td (Lower) Tj ET"]); + + let blocks = text::reading_blocks(&doc, 0).unwrap(); + + assert_eq!(blocks.iter().map(|b| b.text.as_str()).collect::>(), ["Upper", "Lower"]); +} + +#[test] +fn joins_rows_when_same_panel_spans_separate_streams() { + let doc = multi_stream_page(&["60 650 200 65 re f BT /F1 12 Tf 72 700 Td (First) Tj ET", "BT /F1 12 Tf 72 682 Td (Second) Tj ET"]); + + let blocks = text::text_blocks(&doc, 0).unwrap(); + + assert_eq!(blocks.iter().map(|b| b.editor_text.as_str()).collect::>(), ["First\nSecond"]); +} + +#[test] +fn separates_rows_when_rectangle_and_fill_are_in_separate_streams() { + let doc = multi_stream_page(&["q 2 0 0 2 20 10 cm 120 352.5 -100 -12.5 re", "f Q BT /F1 12 Tf 72 700 Td (Panel) Tj 0 -18 Td (Outside) Tj ET"]); + + let blocks = text::text_blocks(&doc, 0).unwrap(); + + assert_eq!(blocks.iter().map(|b| b.text.as_str()).collect::>(), ["Panel", "Outside"]); +} + +#[test] +fn separates_page_rows_when_transformed_background_is_in_a_form_stream() { + let mut doc = multi_stream_page(&["/Panel Do", "BT /F1 12 Tf 72 700 Td (Panel) Tj 0 -18 Td (Outside) Tj ET"]); + panel_form(&mut doc, "20 340 100 12.5 re f", [2, 0, 0, 2, 20, 10]); + + let blocks = text::text_blocks(&doc, 0).unwrap(); + + assert_eq!(blocks.iter().map(|b| b.text.as_str()).collect::>(), ["Panel", "Outside"]); +} + +#[test] +fn separates_rows_when_distinct_panels_are_in_form_streams() { + let mut doc = multi_stream_page(&["/Panel Do q 1 0 0 1 0 -18 cm /Panel Do Q"]); + panel_form(&mut doc, "60 690 200 17 re f BT /F1 12 Tf 72 700 Td (Row) Tj ET", [1, 0, 0, 1, 0, 0]); + + let blocks = text::reading_blocks(&doc, 0).unwrap(); + + assert_eq!(blocks.iter().map(|b| b.text.as_str()).collect::>(), ["Row", "Row"]); +} + +#[test] +fn joins_rows_when_page_panel_contains_form_text() { + let mut doc = multi_stream_page(&["60 650 200 65 re f BT /F1 12 Tf 72 700 Td (First) Tj ET", "/Panel Do"]); + panel_form(&mut doc, "BT /F1 12 Tf 72 682 Td (Second) Tj ET", [1, 0, 0, 1, 0, 0]); + + let blocks = text::reading_blocks(&doc, 0).unwrap(); + + assert_eq!(blocks.iter().map(|b| b.editor_text.as_str()).collect::>(), ["First\nSecond"]); +} + +#[test] +fn separates_rows_when_size_change_is_large() { + let doc = page("BT /F1 24 Tf 72 700 Td (Heading) Tj /F1 10 Tf 0 -24 Td (Body) Tj ET", "Helvetica"); + + let blocks = text::text_blocks(&doc, 0).unwrap(); + + assert_eq!(blocks.iter().map(|b| b.text.as_str()).collect::>(), ["Heading", "Body"]); +} + +#[test] +fn separates_equal_size_rows_when_families_differ() { + let doc = page("BT /F1 12 Tf 72 700 Td (Heading) Tj /F2 12 Tf 0 -16 Td (Body) Tj ET", "Courier"); + + let blocks = text::text_blocks(&doc, 0).unwrap(); + + assert_eq!(blocks.iter().map(|b| b.text.as_str()).collect::>(), ["Heading", "Body"]); +} + +#[test] +fn separates_equal_style_rows_when_crossing_a_filled_container() { + let doc = page("q 0.9 g 60 690 200 25 re f Q BT /F1 12 Tf 72 700 Td (Panel) Tj 0 -18 Td (Outside) Tj ET", "Helvetica"); + + let blocks = text::text_blocks(&doc, 0).unwrap(); + + assert_eq!(blocks.iter().map(|b| b.text.as_str()).collect::>(), ["Panel", "Outside"]); +} + +#[test] +fn separates_rows_when_containers_are_adjacent() { + let doc = page("q 60 690 200 25 re f 60 670 200 20 re f Q BT /F1 12 Tf 72 700 Td (Upper) Tj 0 -18 Td (Lower) Tj ET", "Helvetica"); + + let blocks = text::text_blocks(&doc, 0).unwrap(); + + assert_eq!(blocks.len(), 2); +} + +#[test] +fn joins_multiline_when_inside_the_same_filled_container() { + let doc = page("q 0.9 g 60 650 200 65 re f Q BT /F1 12 Tf 72 700 Td (First) Tj 0 -18 Td (Second) Tj 0 -18 Td (Third) Tj ET", "Helvetica"); + + let blocks = text::text_blocks(&doc, 0).unwrap(); + + assert_eq!(blocks.iter().map(|b| b.editor_text.as_str()).collect::>(), ["First\nSecond\nThird"]); +} + +#[test] +fn joins_rows_when_a_fill_is_painted_over_one_of_them() { + // A box painted after the text covers it (a redaction); it is not a panel behind the text. + let doc = page("BT /F1 12 Tf 72 700 Td (First) Tj 0 -18 Td (Second) Tj ET 0 g 70 696 60 20 re f", "Helvetica"); + + let blocks = text::text_blocks(&doc, 0).unwrap(); + + assert_eq!(blocks.iter().map(|b| b.editor_text.as_str()).collect::>(), ["First\nSecond"]); +} + +#[test] +fn joins_rows_when_their_panel_is_repainted_behind_each_row() { + let doc = page( + "0.9 g 60 650 200 65 re f BT /F1 12 Tf 0 g 72 700 Td (First) Tj ET 0.9 g 60 650 200 65 re f BT /F1 12 Tf 0 g 72 682 Td (Second) Tj ET", + "Helvetica", + ); + + let blocks = text::text_blocks(&doc, 0).unwrap(); + + assert_eq!(blocks.iter().map(|b| b.editor_text.as_str()).collect::>(), ["First\nSecond"]); +} + +#[test] +fn joins_rows_when_an_edit_wraps_a_fallback_word_onto_its_own_row() { + // The bundled Inter face draws the Cyrillic Helvetica lacks; wrapped alone onto a row, the + // word is still part of the paragraph that was edited. + let mut doc = page( + "BT /F1 12 Tf 14.4 TL 72 700 Td (The quick brown fox jumps over the lazy dog) Tj T* (and keeps running through the long field.) Tj ET", + "Helvetica", + ); + let edited = "The quick brown fox jumps over the lazy dog \u{049b}\u{0438}\u{0437}\u{0438}\u{043b}\nand keeps running through the long field."; + text::rewrite_block(&mut doc, 0, 0, Some(edited), &text::BlockStyle::default()).unwrap(); + + let blocks = text::text_blocks(&reopen(&doc), 0).unwrap(); + + assert_eq!(blocks.len(), 1, "{:?}", blocks.iter().map(|b| &b.editor_text).collect::>()); + assert!(blocks[0].rows.len() > 2, "the word wraps onto a row of its own: {:?}", blocks[0].editor_text); +} + +#[test] +fn joins_plain_multiline_when_no_container_exists() { + let doc = page("BT /F1 12 Tf 72 700 Td (First) Tj 0 -18 Td (Second) Tj ET", "Helvetica"); + + let blocks = text::text_blocks(&doc, 0).unwrap(); + + assert_eq!(blocks.iter().map(|b| b.editor_text.as_str()).collect::>(), ["First\nSecond"]); +} + +#[test] +fn joins_inline_styles_when_family_and_size_change() { + let doc = page("BT /F1 12 Tf 72 700 Td (Plain ) Tj /F2 20 Tf (mixed) Tj ET", "Courier-Bold"); + + let blocks = text::text_blocks(&doc, 0).unwrap(); + + assert_eq!(blocks.iter().map(|b| b.editor_text.as_str()).collect::>(), ["Plain mixed"]); +} + +#[test] +fn joins_rows_when_subset_and_weight_names_differ() { + let mut doc = page("BT /F1 12 Tf 72 700 Td (First) Tj /F2 12 Tf 0 -18 Td (Second) Tj ET", "GHIJKL+Helvetica-Bold"); + doc.update_dict(pdfcraft_cos::ObjRef::new(5, 0), |font| font.set(b"BaseFont".to_vec(), Object::name("ABCDEF+Helvetica"))).unwrap(); + + let blocks = text::text_blocks(&doc, 0).unwrap(); + + assert_eq!(blocks.iter().map(|b| b.editor_text.as_str()).collect::>(), ["First\nSecond"]); +} + +#[test] +fn joins_rows_when_stacked_weight_suffixes_differ() { + for (regular, bold) in [("TimesNewRomanPSMT", "TimesNewRomanPS-BoldMT"), ("MinionPro-Regular", "MinionPro-BoldIt")] { + let mut doc = page("BT /F1 12 Tf 72 700 Td (First) Tj /F2 12 Tf 0 -18 Td (Second) Tj ET", bold); + doc.update_dict(pdfcraft_cos::ObjRef::new(5, 0), |font| font.set(b"BaseFont".to_vec(), Object::name(regular))).unwrap(); + + let blocks = text::text_blocks(&doc, 0).unwrap(); + + assert_eq!(blocks.iter().map(|b| b.editor_text.as_str()).collect::>(), ["First\nSecond"], "{regular} / {bold}"); + } +} + +#[test] +fn joins_rows_when_a_highlight_hugs_one_word() { + let doc = page("q 1 1 0 rg 98 697 36 12 re f Q BT /F1 12 Tf 72 700 Td (Plain ) Tj (word) Tj ( rest) Tj 0 -18 Td (Second row) Tj ET", "Helvetica"); + + let blocks = text::text_blocks(&doc, 0).unwrap(); + + assert_eq!(blocks.iter().map(|b| b.editor_text.as_str()).collect::>(), ["Plain word rest\nSecond row"]); +} + +#[test] +fn joins_rows_when_a_padded_highlight_surrounds_one_word() { + // Highlighters pad the box past the glyphs; it is still a highlight, not a panel. + for padded in ["98 695 36 16 re", "98 694 36 18 re", "96 693 40 20 re"] { + let doc = page( + &format!("q 1 1 0 rg {padded} f Q BT /F1 12 Tf 72 700 Td (Plain ) Tj (word) Tj ( rest) Tj 0 -18 Td (Second row) Tj ET"), + "Helvetica", + ); + + let blocks = text::text_blocks(&doc, 0).unwrap(); + + assert_eq!(blocks.iter().map(|b| b.editor_text.as_str()).collect::>(), ["Plain word rest\nSecond row"], "{padded}"); + } +} + +#[test] +fn joins_rows_when_a_padded_highlight_sits_inside_a_one_run_line() { + // One `Tj` draws the whole line, so the highlight's word is not a run of its own. + let doc = page("q 1 1 0 rg 98 695 36 16 re f Q BT /F1 12 Tf 72 700 Td (Plain word rest) Tj 0 -18 Td (Second row) Tj ET", "Helvetica"); + + let blocks = text::text_blocks(&doc, 0).unwrap(); + + assert_eq!(blocks.iter().map(|b| b.editor_text.as_str()).collect::>(), ["Plain word rest\nSecond row"]); +} + +#[test] +fn joins_rows_when_only_right_edges_align() { + let doc = page("BT /F1 12 Tf 72 700 Td (Long first row) Tj ET BT /F1 12 Tf 300 682 Td (Short) Tj ET", "Helvetica"); + let lines = text::text_lines(&doc, 0).unwrap(); + let x = lines[0].rect[2] - (lines[1].rect[2] - lines[1].rect[0]); + let doc = page(&format!("BT /F1 12 Tf 72 700 Td (Long first row) Tj ET BT /F1 12 Tf {x} 682 Td (Short) Tj ET"), "Helvetica"); + + let blocks = text::text_blocks(&doc, 0).unwrap(); + + assert_eq!(blocks.iter().map(|b| b.editor_text.as_str()).collect::>(), ["Long first row\nShort"]); +} + +#[test] +fn keeps_outside_text_when_editing_a_container_paragraph() { + let mut doc = page("q 0.9 g 60 690 200 25 re f Q BT /F1 12 Tf 72 700 Td (Panel) Tj 0 -18 Td (Outside) Tj ET", "Helvetica"); + let outside = text::text_lines(&doc, 0).unwrap()[1].clone(); + + text::replace_block(&mut doc, 0, 0, "Edited").unwrap(); + + let reopened = reopen(&doc); + let lines = text::text_lines(&reopened, 0).unwrap(); + let kept = lines.iter().find(|line| line.text == "Outside").expect("outside paragraph survives"); + assert_eq!((kept.rect, kept.size, &kept.base_font), (outside.rect, outside.size, &outside.base_font)); +} + +#[test] +fn keeps_neighboring_panel_when_editing_an_isolated_panel() { + let mut doc = + multi_stream_page(&["60 690 200 25 re f BT /F1 12 Tf 72 700 Td (Upper) Tj ET", "60 670 200 20 re f BT /F1 12 Tf 72 682 Td (Lower) Tj ET"]); + assert_eq!(text::text_blocks(&doc, 0).unwrap().len(), 2); + let neighbor = text::text_lines(&doc, 0).unwrap()[1].clone(); + + text::replace_block(&mut doc, 0, 0, "Edited").unwrap(); + + let reopened = reopen(&doc); + let blocks = text::text_blocks(&reopened, 0).unwrap(); + assert_eq!(blocks.iter().map(|block| block.text.as_str()).collect::>(), ["Edited", "Lower"]); + let lines = text::text_lines(&reopened, 0).unwrap(); + let kept = lines.iter().find(|line| line.text == "Lower").expect("neighboring panel survives"); + assert_eq!( + (kept.rect, kept.baseline(), kept.size, &kept.base_font, kept.color), + (neighbor.rect, neighbor.baseline(), neighbor.size, &neighbor.base_font, neighbor.color) + ); +} + +#[test] +fn separates_rows_when_container_has_a_transformed_negative_rectangle() { + let doc = page("q 2 0 0 2 20 10 cm 120 352.5 -100 -12.5 re B Q BT /F1 12 Tf 72 700 Td (Panel) Tj 0 -18 Td (Outside) Tj ET", "Helvetica"); + + let blocks = text::text_blocks(&doc, 0).unwrap(); + + assert_eq!(blocks.iter().map(|b| b.text.as_str()).collect::>(), ["Panel", "Outside"]); +} + +#[test] +fn joins_rows_when_rectangle_is_only_stroked_or_clipped() { + for paint in ["S", "W n", "W* n"] { + let doc = page(&format!("q 60 690 200 25 re {paint} Q BT /F1 12 Tf 72 700 Td (First) Tj 0 -18 Td (Second) Tj ET"), "Helvetica"); + + let blocks = text::text_blocks(&doc, 0).unwrap(); + + assert_eq!(blocks.iter().map(|b| b.editor_text.as_str()).collect::>(), ["First\nSecond"], "{paint}"); + } +} + +#[test] +fn joins_multiline_with_inline_mixed_families() { + let doc = page("BT /F1 12 Tf 72 700 Td (Ordinary text ) Tj /F2 12 Tf (code) Tj /F1 12 Tf 0 -18 Td (Following row) Tj ET", "Courier-Bold"); + + let blocks = text::text_blocks(&doc, 0).unwrap(); + + assert_eq!(blocks.iter().map(|b| b.editor_text.as_str()).collect::>(), ["Ordinary text code\nFollowing row"]); +} + +#[test] +fn separates_inline_labels_when_a_container_edge_is_between_them() { + let doc = page("q 60 690 50 25 re f Q BT /F1 12 Tf 72 700 Td (Panel) Tj 1 0 0 1 112 700 Tm (Outside) Tj ET", "Helvetica"); + + let blocks = text::text_blocks(&doc, 0).unwrap(); + + assert_eq!(blocks.iter().map(|b| b.text.as_str()).collect::>(), ["Panel", "Outside"]); +} diff --git a/crates/edit/src/tests.rs b/crates/edit/src/tests.rs index e78da842b8..2075ba56bf 100644 --- a/crates/edit/src/tests.rs +++ b/crates/edit/src/tests.rs @@ -6,6 +6,8 @@ use super::*; #[path = "mark_transaction_tests.rs"] mod mark_transactions; +#[path = "paragraph_grouping_tests.rs"] +mod paragraph_grouping; /// Three pages: an upright page with content that leaves the graphics state changed (an /// unbalanced `cm`), a page rotated 90° and one with inherited, shared resources. @@ -7533,12 +7535,13 @@ fn japanese_paragraphs_wrap_between_characters_without_closing_marks_at_a_row_st #[test] fn rewritten_paragraph_is_drawn_after_backgrounds_between_its_rows() { - // Each row has its own background box drawn immediately before its BT..ET, as cards and - // highlighted headings exported from LibreOffice or browsers do (#2377). - let card = "0 0.45 0.25 rg 60 696 240 16 re f BT /F1 10 Tf 1 1 1 rg 64 700 Td (SEMINARIO ONLINE) Tj ET \ - 0 0.45 0.25 rg 60 668 240 24 re f BT /F1 16 Tf 1 1 1 rg 64 674 Td (Dalla teoria alla pratica:) Tj ET \ - 0 0.45 0.25 rg 60 632 240 32 re f BT /F1 24 Tf 1 1 1 rg 64 640 Td (gestire con metodo) Tj ET \ - 0 0.45 0.25 rg 60 596 240 32 re f BT /F1 24 Tf 1 1 1 rg 64 604 Td (un progetto complesso) Tj ET"; + // Layered paragraph-wide backgrounds still paint between rows (#2377), but every row has + // the same container membership. Compatible size changes retain the mixed-style rewrite + // without asking the grouping heuristic to merge independent panels or headings. + let card = "0 0.45 0.25 rg 60 540 240 180 re f BT /F1 16 Tf 1 1 1 rg 64 700 Td (SEMINARIO ONLINE) Tj ET \ + 0 0.45 0.25 rg 60 540 240 180 re f BT /F1 20 Tf 1 1 1 rg 64 674 Td (Dalla teoria alla pratica:) Tj ET \ + 0 0.45 0.25 rg 60 540 240 180 re f BT /F1 24 Tf 1 1 1 rg 64 640 Td (gestire con metodo) Tj ET \ + 0 0.45 0.25 rg 60 540 240 180 re f BT /F1 24 Tf 1 1 1 rg 64 604 Td (un progetto complesso) Tj ET"; let shown_at = |ops: &[pdfcraft_content::Op], needle: &str| { ops.iter() .position(|op| { @@ -7551,6 +7554,13 @@ fn rewritten_paragraph_is_drawn_after_backgrounds_between_its_rows() { // 1. Editing the title rows emits all rewritten rows after all four background fills. let mut doc = text_page(card); assert_eq!(text::text_blocks(&doc, 0).unwrap().len(), 1); + let source_ops = pdfcraft_content::parse(&page_content_bytes(&doc, 0)).ops; + let source_fills: Vec = source_ops.iter().enumerate().filter_map(|(i, op)| op.is("f").then_some(i)).collect(); + assert_eq!(source_fills.len(), 4); + for (row, needle) in ["SEMINARIO", "pratica:", "metodo", "complesso"].iter().enumerate() { + let shown = shown_at(&source_ops, needle); + assert!(source_fills[row] < shown && source_fills.get(row + 1).is_none_or(|next| shown < *next), "backgrounds must stay interleaved"); + } let edited = "SEMINARIO ONLINE\nDalla teoria alla pratica:\ngestire con criterio\nun progetto nuovo"; text::rewrite_block(&mut doc, 0, 0, Some(edited), &text::BlockStyle::default()).unwrap(); let doc = reopen(&doc); @@ -7586,6 +7596,9 @@ fn rewritten_paragraph_is_drawn_after_backgrounds_between_its_rows() { let wrapped_edit = "SEMINARIO ONLINE\nDalla teoria alla pratica:\ngestire con criterio e metodo approfondito\nun progetto complesso"; text::rewrite_block(&mut doc, 0, 0, Some(wrapped_edit), &text::BlockStyle::default()).unwrap(); let doc = reopen(&doc); + let wrapped = text::text_blocks(&doc, 0).unwrap(); + assert!(wrapped[0].rows.len() > 4, "the long edit must wrap and push the suffix row down"); + assert_eq!(wrapped[0].text, wrapped_edit.replace('\n', " ")); let ops = pdfcraft_content::parse(&page_content_bytes(&doc, 0)).ops; let last_fill = ops.iter().rposition(|op| op.is("f")).unwrap(); assert!( @@ -7595,8 +7608,8 @@ fn rewritten_paragraph_is_drawn_after_backgrounds_between_its_rows() { // 4. Single-style paragraph path across a CTM change between rows, with movement, underline, // and a trailing unrelated line sharing the second row's BT..ET. - let cross_ctm = "0.9 0.9 0.2 rg 60 696 240 18 re f BT /F1 12 Tf 0 0 0 rg 64 700 Td (First highlighted row) Tj ET \ - q 1 0 0 1 10 12 cm 0.9 0.9 0.2 rg 50 668 240 18 re f \ + let cross_ctm = "0.9 0.9 0.2 rg 60 676 240 38 re f BT /F1 12 Tf 0 0 0 rg 64 700 Td (First highlighted row) Tj ET \ + q 1 0 0 1 10 12 cm 0.9 0.9 0.2 rg 50 664 240 38 re f \ BT /F1 12 Tf 0 0 0 rg 54 672 Td (Second highlighted row) Tj 246 -40 Td (Side footer) Tj ET Q"; let mut doc = text_page(cross_ctm); let para = text::text_blocks(&doc, 0).unwrap().into_iter().position(|b| b.text.starts_with("First highlighted")).unwrap(); diff --git a/crates/edit/src/text.rs b/crates/edit/src/text.rs index 0fb00324b6..74bad2a7b6 100644 --- a/crates/edit/src/text.rs +++ b/crates/edit/src/text.rs @@ -28,6 +28,11 @@ pub use fallback::strip_subset_tag; use regions::{alignment_frame, group_blocks, is_centred, rewrite_styled_block}; pub use session::TextSession; +#[path = "text_containers.rs"] +mod containers; +#[path = "text_row_style.rs"] +mod row_style; + mod blocks; mod editor; mod fallback; @@ -102,6 +107,7 @@ pub struct TextLine { scope: Option, /// The layers and graphics state parameters it is drawn in; see [`Paint`]. paint: Paint, + containers: Vec, /// Right-to-left `/ActualText` already supplies typing order; glyph text still needs bidi /// recovery. Left-to-right ActualText (e.g. a Latin ligature) joins its line as usual. logical_order: bool, diff --git a/crates/edit/src/text/interp.rs b/crates/edit/src/text/interp.rs index 2a9f6da61a..9b3621093e 100644 --- a/crates/edit/src/text/interp.rs +++ b/crates/edit/src/text/interp.rs @@ -299,6 +299,7 @@ pub(super) struct Shown { pub(super) decodable: bool, pub(super) scope: Option, pub(super) paint: Paint, + pub(super) containers: Vec, pub(super) logical_order: bool, pub(super) actual_text: bool, /// Set when a `/PCSoft` or `/PCHard` marker was seen since the previous text line. @@ -442,6 +443,9 @@ pub(super) struct Carry { pub(super) layers: Vec>>, /// Bytes of glyph text the rest of the page may still produce (see [`MAX_PAGE_TEXT`]). pub(super) text_left: usize, + pub(super) containers: Rc, + /// The operator indices of the `Do`s, from the page down, that draw these operators. + pub(super) at: Vec, } /// The most glyph text one page's extraction produces, in bytes. A ToUnicode destination is @@ -472,7 +476,7 @@ impl Carry { dash: (Vec::new(), 0.0), line_cap: 0, }; - Carry { ts, stack: Vec::new(), marked: Vec::new(), layers: Vec::new(), text_left: MAX_PAGE_TEXT } + Carry { ts, stack: Vec::new(), marked: Vec::new(), layers: Vec::new(), text_left: MAX_PAGE_TEXT, containers: Rc::default(), at: Vec::new() } } } @@ -754,6 +758,7 @@ fn show_text(op: &Op, i: usize, state: &mut TextRunState<'_>) -> Result<(), Edit decodable, scope: marked.regions.last().copied().flatten(), paint: Paint { layers: marked.layers.iter().flatten().cloned().collect(), gs: ts.gs.clone() }, + containers: Vec::new(), logical_order: false, actual_text: false, soft_break: state.soft_break, @@ -956,5 +961,46 @@ pub(super) fn interpret( carry.marked = marked.regions; carry.layers = marked.layers; positioned_tracking(&mut out); + for shown in &mut out { + shown.containers = carry.containers.membership(shown.rect, &[carry.at.as_slice(), &[shown.op]].concat()); + } + // A box a highlight's height that does not reach across the text is a highlight behind part + // of it, as when one `Tj` draws the whole line. + for shown in &mut out { + let rect = shown.rect; + shown.containers.retain(|panel| carry.containers.spans(*panel, rect) || !carry.containers.hugs(*panel, rect)); + } + // Text that runs on along its line keeps a box only part of it is in when the box is a + // panel's height: a highlight padded around one word of the line is not a panel. + let mut start = 0; + while start < out.len() { + let mut end = start + 1; + while out.get(end).is_some_and(|next| runs_on(&out[end - 1].rect, &next.rect)) { + end += 1; + } + if end - start > 1 { + // How many of the run's pieces each box holds (`membership` lists a box once per piece), + // counted in one pass: a hostile page can chain thousands of runs into one line. + let mut held: HashMap = HashMap::new(); + for shown in &out[start..end] { + for panel in &shown.containers { + *held.entry(*panel).or_default() += 1; + } + } + for shown in &mut out[start..end] { + let rect = shown.rect; + shown.containers.retain(|panel| held.get(panel) == Some(&(end - start)) || !carry.containers.hugs(*panel, rect)); + } + } + start = end; + } Ok(out) } + +/// Whether text in `next` continues `previous` along its line: about the same height across it, +/// and starting at or after it with less than a line's height between them. +fn runs_on(previous: &[f64; 4], next: &[f64; 4]) -> bool { + let height = (previous[3] - previous[1]).max(next[3] - next[1]); + let centre = |r: &[f64; 4]| (r[1] + r[3]) / 2.0; + (centre(previous) - centre(next)).abs() < height / 2.0 && next[0] >= previous[0] && next[0] - previous[2] < height +} diff --git a/crates/edit/src/text/lines.rs b/crates/edit/src/text/lines.rs index 85209a5472..a8ce40a04a 100644 --- a/crates/edit/src/text/lines.rs +++ b/crates/edit/src/text/lines.rs @@ -204,6 +204,7 @@ fn text_lines_in(doc: &Document, p: &pdfcraft_model::Page, actual_text: bool) -> let pieces = Pieces::join(&content_streams(doc, &p.dict)?.into_iter().map(|(_, d)| d).collect::>()); let ops = pieces.parse().ops; let properties = res.get(b"Properties").and_then(|o| doc.dict(o)).unwrap_or_default(); + carry.containers = std::rc::Rc::new(super::containers::Containers::collect(doc, &ops, &res)); let shown = interpret(doc, &ops, &res, &mut cache, &mut carry, None, actual_text.then_some(&properties))?; let mut last: Option<(usize, Pen)> = None; // the stream piece and where its last run ended for mut s in shown { @@ -222,7 +223,9 @@ fn text_lines_in(doc: &Document, p: &pdfcraft_model::Page, actual_text: bool) -> let bt = pen.bt; let (near, gap) = pen.continues(&s, if bt == s.bt { 3.0 } else { 1.5 }); piece == si - && lines.last().is_some_and(|l| l.scope == s.scope && l.paint == s.paint && l.logical_order == s.logical_order) + && lines.last().is_some_and(|l| { + l.scope == s.scope && l.paint == s.paint && l.containers == s.containers && l.logical_order == s.logical_order + }) && (bt == s.bt || lines.last().is_some_and(|l| compatible_word(l, &s))) && (s.text.trim().is_empty() || lines.last().is_some_and(|l| same_font(l, &s.font, &s.base_font, s.face.as_deref()))) && (s.text.trim().is_empty() @@ -277,6 +280,7 @@ fn text_lines_in(doc: &Document, p: &pdfcraft_model::Page, actual_text: bool) -> stream: si, scope: s.scope, paint: s.paint.clone(), + containers: s.containers.clone(), logical_order: s.logical_order, actual_text: s.actual_text, clips: s.state.render_mode >= 4, @@ -343,7 +347,7 @@ fn compatible_word(line: &TextLine, shown: &Shown) -> bool { fn add_shown(lines: &mut Vec, last: &mut Option, s: Shown, stream: usize) { let joins = last.is_some_and(|pen| { let bt = pen.bt; - lines.last().is_some_and(|l| l.scope == s.scope && l.paint == s.paint && l.logical_order == s.logical_order) + lines.last().is_some_and(|l| l.scope == s.scope && l.paint == s.paint && l.containers == s.containers && l.logical_order == s.logical_order) && (bt == s.bt || lines.last().is_some_and(|l| compatible_word(l, &s))) && (s.text.trim().is_empty() || lines.last().is_some_and(|l| same_font(l, &s.font, &s.base_font, s.face.as_deref()))) && (s.text.trim().is_empty() @@ -394,6 +398,7 @@ fn add_shown(lines: &mut Vec, last: &mut Option, s: Shown, stream stream, scope: s.scope, paint: s.paint.clone(), + containers: s.containers.clone(), logical_order: s.logical_order, actual_text: s.actual_text, clips: s.state.render_mode >= 4, @@ -563,8 +568,8 @@ pub(super) fn reading_lines(doc: &Document, page: usize) -> Result<(Vec Result<(Vec Result<(), EditError> { + fn enter( + w: &mut Walk, + resources: &Dict, + name: &[u8], + ts: Ts, + text_left: &mut usize, + containers: std::rc::Rc, + at: Vec, + ) -> Result<(), EditError> { let Some(form) = form_call(w.doc, resources, name, ts.ctm, &w.path, &mut w.budget) else { return Ok(()) }; let ops = parse(&form.data).ops; // The form starts with the graphics state at its `Do`, its own matrix applied. - let mut carry = Carry { ts: Ts { ctm: form.ctm, ..ts }, stack: Vec::new(), marked: Vec::new(), layers: Vec::new(), text_left: *text_left }; + let mut carry = Carry { + ts: Ts { ctm: form.ctm, ..ts }, + stack: Vec::new(), + marked: Vec::new(), + layers: Vec::new(), + text_left: *text_left, + containers, + at, + }; let stream = w.next_stream; w.next_stream = w.next_stream.saturating_add(1); if let Some(r) = form.obj { @@ -611,6 +632,7 @@ pub(super) fn reading_lines(doc: &Document, page: usize) -> Result<(Vec>()); let ops = pieces.parse().ops; let stream_of = |i: usize| ops.get(i).map_or(0, |op| pieces.pieces_of(op).0); + carry.containers = std::rc::Rc::new(super::containers::Containers::collect(doc, &ops, &res)); walk(&mut w, &ops, &res, &mut carry, &stream_of)?; let mut lines = w.lines; // A visual-order Indic font draws pre-base vowel signs before their consonant. diff --git a/crates/edit/src/text_containers.rs b/crates/edit/src/text_containers.rs new file mode 100644 index 0000000000..16b1e3a2a2 --- /dev/null +++ b/crates/edit/src/text_containers.rs @@ -0,0 +1,171 @@ +//! Filled rectangular panel boundaries used by editable text grouping. + +use pdfcraft_content::{Matrix, Op}; +use pdfcraft_cos::{Dict, Document, ObjRef}; + +struct Container { + inverse: Matrix, + rect: [f64; 4], + /// Where it is painted in the page's drawing order (see [`Containers::membership`]). + at: Vec, + /// Its bounding box on the page, whatever matrix drew it. + page: [f64; 4], + /// The first container with the same box on the page: a panel painted again behind each of + /// its rows, under any matrix, is still one panel. + id: usize, +} + +#[derive(Default)] +pub(super) struct Containers { + filled: Vec, + pending: Option, + complex: bool, +} + +impl Containers { + pub(super) fn collect(doc: &Document, ops: &[Op], resources: &Dict) -> Self { + let mut collector = Collector { + doc, + containers: Self::default(), + path: Vec::new(), + budget: super::lines::FormBudget::new(pdfcraft_cos::DecodeBudget::page()), + }; + collector.walk(ops, resources, Matrix::IDENTITY, &[]); + let mut first = std::collections::HashMap::new(); + for (index, container) in collector.containers.filled.iter_mut().enumerate() { + let key = container.page.map(|v| (v * 1000.0).round() as i64); + container.id = *first.entry(key).or_insert(index); + } + collector.containers + } + + fn observe(&mut self, op: &Op, ctm: Matrix, at: &[usize]) { + match op.op.as_slice() { + b"re" => { + if self.pending.is_some() { + self.complex = true; + } + self.pending = op.nums::<4>().zip(ctm.invert()).and_then(|([x, y, width, height], inverse)| { + let rect = [x.min(x + width), y.min(y + height), x.max(x + width), y.max(y + height)]; + (rect.iter().all(|v| v.is_finite()) && rect[2] > rect[0] && rect[3] > rect[1]).then_some(Container { + inverse, + rect, + at: Vec::new(), + page: page_box(rect, ctm), + id: 0, + }) + }); + } + b"m" | b"l" | b"c" | b"v" | b"y" => self.complex = true, + b"f" | b"F" | b"f*" | b"B" | b"B*" | b"b" | b"b*" => { + if !self.complex + && self.filled.len() < 4096 + && let Some(mut rect) = self.pending.take() + { + rect.at = at.to_vec(); + self.filled.push(rect); + } + self.pending = None; + self.complex = false; + } + b"n" | b"S" | b"s" => { + self.pending = None; + self.complex = false; + } + _ => {} + } + } + + /// The panels that hold `rect`'s centre and are taller than it. A highlight or inline shading + /// drawn to the height of its glyphs is not a panel, and neither is a fill painted after the + /// text (a redaction cover): `at` is the text's place in the drawing order, the operator + /// indices from the page down through the forms that draw it. + pub(super) fn membership(&self, rect: [f64; 4], at: &[usize]) -> Vec { + let (x, y) = ((rect[0] + rect[2]) / 2.0, (rect[1] + rect[3]) / 2.0); + let mut ids: Vec = self + .filled + .iter() + .filter_map(|container| { + let ys = + [(rect[0], rect[1]), (rect[2], rect[1]), (rect[0], rect[3]), (rect[2], rect[3])].map(|(x, y)| container.inverse.apply(x, y).1); + let height = ys.iter().copied().fold(f64::NEG_INFINITY, f64::max) - ys.iter().copied().fold(f64::INFINITY, f64::min); + let (x, y) = container.inverse.apply(x, y); + let [left, bottom, right, top] = container.rect; + (container.at.as_slice() < at && x >= left && x <= right && y >= bottom && y <= top && top - bottom >= height * 1.15) + .then_some(container.id) + }) + .collect(); + ids.sort_unstable(); + ids.dedup(); + ids + } +} + +fn page_box([left, bottom, right, top]: [f64; 4], ctm: Matrix) -> [f64; 4] { + let corners = [(left, bottom), (right, bottom), (left, top), (right, top)].map(|(x, y)| ctm.apply(x, y)); + corners.iter().fold([f64::INFINITY, f64::INFINITY, f64::NEG_INFINITY, f64::NEG_INFINITY], |[x0, y0, x1, y1], &(x, y)| { + [x0.min(x), y0.min(y), x1.max(x), y1.max(y)] + }) +} + +impl Containers { + /// Whether panel `id` (from [`Containers::membership`]) is no more than a padded highlight + /// around `rect`: under 1.75 times its height on the page. + pub(super) fn hugs(&self, id: usize, rect: [f64; 4]) -> bool { + self.filled.get(id).is_some_and(|panel| panel.page[3] - panel.page[1] < (rect[3] - rect[1]) * 1.75) + } + + /// Whether panel `id` reaches across `rect` from its left edge to its right one on the page. + pub(super) fn spans(&self, id: usize, rect: [f64; 4]) -> bool { + let tolerance = (rect[3] - rect[1]) * 0.25; + self.filled.get(id).is_some_and(|panel| panel.page[0] <= rect[0] + tolerance && panel.page[2] >= rect[2] - tolerance) + } +} + +struct Collector<'a> { + doc: &'a Document, + containers: Containers, + path: Vec, + budget: super::lines::FormBudget, +} + +impl Collector<'_> { + fn walk(&mut self, ops: &[Op], resources: &Dict, initial: Matrix, prefix: &[usize]) { + let mut local = Containers::default(); + let mut ctm = initial; + let mut stack = Vec::new(); + for (i, op) in ops.iter().enumerate() { + let at = [prefix, &[i]].concat(); + local.observe(op, ctm, &at); + match op.op.as_slice() { + b"q" => stack.push(ctm), + b"Q" => { + if let Some(saved) = stack.pop() { + ctm = saved; + } + } + b"cm" => { + if let Some(matrix) = op.nums::<6>() { + ctm = Matrix(matrix).then(&ctm); + } + } + b"Do" => { + if let Some(name) = op.name(0) + && let Some(form) = super::lines::form_call(self.doc, resources, name, ctm, &self.path, &mut self.budget) + { + if let Some(obj) = form.obj { + self.path.push(obj); + } + self.walk(&pdfcraft_content::parse(&form.data).ops, form.resources(resources), form.ctm, &at); + if form.obj.is_some() { + self.path.pop(); + } + } + } + _ => {} + } + } + let remaining = 4096_usize.saturating_sub(self.containers.filled.len()); + self.containers.filled.extend(local.filled.into_iter().take(remaining)); + } +} diff --git a/crates/edit/src/text_regions/grouping.rs b/crates/edit/src/text_regions/grouping.rs index 788499fafe..4b308b2819 100644 --- a/crates/edit/src/text_regions/grouping.rs +++ b/crates/edit/src/text_regions/grouping.rs @@ -5,6 +5,7 @@ fn same_plane(a: &TextLine, b: &TextLine) -> bool { let bt = Matrix(b.origin.tm).then(&Matrix(b.origin.ctm)); a.scope == b.scope && a.paint == b.paint + && a.containers == b.containers && [0, 2].iter().all(|axis| { let ax = at.0.get(*axis).copied().unwrap_or(0.0); let ay = at.0.get(axis + 1).copied().unwrap_or(0.0); @@ -339,7 +340,7 @@ fn group_layout(lines: &[TextLine], mixed: bool) -> Vec { // The rewrite sets every row in the first one's horizontal scale. && (prev.origin.state.scale - first.origin.state.scale).abs() < 1e-6 && aligned - && first.size.min(prev.size) >= first.size.max(prev.size) * 0.4 + && super::super::row_style::compatible(prev_row, row, lines) && gap > first.size.min(prev.size) * 0.8 && gap < max_gap }); diff --git a/crates/edit/src/text_row_style.rs b/crates/edit/src/text_row_style.rs new file mode 100644 index 0000000000..d4db725065 --- /dev/null +++ b/crates/edit/src/text_row_style.rs @@ -0,0 +1,44 @@ +//! Row-level typography compatibility, independent of inline style boundaries. + +use super::TextLine; + +fn family(line: &TextLine) -> String { + const SUFFIXES: [&str; 16] = [ + "bolditalic", + "boldoblique", + "semibold", + "demibold", + "regular", + "boldit", + "italic", + "oblique", + "medium", + "light", + "bold", + "roman", + "psmt", + "mt", + "ps", + "it", + ]; + let mut key = pdfcraft_fonts::embedding::face_key(&line.base_font); + // Weight and style suffixes stack (TimesNewRomanPS-BoldMT), so strip until none is left. + while let Some(base) = SUFFIXES.iter().find_map(|suffix| key.strip_suffix(suffix)).filter(|base| !base.is_empty()) { + key = base.to_owned(); + } + key +} + +pub(super) fn compatible(previous: &[usize], next: &[usize], lines: &[TextLine]) -> bool { + let representative = + |row: &[usize]| row.iter().filter_map(|index| lines.get(*index)).max_by(|a, b| (a.rect[2] - a.rect[0]).total_cmp(&(b.rect[2] - b.rect[0]))); + match (representative(previous), representative(next)) { + (Some(previous), Some(next)) => { + // A row in one of the generated fallback faces holds characters the paragraph's own + // font lacks; the edit chose that face, so it is no change of family. + previous.size.min(next.size) >= previous.size.max(next.size) * 0.65 + && (previous.face.is_some() || next.face.is_some() || family(previous) == family(next)) + } + _ => false, + } +} diff --git a/crates/ui-egui/tests/it/editing.rs b/crates/ui-egui/tests/it/editing.rs index c4231d0f69..8dbc588d3e 100644 --- a/crates/ui-egui/tests/it/editing.rs +++ b/crates/ui-egui/tests/it/editing.rs @@ -6138,7 +6138,7 @@ fn host_dirty_hears_when_unsaved_work_appears_and_goes() { fn one_editor_contains_mixed_styles_and_visual_rows() { let _gpu = gpu(); let bytes = source_font_fixture_with_text( - "BT 0 0.2 0.5 rg /F1 1 Tf 18 0 0 18 20 240 Tm (Heading) Tj ET \ + "BT 0 0.2 0.5 rg /F2 1 Tf 18 0 0 18 20 240 Tm (Heading) Tj ET \ BT 0 g /F2 12 Tf 20 215 Td (Plain ) Tj /F1 12 Tf 0 0.2 0.5 rg (bold) Tj /F2 12 Tf 0 g ( words) Tj ET \ BT /F2 10 Tf 20 195 Td (Last row) Tj ET", ); @@ -6215,7 +6215,7 @@ fn one_editor_contains_mixed_styles_and_visual_rows() { fn the_caret_on_a_small_row_is_as_tall_as_that_row() { // It was one row of the region's first (18 pt) size tall, reaching into the row below. let bytes = source_font_fixture_with_text( - "BT 0 0.2 0.5 rg /F1 1 Tf 18 0 0 18 20 240 Tm (Heading) Tj ET \ + "BT 0 0.2 0.5 rg /F2 1 Tf 18 0 0 18 20 240 Tm (Heading) Tj ET \ BT 0 g /F2 12 Tf 20 215 Td (Plain ) Tj /F1 12 Tf 0 0.2 0.5 rg (bold) Tj /F2 12 Tf 0 g ( words) Tj ET \ BT /F2 10 Tf 20 195 Td (Last row) Tj ET", ); diff --git a/docs/roadmap.md b/docs/roadmap.md index d17893c1aa..af801b88a9 100644 --- a/docs/roadmap.md +++ b/docs/roadmap.md @@ -1,5 +1,7 @@ # PdfCraft roadmap: milestones and what's next +> **Last reviewed:** 2026-11-04 | **Last updated:** 2026-11-04 | **Change:** minor (M7: paragraph boundaries respect row typography and page-wide filled panels; estimates unchanged) + > **Last reviewed:** 2026-11-03 | **Last updated:** 2026-11-03 | **Change:** patch (M5 #5850 review: indirect typewriter intent and composer edits preserve outer whitespace; movement regression commits by outside click; estimates unchanged) > **Last reviewed:** 2026-11-03 | **Last updated:** 2026-11-03 | **Change:** patch (M5 #5850: Enter adds Fill & Sign line breaks; outside clicks commit, Escape cancels, and saved multiline appearances retain their text and height; estimates unchanged) @@ -233,7 +235,7 @@ total matches the parity estimate. | M6 | Forms + JavaScript | 160–320 | 50% | 40–75 | Done: filling all field types with regenerated appearances; Prepare a form (every field type, multi-select/shared properties, move/resize/delete, Field Properties General/Appearance/Position/Options/Format/Validate/Calculate); Acrobat's AF format/keystroke/validate/calculate functions and simplified field notation run natively in Acrobat's event order; tab order; push-button actions; flatten; agent tools. Form data exchange (FDF, XFDF, XML, CSV, text) done; XFDF values retain text across XML comments and processing instructions. XML/XFDF exports preserve tabs and line breaks in names and comment metadata. Plain AcroForm XML imports retain all direct text around comments and processing instructions, including CDATA and character references. CSV export and spreadsheet merging quote tabs, and import distinguishes quoted tabs from TSV delimiters without changing field identities.
Done since: JavaScript engine (boa, sandboxed) running custom keystroke/validate/calculate/format and button scripts, document JavaScripts, console. Missing: Actions tab, wider object model (annotations, layers, dialogs), XFA
Done since: Multi-select choice fields write ascending `/I` option indices while preserving `/V` selection order; synthetic forms/engine regressions cover reverse selection and save/reopen. CSV export preserves carriage returns in names and values. | | M7 | Content editing (text, images, header/footer, watermark) | 250–500 | 20% | 100–180 | Done: header & footer, watermarks, backgrounds, Bates; added text and images that stay editable (move, resize, format, rotate, flip, crop, replace); links (Link tool, Link Properties, create from URLs, remove all). Done since: Edit text preserves Arabic/Hebrew `/ActualText` typing order, with font-independent regressions; single-glyph RTL ligature spans (including lam-alef) join their surrounding word. Done since (#1116): editable text regions grouped across compatible words and subset fonts, one rich-text editor over a background with the source text removed, embedded sfnt faces reused as editor faces, and visible (clipped) bounds for cropped-image selection and resize. Exclusive crops now resize across nested states and content streams, with shared clips fixed.
Done since: #594 ordinary paragraph drags preserve overlapping source text; UI/engine regressions, native save/reopen, independent-reader checks and full CI passed in the Linux test environment. #1200 candidate: local GoToR links open in desktop tabs and through root-confined automation; appearance-only edits preserve existing actions. Named destinations remain unapplied and `/NewWindow` is a tab hint. Done since: #3187: Added-image automation normalizes extreme signed rotation angles before combining them with the current orientation; integer bounds, history, pixels, save/reopen and MCP have regressions. Done since: #2592: Styled fallback fonts batch up to 240 glyphs per actual face and retain source styles. Budget refusal and distinct same-BaseFont descriptor weights have mutation-checked regressions; coverage and complex mixed runs remain limited. Done since: #5657 page-mark operations are atomic across selected pages, including shared/inherited resources and existing unsaved edits. Missing: editing existing text and images in place (the longest pole), image/PDF watermarks PR #2155 candidate: editor-owned crops preserve original clips through group moves; Arrange preserves added-item stream ownership and refuses unsafe scope/state/tag extraction; image handles and flips follow page orientation; general transforms and Unicode script toggles have headless tools. Clipboard, mixed-size formatting, Home pins and reloadable installed-font discovery have review regressions. Latest follow-up uses explicit image-paste events, refreshes the mixed-size display, and documents script normalization with Undo. Further review covers inherited Form text and mask chronology, scoped transform composition, affine resize/rotation pivots, paste/selection ownership, no-op scripts and page-menu permissions. Done since: #5835 a right-click on an image in crop mode keeps the crop and opens no menu, also over overlapping and rotated images. | | M7 | Content editing (text, images, header/footer, watermark) | 250–500 | 20% | 100–180 | Done: header & footer, watermarks, backgrounds, Bates; added text and images that stay editable (move, resize, format, rotate, flip, crop, replace); links (Link tool, Link Properties, create from URLs, remove all). Done since: Edit text preserves Arabic/Hebrew `/ActualText` typing order, with font-independent regressions. Done since (#1116): editable text regions grouped across compatible words and subset fonts, one rich-text editor over a background with the source text removed, embedded sfnt faces reused as editor faces, and visible (clipped) bounds for cropped-image selection and resize. Exclusive crops now resize across nested states and content streams, with shared clips fixed.
Done since: #594 ordinary paragraph drags preserve overlapping source text; UI/engine regressions, native save/reopen, independent-reader checks and full CI passed in the Linux test environment. #1200 candidate: local GoToR links open in desktop tabs and through root-confined automation; appearance-only edits preserve existing actions. Named destinations remain unapplied and `/NewWindow` is a tab hint. #1316: replacing a line or paragraph keeps a neighbouring line whose glyph box overlaps when the baselines differ; a second copy on the same baseline is still replaced. Missing: editing existing text and images in place (the longest pole), image/PDF watermarks | -| M7 | Content editing (text, images, header/footer, watermark) | 250–500 | 20% | 100–180 | Done: header & footer, watermarks, backgrounds, Bates; added text and images that stay editable (move, resize, format, rotate, flip, crop, replace); links (Link tool, Link Properties, create from URLs, remove all). #3212: Headers, Bates numbers, watermarks and added text stay visible after unfinished marked content, without revealing hidden content. Tracked editable text distinguishes repeated glyph spacing from word gaps, with synthetic paragraph/object regressions. Missing: editing existing text and images in place (the longest pole), watermark print/screen visibility and repeat | +| M7 | Content editing (text, images, header/footer, watermark) | 250–500 | 20% | 100–180 | Done: header & footer, watermarks, backgrounds, Bates; added text and images that stay editable (move, resize, format, rotate, flip, crop, replace); links (Link tool, Link Properties, create from URLs, remove all). #3212: Headers, Bates numbers, watermarks and added text stay visible after unfinished marked content, without revealing hidden content. Tracked editable text distinguishes repeated glyph spacing from word gaps, with synthetic paragraph/object regressions. Paragraphs separate across large row-size changes, font-family changes and filled rectangular panels without splitting compatible multiline text or inline styles. Panel membership is page-wide across content streams and transformed forms, with split-path and isolated-panel save/reopen regressions; delayed-background rewrite checks (#2377) remain covered. Missing: editing existing text and images in place (the longest pole), watermark print/screen visibility and repeat | | M6 | Forms + JavaScript | 160–320 | 50% | 40–75 | Done: filling all field types with regenerated appearances; Prepare a form (every field type, multi-select/shared properties, move/resize/delete, Field Properties General/Appearance/Position/Options/Format/Validate/Calculate); Acrobat's AF format/keystroke/validate/calculate functions and simplified field notation run natively in Acrobat's event order; tab order; push-button actions; flatten; agent tools. Form data exchange (FDF, XFDF, XML, CSV, text) done; XFDF values retain text across XML comments and processing instructions.
Done since: JavaScript engine (boa, sandboxed) running custom keystroke/validate/calculate/format and button scripts, document JavaScripts, console. Missing: Actions tab, wider object model (annotations, layers, dialogs), XFA
Done since: Existing simple field-font encodings and Differences are respected when generating appearances; an unencodable value uses a separate Helvetica appearance font without changing the source font. Synthetic reopen regressions cover punctuation, subset fallback and multiline text. Exact font metrics/layout and broader Unicode fallback remain incomplete. | | M6 | Forms + JavaScript | 160–320 | 50% | 40–75 | Done: filling all field types with regenerated appearances; Prepare a form (every field type, multi-select/shared properties, move/resize/delete, Field Properties General/Appearance/Position/Options/Format/Validate/Calculate); Acrobat's AF format/keystroke/validate/calculate functions and simplified field notation run natively in Acrobat's event order; tab order; push-button actions; flatten; agent tools. Form data exchange (FDF, XFDF, XML, CSV, text) done; XFDF values retain text across XML comments and processing instructions.
Done since: JavaScript engine (boa, sandboxed) running custom keystroke/validate/calculate/format and button scripts, document JavaScripts, console. Missing: Actions tab, wider object model (annotations, layers, dialogs), XFA
Done since: Tab and Shift-Tab wrapping to the same field or another widget of that field refresh the newly opened editor from the accepted value before Save. Synthetic UI regressions cover both directions, same-frame Save, validation refusal and undo/redo. Renaming a field renames it in the calculations that read it (field lists, notation, literal `getField` names), in one undo step, and says how many changed. Prepare a form ▸ Calculation order, a page of its own: each calculated field's formula and value, what is wrong (fields that calculate too early, loops, fields missing from `/CO`) and Fix order, Up/Down, Alt+↑/↓ and drag, and on the page each field's step and arrows to and from the field in focus (`form_calculation_order` headlessly). | | M7 | Content editing (text, images, header/footer, watermark) | 250–500 | 20% | 100–180 | Done: header & footer, watermarks, backgrounds, Bates; added text and images that stay editable (move, resize, format, rotate, flip, crop, replace); links (Link tool, Link Properties, create from URLs, remove all). Missing: editing existing text and images in place (the longest pole), image/PDF watermarks | @@ -304,6 +306,7 @@ Estimates unchanged. | Date | Change | Summary | |---|---|---| +| 2026-11-04 | minor | M7: row typography and page-wide filled panels define paragraph boundaries across content streams and transformed forms; compatible multiline/inline styles, isolated-panel edits and delayed-background rewriting remain covered. Estimates unchanged. | | 2026-11-03 | minor | M11: Optimize's JBIG2 images share a symbol dictionary (`/JBIG2Globals`), up to 16 at a time and when smaller (`pdfcraft_filters::encode_jbig2_shared`): 41–46% smaller on rendered text in proportional fonts, 10% in Courier | | 2026-11-03 | patch | M5 #5850 review: indirect typewriter intent and composer edits preserve outer whitespace; movement regression commits by outside click; estimates unchanged. | | 2026-11-03 | patch | M5 #5850: Enter adds Fill & Sign line breaks; outside clicks commit, Escape cancels, and saved multiline appearances retain their text and height; estimates unchanged. |