From 5b029fe5752c11e8de2e683c857db547e90a45be Mon Sep 17 00:00:00 2001 From: Tor Andersson Date: Thu, 7 Jul 2016 14:06:10 +0200 Subject: Slim pdf_annot struct: remove cached annot_type and widget_type fields. --- source/pdf/pdf-annot-edit.c | 2 -- source/pdf/pdf-annot.c | 11 ++--------- source/pdf/pdf-appearance.c | 2 +- source/pdf/pdf-form.c | 13 +++++++------ 4 files changed, 10 insertions(+), 18 deletions(-) (limited to 'source') diff --git a/source/pdf/pdf-annot-edit.c b/source/pdf/pdf-annot-edit.c index f4431414..95b41958 100644 --- a/source/pdf/pdf-annot-edit.c +++ b/source/pdf/pdf-annot-edit.c @@ -121,8 +121,6 @@ pdf_create_annot(fz_context *ctx, pdf_document *doc, pdf_page *page, fz_annot_ty annot = pdf_new_annot(ctx, page, &page_ctm, &inv_page_ctm); annot->ap = NULL; - annot->widget_type = PDF_WIDGET_TYPE_NOT_WIDGET; - annot->annot_type = type; /* Both annotation object and annotation structure are now created. diff --git a/source/pdf/pdf-annot.c b/source/pdf/pdf-annot.c index 00e5b983..b502730a 100644 --- a/source/pdf/pdf-annot.c +++ b/source/pdf/pdf-annot.c @@ -427,8 +427,9 @@ pdf_annot_transform(fz_context *ctx, pdf_annot *annot, fz_matrix *annot_ctm) fz_pre_scale(fz_translate(annot_ctm, x, y), w, h); } -fz_annot_type pdf_annot_obj_type(fz_context *ctx, pdf_obj *obj) +fz_annot_type pdf_annot_type(fz_context *ctx, pdf_annot *annot) { + pdf_obj *obj = annot->obj; pdf_obj *subtype = pdf_dict_get(ctx, obj, PDF_NAME_Subtype); if (pdf_name_eq(ctx, PDF_NAME_Text, subtype)) return FZ_ANNOT_TEXT; @@ -584,8 +585,6 @@ pdf_load_annots(fz_context *ctx, pdf_document *doc, pdf_page *page, pdf_obj *ann n = pdf_dict_get(ctx, n, as); annot->ap = NULL; - annot->annot_type = pdf_annot_obj_type(ctx, obj); - annot->widget_type = annot->annot_type == FZ_ANNOT_WIDGET ? pdf_field_type(ctx, doc, obj) : PDF_WIDGET_TYPE_NOT_WIDGET; if (pdf_is_stream(ctx, n)) { @@ -644,9 +643,3 @@ pdf_bound_annot(fz_context *ctx, pdf_annot *annot, fz_rect *rect) fz_transform_rect(rect, &annot->page_ctm); return rect; } - -fz_annot_type -pdf_annot_type(fz_context *ctx, pdf_annot *annot) -{ - return annot->annot_type; -} diff --git a/source/pdf/pdf-appearance.c b/source/pdf/pdf-appearance.c index 1e74fa15..d9e9e5a0 100644 --- a/source/pdf/pdf-appearance.c +++ b/source/pdf/pdf-appearance.c @@ -2435,7 +2435,7 @@ void pdf_update_appearance(fz_context *ctx, pdf_document *doc, pdf_annot *annot) pdf_obj *obj = annot->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); + fz_annot_type type = pdf_annot_type(ctx, annot); switch (type) { case FZ_ANNOT_WIDGET: diff --git a/source/pdf/pdf-form.c b/source/pdf/pdf-form.c index 3e39409e..d29d7c41 100644 --- a/source/pdf/pdf-form.c +++ b/source/pdf/pdf-form.c @@ -643,7 +643,7 @@ int pdf_pass_event(fz_context *ctx, pdf_document *doc, pdf_page *page, pdf_ui_ev if (annot) { - switch (annot->widget_type) + switch (pdf_widget_type(ctx, (pdf_widget*)annot)) { case PDF_WIDGET_TYPE_RADIOBUTTON: case PDF_WIDGET_TYPE_CHECKBOX: @@ -748,7 +748,7 @@ pdf_widget *pdf_first_widget(fz_context *ctx, pdf_document *doc, pdf_page *page) { pdf_annot *annot = page->annots; - while (annot && annot->widget_type == PDF_WIDGET_TYPE_NOT_WIDGET) + while (annot && pdf_annot_type(ctx, annot) != FZ_ANNOT_WIDGET) annot = annot->next; return (pdf_widget *)annot; @@ -761,7 +761,7 @@ pdf_widget *pdf_next_widget(fz_context *ctx, pdf_widget *previous) if (annot) annot = annot->next; - while (annot && annot->widget_type == PDF_WIDGET_TYPE_NOT_WIDGET) + while (annot && pdf_annot_type(ctx, annot) != FZ_ANNOT_WIDGET) annot = annot->next; return (pdf_widget *)annot; @@ -777,7 +777,6 @@ pdf_widget *pdf_create_widget(fz_context *ctx, pdf_document *doc, pdf_page *page { pdf_set_field_type(ctx, doc, annot->obj, type); 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) { @@ -813,10 +812,12 @@ pdf_widget *pdf_create_widget(fz_context *ctx, pdf_document *doc, pdf_page *page return (pdf_widget *)annot; } -int pdf_widget_get_type(fz_context *ctx, pdf_widget *widget) +int pdf_widget_type(fz_context *ctx, pdf_widget *widget) { pdf_annot *annot = (pdf_annot *)widget; - return annot->widget_type; + if (pdf_annot_type(ctx, annot) == FZ_ANNOT_WIDGET) + return pdf_field_type(ctx, pdf_get_bound_document(ctx, annot->obj), annot->obj); + return PDF_WIDGET_TYPE_NOT_WIDGET; } static int set_text_field_value(fz_context *ctx, pdf_document *doc, pdf_obj *field, const char *text) -- cgit v1.2.3