[util] Remove main_font_text_t class, use bare function

This commit is contained in:
Behdad Esfahbod 2021-08-07 11:04:46 -06:00
parent 58c223357b
commit 5545eea7e5
6 changed files with 55 additions and 64 deletions

View File

@ -113,6 +113,5 @@ struct shape_closure_consumer_t
int int
main (int argc, char **argv) main (int argc, char **argv)
{ {
main_font_text_t<shape_closure_consumer_t, font_options_t, text_options_t> driver; return main_font_text<shape_closure_consumer_t, font_options_t, text_options_t> (argc, argv);
return driver.main (argc, argv);
} }

View File

@ -159,7 +159,7 @@ struct output_buffer_t
int int
main (int argc, char **argv) main (int argc, char **argv)
{ {
using driver_t = main_font_text_t<shape_consumer_t<output_buffer_t>, font_options_t, text_options_t>; auto main_func = main_font_text<shape_consumer_t<output_buffer_t>, font_options_t, text_options_t>;
if (argc == 2 && !strcmp (argv[1], "--batch")) if (argc == 2 && !strcmp (argv[1], "--batch"))
{ {
@ -185,13 +185,11 @@ main (int argc, char **argv)
start_offset = argc == 2 && p[0] != '\0' && p[0] != ':' && p[1] == ':' && (p[2] == '\\' || p[2] == '/') ? 2 : 0; start_offset = argc == 2 && p[0] != '\0' && p[0] != ':' && p[1] == ':' && (p[2] == '\\' || p[2] == '/') ? 2 : 0;
} }
driver_t driver; ret |= main_func (argc, args, EOF);
ret |= driver.main (argc, args, EOF);
fflush (stdout); fflush (stdout);
} }
return ret; return ret;
} }
driver_t driver; return main_func (argc, argv, '\n');
return driver.main (argc, argv);
} }

View File

@ -132,7 +132,7 @@ struct subset_consumer_t : subset_options_t
int int
main (int argc, char **argv) main (int argc, char **argv)
{ {
using driver_t = main_font_text_t<subset_consumer_t, face_options_t, text_options_t>; auto main_func = main_font_text<subset_consumer_t, face_options_t, text_options_t>;
if (argc == 2 && !strcmp (argv[1], "--batch")) if (argc == 2 && !strcmp (argv[1], "--batch"))
{ {
@ -156,8 +156,7 @@ main (int argc, char **argv)
args[argc++] = p = e; args[argc++] = p = e;
} }
driver_t driver; int result = main_func (argc, args, EOF);
int result = driver.main (argc, args, EOF);
fprintf (stdout, result == 0 ? "success\n" : "failure\n"); fprintf (stdout, result == 0 ? "success\n" : "failure\n");
fflush (stdout); fflush (stdout);
ret |= result; ret |= result;
@ -165,6 +164,5 @@ main (int argc, char **argv)
return ret; return ret;
} }
driver_t driver; return main_func (argc, argv, '\n');
return driver.main (argc, argv);
} }

View File

@ -35,6 +35,5 @@ const unsigned SUBPIXEL_BITS = 6;
int int
main (int argc, char **argv) main (int argc, char **argv)
{ {
main_font_text_t<shape_consumer_t<view_cairo_t>, font_options_t, text_options_t> driver; return main_font_text<shape_consumer_t<view_cairo_t>, font_options_t, text_options_t> (argc, argv);
return driver.main (argc, argv);
} }

View File

@ -31,26 +31,9 @@
/* main() body for utilities taking font and processing text.*/ /* main() body for utilities taking font and processing text.*/
static char *
locale_to_utf8 (char *s)
{
char *t;
GError *error = nullptr;
t = g_locale_to_utf8 (s, -1, nullptr, nullptr, &error);
if (!t)
{
fail (true, "Failed converting text to UTF-8");
}
return t;
}
template <typename consumer_t, typename font_options_t, typename text_options_t> template <typename consumer_t, typename font_options_t, typename text_options_t>
struct main_font_text_t
{
int int
main (int argc, char **argv, int eol = '\n') main_font_text (int argc, char **argv, int eol = '\n')
{ {
font_options_t font_opts; font_options_t font_opts;
@ -84,6 +67,5 @@ struct main_font_text_t
return consumer.failed ? 1 : 0; return consumer.failed ? 1 : 0;
} }
};
#endif #endif

View File

@ -70,6 +70,21 @@ fail (hb_bool_t suggest_help, const char *format, ...)
exit (1); exit (1);
} }
static inline char *
locale_to_utf8 (char *s)
{
char *t;
GError *error = nullptr;
t = g_locale_to_utf8 (s, -1, nullptr, nullptr, &error);
if (!t)
{
fail (true, "Failed converting text to UTF-8");
}
return t;
}
struct option_parser_t struct option_parser_t
{ {