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

Side by Side Diff: core/fxge/ge/fx_ge_text.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_renderdevice.cpp ('k') | core/fxge/ifx_renderdevicedriver.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <limits> 7 #include <limits>
8 #include <vector> 8 #include <vector>
9 9
10 #include "core/fxcodec/include/fx_codec.h" 10 #include "core/fxcodec/include/fx_codec.h"
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
99 99
100 rect.left = char_left.ValueOrDie(); 100 rect.left = char_left.ValueOrDie();
101 rect.right = char_right.ValueOrDie(); 101 rect.right = char_right.ValueOrDie();
102 rect.top = char_top.ValueOrDie(); 102 rect.top = char_top.ValueOrDie();
103 rect.bottom = char_bottom.ValueOrDie(); 103 rect.bottom = char_bottom.ValueOrDie();
104 bStarted = true; 104 bStarted = true;
105 } 105 }
106 return rect; 106 return rect;
107 } 107 }
108 108
109 CFX_FontCache::CFX_FontCache() {}
110
111 CFX_FontCache::~CFX_FontCache() {
112 FreeCache(TRUE);
113 }
114
115 CFX_FaceCache* CFX_FontCache::GetCachedFace(CFX_Font* pFont) {
116 FXFT_Face face = pFont->GetFace();
117 const bool bExternal = !face;
118 CFX_FTCacheMap& map = bExternal ? m_ExtFaceMap : m_FTFaceMap;
119 auto it = map.find(face);
120 if (it != map.end()) {
121 CFX_CountedFaceCache* counted_face_cache = it->second;
122 counted_face_cache->m_nCount++;
123 return counted_face_cache->m_Obj;
124 }
125
126 CFX_FaceCache* face_cache = new CFX_FaceCache(bExternal ? nullptr : face);
127 CFX_CountedFaceCache* counted_face_cache = new CFX_CountedFaceCache;
128 counted_face_cache->m_nCount = 2;
129 counted_face_cache->m_Obj = face_cache;
130 map[face] = counted_face_cache;
131 return face_cache;
132 }
133
134 #ifdef _SKIA_SUPPORT_ 109 #ifdef _SKIA_SUPPORT_
135 CFX_TypeFace* CFX_FontCache::GetDeviceCache(CFX_Font* pFont) {
136 return GetCachedFace(pFont)->GetDeviceCache(pFont);
137 }
138
139 CFX_TypeFace* CFX_FaceCache::GetDeviceCache(CFX_Font* pFont) { 110 CFX_TypeFace* CFX_FaceCache::GetDeviceCache(CFX_Font* pFont) {
140 if (!m_pTypeface) { 111 if (!m_pTypeface) {
141 m_pTypeface = 112 m_pTypeface =
142 SkTypeface::MakeFromStream( 113 SkTypeface::MakeFromStream(
143 new SkMemoryStream(pFont->GetFontData(), pFont->GetSize())) 114 new SkMemoryStream(pFont->GetFontData(), pFont->GetSize()))
144 .release(); 115 .release();
145 } 116 }
146 return m_pTypeface; 117 return m_pTypeface;
147 } 118 }
148 #endif 119 #endif
149 120
150 void CFX_FontCache::ReleaseCachedFace(CFX_Font* pFont) {
151 FXFT_Face face = pFont->GetFace();
152 const bool bExternal = !face;
153 CFX_FTCacheMap& map = bExternal ? m_ExtFaceMap : m_FTFaceMap;
154
155 auto it = map.find(face);
156 if (it == map.end())
157 return;
158
159 CFX_CountedFaceCache* counted_face_cache = it->second;
160 if (counted_face_cache->m_nCount > 1) {
161 counted_face_cache->m_nCount--;
162 }
163 }
164
165 void CFX_FontCache::FreeCache(FX_BOOL bRelease) {
166 for (auto it = m_FTFaceMap.begin(); it != m_FTFaceMap.end();) {
167 auto curr_it = it++;
168 CFX_CountedFaceCache* cache = curr_it->second;
169 if (bRelease || cache->m_nCount < 2) {
170 delete cache->m_Obj;
171 delete cache;
172 m_FTFaceMap.erase(curr_it);
173 }
174 }
175
176 for (auto it = m_ExtFaceMap.begin(); it != m_ExtFaceMap.end();) {
177 auto curr_it = it++;
178 CFX_CountedFaceCache* cache = curr_it->second;
179 if (bRelease || cache->m_nCount < 2) {
180 delete cache->m_Obj;
181 delete cache;
182 m_ExtFaceMap.erase(curr_it);
183 }
184 }
185 }
186
187 CFX_FaceCache::CFX_FaceCache(FXFT_Face face) 121 CFX_FaceCache::CFX_FaceCache(FXFT_Face face)
188 : m_Face(face) 122 : m_Face(face)
189 #ifdef _SKIA_SUPPORT_ 123 #ifdef _SKIA_SUPPORT_
190 , 124 ,
191 m_pTypeface(nullptr) 125 m_pTypeface(nullptr)
192 #endif 126 #endif
193 { 127 {
194 } 128 }
195 129
196 CFX_FaceCache::~CFX_FaceCache() { 130 CFX_FaceCache::~CFX_FaceCache() {
(...skipping 639 matching lines...) Expand 10 before | Expand all | Expand 10 after
836 void _CFX_UniqueKeyGen::Generate(int count, ...) { 770 void _CFX_UniqueKeyGen::Generate(int count, ...) {
837 va_list argList; 771 va_list argList;
838 va_start(argList, count); 772 va_start(argList, count);
839 for (int i = 0; i < count; i++) { 773 for (int i = 0; i < count; i++) {
840 int p = va_arg(argList, int); 774 int p = va_arg(argList, int);
841 ((uint32_t*)m_Key)[i] = p; 775 ((uint32_t*)m_Key)[i] = p;
842 } 776 }
843 va_end(argList); 777 va_end(argList);
844 m_KeyLen = count * sizeof(uint32_t); 778 m_KeyLen = count * sizeof(uint32_t);
845 } 779 }
OLDNEW
« no previous file with comments | « core/fxge/ge/cfx_renderdevice.cpp ('k') | core/fxge/ifx_renderdevicedriver.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698