| 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/fxcrt/include/fx_system.h" | 7 #include "core/fxcrt/include/fx_system.h" |
| 8 | 8 |
| 9 #if _FX_OS_ == _FX_ANDROID_ | 9 #if _FX_OS_ == _FX_ANDROID_ |
| 10 | 10 |
| (...skipping 12 matching lines...) Expand all Loading... |
| 23 #endif | 23 #endif |
| 24 static unsigned long FPF_SkiaStream_Read(FXFT_Stream stream, | 24 static unsigned long FPF_SkiaStream_Read(FXFT_Stream stream, |
| 25 unsigned long offset, | 25 unsigned long offset, |
| 26 unsigned char* buffer, | 26 unsigned char* buffer, |
| 27 unsigned long count) { | 27 unsigned long count) { |
| 28 IFX_FileRead* pFileRead = (IFX_FileRead*)stream->descriptor.pointer; | 28 IFX_FileRead* pFileRead = (IFX_FileRead*)stream->descriptor.pointer; |
| 29 if (!pFileRead) { | 29 if (!pFileRead) { |
| 30 return 0; | 30 return 0; |
| 31 } | 31 } |
| 32 if (count > 0) { | 32 if (count > 0) { |
| 33 if (pFileRead->ReadBlock(buffer, (FX_FILESIZE)offset, (size_t)count) != | 33 if (!pFileRead->ReadBlock(buffer, (FX_FILESIZE)offset, (size_t)count)) { |
| 34 count) { | |
| 35 return 0; | 34 return 0; |
| 36 } | 35 } |
| 37 } | 36 } |
| 38 return count; | 37 return count; |
| 39 } | 38 } |
| 40 static void FPF_SkiaStream_Close(FXFT_Stream stream) {} | 39 static void FPF_SkiaStream_Close(FXFT_Stream stream) {} |
| 41 #ifdef __cplusplus | 40 #ifdef __cplusplus |
| 42 }; | 41 }; |
| 43 #endif | 42 #endif |
| 44 struct FPF_SKIAFONTMAP { | 43 struct FPF_SKIAFONTMAP { |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 202 bsFont += uCharset; | 201 bsFont += uCharset; |
| 203 return FPF_GetHashCode_StringA(bsFont.c_str(), bsFont.GetLength(), TRUE); | 202 return FPF_GetHashCode_StringA(bsFont.c_str(), bsFont.GetLength(), TRUE); |
| 204 } | 203 } |
| 205 static FX_BOOL FPF_SkiaIsCJK(uint8_t uCharset) { | 204 static FX_BOOL FPF_SkiaIsCJK(uint8_t uCharset) { |
| 206 return (uCharset == FXFONT_GB2312_CHARSET) || | 205 return (uCharset == FXFONT_GB2312_CHARSET) || |
| 207 (uCharset == FXFONT_CHINESEBIG5_CHARSET) || | 206 (uCharset == FXFONT_CHINESEBIG5_CHARSET) || |
| 208 (uCharset == FXFONT_HANGEUL_CHARSET) || | 207 (uCharset == FXFONT_HANGEUL_CHARSET) || |
| 209 (uCharset == FXFONT_SHIFTJIS_CHARSET); | 208 (uCharset == FXFONT_SHIFTJIS_CHARSET); |
| 210 } | 209 } |
| 211 static FX_BOOL FPF_SkiaMaybeSymbol(const CFX_ByteStringC& bsFacename) { | 210 static FX_BOOL FPF_SkiaMaybeSymbol(const CFX_ByteStringC& bsFacename) { |
| 212 CFX_ByteString bsName = bsFacename; | 211 CFX_ByteString bsName(bsFacename); |
| 213 bsName.MakeLower(); | 212 bsName.MakeLower(); |
| 214 return bsName.Find("symbol") > -1; | 213 return bsName.Find("symbol") > -1; |
| 215 } | 214 } |
| 216 static FX_BOOL FPF_SkiaMaybeArabic(const CFX_ByteStringC& bsFacename) { | 215 static FX_BOOL FPF_SkiaMaybeArabic(const CFX_ByteStringC& bsFacename) { |
| 217 CFX_ByteString bsName = bsFacename; | 216 CFX_ByteString bsName(bsFacename); |
| 218 bsName.MakeLower(); | 217 bsName.MakeLower(); |
| 219 return bsName.Find("arabic") > -1; | 218 return bsName.Find("arabic") > -1; |
| 220 } | 219 } |
| 221 CFPF_SkiaFontMgr::CFPF_SkiaFontMgr() : m_bLoaded(FALSE), m_FTLibrary(nullptr) {} | 220 CFPF_SkiaFontMgr::CFPF_SkiaFontMgr() : m_bLoaded(FALSE), m_FTLibrary(nullptr) {} |
| 222 CFPF_SkiaFontMgr::~CFPF_SkiaFontMgr() { | 221 CFPF_SkiaFontMgr::~CFPF_SkiaFontMgr() { |
| 223 for (const auto& pair : m_FamilyFonts) { | 222 for (const auto& pair : m_FamilyFonts) { |
| 224 if (pair.second) | 223 if (pair.second) |
| 225 pair.second->Release(); | 224 pair.second->Release(); |
| 226 } | 225 } |
| 227 m_FamilyFonts.clear(); | 226 m_FamilyFonts.clear(); |
| (...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 364 FXFT_Face CFPF_SkiaFontMgr::GetFontFace(const CFX_ByteStringC& bsFile, | 363 FXFT_Face CFPF_SkiaFontMgr::GetFontFace(const CFX_ByteStringC& bsFile, |
| 365 int32_t iFaceIndex) { | 364 int32_t iFaceIndex) { |
| 366 if (bsFile.IsEmpty()) { | 365 if (bsFile.IsEmpty()) { |
| 367 return nullptr; | 366 return nullptr; |
| 368 } | 367 } |
| 369 if (iFaceIndex < 0) { | 368 if (iFaceIndex < 0) { |
| 370 return nullptr; | 369 return nullptr; |
| 371 } | 370 } |
| 372 FXFT_Open_Args args; | 371 FXFT_Open_Args args; |
| 373 args.flags = FT_OPEN_PATHNAME; | 372 args.flags = FT_OPEN_PATHNAME; |
| 374 args.pathname = static_cast<FT_String*>(bsFile.c_str()); | 373 args.pathname = const_cast<FT_String*>(bsFile.c_str()); |
| 375 FXFT_Face face; | 374 FXFT_Face face; |
| 376 if (FXFT_Open_Face(m_FTLibrary, &args, iFaceIndex, &face)) { | 375 if (FXFT_Open_Face(m_FTLibrary, &args, iFaceIndex, &face)) { |
| 377 return FALSE; | 376 return FALSE; |
| 378 } | 377 } |
| 379 FXFT_Set_Pixel_Sizes(face, 0, 64); | 378 FXFT_Set_Pixel_Sizes(face, 0, 64); |
| 380 return face; | 379 return face; |
| 381 } | 380 } |
| 382 FXFT_Face CFPF_SkiaFontMgr::GetFontFace(const uint8_t* pBuffer, | 381 FXFT_Face CFPF_SkiaFontMgr::GetFontFace(const uint8_t* pBuffer, |
| 383 size_t szBuffer, | 382 size_t szBuffer, |
| 384 int32_t iFaceIndex) { | 383 int32_t iFaceIndex) { |
| 385 if (!pBuffer || szBuffer < 1) { | 384 if (!pBuffer || szBuffer < 1) { |
| 386 return nullptr; | 385 return nullptr; |
| 387 } | 386 } |
| 388 if (iFaceIndex < 0) { | 387 if (iFaceIndex < 0) { |
| 389 return nullptr; | 388 return nullptr; |
| 390 } | 389 } |
| 391 FXFT_Open_Args args; | 390 FXFT_Open_Args args; |
| 392 args.flags = FT_OPEN_MEMORY; | 391 args.flags = FT_OPEN_MEMORY; |
| 393 args.memory_base = pBuffer; | 392 args.memory_base = pBuffer; |
| 394 args.memory_size = szBuffer; | 393 args.memory_size = szBuffer; |
| 395 FXFT_Face face; | 394 FXFT_Face face; |
| 396 if (FXFT_Open_Face(m_FTLibrary, &args, iFaceIndex, &face)) { | 395 if (FXFT_Open_Face(m_FTLibrary, &args, iFaceIndex, &face)) { |
| 397 return FALSE; | 396 return FALSE; |
| 398 } | 397 } |
| 399 FXFT_Set_Pixel_Sizes(face, 0, 64); | 398 FXFT_Set_Pixel_Sizes(face, 0, 64); |
| 400 return face; | 399 return face; |
| 401 } | 400 } |
| 402 void CFPF_SkiaFontMgr::ScanPath(const CFX_ByteStringC& path) { | 401 void CFPF_SkiaFontMgr::ScanPath(const CFX_ByteString& path) { |
| 403 void* handle = FX_OpenFolder(path.c_str()); | 402 void* handle = FX_OpenFolder(path.c_str()); |
| 404 if (!handle) { | 403 if (!handle) { |
| 405 return; | 404 return; |
| 406 } | 405 } |
| 407 CFX_ByteString filename; | 406 CFX_ByteString filename; |
| 408 FX_BOOL bFolder = FALSE; | 407 FX_BOOL bFolder = FALSE; |
| 409 while (FX_GetNextFile(handle, filename, bFolder)) { | 408 while (FX_GetNextFile(handle, filename, bFolder)) { |
| 410 if (bFolder) { | 409 if (bFolder) { |
| 411 if (filename == "." || filename == "..") { | 410 if (filename == "." || filename == "..") { |
| 412 continue; | 411 continue; |
| 413 } | 412 } |
| 414 } else { | 413 } else { |
| 415 CFX_ByteString ext = filename.Right(4); | 414 CFX_ByteString ext = filename.Right(4); |
| 416 ext.MakeLower(); | 415 ext.MakeLower(); |
| 417 if (ext != ".ttf" && ext != ".ttc" && ext != ".otf") { | 416 if (ext != ".ttf" && ext != ".ttc" && ext != ".otf") { |
| 418 continue; | 417 continue; |
| 419 } | 418 } |
| 420 } | 419 } |
| 421 CFX_ByteString fullpath = path; | 420 CFX_ByteString fullpath(path); |
| 422 fullpath += "/"; | 421 fullpath += "/"; |
| 423 fullpath += filename; | 422 fullpath += filename; |
| 424 if (bFolder) { | 423 if (bFolder) { |
| 425 ScanPath(fullpath); | 424 ScanPath(fullpath); |
| 426 } else { | 425 } else { |
| 427 ScanFile(fullpath); | 426 ScanFile(fullpath); |
| 428 } | 427 } |
| 429 } | 428 } |
| 430 FX_CloseFolder(handle); | 429 FX_CloseFolder(handle); |
| 431 } | 430 } |
| 432 void CFPF_SkiaFontMgr::ScanFile(const CFX_ByteStringC& file) { | 431 void CFPF_SkiaFontMgr::ScanFile(const CFX_ByteString& file) { |
| 433 FXFT_Face face = GetFontFace(file); | 432 FXFT_Face face = GetFontFace(file.AsStringC()); |
| 434 if (face) { | 433 if (face) { |
| 435 CFPF_SkiaPathFont* pFontDesc = new CFPF_SkiaPathFont; | 434 CFPF_SkiaPathFont* pFontDesc = new CFPF_SkiaPathFont; |
| 436 pFontDesc->SetPath(file.c_str()); | 435 pFontDesc->SetPath(file.c_str()); |
| 437 ReportFace(face, pFontDesc); | 436 ReportFace(face, pFontDesc); |
| 438 m_FontFaces.push_back(pFontDesc); | 437 m_FontFaces.push_back(pFontDesc); |
| 439 FXFT_Done_Face(face); | 438 FXFT_Done_Face(face); |
| 440 } | 439 } |
| 441 } | 440 } |
| 442 static const uint32_t g_FPFSkiaFontCharsets[] = { | 441 static const uint32_t g_FPFSkiaFontCharsets[] = { |
| 443 FPF_SKIACHARSET_Ansi, | 442 FPF_SKIACHARSET_Ansi, |
| (...skipping 70 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 514 } | 513 } |
| 515 if (pOS2 && (pOS2->ulCodePageRange1 & (1 << 31))) { | 514 if (pOS2 && (pOS2->ulCodePageRange1 & (1 << 31))) { |
| 516 pFontDesc->m_dwStyle |= FXFONT_SYMBOLIC; | 515 pFontDesc->m_dwStyle |= FXFONT_SYMBOLIC; |
| 517 } | 516 } |
| 518 pFontDesc->m_dwCharsets = FPF_SkiaGetFaceCharset(pOS2); | 517 pFontDesc->m_dwCharsets = FPF_SkiaGetFaceCharset(pOS2); |
| 519 pFontDesc->m_iFaceIndex = face->face_index; | 518 pFontDesc->m_iFaceIndex = face->face_index; |
| 520 pFontDesc->m_iGlyphNum = face->num_glyphs; | 519 pFontDesc->m_iGlyphNum = face->num_glyphs; |
| 521 } | 520 } |
| 522 void CFPF_SkiaFontMgr::OutputSystemFonts() {} | 521 void CFPF_SkiaFontMgr::OutputSystemFonts() {} |
| 523 #endif | 522 #endif |
| OLD | NEW |