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.
https://github.com/wxWidgets/wxWidgets/pull/26078
(4 files)
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
@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!
> +#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.
> @@ -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 pushed 1 commit.
—
View it on GitHub or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
@moi15moi commented on this pull request.
> +#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.![]()
@moi15moi commented on this pull request.
> @@ -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.![]()
@vadz pushed 1 commit.
—
View it on GitHub or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()
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.![]()
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.![]()
—
Reply to this email directly, view it on GitHub, or unsubscribe.
You are receiving this because you are subscribed to this thread.![]()