[msw/font] If the face name might be truncated, try to get the full face name (PR #26078)

29 views
Skip to first unread message

moi15moi

unread,
Jan 7, 2026, 9:31:23 PM (4 days ago) Jan 7
to wx-...@googlegroups.com, Subscribed

Fix: #25333
LOGFONT.lfFaceName has a defined size (32). Because of that, the face name can be truncated (see the issue for a font with a family name longer then 31 characters). To avoid this problem, we can just call GetOutlineTextMetrics and use it's otmpFamilyName which is not truncated.

To test this, I used https://github.com/wxWidgets/wxWidgets/tree/1b582af60d99388b56b383fe240b647387a5e4b4/samples/font

In the issue, you mentionned I should just edit wxFontEnumerator, but actually, I also needed to edit wxFontRefData because with the sample, if I use Select -> Select font, the textbox will contain the truncated face name if I don't add a check with wxFontRefData.


You can view, comment on, or merge this pull request online at:

  https://github.com/wxWidgets/wxWidgets/pull/26078

Commit Summary

  • afd73e8 [msw/font] If the face name might be truncated, try to get the full face name

File Changes

(4 files)

Patch Links:


Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/26078@github.com>

VZ

unread,
Jan 8, 2026, 9:39:09 AM (3 days ago) Jan 8
to wx-...@googlegroups.com, Subscribed

@vadz commented on this pull request.

Thanks, this looks good to me and could be merged and even backported to 3.2, as it doesn't affect ABI.

It would be nice if you could please address the various minor comments below. TIA!


In include/wx/fontutil.h:

> +#if defined(__WXMSW__)
+// Helper function to get the non-truncated face name from an HFONT
+WXDLLIMPEXP_CORE wxString GetMSWFaceNameFromHFONT(HFONT hFont);
+#endif // __WXMSW__
+

This should go to include/wx/msw/private.h or maybe a new include/wx/msw/private/font.h, I don't think there is any need to make it public.


In src/msw/fontenum.cpp:

> @@ -90,6 +91,22 @@ class wxFontEnumeratorHelper
 // private functions
 // ----------------------------------------------------------------------------
 
+
+// Helper function to get the non-truncated face name from a LOGFONT.
+static wxString GetMSWFaceNameFromLogFont(const LOGFONT* lf)
+{
+    HFONT hFont = ::CreateFontIndirect(lf);
⬇️ Suggested change
-    HFONT hFont = ::CreateFontIndirect(lf);
+    AutoHFONT hFont(lf);

and then there is no need for wxON_BLOCK_EXIT.


In src/msw/font.cpp:

> @@ -115,7 +115,9 @@ class WXDLLEXPORT wxFontRefData: public wxGDIRefData
     wxString GetFaceName() const
     {
         wxString facename = m_nativeFontInfo.GetFaceName();
-        if ( facename.empty() )
+
+        // If the facename.size() is 31, the facename might be truncated

moi15moi

unread,
Jan 8, 2026, 7:03:14 PM (3 days ago) Jan 8
to wx-...@googlegroups.com, Push

@moi15moi pushed 1 commit.

  • a31d854 [msw/font] If the face name might be truncated, try to get the full face name


View it on GitHub or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/26078/before/afd73e80ccb28e6f55b106b371adb2bff5d3484d/after/a31d854c3bc5de8c95398272f4a27054f65952d0@github.com>

moi15moi

unread,
Jan 8, 2026, 7:19:14 PM (3 days ago) Jan 8
to wx-...@googlegroups.com, Subscribed

@moi15moi commented on this pull request.


In include/wx/fontutil.h:

> +#if defined(__WXMSW__)
+// Helper function to get the non-truncated face name from an HFONT
+WXDLLIMPEXP_CORE wxString GetMSWFaceNameFromHFONT(HFONT hFont);
+#endif // __WXMSW__
+

I added it in include/wx/msw/private.h


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/26078/review/3641820847@github.com>

moi15moi

unread,
Jan 8, 2026, 7:19:32 PM (3 days ago) Jan 8
to wx-...@googlegroups.com, Subscribed

@moi15moi commented on this pull request.


In src/msw/fontenum.cpp:

> @@ -90,6 +91,22 @@ class wxFontEnumeratorHelper
 // private functions
 // ----------------------------------------------------------------------------
 
+
+// Helper function to get the non-truncated face name from a LOGFONT.
+static wxString GetMSWFaceNameFromLogFont(const LOGFONT* lf)
+{
+    HFONT hFont = ::CreateFontIndirect(lf);

Fixed in last commit


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/26078/review/3641821676@github.com>

moi15moi

unread,
Jan 8, 2026, 7:19:48 PM (3 days ago) Jan 8
to wx-...@googlegroups.com, Subscribed

@moi15moi commented on this pull request.


In src/msw/font.cpp:

VZ

unread,
Jan 10, 2026, 9:48:05 AM (yesterday) Jan 10
to wx-...@googlegroups.com, Push

@vadz pushed 1 commit.

  • 85fd48d fixup! [msw/font] If the face name might be truncated, try to get the full face name


View it on GitHub or unsubscribe.
You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/26078/before/a31d854c3bc5de8c95398272f4a27054f65952d0/after/85fd48df5d4a28396eeea258f486e6a9afa4521b@github.com>

VZ

unread,
Jan 10, 2026, 9:49:01 AM (yesterday) Jan 10
to wx-...@googlegroups.com, Subscribed
vadz left a comment (wxWidgets/wxWidgets#26078)

I've made a couple of minor changes to simplify this and pushed it in this branch — please let me know if you have any objections, otherwise I'll merge this soon. Thanks!


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/26078/c3732927418@github.com>

moi15moi

unread,
Jan 10, 2026, 10:13:25 AM (yesterday) Jan 10
to wx-...@googlegroups.com, Subscribed
moi15moi left a comment (wxWidgets/wxWidgets#26078)

If it work and is better in term of maintenance, go for it.


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/26078/c3732992566@github.com>

VZ

unread,
Jan 10, 2026, 10:31:51 AM (yesterday) Jan 10
to wx-...@googlegroups.com, Subscribed

Closed #26078 via c73b1b1.


Reply to this email directly, view it on GitHub, or unsubscribe.

You are receiving this because you are subscribed to this thread.Message ID: <wxWidgets/wxWidgets/pull/26078/issue_event/21964077139@github.com>

Reply all
Reply to author
Forward
0 new messages