Index: core/fpdfdoc/doc_tagged.cpp |
diff --git a/core/fpdfdoc/doc_tagged.cpp b/core/fpdfdoc/doc_tagged.cpp |
index 39feaeef88c15168b5fdc16f1ad1226ac2bc23eb..5feb205542649e9ca3dbdf5dc33b2c0d520fd6f7 100644 |
--- a/core/fpdfdoc/doc_tagged.cpp |
+++ b/core/fpdfdoc/doc_tagged.cpp |
@@ -39,27 +39,27 @@ std::unique_ptr<IPDF_StructTree> IPDF_StructTree::LoadPage( |
if (!IsTagged(pDoc)) |
return nullptr; |
- auto pTree = pdfium::MakeUnique<CPDF_StructTreeImpl>(pDoc); |
+ auto pTree = pdfium::MakeUnique<CPDF_StructTree>(pDoc); |
pTree->LoadPageTree(pPageDict); |
return std::move(pTree); |
} |
-CPDF_StructTreeImpl::CPDF_StructTreeImpl(const CPDF_Document* pDoc) |
+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_StructTreeImpl::~CPDF_StructTreeImpl() {} |
+CPDF_StructTree::~CPDF_StructTree() {} |
-int CPDF_StructTreeImpl::CountTopElements() const { |
+int CPDF_StructTree::CountTopElements() const { |
return pdfium::CollectionSize<int>(m_Kids); |
} |
-IPDF_StructElement* CPDF_StructTreeImpl::GetTopElement(int i) const { |
+IPDF_StructElement* CPDF_StructTree::GetTopElement(int i) const { |
return m_Kids[i].Get(); |
} |
-void CPDF_StructTreeImpl::LoadPageTree(const CPDF_Dictionary* pPageDict) { |
+void CPDF_StructTree::LoadPageTree(const CPDF_Dictionary* pPageDict) { |
m_pPage = pPageDict; |
if (!m_pTreeRoot) |
return; |
@@ -91,16 +91,16 @@ void CPDF_StructTreeImpl::LoadPageTree(const CPDF_Dictionary* pPageDict) { |
if (!pParentArray) |
return; |
- std::map<CPDF_Dictionary*, CPDF_StructElementImpl*> element_map; |
+ std::map<CPDF_Dictionary*, CPDF_StructElement*> element_map; |
for (size_t i = 0; i < pParentArray->GetCount(); i++) { |
if (CPDF_Dictionary* pParent = pParentArray->GetDictAt(i)) |
AddPageNode(pParent, element_map); |
} |
} |
-CPDF_StructElementImpl* CPDF_StructTreeImpl::AddPageNode( |
+CPDF_StructElement* CPDF_StructTree::AddPageNode( |
CPDF_Dictionary* pDict, |
- std::map<CPDF_Dictionary*, CPDF_StructElementImpl*>& map, |
+ std::map<CPDF_Dictionary*, CPDF_StructElement*>& map, |
int nLevel) { |
if (nLevel > nMaxRecursion) |
return nullptr; |
@@ -109,8 +109,7 @@ CPDF_StructElementImpl* CPDF_StructTreeImpl::AddPageNode( |
if (it != map.end()) |
return it->second; |
- CPDF_StructElementImpl* pElement = |
- new CPDF_StructElementImpl(this, nullptr, pDict); |
+ CPDF_StructElement* pElement = new CPDF_StructElement(this, nullptr, pDict); |
map[pDict] = pElement; |
CPDF_Dictionary* pParent = pDict->GetDictFor("P"); |
if (!pParent || pParent->GetStringFor("Type") == "StructTreeRoot") { |
@@ -119,10 +118,9 @@ CPDF_StructElementImpl* CPDF_StructTreeImpl::AddPageNode( |
map.erase(pDict); |
} |
} else { |
- CPDF_StructElementImpl* pParentElement = |
- AddPageNode(pParent, map, nLevel + 1); |
+ CPDF_StructElement* pParentElement = AddPageNode(pParent, map, nLevel + 1); |
bool bSave = false; |
- for (CPDF_StructKid& kid : pParentElement->m_Kids) { |
+ for (CPDF_StructKid& kid : *pParentElement->GetKids()) { |
if (kid.m_Type != CPDF_StructKid::Element) |
continue; |
if (kid.m_Element.m_pDict != pDict) |
@@ -137,8 +135,8 @@ CPDF_StructElementImpl* CPDF_StructTreeImpl::AddPageNode( |
} |
return pElement; |
} |
-bool CPDF_StructTreeImpl::AddTopLevelNode(CPDF_Dictionary* pDict, |
- CPDF_StructElementImpl* pElement) { |
+bool CPDF_StructTree::AddTopLevelNode(CPDF_Dictionary* pDict, |
+ CPDF_StructElement* pElement) { |
CPDF_Object* pObj = m_pTreeRoot->GetDirectObjectFor("K"); |
if (!pObj) |
return false; |
@@ -163,9 +161,9 @@ bool CPDF_StructTreeImpl::AddTopLevelNode(CPDF_Dictionary* pDict, |
return true; |
} |
-CPDF_StructElementImpl::CPDF_StructElementImpl(CPDF_StructTreeImpl* pTree, |
- CPDF_StructElementImpl* pParent, |
- CPDF_Dictionary* pDict) |
+CPDF_StructElement::CPDF_StructElement(CPDF_StructTree* pTree, |
+ CPDF_StructElement* pParent, |
+ CPDF_Dictionary* pDict) |
: m_RefCount(0), |
m_pTree(pTree), |
m_pParent(pParent), |
@@ -179,47 +177,49 @@ CPDF_StructElementImpl::CPDF_StructElementImpl(CPDF_StructTreeImpl* pTree, |
LoadKids(pDict); |
} |
-IPDF_StructTree* CPDF_StructElementImpl::GetTree() const { |
+IPDF_StructTree* CPDF_StructElement::GetTree() const { |
return m_pTree; |
} |
-const CFX_ByteString& CPDF_StructElementImpl::GetType() const { |
+const CFX_ByteString& CPDF_StructElement::GetType() const { |
return m_Type; |
} |
-IPDF_StructElement* CPDF_StructElementImpl::GetParent() const { |
+IPDF_StructElement* CPDF_StructElement::GetParent() const { |
return m_pParent; |
} |
-CPDF_Dictionary* CPDF_StructElementImpl::GetDict() const { |
+CPDF_Dictionary* CPDF_StructElement::GetDict() const { |
return m_pDict; |
} |
-int CPDF_StructElementImpl::CountKids() const { |
+int CPDF_StructElement::CountKids() const { |
return pdfium::CollectionSize<int>(m_Kids); |
} |
-const CPDF_StructKid& CPDF_StructElementImpl::GetKid(int index) const { |
- return m_Kids[index]; |
+IPDF_StructElement* CPDF_StructElement::GetKidIfElement(int index) const { |
+ return m_Kids[index].m_Type == CPDF_StructKid::Element |
+ ? m_Kids[index].m_Element.m_pElement |
+ : nullptr; |
} |
-CPDF_StructElementImpl::~CPDF_StructElementImpl() { |
+CPDF_StructElement::~CPDF_StructElement() { |
for (CPDF_StructKid& kid : m_Kids) { |
if (kid.m_Type == CPDF_StructKid::Element && kid.m_Element.m_pElement) |
- static_cast<CPDF_StructElementImpl*>(kid.m_Element.m_pElement)->Release(); |
+ static_cast<CPDF_StructElement*>(kid.m_Element.m_pElement)->Release(); |
} |
} |
-CPDF_StructElementImpl* CPDF_StructElementImpl::Retain() { |
+CPDF_StructElement* CPDF_StructElement::Retain() { |
m_RefCount++; |
return this; |
} |
-void CPDF_StructElementImpl::Release() { |
+void CPDF_StructElement::Release() { |
if (--m_RefCount < 1) { |
delete this; |
} |
} |
-void CPDF_StructElementImpl::LoadKids(CPDF_Dictionary* pDict) { |
+void CPDF_StructElement::LoadKids(CPDF_Dictionary* pDict) { |
CPDF_Object* pObj = pDict->GetObjectFor("Pg"); |
uint32_t PageObjNum = 0; |
if (CPDF_Reference* pRef = ToReference(pObj)) |
@@ -241,9 +241,9 @@ void CPDF_StructElementImpl::LoadKids(CPDF_Dictionary* pDict) { |
LoadKid(PageObjNum, pKids, &m_Kids[0]); |
} |
} |
-void CPDF_StructElementImpl::LoadKid(uint32_t PageObjNum, |
- CPDF_Object* pKidObj, |
- CPDF_StructKid* pKid) { |
+void CPDF_StructElement::LoadKid(uint32_t PageObjNum, |
+ CPDF_Object* pKidObj, |
+ CPDF_StructKid* pKid) { |
pKid->m_Type = CPDF_StructKid::Invalid; |
if (!pKidObj) |
return; |
@@ -294,7 +294,7 @@ void CPDF_StructElementImpl::LoadKid(uint32_t PageObjNum, |
pKid->m_Element.m_pDict = pKidDict; |
if (!m_pTree->m_pPage) { |
pKid->m_Element.m_pElement = |
- new CPDF_StructElementImpl(m_pTree, this, pKidDict); |
+ new CPDF_StructElement(m_pTree, this, pKidDict); |
} else { |
pKid->m_Element.m_pElement = nullptr; |
} |
@@ -325,10 +325,10 @@ static CPDF_Dictionary* FindAttrDict(CPDF_Object* pAttrs, |
return pDict; |
return nullptr; |
} |
-CPDF_Object* CPDF_StructElementImpl::GetAttr(const CFX_ByteStringC& owner, |
- const CFX_ByteStringC& name, |
- bool bInheritable, |
- FX_FLOAT fLevel) { |
+CPDF_Object* CPDF_StructElement::GetAttr(const CFX_ByteStringC& owner, |
+ const CFX_ByteStringC& name, |
+ bool bInheritable, |
+ FX_FLOAT fLevel) { |
if (fLevel > nMaxRecursion) { |
return nullptr; |
} |
@@ -375,10 +375,10 @@ CPDF_Object* CPDF_StructElementImpl::GetAttr(const CFX_ByteStringC& owner, |
return pClassDict->GetDirectObjectFor(CFX_ByteString(name)); |
return nullptr; |
} |
-CPDF_Object* CPDF_StructElementImpl::GetAttr(const CFX_ByteStringC& owner, |
- const CFX_ByteStringC& name, |
- bool bInheritable, |
- int subindex) { |
+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) |
@@ -388,23 +388,22 @@ CPDF_Object* CPDF_StructElementImpl::GetAttr(const CFX_ByteStringC& owner, |
return pAttr; |
return pArray->GetDirectObjectAt(subindex); |
} |
-CFX_ByteString CPDF_StructElementImpl::GetName( |
- const CFX_ByteStringC& owner, |
- const CFX_ByteStringC& name, |
- const CFX_ByteStringC& default_value, |
- bool bInheritable, |
- int 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_StructElementImpl::GetColor(const CFX_ByteStringC& owner, |
- const CFX_ByteStringC& name, |
- FX_ARGB default_value, |
- bool bInheritable, |
- int subindex) { |
+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; |
@@ -412,19 +411,19 @@ FX_ARGB CPDF_StructElementImpl::GetColor(const CFX_ByteStringC& owner, |
((int)(pArray->GetNumberAt(1) * 255) << 8) | |
(int)(pArray->GetNumberAt(2) * 255); |
} |
-FX_FLOAT CPDF_StructElementImpl::GetNumber(const CFX_ByteStringC& owner, |
- const CFX_ByteStringC& name, |
- FX_FLOAT default_value, |
- bool bInheritable, |
- int subindex) { |
- CPDF_Object* pAttr = GetAttr(owner, name, bInheritable, subindex); |
- return ToNumber(pAttr) ? pAttr->GetNumber() : default_value; |
-} |
-int CPDF_StructElementImpl::GetInteger(const CFX_ByteStringC& owner, |
+FX_FLOAT CPDF_StructElement::GetNumber(const CFX_ByteStringC& owner, |
const CFX_ByteStringC& name, |
- int default_value, |
+ FX_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; |
} |