From 3dccb4108ff8ea8bfd6d56529db36ba257c17d6a Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Tue, 20 Mar 2018 16:11:09 +0100 Subject: Use PDF object creation convenience functions. Use pdf_dict_put_* convenience functions. Use pdf_dict_get instead of pdf_dict_gets with constant strings. --- source/pdf/pdf-annot-edit.c | 51 ++++++++++++++++++++------------------------- source/pdf/pdf-annot.c | 2 +- source/pdf/pdf-object.c | 32 +++++++++++----------------- source/pdf/pdf-pattern.c | 4 ++-- source/pdf/pdf-write.c | 2 +- source/pdf/pdf-xref.c | 6 +++--- 6 files changed, 42 insertions(+), 55 deletions(-) (limited to 'source/pdf') diff --git a/source/pdf/pdf-annot-edit.c b/source/pdf/pdf-annot-edit.c index 8ca64198..900145a5 100644 --- a/source/pdf/pdf-annot-edit.c +++ b/source/pdf/pdf-annot-edit.c @@ -233,8 +233,7 @@ pdf_annot_flags(fz_context *ctx, pdf_annot *annot) void pdf_set_annot_flags(fz_context *ctx, pdf_annot *annot, int flags) { - pdf_document *doc = annot->page->doc; - pdf_dict_put_drop(ctx, annot->obj, PDF_NAME_F, pdf_new_int(ctx, doc, flags)); + pdf_dict_put_int(ctx, annot->obj, PDF_NAME_F, flags); pdf_dirty_annot(ctx, annot); } @@ -341,9 +340,8 @@ pdf_annot_icon_name(fz_context *ctx, pdf_annot *annot) void pdf_set_annot_icon_name(fz_context *ctx, pdf_annot *annot, const char *name) { - pdf_document *doc = annot->page->doc; check_allowed_subtypes(ctx, annot, PDF_NAME_Name, icon_name_subtypes); - pdf_dict_put_drop(ctx, annot->obj, PDF_NAME_Name, pdf_new_name(ctx, doc, name)); + pdf_dict_put_name(ctx, annot->obj, PDF_NAME_Name, name); pdf_dirty_annot(ctx, annot); } @@ -602,18 +600,18 @@ static void pdf_set_annot_color_imp(fz_context *ctx, pdf_annot *annot, pdf_obj * switch (n) { case 1: - pdf_array_insert_drop(ctx, arr, pdf_new_real(ctx, doc, color[0]), 0); + pdf_array_push_real(ctx, arr, color[0]); break; case 3: - pdf_array_insert_drop(ctx, arr, pdf_new_real(ctx, doc, color[0]), 0); - pdf_array_insert_drop(ctx, arr, pdf_new_real(ctx, doc, color[1]), 1); - pdf_array_insert_drop(ctx, arr, pdf_new_real(ctx, doc, color[2]), 2); + pdf_array_push_real(ctx, arr, color[0]); + pdf_array_push_real(ctx, arr, color[1]); + pdf_array_push_real(ctx, arr, color[2]); break; case 4: - pdf_array_insert_drop(ctx, arr, pdf_new_real(ctx, doc, color[0]), 0); - pdf_array_insert_drop(ctx, arr, pdf_new_real(ctx, doc, color[1]), 1); - pdf_array_insert_drop(ctx, arr, pdf_new_real(ctx, doc, color[2]), 2); - pdf_array_insert_drop(ctx, arr, pdf_new_real(ctx, doc, color[3]), 3); + pdf_array_push_real(ctx, arr, color[0]); + pdf_array_push_real(ctx, arr, color[1]); + pdf_array_push_real(ctx, arr, color[2]); + pdf_array_push_real(ctx, arr, color[3]); break; } } @@ -782,8 +780,8 @@ pdf_set_annot_vertices(fz_context *ctx, pdf_annot *annot, int n, const fz_point { point = v[i]; fz_transform_point(&point, &inv_page_ctm); - pdf_array_push_drop(ctx, vertices, pdf_new_real(ctx, doc, point.x)); - pdf_array_push_drop(ctx, vertices, pdf_new_real(ctx, doc, point.y)); + pdf_array_push_real(ctx, vertices, point.x); + pdf_array_push_real(ctx, vertices, point.y); } pdf_dict_put_drop(ctx, annot->obj, PDF_NAME_Vertices, vertices); pdf_dirty_annot(ctx, annot); @@ -909,8 +907,8 @@ pdf_set_annot_quad_points(fz_context *ctx, pdf_annot *annot, int n, const float point.x = v[i * 8 + k * 2 + 0]; point.y = v[i * 8 + k * 2 + 1]; fz_transform_point(&point, &inv_page_ctm); - pdf_array_push_drop(ctx, quad_points, pdf_new_real(ctx, doc, point.x)); - pdf_array_push_drop(ctx, quad_points, pdf_new_real(ctx, doc, point.y)); + pdf_array_push_real(ctx, quad_points, point.x); + pdf_array_push_real(ctx, quad_points, point.y); } } pdf_dict_put_drop(ctx, annot->obj, PDF_NAME_QuadPoints, quad_points); @@ -1038,8 +1036,8 @@ pdf_set_annot_ink_list(fz_context *ctx, pdf_annot *annot, int n, const int *coun { point = *v++; fz_transform_point(&point, &inv_page_ctm); - pdf_array_push_drop(ctx, stroke, pdf_new_real(ctx, doc, point.x)); - pdf_array_push_drop(ctx, stroke, pdf_new_real(ctx, doc, point.y)); + pdf_array_push_real(ctx, stroke, point.x); + pdf_array_push_real(ctx, stroke, point.y); } pdf_array_push_drop(ctx, ink_list, stroke); } @@ -1100,7 +1098,6 @@ pdf_add_annot_ink_list(fz_context *ctx, pdf_annot *annot, int n, fz_point p[]) void pdf_set_text_annot_position(fz_context *ctx, pdf_annot *annot, fz_point pt) { - pdf_document *doc = annot->page->doc; fz_matrix page_ctm, inv_page_ctm; fz_rect rect; int flags; @@ -1114,11 +1111,11 @@ pdf_set_text_annot_position(fz_context *ctx, pdf_annot *annot, fz_point pt) rect.y1 = pt.y + TEXT_ANNOT_SIZE; fz_transform_rect(&rect, &inv_page_ctm); - pdf_dict_put_drop(ctx, annot->obj, PDF_NAME_Rect, pdf_new_rect(ctx, doc, &rect)); + pdf_dict_put_rect(ctx, annot->obj, PDF_NAME_Rect, &rect); flags = pdf_to_int(ctx, pdf_dict_get(ctx, annot->obj, PDF_NAME_F)); flags |= (PDF_ANNOT_IS_NO_ZOOM|PDF_ANNOT_IS_NO_ROTATE); - pdf_dict_put_drop(ctx, annot->obj, PDF_NAME_F, pdf_new_int(ctx, doc, flags)); + pdf_dict_put_int(ctx, annot->obj, PDF_NAME_F, flags); } static void @@ -1251,13 +1248,12 @@ pdf_annot_modification_date(fz_context *ctx, pdf_annot *annot) void pdf_set_annot_modification_date(fz_context *ctx, pdf_annot *annot, int64_t secs) { - pdf_document *doc = annot->page->doc; char s[40]; check_allowed_subtypes(ctx, annot, PDF_NAME_M, markup_subtypes); pdf_format_date(ctx, s, sizeof s, secs); - pdf_dict_put_drop(ctx, annot->obj, PDF_NAME_M, pdf_new_string(ctx, doc, s, strlen(s))); + pdf_dict_put_string(ctx, annot->obj, PDF_NAME_M, s, strlen(s)); pdf_dirty_annot(ctx, annot); } @@ -1277,9 +1273,8 @@ pdf_copy_annot_author(fz_context *ctx, pdf_annot *annot) void pdf_set_annot_author(fz_context *ctx, pdf_annot *annot, const char *author) { - pdf_document *doc = annot->page->doc; check_allowed_subtypes(ctx, annot, PDF_NAME_T, markup_subtypes); - pdf_dict_put_drop(ctx, annot->obj, PDF_NAME_T, pdf_new_text_string(ctx, doc, author)); + pdf_dict_put_text_string(ctx, annot->obj, PDF_NAME_T, author); pdf_dirty_annot(ctx, annot); } @@ -1359,10 +1354,10 @@ pdf_set_free_text_details(fz_context *ctx, pdf_annot *annot, fz_point *pos, char pdf_fzbuf_print_da(ctx, fzbuf, &da_info); da_len = fz_buffer_storage(ctx, fzbuf, &da_str); - pdf_dict_put_drop(ctx, annot->obj, PDF_NAME_DA, pdf_new_string(ctx, doc, (char *)da_str, da_len)); + pdf_dict_put_string(ctx, annot->obj, PDF_NAME_DA, (char *)da_str, da_len); /* FIXME: should convert to WinAnsiEncoding */ - pdf_dict_put_drop(ctx, annot->obj, PDF_NAME_Contents, pdf_new_string(ctx, doc, text, strlen(text))); + pdf_dict_put_text_string(ctx, annot->obj, PDF_NAME_Contents, text); font_desc = pdf_load_font(ctx, doc, NULL, font, 0); pdf_measure_text(ctx, font_desc, (unsigned char *)text, strlen(text), &bounds); @@ -1380,7 +1375,7 @@ pdf_set_free_text_details(fz_context *ctx, pdf_annot *annot, fz_point *pos, char bounds.y0 += page_pos.y; bounds.y1 += page_pos.y; - pdf_dict_put_drop(ctx, annot->obj, PDF_NAME_Rect, pdf_new_rect(ctx, doc, &bounds)); + pdf_dict_put_rect(ctx, annot->obj, PDF_NAME_Rect, &bounds); } fz_always(ctx) { diff --git a/source/pdf/pdf-annot.c b/source/pdf/pdf-annot.c index 314ca092..f60401af 100644 --- a/source/pdf/pdf-annot.c +++ b/source/pdf/pdf-annot.c @@ -136,7 +136,7 @@ pdf_parse_file_spec(fz_context *ctx, pdf_document *doc, pdf_obj *file_spec, pdf_ path = pdf_to_utf8(ctx, filename); #ifdef _WIN32 - if (strcmp(pdf_to_name(ctx, pdf_dict_gets(ctx, file_spec, "FS")), "URL") != 0) + if (!pdf_name_eq(ctx, pdf_dict_get(ctx, file_spec, PDF_NAME_FS), PDF_NAME_URL)) { /* move the file name into the expected place and use the expected path separator */ char *c; diff --git a/source/pdf/pdf-object.c b/source/pdf/pdf-object.c index 9b1ef7b5..bd68b761 100644 --- a/source/pdf/pdf-object.c +++ b/source/pdf/pdf-object.c @@ -818,47 +818,39 @@ pdf_array_find(fz_context *ctx, pdf_obj *arr, pdf_obj *obj) pdf_obj *pdf_new_rect(fz_context *ctx, pdf_document *doc, const fz_rect *rect) { - pdf_obj *arr; - - arr = pdf_new_array(ctx, doc, 4); - + pdf_obj *arr = pdf_new_array(ctx, doc, 4); fz_try(ctx) { - pdf_array_push_drop(ctx, arr, pdf_new_real(ctx, doc, rect->x0)); - pdf_array_push_drop(ctx, arr, pdf_new_real(ctx, doc, rect->y0)); - pdf_array_push_drop(ctx, arr, pdf_new_real(ctx, doc, rect->x1)); - pdf_array_push_drop(ctx, arr, pdf_new_real(ctx, doc, rect->y1)); + pdf_array_push_real(ctx, arr, rect->x0); + pdf_array_push_real(ctx, arr, rect->y0); + pdf_array_push_real(ctx, arr, rect->x1); + pdf_array_push_real(ctx, arr, rect->y1); } fz_catch(ctx) { pdf_drop_obj(ctx, arr); fz_rethrow(ctx); } - return arr; } pdf_obj *pdf_new_matrix(fz_context *ctx, pdf_document *doc, const fz_matrix *mtx) { - pdf_obj *arr; - - arr = pdf_new_array(ctx, doc, 6); - + pdf_obj *arr = pdf_new_array(ctx, doc, 6); fz_try(ctx) { - pdf_array_push_drop(ctx, arr, pdf_new_real(ctx, doc, mtx->a)); - pdf_array_push_drop(ctx, arr, pdf_new_real(ctx, doc, mtx->b)); - pdf_array_push_drop(ctx, arr, pdf_new_real(ctx, doc, mtx->c)); - pdf_array_push_drop(ctx, arr, pdf_new_real(ctx, doc, mtx->d)); - pdf_array_push_drop(ctx, arr, pdf_new_real(ctx, doc, mtx->e)); - pdf_array_push_drop(ctx, arr, pdf_new_real(ctx, doc, mtx->f)); + pdf_array_push_real(ctx, arr, mtx->a); + pdf_array_push_real(ctx, arr, mtx->b); + pdf_array_push_real(ctx, arr, mtx->c); + pdf_array_push_real(ctx, arr, mtx->d); + pdf_array_push_real(ctx, arr, mtx->e); + pdf_array_push_real(ctx, arr, mtx->f); } fz_catch(ctx) { pdf_drop_obj(ctx, arr); fz_rethrow(ctx); } - return arr; } diff --git a/source/pdf/pdf-pattern.c b/source/pdf/pdf-pattern.c index 578f1d93..7523c5bc 100644 --- a/source/pdf/pdf-pattern.c +++ b/source/pdf/pdf-pattern.c @@ -57,10 +57,10 @@ pdf_load_pattern(fz_context *ctx, pdf_document *doc, pdf_obj *dict) pat->xstep = pdf_to_real(ctx, pdf_dict_get(ctx, dict, PDF_NAME_XStep)); pat->ystep = pdf_to_real(ctx, pdf_dict_get(ctx, dict, PDF_NAME_YStep)); - obj = pdf_dict_gets(ctx, dict, "BBox"); + obj = pdf_dict_get(ctx, dict, PDF_NAME_BBox); pdf_to_rect(ctx, obj, &pat->bbox); - obj = pdf_dict_gets(ctx, dict, "Matrix"); + obj = pdf_dict_get(ctx, dict, PDF_NAME_Matrix); if (obj) pdf_to_matrix(ctx, obj, &pat->matrix); else diff --git a/source/pdf/pdf-write.c b/source/pdf/pdf-write.c index 2d5b5372..b4d51949 100644 --- a/source/pdf/pdf-write.c +++ b/source/pdf/pdf-write.c @@ -1616,7 +1616,7 @@ static void addhexfilter(fz_context *ctx, pdf_document *doc, pdf_obj *dict) { pdf_array_insert(ctx, f, PDF_NAME_ASCIIHexDecode, 0); if (pdf_is_array(ctx, dp)) - pdf_array_insert_drop(ctx, dp, pdf_new_null(ctx, doc), 0); + pdf_array_insert(ctx, dp, PDF_OBJ_NULL, 0); } else f = PDF_NAME_ASCIIHexDecode; diff --git a/source/pdf/pdf-xref.c b/source/pdf/pdf-xref.c index c48cf83f..8515090d 100644 --- a/source/pdf/pdf-xref.c +++ b/source/pdf/pdf-xref.c @@ -2174,11 +2174,11 @@ pdf_update_stream(fz_context *ctx, pdf_document *doc, pdf_obj *obj, fz_buffer *n fz_drop_buffer(ctx, x->stm_buf); x->stm_buf = fz_keep_buffer(ctx, newbuf); - pdf_dict_puts_drop(ctx, obj, "Length", pdf_new_int(ctx, doc, (int)fz_buffer_storage(ctx, newbuf, NULL))); + pdf_dict_put_int(ctx, obj, PDF_NAME_Length, (int)fz_buffer_storage(ctx, newbuf, NULL)); if (!compressed) { - pdf_dict_dels(ctx, obj, "Filter"); - pdf_dict_dels(ctx, obj, "DecodeParms"); + pdf_dict_del(ctx, obj, PDF_NAME_Filter); + pdf_dict_del(ctx, obj, PDF_NAME_DecodeParms); } } -- cgit v1.2.3