1 | //======================================================================== |
2 | // |
3 | // OptionalContent.h |
4 | // |
5 | // Copyright 2007 Brad Hards <bradh@kde.org> |
6 | // Copyright 2008 Carlos Garcia Campos <carlosgc@gnome.org> |
7 | // Copyright 2013, 2018, 2019, 2021 Albert Astals Cid <aacid@kde.org> |
8 | // Copyright 2018 Adam Reichold <adam.reichold@t-online.de> |
9 | // Copyright 2019 Oliver Sander <oliver.sander@tu-dresden.de> |
10 | // |
11 | // Released under the GPL (version 2, or later, at your option) |
12 | // |
13 | //======================================================================== |
14 | |
15 | #ifndef OPTIONALCONTENT_H |
16 | #define OPTIONALCONTENT_H |
17 | |
18 | #include "Object.h" |
19 | #include "CharTypes.h" |
20 | #include "poppler_private_export.h" |
21 | #include <unordered_map> |
22 | #include <memory> |
23 | |
24 | class GooString; |
25 | class XRef; |
26 | |
27 | class OptionalContentGroup; |
28 | |
29 | //------------------------------------------------------------------------ |
30 | |
31 | class POPPLER_PRIVATE_EXPORT OCGs |
32 | { |
33 | public: |
34 | OCGs(Object *ocgObject, XRef *xref); |
35 | |
36 | OCGs(const OCGs &) = delete; |
37 | OCGs &operator=(const OCGs &) = delete; |
38 | |
39 | // Is OCGS valid? |
40 | bool isOk() const { return ok; } |
41 | |
42 | bool hasOCGs() const; |
43 | const std::unordered_map<Ref, std::unique_ptr<OptionalContentGroup>> &getOCGs() const { return optionalContentGroups; } |
44 | |
45 | OptionalContentGroup *findOcgByRef(const Ref ref); |
46 | |
47 | Array *getOrderArray() { return (order.isArray() && order.arrayGetLength() > 0) ? order.getArray() : nullptr; } |
48 | Array *getRBGroupsArray() { return (rbgroups.isArray() && rbgroups.arrayGetLength()) ? rbgroups.getArray() : nullptr; } |
49 | |
50 | bool optContentIsVisible(const Object *dictRef); |
51 | |
52 | private: |
53 | bool ok; |
54 | |
55 | bool evalOCVisibilityExpr(const Object *expr, int recursion); |
56 | bool allOn(Array *ocgArray); |
57 | bool allOff(Array *ocgArray); |
58 | bool anyOn(Array *ocgArray); |
59 | bool anyOff(Array *ocgArray); |
60 | |
61 | std::unordered_map<Ref, std::unique_ptr<OptionalContentGroup>> optionalContentGroups; |
62 | |
63 | Object order; |
64 | Object rbgroups; |
65 | XRef *m_xref; |
66 | }; |
67 | |
68 | //------------------------------------------------------------------------ |
69 | |
70 | class POPPLER_PRIVATE_EXPORT OptionalContentGroup |
71 | { |
72 | public: |
73 | enum State |
74 | { |
75 | On, |
76 | Off |
77 | }; |
78 | |
79 | // Values from the optional content usage dictionary. |
80 | enum UsageState |
81 | { |
82 | ocUsageOn, |
83 | ocUsageOff, |
84 | ocUsageUnset |
85 | }; |
86 | |
87 | explicit OptionalContentGroup(Dict *dict); |
88 | |
89 | explicit OptionalContentGroup(GooString *label); |
90 | |
91 | ~OptionalContentGroup(); |
92 | |
93 | OptionalContentGroup(const OptionalContentGroup &) = delete; |
94 | OptionalContentGroup &operator=(const OptionalContentGroup &) = delete; |
95 | |
96 | const GooString *getName() const; |
97 | |
98 | Ref getRef() const; |
99 | void setRef(const Ref ref); |
100 | |
101 | State getState() const { return m_state; }; |
102 | void setState(State state) { m_state = state; }; |
103 | |
104 | UsageState getViewState() const { return viewState; } |
105 | UsageState getPrintState() const { return printState; } |
106 | |
107 | private: |
108 | GooString *m_name; |
109 | Ref m_ref; |
110 | State m_state; |
111 | UsageState viewState; // suggested state when viewing |
112 | UsageState printState; // suggested state when printing |
113 | }; |
114 | |
115 | //------------------------------------------------------------------------ |
116 | |
117 | #endif |
118 | |