Commit 60ae4ac4 authored by Matthias Clasen's avatar Matthias Clasen
Browse files

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.
parent b8dbc92a
......@@ -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);
}
}
......
......@@ -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" : {
......
......@@ -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,
......
......@@ -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"
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment