summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobin Watts <robin.watts@artifex.com>2016-04-12 19:42:19 +0100
committerRobin Watts <robin.watts@artifex.com>2016-04-26 10:54:48 +0100
commitf4a365df3f7709192ec6052832e857d2832ae47f (patch)
tree407bbbb259c173ed9d89c0064610b442bfc84e12
parent4584bb1fbd3208e516a6f17b36c3b861903529f7 (diff)
downloadmupdf-f4a365df3f7709192ec6052832e857d2832ae47f.tar.xz
Update mutool clean sanitize to clean annotations too.
-rw-r--r--include/mupdf/pdf/page.h27
-rw-r--r--source/pdf/pdf-clean.c21
-rw-r--r--source/pdf/pdf-interpret.c2
-rw-r--r--source/pdf/pdf-write.c7
4 files changed, 56 insertions, 1 deletions
diff --git a/include/mupdf/pdf/page.h b/include/mupdf/pdf/page.h
index 1b8fa755..f1caf936 100644
--- a/include/mupdf/pdf/page.h
+++ b/include/mupdf/pdf/page.h
@@ -122,6 +122,33 @@ void pdf_clean_page_contents(fz_context *ctx, pdf_document *doc, pdf_page *page,
pdf_page_contents_process_fn *proc, void *proc_arg, int ascii);
/*
+ pdf_clean_annot_contents: Clean a loaded annotations rendering operations,
+ with an optional post processing step.
+
+ Each appearance stream in the annotation is processed.
+
+ Firstly, this filters the PDF operators used to avoid (some cases
+ of) repetition, and leaves the page in a balanced state with an
+ unchanged top level matrix etc. At the same time, the resources
+ used by the page contents are collected.
+
+ Next, the resources themselves are cleaned (as appropriate) in the
+ same way.
+
+ Next, an optional post processing stage is called.
+
+ Finally, the updated stream of operations is reinserted into the
+ appearance stream.
+
+ annot: An annotation loaded by pdf_load_annot.
+
+ cookie: A pointer to an optional fz_cookie structure that can be used
+ to track progress, collect errors etc.
+*/
+void pdf_clean_annot_contents(fz_context *ctx, pdf_document *doc, pdf_annot *annot, fz_cookie *cookie,
+ pdf_page_contents_process_fn *proc, void *proc_arg, int ascii);
+
+/*
Presentation interface.
*/
fz_transition *pdf_page_presentation(fz_context *ctx, pdf_page *page, float *duration);
diff --git a/source/pdf/pdf-clean.c b/source/pdf/pdf-clean.c
index 2c8ade73..ecadc7f2 100644
--- a/source/pdf/pdf-clean.c
+++ b/source/pdf/pdf-clean.c
@@ -287,3 +287,24 @@ void pdf_clean_page_contents(fz_context *ctx, pdf_document *doc, pdf_page *page,
fz_rethrow_message(ctx, "Failed while cleaning page");
}
}
+
+void pdf_clean_annot_contents(fz_context *ctx, pdf_document *doc, pdf_annot *annot, fz_cookie *cookie, pdf_page_contents_process_fn *proc_fn, void *proc_arg, int ascii)
+{
+ pdf_obj *ap;
+ int i, n;
+
+ ap = pdf_dict_get(ctx, annot->obj, PDF_NAME_AP);
+ if (ap == NULL)
+ return;
+
+ n = pdf_dict_len(ctx, ap);
+ for (i = 0; i < n; i++)
+ {
+ pdf_obj *v = pdf_dict_get_val(ctx, ap, i);
+
+ if (v == NULL)
+ continue;
+
+ pdf_clean_stream_object(ctx, doc, v, NULL, cookie, 1, 1);
+ }
+}
diff --git a/source/pdf/pdf-interpret.c b/source/pdf/pdf-interpret.c
index 3a386614..cff3f197 100644
--- a/source/pdf/pdf-interpret.c
+++ b/source/pdf/pdf-interpret.c
@@ -1258,7 +1258,7 @@ pdf_process_annot(fz_context *ctx, pdf_processor *proc, pdf_document *doc, pdf_p
proc->op_cm(ctx, proc,
annot->matrix.a, annot->matrix.b, annot->matrix.c,
annot->matrix.d, annot->matrix.e, annot->matrix.f);
- proc->op_Do_form(ctx, proc, "Annot", annot->ap, page->resources);
+ proc->op_Do_form(ctx, proc, NULL, annot->ap, page->resources);
proc->op_Q(ctx, proc);
}
}
diff --git a/source/pdf/pdf-write.c b/source/pdf/pdf-write.c
index 388a5820..8e686218 100644
--- a/source/pdf/pdf-write.c
+++ b/source/pdf/pdf-write.c
@@ -2656,8 +2656,15 @@ static void sanitize(fz_context *ctx, pdf_document *doc, int ascii)
for (i = 0; i < n; i++)
{
+ pdf_annot *annot;
pdf_page *page = pdf_load_page(ctx, doc, i);
pdf_clean_page_contents(ctx, doc, page, NULL, NULL, NULL, ascii);
+
+ for (annot = pdf_first_annot(ctx, page); annot != NULL; annot = pdf_next_annot(ctx, annot))
+ {
+ pdf_clean_annot_contents(ctx, doc, annot, NULL, NULL, NULL, ascii);
+ }
+
fz_drop_page(ctx, &page->super);
}
}