summaryrefslogtreecommitdiff
path: root/pango
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2021-11-21 23:01:53 -0500
committerMatthias Clasen <mclasen@redhat.com>2021-11-24 19:57:58 -0500
commitc1f9c9f85bf9f400e44477304e5eb135f1183ac9 (patch)
tree76b58ba908a57ee66e513cf3965161ed7fe70977 /pango
parent12a46f672c5fb5c6232218f02018c30cd44a16e2 (diff)
downloadpango-c1f9c9f85bf9f400e44477304e5eb135f1183ac9.tar.gz
Add flags to serialize and deserialize
This gives us some room to add more things to these apis, e.g. a way to store not just the input part of a layout, but also the output.
Diffstat (limited to 'pango')
-rw-r--r--pango/pango-layout.h40
-rw-r--r--pango/serializer.c26
2 files changed, 52 insertions, 14 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),