| OLD | NEW |
| 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/parser/cfdf_document.h" | 7 #include "core/fpdfapi/parser/cfdf_document.h" |
| 8 | 8 |
| 9 #include <memory> | 9 #include <memory> |
| 10 #include <utility> | 10 #include <utility> |
| 11 | 11 |
| 12 #include "core/fpdfapi/edit/cpdf_creator.h" | 12 #include "core/fpdfapi/edit/cpdf_creator.h" |
| 13 #include "core/fpdfapi/parser/cpdf_dictionary.h" | 13 #include "core/fpdfapi/parser/cpdf_dictionary.h" |
| 14 #include "core/fpdfapi/parser/cpdf_syntax_parser.h" | 14 #include "core/fpdfapi/parser/cpdf_syntax_parser.h" |
| 15 #include "third_party/base/ptr_util.h" | 15 #include "third_party/base/ptr_util.h" |
| 16 | 16 |
| 17 CFDF_Document::CFDF_Document() | 17 CFDF_Document::CFDF_Document() |
| 18 : CPDF_IndirectObjectHolder(), | 18 : CPDF_IndirectObjectHolder(), |
| 19 m_pRootDict(nullptr), | 19 m_pRootDict(nullptr), |
| 20 m_pFile(nullptr), | 20 m_pFile(nullptr), |
| 21 m_bOwnFile(false) {} | 21 m_bOwnFile(false) {} |
| 22 | 22 |
| 23 CFDF_Document::~CFDF_Document() { | 23 CFDF_Document::~CFDF_Document() { |
| 24 if (m_bOwnFile && m_pFile) | 24 if (m_bOwnFile && m_pFile) |
| 25 m_pFile->Release(); | 25 m_pFile->Release(); |
| 26 } | 26 } |
| 27 | 27 |
| 28 CFDF_Document* CFDF_Document::CreateNewDoc() { | 28 std::unique_ptr<CFDF_Document> CFDF_Document::CreateNewDoc() { |
| 29 CFDF_Document* pDoc = new CFDF_Document; | 29 auto pDoc = pdfium::MakeUnique<CFDF_Document>(); |
| 30 pDoc->m_pRootDict = pDoc->NewIndirect<CPDF_Dictionary>(); | 30 pDoc->m_pRootDict = pDoc->NewIndirect<CPDF_Dictionary>(); |
| 31 pDoc->m_pRootDict->SetNewFor<CPDF_Dictionary>("FDF"); | 31 pDoc->m_pRootDict->SetNewFor<CPDF_Dictionary>("FDF"); |
| 32 return pDoc; | 32 return pDoc; |
| 33 } | 33 } |
| 34 | 34 |
| 35 CFDF_Document* CFDF_Document::ParseFile(IFX_SeekableReadStream* pFile, | 35 std::unique_ptr<CFDF_Document> CFDF_Document::ParseFile( |
| 36 bool bOwnFile) { | 36 IFX_SeekableReadStream* pFile, |
| 37 bool bOwnFile) { |
| 37 if (!pFile) | 38 if (!pFile) |
| 38 return nullptr; | 39 return nullptr; |
| 39 | 40 |
| 40 std::unique_ptr<CFDF_Document> pDoc(new CFDF_Document); | 41 auto pDoc = pdfium::MakeUnique<CFDF_Document>(); |
| 41 pDoc->ParseStream(pFile, bOwnFile); | 42 pDoc->ParseStream(pFile, bOwnFile); |
| 42 return pDoc->m_pRootDict ? pDoc.release() : nullptr; | 43 return pDoc->m_pRootDict ? std::move(pDoc) : nullptr; |
| 43 } | 44 } |
| 44 | 45 |
| 45 CFDF_Document* CFDF_Document::ParseMemory(const uint8_t* pData, uint32_t size) { | 46 std::unique_ptr<CFDF_Document> CFDF_Document::ParseMemory(const uint8_t* pData, |
| 47 uint32_t size) { |
| 46 return CFDF_Document::ParseFile(FX_CreateMemoryStream((uint8_t*)pData, size), | 48 return CFDF_Document::ParseFile(FX_CreateMemoryStream((uint8_t*)pData, size), |
| 47 true); | 49 true); |
| 48 } | 50 } |
| 49 | 51 |
| 50 void CFDF_Document::ParseStream(IFX_SeekableReadStream* pFile, bool bOwnFile) { | 52 void CFDF_Document::ParseStream(IFX_SeekableReadStream* pFile, bool bOwnFile) { |
| 51 m_pFile = pFile; | 53 m_pFile = pFile; |
| 52 m_bOwnFile = bOwnFile; | 54 m_bOwnFile = bOwnFile; |
| 53 CPDF_SyntaxParser parser; | 55 CPDF_SyntaxParser parser; |
| 54 parser.InitParser(m_pFile, 0); | 56 parser.InitParser(m_pFile, 0); |
| 55 while (1) { | 57 while (1) { |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 97 | 99 |
| 98 buf << "%FDF-1.2\r\n"; | 100 buf << "%FDF-1.2\r\n"; |
| 99 for (const auto& pair : *this) | 101 for (const auto& pair : *this) |
| 100 buf << pair.first << " 0 obj\r\n" | 102 buf << pair.first << " 0 obj\r\n" |
| 101 << pair.second.get() << "\r\nendobj\r\n\r\n"; | 103 << pair.second.get() << "\r\nendobj\r\n\r\n"; |
| 102 | 104 |
| 103 buf << "trailer\r\n<</Root " << m_pRootDict->GetObjNum() | 105 buf << "trailer\r\n<</Root " << m_pRootDict->GetObjNum() |
| 104 << " 0 R>>\r\n%%EOF\r\n"; | 106 << " 0 R>>\r\n%%EOF\r\n"; |
| 105 return true; | 107 return true; |
| 106 } | 108 } |
| OLD | NEW |