forked from GNOME/gtk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
gtk-path-tool-info.c
163 lines (141 loc) · 3.89 KB
/
gtk-path-tool-info.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
/* 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 <http://www.gnu.org/licenses/>.
*
* Author: Matthias Clasen
*/
#include "config.h"
#include <gtk/gtk.h>
#include "gtk-path-tool.h"
#include <glib/gi18n-lib.h>
typedef struct
{
int contours;
int ops;
int lines;
int quads;
int cubics;
int conics;
} Statistics;
static gboolean
stats_cb (GskPathOperation op,
const graphene_point_t *pts,
gsize n_pts,
float weight,
gpointer user_data)
{
Statistics *stats = user_data;
stats->ops++;
switch (op)
{
case GSK_PATH_MOVE:
stats->contours++;
break;
case GSK_PATH_CLOSE:
case GSK_PATH_LINE:
stats->lines++;
break;
case GSK_PATH_QUAD:
stats->quads++;
break;
case GSK_PATH_CUBIC:
stats->cubics++;
break;
case GSK_PATH_CONIC:
stats->conics++;
break;
default:
g_assert_not_reached ();
}
return TRUE;
}
static void
collect_statistics (GskPath *path,
Statistics *stats)
{
memset (stats, 0, sizeof (Statistics));
gsk_path_foreach (path, -1, stats_cb, stats);
}
void
do_info (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;
GskPathMeasure *measure;
graphene_rect_t bounds;
g_set_prgname ("gtk4-path-tool info");
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, _("Print information about 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]);
measure = gsk_path_measure_new (path);
if (gsk_path_is_empty (path))
g_print ("%s\n", _("Path is empty."));
else
{
Statistics stats;
if (gsk_path_is_closed (path))
g_print ("%s\n", _("Path is closed"));
g_print ("%s %g\n", _("Path length"), gsk_path_measure_get_length (measure));
if (gsk_path_get_bounds (path, &bounds))
g_print ("%s: %g %g %g %g\n", _("Bounds"),
bounds.origin.x, bounds.origin.y,
bounds.size.width, bounds.size.height);
collect_statistics (path, &stats);
g_print (_("%d contours"), stats.contours);
g_print ("\n");
g_print (_("%d operations"), stats.ops);
g_print ("\n");
if (stats.lines)
{
g_print (_("%d lines"), stats.lines);
g_print ("\n");
}
if (stats.quads)
{
g_print (_("%d quadratics"), stats.quads);
g_print ("\n");
}
if (stats.cubics)
{
g_print (_("%d cubics"), stats.cubics);
g_print ("\n");
}
if (stats.conics)
{
g_print (_("%d conics"), stats.conics);
g_print ("\n");
}
}
}