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

Side by Side Diff: core/fpdfapi/page/cpdf_streamcontentparser.cpp

Issue 2384883003: Remove CPDF_Object::Release() in favor of direct delete (Closed)
Patch Set: rebase Created 4 years, 1 month 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 2016 PDFium Authors. All rights reserved. 1 // Copyright 2016 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/fpdfapi/page/cpdf_streamcontentparser.h" 7 #include "core/fpdfapi/page/cpdf_streamcontentparser.h"
8 8
9 #include "core/fpdfapi/font/cpdf_font.h" 9 #include "core/fpdfapi/font/cpdf_font.h"
10 #include "core/fpdfapi/font/cpdf_type3font.h" 10 #include "core/fpdfapi/font/cpdf_type3font.h"
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
173 m_pCurStates->m_ColorState.Emplace(); 173 m_pCurStates->m_ColorState.Emplace();
174 } 174 }
175 for (size_t i = 0; i < FX_ArraySize(m_Type3Data); ++i) { 175 for (size_t i = 0; i < FX_ArraySize(m_Type3Data); ++i) {
176 m_Type3Data[i] = 0.0; 176 m_Type3Data[i] = 0.0;
177 } 177 }
178 } 178 }
179 179
180 CPDF_StreamContentParser::~CPDF_StreamContentParser() { 180 CPDF_StreamContentParser::~CPDF_StreamContentParser() {
181 ClearAllParams(); 181 ClearAllParams();
182 FX_Free(m_pPathPoints); 182 FX_Free(m_pPathPoints);
183 if (m_pLastImageDict) { 183 delete m_pLastImageDict;
184 m_pLastImageDict->Release(); 184 delete m_pLastCloneImageDict;
185 }
186 if (m_pLastCloneImageDict) {
187 m_pLastCloneImageDict->Release();
188 }
189 } 185 }
190 186
191 int CPDF_StreamContentParser::GetNextParamPos() { 187 int CPDF_StreamContentParser::GetNextParamPos() {
192 if (m_ParamCount == kParamBufSize) { 188 if (m_ParamCount == kParamBufSize) {
193 m_ParamStartPos++; 189 m_ParamStartPos++;
194 if (m_ParamStartPos == kParamBufSize) { 190 if (m_ParamStartPos == kParamBufSize) {
195 m_ParamStartPos = 0; 191 m_ParamStartPos = 0;
196 } 192 }
197 if (m_ParamBuf[m_ParamStartPos].m_Type == 0) { 193 if (m_ParamBuf[m_ParamStartPos].m_Type == 0)
198 if (CPDF_Object* pObject = m_ParamBuf[m_ParamStartPos].m_pObject) 194 delete m_ParamBuf[m_ParamStartPos].m_pObject;
199 pObject->Release(); 195
200 }
201 return m_ParamStartPos; 196 return m_ParamStartPos;
202 } 197 }
203 int index = m_ParamStartPos + m_ParamCount; 198 int index = m_ParamStartPos + m_ParamCount;
204 if (index >= kParamBufSize) { 199 if (index >= kParamBufSize) {
205 index -= kParamBufSize; 200 index -= kParamBufSize;
206 } 201 }
207 m_ParamCount++; 202 m_ParamCount++;
208 return index; 203 return index;
209 } 204 }
210 205
(...skipping 26 matching lines...) Expand all
237 232
238 void CPDF_StreamContentParser::AddObjectParam(CPDF_Object* pObj) { 233 void CPDF_StreamContentParser::AddObjectParam(CPDF_Object* pObj) {
239 ContentParam& param = m_ParamBuf[GetNextParamPos()]; 234 ContentParam& param = m_ParamBuf[GetNextParamPos()];
240 param.m_Type = ContentParam::OBJECT; 235 param.m_Type = ContentParam::OBJECT;
241 param.m_pObject = pObj; 236 param.m_pObject = pObj;
242 } 237 }
243 238
244 void CPDF_StreamContentParser::ClearAllParams() { 239 void CPDF_StreamContentParser::ClearAllParams() {
245 uint32_t index = m_ParamStartPos; 240 uint32_t index = m_ParamStartPos;
246 for (uint32_t i = 0; i < m_ParamCount; i++) { 241 for (uint32_t i = 0; i < m_ParamCount; i++) {
247 if (m_ParamBuf[index].m_Type == 0) { 242 if (m_ParamBuf[index].m_Type == 0)
248 if (CPDF_Object* pObject = m_ParamBuf[index].m_pObject) 243 delete m_ParamBuf[index].m_pObject;
249 pObject->Release(); 244
250 }
251 index++; 245 index++;
252 if (index == kParamBufSize) { 246 if (index == kParamBufSize) {
253 index = 0; 247 index = 0;
254 } 248 }
255 } 249 }
256 m_ParamStartPos = 0; 250 m_ParamStartPos = 0;
257 m_ParamCount = 0; 251 m_ParamCount = 0;
258 } 252 }
259 253
260 CPDF_Object* CPDF_StreamContentParser::GetObject(uint32_t index) { 254 CPDF_Object* CPDF_StreamContentParser::GetObject(uint32_t index) {
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after
524 FX_FILESIZE savePos = m_pSyntax->GetPos(); 518 FX_FILESIZE savePos = m_pSyntax->GetPos();
525 CPDF_Dictionary* pDict = 519 CPDF_Dictionary* pDict =
526 new CPDF_Dictionary(m_pDocument->GetByteStringPool()); 520 new CPDF_Dictionary(m_pDocument->GetByteStringPool());
527 while (1) { 521 while (1) {
528 CPDF_StreamParser::SyntaxType type = m_pSyntax->ParseNextElement(); 522 CPDF_StreamParser::SyntaxType type = m_pSyntax->ParseNextElement();
529 if (type == CPDF_StreamParser::Keyword) { 523 if (type == CPDF_StreamParser::Keyword) {
530 CFX_ByteString bsKeyword(m_pSyntax->GetWordBuf(), 524 CFX_ByteString bsKeyword(m_pSyntax->GetWordBuf(),
531 m_pSyntax->GetWordSize()); 525 m_pSyntax->GetWordSize());
532 if (bsKeyword != "ID") { 526 if (bsKeyword != "ID") {
533 m_pSyntax->SetPos(savePos); 527 m_pSyntax->SetPos(savePos);
534 pDict->Release(); 528 delete pDict;
535 return; 529 return;
536 } 530 }
537 } 531 }
538 if (type != CPDF_StreamParser::Name) { 532 if (type != CPDF_StreamParser::Name) {
539 break; 533 break;
540 } 534 }
541 CFX_ByteString key((const FX_CHAR*)m_pSyntax->GetWordBuf() + 1, 535 CFX_ByteString key((const FX_CHAR*)m_pSyntax->GetWordBuf() + 1,
542 m_pSyntax->GetWordSize() - 1); 536 m_pSyntax->GetWordSize() - 1);
543 std::unique_ptr<CPDF_Object, ReleaseDeleter<CPDF_Object>> pObj( 537 std::unique_ptr<CPDF_Object> pObj(m_pSyntax->ReadNextObject(false, 0));
544 m_pSyntax->ReadNextObject(false, 0));
545 if (!key.IsEmpty()) { 538 if (!key.IsEmpty()) {
546 uint32_t dwObjNum = pObj ? pObj->GetObjNum() : 0; 539 uint32_t dwObjNum = pObj ? pObj->GetObjNum() : 0;
547 if (dwObjNum) 540 if (dwObjNum)
548 pDict->SetReferenceFor(key, m_pDocument, dwObjNum); 541 pDict->SetReferenceFor(key, m_pDocument, dwObjNum);
549 else 542 else
550 pDict->SetFor(key, pObj.release()); 543 pDict->SetFor(key, pObj.release());
551 } 544 }
552 } 545 }
553 PDF_ReplaceAbbr(pDict); 546 PDF_ReplaceAbbr(pDict);
554 CPDF_Object* pCSObj = nullptr; 547 CPDF_Object* pCSObj = nullptr;
555 if (pDict->KeyExist("ColorSpace")) { 548 if (pDict->KeyExist("ColorSpace")) {
556 pCSObj = pDict->GetDirectObjectFor("ColorSpace"); 549 pCSObj = pDict->GetDirectObjectFor("ColorSpace");
557 if (pCSObj->IsName()) { 550 if (pCSObj->IsName()) {
558 CFX_ByteString name = pCSObj->GetString(); 551 CFX_ByteString name = pCSObj->GetString();
559 if (name != "DeviceRGB" && name != "DeviceGray" && name != "DeviceCMYK") { 552 if (name != "DeviceRGB" && name != "DeviceGray" && name != "DeviceCMYK") {
560 pCSObj = FindResourceObj("ColorSpace", name); 553 pCSObj = FindResourceObj("ColorSpace", name);
561 if (pCSObj && pCSObj->IsInline()) { 554 if (pCSObj && pCSObj->IsInline()) {
562 pCSObj = pCSObj->Clone(); 555 pCSObj = pCSObj->Clone();
563 pDict->SetFor("ColorSpace", pCSObj); 556 pDict->SetFor("ColorSpace", pCSObj);
564 } 557 }
565 } 558 }
566 } 559 }
567 } 560 }
568 pDict->SetNameFor("Subtype", "Image"); 561 pDict->SetNameFor("Subtype", "Image");
569 UniqueStream pStream(m_pSyntax->ReadInlineStream(m_pDocument, pDict, pCSObj)); 562 std::unique_ptr<CPDF_Stream> pStream(
563 m_pSyntax->ReadInlineStream(m_pDocument, pDict, pCSObj));
570 bool bGaveDictAway = !!pStream; 564 bool bGaveDictAway = !!pStream;
571 while (1) { 565 while (1) {
572 CPDF_StreamParser::SyntaxType type = m_pSyntax->ParseNextElement(); 566 CPDF_StreamParser::SyntaxType type = m_pSyntax->ParseNextElement();
573 if (type == CPDF_StreamParser::EndOfData) { 567 if (type == CPDF_StreamParser::EndOfData) {
574 break; 568 break;
575 } 569 }
576 if (type != CPDF_StreamParser::Keyword) { 570 if (type != CPDF_StreamParser::Keyword) {
577 continue; 571 continue;
578 } 572 }
579 if (m_pSyntax->GetWordSize() == 2 && m_pSyntax->GetWordBuf()[0] == 'E' && 573 if (m_pSyntax->GetWordSize() == 2 && m_pSyntax->GetWordBuf()[0] == 'E' &&
580 m_pSyntax->GetWordBuf()[1] == 'I') { 574 m_pSyntax->GetWordBuf()[1] == 'I') {
581 break; 575 break;
582 } 576 }
583 } 577 }
584 CPDF_ImageObject* pImgObj = AddImage(std::move(pStream)); 578 CPDF_ImageObject* pImgObj = AddImage(std::move(pStream));
585 if (!pImgObj && !bGaveDictAway) 579 if (!pImgObj && !bGaveDictAway)
586 pDict->Release(); 580 delete pDict;
587 } 581 }
588 582
589 void CPDF_StreamContentParser::Handle_BeginMarkedContent() { 583 void CPDF_StreamContentParser::Handle_BeginMarkedContent() {
590 m_CurContentMark.AddMark(GetString(0), nullptr, false); 584 m_CurContentMark.AddMark(GetString(0), nullptr, false);
591 } 585 }
592 586
593 void CPDF_StreamContentParser::Handle_BeginText() { 587 void CPDF_StreamContentParser::Handle_BeginText() {
594 m_pCurStates->m_TextMatrix.Set(1.0f, 0, 0, 1.0f, 0, 0); 588 m_pCurStates->m_TextMatrix.Set(1.0f, 0, 0, 1.0f, 0, 0);
595 OnChangeTextMatrix(); 589 OnChangeTextMatrix();
596 m_pCurStates->m_TextX = 0; 590 m_pCurStates->m_TextX = 0;
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after
662 if (!pXObject) { 656 if (!pXObject) {
663 m_bResourceMissing = true; 657 m_bResourceMissing = true;
664 return; 658 return;
665 } 659 }
666 660
667 CFX_ByteString type; 661 CFX_ByteString type;
668 if (pXObject->GetDict()) 662 if (pXObject->GetDict())
669 type = pXObject->GetDict()->GetStringFor("Subtype"); 663 type = pXObject->GetDict()->GetStringFor("Subtype");
670 664
671 if (type == "Image") { 665 if (type == "Image") {
672 CPDF_ImageObject* pObj = 666 CPDF_ImageObject* pObj = pXObject->IsInline()
673 pXObject->IsInline() 667 ? AddImage(std::unique_ptr<CPDF_Stream>(
674 ? AddImage(UniqueStream(ToStream(pXObject->Clone()))) 668 ToStream(pXObject->Clone())))
675 : AddImage(pXObject->GetObjNum()); 669 : AddImage(pXObject->GetObjNum());
676 670
677 m_LastImageName = name; 671 m_LastImageName = name;
678 m_pLastImage = pObj->GetImage(); 672 m_pLastImage = pObj->GetImage();
679 if (!m_pObjectHolder->HasImageMask()) 673 if (!m_pObjectHolder->HasImageMask())
680 m_pObjectHolder->SetHasImageMask(m_pLastImage->IsMask()); 674 m_pObjectHolder->SetHasImageMask(m_pLastImage->IsMask());
681 } else if (type == "Form") { 675 } else if (type == "Form") {
682 AddForm(pXObject); 676 AddForm(pXObject);
683 } 677 }
684 } 678 }
685 679
(...skipping 11 matching lines...) Expand all
697 pFormObj->m_pForm->ParseContent(&status, nullptr, nullptr, m_Level + 1); 691 pFormObj->m_pForm->ParseContent(&status, nullptr, nullptr, m_Level + 1);
698 if (!m_pObjectHolder->BackgroundAlphaNeeded() && 692 if (!m_pObjectHolder->BackgroundAlphaNeeded() &&
699 pFormObj->m_pForm->BackgroundAlphaNeeded()) { 693 pFormObj->m_pForm->BackgroundAlphaNeeded()) {
700 m_pObjectHolder->SetBackgroundAlphaNeeded(true); 694 m_pObjectHolder->SetBackgroundAlphaNeeded(true);
701 } 695 }
702 pFormObj->CalcBoundingBox(); 696 pFormObj->CalcBoundingBox();
703 SetGraphicStates(pFormObj.get(), true, true, true); 697 SetGraphicStates(pFormObj.get(), true, true, true);
704 m_pObjectHolder->GetPageObjectList()->push_back(std::move(pFormObj)); 698 m_pObjectHolder->GetPageObjectList()->push_back(std::move(pFormObj));
705 } 699 }
706 700
707 CPDF_ImageObject* CPDF_StreamContentParser::AddImage(UniqueStream pStream) { 701 CPDF_ImageObject* CPDF_StreamContentParser::AddImage(
702 std::unique_ptr<CPDF_Stream> pStream) {
708 if (!pStream) 703 if (!pStream)
709 return nullptr; 704 return nullptr;
710 705
711 auto pImageObj = pdfium::MakeUnique<CPDF_ImageObject>(); 706 auto pImageObj = pdfium::MakeUnique<CPDF_ImageObject>();
712 pImageObj->SetOwnedImage( 707 pImageObj->SetOwnedImage(
713 pdfium::MakeUnique<CPDF_Image>(m_pDocument, std::move(pStream))); 708 pdfium::MakeUnique<CPDF_Image>(m_pDocument, std::move(pStream)));
714 return AddImageObject(std::move(pImageObj)); 709 return AddImageObject(std::move(pImageObj));
715 } 710 }
716 711
717 CPDF_ImageObject* CPDF_StreamContentParser::AddImage(uint32_t streamObjNum) { 712 CPDF_ImageObject* CPDF_StreamContentParser::AddImage(uint32_t streamObjNum) {
(...skipping 837 matching lines...) Expand 10 before | Expand all | Expand 10 after
1555 } 1550 }
1556 default: 1551 default:
1557 bProcessed = false; 1552 bProcessed = false;
1558 } 1553 }
1559 if (!bProcessed) { 1554 if (!bProcessed) {
1560 m_pSyntax->SetPos(last_pos); 1555 m_pSyntax->SetPos(last_pos);
1561 return; 1556 return;
1562 } 1557 }
1563 } 1558 }
1564 } 1559 }
OLDNEW
« no previous file with comments | « core/fpdfapi/page/cpdf_streamcontentparser.h ('k') | core/fpdfapi/page/fpdf_page_parser_old.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698