OLD | NEW |
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 <memory> | 9 #include <memory> |
10 #include <utility> | 10 #include <utility> |
(...skipping 612 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
623 return; | 623 return; |
624 bDirect = false; | 624 bDirect = false; |
625 } | 625 } |
626 if (CPDF_Dictionary* pDict = pProperty->AsDictionary()) { | 626 if (CPDF_Dictionary* pDict = pProperty->AsDictionary()) { |
627 m_CurContentMark.AddMark(tag, pDict, bDirect); | 627 m_CurContentMark.AddMark(tag, pDict, bDirect); |
628 } | 628 } |
629 } | 629 } |
630 | 630 |
631 void CPDF_StreamContentParser::Handle_BeginImage() { | 631 void CPDF_StreamContentParser::Handle_BeginImage() { |
632 FX_FILESIZE savePos = m_pSyntax->GetPos(); | 632 FX_FILESIZE savePos = m_pSyntax->GetPos(); |
633 CPDF_Dictionary* pDict = | 633 auto pDict = |
634 new CPDF_Dictionary(m_pDocument->GetByteStringPool()); | 634 pdfium::MakeUnique<CPDF_Dictionary>(m_pDocument->GetByteStringPool()); |
635 while (1) { | 635 while (1) { |
636 CPDF_StreamParser::SyntaxType type = m_pSyntax->ParseNextElement(); | 636 CPDF_StreamParser::SyntaxType type = m_pSyntax->ParseNextElement(); |
637 if (type == CPDF_StreamParser::Keyword) { | 637 if (type == CPDF_StreamParser::Keyword) { |
638 CFX_ByteString bsKeyword(m_pSyntax->GetWordBuf(), | 638 CFX_ByteString bsKeyword(m_pSyntax->GetWordBuf(), |
639 m_pSyntax->GetWordSize()); | 639 m_pSyntax->GetWordSize()); |
640 if (bsKeyword != "ID") { | 640 if (bsKeyword != "ID") { |
641 m_pSyntax->SetPos(savePos); | 641 m_pSyntax->SetPos(savePos); |
642 delete pDict; | |
643 return; | 642 return; |
644 } | 643 } |
645 } | 644 } |
646 if (type != CPDF_StreamParser::Name) { | 645 if (type != CPDF_StreamParser::Name) { |
647 break; | 646 break; |
648 } | 647 } |
649 CFX_ByteString key((const FX_CHAR*)m_pSyntax->GetWordBuf() + 1, | 648 CFX_ByteString key((const FX_CHAR*)m_pSyntax->GetWordBuf() + 1, |
650 m_pSyntax->GetWordSize() - 1); | 649 m_pSyntax->GetWordSize() - 1); |
651 auto pObj = m_pSyntax->ReadNextObject(false, 0); | 650 auto pObj = m_pSyntax->ReadNextObject(false, 0); |
652 if (!key.IsEmpty()) { | 651 if (!key.IsEmpty()) { |
653 uint32_t dwObjNum = pObj ? pObj->GetObjNum() : 0; | 652 uint32_t dwObjNum = pObj ? pObj->GetObjNum() : 0; |
654 if (dwObjNum) | 653 if (dwObjNum) |
655 pDict->SetNewFor<CPDF_Reference>(key, m_pDocument, dwObjNum); | 654 pDict->SetNewFor<CPDF_Reference>(key, m_pDocument, dwObjNum); |
656 else | 655 else |
657 pDict->SetFor(key, std::move(pObj)); | 656 pDict->SetFor(key, std::move(pObj)); |
658 } | 657 } |
659 } | 658 } |
660 ReplaceAbbr(pDict); | 659 ReplaceAbbr(pDict.get()); |
661 CPDF_Object* pCSObj = nullptr; | 660 CPDF_Object* pCSObj = nullptr; |
662 if (pDict->KeyExist("ColorSpace")) { | 661 if (pDict->KeyExist("ColorSpace")) { |
663 pCSObj = pDict->GetDirectObjectFor("ColorSpace"); | 662 pCSObj = pDict->GetDirectObjectFor("ColorSpace"); |
664 if (pCSObj->IsName()) { | 663 if (pCSObj->IsName()) { |
665 CFX_ByteString name = pCSObj->GetString(); | 664 CFX_ByteString name = pCSObj->GetString(); |
666 if (name != "DeviceRGB" && name != "DeviceGray" && name != "DeviceCMYK") { | 665 if (name != "DeviceRGB" && name != "DeviceGray" && name != "DeviceCMYK") { |
667 pCSObj = FindResourceObj("ColorSpace", name); | 666 pCSObj = FindResourceObj("ColorSpace", name); |
668 if (pCSObj && pCSObj->IsInline()) | 667 if (pCSObj && pCSObj->IsInline()) |
669 pDict->SetFor("ColorSpace", pCSObj->Clone()); | 668 pDict->SetFor("ColorSpace", pCSObj->Clone()); |
670 } | 669 } |
671 } | 670 } |
672 } | 671 } |
673 pDict->SetNewFor<CPDF_Name>("Subtype", "Image"); | 672 pDict->SetNewFor<CPDF_Name>("Subtype", "Image"); |
674 std::unique_ptr<CPDF_Stream> pStream( | 673 std::unique_ptr<CPDF_Stream> pStream = |
675 m_pSyntax->ReadInlineStream(m_pDocument, pDict, pCSObj)); | 674 m_pSyntax->ReadInlineStream(m_pDocument, std::move(pDict), pCSObj); |
676 bool bGaveDictAway = !!pStream; | |
677 while (1) { | 675 while (1) { |
678 CPDF_StreamParser::SyntaxType type = m_pSyntax->ParseNextElement(); | 676 CPDF_StreamParser::SyntaxType type = m_pSyntax->ParseNextElement(); |
679 if (type == CPDF_StreamParser::EndOfData) { | 677 if (type == CPDF_StreamParser::EndOfData) { |
680 break; | 678 break; |
681 } | 679 } |
682 if (type != CPDF_StreamParser::Keyword) { | 680 if (type != CPDF_StreamParser::Keyword) { |
683 continue; | 681 continue; |
684 } | 682 } |
685 if (m_pSyntax->GetWordSize() == 2 && m_pSyntax->GetWordBuf()[0] == 'E' && | 683 if (m_pSyntax->GetWordSize() == 2 && m_pSyntax->GetWordBuf()[0] == 'E' && |
686 m_pSyntax->GetWordBuf()[1] == 'I') { | 684 m_pSyntax->GetWordBuf()[1] == 'I') { |
687 break; | 685 break; |
688 } | 686 } |
689 } | 687 } |
690 CPDF_ImageObject* pImgObj = AddImage(std::move(pStream)); | 688 AddImage(std::move(pStream)); |
691 if (!pImgObj && !bGaveDictAway) | |
692 delete pDict; | |
693 } | 689 } |
694 | 690 |
695 void CPDF_StreamContentParser::Handle_BeginMarkedContent() { | 691 void CPDF_StreamContentParser::Handle_BeginMarkedContent() { |
696 m_CurContentMark.AddMark(GetString(0), nullptr, false); | 692 m_CurContentMark.AddMark(GetString(0), nullptr, false); |
697 } | 693 } |
698 | 694 |
699 void CPDF_StreamContentParser::Handle_BeginText() { | 695 void CPDF_StreamContentParser::Handle_BeginText() { |
700 m_pCurStates->m_TextMatrix.Set(1.0f, 0, 0, 1.0f, 0, 0); | 696 m_pCurStates->m_TextMatrix.Set(1.0f, 0, 0, 1.0f, 0, 0); |
701 OnChangeTextMatrix(); | 697 OnChangeTextMatrix(); |
702 m_pCurStates->m_TextX = 0; | 698 m_pCurStates->m_TextX = 0; |
(...skipping 959 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1662 if (!bProcessed) { | 1658 if (!bProcessed) { |
1663 m_pSyntax->SetPos(last_pos); | 1659 m_pSyntax->SetPos(last_pos); |
1664 return; | 1660 return; |
1665 } | 1661 } |
1666 } | 1662 } |
1667 } | 1663 } |
1668 | 1664 |
1669 CPDF_StreamContentParser::ContentParam::ContentParam() {} | 1665 CPDF_StreamContentParser::ContentParam::ContentParam() {} |
1670 | 1666 |
1671 CPDF_StreamContentParser::ContentParam::~ContentParam() {} | 1667 CPDF_StreamContentParser::ContentParam::~ContentParam() {} |
OLD | NEW |