summaryrefslogtreecommitdiff
path: root/core/fxge/cfx_fontmapper.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'core/fxge/cfx_fontmapper.cpp')
-rw-r--r--core/fxge/cfx_fontmapper.cpp52
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) {