diff options
author | Matthias Clasen <mclasen@redhat.com> | 2021-11-22 10:57:33 -0500 |
---|---|---|
committer | Matthias Clasen <mclasen@redhat.com> | 2021-11-24 19:57:58 -0500 |
commit | 4d296ae799efb452f1b2a5e767ba2bf315ff883c (patch) | |
tree | 9d46d9bf90fa33d678a99ae3a9904db4785fb964 /pango/serializer.c | |
parent | b9ed027ed762f5ee384defcf4cfa5bc6c9279968 (diff) | |
download | pango-4d296ae799efb452f1b2a5e767ba2bf315ff883c.tar.gz |
serializer: Cosmetics
Avoid writing out empty attributes or tabs.
Diffstat (limited to 'pango/serializer.c')
-rw-r--r-- | pango/serializer.c | 27 |
1 files changed, 16 insertions, 11 deletions
diff --git a/pango/serializer.c b/pango/serializer.c index ca92eb21..62addc36 100644 --- a/pango/serializer.c +++ b/pango/serializer.c @@ -178,9 +178,17 @@ add_attr_list (JsonBuilder *builder, { GSList *attributes, *l; - json_builder_begin_array (builder); + if (!attrs) + return; attributes = pango_attr_list_get_attributes (attrs); + + if (!attributes) + return; + + json_builder_set_member_name (builder, "attributes"); + json_builder_begin_array (builder); + for (l = attributes; l; l = l->next) { PangoAttribute *attr = l->data; @@ -195,6 +203,11 @@ static void add_tab_array (JsonBuilder *builder, PangoTabArray *tabs) { + if (!tabs || pango_tab_array_get_size (tabs) == 0) + return; + + json_builder_set_member_name (builder, "tabs"); + json_builder_begin_object (builder); json_builder_set_member_name (builder, "positions-in-pixels"); @@ -266,11 +279,7 @@ layout_to_json (PangoLayout *layout, json_builder_set_member_name (builder, "text"); json_builder_add_string_value (builder, layout->text); - if (layout->attrs) - { - json_builder_set_member_name (builder, "attributes"); - add_attr_list (builder, layout->attrs); - } + add_attr_list (builder, layout->attrs); if (layout->font_desc) { @@ -280,11 +289,7 @@ layout_to_json (PangoLayout *layout, g_free (str); } - if (layout->tabs) - { - json_builder_set_member_name (builder, "tabs"); - add_tab_array (builder, layout->tabs); - } + add_tab_array (builder, layout->tabs); if (layout->justify) { |