Bug 502105 - [GTK4] gtk_widget_override_font() is deprecated
Summary: [GTK4] gtk_widget_override_font() is deprecated
Status: RESOLVED FIXED
Alias: None
Product: Platform
Classification: Eclipse Project
Component: SWT (show other bugs)
Version: 4.7   Edit
Hardware: PC Linux
: P3 normal (vote)
Target Milestone: 4.19   Edit
Assignee: Platform-SWT-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords: triaged
: 496876 544084 (view as bug list)
Depends on:
Blocks: 502193
  Show dependency tree
 
Reported: 2016-09-25 00:03 EDT by Eric Williams CLA
Modified: 2021-11-26 14:25 EST (History)
6 users (show)

See Also:


Attachments
Screenshot showing same snippet in Broadway vs Wayland (63.52 KB, image/png)
2019-08-26 10:35 EDT, Mickael Istria CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Eric Williams CLA 2016-09-25 00:03:59 EDT
The function gtk_widget_override_font() is deprecated since GTK3.16. This is a dynamic function.

https://developer.gnome.org/gtk3/stable/GtkWidget.html#gtk-widget-override-font
Comment 1 Eclipse Genie CLA 2019-01-31 17:06:37 EST
New Gerrit change created: https://git.eclipse.org/r/136117
Comment 2 Eric Williams CLA 2019-02-08 15:53:30 EST
*** Bug 496876 has been marked as a duplicate of this bug. ***
Comment 3 Xi Yan CLA 2019-02-13 14:51:44 EST
*** Bug 544084 has been marked as a duplicate of this bug. ***
Comment 4 Xi Yan CLA 2019-04-18 12:45:02 EDT
(In reply to Eclipse Genie from comment #1)
> New Gerrit change created: https://git.eclipse.org/r/136117

This patch makes setting font entirely through CSS and adds the CSS caching mechanism for all widgets. 

It cannot be merged as setting font through CSS causes an issue where the size of the widgets does not get updated immediately after a font change. This happens for widgets with a container wrapped around the text. (i.e.
Button, Combo, DateTime, List, TabFolder, Table/Tree, etc). 

From some investigation, this is to due to that widgets requires many iterations of the gtk_main loop before size gets updated correctly. One possible workaround is to explicitly calculate the size in SWT after setting font to force the size to be correct immediately (patchset 9), but this is too hacky and causes artifacts to be shown on GTK3 in some cases.
Comment 5 Mickael Istria CLA 2019-05-08 03:29:07 EDT
I upgraded to Fedora 30 (using GTK 3.24.8 and still see same error and new ones, when starting with broadway as backend):

(Eclipse:8357): Pango-CRITICAL **: 09:26:45.562: pango_font_description_set_size: assertion 'size >= 0' failed

*** BUG ***
In pixman_region32_init_rect: Invalid rectangle passed
Set a breakpoint on '_pixman_log_error' to debug
Comment 6 Mickael Istria CLA 2019-08-26 09:25:31 EDT
For this one, on Braodway specifically, text isn't shown while it's shown on plain GTK. Do you think a fix should be provided to Broadway and it's really and purely a SWT bug?
Comment 7 Eric Williams CLA 2019-08-26 09:34:15 EDT
(In reply to Mickael Istria from comment #6)
> For this one, on Braodway specifically, text isn't shown while it's shown on
> plain GTK. Do you think a fix should be provided to Broadway and it's really
> and purely a SWT bug?

The affected widgets (Labels, mostly) use Pango for their text rendering and I believe the bug is either: 1) in Pango itself or 2) in the way SWT is using Pango.


(In reply to Mickael Istria from comment #5)
> I upgraded to Fedora 30 (using GTK 3.24.8 and still see same error and new
> ones, when starting with broadway as backend):
> 
> (Eclipse:8357): Pango-CRITICAL **: 09:26:45.562:
> pango_font_description_set_size: assertion 'size >= 0' failed
> 
> *** BUG ***
> In pixman_region32_init_rect: Invalid rectangle passed
> Set a breakpoint on '_pixman_log_error' to debug


The pango message is definitely related somehow to the bug, the other warning is just a generic one we see even on Wayland/X11.
Comment 8 Mickael Istria CLA 2019-08-26 10:35:05 EDT
Created attachment 279681 [details]
Screenshot showing same snippet in Broadway vs Wayland

See difference for a label with following snippet.
I see the Pango error in Broadway, not in Wayland



public class Snippet34 {

public static void main (String[] args) {
	Display display = new Display();
	Shell shell = new Shell (display);
	shell.setText("Snippet 34");
	Label label = new Label (shell, SWT.BORDER);
	Rectangle clientArea = shell.getClientArea ();
	label.setLocation (clientArea.x, clientArea.y);
	label.setText("Hello!");
	label.pack ();
	shell.pack ();
	shell.open ();
	while (!shell.isDisposed ()) {
		if (!display.readAndDispatch ()) {
			display.sleep ();
		}
	}
	display.dispose ();
}

}
Comment 9 Eric Williams CLA 2019-08-27 11:09:56 EDT
I've reproduced the issue in a native GTK snippet (no SWT), and have filed a bug upstream with GTK: https://gitlab.gnome.org/GNOME/gtk/issues/2119
Comment 10 Eric Williams CLA 2019-08-27 12:56:17 EDT
Furthermore: to work around this issue you can comment out the "GTK.gtk_widget_override_font" call in Widget.setFontDescription(). Setting a custom font won't work if you do this, but all text should render in the default font.
Comment 11 Mickael Istria CLA 2019-08-28 11:32:45 EDT
(In reply to Eric Williams from comment #10)
> Furthermore: to work around this issue you can comment out the
> "GTK.gtk_widget_override_font" call in Widget.setFontDescription(). Setting
> a custom font won't work if you do this, but all text should render in the
> default font.

Good to know, thanks. I may implement this workaround for a demo one day if neither GTK nor SWT are fixed in the meantime.
Comment 12 Eclipse Genie CLA 2020-11-26 14:46:45 EST
New Gerrit change created: https://git.eclipse.org/r/c/platform/eclipse.platform.swt/+/172892
Comment 14 Joel Majano CLA 2021-11-26 14:22:25 EST
This bug appears to have been a bug filed against GTK3 but was in fact a GTK bug. It then appears to have been changed to GTK4 since gtk_widget_override_font() is deprecated in the new version. A gerrit patch was created and merged to fix this, so that Snippet 55 works correctly in GTK4. 

Marking this as resolved as the bug that was filed in GTK was resolved (https://gitlab.gnome.org/GNOME/gtk/issues/2119) and any new GTK4 bugs should have their own bug created.
Comment 15 Joel Majano CLA 2021-11-26 14:25:25 EST
Furthermore, in https://git.eclipse.org/r/c/platform/eclipse.platform.swt/+/136117/ it was decided that this deprecated function would be kept in GTK3 for stability reasons.