diff options
author | tsepez <tsepez@chromium.org> | 2016-05-17 12:08:20 -0700 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2016-05-17 12:08:20 -0700 |
commit | 61a4544a812813922493e00a5fed4ca775498329 (patch) | |
tree | f57fc4813273ce66c7e230af7107a4292a31a62b /core | |
parent | 935d8d5dcbf1da2b3198675428cbf7ca0406788f (diff) | |
download | pdfium-61a4544a812813922493e00a5fed4ca775498329.tar.xz |
Rename CPDF_Struct{Element,Tree} to IPDF_
After all, what good is a naming convention unless you're going
to blindly adhere to it?
Review-Url: https://codereview.chromium.org/1981403002
Diffstat (limited to 'core')
-rw-r--r-- | core/fpdfdoc/doc_tagged.cpp | 71 | ||||
-rw-r--r-- | core/fpdfdoc/include/fpdf_tagged.h | 39 | ||||
-rw-r--r-- | core/fpdfdoc/tagged_int.h | 30 |
3 files changed, 72 insertions, 68 deletions
diff --git a/core/fpdfdoc/doc_tagged.cpp b/core/fpdfdoc/doc_tagged.cpp index 2eca698614..cfa9e4663c 100644 --- a/core/fpdfdoc/doc_tagged.cpp +++ b/core/fpdfdoc/doc_tagged.cpp @@ -15,43 +15,59 @@ #include "core/fpdfdoc/include/fpdf_tagged.h" #include "core/fpdfdoc/tagged_int.h" +namespace { + const int nMaxRecursion = 32; -static FX_BOOL IsTagged(const CPDF_Document* pDoc) { + +bool IsTagged(const CPDF_Document* pDoc) { CPDF_Dictionary* pCatalog = pDoc->GetRoot(); CPDF_Dictionary* pMarkInfo = pCatalog->GetDictBy("MarkInfo"); return pMarkInfo && pMarkInfo->GetIntegerBy("Marked"); } -CPDF_StructTree* CPDF_StructTree::LoadPage(const CPDF_Document* pDoc, + +} // namespace + +// static +IPDF_StructTree* IPDF_StructTree::LoadPage(const CPDF_Document* pDoc, const CPDF_Dictionary* pPageDict) { - if (!IsTagged(pDoc)) { - return NULL; - } + if (!IsTagged(pDoc)) + return nullptr; + CPDF_StructTreeImpl* pTree = new CPDF_StructTreeImpl(pDoc); pTree->LoadPageTree(pPageDict); return pTree; } -CPDF_StructTree* CPDF_StructTree::LoadDoc(const CPDF_Document* pDoc) { - if (!IsTagged(pDoc)) { - return NULL; - } + +// static. +IPDF_StructTree* IPDF_StructTree::LoadDoc(const CPDF_Document* pDoc) { + if (!IsTagged(pDoc)) + return nullptr; + CPDF_StructTreeImpl* pTree = new CPDF_StructTreeImpl(pDoc); pTree->LoadDocTree(); return pTree; } -CPDF_StructTreeImpl::CPDF_StructTreeImpl(const CPDF_Document* pDoc) { - CPDF_Dictionary* pCatalog = pDoc->GetRoot(); - m_pTreeRoot = pCatalog->GetDictBy("StructTreeRoot"); - if (!m_pTreeRoot) { - return; - } - m_pRoleMap = m_pTreeRoot->GetDictBy("RoleMap"); -} + +CPDF_StructTreeImpl::CPDF_StructTreeImpl(const CPDF_Document* pDoc) + : m_pTreeRoot(pDoc->GetRoot()->GetDictBy("StructTreeRoot")), + m_pRoleMap(m_pTreeRoot ? m_pTreeRoot->GetDictBy("RoleMap") : nullptr), + m_pPage(nullptr) {} + CPDF_StructTreeImpl::~CPDF_StructTreeImpl() { - for (int i = 0; i < m_Kids.GetSize(); i++) - if (m_Kids[i]) { + for (int i = 0; i < m_Kids.GetSize(); i++) { + if (m_Kids[i]) m_Kids[i]->Release(); - } + } } + +int CPDF_StructTreeImpl::CountTopElements() const { + return m_Kids.GetSize(); +} + +IPDF_StructElement* CPDF_StructTreeImpl::GetTopElement(int i) const { + return m_Kids.GetAt(i); +} + void CPDF_StructTreeImpl::LoadDocTree() { m_pPage = nullptr; if (!m_pTreeRoot) @@ -197,22 +213,23 @@ FX_BOOL CPDF_StructTreeImpl::AddTopLevelNode(CPDF_Dictionary* pDict, } return TRUE; } + CPDF_StructElementImpl::CPDF_StructElementImpl(CPDF_StructTreeImpl* pTree, CPDF_StructElementImpl* pParent, CPDF_Dictionary* pDict) - : m_RefCount(0) { - m_pTree = pTree; - m_pDict = pDict; - m_Type = pDict->GetStringBy("S"); + : m_RefCount(0), + m_pTree(pTree), + m_pParent(pParent), + m_pDict(pDict), + m_Type(pDict->GetStringBy("S")) { if (pTree->m_pRoleMap) { CFX_ByteString mapped = pTree->m_pRoleMap->GetStringBy(m_Type); - if (!mapped.IsEmpty()) { + if (!mapped.IsEmpty()) m_Type = mapped; - } } - m_pParent = pParent; LoadKids(pDict); } + CPDF_StructElementImpl::~CPDF_StructElementImpl() { for (int i = 0; i < m_Kids.GetSize(); i++) { if (m_Kids[i].m_Type == CPDF_StructKid::Element && diff --git a/core/fpdfdoc/include/fpdf_tagged.h b/core/fpdfdoc/include/fpdf_tagged.h index 807f178229..43d69e8db9 100644 --- a/core/fpdfdoc/include/fpdf_tagged.h +++ b/core/fpdfdoc/include/fpdf_tagged.h @@ -9,66 +9,55 @@ #include "core/fxge/include/fx_dib.h" +class CPDF_Dictionary; class CPDF_Document; -class CPDF_StructElement; -class CPDF_StructTree; -struct CPDF_StructKid; +class IPDF_StructElement; -class CPDF_StructTree { +class IPDF_StructTree { public: - static CPDF_StructTree* LoadDoc(const CPDF_Document* pDoc); - - static CPDF_StructTree* LoadPage(const CPDF_Document* pDoc, + static IPDF_StructTree* LoadDoc(const CPDF_Document* pDoc); + static IPDF_StructTree* LoadPage(const CPDF_Document* pDoc, const CPDF_Dictionary* pPageDict); - virtual ~CPDF_StructTree() {} + virtual ~IPDF_StructTree() {} virtual int CountTopElements() const = 0; - - virtual CPDF_StructElement* GetTopElement(int i) const = 0; + virtual IPDF_StructElement* GetTopElement(int i) const = 0; }; + struct CPDF_StructKid { enum { Invalid, Element, PageContent, StreamContent, Object } m_Type; union { struct { - CPDF_StructElement* m_pElement; - + IPDF_StructElement* m_pElement; CPDF_Dictionary* m_pDict; } m_Element; struct { uint32_t m_PageObjNum; - uint32_t m_ContentId; } m_PageContent; struct { uint32_t m_PageObjNum; - uint32_t m_ContentId; - uint32_t m_RefObjNum; } m_StreamContent; struct { uint32_t m_PageObjNum; - uint32_t m_RefObjNum; } m_Object; }; }; -class CPDF_StructElement { - public: - virtual ~CPDF_StructElement() {} - virtual CPDF_StructTree* GetTree() const = 0; +class IPDF_StructElement { + public: + virtual ~IPDF_StructElement() {} + virtual IPDF_StructTree* GetTree() const = 0; virtual const CFX_ByteString& GetType() const = 0; - - virtual CPDF_StructElement* GetParent() const = 0; - + virtual IPDF_StructElement* GetParent() const = 0; virtual CPDF_Dictionary* GetDict() const = 0; - virtual int CountKids() const = 0; - virtual const CPDF_StructKid& GetKid(int index) const = 0; virtual CPDF_Object* GetAttr(const CFX_ByteStringC& owner, diff --git a/core/fpdfdoc/tagged_int.h b/core/fpdfdoc/tagged_int.h index f6e845a7af..7b9a32fa84 100644 --- a/core/fpdfdoc/tagged_int.h +++ b/core/fpdfdoc/tagged_int.h @@ -13,16 +13,14 @@ class CPDF_StructElementImpl; -class CPDF_StructTreeImpl : public CPDF_StructTree { +class CPDF_StructTreeImpl final : public IPDF_StructTree { public: explicit CPDF_StructTreeImpl(const CPDF_Document* pDoc); ~CPDF_StructTreeImpl() override; - // CPDF_StructTree - int CountTopElements() const override { return m_Kids.GetSize(); } - CPDF_StructElement* GetTopElement(int i) const override { - return (CPDF_StructElement*)m_Kids.GetAt(i); - } + // IPDF_StructTree: + int CountTopElements() const override; + IPDF_StructElement* GetTopElement(int i) const override; void LoadDocTree(); void LoadPageTree(const CPDF_Dictionary* pPageDict); @@ -34,23 +32,23 @@ class CPDF_StructTreeImpl : public CPDF_StructTree { CPDF_StructElementImpl* pElement); protected: - const CPDF_Dictionary* m_pTreeRoot; - const CPDF_Dictionary* m_pRoleMap; + const CPDF_Dictionary* const m_pTreeRoot; + const CPDF_Dictionary* const m_pRoleMap; const CPDF_Dictionary* m_pPage; CFX_ArrayTemplate<CPDF_StructElementImpl*> m_Kids; friend class CPDF_StructElementImpl; }; -class CPDF_StructElementImpl final : public CPDF_StructElement { +class CPDF_StructElementImpl final : public IPDF_StructElement { public: CPDF_StructElementImpl(CPDF_StructTreeImpl* pTree, CPDF_StructElementImpl* pParent, CPDF_Dictionary* pDict); - // CPDF_StructTreeImpl - CPDF_StructTree* GetTree() const override { return m_pTree; } + // IPDF_StructElement: + IPDF_StructTree* GetTree() const override { return m_pTree; } const CFX_ByteString& GetType() const override { return m_Type; } - CPDF_StructElement* GetParent() const override { return m_pParent; } + IPDF_StructElement* GetParent() const override { return m_pParent; } CPDF_Dictionary* GetDict() const override { return m_pDict; } int CountKids() const override { return m_Kids.GetSize(); } const CPDF_StructKid& GetKid(int index) const override { @@ -93,12 +91,12 @@ class CPDF_StructElementImpl final : public CPDF_StructElement { protected: ~CPDF_StructElementImpl() override; - CPDF_StructTreeImpl* m_pTree; + int m_RefCount; + CPDF_StructTreeImpl* const m_pTree; + CPDF_StructElementImpl* const m_pParent; + CPDF_Dictionary* const m_pDict; CFX_ByteString m_Type; - CPDF_StructElementImpl* m_pParent; - CPDF_Dictionary* m_pDict; CFX_ArrayTemplate<CPDF_StructKid> m_Kids; - int m_RefCount; friend class CPDF_StructTreeImpl; }; |