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 #include "core/include/fpdfapi/fpdf_parser.h" | |
| 9 #include "core/include/fpdfapi/fpdf_serial.h" | 10 #include "core/include/fpdfapi/fpdf_serial.h" |
| 10 #include "fpdfsdk/include/fsdk_define.h" | 11 #include "fpdfsdk/include/fsdk_define.h" |
| 11 #include "public/fpdf_edit.h" | 12 #include "public/fpdf_edit.h" |
| 12 | 13 |
| 13 #ifdef PDF_ENABLE_XFA | 14 #ifdef PDF_ENABLE_XFA |
| 14 #include "fpdfsdk/include/fpdfxfa/fpdfxfa_app.h" | 15 #include "fpdfsdk/include/fpdfxfa/fpdfxfa_app.h" |
| 15 #include "fpdfsdk/include/fpdfxfa/fpdfxfa_doc.h" | 16 #include "fpdfsdk/include/fpdfxfa/fpdfxfa_doc.h" |
| 16 #include "fpdfsdk/include/fpdfxfa/fpdfxfa_util.h" | 17 #include "fpdfsdk/include/fpdfxfa/fpdfxfa_util.h" |
| 17 #include "public/fpdf_formfill.h" | 18 #include "public/fpdf_formfill.h" |
| 18 #endif | 19 #endif |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 53 return FALSE; | 54 return FALSE; |
| 54 | 55 |
| 55 m_pFileWriteStruct->WriteBlock(m_pFileWriteStruct, pData, size); | 56 m_pFileWriteStruct->WriteBlock(m_pFileWriteStruct, pData, size); |
| 56 return TRUE; | 57 return TRUE; |
| 57 } | 58 } |
| 58 | 59 |
| 59 void CFX_IFileWrite::Release() { | 60 void CFX_IFileWrite::Release() { |
| 60 delete this; | 61 delete this; |
| 61 } | 62 } |
| 62 | 63 |
| 64 namespace { | |
| 65 | |
| 63 #ifdef PDF_ENABLE_XFA | 66 #ifdef PDF_ENABLE_XFA |
| 64 FX_BOOL _SaveXFADocumentData(CPDFXFA_Document* pDocument, | 67 bool SaveXFADocumentData(CPDFXFA_Document* pDocument, |
| 65 CFX_PtrArray& fileList) { | 68 std::vector<ScopedFileStream>* fileList) { |
| 66 if (!pDocument) | 69 if (!pDocument) |
| 67 return FALSE; | 70 return false; |
| 71 | |
| 68 if (pDocument->GetDocType() != DOCTYPE_DYNAMIC_XFA && | 72 if (pDocument->GetDocType() != DOCTYPE_DYNAMIC_XFA && |
| 69 pDocument->GetDocType() != DOCTYPE_STATIC_XFA) | 73 pDocument->GetDocType() != DOCTYPE_STATIC_XFA) |
| 70 return TRUE; | 74 return true; |
| 75 | |
| 71 if (!CPDFXFA_App::GetInstance()->GetXFAApp()) | 76 if (!CPDFXFA_App::GetInstance()->GetXFAApp()) |
| 72 return TRUE; | 77 return true; |
| 73 | 78 |
| 74 IXFA_DocView* pXFADocView = pDocument->GetXFADocView(); | 79 IXFA_DocView* pXFADocView = pDocument->GetXFADocView(); |
| 75 if (NULL == pXFADocView) | 80 if (!pXFADocView) |
| 76 return TRUE; | 81 return true; |
| 77 | 82 |
| 78 IXFA_DocHandler* pXFADocHandler = | 83 IXFA_DocHandler* pXFADocHandler = |
| 79 CPDFXFA_App::GetInstance()->GetXFAApp()->GetDocHandler(); | 84 CPDFXFA_App::GetInstance()->GetXFAApp()->GetDocHandler(); |
| 80 CPDF_Document* pPDFDocument = pDocument->GetPDFDoc(); | 85 CPDF_Document* pPDFDocument = pDocument->GetPDFDoc(); |
| 81 if (pDocument == NULL) | 86 if (!pDocument) |
| 82 return FALSE; | 87 return false; |
| 83 | 88 |
| 84 CPDF_Dictionary* pRoot = pPDFDocument->GetRoot(); | 89 CPDF_Dictionary* pRoot = pPDFDocument->GetRoot(); |
| 85 if (pRoot == NULL) | 90 if (!pRoot) |
| 86 return FALSE; | 91 return false; |
| 92 | |
| 87 CPDF_Dictionary* pAcroForm = pRoot->GetDictBy("AcroForm"); | 93 CPDF_Dictionary* pAcroForm = pRoot->GetDictBy("AcroForm"); |
| 88 if (NULL == pAcroForm) | 94 if (!pAcroForm) |
| 89 return FALSE; | 95 return false; |
| 96 | |
| 90 CPDF_Object* pXFA = pAcroForm->GetElement("XFA"); | 97 CPDF_Object* pXFA = pAcroForm->GetElement("XFA"); |
| 91 if (pXFA == NULL) | 98 if (!pXFA) |
| 92 return TRUE; | 99 return true; |
| 100 | |
| 93 if (!pXFA->IsArray()) | 101 if (!pXFA->IsArray()) |
| 94 return FALSE; | 102 return false; |
| 103 | |
| 95 CPDF_Array* pArray = pXFA->GetArray(); | 104 CPDF_Array* pArray = pXFA->GetArray(); |
| 96 if (NULL == pArray) | 105 if (!pArray) |
| 97 return FALSE; | 106 return false; |
| 107 | |
| 98 int size = pArray->GetCount(); | 108 int size = pArray->GetCount(); |
| 99 int iFormIndex = -1; | 109 int iFormIndex = -1; |
| 100 int iDataSetsIndex = -1; | 110 int iDataSetsIndex = -1; |
| 101 int iTemplate = -1; | 111 int iTemplate = -1; |
| 102 int iLast = size - 2; | 112 int iLast = size - 2; |
| 103 for (int i = 0; i < size - 1; i++) { | 113 for (int i = 0; i < size - 1; i++) { |
| 104 CPDF_Object* pPDFObj = pArray->GetElement(i); | 114 CPDF_Object* pPDFObj = pArray->GetElement(i); |
| 105 if (!pPDFObj->IsString()) | 115 if (!pPDFObj->IsString()) |
| 106 continue; | 116 continue; |
| 107 if (pPDFObj->GetString() == "form") | 117 if (pPDFObj->GetString() == "form") |
| 108 iFormIndex = i + 1; | 118 iFormIndex = i + 1; |
| 109 else if (pPDFObj->GetString() == "datasets") | 119 else if (pPDFObj->GetString() == "datasets") |
| 110 iDataSetsIndex = i + 1; | 120 iDataSetsIndex = i + 1; |
| 111 else if (pPDFObj->GetString() == "template") | 121 else if (pPDFObj->GetString() == "template") |
| 112 iTemplate = i + 1; | 122 iTemplate = i + 1; |
| 113 } | 123 } |
| 114 IXFA_ChecksumContext* pContext = NULL; | 124 std::unique_ptr<IXFA_ChecksumContext, ReleaseDeleter<IXFA_ChecksumContext>> |
| 115 // Checksum | 125 pContext(XFA_Checksum_Create()); |
| 116 pContext = XFA_Checksum_Create(); | |
| 117 FXSYS_assert(pContext); | |
| 118 pContext->StartChecksum(); | 126 pContext->StartChecksum(); |
| 119 | 127 |
| 120 // template | 128 // template |
| 121 if (iTemplate > -1) { | 129 if (iTemplate > -1) { |
| 122 CPDF_Stream* pTemplateStream = pArray->GetStreamAt(iTemplate); | 130 CPDF_Stream* pTemplateStream = pArray->GetStreamAt(iTemplate); |
| 123 CPDF_StreamAcc streamAcc; | 131 CPDF_StreamAcc streamAcc; |
| 124 streamAcc.LoadAllData(pTemplateStream); | 132 streamAcc.LoadAllData(pTemplateStream); |
| 125 uint8_t* pData = (uint8_t*)streamAcc.GetData(); | 133 uint8_t* pData = (uint8_t*)streamAcc.GetData(); |
| 126 FX_DWORD dwSize2 = streamAcc.GetSize(); | 134 FX_DWORD dwSize2 = streamAcc.GetSize(); |
| 127 IFX_FileStream* pTemplate = FX_CreateMemoryStream(pData, dwSize2); | 135 ScopedFileStream pTemplate(FX_CreateMemoryStream(pData, dwSize2)); |
| 128 pContext->UpdateChecksum((IFX_FileRead*)pTemplate); | 136 pContext->UpdateChecksum(pTemplate.get()); |
| 129 pTemplate->Release(); | |
| 130 } | 137 } |
| 131 CPDF_Stream* pFormStream = NULL; | 138 CPDF_Stream* pFormStream = NULL; |
| 132 CPDF_Stream* pDataSetsStream = NULL; | 139 CPDF_Stream* pDataSetsStream = NULL; |
| 133 if (iFormIndex != -1) { | 140 if (iFormIndex != -1) { |
| 134 // Get form CPDF_Stream | 141 // Get form CPDF_Stream |
| 135 CPDF_Object* pFormPDFObj = pArray->GetElement(iFormIndex); | 142 CPDF_Object* pFormPDFObj = pArray->GetElement(iFormIndex); |
| 136 if (pFormPDFObj->IsReference()) { | 143 if (pFormPDFObj->IsReference()) { |
| 137 CPDF_Object* pFormDirectObj = pFormPDFObj->GetDirect(); | 144 CPDF_Object* pFormDirectObj = pFormPDFObj->GetDirect(); |
| 138 if (pFormDirectObj && pFormDirectObj->IsStream()) { | 145 if (pFormDirectObj && pFormDirectObj->IsStream()) { |
| 139 pFormStream = (CPDF_Stream*)pFormDirectObj; | 146 pFormStream = (CPDF_Stream*)pFormDirectObj; |
| 140 } | 147 } |
| 141 } else if (pFormPDFObj->IsStream()) { | 148 } else if (pFormPDFObj->IsStream()) { |
| 142 pFormStream = (CPDF_Stream*)pFormPDFObj; | 149 pFormStream = (CPDF_Stream*)pFormPDFObj; |
| 143 } | 150 } |
| 144 } | 151 } |
| 145 | 152 |
| 146 if (iDataSetsIndex != -1) { | 153 if (iDataSetsIndex != -1) { |
| 147 // Get datasets CPDF_Stream | 154 // Get datasets CPDF_Stream |
| 148 CPDF_Object* pDataSetsPDFObj = pArray->GetElement(iDataSetsIndex); | 155 CPDF_Object* pDataSetsPDFObj = pArray->GetElement(iDataSetsIndex); |
| 149 if (pDataSetsPDFObj->IsReference()) { | 156 if (pDataSetsPDFObj->IsReference()) { |
| 150 CPDF_Reference* pDataSetsRefObj = (CPDF_Reference*)pDataSetsPDFObj; | 157 CPDF_Reference* pDataSetsRefObj = (CPDF_Reference*)pDataSetsPDFObj; |
| 151 CPDF_Object* pDataSetsDirectObj = pDataSetsRefObj->GetDirect(); | 158 CPDF_Object* pDataSetsDirectObj = pDataSetsRefObj->GetDirect(); |
| 152 if (pDataSetsDirectObj && pDataSetsDirectObj->IsStream()) { | 159 if (pDataSetsDirectObj && pDataSetsDirectObj->IsStream()) { |
| 153 pDataSetsStream = (CPDF_Stream*)pDataSetsDirectObj; | 160 pDataSetsStream = (CPDF_Stream*)pDataSetsDirectObj; |
| 154 } | 161 } |
| 155 } else if (pDataSetsPDFObj->IsStream()) { | 162 } else if (pDataSetsPDFObj->IsStream()) { |
| 156 pDataSetsStream = (CPDF_Stream*)pDataSetsPDFObj; | 163 pDataSetsStream = (CPDF_Stream*)pDataSetsPDFObj; |
| 157 } | 164 } |
| 158 } | 165 } |
| 159 // end | |
| 160 // L"datasets" | 166 // L"datasets" |
| 161 { | 167 { |
| 162 IFX_FileStream* pDsfileWrite = FX_CreateMemoryStream(); | 168 ScopedFileStream pDsfileWrite(FX_CreateMemoryStream()); |
| 163 if (NULL == pDsfileWrite) { | |
| 164 pContext->Release(); | |
| 165 pDsfileWrite->Release(); | |
| 166 return FALSE; | |
| 167 } | |
| 168 if (pXFADocHandler->SavePackage(pXFADocView->GetDoc(), | 169 if (pXFADocHandler->SavePackage(pXFADocView->GetDoc(), |
| 169 CFX_WideStringC(L"datasets"), | 170 CFX_WideStringC(L"datasets"), |
| 170 pDsfileWrite) && | 171 pDsfileWrite.get()) && |
| 171 pDsfileWrite->GetSize() > 0) { | 172 pDsfileWrite->GetSize() > 0) { |
| 172 // Datasets | 173 // Datasets |
| 173 pContext->UpdateChecksum((IFX_FileRead*)pDsfileWrite); | 174 pContext->UpdateChecksum(pDsfileWrite.get()); |
| 174 pContext->FinishChecksum(); | 175 pContext->FinishChecksum(); |
| 175 CPDF_Dictionary* pDataDict = new CPDF_Dictionary; | 176 CPDF_Dictionary* pDataDict = new CPDF_Dictionary; |
| 176 if (iDataSetsIndex != -1) { | 177 if (iDataSetsIndex != -1) { |
| 177 if (pDataSetsStream) | 178 if (pDataSetsStream) |
| 178 pDataSetsStream->InitStreamFromFile(pDsfileWrite, pDataDict); | 179 pDataSetsStream->InitStreamFromFile(pDsfileWrite.get(), pDataDict); |
| 179 } else { | 180 } else { |
| 180 CPDF_Stream* pData = new CPDF_Stream(NULL, 0, NULL); | 181 CPDF_Stream* pData = new CPDF_Stream(NULL, 0, NULL); |
| 181 pData->InitStreamFromFile(pDsfileWrite, pDataDict); | 182 pData->InitStreamFromFile(pDsfileWrite.get(), pDataDict); |
| 182 pPDFDocument->AddIndirectObject(pData); | 183 pPDFDocument->AddIndirectObject(pData); |
| 183 iLast = pArray->GetCount() - 2; | 184 iLast = pArray->GetCount() - 2; |
| 184 pArray->InsertAt(iLast, new CPDF_String("datasets", FALSE)); | 185 pArray->InsertAt(iLast, new CPDF_String("datasets", FALSE)); |
| 185 pArray->InsertAt(iLast + 1, pData, pPDFDocument); | 186 pArray->InsertAt(iLast + 1, pData, pPDFDocument); |
| 186 } | 187 } |
| 187 fileList.Add(pDsfileWrite); | 188 fileList->push_back(std::move(pDsfileWrite)); |
| 188 } | 189 } |
| 189 } | 190 } |
| 190 | |
| 191 // L"form" | 191 // L"form" |
| 192 { | 192 { |
| 193 IFX_FileStream* pfileWrite = FX_CreateMemoryStream(); | 193 ScopedFileStream pfileWrite(FX_CreateMemoryStream()); |
| 194 if (NULL == pfileWrite) { | |
| 195 pContext->Release(); | |
| 196 return FALSE; | |
| 197 } | |
| 198 if (pXFADocHandler->SavePackage(pXFADocView->GetDoc(), | 194 if (pXFADocHandler->SavePackage(pXFADocView->GetDoc(), |
| 199 CFX_WideStringC(L"form"), pfileWrite, | 195 CFX_WideStringC(L"form"), pfileWrite.get(), |
| 200 pContext) && | 196 pContext.get()) && |
| 201 pfileWrite > 0) { | 197 pfileWrite->GetSize() > 0) { |
|
Tom Sepez
2016/02/05 22:49:45
This had to be wrong. Comparing a pointer greater
| |
| 202 CPDF_Dictionary* pDataDict = new CPDF_Dictionary; | 198 CPDF_Dictionary* pDataDict = new CPDF_Dictionary; |
| 203 if (iFormIndex != -1) { | 199 if (iFormIndex != -1) { |
| 204 if (pFormStream) | 200 if (pFormStream) |
| 205 pFormStream->InitStreamFromFile(pfileWrite, pDataDict); | 201 pFormStream->InitStreamFromFile(pfileWrite.get(), pDataDict); |
| 206 } else { | 202 } else { |
| 207 CPDF_Stream* pData = new CPDF_Stream(NULL, 0, NULL); | 203 CPDF_Stream* pData = new CPDF_Stream(NULL, 0, NULL); |
| 208 pData->InitStreamFromFile(pfileWrite, pDataDict); | 204 pData->InitStreamFromFile(pfileWrite.get(), pDataDict); |
| 209 pPDFDocument->AddIndirectObject(pData); | 205 pPDFDocument->AddIndirectObject(pData); |
| 210 iLast = pArray->GetCount() - 2; | 206 iLast = pArray->GetCount() - 2; |
| 211 pArray->InsertAt(iLast, new CPDF_String("form", FALSE)); | 207 pArray->InsertAt(iLast, new CPDF_String("form", FALSE)); |
| 212 pArray->InsertAt(iLast + 1, pData, pPDFDocument); | 208 pArray->InsertAt(iLast + 1, pData, pPDFDocument); |
| 213 } | 209 } |
| 214 fileList.Add(pfileWrite); | 210 fileList->push_back(std::move(pfileWrite)); |
| 215 } | 211 } |
| 216 } | 212 } |
| 217 pContext->Release(); | 213 return true; |
| 218 return TRUE; | |
| 219 } | 214 } |
| 220 | 215 |
| 221 FX_BOOL _SendPostSaveToXFADoc(CPDFXFA_Document* pDocument) { | 216 bool SendPostSaveToXFADoc(CPDFXFA_Document* pDocument) { |
| 222 if (!pDocument) | 217 if (!pDocument) |
| 223 return FALSE; | 218 return false; |
| 224 | 219 |
| 225 if (pDocument->GetDocType() != DOCTYPE_DYNAMIC_XFA && | 220 if (pDocument->GetDocType() != DOCTYPE_DYNAMIC_XFA && |
| 226 pDocument->GetDocType() != DOCTYPE_STATIC_XFA) | 221 pDocument->GetDocType() != DOCTYPE_STATIC_XFA) |
| 227 return TRUE; | 222 return true; |
| 228 | 223 |
| 229 IXFA_DocView* pXFADocView = pDocument->GetXFADocView(); | 224 IXFA_DocView* pXFADocView = pDocument->GetXFADocView(); |
| 230 if (NULL == pXFADocView) | 225 if (!pXFADocView) |
| 231 return FALSE; | 226 return false; |
| 227 | |
| 232 IXFA_WidgetHandler* pWidgetHander = pXFADocView->GetWidgetHandler(); | 228 IXFA_WidgetHandler* pWidgetHander = pXFADocView->GetWidgetHandler(); |
| 233 | |
| 234 CXFA_WidgetAcc* pWidgetAcc = NULL; | 229 CXFA_WidgetAcc* pWidgetAcc = NULL; |
| 235 IXFA_WidgetAccIterator* pWidgetAccIterator = | 230 IXFA_WidgetAccIterator* pWidgetAccIterator = |
| 236 pXFADocView->CreateWidgetAccIterator(); | 231 pXFADocView->CreateWidgetAccIterator(); |
| 237 pWidgetAcc = pWidgetAccIterator->MoveToNext(); | 232 pWidgetAcc = pWidgetAccIterator->MoveToNext(); |
| 238 while (pWidgetAcc) { | 233 while (pWidgetAcc) { |
| 239 CXFA_EventParam preParam; | 234 CXFA_EventParam preParam; |
| 240 preParam.m_eType = XFA_EVENT_PostSave; | 235 preParam.m_eType = XFA_EVENT_PostSave; |
| 241 pWidgetHander->ProcessEvent(pWidgetAcc, &preParam); | 236 pWidgetHander->ProcessEvent(pWidgetAcc, &preParam); |
| 242 pWidgetAcc = pWidgetAccIterator->MoveToNext(); | 237 pWidgetAcc = pWidgetAccIterator->MoveToNext(); |
| 243 } | 238 } |
| 244 pWidgetAccIterator->Release(); | 239 pWidgetAccIterator->Release(); |
| 245 pXFADocView->UpdateDocView(); | 240 pXFADocView->UpdateDocView(); |
| 246 pDocument->_ClearChangeMark(); | 241 pDocument->_ClearChangeMark(); |
| 247 return TRUE; | 242 return true; |
| 248 } | 243 } |
| 249 | 244 |
| 250 FX_BOOL _SendPreSaveToXFADoc(CPDFXFA_Document* pDocument, | 245 bool SendPreSaveToXFADoc(CPDFXFA_Document* pDocument, |
| 251 CFX_PtrArray& fileList) { | 246 std::vector<ScopedFileStream>* fileList) { |
| 252 if (pDocument->GetDocType() != DOCTYPE_DYNAMIC_XFA && | 247 if (pDocument->GetDocType() != DOCTYPE_DYNAMIC_XFA && |
| 253 pDocument->GetDocType() != DOCTYPE_STATIC_XFA) | 248 pDocument->GetDocType() != DOCTYPE_STATIC_XFA) |
| 254 return TRUE; | 249 return true; |
| 250 | |
| 255 IXFA_DocView* pXFADocView = pDocument->GetXFADocView(); | 251 IXFA_DocView* pXFADocView = pDocument->GetXFADocView(); |
| 256 if (NULL == pXFADocView) | 252 if (!pXFADocView) |
| 257 return TRUE; | 253 return true; |
| 254 | |
| 258 IXFA_WidgetHandler* pWidgetHander = pXFADocView->GetWidgetHandler(); | 255 IXFA_WidgetHandler* pWidgetHander = pXFADocView->GetWidgetHandler(); |
| 259 CXFA_WidgetAcc* pWidgetAcc = NULL; | 256 CXFA_WidgetAcc* pWidgetAcc = NULL; |
| 260 IXFA_WidgetAccIterator* pWidgetAccIterator = | 257 IXFA_WidgetAccIterator* pWidgetAccIterator = |
| 261 pXFADocView->CreateWidgetAccIterator(); | 258 pXFADocView->CreateWidgetAccIterator(); |
| 262 pWidgetAcc = pWidgetAccIterator->MoveToNext(); | 259 pWidgetAcc = pWidgetAccIterator->MoveToNext(); |
| 263 while (pWidgetAcc) { | 260 while (pWidgetAcc) { |
| 264 CXFA_EventParam preParam; | 261 CXFA_EventParam preParam; |
| 265 preParam.m_eType = XFA_EVENT_PreSave; | 262 preParam.m_eType = XFA_EVENT_PreSave; |
| 266 pWidgetHander->ProcessEvent(pWidgetAcc, &preParam); | 263 pWidgetHander->ProcessEvent(pWidgetAcc, &preParam); |
| 267 pWidgetAcc = pWidgetAccIterator->MoveToNext(); | 264 pWidgetAcc = pWidgetAccIterator->MoveToNext(); |
| 268 } | 265 } |
| 269 pWidgetAccIterator->Release(); | 266 pWidgetAccIterator->Release(); |
| 270 pXFADocView->UpdateDocView(); | 267 pXFADocView->UpdateDocView(); |
| 271 return _SaveXFADocumentData(pDocument, fileList); | 268 return SaveXFADocumentData(pDocument, fileList); |
| 272 } | 269 } |
| 273 #endif // PDF_ENABLE_XFA | 270 #endif // PDF_ENABLE_XFA |
| 274 | 271 |
| 275 FPDF_BOOL _FPDF_Doc_Save(FPDF_DOCUMENT document, | 272 bool FPDF_Doc_Save(FPDF_DOCUMENT document, |
| 276 FPDF_FILEWRITE* pFileWrite, | 273 FPDF_FILEWRITE* pFileWrite, |
| 277 FPDF_DWORD flags, | 274 FPDF_DWORD flags, |
| 278 FPDF_BOOL bSetVersion, | 275 FPDF_BOOL bSetVersion, |
| 279 int fileVerion) { | 276 int fileVerion) { |
| 280 CPDF_Document* pPDFDoc = CPDFDocumentFromFPDFDocument(document); | 277 CPDF_Document* pPDFDoc = CPDFDocumentFromFPDFDocument(document); |
| 281 if (!pPDFDoc) | 278 if (!pPDFDoc) |
| 282 return 0; | 279 return 0; |
| 283 | 280 |
| 284 #ifdef PDF_ENABLE_XFA | 281 #ifdef PDF_ENABLE_XFA |
| 285 CPDFXFA_Document* pDoc = (CPDFXFA_Document*)document; | 282 CPDFXFA_Document* pDoc = static_cast<CPDFXFA_Document*>(document); |
| 286 CFX_PtrArray fileList; | 283 std::vector<ScopedFileStream> fileList; |
|
Lei Zhang
2016/02/05 23:32:49
Do we actually need to hold on to the file streams
Tom Sepez
2016/02/08 17:10:20
I didn't think so ... given the loop at old line 3
Lei Zhang
2016/02/08 20:10:29
What I was wonder is, do we need to hold on to the
| |
| 287 _SendPreSaveToXFADoc(pDoc, fileList); | 284 SendPreSaveToXFADoc(pDoc, &fileList); |
| 288 #endif // PDF_ENABLE_XFA | 285 #endif // PDF_ENABLE_XFA |
| 289 | 286 |
| 290 if (flags < FPDF_INCREMENTAL || flags > FPDF_REMOVE_SECURITY) { | 287 if (flags < FPDF_INCREMENTAL || flags > FPDF_REMOVE_SECURITY) |
| 291 flags = 0; | 288 flags = 0; |
| 292 } | |
| 293 | 289 |
| 294 CPDF_Creator FileMaker(pPDFDoc); | 290 CPDF_Creator FileMaker(pPDFDoc); |
| 295 if (bSetVersion) | 291 if (bSetVersion) |
| 296 FileMaker.SetFileVersion(fileVerion); | 292 FileMaker.SetFileVersion(fileVerion); |
| 297 if (flags == FPDF_REMOVE_SECURITY) { | 293 if (flags == FPDF_REMOVE_SECURITY) { |
| 298 flags = 0; | 294 flags = 0; |
| 299 FileMaker.RemoveSecurity(); | 295 FileMaker.RemoveSecurity(); |
| 300 } | 296 } |
| 301 | 297 |
| 302 CFX_IFileWrite* pStreamWrite = NULL; | 298 CFX_IFileWrite* pStreamWrite = NULL; |
| 303 FX_BOOL bRet; | 299 FX_BOOL bRet; |
| 304 pStreamWrite = new CFX_IFileWrite; | 300 pStreamWrite = new CFX_IFileWrite; |
| 305 pStreamWrite->Init(pFileWrite); | 301 pStreamWrite->Init(pFileWrite); |
| 306 bRet = FileMaker.Create(pStreamWrite, flags); | 302 bRet = FileMaker.Create(pStreamWrite, flags); |
| 307 #ifdef PDF_ENABLE_XFA | 303 #ifdef PDF_ENABLE_XFA |
| 308 _SendPostSaveToXFADoc(pDoc); | 304 SendPostSaveToXFADoc(pDoc); |
| 309 for (int i = 0; i < fileList.GetSize(); i++) { | |
| 310 IFX_FileStream* pFile = (IFX_FileStream*)fileList.GetAt(i); | |
| 311 pFile->Release(); | |
| 312 } | |
| 313 fileList.RemoveAll(); | |
| 314 #endif // PDF_ENABLE_XFA | 305 #endif // PDF_ENABLE_XFA |
| 315 pStreamWrite->Release(); | 306 pStreamWrite->Release(); |
| 316 return bRet; | 307 return bRet; |
| 317 } | 308 } |
| 318 | 309 |
| 310 } // namespace | |
| 311 | |
| 319 DLLEXPORT FPDF_BOOL STDCALL FPDF_SaveAsCopy(FPDF_DOCUMENT document, | 312 DLLEXPORT FPDF_BOOL STDCALL FPDF_SaveAsCopy(FPDF_DOCUMENT document, |
| 320 FPDF_FILEWRITE* pFileWrite, | 313 FPDF_FILEWRITE* pFileWrite, |
| 321 FPDF_DWORD flags) { | 314 FPDF_DWORD flags) { |
| 322 return _FPDF_Doc_Save(document, pFileWrite, flags, FALSE, 0); | 315 return FPDF_Doc_Save(document, pFileWrite, flags, FALSE, 0); |
| 323 } | 316 } |
| 324 | 317 |
| 325 DLLEXPORT FPDF_BOOL STDCALL FPDF_SaveWithVersion(FPDF_DOCUMENT document, | 318 DLLEXPORT FPDF_BOOL STDCALL FPDF_SaveWithVersion(FPDF_DOCUMENT document, |
| 326 FPDF_FILEWRITE* pFileWrite, | 319 FPDF_FILEWRITE* pFileWrite, |
| 327 FPDF_DWORD flags, | 320 FPDF_DWORD flags, |
| 328 int fileVersion) { | 321 int fileVersion) { |
| 329 return _FPDF_Doc_Save(document, pFileWrite, flags, TRUE, fileVersion); | 322 return FPDF_Doc_Save(document, pFileWrite, flags, TRUE, fileVersion); |
| 330 } | 323 } |
| OLD | NEW |