diff options
author | Tom Sepez <tsepez@chromium.org> | 2018-02-16 18:27:38 +0000 |
---|---|---|
committer | Chromium commit bot <commit-bot@chromium.org> | 2018-02-16 18:27:38 +0000 |
commit | 53279b1dcabae4913f7f0a58e741942e82ab7d59 (patch) | |
tree | 4867842f3b5cf7f10b183ae2a7d2325c8c0cdfe8 /xfa/fgas/font | |
parent | 228d415eb4966e9d146fcfee48ca357d4a25bba8 (diff) | |
download | pdfium-53279b1dcabae4913f7f0a58e741942e82ab7d59.tar.xz |
Avoid 100 blank FX_FONTDESCRIPTOR entries.
Change-Id: Ibaf53ee27eefc692ac4f002c3ab28b7738676b31
Reviewed-on: https://pdfium-review.googlesource.com/26991
Commit-Queue: Tom Sepez <tsepez@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
Diffstat (limited to 'xfa/fgas/font')
-rw-r--r-- | xfa/fgas/font/cfgas_fontmgr.cpp | 38 |
1 files changed, 17 insertions, 21 deletions
diff --git a/xfa/fgas/font/cfgas_fontmgr.cpp b/xfa/fgas/font/cfgas_fontmgr.cpp index 4df9863692..8102a0d6dc 100644 --- a/xfa/fgas/font/cfgas_fontmgr.cpp +++ b/xfa/fgas/font/cfgas_fontmgr.cpp @@ -169,23 +169,20 @@ int32_t CALLBACK GdiFontEnumProc(ENUMLOGFONTEX* lpelfe, const LOGFONTW& lf = ((LPENUMLOGFONTEXW)lpelfe)->elfLogFont; if (lf.lfFaceName[0] == L'@') return 1; - FX_FONTDESCRIPTOR* pFont = FX_Alloc(FX_FONTDESCRIPTOR, 1); - memset(pFont, 0, sizeof(FX_FONTDESCRIPTOR)); - pFont->uCharSet = lf.lfCharSet; - pFont->dwFontStyles = GetGdiFontStyles(lf); - FXSYS_wcsncpy(pFont->wsFontFace, (const wchar_t*)lf.lfFaceName, 31); - pFont->wsFontFace[31] = 0; - memcpy(&pFont->FontSignature, &lpntme->ntmFontSig, - sizeof(lpntme->ntmFontSig)); - reinterpret_cast<std::deque<FX_FONTDESCRIPTOR>*>(lParam)->push_back(*pFont); - FX_Free(pFont); + FX_FONTDESCRIPTOR font; + memset(&font, 0, sizeof(FX_FONTDESCRIPTOR)); + font.uCharSet = lf.lfCharSet; + font.dwFontStyles = GetGdiFontStyles(lf); + FXSYS_wcsncpy(font.wsFontFace, (const wchar_t*)lf.lfFaceName, 31); + font.wsFontFace[31] = 0; + memcpy(&font.FontSignature, &lpntme->ntmFontSig, sizeof(lpntme->ntmFontSig)); + reinterpret_cast<std::deque<FX_FONTDESCRIPTOR>*>(lParam)->push_back(font); return 1; } -void EnumGdiFonts(std::deque<FX_FONTDESCRIPTOR>* fonts, - const wchar_t* pwsFaceName, - wchar_t wUnicode) { - HDC hDC = ::GetDC(nullptr); +std::deque<FX_FONTDESCRIPTOR> EnumGdiFonts(const wchar_t* pwsFaceName, + wchar_t wUnicode) { + std::deque<FX_FONTDESCRIPTOR> fonts; LOGFONTW lfFind; memset(&lfFind, 0, sizeof(lfFind)); lfFind.lfCharSet = DEFAULT_CHARSET; @@ -193,16 +190,16 @@ void EnumGdiFonts(std::deque<FX_FONTDESCRIPTOR>* fonts, FXSYS_wcsncpy(lfFind.lfFaceName, pwsFaceName, 31); lfFind.lfFaceName[31] = 0; } + HDC hDC = ::GetDC(nullptr); EnumFontFamiliesExW(hDC, (LPLOGFONTW)&lfFind, (FONTENUMPROCW)GdiFontEnumProc, - (LPARAM)fonts, 0); + (LPARAM)&fonts, 0); ::ReleaseDC(nullptr, hDC); + return fonts; } } // namespace -CFGAS_FontMgr::CFGAS_FontMgr() : m_FontFaces(100) { - EnumGdiFonts(&m_FontFaces, nullptr, 0xFEFF); -} +CFGAS_FontMgr::CFGAS_FontMgr() : m_FontFaces(EnumGdiFonts(nullptr, 0xFEFF)) {} CFGAS_FontMgr::~CFGAS_FontMgr() = default; @@ -224,6 +221,7 @@ const FX_FONTDESCRIPTOR* CFGAS_FontMgr::FindFont(const wchar_t* pszFontFamily, params.pwsFamily = pszFontFamily; params.dwFontStyles = dwFontStyles; params.matchParagraphStyle = matchParagraphStyle; + const FX_FONTDESCRIPTOR* pDesc = MatchDefaultFont(¶ms, m_FontFaces); if (pDesc) return pDesc; @@ -231,10 +229,8 @@ const FX_FONTDESCRIPTOR* CFGAS_FontMgr::FindFont(const wchar_t* pszFontFamily, if (!pszFontFamily) return nullptr; - std::deque<FX_FONTDESCRIPTOR> namedFonts; - EnumGdiFonts(&namedFonts, pszFontFamily, wUnicode); params.pwsFamily = nullptr; - pDesc = MatchDefaultFont(¶ms, namedFonts); + pDesc = MatchDefaultFont(¶ms, EnumGdiFonts(pszFontFamily, wUnicode)); if (!pDesc) return nullptr; |