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 16 matching lines...) Expand all Loading... |
27 #include "xfa/fxfa/include/xfa_rendercontext.h" | 27 #include "xfa/fxfa/include/xfa_rendercontext.h" |
28 #include "xfa/fxgraphics/include/cfx_graphics.h" | 28 #include "xfa/fxgraphics/include/cfx_graphics.h" |
29 #endif // PDF_ENABLE_XFA | 29 #endif // PDF_ENABLE_XFA |
30 | 30 |
31 #if _FX_OS_ == _FX_ANDROID_ | 31 #if _FX_OS_ == _FX_ANDROID_ |
32 #include "time.h" | 32 #include "time.h" |
33 #else | 33 #else |
34 #include <ctime> | 34 #include <ctime> |
35 #endif | 35 #endif |
36 | 36 |
| 37 namespace { |
| 38 |
| 39 // NOTE: |bsUTF16LE| must outlive the use of the result. Care must be taken |
| 40 // since modifying the result would impact |bsUTF16LE|. |
37 FPDF_WIDESTRING AsFPDFWideString(CFX_ByteString* bsUTF16LE) { | 41 FPDF_WIDESTRING AsFPDFWideString(CFX_ByteString* bsUTF16LE) { |
38 return reinterpret_cast<FPDF_WIDESTRING>( | 42 return reinterpret_cast<FPDF_WIDESTRING>( |
39 bsUTF16LE->GetBuffer(bsUTF16LE->GetLength())); | 43 bsUTF16LE->GetBuffer(bsUTF16LE->GetLength())); |
40 } | 44 } |
41 | 45 |
| 46 } // namespace |
| 47 |
42 CPDFDoc_Environment::CPDFDoc_Environment(UnderlyingDocumentType* pDoc, | 48 CPDFDoc_Environment::CPDFDoc_Environment(UnderlyingDocumentType* pDoc, |
43 FPDF_FORMFILLINFO* pFFinfo) | 49 FPDF_FORMFILLINFO* pFFinfo) |
44 : m_pInfo(pFFinfo), m_pSDKDoc(nullptr), m_pUnderlyingDoc(pDoc) { | 50 : m_pInfo(pFFinfo), m_pSDKDoc(nullptr), m_pUnderlyingDoc(pDoc) { |
45 m_pSysHandler.reset(new CFX_SystemHandler(this)); | 51 m_pSysHandler.reset(new CFX_SystemHandler(this)); |
46 } | 52 } |
47 | 53 |
48 CPDFDoc_Environment::~CPDFDoc_Environment() { | 54 CPDFDoc_Environment::~CPDFDoc_Environment() { |
49 #ifdef PDF_ENABLE_XFA | 55 #ifdef PDF_ENABLE_XFA |
50 CPDFXFA_App* pProvider = CPDFXFA_App::GetInstance(); | 56 CPDFXFA_App* pProvider = CPDFXFA_App::GetInstance(); |
51 if (pProvider->m_pEnvList.GetSize() == 0) | 57 if (pProvider->m_pEnvList.GetSize() == 0) |
(...skipping 929 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
981 pEnv->FFI_Invalidate(m_page, rc.left, rc.top, rc.right, rc.bottom); | 987 pEnv->FFI_Invalidate(m_page, rc.left, rc.top, rc.right, rc.bottom); |
982 } | 988 } |
983 | 989 |
984 void CPDFSDK_PageView::UpdateView(CPDFSDK_Annot* pAnnot) { | 990 void CPDFSDK_PageView::UpdateView(CPDFSDK_Annot* pAnnot) { |
985 CFX_FloatRect rcWindow = pAnnot->GetRect(); | 991 CFX_FloatRect rcWindow = pAnnot->GetRect(); |
986 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); | 992 CPDFDoc_Environment* pEnv = m_pSDKDoc->GetEnv(); |
987 pEnv->FFI_Invalidate(m_page, rcWindow.left, rcWindow.top, rcWindow.right, | 993 pEnv->FFI_Invalidate(m_page, rcWindow.left, rcWindow.top, rcWindow.right, |
988 rcWindow.bottom); | 994 rcWindow.bottom); |
989 } | 995 } |
990 | 996 |
991 int CPDFSDK_PageView::GetPageIndex() { | 997 int CPDFSDK_PageView::GetPageIndex() const { |
992 if (m_page) { | 998 if (!m_page) |
| 999 return -1; |
| 1000 |
993 #ifdef PDF_ENABLE_XFA | 1001 #ifdef PDF_ENABLE_XFA |
994 CPDF_Dictionary* pDic = m_page->GetPDFPage()->m_pFormDict; | 1002 int nDocType = m_page->GetDocument()->GetDocType(); |
| 1003 switch (nDocType) { |
| 1004 case DOCTYPE_DYNAMIC_XFA: { |
| 1005 CXFA_FFPageView* pPageView = m_page->GetXFAPageView(); |
| 1006 return pPageView ? pPageView->GetPageIndex() : -1; |
| 1007 } |
| 1008 case DOCTYPE_STATIC_XFA: |
| 1009 case DOCTYPE_PDF: |
| 1010 return GetPageIndexForStaticPDF(); |
| 1011 default: |
| 1012 return -1; |
| 1013 } |
995 #else // PDF_ENABLE_XFA | 1014 #else // PDF_ENABLE_XFA |
996 CPDF_Dictionary* pDic = m_page->m_pFormDict; | 1015 return GetPageIndexForStaticPDF(); |
997 #endif // PDF_ENABLE_XFA | 1016 #endif // PDF_ENABLE_XFA |
998 CPDF_Document* pDoc = m_pSDKDoc->GetPDFDocument(); | |
999 if (pDoc && pDic) { | |
1000 return pDoc->GetPageIndex(pDic->GetObjNum()); | |
1001 } | |
1002 } | |
1003 return -1; | |
1004 } | 1017 } |
1005 | 1018 |
1006 bool CPDFSDK_PageView::IsValidAnnot(const CPDF_Annot* p) const { | 1019 bool CPDFSDK_PageView::IsValidAnnot(const CPDF_Annot* p) const { |
1007 if (!p) | 1020 if (!p) |
1008 return false; | 1021 return false; |
1009 | 1022 |
1010 const auto& annots = m_pAnnotList->All(); | 1023 const auto& annots = m_pAnnotList->All(); |
1011 return pdfium::ContainsValue(annots, p); | 1024 return pdfium::ContainsValue(annots, p); |
1012 } | 1025 } |
1013 | 1026 |
1014 CPDFSDK_Annot* CPDFSDK_PageView::GetFocusAnnot() { | 1027 CPDFSDK_Annot* CPDFSDK_PageView::GetFocusAnnot() { |
1015 CPDFSDK_Annot* pFocusAnnot = m_pSDKDoc->GetFocusAnnot(); | 1028 CPDFSDK_Annot* pFocusAnnot = m_pSDKDoc->GetFocusAnnot(); |
1016 if (!pFocusAnnot) | 1029 if (!pFocusAnnot) |
1017 return nullptr; | 1030 return nullptr; |
1018 | 1031 |
1019 for (CPDFSDK_Annot* pAnnot : m_fxAnnotArray) { | 1032 for (CPDFSDK_Annot* pAnnot : m_fxAnnotArray) { |
1020 if (pAnnot == pFocusAnnot) | 1033 if (pAnnot == pFocusAnnot) |
1021 return pAnnot; | 1034 return pAnnot; |
1022 } | 1035 } |
1023 return nullptr; | 1036 return nullptr; |
1024 } | 1037 } |
| 1038 |
| 1039 int CPDFSDK_PageView::GetPageIndexForStaticPDF() const { |
| 1040 #ifdef PDF_ENABLE_XFA |
| 1041 CPDF_Page* pPage = m_page->GetPDFPage(); |
| 1042 #else // PDF_ENABLE_XFA |
| 1043 CPDF_Page* pPage = m_page; |
| 1044 #endif // PDF_ENABLE_XFA |
| 1045 CPDF_Dictionary* pDict = pPage->m_pFormDict; |
| 1046 CPDF_Document* pDoc = m_pSDKDoc->GetPDFDocument(); |
| 1047 return (pDoc && pDict) ? pDoc->GetPageIndex(pDict->GetObjNum()) : -1; |
| 1048 } |
OLD | NEW |