| 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 "fpdfsdk/include/fsdk_define.h" |
| 10 #include "public/fpdf_edit.h" |
| 11 |
| 9 #ifdef PDF_ENABLE_XFA | 12 #ifdef PDF_ENABLE_XFA |
| 10 #include "../include/fpdfxfa/fpdfxfa_app.h" | 13 #include "../include/fpdfxfa/fpdfxfa_app.h" |
| 11 #include "../include/fpdfxfa/fpdfxfa_doc.h" | 14 #include "../include/fpdfxfa/fpdfxfa_doc.h" |
| 12 #include "../include/fpdfxfa/fpdfxfa_util.h" | 15 #include "../include/fpdfxfa/fpdfxfa_util.h" |
| 13 #endif | |
| 14 #include "fpdfsdk/include/fsdk_define.h" | |
| 15 #include "public/fpdf_edit.h" | |
| 16 #ifdef PDF_ENABLE_XFA | |
| 17 #include "public/fpdf_formfill.h" | 16 #include "public/fpdf_formfill.h" |
| 18 #endif | 17 #endif |
| 19 | 18 |
| 20 #if _FX_OS_ == _FX_ANDROID_ | 19 #if _FX_OS_ == _FX_ANDROID_ |
| 21 #include "time.h" | 20 #include "time.h" |
| 22 #else | 21 #else |
| 23 #include <ctime> | 22 #include <ctime> |
| 24 #endif | 23 #endif |
| 25 | 24 |
| 26 class CFX_IFileWrite final : public IFX_StreamWrite { | 25 class CFX_IFileWrite final : public IFX_StreamWrite { |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 void CFX_IFileWrite::Release() { | 58 void CFX_IFileWrite::Release() { |
| 60 delete this; | 59 delete this; |
| 61 } | 60 } |
| 62 | 61 |
| 63 #ifdef PDF_ENABLE_XFA | 62 #ifdef PDF_ENABLE_XFA |
| 64 #define XFA_DATASETS 0 | 63 #define XFA_DATASETS 0 |
| 65 #define XFA_FORMS 1 | 64 #define XFA_FORMS 1 |
| 66 | 65 |
| 67 FX_BOOL _SaveXFADocumentData(CPDFXFA_Document* pDocument, | 66 FX_BOOL _SaveXFADocumentData(CPDFXFA_Document* pDocument, |
| 68 CFX_PtrArray& fileList) { | 67 CFX_PtrArray& fileList) { |
| 69 #ifdef PDF_ENABLE_XFA | |
| 70 if (!pDocument) | 68 if (!pDocument) |
| 71 return FALSE; | 69 return FALSE; |
| 72 if (pDocument->GetDocType() != DOCTYPE_DYNAMIC_XFA && | 70 if (pDocument->GetDocType() != DOCTYPE_DYNAMIC_XFA && |
| 73 pDocument->GetDocType() != DOCTYPE_STATIC_XFA) | 71 pDocument->GetDocType() != DOCTYPE_STATIC_XFA) |
| 74 return TRUE; | 72 return TRUE; |
| 75 if (!CPDFXFA_App::GetInstance()->GetXFAApp()) | 73 if (!CPDFXFA_App::GetInstance()->GetXFAApp()) |
| 76 return TRUE; | 74 return TRUE; |
| 77 | 75 |
| 78 IXFA_DocView* pXFADocView = pDocument->GetXFADocView(); | 76 IXFA_DocView* pXFADocView = pDocument->GetXFADocView(); |
| 79 if (NULL == pXFADocView) | 77 if (NULL == pXFADocView) |
| (...skipping 29 matching lines...) Expand all Loading... |
| 109 if (pPDFObj->GetType() != PDFOBJ_STRING) | 107 if (pPDFObj->GetType() != PDFOBJ_STRING) |
| 110 continue; | 108 continue; |
| 111 if (pPDFObj->GetString() == "form") | 109 if (pPDFObj->GetString() == "form") |
| 112 iFormIndex = i + 1; | 110 iFormIndex = i + 1; |
| 113 else if (pPDFObj->GetString() == "datasets") | 111 else if (pPDFObj->GetString() == "datasets") |
| 114 iDataSetsIndex = i + 1; | 112 iDataSetsIndex = i + 1; |
| 115 else if (pPDFObj->GetString() == FX_BSTRC("template")) | 113 else if (pPDFObj->GetString() == FX_BSTRC("template")) |
| 116 iTemplate = i + 1; | 114 iTemplate = i + 1; |
| 117 } | 115 } |
| 118 IXFA_ChecksumContext* pContext = NULL; | 116 IXFA_ChecksumContext* pContext = NULL; |
| 119 #define XFA_USECKSUM | |
| 120 #ifdef XFA_USECKSUM | |
| 121 // Checksum | 117 // Checksum |
| 122 pContext = XFA_Checksum_Create(); | 118 pContext = XFA_Checksum_Create(); |
| 123 FXSYS_assert(pContext); | 119 FXSYS_assert(pContext); |
| 124 pContext->StartChecksum(); | 120 pContext->StartChecksum(); |
| 125 | 121 |
| 126 // template | 122 // template |
| 127 if (iTemplate > -1) { | 123 if (iTemplate > -1) { |
| 128 CPDF_Stream* pTemplateStream = pArray->GetStream(iTemplate); | 124 CPDF_Stream* pTemplateStream = pArray->GetStream(iTemplate); |
| 129 CPDF_StreamAcc streamAcc; | 125 CPDF_StreamAcc streamAcc; |
| 130 streamAcc.LoadAllData(pTemplateStream); | 126 streamAcc.LoadAllData(pTemplateStream); |
| 131 uint8_t* pData = (uint8_t*)streamAcc.GetData(); | 127 uint8_t* pData = (uint8_t*)streamAcc.GetData(); |
| 132 FX_DWORD dwSize2 = streamAcc.GetSize(); | 128 FX_DWORD dwSize2 = streamAcc.GetSize(); |
| 133 IFX_FileStream* pTemplate = FX_CreateMemoryStream(pData, dwSize2); | 129 IFX_FileStream* pTemplate = FX_CreateMemoryStream(pData, dwSize2); |
| 134 pContext->UpdateChecksum((IFX_FileRead*)pTemplate); | 130 pContext->UpdateChecksum((IFX_FileRead*)pTemplate); |
| 135 pTemplate->Release(); | 131 pTemplate->Release(); |
| 136 } | 132 } |
| 137 #endif | |
| 138 CPDF_Stream* pFormStream = NULL; | 133 CPDF_Stream* pFormStream = NULL; |
| 139 CPDF_Stream* pDataSetsStream = NULL; | 134 CPDF_Stream* pDataSetsStream = NULL; |
| 140 if (iFormIndex != -1) { | 135 if (iFormIndex != -1) { |
| 141 // Get form CPDF_Stream | 136 // Get form CPDF_Stream |
| 142 CPDF_Object* pFormPDFObj = pArray->GetElement(iFormIndex); | 137 CPDF_Object* pFormPDFObj = pArray->GetElement(iFormIndex); |
| 143 if (pFormPDFObj->GetType() == PDFOBJ_REFERENCE) { | 138 if (pFormPDFObj->GetType() == PDFOBJ_REFERENCE) { |
| 144 CPDF_Object* pFormDircetObj = pFormPDFObj->GetDirect(); | 139 CPDF_Object* pFormDircetObj = pFormPDFObj->GetDirect(); |
| 145 if (NULL != pFormDircetObj && | 140 if (NULL != pFormDircetObj && |
| 146 pFormDircetObj->GetType() == PDFOBJ_STREAM) { | 141 pFormDircetObj->GetType() == PDFOBJ_STREAM) { |
| 147 pFormStream = (CPDF_Stream*)pFormDircetObj; | 142 pFormStream = (CPDF_Stream*)pFormDircetObj; |
| (...skipping 23 matching lines...) Expand all Loading... |
| 171 IFX_FileStream* pDsfileWrite = FX_CreateMemoryStream(); | 166 IFX_FileStream* pDsfileWrite = FX_CreateMemoryStream(); |
| 172 if (NULL == pDsfileWrite) { | 167 if (NULL == pDsfileWrite) { |
| 173 pContext->Release(); | 168 pContext->Release(); |
| 174 pDsfileWrite->Release(); | 169 pDsfileWrite->Release(); |
| 175 return FALSE; | 170 return FALSE; |
| 176 } | 171 } |
| 177 if (pXFADocHandler->SavePackage(pXFADocView->GetDoc(), | 172 if (pXFADocHandler->SavePackage(pXFADocView->GetDoc(), |
| 178 CFX_WideStringC(L"datasets"), | 173 CFX_WideStringC(L"datasets"), |
| 179 pDsfileWrite) && | 174 pDsfileWrite) && |
| 180 pDsfileWrite->GetSize() > 0) { | 175 pDsfileWrite->GetSize() > 0) { |
| 181 #ifdef XFA_USECKSUM | |
| 182 // Datasets | 176 // Datasets |
| 183 pContext->UpdateChecksum((IFX_FileRead*)pDsfileWrite); | 177 pContext->UpdateChecksum((IFX_FileRead*)pDsfileWrite); |
| 184 pContext->FinishChecksum(); | 178 pContext->FinishChecksum(); |
| 185 #endif | |
| 186 CPDF_Dictionary* pDataDict = new CPDF_Dictionary; | 179 CPDF_Dictionary* pDataDict = new CPDF_Dictionary; |
| 187 if (iDataSetsIndex != -1) { | 180 if (iDataSetsIndex != -1) { |
| 188 if (pDataSetsStream) | 181 if (pDataSetsStream) |
| 189 pDataSetsStream->InitStreamFromFile(pDsfileWrite, pDataDict); | 182 pDataSetsStream->InitStreamFromFile(pDsfileWrite, pDataDict); |
| 190 } else { | 183 } else { |
| 191 CPDF_Stream* pData = new CPDF_Stream(NULL, 0, NULL); | 184 CPDF_Stream* pData = new CPDF_Stream(NULL, 0, NULL); |
| 192 pData->InitStreamFromFile(pDsfileWrite, pDataDict); | 185 pData->InitStreamFromFile(pDsfileWrite, pDataDict); |
| 193 pPDFDocument->AddIndirectObject(pData); | 186 pPDFDocument->AddIndirectObject(pData); |
| 194 iLast = pArray->GetCount() - 2; | 187 iLast = pArray->GetCount() - 2; |
| 195 pArray->InsertAt(iLast, CPDF_String::Create("datasets")); | 188 pArray->InsertAt(iLast, CPDF_String::Create("datasets")); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 219 pData->InitStreamFromFile(pfileWrite, pDataDict); | 212 pData->InitStreamFromFile(pfileWrite, pDataDict); |
| 220 pPDFDocument->AddIndirectObject(pData); | 213 pPDFDocument->AddIndirectObject(pData); |
| 221 iLast = pArray->GetCount() - 2; | 214 iLast = pArray->GetCount() - 2; |
| 222 pArray->InsertAt(iLast, CPDF_String::Create("form")); | 215 pArray->InsertAt(iLast, CPDF_String::Create("form")); |
| 223 pArray->InsertAt(iLast + 1, pData, pPDFDocument); | 216 pArray->InsertAt(iLast + 1, pData, pPDFDocument); |
| 224 } | 217 } |
| 225 fileList.Add(pfileWrite); | 218 fileList.Add(pfileWrite); |
| 226 } | 219 } |
| 227 } | 220 } |
| 228 pContext->Release(); | 221 pContext->Release(); |
| 229 #endif // PDF_ENABLE_XFA | |
| 230 | |
| 231 return TRUE; | 222 return TRUE; |
| 232 } | 223 } |
| 233 | 224 |
| 234 FX_BOOL _SendPostSaveToXFADoc(CPDFXFA_Document* pDocument) { | 225 FX_BOOL _SendPostSaveToXFADoc(CPDFXFA_Document* pDocument) { |
| 235 if (!pDocument) | 226 if (!pDocument) |
| 236 return FALSE; | 227 return FALSE; |
| 237 | 228 |
| 238 if (pDocument->GetDocType() != DOCTYPE_DYNAMIC_XFA && | 229 if (pDocument->GetDocType() != DOCTYPE_DYNAMIC_XFA && |
| 239 pDocument->GetDocType() != DOCTYPE_STATIC_XFA) | 230 pDocument->GetDocType() != DOCTYPE_STATIC_XFA) |
| 240 return TRUE; | 231 return TRUE; |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 276 while (pWidgetAcc) { | 267 while (pWidgetAcc) { |
| 277 CXFA_EventParam preParam; | 268 CXFA_EventParam preParam; |
| 278 preParam.m_eType = XFA_EVENT_PreSave; | 269 preParam.m_eType = XFA_EVENT_PreSave; |
| 279 pWidgetHander->ProcessEvent(pWidgetAcc, &preParam); | 270 pWidgetHander->ProcessEvent(pWidgetAcc, &preParam); |
| 280 pWidgetAcc = pWidgetAccIterator->MoveToNext(); | 271 pWidgetAcc = pWidgetAccIterator->MoveToNext(); |
| 281 } | 272 } |
| 282 pWidgetAccIterator->Release(); | 273 pWidgetAccIterator->Release(); |
| 283 pXFADocView->UpdateDocView(); | 274 pXFADocView->UpdateDocView(); |
| 284 return _SaveXFADocumentData(pDocument, fileList); | 275 return _SaveXFADocumentData(pDocument, fileList); |
| 285 } | 276 } |
| 277 #endif // PDF_ENABLE_XFA |
| 286 | 278 |
| 287 #endif | |
| 288 FPDF_BOOL _FPDF_Doc_Save(FPDF_DOCUMENT document, | 279 FPDF_BOOL _FPDF_Doc_Save(FPDF_DOCUMENT document, |
| 289 FPDF_FILEWRITE* pFileWrite, | 280 FPDF_FILEWRITE* pFileWrite, |
| 290 FPDF_DWORD flags, | 281 FPDF_DWORD flags, |
| 291 FPDF_BOOL bSetVersion, | 282 FPDF_BOOL bSetVersion, |
| 292 int fileVerion) { | 283 int fileVerion) { |
| 293 CPDF_Document* pPDFDoc = CPDFDocumentFromFPDFDocument(document); | 284 CPDF_Document* pPDFDoc = CPDFDocumentFromFPDFDocument(document); |
| 294 if (!pPDFDoc) | 285 if (!pPDFDoc) |
| 295 return 0; | 286 return 0; |
| 296 | 287 |
| 297 #ifdef PDF_ENABLE_XFA | 288 #ifdef PDF_ENABLE_XFA |
| 298 CPDFXFA_Document* pDoc = (CPDFXFA_Document*)document; | 289 CPDFXFA_Document* pDoc = (CPDFXFA_Document*)document; |
| 299 CFX_PtrArray fileList; | 290 CFX_PtrArray fileList; |
| 300 _SendPreSaveToXFADoc(pDoc, fileList); | 291 _SendPreSaveToXFADoc(pDoc, fileList); |
| 292 #endif // PDF_ENABLE_XFA |
| 301 | 293 |
| 302 #endif | |
| 303 if (flags < FPDF_INCREMENTAL || flags > FPDF_REMOVE_SECURITY) { | 294 if (flags < FPDF_INCREMENTAL || flags > FPDF_REMOVE_SECURITY) { |
| 304 flags = 0; | 295 flags = 0; |
| 305 } | 296 } |
| 306 | 297 |
| 307 CPDF_Creator FileMaker(pPDFDoc); | 298 CPDF_Creator FileMaker(pPDFDoc); |
| 308 if (bSetVersion) | 299 if (bSetVersion) |
| 309 FileMaker.SetFileVersion(fileVerion); | 300 FileMaker.SetFileVersion(fileVerion); |
| 310 if (flags == FPDF_REMOVE_SECURITY) { | 301 if (flags == FPDF_REMOVE_SECURITY) { |
| 311 flags = 0; | 302 flags = 0; |
| 312 FileMaker.RemoveSecurity(); | 303 FileMaker.RemoveSecurity(); |
| 313 } | 304 } |
| 314 | 305 |
| 315 CFX_IFileWrite* pStreamWrite = NULL; | 306 CFX_IFileWrite* pStreamWrite = NULL; |
| 316 FX_BOOL bRet; | 307 FX_BOOL bRet; |
| 317 pStreamWrite = new CFX_IFileWrite; | 308 pStreamWrite = new CFX_IFileWrite; |
| 318 pStreamWrite->Init(pFileWrite); | 309 pStreamWrite->Init(pFileWrite); |
| 319 bRet = FileMaker.Create(pStreamWrite, flags); | 310 bRet = FileMaker.Create(pStreamWrite, flags); |
| 320 #ifdef PDF_ENABLE_XFA | 311 #ifdef PDF_ENABLE_XFA |
| 321 _SendPostSaveToXFADoc(pDoc); | 312 _SendPostSaveToXFADoc(pDoc); |
| 322 for (int i = 0; i < fileList.GetSize(); i++) { | 313 for (int i = 0; i < fileList.GetSize(); i++) { |
| 323 IFX_FileStream* pFile = (IFX_FileStream*)fileList.GetAt(i); | 314 IFX_FileStream* pFile = (IFX_FileStream*)fileList.GetAt(i); |
| 324 pFile->Release(); | 315 pFile->Release(); |
| 325 } | 316 } |
| 326 fileList.RemoveAll(); | 317 fileList.RemoveAll(); |
| 327 #endif | 318 #endif // PDF_ENABLE_XFA |
| 328 pStreamWrite->Release(); | 319 pStreamWrite->Release(); |
| 329 return bRet; | 320 return bRet; |
| 330 } | 321 } |
| 331 | 322 |
| 332 DLLEXPORT FPDF_BOOL STDCALL FPDF_SaveAsCopy(FPDF_DOCUMENT document, | 323 DLLEXPORT FPDF_BOOL STDCALL FPDF_SaveAsCopy(FPDF_DOCUMENT document, |
| 333 FPDF_FILEWRITE* pFileWrite, | 324 FPDF_FILEWRITE* pFileWrite, |
| 334 FPDF_DWORD flags) { | 325 FPDF_DWORD flags) { |
| 335 return _FPDF_Doc_Save(document, pFileWrite, flags, FALSE, 0); | 326 return _FPDF_Doc_Save(document, pFileWrite, flags, FALSE, 0); |
| 336 } | 327 } |
| 337 | 328 |
| 338 DLLEXPORT FPDF_BOOL STDCALL FPDF_SaveWithVersion(FPDF_DOCUMENT document, | 329 DLLEXPORT FPDF_BOOL STDCALL FPDF_SaveWithVersion(FPDF_DOCUMENT document, |
| 339 FPDF_FILEWRITE* pFileWrite, | 330 FPDF_FILEWRITE* pFileWrite, |
| 340 FPDF_DWORD flags, | 331 FPDF_DWORD flags, |
| 341 int fileVersion) { | 332 int fileVersion) { |
| 342 return _FPDF_Doc_Save(document, pFileWrite, flags, TRUE, fileVersion); | 333 return _FPDF_Doc_Save(document, pFileWrite, flags, TRUE, fileVersion); |
| 343 } | 334 } |
| OLD | NEW |