R7.4: an unembedded font is no damage (#5)
The warning watch skips MuPDF's non-embedded font notice and its repeat counts. Text and search reads are watched too: damage they meet is kept on the document, told by the next draw or picture check, and fails image and text exports until then. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
This commit is contained in:
1 parent
969cb67c96
commit
6b676e06e6
9 files changed
+191
-9
No files matched your search
@@ -31,6 +31,8 @@ struct Doc {
|
||||
/// What MuPDF warned at open; kept as the repair report.
|
||||
warnings: String,
|
||||
repair: Option<String>,
|
||||
/// Damage a read met that no draw has told yet.
|
||||
found: bool,
|
||||
/// The repaired copy standing in; removed on close.
|
||||
copy: Option<std::path::PathBuf>,
|
||||
/// MuPDF's steps: an edit's id, or none for a save.
|
||||
@@ -359,7 +361,7 @@ impl Worker {
|
||||
let id = self.next;
|
||||
self.next += 1;
|
||||
let warnings = output::open_warnings();
|
||||
let doc = Doc { open, password: String::new(), owner, warnings, repair: None, copy: None, steps: Vec::new(), at: 0 };
|
||||
let doc = Doc { open, password: String::new(), owner, warnings, repair: None, found: false, copy: None, steps: Vec::new(), at: 0 };
|
||||
self.docs.insert(id, doc);
|
||||
if !locked && let Err(error) = self.repair(id) {
|
||||
self.forget(id)?;
|
||||
@@ -405,13 +407,12 @@ impl Worker {
|
||||
self.drawn(id, page, (scale, rotate), tile, dark)
|
||||
}
|
||||
tag::TEXT => {
|
||||
let doc = self.doc(ask.u64()?)?;
|
||||
self.mupdf.text(doc, ask.u64()? as usize)
|
||||
let (id, page) = (ask.u64()?, ask.u64()? as usize);
|
||||
self.read(id, |mupdf, doc| mupdf.text(doc, page))
|
||||
}
|
||||
tag::SEARCH => {
|
||||
let doc = self.doc(ask.u64()?)?;
|
||||
let page = ask.u64()? as usize;
|
||||
self.mupdf.search(doc, page, &ask.str()?)
|
||||
let (id, page, needle) = (ask.u64()?, ask.u64()? as usize, ask.str()?);
|
||||
self.read(id, |mupdf, doc| mupdf.search(doc, page, &needle))
|
||||
}
|
||||
tag::OUTLINE => self.mupdf.outline(self.doc(ask.u64()?)?),
|
||||
tag::HELLO => Ok(Pack::new().str(ely_pdf_engine::proto::BUILD).bytes()),
|
||||
|
||||
@@ -82,6 +82,24 @@ impl crate::Worker {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
/// A text read; damage it meets waits for a draw.
|
||||
pub(crate) fn read(&mut self, id: u64, read: impl FnOnce(&Mupdf, &Open) -> io::Result<Vec<u8>>) -> io::Result<Vec<u8>> {
|
||||
let doc = self.doc(id)?;
|
||||
unsafe { ely_watch_begin(self.mupdf.ctx) };
|
||||
let answer = read(&self.mupdf, doc);
|
||||
if unsafe { ely_watch_end(self.mupdf.ctx) } != 0 {
|
||||
self.note_damage(id)?;
|
||||
self.docs.get_mut(&id).expect("just read").found = true;
|
||||
}
|
||||
answer
|
||||
}
|
||||
|
||||
/// Takes damage a read found; the caller tells it.
|
||||
fn found(&mut self, id: u64) -> io::Result<bool> {
|
||||
let doc = self.docs.get_mut(&id).ok_or_else(|| io::Error::other(format!("no document {id}")))?;
|
||||
Ok(std::mem::take(&mut doc.found))
|
||||
}
|
||||
|
||||
/// A tile, and whether drawing it met damage.
|
||||
pub(crate) fn drawn(&mut self, id: u64, page: usize, view: (f32, i32), tile: [i32; 4], dark: bool) -> io::Result<Vec<u8>> {
|
||||
unsafe { ely_watch_begin(self.mupdf.ctx) };
|
||||
@@ -90,7 +108,9 @@ impl crate::Worker {
|
||||
if warned {
|
||||
self.note_damage(id)?;
|
||||
}
|
||||
Ok(Pack::new().u64(u64::from(warned)).blob(&pixels?).bytes())
|
||||
let pixels = pixels?;
|
||||
let damaged = warned | self.found(id)?;
|
||||
Ok(Pack::new().u64(u64::from(damaged)).blob(&pixels).bytes())
|
||||
}
|
||||
|
||||
/// Every picture decoded before an overwrite; true if any failed.
|
||||
@@ -99,6 +119,7 @@ impl crate::Worker {
|
||||
if failed {
|
||||
self.note_damage(id)?;
|
||||
}
|
||||
let failed = failed | self.found(id)?;
|
||||
Ok(Pack::new().u64(u64::from(failed)).bytes())
|
||||
}
|
||||
|
||||
@@ -153,6 +174,12 @@ impl crate::Worker {
|
||||
pub(crate) fn output(&mut self, kind: u8, id: u64, ask: &mut Unpack) -> io::Result<Vec<u8>> {
|
||||
let has = self.allowed(id)?;
|
||||
let doc = self.record(id)?;
|
||||
// What a read found is no whole export.
|
||||
if matches!(kind, tag::EXPORT_IMAGE | tag::EXPORT_TEXT) && doc.found {
|
||||
refuse(may::COPY, has)?;
|
||||
let report = doc.repair.as_deref().expect("noted with the damage");
|
||||
return Err(io::Error::other(format!("the document did not read whole: {report}")));
|
||||
}
|
||||
match kind {
|
||||
tag::EXPORT_IMAGE => {
|
||||
refuse(may::COPY, has)?;
|
||||
|
||||
Reference in new issue
Block a user