xref: /aosp_15_r20/external/pdfium/core/fpdfdoc/cpdf_nametree.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_FPDFDOC_CPDF_NAMETREE_H_
8 #define CORE_FPDFDOC_CPDF_NAMETREE_H_
9 
10 #include <stddef.h>
11 
12 #include <memory>
13 
14 #include "core/fxcrt/fx_string.h"
15 #include "core/fxcrt/retain_ptr.h"
16 
17 class CPDF_Array;
18 class CPDF_Dictionary;
19 class CPDF_Document;
20 class CPDF_Object;
21 
22 class CPDF_NameTree {
23  public:
24   CPDF_NameTree(const CPDF_NameTree&) = delete;
25   CPDF_NameTree& operator=(const CPDF_NameTree&) = delete;
26   ~CPDF_NameTree();
27 
28   static std::unique_ptr<CPDF_NameTree> Create(CPDF_Document* pDoc,
29                                                const ByteString& category);
30 
31   // If necessary, create missing Names dictionary in |pDoc|, and/or missing
32   // Names array in the dictionary that corresponds to |category|, if necessary.
33   // Returns nullptr on failure.
34   static std::unique_ptr<CPDF_NameTree> CreateWithRootNameArray(
35       CPDF_Document* pDoc,
36       const ByteString& category);
37 
38   static std::unique_ptr<CPDF_NameTree> CreateForTesting(
39       CPDF_Dictionary* pRoot);
40 
41   static RetainPtr<const CPDF_Array> LookupNamedDest(CPDF_Document* doc,
42                                                      const ByteString& name);
43 
44   bool AddValueAndName(RetainPtr<CPDF_Object> pObj, const WideString& name);
45   bool DeleteValueAndName(size_t nIndex);
46 
47   RetainPtr<CPDF_Object> LookupValueAndName(size_t nIndex,
48                                             WideString* csName) const;
49   RetainPtr<const CPDF_Object> LookupValue(const WideString& csName) const;
50 
51   size_t GetCount() const;
GetRootForTesting()52   CPDF_Dictionary* GetRootForTesting() const { return m_pRoot.Get(); }
53 
54  private:
55   explicit CPDF_NameTree(RetainPtr<CPDF_Dictionary> pRoot);
56 
57   RetainPtr<const CPDF_Array> LookupNewStyleNamedDest(const ByteString& name);
58 
59   RetainPtr<CPDF_Dictionary> const m_pRoot;
60 };
61 
62 #endif  // CORE_FPDFDOC_CPDF_NAMETREE_H_
63