[gtk/matthiasc/for-master: 2/2] tests: Rewrite PangoAttribute introspection
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/matthiasc/for-master: 2/2] tests: Rewrite PangoAttribute introspection
- Date: Tue, 24 Aug 2021 16:54:28 +0000 (UTC)
commit 03ed585f6f94e99f2e4b9a7f8c491e5ce9717002
Author: Matthias Clasen <mclasen redhat com>
Date: Tue Aug 24 12:47:41 2021 -0400
tests: Rewrite PangoAttribute introspection
We can use the new binding helpers to make this
a little less bothersome. That way, it will need
tweaks less often (only when new fundamental types
are introduced).
testsuite/gtk/label.c | 91 +++++++++++++++++----------------------------------
1 file changed, 30 insertions(+), 61 deletions(-)
---
diff --git a/testsuite/gtk/label.c b/testsuite/gtk/label.c
index d03a03a6da..fa0687cf49 100644
--- a/testsuite/gtk/label.c
+++ b/testsuite/gtk/label.c
@@ -5,6 +5,13 @@ print_attribute (PangoAttribute *attr, GString *string)
{
GEnumClass *class;
GEnumValue *value;
+ PangoAttrString *str;
+ PangoAttrLanguage *lang;
+ PangoAttrInt *integer;
+ PangoAttrFloat *flt;
+ PangoAttrFontDesc *font;
+ PangoAttrColor *color;
+ PangoAttrShape *shape;
g_string_append_printf (string, "[%d,%d]", attr->start_index, attr->end_index);
@@ -13,73 +20,35 @@ print_attribute (PangoAttribute *attr, GString *string)
g_string_append_printf (string, "%s=", value->value_nick);
g_type_class_unref (class);
- switch (attr->klass->type)
+ if ((str = pango_attribute_as_string (attr)) != NULL)
+ g_string_append (string, str->value);
+ else if ((lang = pango_attribute_as_language (attr)) != NULL)
+ g_string_append (string, pango_language_to_string (lang->value));
+ else if ((integer = pango_attribute_as_int (attr)) != NULL)
+ g_string_append_printf (string, "%d", integer->value);
+ else if ((flt = pango_attribute_as_float (attr)) != NULL)
{
- case PANGO_ATTR_LANGUAGE:
- g_string_append (string, pango_language_to_string (((PangoAttrLanguage *)attr)->value));
- break;
- case PANGO_ATTR_FAMILY:
- case PANGO_ATTR_FONT_FEATURES:
- g_string_append (string, ((PangoAttrString *)attr)->value);
- break;
- case PANGO_ATTR_STYLE:
- case PANGO_ATTR_WEIGHT:
- case PANGO_ATTR_VARIANT:
- case PANGO_ATTR_STRETCH:
- case PANGO_ATTR_SIZE:
- case PANGO_ATTR_ABSOLUTE_SIZE:
- case PANGO_ATTR_UNDERLINE:
- case PANGO_ATTR_OVERLINE:
- case PANGO_ATTR_STRIKETHROUGH:
- case PANGO_ATTR_RISE:
- case PANGO_ATTR_FALLBACK:
- case PANGO_ATTR_LETTER_SPACING:
- case PANGO_ATTR_GRAVITY:
- case PANGO_ATTR_GRAVITY_HINT:
- case PANGO_ATTR_FOREGROUND_ALPHA:
- case PANGO_ATTR_BACKGROUND_ALPHA:
- case PANGO_ATTR_ALLOW_BREAKS:
- case PANGO_ATTR_INSERT_HYPHENS:
- case PANGO_ATTR_SHOW:
- case PANGO_ATTR_ABSOLUTE_LINE_HEIGHT:
- case PANGO_ATTR_TEXT_TRANSFORM:
- g_string_append_printf (string, "%d", ((PangoAttrInt *)attr)->value);
- break;
- case PANGO_ATTR_FONT_DESC:
- {
- char *text = pango_font_description_to_string (((PangoAttrFontDesc *)attr)->desc);
- g_string_append (string, text);
- g_free (text);
- }
- break;
- case PANGO_ATTR_FOREGROUND:
- case PANGO_ATTR_BACKGROUND:
- case PANGO_ATTR_UNDERLINE_COLOR:
- case PANGO_ATTR_OVERLINE_COLOR:
- case PANGO_ATTR_STRIKETHROUGH_COLOR:
- {
- char *text = pango_color_to_string (&((PangoAttrColor *)attr)->color);
- g_string_append (string, text);
- g_free (text);
- }
- break;
- case PANGO_ATTR_SHAPE:
- g_string_append_printf (string, "shape");
- break;
- case PANGO_ATTR_SCALE:
- case PANGO_ATTR_LINE_HEIGHT:
- {
char val[20];
- g_ascii_formatd (val, 20, "%f", ((PangoAttrFloat *)attr)->value);
+ g_ascii_formatd (val, 20, "%f", flt->value);
g_string_append (string, val);
}
- break;
- case PANGO_ATTR_INVALID:
- default:
- g_assert_not_reached ();
- break;
+ else if ((font = pango_attribute_as_font_desc (attr)) != NULL)
+ {
+ char *text = pango_font_description_to_string (font->desc);
+ g_string_append (string, text);
+ g_free (text);
+ }
+ else if ((color = pango_attribute_as_color (attr)) != NULL)
+ {
+ char *text = pango_color_to_string (&color->color);
+ g_string_append (string, text);
+ g_free (text);
}
+ else if ((shape = pango_attribute_as_shape (attr)) != NULL)
+ g_string_append_printf (string, "shape");
+ else
+ g_assert_not_reached ();
}
void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]