| 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/include/xfa_ffapp.h" | 7 #include "xfa/fxfa/include/xfa_ffapp.h" |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 19 matching lines...) Expand all Loading... |
| 30 | 30 |
| 31 FX_FILESIZE CXFA_FileRead::GetSize() { | 31 FX_FILESIZE CXFA_FileRead::GetSize() { |
| 32 uint32_t dwSize = 0; | 32 uint32_t dwSize = 0; |
| 33 int32_t iCount = m_Data.GetSize(); | 33 int32_t iCount = m_Data.GetSize(); |
| 34 for (int32_t i = 0; i < iCount; i++) { | 34 for (int32_t i = 0; i < iCount; i++) { |
| 35 CPDF_StreamAcc& acc = m_Data[i]; | 35 CPDF_StreamAcc& acc = m_Data[i]; |
| 36 dwSize += acc.GetSize(); | 36 dwSize += acc.GetSize(); |
| 37 } | 37 } |
| 38 return dwSize; | 38 return dwSize; |
| 39 } | 39 } |
| 40 |
| 40 FX_BOOL CXFA_FileRead::ReadBlock(void* buffer, | 41 FX_BOOL CXFA_FileRead::ReadBlock(void* buffer, |
| 41 FX_FILESIZE offset, | 42 FX_FILESIZE offset, |
| 42 size_t size) { | 43 size_t size) { |
| 43 int32_t iCount = m_Data.GetSize(); | 44 int32_t iCount = m_Data.GetSize(); |
| 44 int32_t index = 0; | 45 int32_t index = 0; |
| 45 while (index < iCount) { | 46 while (index < iCount) { |
| 46 CPDF_StreamAcc& acc = m_Data[index]; | 47 CPDF_StreamAcc& acc = m_Data[index]; |
| 47 FX_FILESIZE dwSize = acc.GetSize(); | 48 FX_FILESIZE dwSize = acc.GetSize(); |
| 48 if (offset < dwSize) { | 49 if (offset < dwSize) { |
| 49 break; | 50 break; |
| (...skipping 15 matching lines...) Expand all Loading... |
| 65 index++; | 66 index++; |
| 66 } | 67 } |
| 67 return FALSE; | 68 return FALSE; |
| 68 } | 69 } |
| 69 | 70 |
| 70 void CXFA_FileRead::Release() { | 71 void CXFA_FileRead::Release() { |
| 71 delete this; | 72 delete this; |
| 72 } | 73 } |
| 73 | 74 |
| 74 CXFA_FFApp::CXFA_FFApp(IXFA_AppProvider* pProvider) | 75 CXFA_FFApp::CXFA_FFApp(IXFA_AppProvider* pProvider) |
| 75 : m_pDocHandler(nullptr), | 76 : m_pProvider(pProvider), |
| 76 m_pFWLTheme(nullptr), | |
| 77 m_pProvider(pProvider), | |
| 78 m_pFontMgr(nullptr), | |
| 79 #if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ | |
| 80 m_pFontSource(nullptr), | |
| 81 #endif | |
| 82 m_pAdapterWidgetMgr(nullptr), | |
| 83 m_pWidgetMgrDelegate(nullptr), | 77 m_pWidgetMgrDelegate(nullptr), |
| 84 m_pFDEFontMgr(nullptr) { | 78 m_pFWLApp(IFWL_App::Create(this)) { |
| 85 m_pFWLApp = IFWL_App::Create(this); | 79 FWL_SetApp(m_pFWLApp.get()); |
| 86 FWL_SetApp(m_pFWLApp); | |
| 87 m_pFWLApp->Initialize(); | 80 m_pFWLApp->Initialize(); |
| 88 CXFA_TimeZoneProvider::Create(); | 81 CXFA_TimeZoneProvider::Create(); |
| 89 } | 82 } |
| 90 | 83 |
| 91 CXFA_FFApp::~CXFA_FFApp() { | 84 CXFA_FFApp::~CXFA_FFApp() { |
| 92 delete m_pDocHandler; | |
| 93 if (m_pFWLApp) { | 85 if (m_pFWLApp) { |
| 94 m_pFWLApp->Finalize(); | 86 m_pFWLApp->Finalize(); |
| 95 m_pFWLApp->Release(); | 87 m_pFWLApp->Release(); |
| 96 delete m_pFWLApp; | |
| 97 } | 88 } |
| 98 delete m_pFWLTheme; | |
| 99 delete m_pAdapterWidgetMgr; | |
| 100 | 89 |
| 101 CXFA_TimeZoneProvider::Destroy(); | 90 CXFA_TimeZoneProvider::Destroy(); |
| 102 delete m_pFontMgr; | |
| 103 #if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ | |
| 104 if (m_pFontSource) | |
| 105 m_pFontSource->Release(); | |
| 106 #endif | |
| 107 if (m_pFDEFontMgr) | |
| 108 m_pFDEFontMgr->Release(); | |
| 109 } | 91 } |
| 110 | 92 |
| 111 CXFA_FFDocHandler* CXFA_FFApp::GetDocHandler() { | 93 CXFA_FFDocHandler* CXFA_FFApp::GetDocHandler() { |
| 112 if (!m_pDocHandler) | 94 if (!m_pDocHandler) |
| 113 m_pDocHandler = new CXFA_FFDocHandler; | 95 m_pDocHandler.reset(new CXFA_FFDocHandler); |
| 114 return m_pDocHandler; | 96 return m_pDocHandler.get(); |
| 115 } | 97 } |
| 98 |
| 116 CXFA_FFDoc* CXFA_FFApp::CreateDoc(IXFA_DocProvider* pProvider, | 99 CXFA_FFDoc* CXFA_FFApp::CreateDoc(IXFA_DocProvider* pProvider, |
| 117 IFX_FileRead* pStream, | 100 IFX_FileRead* pStream, |
| 118 FX_BOOL bTakeOverFile) { | 101 FX_BOOL bTakeOverFile) { |
| 119 std::unique_ptr<CXFA_FFDoc> pDoc(new CXFA_FFDoc(this, pProvider)); | 102 std::unique_ptr<CXFA_FFDoc> pDoc(new CXFA_FFDoc(this, pProvider)); |
| 120 FX_BOOL bSuccess = pDoc->OpenDoc(pStream, bTakeOverFile); | 103 FX_BOOL bSuccess = pDoc->OpenDoc(pStream, bTakeOverFile); |
| 121 return bSuccess ? pDoc.release() : nullptr; | 104 return bSuccess ? pDoc.release() : nullptr; |
| 122 } | 105 } |
| 123 | 106 |
| 124 CXFA_FFDoc* CXFA_FFApp::CreateDoc(IXFA_DocProvider* pProvider, | 107 CXFA_FFDoc* CXFA_FFApp::CreateDoc(IXFA_DocProvider* pProvider, |
| 125 CPDF_Document* pPDFDoc) { | 108 CPDF_Document* pPDFDoc) { |
| 126 if (!pPDFDoc) | 109 if (!pPDFDoc) |
| 127 return nullptr; | 110 return nullptr; |
| 128 | 111 |
| 129 std::unique_ptr<CXFA_FFDoc> pDoc(new CXFA_FFDoc(this, pProvider)); | 112 std::unique_ptr<CXFA_FFDoc> pDoc(new CXFA_FFDoc(this, pProvider)); |
| 130 FX_BOOL bSuccess = pDoc->OpenDoc(pPDFDoc); | 113 FX_BOOL bSuccess = pDoc->OpenDoc(pPDFDoc); |
| 131 return bSuccess ? pDoc.release() : nullptr; | 114 return bSuccess ? pDoc.release() : nullptr; |
| 132 } | 115 } |
| 133 | 116 |
| 134 void CXFA_FFApp::SetDefaultFontMgr(std::unique_ptr<CXFA_DefFontMgr> pFontMgr) { | 117 void CXFA_FFApp::SetDefaultFontMgr(std::unique_ptr<CXFA_DefFontMgr> pFontMgr) { |
| 135 if (!m_pFontMgr) | 118 if (!m_pFontMgr) |
| 136 m_pFontMgr = new CXFA_FontMgr(); | 119 m_pFontMgr.reset(new CXFA_FontMgr()); |
| 137 m_pFontMgr->SetDefFontMgr(std::move(pFontMgr)); | 120 m_pFontMgr->SetDefFontMgr(std::move(pFontMgr)); |
| 138 } | 121 } |
| 139 | 122 |
| 140 CXFA_FontMgr* CXFA_FFApp::GetXFAFontMgr() { | 123 CXFA_FontMgr* CXFA_FFApp::GetXFAFontMgr() const { |
| 141 return m_pFontMgr; | 124 return m_pFontMgr.get(); |
| 142 } | 125 } |
| 143 | 126 |
| 144 IFGAS_FontMgr* CXFA_FFApp::GetFDEFontMgr() { | 127 IFGAS_FontMgr* CXFA_FFApp::GetFDEFontMgr() { |
| 145 if (!m_pFDEFontMgr) { | 128 if (!m_pFDEFontMgr) { |
| 146 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ | 129 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ |
| 147 m_pFDEFontMgr = IFGAS_FontMgr::Create(FX_GetDefFontEnumerator()); | 130 m_pFDEFontMgr = IFGAS_FontMgr::Create(FX_GetDefFontEnumerator()); |
| 148 #else | 131 #else |
| 149 m_pFontSource = new CFX_FontSourceEnum_File; | 132 m_pFontSource.reset(new CFX_FontSourceEnum_File); |
| 150 m_pFDEFontMgr = IFGAS_FontMgr::Create(m_pFontSource); | 133 m_pFDEFontMgr = IFGAS_FontMgr::Create(m_pFontSource.get()); |
| 151 #endif | 134 #endif |
| 152 } | 135 } |
| 153 return m_pFDEFontMgr; | 136 return m_pFDEFontMgr.get(); |
| 154 } | 137 } |
| 138 |
| 155 CXFA_FWLTheme* CXFA_FFApp::GetFWLTheme() { | 139 CXFA_FWLTheme* CXFA_FFApp::GetFWLTheme() { |
| 156 if (!m_pFWLTheme) { | 140 if (!m_pFWLTheme) |
| 157 m_pFWLTheme = new CXFA_FWLTheme(this); | 141 m_pFWLTheme.reset(new CXFA_FWLTheme(this)); |
| 158 } | 142 return m_pFWLTheme.get(); |
| 159 return m_pFWLTheme; | |
| 160 } | 143 } |
| 144 |
| 161 CXFA_FWLAdapterWidgetMgr* CXFA_FFApp::GetWidgetMgr( | 145 CXFA_FWLAdapterWidgetMgr* CXFA_FFApp::GetWidgetMgr( |
| 162 CFWL_WidgetMgrDelegate* pDelegate) { | 146 CFWL_WidgetMgrDelegate* pDelegate) { |
| 163 if (!m_pAdapterWidgetMgr) { | 147 if (!m_pAdapterWidgetMgr) { |
| 164 m_pAdapterWidgetMgr = new CXFA_FWLAdapterWidgetMgr; | 148 m_pAdapterWidgetMgr.reset(new CXFA_FWLAdapterWidgetMgr); |
| 165 pDelegate->OnSetCapability(FWL_WGTMGR_DisableThread | | 149 pDelegate->OnSetCapability(FWL_WGTMGR_DisableThread | |
| 166 FWL_WGTMGR_DisableForm); | 150 FWL_WGTMGR_DisableForm); |
| 167 m_pWidgetMgrDelegate = pDelegate; | 151 m_pWidgetMgrDelegate = pDelegate; |
| 168 } | 152 } |
| 169 return m_pAdapterWidgetMgr; | 153 return m_pAdapterWidgetMgr.get(); |
| 170 } | 154 } |
| 171 IFWL_AdapterTimerMgr* CXFA_FFApp::GetTimerMgr() { | 155 |
| 156 IFWL_AdapterTimerMgr* CXFA_FFApp::GetTimerMgr() const { |
| 172 return m_pProvider->GetTimerMgr(); | 157 return m_pProvider->GetTimerMgr(); |
| 173 } | 158 } |
| OLD | NEW |