summaryrefslogtreecommitdiff
path: root/tests/test-common.c
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2021-11-17 05:39:08 +0000
committerMatthias Clasen <mclasen@redhat.com>2021-11-17 05:39:08 +0000
commit1d800b3f743d493b3568ca07cfd43c0399edb783 (patch)
treef6f852586f3ed5de18abd4f56cd0325fa0e3d079 /tests/test-common.c
parent9278c4f0c59b550f9d4ff10219d8e6242baa081f (diff)
parentb892330253904191c47e5319b0ffdc705961b609 (diff)
downloadpango-1d800b3f743d493b3568ca07cfd43c0399edb783.tar.gz
Merge branch 'serialize-attrs-and-tabs' into 'main'
Add pango_attr_list_to/from_string See merge request GNOME/pango!512
Diffstat (limited to 'tests/test-common.c')
-rw-r--r--tests/test-common.c296
1 files changed, 8 insertions, 288 deletions
diff --git a/tests/test-common.c b/tests/test-common.c
index b59ca4a0..3821a450 100644
--- a/tests/test-common.c
+++ b/tests/test-common.c
@@ -104,58 +104,14 @@ file_has_prefix (const char *filename,
void
print_attribute (PangoAttribute *attr, GString *string)
{
- GEnumClass *class;
- GEnumValue *value;
- PangoAttrString *str;
- PangoAttrLanguage *lang;
- PangoAttrInt *integer;
- PangoAttrFloat *flt;
- PangoAttrFontDesc *font;
- PangoAttrColor *color;
- PangoAttrShape *shape;
- PangoAttrSize *size;
- PangoAttrFontFeatures *features;
-
- g_string_append_printf (string, "[%d,%d]", attr->start_index, attr->end_index);
-
- class = g_type_class_ref (pango_attr_type_get_type ());
- value = g_enum_get_value (class, attr->klass->type);
- g_string_append_printf (string, "%s=", value->value_nick);
- g_type_class_unref (class);
-
- 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)
- {
- char val[20];
-
- g_ascii_formatd (val, 20, "%f", flt->value);
- g_string_append (string, val);
- }
- 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 if ((size = pango_attribute_as_size (attr)) != NULL)
- g_string_append_printf (string, "%d", size->size);
- else if ((features = pango_attribute_as_font_features (attr)) != NULL)
- g_string_append_printf (string, "%s", features->features);
- else
- g_assert_not_reached ();
+ PangoAttrList *l = pango_attr_list_new ();
+ char *s;
+
+ pango_attr_list_insert (l, pango_attribute_copy (attr));
+ s = pango_attr_list_to_string (l);
+ g_string_append (string, s);
+ g_free (s);
+ pango_attr_list_unref (l);
}
void
@@ -200,242 +156,6 @@ print_attributes (GSList *attrs, GString *string)
}
}
-G_GNUC_BEGIN_IGNORE_DEPRECATIONS
-
-PangoAttribute *
-attribute_from_string (const char *string)
-{
- const char *s;
- char *p;
- PangoAttribute *attr;
- long long start, end;
- GEnumClass *class;
- int i;
- PangoColor color;
- int val;
-
- s = string;
- g_assert (*s == '[');
-
- s++;
- start = strtoll (s, &p, 10);
- g_assert (p > s);
- g_assert (*p == ',');
- s = p + 1;
-
- g_assert (start >= 0);
-
- end = strtoll (s, &p, 10);
- g_assert (p > s);
- g_assert (*p == ']');
- s = p + 1;
-
- if (end == -1)
- end = G_MAXUINT;
-
- g_assert (start >= 0);
- g_assert (end >= 0);
-
- class = g_type_class_ref (pango_attr_type_get_type ());
-
- for (i = 0; i < class->n_values; i++)
- {
- if (g_str_has_prefix (s, class->values[i].value_nick))
- break;
- }
-
- g_assert (i < class->n_values);
-
- s += strlen (class->values[i].value_nick);
- g_assert (*s == '=');
- s++;
-
- switch (class->values[i].value)
- {
- case PANGO_ATTR_LANGUAGE:
- attr = pango_attr_language_new (pango_language_from_string (s));
- break;
- case PANGO_ATTR_FAMILY:
- attr = pango_attr_family_new (s);
- break;
- case PANGO_ATTR_FONT_FEATURES:
- attr = pango_attr_font_features_new (s);
- break;
- case PANGO_ATTR_STYLE:
- {
- if (!pango_parse_enum (PANGO_TYPE_STYLE, s, &val, FALSE, NULL))
- val = strtol (s, &p, 10);
- attr = pango_attr_style_new (val);
- }
- break;
- case PANGO_ATTR_WEIGHT:
- {
- if (!pango_parse_enum (PANGO_TYPE_WEIGHT, s, &val, FALSE, NULL))
- val = strtol (s, &p, 10);
- attr = pango_attr_weight_new (val);
- }
- break;
- case PANGO_ATTR_VARIANT:
- {
- if (!pango_parse_enum (PANGO_TYPE_VARIANT, s, &val, FALSE, NULL))
- val = strtol (s, &p, 10);
- attr = pango_attr_variant_new (val);
- }
- break;
- case PANGO_ATTR_STRETCH:
- {
- if (!pango_parse_enum (PANGO_TYPE_STRETCH, s, &val, FALSE, NULL))
- val = strtol (s, &p, 10);
- attr = pango_attr_stretch_new (val);
- }
- break;
- case PANGO_ATTR_SIZE:
- attr = pango_attr_size_new (strtol (s, &p, 10));
- break;
- case PANGO_ATTR_ABSOLUTE_SIZE:
- attr = pango_attr_size_new_absolute (strtol (s, &p, 10));
- break;
- case PANGO_ATTR_UNDERLINE:
- {
- if (!pango_parse_enum (PANGO_TYPE_UNDERLINE, s, &val, FALSE, NULL))
- val = strtol (s, &p, 10);
- attr = pango_attr_underline_new (val);
- }
- break;
- case PANGO_ATTR_OVERLINE:
- {
- if (!pango_parse_enum (PANGO_TYPE_OVERLINE, s, &val, FALSE, NULL))
- val = strtol (s, &p, 10);
- attr = pango_attr_overline_new (val);
- }
- break;
- case PANGO_ATTR_STRIKETHROUGH:
- attr = pango_attr_strikethrough_new (strtol (s, &p, 10));
- break;
- case PANGO_ATTR_RISE:
- attr = pango_attr_rise_new (strtol (s, &p, 10));
- break;
- case PANGO_ATTR_FALLBACK:
- attr = pango_attr_fallback_new (strtol (s, &p, 10));
- break;
- case PANGO_ATTR_LETTER_SPACING:
- attr = pango_attr_letter_spacing_new (strtol (s, &p, 10));
- break;
- case PANGO_ATTR_GRAVITY:
- {
- if (!pango_parse_enum (PANGO_TYPE_GRAVITY, s, &val, FALSE, NULL))
- val = strtol (s, &p, 10);
- attr = pango_attr_gravity_new (val);
- }
- break;
- case PANGO_ATTR_GRAVITY_HINT:
- {
- if (!pango_parse_enum (PANGO_TYPE_GRAVITY_HINT, s, &val, FALSE, NULL))
- val = strtol (s, &p, 10);
- attr = pango_attr_gravity_hint_new (val);
- }
- break;
- case PANGO_ATTR_FOREGROUND_ALPHA:
- attr = pango_attr_foreground_alpha_new (strtol (s, &p, 10));
- break;
- case PANGO_ATTR_BACKGROUND_ALPHA:
- attr = pango_attr_background_alpha_new (strtol (s, &p, 10));
- break;
- case PANGO_ATTR_ALLOW_BREAKS:
- attr = pango_attr_allow_breaks_new (strtol (s, &p, 10));
- break;
- case PANGO_ATTR_INSERT_HYPHENS:
- attr = pango_attr_insert_hyphens_new (strtol (s, &p, 10));
- break;
- case PANGO_ATTR_SHOW:
- attr = pango_attr_show_new (strtol (s, &p, 10));
- break;
- case PANGO_ATTR_FONT_DESC:
- {
- PangoFontDescription *desc = pango_font_description_from_string (s);
- attr = pango_attr_font_desc_new (desc);
- pango_font_description_free (desc);
- }
- break;
- case PANGO_ATTR_FOREGROUND:
- {
- pango_color_parse (&color, s);
- attr = pango_attr_foreground_new (color.red, color.green, color.blue);
- }
- break;
- case PANGO_ATTR_BACKGROUND:
- {
- pango_color_parse (&color, s);
- attr = pango_attr_background_new (color.red, color.green, color.blue);
- }
- break;
- case PANGO_ATTR_UNDERLINE_COLOR:
- {
- pango_color_parse (&color, s);
- attr = pango_attr_underline_color_new (color.red, color.green, color.blue);
- }
- break;
- case PANGO_ATTR_OVERLINE_COLOR:
- {
- pango_color_parse (&color, s);
- attr = pango_attr_overline_color_new (color.red, color.green, color.blue);
- }
- break;
- case PANGO_ATTR_STRIKETHROUGH_COLOR:
- {
- pango_color_parse (&color, s);
- attr = pango_attr_strikethrough_color_new (color.red, color.green, color.blue);
- }
- break;
- case PANGO_ATTR_SHAPE:
- {
- PangoRectangle rect = { 0, };
- attr = pango_attr_shape_new (&rect, &rect);
- }
- break;
- case PANGO_ATTR_SCALE:
- attr = pango_attr_scale_new (strtod (s, &p));
- break;
- default:
- g_assert_not_reached ();
- break;
- }
-
- g_type_class_unref (class);
-
- attr->start_index = start;
- attr->end_index = end;
-
- return attr;
-}
-
-G_GNUC_END_IGNORE_DEPRECATIONS
-
-PangoAttrList *
-attributes_from_string (const char *string)
-{
- PangoAttrList *attrs;
- char **lines;
-
- attrs = pango_attr_list_new ();
-
- lines = g_strsplit (string, "\n", 0);
- for (int i = 0; lines[i]; i++)
- {
- PangoAttribute *attr;
-
- if (lines[i][0] == '\0')
- continue;
-
- attr = attribute_from_string (lines[i]);
- g_assert (attr);
- pango_attr_list_insert (attrs, attr);
- }
- g_strfreev (lines);
-
- return attrs;
-}
-
const char *
get_script_name (GUnicodeScript s)
{