Chromium Code Reviews| 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 #ifdef PDF_ENABLE_XFA | |
| 9 #include "../include/fpdfxfa/fpdfxfa_app.h" | 10 #include "../include/fpdfxfa/fpdfxfa_app.h" |
| 10 #include "../include/fpdfxfa/fpdfxfa_doc.h" | 11 #include "../include/fpdfxfa/fpdfxfa_doc.h" |
| 11 #include "../include/fpdfxfa/fpdfxfa_util.h" | 12 #include "../include/fpdfxfa/fpdfxfa_util.h" |
| 13 #endif | |
| 12 #include "fpdfsdk/include/fsdk_define.h" | 14 #include "fpdfsdk/include/fsdk_define.h" |
| 13 #include "public/fpdf_edit.h" | 15 #include "public/fpdf_edit.h" |
| 16 #ifdef PDF_ENABLE_XFA | |
| 14 #include "public/fpdf_formfill.h" | 17 #include "public/fpdf_formfill.h" |
| 18 #endif | |
| 15 | 19 |
| 16 #if _FX_OS_ == _FX_ANDROID_ | 20 #if _FX_OS_ == _FX_ANDROID_ |
| 17 #include "time.h" | 21 #include "time.h" |
| 18 #else | 22 #else |
| 19 #include <ctime> | 23 #include <ctime> |
| 20 #endif | 24 #endif |
| 21 | 25 |
| 22 class CFX_IFileWrite final : public IFX_StreamWrite { | 26 class CFX_IFileWrite final : public IFX_StreamWrite { |
| 23 public: | 27 public: |
| 24 CFX_IFileWrite(); | 28 CFX_IFileWrite(); |
| (...skipping 24 matching lines...) Expand all Loading... | |
| 49 return FALSE; | 53 return FALSE; |
| 50 | 54 |
| 51 m_pFileWriteStruct->WriteBlock(m_pFileWriteStruct, pData, size); | 55 m_pFileWriteStruct->WriteBlock(m_pFileWriteStruct, pData, size); |
| 52 return TRUE; | 56 return TRUE; |
| 53 } | 57 } |
| 54 | 58 |
| 55 void CFX_IFileWrite::Release() { | 59 void CFX_IFileWrite::Release() { |
| 56 delete this; | 60 delete this; |
| 57 } | 61 } |
| 58 | 62 |
| 63 #ifdef PDF_ENABLE_XFA | |
| 59 #define XFA_DATASETS 0 | 64 #define XFA_DATASETS 0 |
| 60 #define XFA_FORMS 1 | 65 #define XFA_FORMS 1 |
| 61 | 66 |
| 62 FX_BOOL _SaveXFADocumentData(CPDFXFA_Document* pDocument, | 67 FX_BOOL _SaveXFADocumentData(CPDFXFA_Document* pDocument, |
| 63 CFX_PtrArray& fileList) { | 68 CFX_PtrArray& fileList) { |
| 64 #ifdef PDF_ENABLE_XFA | 69 #ifdef PDF_ENABLE_XFA |
| 65 if (!pDocument) | 70 if (!pDocument) |
| 66 return FALSE; | 71 return FALSE; |
| 67 if (pDocument->GetDocType() != DOCTYPE_DYNIMIC_XFA && | 72 if (pDocument->GetDocType() != DOCTYPE_DYNIMIC_XFA && |
| 68 pDocument->GetDocType() != DOCTYPE_STATIC_XFA) | 73 pDocument->GetDocType() != DOCTYPE_STATIC_XFA) |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 272 CXFA_EventParam preParam; | 277 CXFA_EventParam preParam; |
| 273 preParam.m_eType = XFA_EVENT_PreSave; | 278 preParam.m_eType = XFA_EVENT_PreSave; |
| 274 pWidgetHander->ProcessEvent(pWidgetAcc, &preParam); | 279 pWidgetHander->ProcessEvent(pWidgetAcc, &preParam); |
| 275 pWidgetAcc = pWidgetAccIterator->MoveToNext(); | 280 pWidgetAcc = pWidgetAccIterator->MoveToNext(); |
| 276 } | 281 } |
| 277 pWidgetAccIterator->Release(); | 282 pWidgetAccIterator->Release(); |
| 278 pXFADocView->UpdateDocView(); | 283 pXFADocView->UpdateDocView(); |
| 279 return _SaveXFADocumentData(pDocument, fileList); | 284 return _SaveXFADocumentData(pDocument, fileList); |
| 280 } | 285 } |
| 281 | 286 |
| 287 #endif | |
| 282 FPDF_BOOL _FPDF_Doc_Save(FPDF_DOCUMENT document, | 288 FPDF_BOOL _FPDF_Doc_Save(FPDF_DOCUMENT document, |
| 283 FPDF_FILEWRITE* pFileWrite, | 289 FPDF_FILEWRITE* pFileWrite, |
| 284 FPDF_DWORD flags, | 290 FPDF_DWORD flags, |
| 285 FPDF_BOOL bSetVersion, | 291 FPDF_BOOL bSetVersion, |
| 286 int fileVerion) { | 292 int fileVerion) { |
| 293 #ifndef PDF_ENABLE_XFA | |
| 294 CPDF_Document* pDoc = CPDFDocumentFromFPDFDocument(document); | |
| 295 if (!pDoc) | |
| 296 #else | |
| 287 CPDFXFA_Document* pDoc = (CPDFXFA_Document*)document; | 297 CPDFXFA_Document* pDoc = (CPDFXFA_Document*)document; |
|
Lei Zhang
2015/11/25 00:12:02
Maybe more UnderlyingDocumentType here?
| |
| 288 | 298 |
| 289 CFX_PtrArray fileList; | 299 CFX_PtrArray fileList; |
| 290 | 300 |
| 291 _SendPreSaveToXFADoc(pDoc, fileList); | 301 _SendPreSaveToXFADoc(pDoc, fileList); |
| 292 | 302 |
| 293 CPDF_Document* pPDFDoc = pDoc->GetPDFDoc(); | 303 CPDF_Document* pPDFDoc = pDoc->GetPDFDoc(); |
| 294 if (!pPDFDoc) | 304 if (!pPDFDoc) |
| 305 #endif | |
| 295 return 0; | 306 return 0; |
| 296 | 307 |
| 297 if (flags < FPDF_INCREMENTAL || flags > FPDF_REMOVE_SECURITY) { | 308 if (flags < FPDF_INCREMENTAL || flags > FPDF_REMOVE_SECURITY) { |
| 298 flags = 0; | 309 flags = 0; |
| 299 } | 310 } |
| 300 | 311 |
| 312 #ifndef PDF_ENABLE_XFA | |
| 313 CPDF_Creator FileMaker(pDoc); | |
| 314 #else | |
| 301 CPDF_Creator FileMaker(pPDFDoc); | 315 CPDF_Creator FileMaker(pPDFDoc); |
| 316 #endif | |
| 302 if (bSetVersion) | 317 if (bSetVersion) |
| 303 FileMaker.SetFileVersion(fileVerion); | 318 FileMaker.SetFileVersion(fileVerion); |
| 304 if (flags == FPDF_REMOVE_SECURITY) { | 319 if (flags == FPDF_REMOVE_SECURITY) { |
| 305 flags = 0; | 320 flags = 0; |
| 306 FileMaker.RemoveSecurity(); | 321 FileMaker.RemoveSecurity(); |
| 307 } | 322 } |
| 308 CFX_IFileWrite* pStreamWrite = NULL; | 323 CFX_IFileWrite* pStreamWrite = NULL; |
| 309 FX_BOOL bRet; | 324 FX_BOOL bRet; |
| 310 pStreamWrite = new CFX_IFileWrite; | 325 pStreamWrite = new CFX_IFileWrite; |
| 311 pStreamWrite->Init(pFileWrite); | 326 pStreamWrite->Init(pFileWrite); |
| 312 bRet = FileMaker.Create(pStreamWrite, flags); | 327 bRet = FileMaker.Create(pStreamWrite, flags); |
| 328 #ifdef PDF_ENABLE_XFA | |
| 313 | 329 |
| 314 _SendPostSaveToXFADoc(pDoc); | 330 _SendPostSaveToXFADoc(pDoc); |
| 315 | 331 |
| 316 for (int i = 0; i < fileList.GetSize(); i++) { | 332 for (int i = 0; i < fileList.GetSize(); i++) { |
| 317 IFX_FileStream* pFile = (IFX_FileStream*)fileList.GetAt(i); | 333 IFX_FileStream* pFile = (IFX_FileStream*)fileList.GetAt(i); |
| 318 pFile->Release(); | 334 pFile->Release(); |
| 319 } | 335 } |
| 320 fileList.RemoveAll(); | 336 fileList.RemoveAll(); |
| 321 | 337 |
| 338 #endif | |
| 322 pStreamWrite->Release(); | 339 pStreamWrite->Release(); |
| 323 return bRet; | 340 return bRet; |
| 324 } | 341 } |
| 325 | 342 |
| 326 DLLEXPORT FPDF_BOOL STDCALL FPDF_SaveAsCopy(FPDF_DOCUMENT document, | 343 DLLEXPORT FPDF_BOOL STDCALL FPDF_SaveAsCopy(FPDF_DOCUMENT document, |
| 327 FPDF_FILEWRITE* pFileWrite, | 344 FPDF_FILEWRITE* pFileWrite, |
| 328 FPDF_DWORD flags) { | 345 FPDF_DWORD flags) { |
| 329 return _FPDF_Doc_Save(document, pFileWrite, flags, FALSE, 0); | 346 return _FPDF_Doc_Save(document, pFileWrite, flags, FALSE, 0); |
| 330 } | 347 } |
| 331 | 348 |
| 332 DLLEXPORT FPDF_BOOL STDCALL FPDF_SaveWithVersion(FPDF_DOCUMENT document, | 349 DLLEXPORT FPDF_BOOL STDCALL FPDF_SaveWithVersion(FPDF_DOCUMENT document, |
| 333 FPDF_FILEWRITE* pFileWrite, | 350 FPDF_FILEWRITE* pFileWrite, |
| 334 FPDF_DWORD flags, | 351 FPDF_DWORD flags, |
| 335 int fileVersion) { | 352 int fileVersion) { |
| 336 return _FPDF_Doc_Save(document, pFileWrite, flags, TRUE, fileVersion); | 353 return _FPDF_Doc_Save(document, pFileWrite, flags, TRUE, fileVersion); |
| 337 } | 354 } |
| OLD | NEW |