blob: ae6538df8ed6ae9884518bdc8d9ceae4064d44d0 [file] [log] [blame]
npmd6918992016-08-17 13:22:16 -07001// 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
dsinclair74a34fc2016-09-29 16:41:42 -07007#include "core/fxge/cfx_fontcache.h"
npmd6918992016-08-17 13:22:16 -07008
Tom Sepez8f877b22019-05-13 21:53:53 +00009#include "core/fxge/cfx_font.h"
Tom Sepez23607912019-05-16 16:03:54 +000010#include "core/fxge/cfx_glyphcache.h"
dsinclair74a34fc2016-09-29 16:41:42 -070011#include "core/fxge/fx_font.h"
12#include "core/fxge/fx_freetype.h"
npmd6918992016-08-17 13:22:16 -070013
Tom Sepez8f877b22019-05-13 21:53:53 +000014CFX_FontCache::CFX_FontCache() = default;
art-snake9972ff92016-09-20 07:46:25 -070015
Tom Sepez8f877b22019-05-13 21:53:53 +000016CFX_FontCache::~CFX_FontCache() = default;
art-snake9972ff92016-09-20 07:46:25 -070017
Tom Sepez23607912019-05-16 16:03:54 +000018RetainPtr<CFX_GlyphCache> CFX_FontCache::GetGlyphCache(const CFX_Font* pFont) {
Tom Sepez3512b962019-06-12 17:19:56 +000019 RetainPtr<CFX_Face> face = pFont->GetFace();
npmd6918992016-08-17 13:22:16 -070020 const bool bExternal = !face;
Tom Sepez23607912019-05-16 16:03:54 +000021 auto& map = bExternal ? m_ExtGlyphCacheMap : m_GlyphCacheMap;
Tom Sepez3512b962019-06-12 17:19:56 +000022 auto it = map.find(face.Get());
Tom Sepez8f877b22019-05-13 21:53:53 +000023 if (it != map.end() && it->second)
24 return pdfium::WrapRetain(it->second.Get());
npmd6918992016-08-17 13:22:16 -070025
Tom Sepez23607912019-05-16 16:03:54 +000026 auto new_cache = pdfium::MakeRetain<CFX_GlyphCache>(face);
Tom Sepez3512b962019-06-12 17:19:56 +000027 map[face.Get()].Reset(new_cache.Get());
Tom Sepez8f877b22019-05-13 21:53:53 +000028 return new_cache;
npmd6918992016-08-17 13:22:16 -070029}
30
Lei Zhang4facbc92020-07-30 16:49:26 +000031#if defined(_SKIA_SUPPORT_)
art-snake9972ff92016-09-20 07:46:25 -070032CFX_TypeFace* CFX_FontCache::GetDeviceCache(const CFX_Font* pFont) {
Tom Sepez23607912019-05-16 16:03:54 +000033 return GetGlyphCache(pFont)->GetDeviceCache(pFont);
npmd6918992016-08-17 13:22:16 -070034}
35#endif