summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2021-11-24 12:26:50 -0500
committerMatthias Clasen <mclasen@redhat.com>2021-11-24 19:57:58 -0500
commit580ad90e9737b13a941f981c9fa2b2d8e5fae120 (patch)
treeef779c07af048e64d91b4fe9c56c1c77de59935c
parentbecb4a942a87989acd37770af08f04da3e2731ba (diff)
downloadpango-580ad90e9737b13a941f981c9fa2b2d8e5fae120.tar.gz
Add pango_font_serialize
Another debug api. This function produces a serialization of a font that is enough to uniquely identify the font. This is more detailed than what pango_font_describe creates.
-rw-r--r--pango/pango-font.h3
-rw-r--r--pango/serializer.c55
2 files changed, 58 insertions, 0 deletions
diff --git a/pango/pango-font.h b/pango/pango-font.h
index c56fb792..bfe4bc31 100644
--- a/pango/pango-font.h
+++ b/pango/pango-font.h
@@ -634,6 +634,9 @@ hb_font_t * pango_font_get_hb_font (PangoFont *font);
PANGO_AVAILABLE_IN_1_50
PangoLanguage ** pango_font_get_languages (PangoFont *font);
+PANGO_AVAILABLE_IN_1_50
+GBytes * pango_font_serialize (PangoFont *font);
+
/**
* PANGO_GLYPH_EMPTY:
*
diff --git a/pango/serializer.c b/pango/serializer.c
index a4383aed..5c2bdf77 100644
--- a/pango/serializer.c
+++ b/pango/serializer.c
@@ -793,6 +793,20 @@ layout_to_json (PangoLayout *layout,
return root;
}
+static JsonNode *
+font_to_json (PangoFont *font)
+{
+ JsonBuilder *builder;
+ JsonNode *root;
+
+ builder = json_builder_new_immutable ();
+ add_font (builder, font);
+ root = json_builder_get_root (builder);
+ g_object_unref (builder);
+
+ return root;
+}
+
/* }}} */
/* {{{ Deserialization */
@@ -1569,6 +1583,47 @@ pango_layout_deserialize (PangoContext *context,
return layout;
}
+/**
+ * pango_font_serialize:
+ * @font: a `PangoFont`
+ *
+ * Serializes the @font in a way that can be uniquely identified.
+ *
+ * There are no guarantees about the format of the output across different
+ * versions of Pango.
+ *
+ * The intended use of this function is testing, benchmarking and debugging.
+ * The format is not meant as a permanent storage format.
+ *
+ * Returns: a `GBytes` containing the serialized form of @font
+ *
+ * Since: 1.50
+ */
+GBytes *
+pango_font_serialize (PangoFont *font)
+{
+ JsonGenerator *generator;
+ JsonNode *node;
+ char *data;
+ gsize size;
+
+ g_return_val_if_fail (PANGO_IS_FONT (font), NULL);
+
+ node = font_to_json (font);
+
+ generator = json_generator_new ();
+ json_generator_set_pretty (generator, TRUE);
+ json_generator_set_indent (generator, 2);
+
+ json_generator_set_root (generator, node);
+ data = json_generator_to_data (generator, &size);
+
+ json_node_free (node);
+ g_object_unref (generator);
+
+ return g_bytes_new_take (data, size);
+}
+
/* }}} */
/* vim:set foldmethod=marker expandtab: */