Add buffer serialization / deserialization API
Two output formats for now: TEXT, and JSON. For example:
hb-shape --output-format=json
Deserialization API is added, but not implemented yet.
diff --git a/util/hb-shape.cc b/util/hb-shape.cc
index b23519b..ef926da 100644
--- a/util/hb-shape.cc
+++ b/util/hb-shape.cc
@@ -40,6 +40,20 @@
gs = g_string_new (NULL);
line_no = 0;
font = hb_font_reference (font_opts->get_font ());
+
+ if (!options.output_format)
+ output_format = HB_BUFFER_SERIALIZE_FORMAT_TEXT;
+ else
+ output_format = hb_buffer_serialize_format_from_string (options.output_format, -1);
+
+ unsigned int flags = HB_BUFFER_SERIALIZE_FLAGS_DEFAULT;
+ if (!format.show_glyph_names)
+ flags |= HB_BUFFER_SERIALIZE_FLAG_NO_GLYPH_NAMES;
+ if (!format.show_clusters)
+ flags |= HB_BUFFER_SERIALIZE_FLAG_NO_CLUSTERS;
+ if (!format.show_positions)
+ flags |= HB_BUFFER_SERIALIZE_FLAG_NO_POSITIONS;
+ format_flags = (hb_buffer_serialize_flags_t) flags;
}
void new_line (void)
{
@@ -51,7 +65,7 @@
hb_bool_t utf8_clusters)
{
g_string_set_size (gs, 0);
- format.serialize_buffer_of_text (buffer, line_no, text, text_len, font, utf8_clusters, gs);
+ format.serialize_buffer_of_text (buffer, line_no, text, text_len, font, gs);
fprintf (options.fp, "%s", gs->str);
}
void shape_failed (hb_buffer_t *buffer,
@@ -69,7 +83,8 @@
hb_bool_t utf8_clusters)
{
g_string_set_size (gs, 0);
- format.serialize_buffer_of_glyphs (buffer, line_no, text, text_len, font, utf8_clusters, gs);
+ format.serialize_buffer_of_glyphs (buffer, line_no, text, text_len, font,
+ output_format, format_flags, gs);
fprintf (options.fp, "%s", gs->str);
}
void finish (const font_options_t *font_opts)
@@ -87,6 +102,8 @@
GString *gs;
unsigned int line_no;
hb_font_t *font;
+ hb_buffer_serialize_format_t output_format;
+ hb_buffer_serialize_flags_t format_flags;
};
int