After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 751677 - per-widget font options
per-widget font options
Status: RESOLVED FIXED
Product: gtk+
Classification: Platform
Component: Widget: Other
unspecified
Other Linux
: Normal normal
: ---
Assigned To: gtk-bugs
gtk-bugs
Depends on:
Blocks:
 
 
Reported: 2015-06-29 21:02 UTC by Matthias Clasen
Modified: 2015-07-01 14:37 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Add gtk_widget_set_font_options and gtk_widget_get_font_options (4.37 KB, patch)
2015-06-30 18:07 UTC, Arc Riley
none Details | Review
Add gtk_widget_set_font_options and gtk_widget_get_font_options (4.57 KB, patch)
2015-06-30 21:40 UTC, Arc Riley
none Details | Review
Add gtk_widget_set_font_options and gtk_widget_get_font_options (5.59 KB, patch)
2015-06-30 22:23 UTC, Arc Riley
committed Details | Review

Description Matthias Clasen 2015-06-29 21:02:22 UTC
gnome-builder has a need for overriding font options for certain widgets.

The api should look like this:

GDK_AVAILABLE_IN_3_18
void gtk_widget_set_font_options (GdkWidget                  *widget,
                                  const cairo_font_options_t *options);
GDK_AVAILABLE_IN_3_!8
const cairo_font_options_t *gtk_widget_get_font_options (GtkWidget *widget);

And it just needs to be hooked into gtkwidget.c:update_pango_context
Comment 1 Arc Riley 2015-06-30 18:07:32 UTC
Created attachment 306427 [details] [review]
Add gtk_widget_set_font_options and  gtk_widget_get_font_options
Comment 2 Christian Hergert 2015-06-30 20:34:26 UTC
Review of attachment 306427 [details] [review]:

Thanks for working on this

::: gtk/gtkwidget.c
@@ +10383,3 @@
+  cairo_font_options_t *options_copy = NULL;
+
+  g_return_if_fail (GTK_IS_WIDGET (widget));

if (options == widget->priv->font_options)
  return;

@@ -10354,5 +10356,34 @@
-      if (screen)
-	{
-	  pango_cairo_context_set_font_options (context,
... 2 more ...
+      if (widget->priv->font_options)
+        {
+          pango_cairo_context_set_font_options (context,
... 31 more ...

We need to use C89 comments: /* foo */

@@ +10398,3 @@
+  if (widget->priv->font_options != NULL)
+    cairo_font_options_destroy(widget->priv->font_options);
+  widget->priv->font_options = options_copy;

I think we are missing a free of the options when the object is freed. Probably best to put this in dispose or finalize callbacks.
Comment 3 Matthias Clasen 2015-06-30 20:41:04 UTC
Review of attachment 306427 [details] [review]:

Thanks for the patch! Only minor changes needed.

One thing that is missing here is that you need to destroy the font_options in finalize.

::: gtk/gtkwidget.c
@@ +10375,3 @@
+ * Sets the #cairo_font_options_t used for Pango rendering. When not set,
+ * the defaults font options for the #GdkScreen will be used.
+ *

You need to add a

Since: 3.18

at the end of the doc comment here.

@@ +10388,3 @@
+    {
+      // On malloc failure this returns a copy of a dummy no-op font options
+      options_copy = cairo_font_options_copy(options);

GTK+ coding style has a space before ( in function calls. That needs fixing throughout

@@ +10398,3 @@
+  if (widget->priv->font_options != NULL)
+    cairo_font_options_destroy(widget->priv->font_options);
+  widget->priv->font_options = options_copy;

Looking at the corresponding code in gdk_screen_set_font_options, I don't think we have to handle oom here. I would just do this the same way we do in that function:

 if (priv->font_options != options)
    { 
      if (priv->font_options)
        cairo_font_options_destroy (priv->font_options);

      if (options)
        priv->font_options = cairo_font_options_copy (options);
      else
        priv->font_options = NULL;

@@ +10410,3 @@
+ *
+ * Returns: (transfer none): the #cairo_font_options_t or %NULL if not set
+ *

Since: 3.18 here as well
Comment 4 Arc Riley 2015-06-30 21:40:03 UTC
Created attachment 306442 [details] [review]
Add gtk_widget_set_font_options and gtk_widget_get_font_options
Comment 5 Matthias Clasen 2015-06-30 22:20:29 UTC
Review of attachment 306442 [details] [review]:

Looks good now, thanks!
Comment 6 Arc Riley 2015-06-30 22:23:46 UTC
Created attachment 306446 [details] [review]
Add gtk_widget_set_font_options and gtk_widget_get_font_options
Comment 7 Matthias Clasen 2015-06-30 22:36:40 UTC
Review of attachment 306446 [details] [review]:

ok
Comment 8 Matthias Clasen 2015-07-01 14:37:55 UTC
Attachment 306446 [details] pushed as 15c73a2 - Add gtk_widget_set_font_options and gtk_widget_get_font_options