| 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 12 matching lines...) Expand all Loading... |
| 23 #include "core/fpdfapi/page/cpdf_pathobject.h" | 23 #include "core/fpdfapi/page/cpdf_pathobject.h" |
| 24 #include "core/fpdfapi/page/cpdf_shadingobject.h" | 24 #include "core/fpdfapi/page/cpdf_shadingobject.h" |
| 25 #include "core/fpdfapi/page/cpdf_shadingpattern.h" | 25 #include "core/fpdfapi/page/cpdf_shadingpattern.h" |
| 26 #include "core/fpdfapi/page/cpdf_textobject.h" | 26 #include "core/fpdfapi/page/cpdf_textobject.h" |
| 27 #include "core/fpdfapi/page/pageint.h" | 27 #include "core/fpdfapi/page/pageint.h" |
| 28 #include "core/fpdfapi/parser/cpdf_array.h" | 28 #include "core/fpdfapi/parser/cpdf_array.h" |
| 29 #include "core/fpdfapi/parser/cpdf_dictionary.h" | 29 #include "core/fpdfapi/parser/cpdf_dictionary.h" |
| 30 #include "core/fpdfapi/parser/cpdf_document.h" | 30 #include "core/fpdfapi/parser/cpdf_document.h" |
| 31 #include "core/fpdfapi/parser/cpdf_name.h" | 31 #include "core/fpdfapi/parser/cpdf_name.h" |
| 32 #include "core/fpdfapi/parser/cpdf_number.h" | 32 #include "core/fpdfapi/parser/cpdf_number.h" |
| 33 #include "core/fpdfapi/parser/cpdf_reference.h" |
| 33 #include "core/fpdfapi/parser/cpdf_stream.h" | 34 #include "core/fpdfapi/parser/cpdf_stream.h" |
| 34 #include "core/fpdfapi/parser/fpdf_parser_decode.h" | 35 #include "core/fpdfapi/parser/fpdf_parser_decode.h" |
| 35 #include "core/fxcrt/fx_safe_types.h" | 36 #include "core/fxcrt/fx_safe_types.h" |
| 36 #include "core/fxge/cfx_graphstatedata.h" | 37 #include "core/fxge/cfx_graphstatedata.h" |
| 37 #include "third_party/base/ptr_util.h" | 38 #include "third_party/base/ptr_util.h" |
| 38 | 39 |
| 39 namespace { | 40 namespace { |
| 40 | 41 |
| 41 const int kMaxFormLevel = 30; | 42 const int kMaxFormLevel = 30; |
| 42 | 43 |
| (...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 : CFX_ByteStringC(); | 166 : CFX_ByteStringC(); |
| 166 } | 167 } |
| 167 | 168 |
| 168 void ReplaceAbbr(CPDF_Object* pObj) { | 169 void ReplaceAbbr(CPDF_Object* pObj) { |
| 169 switch (pObj->GetType()) { | 170 switch (pObj->GetType()) { |
| 170 case CPDF_Object::DICTIONARY: { | 171 case CPDF_Object::DICTIONARY: { |
| 171 CPDF_Dictionary* pDict = pObj->AsDictionary(); | 172 CPDF_Dictionary* pDict = pObj->AsDictionary(); |
| 172 std::vector<AbbrReplacementOp> replacements; | 173 std::vector<AbbrReplacementOp> replacements; |
| 173 for (const auto& it : *pDict) { | 174 for (const auto& it : *pDict) { |
| 174 CFX_ByteString key = it.first; | 175 CFX_ByteString key = it.first; |
| 175 CPDF_Object* value = it.second; | 176 CPDF_Object* value = it.second.get(); |
| 176 CFX_ByteStringC fullname = FindFullName( | 177 CFX_ByteStringC fullname = FindFullName( |
| 177 InlineKeyAbbr, FX_ArraySize(InlineKeyAbbr), key.AsStringC()); | 178 InlineKeyAbbr, FX_ArraySize(InlineKeyAbbr), key.AsStringC()); |
| 178 if (!fullname.IsEmpty()) { | 179 if (!fullname.IsEmpty()) { |
| 179 AbbrReplacementOp op; | 180 AbbrReplacementOp op; |
| 180 op.is_replace_key = true; | 181 op.is_replace_key = true; |
| 181 op.key = key; | 182 op.key = key; |
| 182 op.replacement = fullname; | 183 op.replacement = fullname; |
| 183 replacements.push_back(op); | 184 replacements.push_back(op); |
| 184 key = fullname; | 185 key = fullname; |
| 185 } | 186 } |
| (...skipping 10 matching lines...) Expand all Loading... |
| 196 replacements.push_back(op); | 197 replacements.push_back(op); |
| 197 } | 198 } |
| 198 } else { | 199 } else { |
| 199 ReplaceAbbr(value); | 200 ReplaceAbbr(value); |
| 200 } | 201 } |
| 201 } | 202 } |
| 202 for (const auto& op : replacements) { | 203 for (const auto& op : replacements) { |
| 203 if (op.is_replace_key) | 204 if (op.is_replace_key) |
| 204 pDict->ReplaceKey(op.key, CFX_ByteString(op.replacement)); | 205 pDict->ReplaceKey(op.key, CFX_ByteString(op.replacement)); |
| 205 else | 206 else |
| 206 pDict->SetNameFor(op.key, CFX_ByteString(op.replacement)); | 207 pDict->SetNewFor<CPDF_Name>(op.key, CFX_ByteString(op.replacement)); |
| 207 } | 208 } |
| 208 break; | 209 break; |
| 209 } | 210 } |
| 210 case CPDF_Object::ARRAY: { | 211 case CPDF_Object::ARRAY: { |
| 211 CPDF_Array* pArray = pObj->AsArray(); | 212 CPDF_Array* pArray = pObj->AsArray(); |
| 212 for (size_t i = 0; i < pArray->GetCount(); i++) { | 213 for (size_t i = 0; i < pArray->GetCount(); i++) { |
| 213 CPDF_Object* pElement = pArray->GetObjectAt(i); | 214 CPDF_Object* pElement = pArray->GetObjectAt(i); |
| 214 if (pElement->IsName()) { | 215 if (pElement->IsName()) { |
| 215 CFX_ByteString name = pElement->GetString(); | 216 CFX_ByteString name = pElement->GetString(); |
| 216 CFX_ByteStringC fullname = FindFullName( | 217 CFX_ByteStringC fullname = FindFullName( |
| (...skipping 426 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 643 m_pSyntax->SetPos(savePos); | 644 m_pSyntax->SetPos(savePos); |
| 644 delete pDict; | 645 delete pDict; |
| 645 return; | 646 return; |
| 646 } | 647 } |
| 647 } | 648 } |
| 648 if (type != CPDF_StreamParser::Name) { | 649 if (type != CPDF_StreamParser::Name) { |
| 649 break; | 650 break; |
| 650 } | 651 } |
| 651 CFX_ByteString key((const FX_CHAR*)m_pSyntax->GetWordBuf() + 1, | 652 CFX_ByteString key((const FX_CHAR*)m_pSyntax->GetWordBuf() + 1, |
| 652 m_pSyntax->GetWordSize() - 1); | 653 m_pSyntax->GetWordSize() - 1); |
| 653 std::unique_ptr<CPDF_Object> pObj(m_pSyntax->ReadNextObject(false, 0)); | 654 auto pObj = pdfium::WrapUnique(m_pSyntax->ReadNextObject(false, 0)); |
| 654 if (!key.IsEmpty()) { | 655 if (!key.IsEmpty()) { |
| 655 uint32_t dwObjNum = pObj ? pObj->GetObjNum() : 0; | 656 uint32_t dwObjNum = pObj ? pObj->GetObjNum() : 0; |
| 656 if (dwObjNum) | 657 if (dwObjNum) |
| 657 pDict->SetReferenceFor(key, m_pDocument, dwObjNum); | 658 pDict->SetNewFor<CPDF_Reference>(key, m_pDocument, dwObjNum); |
| 658 else | 659 else |
| 659 pDict->SetFor(key, pObj.release()); | 660 pDict->SetFor(key, std::move(pObj)); |
| 660 } | 661 } |
| 661 } | 662 } |
| 662 ReplaceAbbr(pDict); | 663 ReplaceAbbr(pDict); |
| 663 CPDF_Object* pCSObj = nullptr; | 664 CPDF_Object* pCSObj = nullptr; |
| 664 if (pDict->KeyExist("ColorSpace")) { | 665 if (pDict->KeyExist("ColorSpace")) { |
| 665 pCSObj = pDict->GetDirectObjectFor("ColorSpace"); | 666 pCSObj = pDict->GetDirectObjectFor("ColorSpace"); |
| 666 if (pCSObj->IsName()) { | 667 if (pCSObj->IsName()) { |
| 667 CFX_ByteString name = pCSObj->GetString(); | 668 CFX_ByteString name = pCSObj->GetString(); |
| 668 if (name != "DeviceRGB" && name != "DeviceGray" && name != "DeviceCMYK") { | 669 if (name != "DeviceRGB" && name != "DeviceGray" && name != "DeviceCMYK") { |
| 669 pCSObj = FindResourceObj("ColorSpace", name); | 670 pCSObj = FindResourceObj("ColorSpace", name); |
| 670 if (pCSObj && pCSObj->IsInline()) { | 671 if (pCSObj && pCSObj->IsInline()) |
| 671 pCSObj = pCSObj->Clone().release(); | 672 pDict->SetFor("ColorSpace", pCSObj->Clone()); |
| 672 pDict->SetFor("ColorSpace", pCSObj); | |
| 673 } | |
| 674 } | 673 } |
| 675 } | 674 } |
| 676 } | 675 } |
| 677 pDict->SetNameFor("Subtype", "Image"); | 676 pDict->SetNewFor<CPDF_Name>("Subtype", "Image"); |
| 678 std::unique_ptr<CPDF_Stream> pStream( | 677 std::unique_ptr<CPDF_Stream> pStream( |
| 679 m_pSyntax->ReadInlineStream(m_pDocument, pDict, pCSObj)); | 678 m_pSyntax->ReadInlineStream(m_pDocument, pDict, pCSObj)); |
| 680 bool bGaveDictAway = !!pStream; | 679 bool bGaveDictAway = !!pStream; |
| 681 while (1) { | 680 while (1) { |
| 682 CPDF_StreamParser::SyntaxType type = m_pSyntax->ParseNextElement(); | 681 CPDF_StreamParser::SyntaxType type = m_pSyntax->ParseNextElement(); |
| 683 if (type == CPDF_StreamParser::EndOfData) { | 682 if (type == CPDF_StreamParser::EndOfData) { |
| 684 break; | 683 break; |
| 685 } | 684 } |
| 686 if (type != CPDF_StreamParser::Keyword) { | 685 if (type != CPDF_StreamParser::Keyword) { |
| 687 continue; | 686 continue; |
| (...skipping 974 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1662 } | 1661 } |
| 1663 default: | 1662 default: |
| 1664 bProcessed = false; | 1663 bProcessed = false; |
| 1665 } | 1664 } |
| 1666 if (!bProcessed) { | 1665 if (!bProcessed) { |
| 1667 m_pSyntax->SetPos(last_pos); | 1666 m_pSyntax->SetPos(last_pos); |
| 1668 return; | 1667 return; |
| 1669 } | 1668 } |
| 1670 } | 1669 } |
| 1671 } | 1670 } |
| OLD | NEW |