| 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 "core/fpdfapi/edit/cpdf_creator.h" | 9 #include "core/fpdfapi/edit/cpdf_creator.h" |
| 10 #include "core/fpdfapi/parser/cpdf_dictionary.h" | 10 #include "core/fpdfapi/parser/cpdf_dictionary.h" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 | 26 |
| 27 CFDF_Document* CFDF_Document::CreateNewDoc() { | 27 CFDF_Document* CFDF_Document::CreateNewDoc() { |
| 28 CFDF_Document* pDoc = new CFDF_Document; | 28 CFDF_Document* pDoc = new CFDF_Document; |
| 29 pDoc->m_pRootDict = new CPDF_Dictionary(pDoc->GetByteStringPool()); | 29 pDoc->m_pRootDict = new CPDF_Dictionary(pDoc->GetByteStringPool()); |
| 30 pDoc->AddIndirectObject(pDoc->m_pRootDict); | 30 pDoc->AddIndirectObject(pDoc->m_pRootDict); |
| 31 pDoc->m_pRootDict->SetFor("FDF", | 31 pDoc->m_pRootDict->SetFor("FDF", |
| 32 new CPDF_Dictionary(pDoc->GetByteStringPool())); | 32 new CPDF_Dictionary(pDoc->GetByteStringPool())); |
| 33 return pDoc; | 33 return pDoc; |
| 34 } | 34 } |
| 35 | 35 |
| 36 CFDF_Document* CFDF_Document::ParseFile(IFX_FileRead* pFile, FX_BOOL bOwnFile) { | 36 CFDF_Document* CFDF_Document::ParseFile(IFX_SeekableReadStream* pFile, |
| 37 FX_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 std::unique_ptr<CFDF_Document> pDoc(new 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 ? pDoc.release() : nullptr; |
| 43 } | 44 } |
| 44 | 45 |
| 45 CFDF_Document* CFDF_Document::ParseMemory(const uint8_t* pData, uint32_t size) { | 46 CFDF_Document* CFDF_Document::ParseMemory(const uint8_t* pData, uint32_t size) { |
| 46 return CFDF_Document::ParseFile(FX_CreateMemoryStream((uint8_t*)pData, size), | 47 return CFDF_Document::ParseFile(FX_CreateMemoryStream((uint8_t*)pData, size), |
| 47 TRUE); | 48 TRUE); |
| 48 } | 49 } |
| 49 | 50 |
| 50 void CFDF_Document::ParseStream(IFX_FileRead* pFile, FX_BOOL bOwnFile) { | 51 void CFDF_Document::ParseStream(IFX_SeekableReadStream* pFile, |
| 52 FX_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) { |
| 56 bool bNumber; | 58 bool bNumber; |
| 57 CFX_ByteString word = parser.GetNextWord(&bNumber); | 59 CFX_ByteString word = parser.GetNextWord(&bNumber); |
| 58 if (bNumber) { | 60 if (bNumber) { |
| 59 uint32_t objnum = FXSYS_atoui(word.c_str()); | 61 uint32_t objnum = FXSYS_atoui(word.c_str()); |
| 60 word = parser.GetNextWord(&bNumber); | 62 word = parser.GetNextWord(&bNumber); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 93 | 95 |
| 94 buf << "%FDF-1.2\r\n"; | 96 buf << "%FDF-1.2\r\n"; |
| 95 for (const auto& pair : *this) | 97 for (const auto& pair : *this) |
| 96 buf << pair.first << " 0 obj\r\n" | 98 buf << pair.first << " 0 obj\r\n" |
| 97 << pair.second.get() << "\r\nendobj\r\n\r\n"; | 99 << pair.second.get() << "\r\nendobj\r\n\r\n"; |
| 98 | 100 |
| 99 buf << "trailer\r\n<</Root " << m_pRootDict->GetObjNum() | 101 buf << "trailer\r\n<</Root " << m_pRootDict->GetObjNum() |
| 100 << " 0 R>>\r\n%%EOF\r\n"; | 102 << " 0 R>>\r\n%%EOF\r\n"; |
| 101 return TRUE; | 103 return TRUE; |
| 102 } | 104 } |
| OLD | NEW |