From 79e132ab7bdac3fd332c38bf713bee4f221cc10f Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Tue, 22 Aug 2023 09:28:46 -0400 Subject: [PATCH] path-tool: Reorganize options Put fill and stroke options into their own group. This helps produce understandable --help output. --- docs/reference/gtk/gtk4-path-tool.rst | 8 ++++++ tools/gtk-path-tool-render.c | 36 +++++++++++++++++++++++---- tools/gtk-path-tool-show.c | 30 +++++++++++++++++++--- 3 files changed, 66 insertions(+), 8 deletions(-) diff --git a/docs/reference/gtk/gtk4-path-tool.rst b/docs/reference/gtk/gtk4-path-tool.rst index 1a7bbdf1ec..512be64edc 100644 --- a/docs/reference/gtk/gtk4-path-tool.rst +++ b/docs/reference/gtk/gtk4-path-tool.rst @@ -65,6 +65,10 @@ of the path is filled. The color that is used to render the background behind the path. If not specified, white is used. +``--fill`` + + Fill the path (this is the default). + ``--stroke`` Stroke the path instead of filling it. @@ -130,6 +134,10 @@ The interior of the path is filled. The file to save the PNG image to. If not specified, "path.png" is used. +``--fill`` + + Fill the path (this is the default). + ``--stroke`` Stroke the path instead of filling it. diff --git a/tools/gtk-path-tool-render.c b/tools/gtk-path-tool-render.c index a6e194f7dd..7146f591d8 100644 --- a/tools/gtk-path-tool-render.c +++ b/tools/gtk-path-tool-render.c @@ -48,21 +48,30 @@ do_render (int *argc, const char *output_file = NULL; char **args = NULL; GOptionContext *context; + GOptionGroup *options; const GOptionEntry entries[] = { - { "fill-rule", 0, 0, G_OPTION_ARG_STRING, &fill, N_("Fill rule (winding, even-odd)"), N_("VALUE") }, + { "fill", 0, G_OPTION_FLAG_REVERSE, G_OPTION_ARG_NONE, &do_stroke, N_("Fill the path (the default)"), NULL }, + { "stroke", 0, 0, G_OPTION_ARG_NONE, &do_stroke, N_("Stroke the path"), NULL }, + { "output", 0, 0, G_OPTION_ARG_FILENAME, &output_file, N_("The output file"), N_("FILE") }, { "fg-color", 0, 0, G_OPTION_ARG_STRING, &fg_color, N_("Foreground color"), N_("COLOR") }, { "bg-color", 0, 0, G_OPTION_ARG_STRING, &bg_color, N_("Background color"), N_("COLOR") }, - { "stroke", 0, 0, G_OPTION_ARG_NONE, &do_stroke, N_("Stroke the path instead of filling it"), NULL }, + { G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_STRING_ARRAY, &args, NULL, N_("PATH") }, + { NULL, } + }; + const GOptionEntry fill_entries[] = { + { "fill-rule", 0, 0, G_OPTION_ARG_STRING, &fill, N_("Fill rule (winding, even-odd)"), N_("VALUE") }, + { NULL, } + }; + const GOptionEntry stroke_entries[] = { { "line-width", 0, 0, G_OPTION_ARG_DOUBLE, &line_width, N_("Line width (number)"), N_("VALUE") }, { "line-cap", 0, 0, G_OPTION_ARG_STRING, &cap, N_("Line cap (butt, round, square)"), N_("VALUE") }, { "line-join", 0, 0, G_OPTION_ARG_STRING, &join, N_("Line join (miter, miter-clip, round, bevel, arcs)"), N_("VALUE") }, { "miter-limit", 0, 0, G_OPTION_ARG_DOUBLE, &miter_limit, N_("Miter limit (number)"), N_("VALUE") }, { "dashes", 0, 0, G_OPTION_ARG_STRING, &dashes, N_("Dash pattern (comma-separated numbers)"), N_("VALUE") }, { "dash-offset", 0, 0, G_OPTION_ARG_DOUBLE, &dash_offset, N_("Dash offset (number)"), N_("VALUE") }, - { "output", 0, 0, G_OPTION_ARG_FILENAME, &output_file, N_("The output file"), N_("FILE") }, - { G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_STRING_ARRAY, &args, NULL, N_("PATH") }, { NULL, } }; + GskPath *path; GskFillRule fill_rule; GdkRGBA fg, bg; @@ -85,9 +94,26 @@ do_render (int *argc, g_set_prgname ("gtk4-path-tool render"); context = g_option_context_new (NULL); g_option_context_set_translation_domain (context, GETTEXT_PACKAGE); - g_option_context_add_main_entries (context, entries, NULL); g_option_context_set_summary (context, _("Render the path to a png image.")); + g_option_context_add_main_entries (context, entries, NULL); + + options = g_option_group_new ("fill", + _("Options related to filling"), + _("Show help for fill options"), + NULL, NULL); + g_option_group_add_entries (options, fill_entries); + g_option_group_set_translation_domain (options, GETTEXT_PACKAGE); + g_option_context_add_group (context, options); + + options = g_option_group_new ("stroke", + _("Options related to stroking"), + _("Show help for stroke options"), + NULL, NULL); + g_option_group_add_entries (options, stroke_entries); + g_option_group_set_translation_domain (options, GETTEXT_PACKAGE); + g_option_context_add_group (context, options); + if (!g_option_context_parse (context, argc, (char ***)argv, &error)) { g_printerr ("%s\n", error->message); diff --git a/tools/gtk-path-tool-show.c b/tools/gtk-path-tool-show.c index d80fbae3a6..c1eeab5f76 100644 --- a/tools/gtk-path-tool-show.c +++ b/tools/gtk-path-tool-show.c @@ -118,18 +118,26 @@ do_show (int *argc, double dash_offset = 0; char **args = NULL; GOptionContext *context; + GOptionGroup *options; const GOptionEntry entries[] = { - { "fill-rule", 0, 0, G_OPTION_ARG_STRING, &fill, N_("Fill rule (winding, even-odd)"), N_("VALUE") }, + { "fill", 0, G_OPTION_FLAG_REVERSE, G_OPTION_ARG_NONE, &do_stroke, N_("Fill the path (the default)"), NULL }, + { "stroke", 0, 0, G_OPTION_ARG_NONE, &do_stroke, N_("Stroke the path"), NULL }, { "fg-color", 0, 0, G_OPTION_ARG_STRING, &fg_color, N_("Foreground color"), N_("COLOR") }, { "bg-color", 0, 0, G_OPTION_ARG_STRING, &bg_color, N_("Background color"), N_("COLOR") }, - { "stroke", 0, 0, G_OPTION_ARG_NONE, &do_stroke, N_("Stroke the path instead of filling it"), NULL }, + { G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_STRING_ARRAY, &args, NULL, N_("PATH") }, + { NULL, } + }; + const GOptionEntry fill_entries[] = { + { "fill-rule", 0, 0, G_OPTION_ARG_STRING, &fill, N_("Fill rule (winding, even-odd)"), N_("VALUE") }, + { NULL, } + }; + const GOptionEntry stroke_entries[] = { { "line-width", 0, 0, G_OPTION_ARG_DOUBLE, &line_width, N_("Line width (number)"), N_("VALUE") }, { "line-cap", 0, 0, G_OPTION_ARG_STRING, &cap, N_("Line cap (butt, round, square)"), N_("VALUE") }, { "line-join", 0, 0, G_OPTION_ARG_STRING, &join, N_("Line join (miter, miter-clip, round, bevel, arcs)"), N_("VALUE") }, { "miter-limit", 0, 0, G_OPTION_ARG_DOUBLE, &miter_limit, N_("Miter limit (number)"), N_("VALUE") }, { "dashes", 0, 0, G_OPTION_ARG_STRING, &dashes, N_("Dash pattern (comma-separated numbers)"), N_("VALUE") }, { "dash-offset", 0, 0, G_OPTION_ARG_DOUBLE, &dash_offset, N_("Dash offset (number)"), N_("VALUE") }, - { G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_STRING_ARRAY, &args, NULL, N_("PATH") }, { NULL, } }; GskPath *path; @@ -152,6 +160,22 @@ do_show (int *argc, g_option_context_add_main_entries (context, entries, NULL); g_option_context_set_summary (context, _("Display the path.")); + options = g_option_group_new ("fill", + _("Options related to filling"), + _("Show help for fill options"), + NULL, NULL); + g_option_group_add_entries (options, fill_entries); + g_option_group_set_translation_domain (options, GETTEXT_PACKAGE); + g_option_context_add_group (context, options); + + options = g_option_group_new ("stroke", + _("Options related to stroking"), + _("Show help for stroke options"), + NULL, NULL); + g_option_group_add_entries (options, stroke_entries); + g_option_group_set_translation_domain (options, GETTEXT_PACKAGE); + g_option_context_add_group (context, options); + if (!g_option_context_parse (context, argc, (char ***)argv, &error)) { g_printerr ("%s\n", error->message);