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 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 return TRUE; | 198 return TRUE; |
199 } | 199 } |
200 CPDF_StructElementImpl::CPDF_StructElementImpl(CPDF_StructTreeImpl* pTree, | 200 CPDF_StructElementImpl::CPDF_StructElementImpl(CPDF_StructTreeImpl* pTree, |
201 CPDF_StructElementImpl* pParent, | 201 CPDF_StructElementImpl* pParent, |
202 CPDF_Dictionary* pDict) | 202 CPDF_Dictionary* pDict) |
203 : m_RefCount(0) { | 203 : m_RefCount(0) { |
204 m_pTree = pTree; | 204 m_pTree = pTree; |
205 m_pDict = pDict; | 205 m_pDict = pDict; |
206 m_Type = pDict->GetStringBy("S"); | 206 m_Type = pDict->GetStringBy("S"); |
207 if (pTree->m_pRoleMap) { | 207 if (pTree->m_pRoleMap) { |
208 CFX_ByteString mapped = pTree->m_pRoleMap->GetStringBy(m_Type.AsStringC()); | 208 CFX_ByteString mapped = pTree->m_pRoleMap->GetStringBy(m_Type); |
209 if (!mapped.IsEmpty()) { | 209 if (!mapped.IsEmpty()) { |
210 m_Type = mapped; | 210 m_Type = mapped; |
211 } | 211 } |
212 } | 212 } |
213 m_pParent = pParent; | 213 m_pParent = pParent; |
214 LoadKids(pDict); | 214 LoadKids(pDict); |
215 } | 215 } |
216 CPDF_StructElementImpl::~CPDF_StructElementImpl() { | 216 CPDF_StructElementImpl::~CPDF_StructElementImpl() { |
217 for (int i = 0; i < m_Kids.GetSize(); i++) { | 217 for (int i = 0; i < m_Kids.GetSize(); i++) { |
218 if (m_Kids[i].m_Type == CPDF_StructKid::Element && | 218 if (m_Kids[i].m_Type == CPDF_StructKid::Element && |
(...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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 (uint32_t 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 = | 376 CPDF_Dictionary* pClassDict = pClassMap->GetDictBy(class_name); |
377 pClassMap->GetDictBy(class_name.AsStringC()); | |
378 if (pClassDict && pClassDict->GetStringBy("O") == owner) | 377 if (pClassDict && pClassDict->GetStringBy("O") == owner) |
379 return pClassDict->GetDirectObjectBy(name); | 378 return pClassDict->GetDirectObjectBy(name); |
380 } | 379 } |
381 return nullptr; | 380 return nullptr; |
382 } | 381 } |
383 CFX_ByteString class_name = pC->GetString(); | 382 CFX_ByteString class_name = pC->GetString(); |
384 CPDF_Dictionary* pClassDict = pClassMap->GetDictBy(class_name.AsStringC()); | 383 CPDF_Dictionary* pClassDict = pClassMap->GetDictBy(class_name); |
385 if (pClassDict && pClassDict->GetStringBy("O") == owner) | 384 if (pClassDict && pClassDict->GetStringBy("O") == owner) |
386 return pClassDict->GetDirectObjectBy(name); | 385 return pClassDict->GetDirectObjectBy(name); |
387 return nullptr; | 386 return nullptr; |
388 } | 387 } |
389 CPDF_Object* CPDF_StructElementImpl::GetAttr(const CFX_ByteStringC& owner, | 388 CPDF_Object* CPDF_StructElementImpl::GetAttr(const CFX_ByteStringC& owner, |
390 const CFX_ByteStringC& name, | 389 const CFX_ByteStringC& name, |
391 FX_BOOL bInheritable, | 390 FX_BOOL bInheritable, |
392 int subindex) { | 391 int subindex) { |
393 CPDF_Object* pAttr = GetAttr(owner, name, bInheritable); | 392 CPDF_Object* pAttr = GetAttr(owner, name, bInheritable); |
394 CPDF_Array* pArray = ToArray(pAttr); | 393 CPDF_Array* pArray = ToArray(pAttr); |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
432 return ToNumber(pAttr) ? pAttr->GetNumber() : default_value; | 431 return ToNumber(pAttr) ? pAttr->GetNumber() : default_value; |
433 } | 432 } |
434 int CPDF_StructElementImpl::GetInteger(const CFX_ByteStringC& owner, | 433 int CPDF_StructElementImpl::GetInteger(const CFX_ByteStringC& owner, |
435 const CFX_ByteStringC& name, | 434 const CFX_ByteStringC& name, |
436 int default_value, | 435 int default_value, |
437 FX_BOOL bInheritable, | 436 FX_BOOL bInheritable, |
438 int subindex) { | 437 int subindex) { |
439 CPDF_Object* pAttr = GetAttr(owner, name, bInheritable, subindex); | 438 CPDF_Object* pAttr = GetAttr(owner, name, bInheritable, subindex); |
440 return ToNumber(pAttr) ? pAttr->GetInteger() : default_value; | 439 return ToNumber(pAttr) ? pAttr->GetInteger() : default_value; |
441 } | 440 } |
OLD | NEW |