summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTor Andersson <tor.andersson@artifex.com>2018-07-17 15:05:22 +0200
committerTor Andersson <tor.andersson@artifex.com>2018-08-10 14:09:46 +0200
commit4944aa0734523573e76e26c42f65e8998b8692ed (patch)
tree1c89caef8b2ab9c71f12558211a3eac195ee01cd
parent1fbbe664d21be2d8a52b2274f1c39861c17c5cc1 (diff)
downloadmupdf-4944aa0734523573e76e26c42f65e8998b8692ed.tar.xz
Remove functions that implement duplicate functionality.
pdf_get_inheritable also looks in trailer/Root/AcroForm for missing keys, but this behavior is not supported by anything in the specification.
-rw-r--r--include/mupdf/pdf/field.h2
-rw-r--r--source/pdf/pdf-field.c63
-rw-r--r--source/pdf/pdf-form.c42
3 files changed, 18 insertions, 89 deletions
diff --git a/include/mupdf/pdf/field.h b/include/mupdf/pdf/field.h
index 5b25dc3f..65d2af2e 100644
--- a/include/mupdf/pdf/field.h
+++ b/include/mupdf/pdf/field.h
@@ -33,8 +33,6 @@ enum
Ff_CommitOnSelCHange = 1 << (27-1),
};
-char *pdf_get_string_or_stream(fz_context *ctx, pdf_document *doc, pdf_obj *obj);
-pdf_obj *pdf_get_inheritable(fz_context *ctx, pdf_document *doc, pdf_obj *obj, pdf_obj *key);
int pdf_get_field_flags(fz_context *ctx, pdf_document *doc, pdf_obj *obj);
int pdf_field_type(fz_context *ctx, pdf_document *doc, pdf_obj *field);
void pdf_set_field_type(fz_context *ctx, pdf_document *doc, pdf_obj *obj, int type);
diff --git a/source/pdf/pdf-field.c b/source/pdf/pdf-field.c
index 07a6e770..3bb0acc3 100644
--- a/source/pdf/pdf-field.c
+++ b/source/pdf/pdf-field.c
@@ -3,76 +3,19 @@
#include <string.h>
-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_get(ctx, obj, key);
-
- if (!fobj)
- obj = pdf_dict_get(ctx, obj, PDF_NAME(Parent));
- }
-
- 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)
-{
- size_t len = 0;
- char *buf = NULL;
- fz_buffer *stmbuf = NULL;
- char *text = NULL;
-
- fz_var(stmbuf);
- fz_var(text);
- fz_try(ctx)
- {
- if (pdf_is_string(ctx, obj))
- {
- len = pdf_to_str_len(ctx, obj);
- buf = pdf_to_str_buf(ctx, obj);
- }
- else if (pdf_is_stream(ctx, obj))
- {
- stmbuf = pdf_load_stream(ctx, obj);
- len = fz_buffer_storage(ctx, stmbuf, (unsigned char **)&buf);
- }
-
- if (buf)
- {
- text = fz_malloc(ctx, len+1);
- memcpy(text, buf, len);
- text[len] = 0;
- }
- }
- fz_always(ctx)
- {
- fz_drop_buffer(ctx, stmbuf);
- }
- fz_catch(ctx)
- {
- fz_free(ctx, text);
- fz_rethrow(ctx);
- }
-
- return text;
-}
-
char *pdf_field_value(fz_context *ctx, pdf_document *doc, pdf_obj *field)
{
- return pdf_load_stream_or_string_as_utf8(ctx, pdf_get_inheritable(ctx, doc, field, PDF_NAME(V)));
+ return pdf_load_stream_or_string_as_utf8(ctx, pdf_dict_get_inheritable(ctx, 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, PDF_NAME(Ff)));
+ return pdf_to_int(ctx, pdf_dict_get_inheritable(ctx, obj, PDF_NAME(Ff)));
}
static pdf_obj *get_field_type_name(fz_context *ctx, pdf_document *doc, pdf_obj *obj)
{
- return pdf_get_inheritable(ctx, doc, obj, PDF_NAME(FT));
+ return pdf_dict_get_inheritable(ctx, obj, PDF_NAME(FT));
}
int pdf_field_type(fz_context *ctx, pdf_document *doc, pdf_obj *obj)
diff --git a/source/pdf/pdf-form.c b/source/pdf/pdf-form.c
index a838b4b8..454d3a6e 100644
--- a/source/pdf/pdf-form.c
+++ b/source/pdf/pdf-form.c
@@ -132,7 +132,7 @@ static void reset_form_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, PDF_NAME(V));
+ pdf_obj *leafv = pdf_dict_get_inheritable(ctx, field, PDF_NAME(V));
if (leafv)
pdf_keep_obj(ctx, leafv);
@@ -974,7 +974,7 @@ void pdf_field_set_text_color(fz_context *ctx, pdf_document *doc, pdf_obj *field
char buf[100];
const char *font;
float size, color[3], black;
- const char *da = pdf_to_str_buf(ctx, pdf_get_inheritable(ctx, doc, field, PDF_NAME(DA)));
+ const char *da = pdf_to_str_buf(ctx, pdf_dict_get_inheritable(ctx, field, PDF_NAME(DA)));
pdf_parse_default_appearance(ctx, da, &font, &size, color);
@@ -1031,39 +1031,27 @@ 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, PDF_NAME(MaxLen)));
+ return pdf_to_int(ctx, pdf_dict_get_inheritable(ctx, annot->obj, PDF_NAME(MaxLen)));
}
int pdf_text_widget_content_type(fz_context *ctx, pdf_document *doc, pdf_widget *tw)
{
pdf_annot *annot = (pdf_annot *)tw;
- char *code = NULL;
int type = PDF_WIDGET_CONTENT_UNRESTRAINED;
-
- fz_var(code);
- fz_try(ctx)
- {
- 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"))
- type = PDF_WIDGET_CONTENT_NUMBER;
- else if (strstr(code, "AFSpecial_Format"))
- type = PDF_WIDGET_CONTENT_SPECIAL;
- else if (strstr(code, "AFDate_FormatEx"))
- type = PDF_WIDGET_CONTENT_DATE;
- else if (strstr(code, "AFTime_FormatEx"))
- type = PDF_WIDGET_CONTENT_TIME;
- }
- }
- fz_always(ctx)
- {
+ pdf_obj *js = pdf_dict_getl(ctx, annot->obj, PDF_NAME(AA), PDF_NAME(F), PDF_NAME(JS), NULL);
+ if (js)
+ {
+ char *code = pdf_load_stream_or_string_as_utf8(ctx, js);
+ if (strstr(code, "AFNumber_Format"))
+ type = PDF_WIDGET_CONTENT_NUMBER;
+ else if (strstr(code, "AFSpecial_Format"))
+ type = PDF_WIDGET_CONTENT_SPECIAL;
+ else if (strstr(code, "AFDate_FormatEx"))
+ type = PDF_WIDGET_CONTENT_DATE;
+ else if (strstr(code, "AFTime_FormatEx"))
+ type = PDF_WIDGET_CONTENT_TIME;
fz_free(ctx, code);
}
- fz_catch(ctx)
- {
- fz_warn(ctx, "failure in fz_text_widget_content_type");
- }
return type;
}