diff options
-rw-r--r-- | pango/pango-layout.h | 40 | ||||
-rw-r--r-- | pango/serializer.c | 26 | ||||
-rw-r--r-- | tests/test-layout.c | 2 | ||||
-rw-r--r-- | tests/testserialize.c | 10 | ||||
-rw-r--r-- | utils/viewer-render.c | 2 |
5 files changed, 59 insertions, 21 deletions
diff --git a/pango/pango-layout.h b/pango/pango-layout.h index 5e8d8784..e9b4710c 100644 --- a/pango/pango-layout.h +++ b/pango/pango-layout.h @@ -351,8 +351,28 @@ GSList * pango_layout_get_lines (PangoLayout *layout); PANGO_AVAILABLE_IN_1_16 GSList * pango_layout_get_lines_readonly (PangoLayout *layout); +/** + * PangoLayoutSerializeFlags: + * @PANGO_LAYOUT_SERIALIZE_DEFAULT: Default behavior + * + * Flags that influence the behavior of [method@Pango.Layout.serialize]. + * + * New members may be added to this enumeration over time. + */ +typedef enum { + PANGO_LAYOUT_SERIALIZE_DEFAULT = 0, +} PangoLayoutSerializeFlags; + +PANGO_AVAILABLE_IN_1_50 +GBytes * pango_layout_serialize (PangoLayout *layout, + PangoLayoutSerializeFlags flags); + PANGO_AVAILABLE_IN_1_50 -GBytes * pango_layout_serialize (PangoLayout *layout); +gboolean pango_layout_write_to_file (PangoLayout *layout, + PangoLayoutSerializeFlags flags, + + const char *filename, + GError **error); #define PANGO_LAYOUT_DESERIALIZE_ERROR (pango_layout_deserialize_error_quark ()) @@ -379,16 +399,24 @@ typedef enum { PANGO_AVAILABLE_IN_1_50 GQuark pango_layout_deserialize_error_quark (void); +/** + * PangoLayoutDeserializeFlags: + * @PANGO_LAYOUT_DESERIALIZE_DEFAULT: Default behavior + * + * Flags that influence the behavior of [method@Pango.Layout.deserialize]. + * + * New members may be added to this enumeration over time. + */ +typedef enum { + PANGO_LAYOUT_DESERIALIZE_DEFAULT = 0, +} PangoLayoutDeserializeFlags; + PANGO_AVAILABLE_IN_1_50 PangoLayout * pango_layout_deserialize (PangoContext *context, GBytes *bytes, + PangoLayoutDeserializeFlags flags, GError **error); -PANGO_AVAILABLE_IN_1_50 -gboolean pango_layout_write_to_file (PangoLayout *layout, - const char *filename, - GError **error); - #define PANGO_TYPE_LAYOUT_LINE (pango_layout_line_get_type ()) diff --git a/pango/serializer.c b/pango/serializer.c index 7439aabd..b9c24422 100644 --- a/pango/serializer.c +++ b/pango/serializer.c @@ -830,6 +830,7 @@ fail: /** * pango_layout_serialize: * @layout: a `PangoLayout` + * @flags: `PangoLayoutSerializeFlags` * * Serializes the @layout for later deserialization via [method@Pango.Layout.deserialize]. * @@ -845,13 +846,16 @@ fail: * Since: 1.50 */ GBytes * -pango_layout_serialize (PangoLayout *layout) +pango_layout_serialize (PangoLayout *layout, + PangoLayoutSerializeFlags flags) { JsonGenerator *generator; JsonNode *node; char *data; gsize size; + g_return_val_if_fail (PANGO_IS_LAYOUT (layout), NULL); + node = layout_to_json (layout); generator = json_generator_new (); @@ -870,6 +874,7 @@ pango_layout_serialize (PangoLayout *layout) /** * pango_layout_write_to_file: * @layout: a `PangoLayout` + * @flags: `PangoLayoutSerializeFlags` * @filename: (type filename): the file to save it to * @error: Return location for a potential error * @@ -886,9 +891,10 @@ pango_layout_serialize (PangoLayout *layout) * Since: 1.50 */ gboolean -pango_layout_write_to_file (PangoLayout *layout, - const char *filename, - GError **error) +pango_layout_write_to_file (PangoLayout *layout, + PangoLayoutSerializeFlags flags, + const char *filename, + GError **error) { GBytes *bytes; gboolean result; @@ -897,7 +903,7 @@ pango_layout_write_to_file (PangoLayout *layout, g_return_val_if_fail (filename != NULL, FALSE); g_return_val_if_fail (error == NULL || *error == NULL, FALSE); - bytes = pango_layout_serialize (layout); + bytes = pango_layout_serialize (layout, flags); result = g_file_set_contents (filename, g_bytes_get_data (bytes, NULL), g_bytes_get_size (bytes), @@ -911,6 +917,7 @@ pango_layout_write_to_file (PangoLayout *layout, /** * pango_layout_deserialize: * @context: a `PangoContext` + * @flags: `PangoLayoutDeserializeFlags` * @bytes: the bytes containing the data * @error: return location for an error * @@ -923,14 +930,17 @@ pango_layout_write_to_file (PangoLayout *layout, * Since: 1.50 */ PangoLayout * -pango_layout_deserialize (PangoContext *context, - GBytes *bytes, - GError **error) +pango_layout_deserialize (PangoContext *context, + GBytes *bytes, + PangoLayoutDeserializeFlags flags, + GError **error) { JsonParser *parser; JsonNode *node; PangoLayout *layout; + g_return_val_if_fail (PANGO_IS_CONTEXT (context), NULL); + parser = json_parser_new_immutable (); if (!json_parser_load_from_data (parser, g_bytes_get_data (bytes, NULL), diff --git a/tests/test-layout.c b/tests/test-layout.c index 7415efe7..f4b36c77 100644 --- a/tests/test-layout.c +++ b/tests/test-layout.c @@ -236,7 +236,7 @@ test_file (const char *filename, GString *string) bytes = g_bytes_new_take (contents, length); - layout = pango_layout_deserialize (context, bytes, &error); + layout = pango_layout_deserialize (context, bytes, PANGO_LAYOUT_DESERIALIZE_DEFAULT, &error); g_assert_no_error (error); g_bytes_unref (bytes); diff --git a/tests/testserialize.c b/tests/testserialize.c index b09b6ac3..d04ec7cf 100644 --- a/tests/testserialize.c +++ b/tests/testserialize.c @@ -142,7 +142,7 @@ test_serialize_layout_minimal (void) bytes = g_bytes_new_static (test, -1); - layout = pango_layout_deserialize (context, bytes, &error); + layout = pango_layout_deserialize (context, bytes, PANGO_LAYOUT_DESERIALIZE_DEFAULT, &error); g_assert_no_error (error); g_assert_true (PANGO_IS_LAYOUT (layout)); g_assert_cmpstr (pango_layout_get_text (layout), ==, "Almost nothing"); @@ -152,7 +152,7 @@ test_serialize_layout_minimal (void) g_assert_cmpint (pango_layout_get_alignment (layout), ==, PANGO_ALIGN_LEFT); g_assert_cmpint (pango_layout_get_width (layout), ==, -1); - out_bytes = pango_layout_serialize (layout); + out_bytes = pango_layout_serialize (layout, PANGO_LAYOUT_SERIALIZE_DEFAULT); str = g_bytes_get_data (out_bytes, NULL); g_assert_cmpstr (str, ==, test); @@ -215,7 +215,7 @@ test_serialize_layout_valid (void) bytes = g_bytes_new_static (test, -1); - layout = pango_layout_deserialize (context, bytes, &error); + layout = pango_layout_deserialize (context, bytes, PANGO_LAYOUT_DESERIALIZE_DEFAULT, &error); g_assert_no_error (error); g_assert_true (PANGO_IS_LAYOUT (layout)); g_assert_cmpstr (pango_layout_get_text (layout), ==, "Some fun with layouts!"); @@ -230,7 +230,7 @@ test_serialize_layout_valid (void) g_assert_cmpint (pango_layout_get_width (layout), ==, 350000); g_assert_cmpfloat_with_epsilon (pango_layout_get_line_spacing (layout), 1.5, 0.0001); - out_bytes = pango_layout_serialize (layout); + out_bytes = pango_layout_serialize (layout, PANGO_LAYOUT_SERIALIZE_DEFAULT); str = g_bytes_get_data (out_bytes, NULL); g_assert_cmpstr (str, ==, test); @@ -299,7 +299,7 @@ test_serialize_layout_invalid (void) GError *error = NULL; bytes = g_bytes_new_static (test[i].json, -1); - layout = pango_layout_deserialize (context, bytes, &error); + layout = pango_layout_deserialize (context, bytes, PANGO_LAYOUT_DESERIALIZE_DEFAULT, &error); g_assert_null (layout); g_assert_error (error, PANGO_LAYOUT_DESERIALIZE_ERROR, test[i].expected_error); g_bytes_unref (bytes); diff --git a/utils/viewer-render.c b/utils/viewer-render.c index 23e13c71..d2969da3 100644 --- a/utils/viewer-render.c +++ b/utils/viewer-render.c @@ -115,7 +115,7 @@ make_layout(PangoContext *context, if (!g_file_get_contents (file_arg, &text, &len, &error)) fail ("%s\n", error->message); bytes = g_bytes_new_take (text, size); - layout = pango_layout_deserialize (context, bytes, &error); + layout = pango_layout_deserialize (context, bytes, PANGO_LAYOUT_DESERIALIZE_DEFAULT, &error); if (!layout) fail ("%s\n", error->message); g_bytes_unref (bytes); |