1 // Copyright 2016 PDFium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com
6 
7 #ifndef CORE_FPDFAPI_PAGE_CPDF_OCCONTEXT_H_
8 #define CORE_FPDFAPI_PAGE_CPDF_OCCONTEXT_H_
9 
10 #include <map>
11 
12 #include "core/fxcrt/fx_string.h"
13 #include "core/fxcrt/retain_ptr.h"
14 
15 class CPDF_Array;
16 class CPDF_Dictionary;
17 class CPDF_Document;
18 class CPDF_PageObject;
19 
20 class CPDF_OCContext final : public Retainable {
21  public:
22   enum UsageType { View = 0, Design, Print, Export };
23 
24   template <typename T, typename... Args>
25   friend RetainPtr<T> pdfium::MakeRetain(Args&&... args);
26 
27   bool CheckOCGVisible(const CPDF_Dictionary* pOCGDict) const;
28   bool CheckObjectVisible(const CPDF_PageObject* pObj) const;
29 
30  private:
31   CPDF_OCContext(CPDF_Document* pDoc, UsageType eUsageType);
32   ~CPDF_OCContext() override;
33 
34   bool LoadOCGStateFromConfig(const ByteString& csConfig,
35                               const CPDF_Dictionary* pOCGDict) const;
36   bool LoadOCGState(const CPDF_Dictionary* pOCGDict) const;
37   bool GetOCGVisible(const CPDF_Dictionary* pOCGDict) const;
38   bool GetOCGVE(const CPDF_Array* pExpression, int nLevel) const;
39   bool LoadOCMDState(const CPDF_Dictionary* pOCMDDict) const;
40 
41   UnownedPtr<CPDF_Document> const m_pDocument;
42   const UsageType m_eUsageType;
43   mutable std::map<const CPDF_Dictionary*, bool> m_OGCStateCache;
44 };
45 
46 #endif  // CORE_FPDFAPI_PAGE_CPDF_OCCONTEXT_H_
47