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 "public/fpdf_save.h" | 7 #include "public/fpdf_save.h" |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 #include <utility> | 10 #include <utility> |
(...skipping 118 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
129 std::unique_ptr<CXFA_ChecksumContext> pChecksum(new CXFA_ChecksumContext); | 129 std::unique_ptr<CXFA_ChecksumContext> pChecksum(new CXFA_ChecksumContext); |
130 pChecksum->StartChecksum(); | 130 pChecksum->StartChecksum(); |
131 | 131 |
132 // template | 132 // template |
133 if (iTemplate > -1) { | 133 if (iTemplate > -1) { |
134 CPDF_Stream* pTemplateStream = pArray->GetStreamAt(iTemplate); | 134 CPDF_Stream* pTemplateStream = pArray->GetStreamAt(iTemplate); |
135 CPDF_StreamAcc streamAcc; | 135 CPDF_StreamAcc streamAcc; |
136 streamAcc.LoadAllData(pTemplateStream); | 136 streamAcc.LoadAllData(pTemplateStream); |
137 uint8_t* pData = (uint8_t*)streamAcc.GetData(); | 137 uint8_t* pData = (uint8_t*)streamAcc.GetData(); |
138 uint32_t dwSize2 = streamAcc.GetSize(); | 138 uint32_t dwSize2 = streamAcc.GetSize(); |
139 ScopedFileStream pTemplate(FX_CreateMemoryStream(pData, dwSize2)); | 139 ScopedFileStream pTemplate(IFX_MemoryStream::Create(pData, dwSize2)); |
140 pChecksum->UpdateChecksum(pTemplate.get()); | 140 pChecksum->UpdateChecksum(pTemplate.get()); |
141 } | 141 } |
142 CPDF_Stream* pFormStream = nullptr; | 142 CPDF_Stream* pFormStream = nullptr; |
143 CPDF_Stream* pDataSetsStream = nullptr; | 143 CPDF_Stream* pDataSetsStream = nullptr; |
144 if (iFormIndex != -1) { | 144 if (iFormIndex != -1) { |
145 // Get form CPDF_Stream | 145 // Get form CPDF_Stream |
146 CPDF_Object* pFormPDFObj = pArray->GetObjectAt(iFormIndex); | 146 CPDF_Object* pFormPDFObj = pArray->GetObjectAt(iFormIndex); |
147 if (pFormPDFObj->IsReference()) { | 147 if (pFormPDFObj->IsReference()) { |
148 CPDF_Object* pFormDirectObj = pFormPDFObj->GetDirect(); | 148 CPDF_Object* pFormDirectObj = pFormPDFObj->GetDirect(); |
149 if (pFormDirectObj && pFormDirectObj->IsStream()) { | 149 if (pFormDirectObj && pFormDirectObj->IsStream()) { |
(...skipping 12 matching lines...) Expand all Loading... |
162 CPDF_Object* pDataSetsDirectObj = pDataSetsRefObj->GetDirect(); | 162 CPDF_Object* pDataSetsDirectObj = pDataSetsRefObj->GetDirect(); |
163 if (pDataSetsDirectObj && pDataSetsDirectObj->IsStream()) { | 163 if (pDataSetsDirectObj && pDataSetsDirectObj->IsStream()) { |
164 pDataSetsStream = (CPDF_Stream*)pDataSetsDirectObj; | 164 pDataSetsStream = (CPDF_Stream*)pDataSetsDirectObj; |
165 } | 165 } |
166 } else if (pDataSetsPDFObj->IsStream()) { | 166 } else if (pDataSetsPDFObj->IsStream()) { |
167 pDataSetsStream = (CPDF_Stream*)pDataSetsPDFObj; | 167 pDataSetsStream = (CPDF_Stream*)pDataSetsPDFObj; |
168 } | 168 } |
169 } | 169 } |
170 // L"datasets" | 170 // L"datasets" |
171 { | 171 { |
172 ScopedFileStream pDsfileWrite(FX_CreateMemoryStream()); | 172 ScopedFileStream pDsfileWrite(IFX_MemoryStream::Create()); |
173 if (pXFADocView->GetDoc()->SavePackage(XFA_HASHCODE_Datasets, | 173 if (pXFADocView->GetDoc()->SavePackage(XFA_HASHCODE_Datasets, |
174 pDsfileWrite.get(), nullptr) && | 174 pDsfileWrite.get(), nullptr) && |
175 pDsfileWrite->GetSize() > 0) { | 175 pDsfileWrite->GetSize() > 0) { |
176 // Datasets | 176 // Datasets |
177 pChecksum->UpdateChecksum(pDsfileWrite.get()); | 177 pChecksum->UpdateChecksum(pDsfileWrite.get()); |
178 pChecksum->FinishChecksum(); | 178 pChecksum->FinishChecksum(); |
179 auto pDataDict = pdfium::MakeUnique<CPDF_Dictionary>( | 179 auto pDataDict = pdfium::MakeUnique<CPDF_Dictionary>( |
180 pPDFDocument->GetByteStringPool()); | 180 pPDFDocument->GetByteStringPool()); |
181 if (iDataSetsIndex != -1) { | 181 if (iDataSetsIndex != -1) { |
182 if (pDataSetsStream) { | 182 if (pDataSetsStream) { |
183 pDataSetsStream->InitStreamFromFile(pDsfileWrite.get(), | 183 pDataSetsStream->InitStreamFromFile(pDsfileWrite.get(), |
184 std::move(pDataDict)); | 184 std::move(pDataDict)); |
185 } | 185 } |
186 } else { | 186 } else { |
187 CPDF_Stream* pData = pPDFDocument->NewIndirect<CPDF_Stream>(); | 187 CPDF_Stream* pData = pPDFDocument->NewIndirect<CPDF_Stream>(); |
188 pData->InitStreamFromFile(pDsfileWrite.get(), std::move(pDataDict)); | 188 pData->InitStreamFromFile(pDsfileWrite.get(), std::move(pDataDict)); |
189 iLast = pArray->GetCount() - 2; | 189 iLast = pArray->GetCount() - 2; |
190 pArray->InsertNewAt<CPDF_String>(iLast, "datasets", false); | 190 pArray->InsertNewAt<CPDF_String>(iLast, "datasets", false); |
191 pArray->InsertNewAt<CPDF_Reference>(iLast + 1, pPDFDocument, | 191 pArray->InsertNewAt<CPDF_Reference>(iLast + 1, pPDFDocument, |
192 pData->GetObjNum()); | 192 pData->GetObjNum()); |
193 } | 193 } |
194 fileList->push_back(std::move(pDsfileWrite)); | 194 fileList->push_back(std::move(pDsfileWrite)); |
195 } | 195 } |
196 } | 196 } |
197 // L"form" | 197 // L"form" |
198 { | 198 { |
199 ScopedFileStream pfileWrite(FX_CreateMemoryStream()); | 199 ScopedFileStream pfileWrite(IFX_MemoryStream::Create()); |
200 if (pXFADocView->GetDoc()->SavePackage(XFA_HASHCODE_Form, pfileWrite.get(), | 200 if (pXFADocView->GetDoc()->SavePackage(XFA_HASHCODE_Form, pfileWrite.get(), |
201 pChecksum.get()) && | 201 pChecksum.get()) && |
202 pfileWrite->GetSize() > 0) { | 202 pfileWrite->GetSize() > 0) { |
203 auto pDataDict = pdfium::MakeUnique<CPDF_Dictionary>( | 203 auto pDataDict = pdfium::MakeUnique<CPDF_Dictionary>( |
204 pPDFDocument->GetByteStringPool()); | 204 pPDFDocument->GetByteStringPool()); |
205 if (iFormIndex != -1) { | 205 if (iFormIndex != -1) { |
206 if (pFormStream) { | 206 if (pFormStream) { |
207 pFormStream->InitStreamFromFile(pfileWrite.get(), | 207 pFormStream->InitStreamFromFile(pfileWrite.get(), |
208 std::move(pDataDict)); | 208 std::move(pDataDict)); |
209 } | 209 } |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
312 FPDF_DWORD flags) { | 312 FPDF_DWORD flags) { |
313 return FPDF_Doc_Save(document, pFileWrite, flags, false, 0); | 313 return FPDF_Doc_Save(document, pFileWrite, flags, false, 0); |
314 } | 314 } |
315 | 315 |
316 DLLEXPORT FPDF_BOOL STDCALL FPDF_SaveWithVersion(FPDF_DOCUMENT document, | 316 DLLEXPORT FPDF_BOOL STDCALL FPDF_SaveWithVersion(FPDF_DOCUMENT document, |
317 FPDF_FILEWRITE* pFileWrite, | 317 FPDF_FILEWRITE* pFileWrite, |
318 FPDF_DWORD flags, | 318 FPDF_DWORD flags, |
319 int fileVersion) { | 319 int fileVersion) { |
320 return FPDF_Doc_Save(document, pFileWrite, flags, true, fileVersion); | 320 return FPDF_Doc_Save(document, pFileWrite, flags, true, fileVersion); |
321 } | 321 } |
OLD | NEW |