Commit 12c4730e authored by Paolo Borelli's avatar Paolo Borelli

Small cleanup in gailtextview code.

Fold gail_misc_add_to_attr_set into the only function calling it, which
avoids a useless big "switch" and results in much less code.

https://bugzilla.gnome.org/show_bug.cgi?id=639030
parent 89c8e2af
......@@ -640,6 +640,16 @@ gail_text_view_get_run_attributes (AtkText *text,
start_offset, end_offset);
}
static AtkAttributeSet*
add_text_attribute (AtkAttributeSet *attrib_set, AtkTextAttribute attr, gint i)
{
const gchar *value;
value = atk_text_attribute_get_value (attr, i);
return gail_misc_add_attribute (attrib_set, i, g_strdup (value));
}
static AtkAttributeSet*
gail_text_view_get_default_attributes (AtkText *text)
{
......@@ -648,6 +658,7 @@ gail_text_view_get_default_attributes (AtkText *text)
GtkTextAttributes *text_attrs;
AtkAttributeSet *attrib_set = NULL;
PangoFontDescription *font;
gchar *value;
widget = gtk_accessible_get_widget (GTK_ACCESSIBLE (text));
if (widget == NULL)
......@@ -661,96 +672,78 @@ gail_text_view_get_default_attributes (AtkText *text)
if (font)
{
attrib_set = gail_misc_add_to_attr_set (attrib_set, text_attrs,
ATK_TEXT_ATTR_STYLE);
attrib_set = gail_misc_add_to_attr_set (attrib_set, text_attrs,
ATK_TEXT_ATTR_VARIANT);
attrib_set = gail_misc_add_to_attr_set (attrib_set, text_attrs,
ATK_TEXT_ATTR_STRETCH);
}
attrib_set = gail_misc_add_to_attr_set (attrib_set, text_attrs,
ATK_TEXT_ATTR_JUSTIFICATION);
attrib_set = gail_misc_add_to_attr_set (attrib_set, text_attrs,
ATK_TEXT_ATTR_DIRECTION);
attrib_set = add_text_attribute (attrib_set, ATK_TEXT_ATTR_STYLE,
pango_font_description_get_style (font));
attrib_set = gail_misc_add_to_attr_set (attrib_set, text_attrs,
ATK_TEXT_ATTR_WRAP_MODE);
attrib_set = add_text_attribute (attrib_set, ATK_TEXT_ATTR_VARIANT,
pango_font_description_get_variant (font));
attrib_set = gail_misc_add_to_attr_set (attrib_set, text_attrs,
ATK_TEXT_ATTR_FG_STIPPLE);
attrib_set = add_text_attribute (attrib_set, ATK_TEXT_ATTR_STRETCH,
pango_font_description_get_stretch (font));
attrib_set = gail_misc_add_to_attr_set (attrib_set, text_attrs,
ATK_TEXT_ATTR_BG_STIPPLE);
value = g_strdup (pango_font_description_get_family (font));
attrib_set = gail_misc_add_attribute (attrib_set, ATK_TEXT_ATTR_FAMILY_NAME, value);
attrib_set = gail_misc_add_to_attr_set (attrib_set, text_attrs,
ATK_TEXT_ATTR_FG_COLOR);
value = g_strdup_printf ("%d", pango_font_description_get_weight (font));
attrib_set = gail_misc_add_attribute (attrib_set, ATK_TEXT_ATTR_WEIGHT, value);
attrib_set = gail_misc_add_to_attr_set (attrib_set, text_attrs,
ATK_TEXT_ATTR_BG_COLOR);
if (font)
{
attrib_set = gail_misc_add_to_attr_set (attrib_set, text_attrs,
ATK_TEXT_ATTR_FAMILY_NAME);
value = g_strdup_printf ("%i", pango_font_description_get_size (font) / PANGO_SCALE);
attrib_set = gail_misc_add_attribute (attrib_set, ATK_TEXT_ATTR_SIZE, value);
}
attrib_set = gail_misc_add_to_attr_set (attrib_set, text_attrs,
ATK_TEXT_ATTR_LANGUAGE);
attrib_set = add_text_attribute (attrib_set, ATK_TEXT_ATTR_JUSTIFICATION, text_attrs->justification);
attrib_set = add_text_attribute (attrib_set, ATK_TEXT_ATTR_DIRECTION, text_attrs->direction);
attrib_set = add_text_attribute (attrib_set, ATK_TEXT_ATTR_WRAP_MODE, text_attrs->wrap_mode);
attrib_set = add_text_attribute (attrib_set, ATK_TEXT_ATTR_EDITABLE, text_attrs->editable);
attrib_set = add_text_attribute (attrib_set, ATK_TEXT_ATTR_INVISIBLE, text_attrs->invisible);
attrib_set = add_text_attribute (attrib_set, ATK_TEXT_ATTR_BG_FULL_HEIGHT, text_attrs->bg_full_height);
if (font)
{
attrib_set = gail_misc_add_to_attr_set (attrib_set, text_attrs,
ATK_TEXT_ATTR_WEIGHT);
}
attrib_set = gail_misc_add_attribute (attrib_set, ATK_TEXT_ATTR_FG_STIPPLE, NULL);
attrib_set = gail_misc_add_attribute (attrib_set, ATK_TEXT_ATTR_BG_STIPPLE, NULL);
attrib_set = gail_misc_add_to_attr_set (attrib_set, text_attrs,
ATK_TEXT_ATTR_SCALE);
attrib_set = add_text_attribute (attrib_set, ATK_TEXT_ATTR_STRIKETHROUGH,
text_attrs->appearance.strikethrough);
attrib_set = add_text_attribute (attrib_set, ATK_TEXT_ATTR_UNDERLINE,
text_attrs->appearance.underline);
if (font)
{
attrib_set = gail_misc_add_to_attr_set (attrib_set, text_attrs,
ATK_TEXT_ATTR_SIZE);
}
value = g_strdup_printf ("%u,%u,%u",
text_attrs->appearance.bg_color.red,
text_attrs->appearance.bg_color.green,
text_attrs->appearance.bg_color.blue);
attrib_set = gail_misc_add_attribute (attrib_set, ATK_TEXT_ATTR_BG_COLOR, value);
attrib_set = gail_misc_add_to_attr_set (attrib_set, text_attrs,
ATK_TEXT_ATTR_STRIKETHROUGH);
value = g_strdup_printf ("%u,%u,%u",
text_attrs->appearance.fg_color.red,
text_attrs->appearance.fg_color.green,
text_attrs->appearance.fg_color.blue);
attrib_set = gail_misc_add_attribute (attrib_set, ATK_TEXT_ATTR_FG_COLOR, value);
attrib_set = gail_misc_add_to_attr_set (attrib_set, text_attrs,
ATK_TEXT_ATTR_UNDERLINE);
value = g_strdup_printf ("%g", text_attrs->font_scale);
attrib_set = gail_misc_add_attribute (attrib_set, ATK_TEXT_ATTR_SCALE, value);
attrib_set = gail_misc_add_to_attr_set (attrib_set, text_attrs,
ATK_TEXT_ATTR_RISE);
value = g_strdup ((gchar *)(text_attrs->language));
attrib_set = gail_misc_add_attribute (attrib_set, ATK_TEXT_ATTR_LANGUAGE, value);
attrib_set = gail_misc_add_to_attr_set (attrib_set, text_attrs,
ATK_TEXT_ATTR_BG_FULL_HEIGHT);
value = g_strdup_printf ("%i", text_attrs->appearance.rise);
attrib_set = gail_misc_add_attribute (attrib_set, ATK_TEXT_ATTR_RISE, value);
attrib_set = gail_misc_add_to_attr_set (attrib_set, text_attrs,
ATK_TEXT_ATTR_PIXELS_INSIDE_WRAP);
value = g_strdup_printf ("%i", text_attrs->pixels_inside_wrap);
attrib_set = gail_misc_add_attribute (attrib_set, ATK_TEXT_ATTR_PIXELS_INSIDE_WRAP, value);
attrib_set = gail_misc_add_to_attr_set (attrib_set, text_attrs,
ATK_TEXT_ATTR_PIXELS_BELOW_LINES);
value = g_strdup_printf ("%i", text_attrs->pixels_below_lines);
attrib_set = gail_misc_add_attribute (attrib_set, ATK_TEXT_ATTR_PIXELS_BELOW_LINES, value);
attrib_set = gail_misc_add_to_attr_set (attrib_set, text_attrs,
ATK_TEXT_ATTR_PIXELS_ABOVE_LINES);
attrib_set = gail_misc_add_to_attr_set (attrib_set, text_attrs,
ATK_TEXT_ATTR_EDITABLE);
attrib_set = gail_misc_add_to_attr_set (attrib_set, text_attrs,
ATK_TEXT_ATTR_INVISIBLE);
value = g_strdup_printf ("%i", text_attrs->pixels_above_lines);
attrib_set = gail_misc_add_attribute (attrib_set, ATK_TEXT_ATTR_PIXELS_ABOVE_LINES, value);
attrib_set = gail_misc_add_to_attr_set (attrib_set, text_attrs,
ATK_TEXT_ATTR_INDENT);
value = g_strdup_printf ("%i", text_attrs->indent);
attrib_set = gail_misc_add_attribute (attrib_set, ATK_TEXT_ATTR_INDENT, value);
attrib_set = gail_misc_add_to_attr_set (attrib_set, text_attrs,
ATK_TEXT_ATTR_RIGHT_MARGIN);
value = g_strdup_printf ("%i", text_attrs->left_margin);
attrib_set = gail_misc_add_attribute (attrib_set, ATK_TEXT_ATTR_LEFT_MARGIN, value);
attrib_set = gail_misc_add_to_attr_set (attrib_set, text_attrs,
ATK_TEXT_ATTR_LEFT_MARGIN);
value = g_strdup_printf ("%i", text_attrs->right_margin);
attrib_set = gail_misc_add_attribute (attrib_set, ATK_TEXT_ATTR_RIGHT_MARGIN, value);
gtk_text_attributes_unref (text_attrs);
return attrib_set;
......
......@@ -560,119 +560,6 @@ gail_misc_get_origins (GtkWidget *widget,
gdk_window_get_origin (window, x_toplevel, y_toplevel);
}
/**
* gail_misc_add_to_attr_set:
* @attrib_set: An #AtkAttributeSet
* @attrs: The #GtkTextAttributes containing the attribute value
* @attr: The #AtkTextAttribute to be added
*
* Gets the value for the AtkTextAttribute from the GtkTextAttributes
* and adds it to the AttributeSet.
*
* Returns: A pointer to the updated #AtkAttributeSet.
**/
AtkAttributeSet*
gail_misc_add_to_attr_set (AtkAttributeSet *attrib_set,
GtkTextAttributes *attrs,
AtkTextAttribute attr)
{
gchar *value;
switch (attr)
{
case ATK_TEXT_ATTR_LEFT_MARGIN:
value = g_strdup_printf ("%i", attrs->left_margin);
break;
case ATK_TEXT_ATTR_RIGHT_MARGIN:
value = g_strdup_printf ("%i", attrs->right_margin);
break;
case ATK_TEXT_ATTR_INDENT:
value = g_strdup_printf ("%i", attrs->indent);
break;
case ATK_TEXT_ATTR_INVISIBLE:
value = g_strdup (atk_text_attribute_get_value (attr, attrs->invisible));
break;
case ATK_TEXT_ATTR_EDITABLE:
value = g_strdup (atk_text_attribute_get_value (attr, attrs->editable));
break;
case ATK_TEXT_ATTR_PIXELS_ABOVE_LINES:
value = g_strdup_printf ("%i", attrs->pixels_above_lines);
break;
case ATK_TEXT_ATTR_PIXELS_BELOW_LINES:
value = g_strdup_printf ("%i", attrs->pixels_below_lines);
break;
case ATK_TEXT_ATTR_PIXELS_INSIDE_WRAP:
value = g_strdup_printf ("%i", attrs->pixels_inside_wrap);
break;
case ATK_TEXT_ATTR_BG_FULL_HEIGHT:
value = g_strdup (atk_text_attribute_get_value (attr, attrs->bg_full_height));
break;
case ATK_TEXT_ATTR_RISE:
value = g_strdup_printf ("%i", attrs->appearance.rise);
break;
case ATK_TEXT_ATTR_UNDERLINE:
value = g_strdup (atk_text_attribute_get_value (attr, attrs->appearance.underline));
break;
case ATK_TEXT_ATTR_STRIKETHROUGH:
value = g_strdup (atk_text_attribute_get_value (attr, attrs->appearance.strikethrough));
break;
case ATK_TEXT_ATTR_SIZE:
value = g_strdup_printf ("%i",
pango_font_description_get_size (attrs->font) / PANGO_SCALE);
break;
case ATK_TEXT_ATTR_SCALE:
value = g_strdup_printf ("%g", attrs->font_scale);
break;
case ATK_TEXT_ATTR_WEIGHT:
value = g_strdup_printf ("%d",
pango_font_description_get_weight (attrs->font));
break;
case ATK_TEXT_ATTR_LANGUAGE:
value = g_strdup ((gchar *)(attrs->language));
break;
case ATK_TEXT_ATTR_FAMILY_NAME:
value = g_strdup (pango_font_description_get_family (attrs->font));
break;
case ATK_TEXT_ATTR_BG_COLOR:
value = g_strdup_printf ("%u,%u,%u",
attrs->appearance.bg_color.red,
attrs->appearance.bg_color.green,
attrs->appearance.bg_color.blue);
break;
case ATK_TEXT_ATTR_FG_COLOR:
value = g_strdup_printf ("%u,%u,%u",
attrs->appearance.fg_color.red,
attrs->appearance.fg_color.green,
attrs->appearance.fg_color.blue);
break;
case ATK_TEXT_ATTR_WRAP_MODE:
value = g_strdup (atk_text_attribute_get_value (attr, attrs->wrap_mode));
break;
case ATK_TEXT_ATTR_DIRECTION:
value = g_strdup (atk_text_attribute_get_value (attr, attrs->direction));
break;
case ATK_TEXT_ATTR_JUSTIFICATION:
value = g_strdup (atk_text_attribute_get_value (attr, attrs->justification));
break;
case ATK_TEXT_ATTR_STRETCH:
value = g_strdup (atk_text_attribute_get_value (attr,
pango_font_description_get_stretch (attrs->font)));
break;
case ATK_TEXT_ATTR_VARIANT:
value = g_strdup (atk_text_attribute_get_value (attr,
pango_font_description_get_variant (attrs->font)));
break;
case ATK_TEXT_ATTR_STYLE:
value = g_strdup (atk_text_attribute_get_value (attr,
pango_font_description_get_style (attrs->font)));
break;
default:
value = NULL;
break;
}
return gail_misc_add_attribute (attrib_set, attr, value);
}
/**
* gail_misc_buffer_get_run_attributes:
* @buffer: The #GtkTextBuffer for which the attributes will be obtained
......
......@@ -67,10 +67,6 @@ void gail_misc_get_origins (GtkWidget *widget,
gint *x_toplevel,
gint *y_toplevel);
AtkAttributeSet* gail_misc_add_to_attr_set (AtkAttributeSet *attrib_set,
GtkTextAttributes *attrs,
AtkTextAttribute attr);
AtkAttributeSet* gail_misc_buffer_get_run_attributes
(GtkTextBuffer *buffer,
gint offset,
......
EXPORTS
gail_misc_add_attribute
gail_misc_add_to_attr_set
gail_misc_buffer_get_run_attributes
gail_misc_get_default_attributes
gail_misc_get_extents_from_pango_rectangle
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment