• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
7 #include "core/fxge/cfx_fontcache.h"
8 
9 #include <memory>
10 #include <utility>
11 
12 #include "core/fxge/cfx_font.h"
13 #include "core/fxge/cfx_glyphcache.h"
14 #include "core/fxge/fx_font.h"
15 #include "core/fxge/fx_freetype.h"
16 #include "third_party/base/ptr_util.h"
17 
18 CFX_FontCache::CFX_FontCache() = default;
19 
20 CFX_FontCache::~CFX_FontCache() = default;
21 
GetGlyphCache(const CFX_Font * pFont)22 RetainPtr<CFX_GlyphCache> CFX_FontCache::GetGlyphCache(const CFX_Font* pFont) {
23   RetainPtr<CFX_Face> face = pFont->GetFace();
24   const bool bExternal = !face;
25   auto& map = bExternal ? m_ExtGlyphCacheMap : m_GlyphCacheMap;
26   auto it = map.find(face.Get());
27   if (it != map.end() && it->second)
28     return pdfium::WrapRetain(it->second.Get());
29 
30   auto new_cache = pdfium::MakeRetain<CFX_GlyphCache>(face);
31   map[face.Get()].Reset(new_cache.Get());
32   return new_cache;
33 }
34 
35 #ifdef _SKIA_SUPPORT_
GetDeviceCache(const CFX_Font * pFont)36 CFX_TypeFace* CFX_FontCache::GetDeviceCache(const CFX_Font* pFont) {
37   return GetGlyphCache(pFont)->GetDeviceCache(pFont);
38 }
39 #endif
40