C14.14: export HTML, HTML and folder, PDF (MuPDF story in the PDF worker) and plain text; print; rich copy

Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
ZacharyZhang-NYandClaude Opus 5.5 committed 2026-10-12 10:16:11 -04:00
1 parent f1cb7eff99
commit d7ded183ae
27 files changed
+1427 -24

No files matched your search

@@ -331,7 +331,7 @@ impl Worker {
// A document request names the state it was made for.
let stamped;
let payload = match kind {
tag::OPEN | tag::HELLO => payload,
tag::OPEN | tag::HELLO | tag::HTML_PDF => payload,
_ => {
stamped = self.current(payload)?;
&stamped
@@ -415,6 +415,10 @@ impl Worker {
}
tag::OUTLINE => self.mupdf.outline(self.doc(ask.u64()?)?),
tag::HELLO => Ok(Pack::new().str(ely_pdf_engine::proto::BUILD).bytes()),
tag::HTML_PDF => {
let (dir, page, out) = (ask.str()?, ask.str()?, ask.str()?);
self.mupdf.html_pdf(&dir, &page, &out).map(|()| Vec::new())
}
tag::CLOSE => {
self.forget(ask.u64()?)?;
Ok(Vec::new())
@@ -34,6 +34,7 @@ unsafe extern "C" {
fn ely_watch_end(ctx: *mut Context) -> c_int;
fn ely_check_pictures(ctx: *mut Context, doc: *mut Document) -> c_int;
fn ely_print_copy(ctx: *mut Context, doc: *mut Document, raw: *const c_char, out: *const c_char, password: *const c_char) -> c_int;
fn ely_html_pdf(ctx: *mut Context, dir: *const c_char, page: *const c_char, out: *const c_char) -> c_int;
}
/// What MuPDF warned while opening the last file.
@@ -56,6 +57,16 @@ impl Mupdf {
done.map(|_| ())
}
/// `page` in `dir` set as a PDF at `out`.
pub fn html_pdf(&self, dir: &str, page: &str, out: &str) -> io::Result<()> {
let (dir_c, page_c, out_c) = (text(dir)?, text(page)?, text(out)?);
let done = checked(unsafe { ely_html_pdf(self.ctx, dir_c.as_ptr(), page_c.as_ptr(), out_c.as_ptr()) });
if done.is_err() {
clean(out.as_ref());
}
done.map(|_| log::info!("pdf-worker: set an HTML page as a PDF"))
}
pub fn repaired(&self, doc: &Open) -> io::Result<bool> {
checked(unsafe { ely_repaired(self.ctx, doc.0) }).map(|repaired| repaired != 0)
}