Only use font scaling code with GTK 3 or later

It's useless to do it for GTK 2 which doesn't support font scaling
anyhow.
This commit is contained in:
Vadim Zeitlin
2019-11-16 00:50:13 +01:00
parent 4d4e3e71a5
commit ac14c3ffbc

View File

@@ -527,14 +527,12 @@ protected:
int m_mswStateSavedDC; int m_mswStateSavedDC;
#endif #endif
#ifdef __WXGTK__ #ifdef __WXGTK__
// This factor must be applied to the font before actually using it, for
// consistency with the text drawn by GTK itself.
float m_fontScalingFactor;
// Tiny helper actually applying the font. It's convenient because it can // Tiny helper actually applying the font. It's convenient because it can
// be called with a temporary wxFont, as we're going to make a copy of its // be called with a temporary wxFont, as we're going to make a copy of its
// Pango font description inside this function before the font object is // Pango font description inside this function before the font object is
// destroyed. // destroyed.
//
// It's also all we need for GTK < 3.
static void DoApplyFont(PangoLayout* layout, const wxFont& font) static void DoApplyFont(PangoLayout* layout, const wxFont& font)
{ {
pango_layout_set_font_description pango_layout_set_font_description
@@ -544,6 +542,11 @@ protected:
); );
} }
#ifdef __WXGTK3__
// This factor must be applied to the font before actually using it, for
// consistency with the text drawn by GTK itself.
float m_fontScalingFactor;
// Function applying the Pango font description for the given font scaled by // Function applying the Pango font description for the given font scaled by
// the font scaling factor if necessary to the specified layout. // the font scaling factor if necessary to the specified layout.
void ApplyFont(PangoLayout* layout, const wxFont& font) const void ApplyFont(PangoLayout* layout, const wxFont& font) const
@@ -553,7 +556,15 @@ protected:
? font ? font
: font.Scaled(m_fontScalingFactor)); : font.Scaled(m_fontScalingFactor));
} }
#endif #else // GTK < 3
// Provide the same function even if it does nothing in this case to keep
// the same code for all GTK versions.
void ApplyFont(PangoLayout* layout, const wxFont& font) const
{
DoApplyFont(layout, font);
}
#endif // __WXGTK3__
#endif // __WXGTK__
private: private:
cairo_t* m_context; cairo_t* m_context;
@@ -2388,7 +2399,7 @@ wxCairoContext::~wxCairoContext()
void wxCairoContext::Init(cairo_t *context) void wxCairoContext::Init(cairo_t *context)
{ {
#ifdef __WXGTK__ #ifdef __WXGTK3__
// Attempt to find the system font scaling parameter (e.g. "Fonts->Scaling // Attempt to find the system font scaling parameter (e.g. "Fonts->Scaling
// Factor" in Gnome Tweaks, "Force font DPI" in KDE System Settings or // Factor" in Gnome Tweaks, "Force font DPI" in KDE System Settings or
// GDK_DPI_SCALE environment variable). // GDK_DPI_SCALE environment variable).