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_fontmapper.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_fontmapper.cpp')
-rw-r--r-- | core/fxge/cfx_fontmapper.cpp | 52 |
1 files changed, 28 insertions, 24 deletions
diff --git a/core/fxge/cfx_fontmapper.cpp b/core/fxge/cfx_fontmapper.cpp index b3e88c00fe..c0b111a51e 100644 --- a/core/fxge/cfx_fontmapper.cpp +++ b/core/fxge/cfx_fontmapper.cpp @@ -751,22 +751,25 @@ FXFT_Face CFX_FontMapper::GetCachedTTCFace(void* hFont, const uint32_t tableTTCF, uint32_t ttc_size, uint32_t font_size) { - uint8_t buffer[1024]; - m_pFontInfo->GetFontData(hFont, tableTTCF, buffer, FX_ArraySize(buffer)); - uint32_t* pBuffer = reinterpret_cast<uint32_t*>(buffer); uint32_t checksum = 0; - for (int i = 0; i < 256; i++) - checksum += pBuffer[i]; - uint8_t* pFontData; - FXFT_Face face = m_pFontMgr->GetCachedTTCFace( - ttc_size, checksum, ttc_size - font_size, &pFontData); - if (!face) { - pFontData = FX_Alloc(uint8_t, ttc_size); - m_pFontInfo->GetFontData(hFont, tableTTCF, pFontData, ttc_size); - face = m_pFontMgr->AddCachedTTCFace(ttc_size, checksum, pFontData, ttc_size, - ttc_size - font_size); + { + uint8_t buffer[1024]; + m_pFontInfo->GetFontData(hFont, tableTTCF, buffer, sizeof(buffer)); + uint32_t* pBuffer = reinterpret_cast<uint32_t*>(buffer); + for (int i = 0; i < 256; i++) + checksum += pBuffer[i]; } - return face; + uint8_t* pIgnore = nullptr; + FXFT_Face face = m_pFontMgr->GetCachedTTCFace(ttc_size, checksum, + ttc_size - font_size, &pIgnore); + if (face) + return face; + + std::unique_ptr<uint8_t, FxFreeDeleter> pFontData( + FX_Alloc(uint8_t, ttc_size)); + m_pFontInfo->GetFontData(hFont, tableTTCF, pFontData.get(), ttc_size); + return m_pFontMgr->AddCachedTTCFace(ttc_size, checksum, std::move(pFontData), + ttc_size, ttc_size - font_size); } FXFT_Face CFX_FontMapper::GetCachedFace(void* hFont, @@ -774,17 +777,18 @@ FXFT_Face CFX_FontMapper::GetCachedFace(void* hFont, int weight, bool bItalic, uint32_t font_size) { - uint8_t* pFontData; + uint8_t* pIgnore = nullptr; FXFT_Face face = - m_pFontMgr->GetCachedFace(SubstName, weight, bItalic, &pFontData); - if (!face) { - pFontData = FX_Alloc(uint8_t, font_size); - m_pFontInfo->GetFontData(hFont, 0, pFontData, font_size); - face = - m_pFontMgr->AddCachedFace(SubstName, weight, bItalic, pFontData, - font_size, m_pFontInfo->GetFaceIndex(hFont)); - } - return face; + m_pFontMgr->GetCachedFace(SubstName, weight, bItalic, &pIgnore); + if (face) + return face; + + std::unique_ptr<uint8_t, FxFreeDeleter> pFontData( + FX_Alloc(uint8_t, font_size)); + m_pFontInfo->GetFontData(hFont, 0, pFontData.get(), font_size); + return m_pFontMgr->AddCachedFace(SubstName, weight, bItalic, + std::move(pFontData), font_size, + m_pFontInfo->GetFaceIndex(hFont)); } int PDF_GetStandardFontName(ByteString* name) { |