| npm | d691899 | 2016-08-17 13:22:16 -0700 | [diff] [blame] | 1 | // Copyright 2016 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 | |
| dsinclair | 74a34fc | 2016-09-29 16:41:42 -0700 | [diff] [blame] | 7 | #include "core/fxge/cfx_fontcache.h" |
| npm | d691899 | 2016-08-17 13:22:16 -0700 | [diff] [blame] | 8 | |
| Tom Sepez | 8f877b2 | 2019-05-13 21:53:53 +0000 | [diff] [blame] | 9 | #include "core/fxge/cfx_font.h" |
| Tom Sepez | 2360791 | 2019-05-16 16:03:54 +0000 | [diff] [blame] | 10 | #include "core/fxge/cfx_glyphcache.h" |
| dsinclair | 74a34fc | 2016-09-29 16:41:42 -0700 | [diff] [blame] | 11 | #include "core/fxge/fx_font.h" |
| 12 | #include "core/fxge/fx_freetype.h" |
| npm | d691899 | 2016-08-17 13:22:16 -0700 | [diff] [blame] | 13 | |
| Tom Sepez | 8f877b2 | 2019-05-13 21:53:53 +0000 | [diff] [blame] | 14 | CFX_FontCache::CFX_FontCache() = default; |
| art-snake | 9972ff9 | 2016-09-20 07:46:25 -0700 | [diff] [blame] | 15 | |
| Tom Sepez | 8f877b2 | 2019-05-13 21:53:53 +0000 | [diff] [blame] | 16 | CFX_FontCache::~CFX_FontCache() = default; |
| art-snake | 9972ff9 | 2016-09-20 07:46:25 -0700 | [diff] [blame] | 17 | |
| Tom Sepez | 2360791 | 2019-05-16 16:03:54 +0000 | [diff] [blame] | 18 | RetainPtr<CFX_GlyphCache> CFX_FontCache::GetGlyphCache(const CFX_Font* pFont) { |
| Tom Sepez | 3512b96 | 2019-06-12 17:19:56 +0000 | [diff] [blame] | 19 | RetainPtr<CFX_Face> face = pFont->GetFace(); |
| npm | d691899 | 2016-08-17 13:22:16 -0700 | [diff] [blame] | 20 | const bool bExternal = !face; |
| Tom Sepez | 2360791 | 2019-05-16 16:03:54 +0000 | [diff] [blame] | 21 | auto& map = bExternal ? m_ExtGlyphCacheMap : m_GlyphCacheMap; |
| Tom Sepez | 3512b96 | 2019-06-12 17:19:56 +0000 | [diff] [blame] | 22 | auto it = map.find(face.Get()); |
| Tom Sepez | 8f877b2 | 2019-05-13 21:53:53 +0000 | [diff] [blame] | 23 | if (it != map.end() && it->second) |
| 24 | return pdfium::WrapRetain(it->second.Get()); |
| npm | d691899 | 2016-08-17 13:22:16 -0700 | [diff] [blame] | 25 | |
| Tom Sepez | 2360791 | 2019-05-16 16:03:54 +0000 | [diff] [blame] | 26 | auto new_cache = pdfium::MakeRetain<CFX_GlyphCache>(face); |
| Tom Sepez | 3512b96 | 2019-06-12 17:19:56 +0000 | [diff] [blame] | 27 | map[face.Get()].Reset(new_cache.Get()); |
| Tom Sepez | 8f877b2 | 2019-05-13 21:53:53 +0000 | [diff] [blame] | 28 | return new_cache; |
| npm | d691899 | 2016-08-17 13:22:16 -0700 | [diff] [blame] | 29 | } |
| 30 | |
| Lei Zhang | 4facbc9 | 2020-07-30 16:49:26 +0000 | [diff] [blame] | 31 | #if defined(_SKIA_SUPPORT_) |
| art-snake | 9972ff9 | 2016-09-20 07:46:25 -0700 | [diff] [blame] | 32 | CFX_TypeFace* CFX_FontCache::GetDeviceCache(const CFX_Font* pFont) { |
| Tom Sepez | 2360791 | 2019-05-16 16:03:54 +0000 | [diff] [blame] | 33 | return GetGlyphCache(pFont)->GetDeviceCache(pFont); |
| npm | d691899 | 2016-08-17 13:22:16 -0700 | [diff] [blame] | 34 | } |
| 35 | #endif |