xref: /aosp_15_r20/external/pdfium/core/fpdfapi/page/cpdf_occontext.h (revision 3ac0a46f773bac49fa9476ec2b1cf3f8da5ec3a4)
1 // Copyright 2016 The PDFium Authors
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 <functional>
11 #include <map>
12 
13 #include "core/fxcrt/bytestring.h"
14 #include "core/fxcrt/retain_ptr.h"
15 #include "core/fxcrt/unowned_ptr.h"
16 
17 class CPDF_Array;
18 class CPDF_Dictionary;
19 class CPDF_Document;
20 class CPDF_PageObject;
21 
22 class CPDF_OCContext final : public Retainable {
23  public:
24   enum UsageType { kView = 0, kDesign, kPrint, kExport };
25 
26   CONSTRUCT_VIA_MAKE_RETAIN;
27 
28   bool CheckOCGDictVisible(const CPDF_Dictionary* pOCGDict) const;
29   bool CheckPageObjectVisible(const CPDF_PageObject* pObj) const;
30 
31  private:
32   CPDF_OCContext(CPDF_Document* pDoc, UsageType eUsageType);
33   ~CPDF_OCContext() override;
34 
35   bool LoadOCGStateFromConfig(const ByteString& csConfig,
36                               const CPDF_Dictionary* pOCGDict) const;
37   bool LoadOCGState(const CPDF_Dictionary* pOCGDict) const;
38   bool GetOCGVisible(const CPDF_Dictionary* pOCGDict) const;
39   bool GetOCGVE(const CPDF_Array* pExpression, int nLevel) const;
40   bool LoadOCMDState(const CPDF_Dictionary* pOCMDDict) const;
41 
42   UnownedPtr<CPDF_Document> const m_pDocument;
43   const UsageType m_eUsageType;
44   mutable std::map<RetainPtr<const CPDF_Dictionary>, bool, std::less<>>
45       m_OGCStateCache;
46 };
47 
48 #endif  // CORE_FPDFAPI_PAGE_CPDF_OCCONTEXT_H_
49