From 5555b1a2493e7263ec50af5cd1d22b9526af1642 Mon Sep 17 00:00:00 2001 From: kiwi4boy Date: Mon, 16 Nov 2026 21:36:55 -0500 Subject: [PATCH] export: pin craft-libs main with push_text, the header-row fix and the RTF generator name craft-rtf, craft-wordmodel, craft-docx and craft-mime move to craft-libs b8eaa8e2, which has storytold/craft-libs#1946, #1947 and #1950. The mapping appends through Paragraph::push_text/push_object, tables keep the default look, and the RTF names PdfCraft as its generator. --- Cargo.lock | 18 ++++++++-------- Cargo.toml | 8 +++---- crates/export/src/as_rtf.rs | 5 ++++- crates/export/src/as_word.rs | 42 ++++++++---------------------------- crates/export/src/tests.rs | 6 ++++-- 5 files changed, 30 insertions(+), 49 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 4d4328c509..2ea38f655b 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1211,7 +1211,7 @@ dependencies = [ [[package]] name = "craft-codepage" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=892ef9116c432d7afb5c08aba93e93a4e0b1548f#892ef9116c432d7afb5c08aba93e93a4e0b1548f" +source = "git+https://github.com/storytold/craft-libs?rev=b8eaa8e2f3561f9fa27fcf3b7f67ce915e93caa3#b8eaa8e2f3561f9fa27fcf3b7f67ce915e93caa3" [[package]] name = "craft-csv" @@ -1229,7 +1229,7 @@ source = "git+https://github.com/storytold/craft-libs?rev=e2dc681a3#e2dc681a3ad8 [[package]] name = "craft-flow" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=892ef9116c432d7afb5c08aba93e93a4e0b1548f#892ef9116c432d7afb5c08aba93e93a4e0b1548f" +source = "git+https://github.com/storytold/craft-libs?rev=b8eaa8e2f3561f9fa27fcf3b7f67ce915e93caa3#b8eaa8e2f3561f9fa27fcf3b7f67ce915e93caa3" dependencies = [ "craft-wordmodel", "image", @@ -1307,9 +1307,9 @@ dependencies = [ [[package]] name = "craft-math" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=892ef9116c432d7afb5c08aba93e93a4e0b1548f#892ef9116c432d7afb5c08aba93e93a4e0b1548f" +source = "git+https://github.com/storytold/craft-libs?rev=b8eaa8e2f3561f9fa27fcf3b7f67ce915e93caa3#b8eaa8e2f3561f9fa27fcf3b7f67ce915e93caa3" dependencies = [ - "craft-xml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=892ef9116c432d7afb5c08aba93e93a4e0b1548f)", + "craft-xml 0.1.0 (git+https://github.com/storytold/craft-libs?rev=b8eaa8e2f3561f9fa27fcf3b7f67ce915e93caa3)", "serde", ] @@ -1329,7 +1329,7 @@ dependencies = [ [[package]] name = "craft-metafile" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=892ef9116c432d7afb5c08aba93e93a4e0b1548f#892ef9116c432d7afb5c08aba93e93a4e0b1548f" +source = "git+https://github.com/storytold/craft-libs?rev=b8eaa8e2f3561f9fa27fcf3b7f67ce915e93caa3#b8eaa8e2f3561f9fa27fcf3b7f67ce915e93caa3" dependencies = [ "encoding_rs", "image", @@ -1340,7 +1340,7 @@ dependencies = [ [[package]] name = "craft-mime" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=892ef9116c432d7afb5c08aba93e93a4e0b1548f#892ef9116c432d7afb5c08aba93e93a4e0b1548f" +source = "git+https://github.com/storytold/craft-libs?rev=b8eaa8e2f3561f9fa27fcf3b7f67ce915e93caa3#b8eaa8e2f3561f9fa27fcf3b7f67ce915e93caa3" dependencies = [ "chrono", "craft-codepage", @@ -1446,7 +1446,7 @@ dependencies = [ [[package]] name = "craft-rtf" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=892ef9116c432d7afb5c08aba93e93a4e0b1548f#892ef9116c432d7afb5c08aba93e93a4e0b1548f" +source = "git+https://github.com/storytold/craft-libs?rev=b8eaa8e2f3561f9fa27fcf3b7f67ce915e93caa3#b8eaa8e2f3561f9fa27fcf3b7f67ce915e93caa3" dependencies = [ "craft-codepage", "craft-flow", @@ -1555,7 +1555,7 @@ dependencies = [ [[package]] name = "craft-wordmodel" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=892ef9116c432d7afb5c08aba93e93a4e0b1548f#892ef9116c432d7afb5c08aba93e93a4e0b1548f" +source = "git+https://github.com/storytold/craft-libs?rev=b8eaa8e2f3561f9fa27fcf3b7f67ce915e93caa3#b8eaa8e2f3561f9fa27fcf3b7f67ce915e93caa3" dependencies = [ "base64 0.23.1", "craft-math", @@ -1569,7 +1569,7 @@ dependencies = [ [[package]] name = "craft-xml" version = "0.1.0" -source = "git+https://github.com/storytold/craft-libs?rev=892ef9116c432d7afb5c08aba93e93a4e0b1548f#892ef9116c432d7afb5c08aba93e93a4e0b1548f" +source = "git+https://github.com/storytold/craft-libs?rev=b8eaa8e2f3561f9fa27fcf3b7f67ce915e93caa3#b8eaa8e2f3561f9fa27fcf3b7f67ce915e93caa3" dependencies = [ "quick-xml 0.41.0", "serde", diff --git a/Cargo.toml b/Cargo.toml index eb1eb2bcf5..5d6c178550 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -37,16 +37,16 @@ craft-update = { git = "https://github.com/storytold/craft-libs", version = "=0. craft-pdf = { git = "https://github.com/storytold/craft-libs", version = "0.1.0", rev = "8e03cd016d42032b867fef6bad86bc69bf2c1920", features = ["cos", "crypt", "filters"] } # The writers the Word and RTF exports map onto (storytold/craft-libs#793). craft-rtf, craft-wordmodel and # craft-docx move together: craft_rtf::doc::export takes its own revision's Document. -craft-rtf = { git = "https://github.com/storytold/craft-libs", version = "0.1.0", rev = "892ef9116c432d7afb5c08aba93e93a4e0b1548f" } +craft-rtf = { git = "https://github.com/storytold/craft-libs", version = "0.1.0", rev = "b8eaa8e2f3561f9fa27fcf3b7f67ce915e93caa3" } # Shared Base64 encoder; use the existing RTF revision to reuse its codepage dependency. -craft-mime = { git = "https://github.com/storytold/craft-libs", version = "0.1.0", rev = "892ef9116c432d7afb5c08aba93e93a4e0b1548f" } +craft-mime = { git = "https://github.com/storytold/craft-libs", version = "0.1.0", rev = "b8eaa8e2f3561f9fa27fcf3b7f67ce915e93caa3" } craft-csv = { git = "https://github.com/storytold/craft-libs", version = "0.1.0", rev = "e2dc681a3" } craft-xml = { git = "https://github.com/storytold/craft-libs", version = "0.1.0", rev = "e2dc681a3" } craft-image-codecs = { git = "https://github.com/storytold/craft-libs", version = "0.1.0", rev = "e2dc681a3" } craft-tiff = { git = "https://github.com/storytold/craft-libs", version = "0.1.0", rev = "e2dc681a3" } craft-jpeg = { git = "https://github.com/storytold/craft-libs", version = "0.1.0", rev = "e2dc681a3" } -craft-docx = { git = "https://github.com/storytold/craft-libs", version = "0.1.0", rev = "892ef9116c432d7afb5c08aba93e93a4e0b1548f" } -craft-wordmodel = { git = "https://github.com/storytold/craft-libs", version = "0.1.0", rev = "892ef9116c432d7afb5c08aba93e93a4e0b1548f" } +craft-docx = { git = "https://github.com/storytold/craft-libs", version = "0.1.0", rev = "b8eaa8e2f3561f9fa27fcf3b7f67ce915e93caa3" } +craft-wordmodel = { git = "https://github.com/storytold/craft-libs", version = "0.1.0", rev = "b8eaa8e2f3561f9fa27fcf3b7f67ce915e93caa3" } craft-pptx = { git = "https://github.com/storytold/craft-libs", version = "0.1.0", rev = "e2dc681a3" } craft-drawingml = { git = "https://github.com/storytold/craft-libs", version = "0.1.0", rev = "e2dc681a3" } craft-opc = { git = "https://github.com/storytold/craft-libs", version = "0.1.0", rev = "e2dc681a3" } diff --git a/crates/export/src/as_rtf.rs b/crates/export/src/as_rtf.rs index 4ab7a39c2c..b5ae44d137 100644 --- a/crates/export/src/as_rtf.rs +++ b/crates/export/src/as_rtf.rs @@ -8,6 +8,9 @@ use super::layout::Page; /// it in its sans-serif, which the font table's `\fswiss` asks for). const FONT: &str = "Helvetica"; +/// The application the RTF names as its writer (`{\*\generator}`). +pub(crate) const GENERATOR: &str = "PdfCraft"; + /// Rich Text Format: paragraphs with their sizes, bold, italic and colours, headings, tables, /// pictures, and each page in a section of its own size. pub fn rtf(pages: &[Page]) -> String { @@ -16,5 +19,5 @@ pub fn rtf(pages: &[Page]) -> String { /// [`rtf`] with the document's title (`\info\title`). pub fn rtf_with_title(pages: &[Page], title: &str) -> String { - craft_rtf::doc::export(&flow_doc(pages, &Meta { title, language: None, font: FONT })) + craft_rtf::doc::export_with_generator(&flow_doc(pages, &Meta { title, language: None, font: FONT }), GENERATOR) } diff --git a/crates/export/src/as_word.rs b/crates/export/src/as_word.rs index 176a244883..01d9d3723c 100644 --- a/crates/export/src/as_word.rs +++ b/crates/export/src/as_word.rs @@ -6,8 +6,8 @@ use super::as_docx::{MAX_MEDIA, rgb8}; use super::as_html::{allowed, language_tag}; use super::layout::{Image, Item, Page, Table, items}; -use craft_wordmodel::para::{Float, OBJ}; -use craft_wordmodel::props::{Border, BorderStyle, Borders, CellProps, LineSpacing, TableLook, TableProps}; +use craft_wordmodel::para::Float; +use craft_wordmodel::props::{Border, BorderStyle, Borders, CellProps, LineSpacing, TableProps}; use craft_wordmodel::{Block, CharProps, Document, InlineObject, ParaProps, Paragraph, Rgb, SectionProps, Style, StyleSheet, TextColor}; /// A run's formatting: its size, bold, italic and colour (none for black, the default). @@ -24,36 +24,15 @@ fn chr(size: f64, bold: bool, italic: bool, color: [f64; 3]) -> CharProps { } } -/// Appends `text` to `p` as a run, merged into the last one when the formatting is the same. Only -/// the characters Word and RTF readers accept, and never U+FFFC, the model's object mark: in the -/// PDF's text it is a character, not an object. Appending to the fields takes constant time, where -/// `Paragraph::insert_text` walks every run on each call. +/// Appends `text` to `p` as a run (`Paragraph::push_text` drops U+FFFC, the model's object mark, +/// which in the PDF's text is a character, not an object), keeping only the characters Word and +/// RTF readers accept. fn push_text(p: &mut Paragraph, text: &str, props: CharProps) { // A hard line ending in the text (LF, CR or CRLF) is a line break, the model's `\n`, which the // writers keep inside its paragraph or cell (storytold/pdfcraft#4723). let text = text.replace("\r\n", "\n").replace('\r', "\n"); - let text: String = text.chars().filter(|c| allowed(*c) && *c != OBJ).collect(); - if text.is_empty() { - return; - } - p.text.push_str(&text); - match p.runs.last_mut() { - Some(last) if last.props == props => last.len += text.len(), - _ => p.runs.push(craft_wordmodel::Run { len: text.len(), props }), - } -} - -/// Appends an object to `p` in constant time (`Paragraph::insert_object` counts the objects before -/// its offset). -fn push_object(p: &mut Paragraph, obj: InlineObject) { - let props = CharProps::default(); - p.text.push(OBJ); - p.objects.push(obj); - let len = OBJ.len_utf8(); - match p.runs.last_mut() { - Some(last) if last.props == props => last.len += len, - _ => p.runs.push(craft_wordmodel::Run { len, props }), - } + let text: String = text.chars().filter(|c| allowed(*c)).collect(); + p.push_text(&text, &props); } /// A table: its grid from the column edges, ruled where the PDF draws rules, one paragraph per @@ -75,9 +54,6 @@ fn table(t: &Table) -> craft_wordmodel::Table { between: rule(inside), inside_v: rule(inside), }), - // No table style, so none of its options: no header row, bands or first column. (craft-flow - // made the first row of a table with no style a header row from the default look.) - look: TableLook { header_row: false, total_row: false, banded_rows: false, first_column: false, last_column: false, banded_columns: false }, ..TableProps::default() }; let rows = t @@ -163,8 +139,7 @@ fn picture(doc: &mut Document, im: &Image, sec: &SectionProps) -> Paragraph { let k = (text_w / w).min(1.0); let media = doc.add_media(im.bytes.to_vec(), im.ext); let mut p = Paragraph::new(); - push_object( - &mut p, + p.push_object( InlineObject::Image { media, w: (w * k) as f32, @@ -175,6 +150,7 @@ fn picture(doc: &mut Document, im: &Image, sec: &SectionProps) -> Paragraph { fx: Default::default(), ole: None, }, + &CharProps::default(), ); p } diff --git a/crates/export/src/tests.rs b/crates/export/src/tests.rs index f9ea2ba72a..c37bbdbb62 100644 --- a/crates/export/src/tests.rs +++ b/crates/export/src/tests.rs @@ -1509,11 +1509,13 @@ fn rtf_headings_have_heading_styles() { assert_eq!(style, Some(Some(0)), "Annual Report is a level 1 heading: {r}"); } -/// The document's title goes into the RTF's information group. +/// The document's title goes into the RTF's information group, and PdfCraft is named as the +/// application that wrote it. #[test] -fn rtf_names_the_title() { +fn rtf_names_the_title_and_pdfcraft() { let r = crate::rtf_with_title(&[page()], "Annual Report"); assert_eq!(craft_rtf::doc::import(r.as_bytes()).unwrap().core.title, "Annual Report", "{r}"); + assert!(r.contains(r"{\*\generator PdfCraft;}") && !r.contains("WordCraft"), "{r}"); } /// Two tables one under the other stay two tables: in RTF, rows that follow each other are one