From af9d2495dc68c4a64bab87a7cc0a60927d81fa53 Mon Sep 17 00:00:00 2001 From: Behdad Esfahbod Date: Sat, 7 Aug 2021 12:29:52 -0600 Subject: [PATCH] [util] Use inheritance for output_options_t --- util/hb-shape.cc | 41 ++++++++++++++++++++--------------------- util/hb-subset.cc | 9 +++------ util/view-cairo.hh | 12 ++++++------ 3 files changed, 29 insertions(+), 33 deletions(-) diff --git a/util/hb-shape.cc b/util/hb-shape.cc index 732923b13..776afcdb4 100644 --- a/util/hb-shape.cc +++ b/util/hb-shape.cc @@ -32,38 +32,38 @@ const unsigned DEFAULT_FONT_SIZE = FONT_SIZE_UPEM; const unsigned SUBPIXEL_BITS = 0; -struct output_buffer_t +struct output_buffer_t : output_options_t { void add_options (option_parser_t *parser) { - options.add_options (parser, hb_buffer_serialize_list_formats ()); + output_options_t::add_options (parser, hb_buffer_serialize_list_formats ()); format.add_options (parser); } void init (hb_buffer_t *buffer, const font_options_t *font_opts) { - options.get_file_handle (); + get_file_handle (); gs = g_string_new (nullptr); line_no = 0; font = hb_font_reference (font_opts->get_font ()); - if (!options.output_format) - output_format = HB_BUFFER_SERIALIZE_FORMAT_TEXT; + if (!output_format) + serialize_format = HB_BUFFER_SERIALIZE_FORMAT_TEXT; else - output_format = hb_buffer_serialize_format_from_string (options.output_format, -1); + serialize_format = hb_buffer_serialize_format_from_string (output_format, -1); /* An empty "output_format" parameter basically skips output generating. * Useful for benchmarking. */ - if ((!options.output_format || *options.output_format) && - !hb_buffer_serialize_format_to_string (output_format)) + if ((!output_format || *output_format) && + !hb_buffer_serialize_format_to_string (serialize_format)) { - if (options.explicit_output_format) + if (explicit_output_format) fail (false, "Unknown output format `%s'; supported formats are: %s", - options.output_format, + output_format, g_strjoinv ("/", const_cast (hb_buffer_serialize_list_formats ()))); else /* Just default to TEXT if not explicitly requested and the * file extension is not recognized. */ - output_format = HB_BUFFER_SERIALIZE_FORMAT_TEXT; + serialize_format = HB_BUFFER_SERIALIZE_FORMAT_TEXT; } unsigned int flags = HB_BUFFER_SERIALIZE_FLAG_DEFAULT; @@ -79,7 +79,7 @@ struct output_buffer_t flags |= HB_BUFFER_SERIALIZE_FLAG_GLYPH_EXTENTS; if (format.show_flags) flags |= HB_BUFFER_SERIALIZE_FLAG_GLYPH_FLAGS; - format_flags = (hb_buffer_serialize_flags_t) flags; + serialize_flags = (hb_buffer_serialize_flags_t) flags; if (format.trace) hb_buffer_set_message_func (buffer, message_func, this, nullptr); @@ -92,13 +92,13 @@ struct output_buffer_t { g_string_set_size (gs, 0); format.serialize_buffer_of_text (buffer, line_no, text, text_len, font, gs); - fprintf (options.fp, "%s", gs->str); + fprintf (fp, "%s", gs->str); } void error (const char *message) { g_string_set_size (gs, 0); format.serialize_message (line_no, "error", message, gs); - fprintf (options.fp, "%s", gs->str); + fprintf (fp, "%s", gs->str); } void consume_glyphs (hb_buffer_t *buffer, const char *text, @@ -107,8 +107,8 @@ struct output_buffer_t { g_string_set_size (gs, 0); format.serialize_buffer_of_glyphs (buffer, line_no, text, text_len, font, - output_format, format_flags, gs); - fprintf (options.fp, "%s", gs->str); + serialize_format, serialize_flags, gs); + fprintf (fp, "%s", gs->str); } void finish (hb_buffer_t *buffer, const font_options_t *font_opts) { @@ -138,22 +138,21 @@ 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 (buffer, font, output_format, format_flags, gs); + format.serialize (buffer, font, serialize_format, serialize_flags, gs); g_string_append_c (gs, '\n'); - fprintf (options.fp, "%s", gs->str); + fprintf (fp, "%s", gs->str); } protected: - output_options_t options; shape_format_options_t format; GString *gs = nullptr; unsigned int line_no = 0; hb_font_t *font = nullptr; - hb_buffer_serialize_format_t output_format = HB_BUFFER_SERIALIZE_FORMAT_INVALID; - hb_buffer_serialize_flags_t format_flags = HB_BUFFER_SERIALIZE_FLAG_DEFAULT; + hb_buffer_serialize_format_t serialize_format = HB_BUFFER_SERIALIZE_FORMAT_INVALID; + hb_buffer_serialize_flags_t serialize_flags = HB_BUFFER_SERIALIZE_FLAG_DEFAULT; }; int diff --git a/util/hb-subset.cc b/util/hb-subset.cc index c20cade42..704070757 100644 --- a/util/hb-subset.cc +++ b/util/hb-subset.cc @@ -36,12 +36,12 @@ */ -struct subset_consumer_t : subset_options_t +struct subset_consumer_t : subset_options_t, output_options_t { void add_options (option_parser_t *parser) { subset_options_t::add_options (parser); - output_options.add_options (parser); + output_options_t::add_options (parser); } void init (const face_options_t *face_opts) @@ -110,7 +110,7 @@ struct subset_consumer_t : subset_options_t if (!failed) { hb_blob_t *result = hb_face_reference_blob (new_face); - write_file (output_options.output_file, result); + write_file (output_file, result); hb_blob_destroy (result); } @@ -122,9 +122,6 @@ struct subset_consumer_t : subset_options_t public: bool failed = false; - private: - output_options_t output_options; - hb_face_t *face = nullptr; hb_subset_input_t *input = nullptr; }; diff --git a/util/view-cairo.hh b/util/view-cairo.hh index d1915d0a5..47fbf35f4 100644 --- a/util/view-cairo.hh +++ b/util/view-cairo.hh @@ -30,7 +30,7 @@ #include "view-options.hh" #include "helper-cairo.hh" -struct view_cairo_t : view_options_t +struct view_cairo_t : view_options_t, output_options_t { ~view_cairo_t () { @@ -39,8 +39,8 @@ struct view_cairo_t : view_options_t void add_options (option_parser_t *parser) { - view_options_t::add_options (parser); - output_options.add_options (parser, helper_cairo_supported_formats); + view_options_t::add_options (parser); + output_options_t::add_options (parser, helper_cairo_supported_formats); } void init (hb_buffer_t *buffer, const font_options_t *font_opts) @@ -84,8 +84,6 @@ struct view_cairo_t : view_options_t void render (const font_options_t *font_opts); - output_options_t output_options; - hb_direction_t direction = HB_DIRECTION_INVALID; // Remove this, make segment_properties accessible GArray *lines = nullptr; int scale_bits = 0; @@ -142,7 +140,9 @@ view_cairo_t::render (const font_options_t *font_opts) /* Create surface. */ cairo_t *cr = helper_cairo_create_context (w + margin.l + margin.r, h + margin.t + margin.b, - static_cast (this), &output_options, content); + static_cast (this), + static_cast (this), + content); cairo_set_scaled_font (cr, scaled_font); /* Setup coordinate system. */