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

Side by Side Diff: core/src/fpdfapi/fpdf_page/fpdf_page_parser_old.cpp

Issue 1540693002: Get rid of a few CPDF_Object Create() methods and just use new instead. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
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
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 "pageint.h" 7 #include "pageint.h"
8 8
9 #include <limits.h> 9 #include <limits.h>
10 10
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 break; 68 break;
69 default: 69 default:
70 AddObjectParam(syntax.GetObject()); 70 AddObjectParam(syntax.GetObject());
71 } 71 }
72 } 72 }
73 return m_pSyntax->GetPos(); 73 return m_pSyntax->GetPos();
74 } 74 }
75 void _PDF_ReplaceAbbr(CPDF_Object* pObj); 75 void _PDF_ReplaceAbbr(CPDF_Object* pObj);
76 void CPDF_StreamContentParser::Handle_BeginImage() { 76 void CPDF_StreamContentParser::Handle_BeginImage() {
77 FX_FILESIZE savePos = m_pSyntax->GetPos(); 77 FX_FILESIZE savePos = m_pSyntax->GetPos();
78 CPDF_Dictionary* pDict = CPDF_Dictionary::Create(); 78 CPDF_Dictionary* pDict = new CPDF_Dictionary;
79 while (1) { 79 while (1) {
80 CPDF_StreamParser::SyntaxType type = m_pSyntax->ParseNextElement(); 80 CPDF_StreamParser::SyntaxType type = m_pSyntax->ParseNextElement();
81 if (type == CPDF_StreamParser::Keyword) { 81 if (type == CPDF_StreamParser::Keyword) {
82 CFX_ByteString bsKeyword(m_pSyntax->GetWordBuf(), 82 CFX_ByteString bsKeyword(m_pSyntax->GetWordBuf(),
83 m_pSyntax->GetWordSize()); 83 m_pSyntax->GetWordSize());
84 if (bsKeyword != "ID") { 84 if (bsKeyword != "ID") {
85 m_pSyntax->SetPos(savePos); 85 m_pSyntax->SetPos(savePos);
86 pDict->Release(); 86 pDict->Release();
87 return; 87 return;
88 } 88 }
(...skipping 420 matching lines...) Expand 10 before | Expand all | Expand 10 after
509 } 509 }
510 510
511 m_WordBuffer[m_WordSize] = 0; 511 m_WordBuffer[m_WordSize] = 0;
512 if (bIsNumber) 512 if (bIsNumber)
513 return Number; 513 return Number;
514 if (m_WordBuffer[0] == '/') 514 if (m_WordBuffer[0] == '/')
515 return Name; 515 return Name;
516 516
517 if (m_WordSize == 4) { 517 if (m_WordSize == 4) {
518 if (*(FX_DWORD*)m_WordBuffer == FXDWORD_TRUE) { 518 if (*(FX_DWORD*)m_WordBuffer == FXDWORD_TRUE) {
519 m_pLastObj = CPDF_Boolean::Create(TRUE); 519 m_pLastObj = new CPDF_Boolean(TRUE);
520 return Others; 520 return Others;
521 } 521 }
522 if (*(FX_DWORD*)m_WordBuffer == FXDWORD_NULL) { 522 if (*(FX_DWORD*)m_WordBuffer == FXDWORD_NULL) {
523 m_pLastObj = CPDF_Null::Create(); 523 m_pLastObj = new CPDF_Null;
524 return Others; 524 return Others;
525 } 525 }
526 } else if (m_WordSize == 5) { 526 } else if (m_WordSize == 5) {
527 if (*(FX_DWORD*)m_WordBuffer == FXDWORD_FALS && m_WordBuffer[4] == 'e') { 527 if (*(FX_DWORD*)m_WordBuffer == FXDWORD_FALS && m_WordBuffer[4] == 'e') {
528 m_pLastObj = CPDF_Boolean::Create(FALSE); 528 m_pLastObj = new CPDF_Boolean(FALSE);
529 return Others; 529 return Others;
530 } 530 }
531 } 531 }
532 return Keyword; 532 return Keyword;
533 } 533 }
534 534
535 void CPDF_StreamParser::SkipPathObject() { 535 void CPDF_StreamParser::SkipPathObject() {
536 FX_DWORD command_startpos = m_Pos; 536 FX_DWORD command_startpos = m_Pos;
537 if (!PositionIsInBounds()) 537 if (!PositionIsInBounds())
538 return; 538 return;
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
596 } 596 }
597 CPDF_Object* CPDF_StreamParser::ReadNextObject(FX_BOOL bAllowNestedArray, 597 CPDF_Object* CPDF_StreamParser::ReadNextObject(FX_BOOL bAllowNestedArray,
598 FX_BOOL bInArray) { 598 FX_BOOL bInArray) {
599 FX_BOOL bIsNumber; 599 FX_BOOL bIsNumber;
600 GetNextWord(bIsNumber); 600 GetNextWord(bIsNumber);
601 if (m_WordSize == 0) { 601 if (m_WordSize == 0) {
602 return NULL; 602 return NULL;
603 } 603 }
604 if (bIsNumber) { 604 if (bIsNumber) {
605 m_WordBuffer[m_WordSize] = 0; 605 m_WordBuffer[m_WordSize] = 0;
606 return CPDF_Number::Create(CFX_ByteStringC(m_WordBuffer, m_WordSize)); 606 return new CPDF_Number(CFX_ByteStringC(m_WordBuffer, m_WordSize));
607 } 607 }
608 int first_char = m_WordBuffer[0]; 608 int first_char = m_WordBuffer[0];
609 if (first_char == '/') { 609 if (first_char == '/') {
610 return CPDF_Name::Create( 610 return new CPDF_Name(
611 PDF_NameDecode(CFX_ByteStringC(m_WordBuffer + 1, m_WordSize - 1))); 611 PDF_NameDecode(CFX_ByteStringC(m_WordBuffer + 1, m_WordSize - 1)));
612 } 612 }
613 if (first_char == '(') { 613 if (first_char == '(') {
614 return CPDF_String::Create(ReadString()); 614 return new CPDF_String(ReadString(), FALSE);
615 } 615 }
616 if (first_char == '<') { 616 if (first_char == '<') {
617 if (m_WordSize == 1) { 617 if (m_WordSize == 1) {
618 return CPDF_String::Create(ReadHexString(), TRUE); 618 return new CPDF_String(ReadHexString(), TRUE);
619 } 619 }
620 CPDF_Dictionary* pDict = CPDF_Dictionary::Create(); 620 CPDF_Dictionary* pDict = new CPDF_Dictionary;
621 while (1) { 621 while (1) {
622 GetNextWord(bIsNumber); 622 GetNextWord(bIsNumber);
623 if (m_WordSize == 0) { 623 if (m_WordSize == 0) {
624 pDict->Release(); 624 pDict->Release();
625 return NULL; 625 return nullptr;
626 } 626 }
627 if (m_WordSize == 2 && m_WordBuffer[0] == '>') { 627 if (m_WordSize == 2 && m_WordBuffer[0] == '>') {
628 break; 628 break;
629 } 629 }
630 if (m_WordBuffer[0] != '/') { 630 if (m_WordBuffer[0] != '/') {
631 pDict->Release(); 631 pDict->Release();
632 return NULL; 632 return nullptr;
633 } 633 }
634 CFX_ByteString key = 634 CFX_ByteString key =
635 PDF_NameDecode(CFX_ByteStringC(m_WordBuffer + 1, m_WordSize - 1)); 635 PDF_NameDecode(CFX_ByteStringC(m_WordBuffer + 1, m_WordSize - 1));
636 CPDF_Object* pObj = ReadNextObject(TRUE); 636 CPDF_Object* pObj = ReadNextObject(TRUE);
637 if (!pObj) { 637 if (!pObj) {
638 if (pDict) { 638 pDict->Release();
639 pDict->Release(); 639 return nullptr;
640 }
641 return NULL;
642 } 640 }
643 if (!key.IsEmpty()) { 641 if (!key.IsEmpty()) {
644 pDict->SetAt(key, pObj); 642 pDict->SetAt(key, pObj);
645 } else { 643 } else {
646 pObj->Release(); 644 pObj->Release();
647 } 645 }
648 } 646 }
649 return pDict; 647 return pDict;
650 } 648 }
651 if (first_char == '[') { 649 if (first_char == '[') {
652 if (!bAllowNestedArray && bInArray) { 650 if (!bAllowNestedArray && bInArray) {
653 return NULL; 651 return NULL;
654 } 652 }
655 CPDF_Array* pArray = CPDF_Array::Create(); 653 CPDF_Array* pArray = new CPDF_Array;
656 while (1) { 654 while (1) {
657 CPDF_Object* pObj = ReadNextObject(bAllowNestedArray, TRUE); 655 CPDF_Object* pObj = ReadNextObject(bAllowNestedArray, TRUE);
658 if (!pObj) { 656 if (pObj) {
659 if (m_WordSize == 0 || m_WordBuffer[0] == ']') {
660 return pArray;
661 }
662 if (m_WordBuffer[0] == '[') {
663 continue;
664 }
665 } else {
666 pArray->Add(pObj); 657 pArray->Add(pObj);
658 continue;
667 } 659 }
660
661 if (m_WordSize == 0 || m_WordBuffer[0] == ']')
662 break;
668 } 663 }
664 return pArray;
669 } 665 }
670 if (m_WordSize == 4) { 666 if (m_WordSize == 4) {
671 if (*(FX_DWORD*)m_WordBuffer == FXDWORD_TRUE) { 667 if (*(FX_DWORD*)m_WordBuffer == FXDWORD_TRUE) {
672 return CPDF_Boolean::Create(TRUE); 668 return new CPDF_Boolean(TRUE);
673 } 669 }
674 if (*(FX_DWORD*)m_WordBuffer == FXDWORD_NULL) { 670 if (*(FX_DWORD*)m_WordBuffer == FXDWORD_NULL) {
675 return CPDF_Null::Create(); 671 return new CPDF_Null;
676 } 672 }
677 } else if (m_WordSize == 5) { 673 } else if (m_WordSize == 5) {
678 if (*(FX_DWORD*)m_WordBuffer == FXDWORD_FALS && m_WordBuffer[4] == 'e') { 674 if (*(FX_DWORD*)m_WordBuffer == FXDWORD_FALS && m_WordBuffer[4] == 'e') {
679 return CPDF_Boolean::Create(FALSE); 675 return new CPDF_Boolean(FALSE);
680 } 676 }
681 } 677 }
682 return NULL; 678 return NULL;
683 } 679 }
684 void CPDF_StreamParser::GetNextWord(FX_BOOL& bIsNumber) { 680 void CPDF_StreamParser::GetNextWord(FX_BOOL& bIsNumber) {
685 m_WordSize = 0; 681 m_WordSize = 0;
686 bIsNumber = TRUE; 682 bIsNumber = TRUE;
687 if (!PositionIsInBounds()) 683 if (!PositionIsInBounds())
688 return; 684 return;
689 685
(...skipping 430 matching lines...) Expand 10 before | Expand all | Expand 10 after
1120 } 1116 }
1121 m_Status = Done; 1117 m_Status = Done;
1122 return; 1118 return;
1123 } 1119 }
1124 steps++; 1120 steps++;
1125 if (pPause && pPause->NeedToPauseNow()) { 1121 if (pPause && pPause->NeedToPauseNow()) {
1126 break; 1122 break;
1127 } 1123 }
1128 } 1124 }
1129 } 1125 }
OLDNEW
« no previous file with comments | « core/src/fpdfapi/fpdf_page/fpdf_page_parser.cpp ('k') | core/src/fpdfapi/fpdf_parser/fpdf_parser_objects.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698