[pango/serialization-improvements: 10/16] serializer: Cosmetics
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pango/serialization-improvements: 10/16] serializer: Cosmetics
- Date: Tue, 23 Nov 2021 19:11:53 +0000 (UTC)
commit fe42efa4e611e2b6b339584a6e21c8ade6b1e8ac
Author: Matthias Clasen <mclasen redhat com>
Date: Mon Nov 22 10:57:33 2021 -0500
serializer: Cosmetics
Avoid writing out empty attributes or tabs.
pango/serializer.c | 27 ++++++++++++++++-----------
1 file changed, 16 insertions(+), 11 deletions(-)
---
diff --git a/pango/serializer.c b/pango/serializer.c
index 84d377ee..fed29883 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)
{
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]