summaryrefslogtreecommitdiff
path: root/print/poppler/patches/patch-ai
blob: a76d829ef6402bd000bd785f01599085c5264ed4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
$NetBSD: patch-ai,v 1.3 2008/05/15 17:51:29 drochner Exp $

--- poppler/OptionalContent.cc.orig	2008-03-26 20:38:52.000000000 +0100
+++ poppler/OptionalContent.cc
@@ -162,12 +162,18 @@ OptionalContentGroup* OCGs::findOcgByRef
 {
   //TODO: make this more efficient
   OptionalContentGroup *ocg = NULL;
-  for (int i=0; i < optionalContentGroups->getLength(); ++i) {
-    ocg = (OptionalContentGroup*)optionalContentGroups->get(i);
-    if ( (ocg->ref().num == ref.num) && (ocg->ref().gen == ref.gen) ) {
-      return ocg;
+  if (optionalContentGroups != NULL)
+  {
+    for (int i=0; i < optionalContentGroups->getLength(); ++i) {
+      ocg = (OptionalContentGroup*)optionalContentGroups->get(i);
+      if ( (ocg->ref().num == ref.num) && (ocg->ref().gen == ref.gen) ) {
+        return ocg;
+      }
     }
   }
+
+  error(-1, "Could not find a OCG with Ref (%d:%d)", ref.num, ref.gen);
+
   // not found
   return NULL;
 }
@@ -208,7 +214,7 @@ bool OCGs::optContentIsVisible( Object *
       }
     } else if (ocg.isRef()) {
       OptionalContentGroup* oc = findOcgByRef( ocg.getRef() );      
-      if ( oc->state() == OptionalContentGroup::Off ) {
+      if ( !oc || oc->state() == OptionalContentGroup::Off ) {
 	result = false;
       } else {
 	result = true ;
@@ -218,13 +224,10 @@ bool OCGs::optContentIsVisible( Object *
     policy.free();
   } else if ( dictType.isName("OCG") ) {
     OptionalContentGroup* oc = findOcgByRef( dictRef->getRef() );
-    if ( oc ) {
-//       printf("Found valid group object\n");
-      if ( oc->state() == OptionalContentGroup::Off ) {
-	result=false;
-      }
+    if ( !oc || oc->state() == OptionalContentGroup::Off ) {
+      result=false;
     }
-  } 
+  }
   dictType.free();
   dictObj.free();
   // printf("visibility: %s\n", result? "on" : "off");
@@ -238,7 +241,7 @@ bool OCGs::allOn( Array *ocgArray )
     ocgArray->getNF(i, &ocgItem);
     if (ocgItem.isRef()) {
       OptionalContentGroup* oc = findOcgByRef( ocgItem.getRef() );      
-      if ( oc->state() == OptionalContentGroup::Off ) {
+      if ( oc && oc->state() == OptionalContentGroup::Off ) {
 	return false;
       }
     }
@@ -253,7 +256,7 @@ bool OCGs::allOff( Array *ocgArray )
     ocgArray->getNF(i, &ocgItem);
     if (ocgItem.isRef()) {
       OptionalContentGroup* oc = findOcgByRef( ocgItem.getRef() );      
-      if ( oc->state() == OptionalContentGroup::On ) {
+      if ( oc && oc->state() == OptionalContentGroup::On ) {
 	return false;
       }
     }
@@ -268,7 +271,7 @@ bool OCGs::anyOn( Array *ocgArray )
     ocgArray->getNF(i, &ocgItem);
     if (ocgItem.isRef()) {
       OptionalContentGroup* oc = findOcgByRef( ocgItem.getRef() );      
-      if ( oc->state() == OptionalContentGroup::On ) {
+      if ( oc && oc->state() == OptionalContentGroup::On ) {
 	return true;
       }
     }
@@ -283,7 +286,7 @@ bool OCGs::anyOff( Array *ocgArray )
     ocgArray->getNF(i, &ocgItem);
     if (ocgItem.isRef()) {
       OptionalContentGroup* oc = findOcgByRef( ocgItem.getRef() );      
-      if ( oc->state() == OptionalContentGroup::Off ) {
+      if ( oc && oc->state() == OptionalContentGroup::Off ) {
 	return true;
       }
     }