diff options
Diffstat (limited to 'xfa/fgas')
-rw-r--r-- | xfa/fgas/crt/fgas_stream.cpp | 148 | ||||
-rw-r--r-- | xfa/fgas/crt/fgas_stream.h | 13 | ||||
-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 |
6 files changed, 133 insertions, 137 deletions
diff --git a/xfa/fgas/crt/fgas_stream.cpp b/xfa/fgas/crt/fgas_stream.cpp index 18d8e0bfe1..3ccb652141 100644 --- a/xfa/fgas/crt/fgas_stream.cpp +++ b/xfa/fgas/crt/fgas_stream.cpp @@ -14,6 +14,7 @@ #include <algorithm> #include <memory> +#include "third_party/base/ptr_util.h" #include "xfa/fgas/crt/fgas_codepage.h" namespace { @@ -100,7 +101,8 @@ class CFGAS_FileReadStreamImp : public IFGAS_StreamImp { CFGAS_FileReadStreamImp(); ~CFGAS_FileReadStreamImp() override {} - bool LoadFileRead(IFX_SeekableReadStream* pFileRead, uint32_t dwAccess); + bool LoadFileRead(const CFX_RetainPtr<IFX_SeekableReadStream>& pFileRead, + uint32_t dwAccess); // IFGAS_StreamImp: int32_t GetLength() const override; @@ -119,7 +121,7 @@ class CFGAS_FileReadStreamImp : public IFGAS_StreamImp { bool SetLength(int32_t iLength) override { return false; } protected: - IFX_SeekableReadStream* m_pFileRead; + CFX_RetainPtr<IFX_SeekableReadStream> m_pFileRead; int32_t m_iPosition; int32_t m_iLength; }; @@ -129,10 +131,9 @@ class CFGAS_BufferReadStreamImp : public IFGAS_StreamImp { CFGAS_BufferReadStreamImp(); ~CFGAS_BufferReadStreamImp() override; - bool LoadBufferRead(IFX_BufferedReadStream* pBufferRead, + bool LoadBufferRead(const CFX_RetainPtr<IFX_BufferedReadStream>& pBufferRead, int32_t iFileSize, - uint32_t dwAccess, - bool bReleaseBufferRead); + uint32_t dwAccess); // IFGAS_StreamImp: int32_t GetLength() const override; @@ -151,8 +152,7 @@ class CFGAS_BufferReadStreamImp : public IFGAS_StreamImp { bool SetLength(int32_t iLength) override { return false; } private: - IFX_BufferedReadStream* m_pBufferRead; - bool m_bReleaseBufferRead; + CFX_RetainPtr<IFX_BufferedReadStream> m_pBufferRead; int32_t m_iPosition; int32_t m_iBufferSize; }; @@ -162,7 +162,8 @@ class CFGAS_FileWriteStreamImp : public IFGAS_StreamImp { CFGAS_FileWriteStreamImp(); ~CFGAS_FileWriteStreamImp() override {} - bool LoadFileWrite(IFX_SeekableWriteStream* pFileWrite, uint32_t dwAccess); + bool LoadFileWrite(const CFX_RetainPtr<IFX_SeekableWriteStream>& pFileWrite, + uint32_t dwAccess); // IFGAS_StreamImp: int32_t GetLength() const override; @@ -179,7 +180,7 @@ class CFGAS_FileWriteStreamImp : public IFGAS_StreamImp { bool SetLength(int32_t iLength) override { return false; } protected: - IFX_SeekableWriteStream* m_pFileWrite; + CFX_RetainPtr<IFX_SeekableWriteStream> m_pFileWrite; int32_t m_iPosition; }; @@ -198,12 +199,13 @@ class CFGAS_Stream : public IFGAS_Stream { bool LoadFile(const FX_WCHAR* pszSrcFileName, uint32_t dwAccess); bool LoadBuffer(uint8_t* pData, int32_t iTotalSize, uint32_t dwAccess); - bool LoadFileRead(IFX_SeekableReadStream* pFileRead, uint32_t dwAccess); - bool LoadFileWrite(IFX_SeekableWriteStream* pFileWrite, uint32_t dwAccess); - bool LoadBufferRead(IFX_BufferedReadStream* pBufferRead, + bool LoadFileRead(const CFX_RetainPtr<IFX_SeekableReadStream>& pFileRead, + uint32_t dwAccess); + bool LoadFileWrite(const CFX_RetainPtr<IFX_SeekableWriteStream>& pFileWrite, + uint32_t dwAccess); + bool LoadBufferRead(const CFX_RetainPtr<IFX_BufferedReadStream>& pBufferRead, int32_t iFileSize, - uint32_t dwAccess, - bool bReleaseBufferRead); + uint32_t dwAccess); // IFGAS_Stream void Release() override; @@ -277,15 +279,17 @@ class CFGAS_TextStream : public IFGAS_Stream { class CFGAS_FileRead : public IFX_SeekableReadStream { public: - CFGAS_FileRead(IFGAS_Stream* pStream, bool bReleaseStream); + static CFX_RetainPtr<CFGAS_FileRead> Create(IFGAS_Stream* pStream, + bool bReleaseStream); ~CFGAS_FileRead() override; // IFX_SeekableReadStream - void Release() override; FX_FILESIZE GetSize() override; bool ReadBlock(void* buffer, FX_FILESIZE offset, size_t size) override; protected: + CFGAS_FileRead(IFGAS_Stream* pStream, bool bReleaseStream); + bool m_bReleaseStream; IFGAS_Stream* m_pStream; }; @@ -322,8 +326,9 @@ bool FileSetSize(FXSYS_FILE* file, int32_t size) { } // namespace // static -IFGAS_Stream* IFGAS_Stream::CreateStream(IFX_SeekableReadStream* pFileRead, - uint32_t dwAccess) { +IFGAS_Stream* IFGAS_Stream::CreateStream( + const CFX_RetainPtr<IFX_SeekableReadStream>& pFileRead, + uint32_t dwAccess) { CFGAS_Stream* pSR = new CFGAS_Stream; if (!pSR->LoadFileRead(pFileRead, dwAccess)) { pSR->Release(); @@ -336,8 +341,9 @@ IFGAS_Stream* IFGAS_Stream::CreateStream(IFX_SeekableReadStream* pFileRead, } // static -IFGAS_Stream* IFGAS_Stream::CreateStream(IFX_SeekableWriteStream* pFileWrite, - uint32_t dwAccess) { +IFGAS_Stream* IFGAS_Stream::CreateStream( + const CFX_RetainPtr<IFX_SeekableWriteStream>& pFileWrite, + uint32_t dwAccess) { CFGAS_Stream* pSR = new CFGAS_Stream; if (!pSR->LoadFileWrite(pFileWrite, dwAccess)) { pSR->Release(); @@ -534,18 +540,22 @@ bool CFGAS_FileStreamImp::SetLength(int32_t iLength) { m_iLength = FileLength(m_hFile); return bRet; } + CFGAS_FileReadStreamImp::CFGAS_FileReadStreamImp() : m_pFileRead(nullptr), m_iPosition(0), m_iLength(0) {} -bool CFGAS_FileReadStreamImp::LoadFileRead(IFX_SeekableReadStream* pFileRead, - uint32_t dwAccess) { + +bool CFGAS_FileReadStreamImp::LoadFileRead( + const CFX_RetainPtr<IFX_SeekableReadStream>& pFileRead, + uint32_t dwAccess) { ASSERT(!m_pFileRead && pFileRead); - if (dwAccess & FX_STREAMACCESS_Write) { + if (dwAccess & FX_STREAMACCESS_Write) return false; - } + m_pFileRead = pFileRead; m_iLength = m_pFileRead->GetSize(); return true; } + int32_t CFGAS_FileReadStreamImp::GetLength() const { return m_iLength; } @@ -600,34 +610,28 @@ int32_t CFGAS_FileReadStreamImp::ReadString(FX_WCHAR* pStr, bEOS = (m_iPosition >= m_iLength) || pStr[i] == L'\0'; return i; } + CFGAS_BufferReadStreamImp::CFGAS_BufferReadStreamImp() - : m_pBufferRead(nullptr), - m_bReleaseBufferRead(false), - m_iPosition(0), - m_iBufferSize(0) {} -CFGAS_BufferReadStreamImp::~CFGAS_BufferReadStreamImp() { - if (m_bReleaseBufferRead && m_pBufferRead) { - m_pBufferRead->Release(); - } -} + : m_iPosition(0), m_iBufferSize(0) {} + +CFGAS_BufferReadStreamImp::~CFGAS_BufferReadStreamImp() {} + bool CFGAS_BufferReadStreamImp::LoadBufferRead( - IFX_BufferedReadStream* pBufferRead, + const CFX_RetainPtr<IFX_BufferedReadStream>& pBufferRead, int32_t iFileSize, - uint32_t dwAccess, - bool bReleaseBufferRead) { + uint32_t dwAccess) { ASSERT(!m_pBufferRead && pBufferRead); - if (dwAccess & FX_STREAMACCESS_Write) { + if (dwAccess & FX_STREAMACCESS_Write) return false; - } - m_bReleaseBufferRead = bReleaseBufferRead; + m_pBufferRead = pBufferRead; m_iBufferSize = iFileSize; - if (m_iBufferSize >= 0) { + if (m_iBufferSize >= 0) return true; - } - if (!m_pBufferRead->ReadNextBlock(true)) { + + if (!m_pBufferRead->ReadNextBlock(true)) return false; - } + m_iBufferSize = m_pBufferRead->GetBlockSize(); while (!m_pBufferRead->IsEOF()) { m_pBufferRead->ReadNextBlock(false); @@ -733,23 +737,25 @@ int32_t CFGAS_BufferReadStreamImp::ReadString(FX_WCHAR* pStr, } CFGAS_FileWriteStreamImp::CFGAS_FileWriteStreamImp() : m_pFileWrite(nullptr), m_iPosition(0) {} + bool CFGAS_FileWriteStreamImp::LoadFileWrite( - IFX_SeekableWriteStream* pFileWrite, + const CFX_RetainPtr<IFX_SeekableWriteStream>& pFileWrite, uint32_t dwAccess) { ASSERT(!m_pFileWrite && pFileWrite); - if (dwAccess & FX_STREAMACCESS_Read) { + if (dwAccess & FX_STREAMACCESS_Read) return false; - } - if (dwAccess & FX_STREAMACCESS_Append) { + + if (dwAccess & FX_STREAMACCESS_Append) m_iPosition = pFileWrite->GetSize(); - } + m_pFileWrite = pFileWrite; return true; } + int32_t CFGAS_FileWriteStreamImp::GetLength() const { - if (!m_pFileWrite) { + if (!m_pFileWrite) return 0; - } + return (int32_t)m_pFileWrite->GetSize(); } int32_t CFGAS_FileWriteStreamImp::Seek(FX_STREAMSEEK eSeek, int32_t iOffset) { @@ -1159,8 +1165,9 @@ bool CFGAS_Stream::LoadFile(const FX_WCHAR* pszSrcFileName, uint32_t dwAccess) { return true; } -bool CFGAS_Stream::LoadFileRead(IFX_SeekableReadStream* pFileRead, - uint32_t dwAccess) { +bool CFGAS_Stream::LoadFileRead( + const CFX_RetainPtr<IFX_SeekableReadStream>& pFileRead, + uint32_t dwAccess) { if (m_eStreamType != FX_SREAMTYPE_Unknown || m_pStreamImp) return false; @@ -1178,16 +1185,16 @@ bool CFGAS_Stream::LoadFileRead(IFX_SeekableReadStream* pFileRead, return true; } -bool CFGAS_Stream::LoadFileWrite(IFX_SeekableWriteStream* pFileWrite, - uint32_t dwAccess) { +bool CFGAS_Stream::LoadFileWrite( + const CFX_RetainPtr<IFX_SeekableWriteStream>& pFileWrite, + uint32_t dwAccess) { if (m_eStreamType != FX_SREAMTYPE_Unknown || m_pStreamImp) return false; if (!pFileWrite) return false; - std::unique_ptr<CFGAS_FileWriteStreamImp> pImp( - new CFGAS_FileWriteStreamImp()); + auto pImp = pdfium::MakeUnique<CFGAS_FileWriteStreamImp>(); if (!pImp->LoadFileWrite(pFileWrite, dwAccess)) return false; @@ -1218,20 +1225,18 @@ bool CFGAS_Stream::LoadBuffer(uint8_t* pData, return true; } -bool CFGAS_Stream::LoadBufferRead(IFX_BufferedReadStream* pBufferRead, - int32_t iFileSize, - uint32_t dwAccess, - bool bReleaseBufferRead) { +bool CFGAS_Stream::LoadBufferRead( + const CFX_RetainPtr<IFX_BufferedReadStream>& pBufferRead, + int32_t iFileSize, + uint32_t dwAccess) { if (m_eStreamType != FX_SREAMTYPE_Unknown || m_pStreamImp) return false; if (!pBufferRead) return false; - std::unique_ptr<CFGAS_BufferReadStreamImp> pImp( - new CFGAS_BufferReadStreamImp); - if (!pImp->LoadBufferRead(pBufferRead, iFileSize, dwAccess, - bReleaseBufferRead)) + auto pImp = pdfium::MakeUnique<CFGAS_BufferReadStreamImp>(); + if (!pImp->LoadBufferRead(pBufferRead, iFileSize, dwAccess)) return false; m_pStreamImp = pImp.release(); @@ -1478,14 +1483,21 @@ IFGAS_Stream* CFGAS_Stream::CreateSharedStream(uint32_t dwAccess, return pShared; } -IFX_SeekableReadStream* IFGAS_Stream::MakeSeekableReadStream() { - return new CFGAS_FileRead(this, false); +CFX_RetainPtr<IFX_SeekableReadStream> IFGAS_Stream::MakeSeekableReadStream() { + return CFGAS_FileRead::Create(this, false); +} + +CFX_RetainPtr<CFGAS_FileRead> CFGAS_FileRead::Create(IFGAS_Stream* pStream, + bool bReleaseStream) { + return CFX_RetainPtr<CFGAS_FileRead>( + new CFGAS_FileRead(pStream, bReleaseStream)); } CFGAS_FileRead::CFGAS_FileRead(IFGAS_Stream* pStream, bool bReleaseStream) : m_bReleaseStream(bReleaseStream), m_pStream(pStream) { ASSERT(m_pStream); } + CFGAS_FileRead::~CFGAS_FileRead() { if (m_bReleaseStream) { m_pStream->Release(); @@ -1500,7 +1512,3 @@ bool CFGAS_FileRead::ReadBlock(void* buffer, FX_FILESIZE offset, size_t size) { int32_t iLen = m_pStream->ReadData((uint8_t*)buffer, (int32_t)size); return iLen == (int32_t)size; } - -void CFGAS_FileRead::Release() { - delete this; -} diff --git a/xfa/fgas/crt/fgas_stream.h b/xfa/fgas/crt/fgas_stream.h index bd065ff308..b6552d9825 100644 --- a/xfa/fgas/crt/fgas_stream.h +++ b/xfa/fgas/crt/fgas_stream.h @@ -7,6 +7,7 @@ #ifndef XFA_FGAS_CRT_FGAS_STREAM_H_ #define XFA_FGAS_CRT_FGAS_STREAM_H_ +#include "core/fxcrt/cfx_retain_ptr.h" #include "core/fxcrt/fx_stream.h" #include "core/fxcrt/fx_system.h" @@ -28,10 +29,12 @@ enum FX_STREAMSEEK { class IFGAS_Stream { public: - static IFGAS_Stream* CreateStream(IFX_SeekableReadStream* pFileRead, - uint32_t dwAccess); - static IFGAS_Stream* CreateStream(IFX_SeekableWriteStream* pFileWrite, - uint32_t dwAccess); + static IFGAS_Stream* CreateStream( + const CFX_RetainPtr<IFX_SeekableReadStream>& pFileRead, + uint32_t dwAccess); + static IFGAS_Stream* CreateStream( + const CFX_RetainPtr<IFX_SeekableWriteStream>& pFileWrite, + uint32_t dwAccess); static IFGAS_Stream* CreateStream(uint8_t* pData, int32_t length, uint32_t dwAccess); @@ -63,7 +66,7 @@ class IFGAS_Stream { virtual uint16_t GetCodePage() const = 0; virtual uint16_t SetCodePage(uint16_t wCodePage) = 0; - IFX_SeekableReadStream* MakeSeekableReadStream(); + CFX_RetainPtr<IFX_SeekableReadStream> MakeSeekableReadStream(); }; 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; |