Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(131)

Side by Side Diff: core/src/fpdfdoc/doc_tagged.cpp

Issue 1520063002: Get rid of most instance of 'foo == NULL' (Closed) Base URL: https://pdfium.googlesource.com/pdfium@bstr_isnull
Patch Set: rebase Created 5 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « core/src/fpdfdoc/doc_ocg.cpp ('k') | core/src/fpdfdoc/doc_utils.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "core/include/fpdfapi/fpdf_page.h" 7 #include "core/include/fpdfapi/fpdf_page.h"
8 #include "core/include/fpdfapi/fpdf_parser.h" 8 #include "core/include/fpdfapi/fpdf_parser.h"
9 #include "core/include/fpdfdoc/fpdf_tagged.h" 9 #include "core/include/fpdfdoc/fpdf_tagged.h"
10 #include "tagged_int.h" 10 #include "tagged_int.h"
(...skipping 17 matching lines...) Expand all
28 if (!IsTagged(pDoc)) { 28 if (!IsTagged(pDoc)) {
29 return NULL; 29 return NULL;
30 } 30 }
31 CPDF_StructTreeImpl* pTree = new CPDF_StructTreeImpl(pDoc); 31 CPDF_StructTreeImpl* pTree = new CPDF_StructTreeImpl(pDoc);
32 pTree->LoadDocTree(); 32 pTree->LoadDocTree();
33 return pTree; 33 return pTree;
34 } 34 }
35 CPDF_StructTreeImpl::CPDF_StructTreeImpl(const CPDF_Document* pDoc) { 35 CPDF_StructTreeImpl::CPDF_StructTreeImpl(const CPDF_Document* pDoc) {
36 CPDF_Dictionary* pCatalog = pDoc->GetRoot(); 36 CPDF_Dictionary* pCatalog = pDoc->GetRoot();
37 m_pTreeRoot = pCatalog->GetDict("StructTreeRoot"); 37 m_pTreeRoot = pCatalog->GetDict("StructTreeRoot");
38 if (m_pTreeRoot == NULL) { 38 if (!m_pTreeRoot) {
39 return; 39 return;
40 } 40 }
41 m_pRoleMap = m_pTreeRoot->GetDict("RoleMap"); 41 m_pRoleMap = m_pTreeRoot->GetDict("RoleMap");
42 } 42 }
43 CPDF_StructTreeImpl::~CPDF_StructTreeImpl() { 43 CPDF_StructTreeImpl::~CPDF_StructTreeImpl() {
44 for (int i = 0; i < m_Kids.GetSize(); i++) 44 for (int i = 0; i < m_Kids.GetSize(); i++)
45 if (m_Kids[i]) { 45 if (m_Kids[i]) {
46 m_Kids[i]->Release(); 46 m_Kids[i]->Release();
47 } 47 }
48 } 48 }
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
88 else 88 else
89 return; 89 return;
90 90
91 FX_DWORD i; 91 FX_DWORD i;
92 m_Kids.SetSize(dwKids); 92 m_Kids.SetSize(dwKids);
93 for (i = 0; i < dwKids; i++) { 93 for (i = 0; i < dwKids; i++) {
94 m_Kids[i] = NULL; 94 m_Kids[i] = NULL;
95 } 95 }
96 CFX_MapPtrToPtr element_map; 96 CFX_MapPtrToPtr element_map;
97 CPDF_Dictionary* pParentTree = m_pTreeRoot->GetDict("ParentTree"); 97 CPDF_Dictionary* pParentTree = m_pTreeRoot->GetDict("ParentTree");
98 if (pParentTree == NULL) { 98 if (!pParentTree) {
99 return; 99 return;
100 } 100 }
101 CPDF_NumberTree parent_tree(pParentTree); 101 CPDF_NumberTree parent_tree(pParentTree);
102 int parents_id = pPageDict->GetInteger("StructParents", -1); 102 int parents_id = pPageDict->GetInteger("StructParents", -1);
103 if (parents_id >= 0) { 103 if (parents_id >= 0) {
104 CPDF_Array* pParentArray = ToArray(parent_tree.LookupValue(parents_id)); 104 CPDF_Array* pParentArray = ToArray(parent_tree.LookupValue(parents_id));
105 if (!pParentArray) 105 if (!pParentArray)
106 return; 106 return;
107 107
108 for (i = 0; i < pParentArray->GetCount(); i++) { 108 for (i = 0; i < pParentArray->GetCount(); i++) {
109 CPDF_Dictionary* pParent = pParentArray->GetDict(i); 109 CPDF_Dictionary* pParent = pParentArray->GetDict(i);
110 if (pParent == NULL) { 110 if (!pParent) {
111 continue; 111 continue;
112 } 112 }
113 AddPageNode(pParent, element_map); 113 AddPageNode(pParent, element_map);
114 } 114 }
115 } 115 }
116 } 116 }
117 CPDF_StructElementImpl* CPDF_StructTreeImpl::AddPageNode(CPDF_Dictionary* pDict, 117 CPDF_StructElementImpl* CPDF_StructTreeImpl::AddPageNode(CPDF_Dictionary* pDict,
118 CFX_MapPtrToPtr& map, 118 CFX_MapPtrToPtr& map,
119 int nLevel) { 119 int nLevel) {
120 if (nLevel > nMaxRecursion) { 120 if (nLevel > nMaxRecursion) {
121 return NULL; 121 return NULL;
122 } 122 }
123 CPDF_StructElementImpl* pElement = NULL; 123 CPDF_StructElementImpl* pElement = NULL;
124 if (map.Lookup(pDict, (void*&)pElement)) { 124 if (map.Lookup(pDict, (void*&)pElement)) {
125 return pElement; 125 return pElement;
126 } 126 }
127 pElement = new CPDF_StructElementImpl(this, NULL, pDict); 127 pElement = new CPDF_StructElementImpl(this, NULL, pDict);
128 map.SetAt(pDict, pElement); 128 map.SetAt(pDict, pElement);
129 CPDF_Dictionary* pParent = pDict->GetDict("P"); 129 CPDF_Dictionary* pParent = pDict->GetDict("P");
130 if (pParent == NULL || pParent->GetString("Type") == "StructTreeRoot") { 130 if (!pParent || pParent->GetString("Type") == "StructTreeRoot") {
131 if (!AddTopLevelNode(pDict, pElement)) { 131 if (!AddTopLevelNode(pDict, pElement)) {
132 pElement->Release(); 132 pElement->Release();
133 map.RemoveKey(pDict); 133 map.RemoveKey(pDict);
134 } 134 }
135 } else { 135 } else {
136 CPDF_StructElementImpl* pParentElement = 136 CPDF_StructElementImpl* pParentElement =
137 AddPageNode(pParent, map, nLevel + 1); 137 AddPageNode(pParent, map, nLevel + 1);
138 FX_BOOL bSave = FALSE; 138 FX_BOOL bSave = FALSE;
139 for (int i = 0; i < pParentElement->m_Kids.GetSize(); i++) { 139 for (int i = 0; i < pParentElement->m_Kids.GetSize(); i++) {
140 if (pParentElement->m_Kids[i].m_Type != CPDF_StructKid::Element) { 140 if (pParentElement->m_Kids[i].m_Type != CPDF_StructKid::Element) {
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after
287 pKid->m_Type = CPDF_StructKid::Object; 287 pKid->m_Type = CPDF_StructKid::Object;
288 if (CPDF_Reference* pObj = ToReference(pKidDict->GetElement("Obj"))) { 288 if (CPDF_Reference* pObj = ToReference(pKidDict->GetElement("Obj"))) {
289 pKid->m_Object.m_RefObjNum = pObj->GetRefObjNum(); 289 pKid->m_Object.m_RefObjNum = pObj->GetRefObjNum();
290 } else { 290 } else {
291 pKid->m_Object.m_RefObjNum = 0; 291 pKid->m_Object.m_RefObjNum = 0;
292 } 292 }
293 pKid->m_Object.m_PageObjNum = PageObjNum; 293 pKid->m_Object.m_PageObjNum = PageObjNum;
294 } else { 294 } else {
295 pKid->m_Type = CPDF_StructKid::Element; 295 pKid->m_Type = CPDF_StructKid::Element;
296 pKid->m_Element.m_pDict = pKidDict; 296 pKid->m_Element.m_pDict = pKidDict;
297 if (m_pTree->m_pPage == NULL) { 297 if (!m_pTree->m_pPage) {
298 pKid->m_Element.m_pElement = 298 pKid->m_Element.m_pElement =
299 new CPDF_StructElementImpl(m_pTree, this, pKidDict); 299 new CPDF_StructElementImpl(m_pTree, this, pKidDict);
300 } else { 300 } else {
301 pKid->m_Element.m_pElement = NULL; 301 pKid->m_Element.m_pElement = NULL;
302 } 302 }
303 } 303 }
304 } 304 }
305 static CPDF_Dictionary* FindAttrDict(CPDF_Object* pAttrs, 305 static CPDF_Dictionary* FindAttrDict(CPDF_Object* pAttrs,
306 const CFX_ByteStringC& owner, 306 const CFX_ByteStringC& owner,
307 FX_FLOAT nLevel = 0.0F) { 307 FX_FLOAT nLevel = 0.0F) {
(...skipping 24 matching lines...) Expand all
332 FX_BOOL bInheritable, 332 FX_BOOL bInheritable,
333 FX_FLOAT fLevel) { 333 FX_FLOAT fLevel) {
334 if (fLevel > nMaxRecursion) { 334 if (fLevel > nMaxRecursion) {
335 return NULL; 335 return NULL;
336 } 336 }
337 if (bInheritable) { 337 if (bInheritable) {
338 CPDF_Object* pAttr = GetAttr(owner, name, FALSE); 338 CPDF_Object* pAttr = GetAttr(owner, name, FALSE);
339 if (pAttr) { 339 if (pAttr) {
340 return pAttr; 340 return pAttr;
341 } 341 }
342 if (m_pParent == NULL) { 342 if (!m_pParent) {
343 return NULL; 343 return NULL;
344 } 344 }
345 return m_pParent->GetAttr(owner, name, TRUE, fLevel + 1); 345 return m_pParent->GetAttr(owner, name, TRUE, fLevel + 1);
346 } 346 }
347 CPDF_Object* pA = m_pDict->GetElementValue("A"); 347 CPDF_Object* pA = m_pDict->GetElementValue("A");
348 if (pA) { 348 if (pA) {
349 CPDF_Dictionary* pAttrDict = FindAttrDict(pA, owner); 349 CPDF_Dictionary* pAttrDict = FindAttrDict(pA, owner);
350 if (pAttrDict) { 350 if (pAttrDict) {
351 CPDF_Object* pAttr = pAttrDict->GetElementValue(name); 351 CPDF_Object* pAttr = pAttrDict->GetElementValue(name);
352 if (pAttr) { 352 if (pAttr) {
(...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after
423 return ToNumber(pAttr) ? pAttr->GetNumber() : default_value; 423 return ToNumber(pAttr) ? pAttr->GetNumber() : default_value;
424 } 424 }
425 int CPDF_StructElementImpl::GetInteger(const CFX_ByteStringC& owner, 425 int CPDF_StructElementImpl::GetInteger(const CFX_ByteStringC& owner,
426 const CFX_ByteStringC& name, 426 const CFX_ByteStringC& name,
427 int default_value, 427 int default_value,
428 FX_BOOL bInheritable, 428 FX_BOOL bInheritable,
429 int subindex) { 429 int subindex) {
430 CPDF_Object* pAttr = GetAttr(owner, name, bInheritable, subindex); 430 CPDF_Object* pAttr = GetAttr(owner, name, bInheritable, subindex);
431 return ToNumber(pAttr) ? pAttr->GetInteger() : default_value; 431 return ToNumber(pAttr) ? pAttr->GetInteger() : default_value;
432 } 432 }
OLDNEW
« no previous file with comments | « core/src/fpdfdoc/doc_ocg.cpp ('k') | core/src/fpdfdoc/doc_utils.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698