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

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

Issue 2416733002: split CPDF_StreamContentParser::AddImage() into 3 overloads. (Closed)
Patch Set: Created 4 years, 2 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
« no previous file with comments | « no previous file | core/fpdfapi/page/pageint.h » ('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/fpdfapi/page/pageint.h" 7 #include "core/fpdfapi/page/pageint.h"
8 8
9 #include <memory> 9 #include <memory>
10 #include <utility> 10 #include <utility>
(...skipping 602 matching lines...) Expand 10 before | Expand all | Expand 10 after
613 CFX_ByteString name = pCSObj->GetString(); 613 CFX_ByteString name = pCSObj->GetString();
614 if (name != "DeviceRGB" && name != "DeviceGray" && name != "DeviceCMYK") { 614 if (name != "DeviceRGB" && name != "DeviceGray" && name != "DeviceCMYK") {
615 pCSObj = FindResourceObj("ColorSpace", name); 615 pCSObj = FindResourceObj("ColorSpace", name);
616 if (pCSObj && pCSObj->IsInline()) { 616 if (pCSObj && pCSObj->IsInline()) {
617 pCSObj = pCSObj->Clone(); 617 pCSObj = pCSObj->Clone();
618 pDict->SetFor("ColorSpace", pCSObj); 618 pDict->SetFor("ColorSpace", pCSObj);
619 } 619 }
620 } 620 }
621 } 621 }
622 } 622 }
623 CPDF_Stream* pStream = 623 pDict->SetNameFor("Subtype", "Image");
624 m_pSyntax->ReadInlineStream(m_pDocument, pDict, pCSObj); 624 UniqueStream pStream(m_pSyntax->ReadInlineStream(m_pDocument, pDict, pCSObj));
625 bool bGaveDictAway = !!pStream;
625 while (1) { 626 while (1) {
626 CPDF_StreamParser::SyntaxType type = m_pSyntax->ParseNextElement(); 627 CPDF_StreamParser::SyntaxType type = m_pSyntax->ParseNextElement();
627 if (type == CPDF_StreamParser::EndOfData) { 628 if (type == CPDF_StreamParser::EndOfData) {
628 break; 629 break;
629 } 630 }
630 if (type != CPDF_StreamParser::Keyword) { 631 if (type != CPDF_StreamParser::Keyword) {
631 continue; 632 continue;
632 } 633 }
633 if (m_pSyntax->GetWordSize() == 2 && m_pSyntax->GetWordBuf()[0] == 'E' && 634 if (m_pSyntax->GetWordSize() == 2 && m_pSyntax->GetWordBuf()[0] == 'E' &&
634 m_pSyntax->GetWordBuf()[1] == 'I') { 635 m_pSyntax->GetWordBuf()[1] == 'I') {
635 break; 636 break;
636 } 637 }
637 } 638 }
638 pDict->SetNameFor("Subtype", "Image"); 639 CPDF_ImageObject* pImgObj = AddImage(std::move(pStream));
639 CPDF_ImageObject* pImgObj = AddImage(pStream, nullptr, true); 640 if (!pImgObj && !bGaveDictAway)
640 if (!pImgObj) { 641 pDict->Release();
641 if (pStream) {
642 pStream->Release();
643 } else {
644 pDict->Release();
645 }
646 }
647 } 642 }
648 643
649 void CPDF_StreamContentParser::Handle_BeginMarkedContent() { 644 void CPDF_StreamContentParser::Handle_BeginMarkedContent() {
650 m_CurContentMark.AddMark(GetString(0), nullptr, FALSE); 645 m_CurContentMark.AddMark(GetString(0), nullptr, FALSE);
651 } 646 }
652 647
653 void CPDF_StreamContentParser::Handle_BeginText() { 648 void CPDF_StreamContentParser::Handle_BeginText() {
654 m_pCurStates->m_TextMatrix.Set(1.0f, 0, 0, 1.0f, 0, 0); 649 m_pCurStates->m_TextMatrix.Set(1.0f, 0, 0, 1.0f, 0, 0);
655 OnChangeTextMatrix(); 650 OnChangeTextMatrix();
656 m_pCurStates->m_TextX = 0; 651 m_pCurStates->m_TextX = 0;
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
707 for (int i = 0; i < 6; i++) { 702 for (int i = 0; i < 6; i++) {
708 m_Type3Data[i] = GetNumber(5 - i); 703 m_Type3Data[i] = GetNumber(5 - i);
709 } 704 }
710 m_bColored = false; 705 m_bColored = false;
711 } 706 }
712 707
713 void CPDF_StreamContentParser::Handle_ExecuteXObject() { 708 void CPDF_StreamContentParser::Handle_ExecuteXObject() {
714 CFX_ByteString name = GetString(0); 709 CFX_ByteString name = GetString(0);
715 if (name == m_LastImageName && m_pLastImage && m_pLastImage->GetStream() && 710 if (name == m_LastImageName && m_pLastImage && m_pLastImage->GetStream() &&
716 m_pLastImage->GetStream()->GetObjNum()) { 711 m_pLastImage->GetStream()->GetObjNum()) {
717 AddImage(nullptr, m_pLastImage, false); 712 AddImage(m_pLastImage);
718 return; 713 return;
719 } 714 }
720 715
721 CPDF_Stream* pXObject = ToStream(FindResourceObj("XObject", name)); 716 CPDF_Stream* pXObject = ToStream(FindResourceObj("XObject", name));
722 if (!pXObject) { 717 if (!pXObject) {
723 m_bResourceMissing = true; 718 m_bResourceMissing = true;
724 return; 719 return;
725 } 720 }
726 721
727 CFX_ByteString type; 722 CFX_ByteString type;
728 if (pXObject->GetDict()) 723 if (pXObject->GetDict())
729 type = pXObject->GetDict()->GetStringFor("Subtype"); 724 type = pXObject->GetDict()->GetStringFor("Subtype");
730 725
731 if (type == "Image") { 726 if (type == "Image") {
732 CPDF_ImageObject* pObj = AddImage(pXObject, nullptr, false); 727 CPDF_ImageObject* pObj = AddImage(pXObject->GetObjNum());
733 m_LastImageName = name; 728 m_LastImageName = name;
734 m_pLastImage = pObj->GetImage(); 729 m_pLastImage = pObj->GetImage();
735 if (!m_pObjectHolder->HasImageMask()) 730 if (!m_pObjectHolder->HasImageMask())
736 m_pObjectHolder->SetHasImageMask(m_pLastImage->IsMask()); 731 m_pObjectHolder->SetHasImageMask(m_pLastImage->IsMask());
737 } else if (type == "Form") { 732 } else if (type == "Form") {
738 AddForm(pXObject); 733 AddForm(pXObject);
739 } 734 }
740 } 735 }
741 736
742 void CPDF_StreamContentParser::AddForm(CPDF_Stream* pStream) { 737 void CPDF_StreamContentParser::AddForm(CPDF_Stream* pStream) {
(...skipping 10 matching lines...) Expand all
753 pFormObj->m_pForm->ParseContent(&status, nullptr, nullptr, m_Level + 1); 748 pFormObj->m_pForm->ParseContent(&status, nullptr, nullptr, m_Level + 1);
754 if (!m_pObjectHolder->BackgroundAlphaNeeded() && 749 if (!m_pObjectHolder->BackgroundAlphaNeeded() &&
755 pFormObj->m_pForm->BackgroundAlphaNeeded()) { 750 pFormObj->m_pForm->BackgroundAlphaNeeded()) {
756 m_pObjectHolder->SetBackgroundAlphaNeeded(TRUE); 751 m_pObjectHolder->SetBackgroundAlphaNeeded(TRUE);
757 } 752 }
758 pFormObj->CalcBoundingBox(); 753 pFormObj->CalcBoundingBox();
759 SetGraphicStates(pFormObj.get(), true, true, true); 754 SetGraphicStates(pFormObj.get(), true, true, true);
760 m_pObjectHolder->GetPageObjectList()->push_back(std::move(pFormObj)); 755 m_pObjectHolder->GetPageObjectList()->push_back(std::move(pFormObj));
761 } 756 }
762 757
763 CPDF_ImageObject* CPDF_StreamContentParser::AddImage(CPDF_Stream* pStream, 758 CPDF_ImageObject* CPDF_StreamContentParser::AddImage(UniqueStream pStream) {
764 CPDF_Image* pImage, 759 if (!pStream)
765 bool bInline) {
766 if (!pStream && !pImage)
767 return nullptr; 760 return nullptr;
768 761
762 auto pImageObj = pdfium::MakeUnique<CPDF_ImageObject>();
763 pImageObj->SetOwnedImage(
764 pdfium::MakeUnique<CPDF_Image>(m_pDocument, pStream.release(), true));
765
766 return AddImageObject(std::move(pImageObj));
767 }
768
769 CPDF_ImageObject* CPDF_StreamContentParser::AddImage(uint32_t streamObjNum) {
770 CPDF_Stream* pStream = ToStream(m_pDocument->GetIndirectObject(streamObjNum));
771 if (!pStream)
772 return nullptr;
773
774 auto pImageObj = pdfium::MakeUnique<CPDF_ImageObject>();
775 pImageObj->SetUnownedImage(m_pDocument->LoadImageF(pStream));
776 return AddImageObject(std::move(pImageObj));
777 }
778
779 CPDF_ImageObject* CPDF_StreamContentParser::AddImage(CPDF_Image* pImage) {
780 if (!pImage)
781 return nullptr;
782
783 auto pImageObj = pdfium::MakeUnique<CPDF_ImageObject>();
784 pImageObj->SetUnownedImage(
785 m_pDocument->GetPageData()->GetImage(pImage->GetStream()));
786
787 return AddImageObject(std::move(pImageObj));
788 }
789
790 CPDF_ImageObject* CPDF_StreamContentParser::AddImageObject(
791 std::unique_ptr<CPDF_ImageObject> pImageObj) {
792 SetGraphicStates(pImageObj.get(), pImageObj->GetImage()->IsMask(), false,
793 false);
794
769 CFX_Matrix ImageMatrix = m_pCurStates->m_CTM; 795 CFX_Matrix ImageMatrix = m_pCurStates->m_CTM;
770 ImageMatrix.Concat(m_mtContentToUser); 796 ImageMatrix.Concat(m_mtContentToUser);
771
772 std::unique_ptr<CPDF_ImageObject> pImageObj(new CPDF_ImageObject);
773 if (pImage) {
774 pImageObj->SetUnownedImage(
775 m_pDocument->GetPageData()->GetImage(pImage->GetStream()));
776 } else if (!pStream->IsInline()) {
777 pImageObj->SetUnownedImage(m_pDocument->LoadImageF(pStream));
778 } else {
779 pImageObj->SetOwnedImage(
780 pdfium::MakeUnique<CPDF_Image>(m_pDocument, pStream, bInline));
781 }
782 SetGraphicStates(pImageObj.get(), pImageObj->GetImage()->IsMask(), false,
783 false);
784 pImageObj->m_Matrix = ImageMatrix; 797 pImageObj->m_Matrix = ImageMatrix;
785 pImageObj->CalcBoundingBox(); 798 pImageObj->CalcBoundingBox();
799
786 CPDF_ImageObject* pRet = pImageObj.get(); 800 CPDF_ImageObject* pRet = pImageObj.get();
787 m_pObjectHolder->GetPageObjectList()->push_back(std::move(pImageObj)); 801 m_pObjectHolder->GetPageObjectList()->push_back(std::move(pImageObj));
788 return pRet; 802 return pRet;
789 } 803 }
790 804
791 void CPDF_StreamContentParser::Handle_MarkPlace_Dictionary() {} 805 void CPDF_StreamContentParser::Handle_MarkPlace_Dictionary() {}
792 806
793 void CPDF_StreamContentParser::Handle_EndImage() {} 807 void CPDF_StreamContentParser::Handle_EndImage() {}
794 808
795 void CPDF_StreamContentParser::Handle_EndMarkedContent() { 809 void CPDF_StreamContentParser::Handle_EndMarkedContent() {
(...skipping 864 matching lines...) Expand 10 before | Expand all | Expand 10 after
1660 } else { 1674 } else {
1661 PDF_ReplaceAbbr(pElement); 1675 PDF_ReplaceAbbr(pElement);
1662 } 1676 }
1663 } 1677 }
1664 break; 1678 break;
1665 } 1679 }
1666 default: 1680 default:
1667 break; 1681 break;
1668 } 1682 }
1669 } 1683 }
OLDNEW
« no previous file with comments | « no previous file | core/fpdfapi/page/pageint.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698