Files
pdfcraft/crates/export/src/as_rtf.rs
T
kiwi4boy f77ad824ee Merge main (#7814, which landed steps 1 and 2) and keep the RTF picture fixes
#7814 brought this branch's first two commits to main inside step 2, but not the three
fixes made here since: the RTF picture budget that counts every placement, rotations baked
into the pictures, pictures fitted to the text height, and the pages that lost a picture
reported through truncated_pages. They now sit in step 2's Builder: RTF's flow_doc gives
it a pictures::Budget, and Word's word_doc doesn't, so Word keeps its own limits
(room_for) and turns positioned pictures through their float. The text-height fit is in
the shared picture(), so Word's flowing pictures fit too.

The truncated_pages doc now says what RTF reports: pictures lost to its own limits or a
rotation it couldn't bake. A picture no format can encode is left out of all of them.
2026-11-18 17:28:58 -05:00

31 lines
1.3 KiB
Rust

//! Rich Text Format through craft-rtf's full writer (storytold/craft-libs#793): the pages are
//! mapped onto a `craft_wordmodel::Document` ([`super::as_word`]), every page flowing.
use super::as_word::{Meta, flow_doc};
use super::layout::Page;
/// The body text's font, as PdfCraft's RTF has always named it (a reader without Helvetica draws
/// 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 {
rtf_with_title(pages, "")
}
/// [`rtf`] with the document's title (`\info\title`).
pub fn rtf_with_title(pages: &[Page], title: &str) -> String {
rtf_with_title_checked(pages, title).0
}
/// [`rtf_with_title`], and the pages (0-based) that lost a picture: one past the RTF's limits on
/// its pictures, or one it couldn't prepare. Those pages keep their other content.
pub fn rtf_with_title_checked(pages: &[Page], title: &str) -> (String, Vec<usize>) {
let (doc, omitted) = flow_doc(pages, &Meta { title, language: None, font: FONT });
(craft_rtf::doc::export_with_generator(&doc, GENERATOR), omitted)
}