7#include "core/fpdfdoc/cpdf_structtree.h"
11#include "core/fpdfapi/parser/cpdf_array.h"
12#include "core/fpdfapi/parser/cpdf_dictionary.h"
13#include "core/fpdfapi/parser/cpdf_document.h"
14#include "core/fpdfapi/parser/cpdf_number.h"
15#include "core/fpdfapi/parser/cpdf_reference.h"
16#include "core/fpdfdoc/cpdf_numbertree.h"
17#include "core/fpdfdoc/cpdf_structelement.h"
22 RetainPtr<
const CPDF_Dictionary> pMarkInfo =
23 pDoc->GetRoot()->GetDictFor(
"MarkInfo");
24 return pMarkInfo && pMarkInfo->GetIntegerFor(
"Marked");
32 RetainPtr<
const CPDF_Dictionary> pPageDict) {
37 pTree->LoadPageTree(
std::move(pPageDict));
49 ByteString mapped = m_pRoleMap->GetNameFor(type);
57 m_pPage = std::move(pPageDict);
66 if (pKids->IsDictionary())
68 else if (
const CPDF_Array* pArray = pKids->AsArray())
69 kids_count = pArray->size();
74 m_Kids.resize(kids_count);
76 RetainPtr<
const CPDF_Dictionary> pParentTree =
77 m_pTreeRoot->GetDictFor(
"ParentTree");
82 int parents_id = m_pPage->GetIntegerFor(
"StructParents", -1);
86 RetainPtr<
const CPDF_Array> pParentArray =
87 ToArray(parent_tree.LookupValue(parents_id));
91 StructElementMap element_map;
92 for (size_t i = 0; i < pParentArray->size(); i++) {
93 RetainPtr<
const CPDF_Dictionary> pParent = pParentArray->GetDictAt(i);
95 AddPageNode(std::move(pParent), &element_map, 0);
101 StructElementMap* map,
103 static constexpr int kStructTreeMaxRecursion = 32;
104 if (nLevel > kStructTreeMaxRecursion)
107 auto it = map->find(pDict);
108 if (it != map->end())
111 RetainPtr<
const CPDF_Dictionary> key(pDict);
112 auto pElement = pdfium::MakeRetain<CPDF_StructElement>(
this, pDict);
113 (*map)[key] = pElement;
114 RetainPtr<
const CPDF_Dictionary> pParent = pDict->GetDictFor(
"P");
115 if (!pParent || pParent->GetNameFor(
"Type") ==
"StructTreeRoot") {
116 if (!AddTopLevelNode(pDict, pElement))
121 RetainPtr<CPDF_StructElement> pParentElement =
122 AddPageNode(std::move(pParent), map, nLevel + 1);
126 if (!pParentElement->UpdateKidIfElement(pDict, pElement.Get())) {
131 pElement->SetParent(pParentElement.Get());
136 const CPDF_Dictionary* pDict,
137 const RetainPtr<CPDF_StructElement>& pElement) {
142 if (pObj->IsDictionary()) {
145 m_Kids[0] = pElement;
148 const CPDF_Array* pTopKids = pObj->AsArray();
153 for (size_t i = 0; i < pTopKids->size(); i++) {
154 RetainPtr<
const CPDF_Reference> pKidRef =
155 ToReference(pTopKids->GetObjectAt(i));
156 if (pKidRef && pKidRef->GetRefObjNum() == pDict
->GetObjNum()) {
157 m_Kids[i] = pElement;
uint32_t GetObjNum() const
CPDF_StructTree(const CPDF_Document *pDoc)
ByteString GetRoleMapNameFor(const ByteString &type) const