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 <optional> 11 #include <vector> 12 13 #include "core/fxcrt/fx_string.h" 14 #include "core/fxcrt/retain_ptr.h" 15 #include "core/fxcrt/unowned_ptr.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 std::optional<WideString> GetID() const; 31 std::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 int GetKidContentId(size_t index) const; 38 bool UpdateKidIfElement(const CPDF_Dictionary* pDict, 39 CPDF_StructElement* pElement); 40 GetParent()41 CPDF_StructElement* GetParent() const { return m_pParentElement; } SetParent(CPDF_StructElement * pParentElement)42 void SetParent(CPDF_StructElement* pParentElement) { 43 m_pParentElement = pParentElement; 44 } 45 46 private: 47 struct Kid { 48 enum Type { kInvalid, kElement, kPageContent, kStreamContent, kObject }; 49 50 Kid(); 51 Kid(const Kid& that); 52 ~Kid(); 53 54 Type m_Type = kInvalid; 55 uint32_t m_PageObjNum = 0; // For {PageContent, StreamContent, Object}. 56 uint32_t m_RefObjNum = 0; // For {StreamContent, Object} types. 57 uint32_t m_ContentId = 0; // For {PageContent, StreamContent} types. 58 RetainPtr<CPDF_StructElement> m_pElement; // For Element type. 59 RetainPtr<const CPDF_Dictionary> m_pDict; // For Element type. 60 }; 61 62 CPDF_StructElement(const CPDF_StructTree* pTree, 63 RetainPtr<const CPDF_Dictionary> pDict); 64 ~CPDF_StructElement() override; 65 66 void LoadKids(); 67 void LoadKid(uint32_t page_obj_num, 68 RetainPtr<const CPDF_Object> pKidObj, 69 Kid& kid); 70 71 UnownedPtr<const CPDF_StructTree> const m_pTree; 72 RetainPtr<const CPDF_Dictionary> const m_pDict; 73 UnownedPtr<CPDF_StructElement> m_pParentElement; 74 const ByteString m_Type; 75 std::vector<Kid> m_Kids; 76 }; 77 78 #endif // CORE_FPDFDOC_CPDF_STRUCTELEMENT_H_ 79