summaryrefslogtreecommitdiff
path: root/source/pdf
diff options
context:
space:
mode:
Diffstat (limited to 'source/pdf')
-rw-r--r--source/pdf/pdf-clean.c20
-rw-r--r--source/pdf/pdf-op-buffer.c49
-rw-r--r--source/pdf/pdf-write.c10
3 files changed, 48 insertions, 31 deletions
diff --git a/source/pdf/pdf-clean.c b/source/pdf/pdf-clean.c
index 90de0444..3d34c1a1 100644
--- a/source/pdf/pdf-clean.c
+++ b/source/pdf/pdf-clean.c
@@ -1,7 +1,7 @@
#include "mupdf/pdf.h"
static void
-pdf_clean_stream_object(fz_context *ctx, pdf_document *doc, pdf_obj *obj, pdf_obj *orig_res, fz_cookie *cookie, int own_res)
+pdf_clean_stream_object(fz_context *ctx, pdf_document *doc, pdf_obj *obj, pdf_obj *orig_res, fz_cookie *cookie, int own_res, int ascii)
{
pdf_processor *proc_buffer = NULL;
pdf_processor *proc_filter = NULL;
@@ -30,7 +30,7 @@ pdf_clean_stream_object(fz_context *ctx, pdf_document *doc, pdf_obj *obj, pdf_ob
res = pdf_new_dict(ctx, doc, 1);
- proc_buffer = pdf_new_buffer_processor(ctx, buffer);
+ proc_buffer = pdf_new_buffer_processor(ctx, buffer, ascii);
proc_filter = pdf_new_filter_processor(ctx, proc_buffer, doc, orig_res, res);
pdf_process_contents(ctx, proc_filter, doc, orig_res, obj, cookie);
@@ -58,7 +58,7 @@ pdf_clean_stream_object(fz_context *ctx, pdf_document *doc, pdf_obj *obj, pdf_ob
}
static void
-pdf_clean_type3(fz_context *ctx, pdf_document *doc, pdf_obj *obj, pdf_obj *orig_res, fz_cookie *cookie)
+pdf_clean_type3(fz_context *ctx, pdf_document *doc, pdf_obj *obj, pdf_obj *orig_res, fz_cookie *cookie, int ascii)
{
pdf_processor *proc_buffer = NULL;
pdf_processor *proc_filter = NULL;
@@ -90,7 +90,7 @@ pdf_clean_type3(fz_context *ctx, pdf_document *doc, pdf_obj *obj, pdf_obj *orig_
fz_buffer *buffer = fz_new_buffer(ctx, 1024);
fz_try(ctx)
{
- proc_buffer = pdf_new_buffer_processor(ctx, buffer);
+ proc_buffer = pdf_new_buffer_processor(ctx, buffer, ascii);
proc_filter = pdf_new_filter_processor(ctx, proc_buffer, doc, orig_res, res);
pdf_process_contents(ctx, proc_filter, doc, orig_res, val, cookie);
@@ -126,7 +126,7 @@ pdf_clean_type3(fz_context *ctx, pdf_document *doc, pdf_obj *obj, pdf_obj *orig_
}
}
-void pdf_clean_page_contents(fz_context *ctx, pdf_document *doc, pdf_page *page, fz_cookie *cookie, pdf_page_contents_process_fn *proc_fn, void *proc_arg)
+void pdf_clean_page_contents(fz_context *ctx, pdf_document *doc, pdf_page *page, fz_cookie *cookie, pdf_page_contents_process_fn *proc_fn, void *proc_arg, int ascii)
{
pdf_processor *proc_buffer = NULL;
pdf_processor *proc_filter = NULL;
@@ -151,7 +151,7 @@ void pdf_clean_page_contents(fz_context *ctx, pdf_document *doc, pdf_page *page,
{
res = pdf_new_dict(ctx, doc, 1);
- proc_buffer = pdf_new_buffer_processor(ctx, buffer);
+ proc_buffer = pdf_new_buffer_processor(ctx, buffer, ascii);
proc_filter = pdf_new_filter_processor(ctx, proc_buffer, doc, page->resources, res);
pdf_process_contents(ctx, proc_filter, doc, page->resources, page->contents, cookie);
@@ -193,7 +193,7 @@ void pdf_clean_page_contents(fz_context *ctx, pdf_document *doc, pdf_page *page,
continue;
/* Transparency group XObject */
- pdf_clean_stream_object(ctx, doc, o, page->resources, cookie, 1);
+ pdf_clean_stream_object(ctx, doc, o, page->resources, cookie, 1, ascii);
}
}
@@ -213,7 +213,7 @@ void pdf_clean_page_contents(fz_context *ctx, pdf_document *doc, pdf_page *page,
if (!pat)
continue;
if (pdf_to_int(ctx, pdf_dict_get(ctx, pat, PDF_NAME_PatternType)) == 1)
- pdf_clean_stream_object(ctx, doc, pat, page->resources, cookie, 0);
+ pdf_clean_stream_object(ctx, doc, pat, page->resources, cookie, 0, ascii);
}
}
@@ -233,7 +233,7 @@ void pdf_clean_page_contents(fz_context *ctx, pdf_document *doc, pdf_page *page,
if (!pdf_name_eq(ctx, PDF_NAME_Form, pdf_dict_get(ctx, xobj, PDF_NAME_Subtype)))
continue;
- pdf_clean_stream_object(ctx, doc, xobj, page->resources, cookie, 1);
+ pdf_clean_stream_object(ctx, doc, xobj, page->resources, cookie, 1, ascii);
}
}
@@ -250,7 +250,7 @@ void pdf_clean_page_contents(fz_context *ctx, pdf_document *doc, pdf_page *page,
if (pdf_name_eq(ctx, PDF_NAME_Type3, pdf_dict_get(ctx, o, PDF_NAME_Subtype)))
{
- pdf_clean_type3(ctx, doc, o, page->resources, cookie);
+ pdf_clean_type3(ctx, doc, o, page->resources, cookie, ascii);
}
}
}
diff --git a/source/pdf/pdf-op-buffer.c b/source/pdf/pdf-op-buffer.c
index cdea4c78..d4f56286 100644
--- a/source/pdf/pdf-op-buffer.c
+++ b/source/pdf/pdf-op-buffer.c
@@ -6,6 +6,7 @@ struct pdf_output_processor_s
{
pdf_processor super;
fz_output *out;
+ int ahxencode;
int extgstate;
};
@@ -543,6 +544,7 @@ static void
pdf_out_BI(fz_context *ctx, pdf_processor *proc, fz_image *img)
{
fz_output *out = ((pdf_output_processor*)proc)->out;
+ int ahx = ((pdf_output_processor*)proc)->ahxencode;
fz_compressed_buffer *cbuf;
fz_buffer *buf;
int i;
@@ -588,15 +590,14 @@ pdf_out_BI(fz_context *ctx, pdf_processor *proc, fz_image *img)
break;
case FZ_IMAGE_JPEG:
- fz_printf(ctx, out, "/F/DCT\n");
+ fz_printf(ctx, out, ahx ? "/F[/AHx/DCT]\n" : "/F/DCT\n");
if (cbuf->params.u.jpeg.color_transform != -1)
fz_printf(ctx, out, "/DP<</ColorTransform %d>>\n",
cbuf->params.u.jpeg.color_transform);
break;
case FZ_IMAGE_FAX:
- fz_printf(ctx, out, "/F/CCF\n");
- fz_printf(ctx, out, "/DP<<\n");
+ fz_printf(ctx, out, ahx ? "/F[/AHx/CCF]\n/DP[null<<\n" : "/F/CCF\n/DP<<\n");
fz_printf(ctx, out, "/K %d\n", cbuf->params.u.fax.k);
if (cbuf->params.u.fax.columns != 1728)
fz_printf(ctx, out, "/Columns %d\n", cbuf->params.u.fax.columns);
@@ -613,21 +614,23 @@ pdf_out_BI(fz_context *ctx, pdf_processor *proc, fz_image *img)
if (cbuf->params.u.fax.damaged_rows_before_error > 0)
fz_printf(ctx, out, "/DamagedRowsBeforeError %d\n",
cbuf->params.u.fax.damaged_rows_before_error);
- fz_printf(ctx, out, ">>\n");
+ fz_printf(ctx, out, ahx ? ">>]\n" : ">>\n");
break;
case FZ_IMAGE_RAW:
+ if (ahx)
+ fz_printf(ctx, out, "/F/AHx\n");
break;
case FZ_IMAGE_RLD:
- fz_printf(ctx, out, "/F/RL\n");
+ fz_printf(ctx, out, ahx ? "/F[/AHx/RL]\n" : "/F/RL\n");
break;
case FZ_IMAGE_FLATE:
- fz_printf(ctx, out, "/F/Fl\n");
+ fz_printf(ctx, out, ahx ? "/F[/AHx/Fl]\n" : "/F/Fl\n");
if (cbuf->params.u.flate.predictor > 1)
{
- fz_printf(ctx, out, "/DP<<\n");
+ fz_printf(ctx, out, ahx ? "/DP[null<<\n" : "/DP<<\n");
fz_printf(ctx, out, "/Predictor %d\n", cbuf->params.u.flate.predictor);
if (cbuf->params.u.flate.columns != 1)
fz_printf(ctx, out, "/Columns %d\n", cbuf->params.u.flate.columns);
@@ -635,15 +638,15 @@ pdf_out_BI(fz_context *ctx, pdf_processor *proc, fz_image *img)
fz_printf(ctx, out, "/Colors %d\n", cbuf->params.u.flate.colors);
if (cbuf->params.u.flate.bpc != 8)
fz_printf(ctx, out, "/BitsPerComponent %d\n", cbuf->params.u.flate.bpc);
- fz_printf(ctx, out, ">>\n");
+ fz_printf(ctx, out, ahx ? ">>]\n" : ">>\n");
}
break;
case FZ_IMAGE_LZW:
- fz_printf(ctx, out, "/F/LZW\n");
+ fz_printf(ctx, out, ahx ? "/F[/AHx/LZW]\n" : "/F/LZW\n");
if (cbuf->params.u.lzw.predictor > 1)
{
- fz_printf(ctx, out, "/DP<<\n");
+ fz_printf(ctx, out, ahx ? "/DP[<<null\n" : "/DP<<\n");
fz_printf(ctx, out, "/Predictor %d\n", cbuf->params.u.lzw.predictor);
if (cbuf->params.u.lzw.columns != 1)
fz_printf(ctx, out, "/Columns %d\n", cbuf->params.u.lzw.columns);
@@ -653,13 +656,28 @@ pdf_out_BI(fz_context *ctx, pdf_processor *proc, fz_image *img)
fz_printf(ctx, out, "/BitsPerComponent %d\n", cbuf->params.u.lzw.bpc);
if (cbuf->params.u.lzw.early_change != 1)
fz_printf(ctx, out, "/EarlyChange %d\n", cbuf->params.u.lzw.early_change);
- fz_printf(ctx, out, ">>\n");
+ fz_printf(ctx, out, ahx ? ">>]\n" : ">>\n");
}
break;
}
fz_printf(ctx, out, "ID\n");
- fz_write(ctx, out, buf->data, buf->len);
+ if (ahx)
+ {
+ for (i = 0; i < buf->len; ++i)
+ {
+ int c = buf->data[i];
+ fz_putc(ctx, out, "0123456789abcdef"[(c >> 4) & 0xf]);
+ fz_putc(ctx, out, "0123456789abcdef"[c & 0xf]);
+ if ((i & 31) == 31)
+ fz_putc(ctx, out, '\n');
+ }
+ fz_putc(ctx, out, '>');
+ }
+ else
+ {
+ fz_write(ctx, out, buf->data, buf->len);
+ }
fz_printf(ctx, out, "\nEI\n");
}
@@ -749,7 +767,7 @@ pdf_drop_imp_output_processor(fz_context *ctx, pdf_processor *proc)
}
static pdf_processor *
-pdf_new_output_processor(fz_context *ctx, fz_output *out)
+pdf_new_output_processor(fz_context *ctx, fz_output *out, int ahxencode)
{
pdf_output_processor *proc = pdf_new_processor(ctx, sizeof *proc);
{
@@ -867,18 +885,19 @@ pdf_new_output_processor(fz_context *ctx, fz_output *out)
}
proc->out = out;
+ proc->ahxencode = ahxencode;
return (pdf_processor*)proc;
}
pdf_processor *
-pdf_new_buffer_processor(fz_context *ctx, fz_buffer *buffer)
+pdf_new_buffer_processor(fz_context *ctx, fz_buffer *buffer, int ahxencode)
{
pdf_processor *proc;
fz_output *out = fz_new_output_with_buffer(ctx, buffer);
fz_try(ctx)
{
- proc = pdf_new_output_processor(ctx, out);
+ proc = pdf_new_output_processor(ctx, out, ahxencode);
}
fz_catch(ctx)
{
diff --git a/source/pdf/pdf-write.c b/source/pdf/pdf-write.c
index 20c9bfca..6ad308f1 100644
--- a/source/pdf/pdf-write.c
+++ b/source/pdf/pdf-write.c
@@ -2548,7 +2548,7 @@ static void complete_signatures(fz_context *ctx, pdf_document *doc, pdf_write_op
}
}
-static void sanitise(fz_context *ctx, pdf_document *doc)
+static void sanitize(fz_context *ctx, pdf_document *doc, int ascii)
{
int n = pdf_count_pages(ctx, doc);
int i;
@@ -2556,9 +2556,7 @@ static void sanitise(fz_context *ctx, pdf_document *doc)
for (i = 0; i < n; i++)
{
pdf_page *page = pdf_load_page(ctx, doc, i);
-
- pdf_clean_page_contents(ctx, doc, page, NULL, NULL, NULL);
-
+ pdf_clean_page_contents(ctx, doc, page, NULL, NULL, NULL, ascii);
fz_drop_page(ctx, &page->super);
}
}
@@ -2580,9 +2578,9 @@ void pdf_write_document(fz_context *ctx, pdf_document *doc, char *filename, fz_w
doc->freeze_updates = 1;
- /* Sanitise the operator streams */
+ /* Sanitize the operator streams */
if (fz_opts->do_clean)
- sanitise(ctx, doc);
+ sanitize(ctx, doc, fz_opts->do_ascii);
pdf_finish_edit(ctx, doc);
presize_unsaved_signature_byteranges(ctx, doc);