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

Side by Side Diff: core/src/fxge/ge/fx_ge_fontmap.cpp

Issue 1412733011: Make CFX_FontMgr member variables private. (try 2) (Closed) Base URL: https://pdfium.googlesource.com/pdfium@master
Patch Set: no unique_ptr Created 5 years, 2 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
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 8
9 #include "../../../include/fxge/fx_ge.h" 9 #include "../../../include/fxge/fx_ge.h"
10 #include "../../../include/fxge/fx_freetype.h" 10 #include "../../../include/fxge/fx_freetype.h"
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
73 return FALSE; 73 return FALSE;
74 } 74 }
75 } 75 }
76 m_RefCount--; 76 m_RefCount--;
77 if (m_RefCount) { 77 if (m_RefCount) {
78 return FALSE; 78 return FALSE;
79 } 79 }
80 delete this; 80 delete this;
81 return TRUE; 81 return TRUE;
82 } 82 }
83
83 CFX_FontMgr::CFX_FontMgr() : m_FTLibrary(nullptr) { 84 CFX_FontMgr::CFX_FontMgr() : m_FTLibrary(nullptr) {
84 m_pBuiltinMapper = new CFX_FontMapper(this); 85 m_pBuiltinMapper = new CFX_FontMapper(this);
85 FXSYS_memset(m_ExternalFonts, 0, sizeof m_ExternalFonts);
86 } 86 }
87
87 CFX_FontMgr::~CFX_FontMgr() { 88 CFX_FontMgr::~CFX_FontMgr() {
88 delete m_pBuiltinMapper; 89 delete m_pBuiltinMapper;
Tom Sepez 2015/10/20 18:58:24 Do we want to do this after the FXFT_DoneFreetype?
Lei Zhang 2015/10/20 19:13:57 Ya, I was thinking about this on the commute. Mayb
89 FreeCache(); 90 for (const auto& pair : m_FaceMap)
90 if (m_FTLibrary) { 91 delete pair.second;
91 FXFT_Done_FreeType(m_FTLibrary); 92 FXFT_Done_FreeType(m_FTLibrary);
Lei Zhang 2015/10/20 18:13:31 FT_Done_FreeType() checks its input already.
92 }
93 } 93 }
94
94 void CFX_FontMgr::InitFTLibrary() { 95 void CFX_FontMgr::InitFTLibrary() {
95 if (m_FTLibrary == NULL) { 96 if (m_FTLibrary)
96 FXFT_Init_FreeType(&m_FTLibrary); 97 return;
97 } 98 FXFT_Init_FreeType(&m_FTLibrary);
98 } 99 }
99 void CFX_FontMgr::FreeCache() { 100
100 for (const auto& pair : m_FaceMap) {
101 delete pair.second;
102 }
103 m_FaceMap.clear();
104 }
105 void CFX_FontMgr::SetSystemFontInfo(IFX_SystemFontInfo* pFontInfo) { 101 void CFX_FontMgr::SetSystemFontInfo(IFX_SystemFontInfo* pFontInfo) {
106 m_pBuiltinMapper->SetSystemFontInfo(pFontInfo); 102 m_pBuiltinMapper->SetSystemFontInfo(pFontInfo);
107 } 103 }
104
108 FXFT_Face CFX_FontMgr::FindSubstFont(const CFX_ByteString& face_name, 105 FXFT_Face CFX_FontMgr::FindSubstFont(const CFX_ByteString& face_name,
109 FX_BOOL bTrueType, 106 FX_BOOL bTrueType,
110 FX_DWORD flags, 107 FX_DWORD flags,
111 int weight, 108 int weight,
112 int italic_angle, 109 int italic_angle,
113 int CharsetCP, 110 int CharsetCP,
114 CFX_SubstFont* pSubstFont) { 111 CFX_SubstFont* pSubstFont) {
115 if (!m_FTLibrary) { 112 InitFTLibrary();
116 FXFT_Init_FreeType(&m_FTLibrary);
117 }
118 return m_pBuiltinMapper->FindSubstFont(face_name, bTrueType, flags, weight, 113 return m_pBuiltinMapper->FindSubstFont(face_name, bTrueType, flags, weight,
119 italic_angle, CharsetCP, pSubstFont); 114 italic_angle, CharsetCP, pSubstFont);
120 } 115 }
116
121 FXFT_Face CFX_FontMgr::GetCachedFace(const CFX_ByteString& face_name, 117 FXFT_Face CFX_FontMgr::GetCachedFace(const CFX_ByteString& face_name,
122 int weight, 118 int weight,
123 FX_BOOL bItalic, 119 FX_BOOL bItalic,
124 uint8_t*& pFontData) { 120 uint8_t*& pFontData) {
125 auto it = m_FaceMap.find(KeyNameFromFace(face_name, weight, bItalic)); 121 auto it = m_FaceMap.find(KeyNameFromFace(face_name, weight, bItalic));
126 if (it == m_FaceMap.end()) 122 if (it == m_FaceMap.end())
127 return nullptr; 123 return nullptr;
128 124
129 CTTFontDesc* pFontDesc = it->second; 125 CTTFontDesc* pFontDesc = it->second;
130 pFontData = pFontDesc->m_pFontData; 126 pFontData = pFontDesc->m_pFontData;
131 pFontDesc->m_RefCount++; 127 pFontDesc->m_RefCount++;
132 return pFontDesc->m_SingleFace.m_pFace; 128 return pFontDesc->m_SingleFace.m_pFace;
133 } 129 }
134 FXFT_Face CFX_FontMgr::AddCachedFace(const CFX_ByteString& face_name, 130 FXFT_Face CFX_FontMgr::AddCachedFace(const CFX_ByteString& face_name,
135 int weight, 131 int weight,
136 FX_BOOL bItalic, 132 FX_BOOL bItalic,
137 uint8_t* pData, 133 uint8_t* pData,
138 FX_DWORD size, 134 FX_DWORD size,
139 int face_index) { 135 int face_index) {
140 CTTFontDesc* pFontDesc = new CTTFontDesc; 136 CTTFontDesc* pFontDesc = new CTTFontDesc;
141 pFontDesc->m_Type = 1; 137 pFontDesc->m_Type = 1;
142 pFontDesc->m_SingleFace.m_pFace = NULL; 138 pFontDesc->m_SingleFace.m_pFace = NULL;
143 pFontDesc->m_SingleFace.m_bBold = weight; 139 pFontDesc->m_SingleFace.m_bBold = weight;
144 pFontDesc->m_SingleFace.m_bItalic = bItalic; 140 pFontDesc->m_SingleFace.m_bItalic = bItalic;
145 pFontDesc->m_pFontData = pData; 141 pFontDesc->m_pFontData = pData;
146 pFontDesc->m_RefCount = 1; 142 pFontDesc->m_RefCount = 1;
147 FXFT_Library library; 143
148 if (m_FTLibrary == NULL) { 144 InitFTLibrary();
149 FXFT_Init_FreeType(&m_FTLibrary); 145 FXFT_Library library = m_FTLibrary;
150 }
151 library = m_FTLibrary;
152 int ret = FXFT_New_Memory_Face(library, pData, size, face_index, 146 int ret = FXFT_New_Memory_Face(library, pData, size, face_index,
153 &pFontDesc->m_SingleFace.m_pFace); 147 &pFontDesc->m_SingleFace.m_pFace);
154 if (ret) { 148 if (ret) {
155 delete pFontDesc; 149 delete pFontDesc;
156 return NULL; 150 return NULL;
157 } 151 }
158 ret = FXFT_Set_Pixel_Sizes(pFontDesc->m_SingleFace.m_pFace, 64, 64); 152 ret = FXFT_Set_Pixel_Sizes(pFontDesc->m_SingleFace.m_pFace, 64, 64);
159 if (ret) { 153 if (ret) {
160 delete pFontDesc; 154 delete pFontDesc;
161 return NULL; 155 return NULL;
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 for (int i = 0; i < 16; i++) { 322 for (int i = 0; i < 16; i++) {
329 pFontDesc->m_TTCFace.m_pFaces[i] = NULL; 323 pFontDesc->m_TTCFace.m_pFaces[i] = NULL;
330 } 324 }
331 pFontDesc->m_RefCount++; 325 pFontDesc->m_RefCount++;
332 m_FaceMap[KeyNameFromSize(ttc_size, checksum)] = pFontDesc; 326 m_FaceMap[KeyNameFromSize(ttc_size, checksum)] = pFontDesc;
333 int face_index = GetTTCIndex(pFontDesc->m_pFontData, ttc_size, font_offset); 327 int face_index = GetTTCIndex(pFontDesc->m_pFontData, ttc_size, font_offset);
334 pFontDesc->m_TTCFace.m_pFaces[face_index] = 328 pFontDesc->m_TTCFace.m_pFaces[face_index] =
335 GetFixedFace(pFontDesc->m_pFontData, ttc_size, face_index); 329 GetFixedFace(pFontDesc->m_pFontData, ttc_size, face_index);
336 return pFontDesc->m_TTCFace.m_pFaces[face_index]; 330 return pFontDesc->m_TTCFace.m_pFaces[face_index];
337 } 331 }
332
338 FXFT_Face CFX_FontMgr::GetFixedFace(const uint8_t* pData, 333 FXFT_Face CFX_FontMgr::GetFixedFace(const uint8_t* pData,
339 FX_DWORD size, 334 FX_DWORD size,
340 int face_index) { 335 int face_index) {
341 FXFT_Library library; 336 InitFTLibrary();
342 if (m_FTLibrary == NULL) { 337 FXFT_Library library = m_FTLibrary;
343 FXFT_Init_FreeType(&m_FTLibrary); 338 FXFT_Face face = nullptr;
344 } 339 if (FXFT_New_Memory_Face(library, pData, size, face_index, &face))
345 library = m_FTLibrary; 340 return nullptr;
346 FXFT_Face face = NULL; 341 return FXFT_Set_Pixel_Sizes(face, 64, 64) ? nullptr : face;
347 int ret = FXFT_New_Memory_Face(library, pData, size, face_index, &face);
348 if (ret) {
349 return NULL;
350 }
351 ret = FXFT_Set_Pixel_Sizes(face, 64, 64);
352 if (ret) {
353 return NULL;
354 }
355 return face;
356 } 342 }
343
357 FXFT_Face CFX_FontMgr::GetFileFace(const FX_CHAR* filename, int face_index) { 344 FXFT_Face CFX_FontMgr::GetFileFace(const FX_CHAR* filename, int face_index) {
358 FXFT_Library library; 345 InitFTLibrary();
359 if (m_FTLibrary == NULL) { 346 FXFT_Library library = m_FTLibrary;
360 FXFT_Init_FreeType(&m_FTLibrary); 347 FXFT_Face face = nullptr;
361 } 348 if (FXFT_New_Face(library, filename, face_index, &face))
362 library = m_FTLibrary; 349 return nullptr;
363 FXFT_Face face = NULL; 350 return FXFT_Set_Pixel_Sizes(face, 64, 64) ? nullptr : face;
364 int ret = FXFT_New_Face(library, filename, face_index, &face);
365 if (ret) {
366 return NULL;
367 }
368 ret = FXFT_Set_Pixel_Sizes(face, 64, 64);
369 if (ret) {
370 return NULL;
371 }
372 return face;
373 } 351 }
352
374 void CFX_FontMgr::ReleaseFace(FXFT_Face face) { 353 void CFX_FontMgr::ReleaseFace(FXFT_Face face) {
375 if (!face) { 354 if (!face) {
376 return; 355 return;
377 } 356 }
378 auto it = m_FaceMap.begin(); 357 auto it = m_FaceMap.begin();
379 while (it != m_FaceMap.end()) { 358 while (it != m_FaceMap.end()) {
380 auto temp = it++; 359 auto temp = it++;
381 if (temp->second->ReleaseFace(face)) { 360 if (temp->second->ReleaseFace(face)) {
382 m_FaceMap.erase(temp); 361 m_FaceMap.erase(temp);
383 } 362 }
(...skipping 667 matching lines...) Expand 10 before | Expand all | Expand 10 after
1051 if ((nStyle & 0x3) == 1) { 1030 if ((nStyle & 0x3) == 1) {
1052 iBaseFont += 1; 1031 iBaseFont += 1;
1053 } 1032 }
1054 if ((nStyle & 0x3) == 2) { 1033 if ((nStyle & 0x3) == 2) {
1055 iBaseFont += 3; 1034 iBaseFont += 3;
1056 } 1035 }
1057 if ((nStyle & 0x3) == 3) { 1036 if ((nStyle & 0x3) == 3) {
1058 iBaseFont += 2; 1037 iBaseFont += 2;
1059 } 1038 }
1060 } 1039 }
1061 if (m_pFontMgr->m_ExternalFonts[iBaseFont].m_pFontData) { 1040 family = g_Base14FontNames[iBaseFont];
1062 if (m_FoxitFaces[iBaseFont]) {
1063 return m_FoxitFaces[iBaseFont];
1064 }
1065 m_FoxitFaces[iBaseFont] = m_pFontMgr->GetFixedFace(
1066 m_pFontMgr->m_ExternalFonts[iBaseFont].m_pFontData,
1067 m_pFontMgr->m_ExternalFonts[iBaseFont].m_dwSize, 0);
1068 if (m_FoxitFaces[iBaseFont]) {
1069 return m_FoxitFaces[iBaseFont];
1070 }
1071 } else {
1072 family = g_Base14FontNames[iBaseFont];
1073 }
1074 pSubstFont->m_SubstFlags |= FXFONT_SUBST_STANDARD; 1041 pSubstFont->m_SubstFlags |= FXFONT_SUBST_STANDARD;
1075 } 1042 }
1076 } else { 1043 } else {
1077 if (flags & FXFONT_ITALIC) { 1044 if (flags & FXFONT_ITALIC) {
1078 bItalic = TRUE; 1045 bItalic = TRUE;
1079 } 1046 }
1080 } 1047 }
1081 iExact = !match.IsEmpty(); 1048 iExact = !match.IsEmpty();
1082 void* hFont = m_pFontInfo->MapFont(weight, bItalic, Charset, PitchFamily, 1049 void* hFont = m_pFontInfo->MapFont(weight, bItalic, Charset, PitchFamily,
1083 family, iExact); 1050 family, iExact);
(...skipping 480 matching lines...) Expand 10 before | Expand all | Expand 10 after
1564 int PDF_GetStandardFontName(CFX_ByteString* name) { 1531 int PDF_GetStandardFontName(CFX_ByteString* name) {
1565 AltFontName* found = static_cast<AltFontName*>( 1532 AltFontName* found = static_cast<AltFontName*>(
1566 FXSYS_bsearch(name->c_str(), g_AltFontNames, FX_ArraySize(g_AltFontNames), 1533 FXSYS_bsearch(name->c_str(), g_AltFontNames, FX_ArraySize(g_AltFontNames),
1567 sizeof(AltFontName), compareString)); 1534 sizeof(AltFontName), compareString));
1568 if (!found) 1535 if (!found)
1569 return -1; 1536 return -1;
1570 1537
1571 *name = g_Base14FontNames[found->m_Index]; 1538 *name = g_Base14FontNames[found->m_Index];
1572 return found->m_Index; 1539 return found->m_Index;
1573 } 1540 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698