Chromium Code Reviews| 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 "../fgas_base.h" | 7 #include "../fgas_base.h" |
| 8 #include "fx_stdfontmgr.h" | 8 #include "fx_stdfontmgr.h" |
| 9 #include "fx_fontutils.h" | 9 #include "fx_fontutils.h" |
| 10 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ | 10 #if _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ |
| (...skipping 593 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 604 delete pFontMgr; | 604 delete pFontMgr; |
| 605 return NULL; | 605 return NULL; |
| 606 } | 606 } |
| 607 CFX_FontMgrImp::CFX_FontMgrImp(IFX_FontSourceEnum* pFontEnum, | 607 CFX_FontMgrImp::CFX_FontMgrImp(IFX_FontSourceEnum* pFontEnum, |
| 608 IFX_FontMgrDelegate* pDelegate, | 608 IFX_FontMgrDelegate* pDelegate, |
| 609 void* pUserData) | 609 void* pUserData) |
| 610 : m_pFontSource(pFontEnum), | 610 : m_pFontSource(pFontEnum), |
| 611 m_pDelegate(pDelegate), | 611 m_pDelegate(pDelegate), |
| 612 m_pUserData(pUserData) {} | 612 m_pUserData(pUserData) {} |
| 613 FX_BOOL CFX_FontMgrImp::EnumFonts() { | 613 FX_BOOL CFX_FontMgrImp::EnumFonts() { |
| 614 FXFT_Library& library = CFX_GEModule::Get()->GetFontMgr()->m_FTLibrary; | |
|
Lei Zhang
2015/10/21 00:51:24
|library| is not used here - initialization not ne
Tom Sepez
2015/10/21 20:03:55
May still need it in case any of our callees expec
Lei Zhang
2015/10/21 23:29:02
I'll just call it anyway.
| |
| 615 if (library == NULL) { | |
| 616 FXFT_Init_FreeType(&library); | |
| 617 } | |
| 618 if (library == NULL) { | |
| 619 return FALSE; | |
| 620 } | |
| 621 FXFT_Face pFace = NULL; | 614 FXFT_Face pFace = NULL; |
| 622 FX_POSITION pos = m_pFontSource->GetStartPosition(); | 615 FX_POSITION pos = m_pFontSource->GetStartPosition(); |
| 623 IFX_FileAccess* pFontSource = NULL; | 616 IFX_FileAccess* pFontSource = NULL; |
| 624 IFX_FileRead* pFontStream = NULL; | 617 IFX_FileRead* pFontStream = NULL; |
| 625 while (pos) { | 618 while (pos) { |
| 626 pFontSource = m_pFontSource->GetNext(pos); | 619 pFontSource = m_pFontSource->GetNext(pos); |
| 627 pFontStream = pFontSource->CreateFileStream(FX_FILEMODE_ReadOnly); | 620 pFontStream = pFontSource->CreateFileStream(FX_FILEMODE_ReadOnly); |
| 628 if (NULL == pFontStream) { | 621 if (NULL == pFontStream) { |
| 629 pFontSource->Release(); | 622 pFontSource->Release(); |
| 630 continue; | 623 continue; |
| (...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 996 } | 989 } |
| 997 IFX_FileRead* pFile = (IFX_FileRead*)stream->descriptor.pointer; | 990 IFX_FileRead* pFile = (IFX_FileRead*)stream->descriptor.pointer; |
| 998 int res = pFile->ReadBlock(buffer, offset, count); | 991 int res = pFile->ReadBlock(buffer, offset, count); |
| 999 if (res) { | 992 if (res) { |
| 1000 return count; | 993 return count; |
| 1001 } | 994 } |
| 1002 return 0; | 995 return 0; |
| 1003 } | 996 } |
| 1004 void _ftStreamClose(FXFT_Stream stream) {} | 997 void _ftStreamClose(FXFT_Stream stream) {} |
| 1005 }; | 998 }; |
| 999 | |
| 1006 FXFT_Face CFX_FontMgrImp::LoadFace(IFX_FileRead* pFontStream, | 1000 FXFT_Face CFX_FontMgrImp::LoadFace(IFX_FileRead* pFontStream, |
| 1007 int32_t iFaceIndex) { | 1001 int32_t iFaceIndex) { |
| 1008 FXFT_Library& library = CFX_GEModule::Get()->GetFontMgr()->m_FTLibrary; | 1002 if (!pFontStream) |
| 1009 FXFT_Open_Args ftArgs; | 1003 return nullptr; |
| 1004 | |
| 1005 CFX_FontMgr* pFontMgr = CFX_GEModule::Get()->GetFontMgr(); | |
| 1006 pFontMgr->InitFTLibrary(); | |
| 1007 FXFT_Library library = pFontMgr->GetFTLibrary(); | |
| 1008 if (!library) | |
| 1009 return nullptr; | |
| 1010 | |
| 1010 FXFT_Stream ftStream = FX_Alloc(FXFT_StreamRec, 1); | 1011 FXFT_Stream ftStream = FX_Alloc(FXFT_StreamRec, 1); |
| 1011 FXFT_Face pFace = NULL; | |
| 1012 if (library == NULL) { | |
| 1013 FXFT_Init_FreeType(&library); | |
| 1014 } | |
| 1015 if (library == NULL) { | |
| 1016 goto BadRet; | |
| 1017 } | |
| 1018 FXSYS_memset(&ftArgs, 0, sizeof(FXFT_Open_Args)); | |
| 1019 if (NULL == ftStream) { | |
| 1020 goto BadRet; | |
| 1021 } | |
| 1022 FXSYS_memset(ftStream, 0, sizeof(FXFT_StreamRec)); | 1012 FXSYS_memset(ftStream, 0, sizeof(FXFT_StreamRec)); |
| 1023 if (NULL == pFontStream) { | |
| 1024 goto BadRet; | |
| 1025 } | |
| 1026 ftStream->base = NULL; | 1013 ftStream->base = NULL; |
| 1027 ftStream->descriptor.pointer = pFontStream; | 1014 ftStream->descriptor.pointer = pFontStream; |
| 1028 ftStream->pos = 0; | 1015 ftStream->pos = 0; |
| 1029 ftStream->size = (unsigned long)pFontStream->GetSize(); | 1016 ftStream->size = (unsigned long)pFontStream->GetSize(); |
| 1030 ftStream->read = _ftStreamRead; | 1017 ftStream->read = _ftStreamRead; |
| 1031 ftStream->close = _ftStreamClose; | 1018 ftStream->close = _ftStreamClose; |
| 1019 | |
| 1020 FXFT_Open_Args ftArgs; | |
| 1021 FXSYS_memset(&ftArgs, 0, sizeof(FXFT_Open_Args)); | |
| 1032 ftArgs.flags |= FT_OPEN_STREAM; | 1022 ftArgs.flags |= FT_OPEN_STREAM; |
| 1033 ftArgs.stream = ftStream; | 1023 ftArgs.stream = ftStream; |
| 1034 if (0 != FXFT_Open_Face(library, &ftArgs, iFaceIndex, &pFace)) { | 1024 |
| 1035 goto BadRet; | 1025 FXFT_Face pFace = NULL; |
| 1026 if (FXFT_Open_Face(library, &ftArgs, iFaceIndex, &pFace)) { | |
| 1027 FX_Free(ftStream); | |
|
Lei Zhang
2015/10/21 00:51:24
Not sure if |ftStream| needs to be freed if FXFT_O
Tom Sepez
2015/10/21 20:03:55
Acknowledged.
| |
| 1028 return nullptr; | |
| 1036 } | 1029 } |
| 1030 | |
| 1037 FXFT_Set_Pixel_Sizes(pFace, 0, 64); | 1031 FXFT_Set_Pixel_Sizes(pFace, 0, 64); |
| 1038 return pFace; | 1032 return pFace; |
| 1039 BadRet: | |
|
Lei Zhang
2015/10/21 00:51:24
Die gotos die!
| |
| 1040 if (NULL != ftStream) { | |
| 1041 FX_Free(ftStream); | |
| 1042 } | |
| 1043 return NULL; | |
| 1044 } | 1033 } |
| 1034 | |
| 1045 int32_t CFX_FontMgrImp::MatchFonts(CFX_FontDescriptorInfos& MatchedFonts, | 1035 int32_t CFX_FontMgrImp::MatchFonts(CFX_FontDescriptorInfos& MatchedFonts, |
| 1046 FX_WORD wCodePage, | 1036 FX_WORD wCodePage, |
| 1047 FX_DWORD dwFontStyles, | 1037 FX_DWORD dwFontStyles, |
| 1048 const CFX_WideString& FontName, | 1038 const CFX_WideString& FontName, |
| 1049 FX_WCHAR wcUnicode) { | 1039 FX_WCHAR wcUnicode) { |
| 1050 MatchedFonts.RemoveAll(); | 1040 MatchedFonts.RemoveAll(); |
| 1051 CFX_WideString wsNormalizedFontName = FontName; | 1041 CFX_WideString wsNormalizedFontName = FontName; |
| 1052 NormalizeFontName(wsNormalizedFontName); | 1042 NormalizeFontName(wsNormalizedFontName); |
| 1053 static const int32_t nMax = 0xffff; | 1043 static const int32_t nMax = 0xffff; |
| 1054 CFX_FontDescriptor* pFont = NULL; | 1044 CFX_FontDescriptor* pFont = NULL; |
| (...skipping 411 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 1466 FontName.Remove('-'); | 1456 FontName.Remove('-'); |
| 1467 } | 1457 } |
| 1468 int32_t CFX_FontMgrImp::IsPartName(const CFX_WideString& Name1, | 1458 int32_t CFX_FontMgrImp::IsPartName(const CFX_WideString& Name1, |
| 1469 const CFX_WideString& Name2) { | 1459 const CFX_WideString& Name2) { |
| 1470 if (Name1.Find((const FX_WCHAR*)Name2) != -1) { | 1460 if (Name1.Find((const FX_WCHAR*)Name2) != -1) { |
| 1471 return 1; | 1461 return 1; |
| 1472 } | 1462 } |
| 1473 return 0; | 1463 return 0; |
| 1474 } | 1464 } |
| 1475 #endif | 1465 #endif |
| OLD | NEW |