| 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 "xfa/fxfa/xfa_ffdoc.h" | 7 #include "xfa/fxfa/xfa_ffdoc.h" |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <memory> | 10 #include <memory> |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 } | 145 } |
| 146 } | 146 } |
| 147 return pDstEnd - pDst; | 147 return pDstEnd - pDst; |
| 148 } | 148 } |
| 149 | 149 |
| 150 } // namespace | 150 } // namespace |
| 151 | 151 |
| 152 CXFA_FFDoc::CXFA_FFDoc(CXFA_FFApp* pApp, IXFA_DocEnvironment* pDocEnvironment) | 152 CXFA_FFDoc::CXFA_FFDoc(CXFA_FFApp* pApp, IXFA_DocEnvironment* pDocEnvironment) |
| 153 : m_pDocEnvironment(pDocEnvironment), | 153 : m_pDocEnvironment(pDocEnvironment), |
| 154 m_pDocumentParser(nullptr), | 154 m_pDocumentParser(nullptr), |
| 155 m_pStream(nullptr), | |
| 156 m_pApp(pApp), | 155 m_pApp(pApp), |
| 157 m_pNotify(nullptr), | 156 m_pNotify(nullptr), |
| 158 m_pPDFDoc(nullptr), | 157 m_pPDFDoc(nullptr), |
| 159 m_dwDocType(XFA_DOCTYPE_Static), | 158 m_dwDocType(XFA_DOCTYPE_Static) {} |
| 160 m_bOwnStream(true) {} | |
| 161 | 159 |
| 162 CXFA_FFDoc::~CXFA_FFDoc() { | 160 CXFA_FFDoc::~CXFA_FFDoc() { |
| 163 CloseDoc(); | 161 CloseDoc(); |
| 164 } | 162 } |
| 165 | 163 |
| 166 uint32_t CXFA_FFDoc::GetDocType() { | 164 uint32_t CXFA_FFDoc::GetDocType() { |
| 167 return m_dwDocType; | 165 return m_dwDocType; |
| 168 } | 166 } |
| 169 | 167 |
| 170 int32_t CXFA_FFDoc::StartLoad() { | 168 int32_t CXFA_FFDoc::StartLoad() { |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 285 return pair.second.get(); | 283 return pair.second.get(); |
| 286 } | 284 } |
| 287 return nullptr; | 285 return nullptr; |
| 288 } | 286 } |
| 289 | 287 |
| 290 CXFA_FFDocView* CXFA_FFDoc::GetDocView() { | 288 CXFA_FFDocView* CXFA_FFDoc::GetDocView() { |
| 291 auto it = m_TypeToDocViewMap.begin(); | 289 auto it = m_TypeToDocViewMap.begin(); |
| 292 return it != m_TypeToDocViewMap.end() ? it->second.get() : nullptr; | 290 return it != m_TypeToDocViewMap.end() ? it->second.get() : nullptr; |
| 293 } | 291 } |
| 294 | 292 |
| 295 bool CXFA_FFDoc::OpenDoc(IFX_SeekableReadStream* pStream, bool bTakeOverFile) { | 293 bool CXFA_FFDoc::OpenDoc(const CFX_RetainPtr<IFX_SeekableReadStream>& pStream) { |
| 296 m_bOwnStream = bTakeOverFile; | |
| 297 m_pStream = pStream; | 294 m_pStream = pStream; |
| 298 return true; | 295 return true; |
| 299 } | 296 } |
| 300 bool CXFA_FFDoc::OpenDoc(CPDF_Document* pPDFDoc) { | 297 bool CXFA_FFDoc::OpenDoc(CPDF_Document* pPDFDoc) { |
| 301 if (!pPDFDoc) | 298 if (!pPDFDoc) |
| 302 return false; | 299 return false; |
| 303 | 300 |
| 304 CPDF_Dictionary* pRoot = pPDFDoc->GetRoot(); | 301 CPDF_Dictionary* pRoot = pPDFDoc->GetRoot(); |
| 305 if (!pRoot) | 302 if (!pRoot) |
| 306 return false; | 303 return false; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 319 for (size_t i = 0; i < pXFAArray->GetCount() / 2; i++) { | 316 for (size_t i = 0; i < pXFAArray->GetCount() / 2; i++) { |
| 320 if (CPDF_Stream* pStream = pXFAArray->GetStreamAt(i * 2 + 1)) | 317 if (CPDF_Stream* pStream = pXFAArray->GetStreamAt(i * 2 + 1)) |
| 321 xfaStreams.push_back(pStream); | 318 xfaStreams.push_back(pStream); |
| 322 } | 319 } |
| 323 } else if (pElementXFA->IsStream()) { | 320 } else if (pElementXFA->IsStream()) { |
| 324 xfaStreams.push_back((CPDF_Stream*)pElementXFA); | 321 xfaStreams.push_back((CPDF_Stream*)pElementXFA); |
| 325 } | 322 } |
| 326 if (xfaStreams.empty()) | 323 if (xfaStreams.empty()) |
| 327 return false; | 324 return false; |
| 328 | 325 |
| 329 IFX_SeekableReadStream* pFileRead = MakeSeekableReadStream(xfaStreams); | |
| 330 m_pPDFDoc = pPDFDoc; | 326 m_pPDFDoc = pPDFDoc; |
| 331 if (m_pStream) { | 327 m_pStream = MakeSeekableReadStream(xfaStreams); |
| 332 m_pStream->Release(); | |
| 333 m_pStream = nullptr; | |
| 334 } | |
| 335 m_pStream = pFileRead; | |
| 336 m_bOwnStream = true; | |
| 337 return true; | 328 return true; |
| 338 } | 329 } |
| 339 | 330 |
| 340 bool CXFA_FFDoc::CloseDoc() { | 331 bool CXFA_FFDoc::CloseDoc() { |
| 341 for (const auto& pair : m_TypeToDocViewMap) | 332 for (const auto& pair : m_TypeToDocViewMap) |
| 342 pair.second->RunDocClose(); | 333 pair.second->RunDocClose(); |
| 343 | 334 |
| 344 CXFA_Document* doc = | 335 CXFA_Document* doc = |
| 345 m_pDocumentParser ? m_pDocumentParser->GetDocument() : nullptr; | 336 m_pDocumentParser ? m_pDocumentParser->GetDocument() : nullptr; |
| 346 if (doc) | 337 if (doc) |
| 347 doc->ClearLayoutData(); | 338 doc->ClearLayoutData(); |
| 348 | 339 |
| 349 m_TypeToDocViewMap.clear(); | 340 m_TypeToDocViewMap.clear(); |
| 350 | 341 |
| 351 m_pNotify.reset(nullptr); | 342 m_pNotify.reset(nullptr); |
| 352 m_pApp->GetXFAFontMgr()->ReleaseDocFonts(this); | 343 m_pApp->GetXFAFontMgr()->ReleaseDocFonts(this); |
| 353 | 344 |
| 354 if (m_dwDocType != XFA_DOCTYPE_XDP && m_pStream && m_bOwnStream) { | |
| 355 m_pStream->Release(); | |
| 356 m_pStream = nullptr; | |
| 357 } | |
| 358 | |
| 359 for (const auto& pair : m_HashToDibDpiMap) | 345 for (const auto& pair : m_HashToDibDpiMap) |
| 360 delete pair.second.pDibSource; | 346 delete pair.second.pDibSource; |
| 361 | 347 |
| 362 m_HashToDibDpiMap.clear(); | 348 m_HashToDibDpiMap.clear(); |
| 363 m_pApp->ClearEventTargets(); | 349 m_pApp->ClearEventTargets(); |
| 364 return true; | 350 return true; |
| 365 } | 351 } |
| 366 void CXFA_FFDoc::SetDocType(uint32_t dwType) { | 352 void CXFA_FFDoc::SetDocType(uint32_t dwType) { |
| 367 m_dwDocType = dwType; | 353 m_dwDocType = dwType; |
| 368 } | 354 } |
| (...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 410 } | 396 } |
| 411 } | 397 } |
| 412 | 398 |
| 413 CPDF_Stream* pStream = ToStream(pObject); | 399 CPDF_Stream* pStream = ToStream(pObject); |
| 414 if (!pStream) | 400 if (!pStream) |
| 415 return nullptr; | 401 return nullptr; |
| 416 | 402 |
| 417 CPDF_StreamAcc streamAcc; | 403 CPDF_StreamAcc streamAcc; |
| 418 streamAcc.LoadAllData(pStream); | 404 streamAcc.LoadAllData(pStream); |
| 419 | 405 |
| 420 IFX_SeekableReadStream* pImageFileRead = IFX_MemoryStream::Create( | 406 CFX_RetainPtr<IFX_SeekableReadStream> pImageFileRead = |
| 421 (uint8_t*)streamAcc.GetData(), streamAcc.GetSize()); | 407 IFX_MemoryStream::Create((uint8_t*)streamAcc.GetData(), |
| 408 streamAcc.GetSize()); |
| 422 | 409 |
| 423 CFX_DIBitmap* pDibSource = XFA_LoadImageFromBuffer( | 410 CFX_DIBitmap* pDibSource = XFA_LoadImageFromBuffer( |
| 424 pImageFileRead, FXCODEC_IMAGE_UNKNOWN, iImageXDpi, iImageYDpi); | 411 pImageFileRead, FXCODEC_IMAGE_UNKNOWN, iImageXDpi, iImageYDpi); |
| 425 m_HashToDibDpiMap[dwHash] = {pDibSource, iImageXDpi, iImageYDpi}; | 412 m_HashToDibDpiMap[dwHash] = {pDibSource, iImageXDpi, iImageYDpi}; |
| 426 pImageFileRead->Release(); | |
| 427 return pDibSource; | 413 return pDibSource; |
| 428 } | 414 } |
| 429 | 415 |
| 430 bool CXFA_FFDoc::SavePackage(XFA_HashCode code, | 416 bool CXFA_FFDoc::SavePackage( |
| 431 IFX_SeekableWriteStream* pFile, | 417 XFA_HashCode code, |
| 432 CXFA_ChecksumContext* pCSContext) { | 418 const CFX_RetainPtr<IFX_SeekableWriteStream>& pFile, |
| 419 CXFA_ChecksumContext* pCSContext) { |
| 433 CXFA_Document* doc = m_pDocumentParser->GetDocument(); | 420 CXFA_Document* doc = m_pDocumentParser->GetDocument(); |
| 434 | |
| 435 std::unique_ptr<CXFA_DataExporter> pExport(new CXFA_DataExporter(doc)); | 421 std::unique_ptr<CXFA_DataExporter> pExport(new CXFA_DataExporter(doc)); |
| 436 CXFA_Node* pNode = code == XFA_HASHCODE_Xfa ? doc->GetRoot() | 422 CXFA_Node* pNode = code == XFA_HASHCODE_Xfa ? doc->GetRoot() |
| 437 : ToNode(doc->GetXFAObject(code)); | 423 : ToNode(doc->GetXFAObject(code)); |
| 438 if (!pNode) | 424 if (!pNode) |
| 439 return !!pExport->Export(pFile); | 425 return !!pExport->Export(pFile); |
| 440 | 426 |
| 441 CFX_ByteString bsChecksum; | 427 CFX_ByteString bsChecksum; |
| 442 if (pCSContext) | 428 if (pCSContext) |
| 443 bsChecksum = pCSContext->GetChecksum(); | 429 bsChecksum = pCSContext->GetChecksum(); |
| 444 | 430 |
| 445 return !!pExport->Export( | 431 return !!pExport->Export( |
| 446 pFile, pNode, 0, bsChecksum.GetLength() ? bsChecksum.c_str() : nullptr); | 432 pFile, pNode, 0, bsChecksum.GetLength() ? bsChecksum.c_str() : nullptr); |
| 447 } | 433 } |
| 448 | 434 |
| 449 bool CXFA_FFDoc::ImportData(IFX_SeekableReadStream* pStream, bool bXDP) { | 435 bool CXFA_FFDoc::ImportData( |
| 450 std::unique_ptr<CXFA_DataImporter> importer( | 436 const CFX_RetainPtr<IFX_SeekableReadStream>& pStream, |
| 451 new CXFA_DataImporter(m_pDocumentParser->GetDocument())); | 437 bool bXDP) { |
| 438 auto importer = |
| 439 pdfium::MakeUnique<CXFA_DataImporter>(m_pDocumentParser->GetDocument()); |
| 452 return importer->ImportData(pStream); | 440 return importer->ImportData(pStream); |
| 453 } | 441 } |
| OLD | NEW |