SloppyJ
Posts: 2
Joined: Wed Nov 14, 2018 6:45 am

GTK applications ignore font-weight on Raspbian?

Wed Nov 14, 2018 7:09 am

As part of an application I'm developing, I need the font of a few specific labels to be bold. I'm using GTK 3.22, and the application itself is compiled for Windows and Raspbian.

The styling is done via CSS, and works on Windows - more precisely, labels that should be bold appear as such on Windows, and looking at the CSS node for font-weight for one of the labels via GTK_DEBUG=interactive confirms that it is bold. Both OSes are using the same font-family of Sans. It looks like so:

Image

Raspbian, however, seems to ignore the font-weight property: inspecting it via that interactive debug window shows it as 'normal'. It looks like this:

Image

What I've tried to fix the issue:
  • Setting the style provider priority: It's set to 'STYLE_PROVIDER_PRIORITY_USER'.
  • Checking /home/pi/.config/gtk-3.0/gtk.css: It's free from any font related CSS nodes.
  • 'Forcing' the font-weight node to be bold via the CSS tab in the interactive debug window: Doesn't change anything. Changing other properties within this window (like font color, for example) does work, however. Seemingly only font-weight doesn't work.

Am I encountering a GTK bug, or is there some other Raspbian config that I don't know about that needs changing?

spl23
Raspberry Pi Engineer & Forum Moderator
Raspberry Pi Engineer & Forum Moderator
Posts: 353
Joined: Fri Dec 26, 2014 11:02 am

Re: GTK applications ignore font-weight on Raspbian?

Wed Nov 14, 2018 8:36 pm

In my experience, the support for font weights in GTK+ version 3 is fundamentally broken - in certain circumstances, GTK+ 3 only bothers using the font family and size, and ignores weight and style parameters, and it looks to me as if this is what you are hitting. I've raised this as a bug with GNOME in the past, but they don't seem to care.

I'd suggest rebuilding your application against GTK+ 2 rather than 3; you might find it just works properly then with no further changes needed, as (for me, anyway), GTK+ 2's font handling is rather better than GTK+ 3's.

There's nothing I know of in Raspbian which should be breaking font weights in GTK; I ended up creating a custom version of the Piboto font used for the desktop in which the "normal" weight is actually the "light" weight to fix this exact problem!

SloppyJ
Posts: 2
Joined: Wed Nov 14, 2018 6:45 am

Re: GTK applications ignore font-weight on Raspbian?

Thu Nov 15, 2018 12:20 am

Thank you for your input!

That's a shame that they don't care - I had somewhat gathered that it was an internal GTK bug that has been left unfixed seeing as the problem persists as I downgrade GTK 3 versions. Your idea behind targeting GTK+ 2 instead sounds great, but, the application is built on top of gtk-rs, a Rust library used to interact with GTK+, which unfortunately only targets versions 3.6+.

The font idea is interesting, I might consider that in the future. I mainly asked just to ensure that there wasn't something the application was doing incorrectly or some config that could be changed (and out of bewilderment that something in GTK actually worked on Windows and not on Linux!)

Return to “Graphics programming”