[pango/tab-align: 4/8] serializer: Support tab alignments




commit 60ae4ac4cf481e49f5ccbc4c97c95bb961620d61
Author: Matthias Clasen <mclasen redhat com>
Date:   Sun Nov 28 18:38:26 2021 -0500

    serializer: Support tab alignments
    
    Serialize tab alignment in addition to tab
    position. We still accept the old format
    and default alignment to left.
    
    Update testserialize and layout tests
    for this.

 pango/serializer.c            | 34 +++++++++++++++++++++++++++++++---
 tests/layouts/valid-12.layout | 25 ++++++++++++++++++++-----
 tests/layouts/valid-13.layout | 25 ++++++++++++++++++++-----
 tests/testserialize.c         | 17 ++++++++++++++---
 4 files changed, 85 insertions(+), 16 deletions(-)
---
diff --git a/pango/serializer.c b/pango/serializer.c
index 6e394a1c..372fbd8b 100644
--- a/pango/serializer.c
+++ b/pango/serializer.c
@@ -218,9 +218,15 @@ add_tab_array (JsonBuilder   *builder,
   json_builder_begin_array (builder);
   for (int i = 0; i < pango_tab_array_get_size (tabs); i++)
     {
+      PangoTabAlign align;
       int pos;
-      pango_tab_array_get_tab (tabs, i, NULL, &pos);
+      pango_tab_array_get_tab (tabs, i, &align, &pos);
+      json_builder_begin_object (builder);
+      json_builder_set_member_name (builder, "position");
       json_builder_add_int_value (builder, pos);
+      json_builder_set_member_name (builder, "alignment");
+      add_enum_value (builder, PANGO_TYPE_TAB_ALIGN, align, FALSE);
+      json_builder_end_object (builder);
     }
   json_builder_end_array (builder);
 
@@ -1133,9 +1139,31 @@ json_to_tab_array (JsonReader  *reader,
       for (int i = 0; i < json_reader_count_elements (reader); i++)
         {
           int pos;
+          PangoTabAlign align;
+
           json_reader_read_element (reader, i);
-          pos = json_reader_get_int_value (reader);
-          pango_tab_array_set_tab (tabs, i, PANGO_TAB_LEFT, pos);
+          if (json_reader_is_object (reader))
+            {
+              json_reader_read_member (reader, "position");
+              pos = json_reader_get_int_value (reader);
+              json_reader_end_member (reader);
+              json_reader_read_member (reader, "alignment");
+
+              align = get_enum_value (PANGO_TYPE_TAB_ALIGN,
+                                      json_reader_get_string_value (reader),
+                                      FALSE,
+                                      error);
+              if (align == -1)
+                goto fail;
+              json_reader_end_member (reader);
+            }
+          else
+            {
+              pos = json_reader_get_int_value (reader);
+              align = PANGO_TAB_LEFT;
+            }
+
+          pango_tab_array_set_tab (tabs, i, align, pos);
           json_reader_end_element (reader);
         }
     }
diff --git a/tests/layouts/valid-12.layout b/tests/layouts/valid-12.layout
index cc647178..bbe9a576 100644
--- a/tests/layouts/valid-12.layout
+++ b/tests/layouts/valid-12.layout
@@ -21,11 +21,26 @@
   "tabs" : {
     "positions-in-pixels" : true,
     "positions" : [
-      0,
-      50,
-      100,
-      150,
-      200
+      {
+        "position" : 0,
+        "alignment" : "left"
+      },
+      {
+        "position" : 50,
+        "alignment" : "left"
+      },
+      {
+        "position" : 100,
+        "alignment" : "left"
+      },
+      {
+        "position" : 150,
+        "alignment" : "left"
+      },
+      {
+        "position" : 200,
+        "alignment" : "left"
+      }
     ]
   },
   "output" : {
diff --git a/tests/layouts/valid-13.layout b/tests/layouts/valid-13.layout
index 7b70a602..bc20a3c1 100644
--- a/tests/layouts/valid-13.layout
+++ b/tests/layouts/valid-13.layout
@@ -21,11 +21,26 @@
   "tabs" : {
     "positions-in-pixels" : true,
     "positions" : [
-      0,
-      50,
-      100,
-      150,
-      200
+      {
+        "position" : 0,
+        "alignment" : "left"
+      },
+      {
+        "position" : 50,
+        "alignment" : "left"
+      },
+      {
+        "position" : 100,
+        "alignment" : "left"
+      },
+      {
+        "position" : 150,
+        "alignment" : "left"
+      },
+      {
+        "position" : 200,
+        "alignment" : "left"
+      }
     ]
   },
   "single-paragraph" : true,
diff --git a/tests/testserialize.c b/tests/testserialize.c
index 4ea7425e..325338f1 100644
--- a/tests/testserialize.c
+++ b/tests/testserialize.c
@@ -86,6 +86,7 @@ test_serialize_tab_array (void)
     "0px 10px 100px 200px 400px",
     "  0    10   ",
     "20 10",
+    "left:10px right:20px center:30px decimal:40px",
     ""
   };
   const char *roundtripped[] = {
@@ -93,6 +94,7 @@ test_serialize_tab_array (void)
     "0px 10px 100px 200px 400px",
     "0 10",
     "20 10",
+    "10px right:20px center:30px decimal:40px",
     ""
   };
   const char *invalid[] = {
@@ -231,9 +233,18 @@ test_serialize_layout_valid (void)
     "  \"tabs\" : {\n"
     "    \"positions-in-pixels\" : true,\n"
     "    \"positions\" : [\n"
-    "      0,\n"
-    "      50,\n"
-    "      100\n"
+    "      {\n"
+    "        \"position\" : 0,\n"
+    "        \"alignment\" : \"left\"\n"
+    "      },\n"
+    "      {\n"
+    "        \"position\" : 50,\n"
+    "        \"alignment\" : \"center\"\n"
+    "      },\n"
+    "      {\n"
+    "        \"position\" : 100,\n"
+    "        \"alignment\" : \"right\"\n"
+    "      }\n"
     "    ]\n"
     "  },\n"
     "  \"alignment\" : \"center\",\n"


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]