diff options
author | George Hazan <george.hazan@gmail.com> | 2024-10-29 19:00:23 +0300 |
---|---|---|
committer | George Hazan <george.hazan@gmail.com> | 2024-10-29 19:00:23 +0300 |
commit | 6dfe0158622a7133ac3a8b149eb0280c86673105 (patch) | |
tree | 3b2eb96e0fe1bb0427befba912e8a5f31b71ff0f /plugins | |
parent | 4ff0acc120ea0334dc36c2f11adab478c92803a0 (diff) |
fixes #4624 (GDI leaks in NewStory)
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/NewStory/src/history_control.h | 3 | ||||
-rw-r--r-- | plugins/NewStory/src/webpage.cpp | 53 |
2 files changed, 33 insertions, 23 deletions
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<std::wstring> 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 @@ -55,6 +55,16 @@ INT_PTR SvcFileReady(WPARAM wParam, LPARAM) } ///////////////////////////////////////////////////////////////////////////////////////// + +static std::set<std::wstring> g_installed_fonts; + +int CALLBACK EnumFontsProc(const LOGFONTW *lplf, const TEXTMETRIC *, DWORD, LPARAM) +{ + g_installed_fonts.insert(lplf->lfFaceName); + return 1; +} + +///////////////////////////////////////////////////////////////////////////////////////// // Litehtml interface struct @@ -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; |