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> |
| 10 #include <utility> |
| 11 |
9 #include "core/fpdfapi/edit/cpdf_creator.h" | 12 #include "core/fpdfapi/edit/cpdf_creator.h" |
10 #include "core/fpdfapi/parser/cpdf_dictionary.h" | 13 #include "core/fpdfapi/parser/cpdf_dictionary.h" |
11 #include "core/fpdfapi/parser/cpdf_syntax_parser.h" | 14 #include "core/fpdfapi/parser/cpdf_syntax_parser.h" |
12 #include "third_party/base/ptr_util.h" | 15 #include "third_party/base/ptr_util.h" |
13 | 16 |
14 CFDF_Document::CFDF_Document() | 17 CFDF_Document::CFDF_Document() |
15 : CPDF_IndirectObjectHolder(), | 18 : CPDF_IndirectObjectHolder(), |
16 m_pRootDict(nullptr), | 19 m_pRootDict(nullptr), |
17 m_pFile(nullptr), | 20 m_pFile(nullptr), |
18 m_bOwnFile(false) {} | 21 m_bOwnFile(false) {} |
19 | 22 |
20 CFDF_Document::~CFDF_Document() { | 23 CFDF_Document::~CFDF_Document() { |
21 if (m_bOwnFile && m_pFile) | 24 if (m_bOwnFile && m_pFile) |
22 m_pFile->Release(); | 25 m_pFile->Release(); |
23 } | 26 } |
24 | 27 |
25 CFDF_Document* CFDF_Document::CreateNewDoc() { | 28 CFDF_Document* CFDF_Document::CreateNewDoc() { |
26 CFDF_Document* pDoc = new CFDF_Document; | 29 CFDF_Document* pDoc = new CFDF_Document; |
27 pDoc->m_pRootDict = pDoc->NewIndirect<CPDF_Dictionary>(); | 30 pDoc->m_pRootDict = pDoc->NewIndirect<CPDF_Dictionary>(); |
28 pDoc->m_pRootDict->SetFor("FDF", | 31 pDoc->m_pRootDict->SetNewFor<CPDF_Dictionary>("FDF"); |
29 new CPDF_Dictionary(pDoc->GetByteStringPool())); | |
30 return pDoc; | 32 return pDoc; |
31 } | 33 } |
32 | 34 |
33 CFDF_Document* CFDF_Document::ParseFile(IFX_SeekableReadStream* pFile, | 35 CFDF_Document* CFDF_Document::ParseFile(IFX_SeekableReadStream* pFile, |
34 bool bOwnFile) { | 36 bool bOwnFile) { |
35 if (!pFile) | 37 if (!pFile) |
36 return nullptr; | 38 return nullptr; |
37 | 39 |
38 std::unique_ptr<CFDF_Document> pDoc(new CFDF_Document); | 40 std::unique_ptr<CFDF_Document> pDoc(new CFDF_Document); |
39 pDoc->ParseStream(pFile, bOwnFile); | 41 pDoc->ParseStream(pFile, bOwnFile); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
95 | 97 |
96 buf << "%FDF-1.2\r\n"; | 98 buf << "%FDF-1.2\r\n"; |
97 for (const auto& pair : *this) | 99 for (const auto& pair : *this) |
98 buf << pair.first << " 0 obj\r\n" | 100 buf << pair.first << " 0 obj\r\n" |
99 << pair.second.get() << "\r\nendobj\r\n\r\n"; | 101 << pair.second.get() << "\r\nendobj\r\n\r\n"; |
100 | 102 |
101 buf << "trailer\r\n<</Root " << m_pRootDict->GetObjNum() | 103 buf << "trailer\r\n<</Root " << m_pRootDict->GetObjNum() |
102 << " 0 R>>\r\n%%EOF\r\n"; | 104 << " 0 R>>\r\n%%EOF\r\n"; |
103 return true; | 105 return true; |
104 } | 106 } |
OLD | NEW |