| 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 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 211 static FX_BOOL FPF_SkiaMaybeSymbol(const CFX_ByteStringC& bsFacename) { | 211 static FX_BOOL FPF_SkiaMaybeSymbol(const CFX_ByteStringC& bsFacename) { |
| 212 CFX_ByteString bsName = bsFacename; | 212 CFX_ByteString bsName = bsFacename; |
| 213 bsName.MakeLower(); | 213 bsName.MakeLower(); |
| 214 return bsName.Find("symbol") > -1; | 214 return bsName.Find("symbol") > -1; |
| 215 } | 215 } |
| 216 static FX_BOOL FPF_SkiaMaybeArabic(const CFX_ByteStringC& bsFacename) { | 216 static FX_BOOL FPF_SkiaMaybeArabic(const CFX_ByteStringC& bsFacename) { |
| 217 CFX_ByteString bsName = bsFacename; | 217 CFX_ByteString bsName = bsFacename; |
| 218 bsName.MakeLower(); | 218 bsName.MakeLower(); |
| 219 return bsName.Find("arabic") > -1; | 219 return bsName.Find("arabic") > -1; |
| 220 } | 220 } |
| 221 CFPF_SkiaFontMgr::CFPF_SkiaFontMgr() : m_bLoaded(FALSE), m_FTLibrary(NULL) {} | 221 CFPF_SkiaFontMgr::CFPF_SkiaFontMgr() : m_bLoaded(FALSE), m_FTLibrary(nullptr) {} |
| 222 CFPF_SkiaFontMgr::~CFPF_SkiaFontMgr() { | 222 CFPF_SkiaFontMgr::~CFPF_SkiaFontMgr() { |
| 223 for (const auto& pair : m_FamilyFonts) { | 223 for (const auto& pair : m_FamilyFonts) { |
| 224 if (pair.second) | 224 if (pair.second) |
| 225 pair.second->Release(); | 225 pair.second->Release(); |
| 226 } | 226 } |
| 227 m_FamilyFonts.clear(); | 227 m_FamilyFonts.clear(); |
| 228 for (auto it = m_FontFaces.rbegin(); it != m_FontFaces.rend(); ++it) { | 228 for (auto it = m_FontFaces.rbegin(); it != m_FontFaces.rend(); ++it) { |
| 229 delete *it; | 229 delete *it; |
| 230 } | 230 } |
| 231 m_FontFaces.clear(); | 231 m_FontFaces.clear(); |
| 232 if (m_FTLibrary) { | 232 if (m_FTLibrary) { |
| 233 FXFT_Done_FreeType(m_FTLibrary); | 233 FXFT_Done_FreeType(m_FTLibrary); |
| 234 } | 234 } |
| 235 } | 235 } |
| 236 FX_BOOL CFPF_SkiaFontMgr::InitFTLibrary() { | 236 FX_BOOL CFPF_SkiaFontMgr::InitFTLibrary() { |
| 237 if (!m_FTLibrary) { | 237 if (!m_FTLibrary) |
| 238 FXFT_Init_FreeType(&m_FTLibrary); | 238 FXFT_Init_FreeType(&m_FTLibrary); |
| 239 } | 239 return !!m_FTLibrary; |
| 240 return m_FTLibrary != NULL; | |
| 241 } | 240 } |
| 242 void CFPF_SkiaFontMgr::LoadSystemFonts() { | 241 void CFPF_SkiaFontMgr::LoadSystemFonts() { |
| 243 if (m_bLoaded) { | 242 if (m_bLoaded) { |
| 244 return; | 243 return; |
| 245 } | 244 } |
| 246 ScanPath("/system/fonts"); | 245 ScanPath("/system/fonts"); |
| 247 OutputSystemFonts(); | 246 OutputSystemFonts(); |
| 248 m_bLoaded = TRUE; | 247 m_bLoaded = TRUE; |
| 249 } | 248 } |
| 250 void CFPF_SkiaFontMgr::LoadPrivateFont(IFX_FileRead* pFontFile) {} | 249 void CFPF_SkiaFontMgr::LoadPrivateFont(IFX_FileRead* pFontFile) {} |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 326 } | 325 } |
| 327 if (nItem > -1) { | 326 if (nItem > -1) { |
| 328 CFPF_SkiaFontDescriptor* pFontDes = m_FontFaces[nItem]; | 327 CFPF_SkiaFontDescriptor* pFontDes = m_FontFaces[nItem]; |
| 329 CFPF_SkiaFont* pFont = new CFPF_SkiaFont; | 328 CFPF_SkiaFont* pFont = new CFPF_SkiaFont; |
| 330 if (pFont->InitFont(this, pFontDes, bsFamilyname, dwStyle, uCharset)) { | 329 if (pFont->InitFont(this, pFontDes, bsFamilyname, dwStyle, uCharset)) { |
| 331 m_FamilyFonts[dwHash] = pFont; | 330 m_FamilyFonts[dwHash] = pFont; |
| 332 return pFont->Retain(); | 331 return pFont->Retain(); |
| 333 } | 332 } |
| 334 pFont->Release(); | 333 pFont->Release(); |
| 335 } | 334 } |
| 336 return NULL; | 335 return nullptr; |
| 337 } | 336 } |
| 338 FXFT_Face CFPF_SkiaFontMgr::GetFontFace(IFX_FileRead* pFileRead, | 337 FXFT_Face CFPF_SkiaFontMgr::GetFontFace(IFX_FileRead* pFileRead, |
| 339 int32_t iFaceIndex) { | 338 int32_t iFaceIndex) { |
| 340 if (!pFileRead) { | 339 if (!pFileRead) { |
| 341 return NULL; | 340 return nullptr; |
| 342 } | 341 } |
| 343 if (pFileRead->GetSize() == 0) { | 342 if (pFileRead->GetSize() == 0) { |
| 344 return NULL; | 343 return nullptr; |
| 345 } | 344 } |
| 346 if (iFaceIndex < 0) { | 345 if (iFaceIndex < 0) { |
| 347 return NULL; | 346 return nullptr; |
| 348 } | 347 } |
| 349 FXFT_StreamRec streamRec; | 348 FXFT_StreamRec streamRec; |
| 350 FXSYS_memset(&streamRec, 0, sizeof(FXFT_StreamRec)); | 349 FXSYS_memset(&streamRec, 0, sizeof(FXFT_StreamRec)); |
| 351 streamRec.size = pFileRead->GetSize(); | 350 streamRec.size = pFileRead->GetSize(); |
| 352 streamRec.descriptor.pointer = pFileRead; | 351 streamRec.descriptor.pointer = pFileRead; |
| 353 streamRec.read = FPF_SkiaStream_Read; | 352 streamRec.read = FPF_SkiaStream_Read; |
| 354 streamRec.close = FPF_SkiaStream_Close; | 353 streamRec.close = FPF_SkiaStream_Close; |
| 355 FXFT_Open_Args args; | 354 FXFT_Open_Args args; |
| 356 args.flags = FT_OPEN_STREAM; | 355 args.flags = FT_OPEN_STREAM; |
| 357 args.stream = &streamRec; | 356 args.stream = &streamRec; |
| 358 FXFT_Face face; | 357 FXFT_Face face; |
| 359 if (FXFT_Open_Face(m_FTLibrary, &args, iFaceIndex, &face)) { | 358 if (FXFT_Open_Face(m_FTLibrary, &args, iFaceIndex, &face)) { |
| 360 return NULL; | 359 return nullptr; |
| 361 } | 360 } |
| 362 FXFT_Set_Pixel_Sizes(face, 0, 64); | 361 FXFT_Set_Pixel_Sizes(face, 0, 64); |
| 363 return face; | 362 return face; |
| 364 } | 363 } |
| 365 FXFT_Face CFPF_SkiaFontMgr::GetFontFace(const CFX_ByteStringC& bsFile, | 364 FXFT_Face CFPF_SkiaFontMgr::GetFontFace(const CFX_ByteStringC& bsFile, |
| 366 int32_t iFaceIndex) { | 365 int32_t iFaceIndex) { |
| 367 if (bsFile.IsEmpty()) { | 366 if (bsFile.IsEmpty()) { |
| 368 return NULL; | 367 return nullptr; |
| 369 } | 368 } |
| 370 if (iFaceIndex < 0) { | 369 if (iFaceIndex < 0) { |
| 371 return NULL; | 370 return nullptr; |
| 372 } | 371 } |
| 373 FXFT_Open_Args args; | 372 FXFT_Open_Args args; |
| 374 args.flags = FT_OPEN_PATHNAME; | 373 args.flags = FT_OPEN_PATHNAME; |
| 375 args.pathname = static_cast<FT_String*>(bsFile.c_str()); | 374 args.pathname = static_cast<FT_String*>(bsFile.c_str()); |
| 376 FXFT_Face face; | 375 FXFT_Face face; |
| 377 if (FXFT_Open_Face(m_FTLibrary, &args, iFaceIndex, &face)) { | 376 if (FXFT_Open_Face(m_FTLibrary, &args, iFaceIndex, &face)) { |
| 378 return FALSE; | 377 return FALSE; |
| 379 } | 378 } |
| 380 FXFT_Set_Pixel_Sizes(face, 0, 64); | 379 FXFT_Set_Pixel_Sizes(face, 0, 64); |
| 381 return face; | 380 return face; |
| 382 } | 381 } |
| 383 FXFT_Face CFPF_SkiaFontMgr::GetFontFace(const uint8_t* pBuffer, | 382 FXFT_Face CFPF_SkiaFontMgr::GetFontFace(const uint8_t* pBuffer, |
| 384 size_t szBuffer, | 383 size_t szBuffer, |
| 385 int32_t iFaceIndex) { | 384 int32_t iFaceIndex) { |
| 386 if (!pBuffer || szBuffer < 1) { | 385 if (!pBuffer || szBuffer < 1) { |
| 387 return NULL; | 386 return nullptr; |
| 388 } | 387 } |
| 389 if (iFaceIndex < 0) { | 388 if (iFaceIndex < 0) { |
| 390 return NULL; | 389 return nullptr; |
| 391 } | 390 } |
| 392 FXFT_Open_Args args; | 391 FXFT_Open_Args args; |
| 393 args.flags = FT_OPEN_MEMORY; | 392 args.flags = FT_OPEN_MEMORY; |
| 394 args.memory_base = pBuffer; | 393 args.memory_base = pBuffer; |
| 395 args.memory_size = szBuffer; | 394 args.memory_size = szBuffer; |
| 396 FXFT_Face face; | 395 FXFT_Face face; |
| 397 if (FXFT_Open_Face(m_FTLibrary, &args, iFaceIndex, &face)) { | 396 if (FXFT_Open_Face(m_FTLibrary, &args, iFaceIndex, &face)) { |
| 398 return FALSE; | 397 return FALSE; |
| 399 } | 398 } |
| 400 FXFT_Set_Pixel_Sizes(face, 0, 64); | 399 FXFT_Set_Pixel_Sizes(face, 0, 64); |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 515 } | 514 } |
| 516 if (pOS2 && (pOS2->ulCodePageRange1 & (1 << 31))) { | 515 if (pOS2 && (pOS2->ulCodePageRange1 & (1 << 31))) { |
| 517 pFontDesc->m_dwStyle |= FXFONT_SYMBOLIC; | 516 pFontDesc->m_dwStyle |= FXFONT_SYMBOLIC; |
| 518 } | 517 } |
| 519 pFontDesc->m_dwCharsets = FPF_SkiaGetFaceCharset(pOS2); | 518 pFontDesc->m_dwCharsets = FPF_SkiaGetFaceCharset(pOS2); |
| 520 pFontDesc->m_iFaceIndex = face->face_index; | 519 pFontDesc->m_iFaceIndex = face->face_index; |
| 521 pFontDesc->m_iGlyphNum = face->num_glyphs; | 520 pFontDesc->m_iGlyphNum = face->num_glyphs; |
| 522 } | 521 } |
| 523 void CFPF_SkiaFontMgr::OutputSystemFonts() {} | 522 void CFPF_SkiaFontMgr::OutputSystemFonts() {} |
| 524 #endif | 523 #endif |
| OLD | NEW |