Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(155)

Side by Side Diff: core/fxge/ge/cfx_fontcache.cpp

Issue 2246223002: Refactor fx_font part 1 (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: CFX_AutoFontCache to own class, fixes Created 4 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « core/fxge/ge/cfx_autofontcache.cpp ('k') | core/fxge/ge/cfx_gemodule.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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/include/cfx_fontcache.h"
8
9 #include "core/fxge/include/fx_font.h"
10 #include "core/fxge/include/fx_freetype.h"
11
12 CFX_FontCache::CFX_FontCache() {}
13
14 CFX_FontCache::~CFX_FontCache() {
15 FreeCache(TRUE);
16 }
17
18 CFX_FaceCache* CFX_FontCache::GetCachedFace(CFX_Font* pFont) {
19 FXFT_Face face = pFont->GetFace();
20 const bool bExternal = !face;
21 CFX_FTCacheMap& map = bExternal ? m_ExtFaceMap : m_FTFaceMap;
22 auto it = map.find(face);
23 if (it != map.end()) {
24 CFX_CountedFaceCache* counted_face_cache = it->second;
25 counted_face_cache->m_nCount++;
26 return counted_face_cache->m_Obj;
27 }
28
29 CFX_FaceCache* face_cache = new CFX_FaceCache(bExternal ? nullptr : face);
30 CFX_CountedFaceCache* counted_face_cache = new CFX_CountedFaceCache;
31 counted_face_cache->m_nCount = 2;
32 counted_face_cache->m_Obj = face_cache;
33 map[face] = counted_face_cache;
34 return face_cache;
35 }
36
37 #ifdef _SKIA_SUPPORT_
38 CFX_TypeFace* CFX_FontCache::GetDeviceCache(CFX_Font* pFont) {
39 return GetCachedFace(pFont)->GetDeviceCache(pFont);
40 }
41 #endif
42
43 void CFX_FontCache::ReleaseCachedFace(CFX_Font* pFont) {
44 FXFT_Face face = pFont->GetFace();
45 const bool bExternal = !face;
46 CFX_FTCacheMap& map = bExternal ? m_ExtFaceMap : m_FTFaceMap;
47
48 auto it = map.find(face);
49 if (it == map.end())
50 return;
51
52 CFX_CountedFaceCache* counted_face_cache = it->second;
53 if (counted_face_cache->m_nCount > 1) {
54 counted_face_cache->m_nCount--;
55 }
56 }
57
58 void CFX_FontCache::FreeCache(FX_BOOL bRelease) {
59 for (auto it = m_FTFaceMap.begin(); it != m_FTFaceMap.end();) {
60 auto curr_it = it++;
61 CFX_CountedFaceCache* cache = curr_it->second;
62 if (bRelease || cache->m_nCount < 2) {
63 delete cache->m_Obj;
64 delete cache;
65 m_FTFaceMap.erase(curr_it);
66 }
67 }
68
69 for (auto it = m_ExtFaceMap.begin(); it != m_ExtFaceMap.end();) {
70 auto curr_it = it++;
71 CFX_CountedFaceCache* cache = curr_it->second;
72 if (bRelease || cache->m_nCount < 2) {
73 delete cache->m_Obj;
74 delete cache;
75 m_ExtFaceMap.erase(curr_it);
76 }
77 }
78 }
OLDNEW
« no previous file with comments | « core/fxge/ge/cfx_autofontcache.cpp ('k') | core/fxge/ge/cfx_gemodule.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698