Commit d399a4ac authored by Tristan Van Berkom's avatar Tristan Van Berkom Committed by Matthias Clasen

Added GdkRGBA properties to GtkTextTag.

This now allows text view to render text with alpha values in
the text foreground and backgrounds, the work is almost complete,
currently the error-underline-color is still a GdkColor style property
and since we use only GdkRGBA for rendering it needs to be converted
and applied, probably a new rgba version of the style property should
also be introduced.

This commit adds tests/testtextview that must be run from the tests/
directory to show translucent text in action.
parent 297e7393
...@@ -61,17 +61,17 @@ ...@@ -61,17 +61,17 @@
* Creates a #GtkTextAttributes, which describes * Creates a #GtkTextAttributes, which describes
* a set of properties on some text. * a set of properties on some text.
* *
* Return value: a new #GtkTextAttributes * Return value: a new #GtkTextAttributes,
**/ * free with gtk_text_attributes_unref().
*/
GtkTextAttributes* GtkTextAttributes*
gtk_text_attributes_new (void) gtk_text_attributes_new (void)
{ {
GtkTextAttributes *values; GtkTextAttributes *values;
values = g_new0 (GtkTextAttributes, 1); values = g_slice_new0 (GtkTextAttributes);
/* 0 is a valid value for most of the struct */ /* 0 is a valid value for most of the struct */
values->refcount = 1; values->refcount = 1;
values->language = gtk_get_default_language (); values->language = gtk_get_default_language ();
...@@ -79,18 +79,19 @@ gtk_text_attributes_new (void) ...@@ -79,18 +79,19 @@ gtk_text_attributes_new (void)
values->font_scale = 1.0; values->font_scale = 1.0;
values->editable = TRUE; values->editable = TRUE;
return values; return values;
} }
/** /**
* gtk_text_attributes_copy: * gtk_text_attributes_copy:
* @src: a #GtkTextAttributes to be copied * @src: a #GtkTextAttributes to be copied
* *
* Copies @src and returns a new #GtkTextAttributes. * Copies @src and returns a new #GtkTextAttributes.
* *
* Return value: a copy of @src * Return value: a copy of @src,
**/ * free with gtk_text_attributes_unref()
*/
GtkTextAttributes* GtkTextAttributes*
gtk_text_attributes_copy (GtkTextAttributes *src) gtk_text_attributes_copy (GtkTextAttributes *src)
{ {
...@@ -110,10 +111,10 @@ G_DEFINE_BOXED_TYPE (GtkTextAttributes, gtk_text_attributes, ...@@ -110,10 +111,10 @@ G_DEFINE_BOXED_TYPE (GtkTextAttributes, gtk_text_attributes,
* gtk_text_attributes_copy_values: * gtk_text_attributes_copy_values:
* @src: a #GtkTextAttributes * @src: a #GtkTextAttributes
* @dest: another #GtkTextAttributes * @dest: another #GtkTextAttributes
* *
* Copies the values from @src to @dest so that @dest has the same values * Copies the values from @src to @dest so that @dest has
* as @src. Frees existing values in @dest. * the same values as @src. Frees existing values in @dest.
**/ */
void void
gtk_text_attributes_copy_values (GtkTextAttributes *src, gtk_text_attributes_copy_values (GtkTextAttributes *src,
GtkTextAttributes *dest) GtkTextAttributes *dest)
...@@ -124,10 +125,24 @@ gtk_text_attributes_copy_values (GtkTextAttributes *src, ...@@ -124,10 +125,24 @@ gtk_text_attributes_copy_values (GtkTextAttributes *src,
return; return;
/* Remove refs */ /* Remove refs */
if (dest->tabs)
pango_tab_array_free (dest->tabs);
if (dest->font) if (dest->font)
pango_font_description_free (dest->font); pango_font_description_free (dest->font);
if (dest->pg_bg_color)
gdk_color_free (dest->pg_bg_color);
if (dest->pg_bg_rgba)
gdk_rgba_free (dest->pg_bg_rgba);
if (dest->appearance.rgba[0])
gdk_rgba_free (dest->appearance.rgba[0]);
if (dest->appearance.rgba[1])
gdk_rgba_free (dest->appearance.rgba[1]);
/* Copy */ /* Copy */
orig_refcount = dest->refcount; orig_refcount = dest->refcount;
...@@ -138,12 +153,21 @@ gtk_text_attributes_copy_values (GtkTextAttributes *src, ...@@ -138,12 +153,21 @@ gtk_text_attributes_copy_values (GtkTextAttributes *src,
dest->language = src->language; dest->language = src->language;
if (dest->font) if (src->font)
dest->font = pango_font_description_copy (src->font); dest->font = pango_font_description_copy (src->font);
if (src->pg_bg_color) if (src->pg_bg_color)
dest->pg_bg_color = gdk_color_copy (src->pg_bg_color); dest->pg_bg_color = gdk_color_copy (src->pg_bg_color);
if (src->pg_bg_rgba)
dest->pg_bg_rgba = gdk_rgba_copy (src->pg_bg_rgba);
if (src->appearance.rgba[0])
dest->appearance.rgba[0] = gdk_rgba_copy (src->appearance.rgba[0]);
if (src->appearance.rgba[1])
dest->appearance.rgba[1] = gdk_rgba_copy (src->appearance.rgba[1]);
dest->refcount = orig_refcount; dest->refcount = orig_refcount;
} }
...@@ -191,7 +215,16 @@ gtk_text_attributes_unref (GtkTextAttributes *values) ...@@ -191,7 +215,16 @@ gtk_text_attributes_unref (GtkTextAttributes *values)
if (values->pg_bg_color) if (values->pg_bg_color)
gdk_color_free (values->pg_bg_color); gdk_color_free (values->pg_bg_color);
g_free (values); if (values->pg_bg_rgba)
gdk_rgba_free (values->pg_bg_rgba);
if (values->appearance.rgba[0])
gdk_rgba_free (values->appearance.rgba[0]);
if (values->appearance.rgba[1])
gdk_rgba_free (values->appearance.rgba[1]);
g_slice_free (GtkTextAttributes, values);
} }
} }
...@@ -216,16 +249,41 @@ _gtk_text_attributes_fill_from_tags (GtkTextAttributes *dest, ...@@ -216,16 +249,41 @@ _gtk_text_attributes_fill_from_tags (GtkTextAttributes *dest,
if (tag->priv->bg_color_set) if (tag->priv->bg_color_set)
{ {
dest->appearance.bg_color = vals->appearance.bg_color; if (dest->appearance.rgba[0])
{
gdk_rgba_free (dest->appearance.rgba[0]);
dest->appearance.rgba[0] = NULL;
}
if (vals->appearance.rgba[0])
dest->appearance.rgba[0] = gdk_rgba_copy (vals->appearance.rgba[0]);
dest->appearance.draw_bg = TRUE; dest->appearance.draw_bg = TRUE;
} }
if (tag->priv->fg_color_set) if (tag->priv->fg_color_set)
dest->appearance.fg_color = vals->appearance.fg_color; {
if (dest->appearance.rgba[1])
{
gdk_rgba_free (dest->appearance.rgba[1]);
dest->appearance.rgba[1] = NULL;
}
if (vals->appearance.rgba[1])
dest->appearance.rgba[1] = gdk_rgba_copy (vals->appearance.rgba[1]);
}
if (tag->priv->pg_bg_color_set) if (tag->priv->pg_bg_color_set)
{ {
dest->pg_bg_color = gdk_color_copy (vals->pg_bg_color); if (dest->pg_bg_rgba)
{
gdk_rgba_free (dest->pg_bg_rgba);
dest->pg_bg_rgba = NULL;
}
if (vals->pg_bg_rgba)
dest->pg_bg_rgba = gdk_rgba_copy (vals->pg_bg_rgba);
} }
if (vals->font) if (vals->font)
......
...@@ -102,8 +102,12 @@ struct _GtkTextAppearance ...@@ -102,8 +102,12 @@ struct _GtkTextAppearance
guint inside_selection : 1; guint inside_selection : 1;
guint is_text : 1; guint is_text : 1;
/*< private >*/ GdkRGBA *rgba[2];
guint padding[4];
#if __SIZEOF_INT__ == __SIZEOF_POINTER__
/* unusable, just for ABI compat */
guint padding[2];
#endif
}; };
struct _GtkTextAttributes struct _GtkTextAttributes
...@@ -155,7 +159,9 @@ struct _GtkTextAttributes ...@@ -155,7 +159,9 @@ struct _GtkTextAttributes
guint editable : 1; guint editable : 1;
/*< private >*/ /*< private >*/
guint padding[4]; GdkRGBA *pg_bg_rgba;
guint padding[3];
}; };
GtkTextAttributes* gtk_text_attributes_new (void); GtkTextAttributes* gtk_text_attributes_new (void);
......
...@@ -110,8 +110,11 @@ struct _GtkTextRenderer ...@@ -110,8 +110,11 @@ struct _GtkTextRenderer
GdkColor *error_color; /* Error underline color for this widget */ GdkColor *error_color; /* Error underline color for this widget */
GList *widgets; /* widgets encountered when drawing */ GList *widgets; /* widgets encountered when drawing */
int state; GdkRGBA rgba[4];
guint8 rgba_set[4];
guint state : 2;
}; };
struct _GtkTextRendererClass struct _GtkTextRendererClass
...@@ -121,46 +124,35 @@ struct _GtkTextRendererClass ...@@ -121,46 +124,35 @@ struct _GtkTextRendererClass
G_DEFINE_TYPE (GtkTextRenderer, _gtk_text_renderer, PANGO_TYPE_RENDERER) G_DEFINE_TYPE (GtkTextRenderer, _gtk_text_renderer, PANGO_TYPE_RENDERER)
static void
text_renderer_set_gdk_color (GtkTextRenderer *text_renderer,
PangoRenderPart part,
GdkColor *gdk_color)
{
PangoRenderer *renderer = PANGO_RENDERER (text_renderer);
if (gdk_color)
{
PangoColor color;
color.red = gdk_color->red;
color.green = gdk_color->green;
color.blue = gdk_color->blue;
pango_renderer_set_color (renderer, part, &color);
}
else
pango_renderer_set_color (renderer, part, NULL);
}
static void static void
text_renderer_set_rgba (GtkTextRenderer *text_renderer, text_renderer_set_rgba (GtkTextRenderer *text_renderer,
PangoRenderPart part, PangoRenderPart part,
GdkRGBA *rgba) const GdkRGBA *rgba)
{ {
PangoRenderer *renderer = PANGO_RENDERER (text_renderer); PangoRenderer *renderer = PANGO_RENDERER (text_renderer);
PangoColor dummy = { 0, };
if ((!rgba && !text_renderer->rgba_set[part]) ||
(rgba && text_renderer->rgba_set[part] &&
text_renderer->rgba[part].red == rgba->red &&
text_renderer->rgba[part].green == rgba->green &&
text_renderer->rgba[part].blue == rgba->blue &&
text_renderer->rgba[part].alpha == rgba->alpha))
return;
if (rgba) if (rgba)
{ {
PangoColor color; text_renderer->rgba_set[part] = TRUE;
text_renderer->rgba[part] = *rgba;
color.red = CLAMP (rgba->red * 65535. + 0.5, 0, 65535); pango_renderer_set_color (renderer, part, &dummy);
color.green = CLAMP (rgba->green * 65535. + 0.5, 0, 65535);
color.blue = CLAMP (rgba->blue * 65535. + 0.5, 0, 65535);
pango_renderer_set_color (renderer, part, &color);
} }
else else
pango_renderer_set_color (renderer, part, NULL); {
text_renderer->rgba_set[part] = FALSE;
pango_renderer_set_color (renderer, part, NULL);
}
} }
static GtkTextAppearance * static GtkTextAppearance *
...@@ -188,9 +180,8 @@ gtk_text_renderer_prepare_run (PangoRenderer *renderer, ...@@ -188,9 +180,8 @@ gtk_text_renderer_prepare_run (PangoRenderer *renderer,
GtkStyleContext *context; GtkStyleContext *context;
GtkStateFlags state; GtkStateFlags state;
GtkTextRenderer *text_renderer = GTK_TEXT_RENDERER (renderer); GtkTextRenderer *text_renderer = GTK_TEXT_RENDERER (renderer);
GdkColor *bg_color = NULL; GdkRGBA *bg_rgba = NULL;
GdkRGBA *fg_rgba = NULL; GdkRGBA *fg_rgba = NULL;
GdkColor *fg_color = NULL;
GtkTextAppearance *appearance; GtkTextAppearance *appearance;
PANGO_RENDERER_CLASS (_gtk_text_renderer_parent_class)->prepare_run (renderer, run); PANGO_RENDERER_CLASS (_gtk_text_renderer_parent_class)->prepare_run (renderer, run);
...@@ -199,15 +190,14 @@ gtk_text_renderer_prepare_run (PangoRenderer *renderer, ...@@ -199,15 +190,14 @@ gtk_text_renderer_prepare_run (PangoRenderer *renderer,
g_assert (appearance != NULL); g_assert (appearance != NULL);
context = gtk_widget_get_style_context (text_renderer->widget); context = gtk_widget_get_style_context (text_renderer->widget);
state = gtk_widget_get_state_flags (text_renderer->widget);
state = gtk_widget_get_state_flags (text_renderer->widget);
if (appearance->draw_bg && text_renderer->state == NORMAL) if (appearance->draw_bg && text_renderer->state == NORMAL)
bg_color = &appearance->bg_color; bg_rgba = appearance->rgba[0];
else else
bg_color = NULL; bg_rgba = NULL;
text_renderer_set_gdk_color (text_renderer, PANGO_RENDER_PART_BACKGROUND, bg_color); text_renderer_set_rgba (text_renderer, PANGO_RENDER_PART_BACKGROUND, bg_rgba);
if (text_renderer->state == SELECTED) if (text_renderer->state == SELECTED)
{ {
...@@ -224,18 +214,10 @@ gtk_text_renderer_prepare_run (PangoRenderer *renderer, ...@@ -224,18 +214,10 @@ gtk_text_renderer_prepare_run (PangoRenderer *renderer,
NULL); NULL);
} }
else else
fg_color = &appearance->fg_color; fg_rgba = appearance->rgba[1];
if (fg_rgba) text_renderer_set_rgba (text_renderer, PANGO_RENDER_PART_FOREGROUND, fg_rgba);
{ text_renderer_set_rgba (text_renderer, PANGO_RENDER_PART_STRIKETHROUGH,fg_rgba);
text_renderer_set_rgba (text_renderer, PANGO_RENDER_PART_FOREGROUND, fg_rgba);
text_renderer_set_rgba (text_renderer, PANGO_RENDER_PART_STRIKETHROUGH,fg_rgba);
}
else
{
text_renderer_set_gdk_color (text_renderer, PANGO_RENDER_PART_FOREGROUND, fg_color);
text_renderer_set_gdk_color (text_renderer, PANGO_RENDER_PART_STRIKETHROUGH, fg_color);
}
if (appearance->underline == PANGO_UNDERLINE_ERROR) if (appearance->underline == PANGO_UNDERLINE_ERROR)
{ {
...@@ -252,28 +234,24 @@ gtk_text_renderer_prepare_run (PangoRenderer *renderer, ...@@ -252,28 +234,24 @@ gtk_text_renderer_prepare_run (PangoRenderer *renderer,
} }
} }
text_renderer_set_gdk_color (text_renderer, PANGO_RENDER_PART_UNDERLINE, text_renderer->error_color); // XXX Transform the gdk color to an gdk rgba here
//text_renderer_set_gdk_color (text_renderer, PANGO_RENDER_PART_UNDERLINE, text_renderer->error_color);
} }
else if (fg_rgba)
text_renderer_set_rgba (text_renderer, PANGO_RENDER_PART_UNDERLINE, fg_rgba);
else else
text_renderer_set_gdk_color (text_renderer, PANGO_RENDER_PART_UNDERLINE, fg_color); text_renderer_set_rgba (text_renderer, PANGO_RENDER_PART_UNDERLINE, fg_rgba);
if (fg_rgba != appearance->rgba[1])
gdk_rgba_free (fg_rgba);
} }
static void static void
set_color (GtkTextRenderer *text_renderer, set_color (GtkTextRenderer *text_renderer,
PangoRenderPart part) PangoRenderPart part)
{ {
PangoColor *color;
cairo_save (text_renderer->cr); cairo_save (text_renderer->cr);
color = pango_renderer_get_color (PANGO_RENDERER (text_renderer), part); if (text_renderer->rgba_set[part])
if (color) gdk_cairo_set_source_rgba (text_renderer->cr, &text_renderer->rgba[part]);
cairo_set_source_rgb (text_renderer->cr,
color->red / 65535.,
color->green / 65535.,
color->blue / 65535.);
} }
static void static void
......
...@@ -1424,9 +1424,27 @@ gtk_text_attr_appearance_destroy (PangoAttribute *attr) ...@@ -1424,9 +1424,27 @@ gtk_text_attr_appearance_destroy (PangoAttribute *attr)
{ {
GtkTextAttrAppearance *appearance_attr = (GtkTextAttrAppearance *)attr; GtkTextAttrAppearance *appearance_attr = (GtkTextAttrAppearance *)attr;
if (appearance_attr->appearance.rgba[0])
gdk_rgba_free (appearance_attr->appearance.rgba[0]);
if (appearance_attr->appearance.rgba[1])
gdk_rgba_free (appearance_attr->appearance.rgba[1]);
g_slice_free (GtkTextAttrAppearance, appearance_attr); g_slice_free (GtkTextAttrAppearance, appearance_attr);
} }
static gboolean
rgba_equal (const GdkRGBA *rgba1, const GdkRGBA *rgba2)
{
if (rgba1 && rgba2)
return gdk_rgba_equal (rgba1, rgba2);
if (rgba1 || rgba2)
return FALSE;
return TRUE;
}
static gboolean static gboolean
gtk_text_attr_appearance_compare (const PangoAttribute *attr1, gtk_text_attr_appearance_compare (const PangoAttribute *attr1,
const PangoAttribute *attr2) const PangoAttribute *attr2)
...@@ -1434,8 +1452,8 @@ gtk_text_attr_appearance_compare (const PangoAttribute *attr1, ...@@ -1434,8 +1452,8 @@ gtk_text_attr_appearance_compare (const PangoAttribute *attr1,
const GtkTextAppearance *appearance1 = &((const GtkTextAttrAppearance *)attr1)->appearance; const GtkTextAppearance *appearance1 = &((const GtkTextAttrAppearance *)attr1)->appearance;
const GtkTextAppearance *appearance2 = &((const GtkTextAttrAppearance *)attr2)->appearance; const GtkTextAppearance *appearance2 = &((const GtkTextAttrAppearance *)attr2)->appearance;
return (gdk_color_equal (&appearance1->fg_color, &appearance2->fg_color) && return (rgba_equal (appearance1->rgba[0], appearance2->rgba[0]) &&
gdk_color_equal (&appearance1->bg_color, &appearance2->bg_color) && rgba_equal (appearance1->rgba[1], appearance2->rgba[1]) &&
appearance1->underline == appearance2->underline && appearance1->underline == appearance2->underline &&
appearance1->strikethrough == appearance2->strikethrough && appearance1->strikethrough == appearance2->strikethrough &&
appearance1->draw_bg == appearance2->draw_bg); appearance1->draw_bg == appearance2->draw_bg);
...@@ -1472,6 +1490,12 @@ gtk_text_attr_appearance_new (const GtkTextAppearance *appearance) ...@@ -1472,6 +1490,12 @@ gtk_text_attr_appearance_new (const GtkTextAppearance *appearance)
result->appearance = *appearance; result->appearance = *appearance;
if (appearance->rgba[0])
result->appearance.rgba[0] = gdk_rgba_copy (appearance->rgba[0]);
if (appearance->rgba[1])
result->appearance.rgba[1] = gdk_rgba_copy (appearance->rgba[1]);
return (PangoAttribute *)result; return (PangoAttribute *)result;
} }
......
...@@ -233,6 +233,7 @@ struct _GtkTextCursorDisplay ...@@ -233,6 +233,7 @@ struct _GtkTextCursorDisplay
guint is_strong : 1; guint is_strong : 1;
guint is_weak : 1; guint is_weak : 1;
}; };
struct _GtkTextLineDisplay struct _GtkTextLineDisplay
{ {
PangoLayout *layout; PangoLayout *layout;
......
...@@ -92,6 +92,8 @@ enum { ...@@ -92,6 +92,8 @@ enum {
PROP_FOREGROUND, PROP_FOREGROUND,
PROP_BACKGROUND_GDK, PROP_BACKGROUND_GDK,
PROP_FOREGROUND_GDK, PROP_FOREGROUND_GDK,
PROP_BACKGROUND_RGBA,
PROP_FOREGROUND_RGBA,
PROP_FONT, PROP_FONT,
PROP_FONT_DESC, PROP_FONT_DESC,
PROP_FAMILY, PROP_FAMILY,
...@@ -121,6 +123,7 @@ enum { ...@@ -121,6 +123,7 @@ enum {
PROP_INVISIBLE, PROP_INVISIBLE,
PROP_PARAGRAPH_BACKGROUND, PROP_PARAGRAPH_BACKGROUND,
PROP_PARAGRAPH_BACKGROUND_GDK, PROP_PARAGRAPH_BACKGROUND_GDK,
PROP_PARAGRAPH_BACKGROUND_RGBA,
/* Behavior args */ /* Behavior args */
PROP_ACCUMULATIVE_MARGIN, PROP_ACCUMULATIVE_MARGIN,
...@@ -206,6 +209,15 @@ gtk_text_tag_class_init (GtkTextTagClass *klass) ...@@ -206,6 +209,15 @@ gtk_text_tag_class_init (GtkTextTagClass *klass)
GDK_TYPE_COLOR, GDK_TYPE_COLOR,
GTK_PARAM_READWRITE)); GTK_PARAM_READWRITE));
g_object_class_install_property (object_class,
PROP_BACKGROUND_RGBA,
g_param_spec_boxed ("background-rgba",
P_("Background rgba"),
P_("Background rgba as a (possibly unallocated) GdkRGBA"),
GDK_TYPE_RGBA,
GTK_PARAM_READWRITE));
g_object_class_install_property (object_class, g_object_class_install_property (object_class,
PROP_BACKGROUND_FULL_HEIGHT, PROP_BACKGROUND_FULL_HEIGHT,
g_param_spec_boolean ("background-full-height", g_param_spec_boolean ("background-full-height",
...@@ -230,6 +242,14 @@ gtk_text_tag_class_init (GtkTextTagClass *klass) ...@@ -230,6 +242,14 @@ gtk_text_tag_class_init (GtkTextTagClass *klass)
GDK_TYPE_COLOR, GDK_TYPE_COLOR,
GTK_PARAM_READWRITE)); GTK_PARAM_READWRITE));
g_object_class_install_property (object_class,
PROP_FOREGROUND_RGBA,
g_param_spec_boxed ("foreground-rgba",
P_("Foreground rgba"),
P_("Foreground rgba as a (possibly unallocated) GdkRGBA"),
GDK_TYPE_RGBA,
GTK_PARAM_READWRITE));
g_object_class_install_property (object_class, g_object_class_install_property (object_class,
PROP_DIRECTION, PROP_DIRECTION,
g_param_spec_enum ("direction", g_param_spec_enum ("direction",
...@@ -531,6 +551,22 @@ gtk_text_tag_class_init (GtkTextTagClass *klass) ...@@ -531,6 +551,22 @@ gtk_text_tag_class_init (GtkTextTagClass *klass)
GDK_TYPE_COLOR, GDK_TYPE_COLOR,
GTK_PARAM_READWRITE)); GTK_PARAM_READWRITE));
/**
* GtkTextTag:paragraph-background-rgba:
*
* The paragraph background color as a as a (possibly unallocated)
* #GdkRGBA.
*
* Since: 3.2
*/
g_object_class_install_property (object_class,
PROP_PARAGRAPH_BACKGROUND_RGBA,
g_param_spec_boxed ("paragraph-background-rgba",
P_("Paragraph background rgba"),
P_("Paragraph background rgba as a (possibly unallocated) GdkRGBA"),
GDK_TYPE_RGBA,
GTK_PARAM_READWRITE));
/** /**
* GtkTextTag:accumulative-margin: * GtkTextTag:accumulative-margin:
* *
...@@ -740,11 +776,16 @@ gtk_text_tag_finalize (GObject *object) ...@@ -740,11 +776,16 @@ gtk_text_tag_finalize (GObject *object)
} }
static void static void
set_bg_color (GtkTextTag *tag, GdkColor *color) set_bg_rgba (GtkTextTag *tag, GdkRGBA *rgba)
{ {
GtkTextTagPrivate *priv = tag->priv; GtkTextTagPrivate *priv = tag->priv;
if (color) if (priv->values->appearance.rgba[0])
gdk_rgba_free (priv->values->appearance.rgba[0]);
priv->values->appearance.rgba[0] = NULL;
if (rgba)
{ {
if (!priv->bg_color_set) if (!priv->bg_color_set)
{ {
...@@ -752,7 +793,7 @@ set_bg_color (GtkTextTag *tag, GdkColor *color) ...@@ -752,7 +793,7 @@ set_bg_color (GtkTextTag *tag, GdkColor *color)
g_object_notify (G_OBJECT (tag), "background-set"); g_object_notify (G_OBJECT (tag), "background-set");
} }
priv->values->appearance.bg_color = *color; priv->values->appearance.rgba[0] = gdk_rgba_copy (rgba);
} }
else else
{ {
...@@ -765,18 +806,24 @@ set_bg_color (GtkTextTag *tag, GdkColor *color) ...@@ -765,18 +806,24 @@ set_bg_color (GtkTextTag *tag, GdkColor *color)
} }
static void static void
set_fg_color (GtkTextTag *tag, GdkColor *color) set_fg_rgba (GtkTextTag *tag, GdkRGBA *rgba)
{ {
GtkTextTagPrivate *priv = tag->priv; GtkTextTagPrivate *priv = tag->priv;
if (color) if (priv->values->appearance.rgba[1])
gdk_rgba_free (priv->values->appearance.rgba[1]);
priv->values->appearance.rgba[1] = NULL;
if (rgba)
{ {
if (!priv->fg_color_set) if (!priv->fg_color_set)
{ {
priv->fg_color_set = TRUE; priv->fg_color_set = TRUE;
g_object_notify (G_OBJECT (tag), "foreground-set"); g_object_notify (G_OBJECT (tag), "foreground-set");
} }
priv->values->appearance.fg_color = *color;
priv->values->appearance.rgba[1] = gdk_rgba_copy (rgba);
} }
else else
{ {
...@@ -789,21 +836,24 @@ set_fg_color (GtkTextTag *tag, GdkColor *color) ...@@ -789,21 +836,24 @@ set_fg_color (GtkTextTag *tag, GdkColor *color)
} }
static void static void
set_pg_bg_color (GtkTextTag *tag, GdkColor *color) set_pg_bg_rgba (GtkTextTag *tag, GdkRGBA *rgba)
{ {
GtkTextTagPrivate *priv = tag->priv; GtkTextTagPrivate *priv = tag->priv;
if (color) if (priv->values->pg_bg_rgba)
gdk_rgba_free (priv->values->pg_bg_rgba);
priv->values->pg_bg_rgba = NULL;
if (rgba)
{ {
if (!priv->pg_bg_color_set) if (!priv->pg_bg_color_set)
{ {
priv->pg_bg_color_set = TRUE; priv->pg_bg_color_set = TRUE;