| 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/fwl/theme/cfwl_widgettp.h" | 7 #include "xfa/fwl/theme/cfwl_widgettp.h" |
| 8 | 8 |
| 9 #include <algorithm> | 9 #include <algorithm> |
| 10 #include <utility> | 10 #include <utility> |
| (...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 291 m_dwStyles = dwFontStyles; | 291 m_dwStyles = dwFontStyles; |
| 292 m_dwCodePage = dwCodePage; | 292 m_dwCodePage = dwCodePage; |
| 293 if (!m_pFontMgr) { | 293 if (!m_pFontMgr) { |
| 294 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ | 294 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ |
| 295 m_pFontMgr = CFGAS_FontMgr::Create(FX_GetDefFontEnumerator()); | 295 m_pFontMgr = CFGAS_FontMgr::Create(FX_GetDefFontEnumerator()); |
| 296 #else | 296 #else |
| 297 m_pFontSource = pdfium::MakeUnique<CFX_FontSourceEnum_File>(); | 297 m_pFontSource = pdfium::MakeUnique<CFX_FontSourceEnum_File>(); |
| 298 m_pFontMgr = CFGAS_FontMgr::Create(m_pFontSource.get()); | 298 m_pFontMgr = CFGAS_FontMgr::Create(m_pFontSource.get()); |
| 299 #endif | 299 #endif |
| 300 } | 300 } |
| 301 m_pFont.reset(CFGAS_GEFont::LoadFont(wsFontFamily.c_str(), dwFontStyles, | 301 m_pFont = CFGAS_GEFont::LoadFont(wsFontFamily.c_str(), dwFontStyles, |
| 302 dwCodePage, m_pFontMgr.get())); | 302 dwCodePage, m_pFontMgr.get()); |
| 303 return !!m_pFont; | 303 return !!m_pFont; |
| 304 } | 304 } |
| 305 | 305 |
| 306 CFWL_FontManager* CFWL_FontManager::s_FontManager = nullptr; | 306 CFWL_FontManager* CFWL_FontManager::s_FontManager = nullptr; |
| 307 CFWL_FontManager* CFWL_FontManager::GetInstance() { | 307 CFWL_FontManager* CFWL_FontManager::GetInstance() { |
| 308 if (!s_FontManager) | 308 if (!s_FontManager) |
| 309 s_FontManager = new CFWL_FontManager; | 309 s_FontManager = new CFWL_FontManager; |
| 310 return s_FontManager; | 310 return s_FontManager; |
| 311 } | 311 } |
| 312 | 312 |
| 313 void CFWL_FontManager::DestroyInstance() { | 313 void CFWL_FontManager::DestroyInstance() { |
| 314 delete s_FontManager; | 314 delete s_FontManager; |
| 315 s_FontManager = nullptr; | 315 s_FontManager = nullptr; |
| 316 } | 316 } |
| 317 | 317 |
| 318 CFWL_FontManager::CFWL_FontManager() {} | 318 CFWL_FontManager::CFWL_FontManager() {} |
| 319 | 319 |
| 320 CFWL_FontManager::~CFWL_FontManager() {} | 320 CFWL_FontManager::~CFWL_FontManager() {} |
| 321 | 321 |
| 322 CFGAS_GEFont* CFWL_FontManager::FindFont(const CFX_WideStringC& wsFontFamily, | 322 CFX_RetainPtr<CFGAS_GEFont> CFWL_FontManager::FindFont( |
| 323 uint32_t dwFontStyles, | 323 const CFX_WideStringC& wsFontFamily, |
| 324 uint16_t wCodePage) { | 324 uint32_t dwFontStyles, |
| 325 uint16_t wCodePage) { |
| 325 for (const auto& pData : m_FontsArray) { | 326 for (const auto& pData : m_FontsArray) { |
| 326 if (pData->Equal(wsFontFamily, dwFontStyles, wCodePage)) | 327 if (pData->Equal(wsFontFamily, dwFontStyles, wCodePage)) |
| 327 return pData->GetFont(); | 328 return pData->GetFont(); |
| 328 } | 329 } |
| 329 std::unique_ptr<CFWL_FontData> pFontData(new CFWL_FontData); | 330 auto pFontData = pdfium::MakeUnique<CFWL_FontData>(); |
| 330 if (!pFontData->LoadFont(wsFontFamily, dwFontStyles, wCodePage)) | 331 if (!pFontData->LoadFont(wsFontFamily, dwFontStyles, wCodePage)) |
| 331 return nullptr; | 332 return nullptr; |
| 333 |
| 332 m_FontsArray.push_back(std::move(pFontData)); | 334 m_FontsArray.push_back(std::move(pFontData)); |
| 333 return m_FontsArray.back()->GetFont(); | 335 return m_FontsArray.back()->GetFont(); |
| 334 } | 336 } |
| 335 | 337 |
| 336 void FWLTHEME_Release() { | 338 void FWLTHEME_Release() { |
| 337 CFWL_FontManager::DestroyInstance(); | 339 CFWL_FontManager::DestroyInstance(); |
| 338 } | 340 } |
| OLD | NEW |