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

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: delete in the right order, rebase 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
« no previous file with comments | « core/src/fxge/ge/fx_ge_font.cpp ('k') | core/src/fxge/ge/fx_ge_text.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 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.reset(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 for (const auto& pair : m_FaceMap)
89 FreeCache(); 90 delete pair.second;
90 if (m_FTLibrary) { 91
91 FXFT_Done_FreeType(m_FTLibrary); 92 // |m_pBuiltinMapper| references |m_FTLibrary|, so it has to be destroyed
92 } 93 // first.
94 m_pBuiltinMapper.reset();
95 FXFT_Done_FreeType(m_FTLibrary);
93 } 96 }
97
94 void CFX_FontMgr::InitFTLibrary() { 98 void CFX_FontMgr::InitFTLibrary() {
95 if (m_FTLibrary == NULL) { 99 if (m_FTLibrary)
96 FXFT_Init_FreeType(&m_FTLibrary); 100 return;
97 } 101 FXFT_Init_FreeType(&m_FTLibrary);
98 } 102 }
99 void CFX_FontMgr::FreeCache() { 103
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) { 104 void CFX_FontMgr::SetSystemFontInfo(IFX_SystemFontInfo* pFontInfo) {
106 m_pBuiltinMapper->SetSystemFontInfo(pFontInfo); 105 m_pBuiltinMapper->SetSystemFontInfo(pFontInfo);
107 } 106 }
107
108 FXFT_Face CFX_FontMgr::FindSubstFont(const CFX_ByteString& face_name, 108 FXFT_Face CFX_FontMgr::FindSubstFont(const CFX_ByteString& face_name,
109 FX_BOOL bTrueType, 109 FX_BOOL bTrueType,
110 FX_DWORD flags, 110 FX_DWORD flags,
111 int weight, 111 int weight,
112 int italic_angle, 112 int italic_angle,
113 int CharsetCP, 113 int CharsetCP,
114 CFX_SubstFont* pSubstFont) { 114 CFX_SubstFont* pSubstFont) {
115 if (!m_FTLibrary) { 115 InitFTLibrary();
116 FXFT_Init_FreeType(&m_FTLibrary);
117 }
118 return m_pBuiltinMapper->FindSubstFont(face_name, bTrueType, flags, weight, 116 return m_pBuiltinMapper->FindSubstFont(face_name, bTrueType, flags, weight,
119 italic_angle, CharsetCP, pSubstFont); 117 italic_angle, CharsetCP, pSubstFont);
120 } 118 }
119
121 FXFT_Face CFX_FontMgr::GetCachedFace(const CFX_ByteString& face_name, 120 FXFT_Face CFX_FontMgr::GetCachedFace(const CFX_ByteString& face_name,
122 int weight, 121 int weight,
123 FX_BOOL bItalic, 122 FX_BOOL bItalic,
124 uint8_t*& pFontData) { 123 uint8_t*& pFontData) {
125 auto it = m_FaceMap.find(KeyNameFromFace(face_name, weight, bItalic)); 124 auto it = m_FaceMap.find(KeyNameFromFace(face_name, weight, bItalic));
126 if (it == m_FaceMap.end()) 125 if (it == m_FaceMap.end())
127 return nullptr; 126 return nullptr;
128 127
129 CTTFontDesc* pFontDesc = it->second; 128 CTTFontDesc* pFontDesc = it->second;
130 pFontData = pFontDesc->m_pFontData; 129 pFontData = pFontDesc->m_pFontData;
131 pFontDesc->m_RefCount++; 130 pFontDesc->m_RefCount++;
132 return pFontDesc->m_SingleFace.m_pFace; 131 return pFontDesc->m_SingleFace.m_pFace;
133 } 132 }
134 FXFT_Face CFX_FontMgr::AddCachedFace(const CFX_ByteString& face_name, 133 FXFT_Face CFX_FontMgr::AddCachedFace(const CFX_ByteString& face_name,
135 int weight, 134 int weight,
136 FX_BOOL bItalic, 135 FX_BOOL bItalic,
137 uint8_t* pData, 136 uint8_t* pData,
138 FX_DWORD size, 137 FX_DWORD size,
139 int face_index) { 138 int face_index) {
140 CTTFontDesc* pFontDesc = new CTTFontDesc; 139 CTTFontDesc* pFontDesc = new CTTFontDesc;
141 pFontDesc->m_Type = 1; 140 pFontDesc->m_Type = 1;
142 pFontDesc->m_SingleFace.m_pFace = NULL; 141 pFontDesc->m_SingleFace.m_pFace = NULL;
143 pFontDesc->m_SingleFace.m_bBold = weight; 142 pFontDesc->m_SingleFace.m_bBold = weight;
144 pFontDesc->m_SingleFace.m_bItalic = bItalic; 143 pFontDesc->m_SingleFace.m_bItalic = bItalic;
145 pFontDesc->m_pFontData = pData; 144 pFontDesc->m_pFontData = pData;
146 pFontDesc->m_RefCount = 1; 145 pFontDesc->m_RefCount = 1;
147 FXFT_Library library; 146
148 if (m_FTLibrary == NULL) { 147 InitFTLibrary();
149 FXFT_Init_FreeType(&m_FTLibrary); 148 FXFT_Library library = m_FTLibrary;
150 }
151 library = m_FTLibrary;
152 int ret = FXFT_New_Memory_Face(library, pData, size, face_index, 149 int ret = FXFT_New_Memory_Face(library, pData, size, face_index,
153 &pFontDesc->m_SingleFace.m_pFace); 150 &pFontDesc->m_SingleFace.m_pFace);
154 if (ret) { 151 if (ret) {
155 delete pFontDesc; 152 delete pFontDesc;
156 return NULL; 153 return NULL;
157 } 154 }
158 ret = FXFT_Set_Pixel_Sizes(pFontDesc->m_SingleFace.m_pFace, 64, 64); 155 ret = FXFT_Set_Pixel_Sizes(pFontDesc->m_SingleFace.m_pFace, 64, 64);
159 if (ret) { 156 if (ret) {
160 delete pFontDesc; 157 delete pFontDesc;
161 return NULL; 158 return NULL;
(...skipping 166 matching lines...) Expand 10 before | Expand all | Expand 10 after
328 for (int i = 0; i < 16; i++) { 325 for (int i = 0; i < 16; i++) {
329 pFontDesc->m_TTCFace.m_pFaces[i] = NULL; 326 pFontDesc->m_TTCFace.m_pFaces[i] = NULL;
330 } 327 }
331 pFontDesc->m_RefCount++; 328 pFontDesc->m_RefCount++;
332 m_FaceMap[KeyNameFromSize(ttc_size, checksum)] = pFontDesc; 329 m_FaceMap[KeyNameFromSize(ttc_size, checksum)] = pFontDesc;
333 int face_index = GetTTCIndex(pFontDesc->m_pFontData, ttc_size, font_offset); 330 int face_index = GetTTCIndex(pFontDesc->m_pFontData, ttc_size, font_offset);
334 pFontDesc->m_TTCFace.m_pFaces[face_index] = 331 pFontDesc->m_TTCFace.m_pFaces[face_index] =
335 GetFixedFace(pFontDesc->m_pFontData, ttc_size, face_index); 332 GetFixedFace(pFontDesc->m_pFontData, ttc_size, face_index);
336 return pFontDesc->m_TTCFace.m_pFaces[face_index]; 333 return pFontDesc->m_TTCFace.m_pFaces[face_index];
337 } 334 }
335
338 FXFT_Face CFX_FontMgr::GetFixedFace(const uint8_t* pData, 336 FXFT_Face CFX_FontMgr::GetFixedFace(const uint8_t* pData,
339 FX_DWORD size, 337 FX_DWORD size,
340 int face_index) { 338 int face_index) {
341 FXFT_Library library; 339 InitFTLibrary();
342 if (m_FTLibrary == NULL) { 340 FXFT_Library library = m_FTLibrary;
343 FXFT_Init_FreeType(&m_FTLibrary); 341 FXFT_Face face = nullptr;
344 } 342 if (FXFT_New_Memory_Face(library, pData, size, face_index, &face))
345 library = m_FTLibrary; 343 return nullptr;
346 FXFT_Face face = NULL; 344 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 } 345 }
346
357 FXFT_Face CFX_FontMgr::GetFileFace(const FX_CHAR* filename, int face_index) { 347 FXFT_Face CFX_FontMgr::GetFileFace(const FX_CHAR* filename, int face_index) {
358 FXFT_Library library; 348 InitFTLibrary();
359 if (m_FTLibrary == NULL) { 349 FXFT_Library library = m_FTLibrary;
360 FXFT_Init_FreeType(&m_FTLibrary); 350 FXFT_Face face = nullptr;
361 } 351 if (FXFT_New_Face(library, filename, face_index, &face))
362 library = m_FTLibrary; 352 return nullptr;
363 FXFT_Face face = NULL; 353 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 } 354 }
355
374 void CFX_FontMgr::ReleaseFace(FXFT_Face face) { 356 void CFX_FontMgr::ReleaseFace(FXFT_Face face) {
375 if (!face) { 357 if (!face) {
376 return; 358 return;
377 } 359 }
378 auto it = m_FaceMap.begin(); 360 auto it = m_FaceMap.begin();
379 while (it != m_FaceMap.end()) { 361 while (it != m_FaceMap.end()) {
380 auto temp = it++; 362 auto temp = it++;
381 if (temp->second->ReleaseFace(face)) { 363 if (temp->second->ReleaseFace(face)) {
382 m_FaceMap.erase(temp); 364 m_FaceMap.erase(temp);
383 } 365 }
(...skipping 667 matching lines...) Expand 10 before | Expand all | Expand 10 after
1051 if ((nStyle & 0x3) == 1) { 1033 if ((nStyle & 0x3) == 1) {
1052 iBaseFont += 1; 1034 iBaseFont += 1;
1053 } 1035 }
1054 if ((nStyle & 0x3) == 2) { 1036 if ((nStyle & 0x3) == 2) {
1055 iBaseFont += 3; 1037 iBaseFont += 3;
1056 } 1038 }
1057 if ((nStyle & 0x3) == 3) { 1039 if ((nStyle & 0x3) == 3) {
1058 iBaseFont += 2; 1040 iBaseFont += 2;
1059 } 1041 }
1060 } 1042 }
1061 if (m_pFontMgr->m_ExternalFonts[iBaseFont].m_pFontData) { 1043 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; 1044 pSubstFont->m_SubstFlags |= FXFONT_SUBST_STANDARD;
1075 } 1045 }
1076 } else { 1046 } else {
1077 if (flags & FXFONT_ITALIC) { 1047 if (flags & FXFONT_ITALIC) {
1078 bItalic = TRUE; 1048 bItalic = TRUE;
1079 } 1049 }
1080 } 1050 }
1081 iExact = !match.IsEmpty(); 1051 iExact = !match.IsEmpty();
1082 void* hFont = m_pFontInfo->MapFont(weight, bItalic, Charset, PitchFamily, 1052 void* hFont = m_pFontInfo->MapFont(weight, bItalic, Charset, PitchFamily,
1083 family, iExact); 1053 family, iExact);
(...skipping 480 matching lines...) Expand 10 before | Expand all | Expand 10 after
1564 int PDF_GetStandardFontName(CFX_ByteString* name) { 1534 int PDF_GetStandardFontName(CFX_ByteString* name) {
1565 AltFontName* found = static_cast<AltFontName*>( 1535 AltFontName* found = static_cast<AltFontName*>(
1566 FXSYS_bsearch(name->c_str(), g_AltFontNames, FX_ArraySize(g_AltFontNames), 1536 FXSYS_bsearch(name->c_str(), g_AltFontNames, FX_ArraySize(g_AltFontNames),
1567 sizeof(AltFontName), compareString)); 1537 sizeof(AltFontName), compareString));
1568 if (!found) 1538 if (!found)
1569 return -1; 1539 return -1;
1570 1540
1571 *name = g_Base14FontNames[found->m_Index]; 1541 *name = g_Base14FontNames[found->m_Index];
1572 return found->m_Index; 1542 return found->m_Index;
1573 } 1543 }
OLDNEW
« no previous file with comments | « core/src/fxge/ge/fx_ge_font.cpp ('k') | core/src/fxge/ge/fx_ge_text.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698