summaryrefslogtreecommitdiff
path: root/gtk
diff options
context:
space:
mode:
authorOwen Taylor <otaylor@redhat.com>2001-09-18 20:06:48 +0000
committerOwen Taylor <otaylor@src.gnome.org>2001-09-18 20:06:48 +0000
commita15d5c36f6e100ff512ca3fc2ff034d3cbd5f572 (patch)
tree977167ee56376a78020bac27816be830a5c04e00 /gtk
parentc45ee0bf85dd61abb6a8469265274c2265772af9 (diff)
downloadgtk+-a15d5c36f6e100ff512ca3fc2ff034d3cbd5f572.tar.gz
Fix up for changes to PangoFontDescription.
Wed Sep 12 11:21:14 2001 Owen Taylor <otaylor@redhat.com> * gtk/gtkcellrenderertext.[ch] gtk/gtktexttag.[ch] gtk/gtktextview.c tests/testgtk.c: Fix up for changes to PangoFontDescription. * gtk/gtkentry.c gtk/gtkclist.c gtk/gtkcellrenderertext.c gtk/gtkspinbutton.c: Fix up for change to PangoMetrics structure. * gtk/gtkfontsel.c: Fix up for new Pango font listing API. * gtk/gtkstyle.[ch]: Add gtk_style_get_font/set_font to replace direct access to style->font. Deprecate gtk_style_ref/unref. * gtk/gtkclist.c gtk/gtkctree.c gtk/gtkstyle.c gtk/gtkwidget.c: Remove gtk_style_ref/unref with g_object_ref/unref. * gtk/gtkcalendar.c: Remove leftover macros accessing style->font. * gtk/gtkhruler.c (gtk_hruler_draw_ticks): Remove unused variable. * gtk/gtktext.c gtk/gtklabel.c: Use gtk_style_get_font() instead of style->font.
Diffstat (limited to 'gtk')
-rw-r--r--gtk/gtkcalendar.c4
-rw-r--r--gtk/gtkcellrenderertext.c403
-rw-r--r--gtk/gtkcellrenderertext.h10
-rw-r--r--gtk/gtkclist.c29
-rw-r--r--gtk/gtkctree.c12
-rw-r--r--gtk/gtkentry.c23
-rw-r--r--gtk/gtkfontsel.c261
-rw-r--r--gtk/gtkfontsel.h9
-rw-r--r--gtk/gtkhruler.c2
-rw-r--r--gtk/gtklabel.c2
-rw-r--r--gtk/gtkspinbutton.c21
-rw-r--r--gtk/gtkstyle.c150
-rw-r--r--gtk/gtkstyle.h17
-rw-r--r--gtk/gtktext.c15
-rw-r--r--gtk/gtktextlayout.c11
-rw-r--r--gtk/gtktexttag.c453
-rw-r--r--gtk/gtktexttag.h8
-rw-r--r--gtk/gtktextview.c12
-rw-r--r--gtk/gtkwidget.c14
19 files changed, 752 insertions, 704 deletions
diff --git a/gtk/gtkcalendar.c b/gtk/gtkcalendar.c
index d72d32704a..bd4cb35f57 100644
--- a/gtk/gtkcalendar.c
+++ b/gtk/gtkcalendar.c
@@ -186,10 +186,6 @@ dates_difference(N_int year1, N_int mm1, N_int dd1,
#define BACKGROUND_COLOR(widget) (& (widget)->style->base[GTK_WIDGET_STATE (widget)])
#define HIGHLIGHT_BACK_COLOR(widget) (& (widget)->style->mid[GTK_WIDGET_STATE (widget)])
-#define HEADER_FONT(widget) ((widget)->style->font)
-#define LABEL_FONT(widget) ((widget)->style->font)
-#define DAY_FONT(widget) ((widget)->style->font)
-
enum {
ARROW_YEAR_LEFT,
ARROW_YEAR_RIGHT,
diff --git a/gtk/gtkcellrenderertext.c b/gtk/gtkcellrenderertext.c
index fbb39e59f1..5a99a5a76a 100644
--- a/gtk/gtkcellrenderertext.c
+++ b/gtk/gtkcellrenderertext.c
@@ -130,6 +130,7 @@ gtk_cell_renderer_text_init (GtkCellRendererText *celltext)
GTK_CELL_RENDERER (celltext)->ypad = 2;
celltext->fixed_height_rows = -1;
+ celltext->font = pango_font_description_new ();
}
static void
@@ -396,8 +397,7 @@ gtk_cell_renderer_text_finalize (GObject *object)
{
GtkCellRendererText *celltext = GTK_CELL_RENDERER_TEXT (object);
- if (celltext->font.family_name)
- g_free (celltext->font.family_name);
+ pango_font_description_free (celltext->font);
if (celltext->text)
g_free (celltext->text);
@@ -408,6 +408,28 @@ gtk_cell_renderer_text_finalize (GObject *object)
(* G_OBJECT_CLASS (parent_class)->finalize) (object);
}
+static PangoFontMask
+get_property_font_set_mask (guint prop_id)
+{
+ switch (prop_id)
+ {
+ case PROP_FAMILY_SET:
+ return PANGO_FONT_MASK_FAMILY;
+ case PROP_STYLE_SET:
+ return PANGO_FONT_MASK_STYLE;
+ case PROP_VARIANT_SET:
+ return PANGO_FONT_MASK_VARIANT;
+ case PROP_WEIGHT_SET:
+ return PANGO_FONT_MASK_WEIGHT;
+ case PROP_STRETCH_SET:
+ return PANGO_FONT_MASK_STRETCH;
+ case PROP_SIZE_SET:
+ return PANGO_FONT_MASK_SIZE;
+ }
+
+ return 0;
+}
+
static void
gtk_cell_renderer_text_get_property (GObject *object,
guint param_id,
@@ -455,42 +477,42 @@ gtk_cell_renderer_text_get_property (GObject *object,
/* FIXME GValue imposes a totally gratuitous string copy
* here, we could just hand off string ownership
*/
- gchar *str = pango_font_description_to_string (&celltext->font);
+ gchar *str = pango_font_description_to_string (celltext->font);
g_value_set_string (value, str);
g_free (str);
}
break;
case PROP_FONT_DESC:
- g_value_set_boxed (value, &celltext->font);
+ g_value_set_boxed (value, celltext->font);
break;
case PROP_FAMILY:
- g_value_set_string (value, celltext->font.family_name);
+ g_value_set_string (value, pango_font_description_get_family (celltext->font));
break;
case PROP_STYLE:
- g_value_set_enum (value, celltext->font.style);
+ g_value_set_enum (value, pango_font_description_get_style (celltext->font));
break;
case PROP_VARIANT:
- g_value_set_enum (value, celltext->font.variant);
+ g_value_set_enum (value, pango_font_description_get_variant (celltext->font));
break;
case PROP_WEIGHT:
- g_value_set_int (value, celltext->font.weight);
+ g_value_set_int (value, pango_font_description_get_weight (celltext->font));
break;
case PROP_STRETCH:
- g_value_set_enum (value, celltext->font.stretch);
+ g_value_set_enum (value, pango_font_description_get_stretch (celltext->font));
break;
case PROP_SIZE:
- g_value_set_int (value, celltext->font.size);
+ g_value_set_int (value, pango_font_description_get_size (celltext->font));
break;
case PROP_SIZE_POINTS:
- g_value_set_double (value, ((double)celltext->font.size) / (double)PANGO_SCALE);
+ g_value_set_double (value, ((double)pango_font_description_get_size (celltext->font)) / (double)PANGO_SCALE);
break;
case PROP_SCALE:
@@ -522,28 +544,15 @@ gtk_cell_renderer_text_get_property (GObject *object,
break;
case PROP_FAMILY_SET:
- g_value_set_boolean (value, celltext->family_set);
- break;
-
case PROP_STYLE_SET:
- g_value_set_boolean (value, celltext->style_set);
- break;
-
case PROP_VARIANT_SET:
- g_value_set_boolean (value, celltext->variant_set);
- break;
-
case PROP_WEIGHT_SET:
- g_value_set_boolean (value, celltext->weight_set);
- break;
-
case PROP_STRETCH_SET:
- g_value_set_boolean (value, celltext->stretch_set);
- break;
-
case PROP_SIZE_SET:
- g_value_set_boolean (value, celltext->size_set);
- break;
+ {
+ PangoFontMask mask = get_property_font_set_mask (param_id);
+ g_value_set_boolean (value, (pango_font_description_get_set_fields (celltext->font) & mask) != 0);
+ }
case PROP_SCALE_SET:
g_value_set_boolean (value, celltext->scale_set);
@@ -629,67 +638,69 @@ set_fg_color (GtkCellRendererText *celltext,
}
static void
+notify_set_changed (GObject *object,
+ PangoFontMask changed_mask)
+{
+ if (changed_mask & PANGO_FONT_MASK_FAMILY)
+ g_object_notify (object, "family_set");
+ if (changed_mask & PANGO_FONT_MASK_STYLE)
+ g_object_notify (object, "style_set");
+ if (changed_mask & PANGO_FONT_MASK_VARIANT)
+ g_object_notify (object, "variant_set");
+ if (changed_mask & PANGO_FONT_MASK_WEIGHT)
+ g_object_notify (object, "weight_set");
+ if (changed_mask & PANGO_FONT_MASK_STRETCH)
+ g_object_notify (object, "stretch_set");
+ if (changed_mask & PANGO_FONT_MASK_SIZE)
+ g_object_notify (object, "size_set");
+}
+
+static void
set_font_description (GtkCellRendererText *celltext,
PangoFontDescription *font_desc)
{
- if (font_desc != NULL)
- {
- /* pango_font_description_from_string() will sometimes return
- * a NULL family or -1 size, so handle those cases.
- */
-
- if (font_desc->family_name)
- g_object_set (G_OBJECT (celltext),
- "family", font_desc->family_name,
- NULL);
-
- if (font_desc->size >= 0)
- g_object_set (G_OBJECT (celltext),
- "size", font_desc->size,
- NULL);
-
- g_object_set (G_OBJECT (celltext),
- "style", font_desc->style,
- "variant", font_desc->variant,
- "weight", font_desc->weight,
- "stretch", font_desc->stretch,
- NULL);
- }
+ GObject *object = G_OBJECT (celltext);
+ PangoFontDescription *new_font_desc;
+ PangoFontMask old_mask, new_mask, changed_mask, set_changed_mask;
+
+ if (font_desc)
+ new_font_desc = pango_font_description_copy (font_desc);
else
+ new_font_desc = pango_font_description_new ();
+
+ old_mask = pango_font_description_get_set_fields (celltext->font);
+ new_mask = pango_font_description_get_set_fields (new_font_desc);
+
+ changed_mask = old_mask | new_mask;
+ set_changed_mask = old_mask ^ new_mask;
+
+ pango_font_description_free (celltext->font);
+ celltext->font = new_font_desc;
+
+ g_object_freeze_notify (object);
+
+ g_object_notify (object, "font_desc");
+ g_object_notify (object, "font");
+
+ if (changed_mask & PANGO_FONT_MASK_FAMILY)
+ g_object_notify (object, "family");
+ if (changed_mask & PANGO_FONT_MASK_STYLE)
+ g_object_notify (object, "style");
+ if (changed_mask & PANGO_FONT_MASK_VARIANT)
+ g_object_notify (object, "variant");
+ if (changed_mask & PANGO_FONT_MASK_WEIGHT)
+ g_object_notify (object, "weight");
+ if (changed_mask & PANGO_FONT_MASK_STRETCH)
+ g_object_notify (object, "stretch");
+ if (changed_mask & PANGO_FONT_MASK_SIZE)
{
- g_object_freeze_notify (G_OBJECT (celltext));
- if (celltext->family_set)
- {
- celltext->family_set = FALSE;
- g_object_notify (G_OBJECT (celltext), "family_set");
- }
- if (celltext->style_set)
- {
- celltext->style_set = FALSE;
- g_object_notify (G_OBJECT (celltext), "style_set");
- }
- if (celltext->variant_set)
- {
- celltext->variant_set = FALSE;
- g_object_notify (G_OBJECT (celltext), "variant_set");
- }
- if (celltext->weight_set)
- {
- celltext->weight_set = FALSE;
- g_object_notify (G_OBJECT (celltext), "weight_set");
- }
- if (celltext->stretch_set)
- {
- celltext->stretch_set = FALSE;
- g_object_notify (G_OBJECT (celltext), "stretch_set");
- }
- if (celltext->size_set)
- {
- celltext->size_set = FALSE;
- g_object_notify (G_OBJECT (celltext), "size_set");
- }
- g_object_thaw_notify (G_OBJECT (celltext));
+ g_object_notify (object, "size");
+ g_object_notify (object, "size_points");
}
+
+ notify_set_changed (object, set_changed_mask);
+
+ g_object_thaw_notify (object);
}
static void
@@ -706,7 +717,7 @@ gtk_cell_renderer_text_set_property (GObject *object,
if (celltext->text)
g_free (celltext->text);
celltext->text = g_strdup (g_value_get_string (value));
- g_object_notify(G_OBJECT(object), "text");
+ g_object_notify (object, "text");
break;
case PROP_ATTRIBUTES:
@@ -761,7 +772,7 @@ gtk_cell_renderer_text_set_property (GObject *object,
else
g_warning ("Don't know color `%s'", g_value_get_string (value));
- g_object_notify (G_OBJECT (celltext), "background_gdk");
+ g_object_notify (object, "background_gdk");
}
break;
@@ -776,7 +787,7 @@ gtk_cell_renderer_text_set_property (GObject *object,
else
g_warning ("Don't know color `%s'", g_value_get_string (value));
- g_object_notify (G_OBJECT (celltext), "foreground_gdk");
+ g_object_notify (object, "foreground_gdk");
}
break;
@@ -800,16 +811,8 @@ gtk_cell_renderer_text_set_property (GObject *object,
if (name)
font_desc = pango_font_description_from_string (name);
- /* This function notifies the relevant GObjects itself.
- * I'm not sure how useful the notify() on 'font'
- * actually is here, but it's here for consistency.
- */
set_font_description (celltext, font_desc);
- g_object_notify(G_OBJECT(object), "font_desc");
- g_object_notify(G_OBJECT(object), "font");
- if (font_desc)
- pango_font_description_free (font_desc);
if (celltext->fixed_height_rows != -1)
celltext->calc_fixed_height = TRUE;
}
@@ -817,119 +820,94 @@ gtk_cell_renderer_text_set_property (GObject *object,
case PROP_FONT_DESC:
set_font_description (celltext, g_value_get_boxed (value));
+
if (celltext->fixed_height_rows != -1)
celltext->calc_fixed_height = TRUE;
break;
case PROP_FAMILY:
- if (celltext->font.family_name)
- g_free (celltext->font.family_name);
- celltext->font.family_name = g_strdup (g_value_get_string (value));
-
- celltext->family_set = TRUE;
- g_object_notify (G_OBJECT (celltext), "family_set");
- g_object_notify (G_OBJECT (celltext), "font_desc");
- g_object_notify (G_OBJECT (celltext), "font");
- if (celltext->fixed_height_rows != -1)
- celltext->calc_fixed_height = TRUE;
- break;
-
case PROP_STYLE:
- celltext->font.style = g_value_get_enum (value);
-
- celltext->style_set = TRUE;
- g_object_notify (G_OBJECT (celltext), "style_set");
- g_object_notify (G_OBJECT (celltext), "font_desc");
- g_object_notify (G_OBJECT (celltext), "font");
- if (celltext->fixed_height_rows != -1)
- celltext->calc_fixed_height = TRUE;
- break;
-
case PROP_VARIANT:
- celltext->font.variant = g_value_get_enum (value);
-
- celltext->variant_set = TRUE;
- g_object_notify (G_OBJECT (celltext), "variant_set");
- g_object_notify (G_OBJECT (celltext), "font_desc");
- g_object_notify (G_OBJECT (celltext), "font");
- if (celltext->fixed_height_rows != -1)
- celltext->calc_fixed_height = TRUE;
- break;
-
case PROP_WEIGHT:
- celltext->font.weight = g_value_get_int (value);
-
- celltext->weight_set = TRUE;
- g_object_notify (G_OBJECT (celltext), "weight_set");
- g_object_notify (G_OBJECT (celltext), "font_desc");
- g_object_notify (G_OBJECT (celltext), "font");
- if (celltext->fixed_height_rows != -1)
- celltext->calc_fixed_height = TRUE;
- break;
-
case PROP_STRETCH:
- celltext->font.stretch = g_value_get_enum (value);
-
- celltext->stretch_set = TRUE;
- g_object_notify (G_OBJECT (celltext), "stretch_set");
- g_object_notify (G_OBJECT (celltext), "font_desc");
- g_object_notify (G_OBJECT (celltext), "font");
- if (celltext->fixed_height_rows != -1)
- celltext->calc_fixed_height = TRUE;
- break;
-
case PROP_SIZE:
- celltext->font.size = g_value_get_int (value);
-
- celltext->size_set = TRUE;
- g_object_notify (G_OBJECT (celltext), "size_set");
- g_object_notify (G_OBJECT (celltext), "font_desc");
- g_object_notify (G_OBJECT (celltext), "font");
- if (celltext->fixed_height_rows != -1)
- celltext->calc_fixed_height = TRUE;
- break;
-
+ case PROP_SIZE_POINTS:
+ {
+ PangoFontMask old_set_mask = pango_font_description_get_set_fields (celltext->font);
+
+ switch (param_id)
+ {
+ case PROP_FAMILY:
+ pango_font_description_set_family (celltext->font,
+ g_value_get_string (value));
+ break;
+ case PROP_STYLE:
+ pango_font_description_set_style (celltext->font,
+ g_value_get_enum (value));
+ break;
+ case PROP_VARIANT:
+ pango_font_description_set_variant (celltext->font,
+ g_value_get_enum (value));
+ break;
+ case PROP_WEIGHT:
+ pango_font_description_set_weight (celltext->font,
+ g_value_get_enum (value));
+ break;
+ case PROP_STRETCH:
+ pango_font_description_set_stretch (celltext->font,
+ g_value_get_enum (value));
+ break;
+ case PROP_SIZE:
+ pango_font_description_set_size (celltext->font,
+ g_value_get_int (value));
+ g_object_notify (object, "size_points");
+ break;
+ case PROP_SIZE_POINTS:
+ pango_font_description_set_size (celltext->font,
+ g_value_get_double (value) * PANGO_SCALE);
+ g_object_notify (object, "size");
+ break;
+ }
+
+ if (celltext->fixed_height_rows != -1)
+ celltext->calc_fixed_height = TRUE;
+
+ notify_set_changed (object, old_set_mask & pango_font_description_get_set_fields (celltext->font));
+ g_object_notify (object, "font_desc");
+ g_object_notify (object, "font");
+ }
+
case PROP_SCALE:
celltext->font_scale = g_value_get_double (value);
celltext->scale_set = TRUE;
if (celltext->fixed_height_rows != -1)
celltext->calc_fixed_height = TRUE;
+ g_object_notify (object, "scale_set");
break;
- case PROP_SIZE_POINTS:
- celltext->font.size = g_value_get_double (value) * PANGO_SCALE;
-
- celltext->size_set = TRUE;
- g_object_notify (G_OBJECT (celltext), "size_set");
- g_object_notify (G_OBJECT (celltext), "font_desc");
- g_object_notify (G_OBJECT (celltext), "font");
- if (celltext->fixed_height_rows != -1)
- celltext->calc_fixed_height = TRUE;
- break;
-
case PROP_EDITABLE:
celltext->editable = g_value_get_boolean (value);
celltext->editable_set = TRUE;
- g_object_notify (G_OBJECT (celltext), "editable_set");
+ g_object_notify (object, "editable_set");
break;
case PROP_STRIKETHROUGH:
celltext->strikethrough = g_value_get_boolean (value);
celltext->strikethrough_set = TRUE;
- g_object_notify (G_OBJECT (celltext), "strikethrough_set");
+ g_object_notify (object, "strikethrough_set");
break;
case PROP_UNDERLINE:
celltext->underline_style = g_value_get_enum (value);
celltext->underline_set = TRUE;
- g_object_notify (G_OBJECT (celltext), "underline_set");
+ g_object_notify (object, "underline_set");
break;
case PROP_RISE:
celltext->rise = g_value_get_int (value);
celltext->rise_set = TRUE;
- g_object_notify (G_OBJECT (celltext), "rise_set");
+ g_object_notify (object, "rise_set");
if (celltext->fixed_height_rows != -1)
celltext->calc_fixed_height = TRUE;
break;
@@ -943,27 +921,14 @@ gtk_cell_renderer_text_set_property (GObject *object,
break;
case PROP_FAMILY_SET:
- celltext->family_set = g_value_get_boolean (value);
- break;
-
case PROP_STYLE_SET:
- celltext->style_set = g_value_get_boolean (value);
- break;
-
case PROP_VARIANT_SET:
- celltext->variant_set = g_value_get_boolean (value);
- break;
-
case PROP_WEIGHT_SET:
- celltext->weight_set = g_value_get_boolean (value);
- break;
-
case PROP_STRETCH_SET:
- celltext->stretch_set = g_value_get_boolean (value);
- break;
-
case PROP_SIZE_SET:
- celltext->size_set = g_value_get_boolean (value);
+ if (!g_value_get_boolean (value))
+ pango_font_description_unset_fields (celltext->font,
+ get_property_font_set_mask (param_id));
break;
case PROP_SCALE_SET:
@@ -1061,25 +1026,7 @@ get_layout (GtkCellRendererText *celltext,
pango_attr_strikethrough_new (celltext->strikethrough));
}
- if (celltext->family_set &&
- celltext->font.family_name)
- add_attr (attr_list, pango_attr_family_new (celltext->font.family_name));
-
- if (celltext->style_set)
- add_attr (attr_list, pango_attr_style_new (celltext->font.style));
-
- if (celltext->variant_set)
- add_attr (attr_list, pango_attr_variant_new (celltext->font.variant));
-
- if (celltext->weight_set)
- add_attr (attr_list, pango_attr_weight_new (celltext->font.weight));
-
- if (celltext->stretch_set)
- add_attr (attr_list, pango_attr_stretch_new (celltext->font.stretch));
-
- if (celltext->size_set &&
- celltext->font.size >= 0)
- add_attr (attr_list, pango_attr_size_new (celltext->font.size));
+ add_attr (attr_list, pango_attr_font_desc_new (celltext->font));
if (celltext->scale_set &&
celltext->font_scale != 1.0)
@@ -1137,38 +1084,30 @@ gtk_cell_renderer_text_get_size (GtkCellRenderer *cell,
if (celltext->calc_fixed_height)
{
PangoContext *context;
- PangoFontMetrics metrics;
- PangoFontDescription font_desc;
+ PangoFontMetrics *metrics;
+ PangoFontDescription *font_desc;
+ gint row_height;
- font_desc = (* widget->style->font_desc);
+ font_desc = pango_font_description_copy (widget->style->font_desc);
+ pango_font_description_merge (font_desc, celltext->font, TRUE);
- if (celltext->family_set &&
- celltext->font.family_name)
- font_desc.family_name = celltext->font.family_name;
- if (celltext->style_set)
- font_desc.style = celltext->font.style;
-
- if (celltext->variant_set)
- font_desc.variant = celltext->font.variant;
-
- if (celltext->weight_set)
- font_desc.weight = celltext->font.weight;
-
- if (celltext->stretch_set)
- font_desc.stretch = celltext->font.stretch;
-
- if (celltext->size_set &&
- celltext->font.size >= 0)
- font_desc.size = celltext->font.size;
+ if (celltext->scale_set)
+ pango_font_description_set_size (font_desc,
+ celltext->font_scale * pango_font_description_get_size (font_desc));
context = gtk_widget_get_pango_context (widget);
- pango_context_get_metrics (context,
- &font_desc,
- pango_context_get_language (context),
- &metrics);
+
+ metrics = pango_context_get_metrics (context,
+ font_desc,
+ pango_context_get_language (context));
+ row_height = (pango_font_metrics_get_ascent (metrics) +
+ pango_font_metrics_get_descent (metrics));
+ pango_font_metrics_unref (metrics);
+
gtk_cell_renderer_set_fixed_size (cell,
cell->width, 2*cell->ypad +
- celltext->fixed_height_rows*(metrics.ascent + metrics.descent)/PANGO_SCALE);
+ celltext->fixed_height_rows * PANGO_PIXELS (row_height));
+
if (height)
{
*height = cell->height;
diff --git a/gtk/gtkcellrenderertext.h b/gtk/gtkcellrenderertext.h
index 523d39a036..41a8fcb7e4 100644
--- a/gtk/gtkcellrenderertext.h
+++ b/gtk/gtkcellrenderertext.h
@@ -44,7 +44,7 @@ struct _GtkCellRendererText
/*< private >*/
gchar *text;
- PangoFontDescription font;
+ PangoFontDescription *font;
gdouble font_scale;
PangoColor foreground;
PangoColor background;
@@ -61,14 +61,6 @@ struct _GtkCellRendererText
/* editable feature doesn't work */
guint editable : 1;
- /* font elements set */
- guint family_set : 1;
- guint style_set : 1;
- guint variant_set : 1;
- guint weight_set : 1;
- guint stretch_set : 1;
- guint size_set : 1;
-
guint scale_set : 1;
guint foreground_set : 1;
diff --git a/gtk/gtkclist.c b/gtk/gtkclist.c
index 874f9c72b4..2ea8aa7e25 100644
--- a/gtk/gtkclist.c
+++ b/gtk/gtkclist.c
@@ -3052,15 +3052,20 @@ gtk_clist_set_row_height (GtkCList *clist,
if (widget->style->font_desc)
{
PangoContext *context = gtk_widget_get_pango_context (widget);
- PangoFontMetrics metrics;
+ PangoFontMetrics *metrics;
- pango_context_get_metrics (context,
- widget->style->font_desc,
- pango_context_get_language (context),
- &metrics);
+ metrics = pango_context_get_metrics (context,
+ widget->style->font_desc,
+ pango_context_get_language (context));
if (!GTK_CLIST_ROW_HEIGHT_SET(clist))
- clist->row_height = PANGO_PIXELS (metrics.ascent + metrics.descent);
+ {
+ clist->row_height = (pango_font_metrics_get_ascent (metrics) +
+ pango_font_metrics_get_descent (metrics));
+ clist->row_height = PANGO_PIXELS (clist->row_height);
+ }
+
+ pango_font_metrics_unref (metrics);
}
CLIST_REFRESH (clist);
@@ -3294,14 +3299,14 @@ gtk_clist_set_cell_style (GtkCList *clist,
{
if (GTK_WIDGET_REALIZED (clist))
gtk_style_detach (clist_row->cell[column].style);
- gtk_style_unref (clist_row->cell[column].style);
+ g_object_unref (clist_row->cell[column].style);
}
clist_row->cell[column].style = style;
if (clist_row->cell[column].style)
{
- gtk_style_ref (clist_row->cell[column].style);
+ g_object_ref (clist_row->cell[column].style);
if (GTK_WIDGET_REALIZED (clist))
clist_row->cell[column].style =
@@ -3373,14 +3378,14 @@ gtk_clist_set_row_style (GtkCList *clist,
{
if (GTK_WIDGET_REALIZED (clist))
gtk_style_detach (clist_row->style);
- gtk_style_unref (clist_row->style);
+ g_object_unref (clist_row->style);
}
clist_row->style = style;
if (clist_row->style)
{
- gtk_style_ref (clist_row->style);
+ g_object_ref (clist_row->style);
if (GTK_WIDGET_REALIZED (clist))
clist_row->style = gtk_style_attach (clist_row->style,
@@ -6323,7 +6328,7 @@ row_delete (GtkCList *clist,
{
if (GTK_WIDGET_REALIZED (clist))
gtk_style_detach (clist_row->cell[i].style);
- gtk_style_unref (clist_row->cell[i].style);
+ g_object_unref (clist_row->cell[i].style);
}
}
@@ -6331,7 +6336,7 @@ row_delete (GtkCList *clist,
{
if (GTK_WIDGET_REALIZED (clist))
gtk_style_detach (clist_row->style);
- gtk_style_unref (clist_row->style);
+ g_object_unref (clist_row->style);
}
if (clist_row->destroy)
diff --git a/gtk/gtkctree.c b/gtk/gtkctree.c
index 5e53442acf..fc637bbf97 100644
--- a/gtk/gtkctree.c
+++ b/gtk/gtkctree.c
@@ -3267,7 +3267,7 @@ row_delete (GtkCTree *ctree,
{
if (GTK_WIDGET_REALIZED (ctree))
gtk_style_detach (ctree_row->row.cell[i].style);
- gtk_style_unref (ctree_row->row.cell[i].style);
+ g_object_unref (ctree_row->row.cell[i].style);
}
}
@@ -3275,7 +3275,7 @@ row_delete (GtkCTree *ctree,
{
if (GTK_WIDGET_REALIZED (ctree))
gtk_style_detach (ctree_row->row.style);
- gtk_style_unref (ctree_row->row.style);
+ g_object_unref (ctree_row->row.style);
}
if (ctree_row->pixmap_closed)
@@ -5001,14 +5001,14 @@ gtk_ctree_node_set_cell_style (GtkCTree *ctree,
{
if (GTK_WIDGET_REALIZED (ctree))
gtk_style_detach (GTK_CTREE_ROW (node)->row.cell[column].style);
- gtk_style_unref (GTK_CTREE_ROW (node)->row.cell[column].style);
+ g_object_unref (GTK_CTREE_ROW (node)->row.cell[column].style);
}
GTK_CTREE_ROW (node)->row.cell[column].style = style;
if (GTK_CTREE_ROW (node)->row.cell[column].style)
{
- gtk_style_ref (GTK_CTREE_ROW (node)->row.cell[column].style);
+ g_object_ref (GTK_CTREE_ROW (node)->row.cell[column].style);
if (GTK_WIDGET_REALIZED (ctree))
GTK_CTREE_ROW (node)->row.cell[column].style =
@@ -5073,14 +5073,14 @@ gtk_ctree_node_set_row_style (GtkCTree *ctree,
{
if (GTK_WIDGET_REALIZED (ctree))
gtk_style_detach (GTK_CTREE_ROW (node)->row.style);
- gtk_style_unref (GTK_CTREE_ROW (node)->row.style);
+ g_object_unref (GTK_CTREE_ROW (node)->row.style);
}
GTK_CTREE_ROW (node)->row.style = style;
if (GTK_CTREE_ROW (node)->row.style)
{
- gtk_style_ref (GTK_CTREE_ROW (node)->row.style);
+ g_object_ref (GTK_CTREE_ROW (node)->row.style);
if (GTK_WIDGET_REALIZED (ctree))
GTK_CTREE_ROW (node)->row.style =
diff --git a/gtk/gtkentry.c b/gtk/gtkentry.c
index 272247b0b8..bd8e7311e8 100644
--- a/gtk/gtkentry.c
+++ b/gtk/gtkentry.c
@@ -1043,7 +1043,7 @@ gtk_entry_size_request (GtkWidget *widget,
GtkRequisition *requisition)
{
GtkEntry *entry;
- PangoFontMetrics metrics;
+ PangoFontMetrics *metrics;
gint xborder, yborder;
PangoContext *context;
@@ -1053,13 +1053,12 @@ gtk_entry_size_request (GtkWidget *widget,
entry = GTK_ENTRY (widget);
context = gtk_widget_get_pango_context (widget);
- pango_context_get_metrics (context,
- widget->style->font_desc,
- pango_context_get_language (context),
- &metrics);
+ metrics = pango_context_get_metrics (context,
+ widget->style->font_desc,
+ pango_context_get_language (context));
- entry->ascent = metrics.ascent;
- entry->descent = metrics.descent;
+ entry->ascent = pango_font_metrics_get_ascent (metrics);
+ entry->descent = pango_font_metrics_get_descent (metrics);
xborder = INNER_BORDER;
yborder = INNER_BORDER;
@@ -1080,13 +1079,13 @@ gtk_entry_size_request (GtkWidget *widget,
requisition->width = MIN_ENTRY_WIDTH + xborder * 2;
else
{
- requisition->width =
- PANGO_PIXELS (metrics.approximate_char_width) * entry->width_chars +
- xborder * 2;
+ gint char_width = pango_font_metrics_get_approximate_char_width (metrics);
+ requisition->width = PANGO_PIXELS (char_width) * entry->width_chars + xborder * 2;
}
- requisition->height = ((metrics.ascent + metrics.descent) / PANGO_SCALE +
- yborder * 2);
+ requisition->height = PANGO_PIXELS (entry->ascent + entry->descent) + yborder * 2;
+
+ pango_font_metrics_unref (metrics);
}
static void
diff --git a/gtk/gtkfontsel.c b/gtk/gtkfontsel.c
index 3a64503181..d7196fea47 100644
--- a/gtk/gtkfontsel.c
+++ b/gtk/gtkfontsel.c
@@ -262,7 +262,7 @@ gtk_font_selection_init (GtkFontSelection *fontsel)
GtkWidget *text_box;
GtkWidget *table, *label;
- fontsel->font_desc = pango_font_description_from_string ("sans 12");
+ fontsel->size = 12 * PANGO_SCALE;
/* Create the table of font, style & size. */
table = gtk_table_new (3, 3, FALSE);
@@ -431,7 +431,8 @@ gtk_font_selection_finalize (GObject *object)
fontsel = GTK_FONT_SELECTION (object);
- pango_font_description_free (fontsel->font_desc);
+ g_free (fontsel->families);
+ g_free (fontsel->faces);
if (fontsel->font)
gdk_font_unref (fontsel->font);
@@ -512,12 +513,12 @@ gtk_font_selection_select_font (GtkWidget *w,
{
index = GPOINTER_TO_INT (GTK_CLIST (fontsel->font_clist)->selection->data);
- if (gtk_clist_get_text (GTK_CLIST (fontsel->font_clist), index, 0, &family_name) &&
- strcasecmp (fontsel->font_desc->family_name, family_name) != 0)
+ if (fontsel->family != fontsel->families[index])
{
- g_free (fontsel->font_desc->family_name);
- fontsel->font_desc->family_name = g_strdup (family_name);
-
+ fontsel->family = fontsel->families[index];
+
+ family_name = pango_font_family_get_name (fontsel->family);
+
gtk_entry_set_text (GTK_ENTRY (fontsel->font_entry), family_name);
gtk_font_selection_show_available_styles (fontsel);
@@ -527,66 +528,92 @@ gtk_font_selection_select_font (GtkWidget *w,
}
static int
-cmp_strings (const void *a, const void *b)
+cmp_families (const void *a, const void *b)
{
- return strcasecmp (*(const char **)a, *(const char **)b);
+ const char *a_name = pango_font_family_get_name (*(PangoFontFamily **)a);
+ const char *b_name = pango_font_family_get_name (*(PangoFontFamily **)b);
+
+ return strcmp (a_name, b_name);
}
static void
gtk_font_selection_show_available_fonts (GtkFontSelection *fontsel)
{
- gchar **families;
- int n_families, i;
+ gint n_families, i;
+ gint match_row = -1;
pango_context_list_families (gtk_widget_get_pango_context (GTK_WIDGET (fontsel)),
- &families, &n_families);
- qsort (families, n_families, sizeof (char *), cmp_strings);
+ &fontsel->families, &n_families);
+ qsort (fontsel->families, n_families, sizeof (PangoFontFamily *), cmp_families);
gtk_clist_freeze (GTK_CLIST (fontsel->font_clist));
gtk_clist_clear (GTK_CLIST (fontsel->font_clist));
for (i=0; i<n_families; i++)
{
- gtk_clist_append (GTK_CLIST (fontsel->font_clist), &families[i]);
+ const gchar *name = pango_font_family_get_name (fontsel->families[i]);
+
+ gtk_clist_append (GTK_CLIST (fontsel->font_clist), (char **)&name);
- if (!strcasecmp (families[i], fontsel->font_desc->family_name))
- {
- gtk_clist_select_row (GTK_CLIST (fontsel->font_clist), i, 0);
- gtk_entry_set_text (GTK_ENTRY (fontsel->font_entry), families[i]);
- }
+ if (!strcasecmp (name, "sans"))
+ match_row = i;
}
+
+ if (match_row < 0)
+ match_row = 0;
+
+ gtk_clist_select_row (GTK_CLIST (fontsel->font_clist), match_row, 0);
+ gtk_entry_set_text (GTK_ENTRY (fontsel->font_entry),
+ pango_font_family_get_name (fontsel->families[match_row]));
+ fontsel->family = fontsel->families[match_row];
gtk_clist_thaw (GTK_CLIST (fontsel->font_clist));
-
- pango_font_map_free_families (families, n_families);
}
static int
compare_font_descriptions (const PangoFontDescription *a, const PangoFontDescription *b)
{
- int val = strcasecmp (a->family_name, b->family_name);
+ int val = strcmp (pango_font_description_get_family (a), pango_font_description_get_family (b));
if (val != 0)
return val;
- if (a->weight != b->weight)
- return a->weight - b->weight;
+ if (pango_font_description_get_weight (a) != pango_font_description_get_weight (b))
+ return pango_font_description_get_weight (a) - pango_font_description_get_weight (b);
- if (a->style != b->style)
- return a->style - b->style;
+ if (pango_font_description_get_style (a) != pango_font_description_get_style (b))
+ return pango_font_description_get_style (a) - pango_font_description_get_style (b);
- if (a->stretch != b->stretch)
- return a->stretch - b->stretch;
+ if (pango_font_description_get_stretch (a) != pango_font_description_get_stretch (b))
+ return pango_font_description_get_stretch (a) - pango_font_description_get_stretch (b);
- if (a->variant != b->variant)
- return a->variant - b->variant;
+ if (pango_font_description_get_variant (a) != pango_font_description_get_variant (b))
+ return pango_font_description_get_variant (a) - pango_font_description_get_variant (b);
return 0;
}
static int
-font_description_sort_func (const void *a, const void *b)
+faces_sort_func (const void *a, const void *b)
{
- return compare_font_descriptions (*(PangoFontDescription **)a, *(PangoFontDescription **)b);
+ PangoFontDescription *desc_a = pango_font_face_describe (*(PangoFontFace **)a);
+ PangoFontDescription *desc_b = pango_font_face_describe (*(PangoFontFace **)b);
+
+ int ord = compare_font_descriptions (desc_a, desc_b);
+
+ pango_font_description_free (desc_a);
+ pango_font_description_free (desc_b);
+
+ return ord;
+}
+
+static gboolean
+font_description_style_equal (const PangoFontDescription *a,
+ const PangoFontDescription *b)
+{
+ return (pango_font_description_get_weight (a) == pango_font_description_get_weight (b) &&
+ pango_font_description_get_style (a) == pango_font_description_get_style (b) &&
+ pango_font_description_get_stretch (a) == pango_font_description_get_stretch (b) &&
+ pango_font_description_get_variant (a) == pango_font_description_get_variant (b));
}
/* This fills the font style clist with all the possible style combinations
@@ -594,48 +621,59 @@ font_description_sort_func (const void *a, const void *b)
static void
gtk_font_selection_show_available_styles (GtkFontSelection *fontsel)
{
- PangoFontDescription **descs;
- int n_descs, i;
gint match_row = -1;
- gchar *str;
+ gint n_faces, i;
+ const gchar *str;
+ PangoFontDescription *old_desc;
+
+ if (fontsel->face)
+ old_desc = pango_font_face_describe (fontsel->face);
+ else
+ old_desc= NULL;
+
+ if (fontsel->faces)
+ g_free (fontsel->faces);
- pango_context_list_fonts (gtk_widget_get_pango_context (GTK_WIDGET (fontsel)),
- fontsel->font_desc->family_name, &descs, &n_descs);
- qsort (descs, n_descs, sizeof (PangoFontDescription *), font_description_sort_func);
+ pango_font_family_list_faces (fontsel->family, &fontsel->faces, &n_faces);
+ qsort (fontsel->faces, n_faces, sizeof (PangoFontFace *), faces_sort_func);
gtk_clist_freeze (GTK_CLIST (fontsel->font_style_clist));
gtk_clist_clear (GTK_CLIST (fontsel->font_style_clist));
- for (i=0; i<n_descs; i++)
+ for (i=0; i < n_faces; i++)
{
- PangoFontDescription tmp_desc;
-
- tmp_desc = *descs[i];
- tmp_desc.family_name = NULL;
- tmp_desc.size = 0;
+ str = pango_font_face_get_face_name (fontsel->faces[i]);
+ gtk_clist_append (GTK_CLIST (fontsel->font_style_clist), (char **)&str);
- str = pango_font_description_to_string (&tmp_desc);
- gtk_clist_append (GTK_CLIST (fontsel->font_style_clist), &str);
-
- if (descs[i]->weight == fontsel->font_desc->weight &&
- descs[i]->style == fontsel->font_desc->style &&
- descs[i]->stretch == fontsel->font_desc->stretch &&
- descs[i]->variant == fontsel->font_desc->variant)
- match_row = i;
+ if (old_desc)
+ {
+ PangoFontDescription *tmp_desc = pango_font_face_describe (fontsel->faces[i]);
+
+ if (font_description_style_equal (tmp_desc, old_desc))
+ match_row = i;
- g_free (str);
+ pango_font_description_free (tmp_desc);
+ }
}
- gtk_clist_select_row (GTK_CLIST (fontsel->font_style_clist), match_row, 0);
+ if (old_desc)
+ pango_font_description_free (old_desc);
+
+ if (match_row < 0 && n_faces)
+ match_row = 0;
+
if (match_row >= 0)
{
- gtk_clist_get_text (GTK_CLIST (fontsel->font_style_clist), match_row, 0, &str);
+ fontsel->face = fontsel->faces[match_row];
+ gtk_clist_select_row (GTK_CLIST (fontsel->font_style_clist), match_row, 0);
+
+ str = pango_font_face_get_face_name (fontsel->face);
gtk_entry_set_text (GTK_ENTRY (fontsel->font_style_entry), str);
}
+ else
+ fontsel->face = NULL;
gtk_clist_thaw (GTK_CLIST (fontsel->font_style_clist));
-
- pango_font_descriptions_free (descs, n_descs);
}
@@ -669,8 +707,6 @@ gtk_font_selection_select_style (GtkWidget *w,
gpointer data)
{
GtkFontSelection *fontsel = GTK_FONT_SELECTION (data);
- PangoFontDescription *tmp_desc;
- gchar *text;
gint index;
if (bevent && !GTK_WIDGET_HAS_FOCUS (w))
@@ -679,18 +715,7 @@ gtk_font_selection_select_style (GtkWidget *w,
if (GTK_CLIST (fontsel->font_style_clist)->selection)
{
index = GPOINTER_TO_INT (GTK_CLIST (fontsel->font_style_clist)->selection->data);
-
- if (gtk_clist_get_text (GTK_CLIST (fontsel->font_style_clist), index, 0, &text))
- {
- tmp_desc = pango_font_description_from_string (text);
-
- fontsel->font_desc->style = tmp_desc->style;
- fontsel->font_desc->variant = tmp_desc->variant;
- fontsel->font_desc->weight = tmp_desc->weight;
- fontsel->font_desc->stretch = tmp_desc->stretch;
-
- pango_font_description_free (tmp_desc);
- }
+ fontsel->face = fontsel->faces[index];
}
gtk_font_selection_show_available_sizes (fontsel);
@@ -701,6 +726,7 @@ static void
gtk_font_selection_show_available_sizes (GtkFontSelection *fontsel)
{
gint i;
+ gint current_size = fontsel->size;
gchar buffer[128];
gchar *size;
@@ -713,12 +739,12 @@ gtk_font_selection_show_available_sizes (GtkFontSelection *fontsel)
sprintf (buffer, "%i", font_sizes[i]);
size = buffer;
gtk_clist_append (GTK_CLIST (fontsel->size_clist), &size);
- if (font_sizes[i] * PANGO_SCALE == fontsel->font_desc->size)
+ if (font_sizes[i] * PANGO_SCALE == current_size)
gtk_clist_select_row (GTK_CLIST (fontsel->size_clist), i, 0);
}
gtk_clist_thaw (GTK_CLIST (fontsel->size_clist));
- sprintf (buffer, "%i", fontsel->font_desc->size / PANGO_SCALE);
+ sprintf (buffer, "%i", current_size / PANGO_SCALE);
gtk_entry_set_text (GTK_ENTRY (fontsel->size_entry), buffer);
}
@@ -743,9 +769,9 @@ gtk_font_selection_size_activate (GtkWidget *w,
text = gtk_entry_get_text (GTK_ENTRY (fontsel->size_entry));
new_size = atoi (text) * PANGO_SCALE;
- if (fontsel->font_desc->size != new_size)
+ if (fontsel->size != new_size)
{
- fontsel->font_desc->size = new_size;
+ fontsel->size = new_size;
gtk_font_selection_load_font (fontsel);
}
}
@@ -770,11 +796,10 @@ gtk_font_selection_select_size (GtkWidget *w,
gtk_clist_get_text (GTK_CLIST (fontsel->size_clist), row, 0, &text);
new_size = atoi (text) * PANGO_SCALE;
- if (fontsel->font_desc->size != new_size)
+ if (fontsel->size != new_size)
{
/* If the size was selected by the user we set the selected_size. */
- fontsel->font_desc->size = new_size;
-
+ fontsel->size = new_size;
gtk_font_selection_load_font (fontsel);
}
}
@@ -789,6 +814,15 @@ gtk_font_selection_load_font (GtkFontSelection *fontsel)
gtk_font_selection_update_preview (fontsel);
}
+static PangoFontDescription *
+gtk_font_selection_get_font_description (GtkFontSelection *fontsel)
+{
+ PangoFontDescription *font_desc = pango_font_face_describe (fontsel->face);
+ pango_font_description_set_size (font_desc, fontsel->size);
+
+ return font_desc;
+}
+
/* This sets the font in the preview entry to the selected font, and tries to
make sure that the preview entry is a reasonable size, i.e. so that the
text can be seen with a bit of space to spare. But it tries to avoid
@@ -807,7 +841,8 @@ gtk_font_selection_update_preview (GtkFontSelection *fontsel)
gtk_widget_get_child_requisition (preview_entry, &old_requisition);
rc_style = gtk_rc_style_new ();
- rc_style->font_desc = pango_font_description_copy (fontsel->font_desc);
+ rc_style->font_desc = gtk_font_selection_get_font_description (fontsel);
+
gtk_widget_modify_style (preview_entry, rc_style);
gtk_rc_style_unref (rc_style);
@@ -834,7 +869,11 @@ GdkFont*
gtk_font_selection_get_font (GtkFontSelection *fontsel)
{
if (!fontsel->font)
- fontsel->font = gdk_font_from_description (fontsel->font_desc);
+ {
+ PangoFontDescription *font_desc = gtk_font_selection_get_font_description (fontsel);
+ fontsel->font = gdk_font_from_description (font_desc);
+ pango_font_description_free (font_desc);
+ }
return fontsel->font;
}
@@ -843,7 +882,13 @@ gtk_font_selection_get_font (GtkFontSelection *fontsel)
gchar *
gtk_font_selection_get_font_name (GtkFontSelection *fontsel)
{
- return pango_font_description_to_string (fontsel->font_desc);
+ gchar *result;
+
+ PangoFontDescription *font_desc = gtk_font_selection_get_font_description (fontsel);
+ result = pango_font_description_to_string (font_desc);
+ pango_font_description_free (font_desc);
+
+ return result;
}
@@ -856,44 +901,56 @@ gboolean
gtk_font_selection_set_font_name (GtkFontSelection *fontsel,
const gchar *fontname)
{
+ PangoFontFamily *new_family = NULL;
+ PangoFontFace *new_face = NULL;
PangoFontDescription *new_desc;
- PangoFontDescription **descs;
- int n_descs, i;
- gboolean found = FALSE;
-
+ gint n_families, n_faces, i;
+
g_return_val_if_fail (GTK_IS_FONT_SELECTION (fontsel), FALSE);
new_desc = pango_font_description_from_string (fontname);
/* Check to make sure that this is in the list of allowed fonts */
- pango_context_list_fonts (gtk_widget_get_pango_context (GTK_WIDGET (fontsel)),
- new_desc->family_name, &descs, &n_descs);
-
- for (i=0; i<n_descs; i++)
+ n_families = GTK_CLIST (fontsel->font_clist)->rows;
+ for (i = 0; i < n_families; i++)
{
- if (descs[i]->weight == new_desc->weight &&
- descs[i]->style == new_desc->style &&
- descs[i]->stretch == new_desc->stretch &&
- descs[i]->variant == new_desc->variant)
- {
- found = TRUE;
- break;
- }
+ if (strcasecmp (pango_font_family_get_name (fontsel->families[i]),
+ pango_font_description_get_family (new_desc)) == 0)
+ new_family = fontsel->families[i];
}
- pango_font_descriptions_free (descs, n_descs);
-
- if (!found)
+ if (!new_family)
return FALSE;
- pango_font_description_free (fontsel->font_desc);
- fontsel->font_desc = new_desc;
+ fontsel->family = new_family;
+ gtk_font_selection_show_available_styles (fontsel);
+
+ n_faces = GTK_CLIST (fontsel->font_style_clist)->rows;
+ for (i=0; i < n_faces; i++)
+ {
+ PangoFontDescription *tmp_desc = pango_font_face_describe (fontsel->faces[i]);
+
+ if (font_description_style_equal (tmp_desc, new_desc))
+ new_face = fontsel->faces[i];
+
+ pango_font_description_free (tmp_desc);
+
+ if (new_face)
+ break;
+ }
+
+ if (!new_face)
+ new_face = fontsel->faces[0];
+
+ fontsel->face = new_face;
+ gtk_font_selection_select_best_size (fontsel);
g_object_freeze_notify (G_OBJECT (fontsel));
g_object_notify (G_OBJECT (fontsel), "font_name");
g_object_notify (G_OBJECT (fontsel), "font");
g_object_thaw_notify (G_OBJECT (fontsel));
+
return TRUE;
}
diff --git a/gtk/gtkfontsel.h b/gtk/gtkfontsel.h
index aa39d16372..5d8eb82142 100644
--- a/gtk/gtkfontsel.h
+++ b/gtk/gtkfontsel.h
@@ -78,7 +78,14 @@ struct _GtkFontSelection
GtkWidget *filter_button;
GtkWidget *preview_entry;
- PangoFontDescription *font_desc;
+ PangoFontFamily **families;
+ PangoFontFamily *family; /* Current family */
+
+ PangoFontFace **faces;
+ PangoFontFace *face; /* Current face */
+
+ gint size;
+
GdkFont *font; /* Cache for gdk_font_selection_get_font, so we can preserve
* refcounting behavior
*/
diff --git a/gtk/gtkhruler.c b/gtk/gtkhruler.c
index c13d19cabd..573b6e03f2 100644
--- a/gtk/gtkhruler.c
+++ b/gtk/gtkhruler.c
@@ -135,7 +135,6 @@ gtk_hruler_draw_ticks (GtkRuler *ruler)
{
GtkWidget *widget;
GdkGC *gc, *bg_gc;
- GdkFont *font;
gint i;
gint width, height;
gint xthickness;
@@ -163,7 +162,6 @@ gtk_hruler_draw_ticks (GtkRuler *ruler)
gc = widget->style->fg_gc[GTK_STATE_NORMAL];
bg_gc = widget->style->bg_gc[GTK_STATE_NORMAL];
- font = widget->style->font;
xthickness = widget->style->xthickness;
ythickness = widget->style->ythickness;
diff --git a/gtk/gtklabel.c b/gtk/gtklabel.c
index 0f8eb5053c..7100a567d9 100644
--- a/gtk/gtklabel.c
+++ b/gtk/gtklabel.c
@@ -1205,7 +1205,7 @@ gtk_label_ensure_layout (GtkLabel *label,
longest_paragraph = width;
width = MIN (width,
- PANGO_SCALE * gdk_string_width (GTK_WIDGET (label)->style->font,
+ PANGO_SCALE * gdk_string_width (gtk_style_get_font (GTK_WIDGET (label)->style),
"This long string gives a good enough length for any line to have."));
width = MIN (width,
PANGO_SCALE * (gdk_screen_width () + 1) / 2);
diff --git a/gtk/gtkspinbutton.c b/gtk/gtkspinbutton.c
index acb463f9f7..7a7a2d07a9 100644
--- a/gtk/gtkspinbutton.c
+++ b/gtk/gtkspinbutton.c
@@ -563,16 +563,21 @@ gtk_spin_button_size_request (GtkWidget *widget,
if (entry->width_chars < 0)
{
PangoContext *context;
- PangoFontMetrics metrics;
+ PangoFontMetrics *metrics;
gint width;
gint w;
- int string_len;
+ gint string_len;
+ gint digit_width;
context = gtk_widget_get_pango_context (widget);
- pango_context_get_metrics (context,
- widget->style->font_desc,
- pango_context_get_language (context),
- &metrics);
+ metrics = pango_context_get_metrics (context,
+ widget->style->font_desc,
+ pango_context_get_language (context));
+
+ digit_width = pango_font_metrics_get_approximate_digit_width (metrics);
+ digit_width = PANGO_PIXELS (digit_width);
+
+ pango_font_metrics_unref (metrics);
/* Get max of MIN_SPIN_BUTTON_WIDTH, size of upper, size of lower */
@@ -580,11 +585,11 @@ gtk_spin_button_size_request (GtkWidget *widget,
string_len = compute_double_length (spin_button->adjustment->upper,
spin_button->digits);
- w = MIN (string_len, 10) * PANGO_PIXELS (metrics.approximate_digit_width);
+ w = MIN (string_len, 10) * digit_width;
width = MAX (width, w);
string_len = compute_double_length (spin_button->adjustment->lower,
spin_button->adjustment->step_increment);
- w = MIN (string_len, 10) * PANGO_PIXELS (metrics.approximate_digit_width);
+ w = MIN (string_len, 10) * digit_width;
width = MAX (width, w);
requisition->width = width + ARROW_SIZE + 2 * widget->style->xthickness;
diff --git a/gtk/gtkstyle.c b/gtk/gtkstyle.c
index dfddd0a1de..5a91aab433 100644
--- a/gtk/gtkstyle.c
+++ b/gtk/gtkstyle.c
@@ -412,7 +412,6 @@ static GdkColor gtk_default_selected_base = { 0, 0xa4a4, 0xdfdf, 0xffff };
static GdkColor gtk_default_active_base = { 0, 0xbcbc, 0xd2d2, 0xeeee };
static gpointer parent_class = NULL;
-static GdkFont *static_default_font = NULL;
/* --- functions --- */
@@ -451,20 +450,6 @@ gtk_style_init (GtkStyle *style)
style->font_desc = pango_font_description_from_string ("Sans 10");
- if (!static_default_font)
- {
- static_default_font = gdk_font_from_description (style->font_desc);
-
- if (!static_default_font)
- static_default_font = gdk_font_load ("fixed");
-
- if (!static_default_font)
- g_error ("Unable to load \"fixed\" font");
- }
-
- style->font = static_default_font;
- gdk_font_ref (style->font);
-
style->attach_count = 0;
style->colormap = NULL;
style->depth = -1;
@@ -612,10 +597,15 @@ gtk_style_finalize (GObject *object)
g_slist_free_1 (style->styles);
}
}
-
- gdk_font_unref (style->font);
+
pango_font_description_free (style->font_desc);
+ if (style->private_font)
+ gdk_font_unref (style->private_font);
+
+ if (style->private_font_desc)
+ pango_font_description_free (style->private_font_desc);
+
if (style->rc_style)
gtk_rc_style_unref (style->rc_style);
@@ -735,13 +725,13 @@ gtk_style_attach (GtkStyle *style,
/* A style gets a refcount from being attached */
if (new_style->attach_count == 0)
- gtk_style_ref (new_style);
+ g_object_ref (new_style);
/* Another refcount belongs to the parent */
if (style != new_style)
{
- gtk_style_unref (style);
- gtk_style_ref (new_style);
+ g_object_unref (style);
+ g_object_ref (new_style);
}
new_style->attach_count++;
@@ -762,7 +752,7 @@ gtk_style_detach (GtkStyle *style)
gdk_colormap_unref (style->colormap);
style->colormap = NULL;
- gtk_style_unref (style);
+ g_object_unref (style);
}
}
@@ -1195,11 +1185,11 @@ gtk_style_real_copy (GtkStyle *style,
style->bg_pixmap[i] = src->bg_pixmap[i];
}
- if (style->font)
- gdk_font_unref (style->font);
- style->font = src->font;
- if (style->font)
- gdk_font_ref (style->font);
+ if (style->private_font)
+ gdk_font_unref (style->private_font);
+ style->private_font = src->private_font;
+ if (style->private_font)
+ gdk_font_ref (style->private_font);
if (style->font_desc)
pango_font_description_free (style->font_desc);
@@ -1225,7 +1215,6 @@ static void
gtk_style_real_init_from_rc (GtkStyle *style,
GtkRcStyle *rc_style)
{
- GdkFont *old_font;
gint i;
/* cache _should_ be still empty */
@@ -1235,13 +1224,6 @@ gtk_style_real_init_from_rc (GtkStyle *style,
{
pango_font_description_free (style->font_desc);
style->font_desc = pango_font_description_copy (rc_style->font_desc);
-
- old_font = style->font;
- style->font = gdk_font_from_description (style->font_desc);
- if (style->font)
- gdk_font_unref (old_font);
- else
- style->font = old_font;
}
for (i = 0; i < 5; i++)
@@ -1412,15 +1394,7 @@ gtk_style_real_realize (GtkStyle *style)
gdk_color_black (style->colormap, &style->black);
gdk_color_white (style->colormap, &style->white);
- gc_values_mask = GDK_GC_FOREGROUND | GDK_GC_FONT;
- if (style->font->type == GDK_FONT_FONT)
- {
- gc_values.font = style->font;
- }
- else if (style->font->type == GDK_FONT_FONTSET)
- {
- gc_values.font = static_default_font;
- }
+ gc_values_mask = GDK_GC_FOREGROUND;
gc_values.foreground = style->black;
style->black_gc = gtk_gc_get (style->depth, style->colormap, &gc_values, gc_values_mask);
@@ -2796,9 +2770,9 @@ gtk_default_draw_string (GtkStyle *style,
}
if (state_type == GTK_STATE_INSENSITIVE)
- gdk_draw_string (window, style->font, style->white_gc, x + 1, y + 1, string);
+ gdk_draw_string (window, gtk_style_get_font (style), style->white_gc, x + 1, y + 1, string);
- gdk_draw_string (window, style->font, style->fg_gc[state_type], x, y, string);
+ gdk_draw_string (window, gtk_style_get_font (style), style->fg_gc[state_type], x, y, string);
if (area)
{
@@ -4990,3 +4964,89 @@ gtk_border_free (GtkBorder *border)
g_free (border);
}
+/**
+ * gtk_style_get_font:
+ * @style: a #GtkStyle
+ *
+ * Gets the #GdkFont to use for the given style. This is
+ * meant only as a replacement for direct access to style->font
+ * and should not be used in new code. New code should
+ * use style->font_desc instead.
+ *
+ * Return value: the #GdkFont for the style. This font is owned
+ * by the style; if you want to keep around a copy, you must
+ * call gdk_font_ref().
+ **/
+GdkFont *
+gtk_style_get_font (GtkStyle *style)
+{
+ g_return_val_if_fail (GTK_IS_STYLE (style), NULL);
+
+ if (style->private_font && style->private_font_desc)
+ {
+ if (!style->font_desc ||
+ !pango_font_description_equal (style->private_font_desc, style->font_desc))
+ {
+ gdk_font_unref (style->private_font);
+ style->private_font = NULL;
+
+ if (style->private_font_desc)
+ {
+ pango_font_description_free (style->private_font_desc);
+ style->private_font_desc = NULL;
+ }
+ }
+ }
+
+ if (!style->private_font)
+ {
+ if (style->font_desc)
+ {
+ style->private_font = gdk_font_from_description (style->font_desc);
+ style->private_font_desc = pango_font_description_copy (style->font_desc);
+ }
+
+ if (!style->private_font)
+ style->private_font = gdk_font_load ("fixed");
+
+ if (!style->private_font)
+ g_error ("Unable to load \"fixed\" font");
+ }
+
+ return style->private_font;
+}
+
+/**
+ * gtk_style_set_font:
+ * @style: a #GtkStyle.
+ * @font: a #GdkFont, or %NULL to use the #GdkFont corresponding
+ * to style->font_desc.
+ *
+ * Sets the #GdkFont to use for a given style. This is
+ * meant only as a replacement for direct access to style->font
+ * and should not be used in new code. New code should
+ * use style->font_desc instead.
+ **/
+void
+gtk_style_set_font (GtkStyle *style,
+ GdkFont *font)
+{
+ GdkFont *old_font;
+
+ g_return_if_fail (GTK_IS_STYLE (style));
+
+ old_font = style->private_font;
+
+ style->private_font = font;
+ if (font)
+ gdk_font_ref (font);
+
+ if (old_font)
+ gdk_font_unref (old_font);
+
+ if (style->private_font_desc)
+ {
+ pango_font_description_free (style->private_font_desc);
+ style->private_font_desc = NULL;
+ }
+}
diff --git a/gtk/gtkstyle.h b/gtk/gtkstyle.h
index 8c2a0c5b4c..a6de90197f 100644
--- a/gtk/gtkstyle.h
+++ b/gtk/gtkstyle.h
@@ -87,7 +87,6 @@ struct _GtkStyle
GdkColor black;
GdkColor white;
- GdkFont *font;
PangoFontDescription *font_desc;
gint xthickness;
@@ -112,6 +111,8 @@ struct _GtkStyle
gint depth;
GdkColormap *colormap;
+ GdkFont *private_font;
+ PangoFontDescription *private_font_desc; /* Font description for style->private_font or %NULL */
/* the RcStyle from which this style was created */
GtkRcStyle *rc_style;
@@ -414,12 +415,20 @@ struct _GtkBorder
GType gtk_style_get_type (void) G_GNUC_CONST;
GtkStyle* gtk_style_new (void);
-GtkStyle* gtk_style_copy (GtkStyle *style);
-GtkStyle* gtk_style_attach (GtkStyle *style,
- GdkWindow *window);
+GtkStyle* gtk_style_copy (GtkStyle *style);
+GtkStyle* gtk_style_attach (GtkStyle *style,
+ GdkWindow *window);
void gtk_style_detach (GtkStyle *style);
+
+#ifndef GTK_DISABLE_DEPRECATED
GtkStyle* gtk_style_ref (GtkStyle *style);
void gtk_style_unref (GtkStyle *style);
+
+GdkFont * gtk_style_get_font (GtkStyle *style);
+void gtk_style_set_font (GtkStyle *style,
+ GdkFont *font);
+#endif /* GTK_DISABLE_DEPRECATED */
+
void gtk_style_set_background (GtkStyle *style,
GdkWindow *window,
GtkStateType state_type);
diff --git a/gtk/gtktext.c b/gtk/gtktext.c
index 4ab3b453b8..f573091977 100644
--- a/gtk/gtktext.c
+++ b/gtk/gtktext.c
@@ -72,7 +72,7 @@
#define MARK_CURRENT_FONT(text, mark) \
((MARK_CURRENT_PROPERTY(mark)->flags & PROPERTY_FONT) ? \
MARK_CURRENT_PROPERTY(mark)->font->gdk_font : \
- GTK_WIDGET (text)->style->font)
+ gtk_style_get_font (GTK_WIDGET (text)->style))
#define MARK_CURRENT_FORE(text, mark) \
((MARK_CURRENT_PROPERTY(mark)->flags & PROPERTY_FOREGROUND) ? \
&MARK_CURRENT_PROPERTY(mark)->fore_color : \
@@ -985,7 +985,7 @@ gtk_text_insert (GtkText *text,
GtkWidget *widget;
widget = GTK_WIDGET (text);
gtk_widget_ensure_style (widget);
- if ((widget->style) && (widget->style->font->type == GDK_FONT_FONTSET))
+ if ((widget->style) && (gtk_style_get_font (widget->style)->type == GDK_FONT_FONTSET))
{
text->use_wchar = TRUE;
g_free (text->text.ch);
@@ -1392,7 +1392,7 @@ gtk_text_style_set (GtkWidget *widget,
if (text->current_font)
text_font_unref (text->current_font);
- text->current_font = get_text_font (widget->style->font);
+ text->current_font = get_text_font (gtk_style_get_font (widget->style));
}
static void
@@ -1544,6 +1544,7 @@ static void
gtk_text_size_request (GtkWidget *widget,
GtkRequisition *requisition)
{
+ GdkFont *font;
gint xthickness;
gint ythickness;
gint char_height;
@@ -1554,11 +1555,13 @@ gtk_text_size_request (GtkWidget *widget,
xthickness = widget->style->xthickness + TEXT_BORDER_ROOM;
ythickness = widget->style->ythickness + TEXT_BORDER_ROOM;
+
+ font = gtk_style_get_font (widget->style);
- char_height = MIN_TEXT_HEIGHT_LINES * (widget->style->font->ascent +
- widget->style->font->descent);
+ char_height = MIN_TEXT_HEIGHT_LINES * (font->ascent +
+ font->descent);
- char_width = MIN_TEXT_WIDTH_LINES * (gdk_text_width (widget->style->font,
+ char_width = MIN_TEXT_WIDTH_LINES * (gdk_text_width (font,
"ABCDEFGHIJKLMNOPQRSTUVWXYZ",
26)
/ 26);
diff --git a/gtk/gtktextlayout.c b/gtk/gtktextlayout.c
index bcb10912e3..62ac18c6f4 100644
--- a/gtk/gtktextlayout.c
+++ b/gtk/gtktextlayout.c
@@ -1313,7 +1313,7 @@ add_text_attrs (GtkTextLayout *layout,
{
PangoAttribute *attr;
- attr = pango_attr_font_desc_new (&style->font);
+ attr = pango_attr_font_desc_new (style->font);
attr->start_index = start;
attr->end_index = start + byte_count;
@@ -1585,7 +1585,7 @@ add_preedit_attrs (GtkTextLayout *layout,
do
{
GtkTextAppearance appearance = style->appearance;
- PangoFontDescription font_desc;
+ PangoFontDescription *font_desc = pango_font_description_copy_static (style->font);
PangoAttribute *insert_attr;
GSList *extra_attrs = NULL;
GSList *tmp_list;
@@ -1597,8 +1597,7 @@ add_preedit_attrs (GtkTextLayout *layout,
if (end == G_MAXINT)
end = layout->preedit_len;
- pango_attr_iterator_get_font (iter, &style->font,
- &font_desc, &language, &extra_attrs);
+ pango_attr_iterator_get_font (iter, font_desc, &language, &extra_attrs);
tmp_list = extra_attrs;
while (tmp_list)
@@ -1633,7 +1632,7 @@ add_preedit_attrs (GtkTextLayout *layout,
g_slist_free (extra_attrs);
- insert_attr = pango_attr_font_desc_new (&font_desc);
+ insert_attr = pango_attr_font_desc_new (font_desc);
insert_attr->start_index = start + offset;
insert_attr->end_index = end + offset;
@@ -1651,6 +1650,8 @@ add_preedit_attrs (GtkTextLayout *layout,
add_generic_attrs (layout, &appearance, end - start,
attrs, start + offset,
size_only, TRUE);
+
+ pango_font_description_free (font_desc);
}
while (pango_attr_iterator_next (iter));
diff --git a/gtk/gtktexttag.c b/gtk/gtktexttag.c
index 93f1313db3..97057f8fb7 100644
--- a/gtk/gtktexttag.c
+++ b/gtk/gtktexttag.c
@@ -727,68 +727,104 @@ set_fg_color (GtkTextTag *tag, GdkColor *color)
}
}
+static PangoFontMask
+get_property_font_set_mask (guint prop_id)
+{
+ switch (prop_id)
+ {
+ case PROP_FAMILY_SET:
+ return PANGO_FONT_MASK_FAMILY;
+ case PROP_STYLE_SET:
+ return PANGO_FONT_MASK_STYLE;
+ case PROP_VARIANT_SET:
+ return PANGO_FONT_MASK_VARIANT;
+ case PROP_WEIGHT_SET:
+ return PANGO_FONT_MASK_WEIGHT;
+ case PROP_STRETCH_SET:
+ return PANGO_FONT_MASK_STRETCH;
+ case PROP_SIZE_SET:
+ return PANGO_FONT_MASK_SIZE;
+ }
+
+ return 0;
+}
+
+static void
+notify_set_changed (GObject *object,
+ PangoFontMask changed_mask)
+{
+ if (changed_mask & PANGO_FONT_MASK_FAMILY)
+ g_object_notify (object, "family_set");
+ if (changed_mask & PANGO_FONT_MASK_STYLE)
+ g_object_notify (object, "style_set");
+ if (changed_mask & PANGO_FONT_MASK_VARIANT)
+ g_object_notify (object, "variant_set");
+ if (changed_mask & PANGO_FONT_MASK_WEIGHT)
+ g_object_notify (object, "weight_set");
+ if (changed_mask & PANGO_FONT_MASK_STRETCH)
+ g_object_notify (object, "stretch_set");
+ if (changed_mask & PANGO_FONT_MASK_SIZE)
+ g_object_notify (object, "size_set");
+}
+
static void
set_font_description (GtkTextTag *text_tag,
PangoFontDescription *font_desc)
{
- if (font_desc != NULL)
- {
- /* pango_font_description_from_string() will sometimes return
- * a NULL family or -1 size, so handle those cases.
- */
-
- if (font_desc->family_name)
- g_object_set (G_OBJECT (text_tag),
- "family", font_desc->family_name,
- NULL);
-
- if (font_desc->size >= 0)
- g_object_set (G_OBJECT (text_tag),
- "size", font_desc->size,
- NULL);
-
- g_object_set (G_OBJECT (text_tag),
- "style", font_desc->style,
- "variant", font_desc->variant,
- "weight", font_desc->weight,
- "stretch", font_desc->stretch,
- NULL);
- }
+ GObject *object = G_OBJECT (text_tag);
+ PangoFontDescription *new_font_desc;
+ PangoFontMask old_mask, new_mask, changed_mask, set_changed_mask;
+
+ if (font_desc)
+ new_font_desc = pango_font_description_copy (font_desc);
+ else
+ new_font_desc = pango_font_description_new ();
+
+ if (text_tag->values->font)
+ old_mask = pango_font_description_get_set_fields (text_tag->values->font);
else
+ old_mask = 0;
+
+ new_mask = pango_font_description_get_set_fields (new_font_desc);
+
+ changed_mask = old_mask | new_mask;
+ set_changed_mask = old_mask ^ new_mask;
+
+ if (text_tag->values->font)
+ pango_font_description_free (text_tag->values->font);
+ text_tag->values->font = new_font_desc;
+
+ g_object_freeze_notify (object);
+
+ g_object_notify (object, "font_desc");
+ g_object_notify (object, "font");
+
+ if (changed_mask & PANGO_FONT_MASK_FAMILY)
+ g_object_notify (object, "family");
+ if (changed_mask & PANGO_FONT_MASK_STYLE)
+ g_object_notify (object, "style");
+ if (changed_mask & PANGO_FONT_MASK_VARIANT)
+ g_object_notify (object, "variant");
+ if (changed_mask & PANGO_FONT_MASK_WEIGHT)
+ g_object_notify (object, "weight");
+ if (changed_mask & PANGO_FONT_MASK_STRETCH)
+ g_object_notify (object, "stretch");
+ if (changed_mask & PANGO_FONT_MASK_SIZE)
{
- g_object_freeze_notify (G_OBJECT (text_tag));
- if (text_tag->family_set)
- {
- text_tag->family_set = FALSE;
- g_object_notify (G_OBJECT (text_tag), "family_set");
- }
- if (text_tag->style_set)
- {
- text_tag->style_set = FALSE;
- g_object_notify (G_OBJECT (text_tag), "style_set");
- }
- if (text_tag->variant_set)
- {
- text_tag->variant_set = FALSE;
- g_object_notify (G_OBJECT (text_tag), "variant_set");
- }
- if (text_tag->weight_set)
- {
- text_tag->weight_set = FALSE;
- g_object_notify (G_OBJECT (text_tag), "weight_set");
- }
- if (text_tag->stretch_set)
- {
- text_tag->stretch_set = FALSE;
- g_object_notify (G_OBJECT (text_tag), "stretch_set");
- }
- if (text_tag->size_set)
- {
- text_tag->size_set = FALSE;
- g_object_notify (G_OBJECT (text_tag), "size_set");
- }
- g_object_thaw_notify (G_OBJECT (text_tag));
+ g_object_notify (object, "size");
+ g_object_notify (object, "size_points");
}
+
+ notify_set_changed (object, set_changed_mask);
+
+ g_object_thaw_notify (object);
+}
+
+static void
+gtk_text_tag_ensure_font (GtkTextTag *text_tag)
+{
+ if (!text_tag->values->font)
+ text_tag->values->font = pango_font_description_new ();
}
static void
@@ -820,7 +856,7 @@ gtk_text_tag_set_property (GObject *object,
else
g_warning ("Don't know color `%s'", g_value_get_string (value));
- g_object_notify (G_OBJECT (text_tag), "background_gdk");
+ g_object_notify (object, "background_gdk");
}
break;
@@ -833,7 +869,7 @@ gtk_text_tag_set_property (GObject *object,
else
g_warning ("Don't know color `%s'", g_value_get_string (value));
- g_object_notify (G_OBJECT (text_tag), "foreground_gdk");
+ g_object_notify (object, "foreground_gdk");
}
break;
@@ -858,7 +894,7 @@ gtk_text_tag_set_property (GObject *object,
GdkBitmap *bitmap = g_value_get_object (value);
text_tag->bg_stipple_set = TRUE;
- g_object_notify (G_OBJECT (text_tag), "background_stipple_set");
+ g_object_notify (object, "background_stipple_set");
if (text_tag->values->appearance.bg_stipple != bitmap)
{
@@ -878,7 +914,7 @@ gtk_text_tag_set_property (GObject *object,
GdkBitmap *bitmap = g_value_get_object (value);
text_tag->fg_stipple_set = TRUE;
- g_object_notify (G_OBJECT (text_tag), "foreground_stipple_set");
+ g_object_notify (object, "foreground_stipple_set");
if (text_tag->values->appearance.fg_stipple != bitmap)
{
@@ -905,9 +941,6 @@ gtk_text_tag_set_property (GObject *object,
set_font_description (text_tag, font_desc);
- if (font_desc)
- pango_font_description_free (font_desc);
-
size_changed = TRUE;
}
break;
@@ -925,116 +958,103 @@ gtk_text_tag_set_property (GObject *object,
break;
case PROP_FAMILY:
- if (text_tag->values->font.family_name)
- g_free (text_tag->values->font.family_name);
- text_tag->values->font.family_name = g_strdup (g_value_get_string (value));
- text_tag->family_set = TRUE;
- g_object_notify (G_OBJECT (text_tag), "family_set");
- g_object_notify (G_OBJECT (text_tag), "font_desc");
- g_object_notify (G_OBJECT (text_tag), "font");
- size_changed = TRUE;
- break;
-
case PROP_STYLE:
- text_tag->values->font.style = g_value_get_enum (value);
- text_tag->style_set = TRUE;
- g_object_notify (G_OBJECT (text_tag), "style_set");
- g_object_notify (G_OBJECT (text_tag), "font_desc");
- g_object_notify (G_OBJECT (text_tag), "font");
- size_changed = TRUE;
- break;
-
case PROP_VARIANT:
- text_tag->values->font.variant = g_value_get_enum (value);
- text_tag->variant_set = TRUE;
- g_object_notify (G_OBJECT (text_tag), "variant_set");
- g_object_notify (G_OBJECT (text_tag), "font_desc");
- g_object_notify (G_OBJECT (text_tag), "font");
- size_changed = TRUE;
- break;
-
case PROP_WEIGHT:
- text_tag->values->font.weight = g_value_get_int (value);
- text_tag->weight_set = TRUE;
- g_object_notify (G_OBJECT (text_tag), "weight_set");
- g_object_notify (G_OBJECT (text_tag), "font_desc");
- g_object_notify (G_OBJECT (text_tag), "font");
- size_changed = TRUE;
- break;
-
case PROP_STRETCH:
- text_tag->values->font.stretch = g_value_get_enum (value);
- text_tag->stretch_set = TRUE;
- g_object_notify (G_OBJECT (text_tag), "stretch_set");
- g_object_notify (G_OBJECT (text_tag), "font_desc");
- g_object_notify (G_OBJECT (text_tag), "font");
- size_changed = TRUE;
- break;
-
case PROP_SIZE:
- text_tag->values->font.size = g_value_get_int (value);
- text_tag->size_set = TRUE;
- g_object_notify (G_OBJECT (text_tag), "size_points");
- g_object_notify (G_OBJECT (text_tag), "size_set");
- g_object_notify (G_OBJECT (text_tag), "font_desc");
- g_object_notify (G_OBJECT (text_tag), "font");
- size_changed = TRUE;
- break;
-
+ case PROP_SIZE_POINTS:
+ {
+ PangoFontMask old_set_mask;
+
+ gtk_text_tag_ensure_font (text_tag);
+ old_set_mask = pango_font_description_get_set_fields (text_tag->values->font);
+
+ switch (prop_id)
+ {
+ case PROP_FAMILY:
+ pango_font_description_set_family (text_tag->values->font,
+ g_value_get_string (value));
+ break;
+ case PROP_STYLE:
+ pango_font_description_set_style (text_tag->values->font,
+ g_value_get_enum (value));
+ break;
+ case PROP_VARIANT:
+ pango_font_description_set_variant (text_tag->values->font,
+ g_value_get_enum (value));
+ break;
+ case PROP_WEIGHT:
+ pango_font_description_set_weight (text_tag->values->font,
+ g_value_get_enum (value));
+ break;
+ case PROP_STRETCH:
+ pango_font_description_set_stretch (text_tag->values->font,
+ g_value_get_enum (value));
+ break;
+ case PROP_SIZE:
+ pango_font_description_set_size (text_tag->values->font,
+ g_value_get_int (value));
+ g_object_notify (object, "size_points");
+ break;
+ case PROP_SIZE_POINTS:
+ pango_font_description_set_size (text_tag->values->font,
+ g_value_get_double (value) * PANGO_SCALE);
+ g_object_notify (object, "size");
+ break;
+ }
+
+ size_changed = TRUE;
+ notify_set_changed (object, old_set_mask & pango_font_description_get_set_fields (text_tag->values->font));
+ g_object_notify (object, "font_desc");
+ g_object_notify (object, "font");
+ }
+
case PROP_SCALE:
text_tag->values->font_scale = g_value_get_double (value);
text_tag->scale_set = TRUE;
- size_changed = TRUE;
- break;
-
- case PROP_SIZE_POINTS:
- text_tag->values->font.size = g_value_get_double (value) * PANGO_SCALE;
- text_tag->size_set = TRUE;
- g_object_notify (G_OBJECT (text_tag), "size");
- g_object_notify (G_OBJECT (text_tag), "size_set");
- g_object_notify (G_OBJECT (text_tag), "font_desc");
- g_object_notify (G_OBJECT (text_tag), "font");
+ g_object_notify (object, "scale_set");
size_changed = TRUE;
break;
case PROP_PIXELS_ABOVE_LINES:
text_tag->pixels_above_lines_set = TRUE;
text_tag->values->pixels_above_lines = g_value_get_int (value);
- g_object_notify (G_OBJECT (text_tag), "pixels_above_lines_set");
+ g_object_notify (object, "pixels_above_lines_set");
size_changed = TRUE;
break;
case PROP_PIXELS_BELOW_LINES:
text_tag->pixels_below_lines_set = TRUE;
text_tag->values->pixels_below_lines = g_value_get_int (value);
- g_object_notify (G_OBJECT (text_tag), "pixels_below_lines_set");
+ g_object_notify (object, "pixels_below_lines_set");
size_changed = TRUE;
break;
case PROP_PIXELS_INSIDE_WRAP:
text_tag->pixels_inside_wrap_set = TRUE;
text_tag->values->pixels_inside_wrap = g_value_get_int (value);
- g_object_notify (G_OBJECT (text_tag), "pixels_inside_wrap_set");
+ g_object_notify (object, "pixels_inside_wrap_set");
size_changed = TRUE;
break;
case PROP_EDITABLE:
text_tag->editable_set = TRUE;
text_tag->values->editable = g_value_get_boolean (value);
- g_object_notify (G_OBJECT (text_tag), "editable_set");
+ g_object_notify (object, "editable_set");
break;
case PROP_WRAP_MODE:
text_tag->wrap_mode_set = TRUE;
text_tag->values->wrap_mode = g_value_get_enum (value);
- g_object_notify (G_OBJECT (text_tag), "wrap_mode_set");
+ g_object_notify (object, "wrap_mode_set");
size_changed = TRUE;
break;
case PROP_JUSTIFICATION:
text_tag->justification_set = TRUE;
text_tag->values->justification = g_value_get_enum (value);
- g_object_notify (G_OBJECT (text_tag), "justification_set");
+ g_object_notify (object, "justification_set");
size_changed = TRUE;
break;
@@ -1045,53 +1065,53 @@ gtk_text_tag_set_property (GObject *object,
case PROP_LEFT_MARGIN:
text_tag->left_margin_set = TRUE;
text_tag->values->left_margin = g_value_get_int (value);
- g_object_notify (G_OBJECT (text_tag), "left_margin_set");
+ g_object_notify (object, "left_margin_set");
size_changed = TRUE;
break;
case PROP_INDENT:
text_tag->indent_set = TRUE;
text_tag->values->indent = g_value_get_int (value);
- g_object_notify (G_OBJECT (text_tag), "indent_set");
+ g_object_notify (object, "indent_set");
size_changed = TRUE;
break;
case PROP_STRIKETHROUGH:
text_tag->strikethrough_set = TRUE;
text_tag->values->appearance.strikethrough = g_value_get_boolean (value);
- g_object_notify (G_OBJECT (text_tag), "strikethrough_set");
+ g_object_notify (object, "strikethrough_set");
break;
case PROP_RIGHT_MARGIN:
text_tag->right_margin_set = TRUE;
text_tag->values->right_margin = g_value_get_int (value);
- g_object_notify (G_OBJECT (text_tag), "right_margin_set");
+ g_object_notify (object, "right_margin_set");
size_changed = TRUE;
break;
case PROP_UNDERLINE:
text_tag->underline_set = TRUE;
text_tag->values->appearance.underline = g_value_get_enum (value);
- g_object_notify (G_OBJECT (text_tag), "underline_set");
+ g_object_notify (object, "underline_set");
break;
case PROP_RISE:
text_tag->rise_set = TRUE;
text_tag->values->appearance.rise = g_value_get_int (value);
- g_object_notify (G_OBJECT (text_tag), "rise_set");
+ g_object_notify (object, "rise_set");
size_changed = TRUE;
break;
case PROP_BG_FULL_HEIGHT:
text_tag->bg_full_height_set = TRUE;
text_tag->values->bg_full_height = g_value_get_boolean (value);
- g_object_notify (G_OBJECT (text_tag), "bg_full_height_set");
+ g_object_notify (object, "bg_full_height_set");
break;
case PROP_LANGUAGE:
text_tag->language_set = TRUE;
text_tag->values->language = pango_language_from_string (g_value_get_string (value));
- g_object_notify (G_OBJECT (text_tag), "language_set");
+ g_object_notify (object, "language_set");
break;
case PROP_TABS:
@@ -1104,7 +1124,7 @@ gtk_text_tag_set_property (GObject *object,
text_tag->values->tabs =
pango_tab_array_copy (g_value_get_boxed (value));
- g_object_notify (G_OBJECT (text_tag), "tabs_set");
+ g_object_notify (object, "tabs_set");
size_changed = TRUE;
break;
@@ -1112,7 +1132,7 @@ gtk_text_tag_set_property (GObject *object,
case PROP_INVISIBLE:
text_tag->invisible_set = TRUE;
text_tag->values->invisible = g_value_get_boolean (value);
- g_object_notify (G_OBJECT (text_tag), "invisible_set");
+ g_object_notify (object, "invisible_set");
size_changed = TRUE;
break;
@@ -1147,33 +1167,14 @@ gtk_text_tag_set_property (GObject *object,
break;
case PROP_FAMILY_SET:
- text_tag->family_set = g_value_get_boolean (value);
- size_changed = TRUE;
- break;
-
case PROP_STYLE_SET:
- text_tag->style_set = g_value_get_boolean (value);
- size_changed = TRUE;
- break;
-
case PROP_VARIANT_SET:
- text_tag->variant_set = g_value_get_boolean (value);
- size_changed = TRUE;
- break;
-
case PROP_WEIGHT_SET:
- text_tag->weight_set = g_value_get_boolean (value);
- size_changed = TRUE;
- break;
-
case PROP_STRETCH_SET:
- text_tag->stretch_set = g_value_get_boolean (value);
- size_changed = TRUE;
- break;
-
case PROP_SIZE_SET:
- text_tag->size_set = g_value_get_boolean (value);
- size_changed = TRUE;
+ if (!g_value_get_boolean (value) && text_tag->values->font)
+ pango_font_description_unset_fields (text_tag->values->font,
+ get_property_font_set_mask (prop_id));
break;
case PROP_SCALE_SET:
@@ -1328,44 +1329,61 @@ gtk_text_tag_get_property (GObject *object,
/* FIXME GValue imposes a totally gratuitous string copy
* here, we could just hand off string ownership
*/
- gchar *str = pango_font_description_to_string (&tag->values->font);
+ gchar *str;
+
+ gtk_text_tag_ensure_font (tag);
+
+ str = pango_font_description_to_string (tag->values->font);
g_value_set_string (value, str);
g_free (str);
}
break;
case PROP_FONT_DESC:
- g_value_set_boxed (value, &tag->values->font);
+ gtk_text_tag_ensure_font (tag);
+ g_value_set_boxed (value, tag->values->font);
break;
case PROP_FAMILY:
- g_value_set_string (value, tag->values->font.family_name);
- break;
-
case PROP_STYLE:
- g_value_set_enum (value, tag->values->font.style);
- break;
-
case PROP_VARIANT:
- g_value_set_enum (value, tag->values->font.variant);
- break;
-
case PROP_WEIGHT:
- g_value_set_int (value, tag->values->font.weight);
- break;
-
case PROP_STRETCH:
- g_value_set_enum (value, tag->values->font.stretch);
- break;
-
case PROP_SIZE:
- g_value_set_int (value, tag->values->font.size);
- break;
-
case PROP_SIZE_POINTS:
- g_value_set_double (value, ((double)tag->values->font.size) / (double)PANGO_SCALE);
+ gtk_text_tag_ensure_font (tag);
+ switch (prop_id)
+ {
+ case PROP_FAMILY:
+ g_value_set_string (value, pango_font_description_get_family (tag->values->font));
+ break;
+
+ case PROP_STYLE:
+ g_value_set_enum (value, pango_font_description_get_style (tag->values->font));
+ break;
+
+ case PROP_VARIANT:
+ g_value_set_enum (value, pango_font_description_get_variant (tag->values->font));
+ break;
+
+ case PROP_WEIGHT:
+ g_value_set_int (value, pango_font_description_get_weight (tag->values->font));
+ break;
+
+ case PROP_STRETCH:
+ g_value_set_enum (value, pango_font_description_get_stretch (tag->values->font));
+ break;
+
+ case PROP_SIZE:
+ g_value_set_int (value, pango_font_description_get_size (tag->values->font));
+ break;
+
+ case PROP_SIZE_POINTS:
+ g_value_set_double (value, ((double)pango_font_description_get_size (tag->values->font)) / (double)PANGO_SCALE);
+ break;
+ }
break;
-
+
case PROP_SCALE:
g_value_set_double (value, tag->values->font_scale);
break;
@@ -1456,28 +1474,16 @@ gtk_text_tag_get_property (GObject *object,
break;
case PROP_FAMILY_SET:
- g_value_set_boolean (value, tag->family_set);
- break;
-
case PROP_STYLE_SET:
- g_value_set_boolean (value, tag->style_set);
- break;
-
case PROP_VARIANT_SET:
- g_value_set_boolean (value, tag->variant_set);
- break;
-
case PROP_WEIGHT_SET:
- g_value_set_boolean (value, tag->weight_set);
- break;
-
case PROP_STRETCH_SET:
- g_value_set_boolean (value, tag->stretch_set);
- break;
-
case PROP_SIZE_SET:
- g_value_set_boolean (value, tag->size_set);
- break;
+ {
+ PangoFontMask set_mask = tag->values->font ? pango_font_description_get_set_fields (tag->values->font) : 0;
+ PangoFontMask test_mask = get_property_font_set_mask (prop_id);
+ g_value_set_boolean (value, (set_mask & test_mask) != 0);
+ }
case PROP_SCALE_SET:
g_value_set_boolean (value, tag->scale_set);
@@ -1820,8 +1826,8 @@ gtk_text_attributes_copy_values (GtkTextAttributes *src,
if (dest->appearance.fg_stipple)
gdk_bitmap_unref (dest->appearance.fg_stipple);
- if (dest->font.family_name)
- g_free (dest->font.family_name);
+ if (dest->font)
+ pango_font_description_free (dest->font);
/* Copy */
orig_refcount = dest->refcount;
@@ -1833,7 +1839,8 @@ gtk_text_attributes_copy_values (GtkTextAttributes *src,
dest->language = src->language;
- dest->font.family_name = g_strdup (src->font.family_name);
+ if (dest->font)
+ dest->font = pango_font_description_copy (src->font);
dest->refcount = orig_refcount;
dest->realized = FALSE;
@@ -1881,8 +1888,8 @@ gtk_text_attributes_unref (GtkTextAttributes *values)
if (values->tabs)
pango_tab_array_free (values->tabs);
- if (values->font.family_name)
- g_free (values->font.family_name);
+ if (values->font)
+ pango_font_description_free (values->font);
g_free (values);
}
@@ -1976,28 +1983,13 @@ _gtk_text_attributes_fill_from_tags (GtkTextAttributes *dest,
dest->appearance.fg_stipple = vals->appearance.fg_stipple;
}
- if (tag->family_set)
- {
- if (dest->font.family_name)
- g_free (dest->font.family_name);
-
- dest->font.family_name = g_strdup (vals->font.family_name);
- }
-
- if (tag->style_set)
- dest->font.style = vals->font.style;
-
- if (tag->variant_set)
- dest->font.variant = vals->font.variant;
-
- if (tag->weight_set)
- dest->font.weight = vals->font.weight;
-
- if (tag->stretch_set)
- dest->font.stretch = vals->font.stretch;
-
- if (tag->size_set)
- dest->font.size = vals->font.size;
+ if (vals->font)
+ {
+ if (dest->font)
+ pango_font_description_merge (dest->font, vals->font, TRUE);
+ else
+ dest->font = pango_font_description_copy (vals->font);
+ }
/* multiply all the scales together to get a composite */
if (tag->scale_set)
@@ -2068,13 +2060,8 @@ _gtk_text_tag_affects_size (GtkTextTag *tag)
g_return_val_if_fail (GTK_IS_TEXT_TAG (tag), FALSE);
return
- tag->family_set ||
- tag->style_set ||
- tag->variant_set ||
- tag->weight_set ||
- tag->size_set ||
+ (tag->values->font && pango_font_description_get_set_fields (tag->values->font) != 0) ||
tag->scale_set ||
- tag->stretch_set ||
tag->justification_set ||
tag->left_margin_set ||
tag->indent_set ||
diff --git a/gtk/gtktexttag.h b/gtk/gtktexttag.h
index 10b7bb2980..3020e8b6e5 100644
--- a/gtk/gtktexttag.h
+++ b/gtk/gtktexttag.h
@@ -54,12 +54,6 @@ struct _GtkTextTag
guint bg_color_set : 1;
guint bg_stipple_set : 1;
guint fg_color_set : 1;
- guint family_set : 1;
- guint style_set : 1;
- guint variant_set : 1;
- guint weight_set : 1;
- guint stretch_set : 1;
- guint size_set : 1;
guint scale_set : 1;
guint fg_stipple_set : 1;
guint justification_set : 1;
@@ -147,7 +141,7 @@ struct _GtkTextAttributes
GtkTextDirection direction;
/* Individual chunks of this can be set/unset as a group */
- PangoFontDescription font;
+ PangoFontDescription *font;
gdouble font_scale;
diff --git a/gtk/gtktextview.c b/gtk/gtktextview.c
index 1e1a82dbf7..5054501df1 100644
--- a/gtk/gtktextview.c
+++ b/gtk/gtktextview.c
@@ -302,9 +302,6 @@ static void gtk_text_view_forall (GtkContainer *container,
/* FIXME probably need the focus methods. */
-/* Hack-around */
-#define g_signal_handlers_disconnect_by_func(obj, func, data) g_signal_handlers_disconnect_matched (obj, G_SIGNAL_MATCH_FUNC | G_SIGNAL_MATCH_DATA, 0, 0, NULL, func, data)
-
typedef struct _GtkTextViewChild GtkTextViewChild;
struct _GtkTextViewChild
@@ -4419,17 +4416,16 @@ gtk_text_view_end_selection_drag (GtkTextView *text_view, GdkEventButton *event)
static void
gtk_text_view_set_attributes_from_style (GtkTextView *text_view,
- GtkTextAttributes *values,
+ GtkTextAttributes *values,
GtkStyle *style)
{
values->appearance.bg_color = style->base[GTK_STATE_NORMAL];
values->appearance.fg_color = style->text[GTK_STATE_NORMAL];
- if (values->font.family_name)
- g_free (values->font.family_name);
+ if (values->font)
+ pango_font_description_free (values->font);
- values->font = *style->font_desc;
- values->font.family_name = g_strdup (style->font_desc->family_name);
+ values->font = pango_font_description_copy (style->font_desc);
}
static void
diff --git a/gtk/gtkwidget.c b/gtk/gtkwidget.c
index 460038f362..c039bb06ab 100644
--- a/gtk/gtkwidget.c
+++ b/gtk/gtkwidget.c
@@ -1249,7 +1249,7 @@ gtk_widget_init (GtkWidget *widget)
GTK_DOUBLE_BUFFERED);
widget->style = gtk_widget_get_default_style ();
- gtk_style_ref (widget->style);
+ g_object_ref (widget->style);
}
@@ -3808,7 +3808,7 @@ gtk_widget_set_style_internal (GtkWidget *widget,
previous_style = widget->style;
widget->style = style;
- gtk_style_ref (widget->style);
+ g_object_ref (widget->style);
if (GTK_WIDGET_REALIZED (widget))
widget->style = gtk_style_attach (widget->style, widget->window);
@@ -3816,7 +3816,7 @@ gtk_widget_set_style_internal (GtkWidget *widget,
gtk_signal_emit (GTK_OBJECT (widget),
widget_signals[STYLE_SET],
initial_emission ? NULL : previous_style);
- gtk_style_unref (previous_style);
+ g_object_unref (previous_style);
if (widget->parent && !initial_emission)
{
@@ -3920,7 +3920,7 @@ gtk_widget_get_default_style (void)
if (!gtk_default_style)
{
gtk_default_style = gtk_style_new ();
- gtk_style_ref (gtk_default_style);
+ g_object_ref (gtk_default_style);
}
return gtk_default_style;
@@ -5167,9 +5167,9 @@ gtk_widget_real_destroy (GtkObject *object)
gtk_grab_remove (widget);
gtk_selection_remove_all (widget);
- gtk_style_unref (widget->style);
+ g_object_unref (widget->style);
widget->style = gtk_widget_get_default_style ();
- gtk_style_ref (widget->style);
+ g_object_ref (widget->style);
GTK_OBJECT_CLASS (parent_class)->destroy (object);
}
@@ -5186,7 +5186,7 @@ gtk_widget_finalize (GObject *object)
gtk_grab_remove (widget);
gtk_selection_remove_all (widget);
- gtk_style_unref (widget->style);
+ g_object_unref (widget->style);
widget->style = NULL;
if (widget->name)