summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'pdf/pdf_optcontent.c')
-rw-r--r--pdf/pdf_optcontent.c135
1 files changed, 81 insertions, 54 deletions
diff --git a/pdf/pdf_optcontent.c b/pdf/pdf_optcontent.c
index 484d72c9..288ee231 100644
--- a/pdf/pdf_optcontent.c
+++ b/pdf/pdf_optcontent.c
@@ -167,8 +167,8 @@ pdfi_oc_check_OCMD_array(pdf_context *ctx, pdf_array *array, ocmd_p_type type)
code = pdfi_array_get(ctx, array, i, &val);
if (code < 0) continue;
- if (val->type != PDF_DICT) {
- dmprintf1(ctx->memory, "WARNING: OCMD array contains item type %d, expected PDF_DICT or PDF_NULL\n", val->type);
+ if (pdfi_type_of(val) != PDF_DICT) {
+ dmprintf1(ctx->memory, "WARNING: OCMD array contains item type %d, expected PDF_DICT or PDF_NULL\n", pdfi_type_of(val));
pdfi_countdown(val);
val = NULL;
continue;
@@ -235,9 +235,9 @@ pdfi_oc_check_OCMD(pdf_context *ctx, pdf_dict *ocdict)
code = pdfi_dict_knownget(ctx, ocdict, "OCGs", &obj);
if (code <= 0)
goto cleanup;
- if (obj->type == PDF_ARRAY) {
+ if (pdfi_type_of(obj) == PDF_ARRAY) {
OCGs_array = (pdf_array *)obj;
- } else if (obj->type == PDF_DICT) {
+ } else if (pdfi_type_of(obj) == PDF_DICT) {
OCGs_dict = (pdf_dict *)obj;
} else {
goto cleanup;
@@ -367,7 +367,7 @@ static int pdfi_oc_levels_set(pdf_context *ctx, pdfi_oc_levels_t *levels, uint64
byte *new = NULL;
uint64_t newmax;
- if (index > levels->max_flags) {
+ if (index > levels->max_flags - 1) {
/* Expand the flags buffer */
newmax = levels->max_flags + NUM_CONTENT_LEVELS;
if (index > newmax)
@@ -390,7 +390,7 @@ static int pdfi_oc_levels_set(pdf_context *ctx, pdfi_oc_levels_t *levels, uint64
static int pdfi_oc_levels_clear(pdf_context *ctx, pdfi_oc_levels_t *levels, uint64_t index)
{
- if (index > levels->max_flags)
+ if (index > levels->max_flags - 1)
return -1;
if (levels->flags[index] != 0)
levels->num_off --;
@@ -446,16 +446,19 @@ int pdfi_op_MP(pdf_context *ctx)
goto exit;
o = ctx->stack_top[-1];
- if (o->type != PDF_NAME) {
- pdfi_pop(ctx, 1);
- return_error(gs_error_typecheck);
+ pdfi_countup(o);
+ pdfi_pop(ctx, 1);
+
+ if (pdfi_type_of(o) != PDF_NAME) {
+ code = gs_note_error(gs_error_typecheck);
+ goto exit;
}
code = pdfi_pdfmark_from_objarray(ctx, &o, 1, NULL, "MP");
ctx->BMClevel ++;
exit:
- pdfi_pop(ctx, 1);
+ pdfi_countdown(o);
return code;
}
@@ -463,17 +466,20 @@ int pdfi_op_DP(pdf_context *ctx, pdf_dict *stream_dict, pdf_dict *page_dict)
{
pdf_name *properties = NULL;
int code = 0;
- pdf_obj **objarray = NULL;
+ pdf_obj **objarray = NULL, *o = NULL;
if (pdfi_count_stack(ctx) < 2) {
pdfi_clearstack(ctx);
return gs_note_error(gs_error_stackunderflow);
}
- if (!ctx->device_state.writepdfmarks || !ctx->args.preservemarkedcontent)
+ if (!ctx->device_state.writepdfmarks || !ctx->args.preservemarkedcontent) {
+ pdfi_pop(ctx, 2); /* pop args */
goto exit;
+ }
- if ((ctx->stack_top[-2])->type != PDF_NAME) {
+ if (pdfi_type_of(ctx->stack_top[-2]) != PDF_NAME) {
+ pdfi_pop(ctx, 2); /* pop args */
code = gs_note_error(gs_error_typecheck);
goto exit;
}
@@ -485,30 +491,38 @@ int pdfi_op_DP(pdf_context *ctx, pdf_dict *stream_dict, pdf_dict *page_dict)
}
objarray[0] = ctx->stack_top[-2];
+ pdfi_countup(objarray[0]);
+ o = ctx->stack_top[-2];
+ pdfi_countup(o);
+ pdfi_pop(ctx, 2); /* pop args */
- if ((ctx->stack_top[-1])->type == PDF_NAME) {
- code = pdfi_find_resource(ctx, (unsigned char *)"Properties", (pdf_name *)ctx->stack_top[-1], stream_dict, page_dict, (pdf_obj **)&properties);
- if(code < 0)
- goto exit;
- if (properties->type != PDF_DICT) {
- code = gs_note_error(gs_error_typecheck);
- goto exit;
- }
- objarray[1] = (pdf_obj *)properties;
- } else {
- if ((ctx->stack_top[-1])->type != PDF_DICT) {
+ switch (pdfi_type_of(o)) {
+ case PDF_NAME:
+ code = pdfi_find_resource(ctx, (unsigned char *)"Properties", (pdf_name *)o, stream_dict, page_dict, (pdf_obj **)&properties);
+ if(code < 0)
+ goto exit;
+ if (pdfi_type_of(properties) != PDF_DICT) {
+ code = gs_note_error(gs_error_typecheck);
+ goto exit;
+ }
+ objarray[1] = (pdf_obj *)properties;
+ break;
+ case PDF_DICT:
+ objarray[1] = o;
+ break;
+ default:
code = gs_note_error(gs_error_VMerror);
goto exit;
- }
- objarray[1] = ctx->stack_top[-1];
}
code = pdfi_pdfmark_from_objarray(ctx, objarray, 2, NULL, "DP");
exit:
- if (objarray != NULL)
+ if (objarray != NULL) {
+ pdfi_countdown(objarray[0]);
gs_free_object(ctx->memory, objarray, "free pdfi_op_DP");
- pdfi_pop(ctx, 2); /* pop args */
+ }
+ pdfi_countdown(o);
pdfi_countdown(properties);
return code;
}
@@ -525,13 +539,18 @@ int pdfi_op_BMC(pdf_context *ctx)
if (pdfi_count_stack(ctx) < 1)
return_error(gs_error_stackunderflow);
- if (!ctx->device_state.writepdfmarks || !ctx->args.preservemarkedcontent)
+ if (!ctx->device_state.writepdfmarks || !ctx->args.preservemarkedcontent) {
+ pdfi_pop(ctx, 1);
goto exit;
+ }
o = ctx->stack_top[-1];
- if (o->type != PDF_NAME) {
- pdfi_pop(ctx, 1);
- return_error(gs_error_typecheck);
+ pdfi_countup(o);
+ pdfi_pop(ctx, 1);
+
+ if (pdfi_type_of(o) != PDF_NAME) {
+ code = gs_note_error(gs_error_typecheck);
+ goto exit;
}
ctx->BDCWasOC = false;
@@ -539,7 +558,7 @@ int pdfi_op_BMC(pdf_context *ctx)
ctx->BMClevel ++;
exit:
- pdfi_pop(ctx, 1);
+ pdfi_countdown(o);
return code;
}
@@ -551,7 +570,7 @@ int pdfi_op_BDC(pdf_context *ctx, pdf_dict *stream_dict, pdf_dict *page_dict)
pdf_dict *oc_dict = NULL;
int code = 0;
bool ocg_is_visible;
- pdf_obj **objarray = NULL;
+ pdf_obj **objarray = NULL, *o = NULL;;
/* This will also prevent us writing out an EMC if the BDC is in any way invalid */
ctx->BDCWasOC = true;
@@ -564,7 +583,12 @@ int pdfi_op_BDC(pdf_context *ctx, pdf_dict *stream_dict, pdf_dict *page_dict)
ctx->BMClevel ++;
tag = (pdf_name *)ctx->stack_top[-2];
- if (tag->type != PDF_NAME)
+ pdfi_countup(tag);
+ o = ctx->stack_top[-1];
+ pdfi_countup(o);
+ pdfi_pop(ctx, 2);
+
+ if (pdfi_type_of(tag) != PDF_NAME)
goto exit;
if (!pdfi_name_is(tag, "OC")) {
@@ -578,23 +602,25 @@ int pdfi_op_BDC(pdf_context *ctx, pdf_dict *stream_dict, pdf_dict *page_dict)
goto exit;
}
- objarray[0] = ctx->stack_top[-2];
-
- if ((ctx->stack_top[-1])->type == PDF_NAME) {
- code = pdfi_find_resource(ctx, (unsigned char *)"Properties", (pdf_name *)ctx->stack_top[-1], stream_dict, page_dict, (pdf_obj **)&oc_dict);
- if(code < 0)
- goto exit;
- if (oc_dict->type != PDF_DICT) {
- code = gs_note_error(gs_error_typecheck);
- goto exit;
- }
- objarray[1] = (pdf_obj *)oc_dict;
- } else {
- if ((ctx->stack_top[-1])->type != PDF_DICT) {
+ objarray[0] = (pdf_obj *)tag;
+
+ switch (pdfi_type_of(o)) {
+ case PDF_NAME:
+ code = pdfi_find_resource(ctx, (unsigned char *)"Properties", (pdf_name *)o, stream_dict, page_dict, (pdf_obj **)&oc_dict);
+ if(code < 0)
+ goto exit;
+ if (pdfi_type_of(oc_dict) != PDF_DICT) {
+ code = gs_note_error(gs_error_typecheck);
+ goto exit;
+ }
+ objarray[1] = (pdf_obj *)oc_dict;
+ break;
+ case PDF_DICT:
+ objarray[1] = o;
+ break;
+ default:
code = gs_note_error(gs_error_VMerror);
goto exit;
- }
- objarray[1] = ctx->stack_top[-1];
}
code = pdfi_pdfmark_from_objarray(ctx, objarray, 2, NULL, "BDC");
@@ -605,8 +631,8 @@ int pdfi_op_BDC(pdf_context *ctx, pdf_dict *stream_dict, pdf_dict *page_dict)
/* TODO: spec says it could also be an inline dict that we should be able to handle,
* but I am just matching what gs does for now, and it doesn't handle that case.
*/
- properties = (pdf_name *)ctx->stack_top[-1];
- if (properties->type != PDF_NAME)
+ properties = (pdf_name *)o;
+ if (pdfi_type_of(properties) != PDF_NAME)
goto exit;
/* If it's a name, look it up in Properties */
@@ -614,7 +640,7 @@ int pdfi_op_BDC(pdf_context *ctx, pdf_dict *stream_dict, pdf_dict *page_dict)
(pdf_dict *)stream_dict, page_dict, (pdf_obj **)&oc_dict);
if (code != 0)
goto exit;
- if (oc_dict->type != PDF_DICT)
+ if (pdfi_type_of(oc_dict) != PDF_DICT)
goto exit;
/* Now we have an OC dict, see if it's visible */
@@ -625,7 +651,8 @@ int pdfi_op_BDC(pdf_context *ctx, pdf_dict *stream_dict, pdf_dict *page_dict)
exit:
if (objarray != NULL)
gs_free_object(ctx->memory, objarray, "free pdfi_op_BDC");
- pdfi_pop(ctx, 2); /* pop args */
+ pdfi_countdown(o);
+ pdfi_countdown(tag);
pdfi_countdown(oc_dict);
return code;
}