diff options
author | Matthias Clasen <mclasen@redhat.com> | 2021-11-23 11:42:55 -0500 |
---|---|---|
committer | Matthias Clasen <mclasen@redhat.com> | 2021-11-24 19:57:58 -0500 |
commit | 2b013d4114cdca3581c0fd5eba1238e9eb890f8d (patch) | |
tree | 4102c22e1d1d81d737e1456c75152657fb65dc7a | |
parent | 9a63774e6f6bdc262da09088aa9075330798f18a (diff) | |
download | pango-2b013d4114cdca3581c0fd5eba1238e9eb890f8d.tar.gz |
serializer: Support a "comment" field
Json doesn't have comments, so we have to add
an explicit comment value. This will be useful
to describe what test cases are about.
-rw-r--r-- | pango/serializer.c | 47 |
1 files changed, 47 insertions, 0 deletions
diff --git a/pango/serializer.c b/pango/serializer.c index 855fafea..a4383aed 100644 --- a/pango/serializer.c +++ b/pango/serializer.c @@ -661,6 +661,7 @@ layout_to_json (PangoLayout *layout, { JsonBuilder *builder; JsonNode *root; + const char *str; builder = json_builder_new_immutable (); @@ -672,6 +673,25 @@ layout_to_json (PangoLayout *layout, add_context (builder, layout->context); } + str = (const char *) g_object_get_data (G_OBJECT (layout), "comment"); + if (str) + { + json_builder_set_member_name (builder, "comment"); + if (strstr (str, "\n") != NULL) + { + char **strs = g_strsplit (str, "\n", -1); + + json_builder_begin_array (builder); + for (int i = 0; strs[i]; i++) + json_builder_add_string_value (builder, strs[i]); + json_builder_end_array (builder); + + g_strfreev (strs); + } + else + json_builder_add_string_value (builder, str); + } + json_builder_set_member_name (builder, "text"); json_builder_add_string_value (builder, layout->text); @@ -1244,6 +1264,33 @@ json_to_layout (PangoContext *context, layout = pango_layout_new (context); + if (json_reader_read_member (reader, "comment")) + { + if (json_reader_is_array (reader)) + { + GString *s; + + s = g_string_new (""); + for (int i = 0; i < json_reader_count_elements (reader); i++) + { + json_reader_read_element (reader, i); + if (s->len > 0) + g_string_append_c (s, '\n'); + g_string_append (s, json_reader_get_string_value (reader)); + json_reader_end_element (reader); + } + + g_object_set_data_full (G_OBJECT (layout), "comment", + g_string_free (s, FALSE), + g_free); + } + else + g_object_set_data_full (G_OBJECT (layout), "comment", + g_strdup (json_reader_get_string_value (reader)), + g_free); + } + json_reader_end_member (reader); + if (json_reader_read_member (reader, "text")) pango_layout_set_text (layout, json_reader_get_string_value (reader), -1); json_reader_end_member (reader); |