summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2022-10-09 13:53:54 +0000
committerMatthias Clasen <mclasen@redhat.com>2022-10-09 13:53:54 +0000
commit6a6ef0f437ecdd2677b7b459d921980ddf77ca31 (patch)
tree3b32329d35bb7bb0da76eb14584b10e6a8fd2a99
parentc2c094e8a16016a853a193a6af856e2e28193f1d (diff)
parent32ef462f1df74a148e95272bcebd707d3550e343 (diff)
downloadgtk+-6a6ef0f437ecdd2677b7b459d921980ddf77ca31.tar.gz
Merge branch 'matthiasc/for-main' into 'main'
inspector: Fix some criticals See merge request GNOME/gtk!5104
-rw-r--r--gtk/gtkfontbutton.c227
-rw-r--r--gtk/inspector/css-node-tree.c20
2 files changed, 28 insertions, 219 deletions
diff --git a/gtk/gtkfontbutton.c b/gtk/gtkfontbutton.c
index 0edf9de4fc..ef8f64c2b5 100644
--- a/gtk/gtkfontbutton.c
+++ b/gtk/gtkfontbutton.c
@@ -31,7 +31,6 @@
#include "gtkbinlayout.h"
#include "gtkbox.h"
-#include "gtkcssprovider.h"
#include "gtkfontchooser.h"
#include "gtkfontchooserdialog.h"
#include "gtkfontchooserutils.h"
@@ -40,7 +39,6 @@
#include "gtkmarshalers.h"
#include "gtkprivate.h"
#include "gtkseparator.h"
-#include "gtkstylecontext.h"
#include "gtkwidgetprivate.h"
#include <string.h>
@@ -102,7 +100,6 @@ struct _GtkFontButton
GtkFontFilterFunc font_filter;
gpointer font_filter_data;
GDestroyNotify font_filter_data_destroy;
- GtkCssProvider *provider;
};
struct _GtkFontButtonClass
@@ -640,8 +637,6 @@ gtk_font_button_finalize (GObject *object)
g_free (font_button->preview_text);
- g_clear_object (&font_button->provider);
-
gtk_widget_unparent (font_button->button);
G_OBJECT_CLASS (gtk_font_button_parent_class)->finalize (object);
@@ -1087,225 +1082,35 @@ dialog_destroy (GtkWidget *widget,
}
static void
-add_css_variations (GString *s,
- const char *variations)
-{
- const char *p;
- const char *sep = "";
-
- if (variations == NULL || variations[0] == '\0')
- {
- g_string_append (s, "normal");
- return;
- }
-
- p = variations;
- while (p && *p)
- {
- const char *start;
- const char *end, *end2;
- double value;
- char name[5];
-
- while (g_ascii_isspace (*p)) p++;
-
- start = p;
- end = strchr (p, ',');
- if (end && (end - p < 6))
- goto skip;
-
- name[0] = p[0];
- name[1] = p[1];
- name[2] = p[2];
- name[3] = p[3];
- name[4] = '\0';
-
- p += 4;
- while (g_ascii_isspace (*p)) p++;
- if (*p == '=') p++;
-
- if (p - start < 5)
- goto skip;
-
- value = g_ascii_strtod (p, (char **) &end2);
-
- while (end2 && g_ascii_isspace (*end2)) end2++;
-
- if (end2 && (*end2 != ',' && *end2 != '\0'))
- goto skip;
-
- g_string_append_printf (s, "%s\"%s\" %g", sep, name, value);
- sep = ", ";
-
-skip:
- p = end ? end + 1 : NULL;
- }
-}
-
-static char *
-pango_font_description_to_css (PangoFontDescription *desc,
- const char *features,
- const char *language)
-{
- GString *s;
- PangoFontMask set;
-
- s = g_string_new ("* { ");
-
- set = pango_font_description_get_set_fields (desc);
- if (set & PANGO_FONT_MASK_FAMILY)
- {
- g_string_append (s, "font-family: \"");
- g_string_append (s, pango_font_description_get_family (desc));
- g_string_append (s, "\"; ");
- }
- if (set & PANGO_FONT_MASK_STYLE)
- {
- switch (pango_font_description_get_style (desc))
- {
- case PANGO_STYLE_NORMAL:
- g_string_append (s, "font-style: normal; ");
- break;
- case PANGO_STYLE_OBLIQUE:
- g_string_append (s, "font-style: oblique; ");
- break;
- case PANGO_STYLE_ITALIC:
- g_string_append (s, "font-style: italic; ");
- break;
- default:
- break;
- }
- }
- if (set & PANGO_FONT_MASK_VARIANT)
- {
- switch (pango_font_description_get_variant (desc))
- {
- case PANGO_VARIANT_NORMAL:
- g_string_append (s, "font-variant: normal; ");
- break;
- case PANGO_VARIANT_SMALL_CAPS:
- g_string_append (s, "font-variant: small-caps; ");
- break;
- case PANGO_VARIANT_ALL_SMALL_CAPS:
- g_string_append (s, "font-variant: all-small-caps; ");
- break;
- case PANGO_VARIANT_PETITE_CAPS:
- g_string_append (s, "font-variant: petite-caps; ");
- break;
- case PANGO_VARIANT_ALL_PETITE_CAPS:
- g_string_append (s, "font-variant: all-petite-caps; ");
- break;
- case PANGO_VARIANT_UNICASE:
- g_string_append (s, "font-variant: unicase; ");
- break;
- case PANGO_VARIANT_TITLE_CAPS:
- g_string_append (s, "font-variant: titling-caps; ");
- break;
- default:
- break;
- }
- }
- if (set & PANGO_FONT_MASK_WEIGHT)
- g_string_append_printf (s, "font-weight: %d; ", pango_font_description_get_weight (desc));
-
- if (set & PANGO_FONT_MASK_STRETCH)
- {
- switch (pango_font_description_get_stretch (desc))
- {
- case PANGO_STRETCH_ULTRA_CONDENSED:
- g_string_append (s, "font-stretch: ultra-condensed; ");
- break;
- case PANGO_STRETCH_EXTRA_CONDENSED:
- g_string_append (s, "font-stretch: extra-condensed; ");
- break;
- case PANGO_STRETCH_CONDENSED:
- g_string_append (s, "font-stretch: condensed; ");
- break;
- case PANGO_STRETCH_SEMI_CONDENSED:
- g_string_append (s, "font-stretch: semi-condensed; ");
- break;
- case PANGO_STRETCH_NORMAL:
- g_string_append (s, "font-stretch: normal; ");
- break;
- case PANGO_STRETCH_SEMI_EXPANDED:
- g_string_append (s, "font-stretch: semi-expanded; ");
- break;
- case PANGO_STRETCH_EXPANDED:
- g_string_append (s, "font-stretch: expanded; ");
- break;
- case PANGO_STRETCH_EXTRA_EXPANDED:
- g_string_append (s, "font-stretch: extra-expanded; ");
- break;
- case PANGO_STRETCH_ULTRA_EXPANDED:
- g_string_append (s, "font-stretch: ultra-expanded; ");
- break;
- default:
- break;
- }
- }
- if (set & PANGO_FONT_MASK_SIZE)
- {
- g_string_append_printf (s, "font-size: %dpt; ", pango_font_description_get_size (desc) / PANGO_SCALE);
- }
-
- if (set & PANGO_FONT_MASK_VARIATIONS)
- {
- const char *variations;
-
- g_string_append (s, "font-variation-settings: ");
- variations = pango_font_description_get_variations (desc);
- add_css_variations (s, variations);
- g_string_append (s, "; ");
- }
- if (features)
- {
- g_string_append_printf (s, "font-feature-settings: %s;", features);
- }
-
- g_string_append (s, "}");
-
- return g_string_free (s, FALSE);
-}
-
-static void
gtk_font_button_label_use_font (GtkFontButton *font_button)
{
- GtkStyleContext *context;
-
- context = gtk_widget_get_style_context (font_button->font_label);
-
if (!font_button->use_font)
- {
- if (font_button->provider)
- {
- gtk_style_context_remove_provider (context, GTK_STYLE_PROVIDER (font_button->provider));
- g_clear_object (&font_button->provider);
- }
- }
+ gtk_label_set_attributes (GTK_LABEL (font_button->font_label), NULL);
else
{
PangoFontDescription *desc;
- char *data;
-
- if (!font_button->provider)
- {
- font_button->provider = gtk_css_provider_new ();
- gtk_style_context_add_provider (context,
- GTK_STYLE_PROVIDER (font_button->provider),
- GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
- }
+ PangoAttrList *attrs;
desc = pango_font_description_copy (font_button->font_desc);
if (!font_button->use_size)
pango_font_description_unset_fields (desc, PANGO_FONT_MASK_SIZE);
- data = pango_font_description_to_css (desc,
- font_button->font_features,
- pango_language_to_string (font_button->language));
- gtk_css_provider_load_from_data (font_button->provider, data, -1);
+ attrs = pango_attr_list_new ();
+
+ /* Prevent font fallback */
+ pango_attr_list_insert (attrs, pango_attr_fallback_new (FALSE));
+
+ /* Force current font and features */
+ pango_attr_list_insert (attrs, pango_attr_font_desc_new (desc));
+ if (font_button->font_features)
+ pango_attr_list_insert (attrs, pango_attr_font_features_new (font_button->font_features));
+ if (font_button->language)
+ pango_attr_list_insert (attrs, pango_attr_language_new (font_button->language));
+
+ gtk_label_set_attributes (GTK_LABEL (font_button->font_label), attrs);
- g_free (data);
+ pango_attr_list_unref (attrs);
pango_font_description_free (desc);
}
}
diff --git a/gtk/inspector/css-node-tree.c b/gtk/inspector/css-node-tree.c
index f15eed3ca2..30651f5d65 100644
--- a/gtk/inspector/css-node-tree.c
+++ b/gtk/inspector/css-node-tree.c
@@ -188,19 +188,25 @@ G_DEFINE_TYPE_WITH_PRIVATE (GtkInspectorCssNodeTree, gtk_inspector_css_node_tree
static void
gtk_inspector_css_node_tree_set_node (GtkInspectorCssNodeTree *cnt,
GtkCssNode *node);
+static void
+gtk_inspector_css_node_tree_unset_node (GtkInspectorCssNodeTree *cnt);
static void
selection_changed (GtkSelectionModel *model,
GParamSpec *pspec,
GtkInspectorCssNodeTree *cnt)
{
- GtkTreeListRow *row;
- GtkCssNode *node;
-
- row = gtk_single_selection_get_selected_item (cnt->priv->selection_model);
- node = gtk_tree_list_row_get_item (row);
+ if (gtk_single_selection_get_selected (cnt->priv->selection_model) != GTK_INVALID_LIST_POSITION)
+ {
+ GtkTreeListRow *row;
+ GtkCssNode *node;
- gtk_inspector_css_node_tree_set_node (cnt, node);
+ row = gtk_single_selection_get_selected_item (cnt->priv->selection_model);
+ node = gtk_tree_list_row_get_item (row);
+ gtk_inspector_css_node_tree_set_node (cnt, node);
+ }
+ else
+ gtk_inspector_css_node_tree_unset_node (cnt);
}
static void
@@ -261,8 +267,6 @@ gtk_inspector_css_node_tree_finalize (GObject *object)
gtk_inspector_css_node_tree_unset_node (cnt);
- g_object_unref (cnt->priv->prop_model);
-
G_OBJECT_CLASS (gtk_inspector_css_node_tree_parent_class)->finalize (object);
}