From dcbca3f0d703a4e89816ea1b8cc81af7a366e5bd Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Mon, 28 Aug 2023 00:26:19 -0400 Subject: [PATCH] path-tool: Add a reverse command It does what it says. --- docs/reference/gtk/gtk4-path-tool.rst | 7 +++ tools/gtk-path-tool-reverse.c | 81 +++++++++++++++++++++++++++ tools/gtk-path-tool.c | 3 + tools/gtk-path-tool.h | 1 + tools/meson.build | 1 + 5 files changed, 93 insertions(+) create mode 100644 tools/gtk-path-tool-reverse.c diff --git a/docs/reference/gtk/gtk4-path-tool.rst b/docs/reference/gtk/gtk4-path-tool.rst index 600d204231..2decd89171 100644 --- a/docs/reference/gtk/gtk4-path-tool.rst +++ b/docs/reference/gtk/gtk4-path-tool.rst @@ -15,6 +15,7 @@ SYNOPSIS | **gtk4-path-tool** decompose [OPTIONS...] | **gtk4-path-tool** show [OPTIONS...] | **gtk4-path-tool** render [OPTIONS...] +| **gtk4-path-tool** reverse [OPTIONS...] | **gtk4-path-tool** info [OPTIONS...] DESCRIPTION @@ -181,6 +182,12 @@ The interior of the path is filled. The offset into the dash pattern where dashing should begin. The default value is 0. +Reversing +^^^^^^^^^ + +The ``reverse`` command changes the direction of the path. The resulting +paths starts where the original path ends. + Info ^^^^ diff --git a/tools/gtk-path-tool-reverse.c b/tools/gtk-path-tool-reverse.c new file mode 100644 index 0000000000..f1deb204e2 --- /dev/null +++ b/tools/gtk-path-tool-reverse.c @@ -0,0 +1,81 @@ +/* Copyright 2023 Red Hat, Inc. + * + * GTK+ is free software; you can redistribute it and/or modify it + * under the terms of the GNU Lesser General Public License as + * published by the Free Software Foundation; either version 2 of the + * License, or (at your option) any later version. + * + * GLib is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with GTK+; see the file COPYING. If not, + * see . + * + * Author: Matthias Clasen + */ + +#include "config.h" + +#include +#include "gtk-path-tool.h" + +#include + +void +do_reverse (int *argc, const char ***argv) +{ + GError *error = NULL; + char **args = NULL; + GOptionContext *context; + GOptionEntry entries[] = { + { G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &args, NULL, N_("PATH") }, + { NULL, }, + }; + GskPath *path, *result; + GskPathBuilder *builder; + + g_set_prgname ("gtk4-path-tool reverse"); + + 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, _("Reverse a path.")); + + if (!g_option_context_parse (context, argc, (char ***)argv, &error)) + { + g_printerr ("%s\n", error->message); + g_error_free (error); + exit (1); + } + + g_option_context_free (context); + + if (args == NULL) + { + g_printerr ("%s\n", _("No paths given.")); + exit (1); + } + + path = get_path (args[0]); + + builder = gsk_path_builder_new (); + + gsk_path_builder_add_reverse_path (builder, path); + + result = gsk_path_builder_free_to_path (builder); + + if (result) + { + char *str = gsk_path_to_string (result); + g_print ("%s\n", str); + g_free (str); + } + else + { + g_printerr ("%s\n", _("That didn't work out.")); + exit (1); + } +} diff --git a/tools/gtk-path-tool.c b/tools/gtk-path-tool.c index 4d5c6cf817..a820fae0c1 100644 --- a/tools/gtk-path-tool.c +++ b/tools/gtk-path-tool.c @@ -39,6 +39,7 @@ usage (void) "\n" "Commands:\n" " decompose Decompose the path\n" + " reverse Reverse the path\n" " restrict Restrict the path to a segment\n" " show Display the path in a window\n" " render Render the path as an image\n" @@ -133,6 +134,8 @@ main (int argc, const char *argv[]) do_render (&argc, &argv); else if (strcmp (argv[0], "restrict") == 0) do_restrict (&argc, &argv); + else if (strcmp (argv[0], "reverse") == 0) + do_reverse (&argc, &argv); else if (strcmp (argv[0], "show") == 0) do_show (&argc, &argv); else diff --git a/tools/gtk-path-tool.h b/tools/gtk-path-tool.h index 34a137dc1f..505d5c2bd3 100644 --- a/tools/gtk-path-tool.h +++ b/tools/gtk-path-tool.h @@ -3,6 +3,7 @@ void do_info (int *argc, const char ***argv); void do_decompose (int *argc, const char ***argv); void do_restrict (int *argc, const char ***argv); +void do_reverse (int *argc, const char ***argv); void do_render (int *argc, const char ***argv); void do_show (int *argc, const char ***argv); diff --git a/tools/meson.build b/tools/meson.build index 1197c3dcc4..b7b8fd4976 100644 --- a/tools/meson.build +++ b/tools/meson.build @@ -28,6 +28,7 @@ gtk_tools = [ 'gtk-path-tool-info.c', 'gtk-path-tool-render.c', 'gtk-path-tool-restrict.c', + 'gtk-path-tool-reverse.c', 'gtk-path-tool-show.c', 'gtk-path-tool-utils.c', 'path-view.c'], [libgtk_dep]],