[pango/tab-spaces: 6/7] serializer: Support tabs in spaces
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pango/tab-spaces: 6/7] serializer: Support tabs in spaces
- Date: Wed, 8 Dec 2021 13:04:23 +0000 (UTC)
commit 8d64ac935ab521d63946a1215be441076b384382
Author: Matthias Clasen <mclasen redhat com>
Date: Wed Dec 8 07:58:51 2021 -0500
serializer: Support tabs in spaces
When serializing to a string, we use 'sp'
as unit for spaces. When serializing to json,
we now set a string member 'positions-in',
with the possible values 'pixels' or 'spaces'.
pango/serializer.c | 21 ++++++++++++++++-----
1 file changed, 16 insertions(+), 5 deletions(-)
---
diff --git a/pango/serializer.c b/pango/serializer.c
index 385410cc..8bb79da4 100644
--- a/pango/serializer.c
+++ b/pango/serializer.c
@@ -198,7 +198,11 @@ add_tab_array (GtkJsonPrinter *printer,
gtk_json_printer_start_object (printer, "tabs");
- gtk_json_printer_add_boolean (printer, "positions-in-pixels", pango_tab_array_get_positions_in_pixels
(tabs));
+ if (pango_tab_array_get_positions_in_pixels (tabs))
+ gtk_json_printer_add_string (printer, "positions-in", "pixels");
+ else if (pango_tab_array_get_positions_in_spaces (tabs))
+ gtk_json_printer_add_string (printer, "positions-in", "spaces");
+
gtk_json_printer_start_array (printer, "positions");
for (int i = 0; i < pango_tab_array_get_size (tabs); i++)
{
@@ -1016,12 +1020,12 @@ json_parser_fill_tabs (GtkJsonParser *parser,
}
enum {
- TABS_POSITIONS_IN_PIXELS,
+ TABS_POSITIONS_IN,
TABS_POSITIONS
};
static const char *tabs_members[] = {
- "positions-in-pixels",
+ "positions-in",
"positions",
NULL
};
@@ -1036,8 +1040,15 @@ json_parser_fill_tab_array (GtkJsonParser *parser,
{
switch (gtk_json_parser_select_member (parser, tabs_members))
{
- case TABS_POSITIONS_IN_PIXELS:
- pango_tab_array_set_positions_in_pixels (tabs, gtk_json_parser_get_boolean (parser));
+ case TABS_POSITIONS_IN:
+ {
+ char *str = gtk_json_parser_get_string (parser);
+ if (strcmp (str, "pixels") == 0)
+ pango_tab_array_set_positions_in_pixels (tabs, TRUE);
+ else if (strcmp (str, "spaces") == 0)
+ pango_tab_array_set_positions_in_spaces (tabs, TRUE);
+ g_free (str);
+ }
break;
case TABS_POSITIONS:
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]