xref: /aosp_15_r20/external/pdfium/core/fpdfdoc/cpdf_structelement.h (revision 3ac0a46f773bac49fa9476ec2b1cf3f8da5ec3a4)
1 // Copyright 2017 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_STRUCTELEMENT_H_
8 #define CORE_FPDFDOC_CPDF_STRUCTELEMENT_H_
9 
10 #include <vector>
11 
12 #include "core/fxcrt/fx_string.h"
13 #include "core/fxcrt/retain_ptr.h"
14 #include "core/fxcrt/unowned_ptr.h"
15 #include "third_party/abseil-cpp/absl/types/optional.h"
16 
17 class CPDF_Dictionary;
18 class CPDF_Object;
19 class CPDF_StructTree;
20 
21 class CPDF_StructElement final : public Retainable {
22  public:
23   CONSTRUCT_VIA_MAKE_RETAIN;
24 
GetType()25   ByteString GetType() const { return m_Type; }
26   ByteString GetObjType() const;
27   WideString GetAltText() const;
28   WideString GetActualText() const;
29   WideString GetTitle() const;
30   absl::optional<WideString> GetID() const;
31   absl::optional<WideString> GetLang() const;
32   RetainPtr<const CPDF_Object> GetA() const;
33   RetainPtr<const CPDF_Object> GetK() const;
34 
35   size_t CountKids() const;
36   CPDF_StructElement* GetKidIfElement(size_t index) const;
37   bool UpdateKidIfElement(const CPDF_Dictionary* pDict,
38                           CPDF_StructElement* pElement);
39 
GetParent()40   CPDF_StructElement* GetParent() const { return m_pParentElement; }
SetParent(CPDF_StructElement * pParentElement)41   void SetParent(CPDF_StructElement* pParentElement) {
42     m_pParentElement = pParentElement;
43   }
44 
45  private:
46   struct Kid {
47     enum Type { kInvalid, kElement, kPageContent, kStreamContent, kObject };
48 
49     Kid();
50     Kid(const Kid& that);
51     ~Kid();
52 
53     Type m_Type = kInvalid;
54     uint32_t m_PageObjNum = 0;  // For {PageContent, StreamContent, Object}.
55     uint32_t m_RefObjNum = 0;   // For {StreamContent, Object} types.
56     uint32_t m_ContentId = 0;   // For {PageContent, StreamContent} types.
57     RetainPtr<CPDF_StructElement> m_pElement;  // For Element type.
58     RetainPtr<const CPDF_Dictionary> m_pDict;  // For Element type.
59   };
60 
61   CPDF_StructElement(const CPDF_StructTree* pTree,
62                      RetainPtr<const CPDF_Dictionary> pDict);
63   ~CPDF_StructElement() override;
64 
65   void LoadKids();
66   void LoadKid(uint32_t page_obj_num,
67                RetainPtr<const CPDF_Object> pKidObj,
68                Kid& kid);
69 
70   UnownedPtr<const CPDF_StructTree> const m_pTree;
71   RetainPtr<const CPDF_Dictionary> const m_pDict;
72   UnownedPtr<CPDF_StructElement> m_pParentElement;
73   const ByteString m_Type;
74   std::vector<Kid> m_Kids;
75 };
76 
77 #endif  // CORE_FPDFDOC_CPDF_STRUCTELEMENT_H_
78