OLD | NEW |
1 // Copyright 2014 PDFium Authors. All rights reserved. | 1 // Copyright 2014 PDFium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com |
6 | 6 |
7 #include <map> | 7 #include <map> |
8 | 8 |
9 #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" | 9 #include "core/fpdfapi/fpdf_parser/include/cpdf_array.h" |
10 #include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h" | 10 #include "core/fpdfapi/fpdf_parser/include/cpdf_dictionary.h" |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
63 if (CPDF_Dictionary* pDict = pKids->AsDictionary()) { | 63 if (CPDF_Dictionary* pDict = pKids->AsDictionary()) { |
64 CPDF_StructElementImpl* pStructElementImpl = | 64 CPDF_StructElementImpl* pStructElementImpl = |
65 new CPDF_StructElementImpl(this, nullptr, pDict); | 65 new CPDF_StructElementImpl(this, nullptr, pDict); |
66 m_Kids.Add(pStructElementImpl); | 66 m_Kids.Add(pStructElementImpl); |
67 return; | 67 return; |
68 } | 68 } |
69 CPDF_Array* pArray = pKids->AsArray(); | 69 CPDF_Array* pArray = pKids->AsArray(); |
70 if (!pArray) | 70 if (!pArray) |
71 return; | 71 return; |
72 | 72 |
73 for (FX_DWORD i = 0; i < pArray->GetCount(); i++) { | 73 for (uint32_t i = 0; i < pArray->GetCount(); i++) { |
74 CPDF_Dictionary* pKid = pArray->GetDictAt(i); | 74 CPDF_Dictionary* pKid = pArray->GetDictAt(i); |
75 CPDF_StructElementImpl* pStructElementImpl = | 75 CPDF_StructElementImpl* pStructElementImpl = |
76 new CPDF_StructElementImpl(this, nullptr, pKid); | 76 new CPDF_StructElementImpl(this, nullptr, pKid); |
77 m_Kids.Add(pStructElementImpl); | 77 m_Kids.Add(pStructElementImpl); |
78 } | 78 } |
79 } | 79 } |
80 void CPDF_StructTreeImpl::LoadPageTree(const CPDF_Dictionary* pPageDict) { | 80 void CPDF_StructTreeImpl::LoadPageTree(const CPDF_Dictionary* pPageDict) { |
81 m_pPage = pPageDict; | 81 m_pPage = pPageDict; |
82 if (!m_pTreeRoot) | 82 if (!m_pTreeRoot) |
83 return; | 83 return; |
84 | 84 |
85 CPDF_Object* pKids = m_pTreeRoot->GetElementValue("K"); | 85 CPDF_Object* pKids = m_pTreeRoot->GetElementValue("K"); |
86 if (!pKids) | 86 if (!pKids) |
87 return; | 87 return; |
88 | 88 |
89 FX_DWORD dwKids = 0; | 89 uint32_t dwKids = 0; |
90 if (pKids->IsDictionary()) | 90 if (pKids->IsDictionary()) |
91 dwKids = 1; | 91 dwKids = 1; |
92 else if (CPDF_Array* pArray = pKids->AsArray()) | 92 else if (CPDF_Array* pArray = pKids->AsArray()) |
93 dwKids = pArray->GetCount(); | 93 dwKids = pArray->GetCount(); |
94 else | 94 else |
95 return; | 95 return; |
96 | 96 |
97 FX_DWORD i; | 97 uint32_t i; |
98 m_Kids.SetSize(dwKids); | 98 m_Kids.SetSize(dwKids); |
99 for (i = 0; i < dwKids; i++) { | 99 for (i = 0; i < dwKids; i++) { |
100 m_Kids[i] = NULL; | 100 m_Kids[i] = NULL; |
101 } | 101 } |
102 std::map<CPDF_Dictionary*, CPDF_StructElementImpl*> element_map; | 102 std::map<CPDF_Dictionary*, CPDF_StructElementImpl*> element_map; |
103 CPDF_Dictionary* pParentTree = m_pTreeRoot->GetDictBy("ParentTree"); | 103 CPDF_Dictionary* pParentTree = m_pTreeRoot->GetDictBy("ParentTree"); |
104 if (!pParentTree) { | 104 if (!pParentTree) { |
105 return; | 105 return; |
106 } | 106 } |
107 CPDF_NumberTree parent_tree(pParentTree); | 107 CPDF_NumberTree parent_tree(pParentTree); |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 if (pObj->GetObjNum() == pDict->GetObjNum()) { | 171 if (pObj->GetObjNum() == pDict->GetObjNum()) { |
172 if (m_Kids[0]) { | 172 if (m_Kids[0]) { |
173 m_Kids[0]->Release(); | 173 m_Kids[0]->Release(); |
174 } | 174 } |
175 m_Kids[0] = pElement->Retain(); | 175 m_Kids[0] = pElement->Retain(); |
176 } else { | 176 } else { |
177 return FALSE; | 177 return FALSE; |
178 } | 178 } |
179 } | 179 } |
180 if (CPDF_Array* pTopKids = pObj->AsArray()) { | 180 if (CPDF_Array* pTopKids = pObj->AsArray()) { |
181 FX_DWORD i; | 181 uint32_t i; |
182 FX_BOOL bSave = FALSE; | 182 FX_BOOL bSave = FALSE; |
183 for (i = 0; i < pTopKids->GetCount(); i++) { | 183 for (i = 0; i < pTopKids->GetCount(); i++) { |
184 CPDF_Reference* pKidRef = ToReference(pTopKids->GetElement(i)); | 184 CPDF_Reference* pKidRef = ToReference(pTopKids->GetElement(i)); |
185 if (!pKidRef) | 185 if (!pKidRef) |
186 continue; | 186 continue; |
187 if (pKidRef->GetRefObjNum() != pDict->GetObjNum()) | 187 if (pKidRef->GetRefObjNum() != pDict->GetObjNum()) |
188 continue; | 188 continue; |
189 | 189 |
190 if (m_Kids[i]) | 190 if (m_Kids[i]) |
191 m_Kids[i]->Release(); | 191 m_Kids[i]->Release(); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 m_RefCount++; | 225 m_RefCount++; |
226 return this; | 226 return this; |
227 } | 227 } |
228 void CPDF_StructElementImpl::Release() { | 228 void CPDF_StructElementImpl::Release() { |
229 if (--m_RefCount < 1) { | 229 if (--m_RefCount < 1) { |
230 delete this; | 230 delete this; |
231 } | 231 } |
232 } | 232 } |
233 void CPDF_StructElementImpl::LoadKids(CPDF_Dictionary* pDict) { | 233 void CPDF_StructElementImpl::LoadKids(CPDF_Dictionary* pDict) { |
234 CPDF_Object* pObj = pDict->GetElement("Pg"); | 234 CPDF_Object* pObj = pDict->GetElement("Pg"); |
235 FX_DWORD PageObjNum = 0; | 235 uint32_t PageObjNum = 0; |
236 if (CPDF_Reference* pRef = ToReference(pObj)) | 236 if (CPDF_Reference* pRef = ToReference(pObj)) |
237 PageObjNum = pRef->GetRefObjNum(); | 237 PageObjNum = pRef->GetRefObjNum(); |
238 | 238 |
239 CPDF_Object* pKids = pDict->GetElementValue("K"); | 239 CPDF_Object* pKids = pDict->GetElementValue("K"); |
240 if (!pKids) | 240 if (!pKids) |
241 return; | 241 return; |
242 | 242 |
243 if (CPDF_Array* pArray = pKids->AsArray()) { | 243 if (CPDF_Array* pArray = pKids->AsArray()) { |
244 m_Kids.SetSize(pArray->GetCount()); | 244 m_Kids.SetSize(pArray->GetCount()); |
245 for (FX_DWORD i = 0; i < pArray->GetCount(); i++) { | 245 for (uint32_t i = 0; i < pArray->GetCount(); i++) { |
246 CPDF_Object* pKid = pArray->GetElementValue(i); | 246 CPDF_Object* pKid = pArray->GetElementValue(i); |
247 LoadKid(PageObjNum, pKid, &m_Kids[i]); | 247 LoadKid(PageObjNum, pKid, &m_Kids[i]); |
248 } | 248 } |
249 } else { | 249 } else { |
250 m_Kids.SetSize(1); | 250 m_Kids.SetSize(1); |
251 LoadKid(PageObjNum, pKids, &m_Kids[0]); | 251 LoadKid(PageObjNum, pKids, &m_Kids[0]); |
252 } | 252 } |
253 } | 253 } |
254 void CPDF_StructElementImpl::LoadKid(FX_DWORD PageObjNum, | 254 void CPDF_StructElementImpl::LoadKid(uint32_t PageObjNum, |
255 CPDF_Object* pKidObj, | 255 CPDF_Object* pKidObj, |
256 CPDF_StructKid* pKid) { | 256 CPDF_StructKid* pKid) { |
257 pKid->m_Type = CPDF_StructKid::Invalid; | 257 pKid->m_Type = CPDF_StructKid::Invalid; |
258 if (!pKidObj) | 258 if (!pKidObj) |
259 return; | 259 return; |
260 | 260 |
261 if (pKidObj->IsNumber()) { | 261 if (pKidObj->IsNumber()) { |
262 if (m_pTree->m_pPage && m_pTree->m_pPage->GetObjNum() != PageObjNum) { | 262 if (m_pTree->m_pPage && m_pTree->m_pPage->GetObjNum() != PageObjNum) { |
263 return; | 263 return; |
264 } | 264 } |
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
317 return nullptr; | 317 return nullptr; |
318 if (!pAttrs) | 318 if (!pAttrs) |
319 return nullptr; | 319 return nullptr; |
320 | 320 |
321 CPDF_Dictionary* pDict = nullptr; | 321 CPDF_Dictionary* pDict = nullptr; |
322 if (pAttrs->IsDictionary()) { | 322 if (pAttrs->IsDictionary()) { |
323 pDict = pAttrs->AsDictionary(); | 323 pDict = pAttrs->AsDictionary(); |
324 } else if (CPDF_Stream* pStream = pAttrs->AsStream()) { | 324 } else if (CPDF_Stream* pStream = pAttrs->AsStream()) { |
325 pDict = pStream->GetDict(); | 325 pDict = pStream->GetDict(); |
326 } else if (CPDF_Array* pArray = pAttrs->AsArray()) { | 326 } else if (CPDF_Array* pArray = pAttrs->AsArray()) { |
327 for (FX_DWORD i = 0; i < pArray->GetCount(); i++) { | 327 for (uint32_t i = 0; i < pArray->GetCount(); i++) { |
328 CPDF_Object* pElement = pArray->GetElementValue(i); | 328 CPDF_Object* pElement = pArray->GetElementValue(i); |
329 pDict = FindAttrDict(pElement, owner, nLevel + 1); | 329 pDict = FindAttrDict(pElement, owner, nLevel + 1); |
330 if (pDict) | 330 if (pDict) |
331 return pDict; | 331 return pDict; |
332 } | 332 } |
333 } | 333 } |
334 if (pDict && pDict->GetStringBy("O") == owner) | 334 if (pDict && pDict->GetStringBy("O") == owner) |
335 return pDict; | 335 return pDict; |
336 return nullptr; | 336 return nullptr; |
337 } | 337 } |
(...skipping 26 matching lines...) Expand all Loading... |
364 } | 364 } |
365 CPDF_Object* pC = m_pDict->GetElementValue("C"); | 365 CPDF_Object* pC = m_pDict->GetElementValue("C"); |
366 if (!pC) | 366 if (!pC) |
367 return nullptr; | 367 return nullptr; |
368 | 368 |
369 CPDF_Dictionary* pClassMap = m_pTree->m_pTreeRoot->GetDictBy("ClassMap"); | 369 CPDF_Dictionary* pClassMap = m_pTree->m_pTreeRoot->GetDictBy("ClassMap"); |
370 if (!pClassMap) | 370 if (!pClassMap) |
371 return nullptr; | 371 return nullptr; |
372 | 372 |
373 if (CPDF_Array* pArray = pC->AsArray()) { | 373 if (CPDF_Array* pArray = pC->AsArray()) { |
374 for (FX_DWORD i = 0; i < pArray->GetCount(); i++) { | 374 for (uint32_t i = 0; i < pArray->GetCount(); i++) { |
375 CFX_ByteString class_name = pArray->GetStringAt(i); | 375 CFX_ByteString class_name = pArray->GetStringAt(i); |
376 CPDF_Dictionary* pClassDict = pClassMap->GetDictBy(class_name); | 376 CPDF_Dictionary* pClassDict = pClassMap->GetDictBy(class_name); |
377 if (pClassDict && pClassDict->GetStringBy("O") == owner) | 377 if (pClassDict && pClassDict->GetStringBy("O") == owner) |
378 return pClassDict->GetElementValue(name); | 378 return pClassDict->GetElementValue(name); |
379 } | 379 } |
380 return nullptr; | 380 return nullptr; |
381 } | 381 } |
382 CFX_ByteString class_name = pC->GetString(); | 382 CFX_ByteString class_name = pC->GetString(); |
383 CPDF_Dictionary* pClassDict = pClassMap->GetDictBy(class_name); | 383 CPDF_Dictionary* pClassDict = pClassMap->GetDictBy(class_name); |
384 if (pClassDict && pClassDict->GetStringBy("O") == owner) | 384 if (pClassDict && pClassDict->GetStringBy("O") == owner) |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
431 return ToNumber(pAttr) ? pAttr->GetNumber() : default_value; | 431 return ToNumber(pAttr) ? pAttr->GetNumber() : default_value; |
432 } | 432 } |
433 int CPDF_StructElementImpl::GetInteger(const CFX_ByteStringC& owner, | 433 int CPDF_StructElementImpl::GetInteger(const CFX_ByteStringC& owner, |
434 const CFX_ByteStringC& name, | 434 const CFX_ByteStringC& name, |
435 int default_value, | 435 int default_value, |
436 FX_BOOL bInheritable, | 436 FX_BOOL bInheritable, |
437 int subindex) { | 437 int subindex) { |
438 CPDF_Object* pAttr = GetAttr(owner, name, bInheritable, subindex); | 438 CPDF_Object* pAttr = GetAttr(owner, name, bInheritable, subindex); |
439 return ToNumber(pAttr) ? pAttr->GetInteger() : default_value; | 439 return ToNumber(pAttr) ? pAttr->GetInteger() : default_value; |
440 } | 440 } |
OLD | NEW |