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

Side by Side Diff: core/src/fxge/android/fpf_skiafontmgr.cpp

Issue 1252613002: FX_BOOL considered harmful. (Closed) Base URL: https://pdfium.googlesource.com/pdfium.git@master
Patch Set: Manual edits. Created 5 years, 5 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/android/fpf_skiafontmgr.h ('k') | core/src/fxge/android/fx_android_font.h » ('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 "fx_fpf.h" 7 #include "fx_fpf.h"
8 #if _FX_OS_ == _FX_ANDROID_ 8 #if _FX_OS_ == _FX_ANDROID_
9 #define FPF_SKIAMATCHWEIGHT_NAME1 62 9 #define FPF_SKIAMATCHWEIGHT_NAME1 62
10 #define FPF_SKIAMATCHWEIGHT_NAME2 60 10 #define FPF_SKIAMATCHWEIGHT_NAME2 60
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
96 if (dwHash < pItem->dwFamily) { 96 if (dwHash < pItem->dwFamily) {
97 iEnd = iMid - 1; 97 iEnd = iMid - 1;
98 } else if (dwHash > pItem->dwFamily) { 98 } else if (dwHash > pItem->dwFamily) {
99 iStart = iMid + 1; 99 iStart = iMid + 1;
100 } else { 100 } else {
101 return pItem->dwSubSt; 101 return pItem->dwSubSt;
102 } 102 }
103 } 103 }
104 return 0; 104 return 0;
105 } 105 }
106 static uint32_t FPF_GetHashCode_StringA(const FX_CHAR* pStr, int32_t iLength, FX _BOOL bIgnoreCase = FALSE) 106 static uint32_t FPF_GetHashCode_StringA(const FX_CHAR* pStr, int32_t iLength, bo ol bIgnoreCase = false)
107 { 107 {
108 if (!pStr) { 108 if (!pStr) {
109 return 0; 109 return 0;
110 } 110 }
111 if (iLength < 0) { 111 if (iLength < 0) {
112 iLength = FXSYS_strlen(pStr); 112 iLength = FXSYS_strlen(pStr);
113 } 113 }
114 const FX_CHAR* pStrEnd = pStr + iLength; 114 const FX_CHAR* pStrEnd = pStr + iLength;
115 uint32_t uHashCode = 0; 115 uint32_t uHashCode = 0;
116 if (bIgnoreCase) { 116 if (bIgnoreCase) {
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 if (dwStyle & FXFONT_BOLD) { 201 if (dwStyle & FXFONT_BOLD) {
202 bsFont += "Bold"; 202 bsFont += "Bold";
203 } 203 }
204 if (dwStyle & FXFONT_ITALIC) { 204 if (dwStyle & FXFONT_ITALIC) {
205 bsFont += "Italic"; 205 bsFont += "Italic";
206 } 206 }
207 if (dwStyle & FXFONT_SERIF) { 207 if (dwStyle & FXFONT_SERIF) {
208 bsFont += "Serif"; 208 bsFont += "Serif";
209 } 209 }
210 bsFont += uCharset; 210 bsFont += uCharset;
211 return FPF_GetHashCode_StringA(bsFont.c_str(), bsFont.GetLength(), TRUE); 211 return FPF_GetHashCode_StringA(bsFont.c_str(), bsFont.GetLength(), true);
212 } 212 }
213 static FX_BOOL FPF_SkiaIsCJK(uint8_t uCharset) 213 static bool FPF_SkiaIsCJK(uint8_t uCharset)
214 { 214 {
215 return (uCharset == FXFONT_GB2312_CHARSET) || (uCharset == FXFONT_CHINESEBIG 5_CHARSET) 215 return (uCharset == FXFONT_GB2312_CHARSET) || (uCharset == FXFONT_CHINESEBIG 5_CHARSET)
216 || (uCharset == FXFONT_HANGEUL_CHARSET) || (uCharset == FXFONT_SHIFTJ IS_CHARSET); 216 || (uCharset == FXFONT_HANGEUL_CHARSET) || (uCharset == FXFONT_SHIFTJ IS_CHARSET);
217 } 217 }
218 static FX_BOOL FPF_SkiaMaybeSymbol(const CFX_ByteStringC& bsFacename) 218 static bool FPF_SkiaMaybeSymbol(const CFX_ByteStringC& bsFacename)
219 { 219 {
220 CFX_ByteString bsName = bsFacename; 220 CFX_ByteString bsName = bsFacename;
221 bsName.MakeLower(); 221 bsName.MakeLower();
222 return bsName.Find("symbol") > -1; 222 return bsName.Find("symbol") > -1;
223 } 223 }
224 static FX_BOOL FPF_SkiaMaybeArabic(const CFX_ByteStringC& bsFacename) 224 static bool FPF_SkiaMaybeArabic(const CFX_ByteStringC& bsFacename)
225 { 225 {
226 CFX_ByteString bsName = bsFacename; 226 CFX_ByteString bsName = bsFacename;
227 bsName.MakeLower(); 227 bsName.MakeLower();
228 return bsName.Find("arabic") > -1; 228 return bsName.Find("arabic") > -1;
229 } 229 }
230 CFPF_SkiaFontMgr::CFPF_SkiaFontMgr() 230 CFPF_SkiaFontMgr::CFPF_SkiaFontMgr()
231 : m_bLoaded(FALSE), m_FTLibrary(NULL) 231 : m_bLoaded(false), m_FTLibrary(NULL)
232 { 232 {
233 } 233 }
234 CFPF_SkiaFontMgr::~CFPF_SkiaFontMgr() 234 CFPF_SkiaFontMgr::~CFPF_SkiaFontMgr()
235 { 235 {
236 void *pkey = NULL; 236 void *pkey = NULL;
237 CFPF_SkiaFont *pValue = NULL; 237 CFPF_SkiaFont *pValue = NULL;
238 FX_POSITION pos = m_FamilyFonts.GetStartPosition(); 238 FX_POSITION pos = m_FamilyFonts.GetStartPosition();
239 while (pos) { 239 while (pos) {
240 m_FamilyFonts.GetNextAssoc(pos, pkey, (void*&)pValue); 240 m_FamilyFonts.GetNextAssoc(pos, pkey, (void*&)pValue);
241 if (pValue) { 241 if (pValue) {
242 pValue->Release(); 242 pValue->Release();
243 } 243 }
244 } 244 }
245 m_FamilyFonts.RemoveAll(); 245 m_FamilyFonts.RemoveAll();
246 for (int32_t i = m_FontFaces.GetUpperBound(); i >= 0; i--) { 246 for (int32_t i = m_FontFaces.GetUpperBound(); i >= 0; i--) {
247 CFPF_SkiaFontDescriptor *pFont = (CFPF_SkiaFontDescriptor*)m_FontFaces.E lementAt(i); 247 CFPF_SkiaFontDescriptor *pFont = (CFPF_SkiaFontDescriptor*)m_FontFaces.E lementAt(i);
248 delete pFont; 248 delete pFont;
249 } 249 }
250 m_FontFaces.RemoveAll(); 250 m_FontFaces.RemoveAll();
251 if (m_FTLibrary) { 251 if (m_FTLibrary) {
252 FXFT_Done_FreeType(m_FTLibrary); 252 FXFT_Done_FreeType(m_FTLibrary);
253 } 253 }
254 } 254 }
255 FX_BOOL CFPF_SkiaFontMgr::InitFTLibrary() 255 bool CFPF_SkiaFontMgr::InitFTLibrary()
256 { 256 {
257 if (m_FTLibrary == NULL) { 257 if (m_FTLibrary == NULL) {
258 FXFT_Init_FreeType(&m_FTLibrary); 258 FXFT_Init_FreeType(&m_FTLibrary);
259 } 259 }
260 return m_FTLibrary != NULL; 260 return m_FTLibrary != NULL;
261 } 261 }
262 void CFPF_SkiaFontMgr::LoadSystemFonts() 262 void CFPF_SkiaFontMgr::LoadSystemFonts()
263 { 263 {
264 if (m_bLoaded) { 264 if (m_bLoaded) {
265 return; 265 return;
266 } 266 }
267 ScanPath(FX_BSTRC("/system/fonts")); 267 ScanPath(FX_BSTRC("/system/fonts"));
268 OutputSystemFonts(); 268 OutputSystemFonts();
269 m_bLoaded = TRUE; 269 m_bLoaded = true;
270 } 270 }
271 void CFPF_SkiaFontMgr::LoadPrivateFont(IFX_FileRead* pFontFile) 271 void CFPF_SkiaFontMgr::LoadPrivateFont(IFX_FileRead* pFontFile)
272 { 272 {
273 } 273 }
274 void CFPF_SkiaFontMgr::LoadPrivateFont(const CFX_ByteStringC& bsFileName) 274 void CFPF_SkiaFontMgr::LoadPrivateFont(const CFX_ByteStringC& bsFileName)
275 { 275 {
276 } 276 }
277 void CFPF_SkiaFontMgr::LoadPrivateFont(void* pBuffer, size_t szBuffer) 277 void CFPF_SkiaFontMgr::LoadPrivateFont(void* pBuffer, size_t szBuffer)
278 { 278 {
279 } 279 }
280 IFPF_Font* CFPF_SkiaFontMgr::CreateFont(const CFX_ByteStringC& bsFamilyname, uin t8_t uCharset, FX_DWORD dwStyle, FX_DWORD dwMatch) 280 IFPF_Font* CFPF_SkiaFontMgr::CreateFont(const CFX_ByteStringC& bsFamilyname, uin t8_t uCharset, FX_DWORD dwStyle, FX_DWORD dwMatch)
281 { 281 {
282 FX_DWORD dwHash = FPF_SKIAGetFamilyHash(bsFamilyname, dwStyle, uCharset); 282 FX_DWORD dwHash = FPF_SKIAGetFamilyHash(bsFamilyname, dwStyle, uCharset);
283 IFPF_Font *pFont = NULL; 283 IFPF_Font *pFont = NULL;
284 if (m_FamilyFonts.Lookup((void*)(uintptr_t)dwHash, (void*&)pFont)) { 284 if (m_FamilyFonts.Lookup((void*)(uintptr_t)dwHash, (void*&)pFont)) {
285 if (pFont) { 285 if (pFont) {
286 return pFont->Retain(); 286 return pFont->Retain();
287 } 287 }
288 } 288 }
289 FX_DWORD dwFaceName = FPF_SKIANormalizeFontName(bsFamilyname); 289 FX_DWORD dwFaceName = FPF_SKIANormalizeFontName(bsFamilyname);
290 FX_DWORD dwSubst = FPF_SkiaGetSubstFont(dwFaceName); 290 FX_DWORD dwSubst = FPF_SkiaGetSubstFont(dwFaceName);
291 FX_DWORD dwSubstSans = FPF_SkiaGetSansFont(dwFaceName); 291 FX_DWORD dwSubstSans = FPF_SkiaGetSansFont(dwFaceName);
292 FX_BOOL bMaybeSymbol = FPF_SkiaMaybeSymbol(bsFamilyname); 292 bool bMaybeSymbol = FPF_SkiaMaybeSymbol(bsFamilyname);
293 if (uCharset != FXFONT_ARABIC_CHARSET && FPF_SkiaMaybeArabic(bsFamilyname)) { 293 if (uCharset != FXFONT_ARABIC_CHARSET && FPF_SkiaMaybeArabic(bsFamilyname)) {
294 uCharset = FXFONT_ARABIC_CHARSET; 294 uCharset = FXFONT_ARABIC_CHARSET;
295 } else if (uCharset == FXFONT_ANSI_CHARSET && (dwMatch & FPF_MATCHFONT_REPLA CEANSI)) { 295 } else if (uCharset == FXFONT_ANSI_CHARSET && (dwMatch & FPF_MATCHFONT_REPLA CEANSI)) {
296 uCharset = FXFONT_DEFAULT_CHARSET; 296 uCharset = FXFONT_DEFAULT_CHARSET;
297 } 297 }
298 int32_t nExpectVal = FPF_SKIAMATCHWEIGHT_NAME1 + FPF_SKIAMATCHWEIGHT_1 * 3 + FPF_SKIAMATCHWEIGHT_2 * 2; 298 int32_t nExpectVal = FPF_SKIAMATCHWEIGHT_NAME1 + FPF_SKIAMATCHWEIGHT_1 * 3 + FPF_SKIAMATCHWEIGHT_2 * 2;
299 int32_t nItem = -1; 299 int32_t nItem = -1;
300 int32_t nMax = -1; 300 int32_t nMax = -1;
301 int32_t nGlyphNum = 0; 301 int32_t nGlyphNum = 0;
302 for (int32_t i = m_FontFaces.GetUpperBound(); i >= 0; i--) { 302 for (int32_t i = m_FontFaces.GetUpperBound(); i >= 0; i--) {
303 CFPF_SkiaPathFont *pFontDes = (CFPF_SkiaPathFont*)m_FontFaces.ElementAt( i); 303 CFPF_SkiaPathFont *pFontDes = (CFPF_SkiaPathFont*)m_FontFaces.ElementAt( i);
304 if(!(pFontDes->m_dwCharsets & FPF_SkiaGetCharset(uCharset))) { 304 if(!(pFontDes->m_dwCharsets & FPF_SkiaGetCharset(uCharset))) {
305 continue; 305 continue;
306 } 306 }
307 int32_t nFind = 0; 307 int32_t nFind = 0;
308 FX_DWORD dwSysFontName = FPF_SKIANormalizeFontName(pFontDes->m_pFamily); 308 FX_DWORD dwSysFontName = FPF_SKIANormalizeFontName(pFontDes->m_pFamily);
309 if (dwFaceName == dwSysFontName) { 309 if (dwFaceName == dwSysFontName) {
310 nFind += FPF_SKIAMATCHWEIGHT_NAME1; 310 nFind += FPF_SKIAMATCHWEIGHT_NAME1;
311 } 311 }
312 FX_BOOL bMatchedName = (nFind == FPF_SKIAMATCHWEIGHT_NAME1); 312 bool bMatchedName = (nFind == FPF_SKIAMATCHWEIGHT_NAME1);
313 if ((dwStyle & FXFONT_BOLD) == (pFontDes->m_dwStyle & FXFONT_BOLD)) { 313 if ((dwStyle & FXFONT_BOLD) == (pFontDes->m_dwStyle & FXFONT_BOLD)) {
314 nFind += FPF_SKIAMATCHWEIGHT_1; 314 nFind += FPF_SKIAMATCHWEIGHT_1;
315 } 315 }
316 if ((dwStyle & FXFONT_ITALIC) == (pFontDes->m_dwStyle & FXFONT_ITALIC)) { 316 if ((dwStyle & FXFONT_ITALIC) == (pFontDes->m_dwStyle & FXFONT_ITALIC)) {
317 nFind += FPF_SKIAMATCHWEIGHT_1; 317 nFind += FPF_SKIAMATCHWEIGHT_1;
318 } 318 }
319 if ((dwStyle & FXFONT_FIXED_PITCH) == (pFontDes->m_dwStyle & FXFONT_FIXE D_PITCH)) { 319 if ((dwStyle & FXFONT_FIXED_PITCH) == (pFontDes->m_dwStyle & FXFONT_FIXE D_PITCH)) {
320 nFind += FPF_SKIAMATCHWEIGHT_2; 320 nFind += FPF_SKIAMATCHWEIGHT_2;
321 } 321 }
322 if ((dwStyle & FXFONT_SERIF) == (pFontDes->m_dwStyle & FXFONT_SERIF)) { 322 if ((dwStyle & FXFONT_SERIF) == (pFontDes->m_dwStyle & FXFONT_SERIF)) {
323 nFind += FPF_SKIAMATCHWEIGHT_1; 323 nFind += FPF_SKIAMATCHWEIGHT_1;
324 } 324 }
325 if ((dwStyle & FXFONT_SCRIPT) == (pFontDes->m_dwStyle & FXFONT_SCRIPT)) { 325 if ((dwStyle & FXFONT_SCRIPT) == (pFontDes->m_dwStyle & FXFONT_SCRIPT)) {
326 nFind += FPF_SKIAMATCHWEIGHT_2; 326 nFind += FPF_SKIAMATCHWEIGHT_2;
327 } 327 }
328 if (dwSubst == dwSysFontName || dwSubstSans == dwSysFontName) { 328 if (dwSubst == dwSysFontName || dwSubstSans == dwSysFontName) {
329 nFind += FPF_SKIAMATCHWEIGHT_NAME2; 329 nFind += FPF_SKIAMATCHWEIGHT_NAME2;
330 bMatchedName = TRUE; 330 bMatchedName = true;
331 } 331 }
332 if (uCharset == FXFONT_DEFAULT_CHARSET || bMaybeSymbol) { 332 if (uCharset == FXFONT_DEFAULT_CHARSET || bMaybeSymbol) {
333 if (nFind > nMax && bMatchedName) { 333 if (nFind > nMax && bMatchedName) {
334 nMax = nFind; 334 nMax = nFind;
335 nItem = i; 335 nItem = i;
336 } 336 }
337 } else if (FPF_SkiaIsCJK(uCharset)) { 337 } else if (FPF_SkiaIsCJK(uCharset)) {
338 if (bMatchedName || pFontDes->m_iGlyphNum > nGlyphNum) { 338 if (bMatchedName || pFontDes->m_iGlyphNum > nGlyphNum) {
339 nItem = i; 339 nItem = i;
340 nGlyphNum = pFontDes->m_iGlyphNum; 340 nGlyphNum = pFontDes->m_iGlyphNum;
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
392 return NULL; 392 return NULL;
393 } 393 }
394 if (iFaceIndex < 0) { 394 if (iFaceIndex < 0) {
395 return NULL; 395 return NULL;
396 } 396 }
397 FXFT_Open_Args args; 397 FXFT_Open_Args args;
398 args.flags = FT_OPEN_PATHNAME; 398 args.flags = FT_OPEN_PATHNAME;
399 args.pathname = (FT_String*)bsFile.GetCStr(); 399 args.pathname = (FT_String*)bsFile.GetCStr();
400 FXFT_Face face; 400 FXFT_Face face;
401 if (FXFT_Open_Face(m_FTLibrary, &args, iFaceIndex, &face)) { 401 if (FXFT_Open_Face(m_FTLibrary, &args, iFaceIndex, &face)) {
402 return FALSE; 402 return false;
403 } 403 }
404 FXFT_Set_Pixel_Sizes(face, 0, 64); 404 FXFT_Set_Pixel_Sizes(face, 0, 64);
405 return face; 405 return face;
406 } 406 }
407 FXFT_Face CFPF_SkiaFontMgr::GetFontFace(const uint8_t* pBuffer, size_t szBuffer, int32_t iFaceIndex ) 407 FXFT_Face CFPF_SkiaFontMgr::GetFontFace(const uint8_t* pBuffer, size_t szBuffer, int32_t iFaceIndex )
408 { 408 {
409 if (!pBuffer || szBuffer < 1) { 409 if (!pBuffer || szBuffer < 1) {
410 return NULL; 410 return NULL;
411 } 411 }
412 if (iFaceIndex < 0) { 412 if (iFaceIndex < 0) {
413 return NULL; 413 return NULL;
414 } 414 }
415 FXFT_Open_Args args; 415 FXFT_Open_Args args;
416 args.flags = FT_OPEN_MEMORY; 416 args.flags = FT_OPEN_MEMORY;
417 args.memory_base = pBuffer; 417 args.memory_base = pBuffer;
418 args.memory_size = szBuffer; 418 args.memory_size = szBuffer;
419 FXFT_Face face; 419 FXFT_Face face;
420 if (FXFT_Open_Face(m_FTLibrary, &args, iFaceIndex, &face)) { 420 if (FXFT_Open_Face(m_FTLibrary, &args, iFaceIndex, &face)) {
421 return FALSE; 421 return false;
422 } 422 }
423 FXFT_Set_Pixel_Sizes(face, 0, 64); 423 FXFT_Set_Pixel_Sizes(face, 0, 64);
424 return face; 424 return face;
425 } 425 }
426 void CFPF_SkiaFontMgr::ScanPath(const CFX_ByteStringC& path) 426 void CFPF_SkiaFontMgr::ScanPath(const CFX_ByteStringC& path)
427 { 427 {
428 void *handle = FX_OpenFolder(path.GetCStr()); 428 void *handle = FX_OpenFolder(path.GetCStr());
429 if (!handle) { 429 if (!handle) {
430 return; 430 return;
431 } 431 }
432 CFX_ByteString filename; 432 CFX_ByteString filename;
433 FX_BOOL» bFolder = FALSE; 433 bool» bFolder = false;
434 while (FX_GetNextFile(handle, filename, bFolder)) { 434 while (FX_GetNextFile(handle, filename, bFolder)) {
435 if (bFolder) { 435 if (bFolder) {
436 if (filename == FX_BSTRC(".") || filename == FX_BSTRC("..")) { 436 if (filename == FX_BSTRC(".") || filename == FX_BSTRC("..")) {
437 continue; 437 continue;
438 } 438 }
439 } else { 439 } else {
440 CFX_ByteString ext = filename.Right(4); 440 CFX_ByteString ext = filename.Right(4);
441 ext.MakeLower(); 441 ext.MakeLower();
442 if (ext != FX_BSTRC(".ttf") && ext != FX_BSTRC(".ttc")) { 442 if (ext != FX_BSTRC(".ttf") && ext != FX_BSTRC(".ttc")) {
443 continue; 443 continue;
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
543 pFontDesc->m_dwStyle |= FXFONT_SYMBOLIC; 543 pFontDesc->m_dwStyle |= FXFONT_SYMBOLIC;
544 } 544 }
545 pFontDesc->m_dwCharsets = FPF_SkiaGetFaceCharset(pOS2); 545 pFontDesc->m_dwCharsets = FPF_SkiaGetFaceCharset(pOS2);
546 pFontDesc->m_iFaceIndex = face->face_index; 546 pFontDesc->m_iFaceIndex = face->face_index;
547 pFontDesc->m_iGlyphNum = face->num_glyphs; 547 pFontDesc->m_iGlyphNum = face->num_glyphs;
548 } 548 }
549 void CFPF_SkiaFontMgr::OutputSystemFonts() 549 void CFPF_SkiaFontMgr::OutputSystemFonts()
550 { 550 {
551 } 551 }
552 #endif 552 #endif
OLDNEW
« no previous file with comments | « core/src/fxge/android/fpf_skiafontmgr.h ('k') | core/src/fxge/android/fx_android_font.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698