From 488e7363bc1f41c310024847c6dbc3034fda47dd Mon Sep 17 00:00:00 2001 From: AtesComp Date: Thu, 30 Apr 2026 18:24:53 -0400 Subject: [PATCH] Add support for private fonts to wxQt Use QFontDatabase::addApplicationFont() to implement AddPrivateFont(). Closes #26403. Closes #26419. --- build/cmake/options.cmake | 2 +- configure | 2 +- configure.ac | 2 +- include/wx/chkconf.h | 2 +- src/qt/font.cpp | 27 +++++++++++++++++++++++++++ 5 files changed, 31 insertions(+), 4 deletions(-) diff --git a/build/cmake/options.cmake b/build/cmake/options.cmake index 87b310732f..8ab7d6caf6 100644 --- a/build/cmake/options.cmake +++ b/build/cmake/options.cmake @@ -470,7 +470,7 @@ wx_option(wxUSE_DRAGIMAGE "use wxDragImage") wx_option(wxUSE_UIACTIONSIMULATOR "use wxUIActionSimulator (experimental)") wx_option(wxUSE_DC_TRANSFORM_MATRIX "use wxDC::SetTransformMatrix and related") wx_option(wxUSE_WEBVIEW_WEBKIT "use wxWebView WebKit backend") -if(WIN32 OR APPLE) +if(WIN32 OR APPLE OR WXQT) set(wxUSE_PRIVATE_FONTS_DEFAULT ON) else() set(wxUSE_PRIVATE_FONTS_DEFAULT OFF) diff --git a/configure b/configure index f70cafdeaf..70612cf21d 100755 --- a/configure +++ b/configure @@ -39708,7 +39708,7 @@ $as_echo "yes" >&6; } fi fi - elif test "$wxUSE_MAC" = 1 -o "$wxUSE_MSW" = 1; then + elif test "$wxUSE_QT" = 1 -o "$wxUSE_MAC" = 1 -o "$wxUSE_MSW" = 1; then $as_echo "#define wxUSE_PRIVATE_FONTS 1" >>confdefs.h fi diff --git a/configure.ac b/configure.ac index 3736030019..967585ec0c 100644 --- a/configure.ac +++ b/configure.ac @@ -6800,7 +6800,7 @@ if test "$wxUSE_PRIVATE_FONTS" = "yes"; then ], [AC_MSG_WARN([run-time font loading won't be supported by wxFont])]) fi - elif test "$wxUSE_MAC" = 1 -o "$wxUSE_MSW" = 1; then + elif test "$wxUSE_QT" = 1 -o "$wxUSE_MAC" = 1 -o "$wxUSE_MSW" = 1; then dnl In these ports we don't need anything special. AC_DEFINE(wxUSE_PRIVATE_FONTS) fi diff --git a/include/wx/chkconf.h b/include/wx/chkconf.h index 50890aa85f..5113339f8b 100644 --- a/include/wx/chkconf.h +++ b/include/wx/chkconf.h @@ -2300,7 +2300,7 @@ #endif /* wxUSE_PREFERENCES_EDITOR */ #if wxUSE_PRIVATE_FONTS -# if !defined(__WXMSW__) && !defined(__WXGTK__) && !defined(__WXOSX__) +# if !defined(__WXMSW__) && !defined(__WXGTK__) && !defined(__WXQT__) && !defined(__WXOSX__) # undef wxUSE_PRIVATE_FONTS # define wxUSE_PRIVATE_FONTS 0 # endif diff --git a/src/qt/font.cpp b/src/qt/font.cpp index faa1467f18..2b3ff8f1d6 100644 --- a/src/qt/font.cpp +++ b/src/qt/font.cpp @@ -623,3 +623,30 @@ wxString wxNativeFontInfo::ToUserString() const { return ToString(); } + +// ---------------------------------------------------------------------------- +// Support for adding private fonts +// ---------------------------------------------------------------------------- + +#if wxUSE_PRIVATE_FONTS + +#include "wx/fontenum.h" + +#include + +bool wxFontBase::AddPrivateFont(const wxString& strFilename) +{ + const int iFontID = + QFontDatabase::addApplicationFont( wxQtConvertString(strFilename) ); + if ( iFontID == -1 ) + return false; + + // Ensure that the face names defined by private fonts are recognized by + // our SetFaceName() which uses wxFontEnumerator to check if the name is in + // the list of available faces. + wxFontEnumerator::InvalidateCache(); + + return true; +} + +#endif // wxUSE_PRIVATE_FONTS