/src/xpdf-4.05/xpdf/OptionalContent.h
Line | Count | Source (jump to first uncovered line) |
1 | | //======================================================================== |
2 | | // |
3 | | // OptionalContent.h |
4 | | // |
5 | | // Copyright 2008-2013 Glyph & Cog, LLC |
6 | | // |
7 | | //======================================================================== |
8 | | |
9 | | #ifndef OPTIONALCONTENT_H |
10 | | #define OPTIONALCONTENT_H |
11 | | |
12 | | #include <aconf.h> |
13 | | |
14 | | #include "gtypes.h" |
15 | | #include "Object.h" |
16 | | #include "CharTypes.h" |
17 | | |
18 | | class GString; |
19 | | class GList; |
20 | | class PDFDoc; |
21 | | class TextString; |
22 | | class XRef; |
23 | | class OptionalContentGroup; |
24 | | class OCDisplayNode; |
25 | | |
26 | | //------------------------------------------------------------------------ |
27 | | |
28 | | class OptionalContent { |
29 | | public: |
30 | | |
31 | | OptionalContent(PDFDoc *doc); |
32 | | ~OptionalContent(); |
33 | | |
34 | | // Walk the list of optional content groups. |
35 | | int getNumOCGs(); |
36 | | OptionalContentGroup *getOCG(int idx); |
37 | | |
38 | | // Find an OCG by indirect reference. |
39 | | OptionalContentGroup *findOCG(Ref *ref); |
40 | | |
41 | | // Get the root node of the optional content group display tree |
42 | | // (which does not necessarily include all of the OCGs). |
43 | 0 | OCDisplayNode *getDisplayRoot() { return display; } |
44 | | |
45 | | // Evaluate an optional content object -- either an OCG or an OCMD. |
46 | | // If <obj> is a valid OCG or OCMD, sets *<visible> and returns |
47 | | // true; otherwise returns false. |
48 | | GBool evalOCObject(Object *obj, GBool *visible); |
49 | | |
50 | | private: |
51 | | |
52 | | GBool evalOCVisibilityExpr(Object *expr, int recursion); |
53 | | |
54 | | XRef *xref; |
55 | | GList *ocgs; // all OCGs [OptionalContentGroup] |
56 | | OCDisplayNode *display; // root node of display tree |
57 | | }; |
58 | | |
59 | | //------------------------------------------------------------------------ |
60 | | |
61 | | // Values from the optional content usage dictionary. |
62 | | enum OCUsageState { |
63 | | ocUsageOn, |
64 | | ocUsageOff, |
65 | | ocUsageUnset |
66 | | }; |
67 | | |
68 | | //------------------------------------------------------------------------ |
69 | | |
70 | | class OptionalContentGroup { |
71 | | public: |
72 | | |
73 | | static OptionalContentGroup *parse(Ref *refA, Object *obj); |
74 | | ~OptionalContentGroup(); |
75 | | |
76 | | GBool matches(Ref *refA); |
77 | | |
78 | | Unicode *getName(); |
79 | | int getNameLength(); |
80 | 24 | OCUsageState getViewState() { return viewState; } |
81 | 0 | OCUsageState getPrintState() { return printState; } |
82 | 0 | GBool getState() { return state; } |
83 | 221 | void setState(GBool stateA) { state = stateA; } |
84 | 369 | GBool getInViewUsageAppDict() { return inViewUsageAppDict; } |
85 | 24 | void setInViewUsageAppDict() { inViewUsageAppDict = gTrue; } |
86 | | |
87 | | private: |
88 | | |
89 | | OptionalContentGroup(Ref *refA, TextString *nameA, |
90 | | OCUsageState viewStateA, OCUsageState printStateA); |
91 | | |
92 | | Ref ref; |
93 | | TextString *name; |
94 | | OCUsageState viewState, // suggested state when viewing |
95 | | printState; // suggested state when printing |
96 | | GBool state; // current state (on/off) |
97 | | GBool inViewUsageAppDict; // true if this OCG is listed in a |
98 | | // usage app dict with Event=View |
99 | | |
100 | | friend class OCDisplayNode; |
101 | | }; |
102 | | |
103 | | //------------------------------------------------------------------------ |
104 | | |
105 | | class OCDisplayNode { |
106 | | public: |
107 | | |
108 | | static OCDisplayNode *parse(Object *obj, OptionalContent *oc, XRef *xref, |
109 | | int recursion = 0); |
110 | | OCDisplayNode(); |
111 | | ~OCDisplayNode(); |
112 | | |
113 | | Unicode *getName(); |
114 | | int getNameLength(); |
115 | 0 | OptionalContentGroup *getOCG() { return ocg; } |
116 | | int getNumChildren(); |
117 | | OCDisplayNode *getChild(int idx); |
118 | 0 | OCDisplayNode *getParent() { return parent; } |
119 | | |
120 | | private: |
121 | | |
122 | | OCDisplayNode(GString *nameA); |
123 | | OCDisplayNode(OptionalContentGroup *ocgA); |
124 | | void addChild(OCDisplayNode *child); |
125 | | void addChildren(GList *childrenA); |
126 | | GList *takeChildren(); |
127 | | |
128 | | TextString *name; // display name |
129 | | OptionalContentGroup *ocg; // NULL for display labels |
130 | | OCDisplayNode *parent; // parent node; NULL at root |
131 | | GList *children; // NULL if there are no children |
132 | | // [OCDisplayNode] |
133 | | }; |
134 | | |
135 | | #endif |