summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobin Watts <robin.watts@artifex.com>2016-11-11 19:48:58 +0000
committerRobin Watts <robin.watts@artifex.com>2016-11-14 16:09:41 +0000
commite70dcdfb2372857f5f685de5d7742ab5d6ba9d7c (patch)
tree420137adda596f23f1829b32ad9bfcb4cf93c837
parent7703ad8b2564f2f3a99b85eca5af276d7ba0e3e4 (diff)
downloadmupdf-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.
-rw-r--r--include/mupdf/pdf/document.h6
-rw-r--r--resources/pdf/names.txt3
-rw-r--r--source/pdf/pdf-imp.h2
-rw-r--r--source/pdf/pdf-interpret.c2
-rw-r--r--source/pdf/pdf-layer.c71
5 files changed, 81 insertions, 3 deletions
diff --git a/include/mupdf/pdf/document.h b/include/mupdf/pdf/document.h
index 4cb4c819..dc74ec7b 100644
--- a/include/mupdf/pdf/document.h
+++ b/include/mupdf/pdf/document.h
@@ -237,7 +237,11 @@ typedef struct
*/
void pdf_layer_config_ui_info(fz_context *ctx, pdf_document *doc, int ui, pdf_layer_config_ui *info);
-int pdf_is_hidden_ocg(fz_context *ctx, pdf_ocg_descriptor *desc, pdf_obj *rdb, const char *usage, pdf_obj *ocg);
+/*
+ pdf_set_layer_config_as_default: Write the current layer
+ config back into the document as the default state.
+*/
+void pdf_set_layer_config_as_default(fz_context *ctx, pdf_document *doc);
/*
pdf_update_page: update a page for the sake of changes caused by a call
diff --git a/resources/pdf/names.txt b/resources/pdf/names.txt
index 30f4f60d..5a45a4b5 100644
--- a/resources/pdf/names.txt
+++ b/resources/pdf/names.txt
@@ -11,6 +11,7 @@ ASCII85Decode
ASCIIHexDecode
AcroForm
Adobe.PPKLite
+All
AllOff
AllOn
Alpha
@@ -99,6 +100,7 @@ DecodeParms
Default
DescendantFonts
Descent
+Design
Dest
Dests
DeviceCMYK
@@ -353,6 +355,7 @@ V2
VE
Version
VerticesPerRow
+View
W
W2
WMode
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);
+}