diff options
Diffstat (limited to 'source/pdf')
29 files changed, 1276 insertions, 1078 deletions
diff --git a/source/pdf/js/pdf-js.c b/source/pdf/js/pdf-js.c index 84a14381..6eea8c30 100644 --- a/source/pdf/js/pdf-js.c +++ b/source/pdf/js/pdf-js.c @@ -803,9 +803,9 @@ static pdf_js *pdf_new_js(fz_context *ctx, pdf_document *doc) js->doc = doc; /* Find the form array */ - root = pdf_dict_gets(ctx, pdf_trailer(ctx, doc), "Root"); - acroform = pdf_dict_gets(ctx, root, "AcroForm"); - js->form = pdf_dict_gets(ctx, acroform, "Fields"); + root = pdf_dict_get(ctx, pdf_trailer(ctx, doc), PDF_NAME_Root); + acroform = pdf_dict_get(ctx, root, PDF_NAME_AcroForm); + js->form = pdf_dict_get(ctx, acroform, PDF_NAME_Fields); /* Initialise the javascript engine, passing the main context * for use in memory allocation and exception handling. Also @@ -837,13 +837,13 @@ static void pdf_js_load_document_level(pdf_js *js) { int len, i; - javascript = pdf_load_name_tree(ctx, doc, "JavaScript"); + javascript = pdf_load_name_tree(ctx, doc, PDF_NAME_JavaScript); len = pdf_dict_len(ctx, javascript); for (i = 0; i < len; i++) { pdf_obj *fragment = pdf_dict_get_val(ctx, javascript, i); - pdf_obj *code = pdf_dict_gets(ctx, fragment, "JS"); + pdf_obj *code = pdf_dict_get(ctx, fragment, PDF_NAME_JS); fz_var(codebuf); fz_try(ctx) diff --git a/source/pdf/pdf-annot-edit.c b/source/pdf/pdf-annot-edit.c index 565e3171..aef14e6f 100644 --- a/source/pdf/pdf-annot-edit.c +++ b/source/pdf/pdf-annot-edit.c @@ -45,8 +45,8 @@ pdf_update_annot(fz_context *ctx, pdf_document *doc, pdf_annot *annot) obj = annot->obj; - ap = pdf_dict_gets(ctx, obj, "AP"); - as = pdf_dict_gets(ctx, obj, "AS"); + ap = pdf_dict_get(ctx, obj, PDF_NAME_AP); + as = pdf_dict_get(ctx, obj, PDF_NAME_AS); if (pdf_is_dict(ctx, ap)) { @@ -58,11 +58,11 @@ pdf_update_annot(fz_context *ctx, pdf_document *doc, pdf_annot *annot) && hp->gen == pdf_to_gen(ctx, obj) && (hp->state & HOTSPOT_POINTER_DOWN)) { - n = pdf_dict_gets(ctx, ap, "D"); /* down state */ + n = pdf_dict_get(ctx, ap, PDF_NAME_D); /* down state */ } if (n == NULL) - n = pdf_dict_gets(ctx, ap, "N"); /* normal state */ + n = pdf_dict_get(ctx, ap, PDF_NAME_N); /* normal state */ /* lookup current state in sub-dictionary */ if (!pdf_is_stream(ctx, doc, pdf_to_num(ctx, n), pdf_to_gen(ctx, n))) @@ -102,20 +102,20 @@ pdf_create_annot(fz_context *ctx, pdf_document *doc, pdf_page *page, fz_annot_ty int ind_obj_num; fz_rect rect = {0.0, 0.0, 0.0, 0.0}; const char *type_str = annot_type_str(type); - pdf_obj *annot_arr = pdf_dict_gets(ctx, page->me, "Annots"); + pdf_obj *annot_arr = pdf_dict_get(ctx, page->me, PDF_NAME_Annots); if (annot_arr == NULL) { annot_arr = pdf_new_array(ctx, doc, 0); - pdf_dict_puts_drop(ctx, page->me, "Annots", annot_arr); + pdf_dict_put_drop(ctx, page->me, PDF_NAME_Annots, annot_arr); } - pdf_dict_puts_drop(ctx, annot_obj, "Type", pdf_new_name(ctx, doc, "Annot")); + pdf_dict_put_drop(ctx, annot_obj, PDF_NAME_Type, PDF_NAME_Annot); - pdf_dict_puts_drop(ctx, annot_obj, "Subtype", pdf_new_name(ctx, doc, type_str)); - pdf_dict_puts_drop(ctx, annot_obj, "Rect", pdf_new_rect(ctx, doc, &rect)); + pdf_dict_put_drop(ctx, annot_obj, PDF_NAME_Subtype, pdf_new_name(ctx, doc, type_str)); + pdf_dict_put_drop(ctx, annot_obj, PDF_NAME_Rect, pdf_new_rect(ctx, doc, &rect)); /* Make printable as default */ - pdf_dict_puts_drop(ctx, annot_obj, "F", pdf_new_int(ctx, doc, F_Print)); + pdf_dict_put_drop(ctx, annot_obj, PDF_NAME_F, pdf_new_int(ctx, doc, F_Print)); annot = fz_malloc_struct(ctx, pdf_annot); annot->page = page; @@ -194,7 +194,7 @@ pdf_delete_annot(fz_context *ctx, pdf_document *doc, pdf_page *page, pdf_annot * annot->ap = NULL; /* Recreate the "Annots" array with this annot removed */ - old_annot_arr = pdf_dict_gets(ctx, page->me, "Annots"); + old_annot_arr = pdf_dict_get(ctx, page->me, PDF_NAME_Annots); if (old_annot_arr) { @@ -214,7 +214,7 @@ pdf_delete_annot(fz_context *ctx, pdf_document *doc, pdf_page *page, pdf_annot * if (pdf_is_indirect(ctx, old_annot_arr)) pdf_update_object(ctx, doc, pdf_to_num(ctx, old_annot_arr), annot_arr); else - pdf_dict_puts(ctx, page->me, "Annots", annot_arr); + pdf_dict_put(ctx, page->me, PDF_NAME_Annots, annot_arr); if (pdf_is_indirect(ctx, annot->obj)) pdf_delete_object(ctx, doc, pdf_to_num(ctx, annot->obj)); @@ -243,7 +243,7 @@ pdf_set_markup_annot_quadpoints(fz_context *ctx, pdf_document *doc, pdf_annot *a fz_invert_matrix(&ctm, &annot->page->ctm); - pdf_dict_puts_drop(ctx, annot->obj, "QuadPoints", arr); + pdf_dict_put_drop(ctx, annot->obj, PDF_NAME_QuadPoints, arr); for (i = 0; i < n; i++) { @@ -260,7 +260,7 @@ pdf_set_markup_annot_quadpoints(fz_context *ctx, pdf_document *doc, pdf_annot *a static void update_rect(fz_context *ctx, pdf_annot *annot) { - pdf_to_rect(ctx, pdf_dict_gets(ctx, annot->obj, "Rect"), &annot->rect); + pdf_to_rect(ctx, pdf_dict_get(ctx, annot->obj, PDF_NAME_Rect), &annot->rect); annot->pagerect = annot->rect; fz_transform_rect(&annot->pagerect, &annot->page->ctm); } @@ -276,7 +276,7 @@ pdf_set_ink_annot_list(fz_context *ctx, pdf_document *doc, pdf_annot *annot, fz_ fz_invert_matrix(&ctm, &annot->page->ctm); - pdf_dict_puts_drop(ctx, annot->obj, "InkList", list); + pdf_dict_put_drop(ctx, annot->obj, PDF_NAME_InkList, list); for (i = 0; i < ncount; i++) { @@ -320,15 +320,15 @@ pdf_set_ink_annot_list(fz_context *ctx, pdf_document *doc, pdf_annot *annot, fz_ rect.y1 += thickness; } - pdf_dict_puts_drop(ctx, annot->obj, "Rect", pdf_new_rect(ctx, doc, &rect)); + pdf_dict_put_drop(ctx, annot->obj, PDF_NAME_Rect, pdf_new_rect(ctx, doc, &rect)); update_rect(ctx, annot); bs = pdf_new_dict(ctx, doc, 1); - pdf_dict_puts_drop(ctx, annot->obj, "BS", bs); - pdf_dict_puts_drop(ctx, bs, "W", pdf_new_real(ctx, doc, thickness)); + pdf_dict_put_drop(ctx, annot->obj, PDF_NAME_BS, bs); + pdf_dict_put_drop(ctx, bs, PDF_NAME_W, pdf_new_real(ctx, doc, thickness)); col = pdf_new_array(ctx, doc, 3); - pdf_dict_puts_drop(ctx, annot->obj, "C", col); + pdf_dict_put_drop(ctx, annot->obj, PDF_NAME_C, col); for (i = 0; i < 3; i++) pdf_array_push_drop(ctx, col, pdf_new_real(ctx, doc, color[i])); } @@ -360,23 +360,23 @@ void pdf_set_text_annot_position(fz_context *ctx, pdf_document *doc, pdf_annot * rect.y1 = pt.y + TEXT_ANNOT_SIZE; fz_transform_rect(&rect, &ctm); - pdf_dict_puts_drop(ctx, annot->obj, "Rect", pdf_new_rect(ctx, doc, &rect)); + pdf_dict_put_drop(ctx, annot->obj, PDF_NAME_Rect, pdf_new_rect(ctx, doc, &rect)); - flags = pdf_to_int(ctx, pdf_dict_gets(ctx, annot->obj, "F")); + flags = pdf_to_int(ctx, pdf_dict_get(ctx, annot->obj, PDF_NAME_F)); flags |= (F_NoZoom|F_NoRotate); - pdf_dict_puts_drop(ctx, annot->obj, "F", pdf_new_int(ctx, doc, flags)); + pdf_dict_put_drop(ctx, annot->obj, PDF_NAME_F, pdf_new_int(ctx, doc, flags)); update_rect(ctx, annot); } void pdf_set_annot_contents(fz_context *ctx, pdf_document *doc, pdf_annot *annot, char *text) { - pdf_dict_puts_drop(ctx, annot->obj, "Contents", pdf_new_string(ctx, doc, text, strlen(text))); + pdf_dict_put_drop(ctx, annot->obj, PDF_NAME_Contents, pdf_new_string(ctx, doc, text, strlen(text))); } char *pdf_annot_contents(fz_context *ctx, pdf_document *doc, pdf_annot *annot) { - return pdf_to_str_buf(ctx, pdf_dict_getp(ctx, annot->obj, "Contents")); + return pdf_to_str_buf(ctx, pdf_dict_get(ctx, annot->obj, PDF_NAME_Contents)); } void pdf_set_free_text_details(fz_context *ctx, pdf_document *doc, pdf_annot *annot, fz_point *pos, char *text, char *font_name, float font_size, float color[3]) @@ -394,19 +394,19 @@ void pdf_set_free_text_details(fz_context *ctx, pdf_document *doc, pdf_annot *an fz_invert_matrix(&ctm, &annot->page->ctm); - dr = pdf_dict_gets(ctx, annot->page->me, "Resources"); + dr = pdf_dict_get(ctx, annot->page->me, PDF_NAME_Resources); if (!dr) { dr = pdf_new_dict(ctx, doc, 1); - pdf_dict_putp_drop(ctx, annot->page->me, "Resources", dr); + pdf_dict_put_drop(ctx, annot->page->me, PDF_NAME_Resources, dr); } /* Ensure the resource dictionary includes a font dict */ - form_fonts = pdf_dict_gets(ctx, dr, "Font"); + form_fonts = pdf_dict_get(ctx, dr, PDF_NAME_Font); if (!form_fonts) { form_fonts = pdf_new_dict(ctx, doc, 1); - pdf_dict_puts_drop(ctx, dr, "Font", form_fonts); + pdf_dict_put_drop(ctx, dr, PDF_NAME_Font, form_fonts); /* form_fonts is still valid if execution continues past the above call */ } @@ -424,10 +424,10 @@ void pdf_set_free_text_details(fz_context *ctx, pdf_document *doc, pdf_annot *an ref = pdf_new_ref(ctx, doc, font); pdf_dict_puts_drop(ctx, form_fonts, nbuf, ref); - pdf_dict_puts_drop(ctx, font, "Type", pdf_new_name(ctx, doc, "Font")); - pdf_dict_puts_drop(ctx, font, "Subtype", pdf_new_name(ctx, doc, "Type1")); - pdf_dict_puts_drop(ctx, font, "BaseFont", pdf_new_name(ctx, doc, font_name)); - pdf_dict_puts_drop(ctx, font, "Encoding", pdf_new_name(ctx, doc, "WinAnsiEncoding")); + pdf_dict_put_drop(ctx, font, PDF_NAME_Type, PDF_NAME_Font); + pdf_dict_put_drop(ctx, font, PDF_NAME_Subtype, PDF_NAME_Type1); + pdf_dict_put_drop(ctx, font, PDF_NAME_BaseFont, pdf_new_name(ctx, doc, font_name)); + pdf_dict_put_drop(ctx, font, PDF_NAME_Encoding, PDF_NAME_WinAnsiEncoding); memcpy(da_info.col, color, sizeof(float)*3); da_info.col_size = 3; @@ -438,10 +438,10 @@ void pdf_set_free_text_details(fz_context *ctx, pdf_document *doc, pdf_annot *an pdf_fzbuf_print_da(ctx, fzbuf, &da_info); da_len = fz_buffer_storage(ctx, fzbuf, &da_str); - pdf_dict_puts_drop(ctx, annot->obj, "DA", pdf_new_string(ctx, doc, (char *)da_str, da_len)); + pdf_dict_put_drop(ctx, annot->obj, PDF_NAME_DA, pdf_new_string(ctx, doc, (char *)da_str, da_len)); /* FIXME: should convert to WinAnsiEncoding */ - pdf_dict_puts_drop(ctx, annot->obj, "Contents", pdf_new_string(ctx, doc, text, strlen(text))); + pdf_dict_put_drop(ctx, annot->obj, PDF_NAME_Contents, pdf_new_string(ctx, doc, text, strlen(text))); font_desc = pdf_load_font(ctx, doc, NULL, font, 0); pdf_measure_text(ctx, font_desc, (unsigned char *)text, strlen(text), &bounds); @@ -459,7 +459,7 @@ void pdf_set_free_text_details(fz_context *ctx, pdf_document *doc, pdf_annot *an bounds.y0 += page_pos.y; bounds.y1 += page_pos.y; - pdf_dict_puts_drop(ctx, annot->obj, "Rect", pdf_new_rect(ctx, doc, &bounds)); + pdf_dict_put_drop(ctx, annot->obj, PDF_NAME_Rect, pdf_new_rect(ctx, doc, &bounds)); update_rect(ctx, annot); } fz_always(ctx) diff --git a/source/pdf/pdf-annot.c b/source/pdf/pdf-annot.c index 79114211..50c637d2 100644 --- a/source/pdf/pdf-annot.c +++ b/source/pdf/pdf-annot.c @@ -24,7 +24,7 @@ resolve_dest_rec(fz_context *ctx, pdf_document *doc, pdf_obj *dest, fz_link_kind else if (pdf_is_dict(ctx, dest)) { - dest = pdf_dict_gets(ctx, dest, "D"); + dest = pdf_dict_get(ctx, dest, PDF_NAME_D); return resolve_dest_rec(ctx, doc, dest, kind, depth+1); } @@ -101,27 +101,27 @@ pdf_parse_link_dest(fz_context *ctx, pdf_document *doc, fz_link_kind kind, pdf_o if (!pdf_is_name(ctx, obj)) return ld; - if (!strcmp("XYZ", pdf_to_name(ctx, obj))) + if (pdf_name_eq(ctx, PDF_NAME_XYZ, obj)) { l_from_2 = t_from_3 = z_from_4 = 1; ld.ld.gotor.flags |= fz_link_flag_r_is_zoom; } - else if ((!strcmp("Fit", pdf_to_name(ctx, obj))) || (!strcmp("FitB", pdf_to_name(ctx, obj)))) + else if ((pdf_name_eq(ctx, PDF_NAME_Fit, obj)) || (pdf_name_eq(ctx, PDF_NAME_FitB, obj))) { ld.ld.gotor.flags |= fz_link_flag_fit_h; ld.ld.gotor.flags |= fz_link_flag_fit_v; } - else if ((!strcmp("FitH", pdf_to_name(ctx, obj))) || (!strcmp("FitBH", pdf_to_name(ctx, obj)))) + else if ((pdf_name_eq(ctx, PDF_NAME_FitH, obj)) || (pdf_name_eq(ctx, PDF_NAME_FitBH, obj))) { t_from_2 = 1; ld.ld.gotor.flags |= fz_link_flag_fit_h; } - else if ((!strcmp("FitV", pdf_to_name(ctx, obj))) || (!strcmp("FitBV", pdf_to_name(ctx, obj)))) + else if ((pdf_name_eq(ctx, PDF_NAME_FitV, obj)) || (pdf_name_eq(ctx, PDF_NAME_FitBV, obj))) { l_from_2 = 1; ld.ld.gotor.flags |= fz_link_flag_fit_v; } - else if (!strcmp("FitR", pdf_to_name(ctx, obj))) + else if (pdf_name_eq(ctx, PDF_NAME_FitR, obj)) { l_from_2 = b_from_3 = r_from_4 = t_from_5 = 1; ld.ld.gotor.flags |= fz_link_flag_fit_h; @@ -228,12 +228,12 @@ pdf_parse_file_spec(fz_context *ctx, pdf_document *doc, pdf_obj *file_spec) if (pdf_is_dict(ctx, file_spec)) { #if defined(_WIN32) || defined(_WIN64) - filename = pdf_dict_gets(ctx, file_spec, "DOS"); + filename = pdf_dict_get(ctx, file_spec, PDF_NAME_DOS); #else - filename = pdf_dict_gets(ctx, file_spec, "Unix"); + filename = pdf_dict_get(ctx, file_spec, PDF_NAME_Unix); #endif if (!filename) - filename = pdf_dict_getsa(ctx, file_spec, "UF", "F"); + filename = pdf_dict_geta(ctx, file_spec, PDF_NAME_UF, PDF_NAME_F); } if (!pdf_is_string(ctx, filename)) @@ -274,38 +274,38 @@ pdf_parse_action(fz_context *ctx, pdf_document *doc, pdf_obj *action) if (!action) return ld; - obj = pdf_dict_gets(ctx, action, "S"); - if (!strcmp(pdf_to_name(ctx, obj), "GoTo")) + obj = pdf_dict_get(ctx, action, PDF_NAME_S); + if (pdf_name_eq(ctx, PDF_NAME_GoTo, obj)) { - dest = pdf_dict_gets(ctx, action, "D"); + dest = pdf_dict_get(ctx, action, PDF_NAME_D); ld = pdf_parse_link_dest(ctx, doc, FZ_LINK_GOTO, dest); } - else if (!strcmp(pdf_to_name(ctx, obj), "URI")) + else if (pdf_name_eq(ctx, PDF_NAME_URI, obj)) { ld.kind = FZ_LINK_URI; - ld.ld.uri.is_map = pdf_to_bool(ctx, pdf_dict_gets(ctx, action, "IsMap")); - ld.ld.uri.uri = pdf_to_utf8(ctx, doc, pdf_dict_gets(ctx, action, "URI")); + ld.ld.uri.is_map = pdf_to_bool(ctx, pdf_dict_get(ctx, action, PDF_NAME_IsMap)); + ld.ld.uri.uri = pdf_to_utf8(ctx, doc, pdf_dict_get(ctx, action, PDF_NAME_URI)); } - else if (!strcmp(pdf_to_name(ctx, obj), "Launch")) + else if (pdf_name_eq(ctx, PDF_NAME_Launch, obj)) { ld.kind = FZ_LINK_LAUNCH; - file_spec = pdf_dict_gets(ctx, action, "F"); + file_spec = pdf_dict_get(ctx, action, PDF_NAME_F); ld.ld.launch.file_spec = pdf_parse_file_spec(ctx, doc, file_spec); - ld.ld.launch.new_window = pdf_to_int(ctx, pdf_dict_gets(ctx, action, "NewWindow")); - ld.ld.launch.is_uri = !strcmp(pdf_to_name(ctx, pdf_dict_gets(ctx, file_spec, "FS")), "URL"); + ld.ld.launch.new_window = pdf_to_int(ctx, pdf_dict_get(ctx, action, PDF_NAME_NewWindow)); + ld.ld.launch.is_uri = pdf_name_eq(ctx, PDF_NAME_URL, pdf_dict_get(ctx, file_spec, PDF_NAME_FS)); } - else if (!strcmp(pdf_to_name(ctx, obj), "Named")) + else if (pdf_name_eq(ctx, PDF_NAME_Named, obj)) { ld.kind = FZ_LINK_NAMED; - ld.ld.named.named = fz_strdup(ctx, pdf_to_name(ctx, pdf_dict_gets(ctx, action, "N"))); + ld.ld.named.named = fz_strdup(ctx, pdf_to_name(ctx, pdf_dict_get(ctx, action, PDF_NAME_N))); } - else if (!strcmp(pdf_to_name(ctx, obj), "GoToR")) + else if (pdf_name_eq(ctx, PDF_NAME_GoToR, obj)) { - dest = pdf_dict_gets(ctx, action, "D"); - file_spec = pdf_dict_gets(ctx, action, "F"); + dest = pdf_dict_get(ctx, action, PDF_NAME_D); + file_spec = pdf_dict_get(ctx, action, PDF_NAME_F); ld = pdf_parse_link_dest(ctx, doc, FZ_LINK_GOTOR, dest); ld.ld.gotor.file_spec = pdf_parse_file_spec(ctx, doc, file_spec); - ld.ld.gotor.new_window = pdf_to_int(ctx, pdf_dict_gets(ctx, action, "NewWindow")); + ld.ld.gotor.new_window = pdf_to_int(ctx, pdf_dict_get(ctx, action, PDF_NAME_NewWindow)); } return ld; } @@ -318,7 +318,7 @@ pdf_load_link(fz_context *ctx, pdf_document *doc, pdf_obj *dict, const fz_matrix fz_rect bbox; fz_link_dest ld; - obj = pdf_dict_gets(ctx, dict, "Rect"); + obj = pdf_dict_get(ctx, dict, PDF_NAME_Rect); if (obj) pdf_to_rect(ctx, obj, &bbox); else @@ -326,15 +326,15 @@ pdf_load_link(fz_context *ctx, pdf_document *doc, pdf_obj *dict, const fz_matrix fz_transform_rect(&bbox, page_ctm); - obj = pdf_dict_gets(ctx, dict, "Dest"); + obj = pdf_dict_get(ctx, dict, PDF_NAME_Dest); if (obj) ld = pdf_parse_link_dest(ctx, doc, FZ_LINK_GOTO, obj); else { - action = pdf_dict_gets(ctx, dict, "A"); + action = pdf_dict_get(ctx, dict, PDF_NAME_A); /* fall back to additional action button's down/up action */ if (!action) - action = pdf_dict_getsa(ctx, pdf_dict_gets(ctx, dict, "AA"), "U", "D"); + action = pdf_dict_geta(ctx, pdf_dict_get(ctx, dict, PDF_NAME_AA), PDF_NAME_U, PDF_NAME_D); ld = pdf_parse_action(ctx, doc, action); } @@ -423,56 +423,56 @@ pdf_transform_annot(fz_context *ctx, pdf_annot *annot) fz_annot_type pdf_annot_obj_type(fz_context *ctx, pdf_obj *obj) { - char *subtype = pdf_to_name(ctx, pdf_dict_gets(ctx, obj, "Subtype")); - if (!strcmp(subtype, "Text")) + pdf_obj *subtype = pdf_dict_get(ctx, obj, PDF_NAME_Subtype); + if (pdf_name_eq(ctx, PDF_NAME_Text, subtype)) return FZ_ANNOT_TEXT; - else if (!strcmp(subtype, "Link")) + else if (pdf_name_eq(ctx, PDF_NAME_Link, subtype)) return FZ_ANNOT_LINK; - else if (!strcmp(subtype, "FreeText")) + else if (pdf_name_eq(ctx, PDF_NAME_FreeText, subtype)) return FZ_ANNOT_FREETEXT; - else if (!strcmp(subtype, "Line")) + else if (pdf_name_eq(ctx, PDF_NAME_Line, subtype)) return FZ_ANNOT_LINE; - else if (!strcmp(subtype, "Square")) + else if (pdf_name_eq(ctx, PDF_NAME_Square, subtype)) return FZ_ANNOT_SQUARE; - else if (!strcmp(subtype, "Circle")) + else if (pdf_name_eq(ctx, PDF_NAME_Circle, subtype)) return FZ_ANNOT_CIRCLE; - else if (!strcmp(subtype, "Polygon")) + else if (pdf_name_eq(ctx, PDF_NAME_Polygon, subtype)) return FZ_ANNOT_POLYGON; - else if (!strcmp(subtype, "PolyLine")) + else if (pdf_name_eq(ctx, PDF_NAME_PolyLine, subtype)) return FZ_ANNOT_POLYLINE; - else if (!strcmp(subtype, "Highlight")) + else if (pdf_name_eq(ctx, PDF_NAME_Highlight, subtype)) return FZ_ANNOT_HIGHLIGHT; - else if (!strcmp(subtype, "Underline")) + else if (pdf_name_eq(ctx, PDF_NAME_Underline, subtype)) return FZ_ANNOT_UNDERLINE; - else if (!strcmp(subtype, "Squiggly")) + else if (pdf_name_eq(ctx, PDF_NAME_Squiggly, subtype)) return FZ_ANNOT_SQUIGGLY; - else if (!strcmp(subtype, "StrikeOut")) + else if (pdf_name_eq(ctx, PDF_NAME_StrikeOut, subtype)) return FZ_ANNOT_STRIKEOUT; - else if (!strcmp(subtype, "Stamp")) + else if (pdf_name_eq(ctx, PDF_NAME_Stamp, subtype)) return FZ_ANNOT_STAMP; - else if (!strcmp(subtype, "Caret")) + else if (pdf_name_eq(ctx, PDF_NAME_Caret, subtype)) return FZ_ANNOT_CARET; - else if (!strcmp(subtype, "Ink")) + else if (pdf_name_eq(ctx, PDF_NAME_Ink, subtype)) return FZ_ANNOT_INK; - else if (!strcmp(subtype, "Popup")) + else if (pdf_name_eq(ctx, PDF_NAME_Popup, subtype)) return FZ_ANNOT_POPUP; - else if (!strcmp(subtype, "FileAttachment")) + else if (pdf_name_eq(ctx, PDF_NAME_FileAttachment, subtype)) return FZ_ANNOT_FILEATTACHMENT; - else if (!strcmp(subtype, "Sound")) + else if (pdf_name_eq(ctx, PDF_NAME_Sound, subtype)) return FZ_ANNOT_SOUND; - else if (!strcmp(subtype, "Movie")) + else if (pdf_name_eq(ctx, PDF_NAME_Movie, subtype)) return FZ_ANNOT_MOVIE; - else if (!strcmp(subtype, "Widget")) + else if (pdf_name_eq(ctx, PDF_NAME_Widget, subtype)) return FZ_ANNOT_WIDGET; - else if (!strcmp(subtype, "Screen")) + else if (pdf_name_eq(ctx, PDF_NAME_Screen, subtype)) return FZ_ANNOT_SCREEN; - else if (!strcmp(subtype, "PrinterMark")) + else if (pdf_name_eq(ctx, PDF_NAME_PrinterMark, subtype)) return FZ_ANNOT_PRINTERMARK; - else if (!strcmp(subtype, "TrapNet")) + else if (pdf_name_eq(ctx, PDF_NAME_TrapNet, subtype)) return FZ_ANNOT_TRAPNET; - else if (!strcmp(subtype, "Watermark")) + else if (pdf_name_eq(ctx, PDF_NAME_Watermark, subtype)) return FZ_ANNOT_WATERMARK; - else if (!strcmp(subtype, "3D")) + else if (pdf_name_eq(ctx, PDF_NAME_3D, subtype)) return FZ_ANNOT_3D; else return -1; @@ -538,9 +538,9 @@ pdf_load_annots(fz_context *ctx, pdf_document *doc, pdf_page *page, pdf_obj *ann doc->update_appearance(ctx, doc, annot); obj = annot->obj; - rect = pdf_dict_gets(ctx, obj, "Rect"); - ap = pdf_dict_gets(ctx, obj, "AP"); - as = pdf_dict_gets(ctx, obj, "AS"); + rect = pdf_dict_get(ctx, obj, PDF_NAME_Rect); + ap = pdf_dict_get(ctx, obj, PDF_NAME_AP); + as = pdf_dict_get(ctx, obj, PDF_NAME_AS); /* We only collect annotations with an appearance * stream into this list, so remove any that don't @@ -553,11 +553,11 @@ pdf_load_annots(fz_context *ctx, pdf_document *doc, pdf_page *page, pdf_obj *ann && hp->gen == pdf_to_gen(ctx, obj) && (hp->state & HOTSPOT_POINTER_DOWN)) { - n = pdf_dict_gets(ctx, ap, "D"); /* down state */ + n = pdf_dict_get(ctx, ap, PDF_NAME_D); /* down state */ } if (n == NULL) - n = pdf_dict_gets(ctx, ap, "N"); /* normal state */ + n = pdf_dict_get(ctx, ap, PDF_NAME_N); /* normal state */ /* lookup current state in sub-dictionary */ if (!pdf_is_stream(ctx, doc, pdf_to_num(ctx, n), pdf_to_gen(ctx, n))) diff --git a/source/pdf/pdf-appearance.c b/source/pdf/pdf-appearance.c index 52dfba0b..ce533cf4 100644 --- a/source/pdf/pdf-appearance.c +++ b/source/pdf/pdf-appearance.c @@ -164,7 +164,7 @@ static void get_font_info(fz_context *ctx, pdf_document *doc, pdf_obj *dr, char if (font_rec->da_rec.font_name == NULL) fz_throw(ctx, FZ_ERROR_GENERIC, "No font name in default appearance"); - font_rec->font = font = pdf_load_font(ctx, doc, dr, pdf_dict_gets(ctx, pdf_dict_gets(ctx, dr, "Font"), font_rec->da_rec.font_name), 0); + font_rec->font = font = pdf_load_font(ctx, doc, dr, pdf_dict_gets(ctx, pdf_dict_get(ctx, dr, PDF_NAME_Font), font_rec->da_rec.font_name), 0); font_rec->lineheight = 1.0; if (font && font->ascent != 0.0f && font->descent != 0.0f) font_rec->lineheight = (font->ascent - font->descent) / 1000.0; @@ -179,13 +179,13 @@ static void font_info_fin(fz_context *ctx, font_info *font_rec) static void get_text_widget_info(fz_context *ctx, pdf_document *doc, pdf_obj *widget, text_widget_info *info) { - char *da = pdf_to_str_buf(ctx, pdf_get_inheritable(ctx, doc, widget, "DA")); + char *da = pdf_to_str_buf(ctx, pdf_get_inheritable(ctx, doc, widget, PDF_NAME_DA)); int ff = pdf_get_field_flags(ctx, doc, widget); - pdf_obj *ml = pdf_get_inheritable(ctx, doc, widget, "MaxLen"); + pdf_obj *ml = pdf_get_inheritable(ctx, doc, widget, PDF_NAME_MaxLen); - info->dr = pdf_get_inheritable(ctx, doc, widget, "DR"); - info->col = pdf_dict_getp(ctx, widget, "MK/BG"); - info->q = pdf_to_int(ctx, pdf_get_inheritable(ctx, doc, widget, "Q")); + info->dr = pdf_get_inheritable(ctx, doc, widget, PDF_NAME_DR); + info->col = pdf_dict_getl(ctx, widget, PDF_NAME_MK, PDF_NAME_BG, NULL); + info->q = pdf_to_int(ctx, pdf_get_inheritable(ctx, doc, widget, PDF_NAME_Q)); info->multiline = (ff & Ff_Multiline) != 0; info->comb = (ff & (Ff_Multiline|Ff_Password|Ff_FileSelect|Ff_Comb)) == Ff_Comb; @@ -784,7 +784,7 @@ static int get_matrix(fz_context *ctx, pdf_document *doc, pdf_xobject *form, int if (found) { fz_rect bbox; - pdf_to_rect(ctx, pdf_dict_gets(ctx, form->contents, "BBox"), &bbox); + pdf_to_rect(ctx, pdf_dict_get(ctx, form->contents, PDF_NAME_BBox), &bbox); switch (q) { @@ -928,7 +928,6 @@ static pdf_xobject *load_or_create_form(fz_context *ctx, pdf_document *doc, pdf_ int rot; pdf_obj *formobj = NULL; pdf_xobject *form = NULL; - char *dn = "N"; fz_buffer *fzbuf = NULL; int create_form = 0; @@ -937,25 +936,25 @@ static pdf_xobject *load_or_create_form(fz_context *ctx, pdf_document *doc, pdf_ fz_var(fzbuf); fz_try(ctx) { - rot = pdf_to_int(ctx, pdf_dict_getp(ctx, obj, "MK/R")); - pdf_to_rect(ctx, pdf_dict_gets(ctx, obj, "Rect"), rect); + rot = pdf_to_int(ctx, pdf_dict_getl(ctx, obj, PDF_NAME_MK, PDF_NAME_R, NULL)); + pdf_to_rect(ctx, pdf_dict_get(ctx, obj, PDF_NAME_Rect), rect); rect->x1 -= rect->x0; rect->y1 -= rect->y0; rect->x0 = rect->y0 = 0; account_for_rot(rect, &mat, rot); - ap = pdf_dict_gets(ctx, obj, "AP"); + ap = pdf_dict_get(ctx, obj, PDF_NAME_AP); if (ap == NULL) { ap = pdf_new_dict(ctx, doc, 1); - pdf_dict_puts_drop(ctx, obj, "AP", ap); + pdf_dict_put_drop(ctx, obj, PDF_NAME_AP, ap); } - formobj = pdf_dict_gets(ctx, ap, dn); + formobj = pdf_dict_get(ctx, ap, PDF_NAME_N); if (formobj == NULL) { formobj = pdf_new_xobject(ctx, doc, rect, &mat); - pdf_dict_puts_drop(ctx, ap, dn, formobj); + pdf_dict_put_drop(ctx, ap, PDF_NAME_N, formobj); create_form = 1; } @@ -966,7 +965,7 @@ static pdf_xobject *load_or_create_form(fz_context *ctx, pdf_document *doc, pdf_ pdf_update_xobject_contents(ctx, doc, form, fzbuf); } - copy_resources(ctx, form->resources, pdf_get_inheritable(ctx, doc, obj, "DR")); + copy_resources(ctx, form->resources, pdf_get_inheritable(ctx, doc, obj, PDF_NAME_DR)); } fz_always(ctx) { @@ -1070,15 +1069,15 @@ static void update_marked_content(fz_context *ctx, pdf_document *doc, pdf_xobjec static int get_border_style(fz_context *ctx, pdf_obj *obj) { - char *sname = pdf_to_name(ctx, pdf_dict_getp(ctx, obj, "BS/S")); + pdf_obj *sname = pdf_dict_getl(ctx, obj, PDF_NAME_BS, PDF_NAME_S, NULL); - if (!strcmp(sname, "D")) + if (pdf_name_eq(ctx, PDF_NAME_D, sname)) return BS_Dashed; - else if (!strcmp(sname, "B")) + else if (pdf_name_eq(ctx, PDF_NAME_B, sname)) return BS_Beveled; - else if (!strcmp(sname, "I")) + else if (pdf_name_eq(ctx, PDF_NAME_I, sname)) return BS_Inset; - else if (!strcmp(sname, "U")) + else if (pdf_name_eq(ctx, PDF_NAME_U, sname)) return BS_Underline; else return BS_Solid; @@ -1086,7 +1085,7 @@ static int get_border_style(fz_context *ctx, pdf_obj *obj) static float get_border_width(fz_context *ctx, pdf_obj *obj) { - float w = pdf_to_real(ctx, pdf_dict_getp(ctx, obj, "BS/W")); + float w = pdf_to_real(ctx, pdf_dict_getl(ctx, obj, PDF_NAME_BS, PDF_NAME_W, NULL)); return w == 0.0 ? 1.0 : w; } @@ -1155,7 +1154,7 @@ void pdf_update_combobox_appearance(fz_context *ctx, pdf_document *doc, pdf_obj { get_text_widget_info(ctx, doc, obj, &info); - val = pdf_get_inheritable(ctx, doc, obj, "V"); + val = pdf_get_inheritable(ctx, doc, obj, PDF_NAME_V); if (pdf_is_array(ctx, val)) val = pdf_array_get(ctx, val, 0); @@ -1204,7 +1203,7 @@ void pdf_update_pushbutton_appearance(fz_context *ctx, pdf_document *doc, pdf_ob { form = load_or_create_form(ctx, doc, obj, &rect); fzbuf = fz_new_buffer(ctx, 0); - tobj = pdf_dict_getp(ctx, obj, "MK/BG"); + tobj = pdf_dict_getl(ctx, obj, PDF_NAME_MK, PDF_NAME_BG, NULL); if (pdf_is_array(ctx, tobj)) { fzbuf_print_color(ctx, fzbuf, tobj, 0, 0.0); @@ -1243,7 +1242,7 @@ void pdf_update_pushbutton_appearance(fz_context *ctx, pdf_document *doc, pdf_ob fz_buffer_printf(ctx, fzbuf, fmt_f); } - tobj = pdf_dict_getp(ctx, obj, "MK/BC"); + tobj = pdf_dict_getl(ctx, obj, PDF_NAME_MK, PDF_NAME_BC, NULL); if (tobj) { fzbuf_print_color(ctx, fzbuf, tobj, 1, 0.0); @@ -1254,13 +1253,13 @@ void pdf_update_pushbutton_appearance(fz_context *ctx, pdf_document *doc, pdf_ob fz_buffer_printf(ctx, fzbuf, fmt_s); } - tobj = pdf_dict_getp(ctx, obj, "MK/CA"); + tobj = pdf_dict_getl(ctx, obj, PDF_NAME_MK, PDF_NAME_CA, NULL); if (tobj) { fz_rect clip = rect; fz_rect bounds; fz_matrix mat; - char *da = pdf_to_str_buf(ctx, pdf_get_inheritable(ctx, doc, obj, "DA")); + char *da = pdf_to_str_buf(ctx, pdf_get_inheritable(ctx, doc, obj, PDF_NAME_DA)); char *text = pdf_to_str_buf(ctx, tobj); clip.x0 += btotal; @@ -1330,7 +1329,7 @@ void pdf_update_text_markup_appearance(fz_context *ctx, pdf_document *doc, pdf_a static void update_rect(fz_context *ctx, pdf_annot *annot) { - pdf_to_rect(ctx, pdf_dict_gets(ctx, annot->obj, "Rect"), &annot->rect); + pdf_to_rect(ctx, pdf_dict_get(ctx, annot->obj, PDF_NAME_Rect), &annot->rect); annot->pagerect = annot->rect; fz_transform_rect(&annot->pagerect, &annot->page->ctm); } @@ -1354,27 +1353,27 @@ void pdf_set_annot_appearance(fz_context *ctx, pdf_document *doc, pdf_annot *ann fz_transform_rect(&trect, &ctm); - pdf_dict_puts_drop(ctx, obj, "Rect", pdf_new_rect(ctx, doc, &trect)); + pdf_dict_put_drop(ctx, obj, PDF_NAME_Rect, pdf_new_rect(ctx, doc, &trect)); /* See if there is a current normal appearance */ - ap_obj = pdf_dict_getp(ctx, obj, "AP/N"); + ap_obj = pdf_dict_getl(ctx, obj, PDF_NAME_AP, PDF_NAME_N, NULL); if (!pdf_is_stream(ctx, doc, pdf_to_num(ctx, ap_obj), pdf_to_gen(ctx, ap_obj))) ap_obj = NULL; if (ap_obj == NULL) { ap_obj = pdf_new_xobject(ctx, doc, &trect, &mat); - pdf_dict_putp_drop(ctx, obj, "AP/N", ap_obj); + pdf_dict_putl_drop(ctx, obj, ap_obj, PDF_NAME_AP, PDF_NAME_N, NULL); } else { pdf_xref_ensure_incremental_object(ctx, doc, pdf_to_num(ctx, ap_obj)); /* Update bounding box and matrix in reused xobject obj */ - pdf_dict_puts_drop(ctx, ap_obj, "BBox", pdf_new_rect(ctx, doc, &trect)); - pdf_dict_puts_drop(ctx, ap_obj, "Matrix", pdf_new_matrix(ctx, doc, &mat)); + pdf_dict_put_drop(ctx, ap_obj, PDF_NAME_BBox, pdf_new_rect(ctx, doc, &trect)); + pdf_dict_put_drop(ctx, ap_obj, PDF_NAME_Matrix, pdf_new_matrix(ctx, doc, &mat)); } - dev = pdf_new_pdf_device(ctx, doc, ap_obj, pdf_dict_gets(ctx, ap_obj, "Resources"), &mat, NULL); + dev = pdf_new_pdf_device(ctx, doc, ap_obj, pdf_dict_get(ctx, ap_obj, PDF_NAME_Resources), &mat, NULL); fz_run_display_list(ctx, disp_list, dev, &ctm, &fz_infinite_rect, NULL); fz_drop_device(ctx, dev); @@ -1403,7 +1402,7 @@ void pdf_set_annot_appearance(fz_context *ctx, pdf_document *doc, pdf_annot *ann static fz_point * quadpoints(fz_context *ctx, pdf_document *doc, pdf_obj *annot, int *nout) { - pdf_obj *quad = pdf_dict_gets(ctx, annot, "QuadPoints"); + pdf_obj *quad = pdf_dict_get(ctx, annot, PDF_NAME_QuadPoints); fz_point *qp = NULL; int i, n; @@ -1568,7 +1567,7 @@ void pdf_update_ink_appearance(fz_context *ctx, pdf_document *doc, pdf_annot *an int n, m, i, j; int empty = 1; - cs = pdf_to_color(ctx, doc, pdf_dict_gets(ctx, annot->obj, "C"), color); + cs = pdf_to_color(ctx, doc, pdf_dict_get(ctx, annot->obj, PDF_NAME_C), color); if (!cs) { cs = fz_device_rgb(ctx); @@ -1577,11 +1576,11 @@ void pdf_update_ink_appearance(fz_context *ctx, pdf_document *doc, pdf_annot *an color[2] = 0.0f; } - width = pdf_to_real(ctx, pdf_dict_gets(ctx, pdf_dict_gets(ctx, annot->obj, "BS"), "W")); + width = pdf_to_real(ctx, pdf_dict_get(ctx, pdf_dict_get(ctx, annot->obj, PDF_NAME_BS), PDF_NAME_W)); if (width == 0.0f) width = 1.0f; - list = pdf_dict_gets(ctx, annot->obj, "InkList"); + list = pdf_dict_get(ctx, annot->obj, PDF_NAME_InkList); n = pdf_array_len(ctx, list); @@ -1857,7 +1856,7 @@ void pdf_update_text_annot_appearance(fz_context *ctx, pdf_document *doc, pdf_an fz_rect bounds; fz_matrix tm; - pdf_to_rect(ctx, pdf_dict_gets(ctx, annot->obj, "Rect"), &rect); + pdf_to_rect(ctx, pdf_dict_get(ctx, annot->obj, PDF_NAME_Rect), &rect); dlist = fz_new_display_list(ctx); dev = fz_new_list_device(ctx, dlist); stroke = fz_new_stroke_state(ctx); @@ -1907,7 +1906,7 @@ void pdf_update_free_text_annot_appearance(fz_context *ctx, pdf_document *doc, p { const fz_matrix *page_ctm = &annot->page->ctm; pdf_obj *obj = annot->obj; - pdf_obj *dr = pdf_dict_getp(ctx, annot->page->me, "Resources"); + pdf_obj *dr = pdf_dict_get(ctx, annot->page->me, PDF_NAME_Resources); fz_display_list *dlist = NULL; fz_device *dev = NULL; font_info font_rec; @@ -1926,8 +1925,8 @@ void pdf_update_free_text_annot_appearance(fz_context *ctx, pdf_document *doc, p fz_var(cs); fz_try(ctx) { - char *contents = pdf_to_str_buf(ctx, pdf_dict_gets(ctx, obj, "Contents")); - char *da = pdf_to_str_buf(ctx, pdf_dict_gets(ctx, obj, "DA")); + char *contents = pdf_to_str_buf(ctx, pdf_dict_get(ctx, obj, PDF_NAME_Contents)); + char *da = pdf_to_str_buf(ctx, pdf_dict_get(ctx, obj, PDF_NAME_DA)); fz_rect rect = annot->rect; fz_point pos; @@ -2029,14 +2028,14 @@ static void draw_logo(fz_context *ctx, fz_path *path) static void insert_signature_appearance_layers(fz_context *ctx, pdf_document *doc, pdf_annot *annot) { - pdf_obj *ap = pdf_dict_getp(ctx, annot->obj, "AP/N"); + pdf_obj *ap = pdf_dict_getl(ctx, annot->obj, PDF_NAME_AP, PDF_NAME_N, NULL); pdf_obj *main_ap = NULL; pdf_obj *frm = NULL; pdf_obj *n0 = NULL; fz_rect bbox; fz_buffer *fzbuf = NULL; - pdf_to_rect(ctx, pdf_dict_gets(ctx, ap, "BBox"), &bbox); + pdf_to_rect(ctx, pdf_dict_get(ctx, ap, PDF_NAME_BBox), &bbox); fz_var(main_ap); fz_var(frm); @@ -2048,15 +2047,15 @@ static void insert_signature_appearance_layers(fz_context *ctx, pdf_document *do frm = pdf_new_xobject(ctx, doc, &bbox, &fz_identity); n0 = pdf_new_xobject(ctx, doc, &bbox, &fz_identity); - pdf_dict_putp(ctx, main_ap, "Resources/XObject/FRM", frm); + pdf_dict_putl(ctx, main_ap, frm, PDF_NAME_Resources, PDF_NAME_XObject, PDF_NAME_FRM, NULL); fzbuf = fz_new_buffer(ctx, 8); fz_buffer_printf(ctx, fzbuf, "/FRM Do"); pdf_update_stream(ctx, doc, main_ap, fzbuf, 0); fz_drop_buffer(ctx, fzbuf); fzbuf = NULL; - pdf_dict_putp(ctx, frm, "Resources/XObject/n0", n0); - pdf_dict_putp(ctx, frm, "Resources/XObject/n2", ap); + pdf_dict_putl(ctx, frm, n0, PDF_NAME_Resources, PDF_NAME_XObject, PDF_NAME_n0, NULL); + pdf_dict_putl(ctx, frm, ap, PDF_NAME_Resources, PDF_NAME_XObject, PDF_NAME_n2, NULL); fzbuf = fz_new_buffer(ctx, 8); fz_buffer_printf(ctx, fzbuf, "q 1 0 0 1 0 0 cm /n0 Do Q q 1 0 0 1 0 0 cm /n2 Do Q"); pdf_update_stream(ctx, doc, frm, fzbuf, 0); @@ -2069,7 +2068,7 @@ static void insert_signature_appearance_layers(fz_context *ctx, pdf_document *do fz_drop_buffer(ctx, fzbuf); fzbuf = NULL; - pdf_dict_putp(ctx, annot->obj, "AP/N", main_ap); + pdf_dict_putl(ctx, annot->obj, main_ap, PDF_NAME_AP, PDF_NAME_N, NULL); } fz_always(ctx) { @@ -2091,7 +2090,7 @@ void pdf_set_signature_appearance(fz_context *ctx, pdf_document *doc, pdf_annot { const fz_matrix *page_ctm = &annot->page->ctm; pdf_obj *obj = annot->obj; - pdf_obj *dr = pdf_dict_getp(ctx, pdf_trailer(ctx, doc), "Root/AcroForm/DR"); + pdf_obj *dr = pdf_dict_getl(ctx, pdf_trailer(ctx, doc), PDF_NAME_Root, PDF_NAME_AcroForm, PDF_NAME_DR, NULL); fz_display_list *dlist = NULL; fz_device *dev = NULL; font_info font_rec; @@ -2101,7 +2100,7 @@ void pdf_set_signature_appearance(fz_context *ctx, pdf_document *doc, pdf_annot fz_buffer *fzbuf = NULL; if (!dr) - pdf_dict_putp_drop(ctx, pdf_trailer(ctx, doc), "Root/AcroForm/DR", pdf_new_dict(ctx, doc, 1)); + pdf_dict_putl_drop(ctx, pdf_trailer(ctx, doc), pdf_new_dict(ctx, doc, 1), PDF_NAME_Root, PDF_NAME_AcroForm, PDF_NAME_DR, NULL); memset(&font_rec, 0, sizeof(font_rec)); @@ -2113,7 +2112,7 @@ void pdf_set_signature_appearance(fz_context *ctx, pdf_document *doc, pdf_annot fz_var(fzbuf); fz_try(ctx) { - char *da = pdf_to_str_buf(ctx, pdf_dict_gets(ctx, obj, "DA")); + char *da = pdf_to_str_buf(ctx, pdf_dict_get(ctx, obj, PDF_NAME_DA)); fz_rect rect = annot->rect; fz_rect logo_bounds; fz_matrix logo_tm; @@ -2190,7 +2189,7 @@ void pdf_set_signature_appearance(fz_context *ctx, pdf_document *doc, pdf_annot void pdf_update_appearance(fz_context *ctx, pdf_document *doc, pdf_annot *annot) { pdf_obj *obj = annot->obj; - if (!pdf_dict_gets(ctx, obj, "AP") || pdf_obj_is_dirty(ctx, obj)) + if (!pdf_dict_get(ctx, obj, PDF_NAME_AP) || pdf_obj_is_dirty(ctx, obj)) { fz_annot_type type = pdf_annot_obj_type(ctx, obj); switch (type) @@ -2201,7 +2200,7 @@ void pdf_update_appearance(fz_context *ctx, pdf_document *doc, pdf_annot *annot) case PDF_WIDGET_TYPE_TEXT: { #if 0 - pdf_obj *formatting = pdf_dict_getp(ctx, obj, "AA/F"); + pdf_obj *formatting = pdf_dict_getl(ctx, obj, PDF_NAME_AA, PDF_NAME_F, NULL); if (formatting && doc->js) { /* Apply formatting */ diff --git a/source/pdf/pdf-clean.c b/source/pdf/pdf-clean.c index 399d9339..90de0444 100644 --- a/source/pdf/pdf-clean.c +++ b/source/pdf/pdf-clean.c @@ -23,7 +23,7 @@ pdf_clean_stream_object(fz_context *ctx, pdf_document *doc, pdf_obj *obj, pdf_ob { if (own_res) { - pdf_obj *r = pdf_dict_gets(ctx, obj, "Resources"); + pdf_obj *r = pdf_dict_get(ctx, obj, PDF_NAME_Resources); if (r) orig_res = r; } @@ -40,7 +40,7 @@ pdf_clean_stream_object(fz_context *ctx, pdf_document *doc, pdf_obj *obj, pdf_ob if (own_res) { ref = pdf_new_ref(ctx, doc, res); - pdf_dict_puts(ctx, obj, "Resources", ref); + pdf_dict_put(ctx, obj, PDF_NAME_Resources, ref); } } fz_always(ctx) @@ -74,14 +74,14 @@ pdf_clean_type3(fz_context *ctx, pdf_document *doc, pdf_obj *obj, pdf_obj *orig_ fz_try(ctx) { - res = pdf_dict_gets(ctx, obj, "Resources"); + res = pdf_dict_get(ctx, obj, PDF_NAME_Resources); if (res) orig_res = res; res = NULL; res = pdf_new_dict(ctx, doc, 1); - charprocs = pdf_dict_gets(ctx, obj, "CharProcs"); + charprocs = pdf_dict_get(ctx, obj, PDF_NAME_CharProcs); l = pdf_dict_len(ctx, charprocs); for (i = 0; i < l; i++) @@ -110,10 +110,10 @@ pdf_clean_type3(fz_context *ctx, pdf_document *doc, pdf_obj *obj, pdf_obj *orig_ } /* ProcSet - no cleaning possible. Inherit this from the old dict. */ - pdf_dict_puts(ctx, res, "ProcSet", pdf_dict_gets(ctx, orig_res, "ProcSet")); + pdf_dict_put(ctx, res, PDF_NAME_ProcSet, pdf_dict_get(ctx, orig_res, PDF_NAME_ProcSet)); ref = pdf_new_ref(ctx, doc, res); - pdf_dict_puts(ctx, obj, "Resources", ref); + pdf_dict_put(ctx, obj, PDF_NAME_Resources, ref); } fz_always(ctx) { @@ -166,8 +166,8 @@ void pdf_clean_page_contents(fz_context *ctx, pdf_document *doc, pdf_page *page, } else { - pdf_dict_dels(ctx, contents, "Filter"); - pdf_dict_dels(ctx, contents, "DecodeParms"); + pdf_dict_del(ctx, contents, PDF_NAME_Filter); + pdf_dict_del(ctx, contents, PDF_NAME_DecodeParms); } /* Now deal with resources. The spec allows for Type3 fonts and form @@ -176,7 +176,7 @@ void pdf_clean_page_contents(fz_context *ctx, pdf_document *doc, pdf_page *page, * conceivably cause changes in rendering, but we don't care. */ /* ExtGState */ - obj = pdf_dict_gets(ctx, res, "ExtGState"); + obj = pdf_dict_get(ctx, res, PDF_NAME_ExtGState); if (obj) { int i, l; @@ -184,11 +184,11 @@ void pdf_clean_page_contents(fz_context *ctx, pdf_document *doc, pdf_page *page, l = pdf_dict_len(ctx, obj); for (i = 0; i < l; i++) { - pdf_obj *o = pdf_dict_gets(ctx, pdf_dict_get_val(ctx, obj, i), "SMask"); + pdf_obj *o = pdf_dict_get(ctx, pdf_dict_get_val(ctx, obj, i), PDF_NAME_SMask); if (!o) continue; - o = pdf_dict_gets(ctx, o, "G"); + o = pdf_dict_get(ctx, o, PDF_NAME_G); if (!o) continue; @@ -200,7 +200,7 @@ void pdf_clean_page_contents(fz_context *ctx, pdf_document *doc, pdf_page *page, /* ColorSpace - no cleaning possible */ /* Pattern */ - obj = pdf_dict_gets(ctx, res, "Pattern"); + obj = pdf_dict_get(ctx, res, PDF_NAME_Pattern); if (obj) { int i, l; @@ -212,7 +212,7 @@ void pdf_clean_page_contents(fz_context *ctx, pdf_document *doc, pdf_page *page, if (!pat) continue; - if (pdf_to_int(ctx, pdf_dict_gets(ctx, pat, "PatternType")) == 1) + if (pdf_to_int(ctx, pdf_dict_get(ctx, pat, PDF_NAME_PatternType)) == 1) pdf_clean_stream_object(ctx, doc, pat, page->resources, cookie, 0); } } @@ -220,7 +220,7 @@ void pdf_clean_page_contents(fz_context *ctx, pdf_document *doc, pdf_page *page, /* Shading - no cleaning possible */ /* XObject */ - obj = pdf_dict_gets(ctx, res, "XObject"); + obj = pdf_dict_get(ctx, res, PDF_NAME_XObject); if (obj) { int i, l; @@ -230,7 +230,7 @@ void pdf_clean_page_contents(fz_context *ctx, pdf_document *doc, pdf_page *page, { pdf_obj *xobj = pdf_dict_get_val(ctx, obj, i); - if (strcmp(pdf_to_name(ctx, pdf_dict_gets(ctx, xobj, "Subtype")), "Form")) + if (!pdf_name_eq(ctx, PDF_NAME_Form, pdf_dict_get(ctx, xobj, PDF_NAME_Subtype))) continue; pdf_clean_stream_object(ctx, doc, xobj, page->resources, cookie, 1); @@ -238,7 +238,7 @@ void pdf_clean_page_contents(fz_context *ctx, pdf_document *doc, pdf_page *page, } /* Font */ - obj = pdf_dict_gets(ctx, res, "Font"); + obj = pdf_dict_get(ctx, res, PDF_NAME_Font); if (obj) { int i, l; @@ -248,7 +248,7 @@ void pdf_clean_page_contents(fz_context *ctx, pdf_document *doc, pdf_page *page, { pdf_obj *o = pdf_dict_get_val(ctx, obj, i); - if (!strcmp(pdf_to_name(ctx, pdf_dict_gets(ctx, o, "Subtype")), "Type3")) + if (pdf_name_eq(ctx, PDF_NAME_Type3, pdf_dict_get(ctx, o, PDF_NAME_Subtype))) { pdf_clean_type3(ctx, doc, o, page->resources, cookie); } @@ -256,9 +256,9 @@ void pdf_clean_page_contents(fz_context *ctx, pdf_document *doc, pdf_page *page, } /* ProcSet - no cleaning possible. Inherit this from the old dict. */ - obj = pdf_dict_gets(ctx, page->resources, "ProcSet"); + obj = pdf_dict_get(ctx, page->resources, PDF_NAME_ProcSet); if (obj) - pdf_dict_puts(ctx, res, "ProcSet", obj); + pdf_dict_put(ctx, res, PDF_NAME_ProcSet, obj); /* Properties - no cleaning possible. */ @@ -269,7 +269,7 @@ void pdf_clean_page_contents(fz_context *ctx, pdf_document *doc, pdf_page *page, pdf_drop_obj(ctx, page->resources); ref = pdf_new_ref(ctx, doc, res); page->resources = pdf_keep_obj(ctx, ref); - pdf_dict_puts(ctx, page->me, "Resources", ref); + pdf_dict_put(ctx, page->me, PDF_NAME_Resources, ref); } fz_always(ctx) { diff --git a/source/pdf/pdf-cmap-load.c b/source/pdf/pdf-cmap-load.c index 46338539..159c4e6f 100644 --- a/source/pdf/pdf-cmap-load.c +++ b/source/pdf/pdf-cmap-load.c @@ -49,10 +49,10 @@ pdf_load_embedded_cmap(fz_context *ctx, pdf_document *doc, pdf_obj *stmobj) fz_drop_stream(ctx, file); file = NULL; - wmode = pdf_dict_gets(ctx, stmobj, "WMode"); + wmode = pdf_dict_get(ctx, stmobj, PDF_NAME_WMode); if (pdf_is_int(ctx, wmode)) pdf_set_cmap_wmode(ctx, cmap, pdf_to_int(ctx, wmode)); - obj = pdf_dict_gets(ctx, stmobj, "UseCMap"); + obj = pdf_dict_get(ctx, stmobj, PDF_NAME_UseCMap); if (pdf_is_name(ctx, obj)) { usecmap = pdf_load_system_cmap(ctx, pdf_to_name(ctx, obj)); diff --git a/source/pdf/pdf-colorspace.c b/source/pdf/pdf-colorspace.c index a58dc961..321b224b 100644 --- a/source/pdf/pdf-colorspace.c +++ b/source/pdf/pdf-colorspace.c @@ -8,8 +8,8 @@ load_icc_based(fz_context *ctx, pdf_document *doc, pdf_obj *dict) int n; pdf_obj *obj; - n = pdf_to_int(ctx, pdf_dict_gets(ctx, dict, "N")); - obj = pdf_dict_gets(ctx, dict, "Alternate"); + n = pdf_to_int(ctx, pdf_dict_get(ctx, dict, PDF_NAME_N)); + obj = pdf_dict_get(ctx, dict, PDF_NAME_Alternate); if (obj) { @@ -251,20 +251,19 @@ pdf_load_colorspace_imp(fz_context *ctx, pdf_document *doc, pdf_obj *obj) if (pdf_is_name(ctx, obj)) { - const char *str = pdf_to_name(ctx, obj); - if (!strcmp(str, "Pattern")) + if (pdf_name_eq(ctx, obj, PDF_NAME_Pattern)) return fz_device_gray(ctx); - else if (!strcmp(str, "G")) + else if (pdf_name_eq(ctx, obj, PDF_NAME_G)) return fz_device_gray(ctx); - else if (!strcmp(str, "RGB")) + else if (pdf_name_eq(ctx, obj, PDF_NAME_RGB)) return fz_device_rgb(ctx); - else if (!strcmp(str, "CMYK")) + else if (pdf_name_eq(ctx, obj, PDF_NAME_CMYK)) return fz_device_cmyk(ctx); - else if (!strcmp(str, "DeviceGray")) + else if (pdf_name_eq(ctx, obj, PDF_NAME_DeviceGray)) return fz_device_gray(ctx); - else if (!strcmp(str, "DeviceRGB")) + else if (pdf_name_eq(ctx, obj, PDF_NAME_DeviceRGB)) return fz_device_rgb(ctx); - else if (!strcmp(str, "DeviceCMYK")) + else if (pdf_name_eq(ctx, obj, PDF_NAME_DeviceCMYK)) return fz_device_cmyk(ctx); else fz_throw(ctx, FZ_ERROR_GENERIC, "unknown colorspace: %s", pdf_to_name(ctx, obj)); @@ -273,30 +272,29 @@ pdf_load_colorspace_imp(fz_context *ctx, pdf_document *doc, pdf_obj *obj) else if (pdf_is_array(ctx, obj)) { pdf_obj *name = pdf_array_get(ctx, obj, 0); - const char *str = pdf_to_name(ctx, name); if (pdf_is_name(ctx, name)) { /* load base colorspace instead */ - if (!strcmp(str, "G")) + if (pdf_name_eq(ctx, name, PDF_NAME_G)) return fz_device_gray(ctx); - else if (!strcmp(str, "RGB")) + else if (pdf_name_eq(ctx, name, PDF_NAME_RGB)) return fz_device_rgb(ctx); - else if (!strcmp(str, "CMYK")) + else if (pdf_name_eq(ctx, name, PDF_NAME_CMYK)) return fz_device_cmyk(ctx); - else if (!strcmp(str, "DeviceGray")) + else if (pdf_name_eq(ctx, name, PDF_NAME_DeviceGray)) return fz_device_gray(ctx); - else if (!strcmp(str, "DeviceRGB")) + else if (pdf_name_eq(ctx, name, PDF_NAME_DeviceRGB)) return fz_device_rgb(ctx); - else if (!strcmp(str, "DeviceCMYK")) + else if (pdf_name_eq(ctx, name, PDF_NAME_DeviceCMYK)) return fz_device_cmyk(ctx); - else if (!strcmp(str, "CalGray")) + else if (pdf_name_eq(ctx, name, PDF_NAME_CalGray)) return fz_device_gray(ctx); - else if (!strcmp(str, "CalRGB")) + else if (pdf_name_eq(ctx, name, PDF_NAME_CalRGB)) return fz_device_rgb(ctx); - else if (!strcmp(str, "CalCMYK")) + else if (pdf_name_eq(ctx, name, PDF_NAME_CalCMYK)) return fz_device_cmyk(ctx); - else if (!strcmp(str, "Lab")) + else if (pdf_name_eq(ctx, name, PDF_NAME_Lab)) return fz_device_lab; else { @@ -304,20 +302,20 @@ pdf_load_colorspace_imp(fz_context *ctx, pdf_document *doc, pdf_obj *obj) fz_try(ctx) { pdf_mark_obj(ctx, obj); - if (!strcmp(str, "ICCBased")) + if (pdf_name_eq(ctx, name, PDF_NAME_ICCBased)) cs = load_icc_based(ctx, doc, pdf_array_get(ctx, obj, 1)); - else if (!strcmp(str, "Indexed")) + else if (pdf_name_eq(ctx, name, PDF_NAME_Indexed)) cs = load_indexed(ctx, doc, obj); - else if (!strcmp(str, "I")) + else if (pdf_name_eq(ctx, name, PDF_NAME_I)) cs = load_indexed(ctx, doc, obj); - else if (!strcmp(str, "Separation")) + else if (pdf_name_eq(ctx, name, PDF_NAME_Separation)) cs = load_separation(ctx, doc, obj); - else if (!strcmp(str, "DeviceN")) + else if (pdf_name_eq(ctx, name, PDF_NAME_DeviceN)) cs = load_separation(ctx, doc, obj); - else if (!strcmp(str, "Pattern")) + else if (pdf_name_eq(ctx, name, PDF_NAME_Pattern)) { pdf_obj *pobj; @@ -331,7 +329,7 @@ pdf_load_colorspace_imp(fz_context *ctx, pdf_document *doc, pdf_obj *obj) cs = pdf_load_colorspace(ctx, doc, pobj); } else - fz_throw(ctx, FZ_ERROR_GENERIC, "syntaxerror: unknown colorspace %s", str); + fz_throw(ctx, FZ_ERROR_GENERIC, "syntaxerror: unknown colorspace %s", pdf_to_name(ctx, name)); } fz_always(ctx) { diff --git a/source/pdf/pdf-crypt.c b/source/pdf/pdf-crypt.c index 4519657f..88e485ff 100644 --- a/source/pdf/pdf-crypt.c +++ b/source/pdf/pdf-crypt.c @@ -38,7 +38,7 @@ struct pdf_crypt_s unsigned char key[32]; /* decryption key generated from password */ }; -static void pdf_parse_crypt_filter(fz_context *ctx, pdf_crypt_filter *cf, pdf_crypt *crypt, char *name); +static void pdf_parse_crypt_filter(fz_context *ctx, pdf_crypt_filter *cf, pdf_crypt *crypt, pdf_obj *name); /* * Create crypt object for decrypting strings and streams @@ -55,20 +55,20 @@ pdf_new_crypt(fz_context *ctx, pdf_obj *dict, pdf_obj *id) /* Common to all security handlers (PDF 1.7 table 3.18) */ - obj = pdf_dict_gets(ctx, dict, "Filter"); + obj = pdf_dict_get(ctx, dict, PDF_NAME_Filter); if (!pdf_is_name(ctx, obj)) { pdf_drop_crypt(ctx, crypt); fz_throw(ctx, FZ_ERROR_GENERIC, "unspecified encryption handler"); } - if (strcmp(pdf_to_name(ctx, obj), "Standard") != 0) + if (!pdf_name_eq(ctx, PDF_NAME_Standard, obj) != 0) { pdf_drop_crypt(ctx, crypt); fz_throw(ctx, FZ_ERROR_GENERIC, "unknown encryption handler: '%s'", pdf_to_name(ctx, obj)); } crypt->v = 0; - obj = pdf_dict_gets(ctx, dict, "V"); + obj = pdf_dict_get(ctx, dict, PDF_NAME_V); if (pdf_is_int(ctx, obj)) crypt->v = pdf_to_int(ctx, obj); if (crypt->v != 1 && crypt->v != 2 && crypt->v != 4 && crypt->v != 5) @@ -79,7 +79,7 @@ pdf_new_crypt(fz_context *ctx, pdf_obj *dict, pdf_obj *id) /* Standard security handler (PDF 1.7 table 3.19) */ - obj = pdf_dict_gets(ctx, dict, "R"); + obj = pdf_dict_get(ctx, dict, PDF_NAME_R); if (pdf_is_int(ctx, obj)) crypt->r = pdf_to_int(ctx, obj); else if (crypt->v <= 4) @@ -104,7 +104,7 @@ pdf_new_crypt(fz_context *ctx, pdf_obj *dict, pdf_obj *id) fz_throw(ctx, FZ_ERROR_GENERIC, "unknown crypt revision %d", r); } - obj = pdf_dict_gets(ctx, dict, "O"); + obj = pdf_dict_get(ctx, dict, PDF_NAME_O); if (pdf_is_string(ctx, obj) && pdf_to_str_len(ctx, obj) == 32) memcpy(crypt->o, pdf_to_str_buf(ctx, obj), 32); /* /O and /U are supposed to be 48 bytes long for revision 5 and 6, they're often longer, though */ @@ -116,7 +116,7 @@ pdf_new_crypt(fz_context *ctx, pdf_obj *dict, pdf_obj *id) fz_throw(ctx, FZ_ERROR_GENERIC, "encryption dictionary missing owner password"); } - obj = pdf_dict_gets(ctx, dict, "U"); + obj = pdf_dict_get(ctx, dict, PDF_NAME_U); if (pdf_is_string(ctx, obj) && pdf_to_str_len(ctx, obj) == 32) memcpy(crypt->u, pdf_to_str_buf(ctx, obj), 32); /* /O and /U are supposed to be 48 bytes long for revision 5 and 6, they're often longer, though */ @@ -133,7 +133,7 @@ pdf_new_crypt(fz_context *ctx, pdf_obj *dict, pdf_obj *id) fz_throw(ctx, FZ_ERROR_GENERIC, "encryption dictionary missing user password"); } - obj = pdf_dict_gets(ctx, dict, "P"); + obj = pdf_dict_get(ctx, dict, PDF_NAME_P); if (pdf_is_int(ctx, obj)) crypt->p = pdf_to_int(ctx, obj); else @@ -144,7 +144,7 @@ pdf_new_crypt(fz_context *ctx, pdf_obj *dict, pdf_obj *id) if (crypt->r == 5 || crypt->r == 6) { - obj = pdf_dict_gets(ctx, dict, "OE"); + obj = pdf_dict_get(ctx, dict, PDF_NAME_OE); if (!pdf_is_string(ctx, obj) || pdf_to_str_len(ctx, obj) != 32) { pdf_drop_crypt(ctx, crypt); @@ -152,7 +152,7 @@ pdf_new_crypt(fz_context *ctx, pdf_obj *dict, pdf_obj *id) } memcpy(crypt->oe, pdf_to_str_buf(ctx, obj), 32); - obj = pdf_dict_gets(ctx, dict, "UE"); + obj = pdf_dict_get(ctx, dict, PDF_NAME_UE); if (!pdf_is_string(ctx, obj) || pdf_to_str_len(ctx, obj) != 32) { pdf_drop_crypt(ctx, crypt); @@ -162,7 +162,7 @@ pdf_new_crypt(fz_context *ctx, pdf_obj *dict, pdf_obj *id) } crypt->encrypt_metadata = 1; - obj = pdf_dict_gets(ctx, dict, "EncryptMetadata"); + obj = pdf_dict_get(ctx, dict, PDF_NAME_EncryptMetadata); if (pdf_is_bool(ctx, obj)) crypt->encrypt_metadata = pdf_to_bool(ctx, obj); @@ -182,7 +182,7 @@ pdf_new_crypt(fz_context *ctx, pdf_obj *dict, pdf_obj *id) crypt->length = 40; if (crypt->v == 2 || crypt->v == 4) { - obj = pdf_dict_gets(ctx, dict, "Length"); + obj = pdf_dict_get(ctx, dict, PDF_NAME_Length); if (pdf_is_int(ctx, obj)) crypt->length = pdf_to_int(ctx, obj); @@ -222,7 +222,7 @@ pdf_new_crypt(fz_context *ctx, pdf_obj *dict, pdf_obj *id) crypt->strf.method = PDF_CRYPT_NONE; crypt->strf.length = crypt->length; - obj = pdf_dict_gets(ctx, dict, "CF"); + obj = pdf_dict_get(ctx, dict, PDF_NAME_CF); if (pdf_is_dict(ctx, obj)) { crypt->cf = pdf_keep_obj(ctx, obj); @@ -234,13 +234,13 @@ pdf_new_crypt(fz_context *ctx, pdf_obj *dict, pdf_obj *id) fz_try(ctx) { - obj = pdf_dict_gets(ctx, dict, "StmF"); + obj = pdf_dict_get(ctx, dict, PDF_NAME_StmF); if (pdf_is_name(ctx, obj)) - pdf_parse_crypt_filter(ctx, &crypt->stmf, crypt, pdf_to_name(ctx, obj)); + pdf_parse_crypt_filter(ctx, &crypt->stmf, crypt, obj); - obj = pdf_dict_gets(ctx, dict, "StrF"); + obj = pdf_dict_get(ctx, dict, PDF_NAME_StrF); if (pdf_is_name(ctx, obj)) - pdf_parse_crypt_filter(ctx, &crypt->strf, crypt, pdf_to_name(ctx, obj)); + pdf_parse_crypt_filter(ctx, &crypt->strf, crypt, obj); } fz_catch(ctx) { @@ -269,12 +269,12 @@ pdf_drop_crypt(fz_context *ctx, pdf_crypt *crypt) */ static void -pdf_parse_crypt_filter(fz_context *ctx, pdf_crypt_filter *cf, pdf_crypt *crypt, char *name) +pdf_parse_crypt_filter(fz_context *ctx, pdf_crypt_filter *cf, pdf_crypt *crypt, pdf_obj *name) { pdf_obj *obj; pdf_obj *dict; - int is_identity = (strcmp(name, "Identity") == 0); - int is_stdcf = (!is_identity && (strcmp(name, "StdCF") == 0)); + int is_identity = (pdf_name_eq(ctx, name, PDF_NAME_Identity)); + int is_stdcf = (!is_identity && pdf_name_eq(ctx, name, PDF_NAME_StdCF)); if (!is_identity && !is_stdcf) fz_throw(ctx, FZ_ERROR_GENERIC, "Crypt Filter not Identity or StdCF (%d %d R)", pdf_to_num(ctx, crypt->cf), pdf_to_gen(ctx, crypt->cf)); @@ -288,26 +288,26 @@ pdf_parse_crypt_filter(fz_context *ctx, pdf_crypt_filter *cf, pdf_crypt *crypt, return; } - dict = pdf_dict_gets(ctx, crypt->cf, name); + dict = pdf_dict_get(ctx, crypt->cf, name); if (!pdf_is_dict(ctx, dict)) fz_throw(ctx, FZ_ERROR_GENERIC, "cannot parse crypt filter (%d %d R)", pdf_to_num(ctx, crypt->cf), pdf_to_gen(ctx, crypt->cf)); - obj = pdf_dict_gets(ctx, dict, "CFM"); + obj = pdf_dict_get(ctx, dict, PDF_NAME_CFM); if (pdf_is_name(ctx, obj)) { - if (!strcmp(pdf_to_name(ctx, obj), "None")) + if (pdf_name_eq(ctx, PDF_NAME_None, obj)) cf->method = PDF_CRYPT_NONE; - else if (!strcmp(pdf_to_name(ctx, obj), "V2")) + else if (pdf_name_eq(ctx, PDF_NAME_V2, obj)) cf->method = PDF_CRYPT_RC4; - else if (!strcmp(pdf_to_name(ctx, obj), "AESV2")) + else if (pdf_name_eq(ctx, PDF_NAME_AESV2, obj)) cf->method = PDF_CRYPT_AESV2; - else if (!strcmp(pdf_to_name(ctx, obj), "AESV3")) + else if (pdf_name_eq(ctx, PDF_NAME_AESV3, obj)) cf->method = PDF_CRYPT_AESV3; else fz_warn(ctx, "unknown encryption method: %s", pdf_to_name(ctx, obj)); } - obj = pdf_dict_gets(ctx, dict, "Length"); + obj = pdf_dict_get(ctx, dict, PDF_NAME_Length); if (pdf_is_int(ctx, obj)) cf->length = pdf_to_int(ctx, obj); @@ -977,9 +977,9 @@ pdf_open_crypt(fz_context *ctx, fz_stream *chain, pdf_crypt *crypt, int num, int } fz_stream * -pdf_open_crypt_with_filter(fz_context *ctx, fz_stream *chain, pdf_crypt *crypt, char *name, int num, int gen) +pdf_open_crypt_with_filter(fz_context *ctx, fz_stream *chain, pdf_crypt *crypt, pdf_obj *name, int num, int gen) { - if (strcmp(name, "Identity")) + if (!pdf_name_eq(ctx, name, PDF_NAME_Identity)) { pdf_crypt_filter cf; pdf_parse_crypt_filter(ctx, &cf, crypt, name); diff --git a/source/pdf/pdf-device.c b/source/pdf/pdf-device.c index be477942..553810f6 100644 --- a/source/pdf/pdf-device.c +++ b/source/pdf/pdf-device.c @@ -200,20 +200,20 @@ send_image(fz_context *ctx, pdf_device *pdev, fz_image *image, int mask, int sma pdev->images[num].ref = NULL; /* Will be filled in later */ imobj = pdf_new_dict(ctx, doc, 3); - pdf_dict_puts_drop(ctx, imobj, "Type", pdf_new_name(ctx, doc, "XObject")); - pdf_dict_puts_drop(ctx, imobj, "Subtype", pdf_new_name(ctx, doc, "Image")); - pdf_dict_puts_drop(ctx, imobj, "Width", pdf_new_int(ctx, doc, image->w)); - pdf_dict_puts_drop(ctx, imobj, "Height", pdf_new_int(ctx, doc, image->h)); + pdf_dict_put_drop(ctx, imobj, PDF_NAME_Type, PDF_NAME_XObject); + pdf_dict_put_drop(ctx, imobj, PDF_NAME_Subtype, PDF_NAME_Image); + pdf_dict_put_drop(ctx, imobj, PDF_NAME_Width, pdf_new_int(ctx, doc, image->w)); + pdf_dict_put_drop(ctx, imobj, PDF_NAME_Height, pdf_new_int(ctx, doc, image->h)); if (mask) {} else if (!colorspace || colorspace->n == 1) - pdf_dict_puts_drop(ctx, imobj, "ColorSpace", pdf_new_name(ctx, doc, "DeviceGray")); + pdf_dict_put_drop(ctx, imobj, PDF_NAME_ColorSpace, PDF_NAME_DeviceGray); else if (colorspace->n == 3) - pdf_dict_puts_drop(ctx, imobj, "ColorSpace", pdf_new_name(ctx, doc, "DeviceRGB")); + pdf_dict_put_drop(ctx, imobj, PDF_NAME_ColorSpace, PDF_NAME_DeviceRGB); else if (colorspace->n == 4) - pdf_dict_puts_drop(ctx, imobj, "ColorSpace", pdf_new_name(ctx, doc, "DeviceCMYK")); + pdf_dict_put_drop(ctx, imobj, PDF_NAME_ColorSpace, PDF_NAME_DeviceCMYK); if (!mask) - pdf_dict_puts_drop(ctx, imobj, "BitsPerComponent", pdf_new_int(ctx, doc, image->bpc)); + pdf_dict_put_drop(ctx, imobj, PDF_NAME_BitsPerComponent, pdf_new_int(ctx, doc, image->bpc)); switch (cp ? cp->type : FZ_IMAGE_UNKNOWN) { case FZ_IMAGE_UNKNOWN: /* Unknown also means raw */ @@ -221,32 +221,32 @@ send_image(fz_context *ctx, pdf_device *pdev, fz_image *image, int mask, int sma break; case FZ_IMAGE_JPEG: if (cp->u.jpeg.color_transform != -1) - pdf_dict_puts_drop(ctx, imobj, "ColorTransform", pdf_new_int(ctx, doc, cp->u.jpeg.color_transform)); - pdf_dict_puts_drop(ctx, imobj, "Filter", pdf_new_name(ctx, doc, "DCTDecode")); + pdf_dict_put_drop(ctx, imobj, PDF_NAME_ColorTransform, pdf_new_int(ctx, doc, cp->u.jpeg.color_transform)); + pdf_dict_put_drop(ctx, imobj, PDF_NAME_Filter, PDF_NAME_DCTDecode); break; case FZ_IMAGE_JPX: if (cp->u.jpx.smask_in_data) - pdf_dict_puts_drop(ctx, imobj, "SMaskInData", pdf_new_int(ctx, doc, cp->u.jpx.smask_in_data)); - pdf_dict_puts_drop(ctx, imobj, "Filter", pdf_new_name(ctx, doc, "JPXDecode")); + pdf_dict_put_drop(ctx, imobj, PDF_NAME_SMaskInData, pdf_new_int(ctx, doc, cp->u.jpx.smask_in_data)); + pdf_dict_put_drop(ctx, imobj, PDF_NAME_Filter, PDF_NAME_JPXDecode); break; case FZ_IMAGE_FAX: if (cp->u.fax.columns) - pdf_dict_puts_drop(ctx, imobj, "Columns", pdf_new_int(ctx, doc, cp->u.fax.columns)); + pdf_dict_put_drop(ctx, imobj, PDF_NAME_Columns, pdf_new_int(ctx, doc, cp->u.fax.columns)); if (cp->u.fax.rows) - pdf_dict_puts_drop(ctx, imobj, "Rows", pdf_new_int(ctx, doc, cp->u.fax.rows)); + pdf_dict_put_drop(ctx, imobj, PDF_NAME_Rows, pdf_new_int(ctx, doc, cp->u.fax.rows)); if (cp->u.fax.k) - pdf_dict_puts_drop(ctx, imobj, "K", pdf_new_int(ctx, doc, cp->u.fax.k)); + pdf_dict_put_drop(ctx, imobj, PDF_NAME_K, pdf_new_int(ctx, doc, cp->u.fax.k)); if (cp->u.fax.end_of_line) - pdf_dict_puts_drop(ctx, imobj, "EndOfLine", pdf_new_int(ctx, doc, cp->u.fax.end_of_line)); + pdf_dict_put_drop(ctx, imobj, PDF_NAME_EndOfLine, pdf_new_int(ctx, doc, cp->u.fax.end_of_line)); if (cp->u.fax.encoded_byte_align) - pdf_dict_puts_drop(ctx, imobj, "EncodedByteAlign", pdf_new_int(ctx, doc, cp->u.fax.encoded_byte_align)); + pdf_dict_put_drop(ctx, imobj, PDF_NAME_EncodedByteAlign, pdf_new_int(ctx, doc, cp->u.fax.encoded_byte_align)); if (cp->u.fax.end_of_block) - pdf_dict_puts_drop(ctx, imobj, "EndOfBlock", pdf_new_int(ctx, doc, cp->u.fax.end_of_block)); + pdf_dict_put_drop(ctx, imobj, PDF_NAME_EndOfBlock, pdf_new_int(ctx, doc, cp->u.fax.end_of_block)); if (cp->u.fax.black_is_1) - pdf_dict_puts_drop(ctx, imobj, "BlackIs1", pdf_new_int(ctx, doc, cp->u.fax.black_is_1)); + pdf_dict_put_drop(ctx, imobj, PDF_NAME_BlackIs1, pdf_new_int(ctx, doc, cp->u.fax.black_is_1)); if (cp->u.fax.damaged_rows_before_error) - pdf_dict_puts_drop(ctx, imobj, "DamagedRowsBeforeError", pdf_new_int(ctx, doc, cp->u.fax.damaged_rows_before_error)); - pdf_dict_puts_drop(ctx, imobj, "Filter", pdf_new_name(ctx, doc, "CCITTFaxDecode")); + pdf_dict_put_drop(ctx, imobj, PDF_NAME_DamagedRowsBeforeError, pdf_new_int(ctx, doc, cp->u.fax.damaged_rows_before_error)); + pdf_dict_put_drop(ctx, imobj, PDF_NAME_Filter, PDF_NAME_CCITTFaxDecode); break; case FZ_IMAGE_JBIG2: /* FIXME - jbig2globals */ @@ -254,37 +254,37 @@ send_image(fz_context *ctx, pdf_device *pdev, fz_image *image, int mask, int sma break; case FZ_IMAGE_FLATE: if (cp->u.flate.columns) - pdf_dict_puts_drop(ctx, imobj, "Columns", pdf_new_int(ctx, doc, cp->u.flate.columns)); + pdf_dict_put_drop(ctx, imobj, PDF_NAME_Columns, pdf_new_int(ctx, doc, cp->u.flate.columns)); if (cp->u.flate.colors) - pdf_dict_puts_drop(ctx, imobj, "Colors", pdf_new_int(ctx, doc, cp->u.flate.colors)); + pdf_dict_put_drop(ctx, imobj, PDF_NAME_Colors, pdf_new_int(ctx, doc, cp->u.flate.colors)); if (cp->u.flate.predictor) - pdf_dict_puts_drop(ctx, imobj, "Predictor", pdf_new_int(ctx, doc, cp->u.flate.predictor)); - pdf_dict_puts_drop(ctx, imobj, "Filter", pdf_new_name(ctx, doc, "FlateDecode")); - pdf_dict_puts_drop(ctx, imobj, "BitsPerComponent", pdf_new_int(ctx, doc, image->bpc)); + pdf_dict_put_drop(ctx, imobj, PDF_NAME_Predictor, pdf_new_int(ctx, doc, cp->u.flate.predictor)); + pdf_dict_put_drop(ctx, imobj, PDF_NAME_Filter, PDF_NAME_FlateDecode); + pdf_dict_put_drop(ctx, imobj, PDF_NAME_BitsPerComponent, pdf_new_int(ctx, doc, image->bpc)); break; case FZ_IMAGE_LZW: if (cp->u.lzw.columns) - pdf_dict_puts_drop(ctx, imobj, "Columns", pdf_new_int(ctx, doc, cp->u.lzw.columns)); + pdf_dict_put_drop(ctx, imobj, PDF_NAME_Columns, pdf_new_int(ctx, doc, cp->u.lzw.columns)); if (cp->u.lzw.colors) - pdf_dict_puts_drop(ctx, imobj, "Colors", pdf_new_int(ctx, doc, cp->u.lzw.colors)); + pdf_dict_put_drop(ctx, imobj, PDF_NAME_Colors, pdf_new_int(ctx, doc, cp->u.lzw.colors)); if (cp->u.lzw.predictor) - pdf_dict_puts_drop(ctx, imobj, "Predictor", pdf_new_int(ctx, doc, cp->u.lzw.predictor)); + pdf_dict_put_drop(ctx, imobj, PDF_NAME_Predictor, pdf_new_int(ctx, doc, cp->u.lzw.predictor)); if (cp->u.lzw.early_change) - pdf_dict_puts_drop(ctx, imobj, "EarlyChange", pdf_new_int(ctx, doc, cp->u.lzw.early_change)); - pdf_dict_puts_drop(ctx, imobj, "Filter", pdf_new_name(ctx, doc, "LZWDecode")); + pdf_dict_put_drop(ctx, imobj, PDF_NAME_EarlyChange, pdf_new_int(ctx, doc, cp->u.lzw.early_change)); + pdf_dict_put_drop(ctx, imobj, PDF_NAME_Filter, PDF_NAME_LZWDecode); break; case FZ_IMAGE_RLD: - pdf_dict_puts_drop(ctx, imobj, "Filter", pdf_new_name(ctx, doc, "RunLengthDecode")); + pdf_dict_put_drop(ctx, imobj, PDF_NAME_Filter, PDF_NAME_RunLengthDecode); break; } if (mask) { - pdf_dict_puts_drop(ctx, imobj, "ImageMask", pdf_new_bool(ctx, doc, 1)); + pdf_dict_put_drop(ctx, imobj, PDF_NAME_ImageMask, pdf_new_bool(ctx, doc, 1)); } if (image->mask) { int smasknum = send_image(ctx, pdev, image->mask, 0, 1); - pdf_dict_puts(ctx, imobj, "SMask", pdev->images[smasknum].ref); + pdf_dict_put(ctx, imobj, PDF_NAME_SMask, pdev->images[smasknum].ref); } imref = pdf_new_ref(ctx, doc, imobj); @@ -514,7 +514,7 @@ pdf_dev_alpha(fz_context *ctx, pdf_device *pdev, float alpha, int stroke) fz_try(ctx) { char text[32]; - pdf_dict_puts_drop(ctx, o, (stroke ? "CA" : "ca"), pdf_new_real(ctx, doc, alpha)); + pdf_dict_put_drop(ctx, o, (stroke ? PDF_NAME_CA : PDF_NAME_ca), pdf_new_real(ctx, doc, alpha)); ref = pdf_new_ref(ctx, doc, o); snprintf(text, sizeof(text), "ExtGState/Alp%d", i); pdf_dict_putp(ctx, pdev->resources, text, ref); @@ -574,10 +574,10 @@ pdf_dev_font(fz_context *ctx, pdf_device *pdev, fz_font *font, float size) fz_try(ctx) { char text[32]; - pdf_dict_puts_drop(ctx, o, "Type", pdf_new_name(ctx, doc, "Font")); - pdf_dict_puts_drop(ctx, o, "Subtype", pdf_new_name(ctx, doc, "Type1")); - pdf_dict_puts_drop(ctx, o, "BaseFont", pdf_new_name(ctx, doc, font->name)); - pdf_dict_puts_drop(ctx, o, "Encoding", pdf_new_name(ctx, doc, "WinAnsiEncoding")); + pdf_dict_put_drop(ctx, o, PDF_NAME_Type, PDF_NAME_Font); + pdf_dict_put_drop(ctx, o, PDF_NAME_Subtype, PDF_NAME_Type1); + pdf_dict_put_drop(ctx, o, PDF_NAME_BaseFont, pdf_new_name(ctx, doc, font->name)); + pdf_dict_put_drop(ctx, o, PDF_NAME_Encoding, PDF_NAME_WinAnsiEncoding); ref = pdf_new_ref(ctx, doc, o); snprintf(text, sizeof(text), "Font/F%d", i); pdf_dict_putp(ctx, pdev->resources, text, ref); @@ -800,18 +800,18 @@ pdf_dev_new_form(fz_context *ctx, pdf_obj **form_ref, pdf_device *pdev, const fz group = pdf_new_dict(ctx, doc, 5); fz_try(ctx) { - pdf_dict_puts_drop(ctx, group, "Type", pdf_new_name(ctx, doc, "Group")); - pdf_dict_puts_drop(ctx, group, "S", pdf_new_name(ctx, doc, "Transparency")); - pdf_dict_puts_drop(ctx, group, "K", pdf_new_bool(ctx, doc, knockout)); - pdf_dict_puts_drop(ctx, group, "I", pdf_new_bool(ctx, doc, isolated)); + pdf_dict_put_drop(ctx, group, PDF_NAME_Type, PDF_NAME_Group); + pdf_dict_put_drop(ctx, group, PDF_NAME_S, PDF_NAME_Transparency); + pdf_dict_put_drop(ctx, group, PDF_NAME_K, pdf_new_bool(ctx, doc, knockout)); + pdf_dict_put_drop(ctx, group, PDF_NAME_I, pdf_new_bool(ctx, doc, isolated)); if (!colorspace) {} else if (colorspace->n == 1) - pdf_dict_puts_drop(ctx, group, "CS", pdf_new_name(ctx, doc, "DeviceGray")); + pdf_dict_put_drop(ctx, group, PDF_NAME_CS, PDF_NAME_DeviceGray); else if (colorspace->n == 4) - pdf_dict_puts_drop(ctx, group, "CS", pdf_new_name(ctx, doc, "DeviceCMYK")); + pdf_dict_put_drop(ctx, group, PDF_NAME_CS, PDF_NAME_DeviceCMYK); else - pdf_dict_puts_drop(ctx, group, "CS", pdf_new_name(ctx, doc, "DeviceRGB")); + pdf_dict_put_drop(ctx, group, PDF_NAME_CS, PDF_NAME_DeviceRGB); group_ref = pdev->groups[num].ref = pdf_new_ref(ctx, doc, group); } fz_always(ctx) @@ -829,10 +829,10 @@ pdf_dev_new_form(fz_context *ctx, pdf_obj **form_ref, pdf_device *pdev, const fz form = pdf_new_dict(ctx, doc, 4); fz_try(ctx) { - pdf_dict_puts_drop(ctx, form, "Subtype", pdf_new_name(ctx, doc, "Form")); - pdf_dict_puts(ctx, form, "Group", group_ref); - pdf_dict_puts_drop(ctx, form, "FormType", pdf_new_int(ctx, doc, 1)); - pdf_dict_puts_drop(ctx, form, "BBox", pdf_new_rect(ctx, doc, bbox)); + pdf_dict_put_drop(ctx, form, PDF_NAME_Subtype, PDF_NAME_Form); + pdf_dict_put(ctx, form, PDF_NAME_Group, group_ref); + pdf_dict_put_drop(ctx, form, PDF_NAME_FormType, pdf_new_int(ctx, doc, 1)); + pdf_dict_put_drop(ctx, form, PDF_NAME_BBox, pdf_new_rect(ctx, doc, bbox)); *form_ref = pdf_new_ref(ctx, doc, form); } fz_catch(ctx) @@ -1091,18 +1091,18 @@ pdf_dev_begin_mask(fz_context *ctx, fz_device *dev, const fz_rect *bbox, int lum fz_try(ctx) { smask = pdf_new_dict(ctx, doc, 4); - pdf_dict_puts_drop(ctx, smask, "Type", pdf_new_name(ctx, doc, "Mask")); - pdf_dict_puts_drop(ctx, smask, "S", pdf_new_name(ctx, doc, (luminosity ? "Luminosity" : "Alpha"))); - pdf_dict_puts(ctx, smask, "G", form_ref); + pdf_dict_put_drop(ctx, smask, PDF_NAME_Type, PDF_NAME_Mask); + pdf_dict_put_drop(ctx, smask, PDF_NAME_S, (luminosity ? PDF_NAME_Luminosity : PDF_NAME_Alpha)); + pdf_dict_put(ctx, smask, PDF_NAME_G, form_ref); color_obj = pdf_new_array(ctx, doc, colorspace->n); for (i = 0; i < colorspace->n; i++) pdf_array_push(ctx, color_obj, pdf_new_real(ctx, doc, color[i])); - pdf_dict_puts_drop(ctx, smask, "BC", color_obj); + pdf_dict_put_drop(ctx, smask, PDF_NAME_BC, color_obj); color_obj = NULL; egs = pdf_new_dict(ctx, doc, 5); - pdf_dict_puts_drop(ctx, egs, "Type", pdf_new_name(ctx, doc, "ExtGState")); - pdf_dict_puts_drop(ctx, egs, "SMask", pdf_new_ref(ctx, doc, smask)); + pdf_dict_put_drop(ctx, egs, PDF_NAME_Type, PDF_NAME_ExtGState); + pdf_dict_put_drop(ctx, egs, PDF_NAME_SMask, pdf_new_ref(ctx, doc, smask)); egs_ref = pdf_new_ref(ctx, doc, egs); { @@ -1173,8 +1173,8 @@ pdf_dev_begin_group(fz_context *ctx, fz_device *dev, const fz_rect *bbox, int is { /* No, better make one */ obj = pdf_new_dict(ctx, doc, 2); - pdf_dict_puts_drop(ctx, obj, "Type", pdf_new_name(ctx, doc, "ExtGState")); - pdf_dict_puts_drop(ctx, obj, "BM", pdf_new_name(ctx, doc, fz_blendmode_name(blendmode))); + pdf_dict_put_drop(ctx, obj, PDF_NAME_Type, PDF_NAME_ExtGState); + pdf_dict_put_drop(ctx, obj, PDF_NAME_BM, pdf_new_name(ctx, doc, fz_blendmode_name(blendmode))); pdf_dict_putp_drop(ctx, pdev->resources, text, obj); } } @@ -1332,14 +1332,14 @@ fz_device *pdf_new_pdf_device(fz_context *ctx, pdf_document *doc, pdf_obj *conte fz_device *pdf_page_write(fz_context *ctx, pdf_document *doc, pdf_page *page) { - pdf_obj *resources = pdf_dict_gets(ctx, page->me, "Resources"); + pdf_obj *resources = pdf_dict_get(ctx, page->me, PDF_NAME_Resources); fz_matrix ctm; fz_pre_translate(fz_scale(&ctm, 1, -1), 0, page->mediabox.y0-page->mediabox.y1); if (resources == NULL) { resources = pdf_new_dict(ctx, doc, 0); - pdf_dict_puts_drop(ctx, page->me, "Resources", resources); + pdf_dict_put_drop(ctx, page->me, PDF_NAME_Resources, resources); } if (page->contents == NULL) @@ -1348,7 +1348,7 @@ fz_device *pdf_page_write(fz_context *ctx, pdf_document *doc, pdf_page *page) fz_try(ctx) { page->contents = pdf_new_ref(ctx, doc, obj); - pdf_dict_puts(ctx, page->me, "Contents", page->contents); + pdf_dict_put(ctx, page->me, PDF_NAME_Contents, page->contents); } fz_always(ctx) { diff --git a/source/pdf/pdf-field.c b/source/pdf/pdf-field.c index 5105125a..0571c6cc 100644 --- a/source/pdf/pdf-field.c +++ b/source/pdf/pdf-field.c @@ -1,18 +1,18 @@ #include "mupdf/pdf.h" -pdf_obj *pdf_get_inheritable(fz_context *ctx, pdf_document *doc, pdf_obj *obj, char *key) +pdf_obj *pdf_get_inheritable(fz_context *ctx, pdf_document *doc, pdf_obj *obj, pdf_obj *key) { pdf_obj *fobj = NULL; while (!fobj && obj) { - fobj = pdf_dict_gets(ctx, obj, key); + fobj = pdf_dict_get(ctx, obj, key); if (!fobj) - obj = pdf_dict_gets(ctx, obj, "Parent"); + obj = pdf_dict_get(ctx, obj, PDF_NAME_Parent); } - return fobj ? fobj : pdf_dict_gets(ctx, pdf_dict_gets(ctx, pdf_dict_gets(ctx, pdf_trailer(ctx, doc), "Root"), "AcroForm"), key); + return fobj ? fobj : pdf_dict_get(ctx, pdf_dict_get(ctx, pdf_dict_get(ctx, pdf_trailer(ctx, doc), PDF_NAME_Root), PDF_NAME_AcroForm), key); } char *pdf_get_string_or_stream(fz_context *ctx, pdf_document *doc, pdf_obj *obj) @@ -59,25 +59,25 @@ char *pdf_get_string_or_stream(fz_context *ctx, pdf_document *doc, pdf_obj *obj) char *pdf_field_value(fz_context *ctx, pdf_document *doc, pdf_obj *field) { - return pdf_get_string_or_stream(ctx, doc, pdf_get_inheritable(ctx, doc, field, "V")); + return pdf_get_string_or_stream(ctx, doc, pdf_get_inheritable(ctx, doc, field, PDF_NAME_V)); } int pdf_get_field_flags(fz_context *ctx, pdf_document *doc, pdf_obj *obj) { - return pdf_to_int(ctx, pdf_get_inheritable(ctx, doc, obj, "Ff")); + return pdf_to_int(ctx, pdf_get_inheritable(ctx, doc, obj, PDF_NAME_Ff)); } -static char *get_field_type_name(fz_context *ctx, pdf_document *doc, pdf_obj *obj) +static pdf_obj *get_field_type_name(fz_context *ctx, pdf_document *doc, pdf_obj *obj) { - return pdf_to_name(ctx, pdf_get_inheritable(ctx, doc, obj, "FT")); + return pdf_get_inheritable(ctx, doc, obj, PDF_NAME_FT); } int pdf_field_type(fz_context *ctx, pdf_document *doc, pdf_obj *obj) { - char *type = get_field_type_name(ctx, doc, obj); + pdf_obj *type = get_field_type_name(ctx, doc, obj); int flags = pdf_get_field_flags(ctx, doc, obj); - if (!strcmp(type, "Btn")) + if (pdf_name_eq(ctx, type, PDF_NAME_Btn)) { if (flags & Ff_Pushbutton) return PDF_WIDGET_TYPE_PUSHBUTTON; @@ -86,16 +86,16 @@ int pdf_field_type(fz_context *ctx, pdf_document *doc, pdf_obj *obj) else return PDF_WIDGET_TYPE_CHECKBOX; } - else if (!strcmp(type, "Tx")) + else if (pdf_name_eq(ctx, type, PDF_NAME_Tx)) return PDF_WIDGET_TYPE_TEXT; - else if (!strcmp(type, "Ch")) + else if (pdf_name_eq(ctx, type, PDF_NAME_Ch)) { if (flags & Ff_Combo) return PDF_WIDGET_TYPE_COMBOBOX; else return PDF_WIDGET_TYPE_LISTBOX; } - else if (!strcmp(type, "Sig")) + else if (pdf_name_eq(ctx, type, PDF_NAME_Sig)) return PDF_WIDGET_TYPE_SIGNATURE; else return PDF_WIDGET_TYPE_NOT_WIDGET; @@ -105,47 +105,47 @@ void pdf_set_field_type(fz_context *ctx, pdf_document *doc, pdf_obj *obj, int ty { int setbits = 0; int clearbits = 0; - char *typename = NULL; + pdf_obj *typename = NULL; switch(type) { case PDF_WIDGET_TYPE_PUSHBUTTON: - typename = "Btn"; + typename = PDF_NAME_Btn; setbits = Ff_Pushbutton; break; case PDF_WIDGET_TYPE_CHECKBOX: - typename = "Btn"; + typename = PDF_NAME_Btn; clearbits = Ff_Pushbutton; setbits = Ff_Radio; break; case PDF_WIDGET_TYPE_RADIOBUTTON: - typename = "Btn"; + typename = PDF_NAME_Btn; clearbits = (Ff_Pushbutton|Ff_Radio); break; case PDF_WIDGET_TYPE_TEXT: - typename = "Tx"; + typename = PDF_NAME_Tx; break; case PDF_WIDGET_TYPE_LISTBOX: - typename = "Ch"; + typename = PDF_NAME_Ch; clearbits = Ff_Combo; break; case PDF_WIDGET_TYPE_COMBOBOX: - typename = "Ch"; + typename = PDF_NAME_Ch; setbits = Ff_Combo; break; case PDF_WIDGET_TYPE_SIGNATURE: - typename = "Sig"; + typename = PDF_NAME_Sig; break; } if (typename) - pdf_dict_puts_drop(ctx, obj, "FT", pdf_new_name(ctx, doc, typename)); + pdf_dict_put_drop(ctx, obj, PDF_NAME_FT, typename); if (setbits != 0 || clearbits != 0) { - int bits = pdf_to_int(ctx, pdf_dict_gets(ctx, obj, "Ff")); + int bits = pdf_to_int(ctx, pdf_dict_get(ctx, obj, PDF_NAME_Ff)); bits &= ~clearbits; bits |= setbits; - pdf_dict_puts_drop(ctx, obj, "Ff", pdf_new_int(ctx, doc, bits)); + pdf_dict_put_drop(ctx, obj, PDF_NAME_Ff, pdf_new_int(ctx, doc, bits)); } } diff --git a/source/pdf/pdf-font.c b/source/pdf/pdf-font.c index 5e3f1e19..35e61f93 100644 --- a/source/pdf/pdf-font.c +++ b/source/pdf/pdf-font.c @@ -419,7 +419,7 @@ pdf_load_simple_font_by_name(fz_context *ctx, pdf_document *doc, pdf_obj *dict, pdf_obj *widths; unsigned short *etable = NULL; pdf_font_desc *fontdesc = NULL; - char *subtype; + pdf_obj *subtype; FT_Face face; FT_CharMap cmap; int symbolic; @@ -440,17 +440,17 @@ pdf_load_simple_font_by_name(fz_context *ctx, pdf_document *doc, pdf_obj *dict, { fontdesc = pdf_new_font_desc(ctx); - descriptor = pdf_dict_gets(ctx, dict, "FontDescriptor"); + descriptor = pdf_dict_get(ctx, dict, PDF_NAME_FontDescriptor); if (descriptor) pdf_load_font_descriptor(ctx, doc, fontdesc, descriptor, NULL, basefont, 0); else pdf_load_builtin_font(ctx, fontdesc, basefont, 0); /* Some chinese documents mistakenly consider WinAnsiEncoding to be codepage 936 */ - if (descriptor && pdf_is_string(ctx, pdf_dict_gets(ctx, descriptor, "FontName")) && - !pdf_dict_gets(ctx, dict, "ToUnicode") && - !strcmp(pdf_to_name(ctx, pdf_dict_gets(ctx, dict, "Encoding")), "WinAnsiEncoding") && - pdf_to_int(ctx, pdf_dict_gets(ctx, descriptor, "Flags")) == 4) + if (descriptor && pdf_is_string(ctx, pdf_dict_get(ctx, descriptor, PDF_NAME_FontName)) && + !pdf_dict_get(ctx, dict, PDF_NAME_ToUnicode) && + pdf_name_eq(ctx, pdf_dict_get(ctx, dict, PDF_NAME_Encoding), PDF_NAME_WinAnsiEncoding) && + pdf_to_int(ctx, pdf_dict_get(ctx, descriptor, PDF_NAME_Flags)) == 4) { char *cp936fonts[] = { "\xCB\xCE\xCC\xE5", "SimSun,Regular", @@ -530,7 +530,7 @@ pdf_load_simple_font_by_name(fz_context *ctx, pdf_document *doc, pdf_obj *dict, etable[i] = 0; } - encoding = pdf_dict_gets(ctx, dict, "Encoding"); + encoding = pdf_dict_get(ctx, dict, PDF_NAME_Encoding); if (encoding) { if (pdf_is_name(ctx, encoding)) @@ -540,13 +540,13 @@ pdf_load_simple_font_by_name(fz_context *ctx, pdf_document *doc, pdf_obj *dict, { pdf_obj *base, *diff, *item; - base = pdf_dict_gets(ctx, encoding, "BaseEncoding"); + base = pdf_dict_get(ctx, encoding, PDF_NAME_BaseEncoding); if (pdf_is_name(ctx, base)) pdf_load_encoding(estrings, pdf_to_name(ctx, base)); else if (!fontdesc->is_embedded && !symbolic) pdf_load_encoding(estrings, "StandardEncoding"); - diff = pdf_dict_gets(ctx, encoding, "Differences"); + diff = pdf_dict_get(ctx, encoding, PDF_NAME_Differences); if (pdf_is_array(ctx, diff)) { n = pdf_array_len(ctx, diff); @@ -573,16 +573,16 @@ pdf_load_simple_font_by_name(fz_context *ctx, pdf_document *doc, pdf_obj *dict, has_lock = 1; /* built-in and substitute fonts may be a different type than what the document expects */ - subtype = pdf_to_name(ctx, pdf_dict_gets(ctx, dict, "Subtype")); - if (!strcmp(subtype, "Type1")) + subtype = pdf_dict_get(ctx, dict, PDF_NAME_Subtype); + if (pdf_name_eq(ctx, subtype, PDF_NAME_Type1)) kind = TYPE1; - else if (!strcmp(subtype, "MMType1")) + else if (pdf_name_eq(ctx, subtype, PDF_NAME_MMType1)) kind = TYPE1; - else if (!strcmp(subtype, "TrueType")) + else if (pdf_name_eq(ctx, subtype, PDF_NAME_TrueType)) kind = TRUETYPE; - else if (!strcmp(subtype, "CIDFontType0")) + else if (pdf_name_eq(ctx, subtype, PDF_NAME_CIDFontType0)) kind = TYPE1; - else if (!strcmp(subtype, "CIDFontType2")) + else if (pdf_name_eq(ctx, subtype, PDF_NAME_CIDFontType2)) kind = TRUETYPE; /* encode by glyph name where we can */ @@ -703,7 +703,7 @@ pdf_load_simple_font_by_name(fz_context *ctx, pdf_document *doc, pdf_obj *dict, fz_try(ctx) { - pdf_load_to_unicode(ctx, doc, fontdesc, estrings, NULL, pdf_dict_gets(ctx, dict, "ToUnicode")); + pdf_load_to_unicode(ctx, doc, fontdesc, estrings, NULL, pdf_dict_get(ctx, dict, PDF_NAME_ToUnicode)); } fz_catch(ctx) { @@ -717,13 +717,13 @@ pdf_load_simple_font_by_name(fz_context *ctx, pdf_document *doc, pdf_obj *dict, pdf_set_default_hmtx(ctx, fontdesc, fontdesc->missing_width); - widths = pdf_dict_gets(ctx, dict, "Widths"); + widths = pdf_dict_get(ctx, dict, PDF_NAME_Widths); if (widths) { int first, last; - first = pdf_to_int(ctx, pdf_dict_gets(ctx, dict, "FirstChar")); - last = pdf_to_int(ctx, pdf_dict_gets(ctx, dict, "LastChar")); + first = pdf_to_int(ctx, pdf_dict_get(ctx, dict, PDF_NAME_FirstChar)); + last = pdf_to_int(ctx, pdf_dict_get(ctx, dict, PDF_NAME_LastChar)); if (first < 0 || last > 255 || first > last) first = last = 0; @@ -766,7 +766,7 @@ pdf_load_simple_font_by_name(fz_context *ctx, pdf_document *doc, pdf_obj *dict, static pdf_font_desc * pdf_load_simple_font(fz_context *ctx, pdf_document *doc, pdf_obj *dict) { - char *basefont = pdf_to_name(ctx, pdf_dict_gets(ctx, dict, "BaseFont")); + char *basefont = pdf_to_name(ctx, pdf_dict_get(ctx, dict, PDF_NAME_BaseFont)); return pdf_load_simple_font_by_name(ctx, doc, dict, basefont); } @@ -861,18 +861,18 @@ load_cid_font(fz_context *ctx, pdf_document *doc, pdf_obj *dict, pdf_obj *encodi { /* Get font name and CID collection */ - basefont = pdf_to_name(ctx, pdf_dict_gets(ctx, dict, "BaseFont")); + basefont = pdf_to_name(ctx, pdf_dict_get(ctx, dict, PDF_NAME_BaseFont)); { pdf_obj *cidinfo; char tmpstr[64]; int tmplen; - cidinfo = pdf_dict_gets(ctx, dict, "CIDSystemInfo"); + cidinfo = pdf_dict_get(ctx, dict, PDF_NAME_CIDSystemInfo); if (!cidinfo) fz_throw(ctx, FZ_ERROR_GENERIC, "cid font is missing info"); - obj = pdf_dict_gets(ctx, cidinfo, "Registry"); + obj = pdf_dict_get(ctx, cidinfo, PDF_NAME_Registry); tmplen = fz_mini(sizeof tmpstr - 1, pdf_to_str_len(ctx, obj)); memcpy(tmpstr, pdf_to_str_buf(ctx, obj), tmplen); tmpstr[tmplen] = '\0'; @@ -880,7 +880,7 @@ load_cid_font(fz_context *ctx, pdf_document *doc, pdf_obj *dict, pdf_obj *encodi fz_strlcat(collection, "-", sizeof collection); - obj = pdf_dict_gets(ctx, cidinfo, "Ordering"); + obj = pdf_dict_get(ctx, cidinfo, PDF_NAME_Ordering); tmplen = fz_mini(sizeof tmpstr - 1, pdf_to_str_len(ctx, obj)); memcpy(tmpstr, pdf_to_str_buf(ctx, obj), tmplen); tmpstr[tmplen] = '\0'; @@ -891,9 +891,9 @@ load_cid_font(fz_context *ctx, pdf_document *doc, pdf_obj *dict, pdf_obj *encodi if (pdf_is_name(ctx, encoding)) { - if (!strcmp(pdf_to_name(ctx, encoding), "Identity-H")) + if (pdf_name_eq(ctx, encoding, PDF_NAME_Identity_H)) cmap = pdf_new_identity_cmap(ctx, 0, 2); - else if (!strcmp(pdf_to_name(ctx, encoding), "Identity-V")) + else if (pdf_name_eq(ctx, encoding, PDF_NAME_Identity_V)) cmap = pdf_new_identity_cmap(ctx, 1, 2); else cmap = pdf_load_system_cmap(ctx, pdf_to_name(ctx, encoding)); @@ -916,7 +916,7 @@ load_cid_font(fz_context *ctx, pdf_document *doc, pdf_obj *dict, pdf_obj *encodi pdf_set_font_wmode(ctx, fontdesc, pdf_cmap_wmode(ctx, fontdesc->encoding)); - descriptor = pdf_dict_gets(ctx, dict, "FontDescriptor"); + descriptor = pdf_dict_get(ctx, dict, PDF_NAME_FontDescriptor); if (!descriptor) fz_throw(ctx, FZ_ERROR_GENERIC, "syntaxerror: missing font descriptor"); pdf_load_font_descriptor(ctx, doc, fontdesc, descriptor, collection, basefont, 1); @@ -925,7 +925,7 @@ load_cid_font(fz_context *ctx, pdf_document *doc, pdf_obj *dict, pdf_obj *encodi /* Apply encoding */ - cidtogidmap = pdf_dict_gets(ctx, dict, "CIDToGIDMap"); + cidtogidmap = pdf_dict_get(ctx, dict, PDF_NAME_CIDToGIDMap); if (pdf_is_indirect(ctx, cidtogidmap)) { fz_buffer *buf; @@ -980,12 +980,12 @@ load_cid_font(fz_context *ctx, pdf_document *doc, pdf_obj *dict, pdf_obj *encodi /* Horizontal */ dw = 1000; - obj = pdf_dict_gets(ctx, dict, "DW"); + obj = pdf_dict_get(ctx, dict, PDF_NAME_DW); if (obj) dw = pdf_to_int(ctx, obj); pdf_set_default_hmtx(ctx, fontdesc, dw); - widths = pdf_dict_gets(ctx, dict, "W"); + widths = pdf_dict_get(ctx, dict, PDF_NAME_W); if (widths) { int c0, c1, w, n, m; @@ -1024,7 +1024,7 @@ load_cid_font(fz_context *ctx, pdf_document *doc, pdf_obj *dict, pdf_obj *encodi int dw2y = 880; int dw2w = -1000; - obj = pdf_dict_gets(ctx, dict, "DW2"); + obj = pdf_dict_get(ctx, dict, PDF_NAME_DW2); if (obj) { dw2y = pdf_to_int(ctx, pdf_array_get(ctx, obj, 0)); @@ -1033,7 +1033,7 @@ load_cid_font(fz_context *ctx, pdf_document *doc, pdf_obj *dict, pdf_obj *encodi pdf_set_default_vmtx(ctx, fontdesc, dw2y, dw2w); - widths = pdf_dict_gets(ctx, dict, "W2"); + widths = pdf_dict_get(ctx, dict, PDF_NAME_W2); if (widths) { int c0, c1, w, x, y, n; @@ -1088,19 +1088,19 @@ pdf_load_type0_font(fz_context *ctx, pdf_document *doc, pdf_obj *dict) pdf_obj *encoding; pdf_obj *to_unicode; - dfonts = pdf_dict_gets(ctx, dict, "DescendantFonts"); + dfonts = pdf_dict_get(ctx, dict, PDF_NAME_DescendantFonts); if (!dfonts) fz_throw(ctx, FZ_ERROR_GENERIC, "cid font is missing descendant fonts"); dfont = pdf_array_get(ctx, dfonts, 0); - subtype = pdf_dict_gets(ctx, dfont, "Subtype"); - encoding = pdf_dict_gets(ctx, dict, "Encoding"); - to_unicode = pdf_dict_gets(ctx, dict, "ToUnicode"); + subtype = pdf_dict_get(ctx, dfont, PDF_NAME_Subtype); + encoding = pdf_dict_get(ctx, dict, PDF_NAME_Encoding); + to_unicode = pdf_dict_get(ctx, dict, PDF_NAME_ToUnicode); - if (pdf_is_name(ctx, subtype) && !strcmp(pdf_to_name(ctx, subtype), "CIDFontType0")) + if (pdf_is_name(ctx, subtype) && pdf_name_eq(ctx, subtype, PDF_NAME_CIDFontType0)) return load_cid_font(ctx, doc, dfont, encoding, to_unicode); - if (pdf_is_name(ctx, subtype) && !strcmp(pdf_to_name(ctx, subtype), "CIDFontType2")) + if (pdf_is_name(ctx, subtype) && pdf_name_eq(ctx, subtype, PDF_NAME_CIDFontType2)) return load_cid_font(ctx, doc, dfont, encoding, to_unicode); fz_throw(ctx, FZ_ERROR_GENERIC, "syntaxerror: unknown cid font type"); } @@ -1119,17 +1119,17 @@ pdf_load_font_descriptor(fz_context *ctx, pdf_document *doc, pdf_font_desc *font /* Prefer BaseFont; don't bother with FontName */ fontname = basefont; - fontdesc->flags = pdf_to_int(ctx, pdf_dict_gets(ctx, dict, "Flags")); - fontdesc->italic_angle = pdf_to_real(ctx, pdf_dict_gets(ctx, dict, "ItalicAngle")); - fontdesc->ascent = pdf_to_real(ctx, pdf_dict_gets(ctx, dict, "Ascent")); - fontdesc->descent = pdf_to_real(ctx, pdf_dict_gets(ctx, dict, "Descent")); - fontdesc->cap_height = pdf_to_real(ctx, pdf_dict_gets(ctx, dict, "CapHeight")); - fontdesc->x_height = pdf_to_real(ctx, pdf_dict_gets(ctx, dict, "XHeight")); - fontdesc->missing_width = pdf_to_real(ctx, pdf_dict_gets(ctx, dict, "MissingWidth")); - - obj1 = pdf_dict_gets(ctx, dict, "FontFile"); - obj2 = pdf_dict_gets(ctx, dict, "FontFile2"); - obj3 = pdf_dict_gets(ctx, dict, "FontFile3"); + fontdesc->flags = pdf_to_int(ctx, pdf_dict_get(ctx, dict, PDF_NAME_Flags)); + fontdesc->italic_angle = pdf_to_real(ctx, pdf_dict_get(ctx, dict, PDF_NAME_ItalicAngle)); + fontdesc->ascent = pdf_to_real(ctx, pdf_dict_get(ctx, dict, PDF_NAME_Ascent)); + fontdesc->descent = pdf_to_real(ctx, pdf_dict_get(ctx, dict, PDF_NAME_Descent)); + fontdesc->cap_height = pdf_to_real(ctx, pdf_dict_get(ctx, dict, PDF_NAME_CapHeight)); + fontdesc->x_height = pdf_to_real(ctx, pdf_dict_get(ctx, dict, PDF_NAME_XHeight)); + fontdesc->missing_width = pdf_to_real(ctx, pdf_dict_get(ctx, dict, PDF_NAME_MissingWidth)); + + obj1 = pdf_dict_get(ctx, dict, PDF_NAME_FontFile); + obj2 = pdf_dict_get(ctx, dict, PDF_NAME_FontFile2); + obj3 = pdf_dict_get(ctx, dict, PDF_NAME_FontFile3); obj = obj1 ? obj1 : obj2 ? obj2 : obj3; if (pdf_is_indirect(ctx, obj)) @@ -1209,7 +1209,7 @@ pdf_make_width_table(fz_context *ctx, pdf_font_desc *fontdesc) pdf_font_desc * pdf_load_font(fz_context *ctx, pdf_document *doc, pdf_obj *rdb, pdf_obj *dict, int nested_depth) { - char *subtype; + pdf_obj *subtype; pdf_obj *dfonts; pdf_obj *charprocs; pdf_font_desc *fontdesc; @@ -1220,19 +1220,19 @@ pdf_load_font(fz_context *ctx, pdf_document *doc, pdf_obj *rdb, pdf_obj *dict, i return fontdesc; } - subtype = pdf_to_name(ctx, pdf_dict_gets(ctx, dict, "Subtype")); - dfonts = pdf_dict_gets(ctx, dict, "DescendantFonts"); - charprocs = pdf_dict_gets(ctx, dict, "CharProcs"); + subtype = pdf_dict_get(ctx, dict, PDF_NAME_Subtype); + dfonts = pdf_dict_get(ctx, dict, PDF_NAME_DescendantFonts); + charprocs = pdf_dict_get(ctx, dict, PDF_NAME_CharProcs); - if (subtype && !strcmp(subtype, "Type0")) + if (pdf_name_eq(ctx, subtype, PDF_NAME_Type0)) fontdesc = pdf_load_type0_font(ctx, doc, dict); - else if (subtype && !strcmp(subtype, "Type1")) + else if (pdf_name_eq(ctx, subtype, PDF_NAME_Type1)) fontdesc = pdf_load_simple_font(ctx, doc, dict); - else if (subtype && !strcmp(subtype, "MMType1")) + else if (pdf_name_eq(ctx, subtype, PDF_NAME_MMType1)) fontdesc = pdf_load_simple_font(ctx, doc, dict); - else if (subtype && !strcmp(subtype, "TrueType")) + else if (pdf_name_eq(ctx, subtype, PDF_NAME_TrueType)) fontdesc = pdf_load_simple_font(ctx, doc, dict); - else if (subtype && !strcmp(subtype, "Type3")) + else if (pdf_name_eq(ctx, subtype, PDF_NAME_Type3)) { fontdesc = pdf_load_type3_font(ctx, doc, rdb, dict); type3 = 1; diff --git a/source/pdf/pdf-form.c b/source/pdf/pdf-form.c index 4caadd25..f18396c4 100644 --- a/source/pdf/pdf-form.c +++ b/source/pdf/pdf-form.c @@ -27,15 +27,15 @@ static int pdf_field_dirties_document(fz_context *ctx, pdf_document *doc, pdf_ob * share the same name */ static pdf_obj *find_head_of_field_group(fz_context *ctx, pdf_obj *obj) { - if (obj == NULL || pdf_dict_gets(ctx, obj, "T")) + if (obj == NULL || pdf_dict_get(ctx, obj, PDF_NAME_T)) return obj; else - return find_head_of_field_group(ctx, pdf_dict_gets(ctx, obj, "Parent")); + return find_head_of_field_group(ctx, pdf_dict_get(ctx, obj, PDF_NAME_Parent)); } static void pdf_field_mark_dirty(fz_context *ctx, pdf_document *doc, pdf_obj *field) { - pdf_obj *kids = pdf_dict_gets(ctx, field, "Kids"); + pdf_obj *kids = pdf_dict_get(ctx, field, PDF_NAME_Kids); if (kids) { int i, n = pdf_array_len(ctx, kids); @@ -67,7 +67,7 @@ static void update_field_value(fz_context *ctx, pdf_document *doc, pdf_obj *obj, fz_try(ctx) { sobj = pdf_new_string(ctx, doc, text, strlen(text)); - pdf_dict_puts(ctx, obj, "V", sobj); + pdf_dict_put(ctx, obj, PDF_NAME_V, sobj); } fz_always(ctx) { @@ -92,7 +92,7 @@ static pdf_obj *find_field(fz_context *ctx, pdf_obj *dict, char *name, int len) char *part; field = pdf_array_get(ctx, dict, i); - part = pdf_to_str_buf(ctx, pdf_dict_gets(ctx, field, "T")); + part = pdf_to_str_buf(ctx, pdf_dict_get(ctx, field, PDF_NAME_T)); if (strlen(part) == (size_t)len && !memcmp(part, name, len)) return field; } @@ -119,7 +119,7 @@ pdf_obj *pdf_lookup_field(fz_context *ctx, pdf_obj *form, char *name) len = dot ? dot - namep : strlen(namep); dict = find_field(ctx, form, namep, len); if (dot) - form = pdf_dict_gets(ctx, dict, "Kids"); + form = pdf_dict_get(ctx, dict, PDF_NAME_Kids); } return dict; @@ -134,13 +134,13 @@ static void reset_field(fz_context *ctx, pdf_document *doc, pdf_obj *field) * At the bottom of the hierarchy we may find widget annotations * that aren't also fields, but DV and V will not be present in their * dictionaries, and attempts to remove V will be harmless. */ - pdf_obj *dv = pdf_dict_gets(ctx, field, "DV"); - pdf_obj *kids = pdf_dict_gets(ctx, field, "Kids"); + pdf_obj *dv = pdf_dict_get(ctx, field, PDF_NAME_DV); + pdf_obj *kids = pdf_dict_get(ctx, field, PDF_NAME_Kids); if (dv) - pdf_dict_puts(ctx, field, "V", dv); + pdf_dict_put(ctx, field, PDF_NAME_V, dv); else - pdf_dict_dels(ctx, field, "V"); + pdf_dict_del(ctx, field, PDF_NAME_V); if (kids == NULL) { @@ -153,16 +153,16 @@ static void reset_field(fz_context *ctx, pdf_document *doc, pdf_obj *field) case PDF_WIDGET_TYPE_RADIOBUTTON: case PDF_WIDGET_TYPE_CHECKBOX: { - pdf_obj *leafv = pdf_get_inheritable(ctx, doc, field, "V"); + pdf_obj *leafv = pdf_get_inheritable(ctx, doc, field, PDF_NAME_V); if (leafv) pdf_keep_obj(ctx, leafv); else - leafv = pdf_new_name(ctx, doc, "Off"); + leafv = PDF_NAME_Off; fz_try(ctx) { - pdf_dict_puts(ctx, field, "AS", leafv); + pdf_dict_put(ctx, field, PDF_NAME_AS, leafv); } fz_always(ctx) { @@ -190,7 +190,7 @@ static void reset_field(fz_context *ctx, pdf_document *doc, pdf_obj *field) void pdf_field_reset(fz_context *ctx, pdf_document *doc, pdf_obj *field) { - pdf_obj *kids = pdf_dict_gets(ctx, field, "Kids"); + pdf_obj *kids = pdf_dict_get(ctx, field, PDF_NAME_Kids); reset_field(ctx, doc, field); @@ -205,8 +205,8 @@ void pdf_field_reset(fz_context *ctx, pdf_document *doc, pdf_obj *field) static void add_field_hierarchy_to_array(fz_context *ctx, pdf_obj *array, pdf_obj *field) { - pdf_obj *kids = pdf_dict_gets(ctx, field, "Kids"); - pdf_obj *exclude = pdf_dict_gets(ctx, field, "Exclude"); + pdf_obj *kids = pdf_dict_get(ctx, field, PDF_NAME_Kids); + pdf_obj *exclude = pdf_dict_get(ctx, field, PDF_NAME_Exclude); if (exclude) return; @@ -231,7 +231,7 @@ static void add_field_hierarchy_to_array(fz_context *ctx, pdf_obj *array, pdf_ob */ static pdf_obj *specified_fields(fz_context *ctx, pdf_document *doc, pdf_obj *fields, int exclude) { - pdf_obj *form = pdf_dict_getp(ctx, pdf_trailer(ctx, doc), "Root/AcroForm/Fields"); + pdf_obj *form = pdf_dict_getl(ctx, pdf_trailer(ctx, doc), PDF_NAME_Root, PDF_NAME_AcroForm, PDF_NAME_Fields, NULL); int i, n; pdf_obj *result = pdf_new_array(ctx, doc, 0); pdf_obj *nil = NULL; @@ -256,7 +256,7 @@ static pdf_obj *specified_fields(fz_context *ctx, pdf_document *doc, pdf_obj *fi field = pdf_lookup_field(ctx, form, pdf_to_str_buf(ctx, field)); if (field) - pdf_dict_puts(ctx, field, "Exclude", nil); + pdf_dict_put(ctx, field, PDF_NAME_Exclude, nil); } /* Act upon all unmarked fields */ @@ -276,7 +276,7 @@ static pdf_obj *specified_fields(fz_context *ctx, pdf_document *doc, pdf_obj *fi field = pdf_lookup_field(ctx, form, pdf_to_str_buf(ctx, field)); if (field) - pdf_dict_dels(ctx, field, "Exclude"); + pdf_dict_del(ctx, field, PDF_NAME_Exclude); } } else @@ -333,11 +333,11 @@ static void execute_action(fz_context *ctx, pdf_document *doc, pdf_obj *obj, pdf { if (a) { - char *type = pdf_to_name(ctx, pdf_dict_gets(ctx, a, "S")); + pdf_obj *type = pdf_dict_get(ctx, a, PDF_NAME_S); - if (!strcmp(type, "JavaScript")) + if (pdf_name_eq(ctx, type, PDF_NAME_JavaScript)) { - pdf_obj *js = pdf_dict_gets(ctx, a, "JS"); + pdf_obj *js = pdf_dict_get(ctx, a, PDF_NAME_JS); if (js) { char *code = pdf_to_utf8(ctx, doc, js); @@ -355,15 +355,15 @@ static void execute_action(fz_context *ctx, pdf_document *doc, pdf_obj *obj, pdf } } } - else if (!strcmp(type, "ResetForm")) + else if (pdf_name_eq(ctx, type, PDF_NAME_ResetForm)) { - reset_form(ctx, doc, pdf_dict_gets(ctx, a, "Fields"), pdf_to_int(ctx, pdf_dict_gets(ctx, a, "Flags")) & 1); + reset_form(ctx, doc, pdf_dict_get(ctx, a, PDF_NAME_Fields), pdf_to_int(ctx, pdf_dict_get(ctx, a, PDF_NAME_Flags)) & 1); } - else if (!strcmp(type, "Named")) + else if (pdf_name_eq(ctx, type, PDF_NAME_Named)) { - char *name = pdf_to_name(ctx, pdf_dict_gets(ctx, a, "N")); + pdf_obj *name = pdf_dict_get(ctx, a, PDF_NAME_N); - if (!strcmp(name, "Print")) + if (pdf_name_eq(ctx, name, PDF_NAME_Print)) pdf_event_issue_print(ctx, doc); } } @@ -371,7 +371,7 @@ static void execute_action(fz_context *ctx, pdf_document *doc, pdf_obj *obj, pdf static void execute_action_chain(fz_context *ctx, pdf_document *doc, pdf_obj *obj) { - pdf_obj *a = pdf_dict_gets(ctx, obj, "A"); + pdf_obj *a = pdf_dict_get(ctx, obj, PDF_NAME_A); pdf_js_event e; e.target = obj; @@ -381,7 +381,7 @@ static void execute_action_chain(fz_context *ctx, pdf_document *doc, pdf_obj *ob while (a) { execute_action(ctx, doc, obj, a); - a = pdf_dict_gets(ctx, a, "Next"); + a = pdf_dict_get(ctx, a, PDF_NAME_Next); } } @@ -402,56 +402,29 @@ static void execute_additional_action(fz_context *ctx, pdf_document *doc, pdf_ob static void check_off(fz_context *ctx, pdf_document *doc, pdf_obj *obj) { - pdf_obj *off = NULL; - - fz_var(off); - fz_try(ctx); - { - off = pdf_new_name(ctx, doc, "Off"); - pdf_dict_puts(ctx, obj, "AS", off); - } - fz_always(ctx) - { - pdf_drop_obj(ctx, off); - } - fz_catch(ctx) - { - fz_rethrow(ctx); - } + pdf_dict_put(ctx, obj, PDF_NAME_AS, PDF_NAME_Off); } -static void set_check(fz_context *ctx, pdf_document *doc, pdf_obj *chk, char *name) +static void set_check(fz_context *ctx, pdf_document *doc, pdf_obj *chk, pdf_obj *name) { pdf_obj *n = pdf_dict_getp(ctx, chk, "AP/N"); - pdf_obj *val = NULL; + pdf_obj *val; - fz_var(val); - fz_try(ctx) - { - /* If name is a possible value of this check - * box then use it, otherwise use "Off" */ - if (pdf_dict_gets(ctx, n, name)) - val = pdf_new_name(ctx, doc, name); - else - val = pdf_new_name(ctx, doc, "Off"); + /* If name is a possible value of this check + * box then use it, otherwise use "Off" */ + if (pdf_dict_get(ctx, n, name)) + val = name; + else + val = PDF_NAME_Off; - pdf_dict_puts(ctx, chk, "AS", val); - } - fz_always(ctx) - { - pdf_drop_obj(ctx, val); - } - fz_catch(ctx) - { - fz_rethrow(ctx); - } + pdf_dict_put_drop(ctx, chk, PDF_NAME_AS, val); } /* Set the values of all fields in a group defined by a node * in the hierarchy */ -static void set_check_grp(fz_context *ctx, pdf_document *doc, pdf_obj *grp, char *val) +static void set_check_grp(fz_context *ctx, pdf_document *doc, pdf_obj *grp, pdf_obj *val) { - pdf_obj *kids = pdf_dict_gets(ctx, grp, "Kids"); + pdf_obj *kids = pdf_dict_get(ctx, grp, PDF_NAME_Kids); if (kids == NULL) { @@ -512,16 +485,16 @@ static void recalculate(fz_context *ctx, pdf_document *doc) static void toggle_check_box(fz_context *ctx, pdf_document *doc, pdf_obj *obj) { - pdf_obj *as = pdf_dict_gets(ctx, obj, "AS"); + pdf_obj *as = pdf_dict_get(ctx, obj, PDF_NAME_AS); int ff = pdf_get_field_flags(ctx, doc, obj); int radio = ((ff & (Ff_Pushbutton|Ff_Radio)) == Ff_Radio); char *val = NULL; - pdf_obj *grp = radio ? pdf_dict_gets(ctx, obj, "Parent") : find_head_of_field_group(ctx, obj); + pdf_obj *grp = radio ? pdf_dict_get(ctx, obj, PDF_NAME_Parent) : find_head_of_field_group(ctx, obj); if (!grp) grp = obj; - if (as && strcmp(pdf_to_name(ctx, as), "Off")) + if (as && !pdf_name_eq(ctx, as, PDF_NAME_Off)) { /* "as" neither missing nor set to Off. Set it to Off, unless * this is a non-toggle-off radio button. */ @@ -543,7 +516,7 @@ static void toggle_check_box(fz_context *ctx, pdf_document *doc, pdf_obj *obj) for (i = 0; i < len; i++) { key = pdf_dict_get_key(ctx, n, i); - if (pdf_is_name(ctx, key) && strcmp(pdf_to_name(ctx, key), "Off")) + if (pdf_is_name(ctx, key) && !pdf_name_eq(ctx, key, PDF_NAME_Off)) break; } @@ -551,19 +524,17 @@ static void toggle_check_box(fz_context *ctx, pdf_document *doc, pdf_obj *obj) if (!key) return; - val = pdf_to_name(ctx, key); - if (radio) { /* For radio buttons, first turn off all buttons in the group and * then set the one that was clicked */ - pdf_obj *kids = pdf_dict_gets(ctx, grp, "Kids"); + pdf_obj *kids = pdf_dict_get(ctx, grp, PDF_NAME_Kids); len = pdf_array_len(ctx, kids); for (i = 0; i < len; i++) check_off(ctx, doc, pdf_array_get(ctx, kids, i)); - pdf_dict_puts(ctx, obj, "AS", key); + pdf_dict_put(ctx, obj, PDF_NAME_AS, key); } else { @@ -572,9 +543,9 @@ static void toggle_check_box(fz_context *ctx, pdf_document *doc, pdf_obj *obj) * all to the same value. This may cause the group to act like * radio buttons, if each have distinct "On" values */ if (grp) - set_check_grp(ctx, doc, grp, val); + set_check_grp(ctx, doc, grp, key); else - set_check(ctx, doc, obj, val); + set_check(ctx, doc, obj, key); } } @@ -586,7 +557,7 @@ static void toggle_check_box(fz_context *ctx, pdf_document *doc, pdf_obj *obj) fz_try(ctx) { v = pdf_new_string(ctx, doc, val, strlen(val)); - pdf_dict_puts(ctx, grp, "V", v); + pdf_dict_put(ctx, grp, PDF_NAME_V, v); } fz_always(ctx) { @@ -625,7 +596,7 @@ int pdf_pass_event(fz_context *ctx, pdf_document *doc, pdf_page *page, pdf_ui_ev if (annot) { - int f = pdf_to_int(ctx, pdf_dict_gets(ctx, annot->obj, "F")); + int f = pdf_to_int(ctx, pdf_dict_get(ctx, annot->obj, PDF_NAME_F)); if (f & (F_Hidden|F_NoView)) annot = NULL; @@ -805,13 +776,13 @@ pdf_widget *pdf_create_widget(fz_context *ctx, pdf_document *doc, pdf_page *page fz_try(ctx) { pdf_set_field_type(ctx, doc, annot->obj, type); - pdf_dict_puts_drop(ctx, annot->obj, "T", pdf_new_string(ctx, doc, fieldname, strlen(fieldname))); + pdf_dict_put_drop(ctx, annot->obj, PDF_NAME_T, pdf_new_string(ctx, doc, fieldname, strlen(fieldname))); annot->widget_type = type; if (type == PDF_WIDGET_TYPE_SIGNATURE) { int sigflags = (old_sigflags | (SigFlag_SignaturesExist|SigFlag_AppendOnly)); - pdf_dict_putp_drop(ctx, pdf_trailer(ctx, doc), "Root/AcroForm/SigFlags", pdf_new_int(ctx, doc, sigflags)); + pdf_dict_putl_drop(ctx, pdf_trailer(ctx, doc), pdf_new_int(ctx, doc, sigflags), PDF_NAME_Root, PDF_NAME_AcroForm, PDF_NAME_SigFlags, NULL); } /* @@ -822,7 +793,7 @@ pdf_widget *pdf_create_widget(fz_context *ctx, pdf_document *doc, pdf_page *page if (!form) { form = pdf_new_array(ctx, doc, 1); - pdf_dict_putp_drop(ctx, pdf_trailer(ctx, doc), "Root/AcroForm/Fields", form); + pdf_dict_putl_drop(ctx, pdf_trailer(ctx, doc), form, PDF_NAME_Root, PDF_NAME_AcroForm, PDF_NAME_Fields, NULL); } pdf_array_push(ctx, form, annot->obj); /* Cleanup relies on this statement being last */ @@ -834,7 +805,7 @@ pdf_widget *pdf_create_widget(fz_context *ctx, pdf_document *doc, pdf_page *page /* An empty Fields array may have been created, but that is harmless */ if (type == PDF_WIDGET_TYPE_SIGNATURE) - pdf_dict_putp_drop(ctx, pdf_trailer(ctx, doc), "Root/AcroForm/SigFlags", pdf_new_int(ctx, doc, old_sigflags)); + pdf_dict_putl_drop(ctx, pdf_trailer(ctx, doc), pdf_new_int(ctx, doc, old_sigflags), PDF_NAME_Root, PDF_NAME_AcroForm, PDF_NAME_SigFlags, NULL); fz_rethrow(ctx); } @@ -876,7 +847,7 @@ static int set_text_field_value(fz_context *ctx, pdf_document *doc, pdf_obj *fie static void update_checkbox_selector(fz_context *ctx, pdf_document *doc, pdf_obj *field, char *val) { - pdf_obj *kids = pdf_dict_gets(ctx, field, "Kids"); + pdf_obj *kids = pdf_dict_get(ctx, field, PDF_NAME_Kids); if (kids) { @@ -896,9 +867,9 @@ static void update_checkbox_selector(fz_context *ctx, pdf_document *doc, pdf_obj if (pdf_dict_gets(ctx, n, val)) oval = pdf_new_name(ctx, doc, val); else - oval = pdf_new_name(ctx, doc, "Off"); + oval = PDF_NAME_Off; - pdf_dict_puts(ctx, field, "AS", oval); + pdf_dict_put(ctx, field, PDF_NAME_AS, oval); } fz_always(ctx) { @@ -947,7 +918,7 @@ int pdf_field_set_value(fz_context *ctx, pdf_document *doc, pdf_obj *field, char char *pdf_field_border_style(fz_context *ctx, pdf_document *doc, pdf_obj *field) { - char *bs = pdf_to_name(ctx, pdf_dict_getp(ctx, field, "BS/S")); + char *bs = pdf_to_name(ctx, pdf_dict_getl(ctx, field, PDF_NAME_BS, PDF_NAME_S, NULL)); switch (*bs) { @@ -966,21 +937,21 @@ void pdf_field_set_border_style(fz_context *ctx, pdf_document *doc, pdf_obj *fie pdf_obj *val = NULL; if (!strcmp(text, "Solid")) - val = pdf_new_name(ctx, doc, "S"); + val = PDF_NAME_S; else if (!strcmp(text, "Dashed")) - val = pdf_new_name(ctx, doc, "D"); + val = PDF_NAME_D; else if (!strcmp(text, "Beveled")) - val = pdf_new_name(ctx, doc, "B"); + val = PDF_NAME_B; else if (!strcmp(text, "Inset")) - val = pdf_new_name(ctx, doc, "I"); + val = PDF_NAME_I; else if (!strcmp(text, "Underline")) - val = pdf_new_name(ctx, doc, "U"); + val = PDF_NAME_U; else return; fz_try(ctx); { - pdf_dict_putp(ctx, field, "BS/S", val); + pdf_dict_putl(ctx, field, val, PDF_NAME_BS, PDF_NAME_S, NULL); pdf_field_mark_dirty(ctx, doc, field); } fz_always(ctx) @@ -1001,7 +972,7 @@ void pdf_field_set_button_caption(fz_context *ctx, pdf_document *doc, pdf_obj *f { if (pdf_field_type(ctx, doc, field) == PDF_WIDGET_TYPE_PUSHBUTTON) { - pdf_dict_putp(ctx, field, "MK/CA", val); + pdf_dict_putl(ctx, field, val, PDF_NAME_MK, PDF_NAME_CA, NULL); pdf_field_mark_dirty(ctx, doc, field); } } @@ -1023,10 +994,10 @@ int pdf_field_display(fz_context *ctx, pdf_document *doc, pdf_obj *field) /* Base response on first of children. Not ideal, * but not clear how to handle children with * differing values */ - while ((kids = pdf_dict_gets(ctx, field, "Kids")) != NULL) + while ((kids = pdf_dict_get(ctx, field, PDF_NAME_Kids)) != NULL) field = pdf_array_get(ctx, kids, 0); - f = pdf_to_int(ctx, pdf_dict_gets(ctx, field, "F")); + f = pdf_to_int(ctx, pdf_dict_get(ctx, field, PDF_NAME_F)); if (f & F_Hidden) { @@ -1055,8 +1026,8 @@ int pdf_field_display(fz_context *ctx, pdf_document *doc, pdf_obj *field) static char *get_field_name(fz_context *ctx, pdf_document *doc, pdf_obj *field, int spare) { char *res = NULL; - pdf_obj *parent = pdf_dict_gets(ctx, field, "Parent"); - char *lname = pdf_to_str_buf(ctx, pdf_dict_gets(ctx, field, "T")); + pdf_obj *parent = pdf_dict_get(ctx, field, PDF_NAME_Parent); + char *lname = pdf_to_str_buf(ctx, pdf_dict_get(ctx, field, PDF_NAME_T)); int llen = strlen(lname); /* @@ -1094,12 +1065,12 @@ char *pdf_field_name(fz_context *ctx, pdf_document *doc, pdf_obj *field) void pdf_field_set_display(fz_context *ctx, pdf_document *doc, pdf_obj *field, int d) { - pdf_obj *kids = pdf_dict_gets(ctx, field, "Kids"); + pdf_obj *kids = pdf_dict_get(ctx, field, PDF_NAME_Kids); if (!kids) { int mask = (F_Hidden|F_Print|F_NoView); - int f = pdf_to_int(ctx, pdf_dict_gets(ctx, field, "F")) & ~mask; + int f = pdf_to_int(ctx, pdf_dict_get(ctx, field, PDF_NAME_F)) & ~mask; pdf_obj *fo = NULL; switch (d) @@ -1121,7 +1092,7 @@ void pdf_field_set_display(fz_context *ctx, pdf_document *doc, pdf_obj *field, i fz_try(ctx) { fo = pdf_new_int(ctx, doc, f); - pdf_dict_puts(ctx, field, "F", fo); + pdf_dict_put(ctx, field, PDF_NAME_F, fo); } fz_always(ctx) { @@ -1146,7 +1117,7 @@ void pdf_field_set_fill_color(fz_context *ctx, pdf_document *doc, pdf_obj *field /* col == NULL mean transparent, but we can simply pass it on as with * non-NULL values because pdf_dict_putp interprets a NULL value as * delete */ - pdf_dict_putp(ctx, field, "MK/BG", col); + pdf_dict_putl(ctx, field, col, PDF_NAME_MK, PDF_NAME_BG, NULL); pdf_field_mark_dirty(ctx, doc, field); } @@ -1154,7 +1125,7 @@ void pdf_field_set_text_color(fz_context *ctx, pdf_document *doc, pdf_obj *field { pdf_da_info di; fz_buffer *fzbuf = NULL; - char *da = pdf_to_str_buf(ctx, pdf_get_inheritable(ctx, doc, field, "DA")); + char *da = pdf_to_str_buf(ctx, pdf_get_inheritable(ctx, doc, field, PDF_NAME_DA)); unsigned char *buf; int len; pdf_obj *daobj = NULL; @@ -1179,7 +1150,7 @@ void pdf_field_set_text_color(fz_context *ctx, pdf_document *doc, pdf_obj *field pdf_fzbuf_print_da(ctx, fzbuf, &di); len = fz_buffer_storage(ctx, fzbuf, &buf); daobj = pdf_new_string(ctx, doc, (char *)buf, len); - pdf_dict_puts(ctx, field, "DA", daobj); + pdf_dict_put(ctx, field, PDF_NAME_DA, daobj); pdf_field_mark_dirty(ctx, doc, field); } fz_always(ctx) @@ -1227,7 +1198,7 @@ int pdf_text_widget_max_len(fz_context *ctx, pdf_document *doc, pdf_widget *tw) { pdf_annot *annot = (pdf_annot *)tw; - return pdf_to_int(ctx, pdf_get_inheritable(ctx, doc, annot->obj, "MaxLen")); + return pdf_to_int(ctx, pdf_get_inheritable(ctx, doc, annot->obj, PDF_NAME_MaxLen)); } int pdf_text_widget_content_type(fz_context *ctx, pdf_document *doc, pdf_widget *tw) @@ -1239,7 +1210,7 @@ int pdf_text_widget_content_type(fz_context *ctx, pdf_document *doc, pdf_widget fz_var(code); fz_try(ctx) { - code = pdf_get_string_or_stream(ctx, doc, pdf_dict_getp(ctx, annot->obj, "AA/F/JS")); + code = pdf_get_string_or_stream(ctx, doc, pdf_dict_getl(ctx, annot->obj, PDF_NAME_AA, PDF_NAME_F, PDF_NAME_JS, NULL)); if (code) { if (strstr(code, "AFNumber_Format")) @@ -1266,7 +1237,7 @@ int pdf_text_widget_content_type(fz_context *ctx, pdf_document *doc, pdf_widget static int run_keystroke(fz_context *ctx, pdf_document *doc, pdf_obj *field, char **text) { - pdf_obj *k = pdf_dict_getp(ctx, field, "AA/K"); + pdf_obj *k = pdf_dict_getl(ctx, field, PDF_NAME_AA, PDF_NAME_K, NULL); if (k && doc->js) { @@ -1314,7 +1285,7 @@ int pdf_choice_widget_options(fz_context *ctx, pdf_document *doc, pdf_widget *tw if (!annot) return 0; - optarr = pdf_dict_gets(ctx, annot->obj, "Opt"); + optarr = pdf_dict_get(ctx, annot->obj, PDF_NAME_Opt); n = pdf_array_len(ctx, optarr); if (opts) @@ -1353,7 +1324,7 @@ int pdf_choice_widget_value(fz_context *ctx, pdf_document *doc, pdf_widget *tw, if (!annot) return 0; - optarr = pdf_dict_gets(ctx, annot->obj, "V"); + optarr = pdf_dict_get(ctx, annot->obj, PDF_NAME_V); if (pdf_is_string(ctx, optarr)) { @@ -1408,18 +1379,18 @@ void pdf_choice_widget_set_value(fz_context *ctx, pdf_document *doc, pdf_widget opt = NULL; } - pdf_dict_puts(ctx, annot->obj, "V", optarr); + pdf_dict_put(ctx, annot->obj, PDF_NAME_V, optarr); pdf_drop_obj(ctx, optarr); } else { opt = pdf_new_string(ctx, doc, opts[0], strlen(opts[0])); - pdf_dict_puts(ctx, annot->obj, "V", opt); + pdf_dict_put(ctx, annot->obj, PDF_NAME_V, opt); pdf_drop_obj(ctx, opt); } /* FIXME: when n > 1, we should be regenerating the indexes */ - pdf_dict_dels(ctx, annot->obj, "I"); + pdf_dict_del(ctx, annot->obj, PDF_NAME_I); pdf_field_mark_dirty(ctx, doc, annot->obj); if (pdf_field_dirties_document(ctx, doc, annot->obj)) @@ -1436,7 +1407,7 @@ void pdf_choice_widget_set_value(fz_context *ctx, pdf_document *doc, pdf_widget int pdf_signature_widget_byte_range(fz_context *ctx, pdf_document *doc, pdf_widget *widget, int (*byte_range)[2]) { pdf_annot *annot = (pdf_annot *)widget; - pdf_obj *br = pdf_dict_getp(ctx, annot->obj, "V/ByteRange"); + pdf_obj *br = pdf_dict_getl(ctx, annot->obj, PDF_NAME_V, PDF_NAME_ByteRange, NULL); int i, n = pdf_array_len(ctx, br)/2; if (byte_range) @@ -1454,7 +1425,7 @@ int pdf_signature_widget_byte_range(fz_context *ctx, pdf_document *doc, pdf_widg int pdf_signature_widget_contents(fz_context *ctx, pdf_document *doc, pdf_widget *widget, char **contents) { pdf_annot *annot = (pdf_annot *)widget; - pdf_obj *c = pdf_dict_getp(ctx, annot->obj, "V/Contents"); + pdf_obj *c = pdf_dict_getl(ctx, annot->obj, PDF_NAME_V, PDF_NAME_Contents, NULL); if (contents) *contents = pdf_to_str_buf(ctx, c); return pdf_to_str_len(ctx, c); @@ -1474,7 +1445,7 @@ void pdf_signature_set_value(fz_context *ctx, pdf_document *doc, pdf_obj *field, vnum = pdf_create_object(ctx, doc); indv = pdf_new_indirect(ctx, doc, vnum, 0); - pdf_dict_puts_drop(ctx, field, "V", indv); + pdf_dict_put_drop(ctx, field, PDF_NAME_V, indv); fz_var(v); fz_try(ctx) @@ -1492,13 +1463,13 @@ void pdf_signature_set_value(fz_context *ctx, pdf_document *doc, pdf_obj *field, } byte_range = pdf_new_array(ctx, doc, 4); - pdf_dict_puts_drop(ctx, v, "ByteRange", byte_range); + pdf_dict_put_drop(ctx, v, PDF_NAME_ByteRange, byte_range); contents = pdf_new_string(ctx, doc, buf, sizeof(buf)); - pdf_dict_puts_drop(ctx, v, "Contents", contents); + pdf_dict_put_drop(ctx, v, PDF_NAME_Contents, contents); - pdf_dict_puts_drop(ctx, v, "Filter", pdf_new_name(ctx, doc, "Adobe.PPKLite")); - pdf_dict_puts_drop(ctx, v, "SubFilter", pdf_new_name(ctx, doc, "adbe.pkcs7.detached")); + pdf_dict_put_drop(ctx, v, PDF_NAME_Filter, PDF_NAME_Adobe_PPKLite); + pdf_dict_put_drop(ctx, v, PDF_NAME_SubFilter, PDF_NAME_adbe_pkcs7_detached); /* Record details within the document structure so that contents * and byte_range can be updated with their correct values at diff --git a/source/pdf/pdf-function.c b/source/pdf/pdf-function.c index 7ead09ca..1969cbba 100644 --- a/source/pdf/pdf-function.c +++ b/source/pdf/pdf-function.c @@ -919,7 +919,7 @@ load_sample_func(fz_context *ctx, pdf_document *doc, pdf_function *func, pdf_obj func->u.sa.samples = NULL; - obj = pdf_dict_gets(ctx, dict, "Size"); + obj = pdf_dict_get(ctx, dict, PDF_NAME_Size); if (pdf_array_len(ctx, obj) < func->base.m) fz_throw(ctx, FZ_ERROR_GENERIC, "too few sample function dimension sizes"); if (pdf_array_len(ctx, obj) > func->base.m) @@ -934,7 +934,7 @@ load_sample_func(fz_context *ctx, pdf_document *doc, pdf_function *func, pdf_obj } } - obj = pdf_dict_gets(ctx, dict, "BitsPerSample"); + obj = pdf_dict_get(ctx, dict, PDF_NAME_BitsPerSample); func->u.sa.bps = bps = pdf_to_int(ctx, obj); for (i = 0; i < func->base.m; i++) @@ -942,7 +942,7 @@ load_sample_func(fz_context *ctx, pdf_document *doc, pdf_function *func, pdf_obj func->u.sa.encode[i][0] = 0; func->u.sa.encode[i][1] = func->u.sa.size[i] - 1; } - obj = pdf_dict_gets(ctx, dict, "Encode"); + obj = pdf_dict_get(ctx, dict, PDF_NAME_Encode); if (pdf_is_array(ctx, obj)) { int ranges = fz_mini(func->base.m, pdf_array_len(ctx, obj) / 2); @@ -962,7 +962,7 @@ load_sample_func(fz_context *ctx, pdf_document *doc, pdf_function *func, pdf_obj func->u.sa.decode[i][1] = func->range[i][1]; } - obj = pdf_dict_gets(ctx, dict, "Decode"); + obj = pdf_dict_get(ctx, dict, PDF_NAME_Decode); if (pdf_is_array(ctx, obj)) { int ranges = fz_mini(func->base.n, pdf_array_len(ctx, obj) / 2); @@ -1141,7 +1141,7 @@ load_exponential_func(fz_context *ctx, pdf_document *doc, pdf_function *func, pd fz_warn(ctx, "exponential functions have at most one input"); func->base.m = 1; - obj = pdf_dict_gets(ctx, dict, "N"); + obj = pdf_dict_get(ctx, dict, PDF_NAME_N); func->u.e.n = pdf_to_real(ctx, obj); /* See exponential functions (PDF 1.7 section 3.9.2) */ @@ -1167,7 +1167,7 @@ load_exponential_func(fz_context *ctx, pdf_document *doc, pdf_function *func, pd func->u.e.c1[i] = 1; } - obj = pdf_dict_gets(ctx, dict, "C0"); + obj = pdf_dict_get(ctx, dict, PDF_NAME_C0); if (pdf_is_array(ctx, obj)) { int ranges = fz_mini(func->base.n, pdf_array_len(ctx, obj)); @@ -1178,7 +1178,7 @@ load_exponential_func(fz_context *ctx, pdf_document *doc, pdf_function *func, pd func->u.e.c0[i] = pdf_to_real(ctx, pdf_array_get(ctx, obj, i)); } - obj = pdf_dict_gets(ctx, dict, "C1"); + obj = pdf_dict_get(ctx, dict, PDF_NAME_C1); if (pdf_is_array(ctx, obj)) { int ranges = fz_mini(func->base.n, pdf_array_len(ctx, obj)); @@ -1232,7 +1232,7 @@ load_stitching_func(fz_context *ctx, pdf_document *doc, pdf_function *func, pdf_ fz_warn(ctx, "stitching functions have at most one input"); func->base.m = 1; - obj = pdf_dict_gets(ctx, dict, "Functions"); + obj = pdf_dict_get(ctx, dict, PDF_NAME_Functions); if (!pdf_is_array(ctx, obj)) fz_throw(ctx, FZ_ERROR_GENERIC, "stitching function has no input functions"); @@ -1269,7 +1269,7 @@ load_stitching_func(fz_context *ctx, pdf_document *doc, pdf_function *func, pdf_ fz_rethrow(ctx); } - obj = pdf_dict_gets(ctx, dict, "Bounds"); + obj = pdf_dict_get(ctx, dict, PDF_NAME_Bounds); if (!pdf_is_array(ctx, obj)) fz_throw(ctx, FZ_ERROR_GENERIC, "stitching function has no bounds"); { @@ -1297,7 +1297,7 @@ load_stitching_func(fz_context *ctx, pdf_document *doc, pdf_function *func, pdf_ func->u.st.encode[i * 2 + 1] = 0; } - obj = pdf_dict_gets(ctx, dict, "Encode"); + obj = pdf_dict_get(ctx, dict, PDF_NAME_Encode); if (pdf_is_array(ctx, obj)) { int ranges = fz_mini(k, pdf_array_len(ctx, obj) / 2); @@ -1645,11 +1645,11 @@ pdf_load_function(fz_context *ctx, pdf_document *doc, pdf_obj *dict, int in, int func->base.debug = pdf_debug_function; #endif - obj = pdf_dict_gets(ctx, dict, "FunctionType"); + obj = pdf_dict_get(ctx, dict, PDF_NAME_FunctionType); func->type = pdf_to_int(ctx, obj); /* required for all */ - obj = pdf_dict_gets(ctx, dict, "Domain"); + obj = pdf_dict_get(ctx, dict, PDF_NAME_Domain); func->base.m = fz_clampi(pdf_array_len(ctx, obj) / 2, 1, FZ_FN_MAXM); for (i = 0; i < func->base.m; i++) { @@ -1658,7 +1658,7 @@ pdf_load_function(fz_context *ctx, pdf_document *doc, pdf_obj *dict, int in, int } /* required for type0 and type4, optional otherwise */ - obj = pdf_dict_gets(ctx, dict, "Range"); + obj = pdf_dict_get(ctx, dict, PDF_NAME_Range); if (pdf_is_array(ctx, obj)) { func->has_range = 1; diff --git a/source/pdf/pdf-image.c b/source/pdf/pdf-image.c index 30f96dc8..87fa8f38 100644 --- a/source/pdf/pdf-image.c +++ b/source/pdf/pdf-image.c @@ -55,13 +55,13 @@ pdf_load_image_imp(fz_context *ctx, pdf_document *doc, pdf_obj *rdb, pdf_obj *di break; /* Out of fz_try */ } - w = pdf_to_int(ctx, pdf_dict_getsa(ctx, dict, "Width", "W")); - h = pdf_to_int(ctx, pdf_dict_getsa(ctx, dict, "Height", "H")); - bpc = pdf_to_int(ctx, pdf_dict_getsa(ctx, dict, "BitsPerComponent", "BPC")); + w = pdf_to_int(ctx, pdf_dict_geta(ctx, dict, PDF_NAME_Width, PDF_NAME_W)); + h = pdf_to_int(ctx, pdf_dict_geta(ctx, dict, PDF_NAME_Height, PDF_NAME_H)); + bpc = pdf_to_int(ctx, pdf_dict_geta(ctx, dict, PDF_NAME_BitsPerComponent, PDF_NAME_BPC)); if (bpc == 0) bpc = 8; - imagemask = pdf_to_bool(ctx, pdf_dict_getsa(ctx, dict, "ImageMask", "IM")); - interpolate = pdf_to_bool(ctx, pdf_dict_getsa(ctx, dict, "Interpolate", "I")); + imagemask = pdf_to_bool(ctx, pdf_dict_geta(ctx, dict, PDF_NAME_ImageMask, PDF_NAME_IM)); + interpolate = pdf_to_bool(ctx, pdf_dict_geta(ctx, dict, PDF_NAME_Interpolate, PDF_NAME_I)); indexed = 0; usecolorkey = 0; @@ -82,13 +82,13 @@ pdf_load_image_imp(fz_context *ctx, pdf_document *doc, pdf_obj *rdb, pdf_obj *di if (h > (1 << 16)) fz_throw(ctx, FZ_ERROR_GENERIC, "image is too high"); - obj = pdf_dict_getsa(ctx, dict, "ColorSpace", "CS"); + obj = pdf_dict_geta(ctx, dict, PDF_NAME_ColorSpace, PDF_NAME_CS); if (obj && !imagemask && !forcemask) { /* colorspace resource lookup is only done for inline images */ if (pdf_is_name(ctx, obj)) { - res = pdf_dict_get(ctx, pdf_dict_gets(ctx, rdb, "ColorSpace"), obj); + res = pdf_dict_get(ctx, pdf_dict_get(ctx, rdb, PDF_NAME_ColorSpace), obj); if (res) obj = res; } @@ -103,7 +103,7 @@ pdf_load_image_imp(fz_context *ctx, pdf_document *doc, pdf_obj *rdb, pdf_obj *di n = 1; } - obj = pdf_dict_getsa(ctx, dict, "Decode", "D"); + obj = pdf_dict_geta(ctx, dict, PDF_NAME_Decode, PDF_NAME_D); if (obj) { for (i = 0; i < n * 2; i++) @@ -116,7 +116,7 @@ pdf_load_image_imp(fz_context *ctx, pdf_document *doc, pdf_obj *rdb, pdf_obj *di decode[i] = i & 1 ? maxval : 0; } - obj = pdf_dict_getsa(ctx, dict, "SMask", "Mask"); + obj = pdf_dict_geta(ctx, dict, PDF_NAME_SMask, PDF_NAME_Mask); if (pdf_is_dict(ctx, obj)) { /* Not allowed for inline images or soft masks */ @@ -127,7 +127,7 @@ pdf_load_image_imp(fz_context *ctx, pdf_document *doc, pdf_obj *rdb, pdf_obj *di else { mask = pdf_load_image_imp(ctx, doc, rdb, obj, NULL, 1); - obj = pdf_dict_gets(ctx, obj, "Matte"); + obj = pdf_dict_get(ctx, obj, PDF_NAME_Matte); if (pdf_is_array(ctx, obj)) { usecolorkey = 1; @@ -191,12 +191,12 @@ pdf_is_jpx_image(fz_context *ctx, pdf_obj *dict) pdf_obj *filter; int i, n; - filter = pdf_dict_gets(ctx, dict, "Filter"); - if (!strcmp(pdf_to_name(ctx, filter), "JPXDecode")) + filter = pdf_dict_get(ctx, dict, PDF_NAME_Filter); + if (pdf_name_eq(ctx, filter, PDF_NAME_JPXDecode)) return 1; n = pdf_array_len(ctx, filter); for (i = 0; i < n; i++) - if (!strcmp(pdf_to_name(ctx, pdf_array_get(ctx, filter, i)), "JPXDecode")) + if (pdf_name_eq(ctx, pdf_array_get(ctx, filter, i), PDF_NAME_JPXDecode)) return 1; return 0; } @@ -222,7 +222,7 @@ pdf_load_jpx(fz_context *ctx, pdf_document *doc, pdf_obj *dict, int forcemask) /* FIXME: We can't handle decode arrays for indexed images currently */ fz_try(ctx) { - obj = pdf_dict_gets(ctx, dict, "ColorSpace"); + obj = pdf_dict_get(ctx, dict, PDF_NAME_ColorSpace); if (obj) { colorspace = pdf_load_colorspace(ctx, doc, obj); @@ -231,7 +231,7 @@ pdf_load_jpx(fz_context *ctx, pdf_document *doc, pdf_obj *dict, int forcemask) pix = fz_load_jpx(ctx, buf->data, buf->len, colorspace, indexed); - obj = pdf_dict_getsa(ctx, dict, "SMask", "Mask"); + obj = pdf_dict_geta(ctx, dict, PDF_NAME_SMask, PDF_NAME_Mask); if (pdf_is_dict(ctx, obj)) { if (forcemask) @@ -240,7 +240,7 @@ pdf_load_jpx(fz_context *ctx, pdf_document *doc, pdf_obj *dict, int forcemask) mask = pdf_load_image_imp(ctx, doc, NULL, obj, NULL, 1); } - obj = pdf_dict_getsa(ctx, dict, "Decode", "D"); + obj = pdf_dict_geta(ctx, dict, PDF_NAME_Decode, PDF_NAME_D); if (obj && !indexed) { float decode[FZ_MAX_COLORS * 2]; diff --git a/source/pdf/pdf-interpret.c b/source/pdf/pdf-interpret.c index 0961b742..40aa51ad 100644 --- a/source/pdf/pdf-interpret.c +++ b/source/pdf/pdf-interpret.c @@ -104,8 +104,7 @@ static int pdf_is_hidden_ocg(fz_context *ctx, pdf_ocg_descriptor *desc, pdf_obj *rdb, const char *event, pdf_obj *ocg) { char event_state[16]; - pdf_obj *obj, *obj2; - char *type; + pdf_obj *obj, *obj2, *type; /* Avoid infinite recursions */ if (pdf_obj_marked(ctx, ocg)) @@ -122,7 +121,7 @@ pdf_is_hidden_ocg(fz_context *ctx, pdf_ocg_descriptor *desc, pdf_obj *rdb, const /* If we've been handed a name, look it up in the properties. */ if (pdf_is_name(ctx, ocg)) { - ocg = pdf_dict_gets(ctx, pdf_dict_gets(ctx, rdb, "Properties"), pdf_to_name(ctx, ocg)); + ocg = pdf_dict_get(ctx, pdf_dict_get(ctx, rdb, PDF_NAME_Properties), ocg); } /* If we haven't been given an ocg at all, then we're visible */ if (!ocg) @@ -131,9 +130,9 @@ pdf_is_hidden_ocg(fz_context *ctx, pdf_ocg_descriptor *desc, pdf_obj *rdb, const fz_strlcpy(event_state, event, sizeof event_state); fz_strlcat(event_state, "State", sizeof event_state); - type = pdf_to_name(ctx, pdf_dict_gets(ctx, ocg, "Type")); + type = pdf_dict_get(ctx, ocg, PDF_NAME_Type); - if (strcmp(type, "OCG") == 0) + if (pdf_name_eq(ctx, type, PDF_NAME_OCG)) { /* An Optional Content Group */ int default_value = 0; @@ -141,6 +140,7 @@ pdf_is_hidden_ocg(fz_context *ctx, pdf_ocg_descriptor *desc, pdf_obj *rdb, const int gen = pdf_to_gen(ctx, ocg); int len = desc->len; int i; + pdf_obj *es; /* by default an OCG is visible, unless it's explicitly hidden */ for (i = 0; i < len; i++) @@ -154,7 +154,7 @@ pdf_is_hidden_ocg(fz_context *ctx, pdf_ocg_descriptor *desc, pdf_obj *rdb, const /* Check Intents; if our intent is not part of the set given * by the current config, we should ignore it. */ - obj = pdf_dict_gets(ctx, ocg, "Intent"); + obj = pdf_dict_get(ctx, ocg, PDF_NAME_Intent); if (pdf_is_name(ctx, obj)) { /* If it doesn't match, it's hidden */ @@ -190,7 +190,7 @@ pdf_is_hidden_ocg(fz_context *ctx, pdf_ocg_descriptor *desc, pdf_obj *rdb, const * correspond to entries in the AS list in the OCG config. * Given that we don't handle Zoom or User, or Language * dicts, this is not really a problem. */ - obj = pdf_dict_gets(ctx, ocg, "Usage"); + obj = pdf_dict_get(ctx, ocg, PDF_NAME_Usage); if (!pdf_is_dict(ctx, obj)) return default_value; /* FIXME: Should look at Zoom (and return hidden if out of @@ -198,39 +198,40 @@ pdf_is_hidden_ocg(fz_context *ctx, pdf_ocg_descriptor *desc, pdf_obj *rdb, const /* FIXME: Could provide hooks to the caller to check if * User is appropriate - if not return hidden. */ obj2 = pdf_dict_gets(ctx, obj, event); - if (strcmp(pdf_to_name(ctx, pdf_dict_gets(ctx, obj2, event_state)), "OFF") == 0) + es = pdf_dict_gets(ctx, obj2, event_state); + if (pdf_name_eq(ctx, es, PDF_NAME_OFF)) { return 1; } - if (strcmp(pdf_to_name(ctx, pdf_dict_gets(ctx, obj2, event_state)), "ON") == 0) + if (pdf_name_eq(ctx, es, PDF_NAME_ON)) { return 0; } return default_value; } - else if (strcmp(type, "OCMD") == 0) + else if (pdf_name_eq(ctx, type, PDF_NAME_OCMD)) { /* An Optional Content Membership Dictionary */ - char *name; + pdf_obj *name; int combine, on; - obj = pdf_dict_gets(ctx, ocg, "VE"); + obj = pdf_dict_get(ctx, ocg, PDF_NAME_VE); if (pdf_is_array(ctx, obj)) { /* FIXME: Calculate visibility from array */ return 0; } - name = pdf_to_name(ctx, pdf_dict_gets(ctx, ocg, "P")); + name = pdf_dict_get(ctx, ocg, PDF_NAME_P); /* Set combine; Bit 0 set => AND, Bit 1 set => true means * Off, otherwise true means On */ - if (strcmp(name, "AllOn") == 0) + if (pdf_name_eq(ctx, name, PDF_NAME_AllOn)) { combine = 1; } - else if (strcmp(name, "AnyOff") == 0) + else if (pdf_name_eq(ctx, name, PDF_NAME_AnyOff)) { combine = 2; } - else if (strcmp(name, "AllOff") == 0) + else if (pdf_name_eq(ctx, name, PDF_NAME_AllOff)) { combine = 3; } @@ -243,7 +244,7 @@ pdf_is_hidden_ocg(fz_context *ctx, pdf_ocg_descriptor *desc, pdf_obj *rdb, const return 0; /* Should never happen */ fz_try(ctx) { - obj = pdf_dict_gets(ctx, ocg, "OCGs"); + obj = pdf_dict_get(ctx, ocg, PDF_NAME_OCGs); on = combine & 1; if (pdf_is_array(ctx, obj)) { int i, len; @@ -343,23 +344,23 @@ pdf_process_extgstate(fz_context *ctx, pdf_processor *proc, pdf_csi *csi, pdf_ob { pdf_obj *obj; - obj = pdf_dict_gets(ctx, dict, "LW"); + obj = pdf_dict_get(ctx, dict, PDF_NAME_LW); if (pdf_is_number(ctx, obj) && proc->op_w) proc->op_w(ctx, proc, pdf_to_real(ctx, obj)); - obj = pdf_dict_gets(ctx, dict, "LC"); + obj = pdf_dict_get(ctx, dict, PDF_NAME_LC); if (pdf_is_int(ctx, obj) && proc->op_J) proc->op_J(ctx, proc, pdf_to_int(ctx, obj)); - obj = pdf_dict_gets(ctx, dict, "LJ"); + obj = pdf_dict_get(ctx, dict, PDF_NAME_LJ); if (pdf_is_int(ctx, obj) && proc->op_j) proc->op_j(ctx, proc, pdf_to_int(ctx, obj)); - obj = pdf_dict_gets(ctx, dict, "ML"); + obj = pdf_dict_get(ctx, dict, PDF_NAME_ML); if (pdf_is_number(ctx, obj) && proc->op_M) proc->op_M(ctx, proc, pdf_to_real(ctx, obj)); - obj = pdf_dict_gets(ctx, dict, "D"); + obj = pdf_dict_get(ctx, dict, PDF_NAME_D); if (pdf_is_array(ctx, obj) && proc->op_d) { pdf_obj *dash_array = pdf_array_get(ctx, obj, 0); @@ -367,15 +368,15 @@ pdf_process_extgstate(fz_context *ctx, pdf_processor *proc, pdf_csi *csi, pdf_ob proc->op_d(ctx, proc, dash_array, pdf_to_real(ctx, dash_phase)); } - obj = pdf_dict_gets(ctx, dict, "RI"); + obj = pdf_dict_get(ctx, dict, PDF_NAME_RI); if (pdf_is_name(ctx, obj) && proc->op_ri) proc->op_ri(ctx, proc, pdf_to_name(ctx, obj)); - obj = pdf_dict_gets(ctx, dict, "FL"); + obj = pdf_dict_get(ctx, dict, PDF_NAME_FL); if (pdf_is_number(ctx, obj) && proc->op_i) proc->op_i(ctx, proc, pdf_to_real(ctx, obj)); - obj = pdf_dict_gets(ctx, dict, "Font"); + obj = pdf_dict_get(ctx, dict, PDF_NAME_Font); if (pdf_is_array(ctx, obj) && proc->op_Tf) { pdf_obj *font_ref = pdf_array_get(ctx, obj, 0); @@ -391,35 +392,35 @@ pdf_process_extgstate(fz_context *ctx, pdf_processor *proc, pdf_csi *csi, pdf_ob /* transfer functions */ - obj = pdf_dict_gets(ctx, dict, "TR2"); + obj = pdf_dict_get(ctx, dict, PDF_NAME_TR2); if (pdf_is_name(ctx, obj)) - if (strcmp(pdf_to_name(ctx, obj), "Identity") && strcmp(pdf_to_name(ctx, obj), "Default")) + if (!pdf_name_eq(ctx, obj, PDF_NAME_Identity) && !pdf_name_eq(ctx, obj, PDF_NAME_Default)) fz_warn(ctx, "ignoring transfer function"); if (!obj) /* TR is ignored in the presence of TR2 */ { - pdf_obj *tr = pdf_dict_gets(ctx, dict, "TR"); + pdf_obj *tr = pdf_dict_get(ctx, dict, PDF_NAME_TR); if (pdf_is_name(ctx, tr)) - if (strcmp(pdf_to_name(ctx, tr), "Identity")) + if (!pdf_name_eq(ctx, tr, PDF_NAME_Identity)) fz_warn(ctx, "ignoring transfer function"); } /* transparency state */ - obj = pdf_dict_gets(ctx, dict, "CA"); + obj = pdf_dict_get(ctx, dict, PDF_NAME_CA); if (pdf_is_number(ctx, obj) && proc->op_gs_CA) proc->op_gs_CA(ctx, proc, pdf_to_real(ctx, obj)); - obj = pdf_dict_gets(ctx, dict, "ca"); + obj = pdf_dict_get(ctx, dict, PDF_NAME_ca); if (pdf_is_number(ctx, obj) && proc->op_gs_ca) proc->op_gs_ca(ctx, proc, pdf_to_real(ctx, obj)); - obj = pdf_dict_gets(ctx, dict, "BM"); + obj = pdf_dict_get(ctx, dict, PDF_NAME_BM); if (pdf_is_array(ctx, obj)) obj = pdf_array_get(ctx, obj, 0); if (pdf_is_name(ctx, obj) && proc->op_gs_BM) proc->op_gs_BM(ctx, proc, pdf_to_name(ctx, obj)); - obj = pdf_dict_gets(ctx, dict, "SMask"); + obj = pdf_dict_get(ctx, dict, PDF_NAME_SMask); if (proc->op_gs_SMask) { if (pdf_is_dict(ctx, obj)) @@ -432,7 +433,7 @@ pdf_process_extgstate(fz_context *ctx, pdf_processor *proc, pdf_csi *csi, pdf_ob fz_var(xobj); - group = pdf_dict_gets(ctx, obj, "G"); + group = pdf_dict_get(ctx, obj, PDF_NAME_G); if (!group) fz_throw(ctx, FZ_ERROR_GENERIC, "cannot load softmask xobject (%d %d R)", pdf_to_num(ctx, obj), pdf_to_gen(ctx, obj)); xobj = pdf_load_xobject(ctx, csi->doc, group); @@ -446,21 +447,21 @@ pdf_process_extgstate(fz_context *ctx, pdf_processor *proc, pdf_csi *csi, pdf_ob for (k = 0; k < colorspace->n; k++) softmask_bc[k] = 0; - bc = pdf_dict_gets(ctx, obj, "BC"); + bc = pdf_dict_get(ctx, obj, PDF_NAME_BC); if (pdf_is_array(ctx, bc)) { for (k = 0; k < colorspace->n; k++) softmask_bc[k] = pdf_to_real(ctx, pdf_array_get(ctx, bc, k)); } - s = pdf_dict_gets(ctx, obj, "S"); - if (pdf_is_name(ctx, s) && !strcmp(pdf_to_name(ctx, s), "Luminosity")) + s = pdf_dict_get(ctx, obj, PDF_NAME_S); + if (pdf_name_eq(ctx, s, PDF_NAME_Luminosity)) luminosity = 1; else luminosity = 0; - tr = pdf_dict_gets(ctx, obj, "TR"); - if (tr && strcmp(pdf_to_name(ctx, tr), "Identity")) + tr = pdf_dict_get(ctx, obj, PDF_NAME_TR); + if (tr && !pdf_name_eq(ctx, tr, PDF_NAME_Identity)) fz_warn(ctx, "ignoring transfer function"); proc->op_gs_SMask(ctx, proc, xobj, csi->rdb, softmask_bc, luminosity); @@ -474,7 +475,7 @@ pdf_process_extgstate(fz_context *ctx, pdf_processor *proc, pdf_csi *csi, pdf_ob fz_rethrow(ctx); } } - else if (pdf_is_name(ctx, obj) && !strcmp(pdf_to_name(ctx, obj), "None")) + else if (pdf_is_name(ctx, obj) && pdf_name_eq(ctx, obj, PDF_NAME_None)) { proc->op_gs_SMask(ctx, proc, NULL, NULL, NULL, 0); } @@ -486,22 +487,26 @@ pdf_process_Do(fz_context *ctx, pdf_processor *proc, pdf_csi *csi) { pdf_obj *xres, *xobj, *subtype; - xres = pdf_dict_gets(ctx, csi->rdb, "XObject"); + xres = pdf_dict_get(ctx, csi->rdb, PDF_NAME_XObject); if (!xres) fz_throw(ctx, FZ_ERROR_GENERIC, "cannot find XObject dictionary"); xobj = pdf_dict_gets(ctx, xres, csi->name); if (!xobj) fz_throw(ctx, FZ_ERROR_GENERIC, "cannot find XObject resource '%s'", csi->name); - subtype = pdf_dict_gets(ctx, xobj, "Subtype"); - if (!strcmp(pdf_to_name(ctx, subtype), "Form") && pdf_dict_gets(ctx, xobj, "Subtype2")) - subtype = pdf_dict_gets(ctx, xobj, "Subtype2"); + subtype = pdf_dict_get(ctx, xobj, PDF_NAME_Subtype); + if (pdf_name_eq(ctx, subtype, PDF_NAME_Form)) + { + pdf_obj *st = pdf_dict_get(ctx, xobj, PDF_NAME_Subtype2); + if (st) + subtype = st; + } if (!pdf_is_name(ctx, subtype)) fz_throw(ctx, FZ_ERROR_GENERIC, "no XObject subtype specified"); - if (pdf_is_hidden_ocg(ctx, csi->doc->ocg, csi->rdb, proc->event, pdf_dict_gets(ctx, xobj, "OC"))) + if (pdf_is_hidden_ocg(ctx, csi->doc->ocg, csi->rdb, proc->event, pdf_dict_get(ctx, xobj, PDF_NAME_OC))) return; - if (!strcmp(pdf_to_name(ctx, subtype), "Form")) + if (pdf_name_eq(ctx, subtype, PDF_NAME_Form)) { if (proc->op_Do_form) { @@ -516,7 +521,7 @@ pdf_process_Do(fz_context *ctx, pdf_processor *proc, pdf_csi *csi) } } - else if (!strcmp(pdf_to_name(ctx, subtype), "Image")) + else if (pdf_name_eq(ctx, subtype, PDF_NAME_Image)) { if (proc->op_Do_image) { @@ -562,7 +567,7 @@ pdf_process_CS(fz_context *ctx, pdf_processor *proc, pdf_csi *csi, int stroke) else { pdf_obj *csres, *csobj; - csres = pdf_dict_gets(ctx, csi->rdb, "ColorSpace"); + csres = pdf_dict_get(ctx, csi->rdb, PDF_NAME_ColorSpace); if (!csres) fz_throw(ctx, FZ_ERROR_GENERIC, "cannot find ColorSpace dictionary"); csobj = pdf_dict_gets(ctx, csres, csi->name); @@ -592,14 +597,14 @@ pdf_process_SC(fz_context *ctx, pdf_processor *proc, pdf_csi *csi, int stroke) { pdf_obj *patres, *patobj, *type; - patres = pdf_dict_gets(ctx, csi->rdb, "Pattern"); + patres = pdf_dict_get(ctx, csi->rdb, PDF_NAME_Pattern); if (!patres) fz_throw(ctx, FZ_ERROR_GENERIC, "cannot find Pattern dictionary"); patobj = pdf_dict_gets(ctx, patres, csi->name); if (!patobj) fz_throw(ctx, FZ_ERROR_GENERIC, "cannot find Pattern resource '%s'", csi->name); - type = pdf_dict_gets(ctx, patobj, "PatternType"); + type = pdf_dict_get(ctx, patobj, PDF_NAME_PatternType); if (pdf_to_int(ctx, type) == 1) { @@ -661,7 +666,7 @@ static pdf_obj * resolve_properties(fz_context *ctx, pdf_csi *csi, pdf_obj *obj) { if (pdf_is_name(ctx, obj)) - return pdf_dict_gets(ctx, pdf_dict_gets(ctx, csi->rdb, "Properties"), pdf_to_name(ctx, obj)); + return pdf_dict_get(ctx, pdf_dict_get(ctx, csi->rdb, PDF_NAME_Properties), obj); else return obj; } @@ -688,7 +693,7 @@ pdf_process_BDC(fz_context *ctx, pdf_processor *proc, pdf_csi *csi, const char * return; /* Wrong type of property */ - if (strcmp(pdf_to_name(ctx, pdf_dict_gets(ctx, properties, "Type")), "OCG")) + if (!pdf_name_eq(ctx, pdf_dict_get(ctx, properties, PDF_NAME_Type), PDF_NAME_OCG)) return; if (pdf_is_hidden_ocg(ctx, csi->doc->ocg, csi->rdb, proc->event, properties)) @@ -785,7 +790,7 @@ pdf_process_keyword(fz_context *ctx, pdf_processor *proc, pdf_csi *csi, fz_strea case B('g','s'): { pdf_obj *gsres, *gsobj; - gsres = pdf_dict_gets(ctx, csi->rdb, "ExtGState"); + gsres = pdf_dict_get(ctx, csi->rdb, PDF_NAME_ExtGState); if (!gsres) fz_throw(ctx, FZ_ERROR_GENERIC, "cannot find ExtGState dictionary"); gsobj = pdf_dict_gets(ctx, gsres, csi->name); @@ -846,7 +851,7 @@ pdf_process_keyword(fz_context *ctx, pdf_processor *proc, pdf_csi *csi, fz_strea { pdf_obj *fontres, *fontobj; pdf_font_desc *font; - fontres = pdf_dict_gets(ctx, csi->rdb, "Font"); + fontres = pdf_dict_get(ctx, csi->rdb, PDF_NAME_Font); if (!fontres) fz_throw(ctx, FZ_ERROR_GENERIC, "cannot find Font dictionary"); fontobj = pdf_dict_gets(ctx, fontres, csi->name); @@ -938,7 +943,7 @@ pdf_process_keyword(fz_context *ctx, pdf_processor *proc, pdf_csi *csi, fz_strea { pdf_obj *shaderes, *shadeobj; fz_shade *shade; - shaderes = pdf_dict_gets(ctx, csi->rdb, "Shading"); + shaderes = pdf_dict_get(ctx, csi->rdb, PDF_NAME_Shading); if (!shaderes) fz_throw(ctx, FZ_ERROR_GENERIC, "cannot find Shading dictionary"); shadeobj = pdf_dict_gets(ctx, shaderes, csi->name); @@ -1222,7 +1227,7 @@ pdf_process_contents(fz_context *ctx, pdf_processor *proc, pdf_document *doc, pd void pdf_process_annot(fz_context *ctx, pdf_processor *proc, pdf_document *doc, pdf_page *page, pdf_annot *annot, fz_cookie *cookie) { - int flags = pdf_to_int(ctx, pdf_dict_gets(ctx, annot->obj, "F")); + int flags = pdf_to_int(ctx, pdf_dict_get(ctx, annot->obj, PDF_NAME_F)); if (flags & (F_Invisible | F_Hidden)) return; @@ -1238,7 +1243,7 @@ pdf_process_annot(fz_context *ctx, pdf_processor *proc, pdf_document *doc, pdf_p /* TODO: NoZoom and NoRotate */ /* XXX what resources, if any, to use for this check? */ - if (pdf_is_hidden_ocg(ctx, doc->ocg, NULL, proc->event, pdf_dict_gets(ctx, annot->obj, "OC"))) + if (pdf_is_hidden_ocg(ctx, doc->ocg, NULL, proc->event, pdf_dict_get(ctx, annot->obj, PDF_NAME_OC))) return; if (proc->op_q && proc->op_cm && proc->op_Do_form && proc->op_Q) diff --git a/source/pdf/pdf-nametree.c b/source/pdf/pdf-nametree.c index eecbb320..8426b906 100644 --- a/source/pdf/pdf-nametree.c +++ b/source/pdf/pdf-nametree.c @@ -3,8 +3,8 @@ static pdf_obj * pdf_lookup_name_imp(fz_context *ctx, pdf_obj *node, pdf_obj *needle) { - pdf_obj *kids = pdf_dict_gets(ctx, node, "Kids"); - pdf_obj *names = pdf_dict_gets(ctx, node, "Names"); + pdf_obj *kids = pdf_dict_get(ctx, node, PDF_NAME_Kids); + pdf_obj *names = pdf_dict_get(ctx, node, PDF_NAME_Names); if (pdf_is_array(ctx, kids)) { @@ -15,7 +15,7 @@ pdf_lookup_name_imp(fz_context *ctx, pdf_obj *node, pdf_obj *needle) { int m = (l + r) >> 1; pdf_obj *kid = pdf_array_get(ctx, kids, m); - pdf_obj *limits = pdf_dict_gets(ctx, kid, "Limits"); + pdf_obj *limits = pdf_dict_get(ctx, kid, PDF_NAME_Limits); pdf_obj *first = pdf_array_get(ctx, limits, 0); pdf_obj *last = pdf_array_get(ctx, limits, 1); @@ -70,20 +70,20 @@ pdf_lookup_name_imp(fz_context *ctx, pdf_obj *node, pdf_obj *needle) } pdf_obj * -pdf_lookup_name(fz_context *ctx, pdf_document *doc, char *which, pdf_obj *needle) +pdf_lookup_name(fz_context *ctx, pdf_document *doc, pdf_obj *which, pdf_obj *needle) { - pdf_obj *root = pdf_dict_gets(ctx, pdf_trailer(ctx, doc), "Root"); - pdf_obj *names = pdf_dict_gets(ctx, root, "Names"); - pdf_obj *tree = pdf_dict_gets(ctx, names, which); + pdf_obj *root = pdf_dict_get(ctx, pdf_trailer(ctx, doc), PDF_NAME_Root); + pdf_obj *names = pdf_dict_get(ctx, root, PDF_NAME_Names); + pdf_obj *tree = pdf_dict_get(ctx, names, which); return pdf_lookup_name_imp(ctx, tree, needle); } pdf_obj * pdf_lookup_dest(fz_context *ctx, pdf_document *doc, pdf_obj *needle) { - pdf_obj *root = pdf_dict_gets(ctx, pdf_trailer(ctx, doc), "Root"); - pdf_obj *dests = pdf_dict_gets(ctx, root, "Dests"); - pdf_obj *names = pdf_dict_gets(ctx, root, "Names"); + pdf_obj *root = pdf_dict_get(ctx, pdf_trailer(ctx, doc), PDF_NAME_Root); + pdf_obj *dests = pdf_dict_get(ctx, root, PDF_NAME_Dests); + pdf_obj *names = pdf_dict_get(ctx, root, PDF_NAME_Names); pdf_obj *dest = NULL; /* PDF 1.1 has destinations in a dictionary */ @@ -98,7 +98,7 @@ pdf_lookup_dest(fz_context *ctx, pdf_document *doc, pdf_obj *needle) /* PDF 1.2 has destinations in a name tree */ if (names && !dest) { - pdf_obj *tree = pdf_dict_gets(ctx, names, "Dests"); + pdf_obj *tree = pdf_dict_get(ctx, names, PDF_NAME_Dests); return pdf_lookup_name_imp(ctx, tree, needle); } @@ -108,8 +108,8 @@ pdf_lookup_dest(fz_context *ctx, pdf_document *doc, pdf_obj *needle) static void pdf_load_name_tree_imp(fz_context *ctx, pdf_obj *dict, pdf_document *doc, pdf_obj *node) { - pdf_obj *kids = pdf_dict_gets(ctx, node, "Kids"); - pdf_obj *names = pdf_dict_gets(ctx, node, "Names"); + pdf_obj *kids = pdf_dict_get(ctx, node, PDF_NAME_Kids); + pdf_obj *names = pdf_dict_get(ctx, node, PDF_NAME_Names); int i; UNUSED(ctx); @@ -144,11 +144,11 @@ pdf_load_name_tree_imp(fz_context *ctx, pdf_obj *dict, pdf_document *doc, pdf_ob } pdf_obj * -pdf_load_name_tree(fz_context *ctx, pdf_document *doc, char *which) +pdf_load_name_tree(fz_context *ctx, pdf_document *doc, pdf_obj *which) { - pdf_obj *root = pdf_dict_gets(ctx, pdf_trailer(ctx, doc), "Root"); - pdf_obj *names = pdf_dict_gets(ctx, root, "Names"); - pdf_obj *tree = pdf_dict_gets(ctx, names, which); + pdf_obj *root = pdf_dict_get(ctx, pdf_trailer(ctx, doc), PDF_NAME_Root); + pdf_obj *names = pdf_dict_get(ctx, root, PDF_NAME_Names); + pdf_obj *tree = pdf_dict_get(ctx, names, which); if (pdf_is_dict(ctx, tree)) { pdf_obj *dict = pdf_new_dict(ctx, doc, 100); diff --git a/source/pdf/pdf-object.c b/source/pdf/pdf-object.c index 0ed9667d..ecdb1ebb 100644 --- a/source/pdf/pdf-object.c +++ b/source/pdf/pdf-object.c @@ -1,9 +1,11 @@ #include "mupdf/pdf.h" +#include "pdf-name-table.h" + +#include <stdarg.h> + typedef enum pdf_objkind_e { - PDF_NULL = 0, - PDF_BOOL = 'b', PDF_INT = 'i', PDF_REAL = 'f', PDF_STRING = 's', @@ -37,7 +39,6 @@ struct pdf_obj_s int parent_num; union { - int b; int i; float f; struct { @@ -65,28 +66,13 @@ struct pdf_obj_s pdf_obj * pdf_new_null(fz_context *ctx, pdf_document *doc) { - pdf_obj *obj; - obj = Memento_label(fz_malloc(ctx, sizeof(pdf_obj)), "pdf_obj(null)"); - obj->doc = doc; - obj->refs = 1; - obj->kind = PDF_NULL; - obj->flags = 0; - obj->parent_num = 0; - return obj; + return PDF_OBJ_NULL; } pdf_obj * pdf_new_bool(fz_context *ctx, pdf_document *doc, int b) { - pdf_obj *obj; - obj = Memento_label(fz_malloc(ctx, sizeof(pdf_obj)), "pdf_obj(bool)"); - obj->doc = doc; - obj->refs = 1; - obj->kind = PDF_BOOL; - obj->flags = 0; - obj->parent_num = 0; - obj->u.b = b; - return obj; + return b ? PDF_OBJ_TRUE : PDF_OBJ_FALSE; } pdf_obj * @@ -133,10 +119,22 @@ pdf_new_string(fz_context *ctx, pdf_document *doc, const char *str, int len) return obj; } +static int +namecmp(const void *key, const void *name) +{ + return strcmp((char *)key, *(char **)name); +} + pdf_obj * pdf_new_name(fz_context *ctx, pdf_document *doc, const char *str) { pdf_obj *obj; + char **stdname; + + stdname = bsearch(str, &PDF_NAMES[1], PDF_OBJ_ENUM_NAME__LIMIT-1, sizeof(char *), namecmp); + if (stdname != NULL) + return (pdf_obj *)(intptr_t)(stdname - &PDF_NAMES[0]); + obj = Memento_label(fz_malloc(ctx, offsetof(pdf_obj, u.n) + strlen(str) + 1), "pdf_obj(name)"); obj->doc = doc; obj->refs = 1; @@ -165,86 +163,86 @@ pdf_new_indirect(fz_context *ctx, pdf_document *doc, int num, int gen) pdf_obj * pdf_keep_obj(fz_context *ctx, pdf_obj *obj) { - if (obj) + if (obj >= PDF_OBJ__LIMIT) obj->refs ++; return obj; } int pdf_is_indirect(fz_context *ctx, pdf_obj *obj) { - return obj ? obj->kind == PDF_INDIRECT : 0; + return obj >= PDF_OBJ__LIMIT ? obj->kind == PDF_INDIRECT : 0; } #define RESOLVE(obj) \ - if (obj && obj->kind == PDF_INDIRECT) \ + if (obj >= PDF_OBJ__LIMIT && obj->kind == PDF_INDIRECT) \ obj = pdf_resolve_indirect(ctx, obj); \ int pdf_is_null(fz_context *ctx, pdf_obj *obj) { RESOLVE(obj); - return obj ? obj->kind == PDF_NULL : 0; + return obj == PDF_OBJ_NULL; } int pdf_is_bool(fz_context *ctx, pdf_obj *obj) { RESOLVE(obj); - return obj ? obj->kind == PDF_BOOL : 0; + return obj == PDF_OBJ_TRUE || obj == PDF_OBJ_FALSE; } int pdf_is_int(fz_context *ctx, pdf_obj *obj) { RESOLVE(obj); - return obj ? obj->kind == PDF_INT : 0; + return obj >= PDF_OBJ__LIMIT ? obj->kind == PDF_INT : 0; } int pdf_is_real(fz_context *ctx, pdf_obj *obj) { RESOLVE(obj); - return obj ? obj->kind == PDF_REAL : 0; + return obj >= PDF_OBJ__LIMIT ? obj->kind == PDF_REAL : 0; } int pdf_is_number(fz_context *ctx, pdf_obj *obj) { RESOLVE(obj); - return obj ? (obj->kind == PDF_REAL || obj->kind == PDF_INT) : 0; + return obj >= PDF_OBJ__LIMIT ? (obj->kind == PDF_REAL || obj->kind == PDF_INT) : 0; } int pdf_is_string(fz_context *ctx, pdf_obj *obj) { RESOLVE(obj); - return obj ? obj->kind == PDF_STRING : 0; + return obj >= PDF_OBJ__LIMIT ? obj->kind == PDF_STRING : 0; } int pdf_is_name(fz_context *ctx, pdf_obj *obj) { RESOLVE(obj); - return obj ? obj->kind == PDF_NAME : 0; + if (obj < PDF_OBJ__LIMIT) + return obj != NULL && obj < PDF_OBJ_NAME__LIMIT; + return obj->kind == PDF_NAME; } int pdf_is_array(fz_context *ctx, pdf_obj *obj) { RESOLVE(obj); - return obj ? obj->kind == PDF_ARRAY : 0; + return obj >= PDF_OBJ__LIMIT ? obj->kind == PDF_ARRAY : 0; } int pdf_is_dict(fz_context *ctx, pdf_obj *obj) { RESOLVE(obj); - return obj ? obj->kind == PDF_DICT : 0; + return obj >= PDF_OBJ__LIMIT ? obj->kind == PDF_DICT : 0; } int pdf_to_bool(fz_context *ctx, pdf_obj *obj) { RESOLVE(obj); - if (!obj) - return 0; - return obj->kind == PDF_BOOL ? obj->u.b : 0; + return obj == PDF_OBJ_TRUE; } int pdf_to_int(fz_context *ctx, pdf_obj *obj) { RESOLVE(obj); - if (!obj) + if (obj < PDF_OBJ__LIMIT) return 0; if (obj->kind == PDF_INT) return obj->u.i; @@ -256,7 +254,7 @@ int pdf_to_int(fz_context *ctx, pdf_obj *obj) float pdf_to_real(fz_context *ctx, pdf_obj *obj) { RESOLVE(obj); - if (!obj) + if (obj < PDF_OBJ__LIMIT) return 0; if (obj->kind == PDF_REAL) return obj->u.f; @@ -268,7 +266,11 @@ float pdf_to_real(fz_context *ctx, pdf_obj *obj) char *pdf_to_name(fz_context *ctx, pdf_obj *obj) { RESOLVE(obj); - if (!obj || obj->kind != PDF_NAME) + if (!obj) + return ""; + if (obj < PDF_OBJ_NAME__LIMIT) + return PDF_NAMES[(intptr_t)obj]; + if (obj < PDF_OBJ__LIMIT || obj->kind != PDF_NAME) return ""; return obj->u.n; } @@ -276,7 +278,7 @@ char *pdf_to_name(fz_context *ctx, pdf_obj *obj) char *pdf_to_str_buf(fz_context *ctx, pdf_obj *obj) { RESOLVE(obj); - if (!obj || obj->kind != PDF_STRING) + if (obj < PDF_OBJ__LIMIT || obj->kind != PDF_STRING) return ""; return obj->u.s.buf; } @@ -284,14 +286,14 @@ char *pdf_to_str_buf(fz_context *ctx, pdf_obj *obj) int pdf_to_str_len(fz_context *ctx, pdf_obj *obj) { RESOLVE(obj); - if (!obj || obj->kind != PDF_STRING) + if (obj < PDF_OBJ__LIMIT || obj->kind != PDF_STRING) return 0; return obj->u.s.len; } void pdf_set_int(fz_context *ctx, pdf_obj *obj, int i) { - if (!obj || obj->kind != PDF_INT) + if (obj < PDF_OBJ__LIMIT || obj->kind != PDF_INT) return; obj->u.i = i; } @@ -300,7 +302,7 @@ void pdf_set_int(fz_context *ctx, pdf_obj *obj, int i) void pdf_set_str_len(fz_context *ctx, pdf_obj *obj, int newlen) { RESOLVE(obj); - if (!obj || obj->kind != PDF_STRING) + if (obj < PDF_OBJ__LIMIT || obj->kind != PDF_STRING) return; /* This should never happen */ if (newlen > obj->u.s.len) return; /* This should never happen */ @@ -310,30 +312,37 @@ void pdf_set_str_len(fz_context *ctx, pdf_obj *obj, int newlen) pdf_obj *pdf_to_dict(fz_context *ctx, pdf_obj *obj) { RESOLVE(obj); - return (obj && obj->kind == PDF_DICT ? obj : NULL); + return (obj >= PDF_OBJ__LIMIT && obj->kind == PDF_DICT ? obj : NULL); } int pdf_to_num(fz_context *ctx, pdf_obj *obj) { - if (!obj || obj->kind != PDF_INDIRECT) + if (obj < PDF_OBJ__LIMIT || obj->kind != PDF_INDIRECT) return 0; return obj->u.r.num; } int pdf_to_gen(fz_context *ctx, pdf_obj *obj) { - if (!obj || obj->kind != PDF_INDIRECT) + if (obj < PDF_OBJ__LIMIT || obj->kind != PDF_INDIRECT) return 0; return obj->u.r.gen; } pdf_document *pdf_get_indirect_document(fz_context *ctx, pdf_obj *obj) { - if (!obj || obj->kind != PDF_INDIRECT) + if (obj < PDF_OBJ__LIMIT || obj->kind != PDF_INDIRECT) return NULL; return obj->doc; } +int pdf_objcmp_resolve(fz_context *ctx, pdf_obj *a, pdf_obj *b) +{ + RESOLVE(a); + RESOLVE(b); + return pdf_objcmp(ctx, a, b); +} + int pdf_objcmp(fz_context *ctx, pdf_obj *a, pdf_obj *b) { @@ -345,17 +354,31 @@ pdf_objcmp(fz_context *ctx, pdf_obj *a, pdf_obj *b) if (!a || !b) return 1; + if (a < PDF_OBJ_NAME__LIMIT) + { + if (b < PDF_OBJ_NAME__LIMIT) + return a != b; + + if (b->kind != PDF_NAME) + return 1; + return strcmp(b->u.n, PDF_NAMES[(intptr_t)a]); + } + + if (b < PDF_OBJ_NAME__LIMIT) + { + if (a->kind != PDF_NAME) + return 1; + return strcmp(a->u.n, PDF_NAMES[(intptr_t)b]); + } + + if (a < PDF_OBJ__LIMIT || b < PDF_OBJ__LIMIT) + return a != b; + if (a->kind != b->kind) return 1; switch (a->kind) { - case PDF_NULL: - return 0; - - case PDF_BOOL: - return a->u.b - b->u.b; - case PDF_INT: return a->u.i - b->u.i; @@ -418,10 +441,15 @@ pdf_objkindstr(pdf_obj *obj) { if (!obj) return "<NULL>"; + if (obj < PDF_OBJ_NAME__LIMIT) + return "name"; + if (obj == PDF_OBJ_TRUE || obj == PDF_OBJ_FALSE) + return "boolean"; + if (obj == PDF_OBJ_NULL) + return "null"; + switch (obj->kind) { - case PDF_NULL: return "null"; - case PDF_BOOL: return "boolean"; case PDF_INT: return "integer"; case PDF_REAL: return "real"; case PDF_STRING: return "string"; @@ -506,7 +534,7 @@ int pdf_array_len(fz_context *ctx, pdf_obj *obj) { RESOLVE(obj); - if (!obj || obj->kind != PDF_ARRAY) + if (obj < PDF_OBJ__LIMIT || obj->kind != PDF_ARRAY) return 0; return obj->u.a.len; } @@ -515,7 +543,7 @@ pdf_obj * pdf_array_get(fz_context *ctx, pdf_obj *obj, int i) { RESOLVE(obj); - if (!obj || obj->kind != PDF_ARRAY) + if (obj < PDF_OBJ__LIMIT || obj->kind != PDF_ARRAY) return NULL; if (i < 0 || i >= obj->u.a.len) return NULL; @@ -546,7 +574,7 @@ void pdf_array_put(fz_context *ctx, pdf_obj *obj, int i, pdf_obj *item) { RESOLVE(obj); - if (obj) + if (obj >= PDF_OBJ__LIMIT) { if (obj->kind != PDF_ARRAY) fz_warn(ctx, "assert: not an array (%s)", pdf_objkindstr(obj)); @@ -576,7 +604,7 @@ void pdf_array_push(fz_context *ctx, pdf_obj *obj, pdf_obj *item) { RESOLVE(obj); - if (obj) + if (obj >= PDF_OBJ__LIMIT) { if (obj->kind != PDF_ARRAY) fz_warn(ctx, "assert: not an array (%s)", pdf_objkindstr(obj)); @@ -597,7 +625,7 @@ void pdf_array_push_drop(fz_context *ctx, pdf_obj *obj, pdf_obj *item) { RESOLVE(obj); - if (obj) + if (obj >= PDF_OBJ__LIMIT) { fz_try(ctx) pdf_array_push(ctx, obj, item); @@ -612,7 +640,7 @@ void pdf_array_insert(fz_context *ctx, pdf_obj *obj, pdf_obj *item, int i) { RESOLVE(obj); - if (obj) + if (obj >= PDF_OBJ__LIMIT) { if (obj->kind != PDF_ARRAY) fz_warn(ctx, "assert: not an array (%s)", pdf_objkindstr(obj)); @@ -636,7 +664,7 @@ void pdf_array_insert_drop(fz_context *ctx, pdf_obj *obj, pdf_obj *item, int i) { RESOLVE(obj); - if (obj) + if (obj >= PDF_OBJ__LIMIT) { fz_try(ctx) pdf_array_insert(ctx, obj, item, i); @@ -651,7 +679,7 @@ void pdf_array_delete(fz_context *ctx, pdf_obj *obj, int i) { RESOLVE(obj); - if (obj) + if (obj >= PDF_OBJ__LIMIT) { if (obj->kind != PDF_ARRAY) fz_warn(ctx, "assert: not an array (%s)", pdf_objkindstr(obj)); @@ -777,9 +805,26 @@ static int keyvalcmp(const void *ap, const void *bp) { const struct keyval *a = ap; const struct keyval *b = bp; - if (a->k->kind == PDF_NAME && b->k->kind == PDF_NAME) - return strcmp(a->k->u.n, b->k->u.n); - return 0; + const char *an; + const char *bn; + + /* We should never get a->k == NULL or b->k == NULL. If we + * do, then they match. */ + if (a->k < PDF_OBJ_NAME__LIMIT) + an = PDF_NAMES[(intptr_t)a->k]; + else if (a->k >= PDF_OBJ__LIMIT && a->k->kind == PDF_NAME) + an = a->k->u.n; + else + return 0; + + if (b->k < PDF_OBJ_NAME__LIMIT) + bn = PDF_NAMES[(intptr_t)b->k]; + else if (b->k >= PDF_OBJ__LIMIT && b->k->kind == PDF_NAME) + bn = b->k->u.n; + else + return 0; + + return strcmp(an, bn); } pdf_obj * @@ -839,7 +884,7 @@ pdf_copy_dict(fz_context *ctx, pdf_obj *obj) int i, n; RESOLVE(obj); - if (obj) + if (obj >= PDF_OBJ__LIMIT) { pdf_document *doc = obj->doc; @@ -860,7 +905,7 @@ int pdf_dict_len(fz_context *ctx, pdf_obj *obj) { RESOLVE(obj); - if (!obj || obj->kind != PDF_DICT) + if (obj < PDF_OBJ__LIMIT || obj->kind != PDF_DICT) return 0; return obj->u.d.len; } @@ -869,7 +914,7 @@ pdf_obj * pdf_dict_get_key(fz_context *ctx, pdf_obj *obj, int i) { RESOLVE(obj); - if (!obj || obj->kind != PDF_DICT) + if (obj < PDF_OBJ__LIMIT || obj->kind != PDF_DICT) return NULL; if (i < 0 || i >= obj->u.d.len) return NULL; @@ -880,7 +925,7 @@ pdf_obj * pdf_dict_get_val(fz_context *ctx, pdf_obj *obj, int i) { RESOLVE(obj); - if (!obj || obj->kind != PDF_DICT) + if (obj < PDF_OBJ__LIMIT || obj->kind != PDF_DICT) return NULL; if (i < 0 || i >= obj->u.d.len) return NULL; @@ -944,6 +989,66 @@ pdf_dict_finds(fz_context *ctx, pdf_obj *obj, const char *key, int *location) if (strcmp(pdf_to_name(ctx, obj->u.d.items[i].k), key) == 0) return i; + + if (location) + *location = obj->u.d.len; + } + + return -1; +} + +static int +pdf_dict_find(fz_context *ctx, pdf_obj *obj, pdf_obj *key, int *location) +{ + if ((obj->flags & PDF_FLAGS_SORTED) && obj->u.d.len > 0) + { + int l = 0; + int r = obj->u.d.len - 1; + pdf_obj *k = obj->u.d.items[r].k; + + if (k == key || (k >= PDF_OBJ__LIMIT && strcmp(k->u.n, PDF_NAMES[(intptr_t)key]) < 0)) + { + if (location) + *location = r + 1; + return -1; + } + + while (l <= r) + { + int m = (l + r) >> 1; + int c; + + k = obj->u.d.items[m].k; + c = (k < PDF_OBJ__LIMIT ? key-k : -strcmp(k->u.n, PDF_NAMES[(intptr_t)key])); + if (c < 0) + r = m - 1; + else if (c > 0) + l = m + 1; + else + return m; + + if (location) + *location = l; + } + } + else + { + int i; + for (i = 0; i < obj->u.d.len; i++) + { + pdf_obj *k = obj->u.d.items[i].k; + if (k < PDF_OBJ__LIMIT) + { + if (k == key) + return i; + } + else + { + if (!strcmp(PDF_NAMES[(intptr_t)key], k->u.n)) + return i; + } + } + if (location) *location = obj->u.d.len; } @@ -957,7 +1062,7 @@ pdf_dict_gets(fz_context *ctx, pdf_obj *obj, const char *key) int i; RESOLVE(obj); - if (!obj || obj->kind != PDF_DICT) + if (obj < PDF_OBJ__LIMIT || obj->kind != PDF_DICT) return NULL; i = pdf_dict_finds(ctx, obj, key, NULL); @@ -971,7 +1076,7 @@ pdf_obj * pdf_dict_getp(fz_context *ctx, pdf_obj *obj, const char *keys) { RESOLVE(obj); - if (obj) + if (obj >= PDF_OBJ__LIMIT) { char buf[256]; char *k, *e; @@ -1003,11 +1108,44 @@ pdf_dict_getp(fz_context *ctx, pdf_obj *obj, const char *keys) } pdf_obj * +pdf_dict_getl(fz_context *ctx, pdf_obj *obj, ...) +{ + va_list keys; + pdf_obj *key; + + va_start(keys, obj); + + while (obj != NULL && (key = va_arg(keys, pdf_obj *)) != NULL) + { + obj = pdf_dict_get(ctx, obj, key); + } + + va_end(keys); + return obj; +} + + +pdf_obj * pdf_dict_get(fz_context *ctx, pdf_obj *obj, pdf_obj *key) { - if (!key || key->kind != PDF_NAME) + int i; + + if (key >= PDF_OBJ__LIMIT) + { + if (key->kind != PDF_NAME) + return NULL; + + return pdf_dict_gets(ctx, obj, pdf_to_name(ctx, key)); + } + + RESOLVE(obj); + if (obj < PDF_OBJ__LIMIT || obj->kind != PDF_DICT) return NULL; - return pdf_dict_gets(ctx, obj, pdf_to_name(ctx, key)); + + i = pdf_dict_find(ctx, obj, key, NULL); + if (i >= 0) + return obj->u.d.items[i].v; + return NULL; } pdf_obj * @@ -1020,11 +1158,21 @@ pdf_dict_getsa(fz_context *ctx, pdf_obj *obj, const char *key, const char *abbre return pdf_dict_gets(ctx, obj, abbrev); } +pdf_obj * +pdf_dict_geta(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *abbrev) +{ + pdf_obj *v; + v = pdf_dict_get(ctx, obj, key); + if (v) + return v; + return pdf_dict_get(ctx, obj, abbrev); +} + void pdf_dict_put(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val) { RESOLVE(obj); - if (obj) + if (obj >= PDF_OBJ__LIMIT) { int location; char *s; @@ -1037,7 +1185,7 @@ pdf_dict_put(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val) } RESOLVE(key); - if (!key || key->kind != PDF_NAME) + if (!key || (key >= PDF_OBJ__LIMIT && key->kind != PDF_NAME)) { fz_warn(ctx, "assert: key is not a name (%s)", pdf_objkindstr(obj)); return; @@ -1086,6 +1234,17 @@ pdf_dict_put(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val) } void +pdf_dict_put_drop(fz_context *ctx, pdf_obj *obj, pdf_obj *key, pdf_obj *val) +{ + fz_try(ctx) + pdf_dict_put(ctx, obj, key, val); + fz_always(ctx) + pdf_drop_obj(ctx, val); + fz_catch(ctx) + fz_rethrow(ctx); +} + +void pdf_dict_puts(fz_context *ctx, pdf_obj *obj, const char *key, pdf_obj *val) { pdf_document *doc = obj->doc; @@ -1127,7 +1286,7 @@ void pdf_dict_putp(fz_context *ctx, pdf_obj *obj, const char *keys, pdf_obj *val) { RESOLVE(obj); - if (obj) + if (obj >= PDF_OBJ__LIMIT) { pdf_document *doc = obj->doc; @@ -1194,11 +1353,80 @@ pdf_dict_putp_drop(fz_context *ctx, pdf_obj *obj, const char *keys, pdf_obj *val fz_rethrow(ctx); } +static void +pdf_dict_vputl(fz_context *ctx, pdf_obj *obj, pdf_obj *val, va_list keys) +{ + pdf_obj *key; + pdf_obj *next_key; + pdf_obj *next_obj; + + key = va_arg(keys, pdf_obj *); + if (key == NULL) + return; + + while ((next_key = va_arg(keys, pdf_obj *)) != NULL) + { + next_obj = pdf_dict_get(ctx, obj, key); + if (next_obj == NULL) + goto new_obj; + obj = next_obj; + key = next_key; + } + + pdf_dict_put(ctx, obj, key, val); + return; + +new_obj: + /* We have to create entries */ + do + { + next_obj = pdf_new_dict(ctx, obj->doc, 1); + pdf_dict_put_drop(ctx, obj, key, next_obj); + obj = next_obj; + key = next_key; + } + while ((next_key = va_arg(keys, pdf_obj *)) != NULL); + + pdf_dict_put(ctx, obj, key, val); + return; +} + +void +pdf_dict_putl(fz_context *ctx, pdf_obj *obj, pdf_obj *val, ...) +{ + va_list keys; + va_start(keys, val); + + fz_try(ctx) + pdf_dict_vputl(ctx, obj, val, keys); + fz_always(ctx) + va_end(keys); + fz_catch(ctx) + fz_rethrow(ctx); +} + +void +pdf_dict_putl_drop(fz_context *ctx, pdf_obj *obj, pdf_obj *val, ...) +{ + va_list keys; + va_start(keys, val); + + fz_try(ctx) + pdf_dict_vputl(ctx, obj, val, keys); + fz_always(ctx) + { + pdf_drop_obj(ctx, val); + va_end(keys); + } + fz_catch(ctx) + fz_rethrow(ctx); +} + void pdf_dict_dels(fz_context *ctx, pdf_obj *obj, const char *key) { RESOLVE(obj); - if (obj) + if (obj >= PDF_OBJ__LIMIT) { if (obj->kind != PDF_DICT) fz_warn(ctx, "assert: not a dict (%s)", pdf_objkindstr(obj)); @@ -1224,7 +1452,12 @@ void pdf_dict_del(fz_context *ctx, pdf_obj *obj, pdf_obj *key) { RESOLVE(key); - if (key && key->kind == PDF_NAME) + if (!key) + return; /* Can't warn */ + + if (key < PDF_OBJ__LIMIT) + pdf_dict_dels(ctx, obj, PDF_NAMES[(intptr_t)key]); + else if (key->kind == PDF_NAME) pdf_dict_dels(ctx, obj, key->u.n); /* else Can't warn */ } @@ -1233,7 +1466,7 @@ void pdf_sort_dict(fz_context *ctx, pdf_obj *obj) { RESOLVE(obj); - if (!obj || obj->kind != PDF_DICT) + if (obj < PDF_OBJ__LIMIT || obj->kind != PDF_DICT) return; if (!(obj->flags & PDF_FLAGS_SORTED)) { @@ -1246,7 +1479,7 @@ int pdf_obj_marked(fz_context *ctx, pdf_obj *obj) { RESOLVE(obj); - if (!obj) + if (obj < PDF_OBJ__LIMIT) return 0; return !!(obj->flags & PDF_FLAGS_MARKED); } @@ -1256,7 +1489,7 @@ pdf_mark_obj(fz_context *ctx, pdf_obj *obj) { int marked; RESOLVE(obj); - if (!obj) + if (obj < PDF_OBJ__LIMIT) return 0; marked = !!(obj->flags & PDF_FLAGS_MARKED); obj->flags |= PDF_FLAGS_MARKED; @@ -1267,7 +1500,7 @@ void pdf_unmark_obj(fz_context *ctx, pdf_obj *obj) { RESOLVE(obj); - if (!obj) + if (obj < PDF_OBJ__LIMIT) return; obj->flags &= ~PDF_FLAGS_MARKED; } @@ -1275,6 +1508,9 @@ pdf_unmark_obj(fz_context *ctx, pdf_obj *obj) void pdf_set_obj_memo(fz_context *ctx, pdf_obj *obj, int memo) { + if (obj < PDF_OBJ__LIMIT) + return; + obj->flags |= PDF_FLAGS_MEMO; if (memo) obj->flags |= PDF_FLAGS_MEMO_BOOL; @@ -1285,6 +1521,8 @@ pdf_set_obj_memo(fz_context *ctx, pdf_obj *obj, int memo) int pdf_obj_memo(fz_context *ctx, pdf_obj *obj, int *memo) { + if (obj < PDF_OBJ__LIMIT) + return 0; if (!(obj->flags & PDF_FLAGS_MEMO)) return 0; *memo = !!(obj->flags & PDF_FLAGS_MEMO_BOOL); @@ -1294,7 +1532,7 @@ pdf_obj_memo(fz_context *ctx, pdf_obj *obj, int *memo) int pdf_obj_is_dirty(fz_context *ctx, pdf_obj *obj) { RESOLVE(obj); - if (!obj) + if (obj < PDF_OBJ__LIMIT) return 0; return !!(obj->flags & PDF_FLAGS_DIRTY); } @@ -1302,14 +1540,14 @@ int pdf_obj_is_dirty(fz_context *ctx, pdf_obj *obj) void pdf_dirty_obj(fz_context *ctx, pdf_obj *obj) { RESOLVE(obj); - if (!obj) + if (obj < PDF_OBJ__LIMIT) return; obj->flags |= PDF_FLAGS_DIRTY; } void pdf_clean_obj(fz_context *ctx, pdf_obj *obj) { - if (!obj) + if (obj < PDF_OBJ__LIMIT) return; obj->flags &= ~PDF_FLAGS_DIRTY; } @@ -1343,7 +1581,7 @@ pdf_drop_dict(fz_context *ctx, pdf_obj *obj) void pdf_drop_obj(fz_context *ctx, pdf_obj *obj) { - if (obj) + if (obj >= PDF_OBJ__LIMIT) { if (--obj->refs) return; @@ -1361,7 +1599,7 @@ pdf_set_obj_parent(fz_context *ctx, pdf_obj *obj, int num) { int n, i; - if (!obj) + if (obj < PDF_OBJ__LIMIT) return; obj->parent_num = num; @@ -1383,6 +1621,9 @@ pdf_set_obj_parent(fz_context *ctx, pdf_obj *obj, int num) int pdf_obj_parent_num(fz_context *ctx, pdf_obj *obj) { + if (obj < PDF_OBJ__LIMIT) + return 0; + return obj->parent_num; } @@ -1773,5 +2014,5 @@ pdf_print_ref(fz_context *ctx, pdf_obj *ref) int pdf_obj_refs(fz_context *ctx, pdf_obj *ref) { - return (ref ? ref->refs : 0); + return (ref >= PDF_OBJ__LIMIT ? ref->refs : 0); } diff --git a/source/pdf/pdf-op-filter.c b/source/pdf/pdf-op-filter.c index c030f468..24644a37 100644 --- a/source/pdf/pdf-op-filter.c +++ b/source/pdf/pdf-op-filter.c @@ -51,22 +51,22 @@ typedef struct pdf_filter_processor_s } pdf_filter_processor; static void -copy_resource(fz_context *ctx, pdf_filter_processor *p, const char *key, const char *name) +copy_resource(fz_context *ctx, pdf_filter_processor *p, pdf_obj *key, const char *name) { pdf_obj *res, *obj; if (!name || name[0] == 0) return; - res = pdf_dict_gets(ctx, p->old_rdb, key); + res = pdf_dict_get(ctx, p->old_rdb, key); obj = pdf_dict_gets(ctx, res, name); if (obj) { - res = pdf_dict_gets(ctx, p->new_rdb, key); + res = pdf_dict_get(ctx, p->new_rdb, key); if (!res) { res = pdf_new_dict(ctx, p->doc, 1); - pdf_dict_puts_drop(ctx, p->new_rdb, key, res); + pdf_dict_put_drop(ctx, p->new_rdb, key, res); } pdf_dict_putp(ctx, res, name, obj); } @@ -402,7 +402,7 @@ pdf_filter_gs_begin(fz_context *ctx, pdf_processor *proc, const char *name, pdf_ filter_flush(ctx, p, FLUSH_ALL); if (p->chain->op_gs_begin) p->chain->op_gs_begin(ctx, p->chain, name, extgstate); - copy_resource(ctx, p, "ExtGState", name); + copy_resource(ctx, p, PDF_NAME_ExtGState, name); } static void @@ -725,7 +725,7 @@ pdf_filter_Tf(fz_context *ctx, pdf_processor *proc, const char *name, pdf_font_d filter_flush(ctx, p, 0); if (p->chain->op_Tf) p->chain->op_Tf(ctx, p->chain, name, font, size); - copy_resource(ctx, p, "Font", name); + copy_resource(ctx, p, PDF_NAME_Font, name); } static void @@ -851,7 +851,7 @@ pdf_filter_CS(fz_context *ctx, pdf_processor *proc, const char *name, fz_colorsp filter_gstate *gstate = gstate_to_update(ctx, p); fz_strlcpy(gstate->CS.name, name, sizeof gstate->CS.name); gstate->CS.cs = cs; - copy_resource(ctx, p, "ColorSpace", name); + copy_resource(ctx, p, PDF_NAME_ColorSpace, name); } static void @@ -861,7 +861,7 @@ pdf_filter_cs(fz_context *ctx, pdf_processor *proc, const char *name, fz_colorsp filter_gstate *gstate = gstate_to_update(ctx, p); fz_strlcpy(gstate->cs.name, name, sizeof gstate->cs.name); gstate->cs.cs = cs; - copy_resource(ctx, p, "ColorSpace", name); + copy_resource(ctx, p, PDF_NAME_ColorSpace, name); } static void @@ -876,7 +876,7 @@ pdf_filter_SC_pattern(fz_context *ctx, pdf_processor *proc, const char *name, pd gstate->SC.n = n; for (i = 0; i < n; ++i) gstate->SC.c[i] = color[i]; - copy_resource(ctx, p, "Pattern", name); + copy_resource(ctx, p, PDF_NAME_Pattern, name); } static void @@ -891,7 +891,7 @@ pdf_filter_sc_pattern(fz_context *ctx, pdf_processor *proc, const char *name, pd gstate->sc.n = n; for (i = 0; i < n; ++i) gstate->sc.c[i] = color[i]; - copy_resource(ctx, p, "Pattern", name); + copy_resource(ctx, p, PDF_NAME_Pattern, name); } static void @@ -903,7 +903,7 @@ pdf_filter_SC_shade(fz_context *ctx, pdf_processor *proc, const char *name, fz_s gstate->SC.pat = NULL; gstate->SC.shd = shade; gstate->SC.n = 0; - copy_resource(ctx, p, "Pattern", name); + copy_resource(ctx, p, PDF_NAME_Pattern, name); } static void @@ -915,7 +915,7 @@ pdf_filter_sc_shade(fz_context *ctx, pdf_processor *proc, const char *name, fz_s gstate->sc.pat = NULL; gstate->sc.shd = shade; gstate->sc.n = 0; - copy_resource(ctx, p, "Pattern", name); + copy_resource(ctx, p, PDF_NAME_Pattern, name); } static void @@ -1012,7 +1012,7 @@ pdf_filter_sh(fz_context *ctx, pdf_processor *proc, const char *name, fz_shade * filter_flush(ctx, p, FLUSH_ALL); if (p->chain->op_sh) p->chain->op_sh(ctx, p->chain, name, shade); - copy_resource(ctx, p, "Shading", name); + copy_resource(ctx, p, PDF_NAME_Shading, name); } static void @@ -1022,7 +1022,7 @@ pdf_filter_Do_image(fz_context *ctx, pdf_processor *proc, const char *name, fz_i filter_flush(ctx, p, FLUSH_ALL); if (p->chain->op_Do_image) p->chain->op_Do_image(ctx, p->chain, name, image); - copy_resource(ctx, p, "XObject", name); + copy_resource(ctx, p, PDF_NAME_XObject, name); } static void @@ -1032,7 +1032,7 @@ pdf_filter_Do_form(fz_context *ctx, pdf_processor *proc, const char *name, pdf_x filter_flush(ctx, p, FLUSH_ALL); if (p->chain->op_Do_form) p->chain->op_Do_form(ctx, p->chain, name, xobj, page_resources); - copy_resource(ctx, p, "XObject", name); + copy_resource(ctx, p, PDF_NAME_XObject, name); } /* marked content */ diff --git a/source/pdf/pdf-outline.c b/source/pdf/pdf-outline.c index 34bb79ed..8f83fdf9 100644 --- a/source/pdf/pdf-outline.c +++ b/source/pdf/pdf-outline.c @@ -26,25 +26,25 @@ pdf_load_outline_imp(fz_context *ctx, pdf_document *doc, pdf_obj *dict) *prev = node; prev = &node->next; - obj = pdf_dict_gets(ctx, dict, "Title"); + obj = pdf_dict_get(ctx, dict, PDF_NAME_Title); if (obj) node->title = pdf_to_utf8(ctx, doc, obj); - if ((obj = pdf_dict_gets(ctx, dict, "Dest")) != NULL) + if ((obj = pdf_dict_get(ctx, dict, PDF_NAME_Dest)) != NULL) node->dest = pdf_parse_link_dest(ctx, doc, FZ_LINK_GOTO, obj); - else if ((obj = pdf_dict_gets(ctx, dict, "A")) != NULL) + else if ((obj = pdf_dict_get(ctx, dict, PDF_NAME_A)) != NULL) node->dest = pdf_parse_action(ctx, doc, obj); - obj = pdf_dict_gets(ctx, dict, "First"); + obj = pdf_dict_get(ctx, dict, PDF_NAME_First); if (obj) node->down = pdf_load_outline_imp(ctx, doc, obj); - dict = pdf_dict_gets(ctx, dict, "Next"); + dict = pdf_dict_get(ctx, dict, PDF_NAME_Next); } } fz_always(ctx) { - for (dict = odict; dict && pdf_obj_marked(ctx, dict); dict = pdf_dict_gets(ctx, dict, "Next")) + for (dict = odict; dict && pdf_obj_marked(ctx, dict); dict = pdf_dict_get(ctx, dict, PDF_NAME_Next)) pdf_unmark_obj(ctx, dict); } fz_catch(ctx) @@ -61,9 +61,9 @@ pdf_load_outline(fz_context *ctx, pdf_document *doc) { pdf_obj *root, *obj, *first; - root = pdf_dict_gets(ctx, pdf_trailer(ctx, doc), "Root"); - obj = pdf_dict_gets(ctx, root, "Outlines"); - first = pdf_dict_gets(ctx, obj, "First"); + root = pdf_dict_get(ctx, pdf_trailer(ctx, doc), PDF_NAME_Root); + obj = pdf_dict_get(ctx, root, PDF_NAME_Outlines); + first = pdf_dict_get(ctx, obj, PDF_NAME_First); if (first) return pdf_load_outline_imp(ctx, doc, first); diff --git a/source/pdf/pdf-page.c b/source/pdf/pdf-page.c index 7917afbf..588ba093 100644 --- a/source/pdf/pdf-page.c +++ b/source/pdf/pdf-page.c @@ -36,7 +36,7 @@ pdf_lookup_page_loc_imp(fz_context *ctx, pdf_document *doc, pdf_obj *node, int * { do { - kids = pdf_dict_gets(ctx, node, "Kids"); + kids = pdf_dict_get(ctx, node, PDF_NAME_Kids); len = pdf_array_len(ctx, kids); if (len == 0) @@ -62,10 +62,10 @@ pdf_lookup_page_loc_imp(fz_context *ctx, pdf_document *doc, pdf_obj *node, int * for (i = 0; i < len; i++) { pdf_obj *kid = pdf_array_get(ctx, kids, i); - char *type = pdf_to_name(ctx, pdf_dict_gets(ctx, kid, "Type")); - if (*type ? !strcmp(type, "Pages") : pdf_dict_gets(ctx, kid, "Kids") && !pdf_dict_gets(ctx, kid, "MediaBox")) + pdf_obj *type = pdf_dict_get(ctx, kid, PDF_NAME_Type); + if (type ? pdf_name_eq(ctx, type, PDF_NAME_Pages) : pdf_dict_get(ctx, kid, PDF_NAME_Kids) && !pdf_dict_get(ctx, kid, PDF_NAME_MediaBox)) { - int count = pdf_to_int(ctx, pdf_dict_gets(ctx, kid, "Count")); + int count = pdf_to_int(ctx, pdf_dict_get(ctx, kid, PDF_NAME_Count)); if (*skip < count) { node = kid; @@ -78,8 +78,8 @@ pdf_lookup_page_loc_imp(fz_context *ctx, pdf_document *doc, pdf_obj *node, int * } else { - if (*type ? strcmp(type, "Page") != 0 : !pdf_dict_gets(ctx, kid, "MediaBox")) - fz_warn(ctx, "non-page object in page tree (%s)", type); + if (type ? !pdf_name_eq(ctx, type, PDF_NAME_Page) != 0 : !pdf_dict_get(ctx, kid, PDF_NAME_MediaBox)) + fz_warn(ctx, "non-page object in page tree (%s)", pdf_to_name(ctx, type)); if (*skip == 0) { if (parentp) *parentp = node; @@ -114,8 +114,8 @@ pdf_lookup_page_loc_imp(fz_context *ctx, pdf_document *doc, pdf_obj *node, int * pdf_obj * pdf_lookup_page_loc(fz_context *ctx, pdf_document *doc, int needle, pdf_obj **parentp, int *indexp) { - pdf_obj *root = pdf_dict_gets(ctx, pdf_trailer(ctx, doc), "Root"); - pdf_obj *node = pdf_dict_gets(ctx, root, "Pages"); + pdf_obj *root = pdf_dict_get(ctx, pdf_trailer(ctx, doc), PDF_NAME_Root); + pdf_obj *node = pdf_dict_get(ctx, root, PDF_NAME_Pages); int skip = needle; pdf_obj *hit; @@ -137,16 +137,16 @@ pdf_lookup_page_obj(fz_context *ctx, pdf_document *doc, int needle) static int pdf_count_pages_before_kid(fz_context *ctx, pdf_document *doc, pdf_obj *parent, int kid_num) { - pdf_obj *kids = pdf_dict_gets(ctx, parent, "Kids"); + pdf_obj *kids = pdf_dict_get(ctx, parent, PDF_NAME_Kids); int i, total = 0, len = pdf_array_len(ctx, kids); for (i = 0; i < len; i++) { pdf_obj *kid = pdf_array_get(ctx, kids, i); if (pdf_to_num(ctx, kid) == kid_num) return total; - if (!strcmp(pdf_to_name(ctx, pdf_dict_gets(ctx, kid, "Type")), "Pages")) + if (pdf_name_eq(ctx, pdf_dict_get(ctx, kid, PDF_NAME_Type), PDF_NAME_Pages)) { - pdf_obj *count = pdf_dict_gets(ctx, kid, "Count"); + pdf_obj *count = pdf_dict_get(ctx, kid, PDF_NAME_Count); int n = pdf_to_int(ctx, count); if (!pdf_is_int(ctx, count) || n < 0) fz_throw(ctx, FZ_ERROR_GENERIC, "illegal or missing count in pages tree"); @@ -165,10 +165,10 @@ pdf_lookup_page_number(fz_context *ctx, pdf_document *doc, pdf_obj *node) int total = 0; pdf_obj *parent, *parent2; - if (strcmp(pdf_to_name(ctx, pdf_dict_gets(ctx, node, "Type")), "Page") != 0) + if (!pdf_name_eq(ctx, pdf_dict_get(ctx, node, PDF_NAME_Type), PDF_NAME_Page) != 0) fz_throw(ctx, FZ_ERROR_GENERIC, "invalid page object"); - parent2 = parent = pdf_dict_gets(ctx, node, "Parent"); + parent2 = parent = pdf_dict_get(ctx, node, PDF_NAME_Parent); fz_var(parent); fz_try(ctx) { @@ -178,7 +178,7 @@ pdf_lookup_page_number(fz_context *ctx, pdf_document *doc, pdf_obj *node) fz_throw(ctx, FZ_ERROR_GENERIC, "cycle in page tree (parents)"); total += pdf_count_pages_before_kid(ctx, doc, parent, needle); needle = pdf_to_num(ctx, parent); - parent = pdf_dict_gets(ctx, parent, "Parent"); + parent = pdf_dict_get(ctx, parent, PDF_NAME_Parent); } } fz_always(ctx) @@ -189,7 +189,7 @@ pdf_lookup_page_number(fz_context *ctx, pdf_document *doc, pdf_obj *node) pdf_unmark_obj(ctx, parent2); if (parent2 == parent) break; - parent2 = pdf_dict_gets(ctx, parent2, "Parent"); + parent2 = pdf_dict_get(ctx, parent2, PDF_NAME_Parent); } } fz_catch(ctx) @@ -201,7 +201,7 @@ pdf_lookup_page_number(fz_context *ctx, pdf_document *doc, pdf_obj *node) } static pdf_obj * -pdf_lookup_inherited_page_item(fz_context *ctx, pdf_document *doc, pdf_obj *node, const char *key) +pdf_lookup_inherited_page_item(fz_context *ctx, pdf_document *doc, pdf_obj *node, pdf_obj *key) { pdf_obj *node2 = node; pdf_obj *val; @@ -212,12 +212,12 @@ pdf_lookup_inherited_page_item(fz_context *ctx, pdf_document *doc, pdf_obj *node { do { - val = pdf_dict_gets(ctx, node, key); + val = pdf_dict_get(ctx, node, key); if (val) break; if (pdf_mark_obj(ctx, node)) fz_throw(ctx, FZ_ERROR_GENERIC, "cycle in page tree (parents)"); - node = pdf_dict_gets(ctx, node, "Parent"); + node = pdf_dict_get(ctx, node, PDF_NAME_Parent); } while (node); } @@ -228,7 +228,7 @@ pdf_lookup_inherited_page_item(fz_context *ctx, pdf_document *doc, pdf_obj *node pdf_unmark_obj(ctx, node2); if (node2 == node) break; - node2 = pdf_dict_gets(ctx, node2, "Parent"); + node2 = pdf_dict_get(ctx, node2, PDF_NAME_Parent); } while (node2); } @@ -247,8 +247,8 @@ static int pdf_resources_use_blending(fz_context *ctx, pdf_document *doc, pdf_ob static int pdf_extgstate_uses_blending(fz_context *ctx, pdf_document *doc, pdf_obj *dict) { - pdf_obj *obj = pdf_dict_gets(ctx, dict, "BM"); - if (pdf_is_name(ctx, obj) && strcmp(pdf_to_name(ctx, obj), "Normal")) + pdf_obj *obj = pdf_dict_get(ctx, dict, PDF_NAME_BM); + if (obj && !pdf_name_eq(ctx, obj, PDF_NAME_Normal)) return 1; return 0; } @@ -257,18 +257,18 @@ static int pdf_pattern_uses_blending(fz_context *ctx, pdf_document *doc, pdf_obj *dict) { pdf_obj *obj; - obj = pdf_dict_gets(ctx, dict, "Resources"); + obj = pdf_dict_get(ctx, dict, PDF_NAME_Resources); if (pdf_resources_use_blending(ctx, doc, obj)) return 1; - obj = pdf_dict_gets(ctx, dict, "ExtGState"); + obj = pdf_dict_get(ctx, dict, PDF_NAME_ExtGState); return pdf_extgstate_uses_blending(ctx, doc, obj); } static int pdf_xobject_uses_blending(fz_context *ctx, pdf_document *doc, pdf_obj *dict) { - pdf_obj *obj = pdf_dict_gets(ctx, dict, "Resources"); - if (!strcmp(pdf_to_name(ctx, pdf_dict_getp(ctx, dict, "Group/S")), "Transparency")) + pdf_obj *obj = pdf_dict_get(ctx, dict, PDF_NAME_Resources); + if (pdf_name_eq(ctx, pdf_dict_getp(ctx, dict, "Group/S"), PDF_NAME_Transparency)) return 1; return pdf_resources_use_blending(ctx, doc, obj); } @@ -292,19 +292,19 @@ pdf_resources_use_blending(fz_context *ctx, pdf_document *doc, pdf_obj *rdb) fz_try(ctx) { - obj = pdf_dict_gets(ctx, rdb, "ExtGState"); + obj = pdf_dict_get(ctx, rdb, PDF_NAME_ExtGState); n = pdf_dict_len(ctx, obj); for (i = 0; i < n; i++) if (pdf_extgstate_uses_blending(ctx, doc, pdf_dict_get_val(ctx, obj, i))) goto found; - obj = pdf_dict_gets(ctx, rdb, "Pattern"); + obj = pdf_dict_get(ctx, rdb, PDF_NAME_Pattern); n = pdf_dict_len(ctx, obj); for (i = 0; i < n; i++) if (pdf_pattern_uses_blending(ctx, doc, pdf_dict_get_val(ctx, obj, i))) goto found; - obj = pdf_dict_gets(ctx, rdb, "XObject"); + obj = pdf_dict_get(ctx, rdb, PDF_NAME_XObject); n = pdf_dict_len(ctx, obj); for (i = 0; i < n; i++) if (pdf_xobject_uses_blending(ctx, doc, pdf_dict_get_val(ctx, obj, i))) @@ -331,43 +331,43 @@ found: static void pdf_load_transition(fz_context *ctx, pdf_document *doc, pdf_page *page, pdf_obj *transdict) { - char *name; + pdf_obj *name; pdf_obj *obj; int type; - obj = pdf_dict_gets(ctx, transdict, "D"); + obj = pdf_dict_get(ctx, transdict, PDF_NAME_D); page->transition.duration = (obj ? pdf_to_real(ctx, obj) : 1); - page->transition.vertical = (pdf_to_name(ctx, pdf_dict_gets(ctx, transdict, "Dm"))[0] != 'H'); - page->transition.outwards = (pdf_to_name(ctx, pdf_dict_gets(ctx, transdict, "M"))[0] != 'I'); + page->transition.vertical = !pdf_name_eq(ctx, pdf_dict_get(ctx, transdict, PDF_NAME_Dm), PDF_NAME_H); + page->transition.outwards = !pdf_name_eq(ctx, pdf_dict_get(ctx, transdict, PDF_NAME_M), PDF_NAME_I); /* FIXME: If 'Di' is None, it should be handled differently, but * this only affects Fly, and we don't implement that currently. */ - page->transition.direction = (pdf_to_int(ctx, pdf_dict_gets(ctx, transdict, "Di"))); + page->transition.direction = (pdf_to_int(ctx, pdf_dict_get(ctx, transdict, PDF_NAME_Di))); /* FIXME: Read SS for Fly when we implement it */ /* FIXME: Read B for Fly when we implement it */ - name = pdf_to_name(ctx, pdf_dict_gets(ctx, transdict, "S")); - if (!strcmp(name, "Split")) + name = pdf_dict_get(ctx, transdict, PDF_NAME_S); + if (pdf_name_eq(ctx, name, PDF_NAME_Split)) type = FZ_TRANSITION_SPLIT; - else if (!strcmp(name, "Blinds")) + else if (pdf_name_eq(ctx, name, PDF_NAME_Blinds)) type = FZ_TRANSITION_BLINDS; - else if (!strcmp(name, "Box")) + else if (pdf_name_eq(ctx, name, PDF_NAME_Box)) type = FZ_TRANSITION_BOX; - else if (!strcmp(name, "Wipe")) + else if (pdf_name_eq(ctx, name, PDF_NAME_Wipe)) type = FZ_TRANSITION_WIPE; - else if (!strcmp(name, "Dissolve")) + else if (pdf_name_eq(ctx, name, PDF_NAME_Dissolve)) type = FZ_TRANSITION_DISSOLVE; - else if (!strcmp(name, "Glitter")) + else if (pdf_name_eq(ctx, name, PDF_NAME_Glitter)) type = FZ_TRANSITION_GLITTER; - else if (!strcmp(name, "Fly")) + else if (pdf_name_eq(ctx, name, PDF_NAME_Fly)) type = FZ_TRANSITION_FLY; - else if (!strcmp(name, "Push")) + else if (pdf_name_eq(ctx, name, PDF_NAME_Push)) type = FZ_TRANSITION_PUSH; - else if (!strcmp(name, "Cover")) + else if (pdf_name_eq(ctx, name, PDF_NAME_Cover)) type = FZ_TRANSITION_COVER; - else if (!strcmp(name, "Uncover")) + else if (pdf_name_eq(ctx, name, PDF_NAME_Uncover)) type = FZ_TRANSITION_UNCOVER; - else if (!strcmp(name, "Fade")) + else if (pdf_name_eq(ctx, name, PDF_NAME_Fade)) type = FZ_TRANSITION_FADE; else type = FZ_TRANSITION_NONE; @@ -464,13 +464,13 @@ pdf_load_page(fz_context *ctx, pdf_document *doc, int number) page->me = pdf_keep_obj(ctx, pageobj); page->incomplete = 0; - obj = pdf_dict_gets(ctx, pageobj, "UserUnit"); + obj = pdf_dict_get(ctx, pageobj, PDF_NAME_UserUnit); if (pdf_is_real(ctx, obj)) userunit = pdf_to_real(ctx, obj); else userunit = 1; - pdf_to_rect(ctx, pdf_lookup_inherited_page_item(ctx, doc, pageobj, "MediaBox"), &mediabox); + pdf_to_rect(ctx, pdf_lookup_inherited_page_item(ctx, doc, pageobj, PDF_NAME_MediaBox), &mediabox); if (fz_is_empty_rect(&mediabox)) { fz_warn(ctx, "cannot find page size for page %d", number + 1); @@ -480,7 +480,7 @@ pdf_load_page(fz_context *ctx, pdf_document *doc, int number) mediabox.y1 = 792; } - pdf_to_rect(ctx, pdf_lookup_inherited_page_item(ctx, doc, pageobj, "CropBox"), &cropbox); + pdf_to_rect(ctx, pdf_lookup_inherited_page_item(ctx, doc, pageobj, PDF_NAME_CropBox), &cropbox); if (!fz_is_empty_rect(&cropbox)) fz_intersect_rect(&mediabox, &cropbox); @@ -495,7 +495,7 @@ pdf_load_page(fz_context *ctx, pdf_document *doc, int number) page->mediabox = fz_unit_rect; } - page->rotate = pdf_to_int(ctx, pdf_lookup_inherited_page_item(ctx, doc, pageobj, "Rotate")); + page->rotate = pdf_to_int(ctx, pdf_lookup_inherited_page_item(ctx, doc, pageobj, PDF_NAME_Rotate)); /* Snap page->rotate to 0, 90, 180 or 270 */ if (page->rotate < 0) page->rotate = 360 - ((-page->rotate) % 360); @@ -513,7 +513,7 @@ pdf_load_page(fz_context *ctx, pdf_document *doc, int number) fz_try(ctx) { - obj = pdf_dict_gets(ctx, pageobj, "Annots"); + obj = pdf_dict_get(ctx, pageobj, PDF_NAME_Annots); if (obj) { page->links = pdf_load_link_annots(ctx, doc, obj, &page->ctm); @@ -529,9 +529,9 @@ pdf_load_page(fz_context *ctx, pdf_document *doc, int number) page->links = NULL; } - page->duration = pdf_to_real(ctx, pdf_dict_gets(ctx, pageobj, "Dur")); + page->duration = pdf_to_real(ctx, pdf_dict_get(ctx, pageobj, PDF_NAME_Dur)); - obj = pdf_dict_gets(ctx, pageobj, "Trans"); + obj = pdf_dict_get(ctx, pageobj, PDF_NAME_Trans); page->transition_present = (obj != NULL); if (obj) { @@ -539,18 +539,18 @@ pdf_load_page(fz_context *ctx, pdf_document *doc, int number) } // TODO: inherit - page->resources = pdf_lookup_inherited_page_item(ctx, doc, pageobj, "Resources"); + page->resources = pdf_lookup_inherited_page_item(ctx, doc, pageobj, PDF_NAME_Resources); if (page->resources) pdf_keep_obj(ctx, page->resources); - obj = pdf_dict_gets(ctx, pageobj, "Contents"); + obj = pdf_dict_get(ctx, pageobj, PDF_NAME_Contents); fz_try(ctx) { page->contents = pdf_keep_obj(ctx, obj); if (pdf_resources_use_blending(ctx, doc, page->resources)) page->transparency = 1; - else if (!strcmp(pdf_to_name(ctx, pdf_dict_getp(ctx, pageobj, "Group/S")), "Transparency")) + else if (pdf_name_eq(ctx, pdf_dict_getp(ctx, pageobj, "Group/S"), PDF_NAME_Transparency)) page->transparency = 1; for (annot = page->annots; annot && !page->transparency; annot = annot->next) @@ -577,14 +577,14 @@ pdf_delete_page(fz_context *ctx, pdf_document *doc, int at) int i; pdf_lookup_page_loc(ctx, doc, at, &parent, &i); - kids = pdf_dict_gets(ctx, parent, "Kids"); + kids = pdf_dict_get(ctx, parent, PDF_NAME_Kids); pdf_array_delete(ctx, kids, i); while (parent) { - int count = pdf_to_int(ctx, pdf_dict_gets(ctx, parent, "Count")); - pdf_dict_puts_drop(ctx, parent, "Count", pdf_new_int(ctx, doc, count - 1)); - parent = pdf_dict_gets(ctx, parent, "Parent"); + int count = pdf_to_int(ctx, pdf_dict_get(ctx, parent, PDF_NAME_Count)); + pdf_dict_put_drop(ctx, parent, PDF_NAME_Count, pdf_new_int(ctx, doc, count - 1)); + parent = pdf_dict_get(ctx, parent, PDF_NAME_Parent); } doc->page_count = 0; /* invalidate cached value */ @@ -604,12 +604,12 @@ pdf_insert_page(fz_context *ctx, pdf_document *doc, pdf_page *page, int at) { if (count == 0) { - pdf_obj *root = pdf_dict_gets(ctx, pdf_trailer(ctx, doc), "Root"); - parent = pdf_dict_gets(ctx, root, "Pages"); + pdf_obj *root = pdf_dict_get(ctx, pdf_trailer(ctx, doc), PDF_NAME_Root); + parent = pdf_dict_get(ctx, root, PDF_NAME_Pages); if (!parent) fz_throw(ctx, FZ_ERROR_GENERIC, "cannot find page tree"); - kids = pdf_dict_gets(ctx, parent, "Kids"); + kids = pdf_dict_get(ctx, parent, PDF_NAME_Kids); if (!kids) fz_throw(ctx, FZ_ERROR_GENERIC, "malformed page tree"); @@ -625,25 +625,25 @@ pdf_insert_page(fz_context *ctx, pdf_document *doc, pdf_page *page, int at) /* append after last page */ pdf_lookup_page_loc(ctx, doc, count - 1, &parent, &i); - kids = pdf_dict_gets(ctx, parent, "Kids"); + kids = pdf_dict_get(ctx, parent, PDF_NAME_Kids); pdf_array_insert(ctx, kids, page_ref, i + 1); } else { /* insert before found page */ pdf_lookup_page_loc(ctx, doc, at, &parent, &i); - kids = pdf_dict_gets(ctx, parent, "Kids"); + kids = pdf_dict_get(ctx, parent, PDF_NAME_Kids); pdf_array_insert(ctx, kids, page_ref, i); } - pdf_dict_puts(ctx, page->me, "Parent", parent); + pdf_dict_put(ctx, page->me, PDF_NAME_Parent, parent); /* Adjust page counts */ while (parent) { - int count = pdf_to_int(ctx, pdf_dict_gets(ctx, parent, "Count")); - pdf_dict_puts_drop(ctx, parent, "Count", pdf_new_int(ctx, doc, count + 1)); - parent = pdf_dict_gets(ctx, parent, "Parent"); + int count = pdf_to_int(ctx, pdf_dict_get(ctx, parent, PDF_NAME_Count)); + pdf_dict_put_drop(ctx, parent, PDF_NAME_Count, pdf_new_int(ctx, doc, count + 1)); + parent = pdf_dict_get(ctx, parent, PDF_NAME_Parent); } } @@ -686,13 +686,13 @@ pdf_create_page(fz_context *ctx, pdf_document *doc, fz_rect mediabox, int res, i page->annots = NULL; page->me = pageobj = pdf_new_dict(ctx, doc, 4); - pdf_dict_puts_drop(ctx, pageobj, "Type", pdf_new_name(ctx, doc, "Page")); + pdf_dict_put_drop(ctx, pageobj, PDF_NAME_Type, PDF_NAME_Page); page->mediabox.x0 = fz_min(mediabox.x0, mediabox.x1) * userunit; page->mediabox.y0 = fz_min(mediabox.y0, mediabox.y1) * userunit; page->mediabox.x1 = fz_max(mediabox.x0, mediabox.x1) * userunit; page->mediabox.y1 = fz_max(mediabox.y0, mediabox.y1) * userunit; - pdf_dict_puts_drop(ctx, pageobj, "MediaBox", pdf_new_rect(ctx, doc, &page->mediabox)); + pdf_dict_put_drop(ctx, pageobj, PDF_NAME_MediaBox, pdf_new_rect(ctx, doc, &page->mediabox)); /* Snap page->rotate to 0, 90, 180 or 270 */ if (page->rotate < 0) @@ -702,7 +702,7 @@ pdf_create_page(fz_context *ctx, pdf_document *doc, fz_rect mediabox, int res, i page->rotate = 90*((page->rotate + 45)/90); if (page->rotate > 360) page->rotate = 0; - pdf_dict_puts_drop(ctx, pageobj, "Rotate", pdf_new_int(ctx, doc, page->rotate)); + pdf_dict_put_drop(ctx, pageobj, PDF_NAME_Rotate, pdf_new_int(ctx, doc, page->rotate)); fz_pre_rotate(fz_scale(&ctm, 1, -1), -page->rotate); realbox = page->mediabox; diff --git a/source/pdf/pdf-pattern.c b/source/pdf/pdf-pattern.c index 32fd077c..0dc42d58 100644 --- a/source/pdf/pdf-pattern.c +++ b/source/pdf/pdf-pattern.c @@ -53,9 +53,9 @@ pdf_load_pattern(fz_context *ctx, pdf_document *doc, pdf_obj *dict) /* Store pattern now, to avoid possible recursion if objects refer back to this one */ pdf_store_item(ctx, dict, pat, pdf_pattern_size(pat)); - pat->ismask = pdf_to_int(ctx, pdf_dict_gets(ctx, dict, "PaintType")) == 2; - pat->xstep = pdf_to_real(ctx, pdf_dict_gets(ctx, dict, "XStep")); - pat->ystep = pdf_to_real(ctx, pdf_dict_gets(ctx, dict, "YStep")); + pat->ismask = pdf_to_int(ctx, pdf_dict_get(ctx, dict, PDF_NAME_PaintType)) == 2; + 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"); pdf_to_rect(ctx, obj, &pat->bbox); @@ -66,7 +66,7 @@ pdf_load_pattern(fz_context *ctx, pdf_document *doc, pdf_obj *dict) else pat->matrix = fz_identity; - pat->resources = pdf_dict_gets(ctx, dict, "Resources"); + pat->resources = pdf_dict_get(ctx, dict, PDF_NAME_Resources); if (pat->resources) pdf_keep_obj(ctx, pat->resources); diff --git a/source/pdf/pdf-pkcs7.c b/source/pdf/pdf-pkcs7.c index c1a97599..93abd474 100644 --- a/source/pdf/pdf-pkcs7.c +++ b/source/pdf/pdf-pkcs7.c @@ -737,7 +737,7 @@ void pdf_sign_signature(fz_context *ctx, pdf_document *doc, pdf_widget *widget, pdf_signature_set_value(ctx, doc, wobj, signer); - pdf_to_rect(ctx, pdf_dict_gets(ctx, wobj, "Rect"), &rect); + pdf_to_rect(ctx, pdf_dict_get(ctx, wobj, PDF_NAME_Rect), &rect); /* Create an appearance stream only if the signature is intended to be visible */ if (!fz_is_empty_rect(&rect)) { diff --git a/source/pdf/pdf-repair.c b/source/pdf/pdf-repair.c index 0c1c504c..3c149177 100644 --- a/source/pdf/pdf-repair.c +++ b/source/pdf/pdf-repair.c @@ -54,17 +54,17 @@ pdf_repair_obj(fz_context *ctx, pdf_document *doc, pdf_lexbuf *buf, int *stmofsp if (encrypt && id) { - obj = pdf_dict_gets(ctx, dict, "Type"); - if (pdf_is_name(ctx, obj) && !strcmp(pdf_to_name(ctx, obj), "XRef")) + obj = pdf_dict_get(ctx, dict, PDF_NAME_Type); + if (pdf_name_eq(ctx, obj, PDF_NAME_XRef)) { - obj = pdf_dict_gets(ctx, dict, "Encrypt"); + obj = pdf_dict_get(ctx, dict, PDF_NAME_Encrypt); if (obj) { pdf_drop_obj(ctx, *encrypt); *encrypt = pdf_keep_obj(ctx, obj); } - obj = pdf_dict_gets(ctx, dict, "ID"); + obj = pdf_dict_get(ctx, dict, PDF_NAME_ID); if (obj) { pdf_drop_obj(ctx, *id); @@ -73,14 +73,14 @@ pdf_repair_obj(fz_context *ctx, pdf_document *doc, pdf_lexbuf *buf, int *stmofsp } } - obj = pdf_dict_gets(ctx, dict, "Length"); + obj = pdf_dict_get(ctx, dict, PDF_NAME_Length); if (!pdf_is_indirect(ctx, obj) && pdf_is_int(ctx, obj)) stm_len = pdf_to_int(ctx, obj); if (doc->file_reading_linearly && page) { - obj = pdf_dict_gets(ctx, dict, "Type"); - if (!strcmp(pdf_to_name(ctx, obj), "Page")) + obj = pdf_dict_get(ctx, dict, PDF_NAME_Type); + if (pdf_name_eq(ctx, obj, PDF_NAME_Page)) { pdf_drop_obj(ctx, *page); *page = pdf_keep_obj(ctx, dict); @@ -182,7 +182,7 @@ pdf_repair_obj_stm(fz_context *ctx, pdf_document *doc, int num, int gen) { obj = pdf_load_object(ctx, doc, num, gen); - count = pdf_to_int(ctx, pdf_dict_gets(ctx, obj, "N")); + count = pdf_to_int(ctx, pdf_dict_get(ctx, obj, PDF_NAME_N)); pdf_drop_obj(ctx, obj); @@ -403,28 +403,28 @@ pdf_repair_xref(fz_context *ctx, pdf_document *doc) continue; } - obj = pdf_dict_gets(ctx, dict, "Encrypt"); + obj = pdf_dict_get(ctx, dict, PDF_NAME_Encrypt); if (obj) { pdf_drop_obj(ctx, encrypt); encrypt = pdf_keep_obj(ctx, obj); } - obj = pdf_dict_gets(ctx, dict, "ID"); - if (obj && (!id || !encrypt || pdf_dict_gets(ctx, dict, "Encrypt"))) + obj = pdf_dict_get(ctx, dict, PDF_NAME_ID); + if (obj && (!id || !encrypt || pdf_dict_get(ctx, dict, PDF_NAME_Encrypt))) { pdf_drop_obj(ctx, id); id = pdf_keep_obj(ctx, obj); } - obj = pdf_dict_gets(ctx, dict, "Root"); + obj = pdf_dict_get(ctx, dict, PDF_NAME_Root); if (obj) { pdf_drop_obj(ctx, root); root = pdf_keep_obj(ctx, obj); } - obj = pdf_dict_gets(ctx, dict, "Info"); + obj = pdf_dict_get(ctx, dict, PDF_NAME_Info); if (obj) { pdf_drop_obj(ctx, info); @@ -472,7 +472,7 @@ pdf_repair_xref(fz_context *ctx, pdf_document *doc) dict = pdf_load_object(ctx, doc, list[i].num, list[i].gen); length = pdf_new_int(ctx, doc, list[i].stm_len); - pdf_dict_puts(ctx, dict, "Length", length); + pdf_dict_put(ctx, dict, PDF_NAME_Length, length); pdf_drop_obj(ctx, length); pdf_drop_obj(ctx, dict); @@ -507,19 +507,19 @@ pdf_repair_xref(fz_context *ctx, pdf_document *doc) obj = NULL; obj = pdf_new_int(ctx, doc, maxnum + 1); - pdf_dict_puts(ctx, pdf_trailer(ctx, doc), "Size", obj); + pdf_dict_put(ctx, pdf_trailer(ctx, doc), PDF_NAME_Size, obj); pdf_drop_obj(ctx, obj); obj = NULL; if (root) { - pdf_dict_puts(ctx, pdf_trailer(ctx, doc), "Root", root); + pdf_dict_put(ctx, pdf_trailer(ctx, doc), PDF_NAME_Root, root); pdf_drop_obj(ctx, root); root = NULL; } if (info) { - pdf_dict_puts(ctx, pdf_trailer(ctx, doc), "Info", info); + pdf_dict_put(ctx, pdf_trailer(ctx, doc), PDF_NAME_Info, info); pdf_drop_obj(ctx, info); info = NULL; } @@ -534,7 +534,7 @@ pdf_repair_xref(fz_context *ctx, pdf_document *doc) encrypt = obj; obj = NULL; } - pdf_dict_puts(ctx, pdf_trailer(ctx, doc), "Encrypt", encrypt); + pdf_dict_put(ctx, pdf_trailer(ctx, doc), PDF_NAME_Encrypt, encrypt); pdf_drop_obj(ctx, encrypt); encrypt = NULL; } @@ -549,7 +549,7 @@ pdf_repair_xref(fz_context *ctx, pdf_document *doc) id = obj; obj = NULL; } - pdf_dict_puts(ctx, pdf_trailer(ctx, doc), "ID", id); + pdf_dict_put(ctx, pdf_trailer(ctx, doc), PDF_NAME_ID, id); pdf_drop_obj(ctx, id); id = NULL; } @@ -584,7 +584,7 @@ pdf_repair_obj_stms(fz_context *ctx, pdf_document *doc) dict = pdf_load_object(ctx, doc, i, 0); fz_try(ctx) { - if (!strcmp(pdf_to_name(ctx, pdf_dict_gets(ctx, dict, "Type")), "ObjStm")) + if (pdf_name_eq(ctx, pdf_dict_get(ctx, dict, PDF_NAME_Type), PDF_NAME_ObjStm)) pdf_repair_obj_stm(ctx, doc, i, 0); } fz_catch(ctx) diff --git a/source/pdf/pdf-shade.c b/source/pdf/pdf-shade.c index 4203d1b0..94b87cc5 100644 --- a/source/pdf/pdf-shade.c +++ b/source/pdf/pdf-shade.c @@ -58,7 +58,7 @@ pdf_load_function_based_shading(fz_context *ctx, pdf_document *doc, fz_shade *sh x0 = y0 = 0; x1 = y1 = 1; - obj = pdf_dict_gets(ctx, dict, "Domain"); + obj = pdf_dict_get(ctx, dict, PDF_NAME_Domain); if (obj) { x0 = pdf_to_real(ctx, pdf_array_get(ctx, obj, 0)); @@ -67,7 +67,7 @@ pdf_load_function_based_shading(fz_context *ctx, pdf_document *doc, fz_shade *sh y1 = pdf_to_real(ctx, pdf_array_get(ctx, obj, 3)); } - obj = pdf_dict_gets(ctx, dict, "Matrix"); + obj = pdf_dict_get(ctx, dict, PDF_NAME_Matrix); if (obj) pdf_to_matrix(ctx, obj, &matrix); else @@ -103,7 +103,7 @@ pdf_load_linear_shading(fz_context *ctx, pdf_document *doc, fz_shade *shade, pdf float d0, d1; int e0, e1; - obj = pdf_dict_gets(ctx, dict, "Coords"); + obj = pdf_dict_get(ctx, dict, PDF_NAME_Coords); shade->u.l_or_r.coords[0][0] = pdf_to_real(ctx, pdf_array_get(ctx, obj, 0)); shade->u.l_or_r.coords[0][1] = pdf_to_real(ctx, pdf_array_get(ctx, obj, 1)); shade->u.l_or_r.coords[1][0] = pdf_to_real(ctx, pdf_array_get(ctx, obj, 2)); @@ -111,7 +111,7 @@ pdf_load_linear_shading(fz_context *ctx, pdf_document *doc, fz_shade *shade, pdf d0 = 0; d1 = 1; - obj = pdf_dict_gets(ctx, dict, "Domain"); + obj = pdf_dict_get(ctx, dict, PDF_NAME_Domain); if (obj) { d0 = pdf_to_real(ctx, pdf_array_get(ctx, obj, 0)); @@ -119,7 +119,7 @@ pdf_load_linear_shading(fz_context *ctx, pdf_document *doc, fz_shade *shade, pdf } e0 = e1 = 0; - obj = pdf_dict_gets(ctx, dict, "Extend"); + obj = pdf_dict_get(ctx, dict, PDF_NAME_Extend); if (obj) { e0 = pdf_to_bool(ctx, pdf_array_get(ctx, obj, 0)); @@ -139,7 +139,7 @@ pdf_load_radial_shading(fz_context *ctx, pdf_document *doc, fz_shade *shade, pdf float d0, d1; int e0, e1; - obj = pdf_dict_gets(ctx, dict, "Coords"); + obj = pdf_dict_get(ctx, dict, PDF_NAME_Coords); shade->u.l_or_r.coords[0][0] = pdf_to_real(ctx, pdf_array_get(ctx, obj, 0)); shade->u.l_or_r.coords[0][1] = pdf_to_real(ctx, pdf_array_get(ctx, obj, 1)); shade->u.l_or_r.coords[0][2] = pdf_to_real(ctx, pdf_array_get(ctx, obj, 2)); @@ -149,7 +149,7 @@ pdf_load_radial_shading(fz_context *ctx, pdf_document *doc, fz_shade *shade, pdf d0 = 0; d1 = 1; - obj = pdf_dict_gets(ctx, dict, "Domain"); + obj = pdf_dict_get(ctx, dict, PDF_NAME_Domain); if (obj) { d0 = pdf_to_real(ctx, pdf_array_get(ctx, obj, 0)); @@ -157,7 +157,7 @@ pdf_load_radial_shading(fz_context *ctx, pdf_document *doc, fz_shade *shade, pdf } e0 = e1 = 0; - obj = pdf_dict_gets(ctx, dict, "Extend"); + obj = pdf_dict_get(ctx, dict, PDF_NAME_Extend); if (obj) { e0 = pdf_to_bool(ctx, pdf_array_get(ctx, obj, 0)); @@ -198,12 +198,12 @@ pdf_load_mesh_params(fz_context *ctx, pdf_document *doc, fz_shade *shade, pdf_ob shade->u.m.c1[i] = 1; } - shade->u.m.vprow = pdf_to_int(ctx, pdf_dict_gets(ctx, dict, "VerticesPerRow")); - shade->u.m.bpflag = pdf_to_int(ctx, pdf_dict_gets(ctx, dict, "BitsPerFlag")); - shade->u.m.bpcoord = pdf_to_int(ctx, pdf_dict_gets(ctx, dict, "BitsPerCoordinate")); - shade->u.m.bpcomp = pdf_to_int(ctx, pdf_dict_gets(ctx, dict, "BitsPerComponent")); + shade->u.m.vprow = pdf_to_int(ctx, pdf_dict_get(ctx, dict, PDF_NAME_VerticesPerRow)); + shade->u.m.bpflag = pdf_to_int(ctx, pdf_dict_get(ctx, dict, PDF_NAME_BitsPerFlag)); + shade->u.m.bpcoord = pdf_to_int(ctx, pdf_dict_get(ctx, dict, PDF_NAME_BitsPerCoordinate)); + shade->u.m.bpcomp = pdf_to_int(ctx, pdf_dict_get(ctx, dict, PDF_NAME_BitsPerComponent)); - obj = pdf_dict_gets(ctx, dict, "Decode"); + obj = pdf_dict_get(ctx, dict, PDF_NAME_Decode); if (pdf_array_len(ctx, obj) >= 6) { n = (pdf_array_len(ctx, obj) - 4) / 2; @@ -328,15 +328,15 @@ pdf_load_shading_dict(fz_context *ctx, pdf_document *doc, pdf_obj *dict, const f funcs = 0; - obj = pdf_dict_gets(ctx, dict, "ShadingType"); + obj = pdf_dict_get(ctx, dict, PDF_NAME_ShadingType); type = pdf_to_int(ctx, obj); - obj = pdf_dict_gets(ctx, dict, "ColorSpace"); + obj = pdf_dict_get(ctx, dict, PDF_NAME_ColorSpace); if (!obj) fz_throw(ctx, FZ_ERROR_GENERIC, "shading colorspace is missing"); shade->colorspace = pdf_load_colorspace(ctx, doc, obj); - obj = pdf_dict_gets(ctx, dict, "Background"); + obj = pdf_dict_get(ctx, dict, PDF_NAME_Background); if (obj) { shade->use_background = 1; @@ -344,11 +344,11 @@ pdf_load_shading_dict(fz_context *ctx, pdf_document *doc, pdf_obj *dict, const f shade->background[i] = pdf_to_real(ctx, pdf_array_get(ctx, obj, i)); } - obj = pdf_dict_gets(ctx, dict, "BBox"); + obj = pdf_dict_get(ctx, dict, PDF_NAME_BBox); if (pdf_is_array(ctx, obj)) pdf_to_rect(ctx, obj, &shade->bbox); - obj = pdf_dict_gets(ctx, dict, "Function"); + obj = pdf_dict_get(ctx, dict, PDF_NAME_Function); if (pdf_is_dict(ctx, obj)) { funcs = 1; @@ -448,24 +448,24 @@ pdf_load_shading(fz_context *ctx, pdf_document *doc, pdf_obj *dict) } /* Type 2 pattern dictionary */ - if (pdf_dict_gets(ctx, dict, "PatternType")) + if (pdf_dict_get(ctx, dict, PDF_NAME_PatternType)) { - obj = pdf_dict_gets(ctx, dict, "Matrix"); + obj = pdf_dict_get(ctx, dict, PDF_NAME_Matrix); if (obj) pdf_to_matrix(ctx, obj, &mat); else mat = fz_identity; - obj = pdf_dict_gets(ctx, dict, "ExtGState"); + obj = pdf_dict_get(ctx, dict, PDF_NAME_ExtGState); if (obj) { - if (pdf_dict_gets(ctx, obj, "CA") || pdf_dict_gets(ctx, obj, "ca")) + if (pdf_dict_get(ctx, obj, PDF_NAME_CA) || pdf_dict_get(ctx, obj, PDF_NAME_ca)) { fz_warn(ctx, "shading with alpha not supported"); } } - obj = pdf_dict_gets(ctx, dict, "Shading"); + obj = pdf_dict_get(ctx, dict, PDF_NAME_Shading); if (!obj) fz_throw(ctx, FZ_ERROR_GENERIC, "syntaxerror: missing shading dictionary"); diff --git a/source/pdf/pdf-stream.c b/source/pdf/pdf-stream.c index 15fdd29a..ad1e5e2c 100644 --- a/source/pdf/pdf-stream.c +++ b/source/pdf/pdf-stream.c @@ -26,10 +26,10 @@ pdf_stream_has_crypt(fz_context *ctx, pdf_obj *stm) pdf_obj *obj; int i; - filters = pdf_dict_getsa(ctx, stm, "Filter", "F"); + filters = pdf_dict_geta(ctx, stm, PDF_NAME_Filter, PDF_NAME_F); if (filters) { - if (!strcmp(pdf_to_name(ctx, filters), "Crypt")) + if (pdf_name_eq(ctx, filters, PDF_NAME_Crypt)) return 1; if (pdf_is_array(ctx, filters)) { @@ -37,7 +37,7 @@ pdf_stream_has_crypt(fz_context *ctx, pdf_obj *stm) for (i = 0; i < n; i++) { obj = pdf_array_get(ctx, filters, i); - if (!strcmp(pdf_to_name(ctx, obj), "Crypt")) + if (pdf_name_eq(ctx, obj, PDF_NAME_Crypt)) return 1; } } @@ -82,31 +82,29 @@ pdf_load_jbig2_globals(fz_context *ctx, pdf_document *doc, pdf_obj *dict) static fz_stream * build_filter(fz_context *ctx, fz_stream *chain, pdf_document *doc, pdf_obj *f, pdf_obj *p, int num, int gen, fz_compression_params *params) { - char *s = pdf_to_name(ctx, f); - - int predictor = pdf_to_int(ctx, pdf_dict_gets(ctx, p, "Predictor")); - pdf_obj *columns_obj = pdf_dict_gets(ctx, p, "Columns"); + int predictor = pdf_to_int(ctx, pdf_dict_get(ctx, p, PDF_NAME_Predictor)); + pdf_obj *columns_obj = pdf_dict_get(ctx, p, PDF_NAME_Columns); int columns = pdf_to_int(ctx, columns_obj); - int colors = pdf_to_int(ctx, pdf_dict_gets(ctx, p, "Colors")); - int bpc = pdf_to_int(ctx, pdf_dict_gets(ctx, p, "BitsPerComponent")); + int colors = pdf_to_int(ctx, pdf_dict_get(ctx, p, PDF_NAME_Colors)); + int bpc = pdf_to_int(ctx, pdf_dict_get(ctx, p, PDF_NAME_BitsPerComponent)); if (params) params->type = FZ_IMAGE_RAW; - if (!strcmp(s, "ASCIIHexDecode") || !strcmp(s, "AHx")) + if (pdf_name_eq(ctx, f, PDF_NAME_ASCIIHexDecode) || pdf_name_eq(ctx, f, PDF_NAME_AHx)) return fz_open_ahxd(ctx, chain); - else if (!strcmp(s, "ASCII85Decode") || !strcmp(s, "A85")) + else if (pdf_name_eq(ctx, f, PDF_NAME_ASCII85Decode) || pdf_name_eq(ctx, f, PDF_NAME_A85)) return fz_open_a85d(ctx, chain); - else if (!strcmp(s, "CCITTFaxDecode") || !strcmp(s, "CCF")) + else if (pdf_name_eq(ctx, f, PDF_NAME_CCITTFaxDecode) || pdf_name_eq(ctx, f, PDF_NAME_CCF)) { - pdf_obj *k = pdf_dict_gets(ctx, p, "K"); - pdf_obj *eol = pdf_dict_gets(ctx, p, "EndOfLine"); - pdf_obj *eba = pdf_dict_gets(ctx, p, "EncodedByteAlign"); - pdf_obj *rows = pdf_dict_gets(ctx, p, "Rows"); - pdf_obj *eob = pdf_dict_gets(ctx, p, "EndOfBlock"); - pdf_obj *bi1 = pdf_dict_gets(ctx, p, "BlackIs1"); + pdf_obj *k = pdf_dict_get(ctx, p, PDF_NAME_K); + pdf_obj *eol = pdf_dict_get(ctx, p, PDF_NAME_EndOfLine); + pdf_obj *eba = pdf_dict_get(ctx, p, PDF_NAME_EncodedByteAlign); + pdf_obj *rows = pdf_dict_get(ctx, p, PDF_NAME_Rows); + pdf_obj *eob = pdf_dict_get(ctx, p, PDF_NAME_EndOfBlock); + pdf_obj *bi1 = pdf_dict_get(ctx, p, PDF_NAME_BlackIs1); if (params) { /* We will shortstop here */ @@ -130,9 +128,9 @@ build_filter(fz_context *ctx, fz_stream *chain, pdf_document *doc, pdf_obj *f, p bi1 ? pdf_to_bool(ctx, bi1) : 0); } - else if (!strcmp(s, "DCTDecode") || !strcmp(s, "DCT")) + else if (pdf_name_eq(ctx, f, PDF_NAME_DCTDecode) || pdf_name_eq(ctx, f, PDF_NAME_DCT)) { - pdf_obj *ct = pdf_dict_gets(ctx, p, "ColorTransform"); + pdf_obj *ct = pdf_dict_get(ctx, p, PDF_NAME_ColorTransform); if (params) { /* We will shortstop here */ @@ -143,7 +141,7 @@ build_filter(fz_context *ctx, fz_stream *chain, pdf_document *doc, pdf_obj *f, p return fz_open_dctd(ctx, chain, ct ? pdf_to_int(ctx, ct) : -1, 0, NULL); } - else if (!strcmp(s, "RunLengthDecode") || !strcmp(s, "RL")) + else if (pdf_name_eq(ctx, f, PDF_NAME_RunLengthDecode) || pdf_name_eq(ctx, f, PDF_NAME_RL)) { if (params) { @@ -153,7 +151,7 @@ build_filter(fz_context *ctx, fz_stream *chain, pdf_document *doc, pdf_obj *f, p } return fz_open_rld(ctx, chain); } - else if (!strcmp(s, "FlateDecode") || !strcmp(s, "Fl")) + else if (pdf_name_eq(ctx, f, PDF_NAME_FlateDecode) || pdf_name_eq(ctx, f, PDF_NAME_Fl)) { if (params) { @@ -171,9 +169,9 @@ build_filter(fz_context *ctx, fz_stream *chain, pdf_document *doc, pdf_obj *f, p return chain; } - else if (!strcmp(s, "LZWDecode") || !strcmp(s, "LZW")) + else if (pdf_name_eq(ctx, f, PDF_NAME_LZWDecode) || pdf_name_eq(ctx, f, PDF_NAME_LZW)) { - pdf_obj *ec = pdf_dict_gets(ctx, p, "EarlyChange"); + pdf_obj *ec = pdf_dict_get(ctx, p, PDF_NAME_EarlyChange); if (params) { /* We will shortstop here */ @@ -191,20 +189,20 @@ build_filter(fz_context *ctx, fz_stream *chain, pdf_document *doc, pdf_obj *f, p return chain; } - else if (!strcmp(s, "JBIG2Decode")) + else if (pdf_name_eq(ctx, f, PDF_NAME_JBIG2Decode)) { fz_jbig2_globals *globals = NULL; - pdf_obj *obj = pdf_dict_gets(ctx, p, "JBIG2Globals"); + pdf_obj *obj = pdf_dict_get(ctx, p, PDF_NAME_JBIG2Globals); if (pdf_is_indirect(ctx, obj)) globals = pdf_load_jbig2_globals(ctx, doc, obj); /* fz_open_jbig2d takes possession of globals */ return fz_open_jbig2d(ctx, chain, globals); } - else if (!strcmp(s, "JPXDecode")) + else if (pdf_name_eq(ctx, f, PDF_NAME_JPXDecode)) return chain; /* JPX decoding is special cased in the image loading code */ - else if (!strcmp(s, "Crypt")) + else if (pdf_name_eq(ctx, f, PDF_NAME_Crypt)) { pdf_obj *name; @@ -214,14 +212,14 @@ build_filter(fz_context *ctx, fz_stream *chain, pdf_document *doc, pdf_obj *f, p return chain; } - name = pdf_dict_gets(ctx, p, "Name"); + name = pdf_dict_get(ctx, p, PDF_NAME_Name); if (pdf_is_name(ctx, name)) - return pdf_open_crypt_with_filter(ctx, chain, doc->crypt, pdf_to_name(ctx, name), num, gen); + return pdf_open_crypt_with_filter(ctx, chain, doc->crypt, name, num, gen); return chain; } - fz_warn(ctx, "unknown filter name (%s)", s); + fz_warn(ctx, "unknown filter name (%s)", pdf_to_name(ctx, f)); return chain; } @@ -284,7 +282,7 @@ pdf_open_raw_filter(fz_context *ctx, fz_stream *chain, pdf_document *doc, pdf_ob /* don't close chain when we close this filter */ fz_keep_stream(ctx, chain); - len = pdf_to_int(ctx, pdf_dict_gets(ctx, stmobj, "Length")); + len = pdf_to_int(ctx, pdf_dict_get(ctx, stmobj, PDF_NAME_Length)); chain = fz_open_null(ctx, chain, len, offset); hascrypt = pdf_stream_has_crypt(ctx, stmobj); @@ -304,8 +302,8 @@ pdf_open_filter(fz_context *ctx, pdf_document *doc, fz_stream *chain, pdf_obj *s pdf_obj *filters; pdf_obj *params; - filters = pdf_dict_getsa(ctx, stmobj, "Filter", "F"); - params = pdf_dict_getsa(ctx, stmobj, "DecodeParms", "DP"); + filters = pdf_dict_geta(ctx, stmobj, PDF_NAME_Filter, PDF_NAME_F); + params = pdf_dict_geta(ctx, stmobj, PDF_NAME_DecodeParms, PDF_NAME_DP); chain = pdf_open_raw_filter(ctx, chain, doc, stmobj, num, num, gen, offset); @@ -345,8 +343,8 @@ pdf_open_inline_stream(fz_context *ctx, pdf_document *doc, pdf_obj *stmobj, int pdf_obj *filters; pdf_obj *params; - filters = pdf_dict_getsa(ctx, stmobj, "Filter", "F"); - params = pdf_dict_getsa(ctx, stmobj, "DecodeParms", "DP"); + filters = pdf_dict_geta(ctx, stmobj, PDF_NAME_Filter, PDF_NAME_F); + params = pdf_dict_geta(ctx, stmobj, PDF_NAME_DecodeParms, PDF_NAME_DP); /* don't close chain when we close this filter */ fz_keep_stream(ctx, chain); @@ -470,7 +468,7 @@ pdf_load_raw_renumbered_stream(fz_context *ctx, pdf_document *doc, int num, int dict = pdf_load_object(ctx, doc, num, gen); - len = pdf_to_int(ctx, pdf_dict_gets(ctx, dict, "Length")); + len = pdf_to_int(ctx, pdf_dict_get(ctx, dict, PDF_NAME_Length)); pdf_drop_obj(ctx, dict); @@ -517,8 +515,8 @@ pdf_load_image_stream(fz_context *ctx, pdf_document *doc, int num, int gen, int dict = pdf_load_object(ctx, doc, num, gen); - len = pdf_to_int(ctx, pdf_dict_gets(ctx, dict, "Length")); - obj = pdf_dict_gets(ctx, dict, "Filter"); + len = pdf_to_int(ctx, pdf_dict_get(ctx, dict, PDF_NAME_Length)); + obj = pdf_dict_get(ctx, dict, PDF_NAME_Filter); len = pdf_guess_filter_length(len, pdf_to_name(ctx, obj)); n = pdf_array_len(ctx, obj); for (i = 0; i < n; i++) diff --git a/source/pdf/pdf-type3.c b/source/pdf/pdf-type3.c index 3da74806..56128c9a 100644 --- a/source/pdf/pdf-type3.c +++ b/source/pdf/pdf-type3.c @@ -43,7 +43,7 @@ pdf_load_type3_font(fz_context *ctx, pdf_document *doc, pdf_obj *rdb, pdf_obj *d fz_try(ctx) { - obj = pdf_dict_gets(ctx, dict, "Name"); + obj = pdf_dict_get(ctx, dict, PDF_NAME_Name); if (pdf_is_name(ctx, obj)) fz_strlcpy(buf, pdf_to_name(ctx, obj), sizeof buf); else @@ -51,10 +51,10 @@ pdf_load_type3_font(fz_context *ctx, pdf_document *doc, pdf_obj *rdb, pdf_obj *d fontdesc = pdf_new_font_desc(ctx); - obj = pdf_dict_gets(ctx, dict, "FontMatrix"); + obj = pdf_dict_get(ctx, dict, PDF_NAME_FontMatrix); pdf_to_matrix(ctx, obj, &matrix); - obj = pdf_dict_gets(ctx, dict, "FontBBox"); + obj = pdf_dict_get(ctx, dict, PDF_NAME_FontBBox); fz_transform_rect(pdf_to_rect(ctx, obj, &bbox), &matrix); fontdesc->font = fz_new_type3_font(ctx, buf, &matrix); @@ -67,7 +67,7 @@ pdf_load_type3_font(fz_context *ctx, pdf_document *doc, pdf_obj *rdb, pdf_obj *d for (i = 0; i < 256; i++) estrings[i] = NULL; - encoding = pdf_dict_gets(ctx, dict, "Encoding"); + encoding = pdf_dict_get(ctx, dict, PDF_NAME_Encoding); if (!encoding) { fz_throw(ctx, FZ_ERROR_GENERIC, "syntaxerror: Type3 font missing Encoding"); @@ -80,11 +80,11 @@ pdf_load_type3_font(fz_context *ctx, pdf_document *doc, pdf_obj *rdb, pdf_obj *d { pdf_obj *base, *diff, *item; - base = pdf_dict_gets(ctx, encoding, "BaseEncoding"); + base = pdf_dict_get(ctx, encoding, PDF_NAME_BaseEncoding); if (pdf_is_name(ctx, base)) pdf_load_encoding(estrings, pdf_to_name(ctx, base)); - diff = pdf_dict_gets(ctx, encoding, "Differences"); + diff = pdf_dict_get(ctx, encoding, PDF_NAME_Differences); if (pdf_is_array(ctx, diff)) { n = pdf_array_len(ctx, diff); @@ -103,19 +103,19 @@ pdf_load_type3_font(fz_context *ctx, pdf_document *doc, pdf_obj *rdb, pdf_obj *d fontdesc->encoding = pdf_new_identity_cmap(ctx, 0, 1); fontdesc->size += pdf_cmap_size(ctx, fontdesc->encoding); - pdf_load_to_unicode(ctx, doc, fontdesc, estrings, NULL, pdf_dict_gets(ctx, dict, "ToUnicode")); + pdf_load_to_unicode(ctx, doc, fontdesc, estrings, NULL, pdf_dict_get(ctx, dict, PDF_NAME_ToUnicode)); /* Widths */ pdf_set_default_hmtx(ctx, fontdesc, 0); - first = pdf_to_int(ctx, pdf_dict_gets(ctx, dict, "FirstChar")); - last = pdf_to_int(ctx, pdf_dict_gets(ctx, dict, "LastChar")); + first = pdf_to_int(ctx, pdf_dict_get(ctx, dict, PDF_NAME_FirstChar)); + last = pdf_to_int(ctx, pdf_dict_get(ctx, dict, PDF_NAME_LastChar)); if (first < 0 || last > 255 || first > last) first = last = 0; - widths = pdf_dict_gets(ctx, dict, "Widths"); + widths = pdf_dict_get(ctx, dict, PDF_NAME_Widths); if (!widths) { fz_throw(ctx, FZ_ERROR_GENERIC, "syntaxerror: Type3 font missing Widths"); @@ -134,7 +134,7 @@ pdf_load_type3_font(fz_context *ctx, pdf_document *doc, pdf_obj *rdb, pdf_obj *d /* Resources -- inherit page resources if the font doesn't have its own */ fontdesc->font->t3freeres = pdf_t3_free_resources; - fontdesc->font->t3resources = pdf_dict_gets(ctx, dict, "Resources"); + fontdesc->font->t3resources = pdf_dict_get(ctx, dict, PDF_NAME_Resources); if (!fontdesc->font->t3resources) fontdesc->font->t3resources = rdb; if (fontdesc->font->t3resources) @@ -147,7 +147,7 @@ pdf_load_type3_font(fz_context *ctx, pdf_document *doc, pdf_obj *rdb, pdf_obj *d /* CharProcs */ - charprocs = pdf_dict_gets(ctx, dict, "CharProcs"); + charprocs = pdf_dict_get(ctx, dict, PDF_NAME_CharProcs); if (!charprocs) { fz_throw(ctx, FZ_ERROR_GENERIC, "syntaxerror: Type3 font missing CharProcs"); diff --git a/source/pdf/pdf-write.c b/source/pdf/pdf-write.c index a9dd7423..5f815e03 100644 --- a/source/pdf/pdf-write.c +++ b/source/pdf/pdf-write.c @@ -530,12 +530,12 @@ static pdf_obj *markref(fz_context *ctx, pdf_document *doc, pdf_write_options *o { if (pdf_is_stream(ctx, doc, num, gen)) { - pdf_obj *len = pdf_dict_gets(ctx, obj, "Length"); + pdf_obj *len = pdf_dict_get(ctx, obj, PDF_NAME_Length); if (pdf_is_indirect(ctx, len)) { opts->use_list[pdf_to_num(ctx, len)] = 0; len = pdf_resolve_indirect(ctx, len); - pdf_dict_puts(ctx, obj, "Length", len); + pdf_dict_put(ctx, obj, PDF_NAME_Length, len); } } } @@ -949,7 +949,7 @@ mark_pages(fz_context *ctx, pdf_document *doc, pdf_write_options *opts, pdf_obj { if (pdf_is_dict(ctx, val)) { - if (!strcmp("Page", pdf_to_name(ctx, pdf_dict_gets(ctx, val, "Type")))) + if (pdf_name_eq(ctx, PDF_NAME_Page, pdf_dict_get(ctx, val, PDF_NAME_Type))) { int num = pdf_to_num(ctx, val); pdf_unmark_obj(ctx, val); @@ -967,7 +967,7 @@ mark_pages(fz_context *ctx, pdf_document *doc, pdf_write_options *opts, pdf_obj pdf_obj *key = pdf_dict_get_key(ctx, val, i); pdf_obj *obj = pdf_dict_get_val(ctx, val, i); - if (!strcmp("Kids", pdf_to_name(ctx, key))) + if (pdf_name_eq(ctx, PDF_NAME_Kids, key)) pagenum = mark_pages(ctx, doc, opts, obj, pagenum); else mark_all(ctx, doc, opts, obj, USE_CATALOGUE, -1); @@ -1024,21 +1024,21 @@ mark_root(fz_context *ctx, pdf_document *doc, pdf_write_options *opts, pdf_obj * for (i = 0; i < n; i++) { - char *key = pdf_to_name(ctx, pdf_dict_get_key(ctx, dict, i)); + pdf_obj *key = pdf_dict_get_key(ctx, dict, i); pdf_obj *val = pdf_dict_get_val(ctx, dict, i); - if (!strcmp("Pages", key)) + if (pdf_name_eq(ctx, PDF_NAME_Pages, key)) opts->page_count = mark_pages(ctx, doc, opts, val, 0); - else if (!strcmp("Names", key)) + else if (pdf_name_eq(ctx, PDF_NAME_Names, key)) mark_all(ctx, doc, opts, val, USE_OTHER_OBJECTS, -1); - else if (!strcmp("Dests", key)) + else if (pdf_name_eq(ctx, PDF_NAME_Dests, key)) mark_all(ctx, doc, opts, val, USE_OTHER_OBJECTS, -1); - else if (!strcmp("Outlines", key)) + else if (pdf_name_eq(ctx, PDF_NAME_Outlines, key)) { int section; /* Look at PageMode to decide whether to * USE_OTHER_OBJECTS or USE_PAGE1 here. */ - if (strcmp(pdf_to_name(ctx, pdf_dict_gets(ctx, dict, "PageMode")), "UseOutlines") == 0) + if (pdf_name_eq(ctx, pdf_dict_get(ctx, dict, PDF_NAME_PageMode), PDF_NAME_UseOutlines)) section = USE_PAGE1; else section = USE_OTHER_OBJECTS; @@ -1070,10 +1070,10 @@ mark_trailer(fz_context *ctx, pdf_document *doc, pdf_write_options *opts, pdf_ob { for (i = 0; i < n; i++) { - char *key = pdf_to_name(ctx, pdf_dict_get_key(ctx, dict, i)); + pdf_obj *key = pdf_dict_get_key(ctx, dict, i); pdf_obj *val = pdf_dict_get_val(ctx, dict, i); - if (!strcmp("Root", key)) + if (pdf_name_eq(ctx, PDF_NAME_Root, key)) mark_root(ctx, doc, opts, val); else mark_all(ctx, doc, opts, val, USE_CATALOGUE, -1); @@ -1117,24 +1117,24 @@ add_linearization_objs(fz_context *ctx, pdf_document *doc, pdf_write_options *op opts->rev_renumber_map[params_num] = params_num; opts->gen_list[params_num] = 0; opts->rev_gen_list[params_num] = 0; - pdf_dict_puts_drop(ctx, params_obj, "Linearized", pdf_new_real(ctx, doc, 1.0)); + pdf_dict_put_drop(ctx, params_obj, PDF_NAME_Linearized, pdf_new_real(ctx, doc, 1.0)); opts->linear_l = pdf_new_int(ctx, doc, INT_MIN); - pdf_dict_puts(ctx, params_obj, "L", opts->linear_l); + pdf_dict_put(ctx, params_obj, PDF_NAME_L, opts->linear_l); opts->linear_h0 = pdf_new_int(ctx, doc, INT_MIN); o = pdf_new_array(ctx, doc, 2); pdf_array_push(ctx, o, opts->linear_h0); opts->linear_h1 = pdf_new_int(ctx, doc, INT_MIN); pdf_array_push(ctx, o, opts->linear_h1); - pdf_dict_puts_drop(ctx, params_obj, "H", o); + pdf_dict_put_drop(ctx, params_obj, PDF_NAME_H, o); o = NULL; opts->linear_o = pdf_new_int(ctx, doc, INT_MIN); - pdf_dict_puts(ctx, params_obj, "O", opts->linear_o); + pdf_dict_put(ctx, params_obj, PDF_NAME_O, opts->linear_o); opts->linear_e = pdf_new_int(ctx, doc, INT_MIN); - pdf_dict_puts(ctx, params_obj, "E", opts->linear_e); + pdf_dict_put(ctx, params_obj, PDF_NAME_E, opts->linear_e); opts->linear_n = pdf_new_int(ctx, doc, INT_MIN); - pdf_dict_puts(ctx, params_obj, "N", opts->linear_n); + pdf_dict_put(ctx, params_obj, PDF_NAME_N, opts->linear_n); opts->linear_t = pdf_new_int(ctx, doc, INT_MIN); - pdf_dict_puts(ctx, params_obj, "T", opts->linear_t); + pdf_dict_put(ctx, params_obj, PDF_NAME_T, opts->linear_t); /* Primary hint stream */ hint_obj = pdf_new_dict(ctx, doc, 10); @@ -1146,9 +1146,9 @@ add_linearization_objs(fz_context *ctx, pdf_document *doc, pdf_write_options *op opts->rev_renumber_map[hint_num] = hint_num; opts->gen_list[hint_num] = 0; opts->rev_gen_list[hint_num] = 0; - pdf_dict_puts_drop(ctx, hint_obj, "P", pdf_new_int(ctx, doc, 0)); + pdf_dict_put_drop(ctx, hint_obj, PDF_NAME_P, pdf_new_int(ctx, doc, 0)); opts->hints_s = pdf_new_int(ctx, doc, INT_MIN); - pdf_dict_puts(ctx, hint_obj, "S", opts->hints_s); + pdf_dict_put(ctx, hint_obj, PDF_NAME_S, opts->hints_s); /* FIXME: Do we have thumbnails? Do a T entry */ /* FIXME: Do we have outlines? Do an O entry */ /* FIXME: Do we have article threads? Do an A entry */ @@ -1157,9 +1157,9 @@ add_linearization_objs(fz_context *ctx, pdf_document *doc, pdf_write_options *op /* FIXME: Do we have document information? Do an I entry */ /* FIXME: Do we have logical structure heirarchy? Do a C entry */ /* FIXME: Do L, Page Label hint table */ - pdf_dict_puts_drop(ctx, hint_obj, "Filter", pdf_new_name(ctx, doc, "FlateDecode")); + pdf_dict_put_drop(ctx, hint_obj, PDF_NAME_Filter, PDF_NAME_FlateDecode); opts->hints_length = pdf_new_int(ctx, doc, INT_MIN); - pdf_dict_puts(ctx, hint_obj, "Length", opts->hints_length); + pdf_dict_put(ctx, hint_obj, PDF_NAME_Length, opts->hints_length); pdf_get_xref_entry(ctx, doc, hint_num)->stm_ofs = -1; } fz_always(ctx) @@ -1177,19 +1177,19 @@ add_linearization_objs(fz_context *ctx, pdf_document *doc, pdf_write_options *op } static void -lpr_inherit_res_contents(fz_context *ctx, pdf_obj *res, pdf_obj *dict, char *text) +lpr_inherit_res_contents(fz_context *ctx, pdf_obj *res, pdf_obj *dict, pdf_obj *text) { pdf_obj *o, *r; int i, n; /* If the parent node doesn't have an entry of this type, give up. */ - o = pdf_dict_gets(ctx, dict, text); + o = pdf_dict_get(ctx, dict, text); if (!o) return; /* If the resources dict we are building doesn't have an entry of this * type yet, then just copy it (ensuring it's not a reference) */ - r = pdf_dict_gets(ctx, res, text); + r = pdf_dict_get(ctx, res, text); if (r == NULL) { o = pdf_resolve_indirect(ctx, o); @@ -1200,7 +1200,7 @@ lpr_inherit_res_contents(fz_context *ctx, pdf_obj *res, pdf_obj *dict, char *tex else o = NULL; if (o) - pdf_dict_puts(ctx, res, text, o); + pdf_dict_put(ctx, res, text, o); return; } @@ -1213,9 +1213,9 @@ lpr_inherit_res_contents(fz_context *ctx, pdf_obj *res, pdf_obj *dict, char *tex pdf_obj *key = pdf_dict_get_key(ctx, o, i); pdf_obj *val = pdf_dict_get_val(ctx, o, i); - if (pdf_dict_gets(ctx, res, pdf_to_name(ctx, key))) + if (pdf_dict_get(ctx, res, key)) continue; - pdf_dict_puts(ctx, res, pdf_to_name(ctx, key), val); + pdf_dict_put(ctx, res, key, val); } } } @@ -1227,22 +1227,22 @@ lpr_inherit_res(fz_context *ctx, pdf_obj *node, int depth, pdf_obj *dict) { pdf_obj *o; - node = pdf_dict_gets(ctx, node, "Parent"); + node = pdf_dict_get(ctx, node, PDF_NAME_Parent); depth--; if (!node || depth < 0) break; - o = pdf_dict_gets(ctx, node, "Resources"); + o = pdf_dict_get(ctx, node, PDF_NAME_Resources); if (o) { - lpr_inherit_res_contents(ctx, dict, o, "ExtGState"); - lpr_inherit_res_contents(ctx, dict, o, "ColorSpace"); - lpr_inherit_res_contents(ctx, dict, o, "Pattern"); - lpr_inherit_res_contents(ctx, dict, o, "Shading"); - lpr_inherit_res_contents(ctx, dict, o, "XObject"); - lpr_inherit_res_contents(ctx, dict, o, "Font"); - lpr_inherit_res_contents(ctx, dict, o, "ProcSet"); - lpr_inherit_res_contents(ctx, dict, o, "Properties"); + lpr_inherit_res_contents(ctx, dict, o, PDF_NAME_ExtGState); + lpr_inherit_res_contents(ctx, dict, o, PDF_NAME_ColorSpace); + lpr_inherit_res_contents(ctx, dict, o, PDF_NAME_Pattern); + lpr_inherit_res_contents(ctx, dict, o, PDF_NAME_Shading); + lpr_inherit_res_contents(ctx, dict, o, PDF_NAME_XObject); + lpr_inherit_res_contents(ctx, dict, o, PDF_NAME_Font); + lpr_inherit_res_contents(ctx, dict, o, PDF_NAME_ProcSet); + lpr_inherit_res_contents(ctx, dict, o, PDF_NAME_Properties); } } } @@ -1256,7 +1256,7 @@ lpr_inherit(fz_context *ctx, pdf_obj *node, char *text, int depth) if (o) return pdf_resolve_indirect(ctx, o); - node = pdf_dict_gets(ctx, node, "Parent"); + node = pdf_dict_get(ctx, node, PDF_NAME_Parent); depth--; } while (depth >= 0 && node); @@ -1278,53 +1278,53 @@ lpr(fz_context *ctx, pdf_document *doc, pdf_obj *node, int depth, int page) fz_try(ctx) { - if (!strcmp("Page", pdf_to_name(ctx, pdf_dict_gets(ctx, node, "Type")))) + if (pdf_name_eq(ctx, PDF_NAME_Page, pdf_dict_get(ctx, node, PDF_NAME_Type))) { pdf_obj *r; /* r is deliberately not cleaned up */ /* Copy resources down to the child */ - o = pdf_keep_obj(ctx, pdf_dict_gets(ctx, node, "Resources")); + o = pdf_keep_obj(ctx, pdf_dict_get(ctx, node, PDF_NAME_Resources)); if (!o) { o = pdf_keep_obj(ctx, pdf_new_dict(ctx, doc, 2)); - pdf_dict_puts(ctx, node, "Resources", o); + pdf_dict_put(ctx, node, PDF_NAME_Resources, o); } lpr_inherit_res(ctx, node, depth, o); r = lpr_inherit(ctx, node, "MediaBox", depth); if (r) - pdf_dict_puts(ctx, node, "MediaBox", r); + pdf_dict_put(ctx, node, PDF_NAME_MediaBox, r); r = lpr_inherit(ctx, node, "CropBox", depth); if (r) - pdf_dict_puts(ctx, node, "CropBox", r); + pdf_dict_put(ctx, node, PDF_NAME_CropBox, r); r = lpr_inherit(ctx, node, "BleedBox", depth); if (r) - pdf_dict_puts(ctx, node, "BleedBox", r); + pdf_dict_put(ctx, node, PDF_NAME_BleedBox, r); r = lpr_inherit(ctx, node, "TrimBox", depth); if (r) - pdf_dict_puts(ctx, node, "TrimBox", r); + pdf_dict_put(ctx, node, PDF_NAME_TrimBox, r); r = lpr_inherit(ctx, node, "ArtBox", depth); if (r) - pdf_dict_puts(ctx, node, "ArtBox", r); + pdf_dict_put(ctx, node, PDF_NAME_ArtBox, r); r = lpr_inherit(ctx, node, "Rotate", depth); if (r) - pdf_dict_puts(ctx, node, "Rotate", r); + pdf_dict_put(ctx, node, PDF_NAME_Rotate, r); page++; } else { - kids = pdf_dict_gets(ctx, node, "Kids"); + kids = pdf_dict_get(ctx, node, PDF_NAME_Kids); n = pdf_array_len(ctx, kids); for(i = 0; i < n; i++) { page = lpr(ctx, doc, pdf_array_get(ctx, kids, i), depth+1, page); } - pdf_dict_dels(ctx, node, "Resources"); - pdf_dict_dels(ctx, node, "MediaBox"); - pdf_dict_dels(ctx, node, "CropBox"); - pdf_dict_dels(ctx, node, "BleedBox"); - pdf_dict_dels(ctx, node, "TrimBox"); - pdf_dict_dels(ctx, node, "ArtBox"); - pdf_dict_dels(ctx, node, "Rotate"); + pdf_dict_del(ctx, node, PDF_NAME_Resources); + pdf_dict_del(ctx, node, PDF_NAME_MediaBox); + pdf_dict_del(ctx, node, PDF_NAME_CropBox); + pdf_dict_del(ctx, node, PDF_NAME_BleedBox); + pdf_dict_del(ctx, node, PDF_NAME_TrimBox); + pdf_dict_del(ctx, node, PDF_NAME_ArtBox); + pdf_dict_del(ctx, node, PDF_NAME_Rotate); } } fz_always(ctx) @@ -1347,7 +1347,7 @@ pdf_localise_page_resources(fz_context *ctx, pdf_document *doc) if (doc->resources_localised) return; - lpr(ctx, doc, pdf_dict_getp(ctx, pdf_trailer(ctx, doc), "Root/Pages"), 0, 0); + lpr(ctx, doc, pdf_dict_getl(ctx, pdf_trailer(ctx, doc), PDF_NAME_Root, PDF_NAME_Pages, NULL), 0, 0); doc->resources_localised = 1; } @@ -1525,19 +1525,18 @@ static fz_buffer *hexbuf(fz_context *ctx, unsigned char *p, int n) static void addhexfilter(fz_context *ctx, pdf_document *doc, pdf_obj *dict) { pdf_obj *f, *dp, *newf, *newdp; - pdf_obj *ahx, *nullobj; + pdf_obj *nullobj; - ahx = pdf_new_name(ctx, doc, "ASCIIHexDecode"); nullobj = pdf_new_null(ctx, doc); newf = newdp = NULL; - f = pdf_dict_gets(ctx, dict, "Filter"); - dp = pdf_dict_gets(ctx, dict, "DecodeParms"); + f = pdf_dict_get(ctx, dict, PDF_NAME_Filter); + dp = pdf_dict_get(ctx, dict, PDF_NAME_DecodeParms); if (pdf_is_name(ctx, f)) { newf = pdf_new_array(ctx, doc, 2); - pdf_array_push(ctx, newf, ahx); + pdf_array_push(ctx, newf, PDF_NAME_ASCIIHexDecode); pdf_array_push(ctx, newf, f); f = newf; if (pdf_is_dict(ctx, dp)) @@ -1550,18 +1549,17 @@ static void addhexfilter(fz_context *ctx, pdf_document *doc, pdf_obj *dict) } else if (pdf_is_array(ctx, f)) { - pdf_array_insert(ctx, f, ahx, 0); + pdf_array_insert(ctx, f, PDF_NAME_ASCIIHexDecode, 0); if (pdf_is_array(ctx, dp)) pdf_array_insert(ctx, dp, nullobj, 0); } else - f = ahx; + f = PDF_NAME_ASCIIHexDecode; - pdf_dict_puts(ctx, dict, "Filter", f); + pdf_dict_put(ctx, dict, PDF_NAME_Filter, f); if (dp) - pdf_dict_puts(ctx, dict, "DecodeParms", dp); + pdf_dict_put(ctx, dict, PDF_NAME_DecodeParms, dp); - pdf_drop_obj(ctx, ahx); pdf_drop_obj(ctx, nullobj); pdf_drop_obj(ctx, newf); pdf_drop_obj(ctx, newdp); @@ -1587,7 +1585,7 @@ static void copystream(fz_context *ctx, pdf_document *doc, pdf_write_options *op addhexfilter(ctx, doc, obj); newlen = pdf_new_int(ctx, doc, buf->len); - pdf_dict_puts(ctx, obj, "Length", newlen); + pdf_dict_put(ctx, obj, PDF_NAME_Length, newlen); pdf_drop_obj(ctx, newlen); } @@ -1615,8 +1613,8 @@ static void expandstream(fz_context *ctx, pdf_document *doc, pdf_write_options * (*opts->errors)++; obj = pdf_copy_dict(ctx, obj_orig); - 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); if (opts->do_ascii && isbinarystream(buf)) { @@ -1628,7 +1626,7 @@ static void expandstream(fz_context *ctx, pdf_document *doc, pdf_write_options * } newlen = pdf_new_int(ctx, doc, buf->len); - pdf_dict_puts(ctx, obj, "Length", newlen); + pdf_dict_put(ctx, obj, PDF_NAME_Length, newlen); pdf_drop_obj(ctx, newlen); fprintf(opts->out, "%d %d obj\n", num, gen); @@ -1697,14 +1695,14 @@ static void writeobject(fz_context *ctx, pdf_document *doc, pdf_write_options *o /* skip ObjStm and XRef objects */ if (pdf_is_dict(ctx, obj)) { - type = pdf_dict_gets(ctx, obj, "Type"); - if (pdf_is_name(ctx, type) && !strcmp(pdf_to_name(ctx, type), "ObjStm")) + type = pdf_dict_get(ctx, obj, PDF_NAME_Type); + if (pdf_name_eq(ctx, type, PDF_NAME_ObjStm)) { opts->use_list[num] = 0; pdf_drop_obj(ctx, obj); return; } - if (skip_xrefs && pdf_is_name(ctx, type) && !strcmp(pdf_to_name(ctx, type), "XRef")) + if (skip_xrefs && pdf_name_eq(ctx, type, PDF_NAME_XRef)) { opts->use_list[num] = 0; pdf_drop_obj(ctx, obj); @@ -1732,26 +1730,26 @@ static void writeobject(fz_context *ctx, pdf_document *doc, pdf_write_options *o { pdf_obj *o; - if ((o = pdf_dict_gets(ctx, obj, "Type"), !strcmp(pdf_to_name(ctx, o), "XObject")) && - (o = pdf_dict_gets(ctx, obj, "Subtype"), !strcmp(pdf_to_name(ctx, o), "Image"))) + if ((o = pdf_dict_get(ctx, obj, PDF_NAME_Type), pdf_name_eq(ctx, o, PDF_NAME_XObject)) && + (o = pdf_dict_get(ctx, obj, PDF_NAME_Subtype), pdf_name_eq(ctx, o, PDF_NAME_Image))) dontexpand = !(opts->do_expand & fz_expand_images); - if (o = pdf_dict_gets(ctx, obj, "Type"), !strcmp(pdf_to_name(ctx, o), "Font")) + if (o = pdf_dict_get(ctx, obj, PDF_NAME_Type), pdf_name_eq(ctx, o, PDF_NAME_Font)) dontexpand = !(opts->do_expand & fz_expand_fonts); - if (o = pdf_dict_gets(ctx, obj, "Type"), !strcmp(pdf_to_name(ctx, o), "FontDescriptor")) + if (o = pdf_dict_get(ctx, obj, PDF_NAME_Type), pdf_name_eq(ctx, o, PDF_NAME_FontDescriptor)) dontexpand = !(opts->do_expand & fz_expand_fonts); - if (pdf_dict_gets(ctx, obj, "Length1") != NULL) + if (pdf_dict_get(ctx, obj, PDF_NAME_Length1) != NULL) dontexpand = !(opts->do_expand & fz_expand_fonts); - if (pdf_dict_gets(ctx, obj, "Length2") != NULL) + if (pdf_dict_get(ctx, obj, PDF_NAME_Length2) != NULL) dontexpand = !(opts->do_expand & fz_expand_fonts); - if (pdf_dict_gets(ctx, obj, "Length3") != NULL) + if (pdf_dict_get(ctx, obj, PDF_NAME_Length3) != NULL) dontexpand = !(opts->do_expand & fz_expand_fonts); - if (o = pdf_dict_gets(ctx, obj, "Subtype"), !strcmp(pdf_to_name(ctx, o), "Type1C")) + if (o = pdf_dict_get(ctx, obj, PDF_NAME_Subtype), pdf_name_eq(ctx, o, PDF_NAME_Type1C)) dontexpand = !(opts->do_expand & fz_expand_fonts); - if (o = pdf_dict_gets(ctx, obj, "Subtype"), !strcmp(pdf_to_name(ctx, o), "CIDFontType0C")) + if (o = pdf_dict_get(ctx, obj, PDF_NAME_Subtype), pdf_name_eq(ctx, o, PDF_NAME_CIDFontType0C)) dontexpand = !(opts->do_expand & fz_expand_fonts); - if (o = pdf_dict_gets(ctx, obj, "Filter"), filter_implies_image(ctx, doc, o)) + if (o = pdf_dict_get(ctx, obj, PDF_NAME_Filter), filter_implies_image(ctx, doc, o)) dontexpand = !(opts->do_expand & fz_expand_images); - if (pdf_dict_gets(ctx, obj, "Width") != NULL && pdf_dict_gets(ctx, obj, "Height") != NULL) + if (pdf_dict_get(ctx, obj, PDF_NAME_Width) != NULL && pdf_dict_get(ctx, obj, PDF_NAME_Height) != NULL) dontexpand = !(opts->do_expand & fz_expand_images); } fz_try(ctx) @@ -1840,8 +1838,8 @@ static void writexref(fz_context *ctx, pdf_document *doc, pdf_write_options *opt if (opts->do_incremental) { trailer = pdf_keep_obj(ctx, pdf_trailer(ctx, doc)); - pdf_dict_puts_drop(ctx, trailer, "Size", pdf_new_int(ctx, doc, pdf_xref_len(ctx, doc))); - pdf_dict_puts_drop(ctx, trailer, "Prev", pdf_new_int(ctx, doc, doc->startxref)); + 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)); doc->startxref = startxref; } else @@ -1849,28 +1847,28 @@ static void writexref(fz_context *ctx, pdf_document *doc, pdf_write_options *opt trailer = pdf_new_dict(ctx, doc, 5); nobj = pdf_new_int(ctx, doc, to); - pdf_dict_puts(ctx, trailer, "Size", nobj); + pdf_dict_put(ctx, trailer, PDF_NAME_Size, nobj); pdf_drop_obj(ctx, nobj); nobj = NULL; if (first) { - obj = pdf_dict_gets(ctx, pdf_trailer(ctx, doc), "Info"); + obj = pdf_dict_get(ctx, pdf_trailer(ctx, doc), PDF_NAME_Info); if (obj) - pdf_dict_puts(ctx, trailer, "Info", obj); + pdf_dict_put(ctx, trailer, PDF_NAME_Info, obj); - obj = pdf_dict_gets(ctx, pdf_trailer(ctx, doc), "Root"); + obj = pdf_dict_get(ctx, pdf_trailer(ctx, doc), PDF_NAME_Root); if (obj) - pdf_dict_puts(ctx, trailer, "Root", obj); + pdf_dict_put(ctx, trailer, PDF_NAME_Root, obj); - obj = pdf_dict_gets(ctx, pdf_trailer(ctx, doc), "ID"); + obj = pdf_dict_get(ctx, pdf_trailer(ctx, doc), PDF_NAME_ID); if (obj) - pdf_dict_puts(ctx, trailer, "ID", obj); + pdf_dict_put(ctx, trailer, PDF_NAME_ID, obj); } if (main_xref_offset != 0) { nobj = pdf_new_int(ctx, doc, main_xref_offset); - pdf_dict_puts(ctx, trailer, "Prev", nobj); + pdf_dict_put(ctx, trailer, PDF_NAME_Prev, nobj); pdf_drop_obj(ctx, nobj); nobj = NULL; } @@ -1937,49 +1935,49 @@ static void writexrefstream(fz_context *ctx, pdf_document *doc, pdf_write_option if (first) { - obj = pdf_dict_gets(ctx, pdf_trailer(ctx, doc), "Info"); + obj = pdf_dict_get(ctx, pdf_trailer(ctx, doc), PDF_NAME_Info); if (obj) - pdf_dict_puts(ctx, dict, "Info", obj); + pdf_dict_put(ctx, dict, PDF_NAME_Info, obj); - obj = pdf_dict_gets(ctx, pdf_trailer(ctx, doc), "Root"); + obj = pdf_dict_get(ctx, pdf_trailer(ctx, doc), PDF_NAME_Root); if (obj) - pdf_dict_puts(ctx, dict, "Root", obj); + pdf_dict_put(ctx, dict, PDF_NAME_Root, obj); - obj = pdf_dict_gets(ctx, pdf_trailer(ctx, doc), "ID"); + obj = pdf_dict_get(ctx, pdf_trailer(ctx, doc), PDF_NAME_ID); if (obj) - pdf_dict_puts(ctx, dict, "ID", obj); + pdf_dict_put(ctx, dict, PDF_NAME_ID, obj); if (opts->do_incremental) { - obj = pdf_dict_gets(ctx, pdf_trailer(ctx, doc), "Encrypt"); + obj = pdf_dict_get(ctx, pdf_trailer(ctx, doc), PDF_NAME_Encrypt); if (obj) - pdf_dict_puts(ctx, dict, "Encrypt", obj); + pdf_dict_put(ctx, dict, PDF_NAME_Encrypt, obj); } } - pdf_dict_puts_drop(ctx, dict, "Size", pdf_new_int(ctx, doc, to)); + pdf_dict_put_drop(ctx, dict, PDF_NAME_Size, pdf_new_int(ctx, doc, to)); if (opts->do_incremental) { - pdf_dict_puts_drop(ctx, dict, "Prev", pdf_new_int(ctx, doc, doc->startxref)); + pdf_dict_put_drop(ctx, dict, PDF_NAME_Prev, pdf_new_int(ctx, doc, doc->startxref)); doc->startxref = startxref; } else { if (main_xref_offset != 0) - pdf_dict_puts_drop(ctx, dict, "Prev", pdf_new_int(ctx, doc, main_xref_offset)); + pdf_dict_put_drop(ctx, dict, PDF_NAME_Prev, pdf_new_int(ctx, doc, main_xref_offset)); } - pdf_dict_puts_drop(ctx, dict, "Type", pdf_new_name(ctx, doc, "XRef")); + pdf_dict_put_drop(ctx, dict, PDF_NAME_Type, PDF_NAME_XRef); w = pdf_new_array(ctx, doc, 3); - pdf_dict_puts(ctx, dict, "W", w); + 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)); index = pdf_new_array(ctx, doc, 2); - pdf_dict_puts_drop(ctx, dict, "Index", index); + pdf_dict_put_drop(ctx, dict, PDF_NAME_Index, index); opts->ofs_list[num] = opts->first_xref_entry_offset; @@ -2450,7 +2448,7 @@ static void presize_unsaved_signature_byteranges(fz_context *ctx, pdf_document * * the end and between each consecutive pair of signatures, * hence n + 1 */ int i; - pdf_obj *byte_range = pdf_dict_getp(ctx, usig->field, "V/ByteRange"); + pdf_obj *byte_range = pdf_dict_getl(ctx, usig->field, PDF_NAME_V, PDF_NAME_ByteRange, NULL); for (i = 0; i < n+1; i++) { @@ -2485,7 +2483,7 @@ static void complete_signatures(fz_context *ctx, pdf_document *doc, pdf_write_op for (usig = doc->unsaved_sigs; usig; usig = usig->next) { char *bstr, *cstr, *fstr; - int pnum = pdf_obj_parent_num(ctx, pdf_dict_getp(ctx, usig->field, "V/ByteRange")); + int pnum = pdf_obj_parent_num(ctx, pdf_dict_getl(ctx, usig->field, PDF_NAME_V, PDF_NAME_ByteRange, NULL)); fseek(f, opts->ofs_list[pnum], SEEK_SET); (void)fread(buf, 1, sizeof(buf), f); buf[sizeof(buf)-1] = 0; @@ -2506,7 +2504,7 @@ static void complete_signatures(fz_context *ctx, pdf_document *doc, pdf_write_op /* Recreate ByteRange with correct values. Initially store the * recreated object in the first of the unsaved signatures */ byte_range = pdf_new_array(ctx, doc, 4); - pdf_dict_putp_drop(ctx, doc->unsaved_sigs->field, "V/ByteRange", byte_range); + pdf_dict_putl_drop(ctx, doc->unsaved_sigs->field, byte_range, PDF_NAME_V, PDF_NAME_ByteRange, NULL); last_end = 0; for (usig = doc->unsaved_sigs; usig; usig = usig->next) @@ -2520,7 +2518,7 @@ static void complete_signatures(fz_context *ctx, pdf_document *doc, pdf_write_op /* Copy the new ByteRange to the other unsaved signatures */ for (usig = doc->unsaved_sigs->next; usig; usig = usig->next) - pdf_dict_putp_drop(ctx, usig->field, "V/ByteRange", pdf_copy_array(ctx, byte_range)); + pdf_dict_putl_drop(ctx, usig->field, pdf_copy_array(ctx, byte_range), PDF_NAME_V, PDF_NAME_ByteRange, NULL); /* Write the byte range into buf, padding with spaces*/ i = pdf_sprint_obj(ctx, buf, sizeof(buf), byte_range, 1); @@ -2806,10 +2804,10 @@ 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_puts_drop(ctx, me, "Type", pdf_new_name(ctx, doc, "Pages")); - pdf_dict_puts_drop(ctx, me, "Count", pdf_new_int(ctx, doc, r-l)); + 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)); if (!root) - pdf_dict_puts(ctx, me, "Parent", parent_ref); + pdf_dict_put(ctx, me, PDF_NAME_Parent, parent_ref); a = pdf_new_array(ctx, doc, KIDS_PER_LEVEL); me_ref = pdf_new_ref(ctx, doc, me); @@ -2818,7 +2816,7 @@ make_page_tree_node(fz_context *ctx, pdf_document *doc, int l, int r, pdf_obj *p if (spaces >= r-l) { o = pdf_keep_obj(ctx, doc->page_refs[l++]); - pdf_dict_puts(ctx, o, "Parent", me_ref); + pdf_dict_put(ctx, o, PDF_NAME_Parent, me_ref); } else { @@ -2832,7 +2830,7 @@ make_page_tree_node(fz_context *ctx, pdf_document *doc, int l, int r, pdf_obj *p pdf_drop_obj(ctx, o); o = NULL; } - pdf_dict_puts_drop(ctx, me, "Kids", a); + pdf_dict_put_drop(ctx, me, PDF_NAME_Kids, a); a = NULL; } fz_always(ctx) @@ -2858,9 +2856,9 @@ pdf_rebalance_page_tree(fz_context *ctx, pdf_document *doc) if (!doc || !doc->needs_page_tree_rebuild) return; - catalog = pdf_dict_gets(ctx, pdf_trailer(ctx, doc), "Root"); + catalog = pdf_dict_get(ctx, pdf_trailer(ctx, doc), PDF_NAME_Root); pages = make_page_tree_node(ctx, doc, 0, doc->page_len, catalog, 1); - pdf_dict_puts_drop(ctx, catalog, "Pages", pages); + pdf_dict_put_drop(ctx, catalog, PDF_NAME_Pages, pages); doc->needs_page_tree_rebuild = 0; } diff --git a/source/pdf/pdf-xobject.c b/source/pdf/pdf-xobject.c index 404616ae..19d633f0 100644 --- a/source/pdf/pdf-xobject.c +++ b/source/pdf/pdf-xobject.c @@ -58,10 +58,10 @@ pdf_load_xobject(fz_context *ctx, pdf_document *doc, pdf_obj *dict) fz_try(ctx) { - obj = pdf_dict_gets(ctx, dict, "BBox"); + obj = pdf_dict_get(ctx, dict, PDF_NAME_BBox); pdf_to_rect(ctx, obj, &form->bbox); - obj = pdf_dict_gets(ctx, dict, "Matrix"); + obj = pdf_dict_get(ctx, dict, PDF_NAME_Matrix); if (obj) pdf_to_matrix(ctx, obj, &form->matrix); else @@ -71,19 +71,19 @@ pdf_load_xobject(fz_context *ctx, pdf_document *doc, pdf_obj *dict) form->knockout = 0; form->transparency = 0; - obj = pdf_dict_gets(ctx, dict, "Group"); + obj = pdf_dict_get(ctx, dict, PDF_NAME_Group); if (obj) { pdf_obj *attrs = obj; - form->isolated = pdf_to_bool(ctx, pdf_dict_gets(ctx, attrs, "I")); - form->knockout = pdf_to_bool(ctx, pdf_dict_gets(ctx, attrs, "K")); + form->isolated = pdf_to_bool(ctx, pdf_dict_get(ctx, attrs, PDF_NAME_I)); + form->knockout = pdf_to_bool(ctx, pdf_dict_get(ctx, attrs, PDF_NAME_K)); - obj = pdf_dict_gets(ctx, attrs, "S"); - if (pdf_is_name(ctx, obj) && !strcmp(pdf_to_name(ctx, obj), "Transparency")) + obj = pdf_dict_get(ctx, attrs, PDF_NAME_S); + if (pdf_name_eq(ctx, obj, PDF_NAME_Transparency)) form->transparency = 1; - obj = pdf_dict_gets(ctx, attrs, "CS"); + obj = pdf_dict_get(ctx, attrs, PDF_NAME_CS); if (obj) { fz_try(ctx) @@ -97,7 +97,7 @@ pdf_load_xobject(fz_context *ctx, pdf_document *doc, pdf_obj *dict) } } - form->resources = pdf_dict_gets(ctx, dict, "Resources"); + form->resources = pdf_dict_get(ctx, dict, PDF_NAME_Resources); if (form->resources) pdf_keep_obj(ctx, form->resources); @@ -136,49 +136,37 @@ pdf_new_xobject(fz_context *ctx, pdf_document *doc, const fz_rect *bbox, const f dict = pdf_new_dict(ctx, doc, 0); obj = pdf_new_rect(ctx, doc, bbox); - pdf_dict_puts(ctx, dict, "BBox", obj); + pdf_dict_put(ctx, dict, PDF_NAME_BBox, obj); pdf_drop_obj(ctx, obj); obj = NULL; obj = pdf_new_int(ctx, doc, 1); - pdf_dict_puts(ctx, dict, "FormType", obj); + pdf_dict_put(ctx, dict, PDF_NAME_FormType, obj); pdf_drop_obj(ctx, obj); obj = NULL; obj = pdf_new_int(ctx, doc, 0); - pdf_dict_puts(ctx, dict, "Length", obj); + pdf_dict_put(ctx, dict, PDF_NAME_Length, obj); pdf_drop_obj(ctx, obj); obj = NULL; obj = pdf_new_matrix(ctx, doc, mat); - pdf_dict_puts(ctx, dict, "Matrix", obj); + pdf_dict_put(ctx, dict, PDF_NAME_Matrix, obj); pdf_drop_obj(ctx, obj); obj = NULL; res = pdf_new_dict(ctx, doc, 0); procset = pdf_new_array(ctx, doc, 2); - obj = pdf_new_name(ctx, doc, "PDF"); - pdf_array_push(ctx, procset, obj); - pdf_drop_obj(ctx, obj); - obj = NULL; - obj = pdf_new_name(ctx, doc, "Text"); - pdf_array_push(ctx, procset, obj); - pdf_drop_obj(ctx, obj); - obj = NULL; - pdf_dict_puts(ctx, res, "ProcSet", procset); + pdf_array_push(ctx, procset, PDF_NAME_PDF); + pdf_array_push(ctx, procset, PDF_NAME_Text); + pdf_dict_put(ctx, res, PDF_NAME_ProcSet, procset); pdf_drop_obj(ctx, procset); procset = NULL; - pdf_dict_puts(ctx, dict, "Resources", res); + pdf_dict_put(ctx, dict, PDF_NAME_Resources, res); - obj = pdf_new_name(ctx, doc, "Form"); - pdf_dict_puts(ctx, dict, "Subtype", obj); - pdf_drop_obj(ctx, obj); - obj = NULL; + pdf_dict_put(ctx, dict, PDF_NAME_Subtype, PDF_NAME_Form); - obj = pdf_new_name(ctx, doc, "XObject"); - pdf_dict_puts(ctx, dict, "Type", obj); - pdf_drop_obj(ctx, obj); - obj = NULL; + pdf_dict_put(ctx, dict, PDF_NAME_Type, PDF_NAME_XObject); form = fz_malloc_struct(ctx, pdf_xobject); FZ_INIT_STORABLE(form, 1, pdf_drop_xobject_imp); diff --git a/source/pdf/pdf-xref.c b/source/pdf/pdf-xref.c index 64312010..0524376c 100644 --- a/source/pdf/pdf-xref.c +++ b/source/pdf/pdf-xref.c @@ -574,7 +574,7 @@ pdf_xref_size_from_old_trailer(fz_context *ctx, pdf_document *doc, pdf_lexbuf *b trailer = pdf_parse_dict(ctx, doc, doc->file, buf); - size = pdf_to_int(ctx, pdf_dict_gets(ctx, trailer, "Size")); + size = pdf_to_int(ctx, pdf_dict_get(ctx, trailer, PDF_NAME_Size)); if (!size) fz_throw(ctx, FZ_ERROR_GENERIC, "trailer missing Size entry"); } @@ -819,13 +819,13 @@ pdf_read_new_xref(fz_context *ctx, pdf_document *doc, pdf_lexbuf *buf) { pdf_xref_entry *entry; - obj = pdf_dict_gets(ctx, trailer, "Size"); + obj = pdf_dict_get(ctx, trailer, PDF_NAME_Size); if (!obj) fz_throw(ctx, FZ_ERROR_GENERIC, "xref stream missing Size entry (%d %d R)", num, gen); size = pdf_to_int(ctx, obj); - obj = pdf_dict_gets(ctx, trailer, "W"); + obj = pdf_dict_get(ctx, trailer, PDF_NAME_W); if (!obj) fz_throw(ctx, FZ_ERROR_GENERIC, "xref stream missing W entry (%d %d R)", num, gen); w0 = pdf_to_int(ctx, pdf_array_get(ctx, obj, 0)); @@ -843,7 +843,7 @@ pdf_read_new_xref(fz_context *ctx, pdf_document *doc, pdf_lexbuf *buf) w1 = w1 < 0 ? 0 : w1; w2 = w2 < 0 ? 0 : w2; - index = pdf_dict_gets(ctx, trailer, "Index"); + index = pdf_dict_get(ctx, trailer, PDF_NAME_Index); stm = pdf_open_stream_with_offset(ctx, doc, num, gen, trailer, stm_ofs); @@ -955,7 +955,7 @@ read_xref_section(fz_context *ctx, pdf_document *doc, int ofs, pdf_lexbuf *buf, /* FIXME: do we overwrite free entries properly? */ /* FIXME: Does this work properly with progression? */ - xrefstmofs = pdf_to_int(ctx, pdf_dict_gets(ctx, trailer, "XRefStm")); + xrefstmofs = pdf_to_int(ctx, pdf_dict_get(ctx, trailer, PDF_NAME_XRefStm)); if (xrefstmofs) { if (xrefstmofs < 0) @@ -969,7 +969,7 @@ read_xref_section(fz_context *ctx, pdf_document *doc, int ofs, pdf_lexbuf *buf, pdf_drop_obj(ctx, pdf_read_xref(ctx, doc, xrefstmofs, buf)); } - prevofs = pdf_to_int(ctx, pdf_dict_gets(ctx, trailer, "Prev")); + prevofs = pdf_to_int(ctx, pdf_dict_get(ctx, trailer, PDF_NAME_Prev)); if (prevofs < 0) fz_throw(ctx, FZ_ERROR_GENERIC, "negative xref stream offset for previous xref stream"); } @@ -1110,27 +1110,27 @@ pdf_load_linear(fz_context *ctx, pdf_document *doc) dict = pdf_parse_ind_obj(ctx, doc, doc->file, &doc->lexbuf.base, &num, &gen, &stmofs, NULL); if (!pdf_is_dict(ctx, dict)) fz_throw(ctx, FZ_ERROR_GENERIC, "Failed to read linearized dictionary"); - o = pdf_dict_gets(ctx, dict, "Linearized"); + o = pdf_dict_get(ctx, dict, PDF_NAME_Linearized); if (o == NULL) fz_throw(ctx, FZ_ERROR_GENERIC, "Failed to read linearized dictionary"); lin = pdf_to_int(ctx, o); if (lin != 1) fz_throw(ctx, FZ_ERROR_GENERIC, "Unexpected version of Linearized tag (%d)", lin); - len = pdf_to_int(ctx, pdf_dict_gets(ctx, dict, "L")); + len = pdf_to_int(ctx, pdf_dict_get(ctx, dict, PDF_NAME_L)); if (len != doc->file_length) fz_throw(ctx, FZ_ERROR_GENERIC, "File has been updated since linearization"); pdf_read_xref_sections(ctx, doc, fz_tell(ctx, doc->file), &doc->lexbuf.base, 0); - doc->page_count = pdf_to_int(ctx, pdf_dict_gets(ctx, dict, "N")); + doc->page_count = pdf_to_int(ctx, pdf_dict_get(ctx, dict, PDF_NAME_N)); doc->linear_page_refs = fz_resize_array(ctx, doc->linear_page_refs, doc->page_count, sizeof(pdf_obj *)); memset(doc->linear_page_refs, 0, doc->page_count * sizeof(pdf_obj*)); doc->linear_obj = dict; doc->linear_pos = fz_tell(ctx, doc->file); - doc->linear_page1_obj_num = pdf_to_int(ctx, pdf_dict_gets(ctx, dict, "O")); + doc->linear_page1_obj_num = pdf_to_int(ctx, pdf_dict_get(ctx, dict, PDF_NAME_O)); doc->linear_page_refs[0] = pdf_new_indirect(ctx, doc, doc->linear_page1_obj_num, 0); doc->linear_page_num = 0; - hint = pdf_dict_gets(ctx, dict, "H"); + hint = pdf_dict_get(ctx, dict, PDF_NAME_H); doc->hint_object_offset = pdf_to_int(ctx, pdf_array_get(ctx, hint, 0)); doc->hint_object_length = pdf_to_int(ctx, pdf_array_get(ctx, hint, 1)); @@ -1152,9 +1152,9 @@ pdf_ocg_set_config(fz_context *ctx, pdf_document *doc, int config) int i, j, len, len2; pdf_ocg_descriptor *desc = doc->ocg; pdf_obj *obj, *cobj; - char *name; + pdf_obj *name; - obj = pdf_dict_gets(ctx, pdf_dict_gets(ctx, pdf_trailer(ctx, doc), "Root"), "OCProperties"); + obj = pdf_dict_get(ctx, pdf_dict_get(ctx, pdf_trailer(ctx, doc), PDF_NAME_Root), PDF_NAME_OCProperties); if (!obj) { if (config == 0) @@ -1164,29 +1164,29 @@ pdf_ocg_set_config(fz_context *ctx, pdf_document *doc, int config) } if (config == 0) { - cobj = pdf_dict_gets(ctx, obj, "D"); + cobj = pdf_dict_get(ctx, obj, PDF_NAME_D); if (!cobj) fz_throw(ctx, FZ_ERROR_GENERIC, "No default OCG config"); } else { - cobj = pdf_array_get(ctx, pdf_dict_gets(ctx, obj, "Configs"), config); + cobj = pdf_array_get(ctx, pdf_dict_get(ctx, obj, PDF_NAME_Configs), config); if (!cobj) fz_throw(ctx, FZ_ERROR_GENERIC, "Illegal OCG config"); } pdf_drop_obj(ctx, desc->intent); - desc->intent = pdf_dict_gets(ctx, cobj, "Intent"); + desc->intent = pdf_dict_get(ctx, cobj, PDF_NAME_Intent); if (desc->intent) pdf_keep_obj(ctx, desc->intent); len = desc->len; - name = pdf_to_name(ctx, pdf_dict_gets(ctx, cobj, "BaseState")); - if (strcmp(name, "Unchanged") == 0) + name = pdf_dict_get(ctx, cobj, PDF_NAME_BaseState); + if (pdf_name_eq(ctx, name, PDF_NAME_Unchanged)) { /* Do nothing */ } - else if (strcmp(name, "OFF") == 0) + else if (pdf_name_eq(ctx, name, PDF_NAME_OFF)) { for (i = 0; i < len; i++) { @@ -1201,7 +1201,7 @@ pdf_ocg_set_config(fz_context *ctx, pdf_document *doc, int config) } } - obj = pdf_dict_gets(ctx, cobj, "ON"); + obj = pdf_dict_get(ctx, cobj, PDF_NAME_ON); len2 = pdf_array_len(ctx, obj); for (i = 0; i < len2; i++) { @@ -1218,7 +1218,7 @@ pdf_ocg_set_config(fz_context *ctx, pdf_document *doc, int config) } } - obj = pdf_dict_gets(ctx, cobj, "OFF"); + obj = pdf_dict_get(ctx, cobj, PDF_NAME_OFF); len2 = pdf_array_len(ctx, obj); for (i = 0; i < len2; i++) { @@ -1259,10 +1259,10 @@ pdf_read_ocg(fz_context *ctx, pdf_document *doc) fz_var(desc); - obj = pdf_dict_gets(ctx, pdf_dict_gets(ctx, pdf_trailer(ctx, doc), "Root"), "OCProperties"); + obj = pdf_dict_get(ctx, pdf_dict_get(ctx, pdf_trailer(ctx, doc), PDF_NAME_Root), PDF_NAME_OCProperties); if (!obj) return; - ocg = pdf_dict_gets(ctx, obj, "OCGs"); + ocg = pdf_dict_get(ctx, obj, PDF_NAME_OCGs); if (!ocg || !pdf_is_array(ctx, ocg)) /* Not ever supposed to happen, but live with it. */ return; @@ -1364,8 +1364,8 @@ pdf_init_document(fz_context *ctx, pdf_document *doc) pdf_prime_xref_index(ctx, doc); } - encrypt = pdf_dict_gets(ctx, pdf_trailer(ctx, doc), "Encrypt"); - id = pdf_dict_gets(ctx, pdf_trailer(ctx, doc), "ID"); + encrypt = pdf_dict_get(ctx, pdf_trailer(ctx, doc), PDF_NAME_Encrypt); + id = pdf_dict_get(ctx, pdf_trailer(ctx, doc), PDF_NAME_ID); if (pdf_is_dict(ctx, encrypt)) doc->crypt = pdf_new_crypt(ctx, encrypt, id); @@ -1377,8 +1377,8 @@ pdf_init_document(fz_context *ctx, pdf_document *doc) int xref_len = pdf_xref_len(ctx, doc); pdf_repair_obj_stms(ctx, doc); - hasroot = (pdf_dict_gets(ctx, pdf_trailer(ctx, doc), "Root") != NULL); - hasinfo = (pdf_dict_gets(ctx, pdf_trailer(ctx, doc), "Info") != NULL); + hasroot = (pdf_dict_get(ctx, pdf_trailer(ctx, doc), PDF_NAME_Root) != NULL); + hasinfo = (pdf_dict_get(ctx, pdf_trailer(ctx, doc), PDF_NAME_Info) != NULL); for (i = 1; i < xref_len; i++) { @@ -1399,11 +1399,11 @@ pdf_init_document(fz_context *ctx, pdf_document *doc) if (!hasroot) { - obj = pdf_dict_gets(ctx, dict, "Type"); - if (pdf_is_name(ctx, obj) && !strcmp(pdf_to_name(ctx, obj), "Catalog")) + obj = pdf_dict_get(ctx, dict, PDF_NAME_Type); + if (pdf_name_eq(ctx, obj, PDF_NAME_Catalog)) { nobj = pdf_new_indirect(ctx, doc, i, 0); - pdf_dict_puts(ctx, pdf_trailer(ctx, doc), "Root", nobj); + pdf_dict_put(ctx, pdf_trailer(ctx, doc), PDF_NAME_Root, nobj); pdf_drop_obj(ctx, nobj); nobj = NULL; } @@ -1411,10 +1411,10 @@ pdf_init_document(fz_context *ctx, pdf_document *doc) if (!hasinfo) { - if (pdf_dict_gets(ctx, dict, "Creator") || pdf_dict_gets(ctx, dict, "Producer")) + if (pdf_dict_get(ctx, dict, PDF_NAME_Creator) || pdf_dict_get(ctx, dict, PDF_NAME_Producer)) { nobj = pdf_new_indirect(ctx, doc, i, 0); - pdf_dict_puts(ctx, pdf_trailer(ctx, doc), "Info", nobj); + pdf_dict_put(ctx, pdf_trailer(ctx, doc), PDF_NAME_Info, nobj); pdf_drop_obj(ctx, nobj); nobj = NULL; } @@ -1448,7 +1448,7 @@ pdf_init_document(fz_context *ctx, pdf_document *doc) fz_try(ctx) { char *version_str; - obj = pdf_dict_getp(ctx, pdf_trailer(ctx, doc), "Root/Version"); + obj = pdf_dict_getl(ctx, pdf_trailer(ctx, doc), PDF_NAME_Root, PDF_NAME_Version, NULL); version_str = pdf_to_name(ctx, obj); if (*version_str) { @@ -1571,8 +1571,8 @@ pdf_load_obj_stm(fz_context *ctx, pdf_document *doc, int num, int gen, pdf_lexbu { objstm = pdf_load_object(ctx, doc, num, gen); - count = pdf_to_int(ctx, pdf_dict_gets(ctx, objstm, "N")); - first = pdf_to_int(ctx, pdf_dict_gets(ctx, objstm, "First")); + count = pdf_to_int(ctx, pdf_dict_get(ctx, objstm, PDF_NAME_N)); + first = pdf_to_int(ctx, pdf_dict_get(ctx, objstm, PDF_NAME_First)); if (count < 0) fz_throw(ctx, FZ_ERROR_GENERIC, "negative number of objects in object stream"); @@ -1800,7 +1800,7 @@ pdf_load_hinted_page(fz_context *ctx, pdf_document *doc, int pagenum) { int num = doc->hint_page[pagenum].number; pdf_obj *page = pdf_load_object(ctx, doc, num, 0); - if (!strcmp("Page", pdf_to_name(ctx, pdf_dict_gets(ctx, page, "Type")))) + if (pdf_name_eq(ctx, PDF_NAME_Page, pdf_dict_get(ctx, page, PDF_NAME_Type))) { /* We have found the page object! */ DEBUGMESS((ctx, "LoadHintedPage pagenum=%d num=%d", pagenum, num)); @@ -2197,7 +2197,7 @@ pdf_meta(fz_context *ctx, pdf_document *doc, int key, void *ptr, int size) } case FZ_META_INFO: { - pdf_obj *info = pdf_dict_gets(ctx, pdf_trailer(ctx, doc), "Info"); + pdf_obj *info = pdf_dict_get(ctx, pdf_trailer(ctx, doc), PDF_NAME_Info); if (!info) { if (ptr) @@ -2335,7 +2335,7 @@ pdf_load_hints(fz_context *ctx, pdf_document *doc, int objnum, int gennum) if (dict == NULL || !pdf_is_dict(ctx, dict)) fz_throw(ctx, FZ_ERROR_GENERIC, "malformed hint object"); - shared_hint_offset = pdf_to_int(ctx, pdf_dict_gets(ctx, dict, "S")); + shared_hint_offset = pdf_to_int(ctx, pdf_dict_get(ctx, dict, PDF_NAME_S)); /* Malloc the structures (use realloc to cope with the fact we * may try this several times before enough data is loaded) */ @@ -2607,8 +2607,8 @@ pdf_obj *pdf_progressive_advance(fz_context *ctx, pdf_document *doc, int pagenum pdf_obj *pages; doc->linear_pos = doc->file_length; pdf_load_xref(ctx, doc, buf); - catalog = pdf_dict_gets(ctx, pdf_trailer(ctx, doc), "Root"); - pages = pdf_dict_gets(ctx, catalog, "Pages"); + catalog = pdf_dict_get(ctx, pdf_trailer(ctx, doc), PDF_NAME_Root); + pages = pdf_dict_get(ctx, catalog, PDF_NAME_Pages); if (!pdf_is_dict(ctx, pages)) fz_throw(ctx, FZ_ERROR_GENERIC, "missing page tree"); @@ -2663,19 +2663,19 @@ pdf_document *pdf_create_document(fz_context *ctx) pdf_get_populating_xref_entry(ctx, doc, 0); doc->xref_altered = 1; trailer = pdf_new_dict(ctx, doc, 2); - pdf_dict_puts_drop(ctx, trailer, "Size", pdf_new_int(ctx, doc, 3)); + pdf_dict_put_drop(ctx, trailer, PDF_NAME_Size, pdf_new_int(ctx, doc, 3)); o = root = pdf_new_dict(ctx, doc, 2); - pdf_dict_puts_drop(ctx, trailer, "Root", pdf_new_ref(ctx, doc, o)); + pdf_dict_put_drop(ctx, trailer, PDF_NAME_Root, pdf_new_ref(ctx, doc, o)); pdf_drop_obj(ctx, o); o = NULL; - pdf_dict_puts_drop(ctx, root, "Type", pdf_new_name(ctx, doc, "Catalog")); + pdf_dict_put_drop(ctx, root, PDF_NAME_Type, PDF_NAME_Catalog); o = pages = pdf_new_dict(ctx, doc, 3); - pdf_dict_puts_drop(ctx, root, "Pages", pdf_new_ref(ctx, doc, o)); + pdf_dict_put_drop(ctx, root, PDF_NAME_Pages, pdf_new_ref(ctx, doc, o)); pdf_drop_obj(ctx, o); o = NULL; - pdf_dict_puts_drop(ctx, pages, "Type", pdf_new_name(ctx, doc, "Pages")); - pdf_dict_puts_drop(ctx, pages, "Count", pdf_new_int(ctx, doc, 0)); - pdf_dict_puts_drop(ctx, pages, "Kids", pdf_new_array(ctx, doc, 1)); + pdf_dict_put_drop(ctx, pages, PDF_NAME_Type, PDF_NAME_Pages); + pdf_dict_put_drop(ctx, pages, PDF_NAME_Count, pdf_new_int(ctx, doc, 0)); + pdf_dict_put_drop(ctx, pages, PDF_NAME_Kids, pdf_new_array(ctx, doc, 1)); pdf_set_populating_xref_trailer(ctx, doc, trailer); pdf_drop_obj(ctx, trailer); } |