[util] Collect cmdline arg options outside of constructor

This commit is contained in:
Behdad Esfahbod 2021-08-05 11:05:51 -06:00
parent e57dd66889
commit e109f9a6f9
7 changed files with 47 additions and 58 deletions

View File

@ -32,14 +32,10 @@
struct shape_closure_consumer_t : option_group_t
{
shape_closure_consumer_t (option_parser_t *parser)
: shaper (parser)
{
add_options (parser);
}
void add_options (struct option_parser_t *parser) override
{
shaper.add_options (parser);
GOptionEntry entries[] =
{
{"no-glyph-names", 0, G_OPTION_FLAG_REVERSE, G_OPTION_ARG_NONE, &this->show_glyph_names, "Use glyph indices instead of names", nullptr},

View File

@ -30,11 +30,16 @@
struct output_buffer_t
{
output_buffer_t (option_parser_t *parser)
: options (parser, hb_buffer_serialize_list_formats ()),
format (parser)
output_buffer_t ()
: options (hb_buffer_serialize_list_formats ())
{}
void add_options (option_parser_t *parser)
{
options.add_options (parser);
format.add_options (parser);
}
void init (hb_buffer_t *buffer, const font_options_t *font_opts)
{
options.get_file_handle ();

View File

@ -36,10 +36,11 @@
struct subset_consumer_t
{
subset_consumer_t (option_parser_t *parser)
: options (parser),
subset_options (parser)
{}
void add_options (option_parser_t *parser)
{
output_options.add_options (parser);
subset_options.add_options (parser);
}
void init (hb_buffer_t *buffer_,
const font_options_t *font_opts)
@ -108,7 +109,7 @@ struct subset_consumer_t
if (!failed)
{
hb_blob_t *result = hb_face_reference_blob (new_face);
write_file (options.output_file, result);
write_file (output_options.output_file, result);
hb_blob_destroy (result);
}
@ -121,7 +122,7 @@ struct subset_consumer_t
bool failed = false;
private:
output_options_t options;
output_options_t output_options;
subset_options_t subset_options;
hb_face_t *face = nullptr;

View File

@ -51,14 +51,21 @@ template <typename consumer_t, int default_font_size, int subpixel_bits, int eol
struct main_font_text_t
{
main_font_text_t ()
: options ("[FONT-FILE] [TEXT]"),
font_opts (&options, default_font_size, subpixel_bits),
input (&options),
consumer (&options) {}
: font_opts (default_font_size, subpixel_bits)
{}
void add_options (option_parser_t *parser)
{
font_opts.add_options (parser);
input.add_options (parser);
consumer.add_options (parser);
}
int
main (int argc, char **argv)
{
option_parser_t options ("[FONT-FILE] [TEXT]");
add_options (&options);
options.parse (&argc, &argv);
argc--, argv++;
@ -86,7 +93,6 @@ struct main_font_text_t
}
protected:
option_parser_t options;
font_options_t font_opts;
text_options_t input;
consumer_t consumer;

View File

@ -117,10 +117,6 @@ struct option_parser_t
struct view_options_t : option_group_t
{
view_options_t (option_parser_t *parser)
{
add_options (parser);
}
~view_options_t () override
{
g_free (fore);
@ -145,10 +141,6 @@ struct view_options_t : option_group_t
struct shape_options_t : option_group_t
{
shape_options_t (option_parser_t *parser)
{
add_options (parser);
}
~shape_options_t () override
{
g_free (direction);
@ -433,16 +425,13 @@ struct shape_options_t : option_group_t
struct font_options_t : option_group_t
{
font_options_t (option_parser_t *parser,
int default_font_size_,
font_options_t (int default_font_size_,
unsigned int subpixel_bits_)
: default_font_size (default_font_size_),
subpixel_bits (subpixel_bits_),
font_size_x (default_font_size_),
font_size_y (default_font_size_)
{
add_options (parser);
}
{}
~font_options_t () override
{
g_free (font_file);
@ -492,10 +481,6 @@ struct font_options_t : option_group_t
struct text_options_t : option_group_t
{
text_options_t (option_parser_t *parser)
{
add_options (parser);
}
~text_options_t () override
{
g_free (text_before);
@ -535,12 +520,9 @@ struct text_options_t : option_group_t
struct output_options_t : option_group_t
{
output_options_t (option_parser_t *parser,
const char **supported_formats_ = nullptr)
output_options_t (const char **supported_formats_ = nullptr)
: supported_formats (supported_formats_)
{
add_options (parser);
}
{}
~output_options_t () override
{
g_free (output_file);
@ -581,10 +563,6 @@ struct output_options_t : option_group_t
struct format_options_t : option_group_t
{
format_options_t (option_parser_t *parser) {
add_options (parser);
}
void add_options (option_parser_t *parser) override;
void serialize (hb_buffer_t *buffer,
@ -628,12 +606,9 @@ struct format_options_t : option_group_t
struct subset_options_t : option_group_t
{
subset_options_t (option_parser_t *parser)
subset_options_t ()
: input (hb_subset_input_create_or_fail ())
{
add_options (parser);
}
{}
~subset_options_t () override
{
hb_subset_input_destroy (input);

View File

@ -34,10 +34,11 @@
template <typename output_t>
struct shape_consumer_t
{
shape_consumer_t (option_parser_t *parser)
: shaper (parser),
output (parser)
{}
void add_options (option_parser_t *parser)
{
shaper.add_options (parser);
output.add_options (parser);
}
void init (hb_buffer_t *buffer_,
const font_options_t *font_opts)

View File

@ -34,15 +34,20 @@
struct view_cairo_t
{
view_cairo_t (option_parser_t *parser)
: output_options (parser, helper_cairo_supported_formats),
view_options (parser)
view_cairo_t ()
: output_options (helper_cairo_supported_formats)
{}
~view_cairo_t ()
{
cairo_debug_reset_static_data ();
}
void add_options (option_parser_t *parser)
{
output_options.add_options (parser);
view_options.add_options (parser);
}
void init (hb_buffer_t *buffer, const font_options_t *font_opts)
{
lines = g_array_new (false, false, sizeof (helper_cairo_line_t));