From 97308ddf33d388ab3b2f60501e435682c0fe5f84 Mon Sep 17 00:00:00 2001 From: Simon Cozens Date: Thu, 17 Sep 2020 16:49:59 +0100 Subject: [PATCH] Use hb_buffer_serialize to trace in utils --- util/hb-shape.cc | 2 +- util/options.cc | 37 +++++++++++++------------------------ util/options.hh | 4 +--- 3 files changed, 15 insertions(+), 28 deletions(-) diff --git a/util/hb-shape.cc b/util/hb-shape.cc index 78488f476..01b3d4551 100644 --- a/util/hb-shape.cc +++ b/util/hb-shape.cc @@ -137,7 +137,7 @@ struct output_buffer_t g_string_set_size (gs, 0); format.serialize_line_no (line_no, gs); g_string_append_printf (gs, "trace: %s buffer: ", message); - format.serialize_glyphs (buffer, font, output_format, format_flags, gs); + format.serialize (buffer, font, output_format, format_flags, gs); g_string_append_c (gs, '\n'); fprintf (options.fp, "%s", gs->str); } diff --git a/util/options.cc b/util/options.cc index ee09ac5d4..653e2019c 100644 --- a/util/options.cc +++ b/util/options.cc @@ -910,31 +910,16 @@ format_options_t::add_options (option_parser_t *parser) } void -format_options_t::serialize_unicode (hb_buffer_t *buffer, - GString *gs) -{ - unsigned int num_glyphs = hb_buffer_get_length (buffer); - hb_glyph_info_t *info = hb_buffer_get_glyph_infos (buffer, nullptr); - - g_string_append_c (gs, '<'); - for (unsigned int i = 0; i < num_glyphs; i++) - { - if (i) - g_string_append_c (gs, ','); - g_string_append_printf (gs, "U+%04X", info->codepoint); - info++; - } - g_string_append_c (gs, '>'); -} - -void -format_options_t::serialize_glyphs (hb_buffer_t *buffer, +format_options_t::serialize (hb_buffer_t *buffer, hb_font_t *font, hb_buffer_serialize_format_t output_format, hb_buffer_serialize_flags_t flags, GString *gs) { - g_string_append_c (gs, '['); + if (hb_buffer_get_content_type(buffer) == HB_BUFFER_CONTENT_TYPE_UNICODE) + g_string_append_c (gs, '<'); + else + g_string_append_c (gs, '['); unsigned int num_glyphs = hb_buffer_get_length (buffer); unsigned int start = 0; @@ -942,15 +927,19 @@ format_options_t::serialize_glyphs (hb_buffer_t *buffer, { char buf[32768]; unsigned int consumed; - start += hb_buffer_serialize_glyphs (buffer, start, num_glyphs, + start += hb_buffer_serialize (buffer, start, num_glyphs, buf, sizeof (buf), &consumed, font, output_format, flags); if (!consumed) break; g_string_append (gs, buf); } - g_string_append_c (gs, ']'); + if (hb_buffer_get_content_type(buffer) == HB_BUFFER_CONTENT_TYPE_UNICODE) + g_string_append_c (gs, '>'); + else + g_string_append_c (gs, ']'); } + void format_options_t::serialize_line_no (unsigned int line_no, GString *gs) @@ -978,7 +967,7 @@ format_options_t::serialize_buffer_of_text (hb_buffer_t *buffer, if (show_unicode) { serialize_line_no (line_no, gs); - serialize_unicode (buffer, gs); + serialize (buffer, font, HB_BUFFER_SERIALIZE_FORMAT_TEXT, HB_BUFFER_SERIALIZE_FLAG_DEFAULT, gs); g_string_append_c (gs, '\n'); } } @@ -1003,6 +992,6 @@ format_options_t::serialize_buffer_of_glyphs (hb_buffer_t *buffer, GString *gs) { serialize_line_no (line_no, gs); - serialize_glyphs (buffer, font, output_format, format_flags, gs); + serialize (buffer, font, output_format, format_flags, gs); g_string_append_c (gs, '\n'); } diff --git a/util/options.hh b/util/options.hh index 2c10578a9..30b8f5b00 100644 --- a/util/options.hh +++ b/util/options.hh @@ -635,9 +635,7 @@ struct format_options_t : option_group_t void add_options (option_parser_t *parser) override; - void serialize_unicode (hb_buffer_t *buffer, - GString *gs); - void serialize_glyphs (hb_buffer_t *buffer, + void serialize (hb_buffer_t *buffer, hb_font_t *font, hb_buffer_serialize_format_t format, hb_buffer_serialize_flags_t flags,