• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2017 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_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 
16 class CPDF_Dictionary;
17 class CPDF_Object;
18 class CPDF_StructElement;
19 class CPDF_StructTree;
20 
21 class CPDF_StructKid {
22  public:
23   enum Type { kInvalid, kElement, kPageContent, kStreamContent, kObject };
24 
25   CPDF_StructKid();
26   CPDF_StructKid(const CPDF_StructKid& that);
27   ~CPDF_StructKid();
28 
29   Type m_Type = kInvalid;
30   uint32_t m_PageObjNum = 0;  // For {PageContent, StreamContent, Object} types.
31   uint32_t m_RefObjNum = 0;   // For {StreamContent, Object} types.
32   uint32_t m_ContentId = 0;   // For {PageContent, StreamContent} types.
33   RetainPtr<CPDF_StructElement> m_pElement;  // For Element.
34   RetainPtr<const CPDF_Dictionary> m_pDict;  // For Element.
35 };
36 
37 class CPDF_StructElement final : public Retainable {
38  public:
39   template <typename T, typename... Args>
40   friend RetainPtr<T> pdfium::MakeRetain(Args&&... args);
41 
GetType()42   ByteString GetType() const { return m_Type; }
43   WideString GetAltText() const;
44   WideString GetTitle() const;
45 
46   // Never returns nullptr.
GetDict()47   const CPDF_Dictionary* GetDict() const { return m_pDict.Get(); }
48 
49   size_t CountKids() const;
50   CPDF_StructElement* GetKidIfElement(size_t index) const;
GetKids()51   std::vector<CPDF_StructKid>* GetKids() { return &m_Kids; }
52 
53  private:
54   CPDF_StructElement(CPDF_StructTree* pTree,
55                      CPDF_StructElement* pParent,
56                      const CPDF_Dictionary* pDict);
57   ~CPDF_StructElement() override;
58 
59   void LoadKids(const CPDF_Dictionary* pDict);
60   void LoadKid(uint32_t PageObjNum,
61                const CPDF_Object* pKidObj,
62                CPDF_StructKid* pKid);
63 
64   UnownedPtr<CPDF_StructTree> const m_pTree;
65   UnownedPtr<CPDF_StructElement> const m_pParent;
66   RetainPtr<const CPDF_Dictionary> const m_pDict;
67   const ByteString m_Type;
68   std::vector<CPDF_StructKid> m_Kids;
69 };
70 
71 #endif  // CORE_FPDFDOC_CPDF_STRUCTELEMENT_H_
72