diff options
author | Tom Sepez <tsepez@chromium.org> | 2018-04-30 21:02:03 +0000 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2018-04-30 21:02:03 +0000 |
commit | da65a8ea74d2748c93015fb5521da678e29e6548 (patch) | |
tree | c9455640dd3e89a43ab4cf7e3bf17ed475033b5d /core/fxge/cfx_fontmgr.cpp | |
parent | f213df4a87ede709db1f311bbad3c68fbccf159c (diff) | |
download | pdfium-da65a8ea74d2748c93015fb5521da678e29e6548.tar.xz |
Saner memory managment in cttfontdesc, part 1.
A subsequent patch will tackle the ad-hoc ref counting, but we
can tidy this before going down that hole.
Decouple CTTFontDesc creation from face setting.
Remove union and treat single-entry case as vector's first element.
Pass unique_ptr to prove memory ownership.
Change-Id: Ic427798da04f3afbb65a56ee10045b9f22457a73
Reviewed-on: https://pdfium-review.googlesource.com/31730
Reviewed-by: dsinclair <dsinclair@chromium.org>
Commit-Queue: Tom Sepez <tsepez@chromium.org>
Diffstat (limited to 'core/fxge/cfx_fontmgr.cpp')
-rw-r--r-- | core/fxge/cfx_fontmgr.cpp | 47 |
1 files changed, 26 insertions, 21 deletions
diff --git a/core/fxge/cfx_fontmgr.cpp b/core/fxge/cfx_fontmgr.cpp index 158b5d0cdb..2ee46373d5 100644 --- a/core/fxge/cfx_fontmgr.cpp +++ b/core/fxge/cfx_fontmgr.cpp @@ -126,19 +126,21 @@ FXFT_Face CFX_FontMgr::GetCachedFace(const ByteString& face_name, CTTFontDesc* pFontDesc = it->second.get(); *pFontData = pFontDesc->FontData(); pFontDesc->AddRef(); - return pFontDesc->SingleFace(); + return pFontDesc->GetFace(0); } -FXFT_Face CFX_FontMgr::AddCachedFace(const ByteString& face_name, - int weight, - bool bItalic, - uint8_t* pData, - uint32_t size, - int face_index) { +FXFT_Face CFX_FontMgr::AddCachedFace( + const ByteString& face_name, + int weight, + bool bItalic, + std::unique_ptr<uint8_t, FxFreeDeleter> pData, + uint32_t size, + int face_index) { InitFTLibrary(); FXFT_Face face = nullptr; - int ret = FXFT_New_Memory_Face(m_FTLibrary, pData, size, face_index, &face); + int ret = + FXFT_New_Memory_Face(m_FTLibrary, pData.get(), size, face_index, &face); if (ret) return nullptr; @@ -146,10 +148,11 @@ FXFT_Face CFX_FontMgr::AddCachedFace(const ByteString& face_name, if (ret) return nullptr; - auto pFontDesc = pdfium::MakeUnique<CTTFontDesc>(pData, face); + auto pFontDesc = pdfium::MakeUnique<CTTFontDesc>(std::move(pData)); + pFontDesc->SetFace(0, face); CTTFontDesc* pResult = pFontDesc.get(); m_FaceMap[KeyNameFromFace(face_name, weight, bItalic)] = std::move(pFontDesc); - return pResult->SingleFace(); + return pResult->GetFace(0); } FXFT_Face CFX_FontMgr::GetCachedTTCFace(int ttc_size, @@ -163,22 +166,24 @@ FXFT_Face CFX_FontMgr::GetCachedTTCFace(int ttc_size, CTTFontDesc* pFontDesc = it->second.get(); *pFontData = pFontDesc->FontData(); int face_index = GetTTCIndex(pFontDesc->FontData(), ttc_size, font_offset); - if (!pFontDesc->TTCFace(face_index)) { - pFontDesc->SetTTCFace( + if (!pFontDesc->GetFace(face_index)) { + pFontDesc->SetFace( face_index, GetFixedFace(pFontDesc->FontData(), ttc_size, face_index)); } pFontDesc->AddRef(); - return pFontDesc->TTCFace(face_index); + return pFontDesc->GetFace(face_index); } -FXFT_Face CFX_FontMgr::AddCachedTTCFace(int ttc_size, - uint32_t checksum, - uint8_t* pData, - uint32_t size, - int font_offset) { - int face_index = GetTTCIndex(pData, ttc_size, font_offset); - FXFT_Face face = GetFixedFace(pData, ttc_size, face_index); - auto pFontDesc = pdfium::MakeUnique<CTTFontDesc>(pData, face_index, face); +FXFT_Face CFX_FontMgr::AddCachedTTCFace( + int ttc_size, + uint32_t checksum, + std::unique_ptr<uint8_t, FxFreeDeleter> pData, + uint32_t size, + int font_offset) { + int face_index = GetTTCIndex(pData.get(), ttc_size, font_offset); + FXFT_Face face = GetFixedFace(pData.get(), ttc_size, face_index); + auto pFontDesc = pdfium::MakeUnique<CTTFontDesc>(std::move(pData)); + pFontDesc->SetFace(face_index, face); m_FaceMap[KeyNameFromSize(ttc_size, checksum)] = std::move(pFontDesc); return face; } |