GTK3/2 + wxSysetmSettings::GetFont(wxSYS_DEFAULT_GUI_FONT) + HiDPI

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

GTK3/2 + wxSysetmSettings::GetFont(wxSYS_DEFAULT_GUI_FONT) + HiDPI

Eran Ifrah
Hi,
I am making an extensive use of custom drawing controls which I draw using wxGCDC.
On Linux with HiDPI (> 96, e.g. 150), the font returned by wxSysetmSettings::GetFont(wxSYS_DEFAULT_GUI_FONT)  does not return the correct size taking into the system DPI into account

To override this, I wrote this simple method which fixes the issue for me:

wxFont GetDefaultGuiFont() {
    wxFont f = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT);
#ifdef __WXGTK__
    static bool once = false;
    static double ratio = 1.0;
    if(!once) {
        GdkScreen *screen = gdk_screen_get_default();
        if(screen) {
            double res = gdk_screen_get_resolution(screen);
            ratio = (res / 96.);
        }
        once = true;
    }
    int pointSize = f.GetPointSize() * ratio;
    f.SetPointSize(pointSize);
#endif
    return f;
}
I tried using wxScreenDC::GetPPI() but it always returns 96*96 (this fails on both GTK2 and GTK3)
so I had to resort to GTK calls.

Any tips on how to avoid GTK calls directly?
Thanks!

--
Eran Ifrah,
Author of CodeLite, a cross platform open source C/C++ IDE: http://www.codelite.org

--
Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.
 
To unsubscribe, send email to [hidden email]
or visit http://groups.google.com/group/wx-users
Reply | Threaded
Open this post in threaded view
|

Re: GTK3/2 + wxSysetmSettings::GetFont(wxSYS_DEFAULT_GUI_FONT) + HiDPI

Vadim Zeitlin-4
On Thu, 13 Sep 2018 11:54:04 +0300 Eran Ifrah wrote:

EI> I am making an extensive use of custom drawing controls which I draw using
EI> wxGCDC.
EI> On Linux with HiDPI (> 96, e.g. 150), the font returned by
EI> wxSysetmSettings::GetFont(wxSYS_DEFAULT_GUI_FONT)  does not return the
EI> correct size taking into the system DPI into account

 What do you think the correct size should be and what is it actually for
you?

EI> To override this, I wrote this simple method which fixes the issue for me:
EI>
EI> wxFont GetDefaultGuiFont() {
EI>     wxFont f = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT);
EI> #ifdef __WXGTK__
EI>     static bool once = false;
EI>     static double ratio = 1.0;
EI>     if(!once) {
EI>         GdkScreen *screen = gdk_screen_get_default();
EI>         if(screen) {
EI>             double res = gdk_screen_get_resolution(screen);
EI>             ratio = (res / 96.);
EI>         }
EI>         once = true;
EI>     }
EI>     int pointSize = f.GetPointSize() * ratio;
EI>     f.SetPointSize(pointSize);
EI> #endif

 I don't see how could this work with 150 DPI and integer point sizes,
doesn't this just keep the same point size? FWIW with the latest master you
can use SetFractionalPointSize() which does allow you to scale the font
size by DPI.

EI> I tried using wxScreenDC::GetPPI() but it always returns 96*96 (this fails
EI> on both GTK2 and GTK3)

 I've started working on fixing this some time ago but unfortunately never
finished it. It should be done before 3.2.0.

 Regards,
VZ

--
TT-Solutions: wxWidgets consultancy and technical support
               http://www.tt-solutions.com/

attachment0 (203 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: GTK3/2 + wxSysetmSettings::GetFont(wxSYS_DEFAULT_GUI_FONT) + HiDPI

Eran Ifrah


On Wed, Sep 19, 2018 at 1:26 AM Vadim Zeitlin <[hidden email]> wrote:
On Thu, 13 Sep 2018 11:54:04 +0300 Eran Ifrah wrote:

EI> I am making an extensive use of custom drawing controls which I draw using
EI> wxGCDC.
EI> On Linux with HiDPI (> 96, e.g. 150), the font returned by
EI> wxSysetmSettings::GetFont(wxSYS_DEFAULT_GUI_FONT)  does not return the
EI> correct size taking into the system DPI into account

 What do you think the correct size should be and what is it actually for
you?

From what I understood (I might be wrong here, not a DPI expert) the font size returned should be the side defined by the user multiplied by the 'scaling factor'. On Ubuntu + GNOME you can adjust the font size using the "Tweak Tool" and set the scaling factor to 1.5 or any fraction. On LXDE (my main box with Debian installed), I changed the DPI and set it to "144" (144/96=1.5)
My default font size is 10, so it should be 10x1.5=15. Again, this is from my try and observe testings

EI> To override this, I wrote this simple method which fixes the issue for me:
EI>
EI> wxFont GetDefaultGuiFont() {
EI>     wxFont f = wxSystemSettings::GetFont(wxSYS_DEFAULT_GUI_FONT);
EI> #ifdef __WXGTK__
EI>     static bool once = false;
EI>     static double ratio = 1.0;
EI>     if(!once) {
EI>         GdkScreen *screen = gdk_screen_get_default();
EI>         if(screen) {
EI>             double res = gdk_screen_get_resolution(screen);
EI>             ratio = (res / 96.);
EI>         }
EI>         once = true;
EI>     }
EI>     int pointSize = f.GetPointSize() * ratio;
EI>     f.SetPointSize(pointSize);
EI> #endif

 I don't see how could this work with 150 DPI and integer point sizes,
doesn't this just keep the same point size? FWIW with the latest master you
can use SetFractionalPointSize() which does allow you to scale the font
size by DPI.
Yes, you might lose some fine tuning but it will look much better than the current situation.
i.e. rendering the text with 15 (instead of 15.6) vs 10 is still much better. The "int" will only lose the precision, but the result is looking good.

I am attaching two screenshots taken from a VM with scaling factor set to 1.5.
In the first one, you I highlighted with RED areas where custom rendering is done, you can see that the font is small 
compared to other elements. In the second, I have highlighted in green the parts where I am using custom rendering with my fix, you can see that the font size blends in with the rest of the native widgets


EI> I tried using wxScreenDC::GetPPI() but it always returns 96*96 (this fails
EI> on both GTK2 and GTK3)

 I've started working on fixing this some time ago but unfortunately never
finished it. It should be done before 3.2.0.

Thanks, this will help me remove the "gtk" code  from my code base, however, I still would expect that the font size is fixed
internally without me needing to call "Set{Fractional}PointSize". This should have been done by wxSystemSetting::GetFont() call

 Regards,
VZ

--
TT-Solutions: wxWidgets consultancy and technical support
               http://www.tt-solutions.com/


--
Eran Ifrah,
Author of CodeLite, a cross platform open source C/C++ IDE: http://www.codelite.org

--
Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.
 
To unsubscribe, send email to [hidden email]
or visit http://groups.google.com/group/wx-users

small-font-scaling-factor-set-to-1.5-ubuntu.png (302K) Download Attachment
small-font-scaling-factor-set-to-1.5-ubuntu-with-my-fix.png (221K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re[2]: GTK3/2 + wxSysetmSettings::GetFont(wxSYS_DEFAULT_GUI_FONT) + HiDPI

Vadim Zeitlin-4
On Wed, 19 Sep 2018 10:25:44 +0300 Eran Ifrah wrote:

EI> On Wed, Sep 19, 2018 at 1:26 AM Vadim Zeitlin <[hidden email]> wrote:
EI>
EI> > On Thu, 13 Sep 2018 11:54:04 +0300 Eran Ifrah wrote:
EI> >
EI> > EI> I am making an extensive use of custom drawing controls which I draw
EI> > using
EI> > EI> wxGCDC.
EI> > EI> On Linux with HiDPI (> 96, e.g. 150), the font returned by
EI> > EI> wxSysetmSettings::GetFont(wxSYS_DEFAULT_GUI_FONT)  does not return the
EI> > EI> correct size taking into the system DPI into account
EI> >
EI> >  What do you think the correct size should be and what is it actually for
EI> > you?
EI> >
EI> From what I understood (I might be wrong here, not a DPI expert) the font
EI> size returned should be the side defined by the user multiplied by the
EI> 'scaling factor'.

 Well, I don't know if I'm a DPI expert neither, but I don't think this is
correct. Font size in points refers to its physical size, i.e. a 12pt font
is supposed to be 1/6 inch high. This doesn't depend on the DPI at all. So
IMO wxFont::GetPointSize() should always return 10 if you default font size
is 10.

EI> On Ubuntu + GNOME you can adjust the font size using the
EI> "Tweak Tool" and set the scaling factor to 1.5 or any fraction.

 Scaling factor is supposed to be used in order to ensure that 12pt font
is still 1/6in high even when your logical pixels are smaller (by this
factor) than physical pixels. I.e. with GTK+ 2 your 12pt font would
actually have 1/12in high and scaling factor fixes this. But it still
doesn't change the fact that the font size in points remains 12.

EI> I am attaching two screenshots taken from a VM with scaling factor set to
EI> 1.5. In the first one, you I highlighted with RED areas where custom
EI> rendering is done, you can see that the font is small compared to other
EI> elements. In the second, I have highlighted in green the parts where I
EI> am using custom rendering with my fix, you can see that the font size
EI> blends in with the rest of the native widgets

 Yes, something seems wrong here, but I don't think it's the point size
which is wrong. As usual, it's difficult to understand what exactly is
going on with this custom rendering. But if you use wxNORMAL_FONT with
DrawText(), it definitely should come out at the same size as when using
the native controls. If this is not the case for you, could you please open
a ticket with the minimal patch to the (minimal) sample showing the
problem?

 Thanks,
VZ

--
TT-Solutions: wxWidgets consultancy and technical support
               http://www.tt-solutions.com/

attachment0 (203 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Re[2]: GTK3/2 + wxSysetmSettings::GetFont(wxSYS_DEFAULT_GUI_FONT) + HiDPI

Eran Ifrah
Thanks, I will try using wxNORMAL_FONT instead of wxSystemSetting::GetFont(wxSYS_DEFAULT_GUI_FONT)



On Wed, Sep 19, 2018 at 3:14 PM Vadim Zeitlin <[hidden email]> wrote:
On Wed, 19 Sep 2018 10:25:44 +0300 Eran Ifrah wrote:

EI> On Wed, Sep 19, 2018 at 1:26 AM Vadim Zeitlin <[hidden email]> wrote:
EI>
EI> > On Thu, 13 Sep 2018 11:54:04 +0300 Eran Ifrah wrote:
EI> >
EI> > EI> I am making an extensive use of custom drawing controls which I draw
EI> > using
EI> > EI> wxGCDC.
EI> > EI> On Linux with HiDPI (> 96, e.g. 150), the font returned by
EI> > EI> wxSysetmSettings::GetFont(wxSYS_DEFAULT_GUI_FONT)  does not return the
EI> > EI> correct size taking into the system DPI into account
EI> >
EI> >  What do you think the correct size should be and what is it actually for
EI> > you?
EI> >
EI> From what I understood (I might be wrong here, not a DPI expert) the font
EI> size returned should be the side defined by the user multiplied by the
EI> 'scaling factor'.

 Well, I don't know if I'm a DPI expert neither, but I don't think this is
correct. Font size in points refers to its physical size, i.e. a 12pt font
is supposed to be 1/6 inch high. This doesn't depend on the DPI at all. So
IMO wxFont::GetPointSize() should always return 10 if you default font size
is 10.

EI> On Ubuntu + GNOME you can adjust the font size using the
EI> "Tweak Tool" and set the scaling factor to 1.5 or any fraction.

 Scaling factor is supposed to be used in order to ensure that 12pt font
is still 1/6in high even when your logical pixels are smaller (by this
factor) than physical pixels. I.e. with GTK+ 2 your 12pt font would
actually have 1/12in high and scaling factor fixes this. But it still
doesn't change the fact that the font size in points remains 12.

EI> I am attaching two screenshots taken from a VM with scaling factor set to
EI> 1.5. In the first one, you I highlighted with RED areas where custom
EI> rendering is done, you can see that the font is small compared to other
EI> elements. In the second, I have highlighted in green the parts where I
EI> am using custom rendering with my fix, you can see that the font size
EI> blends in with the rest of the native widgets

 Yes, something seems wrong here, but I don't think it's the point size
which is wrong. As usual, it's difficult to understand what exactly is
going on with this custom rendering. But if you use wxNORMAL_FONT with
DrawText(), it definitely should come out at the same size as when using
the native controls. If this is not the case for you, could you please open
a ticket with the minimal patch to the (minimal) sample showing the
problem?

 Thanks,
VZ

--
TT-Solutions: wxWidgets consultancy and technical support
               http://www.tt-solutions.com/


--
Eran Ifrah,
Author of CodeLite, a cross platform open source C/C++ IDE: http://www.codelite.org

--
Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.
 
To unsubscribe, send email to [hidden email]
or visit http://groups.google.com/group/wx-users
Reply | Threaded
Open this post in threaded view
|

Re[4]: GTK3/2 + wxSysetmSettings::GetFont(wxSYS_DEFAULT_GUI_FONT) + HiDPI

Vadim Zeitlin-4
On Wed, 19 Sep 2018 15:46:30 +0300 Eran Ifrah wrote:

EI> Thanks, I will try using wxNORMAL_FONT instead of
EI> wxSystemSetting::GetFont(wxSYS_DEFAULT_GUI_FONT)

 Sorry for the confusion, they're the same thing, I just used the former
because it's shorter, so this is not going to change anything.

 Regards,
VZ

--
TT-Solutions: wxWidgets consultancy and technical support
               http://www.tt-solutions.com/

attachment0 (203 bytes) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Re[4]: GTK3/2 + wxSysetmSettings::GetFont(wxSYS_DEFAULT_GUI_FONT) + HiDPI

Eran Ifrah
I opened a ticket with minimal patch attached


On Wed, Sep 19, 2018 at 3:48 PM Vadim Zeitlin <[hidden email]> wrote:
On Wed, 19 Sep 2018 15:46:30 +0300 Eran Ifrah wrote:

EI> Thanks, I will try using wxNORMAL_FONT instead of
EI> wxSystemSetting::GetFont(wxSYS_DEFAULT_GUI_FONT)

 Sorry for the confusion, they're the same thing, I just used the former
because it's shorter, so this is not going to change anything.

 Regards,
VZ

--
TT-Solutions: wxWidgets consultancy and technical support
               http://www.tt-solutions.com/


--
Eran Ifrah,
Author of CodeLite, a cross platform open source C/C++ IDE: http://www.codelite.org

--
Please read http://www.wxwidgets.org/support/mlhowto.htm before posting.
 
To unsubscribe, send email to [hidden email]
or visit http://groups.google.com/group/wx-users