diff options
author | Robin Watts <robin.watts@artifex.com> | 2016-04-13 17:02:43 +0100 |
---|---|---|
committer | Robin Watts <robin.watts@artifex.com> | 2016-04-18 10:51:22 +0100 |
commit | 335798189cbd40cd518ce49d1fa4c7eaa2811977 (patch) | |
tree | 6436a89506c79174882cc08f0766f328315c1c94 | |
parent | bf73ce40b26317cc067239c0e183ea4257a25c2f (diff) | |
download | mupdf-335798189cbd40cd518ce49d1fa4c7eaa2811977.tar.xz |
Fix broken documents after sanitize
The DP and BDC operators, are used in the form:
<NAME> <PROPERTIES> <OPERATOR>
where <PROPERTIES> can either be a name (that can be looked
up to get a dictionary) or an inline dictionary.
What the spec doesn't say is that the two are not
interchangeable. If you resolve the name to an inline
dict, then insert it, Acrobat will give an error for
some (but not all) cases.
The interpreter currently resolves any references, and
passes the resolved version into the operator handling
function. This precludes us outputting the original
form.
We therefore update it to pass both the raw and the cooked
versions in. This has no effect on MuPDFs own handling of
anything, it just enables the buffer device to output
a correct stream.
-rw-r--r-- | include/mupdf/pdf/interpret.h | 4 | ||||
-rw-r--r-- | source/pdf/pdf-interpret.c | 19 | ||||
-rw-r--r-- | source/pdf/pdf-op-buffer.c | 8 | ||||
-rw-r--r-- | source/pdf/pdf-op-filter.c | 8 | ||||
-rw-r--r-- | source/pdf/pdf-op-run.c | 4 |
5 files changed, 23 insertions, 20 deletions
diff --git a/include/mupdf/pdf/interpret.h b/include/mupdf/pdf/interpret.h index c3791f23..da89e573 100644 --- a/include/mupdf/pdf/interpret.h +++ b/include/mupdf/pdf/interpret.h @@ -112,9 +112,9 @@ struct pdf_processor_s /* marked content */ void (*op_MP)(fz_context *ctx, pdf_processor *proc, const char *tag); - void (*op_DP)(fz_context *ctx, pdf_processor *proc, const char *tag, pdf_obj *properties); + void (*op_DP)(fz_context *ctx, pdf_processor *proc, const char *tag, pdf_obj *raw, pdf_obj *cooked); void (*op_BMC)(fz_context *ctx, pdf_processor *proc, const char *tag); - void (*op_BDC)(fz_context *ctx, pdf_processor *proc, const char *tag, pdf_obj *properties); + void (*op_BDC)(fz_context *ctx, pdf_processor *proc, const char *tag, pdf_obj *raw, pdf_obj *cooked); void (*op_EMC)(fz_context *ctx, pdf_processor *proc); /* compatibility */ diff --git a/source/pdf/pdf-interpret.c b/source/pdf/pdf-interpret.c index 64a60e06..3a386614 100644 --- a/source/pdf/pdf-interpret.c +++ b/source/pdf/pdf-interpret.c @@ -675,10 +675,13 @@ resolve_properties(fz_context *ctx, pdf_csi *csi, pdf_obj *obj) } static void -pdf_process_BDC(fz_context *ctx, pdf_processor *proc, pdf_csi *csi, const char *name, pdf_obj *properties) +pdf_process_BDC(fz_context *ctx, pdf_processor *proc, pdf_csi *csi) { + pdf_obj *raw = csi->obj; + pdf_obj *cooked = resolve_properties(ctx, csi, raw); + if (proc->op_BDC) - proc->op_BDC(ctx, proc, name, properties); + proc->op_BDC(ctx, proc, csi->name, raw, cooked); /* Already hidden, no need to look further */ if (proc->hidden > 0) @@ -688,18 +691,18 @@ pdf_process_BDC(fz_context *ctx, pdf_processor *proc, pdf_csi *csi, const char * } /* We only look at OC groups here */ - if (strcmp(name, "OC")) + if (strcmp(csi->name, "OC")) return; /* No Properties array, or name not found, means visible. */ - if (!properties) + if (!cooked) return; /* Wrong type of property */ - if (!pdf_name_eq(ctx, pdf_dict_get(ctx, properties, PDF_NAME_Type), PDF_NAME_OCG)) + if (!pdf_name_eq(ctx, pdf_dict_get(ctx, cooked, PDF_NAME_Type), PDF_NAME_OCG)) return; - if (pdf_is_hidden_ocg(ctx, csi->doc->ocg, csi->rdb, proc->event, properties)) + if (pdf_is_hidden_ocg(ctx, csi->doc->ocg, csi->rdb, proc->event, cooked)) ++proc->hidden; } @@ -966,9 +969,9 @@ pdf_process_keyword(fz_context *ctx, pdf_processor *proc, pdf_csi *csi, fz_strea /* marked content */ case B('M','P'): if (proc->op_MP) proc->op_MP(ctx, proc, csi->name); break; - case B('D','P'): if (proc->op_DP) proc->op_DP(ctx, proc, csi->name, resolve_properties(ctx, csi, csi->obj)); break; + case B('D','P'): if (proc->op_DP) proc->op_DP(ctx, proc, csi->name, csi->obj, resolve_properties(ctx, csi, csi->obj)); break; case C('B','M','C'): pdf_process_BMC(ctx, proc, csi, csi->name); break; - case C('B','D','C'): pdf_process_BDC(ctx, proc, csi, csi->name, resolve_properties(ctx, csi, csi->obj)); break; + case C('B','D','C'): pdf_process_BDC(ctx, proc, csi); break; case C('E','M','C'): pdf_process_EMC(ctx, proc, csi); break; /* compatibility */ diff --git a/source/pdf/pdf-op-buffer.c b/source/pdf/pdf-op-buffer.c index 6e79a7ee..241b096f 100644 --- a/source/pdf/pdf-op-buffer.c +++ b/source/pdf/pdf-op-buffer.c @@ -712,11 +712,11 @@ pdf_out_MP(fz_context *ctx, pdf_processor *proc, const char *tag) } static void -pdf_out_DP(fz_context *ctx, pdf_processor *proc, const char *tag, pdf_obj *properties) +pdf_out_DP(fz_context *ctx, pdf_processor *proc, const char *tag, pdf_obj *raw, pdf_obj *cooked) { fz_output *out = ((pdf_output_processor*)proc)->out; fz_printf(ctx, out, "/%s ", tag); - pdf_print_obj(ctx, out, properties, 1); + pdf_print_obj(ctx, out, raw, 1); fz_printf(ctx, out, " DP\n"); } @@ -728,11 +728,11 @@ pdf_out_BMC(fz_context *ctx, pdf_processor *proc, const char *tag) } static void -pdf_out_BDC(fz_context *ctx, pdf_processor *proc, const char *tag, pdf_obj *properties) +pdf_out_BDC(fz_context *ctx, pdf_processor *proc, const char *tag, pdf_obj *raw, pdf_obj *cooked) { fz_output *out = ((pdf_output_processor*)proc)->out; fz_printf(ctx, out, "/%s ", tag); - pdf_print_obj(ctx, out, properties, 1); + pdf_print_obj(ctx, out, raw, 1); fz_printf(ctx, out, " BDC\n"); } diff --git a/source/pdf/pdf-op-filter.c b/source/pdf/pdf-op-filter.c index 24644a37..a8496e35 100644 --- a/source/pdf/pdf-op-filter.c +++ b/source/pdf/pdf-op-filter.c @@ -1047,12 +1047,12 @@ pdf_filter_MP(fz_context *ctx, pdf_processor *proc, const char *tag) } static void -pdf_filter_DP(fz_context *ctx, pdf_processor *proc, const char *tag, pdf_obj *properties) +pdf_filter_DP(fz_context *ctx, pdf_processor *proc, const char *tag, pdf_obj *raw, pdf_obj *cooked) { pdf_filter_processor *p = (pdf_filter_processor*)proc; filter_flush(ctx, p, 0); if (p->chain->op_DP) - p->chain->op_DP(ctx, p->chain, tag, properties); + p->chain->op_DP(ctx, p->chain, tag, raw, cooked); } static void @@ -1065,12 +1065,12 @@ pdf_filter_BMC(fz_context *ctx, pdf_processor *proc, const char *tag) } static void -pdf_filter_BDC(fz_context *ctx, pdf_processor *proc, const char *tag, pdf_obj *properties) +pdf_filter_BDC(fz_context *ctx, pdf_processor *proc, const char *tag, pdf_obj *raw, pdf_obj *cooked) { pdf_filter_processor *p = (pdf_filter_processor*)proc; filter_flush(ctx, p, 0); if (p->chain->op_BDC) - p->chain->op_BDC(ctx, p->chain, tag, properties); + p->chain->op_BDC(ctx, p->chain, tag, raw, cooked); } static void diff --git a/source/pdf/pdf-op-run.c b/source/pdf/pdf-op-run.c index cb83aa8b..593afe24 100644 --- a/source/pdf/pdf-op-run.c +++ b/source/pdf/pdf-op-run.c @@ -1931,7 +1931,7 @@ static void pdf_run_MP(fz_context *ctx, pdf_processor *proc, const char *tag) { } -static void pdf_run_DP(fz_context *ctx, pdf_processor *proc, const char *tag, pdf_obj *properties) +static void pdf_run_DP(fz_context *ctx, pdf_processor *proc, const char *tag, pdf_obj *raw, pdf_obj *cooked) { } @@ -1939,7 +1939,7 @@ static void pdf_run_BMC(fz_context *ctx, pdf_processor *proc, const char *tag) { } -static void pdf_run_BDC(fz_context *ctx, pdf_processor *proc, const char *tag, pdf_obj *properties) +static void pdf_run_BDC(fz_context *ctx, pdf_processor *proc, const char *tag, pdf_obj *raw, pdf_obj *cooked) { } |