| 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 "fpdfsdk/include/fsdk_mgr.h" | 7 #include "fpdfsdk/include/fsdk_mgr.h" |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <memory> | 10 #include <memory> |
| (...skipping 281 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 292 return pPage ? GetPageView(pPage, true) : nullptr; | 292 return pPage ? GetPageView(pPage, true) : nullptr; |
| 293 } | 293 } |
| 294 | 294 |
| 295 CPDFSDK_PageView* CPDFSDK_Document::GetPageView(int nIndex) { | 295 CPDFSDK_PageView* CPDFSDK_Document::GetPageView(int nIndex) { |
| 296 UnderlyingPageType* pTempPage = | 296 UnderlyingPageType* pTempPage = |
| 297 UnderlyingFromFPDFPage(m_pEnv->FFI_GetPage(m_pDoc, nIndex)); | 297 UnderlyingFromFPDFPage(m_pEnv->FFI_GetPage(m_pDoc, nIndex)); |
| 298 if (!pTempPage) | 298 if (!pTempPage) |
| 299 return nullptr; | 299 return nullptr; |
| 300 | 300 |
| 301 auto it = m_pageMap.find(pTempPage); | 301 auto it = m_pageMap.find(pTempPage); |
| 302 return it->second; | 302 return it != m_pageMap.end() ? it->second : nullptr; |
| 303 } | 303 } |
| 304 | 304 |
| 305 void CPDFSDK_Document::ProcJavascriptFun() { | 305 void CPDFSDK_Document::ProcJavascriptFun() { |
| 306 CPDF_Document* pPDFDoc = GetPDFDocument(); | 306 CPDF_Document* pPDFDoc = GetPDFDocument(); |
| 307 CPDF_DocJSActions docJS(pPDFDoc); | 307 CPDF_DocJSActions docJS(pPDFDoc); |
| 308 int iCount = docJS.CountJSActions(); | 308 int iCount = docJS.CountJSActions(); |
| 309 if (iCount < 1) | 309 if (iCount < 1) |
| 310 return; | 310 return; |
| 311 for (int i = 0; i < iCount; i++) { | 311 for (int i = 0; i < iCount; i++) { |
| 312 CFX_ByteString csJSName; | 312 CFX_ByteString csJSName; |
| (...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 475 CFX_WideString CPDFSDK_Document::GetPath() { | 475 CFX_WideString CPDFSDK_Document::GetPath() { |
| 476 return m_pEnv->JS_docGetFilePath(); | 476 return m_pEnv->JS_docGetFilePath(); |
| 477 } | 477 } |
| 478 | 478 |
| 479 CPDFSDK_PageView::CPDFSDK_PageView(CPDFSDK_Document* pSDKDoc, | 479 CPDFSDK_PageView::CPDFSDK_PageView(CPDFSDK_Document* pSDKDoc, |
| 480 UnderlyingPageType* page) | 480 UnderlyingPageType* page) |
| 481 : m_page(page), | 481 : m_page(page), |
| 482 m_pSDKDoc(pSDKDoc), | 482 m_pSDKDoc(pSDKDoc), |
| 483 m_CaptureWidget(nullptr), | 483 m_CaptureWidget(nullptr), |
| 484 #ifndef PDF_ENABLE_XFA | 484 #ifndef PDF_ENABLE_XFA |
| 485 m_bTakeOverPage(FALSE), | 485 m_bOwnsPage(false), |
| 486 #endif // PDF_ENABLE_XFA | 486 #endif // PDF_ENABLE_XFA |
| 487 m_bEnterWidget(FALSE), | 487 m_bEnterWidget(FALSE), |
| 488 m_bExitWidget(FALSE), | 488 m_bExitWidget(FALSE), |
| 489 m_bOnWidget(FALSE), | 489 m_bOnWidget(FALSE), |
| 490 m_bValid(FALSE), | 490 m_bValid(FALSE), |
| 491 m_bLocked(FALSE) { | 491 m_bLocked(FALSE) { |
| 492 CPDFSDK_InterForm* pInterForm = pSDKDoc->GetInterForm(); | 492 CPDFSDK_InterForm* pInterForm = pSDKDoc->GetInterForm(); |
| 493 if (pInterForm) { | 493 if (pInterForm) { |
| 494 CPDF_InterForm* pPDFInterForm = pInterForm->GetInterForm(); | 494 CPDF_InterForm* pPDFInterForm = pInterForm->GetInterForm(); |
| 495 #ifdef PDF_ENABLE_XFA | 495 #ifdef PDF_ENABLE_XFA |
| 496 if (page->GetPDFPage()) | 496 if (page->GetPDFPage()) |
| 497 pPDFInterForm->FixPageFields(page->GetPDFPage()); | 497 pPDFInterForm->FixPageFields(page->GetPDFPage()); |
| 498 #else // PDF_ENABLE_XFA | 498 #else // PDF_ENABLE_XFA |
| 499 pPDFInterForm->FixPageFields(page); | 499 pPDFInterForm->FixPageFields(page); |
| 500 #endif // PDF_ENABLE_XFA | 500 #endif // PDF_ENABLE_XFA |
| 501 } | 501 } |
| 502 #ifndef PDF_ENABLE_XFA | 502 #ifndef PDF_ENABLE_XFA |
| 503 m_page->SetView(this); | 503 m_page->SetView(this); |
| 504 #endif // PDF_ENABLE_XFA | 504 #endif // PDF_ENABLE_XFA |
| 505 } | 505 } |
| 506 | 506 |
| 507 CPDFSDK_PageView::~CPDFSDK_PageView() { | 507 CPDFSDK_PageView::~CPDFSDK_PageView() { |
| 508 #ifndef PDF_ENABLE_XFA |
| 509 // The call to |ReleaseAnnot| can cause the page pointed to by |m_page| to |
| 510 // be freed, which will cause issues if we try to cleanup the pageview pointer |
| 511 // in |m_page|. So, reset the pageview pointer before doing anything else. |
| 512 m_page->SetView(nullptr); |
| 513 #endif // PDF_ENABLE_XFA |
| 514 |
| 508 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); | 515 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); |
| 509 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); | 516 CPDFSDK_AnnotHandlerMgr* pAnnotHandlerMgr = pEnv->GetAnnotHandlerMgr(); |
| 510 for (CPDFSDK_Annot* pAnnot : m_fxAnnotArray) | 517 for (CPDFSDK_Annot* pAnnot : m_fxAnnotArray) |
| 511 pAnnotHandlerMgr->ReleaseAnnot(pAnnot); | 518 pAnnotHandlerMgr->ReleaseAnnot(pAnnot); |
| 512 | 519 |
| 513 m_fxAnnotArray.clear(); | 520 m_fxAnnotArray.clear(); |
| 514 m_pAnnotList.reset(); | 521 m_pAnnotList.reset(); |
| 522 |
| 515 #ifndef PDF_ENABLE_XFA | 523 #ifndef PDF_ENABLE_XFA |
| 516 m_page->SetView(nullptr); | 524 if (m_bOwnsPage) |
| 517 if (m_bTakeOverPage) { | |
| 518 delete m_page; | 525 delete m_page; |
| 519 } | |
| 520 #endif // PDF_ENABLE_XFA | 526 #endif // PDF_ENABLE_XFA |
| 521 } | 527 } |
| 522 | 528 |
| 523 void CPDFSDK_PageView::PageView_OnDraw(CFX_RenderDevice* pDevice, | 529 void CPDFSDK_PageView::PageView_OnDraw(CFX_RenderDevice* pDevice, |
| 524 CFX_Matrix* pUser2Device, | 530 CFX_Matrix* pUser2Device, |
| 525 #ifdef PDF_ENABLE_XFA | 531 #ifdef PDF_ENABLE_XFA |
| 526 CPDF_RenderOptions* pOptions, | 532 CPDF_RenderOptions* pOptions, |
| 527 const FX_RECT& pClip) { | 533 const FX_RECT& pClip) { |
| 528 #else | 534 #else |
| 529 CPDF_RenderOptions* pOptions) { | 535 CPDF_RenderOptions* pOptions) { |
| (...skipping 492 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1022 return pAnnot; | 1028 return pAnnot; |
| 1023 } | 1029 } |
| 1024 return nullptr; | 1030 return nullptr; |
| 1025 } | 1031 } |
| 1026 | 1032 |
| 1027 int CPDFSDK_PageView::GetPageIndexForStaticPDF() const { | 1033 int CPDFSDK_PageView::GetPageIndexForStaticPDF() const { |
| 1028 CPDF_Dictionary* pDict = GetPDFPage()->m_pFormDict; | 1034 CPDF_Dictionary* pDict = GetPDFPage()->m_pFormDict; |
| 1029 CPDF_Document* pDoc = m_pSDKDoc->GetPDFDocument(); | 1035 CPDF_Document* pDoc = m_pSDKDoc->GetPDFDocument(); |
| 1030 return (pDoc && pDict) ? pDoc->GetPageIndex(pDict->GetObjNum()) : -1; | 1036 return (pDoc && pDict) ? pDoc->GetPageIndex(pDict->GetObjNum()) : -1; |
| 1031 } | 1037 } |
| OLD | NEW |