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

Side by Side Diff: xfa/fgas/font/fgas_stdfontmgr.cpp

Issue 2037563002: Replace IFGAS_Font with underlying concrete type (Closed) Base URL: https://pdfium.googlesource.com/pdfium@master
Patch Set: Fix Windows Created 4 years, 6 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 "xfa/fgas/font/fgas_stdfontmgr.h" 7 #include "xfa/fgas/font/fgas_stdfontmgr.h"
8 8
9 #include "core/fxcrt/include/fx_stream.h" 9 #include "core/fxcrt/include/fx_stream.h"
10 #include "core/fxge/include/fx_ge.h" 10 #include "core/fxge/include/fx_ge.h"
11 #include "xfa/fgas/crt/fgas_codepage.h" 11 #include "xfa/fgas/crt/fgas_codepage.h"
12 #include "xfa/fgas/font/fgas_fontutils.h" 12 #include "xfa/fgas/font/fgas_fontutils.h"
13 #include "xfa/fgas/font/fgas_gefont.h"
13 14
14 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ 15 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_
15 IFX_FontMgr* IFX_FontMgr::Create(FX_LPEnumAllFonts pEnumerator) { 16 IFX_FontMgr* IFX_FontMgr::Create(FX_LPEnumAllFonts pEnumerator) {
16 return new CFX_StdFontMgrImp(pEnumerator); 17 return new CFX_StdFontMgrImp(pEnumerator);
17 } 18 }
18 CFX_StdFontMgrImp::CFX_StdFontMgrImp(FX_LPEnumAllFonts pEnumerator) 19 CFX_StdFontMgrImp::CFX_StdFontMgrImp(FX_LPEnumAllFonts pEnumerator)
19 : m_pEnumerator(pEnumerator), 20 : m_pEnumerator(pEnumerator),
20 m_FontFaces(), 21 m_FontFaces(),
21 m_CPFonts(8), 22 m_CPFonts(8),
22 m_FamilyFonts(16), 23 m_FamilyFonts(16),
(...skipping 13 matching lines...) Expand all
36 m_FamilyFonts.RemoveAll(); 37 m_FamilyFonts.RemoveAll();
37 m_UnicodeFonts.RemoveAll(); 38 m_UnicodeFonts.RemoveAll();
38 m_BufferFonts.RemoveAll(); 39 m_BufferFonts.RemoveAll();
39 m_FileFonts.RemoveAll(); 40 m_FileFonts.RemoveAll();
40 m_StreamFonts.RemoveAll(); 41 m_StreamFonts.RemoveAll();
41 m_DeriveFonts.RemoveAll(); 42 m_DeriveFonts.RemoveAll();
42 for (int32_t i = m_Fonts.GetUpperBound(); i >= 0; i--) 43 for (int32_t i = m_Fonts.GetUpperBound(); i >= 0; i--)
43 m_Fonts[i]->Release(); 44 m_Fonts[i]->Release();
44 } 45 }
45 46
46 IFX_Font* CFX_StdFontMgrImp::GetDefFontByCodePage( 47 CFX_GEFont* CFX_StdFontMgrImp::GetDefFontByCodePage(
47 uint16_t wCodePage, 48 uint16_t wCodePage,
48 uint32_t dwFontStyles, 49 uint32_t dwFontStyles,
49 const FX_WCHAR* pszFontFamily) { 50 const FX_WCHAR* pszFontFamily) {
50 uint32_t dwHash = FGAS_GetFontHashCode(wCodePage, dwFontStyles); 51 uint32_t dwHash = FGAS_GetFontHashCode(wCodePage, dwFontStyles);
51 IFX_Font* pFont = NULL; 52 CFX_GEFont* pFont = NULL;
dsinclair 2016/06/02 17:37:39 nit: nullptr and others.
52 if (m_CPFonts.Lookup((void*)(uintptr_t)dwHash, (void*&)pFont)) { 53 if (m_CPFonts.Lookup((void*)(uintptr_t)dwHash, (void*&)pFont)) {
53 return pFont ? LoadFont(pFont, dwFontStyles, wCodePage) : NULL; 54 return pFont ? LoadFont(pFont, dwFontStyles, wCodePage) : NULL;
54 } 55 }
55 FX_FONTDESCRIPTOR const* pFD; 56 FX_FONTDESCRIPTOR const* pFD;
56 if ((pFD = FindFont(pszFontFamily, dwFontStyles, TRUE, wCodePage)) == NULL) { 57 if ((pFD = FindFont(pszFontFamily, dwFontStyles, TRUE, wCodePage)) == NULL) {
dsinclair 2016/06/02 17:37:39 nit: if (!( ... and drop the == NULL
57 if ((pFD = FindFont(NULL, dwFontStyles, TRUE, wCodePage)) == NULL) { 58 if ((pFD = FindFont(NULL, dwFontStyles, TRUE, wCodePage)) == NULL) {
58 if ((pFD = FindFont(NULL, dwFontStyles, FALSE, wCodePage)) == NULL) 59 if ((pFD = FindFont(NULL, dwFontStyles, FALSE, wCodePage)) == NULL)
59 return NULL; 60 return NULL;
60 } 61 }
61 } 62 }
62 ASSERT(pFD); 63 ASSERT(pFD);
63 pFont = IFX_Font::LoadFont(pFD->wsFontFace, dwFontStyles, wCodePage, this); 64 pFont = CFX_GEFont::LoadFont(pFD->wsFontFace, dwFontStyles, wCodePage, this);
64 if (pFont) { 65 if (pFont) {
65 m_Fonts.Add(pFont); 66 m_Fonts.Add(pFont);
66 m_CPFonts.SetAt((void*)(uintptr_t)dwHash, (void*)pFont); 67 m_CPFonts.SetAt((void*)(uintptr_t)dwHash, (void*)pFont);
67 dwHash = FGAS_GetFontFamilyHash(pFD->wsFontFace, dwFontStyles, wCodePage); 68 dwHash = FGAS_GetFontFamilyHash(pFD->wsFontFace, dwFontStyles, wCodePage);
68 m_FamilyFonts.SetAt((void*)(uintptr_t)dwHash, (void*)pFont); 69 m_FamilyFonts.SetAt((void*)(uintptr_t)dwHash, (void*)pFont);
69 return LoadFont(pFont, dwFontStyles, wCodePage); 70 return LoadFont(pFont, dwFontStyles, wCodePage);
70 } 71 }
71 return NULL; 72 return NULL;
72 } 73 }
73 IFX_Font* CFX_StdFontMgrImp::GetDefFontByCharset( 74 CFX_GEFont* CFX_StdFontMgrImp::GetDefFontByCharset(
74 uint8_t nCharset, 75 uint8_t nCharset,
75 uint32_t dwFontStyles, 76 uint32_t dwFontStyles,
76 const FX_WCHAR* pszFontFamily) { 77 const FX_WCHAR* pszFontFamily) {
77 return GetDefFontByCodePage(FX_GetCodePageFromCharset(nCharset), dwFontStyles, 78 return GetDefFontByCodePage(FX_GetCodePageFromCharset(nCharset), dwFontStyles,
78 pszFontFamily); 79 pszFontFamily);
79 } 80 }
80 81
81 IFX_Font* CFX_StdFontMgrImp::GetDefFontByUnicode( 82 CFX_GEFont* CFX_StdFontMgrImp::GetDefFontByUnicode(
82 FX_WCHAR wUnicode, 83 FX_WCHAR wUnicode,
83 uint32_t dwFontStyles, 84 uint32_t dwFontStyles,
84 const FX_WCHAR* pszFontFamily) { 85 const FX_WCHAR* pszFontFamily) {
85 const FGAS_FONTUSB* pRet = FGAS_GetUnicodeBitField(wUnicode); 86 const FGAS_FONTUSB* pRet = FGAS_GetUnicodeBitField(wUnicode);
86 if (pRet->wBitField == 999) 87 if (pRet->wBitField == 999)
87 return nullptr; 88 return nullptr;
88 89
89 uint32_t dwHash = 90 uint32_t dwHash =
90 FGAS_GetFontFamilyHash(pszFontFamily, dwFontStyles, pRet->wBitField); 91 FGAS_GetFontFamilyHash(pszFontFamily, dwFontStyles, pRet->wBitField);
91 IFX_Font* pFont = nullptr; 92 CFX_GEFont* pFont = nullptr;
92 if (m_UnicodeFonts.Lookup((void*)(uintptr_t)dwHash, (void*&)pFont)) 93 if (m_UnicodeFonts.Lookup((void*)(uintptr_t)dwHash, (void*&)pFont))
93 return pFont ? LoadFont(pFont, dwFontStyles, pRet->wCodePage) : nullptr; 94 return pFont ? LoadFont(pFont, dwFontStyles, pRet->wCodePage) : nullptr;
94 95
95 FX_FONTDESCRIPTOR const* pFD = 96 FX_FONTDESCRIPTOR const* pFD =
96 FindFont(pszFontFamily, dwFontStyles, FALSE, pRet->wCodePage, 97 FindFont(pszFontFamily, dwFontStyles, FALSE, pRet->wCodePage,
97 pRet->wBitField, wUnicode); 98 pRet->wBitField, wUnicode);
98 if (!pFD && pszFontFamily) { 99 if (!pFD && pszFontFamily) {
99 pFD = FindFont(nullptr, dwFontStyles, FALSE, pRet->wCodePage, 100 pFD = FindFont(nullptr, dwFontStyles, FALSE, pRet->wCodePage,
100 pRet->wBitField, wUnicode); 101 pRet->wBitField, wUnicode);
101 } 102 }
102 if (!pFD) 103 if (!pFD)
103 return nullptr; 104 return nullptr;
104 105
105 uint16_t wCodePage = FX_GetCodePageFromCharset(pFD->uCharSet); 106 uint16_t wCodePage = FX_GetCodePageFromCharset(pFD->uCharSet);
106 const FX_WCHAR* pFontFace = pFD->wsFontFace; 107 const FX_WCHAR* pFontFace = pFD->wsFontFace;
107 pFont = IFX_Font::LoadFont(pFontFace, dwFontStyles, wCodePage, this); 108 pFont = CFX_GEFont::LoadFont(pFontFace, dwFontStyles, wCodePage, this);
108 if (pFont) { 109 if (pFont) {
109 m_Fonts.Add(pFont); 110 m_Fonts.Add(pFont);
110 m_UnicodeFonts.SetAt((void*)(uintptr_t)dwHash, (void*)pFont); 111 m_UnicodeFonts.SetAt((void*)(uintptr_t)dwHash, (void*)pFont);
111 dwHash = FGAS_GetFontHashCode(wCodePage, dwFontStyles); 112 dwHash = FGAS_GetFontHashCode(wCodePage, dwFontStyles);
112 m_CPFonts.SetAt((void*)(uintptr_t)dwHash, (void*)pFont); 113 m_CPFonts.SetAt((void*)(uintptr_t)dwHash, (void*)pFont);
113 dwHash = FGAS_GetFontFamilyHash(pFontFace, dwFontStyles, wCodePage); 114 dwHash = FGAS_GetFontFamilyHash(pFontFace, dwFontStyles, wCodePage);
114 m_FamilyFonts.SetAt((void*)(uintptr_t)dwHash, (void*)pFont); 115 m_FamilyFonts.SetAt((void*)(uintptr_t)dwHash, (void*)pFont);
115 return LoadFont(pFont, dwFontStyles, wCodePage); 116 return LoadFont(pFont, dwFontStyles, wCodePage);
116 } 117 }
117 return nullptr; 118 return nullptr;
118 } 119 }
119 120
120 IFX_Font* CFX_StdFontMgrImp::GetDefFontByLanguage( 121 CFX_GEFont* CFX_StdFontMgrImp::GetDefFontByLanguage(
121 uint16_t wLanguage, 122 uint16_t wLanguage,
122 uint32_t dwFontStyles, 123 uint32_t dwFontStyles,
123 const FX_WCHAR* pszFontFamily) { 124 const FX_WCHAR* pszFontFamily) {
124 return GetDefFontByCodePage(FX_GetDefCodePageByLanguage(wLanguage), 125 return GetDefFontByCodePage(FX_GetDefCodePageByLanguage(wLanguage),
125 dwFontStyles, pszFontFamily); 126 dwFontStyles, pszFontFamily);
126 } 127 }
127 IFX_Font* CFX_StdFontMgrImp::LoadFont(const FX_WCHAR* pszFontFamily, 128 CFX_GEFont* CFX_StdFontMgrImp::LoadFont(const FX_WCHAR* pszFontFamily,
128 uint32_t dwFontStyles, 129 uint32_t dwFontStyles,
129 uint16_t wCodePage) { 130 uint16_t wCodePage) {
130 uint32_t dwHash = 131 uint32_t dwHash =
131 FGAS_GetFontFamilyHash(pszFontFamily, dwFontStyles, wCodePage); 132 FGAS_GetFontFamilyHash(pszFontFamily, dwFontStyles, wCodePage);
132 IFX_Font* pFont = NULL; 133 CFX_GEFont* pFont = NULL;
133 if (m_FamilyFonts.Lookup((void*)(uintptr_t)dwHash, (void*&)pFont)) { 134 if (m_FamilyFonts.Lookup((void*)(uintptr_t)dwHash, (void*&)pFont)) {
134 return pFont ? LoadFont(pFont, dwFontStyles, wCodePage) : NULL; 135 return pFont ? LoadFont(pFont, dwFontStyles, wCodePage) : NULL;
135 } 136 }
136 FX_FONTDESCRIPTOR const* pFD = NULL; 137 FX_FONTDESCRIPTOR const* pFD = NULL;
137 if ((pFD = FindFont(pszFontFamily, dwFontStyles, TRUE, wCodePage)) == NULL) { 138 if ((pFD = FindFont(pszFontFamily, dwFontStyles, TRUE, wCodePage)) == NULL) {
138 if ((pFD = FindFont(pszFontFamily, dwFontStyles, FALSE, wCodePage)) == 139 if ((pFD = FindFont(pszFontFamily, dwFontStyles, FALSE, wCodePage)) ==
139 NULL) { 140 NULL) {
140 return NULL; 141 return NULL;
141 } 142 }
142 } 143 }
143 ASSERT(pFD); 144 ASSERT(pFD);
144 if (wCodePage == 0xFFFF) { 145 if (wCodePage == 0xFFFF) {
145 wCodePage = FX_GetCodePageFromCharset(pFD->uCharSet); 146 wCodePage = FX_GetCodePageFromCharset(pFD->uCharSet);
146 } 147 }
147 pFont = IFX_Font::LoadFont(pFD->wsFontFace, dwFontStyles, wCodePage, this); 148 pFont = CFX_GEFont::LoadFont(pFD->wsFontFace, dwFontStyles, wCodePage, this);
148 if (pFont) { 149 if (pFont) {
149 m_Fonts.Add(pFont); 150 m_Fonts.Add(pFont);
150 m_FamilyFonts.SetAt((void*)(uintptr_t)dwHash, (void*)pFont); 151 m_FamilyFonts.SetAt((void*)(uintptr_t)dwHash, (void*)pFont);
151 dwHash = FGAS_GetFontHashCode(wCodePage, dwFontStyles); 152 dwHash = FGAS_GetFontHashCode(wCodePage, dwFontStyles);
152 m_CPFonts.SetAt((void*)(uintptr_t)dwHash, (void*)pFont); 153 m_CPFonts.SetAt((void*)(uintptr_t)dwHash, (void*)pFont);
153 return LoadFont(pFont, dwFontStyles, wCodePage); 154 return LoadFont(pFont, dwFontStyles, wCodePage);
154 } 155 }
155 return NULL; 156 return NULL;
156 } 157 }
157 IFX_Font* CFX_StdFontMgrImp::LoadFont(const uint8_t* pBuffer, int32_t iLength) { 158 CFX_GEFont* CFX_StdFontMgrImp::LoadFont(const uint8_t* pBuffer,
159 int32_t iLength) {
158 ASSERT(pBuffer && iLength > 0); 160 ASSERT(pBuffer && iLength > 0);
159 IFX_Font* pFont = NULL; 161 CFX_GEFont* pFont = NULL;
160 if (m_BufferFonts.Lookup((void*)pBuffer, (void*&)pFont)) { 162 if (m_BufferFonts.Lookup((void*)pBuffer, (void*&)pFont)) {
161 if (pFont) { 163 if (pFont) {
162 return pFont->Retain(); 164 return pFont->Retain();
163 } 165 }
164 } 166 }
165 pFont = IFX_Font::LoadFont(pBuffer, iLength, this); 167 pFont = CFX_GEFont::LoadFont(pBuffer, iLength, this);
166 if (pFont) { 168 if (pFont) {
167 m_Fonts.Add(pFont); 169 m_Fonts.Add(pFont);
168 m_BufferFonts.SetAt((void*)pBuffer, pFont); 170 m_BufferFonts.SetAt((void*)pBuffer, pFont);
169 return pFont->Retain(); 171 return pFont->Retain();
170 } 172 }
171 return NULL; 173 return NULL;
172 } 174 }
173 IFX_Font* CFX_StdFontMgrImp::LoadFont(const FX_WCHAR* pszFileName) { 175 CFX_GEFont* CFX_StdFontMgrImp::LoadFont(const FX_WCHAR* pszFileName) {
174 ASSERT(pszFileName); 176 ASSERT(pszFileName);
175 uint32_t dwHash = FX_HashCode_GetW(pszFileName, false); 177 uint32_t dwHash = FX_HashCode_GetW(pszFileName, false);
176 IFX_Font* pFont = NULL; 178 CFX_GEFont* pFont = NULL;
177 if (m_FileFonts.Lookup((void*)(uintptr_t)dwHash, (void*&)pFont)) { 179 if (m_FileFonts.Lookup((void*)(uintptr_t)dwHash, (void*&)pFont)) {
178 if (pFont) { 180 if (pFont) {
179 return pFont->Retain(); 181 return pFont->Retain();
180 } 182 }
181 } 183 }
182 pFont = IFX_Font::LoadFont(pszFileName, NULL); 184 pFont = CFX_GEFont::LoadFont(pszFileName);
183 if (pFont) { 185 if (pFont) {
184 m_Fonts.Add(pFont); 186 m_Fonts.Add(pFont);
185 m_FileFonts.SetAt((void*)(uintptr_t)dwHash, (void*)pFont); 187 m_FileFonts.SetAt((void*)(uintptr_t)dwHash, (void*)pFont);
186 return pFont->Retain(); 188 return pFont->Retain();
187 } 189 }
188 return NULL; 190 return NULL;
189 } 191 }
190 IFX_Font* CFX_StdFontMgrImp::LoadFont(IFX_Stream* pFontStream, 192 CFX_GEFont* CFX_StdFontMgrImp::LoadFont(IFX_Stream* pFontStream,
191 const FX_WCHAR* pszFontAlias, 193 const FX_WCHAR* pszFontAlias,
192 uint32_t dwFontStyles, 194 uint32_t dwFontStyles,
193 uint16_t wCodePage, 195 uint16_t wCodePage,
194 FX_BOOL bSaveStream) { 196 FX_BOOL bSaveStream) {
195 ASSERT(pFontStream && pFontStream->GetLength() > 0); 197 ASSERT(pFontStream && pFontStream->GetLength() > 0);
196 IFX_Font* pFont = NULL; 198 CFX_GEFont* pFont = NULL;
197 if (m_StreamFonts.Lookup((void*)pFontStream, (void*&)pFont)) { 199 if (m_StreamFonts.Lookup((void*)pFontStream, (void*&)pFont)) {
198 if (pFont) { 200 if (pFont) {
199 if (pszFontAlias) { 201 if (pszFontAlias) {
200 uint32_t dwHash = 202 uint32_t dwHash =
201 FGAS_GetFontFamilyHash(pszFontAlias, dwFontStyles, wCodePage); 203 FGAS_GetFontFamilyHash(pszFontAlias, dwFontStyles, wCodePage);
202 m_FamilyFonts.SetAt((void*)(uintptr_t)dwHash, (void*)pFont); 204 m_FamilyFonts.SetAt((void*)(uintptr_t)dwHash, (void*)pFont);
203 } 205 }
204 return LoadFont(pFont, dwFontStyles, wCodePage); 206 return LoadFont(pFont, dwFontStyles, wCodePage);
205 } 207 }
206 } 208 }
207 pFont = IFX_Font::LoadFont(pFontStream, this, bSaveStream); 209 pFont = CFX_GEFont::LoadFont(pFontStream, this, bSaveStream);
208 if (pFont) { 210 if (pFont) {
209 m_Fonts.Add(pFont); 211 m_Fonts.Add(pFont);
210 m_StreamFonts.SetAt((void*)pFontStream, (void*)pFont); 212 m_StreamFonts.SetAt((void*)pFontStream, (void*)pFont);
211 if (pszFontAlias) { 213 if (pszFontAlias) {
212 uint32_t dwHash = 214 uint32_t dwHash =
213 FGAS_GetFontFamilyHash(pszFontAlias, dwFontStyles, wCodePage); 215 FGAS_GetFontFamilyHash(pszFontAlias, dwFontStyles, wCodePage);
214 m_FamilyFonts.SetAt((void*)(uintptr_t)dwHash, (void*)pFont); 216 m_FamilyFonts.SetAt((void*)(uintptr_t)dwHash, (void*)pFont);
215 } 217 }
216 return LoadFont(pFont, dwFontStyles, wCodePage); 218 return LoadFont(pFont, dwFontStyles, wCodePage);
217 } 219 }
218 return NULL; 220 return NULL;
219 } 221 }
220 IFX_Font* CFX_StdFontMgrImp::LoadFont(IFX_Font* pSrcFont, 222 CFX_GEFont* CFX_StdFontMgrImp::LoadFont(CFX_GEFont* pSrcFont,
221 uint32_t dwFontStyles, 223 uint32_t dwFontStyles,
222 uint16_t wCodePage) { 224 uint16_t wCodePage) {
223 ASSERT(pSrcFont); 225 ASSERT(pSrcFont);
224 if (pSrcFont->GetFontStyles() == dwFontStyles) { 226 if (pSrcFont->GetFontStyles() == dwFontStyles) {
225 return pSrcFont->Retain(); 227 return pSrcFont->Retain();
226 } 228 }
227 void* buffer[3] = {pSrcFont, (void*)(uintptr_t)dwFontStyles, 229 void* buffer[3] = {pSrcFont, (void*)(uintptr_t)dwFontStyles,
228 (void*)(uintptr_t)wCodePage}; 230 (void*)(uintptr_t)wCodePage};
229 uint32_t dwHash = FX_HashCode_GetA( 231 uint32_t dwHash = FX_HashCode_GetA(
230 CFX_ByteStringC((uint8_t*)buffer, sizeof(buffer)), false); 232 CFX_ByteStringC((uint8_t*)buffer, sizeof(buffer)), false);
231 IFX_Font* pFont = NULL; 233 CFX_GEFont* pFont = NULL;
232 if (m_DeriveFonts.GetCount() > 0) { 234 if (m_DeriveFonts.GetCount() > 0) {
233 m_DeriveFonts.Lookup((void*)(uintptr_t)dwHash, (void*&)pFont); 235 m_DeriveFonts.Lookup((void*)(uintptr_t)dwHash, (void*&)pFont);
234 if (pFont) { 236 if (pFont) {
235 return pFont->Retain(); 237 return pFont->Retain();
236 } 238 }
237 } 239 }
238 pFont = pSrcFont->Derive(dwFontStyles, wCodePage); 240 pFont = pSrcFont->Derive(dwFontStyles, wCodePage);
239 if (pFont) { 241 if (pFont) {
240 m_DeriveFonts.SetAt((void*)(uintptr_t)dwHash, (void*)pFont); 242 m_DeriveFonts.SetAt((void*)(uintptr_t)dwHash, (void*)pFont);
241 int32_t index = m_Fonts.Find(pFont); 243 int32_t index = m_Fonts.Find(pFont);
242 if (index < 0) { 244 if (index < 0) {
243 m_Fonts.Add(pFont); 245 m_Fonts.Add(pFont);
244 pFont->Retain(); 246 pFont->Retain();
245 } 247 }
246 return pFont; 248 return pFont;
247 } 249 }
248 return NULL; 250 return NULL;
249 } 251 }
250 252
251 void CFX_StdFontMgrImp::ClearFontCache() { 253 void CFX_StdFontMgrImp::ClearFontCache() {
252 for (int32_t i = 0; i < m_Fonts.GetSize(); i++) 254 for (int32_t i = 0; i < m_Fonts.GetSize(); i++)
253 m_Fonts[i]->Reset(); 255 m_Fonts[i]->Reset();
254 } 256 }
255 257
256 void CFX_StdFontMgrImp::RemoveFont(CFX_MapPtrToPtr& fontMap, IFX_Font* pFont) { 258 void CFX_StdFontMgrImp::RemoveFont(CFX_MapPtrToPtr& fontMap,
259 CFX_GEFont* pFont) {
257 FX_POSITION pos = fontMap.GetStartPosition(); 260 FX_POSITION pos = fontMap.GetStartPosition();
258 void* pKey; 261 void* pKey;
259 void* pFind; 262 void* pFind;
260 while (pos) { 263 while (pos) {
261 pFind = NULL; 264 pFind = NULL;
262 fontMap.GetNextAssoc(pos, pKey, pFind); 265 fontMap.GetNextAssoc(pos, pKey, pFind);
263 if (pFind != (void*)pFont) { 266 if (pFind != (void*)pFont) {
264 continue; 267 continue;
265 } 268 }
266 fontMap.RemoveKey(pKey); 269 fontMap.RemoveKey(pKey);
267 break; 270 break;
268 } 271 }
269 } 272 }
270 void CFX_StdFontMgrImp::RemoveFont(IFX_Font* pFont) { 273 void CFX_StdFontMgrImp::RemoveFont(CFX_GEFont* pFont) {
271 RemoveFont(m_CPFonts, pFont); 274 RemoveFont(m_CPFonts, pFont);
272 RemoveFont(m_FamilyFonts, pFont); 275 RemoveFont(m_FamilyFonts, pFont);
273 RemoveFont(m_UnicodeFonts, pFont); 276 RemoveFont(m_UnicodeFonts, pFont);
274 RemoveFont(m_BufferFonts, pFont); 277 RemoveFont(m_BufferFonts, pFont);
275 RemoveFont(m_FileFonts, pFont); 278 RemoveFont(m_FileFonts, pFont);
276 RemoveFont(m_StreamFonts, pFont); 279 RemoveFont(m_StreamFonts, pFont);
277 RemoveFont(m_DeriveFonts, pFont); 280 RemoveFont(m_DeriveFonts, pFont);
278 int32_t iFind = m_Fonts.Find(pFont); 281 int32_t iFind = m_Fonts.Find(pFont);
279 if (iFind > -1) { 282 if (iFind > -1) {
280 m_Fonts.RemoveAt(iFind, 1); 283 m_Fonts.RemoveAt(iFind, 1);
(...skipping 341 matching lines...) Expand 10 before | Expand all | Expand 10 after
622 FX_POSITION pos = m_Hash2CandidateList.GetStartPosition(); 625 FX_POSITION pos = m_Hash2CandidateList.GetStartPosition();
623 while (pos) { 626 while (pos) {
624 uint32_t dwHash; 627 uint32_t dwHash;
625 CFX_FontDescriptorInfos* pDescs; 628 CFX_FontDescriptorInfos* pDescs;
626 m_Hash2CandidateList.GetNextAssoc(pos, dwHash, pDescs); 629 m_Hash2CandidateList.GetNextAssoc(pos, dwHash, pDescs);
627 delete pDescs; 630 delete pDescs;
628 } 631 }
629 pos = m_Hash2Fonts.GetStartPosition(); 632 pos = m_Hash2Fonts.GetStartPosition();
630 while (pos) { 633 while (pos) {
631 uint32_t dwHash; 634 uint32_t dwHash;
632 CFX_ArrayTemplate<IFX_Font*>* pFonts; 635 CFX_ArrayTemplate<CFX_GEFont*>* pFonts;
633 m_Hash2Fonts.GetNextAssoc(pos, dwHash, pFonts); 636 m_Hash2Fonts.GetNextAssoc(pos, dwHash, pFonts);
634 delete pFonts; 637 delete pFonts;
635 } 638 }
636 m_Hash2Fonts.RemoveAll(); 639 m_Hash2Fonts.RemoveAll();
637 pos = m_Hash2FileAccess.GetStartPosition(); 640 pos = m_Hash2FileAccess.GetStartPosition();
638 while (pos) { 641 while (pos) {
639 uint32_t dwHash; 642 uint32_t dwHash;
640 IFX_FileAccess* pFileAccess; 643 IFX_FileAccess* pFileAccess;
641 m_Hash2FileAccess.GetNextAssoc(pos, dwHash, pFileAccess); 644 m_Hash2FileAccess.GetNextAssoc(pos, dwHash, pFileAccess);
642 if (NULL != pFileAccess) { 645 if (NULL != pFileAccess) {
643 pFileAccess->Release(); 646 pFileAccess->Release();
644 } 647 }
645 } 648 }
646 pos = m_FileAccess2IFXFont.GetStartPosition(); 649 pos = m_FileAccess2IFXFont.GetStartPosition();
647 while (pos) { 650 while (pos) {
648 uint32_t dwHash; 651 uint32_t dwHash;
649 IFX_Font* pFont; 652 CFX_GEFont* pFont;
650 m_FileAccess2IFXFont.GetNextAssoc(pos, dwHash, pFont); 653 m_FileAccess2IFXFont.GetNextAssoc(pos, dwHash, pFont);
651 if (NULL != pFont) { 654 if (NULL != pFont) {
652 pFont->Release(); 655 pFont->Release();
653 } 656 }
654 } 657 }
655 pos = m_IFXFont2FileRead.GetStartPosition(); 658 pos = m_IFXFont2FileRead.GetStartPosition();
656 while (pos) { 659 while (pos) {
657 IFX_Font* pFont; 660 CFX_GEFont* pFont;
658 IFX_FileRead* pFileRead; 661 IFX_FileRead* pFileRead;
659 m_IFXFont2FileRead.GetNextAssoc(pos, pFont, pFileRead); 662 m_IFXFont2FileRead.GetNextAssoc(pos, pFont, pFileRead);
660 pFileRead->Release(); 663 pFileRead->Release();
661 } 664 }
662 delete this; 665 delete this;
663 } 666 }
664 IFX_Font* CFX_FontMgrImp::GetDefFontByCodePage(uint16_t wCodePage, 667 CFX_GEFont* CFX_FontMgrImp::GetDefFontByCodePage(
665 uint32_t dwFontStyles, 668 uint16_t wCodePage,
666 const FX_WCHAR* pszFontFamily) { 669 uint32_t dwFontStyles,
670 const FX_WCHAR* pszFontFamily) {
667 return nullptr; 671 return nullptr;
668 } 672 }
669 IFX_Font* CFX_FontMgrImp::GetDefFontByCharset(uint8_t nCharset, 673 CFX_GEFont* CFX_FontMgrImp::GetDefFontByCharset(uint8_t nCharset,
670 uint32_t dwFontStyles, 674 uint32_t dwFontStyles,
671 const FX_WCHAR* pszFontFamily) { 675 const FX_WCHAR* pszFontFamily) {
672 return nullptr; 676 return nullptr;
673 } 677 }
674 IFX_Font* CFX_FontMgrImp::GetDefFontByUnicode(FX_WCHAR wUnicode, 678 CFX_GEFont* CFX_FontMgrImp::GetDefFontByUnicode(FX_WCHAR wUnicode,
675 uint32_t dwFontStyles, 679 uint32_t dwFontStyles,
676 const FX_WCHAR* pszFontFamily) { 680 const FX_WCHAR* pszFontFamily) {
677 return nullptr; 681 return nullptr;
678 } 682 }
679 IFX_Font* CFX_FontMgrImp::GetDefFontByLanguage(uint16_t wLanguage, 683 CFX_GEFont* CFX_FontMgrImp::GetDefFontByLanguage(
680 uint32_t dwFontStyles, 684 uint16_t wLanguage,
681 const FX_WCHAR* pszFontFamily) { 685 uint32_t dwFontStyles,
686 const FX_WCHAR* pszFontFamily) {
682 return nullptr; 687 return nullptr;
683 } 688 }
684 689
685 IFX_Font* CFX_FontMgrImp::GetFontByCodePage(uint16_t wCodePage, 690 CFX_GEFont* CFX_FontMgrImp::GetFontByCodePage(uint16_t wCodePage,
686 uint32_t dwFontStyles, 691 uint32_t dwFontStyles,
687 const FX_WCHAR* pszFontFamily) { 692 const FX_WCHAR* pszFontFamily) {
688 CFX_ByteString bsHash; 693 CFX_ByteString bsHash;
689 bsHash.Format("%d, %d", wCodePage, dwFontStyles); 694 bsHash.Format("%d, %d", wCodePage, dwFontStyles);
690 bsHash += CFX_WideString(pszFontFamily).UTF8Encode(); 695 bsHash += CFX_WideString(pszFontFamily).UTF8Encode();
691 uint32_t dwHash = FX_HashCode_GetA(bsHash.AsStringC(), false); 696 uint32_t dwHash = FX_HashCode_GetA(bsHash.AsStringC(), false);
692 CFX_ArrayTemplate<IFX_Font*>* pFonts = nullptr; 697 CFX_ArrayTemplate<CFX_GEFont*>* pFonts = nullptr;
693 if (m_Hash2Fonts.Lookup(dwHash, pFonts)) { 698 if (m_Hash2Fonts.Lookup(dwHash, pFonts)) {
694 if (!pFonts) 699 if (!pFonts)
695 return nullptr; 700 return nullptr;
696 701
697 if (pFonts->GetSize() != 0) 702 if (pFonts->GetSize() != 0)
698 return pFonts->GetAt(0)->Retain(); 703 return pFonts->GetAt(0)->Retain();
699 } 704 }
700 705
701 if (!pFonts) 706 if (!pFonts)
702 pFonts = new CFX_ArrayTemplate<IFX_Font*>; 707 pFonts = new CFX_ArrayTemplate<CFX_GEFont*>;
703 708
704 m_Hash2Fonts.SetAt(dwHash, pFonts); 709 m_Hash2Fonts.SetAt(dwHash, pFonts);
705 CFX_FontDescriptorInfos* sortedFonts = nullptr; 710 CFX_FontDescriptorInfos* sortedFonts = nullptr;
706 if (!m_Hash2CandidateList.Lookup(dwHash, sortedFonts)) { 711 if (!m_Hash2CandidateList.Lookup(dwHash, sortedFonts)) {
707 sortedFonts = new CFX_FontDescriptorInfos; 712 sortedFonts = new CFX_FontDescriptorInfos;
708 MatchFonts(*sortedFonts, wCodePage, dwFontStyles, 713 MatchFonts(*sortedFonts, wCodePage, dwFontStyles,
709 CFX_WideString(pszFontFamily), 0); 714 CFX_WideString(pszFontFamily), 0);
710 m_Hash2CandidateList.SetAt(dwHash, sortedFonts); 715 m_Hash2CandidateList.SetAt(dwHash, sortedFonts);
711 } 716 }
712 if (sortedFonts->GetSize() == 0) 717 if (sortedFonts->GetSize() == 0)
713 return nullptr; 718 return nullptr;
714 719
715 CFX_FontDescriptor* pDesc = sortedFonts->GetAt(0).pFont; 720 CFX_FontDescriptor* pDesc = sortedFonts->GetAt(0).pFont;
716 IFX_Font* pFont = 721 CFX_GEFont* pFont =
717 pDesc->m_pFileAccess 722 pDesc->m_pFileAccess
718 ? LoadFont(pDesc->m_pFileAccess, pDesc->m_nFaceIndex, nullptr) 723 ? LoadFont(pDesc->m_pFileAccess, pDesc->m_nFaceIndex, nullptr)
719 : LoadFont(pDesc->m_wsFaceName, pDesc->m_nFaceIndex, nullptr); 724 : LoadFont(pDesc->m_wsFaceName, pDesc->m_nFaceIndex, nullptr);
720 if (pFont) 725 if (pFont)
721 pFont->SetLogicalFontStyle(dwFontStyles); 726 pFont->SetLogicalFontStyle(dwFontStyles);
722 727
723 pFonts->Add(pFont); 728 pFonts->Add(pFont);
724 return pFont; 729 return pFont;
725 } 730 }
726 IFX_Font* CFX_FontMgrImp::GetFontByCharset(uint8_t nCharset, 731 CFX_GEFont* CFX_FontMgrImp::GetFontByCharset(uint8_t nCharset,
727 uint32_t dwFontStyles, 732 uint32_t dwFontStyles,
728 const FX_WCHAR* pszFontFamily) { 733 const FX_WCHAR* pszFontFamily) {
729 return GetFontByCodePage(FX_GetCodePageFromCharset(nCharset), dwFontStyles, 734 return GetFontByCodePage(FX_GetCodePageFromCharset(nCharset), dwFontStyles,
730 pszFontFamily); 735 pszFontFamily);
731 } 736 }
732 IFX_Font* CFX_FontMgrImp::GetFontByUnicode(FX_WCHAR wUnicode, 737 CFX_GEFont* CFX_FontMgrImp::GetFontByUnicode(FX_WCHAR wUnicode,
733 uint32_t dwFontStyles, 738 uint32_t dwFontStyles,
734 const FX_WCHAR* pszFontFamily) { 739 const FX_WCHAR* pszFontFamily) {
735 IFX_Font* pFont = nullptr; 740 CFX_GEFont* pFont = nullptr;
736 if (m_FailedUnicodes2NULL.Lookup(wUnicode, pFont)) 741 if (m_FailedUnicodes2NULL.Lookup(wUnicode, pFont))
737 return nullptr; 742 return nullptr;
738 const FGAS_FONTUSB* x = FGAS_GetUnicodeBitField(wUnicode); 743 const FGAS_FONTUSB* x = FGAS_GetUnicodeBitField(wUnicode);
739 uint16_t wCodePage = x ? x->wCodePage : 0xFFFF; 744 uint16_t wCodePage = x ? x->wCodePage : 0xFFFF;
740 uint16_t wBitField = x ? x->wBitField : 0x03E7; 745 uint16_t wBitField = x ? x->wBitField : 0x03E7;
741 CFX_ByteString bsHash; 746 CFX_ByteString bsHash;
742 if (wCodePage == 0xFFFF) 747 if (wCodePage == 0xFFFF)
743 bsHash.Format("%d, %d, %d", wCodePage, wBitField, dwFontStyles); 748 bsHash.Format("%d, %d, %d", wCodePage, wBitField, dwFontStyles);
744 else 749 else
745 bsHash.Format("%d, %d", wCodePage, dwFontStyles); 750 bsHash.Format("%d, %d", wCodePage, dwFontStyles);
746 bsHash += CFX_WideString(pszFontFamily).UTF8Encode(); 751 bsHash += CFX_WideString(pszFontFamily).UTF8Encode();
747 uint32_t dwHash = FX_HashCode_GetA(bsHash.AsStringC(), false); 752 uint32_t dwHash = FX_HashCode_GetA(bsHash.AsStringC(), false);
748 CFX_ArrayTemplate<IFX_Font*>* pFonts = nullptr; 753 CFX_ArrayTemplate<CFX_GEFont*>* pFonts = nullptr;
749 if (m_Hash2Fonts.Lookup(dwHash, pFonts)) { 754 if (m_Hash2Fonts.Lookup(dwHash, pFonts)) {
750 if (!pFonts) 755 if (!pFonts)
751 return nullptr; 756 return nullptr;
752 for (int32_t i = 0; i < pFonts->GetSize(); ++i) { 757 for (int32_t i = 0; i < pFonts->GetSize(); ++i) {
753 if (VerifyUnicode(pFonts->GetAt(i), wUnicode)) 758 if (VerifyUnicode(pFonts->GetAt(i), wUnicode))
754 return pFonts->GetAt(i)->Retain(); 759 return pFonts->GetAt(i)->Retain();
755 } 760 }
756 } 761 }
757 if (!pFonts) 762 if (!pFonts)
758 pFonts = new CFX_ArrayTemplate<IFX_Font*>; 763 pFonts = new CFX_ArrayTemplate<CFX_GEFont*>;
759 m_Hash2Fonts.SetAt(dwHash, pFonts); 764 m_Hash2Fonts.SetAt(dwHash, pFonts);
760 CFX_FontDescriptorInfos* sortedFonts = nullptr; 765 CFX_FontDescriptorInfos* sortedFonts = nullptr;
761 if (!m_Hash2CandidateList.Lookup(dwHash, sortedFonts)) { 766 if (!m_Hash2CandidateList.Lookup(dwHash, sortedFonts)) {
762 sortedFonts = new CFX_FontDescriptorInfos; 767 sortedFonts = new CFX_FontDescriptorInfos;
763 MatchFonts(*sortedFonts, wCodePage, dwFontStyles, 768 MatchFonts(*sortedFonts, wCodePage, dwFontStyles,
764 CFX_WideString(pszFontFamily), wUnicode); 769 CFX_WideString(pszFontFamily), wUnicode);
765 m_Hash2CandidateList.SetAt(dwHash, sortedFonts); 770 m_Hash2CandidateList.SetAt(dwHash, sortedFonts);
766 } 771 }
767 for (int32_t i = 0; i < sortedFonts->GetSize(); ++i) { 772 for (int32_t i = 0; i < sortedFonts->GetSize(); ++i) {
768 CFX_FontDescriptor* pDesc = sortedFonts->GetAt(i).pFont; 773 CFX_FontDescriptor* pDesc = sortedFonts->GetAt(i).pFont;
(...skipping 27 matching lines...) Expand all
796 FT_Error retIndex = FXFT_Get_Char_Index(pFace, wcUnicode); 801 FT_Error retIndex = FXFT_Get_Char_Index(pFace, wcUnicode);
797 pFileRead->Release(); 802 pFileRead->Release();
798 if (!pFace) 803 if (!pFace)
799 return FALSE; 804 return FALSE;
800 if (FXFT_Get_Face_External_Stream(pFace)) 805 if (FXFT_Get_Face_External_Stream(pFace))
801 FXFT_Clear_Face_External_Stream(pFace); 806 FXFT_Clear_Face_External_Stream(pFace);
802 FXFT_Done_Face(pFace); 807 FXFT_Done_Face(pFace);
803 return !retCharmap && retIndex; 808 return !retCharmap && retIndex;
804 } 809 }
805 810
806 FX_BOOL CFX_FontMgrImp::VerifyUnicode(IFX_Font* pFont, FX_WCHAR wcUnicode) { 811 FX_BOOL CFX_FontMgrImp::VerifyUnicode(CFX_GEFont* pFont, FX_WCHAR wcUnicode) {
807 if (!pFont) 812 if (!pFont)
808 return FALSE; 813 return FALSE;
809 814
810 FXFT_Face pFace = ((CFX_Font*)pFont->GetDevFont())->GetFace(); 815 FXFT_Face pFace = ((CFX_Font*)pFont->GetDevFont())->GetFace();
811 FXFT_CharMap charmap = FXFT_Get_Face_Charmap(pFace); 816 FXFT_CharMap charmap = FXFT_Get_Face_Charmap(pFace);
812 if (FXFT_Select_Charmap(pFace, FXFT_ENCODING_UNICODE) != 0) 817 if (FXFT_Select_Charmap(pFace, FXFT_ENCODING_UNICODE) != 0)
813 return FALSE; 818 return FALSE;
814 819
815 if (FXFT_Get_Char_Index(pFace, wcUnicode) == 0) { 820 if (FXFT_Get_Char_Index(pFace, wcUnicode) == 0) {
816 FXFT_Set_Charmap(pFace, charmap); 821 FXFT_Set_Charmap(pFace, charmap);
817 return FALSE; 822 return FALSE;
818 } 823 }
819 return TRUE; 824 return TRUE;
820 } 825 }
821 826
822 IFX_Font* CFX_FontMgrImp::GetFontByLanguage(uint16_t wLanguage, 827 CFX_GEFont* CFX_FontMgrImp::GetFontByLanguage(uint16_t wLanguage,
823 uint32_t dwFontStyles, 828 uint32_t dwFontStyles,
824 const FX_WCHAR* pszFontFamily) { 829 const FX_WCHAR* pszFontFamily) {
825 return GetFontByCodePage(FX_GetDefCodePageByLanguage(wLanguage), dwFontStyles, 830 return GetFontByCodePage(FX_GetDefCodePageByLanguage(wLanguage), dwFontStyles,
826 pszFontFamily); 831 pszFontFamily);
827 } 832 }
828 833
829 IFX_Font* CFX_FontMgrImp::LoadFont(const uint8_t* pBuffer, 834 CFX_GEFont* CFX_FontMgrImp::LoadFont(const uint8_t* pBuffer,
830 int32_t iLength, 835 int32_t iLength,
831 int32_t iFaceIndex, 836 int32_t iFaceIndex,
832 int32_t* pFaceCount) { 837 int32_t* pFaceCount) {
833 void* Hash[2] = {(void*)(uintptr_t)pBuffer, (void*)(uintptr_t)iLength}; 838 void* Hash[2] = {(void*)(uintptr_t)pBuffer, (void*)(uintptr_t)iLength};
834 uint32_t dwHash = 839 uint32_t dwHash =
835 FX_HashCode_GetA(CFX_ByteStringC((uint8_t*)Hash, sizeof(Hash)), false); 840 FX_HashCode_GetA(CFX_ByteStringC((uint8_t*)Hash, sizeof(Hash)), false);
836 IFX_FileAccess* pFontAccess = nullptr; 841 IFX_FileAccess* pFontAccess = nullptr;
837 m_Hash2FileAccess.Lookup(dwHash, pFontAccess); 842 m_Hash2FileAccess.Lookup(dwHash, pFontAccess);
838 return pFontAccess ? LoadFont(pFontAccess, iFaceIndex, pFaceCount, TRUE) 843 return pFontAccess ? LoadFont(pFontAccess, iFaceIndex, pFaceCount, TRUE)
839 : nullptr; 844 : nullptr;
840 } 845 }
841 846
842 IFX_Font* CFX_FontMgrImp::LoadFont(const FX_WCHAR* pszFileName, 847 CFX_GEFont* CFX_FontMgrImp::LoadFont(const FX_WCHAR* pszFileName,
843 int32_t iFaceIndex, 848 int32_t iFaceIndex,
844 int32_t* pFaceCount) { 849 int32_t* pFaceCount) {
845 CFX_ByteString bsHash; 850 CFX_ByteString bsHash;
846 bsHash += CFX_WideString(pszFileName).UTF8Encode(); 851 bsHash += CFX_WideString(pszFileName).UTF8Encode();
847 852
848 uint32_t dwHash = FX_HashCode_GetA(bsHash.AsStringC(), false); 853 uint32_t dwHash = FX_HashCode_GetA(bsHash.AsStringC(), false);
849 IFX_FileAccess* pFontAccess = nullptr; 854 IFX_FileAccess* pFontAccess = nullptr;
850 if (!m_Hash2FileAccess.Lookup(dwHash, pFontAccess)) { 855 if (!m_Hash2FileAccess.Lookup(dwHash, pFontAccess)) {
851 pFontAccess = FX_CreateDefaultFileAccess(pszFileName); 856 pFontAccess = FX_CreateDefaultFileAccess(pszFileName);
852 m_Hash2FileAccess.SetAt(dwHash, pFontAccess); 857 m_Hash2FileAccess.SetAt(dwHash, pFontAccess);
853 } 858 }
854 859
855 return pFontAccess ? LoadFont(pFontAccess, iFaceIndex, pFaceCount, TRUE) 860 return pFontAccess ? LoadFont(pFontAccess, iFaceIndex, pFaceCount, TRUE)
856 : nullptr; 861 : nullptr;
857 } 862 }
858 863
859 IFX_Font* CFX_FontMgrImp::LoadFont(IFX_Stream* pFontStream, 864 CFX_GEFont* CFX_FontMgrImp::LoadFont(IFX_Stream* pFontStream,
860 int32_t iFaceIndex, 865 int32_t iFaceIndex,
861 int32_t* pFaceCount, 866 int32_t* pFaceCount,
862 FX_BOOL bSaveStream) { 867 FX_BOOL bSaveStream) {
863 void* Hash[1] = {(void*)(uintptr_t)pFontStream}; 868 void* Hash[1] = {(void*)(uintptr_t)pFontStream};
864 uint32_t dwHash = 869 uint32_t dwHash =
865 FX_HashCode_GetA(CFX_ByteStringC((uint8_t*)Hash, sizeof(Hash)), false); 870 FX_HashCode_GetA(CFX_ByteStringC((uint8_t*)Hash, sizeof(Hash)), false);
866 IFX_FileAccess* pFontAccess = nullptr; 871 IFX_FileAccess* pFontAccess = nullptr;
867 m_Hash2FileAccess.Lookup(dwHash, pFontAccess); 872 m_Hash2FileAccess.Lookup(dwHash, pFontAccess);
868 873
869 return pFontAccess ? LoadFont(pFontAccess, iFaceIndex, pFaceCount, TRUE) 874 return pFontAccess ? LoadFont(pFontAccess, iFaceIndex, pFaceCount, TRUE)
870 : nullptr; 875 : nullptr;
871 } 876 }
872 877
873 IFX_Font* CFX_FontMgrImp::LoadFont(IFX_FileAccess* pFontAccess, 878 CFX_GEFont* CFX_FontMgrImp::LoadFont(IFX_FileAccess* pFontAccess,
874 int32_t iFaceIndex, 879 int32_t iFaceIndex,
875 int32_t* pFaceCount, 880 int32_t* pFaceCount,
876 FX_BOOL bWantCache) { 881 FX_BOOL bWantCache) {
877 uint32_t dwHash = 0; 882 uint32_t dwHash = 0;
878 IFX_Font* pFont = nullptr; 883 CFX_GEFont* pFont = nullptr;
879 if (bWantCache) { 884 if (bWantCache) {
880 CFX_ByteString bsHash; 885 CFX_ByteString bsHash;
881 bsHash.Format("%d, %d", (uintptr_t)pFontAccess, iFaceIndex); 886 bsHash.Format("%d, %d", (uintptr_t)pFontAccess, iFaceIndex);
882 dwHash = FX_HashCode_GetA(bsHash.AsStringC(), false); 887 dwHash = FX_HashCode_GetA(bsHash.AsStringC(), false);
883 if (m_FileAccess2IFXFont.Lookup(dwHash, pFont)) { 888 if (m_FileAccess2IFXFont.Lookup(dwHash, pFont)) {
884 if (pFont) { 889 if (pFont) {
885 if (pFaceCount) 890 if (pFaceCount)
886 *pFaceCount = ((CFX_Font*)pFont->GetDevFont())->GetFace()->num_faces; 891 *pFaceCount = ((CFX_Font*)pFont->GetDevFont())->GetFace()->num_faces;
887 return pFont->Retain(); 892 return pFont->Retain();
888 } 893 }
889 } 894 }
890 } 895 }
891 896
892 CFX_Font* pInternalFont = new CFX_Font; 897 CFX_Font* pInternalFont = new CFX_Font;
893 IFX_FileRead* pFontStream = 898 IFX_FileRead* pFontStream =
894 pFontAccess->CreateFileStream(FX_FILEMODE_ReadOnly); 899 pFontAccess->CreateFileStream(FX_FILEMODE_ReadOnly);
895 if (!pFontStream) { 900 if (!pFontStream) {
896 delete pInternalFont; 901 delete pInternalFont;
897 return nullptr; 902 return nullptr;
898 } 903 }
899 if (!pInternalFont->LoadFile(pFontStream, iFaceIndex)) { 904 if (!pInternalFont->LoadFile(pFontStream, iFaceIndex)) {
900 delete pInternalFont; 905 delete pInternalFont;
901 pFontStream->Release(); 906 pFontStream->Release();
902 return nullptr; 907 return nullptr;
903 } 908 }
904 pFont = IFX_Font::LoadFont(pInternalFont, this, TRUE); 909 pFont = CFX_GEFont::LoadFont(pInternalFont, this, TRUE);
905 if (!pFont) { 910 if (!pFont) {
906 delete pInternalFont; 911 delete pInternalFont;
907 pFontStream->Release(); 912 pFontStream->Release();
908 return nullptr; 913 return nullptr;
909 } 914 }
910 if (bWantCache) 915 if (bWantCache)
911 m_FileAccess2IFXFont.SetAt(dwHash, pFont); 916 m_FileAccess2IFXFont.SetAt(dwHash, pFont);
912 917
913 m_IFXFont2FileRead.SetAt(pFont, pFontStream); 918 m_IFXFont2FileRead.SetAt(pFont, pFontStream);
914 if (pFaceCount) 919 if (pFaceCount)
915 *pFaceCount = ((CFX_Font*)pFont->GetDevFont())->GetFace()->num_faces; 920 *pFaceCount = ((CFX_Font*)pFont->GetDevFont())->GetFace()->num_faces;
916 921
917 return pFont; 922 return pFont;
918 } 923 }
919 924
920 IFX_Font* CFX_FontMgrImp::LoadFont(const CFX_WideString& wsFaceName, 925 CFX_GEFont* CFX_FontMgrImp::LoadFont(const CFX_WideString& wsFaceName,
921 int32_t iFaceIndex, 926 int32_t iFaceIndex,
922 int32_t* pFaceCount) { 927 int32_t* pFaceCount) {
923 CFX_FontMgr* pFontMgr = CFX_GEModule::Get()->GetFontMgr(); 928 CFX_FontMgr* pFontMgr = CFX_GEModule::Get()->GetFontMgr();
924 CFX_FontMapper* pFontMapper = pFontMgr->GetBuiltinMapper(); 929 CFX_FontMapper* pFontMapper = pFontMgr->GetBuiltinMapper();
925 if (!pFontMapper) 930 if (!pFontMapper)
926 return nullptr; 931 return nullptr;
927 932
928 IFX_SystemFontInfo* pSystemFontInfo = pFontMapper->GetSystemFontInfo(); 933 IFX_SystemFontInfo* pSystemFontInfo = pFontMapper->GetSystemFontInfo();
929 if (!pSystemFontInfo) 934 if (!pSystemFontInfo)
930 return nullptr; 935 return nullptr;
931 936
932 IFX_FileRead* pFontStream = CreateFontStream(wsFaceName.UTF8Encode()); 937 IFX_FileRead* pFontStream = CreateFontStream(wsFaceName.UTF8Encode());
933 if (!pFontStream) 938 if (!pFontStream)
934 return nullptr; 939 return nullptr;
935 940
936 if (!LoadFace(pFontStream, 0)) { 941 if (!LoadFace(pFontStream, 0)) {
937 pFontStream->Release(); 942 pFontStream->Release();
938 return nullptr; 943 return nullptr;
939 } 944 }
940 945
941 CFX_Font* pInternalFont = new CFX_Font(); 946 CFX_Font* pInternalFont = new CFX_Font();
942 if (!pInternalFont->LoadFile(pFontStream, iFaceIndex)) { 947 if (!pInternalFont->LoadFile(pFontStream, iFaceIndex)) {
943 pFontStream->Release(); 948 pFontStream->Release();
944 return nullptr; 949 return nullptr;
945 } 950 }
946 951
947 IFX_Font* pFont = IFX_Font::LoadFont(pInternalFont, this, FALSE); 952 CFX_GEFont* pFont = CFX_GEFont::LoadFont(pInternalFont, this, FALSE);
948 if (!pFont) { 953 if (!pFont) {
949 pFontStream->Release(); 954 pFontStream->Release();
950 return nullptr; 955 return nullptr;
951 } 956 }
952 957
953 m_IFXFont2FileRead.SetAt(pFont, pFontStream); 958 m_IFXFont2FileRead.SetAt(pFont, pFontStream);
954 if (pFaceCount) 959 if (pFaceCount)
955 *pFaceCount = ((CFX_Font*)pFont->GetDevFont())->GetFace()->num_faces; 960 *pFaceCount = ((CFX_Font*)pFont->GetDevFont())->GetFace()->num_faces;
956 961
957 return pFont; 962 return pFont;
(...skipping 243 matching lines...) Expand 10 before | Expand all | Expand 10 after
1201 FX_POSITION pos = m_Hash2CandidateList.GetStartPosition(); 1206 FX_POSITION pos = m_Hash2CandidateList.GetStartPosition();
1202 while (pos) { 1207 while (pos) {
1203 uint32_t dwHash; 1208 uint32_t dwHash;
1204 CFX_FontDescriptorInfos* pDescs; 1209 CFX_FontDescriptorInfos* pDescs;
1205 m_Hash2CandidateList.GetNextAssoc(pos, dwHash, pDescs); 1210 m_Hash2CandidateList.GetNextAssoc(pos, dwHash, pDescs);
1206 delete pDescs; 1211 delete pDescs;
1207 } 1212 }
1208 pos = m_FileAccess2IFXFont.GetStartPosition(); 1213 pos = m_FileAccess2IFXFont.GetStartPosition();
1209 while (pos) { 1214 while (pos) {
1210 uint32_t dwHash; 1215 uint32_t dwHash;
1211 IFX_Font* pFont; 1216 CFX_GEFont* pFont;
1212 m_FileAccess2IFXFont.GetNextAssoc(pos, dwHash, pFont); 1217 m_FileAccess2IFXFont.GetNextAssoc(pos, dwHash, pFont);
1213 if (NULL != pFont) { 1218 if (NULL != pFont) {
1214 pFont->Release(); 1219 pFont->Release();
1215 } 1220 }
1216 } 1221 }
1217 pos = m_IFXFont2FileRead.GetStartPosition(); 1222 pos = m_IFXFont2FileRead.GetStartPosition();
1218 while (pos) { 1223 while (pos) {
1219 IFX_Font* pFont; 1224 CFX_GEFont* pFont;
1220 IFX_FileRead* pFileRead; 1225 IFX_FileRead* pFileRead;
1221 m_IFXFont2FileRead.GetNextAssoc(pos, pFont, pFileRead); 1226 m_IFXFont2FileRead.GetNextAssoc(pos, pFont, pFileRead);
1222 pFileRead->Release(); 1227 pFileRead->Release();
1223 } 1228 }
1224 } 1229 }
1225 void CFX_FontMgrImp::RemoveFont(IFX_Font* pEFont) { 1230 void CFX_FontMgrImp::RemoveFont(CFX_GEFont* pEFont) {
1226 if (NULL == pEFont) { 1231 if (NULL == pEFont) {
1227 return; 1232 return;
1228 } 1233 }
1229 IFX_FileRead* pFileRead; 1234 IFX_FileRead* pFileRead;
1230 if (m_IFXFont2FileRead.Lookup(pEFont, pFileRead)) { 1235 if (m_IFXFont2FileRead.Lookup(pEFont, pFileRead)) {
1231 pFileRead->Release(); 1236 pFileRead->Release();
1232 m_IFXFont2FileRead.RemoveKey(pEFont); 1237 m_IFXFont2FileRead.RemoveKey(pEFont);
1233 } 1238 }
1234 FX_POSITION pos; 1239 FX_POSITION pos;
1235 pos = m_FileAccess2IFXFont.GetStartPosition(); 1240 pos = m_FileAccess2IFXFont.GetStartPosition();
1236 while (pos) { 1241 while (pos) {
1237 uint32_t dwHash; 1242 uint32_t dwHash;
1238 IFX_Font* pCFont; 1243 CFX_GEFont* pCFont;
1239 m_FileAccess2IFXFont.GetNextAssoc(pos, dwHash, pCFont); 1244 m_FileAccess2IFXFont.GetNextAssoc(pos, dwHash, pCFont);
1240 if (pCFont == pEFont) { 1245 if (pCFont == pEFont) {
1241 m_FileAccess2IFXFont.RemoveKey(dwHash); 1246 m_FileAccess2IFXFont.RemoveKey(dwHash);
1242 break; 1247 break;
1243 } 1248 }
1244 } 1249 }
1245 pos = m_Hash2Fonts.GetStartPosition(); 1250 pos = m_Hash2Fonts.GetStartPosition();
1246 while (pos) { 1251 while (pos) {
1247 uint32_t dwHash; 1252 uint32_t dwHash;
1248 CFX_ArrayTemplate<IFX_Font*>* pFonts; 1253 CFX_ArrayTemplate<CFX_GEFont*>* pFonts;
1249 m_Hash2Fonts.GetNextAssoc(pos, dwHash, pFonts); 1254 m_Hash2Fonts.GetNextAssoc(pos, dwHash, pFonts);
1250 if (NULL != pFonts) { 1255 if (NULL != pFonts) {
1251 for (int32_t i = 0; i < pFonts->GetSize(); i++) { 1256 for (int32_t i = 0; i < pFonts->GetSize(); i++) {
1252 if (pFonts->GetAt(i) == pEFont) { 1257 if (pFonts->GetAt(i) == pEFont) {
1253 pFonts->SetAt(i, NULL); 1258 pFonts->SetAt(i, NULL);
1254 } 1259 }
1255 } 1260 }
1256 } else { 1261 } else {
1257 m_Hash2Fonts.RemoveKey(dwHash); 1262 m_Hash2Fonts.RemoveKey(dwHash);
1258 } 1263 }
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
1486 } 1491 }
1487 } 1492 }
1488 int32_t CFX_FontMgrImp::IsPartName(const CFX_WideString& Name1, 1493 int32_t CFX_FontMgrImp::IsPartName(const CFX_WideString& Name1,
1489 const CFX_WideString& Name2) { 1494 const CFX_WideString& Name2) {
1490 if (Name1.Find(Name2.c_str()) != -1) { 1495 if (Name1.Find(Name2.c_str()) != -1) {
1491 return 1; 1496 return 1;
1492 } 1497 }
1493 return 0; 1498 return 0;
1494 } 1499 }
1495 #endif 1500 #endif
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698