aboutsummaryrefslogtreecommitdiff
path: root/xpdf/OptionalContent.h
diff options
context:
space:
mode:
authorCalvin Morrison <calvin@pobox.com>2023-04-05 14:13:39 -0400
committerCalvin Morrison <calvin@pobox.com>2023-04-05 14:13:39 -0400
commit835e373b3eeaabcd0621ed6798ab500f37982fae (patch)
treedfa16b0e2e1b4956b38f693220eac4e607802133 /xpdf/OptionalContent.h
xpdf-no-select-disableHEADmaster
Diffstat (limited to 'xpdf/OptionalContent.h')
-rw-r--r--xpdf/OptionalContent.h139
1 files changed, 139 insertions, 0 deletions
diff --git a/xpdf/OptionalContent.h b/xpdf/OptionalContent.h
new file mode 100644
index 0000000..f00ef29
--- /dev/null
+++ b/xpdf/OptionalContent.h
@@ -0,0 +1,139 @@
+//========================================================================
+//
+// OptionalContent.h
+//
+// Copyright 2008-2013 Glyph & Cog, LLC
+//
+//========================================================================
+
+#ifndef OPTIONALCONTENT_H
+#define OPTIONALCONTENT_H
+
+#include <aconf.h>
+
+#ifdef USE_GCC_PRAGMAS
+#pragma interface
+#endif
+
+#include "gtypes.h"
+#include "Object.h"
+#include "CharTypes.h"
+
+class GString;
+class GList;
+class PDFDoc;
+class TextString;
+class XRef;
+class OptionalContentGroup;
+class OCDisplayNode;
+
+//------------------------------------------------------------------------
+
+class OptionalContent {
+public:
+
+ OptionalContent(PDFDoc *doc);
+ ~OptionalContent();
+
+ // Walk the list of optional content groups.
+ int getNumOCGs();
+ OptionalContentGroup *getOCG(int idx);
+
+ // Find an OCG by indirect reference.
+ OptionalContentGroup *findOCG(Ref *ref);
+
+ // Get the root node of the optional content group display tree
+ // (which does not necessarily include all of the OCGs).
+ OCDisplayNode *getDisplayRoot() { return display; }
+
+ // Evaluate an optional content object -- either an OCG or an OCMD.
+ // If <obj> is a valid OCG or OCMD, sets *<visible> and returns
+ // true; otherwise returns false.
+ GBool evalOCObject(Object *obj, GBool *visible);
+
+private:
+
+ GBool evalOCVisibilityExpr(Object *expr, int recursion);
+
+ XRef *xref;
+ GList *ocgs; // all OCGs [OptionalContentGroup]
+ OCDisplayNode *display; // root node of display tree
+};
+
+//------------------------------------------------------------------------
+
+// Values from the optional content usage dictionary.
+enum OCUsageState {
+ ocUsageOn,
+ ocUsageOff,
+ ocUsageUnset
+};
+
+//------------------------------------------------------------------------
+
+class OptionalContentGroup {
+public:
+
+ static OptionalContentGroup *parse(Ref *refA, Object *obj);
+ ~OptionalContentGroup();
+
+ GBool matches(Ref *refA);
+
+ Unicode *getName();
+ int getNameLength();
+ OCUsageState getViewState() { return viewState; }
+ OCUsageState getPrintState() { return printState; }
+ GBool getState() { return state; }
+ void setState(GBool stateA) { state = stateA; }
+ GBool getInViewUsageAppDict() { return inViewUsageAppDict; }
+ void setInViewUsageAppDict() { inViewUsageAppDict = gTrue; }
+
+private:
+
+ OptionalContentGroup(Ref *refA, TextString *nameA,
+ OCUsageState viewStateA, OCUsageState printStateA);
+
+ Ref ref;
+ TextString *name;
+ OCUsageState viewState, // suggested state when viewing
+ printState; // suggested state when printing
+ GBool state; // current state (on/off)
+ GBool inViewUsageAppDict; // true if this OCG is listed in a
+ // usage app dict with Event=View
+
+ friend class OCDisplayNode;
+};
+
+//------------------------------------------------------------------------
+
+class OCDisplayNode {
+public:
+
+ static OCDisplayNode *parse(Object *obj, OptionalContent *oc, XRef *xref,
+ int recursion = 0);
+ OCDisplayNode();
+ ~OCDisplayNode();
+
+ Unicode *getName();
+ int getNameLength();
+ OptionalContentGroup *getOCG() { return ocg; }
+ int getNumChildren();
+ OCDisplayNode *getChild(int idx);
+ OCDisplayNode *getParent() { return parent; }
+
+private:
+
+ OCDisplayNode(GString *nameA);
+ OCDisplayNode(OptionalContentGroup *ocgA);
+ void addChild(OCDisplayNode *child);
+ void addChildren(GList *childrenA);
+ GList *takeChildren();
+
+ TextString *name; // display name
+ OptionalContentGroup *ocg; // NULL for display labels
+ OCDisplayNode *parent; // parent node; NULL at root
+ GList *children; // NULL if there are no children
+ // [OCDisplayNode]
+};
+
+#endif