From 6dfe0158622a7133ac3a8b149eb0280c86673105 Mon Sep 17 00:00:00 2001 From: George Hazan Date: Tue, 29 Oct 2024 19:00:23 +0300 Subject: fixes #4624 (GDI leaks in NewStory) --- plugins/NewStory/src/history_control.h | 3 -- plugins/NewStory/src/webpage.cpp | 53 +++++++++++++++++++++------------- 2 files changed, 33 insertions(+), 23 deletions(-) (limited to 'plugins') diff --git a/plugins/NewStory/src/history_control.h b/plugins/NewStory/src/history_control.h index a313a85091..5826e8265f 100644 --- a/plugins/NewStory/src/history_control.h +++ b/plugins/NewStory/src/history_control.h @@ -14,7 +14,6 @@ class NSWebPage : public document_container position::vector m_clips; HRGN m_hClipRgn; - std::set m_installed_fonts; HDC m_tmp_hdc; NewstoryListData &ctrl; @@ -74,8 +73,6 @@ class NSWebPage : public document_container void clear_images(); - static int CALLBACK EnumFontsProc(const LOGFONT *lplf, const TEXTMETRIC *lptm, DWORD dwType, LPARAM lpData); - public: NSWebPage(NewstoryListData &_1); ~NSWebPage(); diff --git a/plugins/NewStory/src/webpage.cpp b/plugins/NewStory/src/webpage.cpp index 3e098fbd37..d9cdb7149b 100644 --- a/plugins/NewStory/src/webpage.cpp +++ b/plugins/NewStory/src/webpage.cpp @@ -54,6 +54,16 @@ INT_PTR SvcFileReady(WPARAM wParam, LPARAM) return 0; } +///////////////////////////////////////////////////////////////////////////////////////// + +static std::set g_installed_fonts; + +int CALLBACK EnumFontsProc(const LOGFONTW *lplf, const TEXTMETRIC *, DWORD, LPARAM) +{ + g_installed_fonts.insert(lplf->lfFaceName); + return 1; +} + ///////////////////////////////////////////////////////////////////////////////////////// // Litehtml interface @@ -121,12 +131,14 @@ NSWebPage::NSWebPage(NewstoryListData &_1) : m_hClipRgn = NULL; m_tmp_hdc = GetDC(NULL); - EnumFonts(m_tmp_hdc, NULL, EnumFontsProc, (LPARAM)this); - m_installed_fonts.insert(L"monospace"); - m_installed_fonts.insert(L"serif"); - m_installed_fonts.insert(L"sans-serif"); - m_installed_fonts.insert(L"fantasy"); - m_installed_fonts.insert(L"cursive"); + if (g_installed_fonts.empty()) { + EnumFonts(m_tmp_hdc, NULL, EnumFontsProc, 0); + g_installed_fonts.insert(L"monospace"); + g_installed_fonts.insert(L"serif"); + g_installed_fonts.insert(L"sans-serif"); + g_installed_fonts.insert(L"fantasy"); + g_installed_fonts.insert(L"cursive"); + } } NSWebPage::~NSWebPage() @@ -139,6 +151,9 @@ NSWebPage::~NSWebPage() g_arMissingFiles.remove(g_arMissingFiles.indexOf(&it)); } + for (auto &it : m_fonts) + delete_font(it.second.font); + if (m_hClipRgn) DeleteObject(m_hClipRgn); @@ -153,21 +168,19 @@ void NSWebPage::draw() ///////////////////////////////////////////////////////////////////////////////////////// // former win32_container -int CALLBACK NSWebPage::EnumFontsProc(const LOGFONT *lplf, const TEXTMETRIC *, DWORD, LPARAM lpData) -{ - NSWebPage *container = (NSWebPage *)lpData; - container->m_installed_fonts.insert(lplf->lfFaceName); - return 1; -} - static LPCWSTR get_exact_font_name(LPCWSTR facename) { - if (!lstrcmpi(facename, L"monospace")) return L"Courier New"; - else if (!lstrcmpi(facename, L"serif")) return L"Times New Roman"; - else if (!lstrcmpi(facename, L"sans-serif")) return L"Arial"; - else if (!lstrcmpi(facename, L"fantasy")) return L"Impact"; - else if (!lstrcmpi(facename, L"cursive")) return L"Comic Sans MS"; - else return facename; + if (!lstrcmpi(facename, L"monospace")) + return L"Courier New"; + if (!lstrcmpi(facename, L"serif")) + return L"Times New Roman"; + if (!lstrcmpi(facename, L"sans-serif")) + return L"Arial"; + if (!lstrcmpi(facename, L"fantasy")) + return L"Impact"; + if (!lstrcmpi(facename, L"cursive")) + return L"Comic Sans MS"; + return facename; } static void trim_quotes(std::string &str) @@ -189,7 +202,7 @@ uint_ptr NSWebPage::create_font(const char *font_list, int size, int weight, fon trim(name); trim_quotes(name); Utf2T wname(name.c_str()); - if (m_installed_fonts.count(wname.get())) { + if (g_installed_fonts.count(wname.get())) { font_name = wname; found = true; break; -- cgit v1.2.3