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

Side by Side Diff: core/src/fpdfapi/fpdf_parser/fpdf_parser_objects.cpp

Issue 1243953004: Re-land else-after-returns (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Created 5 years, 5 months 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
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 "../../../include/fpdfapi/fpdf_parser.h" 7 #include "../../../include/fpdfapi/fpdf_parser.h"
8 #include "../../../include/fxcrt/fx_string.h" 8 #include "../../../include/fxcrt/fx_string.h"
9 9
10 //static 10 //static
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
153 } 153 }
154 return pObj->GetDict(); 154 return pObj->GetDict();
155 } 155 }
156 } 156 }
157 return NULL; 157 return NULL;
158 } 158 }
159 CPDF_Array* CPDF_Object::GetArray() const 159 CPDF_Array* CPDF_Object::GetArray() const
160 { 160 {
161 if (m_Type == PDFOBJ_ARRAY) 161 if (m_Type == PDFOBJ_ARRAY)
162 return (CPDF_Array*)this; 162 return (CPDF_Array*)this;
163 else 163
164 return NULL; 164 return NULL;
165 } 165 }
166 void CPDF_Object::SetString(const CFX_ByteString& str) 166 void CPDF_Object::SetString(const CFX_ByteString& str)
167 { 167 {
168 ASSERT(this != NULL); 168 ASSERT(this != NULL);
169 switch (m_Type) { 169 switch (m_Type) {
170 case PDFOBJ_BOOLEAN: 170 case PDFOBJ_BOOLEAN:
171 ((CPDF_Boolean*)this)->m_bValue = str == FX_BSTRC("true") ? 1 : 0; 171 ((CPDF_Boolean*)this)->m_bValue = str == FX_BSTRC("true") ? 1 : 0;
172 return; 172 return;
173 case PDFOBJ_NUMBER: 173 case PDFOBJ_NUMBER:
174 ((CPDF_Number*)this)->SetString(str); 174 ((CPDF_Number*)this)->SetString(str);
(...skipping 19 matching lines...) Expand all
194 { 194 {
195 if (this == pOther) { 195 if (this == pOther) {
196 return TRUE; 196 return TRUE;
197 } 197 }
198 if (pOther == NULL) { 198 if (pOther == NULL) {
199 return FALSE; 199 return FALSE;
200 } 200 }
201 if (pOther->m_Type != m_Type) { 201 if (pOther->m_Type != m_Type) {
202 if (m_Type == PDFOBJ_REFERENCE && GetDirect()) { 202 if (m_Type == PDFOBJ_REFERENCE && GetDirect()) {
203 return GetDirect()->IsIdentical(pOther); 203 return GetDirect()->IsIdentical(pOther);
204 } else if (pOther->m_Type == PDFOBJ_REFERENCE) { 204 }
205 if (pOther->m_Type == PDFOBJ_REFERENCE) {
205 return IsIdentical(pOther->GetDirect()); 206 return IsIdentical(pOther->GetDirect());
206 } 207 }
207 return FALSE; 208 return FALSE;
208 } 209 }
209 switch (m_Type) { 210 switch (m_Type) {
210 case PDFOBJ_BOOLEAN: 211 case PDFOBJ_BOOLEAN:
211 return (((CPDF_Boolean*)this)->Identical((CPDF_Boolean*)pOther)); 212 return (((CPDF_Boolean*)this)->Identical((CPDF_Boolean*)pOther));
212 case PDFOBJ_NUMBER: 213 case PDFOBJ_NUMBER:
213 return (((CPDF_Number*)this)->Identical((CPDF_Number*)pOther)); 214 return (((CPDF_Number*)this)->Identical((CPDF_Number*)pOther));
214 case PDFOBJ_STRING: 215 case PDFOBJ_STRING:
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
278 return pCopy; 279 return pCopy;
279 } 280 }
280 case PDFOBJ_NULL: { 281 case PDFOBJ_NULL: {
281 return new CPDF_Null; 282 return new CPDF_Null;
282 } 283 }
283 case PDFOBJ_STREAM: { 284 case PDFOBJ_STREAM: {
284 CPDF_Stream* pThis = (CPDF_Stream*)this; 285 CPDF_Stream* pThis = (CPDF_Stream*)this;
285 CPDF_StreamAcc acc; 286 CPDF_StreamAcc acc;
286 acc.LoadAllData(pThis, TRUE); 287 acc.LoadAllData(pThis, TRUE);
287 FX_DWORD streamSize = acc.GetSize(); 288 FX_DWORD streamSize = acc.GetSize();
288 CPDF_Stream* pObj; 289 CPDF_Dictionary* pDict = pThis->GetDict();
289 if (pThis->GetDict()) 290 if (pDict)
290 pObj = new CPDF_Stream(acc.DetachData(), streamSize, (CPDF_D ictionary*)((CPDF_Object*)pThis->GetDict())->CloneInternal(bDirect, visited)); 291 pDict = (CPDF_Dictionary*)((CPDF_Object*)pDict)->CloneIntern al(bDirect, visited);
291 else 292 return new CPDF_Stream(acc.DetachData(), streamSize, pDict);
292 pObj = new CPDF_Stream(acc.DetachData(), streamSize, NULL);
293 return pObj;
294 } 293 }
295 case PDFOBJ_REFERENCE: { 294 case PDFOBJ_REFERENCE: {
296 CPDF_Reference* pRef = (CPDF_Reference*)this; 295 CPDF_Reference* pRef = (CPDF_Reference*)this;
297 FX_DWORD obj_num = pRef->m_RefObjNum; 296 FX_DWORD obj_num = pRef->m_RefObjNum;
298 if (bDirect && !visited->GetValueAt((void*)(uintptr_t)obj_num)) { 297 if (bDirect && !visited->GetValueAt((void*)(uintptr_t)obj_num)) {
299 visited->SetAt((void*)(uintptr_t)obj_num, (void*)1); 298 visited->SetAt((void*)(uintptr_t)obj_num, (void*)1);
300 CPDF_Object* ret; 299 if (!pRef->GetDirect())
301 if (pRef->GetDirect()) 300 return nullptr;
302 ret = pRef->GetDirect()->CloneInternal(TRUE, visited); 301
303 else 302 return pRef->GetDirect()->CloneInternal(TRUE, visited);
304 ret = NULL;
305 return ret;
306 } else {
307 return new CPDF_Reference(pRef->m_pObjList, obj_num);
308 } 303 }
304 return new CPDF_Reference(pRef->m_pObjList, obj_num);
309 } 305 }
310 } 306 }
311 return NULL; 307 return NULL;
312 } 308 }
313 CPDF_Object* CPDF_Object::CloneRef(CPDF_IndirectObjects* pDoc) const 309 CPDF_Object* CPDF_Object::CloneRef(CPDF_IndirectObjects* pDoc) const
314 { 310 {
315 if (m_ObjNum) { 311 if (m_ObjNum) {
316 return new CPDF_Reference(pDoc, m_ObjNum); 312 return new CPDF_Reference(pDoc, m_ObjNum);
317 } 313 }
318 return Clone(); 314 return Clone();
319 } 315 }
320 CFX_WideString CPDF_Object::GetUnicodeText(CFX_CharMap* pCharMap) const 316 CFX_WideString CPDF_Object::GetUnicodeText(CFX_CharMap* pCharMap) const
321 { 317 {
322 if (m_Type == PDFOBJ_STRING) { 318 if (m_Type == PDFOBJ_STRING) {
323 return PDF_DecodeText(((CPDF_String*)this)->m_String, pCharMap); 319 return PDF_DecodeText(((CPDF_String*)this)->m_String, pCharMap);
324 } else if (m_Type == PDFOBJ_STREAM) { 320 }
321 if (m_Type == PDFOBJ_STREAM) {
325 CPDF_StreamAcc stream; 322 CPDF_StreamAcc stream;
326 stream.LoadAllData((CPDF_Stream*)this, FALSE); 323 stream.LoadAllData((CPDF_Stream*)this, FALSE);
327 CFX_WideString result = PDF_DecodeText(stream.GetData(), stream.GetSize( ), pCharMap); 324 CFX_WideString result = PDF_DecodeText(stream.GetData(), stream.GetSize( ), pCharMap);
328 return result; 325 return result;
329 } else if (m_Type == PDFOBJ_NAME) { 326 }
327 if (m_Type == PDFOBJ_NAME) {
330 return PDF_DecodeText(((CPDF_Name*)this)->m_Name, pCharMap); 328 return PDF_DecodeText(((CPDF_Name*)this)->m_Name, pCharMap);
331 } 329 }
332 return CFX_WideString(); 330 return CFX_WideString();
333 } 331 }
334 void CPDF_Object::SetUnicodeText(const FX_WCHAR* pUnicodes, int len) 332 void CPDF_Object::SetUnicodeText(const FX_WCHAR* pUnicodes, int len)
335 { 333 {
336 if (m_Type == PDFOBJ_STRING) { 334 if (m_Type == PDFOBJ_STRING) {
337 ((CPDF_String*)this)->m_String = PDF_EncodeText(pUnicodes, len); 335 ((CPDF_String*)this)->m_String = PDF_EncodeText(pUnicodes, len);
338 } else if (m_Type == PDFOBJ_STREAM) { 336 } else if (m_Type == PDFOBJ_STREAM) {
339 CFX_ByteString result = PDF_EncodeText(pUnicodes, len); 337 CFX_ByteString result = PDF_EncodeText(pUnicodes, len);
(...skipping 80 matching lines...) Expand 10 before | Expand all | Expand 10 after
420 return NULL; 418 return NULL;
421 } 419 }
422 return ((CPDF_Object*)m_Objects.GetAt(i))->GetDirect(); 420 return ((CPDF_Object*)m_Objects.GetAt(i))->GetDirect();
423 } 421 }
424 CFX_ByteString CPDF_Array::GetString(FX_DWORD i) const 422 CFX_ByteString CPDF_Array::GetString(FX_DWORD i) const
425 { 423 {
426 if (i < (FX_DWORD)m_Objects.GetSize()) { 424 if (i < (FX_DWORD)m_Objects.GetSize()) {
427 CPDF_Object* p = (CPDF_Object*)m_Objects.GetAt(i); 425 CPDF_Object* p = (CPDF_Object*)m_Objects.GetAt(i);
428 return p->GetString(); 426 return p->GetString();
429 } 427 }
430 else 428 return CFX_ByteString();
431 return CFX_ByteString();
432 } 429 }
433 CFX_ByteStringC CPDF_Array::GetConstString(FX_DWORD i) const 430 CFX_ByteStringC CPDF_Array::GetConstString(FX_DWORD i) const
434 { 431 {
435 if (i < (FX_DWORD)m_Objects.GetSize()) { 432 if (i < (FX_DWORD)m_Objects.GetSize()) {
436 CPDF_Object* p = (CPDF_Object*)m_Objects.GetAt(i); 433 CPDF_Object* p = (CPDF_Object*)m_Objects.GetAt(i);
437 return p->GetConstString(); 434 return p->GetConstString();
438 } 435 }
439 else 436 return CFX_ByteStringC();
440 return CFX_ByteStringC();
441 } 437 }
442 int CPDF_Array::GetInteger(FX_DWORD i) const 438 int CPDF_Array::GetInteger(FX_DWORD i) const
443 { 439 {
444 if (i >= (FX_DWORD)m_Objects.GetSize()) { 440 if (i >= (FX_DWORD)m_Objects.GetSize()) {
445 return 0; 441 return 0;
446 } 442 }
447 CPDF_Object* p = (CPDF_Object*)m_Objects.GetAt(i); 443 CPDF_Object* p = (CPDF_Object*)m_Objects.GetAt(i);
448 return p->GetInteger(); 444 return p->GetInteger();
449 } 445 }
450 FX_FLOAT CPDF_Array::GetNumber(FX_DWORD i) const 446 FX_FLOAT CPDF_Array::GetNumber(FX_DWORD i) const
451 { 447 {
452 if (i >= (FX_DWORD)m_Objects.GetSize()) { 448 if (i >= (FX_DWORD)m_Objects.GetSize()) {
453 return 0; 449 return 0;
454 } 450 }
455 CPDF_Object* p = (CPDF_Object*)m_Objects.GetAt(i); 451 CPDF_Object* p = (CPDF_Object*)m_Objects.GetAt(i);
456 return p->GetNumber(); 452 return p->GetNumber();
457 } 453 }
458 CPDF_Dictionary* CPDF_Array::GetDict(FX_DWORD i) const 454 CPDF_Dictionary* CPDF_Array::GetDict(FX_DWORD i) const
459 { 455 {
460 CPDF_Object* p = GetElementValue(i); 456 CPDF_Object* p = GetElementValue(i);
461 if (p == NULL) { 457 if (!p) {
462 return NULL; 458 return NULL;
463 } else if (p->GetType() == PDFOBJ_DICTIONARY) { 459 }
460 if (p->GetType() == PDFOBJ_DICTIONARY) {
464 return (CPDF_Dictionary*)p; 461 return (CPDF_Dictionary*)p;
465 } else if (p->GetType() == PDFOBJ_STREAM) { 462 }
463 if (p->GetType() == PDFOBJ_STREAM) {
466 return ((CPDF_Stream*)p)->GetDict(); 464 return ((CPDF_Stream*)p)->GetDict();
467 } 465 }
468 return NULL; 466 return NULL;
469 } 467 }
470 CPDF_Stream* CPDF_Array::GetStream(FX_DWORD i) const 468 CPDF_Stream* CPDF_Array::GetStream(FX_DWORD i) const
471 { 469 {
472 CPDF_Object* p = GetElementValue(i); 470 CPDF_Object* p = GetElementValue(i);
473 if (p == NULL || p->GetType() != PDFOBJ_STREAM) { 471 if (p == NULL || p->GetType() != PDFOBJ_STREAM) {
474 return NULL; 472 return NULL;
475 } 473 }
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
597 CPDF_Object* CPDF_Dictionary::GetElementValue(const CFX_ByteStringC& key) const 595 CPDF_Object* CPDF_Dictionary::GetElementValue(const CFX_ByteStringC& key) const
598 { 596 {
599 CPDF_Object* p = NULL; 597 CPDF_Object* p = NULL;
600 m_Map.Lookup(key, (void*&)p); 598 m_Map.Lookup(key, (void*&)p);
601 return p ? p->GetDirect() : NULL; 599 return p ? p->GetDirect() : NULL;
602 } 600 }
603 CFX_ByteString CPDF_Dictionary::GetString(const CFX_ByteStringC& key) const 601 CFX_ByteString CPDF_Dictionary::GetString(const CFX_ByteStringC& key) const
604 { 602 {
605 CPDF_Object* p = NULL; 603 CPDF_Object* p = NULL;
606 m_Map.Lookup(key, (void*&)p); 604 m_Map.Lookup(key, (void*&)p);
607 if (p) 605 if (p) {
608 return p->GetString(); 606 return p->GetString();
609 else 607 }
610 return CFX_ByteString(); 608 return CFX_ByteString();
611 } 609 }
612 CFX_ByteStringC CPDF_Dictionary::GetConstString(const CFX_ByteStringC& key) cons t 610 CFX_ByteStringC CPDF_Dictionary::GetConstString(const CFX_ByteStringC& key) cons t
613 { 611 {
614 CPDF_Object* p = NULL; 612 CPDF_Object* p = NULL;
615 m_Map.Lookup(key, (void*&)p); 613 m_Map.Lookup(key, (void*&)p);
616 if (p) 614 if (p) {
617 return p->GetConstString(); 615 return p->GetConstString();
618 else 616 }
619 return CFX_ByteStringC(); 617 return CFX_ByteStringC();
620 } 618 }
621 CFX_WideString CPDF_Dictionary::GetUnicodeText(const CFX_ByteStringC& key, CFX_C harMap* pCharMap) const 619 CFX_WideString CPDF_Dictionary::GetUnicodeText(const CFX_ByteStringC& key, CFX_C harMap* pCharMap) const
622 { 620 {
623 CPDF_Object* p = NULL; 621 CPDF_Object* p = NULL;
624 m_Map.Lookup(key, (void*&)p); 622 m_Map.Lookup(key, (void*&)p);
625 if (p) { 623 if (p) {
626 if(p->GetType() == PDFOBJ_REFERENCE) { 624 if(p->GetType() == PDFOBJ_REFERENCE) {
627 p = ((CPDF_Reference*)p)->GetDirect(); 625 p = ((CPDF_Reference*)p)->GetDirect();
628 if (p) { 626 if (p) {
629 return p->GetUnicodeText(pCharMap); 627 return p->GetUnicodeText(pCharMap);
(...skipping 10 matching lines...) Expand all
640 m_Map.Lookup(key, (void*&)p); 638 m_Map.Lookup(key, (void*&)p);
641 if (p) { 639 if (p) {
642 return p->GetString(); 640 return p->GetString();
643 } 641 }
644 return CFX_ByteString(def); 642 return CFX_ByteString(def);
645 } 643 }
646 CFX_ByteStringC CPDF_Dictionary::GetConstString(const CFX_ByteStringC& key, cons t CFX_ByteStringC& def) const 644 CFX_ByteStringC CPDF_Dictionary::GetConstString(const CFX_ByteStringC& key, cons t CFX_ByteStringC& def) const
647 { 645 {
648 CPDF_Object* p = NULL; 646 CPDF_Object* p = NULL;
649 m_Map.Lookup(key, (void*&)p); 647 m_Map.Lookup(key, (void*&)p);
650 if (p) 648 if (p) {
651 return p->GetConstString(); 649 return p->GetConstString();
652 else 650 }
653 return CFX_ByteStringC(def); 651 return CFX_ByteStringC(def);
654 } 652 }
655 int CPDF_Dictionary::GetInteger(const CFX_ByteStringC& key) const 653 int CPDF_Dictionary::GetInteger(const CFX_ByteStringC& key) const
656 { 654 {
657 CPDF_Object* p = NULL; 655 CPDF_Object* p = NULL;
658 m_Map.Lookup(key, (void*&)p); 656 m_Map.Lookup(key, (void*&)p);
659 if (p) { 657 if (p) {
660 return p->GetInteger(); 658 return p->GetInteger();
661 } 659 }
662 return 0; 660 return 0;
663 } 661 }
(...skipping 20 matching lines...) Expand all
684 CPDF_Object* p = NULL; 682 CPDF_Object* p = NULL;
685 m_Map.Lookup(key, (void*&)p); 683 m_Map.Lookup(key, (void*&)p);
686 if (p && p->GetType() == PDFOBJ_BOOLEAN) { 684 if (p && p->GetType() == PDFOBJ_BOOLEAN) {
687 return p->GetInteger(); 685 return p->GetInteger();
688 } 686 }
689 return bDefault; 687 return bDefault;
690 } 688 }
691 CPDF_Dictionary* CPDF_Dictionary::GetDict(const CFX_ByteStringC& key) const 689 CPDF_Dictionary* CPDF_Dictionary::GetDict(const CFX_ByteStringC& key) const
692 { 690 {
693 CPDF_Object* p = GetElementValue(key); 691 CPDF_Object* p = GetElementValue(key);
694 if (p == NULL) { 692 if (!p) {
695 return NULL; 693 return nullptr;
696 } else if (p->GetType() == PDFOBJ_DICTIONARY) { 694 }
695 if (p->GetType() == PDFOBJ_DICTIONARY) {
697 return (CPDF_Dictionary*)p; 696 return (CPDF_Dictionary*)p;
698 } else if (p->GetType() == PDFOBJ_STREAM) { 697 }
698 if (p->GetType() == PDFOBJ_STREAM) {
699 return ((CPDF_Stream*)p)->GetDict(); 699 return ((CPDF_Stream*)p)->GetDict();
700 } 700 }
701 return NULL; 701 return nullptr;
702 } 702 }
703 CPDF_Array* CPDF_Dictionary::GetArray(const CFX_ByteStringC& key) const 703 CPDF_Array* CPDF_Dictionary::GetArray(const CFX_ByteStringC& key) const
704 { 704 {
705 CPDF_Object* p = GetElementValue(key); 705 CPDF_Object* p = GetElementValue(key);
706 if (p == NULL || p->GetType() != PDFOBJ_ARRAY) { 706 if (p == NULL || p->GetType() != PDFOBJ_ARRAY) {
707 return NULL; 707 return NULL;
708 } 708 }
709 return (CPDF_Array*)p; 709 return (CPDF_Array*)p;
710 } 710 }
711 CPDF_Stream* CPDF_Dictionary::GetStream(const CFX_ByteStringC& key) const 711 CPDF_Stream* CPDF_Dictionary::GetStream(const CFX_ByteStringC& key) const
(...skipping 550 matching lines...) Expand 10 before | Expand all | Expand 10 after
1262 ((CPDF_Object*)value)->Destroy(); 1262 ((CPDF_Object*)value)->Destroy();
1263 m_IndirectObjs.RemoveKey((void*)(uintptr_t)objnum); 1263 m_IndirectObjs.RemoveKey((void*)(uintptr_t)objnum);
1264 } 1264 }
1265 void CPDF_IndirectObjects::InsertIndirectObject(FX_DWORD objnum, CPDF_Object* pO bj) 1265 void CPDF_IndirectObjects::InsertIndirectObject(FX_DWORD objnum, CPDF_Object* pO bj)
1266 { 1266 {
1267 if (objnum == 0 || pObj == NULL) { 1267 if (objnum == 0 || pObj == NULL) {
1268 return; 1268 return;
1269 } 1269 }
1270 void* value = NULL; 1270 void* value = NULL;
1271 if (m_IndirectObjs.Lookup((void*)(uintptr_t)objnum, value)) { 1271 if (m_IndirectObjs.Lookup((void*)(uintptr_t)objnum, value)) {
1272 if (value) 1272 if (value) {
1273 { 1273 if (pObj->GetGenNum() <= ((CPDF_Object*)value)->GetGenNum()) {
1274 if (pObj->GetGenNum() <= ((CPDF_Object*)value)->GetGenNum())
1275 return; 1274 return;
1276 else 1275 }
1277 ((CPDF_Object*)value)->Destroy(); 1276 ((CPDF_Object*)value)->Destroy();
1278 } 1277 }
1279 } 1278 }
1280 pObj->m_ObjNum = objnum; 1279 pObj->m_ObjNum = objnum;
1281 m_IndirectObjs.SetAt((void*)(uintptr_t)objnum, pObj); 1280 m_IndirectObjs.SetAt((void*)(uintptr_t)objnum, pObj);
1282 if (m_LastObjNum < objnum) { 1281 if (m_LastObjNum < objnum) {
1283 m_LastObjNum = objnum; 1282 m_LastObjNum = objnum;
1284 } 1283 }
1285 } 1284 }
1286 FX_DWORD CPDF_IndirectObjects::GetLastObjNum() const 1285 FX_DWORD CPDF_IndirectObjects::GetLastObjNum() const
1287 { 1286 {
1288 return m_LastObjNum; 1287 return m_LastObjNum;
1289 } 1288 }
OLDNEW
« no previous file with comments | « core/src/fpdfapi/fpdf_parser/fpdf_parser_fdf.cpp ('k') | core/src/fpdfapi/fpdf_parser/fpdf_parser_parser.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698