From deff61fe7368c2db41d31accb45291dd41bacd4f Mon Sep 17 00:00:00 2001 From: dan sinclair Date: Thu, 6 Apr 2017 13:42:13 -0400 Subject: Cleanup tagged code. MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This Cl removes a bunch of unused tagged code. Some of this will need to come back in the future (like the attr code) but we can add it back with tests when needed. Bug: pdfium:672 Change-Id: I7aaed79963910b336f42ce665790408038c39ba4 Reviewed-on: https://pdfium-review.googlesource.com/3830 Reviewed-by: Tom Sepez Reviewed-by: Nicolás Peña Commit-Queue: dsinclair --- core/fpdfdoc/cpdf_structelement.cpp | 134 ------------------------------------ core/fpdfdoc/cpdf_structelement.h | 36 +--------- core/fpdfdoc/cpdf_structtree.cpp | 2 +- core/fpdfdoc/cpdf_structtree.h | 11 ++- 4 files changed, 9 insertions(+), 174 deletions(-) diff --git a/core/fpdfdoc/cpdf_structelement.cpp b/core/fpdfdoc/cpdf_structelement.cpp index 418f75b3a9..137d5b32e4 100644 --- a/core/fpdfdoc/cpdf_structelement.cpp +++ b/core/fpdfdoc/cpdf_structelement.cpp @@ -16,38 +16,6 @@ #include "core/fpdfdoc/cpdf_structtree.h" #include "third_party/base/stl_util.h" -namespace { - -const int nMaxRecursion = 32; - -CPDF_Dictionary* FindAttrDict(CPDF_Object* pAttrs, - const CFX_ByteStringC& owner, - float nLevel = 0.0F) { - if (nLevel > nMaxRecursion) - return nullptr; - if (!pAttrs) - return nullptr; - - CPDF_Dictionary* pDict = nullptr; - if (pAttrs->IsDictionary()) { - pDict = pAttrs->AsDictionary(); - } else if (CPDF_Stream* pStream = pAttrs->AsStream()) { - pDict = pStream->GetDict(); - } else if (CPDF_Array* pArray = pAttrs->AsArray()) { - for (uint32_t i = 0; i < pArray->GetCount(); i++) { - CPDF_Object* pElement = pArray->GetDirectObjectAt(i); - pDict = FindAttrDict(pElement, owner, nLevel + 1); - if (pDict) - return pDict; - } - } - if (pDict && pDict->GetStringFor("O") == owner) - return pDict; - return nullptr; -} - -} // namespace - CPDF_StructKid::CPDF_StructKid() : m_Type(Invalid), m_pDict(nullptr), @@ -166,105 +134,3 @@ void CPDF_StructElement::LoadKid(uint32_t PageObjNum, pKid->m_pElement = pdfium::MakeRetain(m_pTree, this, pKidDict); } - -CPDF_Object* CPDF_StructElement::GetAttr(const CFX_ByteStringC& owner, - const CFX_ByteStringC& name, - bool bInheritable, - float fLevel) { - if (fLevel > nMaxRecursion) - return nullptr; - - if (bInheritable) { - if (CPDF_Object* pAttr = GetAttr(owner, name, false)) - return pAttr; - if (!m_pParent) - return nullptr; - return m_pParent->GetAttr(owner, name, true, fLevel + 1); - } - - if (CPDF_Object* pA = m_pDict->GetDirectObjectFor("A")) { - if (CPDF_Dictionary* dict = FindAttrDict(pA, owner)) { - if (CPDF_Object* attr = dict->GetDirectObjectFor(CFX_ByteString(name))) - return attr; - } - } - - CPDF_Object* pC = m_pDict->GetDirectObjectFor("C"); - if (!pC) - return nullptr; - - CPDF_Dictionary* pClassMap = m_pTree->GetTreeRoot()->GetDictFor("ClassMap"); - if (!pClassMap) - return nullptr; - - if (CPDF_Array* pArray = pC->AsArray()) { - for (uint32_t i = 0; i < pArray->GetCount(); i++) { - CFX_ByteString class_name = pArray->GetStringAt(i); - CPDF_Dictionary* pClassDict = pClassMap->GetDictFor(class_name); - if (pClassDict && pClassDict->GetStringFor("O") == owner) - return pClassDict->GetDirectObjectFor(CFX_ByteString(name)); - } - return nullptr; - } - - CFX_ByteString class_name = pC->GetString(); - CPDF_Dictionary* pClassDict = pClassMap->GetDictFor(class_name); - if (pClassDict && pClassDict->GetStringFor("O") == owner) - return pClassDict->GetDirectObjectFor(CFX_ByteString(name)); - return nullptr; -} - -CPDF_Object* CPDF_StructElement::GetAttr(const CFX_ByteStringC& owner, - const CFX_ByteStringC& name, - bool bInheritable, - int subindex) { - CPDF_Object* pAttr = GetAttr(owner, name, bInheritable); - CPDF_Array* pArray = ToArray(pAttr); - if (!pArray || subindex == -1) - return pAttr; - if (subindex >= static_cast(pArray->GetCount())) - return pAttr; - return pArray->GetDirectObjectAt(subindex); -} - -CFX_ByteString CPDF_StructElement::GetName(const CFX_ByteStringC& owner, - const CFX_ByteStringC& name, - const CFX_ByteStringC& default_value, - bool bInheritable, - int subindex) { - CPDF_Object* pAttr = GetAttr(owner, name, bInheritable, subindex); - if (ToName(pAttr)) - return pAttr->GetString(); - return CFX_ByteString(default_value); -} - -FX_ARGB CPDF_StructElement::GetColor(const CFX_ByteStringC& owner, - const CFX_ByteStringC& name, - FX_ARGB default_value, - bool bInheritable, - int subindex) { - CPDF_Array* pArray = ToArray(GetAttr(owner, name, bInheritable, subindex)); - if (!pArray) - return default_value; - return 0xff000000 | (static_cast(pArray->GetNumberAt(0) * 255) << 16) | - (static_cast(pArray->GetNumberAt(1) * 255) << 8) | - static_cast(pArray->GetNumberAt(2) * 255); -} - -float CPDF_StructElement::GetNumber(const CFX_ByteStringC& owner, - const CFX_ByteStringC& name, - float default_value, - bool bInheritable, - int subindex) { - CPDF_Object* pAttr = GetAttr(owner, name, bInheritable, subindex); - return ToNumber(pAttr) ? pAttr->GetNumber() : default_value; -} - -int CPDF_StructElement::GetInteger(const CFX_ByteStringC& owner, - const CFX_ByteStringC& name, - int default_value, - bool bInheritable, - int subindex) { - CPDF_Object* pAttr = GetAttr(owner, name, bInheritable, subindex); - return ToNumber(pAttr) ? pAttr->GetInteger() : default_value; -} diff --git a/core/fpdfdoc/cpdf_structelement.h b/core/fpdfdoc/cpdf_structelement.h index b227397431..ba0685e895 100644 --- a/core/fpdfdoc/cpdf_structelement.h +++ b/core/fpdfdoc/cpdf_structelement.h @@ -38,45 +38,12 @@ class CPDF_StructElement : public CFX_Retainable { template friend CFX_RetainPtr pdfium::MakeRetain(Args&&... args); - CPDF_StructTree* GetTree() const { return m_pTree; } const CFX_ByteString& GetType() const { return m_Type; } - CPDF_StructElement* GetParent() const { return m_pParent; } CPDF_Dictionary* GetDict() const { return m_pDict; } int CountKids() const; CPDF_StructElement* GetKidIfElement(int index) const; - CPDF_Object* GetAttr(const CFX_ByteStringC& owner, - const CFX_ByteStringC& name, - bool bInheritable = false, - float fLevel = 0.0F); - CFX_ByteString GetName(const CFX_ByteStringC& owner, - const CFX_ByteStringC& name, - const CFX_ByteStringC& default_value, - bool bInheritable = false, - int subindex = -1); - FX_ARGB GetColor(const CFX_ByteStringC& owner, - const CFX_ByteStringC& name, - FX_ARGB default_value, - bool bInheritable = false, - int subindex = -1); - float GetNumber(const CFX_ByteStringC& owner, - const CFX_ByteStringC& name, - float default_value, - bool bInheritable = false, - int subindex = -1); - int GetInteger(const CFX_ByteStringC& owner, - const CFX_ByteStringC& name, - int default_value, - bool bInheritable = false, - int subindex = -1); - std::vector* GetKids() { return &m_Kids; } - void LoadKids(CPDF_Dictionary* pDict); - void LoadKid(uint32_t PageObjNum, CPDF_Object* pObj, CPDF_StructKid* pKid); - CPDF_Object* GetAttr(const CFX_ByteStringC& owner, - const CFX_ByteStringC& name, - bool bInheritable, - int subindex); private: CPDF_StructElement(CPDF_StructTree* pTree, @@ -84,6 +51,9 @@ class CPDF_StructElement : public CFX_Retainable { CPDF_Dictionary* pDict); ~CPDF_StructElement() override; + void LoadKids(CPDF_Dictionary* pDict); + void LoadKid(uint32_t PageObjNum, CPDF_Object* pObj, CPDF_StructKid* pKid); + CPDF_StructTree* const m_pTree; CPDF_StructElement* const m_pParent; CPDF_Dictionary* const m_pDict; diff --git a/core/fpdfdoc/cpdf_structtree.cpp b/core/fpdfdoc/cpdf_structtree.cpp index 51ad2c775c..62500ac155 100644 --- a/core/fpdfdoc/cpdf_structtree.cpp +++ b/core/fpdfdoc/cpdf_structtree.cpp @@ -88,7 +88,7 @@ void CPDF_StructTree::LoadPageTree(const CPDF_Dictionary* pPageDict) { std::map> element_map; for (size_t i = 0; i < pParentArray->GetCount(); i++) { if (CPDF_Dictionary* pParent = pParentArray->GetDictAt(i)) - AddPageNode(pParent, &element_map); + AddPageNode(pParent, &element_map, 0); } } diff --git a/core/fpdfdoc/cpdf_structtree.h b/core/fpdfdoc/cpdf_structtree.h index 20bf41e7ee..aa30f802db 100644 --- a/core/fpdfdoc/cpdf_structtree.h +++ b/core/fpdfdoc/cpdf_structtree.h @@ -28,20 +28,19 @@ class CPDF_StructTree { int CountTopElements() const; CPDF_StructElement* GetTopElement(int i) const; + const CPDF_Dictionary* GetRoleMap() const { return m_pRoleMap; } + const CPDF_Dictionary* GetPage() const { return m_pPage; } + const CPDF_Dictionary* GetTreeRoot() const { return m_pTreeRoot; } + private: void LoadPageTree(const CPDF_Dictionary* pPageDict); CFX_RetainPtr AddPageNode( CPDF_Dictionary* pElement, std::map>* map, - int nLevel = 0); + int nLevel); bool AddTopLevelNode(CPDF_Dictionary* pDict, const CFX_RetainPtr& pElement); - const CPDF_Dictionary* GetRoleMap() const { return m_pRoleMap; } - const CPDF_Dictionary* GetPage() const { return m_pPage; } - const CPDF_Dictionary* GetTreeRoot() const { return m_pTreeRoot; } - - private: const CPDF_Dictionary* const m_pTreeRoot; const CPDF_Dictionary* const m_pRoleMap; const CPDF_Dictionary* m_pPage; -- cgit v1.2.3