From 43e6a76ff86747501b77f2e485bdfcd8c067fb8f Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Tue, 30 Jan 2018 16:14:24 +0100 Subject: Use convenience pdf dictionary/array creation functions. --- source/pdf/pdf-write.c | 52 ++++++++++++++++++++++++-------------------------- 1 file changed, 25 insertions(+), 27 deletions(-) (limited to 'source/pdf/pdf-write.c') diff --git a/source/pdf/pdf-write.c b/source/pdf/pdf-write.c index 28a505f9..a7326a17 100644 --- a/source/pdf/pdf-write.c +++ b/source/pdf/pdf-write.c @@ -620,7 +620,7 @@ static int markobj(fz_context *ctx, pdf_document *doc, pdf_write_state *opts, pd { DEBUGGING_MARKING(indent(); printf("ARRAY[%d/%d]\n", i, n)); if (markobj(ctx, doc, opts, pdf_array_get(ctx, obj, i))) - pdf_array_put_drop(ctx, obj, i, pdf_new_null(ctx, doc)); + pdf_array_put(ctx, obj, i, PDF_OBJ_NULL); } } @@ -1185,7 +1185,7 @@ add_linearization_objs(fz_context *ctx, pdf_document *doc, pdf_write_state *opts opts->renumber_map[params_num] = params_num; opts->rev_renumber_map[params_num] = params_num; opts->gen_list[params_num] = 0; - pdf_dict_put_drop(ctx, params_obj, PDF_NAME_Linearized, pdf_new_real(ctx, doc, 1.0f)); + pdf_dict_put_real(ctx, params_obj, PDF_NAME_Linearized, 1.0f); opts->linear_l = pdf_new_int(ctx, doc, INT_MIN); pdf_dict_put(ctx, params_obj, PDF_NAME_L, opts->linear_l); opts->linear_h0 = pdf_new_int(ctx, doc, INT_MIN); @@ -1212,7 +1212,7 @@ add_linearization_objs(fz_context *ctx, pdf_document *doc, pdf_write_state *opts opts->renumber_map[hint_num] = hint_num; opts->rev_renumber_map[hint_num] = hint_num; opts->gen_list[hint_num] = 0; - pdf_dict_put_drop(ctx, hint_obj, PDF_NAME_P, pdf_new_int(ctx, doc, 0)); + pdf_dict_put_int(ctx, hint_obj, PDF_NAME_P, 0); opts->hints_s = pdf_new_int(ctx, doc, INT_MIN); pdf_dict_put(ctx, hint_obj, PDF_NAME_S, opts->hints_s); /* FIXME: Do we have thumbnails? Do a T entry */ @@ -1223,7 +1223,7 @@ add_linearization_objs(fz_context *ctx, pdf_document *doc, pdf_write_state *opts /* FIXME: Do we have document information? Do an I entry */ /* FIXME: Do we have logical structure hierarchy? Do a C entry */ /* FIXME: Do L, Page Label hint table */ - pdf_dict_put_drop(ctx, hint_obj, PDF_NAME_Filter, PDF_NAME_FlateDecode); + pdf_dict_put(ctx, hint_obj, PDF_NAME_Filter, PDF_NAME_FlateDecode); opts->hints_length = pdf_new_int(ctx, doc, INT_MIN); pdf_dict_put(ctx, hint_obj, PDF_NAME_Length, opts->hints_length); pdf_get_xref_entry(ctx, doc, hint_num)->stm_ofs = -1; @@ -1605,7 +1605,7 @@ static void addhexfilter(fz_context *ctx, pdf_document *doc, pdf_obj *dict) if (pdf_is_dict(ctx, dp)) { newdp = pdf_new_array(ctx, doc, 2); - pdf_array_push_drop(ctx, newdp, pdf_new_null(ctx, doc)); + pdf_array_push(ctx, newdp, PDF_OBJ_NULL); pdf_array_push(ctx, newdp, dp); dp = newdp; } @@ -1723,7 +1723,6 @@ static void copystream(fz_context *ctx, pdf_document *doc, pdf_write_state *opts static void expandstream(fz_context *ctx, pdf_document *doc, pdf_write_state *opts, pdf_obj *obj_orig, int num, int gen, int do_deflate) { fz_buffer *buf, *tmp; - pdf_obj *newlen; pdf_obj *obj; int truncated = 0; size_t len; @@ -1769,8 +1768,7 @@ static void expandstream(fz_context *ctx, pdf_document *doc, pdf_write_state *op addhexfilter(ctx, doc, obj); } - newlen = pdf_new_int(ctx, doc, (int)len); - pdf_dict_put_drop(ctx, obj, PDF_NAME_Length, newlen); + pdf_dict_put_int(ctx, obj, PDF_NAME_Length, len); fz_write_printf(ctx, opts->out, "%d %d obj\n", num, gen); pdf_print_encrypted_obj(ctx, opts->out, obj, opts->do_tight, doc->crypt, num, gen); @@ -2000,8 +1998,8 @@ static void writexref(fz_context *ctx, pdf_document *doc, pdf_write_state *opts, if (opts->do_incremental) { trailer = pdf_keep_obj(ctx, pdf_trailer(ctx, doc)); - pdf_dict_put_drop(ctx, trailer, PDF_NAME_Size, pdf_new_int(ctx, doc, pdf_xref_len(ctx, doc))); - pdf_dict_put_drop(ctx, trailer, PDF_NAME_Prev, pdf_new_int(ctx, doc, doc->startxref)); + pdf_dict_put_int(ctx, trailer, PDF_NAME_Size, pdf_xref_len(ctx, doc)); + pdf_dict_put_int(ctx, trailer, PDF_NAME_Prev, doc->startxref); doc->startxref = startxref; } else @@ -2052,8 +2050,8 @@ static void writexrefstreamsubsect(fz_context *ctx, pdf_document *doc, pdf_write { int num; - pdf_array_push_drop(ctx, index, pdf_new_int(ctx, doc, from)); - pdf_array_push_drop(ctx, index, pdf_new_int(ctx, doc, to - from)); + pdf_array_push_int(ctx, index, from); + pdf_array_push_int(ctx, index, to - from); for (num = from; num < to; num++) { fz_append_byte(ctx, fzbuf, opts->use_list[num] ? 1 : 0); @@ -2109,26 +2107,26 @@ static void writexrefstream(fz_context *ctx, pdf_document *doc, pdf_write_state } } - pdf_dict_put_drop(ctx, dict, PDF_NAME_Size, pdf_new_int(ctx, doc, to)); + pdf_dict_put_int(ctx, dict, PDF_NAME_Size, to); if (opts->do_incremental) { - pdf_dict_put_drop(ctx, dict, PDF_NAME_Prev, pdf_new_int(ctx, doc, doc->startxref)); + pdf_dict_put_int(ctx, dict, PDF_NAME_Prev, doc->startxref); doc->startxref = startxref; } else { if (main_xref_offset != 0) - pdf_dict_put_drop(ctx, dict, PDF_NAME_Prev, pdf_new_int(ctx, doc, main_xref_offset)); + pdf_dict_put_int(ctx, dict, PDF_NAME_Prev, main_xref_offset); } - pdf_dict_put_drop(ctx, dict, PDF_NAME_Type, PDF_NAME_XRef); + pdf_dict_put(ctx, dict, PDF_NAME_Type, PDF_NAME_XRef); w = pdf_new_array(ctx, doc, 3); pdf_dict_put(ctx, dict, PDF_NAME_W, w); - pdf_array_push_drop(ctx, w, pdf_new_int(ctx, doc, 1)); - pdf_array_push_drop(ctx, w, pdf_new_int(ctx, doc, 4)); - pdf_array_push_drop(ctx, w, pdf_new_int(ctx, doc, 1)); + pdf_array_push_int(ctx, w, 1); + pdf_array_push_int(ctx, w, 4); + pdf_array_push_int(ctx, w, 1); index = pdf_new_array(ctx, doc, 2); pdf_dict_put_drop(ctx, dict, PDF_NAME_Index, index); @@ -2616,8 +2614,8 @@ static void presize_unsaved_signature_byteranges(fz_context *ctx, pdf_document * for (i = 0; i < n+1; i++) { - pdf_array_push_drop(ctx, byte_range, pdf_new_int(ctx, doc, INT_MAX)); - pdf_array_push_drop(ctx, byte_range, pdf_new_int(ctx, doc, INT_MAX)); + pdf_array_push_int(ctx, byte_range, INT_MAX); + pdf_array_push_int(ctx, byte_range, INT_MAX); } } } @@ -2678,12 +2676,12 @@ static void complete_signatures(fz_context *ctx, pdf_document *doc, pdf_write_st last_end = 0; for (usig = xref->unsaved_sigs; usig; usig = usig->next) { - pdf_array_push_drop(ctx, byte_range, pdf_new_int(ctx, doc, last_end)); - pdf_array_push_drop(ctx, byte_range, pdf_new_int(ctx, doc, usig->contents_start - last_end)); + pdf_array_push_int(ctx, byte_range, last_end); + pdf_array_push_int(ctx, byte_range, usig->contents_start - last_end); last_end = usig->contents_end; } - pdf_array_push_drop(ctx, byte_range, pdf_new_int(ctx, doc, last_end)); - pdf_array_push_drop(ctx, byte_range, pdf_new_int(ctx, doc, xref->end_ofs - last_end)); + pdf_array_push_int(ctx, byte_range, last_end); + pdf_array_push_int(ctx, byte_range, xref->end_ofs - last_end); /* Copy the new ByteRange to the other unsaved signatures */ for (usig = xref->unsaved_sigs->next; usig; usig = usig->next) @@ -3197,8 +3195,8 @@ make_page_tree_node(fz_context *ctx, pdf_document *doc, int l, int r, pdf_obj *p fz_try(ctx) { me = pdf_new_dict(ctx, doc, 2); - pdf_dict_put_drop(ctx, me, PDF_NAME_Type, PDF_NAME_Pages); - pdf_dict_put_drop(ctx, me, PDF_NAME_Count, pdf_new_int(ctx, doc, r-l)); + pdf_dict_put(ctx, me, PDF_NAME_Type, PDF_NAME_Pages); + pdf_dict_put_int(ctx, me, PDF_NAME_Count, r-l); if (!root) pdf_dict_put(ctx, me, PDF_NAME_Parent, parent_ref); a = pdf_new_array(ctx, doc, KIDS_PER_LEVEL); -- cgit v1.2.3