diff options
Diffstat (limited to 'xfa/fgas/font')
-rw-r--r-- | xfa/fgas/font/cfgas_fontmgr.cpp | 75 | ||||
-rw-r--r-- | xfa/fgas/font/cfgas_fontmgr.h | 19 | ||||
-rw-r--r-- | xfa/fgas/font/cfgas_gefont.cpp | 11 | ||||
-rw-r--r-- | xfa/fgas/font/cfgas_gefont.h | 4 |
4 files changed, 47 insertions, 62 deletions
diff --git a/xfa/fgas/font/cfgas_fontmgr.cpp b/xfa/fgas/font/cfgas_fontmgr.cpp index f211e64bc3..060dd95b48 100644 --- a/xfa/fgas/font/cfgas_fontmgr.cpp +++ b/xfa/fgas/font/cfgas_fontmgr.cpp @@ -607,13 +607,6 @@ CFGAS_FontMgr::~CFGAS_FontMgr() { delete pFonts; } m_Hash2Fonts.RemoveAll(); - pos = m_IFXFont2FileRead.GetStartPosition(); - while (pos) { - CFGAS_GEFont* pFont; - IFX_SeekableReadStream* pFileRead; - m_IFXFont2FileRead.GetNextAssoc(pos, pFont, pFileRead); - pFileRead->Release(); - } } bool CFGAS_FontMgr::EnumFontsFromFontMapper() { @@ -628,7 +621,7 @@ bool CFGAS_FontMgr::EnumFontsFromFontMapper() { pSystemFontInfo->EnumFontList(pFontMapper); for (int32_t i = 0; i < pFontMapper->GetFaceSize(); ++i) { - IFX_SeekableReadStream* pFontStream = + CFX_RetainPtr<IFX_SeekableReadStream> pFontStream = CreateFontStream(pFontMapper, pSystemFontInfo, i); if (!pFontStream) continue; @@ -636,19 +629,15 @@ bool CFGAS_FontMgr::EnumFontsFromFontMapper() { CFX_WideString wsFaceName = CFX_WideString::FromLocal(pFontMapper->GetFaceName(i).c_str()); RegisterFaces(pFontStream, &wsFaceName); - pFontStream->Release(); } - if (m_InstalledFonts.GetSize() == 0) - return false; - - return true; + return m_InstalledFonts.GetSize() != 0; } bool CFGAS_FontMgr::EnumFontsFromFiles() { CFX_GEModule::Get()->GetFontMgr()->InitFTLibrary(); FX_POSITION pos = m_pFontSource->GetStartPosition(); IFX_FileAccess* pFontSource = nullptr; - IFX_SeekableReadStream* pFontStream = nullptr; + CFX_RetainPtr<IFX_SeekableReadStream> pFontStream; while (pos) { pFontSource = m_pFontSource->GetNext(pos); pFontStream = pFontSource->CreateFileStream(FX_FILEMODE_ReadOnly); @@ -657,12 +646,9 @@ bool CFGAS_FontMgr::EnumFontsFromFiles() { continue; } RegisterFaces(pFontStream, nullptr); - pFontStream->Release(); pFontSource->Release(); } - if (m_InstalledFonts.GetSize() == 0) - return false; - return true; + return m_InstalledFonts.GetSize() != 0; } bool CFGAS_FontMgr::EnumFonts() { @@ -765,7 +751,7 @@ CFGAS_GEFont* CFGAS_FontMgr::GetFontByUnicode(FX_WCHAR wUnicode, bool CFGAS_FontMgr::VerifyUnicode(CFX_FontDescriptor* pDesc, FX_WCHAR wcUnicode) { - IFX_SeekableReadStream* pFileRead = + CFX_RetainPtr<IFX_SeekableReadStream> pFileRead = CreateFontStream(pDesc->m_wsFaceName.UTF8Encode()); if (!pFileRead) return false; @@ -773,12 +759,12 @@ bool CFGAS_FontMgr::VerifyUnicode(CFX_FontDescriptor* pDesc, FXFT_Face pFace = LoadFace(pFileRead, pDesc->m_nFaceIndex); FT_Error retCharmap = FXFT_Select_Charmap(pFace, FXFT_ENCODING_UNICODE); FT_Error retIndex = FXFT_Get_Char_Index(pFace, wcUnicode); - pFileRead->Release(); if (!pFace) return false; if (FXFT_Get_Face_External_Stream(pFace)) FXFT_Clear_Face_External_Stream(pFace); + FXFT_Done_Face(pFace); return !retCharmap && retIndex; } @@ -811,24 +797,20 @@ CFGAS_GEFont* CFGAS_FontMgr::LoadFont(const CFX_WideString& wsFaceName, if (!pSystemFontInfo) return nullptr; - IFX_SeekableReadStream* pFontStream = + CFX_RetainPtr<IFX_SeekableReadStream> pFontStream = CreateFontStream(wsFaceName.UTF8Encode()); if (!pFontStream) return nullptr; - std::unique_ptr<CFX_Font> pInternalFont(new CFX_Font()); - if (!pInternalFont->LoadFile(pFontStream, iFaceIndex)) { - pFontStream->Release(); + auto pInternalFont = pdfium::MakeUnique<CFX_Font>(); + if (!pInternalFont->LoadFile(pFontStream, iFaceIndex)) return nullptr; - } CFGAS_GEFont* pFont = CFGAS_GEFont::LoadFont(std::move(pInternalFont), this); - if (!pFont) { - pFontStream->Release(); + if (!pFont) return nullptr; - } - m_IFXFont2FileRead.SetAt(pFont, pFontStream); + m_IFXFont2FileRead[pFont] = pFontStream; if (pFaceCount) *pFaceCount = pFont->GetDevFont()->GetFace()->num_faces; @@ -845,24 +827,26 @@ unsigned long _ftStreamRead(FXFT_Stream stream, return 0; IFX_SeekableReadStream* pFile = - (IFX_SeekableReadStream*)stream->descriptor.pointer; - int res = pFile->ReadBlock(buffer, offset, count); - if (res) - return count; - return 0; + static_cast<IFX_SeekableReadStream*>(stream->descriptor.pointer); + if (!pFile->ReadBlock(buffer, offset, count)) + return 0; + + return count; } void _ftStreamClose(FXFT_Stream stream) {} }; // extern "C" -FXFT_Face CFGAS_FontMgr::LoadFace(IFX_SeekableReadStream* pFontStream, - int32_t iFaceIndex) { +FXFT_Face CFGAS_FontMgr::LoadFace( + const CFX_RetainPtr<IFX_SeekableReadStream>& pFontStream, + int32_t iFaceIndex) { if (!pFontStream) return nullptr; CFX_FontMgr* pFontMgr = CFX_GEModule::Get()->GetFontMgr(); pFontMgr->InitFTLibrary(); + FXFT_Library library = pFontMgr->GetFTLibrary(); if (!library) return nullptr; @@ -870,7 +854,7 @@ FXFT_Face CFGAS_FontMgr::LoadFace(IFX_SeekableReadStream* pFontStream, FXFT_Stream ftStream = FX_Alloc(FXFT_StreamRec, 1); FXSYS_memset(ftStream, 0, sizeof(FXFT_StreamRec)); ftStream->base = nullptr; - ftStream->descriptor.pointer = pFontStream; + ftStream->descriptor.pointer = static_cast<void*>(pFontStream.Get()); ftStream->pos = 0; ftStream->size = static_cast<unsigned long>(pFontStream->GetSize()); ftStream->read = _ftStreamRead; @@ -891,7 +875,7 @@ FXFT_Face CFGAS_FontMgr::LoadFace(IFX_SeekableReadStream* pFontStream, return pFace; } -IFX_SeekableReadStream* CFGAS_FontMgr::CreateFontStream( +CFX_RetainPtr<IFX_SeekableReadStream> CFGAS_FontMgr::CreateFontStream( CFX_FontMapper* pFontMapper, IFX_SystemFontInfo* pSystemFontInfo, uint32_t index) { @@ -912,11 +896,10 @@ IFX_SeekableReadStream* CFGAS_FontMgr::CreateFontStream( return IFX_MemoryStream::Create(pBuffer, dwFileSize, true); } -IFX_SeekableReadStream* CFGAS_FontMgr::CreateFontStream( +CFX_RetainPtr<IFX_SeekableReadStream> CFGAS_FontMgr::CreateFontStream( const CFX_ByteString& bsFaceName) { CFX_FontMgr* pFontMgr = CFX_GEModule::Get()->GetFontMgr(); CFX_FontMapper* pFontMapper = pFontMgr->GetBuiltinMapper(); - if (!pFontMapper) return nullptr; @@ -1039,11 +1022,8 @@ void CFGAS_FontMgr::RemoveFont(CFGAS_GEFont* pEFont) { if (!pEFont) return; - IFX_SeekableReadStream* pFileRead; - if (m_IFXFont2FileRead.Lookup(pEFont, pFileRead)) { - pFileRead->Release(); - m_IFXFont2FileRead.RemoveKey(pEFont); - } + m_IFXFont2FileRead.erase(pEFont); + FX_POSITION pos; pos = m_Hash2Fonts.GetStartPosition(); while (pos) { @@ -1096,8 +1076,9 @@ void CFGAS_FontMgr::RegisterFace(FXFT_Face pFace, m_InstalledFonts.Add(pFont.release()); } -void CFGAS_FontMgr::RegisterFaces(IFX_SeekableReadStream* pFontStream, - const CFX_WideString* pFaceName) { +void CFGAS_FontMgr::RegisterFaces( + const CFX_RetainPtr<IFX_SeekableReadStream>& pFontStream, + const CFX_WideString* pFaceName) { int32_t index = 0; int32_t num_faces = 0; do { diff --git a/xfa/fgas/font/cfgas_fontmgr.h b/xfa/fgas/font/cfgas_fontmgr.h index 7b68525188..28a8bb528a 100644 --- a/xfa/fgas/font/cfgas_fontmgr.h +++ b/xfa/fgas/font/cfgas_fontmgr.h @@ -7,6 +7,7 @@ #ifndef XFA_FGAS_FONT_CFGAS_FONTMGR_H_ #define XFA_FGAS_FONT_CFGAS_FONTMGR_H_ +#include <map> #include <memory> #include <vector> @@ -214,7 +215,7 @@ class CFGAS_FontMgr { bool EnumFontsFromFontMapper(); bool EnumFontsFromFiles(); void RegisterFace(FXFT_Face pFace, const CFX_WideString* pFaceName); - void RegisterFaces(IFX_SeekableReadStream* pFontStream, + void RegisterFaces(const CFX_RetainPtr<IFX_SeekableReadStream>& pFontStream, const CFX_WideString* pFaceName); void GetNames(const uint8_t* name_table, CFX_WideStringArray& Names); std::vector<uint16_t> GetCharsets(FXFT_Face pFace) const; @@ -236,16 +237,20 @@ class CFGAS_FontMgr { CFGAS_GEFont* LoadFont(const CFX_WideString& wsFaceName, int32_t iFaceIndex, int32_t* pFaceCount); - FXFT_Face LoadFace(IFX_SeekableReadStream* pFontStream, int32_t iFaceIndex); - IFX_SeekableReadStream* CreateFontStream(CFX_FontMapper* pFontMapper, - IFX_SystemFontInfo* pSystemFontInfo, - uint32_t index); - IFX_SeekableReadStream* CreateFontStream(const CFX_ByteString& bsFaceName); + FXFT_Face LoadFace(const CFX_RetainPtr<IFX_SeekableReadStream>& pFontStream, + int32_t iFaceIndex); + CFX_RetainPtr<IFX_SeekableReadStream> CreateFontStream( + CFX_FontMapper* pFontMapper, + IFX_SystemFontInfo* pSystemFontInfo, + uint32_t index); + CFX_RetainPtr<IFX_SeekableReadStream> CreateFontStream( + const CFX_ByteString& bsFaceName); CFX_FontDescriptors m_InstalledFonts; CFX_MapPtrTemplate<uint32_t, CFX_FontDescriptorInfos*> m_Hash2CandidateList; CFX_MapPtrTemplate<uint32_t, CFX_ArrayTemplate<CFGAS_GEFont*>*> m_Hash2Fonts; - CFX_MapPtrTemplate<CFGAS_GEFont*, IFX_SeekableReadStream*> m_IFXFont2FileRead; + std::map<CFGAS_GEFont*, CFX_RetainPtr<IFX_SeekableReadStream> > + m_IFXFont2FileRead; CFX_MapPtrTemplate<FX_WCHAR, CFGAS_GEFont*> m_FailedUnicodes2Nullptr; CFX_FontSourceEnum_File* const m_pFontSource; }; diff --git a/xfa/fgas/font/cfgas_gefont.cpp b/xfa/fgas/font/cfgas_gefont.cpp index 1d4624fb0d..3bca4dc09f 100644 --- a/xfa/fgas/font/cfgas_gefont.cpp +++ b/xfa/fgas/font/cfgas_gefont.cpp @@ -210,12 +210,13 @@ bool CFGAS_GEFont::LoadFontInternal(IFGAS_Stream* pFontStream, if (bSaveStream) m_pStream.reset(pFontStream); - m_pFileRead.reset(pFontStream->MakeSeekableReadStream()); + m_pFileRead = pFontStream->MakeSeekableReadStream(); m_pFont = new CFX_Font; - if (m_pFont->LoadFile(m_pFileRead.get())) - return InitFont(); - m_pFileRead.reset(); - return false; + if (!m_pFont->LoadFile(m_pFileRead)) { + m_pFileRead.Reset(); + return false; + } + return InitFont(); } #endif // _FXM_PLATFORM_ == _FXM_PLATFORM_WINDOWS_ diff --git a/xfa/fgas/font/cfgas_gefont.h b/xfa/fgas/font/cfgas_gefont.h index 2b4179e711..b4fcf25ae1 100644 --- a/xfa/fgas/font/cfgas_gefont.h +++ b/xfa/fgas/font/cfgas_gefont.h @@ -98,9 +98,7 @@ class CFGAS_GEFont { int32_t m_iRefCount; bool m_bExternalFont; std::unique_ptr<IFGAS_Stream, ReleaseDeleter<IFGAS_Stream>> m_pStream; - std::unique_ptr<IFX_SeekableReadStream, - ReleaseDeleter<IFX_SeekableReadStream>> - m_pFileRead; + CFX_RetainPtr<IFX_SeekableReadStream> m_pFileRead; std::unique_ptr<CFX_UnicodeEncoding> m_pFontEncoding; std::unique_ptr<CFX_DiscreteArrayTemplate<uint16_t>> m_pCharWidthMap; std::unique_ptr<CFX_MassArrayTemplate<CFX_Rect>> m_pRectArray; |