diff options
author | Robin Watts <robin.watts@artifex.com> | 2016-11-11 19:48:58 +0000 |
---|---|---|
committer | Robin Watts <robin.watts@artifex.com> | 2016-11-14 16:09:41 +0000 |
commit | e70dcdfb2372857f5f685de5d7742ab5d6ba9d7c (patch) | |
tree | 420137adda596f23f1829b32ad9bfcb4cf93c837 /source/pdf | |
parent | 7703ad8b2564f2f3a99b85eca5af276d7ba0e3e4 (diff) | |
download | mupdf-e70dcdfb2372857f5f685de5d7742ab5d6ba9d7c.tar.xz |
Continued Layer API work.
Hide pdf_is_hidden_ocg from the public interface.
Ensure that RBGroups and Order properly fall back to the default
entries if they are missing in the OCCDs.
Add pdf_set_layer_config_as_default. This sets the default
layer config to be current one. This destroys the current
default dictionary, but we leave the other configs intact.
Diffstat (limited to 'source/pdf')
-rw-r--r-- | source/pdf/pdf-imp.h | 2 | ||||
-rw-r--r-- | source/pdf/pdf-interpret.c | 2 | ||||
-rw-r--r-- | source/pdf/pdf-layer.c | 71 |
3 files changed, 73 insertions, 2 deletions
diff --git a/source/pdf/pdf-imp.h b/source/pdf/pdf-imp.h index 37605c51..5f2dcc2d 100644 --- a/source/pdf/pdf-imp.h +++ b/source/pdf/pdf-imp.h @@ -6,4 +6,6 @@ void pdf_read_ocg(fz_context *ctx, pdf_document *doc); void pdf_drop_ocg(fz_context *ctx, pdf_document *doc); +int pdf_is_hidden_ocg(fz_context *ctx, pdf_ocg_descriptor *desc, pdf_obj *rdb, const char *usage, pdf_obj *ocg); + #endif diff --git a/source/pdf/pdf-interpret.c b/source/pdf/pdf-interpret.c index 4a8a2a46..258563ca 100644 --- a/source/pdf/pdf-interpret.c +++ b/source/pdf/pdf-interpret.c @@ -1,4 +1,4 @@ -#include "mupdf/pdf.h" +#include "pdf-imp.h" void * pdf_new_processor(fz_context *ctx, int size) diff --git a/source/pdf/pdf-layer.c b/source/pdf/pdf-layer.c index 70dfcd50..3296b6c5 100644 --- a/source/pdf/pdf-layer.c +++ b/source/pdf/pdf-layer.c @@ -156,8 +156,12 @@ load_ui(fz_context *ctx, pdf_ocg_descriptor *desc, pdf_obj *ocprops, pdf_obj *oc /* Count the number of entries */ order = pdf_dict_get(ctx, occg, PDF_NAME_Order); + if (!order) + order = pdf_dict_getp(ctx, ocprops, "D/Order"); count = count_entries(ctx, order); rbgroups = pdf_dict_get(ctx, occg, PDF_NAME_RBGroups); + if (!rbgroups) + rbgroups = pdf_dict_getp(ctx, ocprops, "D/RBGroups"); locked = pdf_dict_get(ctx, occg, PDF_NAME_Locked); desc->num_ui_entries = count; @@ -401,7 +405,7 @@ void pdf_toggle_layer_config_ui(fz_context *ctx, pdf_document *doc, int ui) doc->ocg->ocgs[entry->ocg].state = !selected; } -void pdf_deselect_layer_ui(fz_context *ctx, pdf_document *doc, int ui) +void pdf_deselect_layer_config_ui(fz_context *ctx, pdf_document *doc, int ui) { pdf_ocg_ui *entry; @@ -713,3 +717,68 @@ pdf_read_ocg(fz_context *ctx, pdf_document *doc) pdf_select_layer_config(ctx, doc, 0); } + +void +pdf_set_layer_config_as_default(fz_context *ctx, pdf_document *doc) +{ + pdf_obj *ocprops, *d, *order, *on, *configs, *rbgroups; + int k; + + if (doc == NULL || doc->ocg == NULL) + return; + + ocprops = pdf_dict_getp(ctx, pdf_trailer(ctx, doc), "Root/OCProperties"); + if (!ocprops) + return; + + /* All files with OCGs are required to have a D entry */ + d = pdf_dict_get(ctx, ocprops, PDF_NAME_D); + if (d == NULL) + return; + + pdf_dict_put(ctx, d, PDF_NAME_BaseState, PDF_NAME_OFF); + + /* We are about to delete RBGroups and Order, from D. These are + * both the underlying defaults for other configs, so copy the + * current values out to any config that doesn't have one + * already. */ + order = pdf_dict_get(ctx, d, PDF_NAME_Order); + rbgroups = pdf_dict_get(ctx, d, PDF_NAME_RBGroups); + configs = pdf_dict_get(ctx, ocprops, PDF_NAME_Configs); + if (configs) + { + int len = pdf_array_len(ctx, configs); + for (k=0; k < len; k++) + { + pdf_obj *config = pdf_array_get(ctx, configs, k); + + if (order && !pdf_dict_get(ctx, config, PDF_NAME_Order)) + pdf_dict_put(ctx, config, PDF_NAME_Order, order); + if (rbgroups && !pdf_dict_get(ctx, config, PDF_NAME_RBGroups)) + pdf_dict_put(ctx, config, PDF_NAME_RBGroups, rbgroups); + } + } + + /* Offer all the layers in the UI */ + order = pdf_new_array(ctx, doc, 4); + on = pdf_new_array(ctx, doc, 4); + for (k = 0; k < doc->ocg->len; k++) + { + pdf_ocg_entry *s = &doc->ocg->ocgs[k]; + + pdf_array_push(ctx, order, s->obj); + if (s->state) + pdf_array_push(ctx, on, s->obj); + } + pdf_dict_put(ctx, d, PDF_NAME_Order, order); + pdf_dict_put(ctx, d, PDF_NAME_ON, on); + pdf_dict_del(ctx, d, PDF_NAME_OFF); + pdf_dict_del(ctx, d, PDF_NAME_AS); + pdf_dict_put(ctx, d, PDF_NAME_Intent, PDF_NAME_View); + pdf_dict_del(ctx, d, PDF_NAME_Name); + pdf_dict_del(ctx, d, PDF_NAME_Creator); + pdf_dict_del(ctx, d, PDF_NAME_RBGroups); + pdf_dict_del(ctx, d, PDF_NAME_Locked); + + pdf_dict_del(ctx, ocprops, PDF_NAME_Configs); +} |