diff options
author | Tor Andersson <tor.andersson@artifex.com> | 2018-11-12 14:37:36 +0100 |
---|---|---|
committer | Tor Andersson <tor.andersson@artifex.com> | 2018-11-12 17:55:54 +0100 |
commit | 984ae2a4484c8cf4177349efdfe3aeaa469ba152 (patch) | |
tree | 008249920515761b6831d8f4ccb12d4c59212c98 | |
parent | e51354df45832a138dca9216408b3aea03030f49 (diff) | |
download | mupdf-984ae2a4484c8cf4177349efdfe3aeaa469ba152.tar.xz |
Clean up pdf-portfolio.c
Remove pointless paranoia checks.
Move the check whether it has already been loaded into load_portfolio().
-rw-r--r-- | include/mupdf/pdf/document.h | 34 | ||||
-rw-r--r-- | source/pdf/pdf-portfolio.c | 75 |
2 files changed, 20 insertions, 89 deletions
diff --git a/include/mupdf/pdf/document.h b/include/mupdf/pdf/document.h index 3a11787b..fb62c739 100644 --- a/include/mupdf/pdf/document.h +++ b/include/mupdf/pdf/document.h @@ -393,40 +393,6 @@ int pdf_count_portfolio_entries(fz_context *ctx, pdf_document *doc); fz_buffer *pdf_portfolio_entry(fz_context *ctx, pdf_document *doc, int entry); /* - pdf_portfolio_entry_obj_name: Retrieve the object and - name of a given portfolio entry. - - doc: The document in question. - - entry: A value in the 0..m-1 range, where m is the - value returned from pdf_count_portfolio_entries. - - name: Pointer to a place to store the pointer to the - object representing the name. This is a borrowed - reference - do not drop it. - - Returns a pointer to the pdf_object representing the - object. This is a borrowed reference - do not drop - it. -*/ -pdf_obj *pdf_portfolio_entry_obj_name(fz_context *ctx, pdf_document *doc, int entry, pdf_obj **name); - -/* - pdf_portfolio_entry_obj: Retrieve the object - representing a given portfolio entry. - - doc: The document in question. - - entry: A value in the 0..m-1 range, where m is the - value returned from pdf_count_portfolio_entries. - - Returns a pointer to the pdf_object representing the - object. This is a borrowed reference - do not drop - it. -*/ -pdf_obj *pdf_portfolio_entry_obj(fz_context *ctx, pdf_document *doc, int entry); - -/* pdf_portfolio_entry_name: Retrieve the name of a given portfolio entry. diff --git a/source/pdf/pdf-portfolio.c b/source/pdf/pdf-portfolio.c index 74f9a34f..eb33643b 100644 --- a/source/pdf/pdf-portfolio.c +++ b/source/pdf/pdf-portfolio.c @@ -23,6 +23,9 @@ load_portfolio(fz_context *ctx, pdf_document *doc) int i, n; pdf_portfolio **pp; + if (doc->portfolio) + return; + obj = pdf_dict_getl(ctx, pdf_trailer(ctx, doc), PDF_NAME(Root), PDF_NAME(Collection), PDF_NAME(Schema), NULL); n = pdf_dict_len(ctx, obj); @@ -77,17 +80,15 @@ load_portfolio(fz_context *ctx, pdf_document *doc) int pdf_count_portfolio_schema(fz_context *ctx, pdf_document *doc) { pdf_portfolio *port; - int i; + int n; - if (!doc) - return 0; - - if (doc->portfolio == NULL) - load_portfolio(ctx, doc); + load_portfolio(ctx, doc); - for (i = 0, port = doc->portfolio; port; port = port->next, i++); + n = 0; + for (port = doc->portfolio; port; port = port->next) + ++n; - return i; + return n; } /* @@ -107,11 +108,7 @@ void pdf_portfolio_schema_info(fz_context *ctx, pdf_document *doc, int entry, pd { pdf_portfolio *p; - if (!doc || !info) - fz_throw(ctx, FZ_ERROR_GENERIC, "Bad pdf_portfolio_schema_info call"); - - if (doc->portfolio == NULL) - load_portfolio(ctx, doc); + load_portfolio(ctx, doc); p = doc->portfolio; while (p && entry > 0) @@ -128,11 +125,7 @@ void pdf_reorder_portfolio_schema(fz_context *ctx, pdf_document *doc, int entry, pdf_portfolio **pp; pdf_portfolio *p; - if (!doc) - fz_throw(ctx, FZ_ERROR_GENERIC, "Bad pdf_portfolio_schema_info call"); - - if (doc->portfolio == NULL) - load_portfolio(ctx, doc); + load_portfolio(ctx, doc); /* Take p out */ pp = &doc->portfolio; @@ -160,11 +153,7 @@ void pdf_rename_portfolio_schema(fz_context *ctx, pdf_document *doc, int entry, pdf_portfolio *p; pdf_obj *s; - if (!doc) - fz_throw(ctx, FZ_ERROR_GENERIC, "Bad pdf_rename_portfolio_schema call"); - - if (doc->portfolio == NULL) - load_portfolio(ctx, doc); + load_portfolio(ctx, doc); p = doc->portfolio; while (p && entry > 0) @@ -254,11 +243,7 @@ void pdf_delete_portfolio_schema(fz_context *ctx, pdf_document *doc, int entry) pdf_portfolio *p; pdf_obj *s; - if (!doc) - fz_throw(ctx, FZ_ERROR_GENERIC, "Bad pdf_delete_portfolio_schema call"); - - if (doc->portfolio == NULL) - load_portfolio(ctx, doc); + load_portfolio(ctx, doc); pp = &doc->portfolio; while (*pp && entry > 0) @@ -293,11 +278,7 @@ void pdf_add_portfolio_schema(fz_context *ctx, pdf_document *doc, int entry, con char str_name[32]; pdf_obj *num_name = NULL; - if (!doc) - fz_throw(ctx, FZ_ERROR_GENERIC, "Bad pdf_add_portfolio_schema call"); - - if (doc->portfolio == NULL) - load_portfolio(ctx, doc); + load_portfolio(ctx, doc); fz_var(num_name); fz_var(sc); @@ -379,11 +360,7 @@ int pdf_count_portfolio_entries(fz_context *ctx, pdf_document *doc) pdf_obj *s; int count; - if (!doc) - return 0; - - if (doc->portfolio == NULL) - load_portfolio(ctx, doc); + load_portfolio(ctx, doc); s = pdf_dict_getl(ctx, pdf_trailer(ctx, doc), PDF_NAME(Root), PDF_NAME(Names), PDF_NAME(EmbeddedFiles), NULL); count = 0; @@ -425,7 +402,7 @@ static int find_entry(fz_context *ctx, pdf_obj *container, pdf_obj *key, pdf_obj is borrowed, so call pdf_keep_obj on it if you wish to keep it. */ -pdf_obj *pdf_portfolio_entry_obj_name(fz_context *ctx, pdf_document *doc, int entry, pdf_obj **name) +static pdf_obj *pdf_portfolio_entry_obj_name(fz_context *ctx, pdf_document *doc, int entry, pdf_obj **name) { struct find_data data; pdf_obj *s; @@ -433,11 +410,7 @@ pdf_obj *pdf_portfolio_entry_obj_name(fz_context *ctx, pdf_document *doc, int en if (name) *name = NULL; - if (!doc) - return NULL; - - if (doc->portfolio == NULL) - load_portfolio(ctx, doc); + load_portfolio(ctx, doc); s = pdf_dict_getl(ctx, pdf_trailer(ctx, doc), PDF_NAME(Root), PDF_NAME(Names), PDF_NAME(EmbeddedFiles), NULL); data.count = entry; @@ -450,7 +423,7 @@ pdf_obj *pdf_portfolio_entry_obj_name(fz_context *ctx, pdf_document *doc, int en return data.val; } -pdf_obj *pdf_portfolio_entry_obj(fz_context *ctx, pdf_document *doc, int entry) +static pdf_obj *pdf_portfolio_entry_obj(fz_context *ctx, pdf_document *doc, int entry) { pdf_obj *name; @@ -621,11 +594,7 @@ int pdf_add_portfolio_entry(fz_context *ctx, pdf_document *doc, fz_var(val); - if (!doc) - fz_throw(ctx, FZ_ERROR_GENERIC, "Bad pdf_add_portfolio_entry call"); - - if (doc->portfolio == NULL) - load_portfolio(ctx, doc); + load_portfolio(ctx, doc); /* Portfolios were introduced in PDF 1.7. */ if (doc->version < 17) @@ -680,11 +649,7 @@ void pdf_set_portfolio_entry_info(fz_context *ctx, pdf_document *doc, int entry, pdf_obj *obj, *lookup; int ef = 0; - if (!doc) - fz_throw(ctx, FZ_ERROR_GENERIC, "Bad pdf_add_portfolio_entry call"); - - if (doc->portfolio == NULL) - load_portfolio(ctx, doc); + load_portfolio(ctx, doc); obj = pdf_portfolio_entry_obj_name(ctx, doc, entry, NULL); if (!obj) |