summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGeorge Hazan <george.hazan@gmail.com>2024-10-29 19:00:23 +0300
committerGeorge Hazan <george.hazan@gmail.com>2024-10-29 19:00:23 +0300
commit6dfe0158622a7133ac3a8b149eb0280c86673105 (patch)
tree3b2eb96e0fe1bb0427befba912e8a5f31b71ff0f
parent4ff0acc120ea0334dc36c2f11adab478c92803a0 (diff)
fixes #4624 (GDI leaks in NewStory)
-rw-r--r--libs/litehtml/include/litehtml/document.h1
-rw-r--r--libs/litehtml/include/litehtml/document_container.h2
-rw-r--r--libs/litehtml/src/document.cpp15
-rw-r--r--plugins/NewStory/src/history_control.h3
-rw-r--r--plugins/NewStory/src/webpage.cpp53
5 files changed, 39 insertions, 35 deletions
diff --git a/libs/litehtml/include/litehtml/document.h b/libs/litehtml/include/litehtml/document.h
index 3f94565655..7119636ffe 100644
--- a/libs/litehtml/include/litehtml/document.h
+++ b/libs/litehtml/include/litehtml/document.h
@@ -50,7 +50,6 @@ namespace litehtml
std::shared_ptr<element> m_root;
std::shared_ptr<render_item> m_root_render;
document_container* m_container;
- fonts_map m_fonts;
css_text::vector m_css;
litehtml::css m_styles;
litehtml::web_color m_def_color;
diff --git a/libs/litehtml/include/litehtml/document_container.h b/libs/litehtml/include/litehtml/document_container.h
index 395c6cd1a7..95efe1eb6b 100644
--- a/libs/litehtml/include/litehtml/document_container.h
+++ b/libs/litehtml/include/litehtml/document_container.h
@@ -33,6 +33,8 @@ namespace litehtml
class document_container
{
public:
+ fonts_map m_fonts;
+
virtual litehtml::uint_ptr create_font(const char* faceName, int size, int weight, litehtml::font_style italic, unsigned int decoration, litehtml::font_metrics* fm) = 0;
virtual void delete_font(litehtml::uint_ptr hFont) = 0;
virtual int text_width(const char* text, litehtml::uint_ptr hFont) = 0;
diff --git a/libs/litehtml/src/document.cpp b/libs/litehtml/src/document.cpp
index 471f9204c7..13bfe0e991 100644
--- a/libs/litehtml/src/document.cpp
+++ b/libs/litehtml/src/document.cpp
@@ -37,13 +37,6 @@ document::document(document_container* container)
document::~document()
{
m_over_element = nullptr;
- if(m_container)
- {
- for(auto& font : m_fonts)
- {
- m_container->delete_font(font.second.font);
- }
- }
}
document::ptr document::createFromString(
@@ -463,7 +456,7 @@ uint_ptr document::add_font( const char* name, int size, const char* weight, con
key += ":";
key += decoration;
- if(m_fonts.find(key) == m_fonts.end())
+ if(m_container->m_fonts.find(key) == m_container->m_fonts.end())
{
font_style fs = (font_style) value_index(style, font_style_strings, font_style_normal);
int fw = value_index(weight, font_weight_strings, -1);
@@ -517,7 +510,7 @@ uint_ptr document::add_font( const char* name, int size, const char* weight, con
font_item fi= {0, {}};
fi.font = m_container->create_font(name, size, fw, fs, decor, &fi.metrics);
- m_fonts[key] = fi;
+ m_container->m_fonts[key] = fi;
ret = fi.font;
if(fm)
{
@@ -551,9 +544,9 @@ uint_ptr document::get_font( const char* name, int size, const char* weight, con
key += ":";
key += decoration;
- auto el = m_fonts.find(key);
+ auto el = m_container->m_fonts.find(key);
- if(el != m_fonts.end())
+ if(el != m_container->m_fonts.end())
{
if(fm)
{
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;