From f486147fad0b0f9c440a2a4405d48861eedac4b1 Mon Sep 17 00:00:00 2001 From: Ken Sharp Date: Wed, 21 Dec 2022 09:03:21 +0000 Subject: GhostPDF - PDF 2.0, Halftones can be arrays /tests_private/pdf/PDF_2.0_FTS/fts_24_2432.pdf Missed this somewhere along the way; in PDF 2.0 a /HT (halftone) can have an array value which is an array of spot names, the consumer is supposed to use the first one it recognises..... We weren't expecting an array and returned a typecheck error. This was masked by the fact that some of the halftones in the test file genuinely don't contain usable halftone names so an error is to be expected. Add code to deal with an array by trying to find each spot name in turn in the list of spot names we know about. Causes diffs in /tests_private/pdf/PDF_2.0_FTS/fts_24_2432.pdf because we now use a different spot shape in two cases. --- pdf/pdf_gstate.c | 41 ++++++++++++++++++++++++++++++++++++++--- 1 file changed, 38 insertions(+), 3 deletions(-) (limited to 'pdf') diff --git a/pdf/pdf_gstate.c b/pdf/pdf_gstate.c index 632329ce5..8a6c114ec 100644 --- a/pdf/pdf_gstate.c +++ b/pdf/pdf_gstate.c @@ -1119,7 +1119,7 @@ error: static int build_type1_halftone(pdf_context *ctx, pdf_dict *halftone_dict, pdf_dict *page_dict, gx_ht_order *porder, gs_halftone_component *phtc, char *name, int len, int comp_num) { - int code, i; + int code, i, j; pdf_obj *obj = NULL, *transfer = NULL; double f, a; float values[2] = {0, 0}, domain[4] = {-1, 1, -1, 1}, out; @@ -1164,8 +1164,10 @@ static int build_type1_halftone(pdf_context *ctx, pdf_dict *halftone_dict, pdf_d if (pdfi_name_is((pdf_name *)obj, spot_table[i])) break; } - if (i >= (sizeof(spot_table) / sizeof (char *))) - return gs_note_error(gs_error_rangecheck); + if (i >= (sizeof(spot_table) / sizeof (char *))) { + code = gs_note_error(gs_error_rangecheck); + goto error; + } } code = pdfi_build_halftone_function(ctx, &pfn, (byte *)spot_functions[i], strlen(spot_functions[i])); if (code < 0) @@ -1177,6 +1179,39 @@ static int build_type1_halftone(pdf_context *ctx, pdf_dict *halftone_dict, pdf_d if (code < 0) goto error; break; + case PDF_ARRAY: + for (j = 0; j < pdfi_array_size((pdf_array *)obj); j++) { + pdf_name *n = NULL; + + code = pdfi_array_get(ctx, (pdf_array *)obj, j, (pdf_obj **)&n); + if (code < 0) + goto error; + if (pdfi_type_of(n) != PDF_NAME) + pdfi_set_error(ctx, 0, NULL, E_PDF_BAD_TYPE, "build_type1_halftone", "Halftone array element is not a name"); + else { + for (i = 0; i < (sizeof(spot_table) / sizeof (char *)); i++) { + if (pdfi_name_is((pdf_name *)n, spot_table[i])) { + pdfi_countdown(n); + n = NULL; + code = pdfi_build_halftone_function(ctx, &pfn, (byte *)spot_functions[i], strlen(spot_functions[i])); + if (code < 0) + goto error; + break; + } + } + if (i >= (sizeof(spot_table) / sizeof (char *))) { + pdfi_countdown(n); + n = NULL; + } else + break; + } + pdfi_countdown(n); + } + if (j >= pdfi_array_size((pdf_array *)obj)) { + code = gs_note_error(gs_error_rangecheck); + goto error; + } + break; default: code = gs_note_error(gs_error_typecheck); goto error; -- cgit v1.2.1