From 7c7af425fb8d0467f4550f7ccdfa102d11f0690a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Simon=20B=C3=BCnzli?= Date: Sun, 18 Aug 2013 13:44:47 +0200 Subject: default OCGs to visible By default an OCG is supposed to be visible (for a testcase, see 2011 - ocg without ocgs invisible.pdf). Also, the default visibility value can be overwritten in both ways, so that pdf_is_hidden_ocg must check the state both for being "OFF" and "ON" (testcase was 2066 - ocg not printed.pdf rendered with event="Print"). --- source/pdf/pdf-interpret.c | 13 +++++++++---- source/pdf/pdf-xref.c | 2 +- 2 files changed, 10 insertions(+), 5 deletions(-) (limited to 'source') diff --git a/source/pdf/pdf-interpret.c b/source/pdf/pdf-interpret.c index 62173cf8..0ed30026 100644 --- a/source/pdf/pdf-interpret.c +++ b/source/pdf/pdf-interpret.c @@ -179,17 +179,18 @@ pdf_is_hidden_ocg(pdf_obj *ocg, pdf_csi *csi, pdf_obj *rdb) if (strcmp(type, "OCG") == 0) { /* An Optional Content Group */ + int default_value = 0; int num = pdf_to_num(ocg); int gen = pdf_to_gen(ocg); int len = desc->len; int i; + /* by default an OCG is visible, unless it's explicitly hidden */ for (i = 0; i < len; i++) { if (desc->ocgs[i].num == num && desc->ocgs[i].gen == gen) { - if (desc->ocgs[i].state == 0) - return 1; /* If off, hidden */ + default_value = desc->ocgs[i].state == 0; break; } } @@ -234,7 +235,7 @@ pdf_is_hidden_ocg(pdf_obj *ocg, pdf_csi *csi, pdf_obj *rdb) * dicts, this is not really a problem. */ obj = pdf_dict_gets(ocg, "Usage"); if (!pdf_is_dict(obj)) - return 0; + return default_value; /* FIXME: Should look at Zoom (and return hidden if out of * max/min range) */ /* FIXME: Could provide hooks to the caller to check if @@ -244,7 +245,11 @@ pdf_is_hidden_ocg(pdf_obj *ocg, pdf_csi *csi, pdf_obj *rdb) { return 1; } - return 0; + if (strcmp(pdf_to_name(pdf_dict_gets(obj2, event_state)), "ON") == 0) + { + return 0; + } + return default_value; } else if (strcmp(type, "OCMD") == 0) { diff --git a/source/pdf/pdf-xref.c b/source/pdf/pdf-xref.c index 9c408051..743cf452 100644 --- a/source/pdf/pdf-xref.c +++ b/source/pdf/pdf-xref.c @@ -1002,7 +1002,7 @@ pdf_read_ocg(pdf_document *doc) pdf_obj *o = pdf_array_get(ocg, i); desc->ocgs[i].num = pdf_to_num(o); desc->ocgs[i].gen = pdf_to_gen(o); - desc->ocgs[i].state = 0; + desc->ocgs[i].state = 1; } doc->ocg = desc; } -- cgit v1.2.3