OLD | NEW |
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 "core/fxge/ge/fx_text_int.h" | 7 #include "core/fxge/ge/fx_text_int.h" |
8 #include "core/include/fxcodec/fx_codec.h" | 8 #include "core/include/fxcodec/fx_codec.h" |
9 #include "core/include/fxge/fx_freetype.h" | 9 #include "core/include/fxge/fx_freetype.h" |
10 #include "core/include/fxge/fx_ge.h" | 10 #include "core/include/fxge/fx_ge.h" |
11 | 11 |
| 12 #ifdef _SKIA_SUPPORT_ |
| 13 #include "third_party/skia/include/core/SkStream.h" |
| 14 #include "third_party/skia/include/core/SkTypeface.h" |
| 15 #endif |
| 16 |
12 #undef FX_GAMMA | 17 #undef FX_GAMMA |
13 #undef FX_GAMMA_INVERSE | 18 #undef FX_GAMMA_INVERSE |
14 #define FX_GAMMA(value) (value) | 19 #define FX_GAMMA(value) (value) |
15 #define FX_GAMMA_INVERSE(value) (value) | 20 #define FX_GAMMA_INVERSE(value) (value) |
16 | 21 |
17 namespace { | 22 namespace { |
18 | 23 |
19 void ResetTransform(FT_Face face) { | 24 void ResetTransform(FT_Face face) { |
20 FXFT_Matrix matrix; | 25 FXFT_Matrix matrix; |
21 matrix.xx = 0x10000L; | 26 matrix.xx = 0x10000L; |
(...skipping 1169 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1191 } | 1196 } |
1192 | 1197 |
1193 CFX_FaceCache* face_cache = new CFX_FaceCache(bExternal ? nullptr : face); | 1198 CFX_FaceCache* face_cache = new CFX_FaceCache(bExternal ? nullptr : face); |
1194 CFX_CountedFaceCache* counted_face_cache = new CFX_CountedFaceCache; | 1199 CFX_CountedFaceCache* counted_face_cache = new CFX_CountedFaceCache; |
1195 counted_face_cache->m_nCount = 2; | 1200 counted_face_cache->m_nCount = 2; |
1196 counted_face_cache->m_Obj = face_cache; | 1201 counted_face_cache->m_Obj = face_cache; |
1197 map[face] = counted_face_cache; | 1202 map[face] = counted_face_cache; |
1198 return face_cache; | 1203 return face_cache; |
1199 } | 1204 } |
1200 | 1205 |
| 1206 #ifdef _SKIA_SUPPORT_ |
| 1207 CFX_TypeFace* CFX_FontCache::GetDeviceCache(CFX_Font* pFont) { |
| 1208 return GetCachedFace(pFont)->GetDeviceCache(pFont); |
| 1209 } |
| 1210 |
| 1211 CFX_TypeFace* CFX_FaceCache::GetDeviceCache(CFX_Font* pFont) { |
| 1212 if (!m_pTypeface) { |
| 1213 m_pTypeface = SkTypeface::CreateFromStream( |
| 1214 new SkMemoryStream(pFont->GetFontData(), pFont->GetSize())); |
| 1215 } |
| 1216 return m_pTypeface; |
| 1217 } |
| 1218 #endif |
| 1219 |
1201 void CFX_FontCache::ReleaseCachedFace(CFX_Font* pFont) { | 1220 void CFX_FontCache::ReleaseCachedFace(CFX_Font* pFont) { |
1202 FXFT_Face internal_face = pFont->GetFace(); | 1221 FXFT_Face internal_face = pFont->GetFace(); |
1203 const bool bExternal = !internal_face; | 1222 const bool bExternal = !internal_face; |
1204 FXFT_Face face = | 1223 FXFT_Face face = |
1205 bExternal ? (FXFT_Face)pFont->GetSubstFont()->m_ExtHandle : internal_face; | 1224 bExternal ? (FXFT_Face)pFont->GetSubstFont()->m_ExtHandle : internal_face; |
1206 CFX_FTCacheMap& map = bExternal ? m_ExtFaceMap : m_FTFaceMap; | 1225 CFX_FTCacheMap& map = bExternal ? m_ExtFaceMap : m_FTFaceMap; |
1207 | 1226 |
1208 auto it = map.find(face); | 1227 auto it = map.find(face); |
1209 if (it == map.end()) | 1228 if (it == map.end()) |
1210 return; | 1229 return; |
(...skipping 19 matching lines...) Expand all Loading... |
1230 auto curr_it = it++; | 1249 auto curr_it = it++; |
1231 CFX_CountedFaceCache* cache = curr_it->second; | 1250 CFX_CountedFaceCache* cache = curr_it->second; |
1232 if (bRelease || cache->m_nCount < 2) { | 1251 if (bRelease || cache->m_nCount < 2) { |
1233 delete cache->m_Obj; | 1252 delete cache->m_Obj; |
1234 delete cache; | 1253 delete cache; |
1235 m_ExtFaceMap.erase(curr_it); | 1254 m_ExtFaceMap.erase(curr_it); |
1236 } | 1255 } |
1237 } | 1256 } |
1238 } | 1257 } |
1239 | 1258 |
1240 CFX_FaceCache::CFX_FaceCache(FXFT_Face face) : m_Face(face) {} | 1259 CFX_FaceCache::CFX_FaceCache(FXFT_Face face) |
| 1260 : m_Face(face) |
| 1261 #ifdef _SKIA_SUPPORT_ |
| 1262 , |
| 1263 m_pTypeface(nullptr) |
| 1264 #endif |
| 1265 { |
| 1266 } |
1241 | 1267 |
1242 CFX_FaceCache::~CFX_FaceCache() { | 1268 CFX_FaceCache::~CFX_FaceCache() { |
1243 for (const auto& pair : m_SizeMap) { | 1269 for (const auto& pair : m_SizeMap) { |
1244 delete pair.second; | 1270 delete pair.second; |
1245 } | 1271 } |
1246 m_SizeMap.clear(); | 1272 m_SizeMap.clear(); |
1247 for (const auto& pair : m_PathMap) { | 1273 for (const auto& pair : m_PathMap) { |
1248 delete pair.second; | 1274 delete pair.second; |
1249 } | 1275 } |
1250 m_PathMap.clear(); | 1276 m_PathMap.clear(); |
| 1277 #ifdef _SKIA_SUPPORT_ |
| 1278 SkSafeUnref(m_pTypeface); |
| 1279 #endif |
1251 } | 1280 } |
| 1281 |
1252 #if _FXM_PLATFORM_ != _FXM_PLATFORM_APPLE_ | 1282 #if _FXM_PLATFORM_ != _FXM_PLATFORM_APPLE_ |
1253 void CFX_FaceCache::InitPlatform() {} | 1283 void CFX_FaceCache::InitPlatform() {} |
1254 #endif | 1284 #endif |
1255 CFX_GlyphBitmap* CFX_FaceCache::LookUpGlyphBitmap( | 1285 CFX_GlyphBitmap* CFX_FaceCache::LookUpGlyphBitmap( |
1256 CFX_Font* pFont, | 1286 CFX_Font* pFont, |
1257 const CFX_Matrix* pMatrix, | 1287 const CFX_Matrix* pMatrix, |
1258 CFX_ByteStringC& FaceGlyphsKey, | 1288 CFX_ByteStringC& FaceGlyphsKey, |
1259 uint32_t glyph_index, | 1289 uint32_t glyph_index, |
1260 FX_BOOL bFontStyle, | 1290 FX_BOOL bFontStyle, |
1261 int dest_width, | 1291 int dest_width, |
(...skipping 604 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1866 void _CFX_UniqueKeyGen::Generate(int count, ...) { | 1896 void _CFX_UniqueKeyGen::Generate(int count, ...) { |
1867 va_list argList; | 1897 va_list argList; |
1868 va_start(argList, count); | 1898 va_start(argList, count); |
1869 for (int i = 0; i < count; i++) { | 1899 for (int i = 0; i < count; i++) { |
1870 int p = va_arg(argList, int); | 1900 int p = va_arg(argList, int); |
1871 ((uint32_t*)m_Key)[i] = p; | 1901 ((uint32_t*)m_Key)[i] = p; |
1872 } | 1902 } |
1873 va_end(argList); | 1903 va_end(argList); |
1874 m_KeyLen = count * sizeof(uint32_t); | 1904 m_KeyLen = count * sizeof(uint32_t); |
1875 } | 1905 } |
OLD | NEW |