From 7f389615a0fca78532482d6f4070d18c5d2f9f5d Mon Sep 17 00:00:00 2001 From: dan sinclair Date: Thu, 6 Apr 2017 13:38:54 -0400 Subject: Cleanup the tagged code MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This CL removes the IPDF_Struct* classes in favour of their only implementation. The tagged code was split out into files matching the classes they contain. The friendship between CPDF_StructTree and CPDF_StructElement was broken in favour of accessors. Bug: pdfium:672 Change-Id: Iade83b608fb7168b3b0f41338d10d5fd8ab91a6e Reviewed-on: https://pdfium-review.googlesource.com/3820 Reviewed-by: Tom Sepez Reviewed-by: Nicolás Peña Commit-Queue: dsinclair --- BUILD.gn | 7 +- core/fpdfdoc/cpdf_structelement.cpp | 270 +++++++++++++++++++++++ core/fpdfdoc/cpdf_structelement.h | 94 ++++++++ core/fpdfdoc/cpdf_structtree.cpp | 155 +++++++++++++ core/fpdfdoc/cpdf_structtree.h | 51 +++++ core/fpdfdoc/doc_tagged.cpp | 418 ------------------------------------ core/fpdfdoc/fpdf_tagged.h | 75 ------- core/fpdfdoc/tagged_int.h | 119 ---------- fpdfsdk/fpdf_structtree.cpp | 27 +-- 9 files changed, 588 insertions(+), 628 deletions(-) create mode 100644 core/fpdfdoc/cpdf_structelement.cpp create mode 100644 core/fpdfdoc/cpdf_structelement.h create mode 100644 core/fpdfdoc/cpdf_structtree.cpp create mode 100644 core/fpdfdoc/cpdf_structtree.h delete mode 100644 core/fpdfdoc/doc_tagged.cpp delete mode 100644 core/fpdfdoc/fpdf_tagged.h delete mode 100644 core/fpdfdoc/tagged_int.h diff --git a/BUILD.gn b/BUILD.gn index 46e020fbb2..67be8cde74 100644 --- a/BUILD.gn +++ b/BUILD.gn @@ -325,6 +325,10 @@ static_library("fpdfdoc") { "core/fpdfdoc/cpdf_occontext.h", "core/fpdfdoc/cpdf_pagelabel.cpp", "core/fpdfdoc/cpdf_pagelabel.h", + "core/fpdfdoc/cpdf_structelement.cpp", + "core/fpdfdoc/cpdf_structelement.h", + "core/fpdfdoc/cpdf_structtree.cpp", + "core/fpdfdoc/cpdf_structtree.h", "core/fpdfdoc/cpdf_variabletext.cpp", "core/fpdfdoc/cpdf_variabletext.h", "core/fpdfdoc/cpdf_viewerpreferences.cpp", @@ -353,11 +357,8 @@ static_library("fpdfdoc") { "core/fpdfdoc/csection.h", "core/fpdfdoc/ctypeset.cpp", "core/fpdfdoc/ctypeset.h", - "core/fpdfdoc/doc_tagged.cpp", - "core/fpdfdoc/fpdf_tagged.h", "core/fpdfdoc/ipdf_formnotify.h", "core/fpdfdoc/ipvt_fontmap.h", - "core/fpdfdoc/tagged_int.h", ] configs += [ ":pdfium_core_config" ] deps = [ diff --git a/core/fpdfdoc/cpdf_structelement.cpp b/core/fpdfdoc/cpdf_structelement.cpp new file mode 100644 index 0000000000..418f75b3a9 --- /dev/null +++ b/core/fpdfdoc/cpdf_structelement.cpp @@ -0,0 +1,270 @@ +// Copyright 2017 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "core/fpdfdoc/cpdf_structelement.h" + +#include "core/fpdfapi/parser/cpdf_array.h" +#include "core/fpdfapi/parser/cpdf_dictionary.h" +#include "core/fpdfapi/parser/cpdf_name.h" +#include "core/fpdfapi/parser/cpdf_number.h" +#include "core/fpdfapi/parser/cpdf_object.h" +#include "core/fpdfapi/parser/cpdf_reference.h" +#include "core/fpdfapi/parser/cpdf_stream.h" +#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), + m_PageObjNum(0), + m_RefObjNum(0), + m_ContentId(0) {} + +CPDF_StructKid::CPDF_StructKid(const CPDF_StructKid& that) = default; + +CPDF_StructKid::~CPDF_StructKid() = default; + +CPDF_StructElement::CPDF_StructElement(CPDF_StructTree* pTree, + CPDF_StructElement* pParent, + CPDF_Dictionary* pDict) + : m_pTree(pTree), + m_pParent(pParent), + m_pDict(pDict), + m_Type(pDict->GetStringFor("S")) { + if (pTree->GetRoleMap()) { + CFX_ByteString mapped = pTree->GetRoleMap()->GetStringFor(m_Type); + if (!mapped.IsEmpty()) + m_Type = mapped; + } + LoadKids(pDict); +} + +CPDF_StructElement::~CPDF_StructElement() = default; + +int CPDF_StructElement::CountKids() const { + return pdfium::CollectionSize(m_Kids); +} + +CPDF_StructElement* CPDF_StructElement::GetKidIfElement(int index) const { + return m_Kids[index].m_Type == CPDF_StructKid::Element + ? m_Kids[index].m_pElement.Get() + : nullptr; +} + +void CPDF_StructElement::LoadKids(CPDF_Dictionary* pDict) { + CPDF_Object* pObj = pDict->GetObjectFor("Pg"); + uint32_t PageObjNum = 0; + if (CPDF_Reference* pRef = ToReference(pObj)) + PageObjNum = pRef->GetRefObjNum(); + + CPDF_Object* pKids = pDict->GetDirectObjectFor("K"); + if (!pKids) + return; + + m_Kids.clear(); + if (CPDF_Array* pArray = pKids->AsArray()) { + m_Kids.resize(pArray->GetCount()); + for (uint32_t i = 0; i < pArray->GetCount(); i++) { + CPDF_Object* pKid = pArray->GetDirectObjectAt(i); + LoadKid(PageObjNum, pKid, &m_Kids[i]); + } + return; + } + + m_Kids.resize(1); + LoadKid(PageObjNum, pKids, &m_Kids[0]); +} + +void CPDF_StructElement::LoadKid(uint32_t PageObjNum, + CPDF_Object* pKidObj, + CPDF_StructKid* pKid) { + pKid->m_Type = CPDF_StructKid::Invalid; + if (!pKidObj) + return; + + if (pKidObj->IsNumber()) { + if (m_pTree->GetPage() && m_pTree->GetPage()->GetObjNum() != PageObjNum) + return; + + pKid->m_Type = CPDF_StructKid::PageContent; + pKid->m_ContentId = pKidObj->GetInteger(); + pKid->m_PageObjNum = PageObjNum; + return; + } + + CPDF_Dictionary* pKidDict = pKidObj->AsDictionary(); + if (!pKidDict) + return; + if (CPDF_Reference* pRef = ToReference(pKidDict->GetObjectFor("Pg"))) + PageObjNum = pRef->GetRefObjNum(); + + CFX_ByteString type = pKidDict->GetStringFor("Type"); + if ((type == "MCR" || type == "OBJR") && m_pTree->GetPage() && + m_pTree->GetPage()->GetObjNum() != PageObjNum) { + return; + } + + if (type == "MCR") { + pKid->m_Type = CPDF_StructKid::StreamContent; + CPDF_Reference* pRef = ToReference(pKidDict->GetObjectFor("Stm")); + pKid->m_RefObjNum = pRef ? pRef->GetRefObjNum() : 0; + pKid->m_PageObjNum = PageObjNum; + pKid->m_ContentId = pKidDict->GetIntegerFor("MCID"); + return; + } + + if (type == "OBJR") { + pKid->m_Type = CPDF_StructKid::Object; + CPDF_Reference* pObj = ToReference(pKidDict->GetObjectFor("Obj")); + pKid->m_RefObjNum = pObj ? pObj->GetRefObjNum() : 0; + pKid->m_PageObjNum = PageObjNum; + return; + } + + pKid->m_Type = CPDF_StructKid::Element; + pKid->m_pDict = pKidDict; + if (m_pTree->GetPage()) { + pKid->m_pElement = nullptr; + return; + } + + 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 new file mode 100644 index 0000000000..b227397431 --- /dev/null +++ b/core/fpdfdoc/cpdf_structelement.h @@ -0,0 +1,94 @@ +// Copyright 2017 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef CORE_FPDFDOC_CPDF_STRUCTELEMENT_H_ +#define CORE_FPDFDOC_CPDF_STRUCTELEMENT_H_ + +#include + +#include "core/fxcrt/cfx_retain_ptr.h" +#include "core/fxcrt/fx_string.h" +#include "core/fxge/fx_dib.h" + +class CPDF_Dictionary; +class CPDF_Object; +class CPDF_StructElement; +class CPDF_StructTree; + +class CPDF_StructKid { + public: + CPDF_StructKid(); + CPDF_StructKid(const CPDF_StructKid& that); + ~CPDF_StructKid(); + + enum { Invalid, Element, PageContent, StreamContent, Object } m_Type; + + CFX_RetainPtr m_pElement; // For Element. + CPDF_Dictionary* m_pDict; // For Element. + uint32_t m_PageObjNum; // For PageContent, StreamContent, Object. + uint32_t m_RefObjNum; // For StreamContent, Object. + uint32_t m_ContentId; // For PageContent, StreamContent. +}; + +class CPDF_StructElement : public CFX_Retainable { + public: + 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, + CPDF_StructElement* pParent, + CPDF_Dictionary* pDict); + ~CPDF_StructElement() override; + + CPDF_StructTree* const m_pTree; + CPDF_StructElement* const m_pParent; + CPDF_Dictionary* const m_pDict; + CFX_ByteString m_Type; + std::vector m_Kids; +}; + +#endif // CORE_FPDFDOC_CPDF_STRUCTELEMENT_H_ diff --git a/core/fpdfdoc/cpdf_structtree.cpp b/core/fpdfdoc/cpdf_structtree.cpp new file mode 100644 index 0000000000..51ad2c775c --- /dev/null +++ b/core/fpdfdoc/cpdf_structtree.cpp @@ -0,0 +1,155 @@ +// Copyright 2017 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#include "core/fpdfdoc/cpdf_structtree.h" + +#include "core/fpdfapi/parser/cpdf_array.h" +#include "core/fpdfapi/parser/cpdf_document.h" +#include "core/fpdfapi/parser/cpdf_number.h" +#include "core/fpdfapi/parser/cpdf_reference.h" +#include "core/fpdfdoc/cpdf_numbertree.h" +#include "core/fpdfdoc/cpdf_structelement.h" +#include "third_party/base/stl_util.h" + +namespace { + +const int nMaxRecursion = 32; + +bool IsTagged(const CPDF_Document* pDoc) { + CPDF_Dictionary* pCatalog = pDoc->GetRoot(); + CPDF_Dictionary* pMarkInfo = pCatalog->GetDictFor("MarkInfo"); + return pMarkInfo && pMarkInfo->GetIntegerFor("Marked"); +} + +} // namespace + +// static +std::unique_ptr CPDF_StructTree::LoadPage( + const CPDF_Document* pDoc, + const CPDF_Dictionary* pPageDict) { + if (!IsTagged(pDoc)) + return nullptr; + + auto pTree = pdfium::MakeUnique(pDoc); + pTree->LoadPageTree(pPageDict); + return pTree; +} + +CPDF_StructTree::CPDF_StructTree(const CPDF_Document* pDoc) + : m_pTreeRoot(pDoc->GetRoot()->GetDictFor("StructTreeRoot")), + m_pRoleMap(m_pTreeRoot ? m_pTreeRoot->GetDictFor("RoleMap") : nullptr), + m_pPage(nullptr) {} + +CPDF_StructTree::~CPDF_StructTree() {} + +int CPDF_StructTree::CountTopElements() const { + return pdfium::CollectionSize(m_Kids); +} + +CPDF_StructElement* CPDF_StructTree::GetTopElement(int i) const { + return m_Kids[i].Get(); +} + +void CPDF_StructTree::LoadPageTree(const CPDF_Dictionary* pPageDict) { + m_pPage = pPageDict; + if (!m_pTreeRoot) + return; + + CPDF_Object* pKids = m_pTreeRoot->GetDirectObjectFor("K"); + if (!pKids) + return; + + uint32_t dwKids = 0; + if (pKids->IsDictionary()) + dwKids = 1; + else if (CPDF_Array* pArray = pKids->AsArray()) + dwKids = pArray->GetCount(); + else + return; + + m_Kids.clear(); + m_Kids.resize(dwKids); + CPDF_Dictionary* pParentTree = m_pTreeRoot->GetDictFor("ParentTree"); + if (!pParentTree) + return; + + CPDF_NumberTree parent_tree(pParentTree); + int parents_id = pPageDict->GetIntegerFor("StructParents", -1); + if (parents_id < 0) + return; + + CPDF_Array* pParentArray = ToArray(parent_tree.LookupValue(parents_id)); + if (!pParentArray) + return; + + std::map> element_map; + for (size_t i = 0; i < pParentArray->GetCount(); i++) { + if (CPDF_Dictionary* pParent = pParentArray->GetDictAt(i)) + AddPageNode(pParent, &element_map); + } +} + +CFX_RetainPtr CPDF_StructTree::AddPageNode( + CPDF_Dictionary* pDict, + std::map>* map, + int nLevel) { + if (nLevel > nMaxRecursion) + return nullptr; + + auto it = map->find(pDict); + if (it != map->end()) + return it->second; + + auto pElement = pdfium::MakeRetain(this, nullptr, pDict); + (*map)[pDict] = pElement; + CPDF_Dictionary* pParent = pDict->GetDictFor("P"); + if (!pParent || pParent->GetStringFor("Type") == "StructTreeRoot") { + if (!AddTopLevelNode(pDict, pElement)) + map->erase(pDict); + return pElement; + } + + CFX_RetainPtr pParentElement = + AddPageNode(pParent, map, nLevel + 1); + bool bSave = false; + for (CPDF_StructKid& kid : *pParentElement->GetKids()) { + if (kid.m_Type == CPDF_StructKid::Element && kid.m_pDict == pDict) { + kid.m_pElement = pElement; + bSave = true; + } + } + if (!bSave) + map->erase(pDict); + return pElement; +} + +bool CPDF_StructTree::AddTopLevelNode( + CPDF_Dictionary* pDict, + const CFX_RetainPtr& pElement) { + CPDF_Object* pObj = m_pTreeRoot->GetDirectObjectFor("K"); + if (!pObj) + return false; + + if (pObj->IsDictionary()) { + if (pObj->GetObjNum() != pDict->GetObjNum()) + return false; + m_Kids[0] = pElement; + } + + CPDF_Array* pTopKids = pObj->AsArray(); + if (!pTopKids) + return true; + + bool bSave = false; + for (size_t i = 0; i < pTopKids->GetCount(); i++) { + CPDF_Reference* pKidRef = ToReference(pTopKids->GetObjectAt(i)); + if (pKidRef && pKidRef->GetRefObjNum() == pDict->GetObjNum()) { + m_Kids[i] = pElement; + bSave = true; + } + } + return bSave; +} diff --git a/core/fpdfdoc/cpdf_structtree.h b/core/fpdfdoc/cpdf_structtree.h new file mode 100644 index 0000000000..20bf41e7ee --- /dev/null +++ b/core/fpdfdoc/cpdf_structtree.h @@ -0,0 +1,51 @@ +// Copyright 2017 PDFium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com + +#ifndef CORE_FPDFDOC_CPDF_STRUCTTREE_H_ +#define CORE_FPDFDOC_CPDF_STRUCTTREE_H_ + +#include +#include +#include + +#include "core/fxcrt/cfx_retain_ptr.h" + +class CPDF_Dictionary; +class CPDF_Document; +class CPDF_StructElement; + +class CPDF_StructTree { + public: + static std::unique_ptr LoadPage( + const CPDF_Document* pDoc, + const CPDF_Dictionary* pPageDict); + + explicit CPDF_StructTree(const CPDF_Document* pDoc); + ~CPDF_StructTree(); + + int CountTopElements() const; + CPDF_StructElement* GetTopElement(int i) const; + + void LoadPageTree(const CPDF_Dictionary* pPageDict); + CFX_RetainPtr AddPageNode( + CPDF_Dictionary* pElement, + std::map>* map, + int nLevel = 0); + 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; + std::vector> m_Kids; +}; + +#endif // CORE_FPDFDOC_CPDF_STRUCTTREE_H_ diff --git a/core/fpdfdoc/doc_tagged.cpp b/core/fpdfdoc/doc_tagged.cpp deleted file mode 100644 index 418fab411a..0000000000 --- a/core/fpdfdoc/doc_tagged.cpp +++ /dev/null @@ -1,418 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#include -#include -#include - -#include "core/fpdfapi/parser/cpdf_array.h" -#include "core/fpdfapi/parser/cpdf_dictionary.h" -#include "core/fpdfapi/parser/cpdf_document.h" -#include "core/fpdfapi/parser/cpdf_name.h" -#include "core/fpdfapi/parser/cpdf_number.h" -#include "core/fpdfapi/parser/cpdf_reference.h" -#include "core/fpdfapi/parser/cpdf_stream.h" -#include "core/fpdfdoc/cpdf_numbertree.h" -#include "core/fpdfdoc/fpdf_tagged.h" -#include "core/fpdfdoc/tagged_int.h" -#include "third_party/base/ptr_util.h" - -namespace { - -const int nMaxRecursion = 32; - -bool IsTagged(const CPDF_Document* pDoc) { - CPDF_Dictionary* pCatalog = pDoc->GetRoot(); - CPDF_Dictionary* pMarkInfo = pCatalog->GetDictFor("MarkInfo"); - return pMarkInfo && pMarkInfo->GetIntegerFor("Marked"); -} - -} // namespace - -CPDF_StructKid::CPDF_StructKid() - : m_Type(Invalid), - m_pDict(nullptr), - m_PageObjNum(0), - m_RefObjNum(0), - m_ContentId(0) {} - -CPDF_StructKid::CPDF_StructKid(const CPDF_StructKid& that) = default; - -CPDF_StructKid::~CPDF_StructKid() {} - -// static -std::unique_ptr IPDF_StructTree::LoadPage( - const CPDF_Document* pDoc, - const CPDF_Dictionary* pPageDict) { - if (!IsTagged(pDoc)) - return nullptr; - - auto pTree = pdfium::MakeUnique(pDoc); - pTree->LoadPageTree(pPageDict); - return std::move(pTree); -} - -CPDF_StructTree::CPDF_StructTree(const CPDF_Document* pDoc) - : m_pTreeRoot(pDoc->GetRoot()->GetDictFor("StructTreeRoot")), - m_pRoleMap(m_pTreeRoot ? m_pTreeRoot->GetDictFor("RoleMap") : nullptr), - m_pPage(nullptr) {} - -CPDF_StructTree::~CPDF_StructTree() {} - -int CPDF_StructTree::CountTopElements() const { - return pdfium::CollectionSize(m_Kids); -} - -IPDF_StructElement* CPDF_StructTree::GetTopElement(int i) const { - return m_Kids[i].Get(); -} - -void CPDF_StructTree::LoadPageTree(const CPDF_Dictionary* pPageDict) { - m_pPage = pPageDict; - if (!m_pTreeRoot) - return; - - CPDF_Object* pKids = m_pTreeRoot->GetDirectObjectFor("K"); - if (!pKids) - return; - - uint32_t dwKids = 0; - if (pKids->IsDictionary()) - dwKids = 1; - else if (CPDF_Array* pArray = pKids->AsArray()) - dwKids = pArray->GetCount(); - else - return; - - m_Kids.clear(); - m_Kids.resize(dwKids); - CPDF_Dictionary* pParentTree = m_pTreeRoot->GetDictFor("ParentTree"); - if (!pParentTree) - return; - - CPDF_NumberTree parent_tree(pParentTree); - int parents_id = pPageDict->GetIntegerFor("StructParents", -1); - if (parents_id < 0) - return; - - CPDF_Array* pParentArray = ToArray(parent_tree.LookupValue(parents_id)); - if (!pParentArray) - return; - - std::map> element_map; - for (size_t i = 0; i < pParentArray->GetCount(); i++) { - if (CPDF_Dictionary* pParent = pParentArray->GetDictAt(i)) - AddPageNode(pParent, &element_map); - } -} - -CFX_RetainPtr CPDF_StructTree::AddPageNode( - CPDF_Dictionary* pDict, - std::map>* map, - int nLevel) { - if (nLevel > nMaxRecursion) - return nullptr; - - auto it = map->find(pDict); - if (it != map->end()) - return it->second; - - auto pElement = pdfium::MakeRetain(this, nullptr, pDict); - (*map)[pDict] = pElement; - CPDF_Dictionary* pParent = pDict->GetDictFor("P"); - if (!pParent || pParent->GetStringFor("Type") == "StructTreeRoot") { - if (!AddTopLevelNode(pDict, pElement)) - map->erase(pDict); - return pElement; - } - - CFX_RetainPtr pParentElement = - AddPageNode(pParent, map, nLevel + 1); - bool bSave = false; - for (CPDF_StructKid& kid : *pParentElement->GetKids()) { - if (kid.m_Type == CPDF_StructKid::Element && kid.m_pDict == pDict) { - kid.m_pElement = pElement; - bSave = true; - } - } - if (!bSave) - map->erase(pDict); - return pElement; -} - -bool CPDF_StructTree::AddTopLevelNode( - CPDF_Dictionary* pDict, - const CFX_RetainPtr& pElement) { - CPDF_Object* pObj = m_pTreeRoot->GetDirectObjectFor("K"); - if (!pObj) - return false; - - if (pObj->IsDictionary()) { - if (pObj->GetObjNum() != pDict->GetObjNum()) - return false; - m_Kids[0] = pElement; - } - if (CPDF_Array* pTopKids = pObj->AsArray()) { - bool bSave = false; - for (size_t i = 0; i < pTopKids->GetCount(); i++) { - CPDF_Reference* pKidRef = ToReference(pTopKids->GetObjectAt(i)); - if (pKidRef && pKidRef->GetRefObjNum() == pDict->GetObjNum()) { - m_Kids[i] = pElement; - bSave = true; - } - } - if (!bSave) - return false; - } - return true; -} - -CPDF_StructElement::CPDF_StructElement(CPDF_StructTree* pTree, - CPDF_StructElement* pParent, - CPDF_Dictionary* pDict) - : m_pTree(pTree), - m_pParent(pParent), - m_pDict(pDict), - m_Type(pDict->GetStringFor("S")) { - if (pTree->m_pRoleMap) { - CFX_ByteString mapped = pTree->m_pRoleMap->GetStringFor(m_Type); - if (!mapped.IsEmpty()) - m_Type = mapped; - } - LoadKids(pDict); -} - -IPDF_StructTree* CPDF_StructElement::GetTree() const { - return m_pTree; -} - -const CFX_ByteString& CPDF_StructElement::GetType() const { - return m_Type; -} - -IPDF_StructElement* CPDF_StructElement::GetParent() const { - return m_pParent; -} - -CPDF_Dictionary* CPDF_StructElement::GetDict() const { - return m_pDict; -} - -int CPDF_StructElement::CountKids() const { - return pdfium::CollectionSize(m_Kids); -} - -IPDF_StructElement* CPDF_StructElement::GetKidIfElement(int index) const { - if (m_Kids[index].m_Type != CPDF_StructKid::Element) - return nullptr; - - return m_Kids[index].m_pElement.Get(); -} - -CPDF_StructElement::~CPDF_StructElement() {} - -void CPDF_StructElement::LoadKids(CPDF_Dictionary* pDict) { - CPDF_Object* pObj = pDict->GetObjectFor("Pg"); - uint32_t PageObjNum = 0; - if (CPDF_Reference* pRef = ToReference(pObj)) - PageObjNum = pRef->GetRefObjNum(); - - CPDF_Object* pKids = pDict->GetDirectObjectFor("K"); - if (!pKids) - return; - - m_Kids.clear(); - if (CPDF_Array* pArray = pKids->AsArray()) { - m_Kids.resize(pArray->GetCount()); - for (uint32_t i = 0; i < pArray->GetCount(); i++) { - CPDF_Object* pKid = pArray->GetDirectObjectAt(i); - LoadKid(PageObjNum, pKid, &m_Kids[i]); - } - } else { - m_Kids.resize(1); - LoadKid(PageObjNum, pKids, &m_Kids[0]); - } -} -void CPDF_StructElement::LoadKid(uint32_t PageObjNum, - CPDF_Object* pKidObj, - CPDF_StructKid* pKid) { - pKid->m_Type = CPDF_StructKid::Invalid; - if (!pKidObj) - return; - - if (pKidObj->IsNumber()) { - if (m_pTree->m_pPage && m_pTree->m_pPage->GetObjNum() != PageObjNum) { - return; - } - pKid->m_Type = CPDF_StructKid::PageContent; - pKid->m_ContentId = pKidObj->GetInteger(); - pKid->m_PageObjNum = PageObjNum; - return; - } - - CPDF_Dictionary* pKidDict = pKidObj->AsDictionary(); - if (!pKidDict) - return; - - if (CPDF_Reference* pRef = ToReference(pKidDict->GetObjectFor("Pg"))) - PageObjNum = pRef->GetRefObjNum(); - - CFX_ByteString type = pKidDict->GetStringFor("Type"); - if (type == "MCR") { - if (m_pTree->m_pPage && m_pTree->m_pPage->GetObjNum() != PageObjNum) { - return; - } - pKid->m_Type = CPDF_StructKid::StreamContent; - CPDF_Reference* pRef = ToReference(pKidDict->GetObjectFor("Stm")); - pKid->m_RefObjNum = pRef ? pRef->GetRefObjNum() : 0; - pKid->m_PageObjNum = PageObjNum; - pKid->m_ContentId = pKidDict->GetIntegerFor("MCID"); - } else if (type == "OBJR") { - if (m_pTree->m_pPage && m_pTree->m_pPage->GetObjNum() != PageObjNum) { - return; - } - pKid->m_Type = CPDF_StructKid::Object; - CPDF_Reference* pObj = ToReference(pKidDict->GetObjectFor("Obj")); - pKid->m_RefObjNum = pObj ? pObj->GetRefObjNum() : 0; - pKid->m_PageObjNum = PageObjNum; - } else { - pKid->m_Type = CPDF_StructKid::Element; - pKid->m_pDict = pKidDict; - if (!m_pTree->m_pPage) { - pKid->m_pElement = - pdfium::MakeRetain(m_pTree, this, pKidDict); - } else { - pKid->m_pElement = nullptr; - } - } -} -static 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; -} -CPDF_Object* CPDF_StructElement::GetAttr(const CFX_ByteStringC& owner, - const CFX_ByteStringC& name, - bool bInheritable, - float fLevel) { - if (fLevel > nMaxRecursion) { - return nullptr; - } - if (bInheritable) { - CPDF_Object* pAttr = GetAttr(owner, name, false); - if (pAttr) { - return pAttr; - } - if (!m_pParent) { - return nullptr; - } - return m_pParent->GetAttr(owner, name, true, fLevel + 1); - } - CPDF_Object* pA = m_pDict->GetDirectObjectFor("A"); - if (pA) { - CPDF_Dictionary* pAttrDict = FindAttrDict(pA, owner); - if (pAttrDict) { - CPDF_Object* pAttr = pAttrDict->GetDirectObjectFor(CFX_ByteString(name)); - if (pAttr) { - return pAttr; - } - } - } - CPDF_Object* pC = m_pDict->GetDirectObjectFor("C"); - if (!pC) - return nullptr; - - CPDF_Dictionary* pClassMap = m_pTree->m_pTreeRoot->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 | ((int)(pArray->GetNumberAt(0) * 255) << 16) | - ((int)(pArray->GetNumberAt(1) * 255) << 8) | - (int)(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/fpdf_tagged.h b/core/fpdfdoc/fpdf_tagged.h deleted file mode 100644 index 5e7b1827c5..0000000000 --- a/core/fpdfdoc/fpdf_tagged.h +++ /dev/null @@ -1,75 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef CORE_FPDFDOC_FPDF_TAGGED_H_ -#define CORE_FPDFDOC_FPDF_TAGGED_H_ - -#include - -#include "core/fxge/fx_dib.h" - -class CPDF_Dictionary; -class CPDF_Document; -class IPDF_StructElement; - -class IPDF_StructTree { - public: - static std::unique_ptr LoadPage( - const CPDF_Document* pDoc, - const CPDF_Dictionary* pPageDict); - - - virtual int CountTopElements() const = 0; - virtual IPDF_StructElement* GetTopElement(int i) const = 0; - - protected: - friend std::default_delete; - virtual ~IPDF_StructTree() {} -}; - -class IPDF_StructElement { - public: - virtual IPDF_StructTree* GetTree() const = 0; - virtual const CFX_ByteString& GetType() const = 0; - virtual IPDF_StructElement* GetParent() const = 0; - virtual CPDF_Dictionary* GetDict() const = 0; - virtual int CountKids() const = 0; - virtual IPDF_StructElement* GetKidIfElement(int index) const = 0; - - virtual CPDF_Object* GetAttr(const CFX_ByteStringC& owner, - const CFX_ByteStringC& name, - bool bInheritable = false, - float fLevel = 0.0F) = 0; - - virtual CFX_ByteString GetName(const CFX_ByteStringC& owner, - const CFX_ByteStringC& name, - const CFX_ByteStringC& default_value, - bool bInheritable = false, - int subindex = -1) = 0; - - virtual FX_ARGB GetColor(const CFX_ByteStringC& owner, - const CFX_ByteStringC& name, - FX_ARGB default_value, - bool bInheritable = false, - int subindex = -1) = 0; - - virtual float GetNumber(const CFX_ByteStringC& owner, - const CFX_ByteStringC& name, - float default_value, - bool bInheritable = false, - int subindex = -1) = 0; - - virtual int GetInteger(const CFX_ByteStringC& owner, - const CFX_ByteStringC& name, - int default_value, - bool bInheritable = false, - int subindex = -1) = 0; - - protected: - virtual ~IPDF_StructElement() {} -}; - -#endif // CORE_FPDFDOC_FPDF_TAGGED_H_ diff --git a/core/fpdfdoc/tagged_int.h b/core/fpdfdoc/tagged_int.h deleted file mode 100644 index cafcbd42aa..0000000000 --- a/core/fpdfdoc/tagged_int.h +++ /dev/null @@ -1,119 +0,0 @@ -// Copyright 2014 PDFium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com - -#ifndef CORE_FPDFDOC_TAGGED_INT_H_ -#define CORE_FPDFDOC_TAGGED_INT_H_ - -#include -#include -#include - -#include "core/fpdfdoc/fpdf_tagged.h" -#include "core/fxcrt/cfx_retain_ptr.h" -#include "third_party/base/stl_util.h" - -class CPDF_StructElement; - -struct CPDF_StructKid { - CPDF_StructKid(); - CPDF_StructKid(const CPDF_StructKid& that); - ~CPDF_StructKid(); - - enum { Invalid, Element, PageContent, StreamContent, Object } m_Type; - - CFX_RetainPtr m_pElement; // For Element. - CPDF_Dictionary* m_pDict; // For Element. - uint32_t m_PageObjNum; // For PageContent, StreamContent, Object. - uint32_t m_RefObjNum; // For StreamContent, Object. - uint32_t m_ContentId; // For PageContent, StreamContent. -}; - -class CPDF_StructTree final : public IPDF_StructTree { - public: - explicit CPDF_StructTree(const CPDF_Document* pDoc); - ~CPDF_StructTree() override; - - // IPDF_StructTree: - int CountTopElements() const override; - IPDF_StructElement* GetTopElement(int i) const override; - - void LoadPageTree(const CPDF_Dictionary* pPageDict); - CFX_RetainPtr AddPageNode( - CPDF_Dictionary* pElement, - std::map>* map, - int nLevel = 0); - bool AddTopLevelNode(CPDF_Dictionary* pDict, - const CFX_RetainPtr& pElement); - - protected: - const CPDF_Dictionary* const m_pTreeRoot; - const CPDF_Dictionary* const m_pRoleMap; - const CPDF_Dictionary* m_pPage; - std::vector> m_Kids; - - friend class CPDF_StructElement; -}; - -class CPDF_StructElement final : public CFX_Retainable, - public IPDF_StructElement { - public: - template - friend CFX_RetainPtr pdfium::MakeRetain(Args&&... args); - - // IPDF_StructElement - IPDF_StructTree* GetTree() const override; - const CFX_ByteString& GetType() const override; - IPDF_StructElement* GetParent() const override; - CPDF_Dictionary* GetDict() const override; - int CountKids() const override; - IPDF_StructElement* GetKidIfElement(int index) const override; - CPDF_Object* GetAttr(const CFX_ByteStringC& owner, - const CFX_ByteStringC& name, - bool bInheritable = false, - float fLevel = 0.0F) override; - CFX_ByteString GetName(const CFX_ByteStringC& owner, - const CFX_ByteStringC& name, - const CFX_ByteStringC& default_value, - bool bInheritable = false, - int subindex = -1) override; - FX_ARGB GetColor(const CFX_ByteStringC& owner, - const CFX_ByteStringC& name, - FX_ARGB default_value, - bool bInheritable = false, - int subindex = -1) override; - float GetNumber(const CFX_ByteStringC& owner, - const CFX_ByteStringC& name, - float default_value, - bool bInheritable = false, - int subindex = -1) override; - int GetInteger(const CFX_ByteStringC& owner, - const CFX_ByteStringC& name, - int default_value, - bool bInheritable = false, - int subindex = -1) override; - - 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, - CPDF_StructElement* pParent, - CPDF_Dictionary* pDict); - ~CPDF_StructElement() override; - - CPDF_StructTree* const m_pTree; - CPDF_StructElement* const m_pParent; - CPDF_Dictionary* const m_pDict; - CFX_ByteString m_Type; - std::vector m_Kids; -}; - -#endif // CORE_FPDFDOC_TAGGED_INT_H_ diff --git a/fpdfsdk/fpdf_structtree.cpp b/fpdfsdk/fpdf_structtree.cpp index 8a93d2299d..96d40b41c2 100644 --- a/fpdfsdk/fpdf_structtree.cpp +++ b/fpdfsdk/fpdf_structtree.cpp @@ -8,17 +8,18 @@ #include "core/fpdfapi/page/cpdf_page.h" #include "core/fpdfapi/parser/cpdf_dictionary.h" -#include "core/fpdfdoc/fpdf_tagged.h" +#include "core/fpdfdoc/cpdf_structelement.h" +#include "core/fpdfdoc/cpdf_structtree.h" #include "fpdfsdk/fsdk_define.h" namespace { -IPDF_StructTree* ToStructTree(FPDF_STRUCTTREE struct_tree) { - return reinterpret_cast(struct_tree); +CPDF_StructTree* ToStructTree(FPDF_STRUCTTREE struct_tree) { + return reinterpret_cast(struct_tree); } -IPDF_StructElement* ToStructTreeElement(FPDF_STRUCTELEMENT struct_element) { - return reinterpret_cast(struct_element); +CPDF_StructElement* ToStructTreeElement(FPDF_STRUCTELEMENT struct_element) { + return reinterpret_cast(struct_element); } unsigned long WideStringToBuffer(const CFX_WideString& str, @@ -40,23 +41,23 @@ DLLEXPORT FPDF_STRUCTTREE STDCALL FPDF_StructTree_GetForPage(FPDF_PAGE page) { CPDF_Page* pPage = CPDFPageFromFPDFPage(page); if (!pPage) return nullptr; - return IPDF_StructTree::LoadPage(pPage->m_pDocument, pPage->m_pFormDict) + return CPDF_StructTree::LoadPage(pPage->m_pDocument, pPage->m_pFormDict) .release(); } DLLEXPORT void STDCALL FPDF_StructTree_Close(FPDF_STRUCTTREE struct_tree) { - std::unique_ptr(ToStructTree(struct_tree)); + std::unique_ptr(ToStructTree(struct_tree)); } DLLEXPORT int STDCALL FPDF_StructTree_CountChildren(FPDF_STRUCTTREE struct_tree) { - IPDF_StructTree* tree = ToStructTree(struct_tree); + CPDF_StructTree* tree = ToStructTree(struct_tree); return tree ? tree->CountTopElements() : -1; } DLLEXPORT FPDF_STRUCTELEMENT STDCALL FPDF_StructTree_GetChildAtIndex(FPDF_STRUCTTREE struct_tree, int index) { - IPDF_StructTree* tree = ToStructTree(struct_tree); + CPDF_StructTree* tree = ToStructTree(struct_tree); if (!tree || index < 0 || index >= tree->CountTopElements()) return nullptr; return tree->GetTopElement(index); @@ -66,7 +67,7 @@ DLLEXPORT unsigned long STDCALL FPDF_StructElement_GetAltText(FPDF_STRUCTELEMENT struct_element, void* buffer, unsigned long buflen) { - IPDF_StructElement* elem = ToStructTreeElement(struct_element); + CPDF_StructElement* elem = ToStructTreeElement(struct_element); return (elem && elem->GetDict()) ? WideStringToBuffer(elem->GetDict()->GetUnicodeTextFor("Alt"), buffer, buflen) @@ -77,21 +78,21 @@ DLLEXPORT unsigned long STDCALL FPDF_StructElement_GetType(FPDF_STRUCTELEMENT struct_element, void* buffer, unsigned long buflen) { - IPDF_StructElement* elem = ToStructTreeElement(struct_element); + CPDF_StructElement* elem = ToStructTreeElement(struct_element); return elem ? WideStringToBuffer(elem->GetType().UTF8Decode(), buffer, buflen) : 0; } DLLEXPORT int STDCALL FPDF_StructElement_CountChildren(FPDF_STRUCTELEMENT struct_element) { - IPDF_StructElement* elem = ToStructTreeElement(struct_element); + CPDF_StructElement* elem = ToStructTreeElement(struct_element); return elem ? elem->CountKids() : -1; } DLLEXPORT FPDF_STRUCTELEMENT STDCALL FPDF_StructElement_GetChildAtIndex(FPDF_STRUCTELEMENT struct_element, int index) { - IPDF_StructElement* elem = ToStructTreeElement(struct_element); + CPDF_StructElement* elem = ToStructTreeElement(struct_element); if (!elem || index < 0 || index >= elem->CountKids()) return nullptr; -- cgit v1.2.3