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)
}
+7 -1
View File
@@ -2,7 +2,7 @@
use std::{io, path::Path};
use ely_ipc::Unpack;
use ely_ipc::{Pack, Unpack};
use crate::client::{Doc, Worker};
use crate::proto::tag;
@@ -42,6 +42,12 @@ impl Worker {
self.request(tag::PRINT_COPY, &self.whole(&doc)?.str(utf8(out)?).bytes()).map(|_| ())
}
/// HTML `page` in `dir`, with its pictures, as a PDF.
pub fn html_pdf(&mut self, dir: &Path, page: &str, out: &Path) -> io::Result<()> {
let ask = Pack::new().str(utf8(dir)?).str(page).str(utf8(out)?);
self.request(tag::HTML_PDF, &ask.bytes()).map(|_| ())
}
/// Decodes every picture; true if any failed.
pub fn check_pictures(&mut self, doc: Doc) -> io::Result<bool> {
let reply = self.request(tag::CHECK_PICTURES, &self.whole(&doc)?.bytes())?;
+2
View File
@@ -81,6 +81,8 @@ pub mod tag {
pub const REPAIR_REPORT: u8 = 58;
/// Decodes every picture; answers whether any failed.
pub const CHECK_PICTURES: u8 = 59;
/// A folder's HTML page as a new PDF; no document.
pub const HTML_PDF: u8 = 60;
pub const OK: u8 = 100;
pub const ERR: u8 = 101;
}