| OLD | NEW |
| (Empty) |
| 1 // Copyright 2014 PDFium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com | |
| 6 | |
| 7 #include "xfa/src/fxfa/app/xfa_ffapp.h" | |
| 8 | |
| 9 #include <algorithm> | |
| 10 | |
| 11 #include "xfa/include/fwl/core/fwl_widgetmgr.h" | |
| 12 #include "xfa/src/fxfa/app/xfa_ffdoc.h" | |
| 13 #include "xfa/src/fxfa/app/xfa_ffdochandler.h" | |
| 14 #include "xfa/src/fxfa/app/xfa_ffwidgethandler.h" | |
| 15 #include "xfa/src/fxfa/app/xfa_fontmgr.h" | |
| 16 #include "xfa/src/fxfa/app/xfa_fwladapter.h" | |
| 17 #include "xfa/src/fxfa/app/xfa_fwltheme.h" | |
| 18 | |
| 19 CXFA_FileRead::CXFA_FileRead(const CFX_ArrayTemplate<CPDF_Stream*>& streams) { | |
| 20 int32_t iCount = streams.GetSize(); | |
| 21 for (int32_t i = 0; i < iCount; i++) { | |
| 22 CPDF_StreamAcc& acc = m_Data.Add(); | |
| 23 acc.LoadAllData(streams[i]); | |
| 24 } | |
| 25 } | |
| 26 FX_FILESIZE CXFA_FileRead::GetSize() { | |
| 27 FX_DWORD dwSize = 0; | |
| 28 int32_t iCount = m_Data.GetSize(); | |
| 29 for (int32_t i = 0; i < iCount; i++) { | |
| 30 CPDF_StreamAcc& acc = m_Data[i]; | |
| 31 dwSize += acc.GetSize(); | |
| 32 } | |
| 33 return dwSize; | |
| 34 } | |
| 35 FX_BOOL CXFA_FileRead::ReadBlock(void* buffer, | |
| 36 FX_FILESIZE offset, | |
| 37 size_t size) { | |
| 38 int32_t iCount = m_Data.GetSize(); | |
| 39 int32_t index = 0; | |
| 40 while (index < iCount) { | |
| 41 CPDF_StreamAcc& acc = m_Data[index]; | |
| 42 FX_FILESIZE dwSize = acc.GetSize(); | |
| 43 if (offset < dwSize) { | |
| 44 break; | |
| 45 } | |
| 46 offset -= dwSize; | |
| 47 index++; | |
| 48 } | |
| 49 while (index < iCount) { | |
| 50 CPDF_StreamAcc& acc = m_Data[index]; | |
| 51 FX_DWORD dwSize = acc.GetSize(); | |
| 52 size_t dwRead = std::min(size, static_cast<size_t>(dwSize - offset)); | |
| 53 FXSYS_memcpy(buffer, acc.GetData() + offset, dwRead); | |
| 54 size -= dwRead; | |
| 55 if (size == 0) { | |
| 56 return TRUE; | |
| 57 } | |
| 58 buffer = (uint8_t*)buffer + dwRead; | |
| 59 offset = 0; | |
| 60 index++; | |
| 61 } | |
| 62 return FALSE; | |
| 63 } | |
| 64 // static | |
| 65 IXFA_App* IXFA_App::Create(IXFA_AppProvider* pProvider) { | |
| 66 return new CXFA_FFApp(pProvider); | |
| 67 } | |
| 68 // virtual | |
| 69 IXFA_App::~IXFA_App() {} | |
| 70 CXFA_FFApp::CXFA_FFApp(IXFA_AppProvider* pProvider) | |
| 71 : m_pDocHandler(nullptr), | |
| 72 m_pFWLTheme(nullptr), | |
| 73 m_pProvider(pProvider), | |
| 74 m_pFontMgr(nullptr), | |
| 75 #if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ | |
| 76 m_pFontSource(nullptr), | |
| 77 #endif | |
| 78 m_pAdapterWidgetMgr(nullptr), | |
| 79 m_pWidgetMgrDelegate(nullptr), | |
| 80 m_pFDEFontMgr(nullptr), | |
| 81 m_pMenuHandler(nullptr), | |
| 82 m_pAdapterThreadMgr(nullptr) { | |
| 83 m_pFWLApp = IFWL_App::Create(this); | |
| 84 FWL_SetApp(m_pFWLApp); | |
| 85 m_pFWLApp->Initialize(); | |
| 86 IXFA_TimeZoneProvider::Create(); | |
| 87 } | |
| 88 CXFA_FFApp::~CXFA_FFApp() { | |
| 89 delete m_pDocHandler; | |
| 90 if (m_pFWLApp) { | |
| 91 m_pFWLApp->Finalize(); | |
| 92 m_pFWLApp->Release(); | |
| 93 delete m_pFWLApp; | |
| 94 } | |
| 95 if (m_pFWLTheme) | |
| 96 m_pFWLTheme->Release(); | |
| 97 delete m_pAdapterWidgetMgr; | |
| 98 delete m_pAdapterThreadMgr; | |
| 99 delete m_pMenuHandler; | |
| 100 IXFA_TimeZoneProvider::Destroy(); | |
| 101 delete m_pFontMgr; | |
| 102 #if _FXM_PLATFORM_ != _FXM_PLATFORM_WINDOWS_ | |
| 103 if (m_pFontSource) | |
| 104 m_pFontSource->Release(); | |
| 105 #endif | |
| 106 if (m_pFDEFontMgr) | |
| 107 m_pFDEFontMgr->Release(); | |
| 108 } | |
| 109 IXFA_MenuHandler* CXFA_FFApp::GetMenuHandler() { | |
| 110 if (!m_pMenuHandler) { | |
| 111 m_pMenuHandler = new CXFA_FFMenuHandler; | |
| 112 } | |
| 113 return m_pMenuHandler; | |
| 114 } | |
| 115 IXFA_DocHandler* CXFA_FFApp::GetDocHandler() { | |
| 116 if (!m_pDocHandler) { | |
| 117 m_pDocHandler = new CXFA_FFDocHandler; | |
| 118 } | |
| 119 return m_pDocHandler; | |
| 120 } | |
| 121 IXFA_Doc* CXFA_FFApp::CreateDoc(IXFA_DocProvider* pProvider, | |
| 122 IFX_FileRead* pStream, | |
| 123 FX_BOOL bTakeOverFile) { | |
| 124 CXFA_FFDoc* pDoc = new CXFA_FFDoc(this, pProvider); | |
| 125 FX_BOOL bSuccess = pDoc->OpenDoc(pStream, bTakeOverFile); | |
| 126 if (!bSuccess) { | |
| 127 delete pDoc; | |
| 128 pDoc = NULL; | |
| 129 } | |
| 130 return pDoc; | |
| 131 } | |
| 132 IXFA_Doc* CXFA_FFApp::CreateDoc(IXFA_DocProvider* pProvider, | |
| 133 CPDF_Document* pPDFDoc) { | |
| 134 if (pPDFDoc == NULL) { | |
| 135 return NULL; | |
| 136 } | |
| 137 CXFA_FFDoc* pDoc = new CXFA_FFDoc(this, pProvider); | |
| 138 FX_BOOL bSuccess = pDoc->OpenDoc(pPDFDoc); | |
| 139 if (!bSuccess) { | |
| 140 delete pDoc; | |
| 141 pDoc = NULL; | |
| 142 } | |
| 143 return pDoc; | |
| 144 } | |
| 145 | |
| 146 void CXFA_FFApp::SetDefaultFontMgr(IXFA_FontMgr* pFontMgr) { | |
| 147 if (!m_pFontMgr) { | |
| 148 m_pFontMgr = new CXFA_FontMgr(); | |
| 149 } | |
| 150 m_pFontMgr->SetDefFontMgr(pFontMgr); | |
| 151 } | |
| 152 CXFA_FontMgr* CXFA_FFApp::GetXFAFontMgr() { | |
| 153 return m_pFontMgr; | |
| 154 } | |
| 155 IFX_FontMgr* CXFA_FFApp::GetFDEFontMgr() { | |
| 156 if (!m_pFDEFontMgr) { | |
| 157 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ | |
| 158 m_pFDEFontMgr = IFX_FontMgr::Create(FX_GetDefFontEnumerator()); | |
| 159 #else | |
| 160 m_pFontSource = FX_CreateDefaultFontSourceEnum(); | |
| 161 m_pFDEFontMgr = IFX_FontMgr::Create(m_pFontSource); | |
| 162 #endif | |
| 163 } | |
| 164 return m_pFDEFontMgr; | |
| 165 } | |
| 166 CXFA_FWLTheme* CXFA_FFApp::GetFWLTheme() { | |
| 167 if (!m_pFWLTheme) { | |
| 168 m_pFWLTheme = new CXFA_FWLTheme(this); | |
| 169 } | |
| 170 return m_pFWLTheme; | |
| 171 } | |
| 172 IFWL_AdapterWidgetMgr* CXFA_FFApp::GetWidgetMgr( | |
| 173 IFWL_WidgetMgrDelegate* pDelegate) { | |
| 174 if (!m_pAdapterWidgetMgr) { | |
| 175 m_pAdapterWidgetMgr = new CXFA_FWLAdapterWidgetMgr; | |
| 176 pDelegate->OnSetCapability(FWL_WGTMGR_DisableThread | | |
| 177 FWL_WGTMGR_DisableForm); | |
| 178 m_pWidgetMgrDelegate = pDelegate; | |
| 179 } | |
| 180 return m_pAdapterWidgetMgr; | |
| 181 } | |
| 182 IFWL_AdapterThreadMgr* CXFA_FFApp::GetThreadMgr() { | |
| 183 if (!m_pAdapterThreadMgr) { | |
| 184 m_pAdapterThreadMgr = new CFWL_SDAdapterThreadMgr; | |
| 185 } | |
| 186 return m_pAdapterThreadMgr; | |
| 187 } | |
| 188 IFWL_AdapterTimerMgr* CXFA_FFApp::GetTimerMgr() { | |
| 189 return m_pProvider->GetTimerMgr(); | |
| 190 } | |
| OLD | NEW |