mirror of
https://github.com/storytold/pdfcraft.git
synced 2026-11-09 12:32:52 +00:00
Copying selected page text now also puts an HTML fragment on the system clipboard, so a paste into a word processor or mail client keeps paragraphs, bold, italic, size, colour and font family. The plain text is unchanged and stays on the clipboard as the alternative. - export: clip.rs, the clipboard model (ClipText of paragraphs of styled spans), its builder with caps (20 000 spans, 2 MiB of text, 16 MiB of HTML), font_family (subset tag and style suffixes off, camel case spaced) and clip_html. Family names are reduced to letters, digits, space, '-', '_' and '.', so a font name cannot leave the CSS string; text goes through esc, which drops control characters. - engine: Document::rich_copy(page, text, glyphs). Glyphs (view space) take the style of the reading block their centre lies in; blocks are style-homogeneous. A line wrap inside a block is a space (none after a hyphen), a change of block a new paragraph. Refused when the document does not allow copying. compare.rs's display unit and weight/slant inference are shared, not duplicated. - automation: text_extract takes format "text" (default) or "html"; html adds each page's html and styles_incomplete, for the whole page or only what rect takes. Other values are InvalidArgs. - ui-egui: Copy of a run or column selection writes HTML plus the plain text in one arboard set (desktop only); the web build and Select All of the whole document stay plain text. last_copied_html records what was produced, for tests. - parity: view.copy-with-layout is partial; notes list what is missing (RTF, underline/strike-through, tables, Select All, web, glyphs outside reading blocks). Formatting inference and the HTML serialiser are adapted from pdfcer (MIT, same author) at 540b00ef1a405d1baa67c92f3858535037c7cde8. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01SqmHYx8FiWM5PcsoiErgp9
46 lines
1.5 KiB
Rust
46 lines
1.5 KiB
Rust
//! pdfcraft-export — Export a PDF ▸ Word, HTML, RTF, Markdown (L4).
|
|
//!
|
|
//! The engine reduces each page to [`Page`]: paragraphs (text, box, size, bold/italic) and
|
|
//! images (encoded bytes and box), in reading order. The writers turn that into a flowing
|
|
//! document: headings are the paragraphs set larger than the body text, and a block that
|
|
//! continues another on its line (an italic word, a link) is a run of that block's paragraph.
|
|
//! Word keeps pages with
|
|
//! rotated text, or text overlapped by artwork or watermark-sized text, as positioned, editable
|
|
//! shapes to avoid reflowing overlays; other pages flow with images inline.
|
|
|
|
#![deny(clippy::unwrap_used, clippy::expect_used, clippy::panic, clippy::unimplemented, clippy::todo, clippy::unreachable)]
|
|
|
|
mod pptx;
|
|
mod zip;
|
|
|
|
pub use pptx::pptx;
|
|
pub use zip::Zip;
|
|
|
|
mod as_docx;
|
|
mod as_html;
|
|
mod as_markdown;
|
|
mod as_rtf;
|
|
mod clip;
|
|
mod layout;
|
|
|
|
pub use as_docx::docx;
|
|
pub(crate) use as_docx::hex;
|
|
#[cfg(test)]
|
|
use as_docx::{MAX_MEDIA, docx_table};
|
|
pub(crate) use as_html::esc;
|
|
#[cfg(test)]
|
|
use as_html::{allowed, base64};
|
|
pub use as_html::{html, html_simple};
|
|
pub use as_markdown::markdown;
|
|
#[cfg(test)]
|
|
use as_markdown::{emphasis, paragraph};
|
|
pub use as_rtf::rtf;
|
|
pub use clip::{ClipBuilder, ClipSpan, ClipStyle, ClipText, MAX_CLIP_HTML_BYTES, MAX_CLIP_SPANS, MAX_CLIP_TEXT_BYTES, clip_html, font_family};
|
|
pub use layout::{Block, Cell, Image, Page, Table};
|
|
#[cfg(test)]
|
|
use layout::{LOOKUP_STEPS, MAX_COLS, body_size};
|
|
pub(crate) use layout::{Run, paragraphs, tables};
|
|
|
|
#[cfg(test)]
|
|
mod tests;
|