Compare commits
10 Commits
path-point
...
path-itera
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
244cdafe1b | ||
|
|
a0d17418de | ||
|
|
093e6241e7 | ||
|
|
67b504f823 | ||
|
|
659bc813a4 | ||
|
|
293c0774b3 | ||
|
|
988062889b | ||
|
|
461922b495 | ||
|
|
7150a53ccb | ||
|
|
1e306b148e |
150
LOG
Normal file
@@ -0,0 +1,150 @@
|
||||
TAP version 13
|
||||
# random seed: R02S22611f6aefc1121b0ab2dc5286960449
|
||||
# GLib-GIO-DEBUG: _g_io_module_get_default: Found default implementation dconf (DConfSettingsBackend) for ‘gsettings-backend’
|
||||
# GLib-GIO-DEBUG: Using cross-namespace EXTERNAL authentication (this will deadlock if server is GDBus < 2.73.3)
|
||||
# GLib-GIO-DEBUG: Using cross-namespace EXTERNAL authentication (this will deadlock if server is GDBus < 2.73.3)
|
||||
1..1
|
||||
# Start of ops tests
|
||||
# testcase 0 op 0
|
||||
collecting#
|
||||
Cubic 0: # M 100.000000 100.000000 C 150.000000 100.000000 200.000000 100.000000 250.000000 100.000000
|
||||
Cubic 1: # M 250.000000 100.000000 C 300.000000 100.000000 350.000000 100.000000 400.000000 100.000000
|
||||
Line 2: # M 400 100 L 200 300
|
||||
Line 3: # M 200 300 L 100 100
|
||||
Cubic 4: # M 200.000000 100.000000 C 250.000000 100.000000 300.000000 100.000000 350.000000 100.000000
|
||||
Cubic 5: # M 350.000000 100.000000 C 400.000000 100.000000 450.000000 100.000000 500.000000 100.000000
|
||||
Line 6: # M 500 100 L 300 300
|
||||
Line 7: # M 300 300 L 200 100
|
||||
splitting#
|
||||
1 intersections between Cubic 0 and Cubic 1#
|
||||
1 intersections between Cubic 0 and Line 3#
|
||||
9 intersections between Cubic 0 and Cubic 4#
|
||||
# split Cubic 0.0 from Cubic 0 at 0.666666: M 100.000000 100.000000 C 133.333298 100.000000 166.666595 100.000000 199.999893 100.000000
|
||||
split Cubic 0.1 from Cubic 0 at 0.666666: M 199.999893 100.000000 C 216.666595 100.000000 233.333298 100.000000 250.000000 100.000000split Cubic 0.4 from Cubic 0 at 0.00600814: M 200.300323 100.000000 C 216.866882 100.000000 233.433441 100.000000 250.000000 100.000000split Cubic 0.7 from Cubic 0 at 0.00604445: M 200.600708 100.000000 C 217.067139 100.000000 233.533569 100.000000 250.000000 100.000000# split Cubic 4.9 from Cubic 4 at 0.00533867: M 200.800812 100.000000 C 250.533875 100.000000 300.266937 100.000000 350.000000 100.000000
|
||||
1 intersections between Cubic 0.1 and Line 7#
|
||||
1 intersections between Cubic 1 and Line 2#
|
||||
9 intersections between Cubic 1 and Cubic 4.9#
|
||||
split Cubic 1.9 from Cubic 1 at 0.00534248: M 250.801361 100.000000 C 300.534241 100.000000 350.267120 100.000000 400.000000 100.000000# split Cubic 4.9.0 from Cubic 4.9 at 0.329756: M 200.800812 100.000000 C 217.200577 100.000000 233.600342 100.000000 250.000122 100.000000
|
||||
# split Cubic 4.9.1 from Cubic 4.9 at 0.329756: M 250.000122 100.000000 C 283.333435 100.000000 316.666718 100.000000 350.000000 100.000000
|
||||
# split Cubic 4.9.6 from Cubic 4.9 at 0.00500283: M 250.500412 100.000000 C 283.666931 100.000000 316.833466 100.000000 350.000000 100.000000
|
||||
9 intersections between Cubic 1.9 and Cubic 5#
|
||||
# split Cubic 1.9.0 from Cubic 1.9 at 0.664877: M 250.801361 100.000000 C 283.867615 100.000000 316.933868 100.000000 350.000122 100.000000
|
||||
split Cubic 1.9.1 from Cubic 1.9 at 0.664877: M 350.000122 100.000000 C 366.666748 100.000000 383.333374 100.000000 400.000000 100.000000split Cubic 1.9.4 from Cubic 1.9 at 0.00601021: M 350.300598 100.000000 C 366.867065 100.000000 383.433533 100.000000 400.000000 100.000000split Cubic 1.9.7 from Cubic 1.9 at 0.00604655: M 350.601074 100.000000 C 367.067383 100.000000 383.533691 100.000000 400.000000 100.000000# split Cubic 5.9 from Cubic 5 at 0.00534248: M 350.801361 100.000000 C 400.534241 100.000000 450.267120 100.000000 500.000000 100.000000
|
||||
1 intersections between Line 2 and Line 3#
|
||||
1 intersections between Line 2 and Line 7#
|
||||
# split Line 2.0 from Line 2 at 0.666667: M 400 100 L 266.667 233.333
|
||||
split Line 2.1 from Line 2 at 0.666667: M 266.667 233.333 L 200 300# split Line 7.0 from Line 7 at 0.333333: M 300 300 L 266.667 233.333
|
||||
# split Line 7.1 from Line 7 at 0.333333: M 266.667 233.333 L 200 100
|
||||
1 intersections between Cubic 4 and Cubic 4.9.0#
|
||||
1 intersections between Cubic 4 and Line 7.1#
|
||||
1 intersections between Cubic 4.9.0 and Cubic 4.9.1#
|
||||
1 intersections between Cubic 4.9.1 and Cubic 4.9.6#
|
||||
1 intersections between Cubic 4.9.6 and Cubic 5#
|
||||
1 intersections between Cubic 5 and Cubic 5.9#
|
||||
1 intersections between Cubic 5.9 and Line 6#
|
||||
1 intersections between Line 6 and Line 7.0#
|
||||
Cubic 0.0: # M 100.000000 100.000000 C 133.333298 100.000000 166.666595 100.000000 199.999893 100.000000
|
||||
Cubic 0.1: # M 199.999893 100.000000 C 200.100037 100.000000 200.200180 100.000000 200.300323 100.000000
|
||||
Cubic 0.4: # M 200.300323 100.000000 C 200.400452 100.000000 200.500580 100.000000 200.600708 100.000000
|
||||
Cubic 0.7: # M 200.600708 100.000000 C 217.067139 100.000000 233.533569 100.000000 250.000000 100.000000
|
||||
Cubic 1: # M 250.000000 100.000000 C 250.267120 100.000000 250.534241 100.000000 250.801361 100.000000
|
||||
Cubic 1.9.0: # M 250.801361 100.000000 C 283.867615 100.000000 316.933868 100.000000 350.000122 100.000000
|
||||
Cubic 1.9.1: # M 350.000122 100.000000 C 350.100281 100.000000 350.200439 100.000000 350.300598 100.000000
|
||||
Cubic 1.9.4: # M 350.300598 100.000000 C 350.400757 100.000000 350.500916 100.000000 350.601074 100.000000
|
||||
Cubic 1.9.7: # M 350.601074 100.000000 C 367.067383 100.000000 383.533691 100.000000 400.000000 100.000000
|
||||
Line 2.0: # M 400 100 L 266.667 233.333
|
||||
Line 2.1: # M 266.667 233.333 L 200 300
|
||||
Line 3: # M 200 300 L 100 100
|
||||
Cubic 4: # M 200.000000 100.000000 C 200.266937 100.000000 200.533875 100.000000 200.800812 100.000000
|
||||
Cubic 4.9.0: # M 200.800812 100.000000 C 217.200577 100.000000 233.600342 100.000000 250.000122 100.000000
|
||||
Cubic 4.9.1: # M 250.000122 100.000000 C 250.166885 100.000000 250.333649 100.000000 250.500412 100.000000
|
||||
Cubic 4.9.6: # M 250.500412 100.000000 C 283.666931 100.000000 316.833466 100.000000 350.000000 100.000000
|
||||
Cubic 5: # M 350.000000 100.000000 C 350.267120 100.000000 350.534241 100.000000 350.801361 100.000000
|
||||
Cubic 5.9: # M 350.801361 100.000000 C 400.534241 100.000000 450.267120 100.000000 500.000000 100.000000
|
||||
Line 6: # M 500 100 L 300 300
|
||||
Line 7.0: # M 300 300 L 266.667 233.333
|
||||
Line 7.1: # M 266.667 233.333 L 200 100
|
||||
classifying#
|
||||
01 Cubic 0.0: # M 100.000000 100.000000 C 133.333298 100.000000 166.666595 100.000000 199.999893 100.000000
|
||||
[11 Cubic 0.7: # M 200.600708 100.000000 C 217.067139 100.000000 233.533569 100.000000 250.000000 100.000000 ]
|
||||
[11 Cubic 1.9.0: # M 250.801361 100.000000 C 283.867615 100.000000 316.933868 100.000000 350.000122 100.000000 ]
|
||||
[11 Cubic 1.9.7: # M 350.601074 100.000000 C 367.067383 100.000000 383.533691 100.000000 400.000000 100.000000 ]
|
||||
[11 Line 2.0: # M 400 100 L 266.667 233.333 ]
|
||||
01 Line 2.1: # M 266.667 233.333 L 200 300
|
||||
01 Line 3: # M 200 300 L 100 100
|
||||
[11 Cubic 4: # M 200.000000 100.000000 C 200.266937 100.000000 200.533875 100.000000 200.800812 100.000000 ]
|
||||
[11 Cubic 4.9.0: # M 200.800812 100.000000 C 217.200577 100.000000 233.600342 100.000000 250.000122 100.000000 ]
|
||||
[11 Cubic 4.9.6: # M 250.500412 100.000000 C 283.666931 100.000000 316.833466 100.000000 350.000000 100.000000 ]
|
||||
[11 Cubic 5: # M 350.000000 100.000000 C 350.267120 100.000000 350.534241 100.000000 350.801361 100.000000 ]
|
||||
01 Cubic 5.9: # M 350.801361 100.000000 C 400.534241 100.000000 450.267120 100.000000 500.000000 100.000000
|
||||
01 Line 6: # M 500 100 L 300 300
|
||||
01 Line 7.0: # M 300 300 L 266.667 233.333
|
||||
[11 Line 7.1: # M 266.667 233.333 L 200 100 ]
|
||||
fixups#
|
||||
# found 3 bad nodes
|
||||
# split Cubic 0/Cubic 4 BAD 200.600723 100.000000
|
||||
# [11 Line 7.1 ] 116.565
|
||||
# [11 Cubic 0.7 ] 180
|
||||
# [11 Cubic 4 ] 180
|
||||
# [11 Cubic 4 ] 180
|
||||
# [11 Cubic 4.9.0 ] 180
|
||||
# >01 Cubic 0.0 360
|
||||
# split Cubic 1/Cubic 4.9 BAD 250.801376 100.000000
|
||||
# [11 Cubic 1.9.0 ] 180
|
||||
# [11 Cubic 4.9.6 ] 180
|
||||
# [11 Cubic 0.7 ] 360
|
||||
# [11 Cubic 4.9.0 ] 360
|
||||
# split Cubic 1.9/Cubic 5 BAD 350.601105 100.000000
|
||||
# [11 Cubic 1.9.7 ] 180
|
||||
# [11 Cubic 5 ] 180
|
||||
# [11 Cubic 5 ] 180
|
||||
# <01 Cubic 5.9 180
|
||||
# [11 Cubic 1.9.0 ] 360
|
||||
# [11 Cubic 4.9.6 ] 360
|
||||
reassembling#
|
||||
start new contour Cubic 0.0#
|
||||
# Cubic 0.0 ends at:
|
||||
# start 0 100.000000 100.000000
|
||||
# >01 Line 3 116.565
|
||||
# (10 Cubic 0.0 ) 180
|
||||
picking cw#
|
||||
append Line 3#
|
||||
# Line 3 ends at:
|
||||
# end 2 200.000000 300.000000
|
||||
# >01 Line 2.1 225
|
||||
# (10 Line 3 ) 296.565
|
||||
picking cw#
|
||||
append Line 2.1#
|
||||
# Line 2.1 ends at:
|
||||
# split Line 2/Line 7 266.666656 233.333344
|
||||
# (10 Line 2.1 ) 45
|
||||
# >01 Line 7.0 116.565
|
||||
# [11 Line 2.0 ] 225
|
||||
# [11 Line 7.1 ] 296.565
|
||||
picking cw#
|
||||
append Line 7.0#
|
||||
# Line 7.0 ends at:
|
||||
# end 6 300.000000 300.000000
|
||||
# >01 Line 6 225
|
||||
# (10 Line 7.0 ) 296.565
|
||||
picking cw#
|
||||
append Line 6#
|
||||
# Line 6 ends at:
|
||||
# end 5 500.000000 100.000000
|
||||
# (10 Line 6 ) 45
|
||||
# >01 Cubic 5.9 360
|
||||
picking cw#
|
||||
append Cubic 5.9#
|
||||
# Cubic 5.9 ends at:
|
||||
# split Cubic 1.9/Cubic 5 BAD 350.601105 100.000000
|
||||
# [11 Cubic 1.9.7 ] 180
|
||||
# [11 Cubic 5 ] 180
|
||||
# [11 Cubic 5 ] 180
|
||||
# (10 Cubic 5.9 ) 180
|
||||
# [11 Cubic 1.9.0 ] 360
|
||||
# [11 Cubic 4.9.6 ] 360
|
||||
picking cw#
|
||||
**
|
||||
ERROR:../testsuite/gsk/path-ops.c:359:test_ops_simple: assertion failed (s == tests[i].out): ("M 354.60110473632812 100 A 4 4 0 0 0 346.60110473632812 100 A 4 4 0 0 0 354.60110473632812 100 z M 252.80137634277344 100 A 2 2 0 0 0 248.80137634277344 100 A 2 2 0 0 0 252.80137634277344 100 z M 204.60072326660156 100 A 4 4 0 0 0 196.60072326660156 100 A 4 4 0 0 0 204.60072326660156 100 z" == "M 100 100 z")
|
||||
not ok /ops/simple - ERROR:../testsuite/gsk/path-ops.c:359:test_ops_simple: assertion failed (s == tests[i].out): ("M 354.60110473632812 100 A 4 4 0 0 0 346.60110473632812 100 A 4 4 0 0 0 354.60110473632812 100 z M 252.80137634277344 100 A 2 2 0 0 0 248.80137634277344 100 A 2 2 0 0 0 252.80137634277344 100 z M 204.60072326660156 100 A 4 4 0 0 0 196.60072326660156 100 A 4 4 0 0 0 204.60072326660156 100 z" == "M 100 100 z")
|
||||
Bail out!
|
||||
@@ -336,6 +336,7 @@
|
||||
<file>panes.c</file>
|
||||
<file>password_entry.c</file>
|
||||
<file>path_fill.c</file>
|
||||
<file>path_text.c</file>
|
||||
<file>peg_solitaire.c</file>
|
||||
<file>pickers.c</file>
|
||||
<file>printing.c</file>
|
||||
@@ -421,6 +422,9 @@
|
||||
<gresource prefix="/fontrendering">
|
||||
<file>fontrendering.ui</file>
|
||||
</gresource>
|
||||
<gresource prefix="/path_text">
|
||||
<file>path_text.ui</file>
|
||||
</gresource>
|
||||
<gresource prefix="/org/gtk/Demo4">
|
||||
<file>icons/16x16/actions/application-exit.png</file>
|
||||
<file>icons/16x16/actions/document-new.png</file>
|
||||
|
||||
@@ -73,6 +73,7 @@ demos = files([
|
||||
'panes.c',
|
||||
'password_entry.c',
|
||||
'path_fill.c',
|
||||
'path_text.c',
|
||||
'peg_solitaire.c',
|
||||
'pickers.c',
|
||||
'printing.c',
|
||||
|
||||
604
demos/gtk-demo/path_text.c
Normal file
@@ -0,0 +1,604 @@
|
||||
/* Path/Text
|
||||
*
|
||||
* This demo shows how to use GskPath to animate a path along another path.
|
||||
*/
|
||||
|
||||
#include <glib/gi18n.h>
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
#define GTK_TYPE_PATH_WIDGET (gtk_path_widget_get_type ())
|
||||
G_DECLARE_FINAL_TYPE (GtkPathWidget, gtk_path_widget, GTK, PATH_WIDGET, GtkWidget)
|
||||
|
||||
#define POINT_SIZE 8
|
||||
|
||||
enum {
|
||||
PROP_0,
|
||||
PROP_TEXT,
|
||||
PROP_EDITABLE,
|
||||
N_PROPS
|
||||
};
|
||||
|
||||
struct _GtkPathWidget
|
||||
{
|
||||
GtkWidget parent_instance;
|
||||
|
||||
char *text;
|
||||
gboolean editable;
|
||||
|
||||
graphene_point_t points[4];
|
||||
|
||||
guint active_point;
|
||||
float line_closest;
|
||||
|
||||
GskPath *line_path;
|
||||
GskPathMeasure *line_measure;
|
||||
GskPath *text_path;
|
||||
|
||||
GdkPaintable *background;
|
||||
};
|
||||
|
||||
struct _GtkPathWidgetClass
|
||||
{
|
||||
GtkWidgetClass parent_class;
|
||||
};
|
||||
|
||||
static GParamSpec *properties[N_PROPS] = { NULL, };
|
||||
|
||||
G_DEFINE_TYPE (GtkPathWidget, gtk_path_widget, GTK_TYPE_WIDGET)
|
||||
|
||||
static GskPath *
|
||||
create_path_from_text (GtkWidget *widget,
|
||||
const char *text,
|
||||
graphene_point_t *out_offset)
|
||||
{
|
||||
PangoLayout *layout;
|
||||
PangoFontDescription *desc;
|
||||
GskPathBuilder *builder;
|
||||
GskPath *result;
|
||||
|
||||
layout = gtk_widget_create_pango_layout (widget, text);
|
||||
desc = pango_font_description_from_string ("sans bold 36");
|
||||
pango_layout_set_font_description (layout, desc);
|
||||
pango_font_description_free (desc);
|
||||
|
||||
builder = gsk_path_builder_new ();
|
||||
gsk_path_builder_add_layout (builder, layout);
|
||||
result = gsk_path_builder_free_to_path (builder);
|
||||
|
||||
if (out_offset)
|
||||
graphene_point_init (out_offset, 0, - pango_layout_get_baseline (layout) / (double) PANGO_SCALE);
|
||||
g_object_unref (layout);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
typedef struct
|
||||
{
|
||||
GskPathMeasure *measure;
|
||||
GskPathBuilder *builder;
|
||||
graphene_point_t offset;
|
||||
double scale;
|
||||
} GtkPathTransform;
|
||||
|
||||
static void
|
||||
gtk_path_transform_point (GskPathMeasure *measure,
|
||||
const graphene_point_t *pt,
|
||||
const graphene_point_t *offset,
|
||||
float scale,
|
||||
graphene_point_t *res)
|
||||
{
|
||||
graphene_vec2_t tangent;
|
||||
GskPathPoint point;
|
||||
|
||||
if (gsk_path_measure_get_point (measure, (pt->x + offset->x) * scale, &point))
|
||||
{
|
||||
GskPath *path = gsk_path_measure_get_path (measure);
|
||||
|
||||
gsk_path_point_get_position (path, &point, res);
|
||||
gsk_path_point_get_tangent (path, &point, GSK_PATH_END, &tangent);
|
||||
|
||||
res->x -= (pt->y + offset->y) * scale * graphene_vec2_get_y (&tangent);
|
||||
res->y += (pt->y + offset->y) * scale * graphene_vec2_get_x (&tangent);
|
||||
}
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gtk_path_transform_op (GskPathOperation op,
|
||||
const graphene_point_t *pts,
|
||||
gsize n_pts,
|
||||
gpointer data)
|
||||
{
|
||||
GtkPathTransform *transform = data;
|
||||
|
||||
switch (op)
|
||||
{
|
||||
case GSK_PATH_MOVE:
|
||||
{
|
||||
graphene_point_t res;
|
||||
gtk_path_transform_point (transform->measure, &pts[0], &transform->offset, transform->scale, &res);
|
||||
gsk_path_builder_move_to (transform->builder, res.x, res.y);
|
||||
}
|
||||
break;
|
||||
|
||||
case GSK_PATH_LINE:
|
||||
{
|
||||
graphene_point_t res;
|
||||
gtk_path_transform_point (transform->measure, &pts[1], &transform->offset, transform->scale, &res);
|
||||
gsk_path_builder_line_to (transform->builder, res.x, res.y);
|
||||
}
|
||||
break;
|
||||
|
||||
case GSK_PATH_QUAD:
|
||||
{
|
||||
graphene_point_t res[2];
|
||||
gtk_path_transform_point (transform->measure, &pts[1], &transform->offset, transform->scale, &res[0]);
|
||||
gtk_path_transform_point (transform->measure, &pts[2], &transform->offset, transform->scale, &res[1]);
|
||||
gsk_path_builder_quad_to (transform->builder, res[0].x, res[0].y, res[1].x, res[1].y);
|
||||
}
|
||||
break;
|
||||
|
||||
case GSK_PATH_CUBIC:
|
||||
{
|
||||
graphene_point_t res[3];
|
||||
gtk_path_transform_point (transform->measure, &pts[1], &transform->offset, transform->scale, &res[0]);
|
||||
gtk_path_transform_point (transform->measure, &pts[2], &transform->offset, transform->scale, &res[1]);
|
||||
gtk_path_transform_point (transform->measure, &pts[3], &transform->offset, transform->scale, &res[2]);
|
||||
gsk_path_builder_cubic_to (transform->builder, res[0].x, res[0].y, res[1].x, res[1].y, res[2].x, res[2].y);
|
||||
}
|
||||
break;
|
||||
|
||||
case GSK_PATH_CLOSE:
|
||||
gsk_path_builder_close (transform->builder);
|
||||
break;
|
||||
|
||||
default:
|
||||
g_assert_not_reached();
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static GskPath *
|
||||
gtk_path_transform (GskPathMeasure *measure,
|
||||
GskPath *path,
|
||||
const graphene_point_t *offset)
|
||||
{
|
||||
GtkPathTransform transform = { measure, gsk_path_builder_new (), *offset };
|
||||
graphene_rect_t bounds;
|
||||
|
||||
gsk_path_get_bounds (path, &bounds);
|
||||
if (bounds.origin.x + bounds.size.width > 0)
|
||||
transform.scale = gsk_path_measure_get_length (measure) / (bounds.origin.x + bounds.size.width);
|
||||
else
|
||||
transform.scale = 1.0f;
|
||||
|
||||
gsk_path_foreach (path, -1, gtk_path_transform_op, &transform);
|
||||
|
||||
return gsk_path_builder_free_to_path (transform.builder);
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_path_widget_clear_text_path (GtkPathWidget *self)
|
||||
{
|
||||
g_clear_pointer (&self->text_path, gsk_path_unref);
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_path_widget_clear_paths (GtkPathWidget *self)
|
||||
{
|
||||
gtk_path_widget_clear_text_path (self);
|
||||
|
||||
g_clear_pointer (&self->line_path, gsk_path_unref);
|
||||
g_clear_pointer (&self->line_measure, gsk_path_measure_unref);
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_path_widget_create_text_path (GtkPathWidget *self)
|
||||
{
|
||||
GskPath *path;
|
||||
graphene_point_t offset;
|
||||
|
||||
gtk_path_widget_clear_text_path (self);
|
||||
|
||||
if (self->line_measure == NULL)
|
||||
return;
|
||||
|
||||
path = create_path_from_text (GTK_WIDGET (self), self->text, &offset);
|
||||
self->text_path = gtk_path_transform (self->line_measure, path, &offset);
|
||||
|
||||
gsk_path_unref (path);
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_path_widget_create_paths (GtkPathWidget *self)
|
||||
{
|
||||
double width = gtk_widget_get_width (GTK_WIDGET (self));
|
||||
double height = gtk_widget_get_height (GTK_WIDGET (self));
|
||||
GskPathBuilder *builder;
|
||||
|
||||
gtk_path_widget_clear_paths (self);
|
||||
|
||||
if (width <= 0 || height <= 0)
|
||||
return;
|
||||
|
||||
builder = gsk_path_builder_new ();
|
||||
gsk_path_builder_move_to (builder,
|
||||
self->points[0].x * width, self->points[0].y * height);
|
||||
gsk_path_builder_cubic_to (builder,
|
||||
self->points[1].x * width, self->points[1].y * height,
|
||||
self->points[2].x * width, self->points[2].y * height,
|
||||
self->points[3].x * width, self->points[3].y * height);
|
||||
self->line_path = gsk_path_builder_free_to_path (builder);
|
||||
|
||||
self->line_measure = gsk_path_measure_new (self->line_path);
|
||||
|
||||
gtk_path_widget_create_text_path (self);
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_path_widget_allocate (GtkWidget *widget,
|
||||
int width,
|
||||
int height,
|
||||
int baseline)
|
||||
{
|
||||
GtkPathWidget *self = GTK_PATH_WIDGET (widget);
|
||||
|
||||
GTK_WIDGET_CLASS (gtk_path_widget_parent_class)->size_allocate (widget, width, height, baseline);
|
||||
|
||||
gtk_path_widget_create_paths (self);
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_path_widget_snapshot (GtkWidget *widget,
|
||||
GtkSnapshot *snapshot)
|
||||
{
|
||||
GtkPathWidget *self = GTK_PATH_WIDGET (widget);
|
||||
double width = gtk_widget_get_width (widget);
|
||||
double height = gtk_widget_get_height (widget);
|
||||
GskPath *path;
|
||||
GskStroke *stroke;
|
||||
gsize i;
|
||||
|
||||
/* frosted glass the background */
|
||||
gtk_snapshot_push_blur (snapshot, 100);
|
||||
gdk_paintable_snapshot (self->background, snapshot, width, height);
|
||||
gtk_snapshot_append_color (snapshot, &(GdkRGBA) { 1, 1, 1, 0.6 }, &GRAPHENE_RECT_INIT (0, 0, width, height));
|
||||
gtk_snapshot_pop (snapshot);
|
||||
|
||||
/* draw the text */
|
||||
if (self->text_path)
|
||||
{
|
||||
gtk_snapshot_push_fill (snapshot, self->text_path, GSK_FILL_RULE_WINDING);
|
||||
gdk_paintable_snapshot (self->background, snapshot, width, height);
|
||||
|
||||
/* ... with an emboss effect */
|
||||
stroke = gsk_stroke_new (2.0);
|
||||
gtk_snapshot_translate (snapshot, &GRAPHENE_POINT_INIT(1, 1));
|
||||
gtk_snapshot_push_stroke (snapshot, self->text_path, stroke);
|
||||
gtk_snapshot_append_color (snapshot, &(GdkRGBA) { 0, 0, 0, 0.2 }, &GRAPHENE_RECT_INIT (0, 0, width, height));
|
||||
gsk_stroke_free (stroke);
|
||||
gtk_snapshot_pop (snapshot);
|
||||
|
||||
gtk_snapshot_pop (snapshot);
|
||||
}
|
||||
|
||||
if (self->editable && self->line_path)
|
||||
{
|
||||
GskPathBuilder *builder;
|
||||
|
||||
/* draw the control line */
|
||||
stroke = gsk_stroke_new (1.0);
|
||||
gtk_snapshot_push_stroke (snapshot, self->line_path, stroke);
|
||||
gsk_stroke_free (stroke);
|
||||
gtk_snapshot_append_color (snapshot, &(GdkRGBA) { 0, 0, 0, 1 }, &GRAPHENE_RECT_INIT (0, 0, width, height));
|
||||
gtk_snapshot_pop (snapshot);
|
||||
|
||||
/* draw the points */
|
||||
builder = gsk_path_builder_new ();
|
||||
for (i = 0; i < 4; i++)
|
||||
{
|
||||
gsk_path_builder_add_circle (builder, &GRAPHENE_POINT_INIT (self->points[i].x * width, self->points[i].y * height), POINT_SIZE);
|
||||
}
|
||||
path = gsk_path_builder_free_to_path (builder);
|
||||
|
||||
gtk_snapshot_push_fill (snapshot, path, GSK_FILL_RULE_WINDING);
|
||||
gtk_snapshot_append_color (snapshot, &(GdkRGBA) { 1, 1, 1, 1 }, &GRAPHENE_RECT_INIT (0, 0, width, height));
|
||||
gtk_snapshot_pop (snapshot);
|
||||
|
||||
stroke = gsk_stroke_new (1.0);
|
||||
gtk_snapshot_push_stroke (snapshot, path, stroke);
|
||||
gsk_stroke_free (stroke);
|
||||
gtk_snapshot_append_color (snapshot, &(GdkRGBA) { 0, 0, 0, 1 }, &GRAPHENE_RECT_INIT (0, 0, width, height));
|
||||
gtk_snapshot_pop (snapshot);
|
||||
|
||||
gsk_path_unref (path);
|
||||
}
|
||||
|
||||
if (self->line_closest >= 0)
|
||||
{
|
||||
GskPathBuilder *builder;
|
||||
GskPathPoint point;
|
||||
graphene_point_t closest;
|
||||
|
||||
builder = gsk_path_builder_new ();
|
||||
if (gsk_path_measure_get_point (self->line_measure, self->line_closest, &point))
|
||||
{
|
||||
gsk_path_point_get_position (self->line_path, &point, &closest);
|
||||
gsk_path_builder_add_circle (builder, &closest, POINT_SIZE);
|
||||
path = gsk_path_builder_free_to_path (builder);
|
||||
|
||||
gtk_snapshot_push_fill (snapshot, path, GSK_FILL_RULE_WINDING);
|
||||
gtk_snapshot_append_color (snapshot, &(GdkRGBA) { 0, 0, 1, 1 }, &GRAPHENE_RECT_INIT (0, 0, width, height));
|
||||
gtk_snapshot_pop (snapshot);
|
||||
|
||||
gsk_path_unref (path);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_path_widget_set_text (GtkPathWidget *self,
|
||||
const char *text)
|
||||
{
|
||||
if (g_strcmp0 (self->text, text) == 0)
|
||||
return;
|
||||
|
||||
g_free (self->text);
|
||||
self->text = g_strdup (text);
|
||||
|
||||
gtk_path_widget_create_paths (self);
|
||||
|
||||
gtk_widget_queue_draw (GTK_WIDGET (self));
|
||||
|
||||
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_TEXT]);
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_path_widget_set_editable (GtkPathWidget *self,
|
||||
gboolean editable)
|
||||
{
|
||||
if (self->editable == editable)
|
||||
return;
|
||||
|
||||
self->editable = editable;
|
||||
|
||||
gtk_widget_queue_draw (GTK_WIDGET (self));
|
||||
|
||||
g_object_notify_by_pspec (G_OBJECT (self), properties[PROP_EDITABLE]);
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_path_widget_set_property (GObject *object,
|
||||
guint prop_id,
|
||||
const GValue *value,
|
||||
GParamSpec *pspec)
|
||||
|
||||
{
|
||||
GtkPathWidget *self = GTK_PATH_WIDGET (object);
|
||||
|
||||
switch (prop_id)
|
||||
{
|
||||
case PROP_TEXT:
|
||||
gtk_path_widget_set_text (self, g_value_get_string (value));
|
||||
break;
|
||||
|
||||
case PROP_EDITABLE:
|
||||
gtk_path_widget_set_editable (self, g_value_get_boolean (value));
|
||||
break;
|
||||
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_path_widget_get_property (GObject *object,
|
||||
guint prop_id,
|
||||
GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
GtkPathWidget *self = GTK_PATH_WIDGET (object);
|
||||
|
||||
switch (prop_id)
|
||||
{
|
||||
case PROP_TEXT:
|
||||
g_value_set_string (value, self->text);
|
||||
break;
|
||||
|
||||
case PROP_EDITABLE:
|
||||
g_value_set_boolean (value, self->editable);
|
||||
break;
|
||||
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_path_widget_dispose (GObject *object)
|
||||
{
|
||||
GtkPathWidget *self = GTK_PATH_WIDGET (object);
|
||||
|
||||
gtk_path_widget_clear_paths (self);
|
||||
|
||||
G_OBJECT_CLASS (gtk_path_widget_parent_class)->dispose (object);
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_path_widget_class_init (GtkPathWidgetClass *klass)
|
||||
{
|
||||
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
|
||||
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
||||
|
||||
object_class->dispose = gtk_path_widget_dispose;
|
||||
object_class->set_property = gtk_path_widget_set_property;
|
||||
object_class->get_property = gtk_path_widget_get_property;
|
||||
|
||||
widget_class->size_allocate = gtk_path_widget_allocate;
|
||||
widget_class->snapshot = gtk_path_widget_snapshot;
|
||||
|
||||
properties[PROP_TEXT] =
|
||||
g_param_spec_string ("text",
|
||||
"text",
|
||||
"Text transformed along a path",
|
||||
NULL,
|
||||
G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS);
|
||||
|
||||
properties[PROP_EDITABLE] =
|
||||
g_param_spec_boolean ("editable",
|
||||
"editable",
|
||||
"If the path can be edited by the user",
|
||||
FALSE,
|
||||
G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY | G_PARAM_STATIC_STRINGS);
|
||||
|
||||
g_object_class_install_properties (object_class, N_PROPS, properties);
|
||||
}
|
||||
|
||||
static void
|
||||
drag_begin (GtkGestureDrag *gesture,
|
||||
double x,
|
||||
double y,
|
||||
GtkPathWidget *self)
|
||||
{
|
||||
graphene_point_t mouse = GRAPHENE_POINT_INIT (x, y);
|
||||
double width = gtk_widget_get_width (GTK_WIDGET (self));
|
||||
double height = gtk_widget_get_height (GTK_WIDGET (self));
|
||||
gsize i;
|
||||
|
||||
for (i = 0; i < 4; i++)
|
||||
{
|
||||
if (graphene_point_distance (&GRAPHENE_POINT_INIT (self->points[i].x * width, self->points[i].y * height), &mouse, NULL, NULL) <= POINT_SIZE)
|
||||
{
|
||||
self->active_point = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (i == 4)
|
||||
{
|
||||
gtk_gesture_set_state (GTK_GESTURE (gesture), GTK_EVENT_SEQUENCE_DENIED);
|
||||
return;
|
||||
}
|
||||
|
||||
gtk_widget_queue_draw (GTK_WIDGET (self));
|
||||
}
|
||||
|
||||
static void
|
||||
drag_update (GtkGestureDrag *drag,
|
||||
double offset_x,
|
||||
double offset_y,
|
||||
GtkPathWidget *self)
|
||||
{
|
||||
double width = gtk_widget_get_width (GTK_WIDGET (self));
|
||||
double height = gtk_widget_get_height (GTK_WIDGET (self));
|
||||
double start_x, start_y;
|
||||
|
||||
gtk_gesture_drag_get_start_point (drag, &start_x, &start_y);
|
||||
|
||||
self->points[self->active_point] = GRAPHENE_POINT_INIT ((start_x + offset_x) / width,
|
||||
(start_y + offset_y) / height);
|
||||
self->points[self->active_point].x = CLAMP (self->points[self->active_point].x, 0, 1);
|
||||
self->points[self->active_point].y = CLAMP (self->points[self->active_point].y, 0, 1);
|
||||
|
||||
gtk_path_widget_create_paths (self);
|
||||
|
||||
gtk_widget_queue_draw (GTK_WIDGET (self));
|
||||
}
|
||||
|
||||
static void
|
||||
pointer_motion (GtkEventControllerMotion *controller,
|
||||
double x,
|
||||
double y,
|
||||
GtkPathWidget *self)
|
||||
{
|
||||
GskPathPoint point;
|
||||
graphene_point_t pos;
|
||||
|
||||
if (gsk_path_get_closest_point (gsk_path_measure_get_path (self->line_measure),
|
||||
&GRAPHENE_POINT_INIT (x, y),
|
||||
INFINITY,
|
||||
&point))
|
||||
{
|
||||
gsk_path_point_get_position (self->line_path, &point, &pos);
|
||||
self->line_closest = graphene_point_distance (&pos, &GRAPHENE_POINT_INIT (x, y), NULL, NULL);
|
||||
|
||||
gtk_widget_queue_draw (GTK_WIDGET (self));
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
pointer_leave (GtkEventControllerMotion *controller,
|
||||
GtkPathWidget *self)
|
||||
{
|
||||
self->line_closest = -1;
|
||||
|
||||
gtk_widget_queue_draw (GTK_WIDGET (self));
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_path_widget_init (GtkPathWidget *self)
|
||||
{
|
||||
GtkEventController *controller;
|
||||
|
||||
controller = GTK_EVENT_CONTROLLER (gtk_gesture_drag_new ());
|
||||
g_signal_connect (controller, "drag-begin", G_CALLBACK (drag_begin), self);
|
||||
g_signal_connect (controller, "drag-update", G_CALLBACK (drag_update), self);
|
||||
g_signal_connect (controller, "drag-end", G_CALLBACK (drag_update), self);
|
||||
gtk_widget_add_controller (GTK_WIDGET (self), controller);
|
||||
|
||||
controller = GTK_EVENT_CONTROLLER (gtk_event_controller_motion_new ());
|
||||
g_signal_connect (controller, "enter", G_CALLBACK (pointer_motion), self);
|
||||
g_signal_connect (controller, "motion", G_CALLBACK (pointer_motion), self);
|
||||
g_signal_connect (controller, "leave", G_CALLBACK (pointer_leave), self);
|
||||
gtk_widget_add_controller (GTK_WIDGET (self), controller);
|
||||
|
||||
self->line_closest = -1;
|
||||
|
||||
self->points[0] = GRAPHENE_POINT_INIT (0.1, 0.9);
|
||||
self->points[1] = GRAPHENE_POINT_INIT (0.3, 0.1);
|
||||
self->points[2] = GRAPHENE_POINT_INIT (0.7, 0.1);
|
||||
self->points[3] = GRAPHENE_POINT_INIT (0.9, 0.9);
|
||||
|
||||
self->background = GDK_PAINTABLE (gdk_texture_new_from_resource ("/sliding_puzzle/portland-rose.jpg"));
|
||||
|
||||
gtk_path_widget_set_text (self, "It's almost working");
|
||||
}
|
||||
|
||||
GtkWidget *
|
||||
gtk_path_widget_new (void)
|
||||
{
|
||||
GtkPathWidget *self;
|
||||
|
||||
self = g_object_new (GTK_TYPE_PATH_WIDGET, NULL);
|
||||
|
||||
return GTK_WIDGET (self);
|
||||
}
|
||||
|
||||
GtkWidget *
|
||||
do_path_text (GtkWidget *do_widget)
|
||||
{
|
||||
static GtkWidget *window = NULL;
|
||||
|
||||
if (!window)
|
||||
{
|
||||
GtkBuilder *builder;
|
||||
|
||||
g_type_ensure (GTK_TYPE_PATH_WIDGET);
|
||||
|
||||
builder = gtk_builder_new_from_resource ("/path_text/path_text.ui");
|
||||
window = GTK_WIDGET (gtk_builder_get_object (builder, "window"));
|
||||
gtk_window_set_display (GTK_WINDOW (window),
|
||||
gtk_widget_get_display (do_widget));
|
||||
g_object_add_weak_pointer (G_OBJECT (window), (gpointer *) &window);
|
||||
g_object_unref (builder);
|
||||
}
|
||||
|
||||
if (!gtk_widget_get_visible (window))
|
||||
gtk_window_present (GTK_WINDOW (window));
|
||||
else
|
||||
gtk_window_destroy (GTK_WINDOW (window));
|
||||
|
||||
return window;
|
||||
}
|
||||
38
demos/gtk-demo/path_text.ui
Normal file
@@ -0,0 +1,38 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<interface>
|
||||
<object class="GtkWindow" id="window">
|
||||
<property name="title" translatable="yes">Text along a Path</property>
|
||||
<child type="titlebar">
|
||||
<object class="GtkHeaderBar">
|
||||
<child type="end">
|
||||
<object class="GtkToggleButton" id="edit-toggle">
|
||||
<property name="icon-name">document-edit-symbolic</property>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkBox">
|
||||
<property name="orientation">vertical</property>
|
||||
<child>
|
||||
<object class="GtkRevealer">
|
||||
<property name="reveal-child" bind-source="edit-toggle" bind-property="active" bind-flags="sync-create"></property>
|
||||
<child>
|
||||
<object class="GtkEntry" id="text">
|
||||
<property name="text">Through the looking glass</property>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
<child>
|
||||
<object class="GtkPathWidget" id="view">
|
||||
<property name="editable" bind-source="edit-toggle" bind-property="active" bind-flags="sync-create"></property>
|
||||
<property name="text" bind-source="text" bind-property="text" bind-flags="sync-create"></property>
|
||||
<property name="hexpand">true</property>
|
||||
<property name="vexpand">true</property>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</child>
|
||||
</object>
|
||||
</interface>
|
||||
@@ -34,11 +34,5 @@ base_url = "https://gitlab.gnome.org/GNOME/gtk/-/blob/main/"
|
||||
[extra]
|
||||
content_images = [
|
||||
"gtk-logo.svg",
|
||||
"images/caps-dark.png",
|
||||
"images/caps-light.png",
|
||||
"images/join-dark.png",
|
||||
"images/join-light.png",
|
||||
"images/path-dark.png",
|
||||
"images/path-light.png",
|
||||
]
|
||||
urlmap_file = "urlmap.js"
|
||||
|
||||
|
Before Width: | Height: | Size: 11 KiB |
|
Before Width: | Height: | Size: 12 KiB |
@@ -1,81 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<!-- Created with Inkscape (http://www.inkscape.org/) -->
|
||||
|
||||
<svg
|
||||
width="210mm"
|
||||
height="297mm"
|
||||
viewBox="0 0 210 297"
|
||||
version="1.1"
|
||||
id="svg1"
|
||||
inkscape:version="1.3 (0e150ed6c4, 2023-07-21)"
|
||||
sodipodi:docname="caps.svg"
|
||||
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
xmlns:svg="http://www.w3.org/2000/svg">
|
||||
<sodipodi:namedview
|
||||
id="namedview1"
|
||||
pagecolor="#ffffff"
|
||||
bordercolor="#000000"
|
||||
borderopacity="0.25"
|
||||
inkscape:showpageshadow="2"
|
||||
inkscape:pageopacity="0.0"
|
||||
inkscape:pagecheckerboard="0"
|
||||
inkscape:deskcolor="#d1d1d1"
|
||||
inkscape:document-units="mm"
|
||||
inkscape:zoom="2.1493149"
|
||||
inkscape:cx="438.74445"
|
||||
inkscape:cy="288.69664"
|
||||
inkscape:window-width="1920"
|
||||
inkscape:window-height="1123"
|
||||
inkscape:window-x="0"
|
||||
inkscape:window-y="0"
|
||||
inkscape:window-maximized="1"
|
||||
inkscape:current-layer="layer1" />
|
||||
<defs
|
||||
id="defs1">
|
||||
<linearGradient
|
||||
id="swatch1"
|
||||
inkscape:swatch="solid">
|
||||
<stop
|
||||
style="stop-color:#000000;stop-opacity:1;"
|
||||
offset="0"
|
||||
id="stop1" />
|
||||
</linearGradient>
|
||||
</defs>
|
||||
<g
|
||||
inkscape:label="Layer 1"
|
||||
inkscape:groupmode="layer"
|
||||
id="layer1">
|
||||
<path
|
||||
style="fill:none;stroke:#000064;stroke-width:1;stroke-miterlimit:0;stroke-dasharray:none"
|
||||
d="m 73.096455,77.084329 c 0,0 6.439436,18.711677 18.172676,26.635721"
|
||||
id="path1"
|
||||
sodipodi:nodetypes="cc" />
|
||||
<path
|
||||
style="color:#000000;fill:none;stroke:#000064;stroke-width:0.2;stroke-miterlimit:10;stroke-dasharray:none;stroke-opacity:1"
|
||||
d="m 94.214979,99.722163 c -4.705477,-3.177832 -9.013472,-9.233699 -11.888672,-14.531169 -2.8752,-5.29748 -4.353516,-9.587833 -4.353516,-9.587833 L 68.51576,78.85704 c 0,0 1.743663,5.064163 5.021484,11.103457 3.277822,6.039297 8.05428,13.302573 15.082031,18.048773"
|
||||
id="path1-1"
|
||||
sodipodi:nodetypes="csccsc" />
|
||||
<path
|
||||
style="fill:none;stroke:#000064;stroke-width:1;stroke-miterlimit:0;stroke-dasharray:none"
|
||||
d="m 112.14213,75.736452 c 0,0 6.43944,18.711675 18.17268,26.635728"
|
||||
id="path1-4"
|
||||
sodipodi:nodetypes="cc" />
|
||||
<path
|
||||
style="color:#000000;fill:none;stroke:#000064;stroke-width:0.2;stroke-linecap:round;stroke-miterlimit:0;stroke-dasharray:none;stroke-opacity:1"
|
||||
d="m 132.83284,98.590758 c -4.70551,-3.177807 -9.01347,-9.233742 -11.88867,-14.53125 -2.8752,-5.297508 -4.35351,-9.587891 -4.35351,-9.587891 -0.89828,-2.611719 -3.74396,-4.000453 -6.35547,-3.101562 -2.61172,0.898277 -4.00046,3.743958 -3.10157,6.355468 0,0 1.74367,5.064185 5.02149,11.103516 3.27782,6.039331 8.05428,13.302641 15.08203,18.048851"
|
||||
id="path1-4-5"
|
||||
sodipodi:nodetypes="cscccsc" />
|
||||
<path
|
||||
style="fill:none;stroke:#000064;stroke-width:1;stroke-miterlimit:0;stroke-dasharray:none"
|
||||
d="m 154.10911,73.84561 c 0,0 6.43943,18.711677 18.17267,26.63572"
|
||||
id="path1-0"
|
||||
sodipodi:nodetypes="cc" />
|
||||
<path
|
||||
style="color:#000000;fill:none;stroke:#000064;stroke-width:0.2;stroke-linecap:square;stroke-miterlimit:10;stroke-dasharray:none;stroke-opacity:1"
|
||||
d="M 175.16683,96.47344 C 170.46135,93.295592 166.1514,87.239699 163.2762,81.94219 160.401,76.644682 158.92269,72.3543 158.92269,72.3543 l -1.62696,-4.728516 -9.45508,3.253906 1.62696,4.728516 c 0,0 1.74171,5.066138 5.01953,11.105469 3.27782,6.039331 8.05428,13.300675 15.08203,18.046895"
|
||||
id="path1-4-1"
|
||||
sodipodi:nodetypes="csccccsc" />
|
||||
</g>
|
||||
</svg>
|
||||
|
Before Width: | Height: | Size: 3.6 KiB |
|
Before Width: | Height: | Size: 18 KiB |
|
Before Width: | Height: | Size: 21 KiB |
@@ -1,72 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<!-- Created with Inkscape (http://www.inkscape.org/) -->
|
||||
|
||||
<svg
|
||||
width="210mm"
|
||||
height="297mm"
|
||||
viewBox="0 0 210 297"
|
||||
version="1.1"
|
||||
id="svg1"
|
||||
inkscape:version="1.3 (0e150ed6c4, 2023-07-21)"
|
||||
sodipodi:docname="join.svg"
|
||||
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
xmlns:svg="http://www.w3.org/2000/svg">
|
||||
<sodipodi:namedview
|
||||
id="namedview1"
|
||||
pagecolor="#ffffff"
|
||||
bordercolor="#000000"
|
||||
borderopacity="0.25"
|
||||
inkscape:showpageshadow="2"
|
||||
inkscape:pageopacity="0.0"
|
||||
inkscape:pagecheckerboard="0"
|
||||
inkscape:deskcolor="#d1d1d1"
|
||||
inkscape:document-units="mm"
|
||||
inkscape:zoom="0.75989759"
|
||||
inkscape:cx="118.43701"
|
||||
inkscape:cy="570.47161"
|
||||
inkscape:window-width="1920"
|
||||
inkscape:window-height="1123"
|
||||
inkscape:window-x="0"
|
||||
inkscape:window-y="0"
|
||||
inkscape:window-maximized="1"
|
||||
inkscape:current-layer="layer1" />
|
||||
<defs
|
||||
id="defs1" />
|
||||
<g
|
||||
inkscape:label="Layer 1"
|
||||
inkscape:groupmode="layer"
|
||||
id="layer1">
|
||||
<path
|
||||
style="fill:none;stroke:#000064;stroke-width:1;stroke-linecap:square;stroke-miterlimit:10;stroke-dasharray:none"
|
||||
d="m 12.748727,122.15935 c 4.449842,-15.44496 4.175632,-15.92044 16.908788,-26.568585 0,0 8.478091,16.421195 35.150804,33.660325"
|
||||
id="path1"
|
||||
sodipodi:nodetypes="ccc" />
|
||||
<path
|
||||
style="color:#000000;fill:none;stroke:#000064;stroke-width:0.2;stroke-linecap:square;stroke-miterlimit:10;stroke-dasharray:none;stroke-opacity:1"
|
||||
d="m 17.59375,123.72266 c 3.810222,-13.2249 3.591775,-14.13123 11.107422,-20.53516 1.289688,1.82186 2.604788,3.71164 4.800781,6.23242 5.743296,6.59272 14.891452,15.32766 28.632813,24.20899 M 67.5625,125.23047 C 54.631174,116.87268 46.204933,108.77726 41.041016,102.84961 35.877098,96.921954 34.140625,93.474609 34.140625,93.474609 l -2.861328,-5.544922 -4.789063,4.003907 C 13.673794,102.6514 12.411529,105.58692 7.984375,120.95313"
|
||||
id="path1-3"
|
||||
sodipodi:nodetypes="ccsccscccc" />
|
||||
<path
|
||||
style="fill:none;stroke:#000064;stroke-width:1;stroke-linecap:square;stroke-miterlimit:10;stroke-dasharray:none"
|
||||
d="m 147.99215,122.60257 c 4.44988,-15.44499 4.17566,-15.92048 16.90889,-26.568657 0,0 8.47814,16.421267 35.15101,33.660397"
|
||||
id="path1-5"
|
||||
sodipodi:nodetypes="ccc" />
|
||||
<path
|
||||
style="color:#000000;fill:none;stroke:#000064;stroke-width:0.2;stroke-linecap:square;stroke-linejoin:bevel;stroke-miterlimit:10;stroke-dasharray:none;stroke-opacity:1"
|
||||
d="m 152.79687,123.98633 c 3.81053,-13.22586 3.59005,-14.12993 11.10743,-20.53516 1.28968,1.82184 2.6029,3.71173 4.79882,6.23242 5.74333,6.59274 14.89333,15.32961 28.63477,24.21094 m 5.42773,-8.40039 c -12.9314,-8.35778 -21.35753,-16.45123 -26.52148,-22.37891 -5.16395,-5.927668 -6.90039,-9.374996 -6.90039,-9.374996 l -7.65039,-1.541015 C 148.87685,102.91706 147.61469,105.85252 143.1875,121.21875"
|
||||
id="path1-5-8"
|
||||
sodipodi:nodetypes="ccsccsccc" />
|
||||
<path
|
||||
style="fill:none;stroke:#000064;stroke-width:1;stroke-linecap:square;stroke-miterlimit:10;stroke-dasharray:none"
|
||||
d="m 79.729342,122.0734 c 4.449844,-15.44499 4.175634,-15.92048 16.908794,-26.568654 0,0 8.478114,16.421264 35.150984,33.660394"
|
||||
id="path1-7"
|
||||
sodipodi:nodetypes="ccc" />
|
||||
<path
|
||||
style="color:#000000;fill:none;stroke:#000064;stroke-width:0.2;stroke-linecap:square;stroke-linejoin:round;stroke-miterlimit:10;stroke-dasharray:none;stroke-opacity:1"
|
||||
d="m 84.533203,123.19336 c 3.810222,-13.22495 3.591776,-14.1312 11.107422,-20.53516 1.289696,1.82187 2.604775,3.71164 4.800785,6.23243 5.74333,6.59275 14.89136,15.32765 28.63281,24.20898 m 5.42969,-8.39844 c -12.93141,-8.35778 -21.35949,-16.45122 -26.52344,-22.3789 -5.16395,-5.927686 -6.90039,-9.375004 -6.90039,-9.375004 -0.69636,-1.348401 -1.967393,-2.307601 -3.45508,-2.607422 -1.487509,-0.300132 -3.03083,0.09145 -4.195313,1.064453 C 80.61325,102.12215 79.350982,105.05756 74.923828,120.42383"
|
||||
id="path1-7-4"
|
||||
sodipodi:nodetypes="ccsccscccc" />
|
||||
</g>
|
||||
</svg>
|
||||
|
Before Width: | Height: | Size: 4.1 KiB |
|
Before Width: | Height: | Size: 18 KiB |
|
Before Width: | Height: | Size: 17 KiB |
@@ -1,108 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
|
||||
<!-- Created with Inkscape (http://www.inkscape.org/) -->
|
||||
|
||||
<svg
|
||||
width="210mm"
|
||||
height="297mm"
|
||||
viewBox="0 0 210 297"
|
||||
version="1.1"
|
||||
id="svg1"
|
||||
inkscape:version="1.3 (0e150ed6c4, 2023-07-21)"
|
||||
sodipodi:docname="path.svg"
|
||||
inkscape:export-filename="path-dark.png"
|
||||
inkscape:export-xdpi="96"
|
||||
inkscape:export-ydpi="96"
|
||||
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
|
||||
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
|
||||
xmlns="http://www.w3.org/2000/svg"
|
||||
xmlns:svg="http://www.w3.org/2000/svg">
|
||||
<sodipodi:namedview
|
||||
id="namedview1"
|
||||
pagecolor="#ffffff"
|
||||
bordercolor="#000000"
|
||||
borderopacity="0.25"
|
||||
inkscape:showpageshadow="2"
|
||||
inkscape:pageopacity="0.0"
|
||||
inkscape:pagecheckerboard="0"
|
||||
inkscape:deskcolor="#d1d1d1"
|
||||
inkscape:document-units="mm"
|
||||
inkscape:zoom="0.75989759"
|
||||
inkscape:cx="397.42198"
|
||||
inkscape:cy="561.25984"
|
||||
inkscape:window-width="1920"
|
||||
inkscape:window-height="1123"
|
||||
inkscape:window-x="0"
|
||||
inkscape:window-y="0"
|
||||
inkscape:window-maximized="1"
|
||||
inkscape:current-layer="layer1" />
|
||||
<defs
|
||||
id="defs1" />
|
||||
<g
|
||||
inkscape:label="Layer 1"
|
||||
inkscape:groupmode="layer"
|
||||
id="layer1">
|
||||
<path
|
||||
style="fill:none;fill-opacity:1;stroke:#000000;stroke-width:1;stroke-linecap:square;stroke-linejoin:bevel;stroke-miterlimit:10;stroke-dasharray:none;stroke-opacity:1"
|
||||
d="M 128.28233,149.47912 154.23127,90.244656 86.340809,68.820468"
|
||||
id="path3" />
|
||||
<path
|
||||
style="fill:none;stroke:#000000;stroke-width:1;stroke-linecap:square;stroke-linejoin:bevel;stroke-miterlimit:10;fill-opacity:1;stroke-dasharray:none;stroke-opacity:1"
|
||||
d="m 33.956804,113.31099 c -9.049189,-11.90893 5.40551,-40.570358 20.351208,-39.990271 26.687501,1.035822 4.06495,71.984581 30.695656,74.009711 19.642072,1.49368 41.962402,-34.42048 30.634382,-50.536241 C 99.663884,74.068616 50.763019,135.42833 33.956804,113.31099 Z"
|
||||
id="path1"
|
||||
sodipodi:nodetypes="sssss" />
|
||||
<circle
|
||||
style="fill:#ff0404;fill-opacity:1;stroke:#000000;stroke-width:0.2;stroke-linecap:square;stroke-linejoin:bevel;stroke-miterlimit:10;stroke-dasharray:none;stroke-opacity:1"
|
||||
id="path2"
|
||||
cx="34.517788"
|
||||
cy="113.66589"
|
||||
r="1.5" />
|
||||
<circle
|
||||
style="fill:#ff0404;fill-opacity:1;stroke:#000064;stroke-width:0.2;stroke-linecap:square;stroke-linejoin:bevel;stroke-miterlimit:10;stroke-dasharray:none"
|
||||
id="path2-8"
|
||||
cx="55.045853"
|
||||
cy="73.566689"
|
||||
r="1.5" />
|
||||
<circle
|
||||
style="fill:#ff0404;fill-opacity:1;stroke:#000064;stroke-width:0.2;stroke-linecap:square;stroke-linejoin:bevel;stroke-miterlimit:10;stroke-dasharray:none"
|
||||
id="path2-8-5"
|
||||
cx="55.045834"
|
||||
cy="73.831245"
|
||||
r="1.5" />
|
||||
<circle
|
||||
style="fill:#ff0404;fill-opacity:1;stroke:#000000;stroke-width:0.2;stroke-linecap:square;stroke-linejoin:bevel;stroke-miterlimit:10;stroke-dasharray:none;stroke-opacity:1"
|
||||
id="path2-8-9"
|
||||
cx="55.045834"
|
||||
cy="73.831245"
|
||||
r="1.5" />
|
||||
<circle
|
||||
style="fill:#ff0404;fill-opacity:1;stroke:#000000;stroke-width:0.2;stroke-linecap:square;stroke-linejoin:bevel;stroke-miterlimit:10;stroke-dasharray:none;stroke-opacity:1"
|
||||
id="path2-8-9-7"
|
||||
cx="86.398613"
|
||||
cy="68.897667"
|
||||
r="1.5" />
|
||||
<circle
|
||||
style="fill:#ff0404;fill-opacity:1;stroke:#000000;stroke-width:0.2;stroke-linecap:square;stroke-linejoin:bevel;stroke-miterlimit:10;stroke-dasharray:none;stroke-opacity:1"
|
||||
id="path2-8-9-7-8"
|
||||
cx="153.87553"
|
||||
cy="90.112595"
|
||||
r="1.5" />
|
||||
<circle
|
||||
style="fill:#ff0404;fill-opacity:1;stroke:#000064;stroke-width:0.2;stroke-linecap:square;stroke-linejoin:bevel;stroke-miterlimit:10;stroke-dasharray:none"
|
||||
id="path2-8-7"
|
||||
cx="84.803238"
|
||||
cy="147.51736"
|
||||
r="1.5" />
|
||||
<circle
|
||||
style="fill:#ff0404;fill-opacity:1;stroke:#000000;stroke-width:0.2;stroke-linecap:square;stroke-linejoin:bevel;stroke-miterlimit:10;stroke-dasharray:none;stroke-opacity:1"
|
||||
id="path2-8-7-2"
|
||||
cx="115.28235"
|
||||
cy="96.705284"
|
||||
r="1.5" />
|
||||
<circle
|
||||
style="fill:#ff0404;fill-opacity:1;stroke:#000000;stroke-width:0.2;stroke-linecap:square;stroke-linejoin:bevel;stroke-miterlimit:10;stroke-dasharray:none;stroke-opacity:1"
|
||||
id="path2-8-9-7-9"
|
||||
cx="127.92362"
|
||||
cy="150.03427"
|
||||
r="1.5" />
|
||||
</g>
|
||||
</svg>
|
||||
|
Before Width: | Height: | Size: 4.4 KiB |
@@ -1,181 +0,0 @@
|
||||
.. _gtk4-path-tool(1):
|
||||
|
||||
=================
|
||||
gtk4-path-tool
|
||||
=================
|
||||
|
||||
-----------------------
|
||||
GskPath Utility
|
||||
-----------------------
|
||||
|
||||
SYNOPSIS
|
||||
--------
|
||||
| **gtk4-path-tool** <COMMAND> [OPTIONS...] <PATH>
|
||||
|
|
||||
| **gtk4-path-tool** decompose [OPTIONS...] <PATH>
|
||||
| **gtk4-path-tool** show [OPTIONS...] <PATH>
|
||||
| **gtk4-path-tool** render [OPTIONS...] <PATH>
|
||||
| **gtk4-path-tool** info [OPTIONS...] <PATH>
|
||||
|
||||
DESCRIPTION
|
||||
-----------
|
||||
|
||||
``gtk4-path-tool`` can perform various tasks on paths. Paths are specified
|
||||
in SVG syntax, as strings like "M 100 100 C 100 200 200 200 200 100 Z".
|
||||
|
||||
To read a path from a file, use a filename that starts with a '.' or a '/'.
|
||||
To read a path from stdin, use '-'.
|
||||
|
||||
COMMANDS
|
||||
--------
|
||||
|
||||
Decomposing
|
||||
^^^^^^^^^^^
|
||||
|
||||
The ``decompose`` command approximates the path by one with simpler elements.
|
||||
When used without options, the curves of the path are approximated by line
|
||||
segments.
|
||||
|
||||
``--allow-quad``
|
||||
|
||||
Allow quadratic Bézier curves to be used in the generated path.
|
||||
|
||||
``--allow-cubic``
|
||||
|
||||
Allow cubic Bézier curves to be used in the generated path.
|
||||
|
||||
Showing
|
||||
^^^^^^^
|
||||
|
||||
The ``show`` command displays the given path in a window. The interior
|
||||
of the path is filled.
|
||||
|
||||
``--fill-rule=VALUE``
|
||||
|
||||
The fill rule that is used to determine what areas are inside the path.
|
||||
The possible values are ``winding`` or ``even-odd``. The default is ``winding``.
|
||||
|
||||
``--fg-color=COLOR``
|
||||
|
||||
The color that is used to fill the interior of the path or stroke the path.
|
||||
If not specified, black is used.
|
||||
|
||||
``--bg-color=COLOR``
|
||||
|
||||
The color that is used to render the background behind the path.
|
||||
If not specified, white is used.
|
||||
|
||||
``--stroke``
|
||||
|
||||
Stroke the path instead of filling it.
|
||||
|
||||
``--line-width=VALUE``
|
||||
|
||||
The line width to use for the stroke. ``VALUE`` must be a positive number.
|
||||
The default line width is 1.
|
||||
|
||||
``--line-cap=VALUE``
|
||||
|
||||
The cap style to use at line ends. The possible values are ``butt``, ``round``
|
||||
or ``square``. See the SVG specification for details on these styles.
|
||||
The default cap style is ``butt``.
|
||||
|
||||
``--line-join=VALUE``
|
||||
|
||||
The join style to use at line joins. The possible values are ``miter``,
|
||||
``miter-clip``, ``round``, ``bevel`` or ``arcs``. See the SVG specification
|
||||
for details on these styles.
|
||||
The default join style is ``miter``.
|
||||
|
||||
``--miter-limit=VALUE``
|
||||
|
||||
The limit at which to clip miters at line joins. The default value is 4.
|
||||
|
||||
``--dashes=VALUE``
|
||||
|
||||
The dash pattern to use for this stroke. A dash pattern is specified by
|
||||
a comma-separated list of alternating non-negative numbers. Each number
|
||||
provides the length of alternate "on" and "off" portions of the stroke.
|
||||
If the dash pattern is empty, dashing is disabled, which is the default.
|
||||
See the SVG specification for details on dashing.
|
||||
|
||||
``--dash-offset=VALUE``
|
||||
|
||||
The offset into the dash pattern where dashing should begin.
|
||||
The default value is 0.
|
||||
|
||||
Rendering
|
||||
^^^^^^^^^
|
||||
|
||||
The ``render`` command renders the given path as a PNG image.
|
||||
The interior of the path is filled.
|
||||
|
||||
``--fill-rule=VALUE``
|
||||
|
||||
The fill rule that is used to determine what areas are inside the path.
|
||||
The possible values are ``winding`` or ``even-odd``. The default is ``winding``.
|
||||
|
||||
``--fg-color=COLOR``
|
||||
|
||||
The color that is used to fill the interior of the path or stroke the path.
|
||||
If not specified, black is used.
|
||||
|
||||
``--bg-color=COLOR``
|
||||
|
||||
The color that is used to render the background behind the path.
|
||||
If not specified, white is used.
|
||||
|
||||
``--output-file=FILE``
|
||||
|
||||
The file to save the PNG image to.
|
||||
If not specified, "path.png" is used.
|
||||
|
||||
``--stroke``
|
||||
|
||||
Stroke the path instead of filling it.
|
||||
|
||||
``--line-width=VALUE``
|
||||
|
||||
The line width to use for the stroke. ``VALUE`` must be a positive number.
|
||||
The default line width is 1.
|
||||
|
||||
``--line-cap=VALUE``
|
||||
|
||||
The cap style to use at line ends. The possible values are ``butt``, ``round``
|
||||
or ``square``. See the SVG specification for details on these styles.
|
||||
The default cap style is ``butt``.
|
||||
|
||||
``--line-join=VALUE``
|
||||
|
||||
The join style to use at line joins. The possible values are ``miter``,
|
||||
``miter-clip``, ``round``, ``bevel`` or ``arcs``. See the SVG specification
|
||||
for details on these styles.
|
||||
The default join style is ``miter``.
|
||||
|
||||
``--miter-limit=VALUE``
|
||||
|
||||
The limit at which to clip miters at line joins. The default value is 4.
|
||||
|
||||
``--dashes=VALUE``
|
||||
|
||||
The dash pattern to use for this stroke. A dash pattern is specified by
|
||||
a comma-separated list of alternating non-negative numbers. Each number
|
||||
provides the length of alternate "on" and "off" portions of the stroke.
|
||||
If the dash pattern is empty, dashing is disabled, which is the default.
|
||||
See the SVG specification for details on dashing.
|
||||
|
||||
``--dash-offset=VALUE``
|
||||
|
||||
The offset into the dash pattern where dashing should begin.
|
||||
The default value is 0.
|
||||
|
||||
Info
|
||||
^^^^
|
||||
|
||||
The ``info`` command shows various information about the given path,
|
||||
such as its bounding box.
|
||||
|
||||
REFERENCES
|
||||
----------
|
||||
|
||||
- SVG Path Specification, https://www.w3.org/TR/SVG2/paths.html
|
||||
@@ -77,7 +77,6 @@ if get_option('man-pages') and rst2man.found()
|
||||
[ 'gtk4-query-settings', '1', ],
|
||||
[ 'gtk4-rendernode-tool', '1' ],
|
||||
[ 'gtk4-update-icon-cache', '1', ],
|
||||
[ 'gtk4-path-tool', '1', ],
|
||||
]
|
||||
|
||||
if get_option('demos')
|
||||
|
||||
@@ -297,7 +297,7 @@ gdk_clipboard_read_local_async (GdkClipboard *clipboard,
|
||||
{
|
||||
GOutputStream *output_stream;
|
||||
GIOStream *stream;
|
||||
|
||||
|
||||
stream = gdk_pipe_io_stream_new ();
|
||||
output_stream = g_io_stream_get_output_stream (stream);
|
||||
gdk_clipboard_write_async (clipboard,
|
||||
@@ -767,7 +767,7 @@ gdk_clipboard_read_value_internal (GdkClipboard *clipboard,
|
||||
GdkContentFormats *formats;
|
||||
GValue *value;
|
||||
GTask *task;
|
||||
|
||||
|
||||
task = g_task_new (clipboard, cancellable, callback, user_data);
|
||||
g_task_set_priority (task, io_priority);
|
||||
g_task_set_source_tag (task, source_tag);
|
||||
@@ -946,7 +946,7 @@ gdk_clipboard_read_texture_finish (GdkClipboard *clipboard,
|
||||
value = g_task_propagate_pointer (G_TASK (result), error);
|
||||
if (!value)
|
||||
return NULL;
|
||||
|
||||
|
||||
return g_value_dup_object (value);
|
||||
}
|
||||
|
||||
@@ -1011,7 +1011,7 @@ gdk_clipboard_read_text_finish (GdkClipboard *clipboard,
|
||||
value = g_task_propagate_pointer (G_TASK (result), error);
|
||||
if (!value)
|
||||
return NULL;
|
||||
|
||||
|
||||
return g_value_dup_string (value);
|
||||
}
|
||||
|
||||
@@ -1110,7 +1110,7 @@ gdk_clipboard_write_async (GdkClipboard *clipboard,
|
||||
GError *error = NULL;
|
||||
|
||||
g_assert (gtype != G_TYPE_INVALID);
|
||||
|
||||
|
||||
g_value_init (&value, gtype);
|
||||
if (gdk_content_provider_get_value (priv->content, &value, &error))
|
||||
{
|
||||
@@ -1126,7 +1126,7 @@ gdk_clipboard_write_async (GdkClipboard *clipboard,
|
||||
{
|
||||
g_task_return_error (task, error);
|
||||
}
|
||||
|
||||
|
||||
g_value_unset (&value);
|
||||
}
|
||||
else
|
||||
@@ -1148,7 +1148,7 @@ gdk_clipboard_write_finish (GdkClipboard *clipboard,
|
||||
g_return_val_if_fail (g_task_is_valid (result, clipboard), FALSE);
|
||||
g_return_val_if_fail (g_task_get_source_tag (G_TASK (result)) == gdk_clipboard_write_async, FALSE);
|
||||
|
||||
return g_task_propagate_boolean (G_TASK (result), error);
|
||||
return g_task_propagate_boolean (G_TASK (result), error);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
@@ -1248,8 +1248,8 @@ gdk_clipboard_set_content (GdkClipboard *clipboard,
|
||||
* Sets the clipboard to contain the value collected from the given varargs.
|
||||
*
|
||||
* Values should be passed the same way they are passed to other value
|
||||
* collecting APIs, such as [method@GObject.Object.set] or
|
||||
* [func@GObject.signal_emit].
|
||||
* collecting APIs, such as [`method@GObject.Object.set`] or
|
||||
* [`func@GObject.signal_emit`].
|
||||
*
|
||||
* ```c
|
||||
* gdk_clipboard_set (clipboard, GTK_TYPE_STRING, "Hello World");
|
||||
@@ -1263,7 +1263,7 @@ gdk_clipboard_set (GdkClipboard *clipboard,
|
||||
...)
|
||||
{
|
||||
va_list args;
|
||||
|
||||
|
||||
g_return_if_fail (GDK_IS_CLIPBOARD (clipboard));
|
||||
|
||||
va_start (args, type);
|
||||
|
||||
@@ -1528,8 +1528,7 @@ gdk_gl_context_check_extensions (GdkGLContext *context)
|
||||
|
||||
if (gdk_gl_context_get_use_es (context))
|
||||
{
|
||||
priv->has_unpack_subimage = gdk_gl_version_greater_equal (&priv->gl_version, &GDK_GL_VERSION_INIT (3, 0)) ||
|
||||
epoxy_has_gl_extension ("GL_EXT_unpack_subimage");
|
||||
priv->has_unpack_subimage = epoxy_has_gl_extension ("GL_EXT_unpack_subimage");
|
||||
priv->has_khr_debug = epoxy_has_gl_extension ("GL_KHR_debug");
|
||||
}
|
||||
else
|
||||
|
||||
@@ -153,7 +153,7 @@ gdk_gl_texture_find_format (gboolean use_es,
|
||||
if (gdk_memory_format_alpha (format) != alpha)
|
||||
continue;
|
||||
|
||||
if (!gdk_memory_format_gl_format (format, use_es, gl_major, gl_minor, &q_internal_format, &q_format, &q_type, q_swizzle))
|
||||
if (!gdk_memory_format_gl_format (format, use_es, gl_major, gl_minor, &q_internal_format, &q_format, &q_type, &q_swizzle))
|
||||
continue;
|
||||
|
||||
if (q_format != gl_format || q_type != gl_type)
|
||||
@@ -188,7 +188,7 @@ gdk_gl_texture_do_download (GdkGLTexture *self,
|
||||
FALSE,
|
||||
major, minor,
|
||||
&gl_internal_format,
|
||||
&gl_format, &gl_type, gl_swizzle))
|
||||
&gl_format, &gl_type, &gl_swizzle))
|
||||
{
|
||||
if (download->stride == expected_stride &&
|
||||
download->format == format)
|
||||
|
||||
@@ -739,12 +739,12 @@ gdk_memory_format_gl_format (GdkMemoryFormat format,
|
||||
guint *out_internal_format,
|
||||
guint *out_format,
|
||||
guint *out_type,
|
||||
GLint out_swizzle[4])
|
||||
GLint (*out_swizzle)[4])
|
||||
{
|
||||
*out_internal_format = memory_formats[format].gl.internal_format;
|
||||
*out_format = memory_formats[format].gl.format;
|
||||
*out_type = memory_formats[format].gl.type;
|
||||
memcpy (out_swizzle, memory_formats[format].gl.swizzle, sizeof(GLint) * 4);
|
||||
memcpy (out_swizzle, &memory_formats[format].gl.swizzle, sizeof(GLint) * 4);
|
||||
|
||||
if (gles)
|
||||
{
|
||||
|
||||
@@ -52,7 +52,7 @@ gboolean gdk_memory_format_gl_format (GdkMemoryFormat
|
||||
guint *out_internal_format,
|
||||
guint *out_format,
|
||||
guint *out_type,
|
||||
GLint out_gizzle[4]);
|
||||
GLint (*out_gizzle)[4]);
|
||||
|
||||
void gdk_memory_convert (guchar *dest_data,
|
||||
gsize dest_stride,
|
||||
|
||||
@@ -2857,10 +2857,7 @@ gdk_event_translate (MSG *msg,
|
||||
break;
|
||||
|
||||
case WM_SYSCOMMAND:
|
||||
/* From: https://learn.microsoft.com/en-us/windows/win32/menurc/wm-syscommand?redirectedfrom=MSDN
|
||||
* To obtain the correct result when testing the value of wParam,
|
||||
* an application must combine the value 0xFFF0 with the wParam value by using the bitwise AND operator. */
|
||||
switch (msg->wParam & 0xFFF0)
|
||||
switch (msg->wParam)
|
||||
{
|
||||
case SC_MINIMIZE:
|
||||
case SC_RESTORE:
|
||||
@@ -2967,14 +2964,6 @@ gdk_event_translate (MSG *msg,
|
||||
windowpos = (WINDOWPOS *) msg->lParam;
|
||||
windowpos->cx = our_mmi.ptMaxSize.x;
|
||||
windowpos->cy = our_mmi.ptMaxSize.y;
|
||||
|
||||
if (!_gdk_win32_surface_lacks_wm_decorations (window) &&
|
||||
!(windowpos->flags & SWP_NOCLIENTSIZE) &&
|
||||
window->width == impl->next_layout.configured_width &&
|
||||
window->height == impl->next_layout.configured_height)
|
||||
{
|
||||
impl->inhibit_configure = TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
impl->maximizing = FALSE;
|
||||
|
||||
@@ -1230,11 +1230,18 @@ get_effective_window_decorations (GdkSurface *window,
|
||||
|
||||
*decoration |= GDK_DECOR_MINIMIZE;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
else if (impl->hint_flags & GDK_HINT_MAX_SIZE)
|
||||
{
|
||||
*decoration = GDK_DECOR_ALL | GDK_DECOR_MAXIMIZE;
|
||||
*decoration |= GDK_DECOR_MINIMIZE;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
else
|
||||
{
|
||||
*decoration = GDK_DECOR_ALL;
|
||||
*decoration = (GDK_DECOR_ALL | GDK_DECOR_MINIMIZE | GDK_DECOR_MAXIMIZE);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
@@ -1456,7 +1456,7 @@ memory_format_gl_format (GdkMemoryFormat data_format,
|
||||
guint *gl_internalformat,
|
||||
guint *gl_format,
|
||||
guint *gl_type,
|
||||
GLint gl_swizzle[4])
|
||||
GLint (*gl_swizzle)[4])
|
||||
{
|
||||
GdkMemoryDepth depth;
|
||||
|
||||
@@ -1577,7 +1577,7 @@ gsk_gl_command_queue_do_upload_texture_chunk (GskGLCommandQueue *self,
|
||||
&gl_internalformat,
|
||||
&gl_format,
|
||||
&gl_type,
|
||||
gl_swizzle);
|
||||
&gl_swizzle);
|
||||
|
||||
gdk_texture_downloader_init (&downloader, texture);
|
||||
gdk_texture_downloader_set_format (&downloader, data_format);
|
||||
@@ -1595,7 +1595,8 @@ gsk_gl_command_queue_do_upload_texture_chunk (GskGLCommandQueue *self,
|
||||
{
|
||||
glTexSubImage2D (GL_TEXTURE_2D, 0, x, y, width, height, gl_format, gl_type, data);
|
||||
}
|
||||
else if (stride % bpp == 0 && gdk_gl_context_has_unpack_subimage (self->context))
|
||||
else if (stride % bpp == 0 &&
|
||||
(gdk_gl_context_check_version (self->context, NULL, "3.0") || gdk_gl_context_has_unpack_subimage (self->context)))
|
||||
{
|
||||
glPixelStorei (GL_UNPACK_ROW_LENGTH, stride / bpp);
|
||||
|
||||
@@ -1683,7 +1684,7 @@ gsk_gl_command_queue_upload_texture_chunks (GskGLCommandQueue *self,
|
||||
&gl_internalformat,
|
||||
&gl_format,
|
||||
&gl_type,
|
||||
gl_swizzle);
|
||||
&gl_swizzle);
|
||||
|
||||
glTexImage2D (GL_TEXTURE_2D, 0, gl_internalformat, width, height, 0, gl_format, gl_type, NULL);
|
||||
|
||||
|
||||
@@ -22,6 +22,7 @@
|
||||
#include <gsk/gskenums.h>
|
||||
#include <gsk/gskpath.h>
|
||||
#include <gsk/gskpathbuilder.h>
|
||||
#include <gsk/gskpathmeasure.h>
|
||||
#include <gsk/gskpathpoint.h>
|
||||
#include <gsk/gskrenderer.h>
|
||||
#include <gsk/gskrendernode.h>
|
||||
|
||||
534
gsk/gskcontour.c
@@ -61,12 +61,21 @@ struct _GskContourClass
|
||||
GskContour * (* reverse) (const GskContour *contour);
|
||||
int (* get_winding) (const GskContour *contour,
|
||||
const graphene_point_t *point);
|
||||
gsize (* get_n_points) (const GskContour *contour);
|
||||
gboolean (* get_closest_point) (const GskContour *contour,
|
||||
const graphene_point_t *point,
|
||||
float threshold,
|
||||
GskRealPathPoint *result,
|
||||
float *out_dist);
|
||||
void (* get_start_point) (const GskContour *contour,
|
||||
GskRealPathPoint *result);
|
||||
void (* get_end_point) (const GskContour *contour,
|
||||
GskRealPathPoint *result);
|
||||
gboolean (* get_previous_point) (const GskContour *contour,
|
||||
GskRealPathPoint *point,
|
||||
GskRealPathPoint *result);
|
||||
gboolean (* get_next_point) (const GskContour *contour,
|
||||
GskRealPathPoint *point,
|
||||
GskRealPathPoint *result);
|
||||
void (* get_position) (const GskContour *contour,
|
||||
GskRealPathPoint *point,
|
||||
graphene_point_t *position);
|
||||
@@ -77,11 +86,26 @@ struct _GskContourClass
|
||||
float (* get_curvature) (const GskContour *contour,
|
||||
GskRealPathPoint *point,
|
||||
graphene_point_t *center);
|
||||
gpointer (* init_measure) (const GskContour *contour,
|
||||
float tolerance,
|
||||
float *out_length);
|
||||
void (* free_measure) (const GskContour *contour,
|
||||
gpointer measure_data);
|
||||
int (* point_compare) (const GskContour *contour,
|
||||
GskRealPathPoint *p1,
|
||||
GskRealPathPoint *p2);
|
||||
void (* add_segment) (const GskContour *contour,
|
||||
GskPathBuilder *builder,
|
||||
gboolean emit_move_to,
|
||||
GskRealPathPoint *start,
|
||||
GskRealPathPoint *end);
|
||||
void (* get_point) (const GskContour *contour,
|
||||
gpointer measure_data,
|
||||
float offset,
|
||||
GskRealPathPoint *result);
|
||||
float (* get_distance) (const GskContour *contour,
|
||||
GskRealPathPoint *point,
|
||||
gpointer measure_data);
|
||||
};
|
||||
|
||||
/* {{{ Utilities */
|
||||
@@ -373,6 +397,211 @@ gsk_standard_contour_get_start_end (const GskContour *contour,
|
||||
*end = self->points[self->n_points - 1];
|
||||
}
|
||||
|
||||
typedef struct
|
||||
{
|
||||
float start;
|
||||
float end;
|
||||
float start_progress;
|
||||
float end_progress;
|
||||
GskCurveLineReason reason;
|
||||
graphene_point_t start_point;
|
||||
graphene_point_t end_point;
|
||||
gsize op;
|
||||
} GskStandardContourMeasure;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
GArray *array;
|
||||
GskStandardContourMeasure measure;
|
||||
} LengthDecompose;
|
||||
|
||||
static gboolean
|
||||
gsk_standard_contour_measure_add_point (const graphene_point_t *from,
|
||||
const graphene_point_t *to,
|
||||
float from_progress,
|
||||
float to_progress,
|
||||
GskCurveLineReason reason,
|
||||
gpointer user_data)
|
||||
{
|
||||
LengthDecompose *decomp = user_data;
|
||||
float seg_length;
|
||||
|
||||
seg_length = graphene_point_distance (from, to, NULL, NULL);
|
||||
decomp->measure.end += seg_length;
|
||||
|
||||
if (decomp->measure.start >= decomp->measure.end)
|
||||
return TRUE;
|
||||
|
||||
decomp->measure.start_progress = from_progress;
|
||||
decomp->measure.end_progress = to_progress;
|
||||
decomp->measure.start_point = *from;
|
||||
decomp->measure.end_point = *to;
|
||||
decomp->measure.reason = reason;
|
||||
|
||||
g_array_append_val (decomp->array, decomp->measure);
|
||||
|
||||
decomp->measure.start += seg_length;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gpointer
|
||||
gsk_standard_contour_init_measure (const GskContour *contour,
|
||||
float tolerance,
|
||||
float *out_length)
|
||||
{
|
||||
const GskStandardContour *self = (const GskStandardContour *) contour;
|
||||
gsize i;
|
||||
float length;
|
||||
GArray *array;
|
||||
|
||||
array = g_array_new (FALSE, FALSE, sizeof (GskStandardContourMeasure));
|
||||
length = 0;
|
||||
|
||||
for (i = 1; i < self->n_ops; i ++)
|
||||
{
|
||||
GskCurve curve;
|
||||
LengthDecompose decomp = { array, { length, length, 0, 0, GSK_CURVE_LINE_REASON_SHORT, { 0, 0 }, { 0, 0 }, i } };
|
||||
|
||||
gsk_curve_init (&curve, self->ops[i]);
|
||||
gsk_curve_decompose (&curve, tolerance, gsk_standard_contour_measure_add_point, &decomp);
|
||||
length = decomp.measure.start;
|
||||
}
|
||||
|
||||
*out_length = length;
|
||||
|
||||
return array;
|
||||
}
|
||||
|
||||
static void
|
||||
gsk_standard_contour_free_measure (const GskContour *contour,
|
||||
gpointer data)
|
||||
{
|
||||
g_array_free (data, TRUE);
|
||||
}
|
||||
|
||||
static int
|
||||
gsk_standard_contour_find_measure (gconstpointer m,
|
||||
gconstpointer l)
|
||||
{
|
||||
const GskStandardContourMeasure *measure = m;
|
||||
float length = *(const float *) l;
|
||||
|
||||
if (measure->start > length)
|
||||
return 1;
|
||||
else if (measure->end <= length)
|
||||
return -1;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int
|
||||
gsk_standard_contour_point_compare (const GskContour *contour,
|
||||
GskRealPathPoint *p1,
|
||||
GskRealPathPoint *p2)
|
||||
{
|
||||
if (p1->data.std.idx < p2->data.std.idx)
|
||||
return -1;
|
||||
else if (p1->data.std.idx > p2->data.std.idx)
|
||||
return 1;
|
||||
else if (p1->data.std.t < p2->data.std.t)
|
||||
return -1;
|
||||
else if (p1->data.std.t > p2->data.std.t)
|
||||
return 1;
|
||||
else
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
add_curve (GskCurve *curve,
|
||||
GskPathBuilder *builder,
|
||||
gboolean *emit_move_to)
|
||||
{
|
||||
if (*emit_move_to)
|
||||
{
|
||||
const graphene_point_t *s;
|
||||
|
||||
s = gsk_curve_get_start_point (curve);
|
||||
gsk_path_builder_move_to (builder, s->x, s->y);
|
||||
*emit_move_to = FALSE;
|
||||
}
|
||||
gsk_curve_builder_to (curve, builder);
|
||||
}
|
||||
|
||||
static void
|
||||
gsk_standard_contour_add_segment (const GskContour *contour,
|
||||
GskPathBuilder *builder,
|
||||
gboolean emit_move_to,
|
||||
GskRealPathPoint *start,
|
||||
GskRealPathPoint *end)
|
||||
{
|
||||
GskStandardContour *self = (GskStandardContour *) contour;
|
||||
gsize first, last;
|
||||
float first_t, last_t;
|
||||
GskCurve c, c1, c2;
|
||||
|
||||
if (start)
|
||||
{
|
||||
first = start->data.std.idx;
|
||||
first_t = start->data.std.t;
|
||||
}
|
||||
else
|
||||
{
|
||||
first = 1;
|
||||
first_t = 0;
|
||||
}
|
||||
|
||||
if (end)
|
||||
{
|
||||
last = end->data.std.idx;
|
||||
last_t = end->data.std.t;
|
||||
}
|
||||
else
|
||||
{
|
||||
last = self->n_ops - 1;
|
||||
last_t = 1;
|
||||
}
|
||||
|
||||
gsk_curve_init (&c, self->ops[first]);
|
||||
|
||||
if (first == last)
|
||||
{
|
||||
gsk_curve_segment (&c, first_t, last_t, &c1);
|
||||
add_curve (&c1, builder, &emit_move_to);
|
||||
return;
|
||||
}
|
||||
|
||||
if (first_t == 0)
|
||||
{
|
||||
add_curve (&c, builder, &emit_move_to);
|
||||
}
|
||||
else if (first_t < 1)
|
||||
{
|
||||
gsk_curve_split (&c, first_t, &c1, &c2);
|
||||
add_curve (&c2, builder, &emit_move_to);
|
||||
}
|
||||
|
||||
for (gsize i = first + 1; i < last; i++)
|
||||
{
|
||||
gsk_curve_init (&c, self->ops[i]);
|
||||
add_curve (&c, builder, &emit_move_to);
|
||||
}
|
||||
|
||||
gsk_curve_init (&c, self->ops[last]);
|
||||
if (c.op == GSK_PATH_CLOSE)
|
||||
c.op = GSK_PATH_LINE;
|
||||
|
||||
if (last_t == 1)
|
||||
{
|
||||
add_curve (&c, builder, &emit_move_to);
|
||||
}
|
||||
else if (last_t > 0)
|
||||
{
|
||||
gsk_curve_split (&c, last_t, &c1, &c2);
|
||||
add_curve (&c, builder, &emit_move_to);
|
||||
}
|
||||
}
|
||||
|
||||
static int
|
||||
gsk_standard_contour_get_winding (const GskContour *contour,
|
||||
const graphene_point_t *point)
|
||||
@@ -405,14 +634,6 @@ gsk_standard_contour_get_winding (const GskContour *contour,
|
||||
return winding;
|
||||
}
|
||||
|
||||
static gsize
|
||||
gsk_standard_contour_get_n_points (const GskContour *contour)
|
||||
{
|
||||
GskStandardContour *self = (GskStandardContour *) contour;
|
||||
|
||||
return self->n_ops;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gsk_standard_contour_get_closest_point (const GskContour *contour,
|
||||
const graphene_point_t *point,
|
||||
@@ -434,8 +655,8 @@ gsk_standard_contour_get_closest_point (const GskContour *contour,
|
||||
if (dist <= threshold)
|
||||
{
|
||||
*out_dist = dist;
|
||||
result->idx = 0;
|
||||
result->t = 0;
|
||||
result->data.std.idx = 0;
|
||||
result->data.std.t = 0;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
@@ -463,14 +684,108 @@ gsk_standard_contour_get_closest_point (const GskContour *contour,
|
||||
if (best_idx != G_MAXUINT)
|
||||
{
|
||||
*out_dist = threshold;
|
||||
result->idx = best_idx;
|
||||
result->t = best_t;
|
||||
result->data.std.idx = best_idx;
|
||||
result->data.std.t = best_t;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static void
|
||||
gsk_standard_contour_get_start_point (const GskContour *contour,
|
||||
GskRealPathPoint *result)
|
||||
{
|
||||
result->data.std.idx = 1;
|
||||
result->data.std.t = 0;
|
||||
}
|
||||
|
||||
static void
|
||||
gsk_standard_contour_get_end_point (const GskContour *contour,
|
||||
GskRealPathPoint *result)
|
||||
{
|
||||
GskStandardContour *self = (GskStandardContour *) contour;
|
||||
|
||||
result->data.std.idx = self->n_ops - 1;
|
||||
result->data.std.t = 1;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gsk_standard_contour_get_previous_point (const GskContour *contour,
|
||||
GskRealPathPoint *point,
|
||||
GskRealPathPoint *result)
|
||||
{
|
||||
if (point->data.std.t > 0)
|
||||
{
|
||||
result->data.std.idx = point->data.std.idx;
|
||||
result->data.std.t = 0;
|
||||
return TRUE;
|
||||
}
|
||||
else if (point->data.std.idx > 1)
|
||||
{
|
||||
result->data.std.idx = point->data.std.idx - 1;
|
||||
result->data.std.t = 0;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
gsk_standard_contour_get_next_point (const GskContour *contour,
|
||||
GskRealPathPoint *point,
|
||||
GskRealPathPoint *result)
|
||||
{
|
||||
GskStandardContour *self = (GskStandardContour *) contour;
|
||||
|
||||
if (point->data.std.t < 1)
|
||||
{
|
||||
result->data.std.idx = point->data.std.idx;
|
||||
result->data.std.t = 1;
|
||||
return TRUE;
|
||||
}
|
||||
else if (point->data.std.idx + 1 < self->n_ops - 1)
|
||||
{
|
||||
result->data.std.idx = point->data.std.idx + 1;
|
||||
result->data.std.t = 1;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static void
|
||||
gsk_standard_contour_get_point (const GskContour *contour,
|
||||
gpointer measure_data,
|
||||
float distance,
|
||||
GskRealPathPoint *result)
|
||||
{
|
||||
GArray *array = measure_data;
|
||||
unsigned int idx;
|
||||
GskStandardContourMeasure *measure;
|
||||
float fraction, t;
|
||||
|
||||
if (array->len == 0)
|
||||
{
|
||||
result->data.std.idx = 0;
|
||||
result->data.std.t = 0;
|
||||
return;
|
||||
}
|
||||
|
||||
if (!g_array_binary_search (array, &distance, gsk_standard_contour_find_measure, &idx))
|
||||
idx = array->len - 1;
|
||||
|
||||
measure = &g_array_index (array, GskStandardContourMeasure, idx);
|
||||
|
||||
fraction = (distance - measure->start) / (measure->end - measure->start);
|
||||
t = measure->start_progress + fraction * (measure->end_progress - measure->start_progress);
|
||||
|
||||
g_assert (t >= 0 && t <= 1);
|
||||
|
||||
result->data.std.idx = measure->op;
|
||||
result->data.std.t = t;
|
||||
}
|
||||
|
||||
static void
|
||||
gsk_standard_contour_get_position (const GskContour *contour,
|
||||
GskRealPathPoint *point,
|
||||
@@ -479,14 +794,14 @@ gsk_standard_contour_get_position (const GskContour *contour,
|
||||
GskStandardContour *self = (GskStandardContour *) contour;
|
||||
GskCurve curve;
|
||||
|
||||
if (G_UNLIKELY (point->idx == 0))
|
||||
if (G_UNLIKELY (point->data.std.idx == 0))
|
||||
{
|
||||
*position = self->points[0];
|
||||
return;
|
||||
}
|
||||
|
||||
gsk_curve_init (&curve, self->ops[point->idx]);
|
||||
gsk_curve_get_point (&curve, point->t, position);
|
||||
gsk_curve_init (&curve, self->ops[point->data.std.idx]);
|
||||
gsk_curve_get_point (&curve, point->data.std.t, position);
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -500,18 +815,18 @@ gsk_standard_contour_get_tangent (const GskContour *contour,
|
||||
gsize idx;
|
||||
float t;
|
||||
|
||||
if (G_UNLIKELY (point->idx == 0))
|
||||
if (G_UNLIKELY (point->data.std.idx == 0))
|
||||
{
|
||||
graphene_vec2_init (tangent, 1, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
idx = point->idx;
|
||||
t = point->t;
|
||||
idx = point->data.std.idx;
|
||||
t = point->data.std.t;
|
||||
|
||||
if (t == 0 && direction == GSK_PATH_START)
|
||||
{
|
||||
/* Look at the previous segment */
|
||||
/* Look at the previous segment (0 is always a move, so skip it) */
|
||||
if (idx > 1)
|
||||
{
|
||||
idx--;
|
||||
@@ -533,6 +848,7 @@ gsk_standard_contour_get_tangent (const GskContour *contour,
|
||||
}
|
||||
else if (self->flags & GSK_PATH_CLOSED)
|
||||
{
|
||||
/* segment 0 is always a move */
|
||||
idx = 1;
|
||||
t = 0;
|
||||
}
|
||||
@@ -550,76 +866,42 @@ gsk_standard_contour_get_curvature (const GskContour *contour,
|
||||
GskStandardContour *self = (GskStandardContour *) contour;
|
||||
GskCurve curve;
|
||||
|
||||
if (G_UNLIKELY (point->idx == 0))
|
||||
if (G_UNLIKELY (point->data.std.idx == 0))
|
||||
return 0;
|
||||
|
||||
gsk_curve_init (&curve, self->ops[point->idx]);
|
||||
return gsk_curve_get_curvature (&curve, point->t, center);
|
||||
gsk_curve_init (&curve, self->ops[point->data.std.idx]);
|
||||
return gsk_curve_get_curvature (&curve, point->data.std.t, center);
|
||||
}
|
||||
|
||||
static void
|
||||
add_curve (GskCurve *curve,
|
||||
GskPathBuilder *builder,
|
||||
gboolean *emit_move_to)
|
||||
static float
|
||||
gsk_standard_contour_get_distance (const GskContour *contour,
|
||||
GskRealPathPoint *point,
|
||||
gpointer measure_data)
|
||||
{
|
||||
if (*emit_move_to)
|
||||
{
|
||||
const graphene_point_t *s;
|
||||
GArray *array = measure_data;
|
||||
|
||||
s = gsk_curve_get_start_point (curve);
|
||||
gsk_path_builder_move_to (builder, s->x, s->y);
|
||||
*emit_move_to = FALSE;
|
||||
}
|
||||
gsk_curve_builder_to (curve, builder);
|
||||
}
|
||||
if (G_UNLIKELY (point->data.std.idx == 0))
|
||||
return 0;
|
||||
|
||||
static void
|
||||
gsk_standard_contour_add_segment (const GskContour *contour,
|
||||
GskPathBuilder *builder,
|
||||
gboolean emit_move_to,
|
||||
GskRealPathPoint *start,
|
||||
GskRealPathPoint *end)
|
||||
{
|
||||
GskStandardContour *self = (GskStandardContour *) contour;
|
||||
GskCurve c, c1, c2;
|
||||
for (unsigned int i = 0; i < array->len; i++)
|
||||
{
|
||||
GskStandardContourMeasure *measure = &g_array_index (array, GskStandardContourMeasure, i);
|
||||
float fraction;
|
||||
|
||||
gsk_curve_init (&c, self->ops[start->idx]);
|
||||
if (measure->op != point->data.std.idx)
|
||||
continue;
|
||||
|
||||
if (start->idx == end->idx)
|
||||
{
|
||||
gsk_curve_segment (&c, start->t, end->t, &c1);
|
||||
add_curve (&c1, builder, &emit_move_to);
|
||||
return;
|
||||
}
|
||||
if (start->t == 0)
|
||||
{
|
||||
add_curve (&c, builder, &emit_move_to);
|
||||
}
|
||||
else if (start->t < 1)
|
||||
{
|
||||
gsk_curve_split (&c, start->t, &c1, &c2);
|
||||
add_curve (&c2, builder, &emit_move_to);
|
||||
if (measure->end_progress < point->data.std.t)
|
||||
continue;
|
||||
|
||||
g_assert (measure->op == point->data.std.idx);
|
||||
g_assert (measure->start_progress <= point->data.std.t && point->data.std.t <= measure->end_progress);
|
||||
|
||||
fraction = (point->data.std.t - measure->start_progress) / (measure->end_progress - measure->start_progress);
|
||||
return measure->start + fraction * (measure->end - measure->start);
|
||||
}
|
||||
|
||||
for (gsize i = start->idx + 1; i < end->idx; i++)
|
||||
{
|
||||
gsk_curve_init (&c, self->ops[i]);
|
||||
add_curve (&c, builder, &emit_move_to);
|
||||
}
|
||||
|
||||
gsk_curve_init (&c, self->ops[end->idx]);
|
||||
if (c.op == GSK_PATH_CLOSE)
|
||||
c.op = GSK_PATH_LINE;
|
||||
|
||||
if (end->t == 1)
|
||||
{
|
||||
add_curve (&c, builder, &emit_move_to);
|
||||
}
|
||||
else if (end->t > 0)
|
||||
{
|
||||
gsk_curve_split (&c, end->t, &c1, &c2);
|
||||
add_curve (&c1, builder, &emit_move_to);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const GskContourClass GSK_STANDARD_CONTOUR_CLASS =
|
||||
@@ -636,12 +918,20 @@ static const GskContourClass GSK_STANDARD_CONTOUR_CLASS =
|
||||
gsk_standard_contour_foreach,
|
||||
gsk_standard_contour_reverse,
|
||||
gsk_standard_contour_get_winding,
|
||||
gsk_standard_contour_get_n_points,
|
||||
gsk_standard_contour_get_closest_point,
|
||||
gsk_standard_contour_get_start_point,
|
||||
gsk_standard_contour_get_end_point,
|
||||
gsk_standard_contour_get_previous_point,
|
||||
gsk_standard_contour_get_next_point,
|
||||
gsk_standard_contour_get_position,
|
||||
gsk_standard_contour_get_tangent,
|
||||
gsk_standard_contour_get_curvature,
|
||||
gsk_standard_contour_init_measure,
|
||||
gsk_standard_contour_free_measure,
|
||||
gsk_standard_contour_point_compare,
|
||||
gsk_standard_contour_add_segment,
|
||||
gsk_standard_contour_get_point,
|
||||
gsk_standard_contour_get_distance,
|
||||
};
|
||||
|
||||
/* You must ensure the contour has enough size allocated,
|
||||
@@ -763,6 +1053,21 @@ gsk_contour_foreach (const GskContour *self,
|
||||
return self->klass->foreach (self, tolerance, func, user_data);
|
||||
}
|
||||
|
||||
gpointer
|
||||
gsk_contour_init_measure (const GskContour *self,
|
||||
float tolerance,
|
||||
float *out_length)
|
||||
{
|
||||
return self->klass->init_measure (self, tolerance, out_length);
|
||||
}
|
||||
|
||||
void
|
||||
gsk_contour_free_measure (const GskContour *self,
|
||||
gpointer data)
|
||||
{
|
||||
self->klass->free_measure (self, data);
|
||||
}
|
||||
|
||||
void
|
||||
gsk_contour_get_start_end (const GskContour *self,
|
||||
graphene_point_t *start,
|
||||
@@ -771,6 +1076,24 @@ gsk_contour_get_start_end (const GskContour *self,
|
||||
self->klass->get_start_end (self, start, end);
|
||||
}
|
||||
|
||||
int
|
||||
gsk_contour_point_compare (const GskContour *self,
|
||||
GskRealPathPoint *p1,
|
||||
GskRealPathPoint *p2)
|
||||
{
|
||||
return self->klass->point_compare (self, p1, p2);
|
||||
}
|
||||
|
||||
void
|
||||
gsk_contour_add_segment (const GskContour *self,
|
||||
GskPathBuilder *builder,
|
||||
gboolean emit_move_to,
|
||||
GskRealPathPoint *start,
|
||||
GskRealPathPoint *end)
|
||||
{
|
||||
self->klass->add_segment (self, builder, emit_move_to, start, end);
|
||||
}
|
||||
|
||||
int
|
||||
gsk_contour_get_winding (const GskContour *self,
|
||||
const graphene_point_t *point)
|
||||
@@ -788,10 +1111,43 @@ gsk_contour_get_closest_point (const GskContour *self,
|
||||
return self->klass->get_closest_point (self, point, threshold, result, out_dist);
|
||||
}
|
||||
|
||||
gsize
|
||||
gsk_contour_get_n_points (const GskContour *self)
|
||||
void
|
||||
gsk_contour_get_start_point (const GskContour *self,
|
||||
GskRealPathPoint *result)
|
||||
{
|
||||
return self->klass->get_n_points (self);
|
||||
self->klass->get_start_point (self, result);
|
||||
}
|
||||
|
||||
void
|
||||
gsk_contour_get_end_point (const GskContour *self,
|
||||
GskRealPathPoint *result)
|
||||
{
|
||||
self->klass->get_end_point (self, result);
|
||||
}
|
||||
|
||||
gboolean
|
||||
gsk_contour_get_previous_point (const GskContour *self,
|
||||
GskRealPathPoint *point,
|
||||
GskRealPathPoint *result)
|
||||
{
|
||||
return self->klass->get_previous_point (self, point, result);
|
||||
}
|
||||
|
||||
gboolean
|
||||
gsk_contour_get_next_point (const GskContour *self,
|
||||
GskRealPathPoint *point,
|
||||
GskRealPathPoint *result)
|
||||
{
|
||||
return self->klass->get_next_point (self, point, result);
|
||||
}
|
||||
|
||||
void
|
||||
gsk_contour_get_point (const GskContour *self,
|
||||
gpointer measure_data,
|
||||
float offset,
|
||||
GskRealPathPoint *result)
|
||||
{
|
||||
self->klass->get_point (self, measure_data, offset, result);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -819,14 +1175,12 @@ gsk_contour_get_curvature (const GskContour *self,
|
||||
return self->klass->get_curvature (self, point, center);
|
||||
}
|
||||
|
||||
void
|
||||
gsk_contour_add_segment (const GskContour *self,
|
||||
GskPathBuilder *builder,
|
||||
gboolean emit_move_to,
|
||||
GskRealPathPoint *start,
|
||||
GskRealPathPoint *end)
|
||||
float
|
||||
gsk_contour_get_distance (const GskContour *self,
|
||||
GskRealPathPoint *point,
|
||||
gpointer measure_data)
|
||||
{
|
||||
self->klass->add_segment (self, builder, emit_move_to, start, end);
|
||||
return self->klass->get_distance (self, point, measure_data);
|
||||
}
|
||||
|
||||
/* }}} */
|
||||
|
||||
@@ -57,15 +57,17 @@ void gsk_contour_get_start_end (const GskContou
|
||||
graphene_point_t *end);
|
||||
int gsk_contour_get_winding (const GskContour *self,
|
||||
const graphene_point_t *point);
|
||||
gsize gsk_contour_get_n_points (const GskContour *self);
|
||||
|
||||
gboolean gsk_contour_get_closest_point (const GskContour *self,
|
||||
const graphene_point_t *point,
|
||||
float threshold,
|
||||
GskRealPathPoint *result,
|
||||
float *out_dist);
|
||||
|
||||
void gsk_contour_get_position (const GskContour *self,
|
||||
GskRealPathPoint *point,
|
||||
graphene_point_t *pos);
|
||||
|
||||
void gsk_contour_get_tangent (const GskContour *self,
|
||||
GskRealPathPoint *point,
|
||||
GskPathDirection direction,
|
||||
@@ -73,11 +75,37 @@ void gsk_contour_get_tangent (const GskContou
|
||||
float gsk_contour_get_curvature (const GskContour *self,
|
||||
GskRealPathPoint *point,
|
||||
graphene_point_t *center);
|
||||
gpointer gsk_contour_init_measure (const GskContour *self,
|
||||
float tolerance,
|
||||
float *out_length);
|
||||
void gsk_contour_free_measure (const GskContour *self,
|
||||
gpointer data);
|
||||
int gsk_contour_point_compare (const GskContour *self,
|
||||
GskRealPathPoint *p1,
|
||||
GskRealPathPoint *p2);
|
||||
|
||||
void gsk_contour_add_segment (const GskContour *self,
|
||||
GskPathBuilder *builder,
|
||||
gboolean emit_move_to,
|
||||
GskRealPathPoint *start,
|
||||
GskRealPathPoint *end);
|
||||
|
||||
void gsk_contour_get_point (const GskContour *self,
|
||||
gpointer measure_data,
|
||||
float offset,
|
||||
GskRealPathPoint *result);
|
||||
void gsk_contour_get_start_point (const GskContour *self,
|
||||
GskRealPathPoint *result);
|
||||
void gsk_contour_get_end_point (const GskContour *self,
|
||||
GskRealPathPoint *result);
|
||||
gboolean gsk_contour_get_previous_point (const GskContour *self,
|
||||
GskRealPathPoint *point,
|
||||
GskRealPathPoint *result);
|
||||
gboolean gsk_contour_get_next_point (const GskContour *self,
|
||||
GskRealPathPoint *point,
|
||||
GskRealPathPoint *result);
|
||||
float gsk_contour_get_distance (const GskContour *self,
|
||||
GskRealPathPoint *point,
|
||||
gpointer measure_data);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/* GSK - The GTK Scene Kit
|
||||
* Copyright 2016 Endless
|
||||
* Copyright 2016 Endless
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU Lesser General Public
|
||||
@@ -42,6 +42,8 @@
|
||||
* @GSK_REPEAT_NODE: A node that repeats the child's contents
|
||||
* @GSK_CLIP_NODE: A node that clips its child to a rectangular area
|
||||
* @GSK_ROUNDED_CLIP_NODE: A node that clips its child to a rounded rectangle
|
||||
* @GSK_FILL_NODE: A node that fills a path
|
||||
* @GSK_STROKE_NODE: A node that strokes a path
|
||||
* @GSK_SHADOW_NODE: A node that draws a shadow below its child
|
||||
* @GSK_BLEND_NODE: A node that blends two children together
|
||||
* @GSK_CROSS_FADE_NODE: A node that cross-fades between two children
|
||||
@@ -51,9 +53,7 @@
|
||||
* @GSK_GL_SHADER_NODE: A node that uses OpenGL fragment shaders to render
|
||||
* @GSK_TEXTURE_SCALE_NODE: A node drawing a `GdkTexture` scaled and filtered (Since: 4.10)
|
||||
* @GSK_MASK_NODE: A node that masks one child with another (Since: 4.10)
|
||||
* @GSK_FILL_NODE: A node that fills a path
|
||||
* @GSK_STROKE_NODE: A node that strokes a path
|
||||
|
||||
|
||||
* The type of a node determines what the node is rendering.
|
||||
*/
|
||||
typedef enum {
|
||||
@@ -76,6 +76,8 @@ typedef enum {
|
||||
GSK_REPEAT_NODE,
|
||||
GSK_CLIP_NODE,
|
||||
GSK_ROUNDED_CLIP_NODE,
|
||||
GSK_FILL_NODE,
|
||||
GSK_STROKE_NODE,
|
||||
GSK_SHADOW_NODE,
|
||||
GSK_BLEND_NODE,
|
||||
GSK_CROSS_FADE_NODE,
|
||||
@@ -84,9 +86,7 @@ typedef enum {
|
||||
GSK_DEBUG_NODE,
|
||||
GSK_GL_SHADER_NODE,
|
||||
GSK_TEXTURE_SCALE_NODE,
|
||||
GSK_MASK_NODE,
|
||||
GSK_FILL_NODE,
|
||||
GSK_STROKE_NODE
|
||||
GSK_MASK_NODE
|
||||
} GskRenderNodeType;
|
||||
|
||||
/**
|
||||
@@ -220,11 +220,6 @@ typedef enum {
|
||||
*
|
||||
* The default line cap style is `GSK_LINE_CAP_BUTT`.
|
||||
*
|
||||
* <picture>
|
||||
* <source srcset="caps-dark.png" media="(prefers-color-scheme: dark)">
|
||||
* <img alt="Line Cap Styles" src="caps-light.png">
|
||||
* </picture>
|
||||
*
|
||||
* New entries may be added in future versions.
|
||||
*
|
||||
* Since: 4.14
|
||||
@@ -247,11 +242,6 @@ typedef enum {
|
||||
*
|
||||
* The default line join style is `GSK_LINE_JOIN_MITER`.
|
||||
*
|
||||
* <picture>
|
||||
* <source srcset="join-dark.png" media="(prefers-color-scheme: dark)">
|
||||
* <img alt="Line Join Styles" src="join-light.png">
|
||||
* </picture>
|
||||
*
|
||||
* New entries may be added in future versions.
|
||||
*
|
||||
* Since: 4.14
|
||||
|
||||
359
gsk/gskpath.c
@@ -30,26 +30,18 @@
|
||||
* GskPath:
|
||||
*
|
||||
* A `GskPath` describes lines and curves that are more complex
|
||||
* than simple rectangles.
|
||||
*
|
||||
* Paths can used for rendering (filling or stroking) and for animations
|
||||
* (e.g. as trajectories).
|
||||
* than simple rectangles. Paths can used for rendering (filling or
|
||||
* stroking) and for animations (e.g. as trajectories).
|
||||
*
|
||||
* `GskPath` is an immutable, opaque, reference-counted struct.
|
||||
* After creation, you cannot change the types it represents. Instead,
|
||||
* new `GskPath` objects have to be created. The [struct@Gsk.PathBuilder]
|
||||
* structure is meant to help in this endeavor.
|
||||
* After creation, you cannot change the types it represents.
|
||||
* Instead, new `GskPath` objects have to be created.
|
||||
*
|
||||
* The [struct@Gsk.PathBuilder] structure is meant to help in this endeavor.
|
||||
*
|
||||
* Conceptually, a path consists of zero or more contours (continous, connected
|
||||
* curves), each of which may or may not be closed. Contours are typically
|
||||
* constructed from Bézier segments.
|
||||
*
|
||||
* <picture>
|
||||
* <source srcset="path-dark.png" media="(prefers-color-scheme: dark)">
|
||||
* <img alt="A Path" src="path-light.png">
|
||||
* </picture>
|
||||
*
|
||||
* Since: 4.14
|
||||
*/
|
||||
|
||||
struct _GskPath
|
||||
@@ -428,7 +420,6 @@ gsk_path_get_bounds (GskPath *self,
|
||||
*
|
||||
* Returns: `TRUE` if the path has bounds, `FALSE` if the path is known
|
||||
* to be empty and have no bounds.
|
||||
* Since: 4.14
|
||||
*/
|
||||
gboolean
|
||||
gsk_path_get_stroke_bounds (GskPath *self,
|
||||
@@ -499,72 +490,6 @@ gsk_path_in_fill (GskPath *self,
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* gsk_path_get_start_point:
|
||||
* @self: a `GskPath`
|
||||
* @result: (out caller-allocates): return location for point
|
||||
*
|
||||
* Gets the start point of the path.
|
||||
*
|
||||
* An empty path has no points, so `FALSE`
|
||||
* is returned in this case.
|
||||
*
|
||||
* Returns: `TRUE` if @result was filled
|
||||
*
|
||||
* Since: 4.14
|
||||
*/
|
||||
gboolean
|
||||
gsk_path_get_start_point (GskPath *self,
|
||||
GskPathPoint *result)
|
||||
{
|
||||
GskRealPathPoint *res = (GskRealPathPoint *) result;
|
||||
|
||||
g_return_val_if_fail (self != NULL, FALSE);
|
||||
g_return_val_if_fail (result != NULL, FALSE);
|
||||
|
||||
if (self->n_contours == 0)
|
||||
return FALSE;
|
||||
|
||||
res->contour = 0;
|
||||
res->idx = 1;
|
||||
res->t = 0;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* gsk_path_get_end_point:
|
||||
* @self: a `GskPath`
|
||||
* @result: (out caller-allocates): return location for point
|
||||
*
|
||||
* Gets the end point of the path.
|
||||
*
|
||||
* An empty path has no points, so `FALSE`
|
||||
* is returned in this case.
|
||||
*
|
||||
* Returns: `TRUE` if @result was filled
|
||||
*
|
||||
* Since: 4.14
|
||||
*/
|
||||
gboolean
|
||||
gsk_path_get_end_point (GskPath *self,
|
||||
GskPathPoint *result)
|
||||
{
|
||||
GskRealPathPoint *res = (GskRealPathPoint *) result;
|
||||
|
||||
g_return_val_if_fail (self != NULL, FALSE);
|
||||
g_return_val_if_fail (result != NULL, FALSE);
|
||||
|
||||
if (self->n_contours == 0)
|
||||
return FALSE;
|
||||
|
||||
res->contour = self->n_contours - 1;
|
||||
res->idx = gsk_contour_get_n_points (self->contours[self->n_contours - 1]) - 1;
|
||||
res->t = 1;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* gsk_path_get_closest_point:
|
||||
* @self: a `GskPath`
|
||||
@@ -607,6 +532,7 @@ gsk_path_get_closest_point (GskPath *self,
|
||||
{
|
||||
found = TRUE;
|
||||
res->contour = i;
|
||||
res->path = self;
|
||||
threshold = distance;
|
||||
}
|
||||
}
|
||||
@@ -614,6 +540,74 @@ gsk_path_get_closest_point (GskPath *self,
|
||||
return found;
|
||||
}
|
||||
|
||||
/**
|
||||
* gsk_path_get_start_point:
|
||||
* @self: a `GskPath`
|
||||
* @result: (out caller-allocates): return location for point
|
||||
*
|
||||
* Gets the start point of the path.
|
||||
*
|
||||
* An empty path has no points, so `FALSE`
|
||||
* is returned in this case.
|
||||
*
|
||||
* Returns: `TRUE` if @result was filled
|
||||
*
|
||||
* Since: 4.14
|
||||
*/
|
||||
gboolean
|
||||
gsk_path_get_start_point (GskPath *self,
|
||||
GskPathPoint *result)
|
||||
{
|
||||
GskRealPathPoint *res = (GskRealPathPoint *) result;
|
||||
|
||||
g_return_val_if_fail (self != NULL, FALSE);
|
||||
g_return_val_if_fail (result != NULL, FALSE);
|
||||
|
||||
if (self->n_contours == 0)
|
||||
return FALSE;
|
||||
|
||||
gsk_contour_get_start_point (self->contours[0], res);
|
||||
|
||||
res->path = self;
|
||||
res->contour = 0;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* gsk_path_get_end_point:
|
||||
* @self: a `GskPath`
|
||||
* @result: (out caller-allocates): return location for point
|
||||
*
|
||||
* Gets the end point of the path.
|
||||
*
|
||||
* An empty path has no points, so `FALSE`
|
||||
* is returned in this case.
|
||||
*
|
||||
* Returns: `TRUE` if @result was filled
|
||||
*
|
||||
* Since: 4.14
|
||||
*/
|
||||
gboolean
|
||||
gsk_path_get_end_point (GskPath *self,
|
||||
GskPathPoint *result)
|
||||
{
|
||||
GskRealPathPoint *res = (GskRealPathPoint *) result;
|
||||
|
||||
g_return_val_if_fail (self != NULL, FALSE);
|
||||
g_return_val_if_fail (result!= NULL, FALSE);
|
||||
|
||||
if (self->n_contours == 0)
|
||||
return FALSE;
|
||||
|
||||
gsk_contour_get_end_point (self->contours[self->n_contours - 1], res);
|
||||
|
||||
res->path = self;
|
||||
res->contour = self->n_contours - 1;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* gsk_path_foreach:
|
||||
* @self: a `GskPath`
|
||||
@@ -1013,22 +1007,6 @@ parse_circle (const char **p,
|
||||
* [SVG path syntax](https://www.w3.org/TR/SVG11/paths.html#PathData),
|
||||
* as e.g. produced by [method@Gsk.Path.to_string].
|
||||
*
|
||||
* A high-level summary of the syntax:
|
||||
*
|
||||
* - `M x y` Move to `(x, y)`
|
||||
* - `L x y` Add a line from the current point to `(x, y)`
|
||||
* - `Q x1 y1 x2 y2` Add a quadratic Bézier from the current point to `(x2, y2)`, with control point `(x1, y1)`
|
||||
* - `C x1 y1 x2 y2 x3 y3` Add a cubic Bézier from the current point to `(x3, y3)`, with control points `(x1, y1)` and `(x2, y2)`
|
||||
* - `Z` Close the contour by drawing a line back to the start point
|
||||
* - `H x` Add a horizontal line from the current point to the given x value
|
||||
* - `V y` Add a vertical line from the current point to the given y value
|
||||
* - `T x2 y2` Add a quadratic Bézier, using the reflection of the previous segments' control point as control point
|
||||
* - `S x2 y2 x3 y3` Add a cubic Bézier, using the reflection of the previous segments' second control point as first control point
|
||||
* - `A rx ry r l s x y` Add an elliptical arc from the current point to `(x, y)` with radii rx and ry. See the SVG documentation for how the other parameters influence the arc.
|
||||
*
|
||||
* All the commands have lowercase variants that interpret coordinates
|
||||
* relative to the current point.
|
||||
*
|
||||
* Returns: (nullable): a new `GskPath`, or `NULL`
|
||||
* if @string could not be parsed
|
||||
*
|
||||
@@ -1415,93 +1393,172 @@ error:
|
||||
}
|
||||
|
||||
/**
|
||||
* gsk_path_get_position:
|
||||
* @self: a `GskPath`
|
||||
* @point: a `GskPathPoint` on @path
|
||||
* @position: (out caller-allocates): Return location for
|
||||
* the coordinates of the point
|
||||
* gsk_path_builder_add_segment:
|
||||
* @self: a `GskPathBuilder`
|
||||
* @path: the `GskPath` to take the segment to
|
||||
* @start: the point on @path to start at
|
||||
* @end: the point on @path to end at
|
||||
*
|
||||
* Gets the position of the point.
|
||||
* Adds to @self the segment of @path from @start to @end.
|
||||
*
|
||||
* If @start is after @end, the path will first add the segment
|
||||
* from @start to the end of the path, and then add the segment from
|
||||
* the beginning to @end. If the path is closed, these segments will
|
||||
* be connected.
|
||||
*
|
||||
* Since: 4.14
|
||||
*/
|
||||
void
|
||||
gsk_path_get_position (GskPath *self,
|
||||
const GskPathPoint *point,
|
||||
graphene_point_t *position)
|
||||
gsk_path_builder_add_segment (GskPathBuilder *self,
|
||||
GskPath *path,
|
||||
const GskPathPoint *start,
|
||||
const GskPathPoint *end)
|
||||
{
|
||||
GskRealPathPoint *p = (GskRealPathPoint *) point;
|
||||
GskRealPathPoint *s = (GskRealPathPoint *) start;
|
||||
GskRealPathPoint *e = (GskRealPathPoint *) end;
|
||||
const GskContour *contour;
|
||||
|
||||
g_return_if_fail (self != NULL);
|
||||
g_return_if_fail (point != NULL);
|
||||
g_return_if_fail (position != NULL);
|
||||
g_return_if_fail (p->contour < self->n_contours);
|
||||
g_return_if_fail (path != NULL);
|
||||
g_return_if_fail (path == s->path);
|
||||
g_return_if_fail (path == e->path);
|
||||
|
||||
gsk_contour_get_position (self->contours[p->contour], p, position);
|
||||
contour = gsk_path_get_contour (path, s->contour);
|
||||
|
||||
if (s->contour == e->contour)
|
||||
{
|
||||
if (gsk_contour_point_compare (contour, s, e) < 0)
|
||||
{
|
||||
gsk_contour_add_segment (contour, self, TRUE, s, e);
|
||||
return;
|
||||
}
|
||||
else if (path->n_contours == 1)
|
||||
{
|
||||
gsk_contour_add_segment (contour, self, TRUE, s, NULL);
|
||||
gsk_contour_add_segment (contour, self, FALSE, NULL, e);
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
gsk_contour_add_segment (contour, self, TRUE, s, NULL);
|
||||
|
||||
for (gsize i = (s->contour + 1) % path->n_contours; i != e->contour; i = (i + 1) % path->n_contours)
|
||||
gsk_path_builder_add_contour (self, gsk_contour_dup (gsk_path_get_contour (path, i)));
|
||||
|
||||
contour = gsk_path_get_contour (path, e->contour);
|
||||
gsk_contour_add_segment (contour, self, FALSE, NULL, e);
|
||||
}
|
||||
|
||||
/**
|
||||
* gsk_path_get_tangent:
|
||||
* gsk_path_get_previous_point:
|
||||
* @self: a `GskPath`
|
||||
* @point: a `GskPathPoint` on @path
|
||||
* @direction: the direction for which to return the tangent
|
||||
* @tangent: (out caller-allocates): Return location for
|
||||
* the tangent at the point
|
||||
* @point: a point on @self
|
||||
* @result: (out caller-allocates): Return location for the result
|
||||
*
|
||||
* Gets the tangent of the path at the point.
|
||||
* Gets the previous 'significant' point on @self before @point.
|
||||
*
|
||||
* Note that certain points on a path may not have a single
|
||||
* tangent, such as sharp turns. At such points, there are
|
||||
* two tangents -- the direction of the path going into the
|
||||
* point, and the direction coming out of it. The @direction
|
||||
* argument lets you choose which one to get.
|
||||
* The 'significant' points of a path are typically the
|
||||
* on-curve points that have been specified when the
|
||||
* path was created.
|
||||
*
|
||||
* Since: 4.14
|
||||
* For example, in a path with 3 Bézier segments, the
|
||||
* significant points are the start of the first segment,
|
||||
* the start point of the second segment (which coincides
|
||||
* with the end point of the first segment), the start
|
||||
* point of the third segment, and the end point of the
|
||||
* last segment.
|
||||
*
|
||||
* If @point is the start point of the path, there is no
|
||||
* prior point, and this function returns `FALSE`.
|
||||
*
|
||||
* Returns: `TRUE` if @result has been set to a point
|
||||
*/
|
||||
void
|
||||
gsk_path_get_tangent (GskPath *self,
|
||||
const GskPathPoint *point,
|
||||
GskPathDirection direction,
|
||||
graphene_vec2_t *tangent)
|
||||
gboolean
|
||||
gsk_path_get_previous_point (GskPath *self,
|
||||
const GskPathPoint *point,
|
||||
GskPathPoint *result)
|
||||
{
|
||||
GskRealPathPoint *p = (GskRealPathPoint *) point;
|
||||
GskRealPathPoint *res = (GskRealPathPoint *) result;
|
||||
const GskContour *contour;
|
||||
|
||||
g_return_if_fail (self != NULL);
|
||||
g_return_if_fail (point != NULL);
|
||||
g_return_if_fail (tangent != NULL);
|
||||
g_return_if_fail (p->contour < self->n_contours);
|
||||
g_return_val_if_fail (self != NULL, FALSE);
|
||||
g_return_val_if_fail (self == p->path, FALSE);
|
||||
|
||||
gsk_contour_get_tangent (self->contours[p->contour], p, direction, tangent);
|
||||
contour = gsk_path_get_contour (self, p->contour);
|
||||
|
||||
if (gsk_contour_get_previous_point (contour, p, res))
|
||||
{
|
||||
res->path = self;
|
||||
res->contour = p->contour;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
if (p->contour > 0)
|
||||
{
|
||||
contour = gsk_path_get_contour (self, p->contour - 1);
|
||||
gsk_contour_get_end_point (contour, res);
|
||||
res->path = self;
|
||||
res->contour = p->contour - 1;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
/**
|
||||
* gsk_path_get_curvature:
|
||||
* gsk_path_get_next_point:
|
||||
* @self: a `GskPath`
|
||||
* @point: a `GskPathPoint` on @path
|
||||
* @center: (out caller-allocates) (nullable): Return location for
|
||||
* the center of the osculating circle
|
||||
* @point: a point on @self
|
||||
* @result: (out caller-allocates): Return location for the result
|
||||
*
|
||||
* Calculates the curvature of the path at the point.
|
||||
* Gets the next 'significant' point on @self after @point.
|
||||
*
|
||||
* Optionally, returns the center of the osculating circle as well.
|
||||
* The 'significant' points of a path are typically the
|
||||
* on-curve points that have been specified when the
|
||||
* path was created.
|
||||
*
|
||||
* If the curvature is infinite (at line segments), zero is returned,
|
||||
* and @center is not modified.
|
||||
* For example, in a path with 3 Bézier segments, the
|
||||
* significant points are the start of the first segment,
|
||||
* the start point of the second segment (which coincides
|
||||
* with the end point of the first segment), the start
|
||||
* point of the third segment, and the end point of the
|
||||
* last segment.
|
||||
*
|
||||
* Returns: The curvature of the path at the given point
|
||||
* If @point is the end point of the path, there is no
|
||||
* next point, and this function returns `FALSE`.
|
||||
*
|
||||
* Since: 4.14
|
||||
* Returns: `TRUE` if @result has been set to a point
|
||||
*/
|
||||
float
|
||||
gsk_path_get_curvature (GskPath *self,
|
||||
const GskPathPoint *point,
|
||||
graphene_point_t *center)
|
||||
gboolean
|
||||
gsk_path_get_next_point (GskPath *self,
|
||||
const GskPathPoint *point,
|
||||
GskPathPoint *result)
|
||||
{
|
||||
GskRealPathPoint *p = (GskRealPathPoint *) point;
|
||||
GskRealPathPoint *res = (GskRealPathPoint *) result;
|
||||
const GskContour *contour;
|
||||
|
||||
g_return_val_if_fail (self != NULL, 0);
|
||||
g_return_val_if_fail (point != NULL, 0);
|
||||
g_return_val_if_fail (p->contour < self->n_contours, 0);
|
||||
g_return_val_if_fail (self != NULL, FALSE);
|
||||
g_return_val_if_fail (self == p->path, FALSE);
|
||||
|
||||
return gsk_contour_get_curvature (self->contours[p->contour], p, center);
|
||||
contour = gsk_path_get_contour (self, p->contour);
|
||||
|
||||
if (gsk_contour_get_next_point (contour, p, res))
|
||||
{
|
||||
res->path = self;
|
||||
res->contour = p->contour;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
if (p->contour < self->n_contours - 1)
|
||||
{
|
||||
contour = gsk_path_get_contour (self, p->contour + 1);
|
||||
gsk_contour_get_start_point (contour, res);
|
||||
res->path = self;
|
||||
res->contour = p->contour + 1;
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
@@ -41,8 +41,6 @@ G_BEGIN_DECLS
|
||||
* By default, [method@Gsk.Path.foreach] will only emit a path with all operations
|
||||
* flattened to straight lines to allow for maximum compatibility. The only
|
||||
* operations emitted will be `GSK_PATH_MOVE`, `GSK_PATH_LINE` and `GSK_PATH_CLOSE`.
|
||||
*
|
||||
* Since: 4.14
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
@@ -112,13 +110,6 @@ gboolean gsk_path_in_fill (GskPath
|
||||
const graphene_point_t *point,
|
||||
GskFillRule fill_rule);
|
||||
|
||||
GDK_AVAILABLE_IN_4_14
|
||||
gboolean gsk_path_get_start_point (GskPath *self,
|
||||
GskPathPoint *result);
|
||||
GDK_AVAILABLE_IN_4_14
|
||||
gboolean gsk_path_get_end_point (GskPath *self,
|
||||
GskPathPoint *result);
|
||||
|
||||
GDK_AVAILABLE_IN_4_14
|
||||
gboolean gsk_path_get_closest_point (GskPath *self,
|
||||
const graphene_point_t *point,
|
||||
@@ -126,20 +117,21 @@ gboolean gsk_path_get_closest_point (GskPath
|
||||
GskPathPoint *result);
|
||||
|
||||
GDK_AVAILABLE_IN_4_14
|
||||
void gsk_path_get_position (GskPath *self,
|
||||
gboolean gsk_path_get_previous_point (GskPath *self,
|
||||
const GskPathPoint *point,
|
||||
graphene_point_t *position);
|
||||
GskPathPoint *result);
|
||||
|
||||
GDK_AVAILABLE_IN_4_14
|
||||
void gsk_path_get_tangent (GskPath *self,
|
||||
gboolean gsk_path_get_next_point (GskPath *self,
|
||||
const GskPathPoint *point,
|
||||
GskPathDirection direction,
|
||||
graphene_vec2_t *tangent);
|
||||
GskPathPoint *result);
|
||||
|
||||
GDK_AVAILABLE_IN_4_14
|
||||
float gsk_path_get_curvature (GskPath *self,
|
||||
const GskPathPoint *point,
|
||||
graphene_point_t *center);
|
||||
gboolean gsk_path_get_start_point (GskPath *self,
|
||||
GskPathPoint *result);
|
||||
GDK_AVAILABLE_IN_4_14
|
||||
gboolean gsk_path_get_end_point (GskPath *self,
|
||||
GskPathPoint *result);
|
||||
|
||||
GDK_AVAILABLE_IN_4_14
|
||||
gboolean gsk_path_foreach (GskPath *self,
|
||||
|
||||
@@ -54,9 +54,6 @@
|
||||
* either common shapes like [method@Gsk.PathBuilder.add_circle]
|
||||
* or by adding from other paths like [method@Gsk.PathBuilder.add_path].
|
||||
*
|
||||
* The `gsk_path_builder_add_*` methods always add complete contours,
|
||||
* and do not use or modify the current point.
|
||||
*
|
||||
* The other option is to define each line and curve manually with
|
||||
* the `gsk_path_builder_*_to` group of functions. You start with
|
||||
* a call to [method@Gsk.PathBuilder.move_to] to set the starting point
|
||||
@@ -66,8 +63,6 @@
|
||||
* back with a line to the starting point.
|
||||
*
|
||||
* This is similar for how paths are drawn in Cairo.
|
||||
*
|
||||
* Since: 4.14
|
||||
*/
|
||||
|
||||
struct _GskPathBuilder
|
||||
@@ -393,13 +388,9 @@ void
|
||||
gsk_path_builder_add_cairo_path (GskPathBuilder *self,
|
||||
const cairo_path_t *path)
|
||||
{
|
||||
graphene_point_t current;
|
||||
|
||||
g_return_if_fail (self != NULL);
|
||||
g_return_if_fail (path != NULL);
|
||||
|
||||
current = self->current_point;
|
||||
|
||||
for (gsize i = 0; i < path->num_data; i += path->data[i].header.length)
|
||||
{
|
||||
const cairo_path_data_t *data = &path->data[i];
|
||||
@@ -430,9 +421,6 @@ gsk_path_builder_add_cairo_path (GskPathBuilder *self,
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
gsk_path_builder_end_current (self);
|
||||
self->current_point = current;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -454,12 +442,8 @@ void
|
||||
gsk_path_builder_add_rect (GskPathBuilder *self,
|
||||
const graphene_rect_t *rect)
|
||||
{
|
||||
graphene_point_t current;
|
||||
|
||||
g_return_if_fail (self != NULL);
|
||||
|
||||
current = self->current_point;
|
||||
|
||||
gsk_path_builder_move_to (self, rect->origin.x, rect->origin.y);
|
||||
|
||||
gsk_path_builder_rel_line_to (self, rect->size.width, 0);
|
||||
@@ -467,79 +451,6 @@ gsk_path_builder_add_rect (GskPathBuilder *self,
|
||||
gsk_path_builder_rel_line_to (self, - rect->size.width, 0);
|
||||
|
||||
gsk_path_builder_close (self);
|
||||
self->current_point = current;
|
||||
}
|
||||
|
||||
/**
|
||||
* gsk_path_builder_add_rounded_rect:
|
||||
* @self: a #GskPathBuilder
|
||||
* @rect: the rounded rect
|
||||
*
|
||||
* Adds @rect as a new contour to the path built in @self.
|
||||
*
|
||||
* Since: 4.14
|
||||
**/
|
||||
void
|
||||
gsk_path_builder_add_rounded_rect (GskPathBuilder *self,
|
||||
const GskRoundedRect *rect)
|
||||
{
|
||||
graphene_point_t current;
|
||||
|
||||
g_return_if_fail (self != NULL);
|
||||
g_return_if_fail (rect != NULL);
|
||||
|
||||
current = self->current_point;
|
||||
|
||||
gsk_path_builder_move_to (self,
|
||||
rect->bounds.origin.x + rect->corner[GSK_CORNER_TOP_LEFT].width,
|
||||
rect->bounds.origin.y);
|
||||
/* top */
|
||||
gsk_path_builder_line_to (self,
|
||||
rect->bounds.origin.x + rect->bounds.size.width - rect->corner[GSK_CORNER_TOP_RIGHT].width,
|
||||
rect->bounds.origin.y);
|
||||
/* topright corner */
|
||||
gsk_path_builder_svg_arc_to (self,
|
||||
rect->corner[GSK_CORNER_TOP_RIGHT].width,
|
||||
rect->corner[GSK_CORNER_TOP_RIGHT].height,
|
||||
0, FALSE, TRUE,
|
||||
rect->bounds.origin.x + rect->bounds.size.width,
|
||||
rect->bounds.origin.y + rect->corner[GSK_CORNER_TOP_RIGHT].height);
|
||||
/* right */
|
||||
gsk_path_builder_line_to (self,
|
||||
rect->bounds.origin.x + rect->bounds.size.width,
|
||||
rect->bounds.origin.y + rect->bounds.size.height - rect->corner[GSK_CORNER_BOTTOM_RIGHT].height);
|
||||
/* bottomright corner */
|
||||
gsk_path_builder_svg_arc_to (self,
|
||||
rect->corner[GSK_CORNER_BOTTOM_RIGHT].width,
|
||||
rect->corner[GSK_CORNER_BOTTOM_RIGHT].height,
|
||||
0, FALSE, TRUE,
|
||||
rect->bounds.origin.x + rect->bounds.size.width - rect->corner[GSK_CORNER_BOTTOM_RIGHT].width,
|
||||
rect->bounds.origin.y + rect->bounds.size.height);
|
||||
/* bottom */
|
||||
gsk_path_builder_line_to (self,
|
||||
rect->bounds.origin.x + rect->corner[GSK_CORNER_BOTTOM_LEFT].width,
|
||||
rect->bounds.origin.y + rect->bounds.size.height);
|
||||
/* bottomleft corner */
|
||||
gsk_path_builder_svg_arc_to (self,
|
||||
rect->corner[GSK_CORNER_BOTTOM_LEFT].width,
|
||||
rect->corner[GSK_CORNER_BOTTOM_LEFT].height,
|
||||
0, FALSE, TRUE,
|
||||
rect->bounds.origin.x,
|
||||
rect->bounds.origin.y + rect->bounds.size.height - rect->corner[GSK_CORNER_BOTTOM_LEFT].height);
|
||||
/* left */
|
||||
gsk_path_builder_line_to (self,
|
||||
rect->bounds.origin.x,
|
||||
rect->bounds.origin.y + rect->corner[GSK_CORNER_TOP_LEFT].height);
|
||||
/* topleft corner */
|
||||
gsk_path_builder_svg_arc_to (self,
|
||||
rect->corner[GSK_CORNER_TOP_LEFT].width,
|
||||
rect->corner[GSK_CORNER_TOP_LEFT].height,
|
||||
0, FALSE, TRUE,
|
||||
rect->bounds.origin.x + rect->corner[GSK_CORNER_TOP_LEFT].width,
|
||||
rect->bounds.origin.y);
|
||||
/* done */
|
||||
gsk_path_builder_close (self);
|
||||
self->current_point = current;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
@@ -571,22 +482,16 @@ gsk_path_builder_add_circle (GskPathBuilder *self,
|
||||
const graphene_point_t *center,
|
||||
float radius)
|
||||
{
|
||||
graphene_point_t current;
|
||||
|
||||
g_return_if_fail (self != NULL);
|
||||
g_return_if_fail (center != NULL);
|
||||
g_return_if_fail (radius > 0);
|
||||
|
||||
current = self->current_point;
|
||||
|
||||
gsk_path_builder_move_to (self, center->x + radius, center->y);
|
||||
gsk_spline_decompose_arc (center, radius,
|
||||
GSK_PATH_TOLERANCE_DEFAULT,
|
||||
0, 2 * M_PI,
|
||||
circle_contour_curve, self);
|
||||
|
||||
gsk_path_builder_close (self);
|
||||
self->current_point = current;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -1078,81 +983,3 @@ gsk_path_builder_add_layout (GskPathBuilder *self,
|
||||
cairo_destroy (cr);
|
||||
cairo_surface_destroy (surface);
|
||||
}
|
||||
|
||||
/**
|
||||
* gsk_path_builder_add_segment:
|
||||
* @self: a `GskPathBuilder`
|
||||
* @path: the `GskPath` to take the segment to
|
||||
* @start: the point on @path to start at
|
||||
* @end: the point on @path to end at
|
||||
*
|
||||
* Adds to @self the segment of @path from @start to @end.
|
||||
*
|
||||
* If @start is equal to or after @end, the path will first add the
|
||||
* segment from @start to the end of the path, and then add the segment
|
||||
* from the beginning to @end. If the path is closed, these segments
|
||||
* will be connected.
|
||||
*
|
||||
* Note that this method always adds a path with the given start point
|
||||
* and end point. To add a closed path, use [method@Gsk.PathBuilder.add_path].
|
||||
*
|
||||
* Since: 4.14
|
||||
*/
|
||||
void
|
||||
gsk_path_builder_add_segment (GskPathBuilder *self,
|
||||
GskPath *path,
|
||||
const GskPathPoint *start,
|
||||
const GskPathPoint *end)
|
||||
{
|
||||
GskRealPathPoint *s = (GskRealPathPoint *) start;
|
||||
GskRealPathPoint *e = (GskRealPathPoint *) end;
|
||||
const GskContour *contour;
|
||||
gsize n_contours = gsk_path_get_n_contours (path);
|
||||
graphene_point_t current;
|
||||
|
||||
g_return_if_fail (self != NULL);
|
||||
g_return_if_fail (path != NULL);
|
||||
g_return_if_fail (start != NULL);
|
||||
g_return_if_fail (end != NULL);
|
||||
g_return_if_fail (s->contour < n_contours);
|
||||
g_return_if_fail (e->contour < n_contours);
|
||||
|
||||
current = self->current_point;
|
||||
|
||||
contour = gsk_path_get_contour (path, s->contour);
|
||||
|
||||
if (s->contour == e->contour)
|
||||
{
|
||||
if (gsk_path_point_compare (start, end) < 0)
|
||||
{
|
||||
gsk_contour_add_segment (contour, self, TRUE, s, e);
|
||||
goto out;
|
||||
}
|
||||
else if (n_contours == 1)
|
||||
{
|
||||
gsk_contour_add_segment (contour, self, TRUE,
|
||||
s,
|
||||
&(GskRealPathPoint) { s->contour, gsk_contour_get_n_points (contour) - 1, 1 });
|
||||
gsk_contour_add_segment (contour, self, FALSE,
|
||||
&(GskRealPathPoint) { s->contour, 1, 0 },
|
||||
e);
|
||||
goto out;
|
||||
}
|
||||
}
|
||||
|
||||
gsk_contour_add_segment (contour, self, TRUE,
|
||||
s,
|
||||
&(GskRealPathPoint) { s->contour, gsk_contour_get_n_points (contour) - 1, 1 });
|
||||
|
||||
for (gsize i = (s->contour + 1) % n_contours; i != e->contour; i = (i + 1) % n_contours)
|
||||
gsk_path_builder_add_contour (self, gsk_contour_dup (gsk_path_get_contour (path, i)));
|
||||
|
||||
contour = gsk_path_get_contour (path, e->contour);
|
||||
gsk_contour_add_segment (contour, self, FALSE,
|
||||
&(GskRealPathPoint) { e->contour, 1, 0 },
|
||||
e);
|
||||
|
||||
out:
|
||||
gsk_path_builder_end_current (self);
|
||||
self->current_point = current;
|
||||
}
|
||||
|
||||
@@ -65,9 +65,6 @@ GDK_AVAILABLE_IN_4_14
|
||||
void gsk_path_builder_add_rect (GskPathBuilder *self,
|
||||
const graphene_rect_t *rect);
|
||||
GDK_AVAILABLE_IN_4_14
|
||||
void gsk_path_builder_add_rounded_rect (GskPathBuilder *self,
|
||||
const GskRoundedRect *rect);
|
||||
GDK_AVAILABLE_IN_4_14
|
||||
void gsk_path_builder_add_circle (GskPathBuilder *self,
|
||||
const graphene_point_t *center,
|
||||
float radius);
|
||||
|
||||
328
gsk/gskpathmeasure.c
Normal file
@@ -0,0 +1,328 @@
|
||||
/*
|
||||
* Copyright © 2020 Benjamin Otte
|
||||
*
|
||||
* This library 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.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library 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 this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Authors: Benjamin Otte <otte@gnome.org>
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "gskpathmeasure.h"
|
||||
|
||||
#include "gskpathbuilder.h"
|
||||
#include "gskpathpointprivate.h"
|
||||
#include "gskpathprivate.h"
|
||||
|
||||
/**
|
||||
* GskPathMeasure:
|
||||
*
|
||||
* `GskPathMeasure` is an object that allows measurements
|
||||
* on `GskPath`s such as determining the length of the path.
|
||||
*
|
||||
* Many measuring operations require approximating the path
|
||||
* with simpler shapes. Therefore, a `GskPathMeasure` has
|
||||
* a tolerance that determines what precision is required
|
||||
* for such approximations.
|
||||
*
|
||||
* A `GskPathMeasure` struct is a reference counted struct
|
||||
* and should be treated as opaque.
|
||||
*/
|
||||
|
||||
typedef struct _GskContourMeasure GskContourMeasure;
|
||||
|
||||
struct _GskContourMeasure
|
||||
{
|
||||
float length;
|
||||
gpointer contour_data;
|
||||
};
|
||||
|
||||
struct _GskPathMeasure
|
||||
{
|
||||
/*< private >*/
|
||||
guint ref_count;
|
||||
|
||||
GskPath *path;
|
||||
float tolerance;
|
||||
|
||||
float length;
|
||||
gsize n_contours;
|
||||
GskContourMeasure measures[];
|
||||
};
|
||||
|
||||
G_DEFINE_BOXED_TYPE (GskPathMeasure, gsk_path_measure,
|
||||
gsk_path_measure_ref,
|
||||
gsk_path_measure_unref)
|
||||
|
||||
/**
|
||||
* gsk_path_measure_new:
|
||||
* @path: the path to measure
|
||||
*
|
||||
* Creates a measure object for the given @path.
|
||||
*
|
||||
* Returns: a new `GskPathMeasure` representing @path
|
||||
*
|
||||
* Since: 4.14
|
||||
*/
|
||||
GskPathMeasure *
|
||||
gsk_path_measure_new (GskPath *path)
|
||||
{
|
||||
return gsk_path_measure_new_with_tolerance (path, GSK_PATH_TOLERANCE_DEFAULT);
|
||||
}
|
||||
|
||||
/**
|
||||
* gsk_path_measure_new_with_tolerance:
|
||||
* @path: the path to measure
|
||||
* @tolerance: the tolerance for measuring operations
|
||||
*
|
||||
* Creates a measure object for the given @path and @tolerance.
|
||||
*
|
||||
* Returns: a new `GskPathMeasure` representing @path
|
||||
*
|
||||
* Since: 4.14
|
||||
*/
|
||||
GskPathMeasure *
|
||||
gsk_path_measure_new_with_tolerance (GskPath *path,
|
||||
float tolerance)
|
||||
{
|
||||
GskPathMeasure *self;
|
||||
gsize i, n_contours;
|
||||
|
||||
g_return_val_if_fail (path != NULL, NULL);
|
||||
g_return_val_if_fail (tolerance > 0, NULL);
|
||||
|
||||
n_contours = gsk_path_get_n_contours (path);
|
||||
|
||||
self = g_malloc0 (sizeof (GskPathMeasure) + n_contours * sizeof (GskContourMeasure));
|
||||
|
||||
self->ref_count = 1;
|
||||
self->path = gsk_path_ref (path);
|
||||
self->tolerance = tolerance;
|
||||
self->n_contours = n_contours;
|
||||
|
||||
for (i = 0; i < n_contours; i++)
|
||||
{
|
||||
self->measures[i].contour_data = gsk_contour_init_measure (gsk_path_get_contour (path, i),
|
||||
self->tolerance,
|
||||
&self->measures[i].length);
|
||||
self->length += self->measures[i].length;
|
||||
}
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
/**
|
||||
* gsk_path_measure_ref:
|
||||
* @self: a `GskPathMeasure`
|
||||
*
|
||||
* Increases the reference count of a `GskPathMeasure` by one.
|
||||
*
|
||||
* Returns: the passed in `GskPathMeasure`.
|
||||
*
|
||||
* Since: 4.14
|
||||
*/
|
||||
GskPathMeasure *
|
||||
gsk_path_measure_ref (GskPathMeasure *self)
|
||||
{
|
||||
g_return_val_if_fail (self != NULL, NULL);
|
||||
|
||||
self->ref_count++;
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
/**
|
||||
* gsk_path_measure_unref:
|
||||
* @self: a `GskPathMeasure`
|
||||
*
|
||||
* Decreases the reference count of a `GskPathMeasure` by one.
|
||||
*
|
||||
* If the resulting reference count is zero, frees the object.
|
||||
*
|
||||
* Since: 4.14
|
||||
*/
|
||||
void
|
||||
gsk_path_measure_unref (GskPathMeasure *self)
|
||||
{
|
||||
gsize i;
|
||||
|
||||
g_return_if_fail (self != NULL);
|
||||
g_return_if_fail (self->ref_count > 0);
|
||||
|
||||
self->ref_count--;
|
||||
if (self->ref_count > 0)
|
||||
return;
|
||||
|
||||
for (i = 0; i < self->n_contours; i++)
|
||||
{
|
||||
gsk_contour_free_measure (gsk_path_get_contour (self->path, i),
|
||||
self->measures[i].contour_data);
|
||||
}
|
||||
|
||||
gsk_path_unref (self->path);
|
||||
g_free (self);
|
||||
}
|
||||
|
||||
/**
|
||||
* gsk_path_measure_get_path:
|
||||
* @self: a `GskPathMeasure`
|
||||
*
|
||||
* Returns the path that the measure was created for.
|
||||
*
|
||||
* Returns: (transfer none): the path of @self
|
||||
*
|
||||
* Since: 4.14
|
||||
*/
|
||||
GskPath *
|
||||
gsk_path_measure_get_path (GskPathMeasure *self)
|
||||
{
|
||||
return self->path;
|
||||
}
|
||||
|
||||
/**
|
||||
* gsk_path_measure_get_tolerance:
|
||||
* @self: a `GskPathMeasure`
|
||||
*
|
||||
* Returns the tolerance that the measure was created with.
|
||||
*
|
||||
* Returns: the tolerance of @self
|
||||
*
|
||||
* Since: 4.14
|
||||
*/
|
||||
float
|
||||
gsk_path_measure_get_tolerance (GskPathMeasure *self)
|
||||
{
|
||||
return self->tolerance;
|
||||
}
|
||||
|
||||
/**
|
||||
* gsk_path_measure_get_length:
|
||||
* @self: a `GskPathMeasure`
|
||||
*
|
||||
* Gets the length of the path being measured.
|
||||
*
|
||||
* The length is cached, so this function does not do any work.
|
||||
*
|
||||
* Returns: The length of the path measured by @self
|
||||
*
|
||||
* Since: 4.14
|
||||
*/
|
||||
float
|
||||
gsk_path_measure_get_length (GskPathMeasure *self)
|
||||
{
|
||||
g_return_val_if_fail (self != NULL, 0);
|
||||
|
||||
return self->length;
|
||||
}
|
||||
|
||||
static float
|
||||
gsk_path_measure_clamp_distance (GskPathMeasure *self,
|
||||
float distance)
|
||||
{
|
||||
if (isnan (distance))
|
||||
return 0;
|
||||
|
||||
return CLAMP (distance, 0, self->length);
|
||||
}
|
||||
|
||||
/**
|
||||
* gsk_path_measure_get_point:
|
||||
* @self: a `GskPathMeasure`
|
||||
* @distance: the distance
|
||||
* @result: (out caller-allocates): return location for the result
|
||||
*
|
||||
* Sets @result to the point at the given distance into the path.
|
||||
*
|
||||
* An empty path has no points, so `FALSE` is returned in that case.
|
||||
*
|
||||
* Returns: `TRUE` if @result was set
|
||||
*
|
||||
* Since: 4.14
|
||||
*/
|
||||
gboolean
|
||||
gsk_path_measure_get_point (GskPathMeasure *self,
|
||||
float distance,
|
||||
GskPathPoint *result)
|
||||
{
|
||||
GskRealPathPoint *res = (GskRealPathPoint *) result;
|
||||
gsize i;
|
||||
float offset;
|
||||
const GskContour *contour;
|
||||
|
||||
g_return_val_if_fail (self != NULL, FALSE);
|
||||
g_return_val_if_fail (result != NULL, FALSE);
|
||||
|
||||
if (self->n_contours == 0)
|
||||
return FALSE;
|
||||
|
||||
offset = gsk_path_measure_clamp_distance (self, distance);
|
||||
|
||||
for (i = 0; i < self->n_contours - 1; i++)
|
||||
{
|
||||
if (offset < self->measures[i].length)
|
||||
break;
|
||||
|
||||
offset -= self->measures[i].length;
|
||||
}
|
||||
|
||||
g_assert (0 <= i && i < self->n_contours);
|
||||
|
||||
offset = CLAMP (offset, 0, self->measures[i].length);
|
||||
|
||||
contour = gsk_path_get_contour (self->path, i);
|
||||
|
||||
gsk_contour_get_point (contour, self->measures[i].contour_data, offset, res);
|
||||
|
||||
res->path = self->path;
|
||||
res->contour = i;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* gsk_path_point_get_distance:
|
||||
* @measure: a `GskPathMeasure`
|
||||
* @point: a `GskPathPoint on the path of @self
|
||||
*
|
||||
* Returns the distance from the beginning of the path
|
||||
* to @point.
|
||||
*
|
||||
* Returns: the distance of @point
|
||||
*
|
||||
* Since: 4.14
|
||||
*/
|
||||
float
|
||||
gsk_path_point_get_distance (GskPathMeasure *measure,
|
||||
const GskPathPoint *point)
|
||||
{
|
||||
GskRealPathPoint *p = (GskRealPathPoint *)point;
|
||||
const GskContour *contour = gsk_path_get_contour (measure->path, p->contour);
|
||||
float contour_offset = 0;
|
||||
|
||||
g_return_val_if_fail (measure != NULL, 0);
|
||||
g_return_val_if_fail (measure->path == p->path, 0);
|
||||
g_return_val_if_fail (contour != NULL, 0);
|
||||
|
||||
for (gsize i = 0; i < measure->n_contours; i++)
|
||||
{
|
||||
if (contour == gsk_path_get_contour (measure->path, i))
|
||||
return contour_offset + gsk_contour_get_distance (contour,
|
||||
p,
|
||||
measure->measures[i].contour_data);
|
||||
|
||||
contour_offset += measure->measures[i].length;
|
||||
}
|
||||
|
||||
g_return_val_if_reached (0);
|
||||
}
|
||||
66
gsk/gskpathmeasure.h
Normal file
@@ -0,0 +1,66 @@
|
||||
/*
|
||||
* Copyright © 2020 Benjamin Otte
|
||||
*
|
||||
* This library 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.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library 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 this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Authors: Benjamin Otte <otte@gnome.org>
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#if !defined (__GSK_H_INSIDE__) && !defined (GTK_COMPILATION)
|
||||
#error "Only <gsk/gsk.h> can be included directly."
|
||||
#endif
|
||||
|
||||
|
||||
#include <gsk/gskpath.h>
|
||||
#include <gsk/gskpathpoint.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define GSK_TYPE_PATH_MEASURE (gsk_path_measure_get_type ())
|
||||
|
||||
GDK_AVAILABLE_IN_4_14
|
||||
GType gsk_path_measure_get_type (void) G_GNUC_CONST;
|
||||
GDK_AVAILABLE_IN_4_14
|
||||
GskPathMeasure * gsk_path_measure_new (GskPath *path);
|
||||
GDK_AVAILABLE_IN_4_14
|
||||
GskPathMeasure * gsk_path_measure_new_with_tolerance (GskPath *path,
|
||||
float tolerance);
|
||||
|
||||
GDK_AVAILABLE_IN_4_14
|
||||
GskPathMeasure * gsk_path_measure_ref (GskPathMeasure *self);
|
||||
GDK_AVAILABLE_IN_4_14
|
||||
void gsk_path_measure_unref (GskPathMeasure *self);
|
||||
|
||||
GDK_AVAILABLE_IN_4_14
|
||||
GskPath * gsk_path_measure_get_path (GskPathMeasure *self) G_GNUC_PURE;
|
||||
GDK_AVAILABLE_IN_4_14
|
||||
float gsk_path_measure_get_tolerance (GskPathMeasure *self) G_GNUC_PURE;
|
||||
|
||||
GDK_AVAILABLE_IN_4_14
|
||||
float gsk_path_measure_get_length (GskPathMeasure *self);
|
||||
|
||||
GDK_AVAILABLE_IN_4_14
|
||||
gboolean gsk_path_measure_get_point (GskPathMeasure *self,
|
||||
float distance,
|
||||
GskPathPoint *result);
|
||||
|
||||
GDK_AVAILABLE_IN_4_14
|
||||
float gsk_path_measure_get_distance (GskPathMeasure *self,
|
||||
const GskPathPoint *point);
|
||||
|
||||
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GskPathMeasure, gsk_path_measure_unref)
|
||||
|
||||
G_END_DECLS
|
||||
@@ -22,6 +22,7 @@
|
||||
#include "gskpathpointprivate.h"
|
||||
|
||||
#include "gskcontourprivate.h"
|
||||
#include "gskpathmeasure.h"
|
||||
|
||||
#include "gdk/gdkprivate.h"
|
||||
|
||||
@@ -33,14 +34,13 @@
|
||||
* It can be queried for properties of the path at that point, such as its
|
||||
* tangent or its curvature.
|
||||
*
|
||||
* To obtain a `GskPathPoint`, use [method@Gsk.Path.get_closest_point].
|
||||
* To obtain a `GskPathPoint`, use [method@Gsk.Path.get_closest_point]
|
||||
* or [method@Gsk.PathMeasure.get_point].
|
||||
*
|
||||
* Note that `GskPathPoint` structs are meant to be stack-allocated, and
|
||||
* don't a reference to the path object they are obtained from. It is the
|
||||
* callers responsibility to keep a reference to the path as long as the
|
||||
* `GskPathPoint` is used.
|
||||
*
|
||||
* Since: 4.14
|
||||
*/
|
||||
|
||||
G_DEFINE_BOXED_TYPE (GskPathPoint, gsk_path_point,
|
||||
@@ -67,72 +67,91 @@ gsk_path_point_free (GskPathPoint *point)
|
||||
}
|
||||
|
||||
/**
|
||||
* gsk_path_point_equal:
|
||||
* @point1: a `GskPathPoint`
|
||||
* @point2: another `GskPathPoint`
|
||||
* gsk_path_point_get_position:
|
||||
* @path: a `GskPath`
|
||||
* @point: a `GskPathPoint` on @path
|
||||
* @position: (out caller-allocates): Return location for
|
||||
* the coordinates of the point
|
||||
*
|
||||
* Returns whether the two path points refer to the same
|
||||
* location on all paths.
|
||||
* Gets the position of the point.
|
||||
*
|
||||
* Note that the start- and endpoint of a closed contour
|
||||
* will compare nonequal according to this definition.
|
||||
* Use [method@Gsk.Path.is_closed] to find out if the
|
||||
* start- and endpoint of a concrete path refer to the
|
||||
* same location.
|
||||
*
|
||||
* Return: `TRUE` if @point1 and @point2 are equal
|
||||
* Since: 4.14
|
||||
*/
|
||||
gboolean
|
||||
gsk_path_point_equal (const GskPathPoint *point1,
|
||||
const GskPathPoint *point2)
|
||||
void
|
||||
gsk_path_point_get_position (GskPath *path,
|
||||
const GskPathPoint *point,
|
||||
graphene_point_t *position)
|
||||
{
|
||||
const GskRealPathPoint *p1 = (const GskRealPathPoint *) point1;
|
||||
const GskRealPathPoint *p2 = (const GskRealPathPoint *) point2;
|
||||
GskRealPathPoint *self = (GskRealPathPoint *) point;
|
||||
const GskContour *contour = gsk_path_get_contour (path, self->contour);
|
||||
|
||||
if (p1->contour == p2->contour)
|
||||
{
|
||||
if ((p1->idx == p2->idx && p1->t == p2->t) ||
|
||||
(p1->idx + 1 == p2->idx && p1->t == 1 && p2->t == 0) ||
|
||||
(p1->idx == p2->idx + 1 && p1->t == 0 && p2->t == 1))
|
||||
return TRUE;
|
||||
}
|
||||
g_return_if_fail (path == self->path);
|
||||
g_return_if_fail (contour != NULL);
|
||||
|
||||
return FALSE;
|
||||
gsk_contour_get_position (contour, self, position);
|
||||
}
|
||||
|
||||
/**
|
||||
* gsk_path_point_compare:
|
||||
* @point1: a `GskPathPoint`
|
||||
* @point2: another `GskPathPoint`
|
||||
* gsk_path_point_get_tangent:
|
||||
* @path: a `GskPath`
|
||||
* @point: a `GskPathPoint` on @path
|
||||
* @direction: the direction for which to return the tangent
|
||||
* @tangent: (out caller-allocates): Return location for
|
||||
* the tangent at the point
|
||||
*
|
||||
* Returns whether @point1 is before or after @point2.
|
||||
* Gets the tangent of the path at the point.
|
||||
*
|
||||
* Returns: -1 if @point1 is before @point2,
|
||||
* 1 if @point1 is after @point2,
|
||||
* 0 if they are equal
|
||||
* Note that certain points on a path may not have a single
|
||||
* tangent, such as sharp turns. At such points, there are
|
||||
* two tangents -- the direction of the path going into the
|
||||
* point, and the direction coming out of it. The @direction
|
||||
* argument lets you choose which one to get.
|
||||
*
|
||||
* Since: 4.14
|
||||
*/
|
||||
int
|
||||
gsk_path_point_compare (const GskPathPoint *point1,
|
||||
const GskPathPoint *point2)
|
||||
void
|
||||
gsk_path_point_get_tangent (GskPath *path,
|
||||
const GskPathPoint *point,
|
||||
GskPathDirection direction,
|
||||
graphene_vec2_t *tangent)
|
||||
{
|
||||
const GskRealPathPoint *p1 = (const GskRealPathPoint *) point1;
|
||||
const GskRealPathPoint *p2 = (const GskRealPathPoint *) point2;
|
||||
GskRealPathPoint *self = (GskRealPathPoint *) point;
|
||||
const GskContour *contour = gsk_path_get_contour (path, self->contour);
|
||||
|
||||
if (gsk_path_point_equal (point1, point2))
|
||||
return 0;
|
||||
g_return_if_fail (path == self->path);
|
||||
g_return_if_fail (contour != NULL);
|
||||
|
||||
if (p1->contour < p2->contour)
|
||||
return -1;
|
||||
else if (p1->contour > p2->contour)
|
||||
return 1;
|
||||
else if (p1->idx < p2->idx)
|
||||
return -1;
|
||||
else if (p1->idx > p2->idx)
|
||||
return 1;
|
||||
else if (p1->t < p2->t)
|
||||
return -1;
|
||||
else if (p1->t > p2->t)
|
||||
return 1;
|
||||
|
||||
return 0;
|
||||
gsk_contour_get_tangent (contour, self, direction, tangent);
|
||||
}
|
||||
|
||||
/**
|
||||
* gsk_path_point_get_curvature:
|
||||
* @path: a `GskPath`
|
||||
* @point: a `GskPathPoint` on @path
|
||||
* @center: (out caller-allocates): Return location for
|
||||
* the center of the osculating circle
|
||||
*
|
||||
* Calculates the curvature of the path at the point.
|
||||
*
|
||||
* Optionally, returns the center of the osculating circle as well.
|
||||
*
|
||||
* If the curvature is infinite (at line segments), zero is returned,
|
||||
* and @center is not modified.
|
||||
*
|
||||
* Returns: The curvature of the path at the given point
|
||||
*
|
||||
* Since: 4.14
|
||||
*/
|
||||
float
|
||||
gsk_path_point_get_curvature (GskPath *path,
|
||||
const GskPathPoint *point,
|
||||
graphene_point_t *center)
|
||||
{
|
||||
GskRealPathPoint *self = (GskRealPathPoint *) point;
|
||||
const GskContour *contour = gsk_path_get_contour (path, self->contour);
|
||||
|
||||
g_return_val_if_fail (path == self->path, 0);
|
||||
g_return_val_if_fail (contour != NULL, 0);
|
||||
|
||||
return gsk_contour_get_curvature (contour, self, center);
|
||||
}
|
||||
|
||||
@@ -49,11 +49,23 @@ GDK_AVAILABLE_IN_4_14
|
||||
void gsk_path_point_free (GskPathPoint *point);
|
||||
|
||||
GDK_AVAILABLE_IN_4_14
|
||||
gboolean gsk_path_point_equal (const GskPathPoint *point1,
|
||||
const GskPathPoint *point2);
|
||||
void gsk_path_point_get_position (GskPath *path,
|
||||
const GskPathPoint *point,
|
||||
graphene_point_t *position);
|
||||
|
||||
GDK_AVAILABLE_IN_4_14
|
||||
int gsk_path_point_compare (const GskPathPoint *point1,
|
||||
const GskPathPoint *point2);
|
||||
void gsk_path_point_get_tangent (GskPath *path,
|
||||
const GskPathPoint *point,
|
||||
GskPathDirection direction,
|
||||
graphene_vec2_t *tangent);
|
||||
|
||||
GDK_AVAILABLE_IN_4_14
|
||||
float gsk_path_point_get_curvature (GskPath *path,
|
||||
const GskPathPoint *point,
|
||||
graphene_point_t *center);
|
||||
|
||||
GDK_AVAILABLE_IN_4_14
|
||||
float gsk_path_point_get_distance (GskPathMeasure *measure,
|
||||
const GskPathPoint *point);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
@@ -7,9 +7,15 @@ G_BEGIN_DECLS
|
||||
|
||||
struct _GskRealPathPoint
|
||||
{
|
||||
GskPath *path;
|
||||
gsize contour;
|
||||
gsize idx;
|
||||
float t;
|
||||
|
||||
union {
|
||||
struct {
|
||||
unsigned int idx;
|
||||
float t;
|
||||
} std;
|
||||
} data;
|
||||
};
|
||||
|
||||
G_STATIC_ASSERT (sizeof (GskRealPathPoint) <= sizeof (GskPathPoint));
|
||||
|
||||
@@ -35,6 +35,7 @@ G_BEGIN_DECLS
|
||||
|
||||
#define GSK_SERIALIZATION_ERROR (gsk_serialization_error_quark ())
|
||||
|
||||
typedef struct _GskRenderNode GskRenderNode;
|
||||
typedef struct _GskColorStop GskColorStop;
|
||||
typedef struct _GskShadow GskShadow;
|
||||
|
||||
|
||||
@@ -3970,7 +3970,7 @@ gsk_repeat_node_draw (GskRenderNode *node,
|
||||
scale_x *= width / self->child_bounds.size.width;
|
||||
scale_y *= height / self->child_bounds.size.height;
|
||||
cairo_surface_set_device_scale (surface, scale_x, scale_y);
|
||||
cairo_surface_set_device_offset (surface,
|
||||
cairo_surface_set_device_offset (surface,
|
||||
- self->child_bounds.origin.x * scale_x,
|
||||
- self->child_bounds.origin.y * scale_y);
|
||||
|
||||
@@ -4141,7 +4141,7 @@ gsk_clip_node_diff (GskRenderNode *node1,
|
||||
gsk_render_node_diff_impossible (node1, node2, region);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
static void
|
||||
gsk_clip_node_class_init (gpointer g_class,
|
||||
gpointer class_data)
|
||||
@@ -4372,15 +4372,6 @@ gsk_rounded_clip_node_get_clip (const GskRenderNode *node)
|
||||
/* }}} */
|
||||
/* {{{ GSK_FILL_NODE */
|
||||
|
||||
/**
|
||||
* GskFillNode:
|
||||
*
|
||||
* A render node filling the area given by [struct@Gsk.Path]
|
||||
* and [enum@Gsk.FillRule] with the child node.
|
||||
*
|
||||
* Since: 4.14
|
||||
*/
|
||||
|
||||
struct _GskFillNode
|
||||
{
|
||||
GskRenderNode render_node;
|
||||
@@ -4581,15 +4572,6 @@ gsk_fill_node_get_fill_rule (const GskRenderNode *node)
|
||||
/* }}} */
|
||||
/* {{{ GSK_STROKE_NODE */
|
||||
|
||||
/**
|
||||
* GskStrokeNode:
|
||||
*
|
||||
* A render node that will fill the area determined by stroking the the given
|
||||
* [struct@Gsk.Path] using the [struct@Gsk.Stroke] attributes.
|
||||
*
|
||||
* Since: 4.14
|
||||
*/
|
||||
|
||||
struct _GskStrokeNode
|
||||
{
|
||||
GskRenderNode render_node;
|
||||
@@ -4688,10 +4670,8 @@ gsk_stroke_node_class_init (gpointer g_class,
|
||||
* @path: (transfer none): The path describing the area to stroke
|
||||
* @stroke: (transfer none): The stroke attributes to use
|
||||
*
|
||||
* Creates a #GskRenderNode that will fill the outline generated by stroking
|
||||
* the given @path using the attributes defined in @stroke.
|
||||
*
|
||||
* The area is filled with @child.
|
||||
* Creates a #GskRenderNode that will stroke the @child along the given
|
||||
* @path using the attributes defined in @stroke.
|
||||
*
|
||||
* Returns: (transfer none) (type GskStrokeNode): A new #GskRenderNode
|
||||
*
|
||||
|
||||
@@ -14,7 +14,7 @@ typedef struct _GskRenderNodeClass GskRenderNodeClass;
|
||||
* We don't add an "n-types" value to avoid having to handle
|
||||
* it in every single switch.
|
||||
*/
|
||||
#define GSK_RENDER_NODE_TYPE_N_TYPES (GSK_STROKE_NODE + 1)
|
||||
#define GSK_RENDER_NODE_TYPE_N_TYPES (GSK_MASK_NODE + 1)
|
||||
|
||||
extern GType gsk_render_node_types[];
|
||||
|
||||
|
||||
@@ -26,8 +26,6 @@
|
||||
*
|
||||
* A `GskStroke` struct collects the parameters that influence
|
||||
* the operation of stroking a path.
|
||||
*
|
||||
* Since: 4.14
|
||||
*/
|
||||
|
||||
G_DEFINE_BOXED_TYPE (GskStroke, gsk_stroke, gsk_stroke_copy, gsk_stroke_free)
|
||||
|
||||
@@ -27,9 +27,9 @@
|
||||
|
||||
typedef struct _GskPath GskPath;
|
||||
typedef struct _GskPathBuilder GskPathBuilder;
|
||||
typedef struct _GskPathMeasure GskPathMeasure;
|
||||
typedef struct _GskPathPoint GskPathPoint;
|
||||
typedef struct _GskRenderer GskRenderer;
|
||||
typedef struct _GskRenderNode GskRenderNode;
|
||||
typedef struct _GskStroke GskStroke;
|
||||
typedef struct _GskTransform GskTransform;
|
||||
|
||||
|
||||
@@ -28,6 +28,7 @@ gsk_public_sources = files([
|
||||
'gskglshader.c',
|
||||
'gskpath.c',
|
||||
'gskpathbuilder.c',
|
||||
'gskpathmeasure.c',
|
||||
'gskpathpoint.c',
|
||||
'gskrenderer.c',
|
||||
'gskrendernode.c',
|
||||
@@ -75,6 +76,7 @@ gsk_public_headers = files([
|
||||
'gskglshader.h',
|
||||
'gskpath.h',
|
||||
'gskpathbuilder.h',
|
||||
'gskpathmeasure.h',
|
||||
'gskpathpoint.h',
|
||||
'gskrenderer.h',
|
||||
'gskrendernode.h',
|
||||
|
||||
@@ -234,8 +234,8 @@
|
||||
* API as they come in. Usually `GtkCellArea` is only interested in
|
||||
* button events, however some customized derived areas can be implemented
|
||||
* who are interested in handling other events. Handling an event can
|
||||
* trigger the [signal@Gtk.CellArea::focus-changed] signal to fire; as well
|
||||
* as [signal@Gtk.CellArea::add-editable] in the case that an editable cell
|
||||
* trigger the [`signal@Gtk.CellArea::focus-changed`] signal to fire; as well
|
||||
* as [`signal@Gtk.CellArea::add-editable`] in the case that an editable cell
|
||||
* was clicked and needs to start editing. You can call
|
||||
* [method@Gtk.CellArea.stop_editing] at any time to cancel any cell editing
|
||||
* that is currently in progress.
|
||||
|
||||
@@ -1140,7 +1140,7 @@ gtk_tree_view_class_init (GtkTreeViewClass *class)
|
||||
* @column: (nullable): the `GtkTreeViewColumn` in which the activation occurred
|
||||
*
|
||||
* The "row-activated" signal is emitted when the method
|
||||
* [method@Gtk.TreeView.row_activated] is called.
|
||||
* [`method@Gtk.TreeView.row_activated`] is called.
|
||||
*
|
||||
* This signal is emitted when the user double-clicks a treeview row with the
|
||||
* [property@Gtk.TreeView:activate-on-single-click] property set to %FALSE,
|
||||
|
||||
@@ -937,13 +937,13 @@ gtk_tree_view_column_update_button (GtkTreeViewColumn *tree_column)
|
||||
if ((!alternative && priv->sort_order == GTK_SORT_ASCENDING) ||
|
||||
(alternative && priv->sort_order == GTK_SORT_DESCENDING))
|
||||
{
|
||||
gtk_widget_remove_css_class (arrow, "ascending");
|
||||
gtk_widget_add_css_class (arrow, "descending");
|
||||
gtk_widget_remove_css_class (arrow, "descending");
|
||||
gtk_widget_add_css_class (arrow, "ascending");
|
||||
}
|
||||
else
|
||||
{
|
||||
gtk_widget_remove_css_class (arrow, "descending");
|
||||
gtk_widget_add_css_class (arrow, "ascending");
|
||||
gtk_widget_remove_css_class (arrow, "ascending");
|
||||
gtk_widget_add_css_class (arrow, "descending");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1798,8 +1798,6 @@ gtk_column_view_scroll_to_column (GtkColumnView *self,
|
||||
gtk_adjustment_get_page_size (self->hadjustment));
|
||||
|
||||
gtk_adjustment_set_value (self->hadjustment, new_value);
|
||||
|
||||
g_clear_pointer (&scroll_info, gtk_scroll_info_unref);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -2216,14 +2214,9 @@ gtk_column_view_scroll_to (GtkColumnView *self,
|
||||
if (column && (flags & GTK_LIST_SCROLL_FOCUS))
|
||||
gtk_column_view_set_focus_column (self, column, FALSE);
|
||||
|
||||
gtk_list_view_scroll_to (self->listview,
|
||||
pos,
|
||||
flags,
|
||||
scroll ? gtk_scroll_info_ref (scroll) : NULL);
|
||||
gtk_list_view_scroll_to (self->listview, pos, flags, scroll);
|
||||
|
||||
if (column)
|
||||
gtk_column_view_scroll_to_column (self, column, scroll);
|
||||
else
|
||||
g_clear_pointer (&scroll, gtk_scroll_info_unref);
|
||||
}
|
||||
|
||||
|
||||
@@ -27,9 +27,9 @@
|
||||
* `GtkListHeader` is used by list widgets to represent the headers they
|
||||
* display.
|
||||
*
|
||||
* `GtkListHeader` objects are managed just like [class@Gtk.ListItem]
|
||||
* objects via their factory, but provide a different set of properties suitable
|
||||
* for managing the header instead of individual items.
|
||||
* The `GtkListHeader`s are managed just like [class@gtk.ListItem]s via
|
||||
* their factory, but provide a different set of properties suitable for
|
||||
* managing the header instead of individual items.
|
||||
*
|
||||
* Since: 4.12
|
||||
*/
|
||||
|
||||
@@ -27,14 +27,13 @@
|
||||
/**
|
||||
* GtkListItem:
|
||||
*
|
||||
* `GtkListItem` is used by list widgets to represent items in a
|
||||
* [iface@Gio.ListModel].
|
||||
* `GtkListItem` is used by list widgets to represent items in a `GListModel`.
|
||||
*
|
||||
* `GtkListItem` objects are managed by the list widget (with its factory)
|
||||
* The `GtkListItem`s are managed by the list widget (with its factory)
|
||||
* and cannot be created by applications, but they need to be populated
|
||||
* by application code. This is done by calling [method@Gtk.ListItem.set_child].
|
||||
*
|
||||
* `GtkListItem` objects exist in 2 stages:
|
||||
* `GtkListItem`s exist in 2 stages:
|
||||
*
|
||||
* 1. The unbound stage where the listitem is not currently connected to
|
||||
* an item in the list. In that case, the [property@Gtk.ListItem:item]
|
||||
|
||||
@@ -1510,8 +1510,8 @@ gtk_menu_button_set_child (GtkMenuButton *menu_button,
|
||||
NULL,
|
||||
NULL,
|
||||
NULL,
|
||||
(GtkGizmoFocusFunc)gtk_widget_focus_child,
|
||||
NULL);
|
||||
(GtkGizmoFocusFunc)gtk_widget_focus_self,
|
||||
(GtkGizmoGrabFocusFunc)gtk_widget_grab_focus_self);
|
||||
|
||||
gtk_widget_set_layout_manager (inner_widget, gtk_bin_layout_new ());
|
||||
gtk_widget_set_hexpand (inner_widget, TRUE);
|
||||
|
||||
@@ -33,12 +33,12 @@
|
||||
/**
|
||||
* GtkOverlayLayout:
|
||||
*
|
||||
* `GtkOverlayLayout` is the layout manager used by [class@Gtk.Overlay].
|
||||
* `GtkOverlayLayout` is the layout manager used by `GtkOverlay`.
|
||||
*
|
||||
* It places widgets as overlays on top of the main child.
|
||||
*
|
||||
* This is not a reusable layout manager, since it expects its widget
|
||||
* to be a `GtkOverlay`. It is only listed here so that its layout
|
||||
* to be a `GtkOverlay`. It only listed here so that its layout
|
||||
* properties get documented.
|
||||
*/
|
||||
|
||||
|
||||
@@ -3977,11 +3977,9 @@ gtk_text_insert_at_cursor (GtkText *self,
|
||||
|
||||
if (priv->editable)
|
||||
{
|
||||
begin_change (self);
|
||||
gtk_text_reset_im_context (self);
|
||||
gtk_editable_insert_text (GTK_EDITABLE (self), str, -1, &pos);
|
||||
gtk_text_set_selection_bounds (self, pos, pos);
|
||||
end_change (self);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4001,14 +3999,12 @@ gtk_text_delete_from_cursor (GtkText *self,
|
||||
return;
|
||||
}
|
||||
|
||||
begin_change (self);
|
||||
|
||||
if (priv->selection_bound != priv->current_pos)
|
||||
{
|
||||
gtk_text_delete_selection (self);
|
||||
gtk_text_schedule_im_reset (self);
|
||||
gtk_text_reset_im_context (self);
|
||||
goto done;
|
||||
return;
|
||||
}
|
||||
|
||||
switch (type)
|
||||
@@ -4078,8 +4074,6 @@ gtk_text_delete_from_cursor (GtkText *self,
|
||||
gtk_text_reset_im_context (self);
|
||||
}
|
||||
|
||||
done:
|
||||
end_change (self);
|
||||
gtk_text_pend_cursor_blink (self);
|
||||
}
|
||||
|
||||
@@ -4095,14 +4089,12 @@ gtk_text_backspace (GtkText *self)
|
||||
return;
|
||||
}
|
||||
|
||||
begin_change (self);
|
||||
|
||||
if (priv->selection_bound != priv->current_pos)
|
||||
{
|
||||
gtk_text_delete_selection (self);
|
||||
gtk_text_schedule_im_reset (self);
|
||||
gtk_text_reset_im_context (self);
|
||||
goto done;
|
||||
return;
|
||||
}
|
||||
|
||||
prev_pos = gtk_text_move_logically (self, priv->current_pos, -1);
|
||||
@@ -4155,8 +4147,6 @@ gtk_text_backspace (GtkText *self)
|
||||
gtk_widget_error_bell (GTK_WIDGET (self));
|
||||
}
|
||||
|
||||
done:
|
||||
end_change (self);
|
||||
gtk_text_pend_cursor_blink (self);
|
||||
}
|
||||
|
||||
@@ -4201,11 +4191,7 @@ gtk_text_cut_clipboard (GtkText *self)
|
||||
if (priv->editable)
|
||||
{
|
||||
if (priv->selection_bound != priv->current_pos)
|
||||
{
|
||||
begin_change (self);
|
||||
gtk_text_delete_selection (self);
|
||||
end_change (self);
|
||||
}
|
||||
gtk_text_delete_selection (self);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -4223,15 +4209,9 @@ gtk_text_paste_clipboard (GtkText *self)
|
||||
GtkTextPrivate *priv = gtk_text_get_instance_private (self);
|
||||
|
||||
if (priv->editable)
|
||||
{
|
||||
begin_change (self);
|
||||
gtk_text_paste (self, gtk_widget_get_clipboard (GTK_WIDGET (self)));
|
||||
end_change (self);
|
||||
}
|
||||
gtk_text_paste (self, gtk_widget_get_clipboard (GTK_WIDGET (self)));
|
||||
else
|
||||
{
|
||||
gtk_widget_error_bell (GTK_WIDGET (self));
|
||||
}
|
||||
gtk_widget_error_bell (GTK_WIDGET (self));
|
||||
|
||||
gtk_text_update_handles (self);
|
||||
}
|
||||
|
||||
@@ -744,7 +744,5 @@ gtk_viewport_scroll_to (GtkViewport *viewport,
|
||||
|
||||
gtk_adjustment_animate_to_value (viewport->adjustment[GTK_ORIENTATION_HORIZONTAL], x);
|
||||
gtk_adjustment_animate_to_value (viewport->adjustment[GTK_ORIENTATION_VERTICAL], y);
|
||||
|
||||
g_clear_pointer (&scroll, gtk_scroll_info_unref);
|
||||
}
|
||||
|
||||
|
||||
@@ -1312,22 +1312,10 @@ gtk_inspector_object_tree_select_object (GtkInspectorObjectTree *wt,
|
||||
GTK_LIST_SCROLL_SELECT | GTK_LIST_SCROLL_FOCUS,
|
||||
NULL);
|
||||
|
||||
g_signal_emit (wt, signals[OBJECT_SELECTED], 0, object);
|
||||
g_signal_emit (wt, signals[OBJECT_SELECTED], 0, object); // FIXME
|
||||
g_object_unref (row_item);
|
||||
}
|
||||
|
||||
static void
|
||||
on_selected_item (GtkSingleSelection *selection,
|
||||
GParamSpec *pspec,
|
||||
GtkInspectorObjectTree *wt)
|
||||
{
|
||||
GObject *selected = gtk_single_selection_get_selected_item (selection);
|
||||
GtkTreeListRow *row = GTK_TREE_LIST_ROW (selected);
|
||||
GObject *object = gtk_tree_list_row_get_item (row);
|
||||
g_signal_emit (wt, signals[OBJECT_SELECTED], 0, object);
|
||||
g_object_unref (object);
|
||||
}
|
||||
|
||||
void
|
||||
gtk_inspector_object_tree_set_display (GtkInspectorObjectTree *wt,
|
||||
GdkDisplay *display)
|
||||
@@ -1341,5 +1329,4 @@ gtk_inspector_object_tree_set_display (GtkInspectorObjectTree *wt,
|
||||
wt->priv->selection = gtk_single_selection_new (g_object_ref (G_LIST_MODEL (wt->priv->tree_model)));
|
||||
gtk_column_view_set_model (GTK_COLUMN_VIEW (wt->priv->list),
|
||||
GTK_SELECTION_MODEL (wt->priv->selection));
|
||||
g_signal_connect (wt->priv->selection, "notify::selected-item", G_CALLBACK (on_selected_item), wt);
|
||||
}
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
|
||||
#include <glib-object.h>
|
||||
#include <gtk/gtk.h>
|
||||
#include "gtk/print/gtkprintbackendprivate.h"
|
||||
#include "gtkprintbackendprivate.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
|
||||
@@ -21,7 +21,7 @@
|
||||
|
||||
#include <glib-object.h>
|
||||
#include <cpdb/cpdb-frontend.h>
|
||||
#include <gtk/print/gtkprinterprivate.h>
|
||||
#include <gtk/gtkprinterprivate.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
@@ -43,4 +43,4 @@ void gtk_printer_cpdb_set_printer_obj (GtkPrinterCpdb
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __GTK_PRINTER_CPDB_H__ */
|
||||
#endif /* __GTK_PRINTER_CPDB_H__ */
|
||||
@@ -425,15 +425,9 @@ tools/gtk-builder-tool-screenshot.c
|
||||
tools/gtk-builder-tool-simplify.c
|
||||
tools/gtk-builder-tool-validate.c
|
||||
tools/gtk-launch.c
|
||||
tools/gtk-path-tool.c
|
||||
tools/gtk-path-tool-decompose.c
|
||||
tools/gtk-path-tool-info.c
|
||||
tools/gtk-path-tool-render.c
|
||||
tools/gtk-path-tool-show.c
|
||||
tools/gtk-path-tool-utils.c
|
||||
tools/gtk-rendernode-tool.c
|
||||
tools/gtk-rendernode-tool-info.c
|
||||
tools/gtk-rendernode-tool-render.c
|
||||
tools/gtk-rendernode-tool-show.c
|
||||
tools/gtk-rendernode-tool-render.c
|
||||
tools/gtk-rendernode-tool-utils.c
|
||||
tools/updateiconcache.c
|
||||
|
||||
268
testsuite/gsk/measure-special-cases.c
Normal file
@@ -0,0 +1,268 @@
|
||||
/*
|
||||
* Copyright © 2020 Benjamin Otte
|
||||
*
|
||||
* This library 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.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library 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 this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Authors: Benjamin Otte <otte@gnome.org>
|
||||
*/
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
|
||||
static void
|
||||
test_bad_split (void)
|
||||
{
|
||||
GskPath *path, *path1;
|
||||
GskPathMeasure *measure, *measure1;
|
||||
GskPathBuilder *builder;
|
||||
float split, length, epsilon;
|
||||
GskPathPoint point0, point1;
|
||||
|
||||
/* An example that was isolated from the /path/segment test path.c
|
||||
* It shows how uneven parametrization of cubics can lead to bad
|
||||
* lengths reported by the measure.
|
||||
*/
|
||||
|
||||
path = gsk_path_parse ("M 0 0 C 2 0 4 0 4 0");
|
||||
|
||||
measure = gsk_path_measure_new (path);
|
||||
split = 2.962588;
|
||||
gsk_path_measure_get_point (measure, 0, &point0);
|
||||
gsk_path_measure_get_point (measure, split, &point1);
|
||||
length = gsk_path_measure_get_length (measure);
|
||||
epsilon = MAX (length / 256, 1.f / 1024);
|
||||
|
||||
builder = gsk_path_builder_new ();
|
||||
gsk_path_builder_add_segment (builder, path, &point0, &point1);;
|
||||
path1 = gsk_path_builder_free_to_path (builder);
|
||||
measure1 = gsk_path_measure_new (path1);
|
||||
|
||||
g_assert_cmpfloat_with_epsilon (split, gsk_path_measure_get_length (measure1), epsilon);
|
||||
|
||||
gsk_path_measure_unref (measure1);
|
||||
gsk_path_unref (path1);
|
||||
gsk_path_measure_unref (measure);
|
||||
gsk_path_unref (path);
|
||||
}
|
||||
|
||||
static void
|
||||
test_bad_in_fill (void)
|
||||
{
|
||||
GskPath *path;
|
||||
gboolean inside;
|
||||
|
||||
/* A fat Cantarell W */
|
||||
path = gsk_path_parse ("M -2 694 M 206.1748046875 704 L 390.9371337890625 704 L 551.1888427734375 99.5035400390625 L 473.0489501953125 99.5035400390625 L 649.1048583984375 704 L 828.965087890625 704 L 1028.3077392578125 10 L 857.8111572265625 10 L 710.0489501953125 621.251708984375 L 775.9720458984375 598.426513671875 L 614.5245361328125 14.0489501953125 L 430.2237548828125 14.0489501953125 L 278.6783447265625 602.230712890625 L 330.0909423828125 602.230712890625 L 195.88818359375 10 L 5.7342529296875 10 L 206.1748046875 704 Z");
|
||||
|
||||
/* The midpoint of the right foot of a fat Cantarell X */
|
||||
inside = gsk_path_in_fill (path, &GRAPHENE_POINT_INIT (552.360107, 704.000000), GSK_FILL_RULE_WINDING);
|
||||
|
||||
g_assert_false (inside);
|
||||
|
||||
gsk_path_unref (path);
|
||||
}
|
||||
|
||||
/* Test that path_in_fill implicitly closes contours. I think this is wrong,
|
||||
* but it is what "everybody" does.
|
||||
*/
|
||||
static void
|
||||
test_unclosed_in_fill (void)
|
||||
{
|
||||
GskPath *path;
|
||||
|
||||
path = gsk_path_parse ("M 0 0 L 0 100 L 100 100 L 100 0 Z");
|
||||
g_assert_true (gsk_path_in_fill (path, &GRAPHENE_POINT_INIT (50, 50), GSK_FILL_RULE_WINDING));
|
||||
gsk_path_unref (path);
|
||||
|
||||
path = gsk_path_parse ("M 0 0 L 0 100 L 100 100 L 100 0");
|
||||
g_assert_true (gsk_path_in_fill (path, &GRAPHENE_POINT_INIT (50, 50), GSK_FILL_RULE_WINDING));
|
||||
gsk_path_unref (path);
|
||||
}
|
||||
|
||||
static void
|
||||
test_rect (void)
|
||||
{
|
||||
GskPathBuilder *builder;
|
||||
GskPath *path;
|
||||
GskPathMeasure *measure;
|
||||
GskPathPoint point;
|
||||
graphene_point_t p;
|
||||
graphene_vec2_t tangent, expected_tangent;
|
||||
float length;
|
||||
gboolean ret;
|
||||
|
||||
builder = gsk_path_builder_new ();
|
||||
gsk_path_builder_add_rect (builder, &GRAPHENE_RECT_INIT (0, 0, 100, 50));
|
||||
path = gsk_path_builder_free_to_path (builder);
|
||||
measure = gsk_path_measure_new (path);
|
||||
length = gsk_path_measure_get_length (measure);
|
||||
|
||||
g_assert_true (length == 300);
|
||||
|
||||
#define TEST_POS_AT(distance, X, Y) \
|
||||
ret = gsk_path_measure_get_point (measure, distance, &point); \
|
||||
g_assert_true (ret); \
|
||||
gsk_path_point_get_position (path, &point, &p); \
|
||||
g_assert_true (graphene_point_near (&p, &GRAPHENE_POINT_INIT (X, Y), 0.01)); \
|
||||
ret = gsk_path_get_closest_point (path, &GRAPHENE_POINT_INIT (X, Y), INFINITY, &point); \
|
||||
g_assert_true (ret); \
|
||||
if (distance < length) \
|
||||
g_assert_true (fabs (gsk_path_point_get_distance (measure, &point) - distance) < 0.01); \
|
||||
else \
|
||||
g_assert_true (fabs (gsk_path_point_get_distance (measure, &point)) < 0.01); \
|
||||
gsk_path_point_get_position (path, &point, &p); \
|
||||
g_assert_true (graphene_point_near (&p, &GRAPHENE_POINT_INIT (X, Y), 0.01)); \
|
||||
|
||||
#define TEST_TANGENT_AT(distance, x1, y1, x2, y2) \
|
||||
ret = gsk_path_measure_get_point (measure, distance, &point); \
|
||||
g_assert_true (ret); \
|
||||
gsk_path_point_get_tangent (path, &point, GSK_PATH_START, &tangent); \
|
||||
g_assert_true (graphene_vec2_near (&tangent, graphene_vec2_init (&expected_tangent, x1, y1), 0.01)); \
|
||||
gsk_path_point_get_tangent (path, &point, GSK_PATH_END, &tangent); \
|
||||
g_assert_true (graphene_vec2_near (&tangent, graphene_vec2_init (&expected_tangent, x2, y2), 0.01)); \
|
||||
|
||||
#define TEST_POS_AT2(distance, X, Y, expected_distance) \
|
||||
ret = gsk_path_measure_get_point (measure, distance, &point); \
|
||||
g_assert_true (ret); \
|
||||
gsk_path_point_get_position (path, &point, &p); \
|
||||
g_assert_true (graphene_point_near (&p, &GRAPHENE_POINT_INIT (X, Y), 0.01)); \
|
||||
ret = gsk_path_get_closest_point (path, &GRAPHENE_POINT_INIT (X, Y), INFINITY, &point); \
|
||||
g_assert_true (ret); \
|
||||
g_assert_true (fabs (gsk_path_point_get_distance (measure, &point) - expected_distance) < 0.01); \
|
||||
gsk_path_point_get_position (path, &point, &p); \
|
||||
g_assert_true (graphene_point_near (&p, &GRAPHENE_POINT_INIT (X, Y), 0.01)); \
|
||||
|
||||
TEST_POS_AT (0, 0, 0)
|
||||
TEST_POS_AT (25, 25, 0)
|
||||
TEST_POS_AT (100, 100, 0)
|
||||
TEST_POS_AT (110, 100, 10)
|
||||
TEST_POS_AT (150, 100, 50)
|
||||
TEST_POS_AT (175, 75, 50)
|
||||
TEST_POS_AT (250, 0, 50)
|
||||
TEST_POS_AT (260, 0, 40)
|
||||
TEST_POS_AT2 (300, 0, 0, 0)
|
||||
|
||||
TEST_TANGENT_AT (0, 0, -1, 1, 0)
|
||||
TEST_TANGENT_AT (50, 1, 0, 1, 0)
|
||||
TEST_TANGENT_AT (100, 1, 0, 0, 1)
|
||||
TEST_TANGENT_AT (125, 0, 1, 0, 1)
|
||||
TEST_TANGENT_AT (150, 0, 1, -1, 0)
|
||||
TEST_TANGENT_AT (200, -1, 0, -1, 0)
|
||||
TEST_TANGENT_AT (250, -1, 0, 0, -1)
|
||||
TEST_TANGENT_AT (275, 0, -1, 0, -1)
|
||||
|
||||
gsk_path_measure_unref (measure);
|
||||
gsk_path_unref (path);
|
||||
|
||||
builder = gsk_path_builder_new ();
|
||||
gsk_path_builder_add_rect (builder, &GRAPHENE_RECT_INIT (100, 50, -100, -50));
|
||||
path = gsk_path_builder_free_to_path (builder);
|
||||
measure = gsk_path_measure_new (path);
|
||||
length = gsk_path_measure_get_length (measure);
|
||||
|
||||
g_assert_true (length == 300);
|
||||
|
||||
TEST_POS_AT (0, 100, 50)
|
||||
TEST_POS_AT (25, 75, 50)
|
||||
TEST_POS_AT (100, 0, 50)
|
||||
TEST_POS_AT (110, 0, 40)
|
||||
TEST_POS_AT (150, 0, 0)
|
||||
TEST_POS_AT (175, 25, 0)
|
||||
TEST_POS_AT (250, 100, 0)
|
||||
TEST_POS_AT (260, 100, 10)
|
||||
TEST_POS_AT (300, 100, 50)
|
||||
|
||||
builder = gsk_path_builder_new ();
|
||||
gsk_path_builder_add_rect (builder, &GRAPHENE_RECT_INIT (100, 0, -100, 50));
|
||||
path = gsk_path_builder_free_to_path (builder);
|
||||
measure = gsk_path_measure_new (path);
|
||||
length = gsk_path_measure_get_length (measure);
|
||||
|
||||
g_assert_true (length == 300);
|
||||
|
||||
TEST_POS_AT (0, 100, 0)
|
||||
TEST_POS_AT (25, 75, 0)
|
||||
TEST_POS_AT (100, 0, 0)
|
||||
TEST_POS_AT (110, 0, 10)
|
||||
TEST_POS_AT (150, 0, 50)
|
||||
TEST_POS_AT (175, 25, 50)
|
||||
TEST_POS_AT (250, 100, 50)
|
||||
TEST_POS_AT (260, 100, 40)
|
||||
TEST_POS_AT (300, 100, 0)
|
||||
|
||||
builder = gsk_path_builder_new ();
|
||||
gsk_path_builder_add_rect (builder, &GRAPHENE_RECT_INIT (0, 0, 100, 0));
|
||||
path = gsk_path_builder_free_to_path (builder);
|
||||
measure = gsk_path_measure_new (path);
|
||||
length = gsk_path_measure_get_length (measure);
|
||||
|
||||
g_assert_true (length == 200);
|
||||
|
||||
TEST_POS_AT2 (0, 0, 0, 0)
|
||||
TEST_POS_AT2 (25, 25, 0, 25)
|
||||
TEST_POS_AT2 (100, 100, 0, 100)
|
||||
TEST_POS_AT2 (110, 90, 0, 90)
|
||||
TEST_POS_AT2 (200, 0, 0, 0)
|
||||
|
||||
builder = gsk_path_builder_new ();
|
||||
gsk_path_builder_add_rect (builder, &GRAPHENE_RECT_INIT (100, 0, -100, 0));
|
||||
path = gsk_path_builder_free_to_path (builder);
|
||||
measure = gsk_path_measure_new (path);
|
||||
length = gsk_path_measure_get_length (measure);
|
||||
|
||||
g_assert_true (length == 200);
|
||||
|
||||
/* These cases are ambiguous */
|
||||
TEST_POS_AT2 (0, 100, 0, 0)
|
||||
TEST_POS_AT2 (25, 75, 0, 25)
|
||||
TEST_POS_AT2 (100, 0, 0, 100)
|
||||
TEST_POS_AT2 (110, 10, 0, 110)
|
||||
TEST_POS_AT2 (200, 100, 0, 0)
|
||||
|
||||
builder = gsk_path_builder_new ();
|
||||
gsk_path_builder_add_rect (builder, &GRAPHENE_RECT_INIT (0, 100, 0, -100));
|
||||
path = gsk_path_builder_free_to_path (builder);
|
||||
measure = gsk_path_measure_new (path);
|
||||
length = gsk_path_measure_get_length (measure);
|
||||
|
||||
g_assert_true (length == 200);
|
||||
|
||||
/* These cases are ambiguous */
|
||||
TEST_POS_AT2 (0, 0, 100, 0)
|
||||
TEST_POS_AT2 (25, 0, 75, 25)
|
||||
TEST_POS_AT2 (100, 0, 0, 100)
|
||||
TEST_POS_AT2 (110, 0, 10, 110)
|
||||
TEST_POS_AT2 (200, 0, 100, 0)
|
||||
|
||||
#undef TEST_POS_AT
|
||||
#undef TEST_POS_AT2
|
||||
#undef TEST_TANGENT_AT
|
||||
|
||||
gsk_path_measure_unref (measure);
|
||||
gsk_path_unref (path);
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc,
|
||||
char *argv[])
|
||||
{
|
||||
gtk_test_init (&argc, &argv, NULL);
|
||||
|
||||
g_test_add_func ("/measure/bad-split", test_bad_split);
|
||||
g_test_add_func ("/measure/bad-in-fill", test_bad_in_fill);
|
||||
g_test_add_func ("/measure/unclosed-in-fill", test_unclosed_in_fill);
|
||||
g_test_add_func ("/measure/rect", test_rect);
|
||||
|
||||
return g_test_run ();
|
||||
}
|
||||
887
testsuite/gsk/measure.c
Normal file
@@ -0,0 +1,887 @@
|
||||
/*
|
||||
* Copyright © 2020 Benjamin Otte
|
||||
*
|
||||
* This library 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.1 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This library 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 this library. If not, see <http://www.gnu.org/licenses/>.
|
||||
*
|
||||
* Authors: Benjamin Otte <otte@gnome.org>
|
||||
*/
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
static GskPath *
|
||||
create_random_degenerate_path (guint max_contours)
|
||||
{
|
||||
#define N_DEGENERATE_PATHS 14
|
||||
GskPathBuilder *builder;
|
||||
guint i;
|
||||
|
||||
builder = gsk_path_builder_new ();
|
||||
|
||||
switch (g_test_rand_int_range (0, N_DEGENERATE_PATHS))
|
||||
{
|
||||
case 0:
|
||||
/* empty path */
|
||||
break;
|
||||
|
||||
case 1:
|
||||
/* a single point */
|
||||
gsk_path_builder_move_to (builder,
|
||||
g_test_rand_double_range (-1000, 1000),
|
||||
g_test_rand_double_range (-1000, 1000));
|
||||
break;
|
||||
|
||||
case 2:
|
||||
/* N points */
|
||||
for (i = 0; i < MIN (10, max_contours); i++)
|
||||
{
|
||||
gsk_path_builder_move_to (builder,
|
||||
g_test_rand_double_range (-1000, 1000),
|
||||
g_test_rand_double_range (-1000, 1000));
|
||||
}
|
||||
break;
|
||||
|
||||
case 3:
|
||||
/* 1 closed point */
|
||||
gsk_path_builder_move_to (builder,
|
||||
g_test_rand_double_range (-1000, 1000),
|
||||
g_test_rand_double_range (-1000, 1000));
|
||||
gsk_path_builder_close (builder);
|
||||
break;
|
||||
|
||||
case 4:
|
||||
/* the same point closed N times */
|
||||
gsk_path_builder_move_to (builder,
|
||||
g_test_rand_double_range (-1000, 1000),
|
||||
g_test_rand_double_range (-1000, 1000));
|
||||
for (i = 0; i < MIN (10, max_contours); i++)
|
||||
{
|
||||
gsk_path_builder_close (builder);
|
||||
}
|
||||
break;
|
||||
|
||||
case 5:
|
||||
/* a zero-width and zero-height rect */
|
||||
gsk_path_builder_add_rect (builder,
|
||||
&GRAPHENE_RECT_INIT (g_test_rand_double_range (-1000, 1000),
|
||||
g_test_rand_double_range (-1000, 1000),
|
||||
0, 0));
|
||||
break;
|
||||
|
||||
case 6:
|
||||
/* a zero-width rect */
|
||||
gsk_path_builder_add_rect (builder,
|
||||
&GRAPHENE_RECT_INIT (g_test_rand_double_range (-1000, 1000),
|
||||
g_test_rand_double_range (-1000, 1000),
|
||||
0,
|
||||
g_test_rand_double_range (-1000, 1000)));
|
||||
break;
|
||||
|
||||
case 7:
|
||||
/* a zero-height rect */
|
||||
gsk_path_builder_add_rect (builder,
|
||||
&GRAPHENE_RECT_INIT (g_test_rand_double_range (-1000, 1000),
|
||||
g_test_rand_double_range (-1000, 1000),
|
||||
g_test_rand_double_range (-1000, 1000),
|
||||
0));
|
||||
break;
|
||||
|
||||
case 8:
|
||||
/* a negative-size rect */
|
||||
gsk_path_builder_add_rect (builder,
|
||||
&GRAPHENE_RECT_INIT (g_test_rand_double_range (-1000, 1000),
|
||||
g_test_rand_double_range (-1000, 1000),
|
||||
g_test_rand_double_range (-1000, 0),
|
||||
g_test_rand_double_range (-1000, 0)));
|
||||
break;
|
||||
|
||||
case 9:
|
||||
/* an absolutely random rect */
|
||||
gsk_path_builder_add_rect (builder,
|
||||
&GRAPHENE_RECT_INIT (g_test_rand_double_range (-1000, 1000),
|
||||
g_test_rand_double_range (-1000, 1000),
|
||||
g_test_rand_double_range (-1000, 1000),
|
||||
g_test_rand_double_range (-1000, 1000)));
|
||||
break;
|
||||
|
||||
case 10:
|
||||
/* an absolutely random rect */
|
||||
gsk_path_builder_add_rect (builder,
|
||||
&GRAPHENE_RECT_INIT (g_test_rand_double_range (-1000, 1000),
|
||||
g_test_rand_double_range (-1000, 1000),
|
||||
g_test_rand_double_range (-1000, 1000),
|
||||
g_test_rand_double_range (-1000, 1000)));
|
||||
break;
|
||||
|
||||
case 11:
|
||||
/* an absolutely random circle */
|
||||
gsk_path_builder_add_circle (builder,
|
||||
&GRAPHENE_POINT_INIT (g_test_rand_double_range (-1000, 1000),
|
||||
g_test_rand_double_range (-1000, 1000)),
|
||||
g_test_rand_double_range (1, 1000));
|
||||
break;
|
||||
|
||||
case 12:
|
||||
/* a zero-length line */
|
||||
{
|
||||
graphene_point_t point = GRAPHENE_POINT_INIT (g_test_rand_double_range (-1000, 1000),
|
||||
g_test_rand_double_range (-1000, 1000));
|
||||
gsk_path_builder_move_to (builder, point.x, point.y);
|
||||
gsk_path_builder_line_to (builder, point.x, point.y);
|
||||
}
|
||||
break;
|
||||
|
||||
case 13:
|
||||
/* a curve with start == end */
|
||||
{
|
||||
graphene_point_t point = GRAPHENE_POINT_INIT (g_test_rand_double_range (-1000, 1000),
|
||||
g_test_rand_double_range (-1000, 1000));
|
||||
gsk_path_builder_move_to (builder, point.x, point.y);
|
||||
gsk_path_builder_cubic_to (builder,
|
||||
g_test_rand_double_range (-1000, 1000),
|
||||
g_test_rand_double_range (-1000, 1000),
|
||||
g_test_rand_double_range (-1000, 1000),
|
||||
g_test_rand_double_range (-1000, 1000),
|
||||
point.x, point.y);
|
||||
}
|
||||
break;
|
||||
|
||||
case N_DEGENERATE_PATHS:
|
||||
default:
|
||||
g_assert_not_reached ();
|
||||
}
|
||||
|
||||
return gsk_path_builder_free_to_path (builder);
|
||||
}
|
||||
|
||||
static GskPath *
|
||||
create_random_path (guint max_contours);
|
||||
|
||||
static void
|
||||
add_shape_contour (GskPathBuilder *builder)
|
||||
{
|
||||
#define N_SHAPE_CONTOURS 3
|
||||
switch (g_test_rand_int_range (0, N_SHAPE_CONTOURS))
|
||||
{
|
||||
case 0:
|
||||
gsk_path_builder_add_rect (builder,
|
||||
&GRAPHENE_RECT_INIT (g_test_rand_double_range (-1000, 1000),
|
||||
g_test_rand_double_range (-1000, 1000),
|
||||
g_test_rand_double_range (1, 1000),
|
||||
g_test_rand_double_range (1, 1000)));
|
||||
break;
|
||||
|
||||
case 1:
|
||||
gsk_path_builder_add_circle (builder,
|
||||
&GRAPHENE_POINT_INIT (g_test_rand_double_range (-1000, 1000),
|
||||
g_test_rand_double_range (-1000, 1000)),
|
||||
g_test_rand_double_range (1, 1000));
|
||||
break;
|
||||
|
||||
case 2:
|
||||
{
|
||||
GskPath *path = create_random_path (1);
|
||||
gsk_path_builder_add_path (builder, path);
|
||||
gsk_path_unref (path);
|
||||
}
|
||||
break;
|
||||
|
||||
case N_SHAPE_CONTOURS:
|
||||
default:
|
||||
g_assert_not_reached ();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
add_standard_contour (GskPathBuilder *builder)
|
||||
{
|
||||
guint i, n;
|
||||
|
||||
if (g_test_rand_bit ())
|
||||
{
|
||||
if (g_test_rand_bit ())
|
||||
gsk_path_builder_move_to (builder,
|
||||
g_test_rand_double_range (-1000, 1000),
|
||||
g_test_rand_double_range (-1000, 1000));
|
||||
else
|
||||
gsk_path_builder_rel_move_to (builder,
|
||||
g_test_rand_double_range (-1000, 1000),
|
||||
g_test_rand_double_range (-1000, 1000));
|
||||
}
|
||||
|
||||
/* that 20 is random, but should be enough to get some
|
||||
* crazy self-intersecting shapes */
|
||||
n = g_test_rand_int_range (1, 20);
|
||||
for (i = 0; i < n; i++)
|
||||
{
|
||||
switch (g_test_rand_int_range (0, 6))
|
||||
{
|
||||
case 0:
|
||||
gsk_path_builder_line_to (builder,
|
||||
g_test_rand_double_range (-1000, 1000),
|
||||
g_test_rand_double_range (-1000, 1000));
|
||||
break;
|
||||
|
||||
case 1:
|
||||
gsk_path_builder_rel_line_to (builder,
|
||||
g_test_rand_double_range (-1000, 1000),
|
||||
g_test_rand_double_range (-1000, 1000));
|
||||
break;
|
||||
|
||||
case 2:
|
||||
gsk_path_builder_quad_to (builder,
|
||||
g_test_rand_double_range (-1000, 1000),
|
||||
g_test_rand_double_range (-1000, 1000),
|
||||
g_test_rand_double_range (-1000, 1000),
|
||||
g_test_rand_double_range (-1000, 1000));
|
||||
break;
|
||||
|
||||
case 3:
|
||||
gsk_path_builder_rel_quad_to (builder,
|
||||
g_test_rand_double_range (-1000, 1000),
|
||||
g_test_rand_double_range (-1000, 1000),
|
||||
g_test_rand_double_range (-1000, 1000),
|
||||
g_test_rand_double_range (-1000, 1000));
|
||||
break;
|
||||
|
||||
case 4:
|
||||
gsk_path_builder_cubic_to (builder,
|
||||
g_test_rand_double_range (-1000, 1000),
|
||||
g_test_rand_double_range (-1000, 1000),
|
||||
g_test_rand_double_range (-1000, 1000),
|
||||
g_test_rand_double_range (-1000, 1000),
|
||||
g_test_rand_double_range (-1000, 1000),
|
||||
g_test_rand_double_range (-1000, 1000));
|
||||
break;
|
||||
|
||||
case 5:
|
||||
gsk_path_builder_rel_cubic_to (builder,
|
||||
g_test_rand_double_range (-1000, 1000),
|
||||
g_test_rand_double_range (-1000, 1000),
|
||||
g_test_rand_double_range (-1000, 1000),
|
||||
g_test_rand_double_range (-1000, 1000),
|
||||
g_test_rand_double_range (-1000, 1000),
|
||||
g_test_rand_double_range (-1000, 1000));
|
||||
break;
|
||||
|
||||
default:
|
||||
g_assert_not_reached();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (g_test_rand_bit ())
|
||||
gsk_path_builder_close (builder);
|
||||
}
|
||||
|
||||
static GskPath *
|
||||
create_random_path (guint max_contours)
|
||||
{
|
||||
GskPathBuilder *builder;
|
||||
guint i, n;
|
||||
|
||||
/* 5% chance for a weird shape */
|
||||
if (!g_test_rand_int_range (0, 20))
|
||||
return create_random_degenerate_path (max_contours);
|
||||
|
||||
builder = gsk_path_builder_new ();
|
||||
n = g_test_rand_int_range (1, 10);
|
||||
n = MIN (n, max_contours);
|
||||
|
||||
for (i = 0; i < n; i++)
|
||||
{
|
||||
/* 2/3 of shapes are standard contours */
|
||||
if (g_test_rand_int_range (0, 3))
|
||||
add_standard_contour (builder);
|
||||
else
|
||||
add_shape_contour (builder);
|
||||
}
|
||||
|
||||
return gsk_path_builder_free_to_path (builder);
|
||||
}
|
||||
|
||||
typedef struct {
|
||||
GskPathOperation op;
|
||||
graphene_point_t pts[4];
|
||||
float weight;
|
||||
} PathOperation;
|
||||
|
||||
static void
|
||||
test_segment_start (void)
|
||||
{
|
||||
GskPath *path, *path1;
|
||||
GskPathMeasure *measure, *measure1;
|
||||
GskPathBuilder *builder;
|
||||
float epsilon, length;
|
||||
guint i;
|
||||
GskPathPoint point0, point1;
|
||||
|
||||
path = create_random_path (G_MAXUINT);
|
||||
measure = gsk_path_measure_new (path);
|
||||
length = gsk_path_measure_get_length (measure);
|
||||
epsilon = MAX (length / 1024, G_MINFLOAT);
|
||||
gsk_path_measure_get_point (measure, 0, &point0);
|
||||
|
||||
for (i = 0; i < 100; i++)
|
||||
{
|
||||
float seg_length = length * i / 100.0f;
|
||||
|
||||
gsk_path_measure_get_point (measure, seg_length, &point1);
|
||||
|
||||
builder = gsk_path_builder_new ();
|
||||
gsk_path_builder_add_segment (builder, path, &point0, &point1);
|
||||
path1 = gsk_path_builder_free_to_path (builder);
|
||||
measure1 = gsk_path_measure_new (path1);
|
||||
|
||||
if (seg_length == 0)
|
||||
g_assert_cmpfloat_with_epsilon (gsk_path_measure_get_length (measure), gsk_path_measure_get_length (measure1), epsilon);
|
||||
else
|
||||
g_assert_cmpfloat_with_epsilon (seg_length, gsk_path_measure_get_length (measure1), epsilon);
|
||||
|
||||
gsk_path_measure_unref (measure1);
|
||||
gsk_path_unref (path1);
|
||||
}
|
||||
|
||||
gsk_path_measure_unref (measure);
|
||||
gsk_path_unref (path);
|
||||
}
|
||||
|
||||
static void
|
||||
test_segment_end (void)
|
||||
{
|
||||
GskPath *path, *path1;
|
||||
GskPathMeasure *measure, *measure1;
|
||||
GskPathBuilder *builder;
|
||||
float epsilon, length;
|
||||
guint i;
|
||||
GskPathPoint point0, point1;
|
||||
|
||||
path = create_random_path (G_MAXUINT);
|
||||
measure = gsk_path_measure_new (path);
|
||||
length = gsk_path_measure_get_length (measure);
|
||||
epsilon = MAX (length / 1024, G_MINFLOAT);
|
||||
|
||||
for (i = 0; i < 100; i++)
|
||||
{
|
||||
float seg_length = length * i / 100.0f;
|
||||
|
||||
gsk_path_measure_get_point (measure, length - seg_length, &point0);
|
||||
gsk_path_measure_get_point (measure, length, &point1);
|
||||
builder = gsk_path_builder_new ();
|
||||
gsk_path_builder_add_segment (builder, path, &point0, &point1);
|
||||
path1 = gsk_path_builder_free_to_path (builder);
|
||||
measure1 = gsk_path_measure_new (path1);
|
||||
|
||||
if (seg_length == 0)
|
||||
g_assert_cmpfloat_with_epsilon (gsk_path_measure_get_length (measure), gsk_path_measure_get_length (measure1), epsilon);
|
||||
else
|
||||
g_assert_cmpfloat_with_epsilon (seg_length, gsk_path_measure_get_length (measure1), epsilon);
|
||||
|
||||
gsk_path_measure_unref (measure1);
|
||||
gsk_path_unref (path1);
|
||||
}
|
||||
|
||||
gsk_path_measure_unref (measure);
|
||||
gsk_path_unref (path);
|
||||
}
|
||||
|
||||
static void
|
||||
test_segment_chunk (void)
|
||||
{
|
||||
GskPath *path, *path1, *path2;
|
||||
GskPathMeasure *measure, *measure1, *measure2;
|
||||
GskPathBuilder *builder;
|
||||
float epsilon, length;
|
||||
guint i;
|
||||
GskPathPoint point0, point1;
|
||||
|
||||
path = create_random_path (G_MAXUINT);
|
||||
measure = gsk_path_measure_new (path);
|
||||
length = gsk_path_measure_get_length (measure);
|
||||
epsilon = MAX (length / 1024, G_MINFLOAT);
|
||||
|
||||
for (i = 0; i <= 100; i++)
|
||||
{
|
||||
float seg_start = length * i / 200.0f;
|
||||
|
||||
gsk_path_measure_get_point (measure, seg_start, &point0);
|
||||
gsk_path_measure_get_point (measure, seg_start + length / 2, &point1);
|
||||
builder = gsk_path_builder_new ();
|
||||
gsk_path_builder_add_segment (builder, path, &point0, &point1);
|
||||
path1 = gsk_path_builder_free_to_path (builder);
|
||||
measure1 = gsk_path_measure_new (path1);
|
||||
|
||||
g_assert_cmpfloat_with_epsilon (length / 2, gsk_path_measure_get_length (measure1), epsilon);
|
||||
|
||||
gsk_path_measure_get_point (measure, seg_start + length / 2, &point0);
|
||||
gsk_path_measure_get_point (measure, seg_start, &point1);
|
||||
builder = gsk_path_builder_new ();
|
||||
gsk_path_builder_add_segment (builder, path, &point0, &point1);
|
||||
path2 = gsk_path_builder_free_to_path (builder);
|
||||
measure2 = gsk_path_measure_new (path2);
|
||||
|
||||
g_assert_cmpfloat_with_epsilon (length / 2, gsk_path_measure_get_length (measure2), epsilon);
|
||||
|
||||
gsk_path_measure_unref (measure2);
|
||||
gsk_path_unref (path2);
|
||||
gsk_path_measure_unref (measure1);
|
||||
gsk_path_unref (path1);
|
||||
}
|
||||
|
||||
gsk_path_measure_unref (measure);
|
||||
gsk_path_unref (path);
|
||||
}
|
||||
|
||||
static void
|
||||
test_segment (void)
|
||||
{
|
||||
GskPath *path, *path1, *path2, *path3;
|
||||
GskPathMeasure *measure, *measure1, *measure2, *measure3;
|
||||
GskPathBuilder *builder;
|
||||
guint i;
|
||||
float split1, split2, epsilon, length;
|
||||
GskPathPoint point0, point1, point2, point3;
|
||||
|
||||
for (i = 0; i < 1000; i++)
|
||||
{
|
||||
path = create_random_path (G_MAXUINT);
|
||||
measure = gsk_path_measure_new (path);
|
||||
length = gsk_path_measure_get_length (measure);
|
||||
/* chosen high enough to stop the testsuite from failing */
|
||||
epsilon = MAX (length / 64, 1.f / 1024);
|
||||
|
||||
split1 = g_test_rand_double_range (0, length);
|
||||
split2 = g_test_rand_double_range (split1, length);
|
||||
|
||||
gsk_path_measure_get_point (measure, 0, &point0);
|
||||
gsk_path_measure_get_point (measure, split1, &point1);
|
||||
gsk_path_measure_get_point (measure, split2, &point2);
|
||||
gsk_path_measure_get_point (measure, length, &point3);
|
||||
builder = gsk_path_builder_new ();
|
||||
gsk_path_builder_add_segment (builder, path, &point0, &point1);
|
||||
path1 = gsk_path_builder_free_to_path (builder);
|
||||
measure1 = gsk_path_measure_new (path1);
|
||||
|
||||
builder = gsk_path_builder_new ();
|
||||
gsk_path_builder_add_segment (builder, path, &point1, &point2);
|
||||
path2 = gsk_path_builder_free_to_path (builder);
|
||||
measure2 = gsk_path_measure_new (path2);
|
||||
|
||||
builder = gsk_path_builder_new ();
|
||||
gsk_path_builder_add_segment (builder, path, &point2, &point3);
|
||||
path3 = gsk_path_builder_free_to_path (builder);
|
||||
measure3 = gsk_path_measure_new (path3);
|
||||
|
||||
g_assert_cmpfloat_with_epsilon (split1, gsk_path_measure_get_length (measure1), epsilon);
|
||||
g_assert_cmpfloat_with_epsilon (split2 - split1, gsk_path_measure_get_length (measure2), epsilon);
|
||||
g_assert_cmpfloat_with_epsilon (length - split2, gsk_path_measure_get_length (measure3), epsilon);
|
||||
|
||||
gsk_path_measure_unref (measure2);
|
||||
gsk_path_measure_unref (measure1);
|
||||
gsk_path_measure_unref (measure);
|
||||
gsk_path_unref (path2);
|
||||
gsk_path_unref (path1);
|
||||
gsk_path_unref (path);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
test_get_point (void)
|
||||
{
|
||||
static const guint max_contours = 5;
|
||||
static const float tolerance = 1.0;
|
||||
GskPath *path;
|
||||
GskPathMeasure *measure;
|
||||
GskPathPoint point;
|
||||
guint n_discontinuities;
|
||||
float length, offset, last_offset;
|
||||
graphene_point_t p, last_point;
|
||||
guint i, j;
|
||||
gboolean ret;
|
||||
|
||||
for (i = 0; i < 10; i++)
|
||||
{
|
||||
path = create_random_path (max_contours);
|
||||
measure = gsk_path_measure_new_with_tolerance (path, tolerance);
|
||||
length = gsk_path_measure_get_length (measure);
|
||||
n_discontinuities = 0;
|
||||
|
||||
ret = gsk_path_measure_get_point (measure, 0, &point);
|
||||
if (!ret)
|
||||
{
|
||||
g_assert_true (gsk_path_is_empty (path));
|
||||
continue;
|
||||
}
|
||||
gsk_path_point_get_position (path, &point, &last_point);
|
||||
|
||||
/* FIXME: anything we can test with tangents here? */
|
||||
last_offset = 0;
|
||||
|
||||
for (j = 1; j <= 1024; j++)
|
||||
{
|
||||
offset = length * j / 1024;
|
||||
ret = gsk_path_measure_get_point (measure, offset, &point);
|
||||
g_assert_true (ret);
|
||||
gsk_path_point_get_position (path, &point, &p);
|
||||
|
||||
if (graphene_point_distance (&last_point, &p, NULL, NULL) > 2 * (offset - last_offset))
|
||||
{
|
||||
n_discontinuities++;
|
||||
g_assert_cmpint (n_discontinuities, <, max_contours);
|
||||
}
|
||||
|
||||
last_offset = offset;
|
||||
last_point = p;
|
||||
}
|
||||
|
||||
gsk_path_measure_unref (measure);
|
||||
gsk_path_unref (path);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
test_closest_point (void)
|
||||
{
|
||||
static const float tolerance = 0.5;
|
||||
GskPath *path, *path1, *path2;
|
||||
GskPathMeasure *measure, *measure1, *measure2;
|
||||
GskPathBuilder *builder;
|
||||
GskPathPoint point;
|
||||
guint i, j;
|
||||
gboolean ret;
|
||||
|
||||
if (!g_test_slow ())
|
||||
{
|
||||
g_test_skip ("Skipping slow test");
|
||||
return;
|
||||
}
|
||||
|
||||
for (i = 0; i < 10; i++)
|
||||
{
|
||||
path1 = create_random_path (G_MAXUINT);
|
||||
measure1 = gsk_path_measure_new_with_tolerance (path1, tolerance);
|
||||
path2 = create_random_path (G_MAXUINT);
|
||||
measure2 = gsk_path_measure_new_with_tolerance (path2, tolerance);
|
||||
|
||||
builder = gsk_path_builder_new ();
|
||||
gsk_path_builder_add_path (builder, path1);
|
||||
gsk_path_builder_add_path (builder, path2);
|
||||
path = gsk_path_builder_free_to_path (builder);
|
||||
measure = gsk_path_measure_new_with_tolerance (path, tolerance);
|
||||
|
||||
for (j = 0; j < 100; j++)
|
||||
{
|
||||
graphene_point_t test = GRAPHENE_POINT_INIT (g_test_rand_double_range (-1000, 1000),
|
||||
g_test_rand_double_range (-1000, 1000));
|
||||
graphene_point_t p1, p2, p;
|
||||
graphene_vec2_t t1, t2, t;
|
||||
float offset1, offset2, offset;
|
||||
float distance1, distance2, distance;
|
||||
|
||||
offset1 = offset2 = offset = 0;
|
||||
distance1 = distance2 = distance = 0;
|
||||
ret = gsk_path_get_closest_point (path1, &test, INFINITY, &point);
|
||||
g_assert_true (ret);
|
||||
|
||||
gsk_path_point_get_position (path1, &point, &p1);
|
||||
gsk_path_point_get_tangent (path1, &point, GSK_PATH_END, &t1);
|
||||
offset1 = gsk_path_point_get_distance (measure1, &point);
|
||||
distance1 = graphene_point_distance (&p1, &test, NULL, NULL);
|
||||
|
||||
ret = gsk_path_get_closest_point (path2, &test, INFINITY, &point);
|
||||
g_assert_true (ret);
|
||||
|
||||
gsk_path_point_get_position (path2, &point, &p2);
|
||||
gsk_path_point_get_tangent (path2, &point, GSK_PATH_END, &t2);
|
||||
offset2 = gsk_path_point_get_distance (measure2, &point);
|
||||
distance2 = graphene_point_distance (&p2, &test, NULL, NULL);
|
||||
|
||||
ret = gsk_path_get_closest_point (path, &test, INFINITY, &point);
|
||||
g_assert_true (ret);
|
||||
|
||||
gsk_path_point_get_position (path, &point, &p);
|
||||
gsk_path_point_get_tangent (path, &point, GSK_PATH_END, &t);
|
||||
offset = gsk_path_point_get_distance (measure, &point);
|
||||
distance = graphene_point_distance (&p, &test, NULL, NULL);
|
||||
|
||||
if (distance1 == distance)
|
||||
{
|
||||
g_assert_cmpfloat (distance1, ==, distance);
|
||||
g_assert_cmpfloat (p1.x, ==, p.x);
|
||||
g_assert_cmpfloat (p1.y, ==, p.y);
|
||||
g_assert_cmpfloat (offset1, ==, offset);
|
||||
g_assert_true (graphene_vec2_equal (&t1, &t));
|
||||
}
|
||||
else
|
||||
{
|
||||
g_assert_cmpfloat (distance2, ==, distance);
|
||||
g_assert_cmpfloat (p2.x, ==, p.x);
|
||||
g_assert_cmpfloat (p2.y, ==, p.y);
|
||||
g_assert_cmpfloat_with_epsilon (offset2 + gsk_path_measure_get_length (measure1), offset, MAX (G_MINFLOAT, offset / 1024));
|
||||
g_assert_true (graphene_vec2_equal (&t2, &t));
|
||||
}
|
||||
}
|
||||
|
||||
gsk_path_measure_unref (measure2);
|
||||
gsk_path_measure_unref (measure1);
|
||||
gsk_path_measure_unref (measure);
|
||||
gsk_path_unref (path2);
|
||||
gsk_path_unref (path1);
|
||||
gsk_path_unref (path);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
test_closest_point_for_point (void)
|
||||
{
|
||||
static const float tolerance = 0.5;
|
||||
GskPath *path;
|
||||
GskPathMeasure *measure;
|
||||
GskPathPoint point;
|
||||
float length, offset, distance;
|
||||
graphene_point_t p, closest_point;
|
||||
guint i, j;
|
||||
gboolean ret;
|
||||
|
||||
if (!g_test_slow ())
|
||||
{
|
||||
g_test_skip ("Skipping slow test");
|
||||
return;
|
||||
}
|
||||
|
||||
for (i = 0; i < 100; i++)
|
||||
{
|
||||
path = create_random_path (G_MAXUINT);
|
||||
if (gsk_path_is_empty (path))
|
||||
{
|
||||
/* empty paths have no closest point to anything */
|
||||
gsk_path_unref (path);
|
||||
continue;
|
||||
}
|
||||
|
||||
measure = gsk_path_measure_new_with_tolerance (path, tolerance);
|
||||
length = gsk_path_measure_get_length (measure);
|
||||
|
||||
for (j = 0; j < 100; j++)
|
||||
{
|
||||
offset = g_test_rand_double_range (0, length);
|
||||
ret = gsk_path_measure_get_point (measure, offset, &point);
|
||||
g_assert_true (ret);
|
||||
gsk_path_point_get_position (path, &point, &p);
|
||||
ret = gsk_path_get_closest_point (path, &p, 2 * tolerance, &point);
|
||||
g_assert_true (ret);
|
||||
gsk_path_point_get_position (path, &point, &closest_point);
|
||||
//closest_offset = gsk_path_point_get_distance (measure, &point);
|
||||
distance = graphene_point_distance (&p, &closest_point, NULL, NULL);
|
||||
|
||||
/* should be given due to the TRUE return above, but who knows... */
|
||||
g_assert_cmpfloat (distance, <=, 2 * tolerance);
|
||||
g_assert_cmpfloat (graphene_point_distance (&p, &closest_point, NULL, NULL), <=, 2 * tolerance);
|
||||
/* we can't check offsets here, since we might hit self-intersections
|
||||
g_assert_cmpfloat_with_epsilon (closest_offset, offset, 2 * tolerance);
|
||||
*/
|
||||
}
|
||||
|
||||
gsk_path_measure_unref (measure);
|
||||
gsk_path_unref (path);
|
||||
}
|
||||
}
|
||||
|
||||
#define N_PATHS 3
|
||||
static void
|
||||
test_in_fill_union (void)
|
||||
{
|
||||
GskPath *path;
|
||||
GskPathMeasure *measure, *measures[N_PATHS];
|
||||
GskPathBuilder *builder;
|
||||
guint i, j, k;
|
||||
|
||||
for (i = 0; i < 100; i++)
|
||||
{
|
||||
builder = gsk_path_builder_new ();
|
||||
for (k = 0; k < N_PATHS; k++)
|
||||
{
|
||||
path = create_random_path (G_MAXUINT);
|
||||
measures[k] = gsk_path_measure_new (path);
|
||||
gsk_path_builder_add_path (builder, path);
|
||||
gsk_path_unref (path);
|
||||
}
|
||||
path = gsk_path_builder_free_to_path (builder);
|
||||
measure = gsk_path_measure_new (path);
|
||||
gsk_path_unref (path);
|
||||
|
||||
for (j = 0; j < 100; j++)
|
||||
{
|
||||
graphene_point_t test = GRAPHENE_POINT_INIT (g_test_rand_double_range (-1000, 1000),
|
||||
g_test_rand_double_range (-1000, 1000));
|
||||
GskFillRule fill_rule;
|
||||
|
||||
for (fill_rule = GSK_FILL_RULE_WINDING; fill_rule <= GSK_FILL_RULE_EVEN_ODD; fill_rule++)
|
||||
{
|
||||
guint n_in_fill = 0;
|
||||
gboolean in_fill;
|
||||
|
||||
for (k = 0; k < N_PATHS; k++)
|
||||
{
|
||||
if (gsk_path_in_fill (gsk_path_measure_get_path (measures[k]), &test, GSK_FILL_RULE_EVEN_ODD))
|
||||
n_in_fill++;
|
||||
}
|
||||
|
||||
in_fill = gsk_path_in_fill (gsk_path_measure_get_path (measure), &test, GSK_FILL_RULE_EVEN_ODD);
|
||||
|
||||
switch (fill_rule)
|
||||
{
|
||||
case GSK_FILL_RULE_WINDING:
|
||||
if (n_in_fill == 0)
|
||||
g_assert_false (in_fill);
|
||||
else if (n_in_fill == 1)
|
||||
g_assert_true (in_fill);
|
||||
/* else we can't say anything because the winding rule doesn't give enough info */
|
||||
break;
|
||||
|
||||
case GSK_FILL_RULE_EVEN_ODD:
|
||||
g_assert_cmpint (in_fill, ==, n_in_fill & 1);
|
||||
break;
|
||||
|
||||
default:
|
||||
g_assert_not_reached ();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
gsk_path_measure_unref (measure);
|
||||
for (k = 0; k < N_PATHS; k++)
|
||||
{
|
||||
gsk_path_measure_unref (measures[k]);
|
||||
}
|
||||
}
|
||||
}
|
||||
#undef N_PATHS
|
||||
|
||||
/* This is somewhat sucky because using foreach breaks up the contours
|
||||
* (like rects and circles) and replaces everything with the standard
|
||||
* contour.
|
||||
* But at least it extensively tests the standard contour.
|
||||
*/
|
||||
static gboolean
|
||||
rotate_path_cb (GskPathOperation op,
|
||||
const graphene_point_t *pts,
|
||||
gsize n_pts,
|
||||
gpointer user_data)
|
||||
{
|
||||
GskPathBuilder **builders = user_data;
|
||||
|
||||
switch (op)
|
||||
{
|
||||
case GSK_PATH_MOVE:
|
||||
gsk_path_builder_move_to (builders[0], pts[0].x, pts[0].y);
|
||||
gsk_path_builder_move_to (builders[1], pts[0].y, -pts[0].x);
|
||||
break;
|
||||
|
||||
case GSK_PATH_CLOSE:
|
||||
gsk_path_builder_close (builders[0]);
|
||||
gsk_path_builder_close (builders[1]);
|
||||
break;
|
||||
|
||||
case GSK_PATH_LINE:
|
||||
gsk_path_builder_line_to (builders[0], pts[1].x, pts[1].y);
|
||||
gsk_path_builder_line_to (builders[1], pts[1].y, -pts[1].x);
|
||||
break;
|
||||
|
||||
case GSK_PATH_QUAD:
|
||||
gsk_path_builder_quad_to (builders[0], pts[1].x, pts[1].y, pts[2].x, pts[2].y);
|
||||
gsk_path_builder_quad_to (builders[1], pts[1].y, -pts[1].x, pts[2].y, -pts[2].x);
|
||||
break;
|
||||
|
||||
case GSK_PATH_CUBIC:
|
||||
gsk_path_builder_cubic_to (builders[0], pts[1].x, pts[1].y, pts[2].x, pts[2].y, pts[3].x, pts[3].y);
|
||||
gsk_path_builder_cubic_to (builders[1], pts[1].y, -pts[1].x, pts[2].y, -pts[2].x, pts[3].y, -pts[3].x);
|
||||
break;
|
||||
|
||||
default:
|
||||
g_assert_not_reached ();
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
test_in_fill_rotated (void)
|
||||
{
|
||||
GskPath *path;
|
||||
GskPathBuilder *builders[2];
|
||||
GskPathMeasure *measures[2];
|
||||
guint i, j;
|
||||
|
||||
#define N_FILL_RULES 2
|
||||
/* if this triggers, you added a new enum value to GskFillRule, so the define above needs
|
||||
* an update */
|
||||
g_assert_null (g_enum_get_value (g_type_class_ref (GSK_TYPE_FILL_RULE), N_FILL_RULES));
|
||||
|
||||
for (i = 0; i < 100; i++)
|
||||
{
|
||||
path = create_random_path (G_MAXUINT);
|
||||
builders[0] = gsk_path_builder_new ();
|
||||
builders[1] = gsk_path_builder_new ();
|
||||
/* Use -1 here because we want all the flags, even future additions */
|
||||
gsk_path_foreach (path, -1, rotate_path_cb, builders);
|
||||
gsk_path_unref (path);
|
||||
|
||||
path = gsk_path_builder_free_to_path (builders[0]);
|
||||
measures[0] = gsk_path_measure_new (path);
|
||||
gsk_path_unref (path);
|
||||
path = gsk_path_builder_free_to_path (builders[1]);
|
||||
measures[1] = gsk_path_measure_new (path);
|
||||
gsk_path_unref (path);
|
||||
|
||||
for (j = 0; j < 100; j++)
|
||||
{
|
||||
GskFillRule fill_rule = g_random_int_range (0, N_FILL_RULES);
|
||||
float x = g_test_rand_double_range (-1000, 1000);
|
||||
float y = g_test_rand_double_range (-1000, 1000);
|
||||
|
||||
g_assert_cmpint (gsk_path_in_fill (gsk_path_measure_get_path (measures[0]), &GRAPHENE_POINT_INIT (x, y), fill_rule),
|
||||
==,
|
||||
gsk_path_in_fill (gsk_path_measure_get_path (measures[1]), &GRAPHENE_POINT_INIT (y, -x), fill_rule));
|
||||
g_assert_cmpint (gsk_path_in_fill (gsk_path_measure_get_path (measures[0]), &GRAPHENE_POINT_INIT (y, x), fill_rule),
|
||||
==,
|
||||
gsk_path_in_fill (gsk_path_measure_get_path (measures[1]), &GRAPHENE_POINT_INIT (x, -y), fill_rule));
|
||||
}
|
||||
|
||||
gsk_path_measure_unref (measures[0]);
|
||||
gsk_path_measure_unref (measures[1]);
|
||||
}
|
||||
#undef N_FILL_RULES
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc,
|
||||
char *argv[])
|
||||
{
|
||||
gtk_test_init (&argc, &argv, NULL);
|
||||
|
||||
g_test_add_func ("/measure/segment_start", test_segment_start);
|
||||
g_test_add_func ("/measure/segment_end", test_segment_end);
|
||||
g_test_add_func ("/measure/segment_chunk", test_segment_chunk);
|
||||
g_test_add_func ("/measure/segment", test_segment);
|
||||
g_test_add_func ("/measure/get_point", test_get_point);
|
||||
g_test_add_func ("/measure/closest_point", test_closest_point);
|
||||
g_test_add_func ("/measure/closest_point_for_point", test_closest_point_for_point);
|
||||
g_test_add_func ("/measure/in-fill-union", test_in_fill_union);
|
||||
g_test_add_func ("/measure/in-fill-rotated", test_in_fill_rotated);
|
||||
|
||||
return g_test_run ();
|
||||
}
|
||||
@@ -371,6 +371,8 @@ tests = [
|
||||
['shader'],
|
||||
['path'],
|
||||
['path-special-cases'],
|
||||
['measure'],
|
||||
['measure-special-cases'],
|
||||
]
|
||||
|
||||
test_cargs = []
|
||||
|
||||
@@ -423,52 +423,25 @@ test_foreach (void)
|
||||
}
|
||||
|
||||
/* Test the basics of the path point api */
|
||||
typedef struct _GskRealPathPoint GskRealPathPoint;
|
||||
struct _GskRealPathPoint
|
||||
{
|
||||
gsize contour;
|
||||
gsize idx;
|
||||
float t;
|
||||
};
|
||||
|
||||
static void
|
||||
test_path_point (void)
|
||||
{
|
||||
GskPath *path;
|
||||
GskPathPoint point;
|
||||
GskRealPathPoint *rp = (GskRealPathPoint *)&point;
|
||||
gboolean ret;
|
||||
graphene_point_t pos, center;
|
||||
graphene_vec2_t t1, t2, mx;
|
||||
float curvature;
|
||||
|
||||
path = gsk_path_parse ("M 0 0 L 100 0 L 100 100 L 0 100 Z");
|
||||
|
||||
ret = gsk_path_get_start_point (path, &point);
|
||||
g_assert_true (ret);
|
||||
|
||||
g_assert_true (rp->contour == 0);
|
||||
g_assert_true (rp->idx == 1);
|
||||
g_assert_true (rp->t == 0);
|
||||
|
||||
ret = gsk_path_get_end_point (path, &point);
|
||||
g_assert_true (ret);
|
||||
|
||||
g_assert_true (rp->contour == 0);
|
||||
g_assert_true (rp->idx == 4);
|
||||
g_assert_true (rp->t == 1);
|
||||
path = gsk_path_parse ("M0,0L100,0L100,100L0,100Z");
|
||||
|
||||
ret = gsk_path_get_closest_point (path, &GRAPHENE_POINT_INIT (200, 200), INFINITY, &point);
|
||||
g_assert_true (ret);
|
||||
|
||||
g_assert_true (rp->contour == 0);
|
||||
g_assert_true (rp->idx == 2);
|
||||
g_assert_true (rp->t == 1);
|
||||
|
||||
gsk_path_get_position (path, &point, &pos);
|
||||
gsk_path_get_tangent (path, &point, GSK_PATH_START, &t1);
|
||||
gsk_path_get_tangent (path, &point, GSK_PATH_END, &t2);
|
||||
curvature = gsk_path_get_curvature (path, &point, ¢er);
|
||||
gsk_path_point_get_position (path, &point, &pos);
|
||||
gsk_path_point_get_tangent (path, &point, GSK_PATH_START, &t1);
|
||||
gsk_path_point_get_tangent (path, &point, GSK_PATH_END, &t2);
|
||||
curvature = gsk_path_point_get_curvature (path, &point, ¢er);
|
||||
|
||||
g_assert_true (graphene_point_equal (&pos, &GRAPHENE_POINT_INIT (100, 100)));
|
||||
g_assert_true (graphene_vec2_equal (&t1, graphene_vec2_y_axis ()));
|
||||
@@ -476,13 +449,6 @@ test_path_point (void)
|
||||
g_assert_true (graphene_vec2_equal (&t2, &mx));
|
||||
g_assert_true (curvature == 0);
|
||||
|
||||
ret = gsk_path_get_closest_point (path, &GRAPHENE_POINT_INIT (100, 50), INFINITY, &point);
|
||||
g_assert_true (ret);
|
||||
|
||||
g_assert_true (rp->contour == 0);
|
||||
g_assert_true (rp->idx == 2);
|
||||
g_assert_true (rp->t == 0.5);
|
||||
|
||||
gsk_path_unref (path);
|
||||
}
|
||||
|
||||
@@ -519,12 +485,6 @@ test_path_segments (void)
|
||||
{ 50, 0 },
|
||||
{ 50, 50 },
|
||||
"M 50 0 L 100 0 L 50 50"
|
||||
},
|
||||
{
|
||||
"M 0 0 L 100 0 L 50 50 Z",
|
||||
{ 100, 0 },
|
||||
{ 100, 0 },
|
||||
"M 100 0 L 50 50 L 0 0 L 100 0"
|
||||
}
|
||||
};
|
||||
|
||||
@@ -552,143 +512,6 @@ test_path_segments (void)
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
test_bad_in_fill (void)
|
||||
{
|
||||
GskPath *path;
|
||||
gboolean inside;
|
||||
|
||||
/* A fat Cantarell W */
|
||||
path = gsk_path_parse ("M -2 694 M 206.1748046875 704 L 390.9371337890625 704 L 551.1888427734375 99.5035400390625 L 473.0489501953125 99.5035400390625 L 649.1048583984375 704 L 828.965087890625 704 L 1028.3077392578125 10 L 857.8111572265625 10 L 710.0489501953125 621.251708984375 L 775.9720458984375 598.426513671875 L 614.5245361328125 14.0489501953125 L 430.2237548828125 14.0489501953125 L 278.6783447265625 602.230712890625 L 330.0909423828125 602.230712890625 L 195.88818359375 10 L 5.7342529296875 10 L 206.1748046875 704 Z");
|
||||
|
||||
/* The midpoint of the right foot of a fat Cantarell X */
|
||||
inside = gsk_path_in_fill (path, &GRAPHENE_POINT_INIT (552.360107, 704.000000), GSK_FILL_RULE_WINDING);
|
||||
|
||||
g_assert_false (inside);
|
||||
|
||||
gsk_path_unref (path);
|
||||
}
|
||||
|
||||
/* Test that path_in_fill implicitly closes contours. I think this is wrong,
|
||||
* but it is what "everybody" does.
|
||||
*/
|
||||
static void
|
||||
test_unclosed_in_fill (void)
|
||||
{
|
||||
GskPath *path;
|
||||
|
||||
path = gsk_path_parse ("M 0 0 L 0 100 L 100 100 L 100 0 Z");
|
||||
g_assert_true (gsk_path_in_fill (path, &GRAPHENE_POINT_INIT (50, 50), GSK_FILL_RULE_WINDING));
|
||||
gsk_path_unref (path);
|
||||
|
||||
path = gsk_path_parse ("M 0 0 L 0 100 L 100 100 L 100 0");
|
||||
g_assert_true (gsk_path_in_fill (path, &GRAPHENE_POINT_INIT (50, 50), GSK_FILL_RULE_WINDING));
|
||||
gsk_path_unref (path);
|
||||
}
|
||||
|
||||
/* Test that all the gsk_path_builder_add methods close the current
|
||||
* contour in the end and do not change the current point.
|
||||
*/
|
||||
static void
|
||||
test_path_builder_add (void)
|
||||
{
|
||||
GskPathBuilder *builder;
|
||||
GskPath *path, *path2;
|
||||
char *s;
|
||||
cairo_path_t *cpath;
|
||||
cairo_surface_t *surface;
|
||||
cairo_t *cr;
|
||||
PangoLayout *layout;
|
||||
GskPathPoint point1, point2;
|
||||
|
||||
#define N_ADD_METHODS 8
|
||||
|
||||
path = gsk_path_parse ("M 10 10 L 100 100");
|
||||
|
||||
gsk_path_get_closest_point (path, &GRAPHENE_POINT_INIT (50, 50), INFINITY, &point1);
|
||||
gsk_path_get_end_point (path, &point2);
|
||||
|
||||
surface = cairo_image_surface_create (CAIRO_FORMAT_ARGB32, 100, 100);
|
||||
cr = cairo_create (surface);
|
||||
cairo_move_to (cr, 10, 10);
|
||||
cairo_line_to (cr, 20, 30);
|
||||
cpath = cairo_copy_path (cr);
|
||||
|
||||
layout = pango_cairo_create_layout (cr);
|
||||
pango_layout_set_text (layout, "ABC", -1);
|
||||
|
||||
for (unsigned int i = 0; i < N_ADD_METHODS; i++)
|
||||
{
|
||||
builder = gsk_path_builder_new ();
|
||||
gsk_path_builder_move_to (builder, 123, 456);
|
||||
|
||||
switch (i)
|
||||
{
|
||||
case 0:
|
||||
gsk_path_builder_add_path (builder, path);
|
||||
break;
|
||||
|
||||
case 1:
|
||||
gsk_path_builder_add_reverse_path (builder, path);
|
||||
break;
|
||||
|
||||
case 2:
|
||||
gsk_path_builder_add_segment (builder, path, &point1, &point2);
|
||||
break;
|
||||
|
||||
case 3:
|
||||
gsk_path_builder_add_cairo_path (builder, cpath);
|
||||
break;
|
||||
|
||||
case 4:
|
||||
gsk_path_builder_add_layout (builder, layout);
|
||||
break;
|
||||
|
||||
case 5:
|
||||
gsk_path_builder_add_rect (builder, &GRAPHENE_RECT_INIT (0, 0, 10, 10));
|
||||
break;
|
||||
|
||||
case 6:
|
||||
{
|
||||
GskRoundedRect rect;
|
||||
|
||||
gsk_rounded_rect_init (&rect,
|
||||
&GRAPHENE_RECT_INIT (0, 0, 100, 100),
|
||||
&GRAPHENE_SIZE_INIT (10, 20),
|
||||
&GRAPHENE_SIZE_INIT (20, 30),
|
||||
&GRAPHENE_SIZE_INIT (0, 0),
|
||||
&GRAPHENE_SIZE_INIT (10, 10));
|
||||
gsk_path_builder_add_rounded_rect (builder, &rect);
|
||||
}
|
||||
break;
|
||||
|
||||
case 7:
|
||||
gsk_path_builder_add_circle (builder, &GRAPHENE_POINT_INIT (0, 0), 10);
|
||||
break;
|
||||
|
||||
default:
|
||||
g_assert_not_reached ();
|
||||
}
|
||||
|
||||
gsk_path_builder_rel_line_to (builder, 10, 0);
|
||||
path2 = gsk_path_builder_free_to_path (builder);
|
||||
|
||||
s = gsk_path_to_string (path2);
|
||||
g_assert_true (g_str_has_prefix (s, "M 123 456"));
|
||||
g_assert_true (g_str_has_suffix (s, "M 123 456 L 133 456"));
|
||||
g_free (s);
|
||||
gsk_path_unref (path2);
|
||||
}
|
||||
|
||||
g_object_unref (layout);
|
||||
|
||||
cairo_path_destroy (cpath);
|
||||
cairo_destroy (cr);
|
||||
cairo_surface_destroy (surface);
|
||||
|
||||
gsk_path_unref (path);
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
{
|
||||
@@ -700,9 +523,6 @@ main (int argc, char *argv[])
|
||||
g_test_add_func ("/path/foreach", test_foreach);
|
||||
g_test_add_func ("/path/point", test_path_point);
|
||||
g_test_add_func ("/path/segments", test_path_segments);
|
||||
g_test_add_func ("/path/bad-in-fill", test_bad_in_fill);
|
||||
g_test_add_func ("/path/unclosed-in-fill", test_unclosed_in_fill);
|
||||
g_test_add_func ("/path/builder/add", test_path_builder_add);
|
||||
|
||||
return g_test_run ();
|
||||
}
|
||||
|
||||
@@ -582,166 +582,6 @@ test_parse (void)
|
||||
}
|
||||
}
|
||||
|
||||
#define N_PATHS 3
|
||||
static void
|
||||
test_in_fill_union (void)
|
||||
{
|
||||
GskPath *path, *paths[N_PATHS];
|
||||
GskPathBuilder *builder;
|
||||
guint i, j, k;
|
||||
|
||||
for (i = 0; i < 100; i++)
|
||||
{
|
||||
builder = gsk_path_builder_new ();
|
||||
|
||||
for (k = 0; k < N_PATHS; k++)
|
||||
{
|
||||
paths[k] = create_random_path (G_MAXUINT);
|
||||
gsk_path_builder_add_path (builder, paths[k]);
|
||||
}
|
||||
|
||||
path = gsk_path_builder_free_to_path (builder);
|
||||
|
||||
for (j = 0; j < 100; j++)
|
||||
{
|
||||
graphene_point_t test = GRAPHENE_POINT_INIT (g_test_rand_double_range (-1000, 1000),
|
||||
g_test_rand_double_range (-1000, 1000));
|
||||
GskFillRule fill_rule;
|
||||
|
||||
for (fill_rule = GSK_FILL_RULE_WINDING; fill_rule <= GSK_FILL_RULE_EVEN_ODD; fill_rule++)
|
||||
{
|
||||
guint n_in_fill = 0;
|
||||
gboolean in_fill;
|
||||
|
||||
for (k = 0; k < N_PATHS; k++)
|
||||
{
|
||||
if (gsk_path_in_fill (paths[k], &test, GSK_FILL_RULE_EVEN_ODD))
|
||||
n_in_fill++;
|
||||
}
|
||||
|
||||
in_fill = gsk_path_in_fill (path, &test, GSK_FILL_RULE_EVEN_ODD);
|
||||
switch (fill_rule)
|
||||
{
|
||||
case GSK_FILL_RULE_WINDING:
|
||||
if (n_in_fill == 0)
|
||||
g_assert_false (in_fill);
|
||||
else if (n_in_fill == 1)
|
||||
g_assert_true (in_fill);
|
||||
/* else we can't say anything because the winding rule doesn't give enough info */
|
||||
break;
|
||||
|
||||
case GSK_FILL_RULE_EVEN_ODD:
|
||||
g_assert_cmpint (in_fill, ==, n_in_fill & 1);
|
||||
break;
|
||||
|
||||
default:
|
||||
g_assert_not_reached ();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
gsk_path_unref (path);
|
||||
|
||||
for (k = 0; k < N_PATHS; k++)
|
||||
gsk_path_unref (paths[k]);
|
||||
}
|
||||
}
|
||||
#undef N_PATHS
|
||||
|
||||
/* This is somewhat sucky because using foreach breaks up the contours
|
||||
* (like rects and circles) and replaces everything with the standard
|
||||
* contour.
|
||||
* But at least it extensively tests the standard contour.
|
||||
*/
|
||||
static gboolean
|
||||
rotate_path_cb (GskPathOperation op,
|
||||
const graphene_point_t *pts,
|
||||
gsize n_pts,
|
||||
gpointer user_data)
|
||||
{
|
||||
GskPathBuilder **builders = user_data;
|
||||
|
||||
switch (op)
|
||||
{
|
||||
case GSK_PATH_MOVE:
|
||||
gsk_path_builder_move_to (builders[0], pts[0].x, pts[0].y);
|
||||
gsk_path_builder_move_to (builders[1], pts[0].y, -pts[0].x);
|
||||
break;
|
||||
|
||||
case GSK_PATH_CLOSE:
|
||||
gsk_path_builder_close (builders[0]);
|
||||
gsk_path_builder_close (builders[1]);
|
||||
break;
|
||||
|
||||
case GSK_PATH_LINE:
|
||||
gsk_path_builder_line_to (builders[0], pts[1].x, pts[1].y);
|
||||
gsk_path_builder_line_to (builders[1], pts[1].y, -pts[1].x);
|
||||
break;
|
||||
|
||||
case GSK_PATH_QUAD:
|
||||
gsk_path_builder_quad_to (builders[0], pts[1].x, pts[1].y, pts[2].x, pts[2].y);
|
||||
gsk_path_builder_quad_to (builders[1], pts[1].y, -pts[1].x, pts[2].y, -pts[2].x);
|
||||
break;
|
||||
|
||||
case GSK_PATH_CUBIC:
|
||||
gsk_path_builder_cubic_to (builders[0], pts[1].x, pts[1].y, pts[2].x, pts[2].y, pts[3].x, pts[3].y);
|
||||
gsk_path_builder_cubic_to (builders[1], pts[1].y, -pts[1].x, pts[2].y, -pts[2].x, pts[3].y, -pts[3].x);
|
||||
break;
|
||||
|
||||
default:
|
||||
g_assert_not_reached ();
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
test_in_fill_rotated (void)
|
||||
{
|
||||
GskPath *path;
|
||||
GskPathBuilder *builders[2];
|
||||
GskPath *paths[2];
|
||||
guint i, j;
|
||||
|
||||
#define N_FILL_RULES 2
|
||||
/* if this triggers, you added a new enum value to GskFillRule, so the define above needs
|
||||
* an update */
|
||||
g_assert_null (g_enum_get_value (g_type_class_ref (GSK_TYPE_FILL_RULE), N_FILL_RULES));
|
||||
|
||||
for (i = 0; i < 100; i++)
|
||||
{
|
||||
path = create_random_path (G_MAXUINT);
|
||||
builders[0] = gsk_path_builder_new ();
|
||||
builders[1] = gsk_path_builder_new ();
|
||||
/* Use -1 here because we want all the flags, even future additions */
|
||||
gsk_path_foreach (path, -1, rotate_path_cb, builders);
|
||||
gsk_path_unref (path);
|
||||
|
||||
paths[0] = gsk_path_builder_free_to_path (builders[0]);
|
||||
paths[1] = gsk_path_builder_free_to_path (builders[1]);
|
||||
|
||||
for (j = 0; j < 100; j++)
|
||||
{
|
||||
GskFillRule fill_rule = g_random_int_range (0, N_FILL_RULES);
|
||||
float x = g_test_rand_double_range (-1000, 1000);
|
||||
float y = g_test_rand_double_range (-1000, 1000);
|
||||
|
||||
g_assert_cmpint (gsk_path_in_fill (paths[0], &GRAPHENE_POINT_INIT (x, y), fill_rule),
|
||||
==,
|
||||
gsk_path_in_fill (paths[1], &GRAPHENE_POINT_INIT (y, -x), fill_rule));
|
||||
g_assert_cmpint (gsk_path_in_fill (paths[0], &GRAPHENE_POINT_INIT (y, x), fill_rule),
|
||||
==,
|
||||
gsk_path_in_fill (paths[1], &GRAPHENE_POINT_INIT (x, -y), fill_rule));
|
||||
}
|
||||
|
||||
gsk_path_unref (paths[0]);
|
||||
gsk_path_unref (paths[1]);
|
||||
}
|
||||
#undef N_FILL_RULES
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc,
|
||||
char *argv[])
|
||||
@@ -750,8 +590,6 @@ main (int argc,
|
||||
|
||||
g_test_add_func ("/path/create", test_create);
|
||||
g_test_add_func ("/path/parse", test_parse);
|
||||
g_test_add_func ("/path/in-fill-union", test_in_fill_union);
|
||||
g_test_add_func ("/path/in-fill-rotated", test_in_fill_rotated);
|
||||
|
||||
return g_test_run ();
|
||||
}
|
||||
|
||||
@@ -10,7 +10,7 @@ test_calendar_set_day (void)
|
||||
|
||||
cal = gtk_calendar_new ();
|
||||
|
||||
tz = g_time_zone_new_identifier ("Europe/Brussels");
|
||||
tz = g_time_zone_new_identifier ("MET");
|
||||
g_assert_nonnull (tz);
|
||||
dt = g_date_time_new (tz, 1970, 3, 1, 0, 0, 0);
|
||||
g_assert_nonnull (dt);
|
||||
|
||||
@@ -1,131 +0,0 @@
|
||||
/* 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>
|
||||
|
||||
static gboolean
|
||||
foreach_cb (GskPathOperation op,
|
||||
const graphene_point_t *pts,
|
||||
gsize n_pts,
|
||||
gpointer user_data)
|
||||
{
|
||||
GskPathBuilder *builder = user_data;
|
||||
|
||||
switch (op)
|
||||
{
|
||||
case GSK_PATH_MOVE:
|
||||
gsk_path_builder_move_to (builder, pts[0].x, pts[0].y);
|
||||
break;
|
||||
|
||||
case GSK_PATH_CLOSE:
|
||||
gsk_path_builder_close (builder);
|
||||
break;
|
||||
|
||||
case GSK_PATH_LINE:
|
||||
gsk_path_builder_line_to (builder, pts[1].x, pts[1].y);
|
||||
break;
|
||||
|
||||
case GSK_PATH_QUAD:
|
||||
gsk_path_builder_quad_to (builder, pts[1].x, pts[1].y, pts[2].x, pts[2].y);
|
||||
break;
|
||||
|
||||
case GSK_PATH_CUBIC:
|
||||
gsk_path_builder_cubic_to (builder, pts[1].x, pts[1].y,
|
||||
pts[2].x, pts[2].y,
|
||||
pts[3].x, pts[3].y);
|
||||
break;
|
||||
|
||||
default:
|
||||
g_assert_not_reached ();
|
||||
}
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
void
|
||||
do_decompose (int *argc, const char ***argv)
|
||||
{
|
||||
GError *error = NULL;
|
||||
gboolean allow_quad = FALSE;
|
||||
gboolean allow_curve = FALSE;
|
||||
char **args = NULL;
|
||||
GOptionContext *context;
|
||||
GOptionEntry entries[] = {
|
||||
{ "allow-quad", 0, 0, G_OPTION_ARG_NONE, &allow_quad, N_("Allow quadratic Bézier curves"), NULL },
|
||||
{ "allow-cubic", 0, 0, G_OPTION_ARG_NONE, &allow_curve, N_("Allow cubic Bézier curves"), NULL },
|
||||
{ G_OPTION_REMAINING, 0, 0, G_OPTION_ARG_FILENAME_ARRAY, &args, NULL, N_("PATH") },
|
||||
{ NULL, },
|
||||
};
|
||||
GskPathForeachFlags flags;
|
||||
GskPath *path, *result;
|
||||
GskPathBuilder *builder;
|
||||
|
||||
g_set_prgname ("gtk4-path-tool decompose");
|
||||
|
||||
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, _("Decompose 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]);
|
||||
|
||||
flags = 0;
|
||||
if (allow_quad)
|
||||
flags |= GSK_PATH_FOREACH_ALLOW_QUAD;
|
||||
if (allow_curve)
|
||||
flags |= GSK_PATH_FOREACH_ALLOW_CUBIC;
|
||||
|
||||
builder = gsk_path_builder_new ();
|
||||
|
||||
gsk_path_foreach (path, flags, foreach_cb, builder);
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -1,76 +0,0 @@
|
||||
/* 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>
|
||||
|
||||
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;
|
||||
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]);
|
||||
|
||||
if (gsk_path_is_empty (path))
|
||||
g_print ("%s\n", _("Path is empty."));
|
||||
else
|
||||
{
|
||||
if (gsk_path_is_closed (path))
|
||||
g_print ("%s\n", _("Path is closed"));
|
||||
|
||||
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);
|
||||
}
|
||||
}
|
||||
@@ -1,208 +0,0 @@
|
||||
/* 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 <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <glib/gi18n-lib.h>
|
||||
#include <glib/gprintf.h>
|
||||
#include <glib/gstdio.h>
|
||||
#include <gtk/gtk.h>
|
||||
#include "gtk-path-tool.h"
|
||||
|
||||
|
||||
void
|
||||
do_render (int *argc,
|
||||
const char ***argv)
|
||||
{
|
||||
GError *error = NULL;
|
||||
const char *fill = "winding";
|
||||
const char *fg_color = "black";
|
||||
const char *bg_color = "white";
|
||||
gboolean do_stroke = FALSE;
|
||||
double line_width = 1;
|
||||
const char *cap = "butt";
|
||||
const char *join = "miter";
|
||||
double miter_limit = 4;
|
||||
const char *dashes = NULL;
|
||||
double dash_offset = 0;
|
||||
const char *output_file = NULL;
|
||||
char **args = NULL;
|
||||
GOptionContext *context;
|
||||
const GOptionEntry entries[] = {
|
||||
{ "fill-rule", 0, 0, G_OPTION_ARG_STRING, &fill, N_("Fill rule (winding, even-odd)"), N_("VALUE") },
|
||||
{ "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 },
|
||||
{ "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;
|
||||
graphene_rect_t bounds;
|
||||
GskRenderNode *fg_node, *nodes[2], *node;
|
||||
GdkSurface *surface;
|
||||
GskRenderer *renderer;
|
||||
GdkTexture *texture;
|
||||
const char *filename;
|
||||
GskLineCap line_cap;
|
||||
GskLineJoin line_join;
|
||||
GskStroke *stroke;
|
||||
|
||||
if (gdk_display_get_default () == NULL)
|
||||
{
|
||||
g_printerr ("%s\n", _("Could not initialize windowing system"));
|
||||
exit (1);
|
||||
}
|
||||
|
||||
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."));
|
||||
|
||||
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 path specified"));
|
||||
exit (1);
|
||||
}
|
||||
|
||||
if (g_strv_length (args) > 1)
|
||||
{
|
||||
g_printerr ("%s\n", _("Can only render a single path"));
|
||||
exit (1);
|
||||
}
|
||||
|
||||
path = get_path (args[0]);
|
||||
|
||||
fill_rule = get_enum_value (GSK_TYPE_FILL_RULE, _("fill rule"), fill);
|
||||
get_color (&fg, fg_color);
|
||||
get_color (&bg, bg_color);
|
||||
|
||||
line_cap = get_enum_value (GSK_TYPE_LINE_CAP, _("line cap"), cap);
|
||||
line_join = get_enum_value (GSK_TYPE_LINE_JOIN, _("line join"), join);
|
||||
|
||||
stroke = gsk_stroke_new (line_width);
|
||||
gsk_stroke_set_line_cap (stroke, line_cap);
|
||||
gsk_stroke_set_line_join (stroke, line_join);
|
||||
|
||||
gsk_stroke_set_miter_limit (stroke, miter_limit);
|
||||
|
||||
if (dashes != NULL)
|
||||
{
|
||||
GArray *d = g_array_new (FALSE, FALSE, sizeof (float));
|
||||
char **strings;
|
||||
|
||||
strings = g_strsplit (dashes, ",", 0);
|
||||
|
||||
for (unsigned int i = 0; strings[i]; i++)
|
||||
{
|
||||
char *end = NULL;
|
||||
float f;
|
||||
|
||||
f = (float) g_ascii_strtod (strings[i], &end);
|
||||
|
||||
if (*end != '\0')
|
||||
{
|
||||
char *msg = g_strdup_printf (_("Failed to parse '%s' as number"), strings[i]);
|
||||
g_printerr ("%s\n", msg);
|
||||
exit (1);
|
||||
}
|
||||
|
||||
g_array_append_val (d, f);
|
||||
}
|
||||
|
||||
g_strfreev (strings);
|
||||
|
||||
gsk_stroke_set_dash (stroke, (const float *)d->data, d->len);
|
||||
|
||||
g_array_unref (d);
|
||||
}
|
||||
|
||||
gsk_stroke_set_dash_offset (stroke, dash_offset);
|
||||
|
||||
if (do_stroke)
|
||||
gsk_path_get_stroke_bounds (path, stroke, &bounds);
|
||||
else
|
||||
gsk_path_get_bounds (path, &bounds);
|
||||
graphene_rect_inset (&bounds, -10, -10);
|
||||
|
||||
nodes[0] = gsk_color_node_new (&bg, &bounds);
|
||||
fg_node = gsk_color_node_new (&fg, &bounds);
|
||||
if (do_stroke)
|
||||
nodes[1] = gsk_stroke_node_new (fg_node, path, stroke);
|
||||
else
|
||||
nodes[1] = gsk_fill_node_new (fg_node, path, fill_rule);
|
||||
|
||||
node = gsk_container_node_new (nodes, 2);
|
||||
|
||||
gsk_render_node_unref (fg_node);
|
||||
gsk_render_node_unref (nodes[0]);
|
||||
gsk_render_node_unref (nodes[1]);
|
||||
|
||||
surface = gdk_surface_new_toplevel (gdk_display_get_default ());
|
||||
renderer = gsk_renderer_new_for_surface (surface);
|
||||
|
||||
texture = gsk_renderer_render_texture (renderer, node, &bounds);
|
||||
|
||||
filename = output_file ? output_file : "path.png";
|
||||
if (!gdk_texture_save_to_png (texture, filename))
|
||||
{
|
||||
char *msg = g_strdup_printf (_("Saving png to '%s' failed"), filename);
|
||||
g_printerr ("%s\n", msg);
|
||||
exit (1);
|
||||
}
|
||||
|
||||
if (output_file == NULL)
|
||||
{
|
||||
char *msg = g_strdup_printf (_("Output written to '%s'."), filename);
|
||||
g_print ("%s\n", msg);
|
||||
g_free (msg);
|
||||
}
|
||||
|
||||
g_object_unref (texture);
|
||||
gsk_renderer_unrealize (renderer);
|
||||
g_object_unref (renderer);
|
||||
g_object_unref (surface);
|
||||
gsk_render_node_unref (node);
|
||||
|
||||
gsk_path_unref (path);
|
||||
|
||||
g_strfreev (args);
|
||||
}
|
||||
@@ -1,232 +0,0 @@
|
||||
/* 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 <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <glib/gi18n-lib.h>
|
||||
#include <glib/gprintf.h>
|
||||
#include <glib/gstdio.h>
|
||||
#include <gtk/gtk.h>
|
||||
#include "gtk-path-tool.h"
|
||||
|
||||
#include "path-view.h"
|
||||
|
||||
static void
|
||||
show_path_fill (GskPath *path,
|
||||
GskFillRule fill_rule,
|
||||
const GdkRGBA *fg_color,
|
||||
const GdkRGBA *bg_color)
|
||||
{
|
||||
GtkWidget *window, *sw, *child;
|
||||
|
||||
window = gtk_window_new ();
|
||||
gtk_window_set_title (GTK_WINDOW (window), _("Path Preview"));
|
||||
|
||||
// gtk_window_set_default_size (GTK_WINDOW (window), 700, 500);
|
||||
|
||||
sw = gtk_scrolled_window_new ();
|
||||
gtk_scrolled_window_set_propagate_natural_width (GTK_SCROLLED_WINDOW (sw), TRUE);
|
||||
gtk_scrolled_window_set_propagate_natural_height (GTK_SCROLLED_WINDOW (sw), TRUE);
|
||||
gtk_window_set_child (GTK_WINDOW (window), sw);
|
||||
|
||||
child = path_view_new (path);
|
||||
g_object_set (child,
|
||||
"do-fill", TRUE,
|
||||
"fill-rule", fill_rule,
|
||||
"fg-color", fg_color,
|
||||
"bg-color", bg_color,
|
||||
NULL);
|
||||
gtk_widget_set_hexpand (child, TRUE);
|
||||
gtk_widget_set_vexpand (child, TRUE);
|
||||
gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (sw), child);
|
||||
|
||||
gtk_window_present (GTK_WINDOW (window));
|
||||
|
||||
while (g_list_model_get_n_items (gtk_window_get_toplevels ()) > 0)
|
||||
g_main_context_iteration (NULL, TRUE);
|
||||
}
|
||||
|
||||
static void
|
||||
show_path_stroke (GskPath *path,
|
||||
GskStroke *stroke,
|
||||
const GdkRGBA *fg_color,
|
||||
const GdkRGBA *bg_color)
|
||||
{
|
||||
GtkWidget *window, *sw, *child;
|
||||
|
||||
window = gtk_window_new ();
|
||||
gtk_window_set_title (GTK_WINDOW (window), _("Path Preview"));
|
||||
|
||||
// gtk_window_set_default_size (GTK_WINDOW (window), 700, 500);
|
||||
|
||||
sw = gtk_scrolled_window_new ();
|
||||
gtk_scrolled_window_set_propagate_natural_width (GTK_SCROLLED_WINDOW (sw), TRUE);
|
||||
gtk_scrolled_window_set_propagate_natural_height (GTK_SCROLLED_WINDOW (sw), TRUE);
|
||||
gtk_window_set_child (GTK_WINDOW (window), sw);
|
||||
|
||||
child = path_view_new (path);
|
||||
g_object_set (child,
|
||||
"do-fill", FALSE,
|
||||
"stroke", stroke,
|
||||
"fg-color", fg_color,
|
||||
"bg-color", bg_color,
|
||||
NULL);
|
||||
gtk_widget_set_hexpand (child, TRUE);
|
||||
gtk_widget_set_vexpand (child, TRUE);
|
||||
gtk_scrolled_window_set_child (GTK_SCROLLED_WINDOW (sw), child);
|
||||
|
||||
gtk_window_present (GTK_WINDOW (window));
|
||||
|
||||
while (g_list_model_get_n_items (gtk_window_get_toplevels ()) > 0)
|
||||
g_main_context_iteration (NULL, TRUE);
|
||||
}
|
||||
|
||||
void
|
||||
do_show (int *argc,
|
||||
const char ***argv)
|
||||
{
|
||||
GError *error = NULL;
|
||||
gboolean do_stroke = FALSE;
|
||||
const char *fill = "winding";
|
||||
const char *fg_color = "black";
|
||||
const char *bg_color = "white";
|
||||
double line_width = 1;
|
||||
const char *cap = "butt";
|
||||
const char *join = "miter";
|
||||
double miter_limit = 4;
|
||||
const char *dashes = NULL;
|
||||
double dash_offset = 0;
|
||||
char **args = NULL;
|
||||
GOptionContext *context;
|
||||
const GOptionEntry entries[] = {
|
||||
{ "fill-rule", 0, 0, G_OPTION_ARG_STRING, &fill, N_("Fill rule (winding, even-odd)"), N_("VALUE") },
|
||||
{ "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 },
|
||||
{ "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;
|
||||
GskFillRule fill_rule;
|
||||
GdkRGBA fg;
|
||||
GdkRGBA bg;
|
||||
GskLineCap line_cap;
|
||||
GskLineJoin line_join;
|
||||
GskStroke *stroke;
|
||||
|
||||
if (gdk_display_get_default () == NULL)
|
||||
{
|
||||
g_printerr ("%s\n", _("Could not initialize windowing system"));
|
||||
exit (1);
|
||||
}
|
||||
|
||||
g_set_prgname ("gtk4-path-tool show");
|
||||
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, _("Display the 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 path specified"));
|
||||
exit (1);
|
||||
}
|
||||
|
||||
if (g_strv_length (args) > 1)
|
||||
{
|
||||
g_printerr ("%s\n", _("Can only show a single path"));
|
||||
exit (1);
|
||||
}
|
||||
|
||||
path = get_path (args[0]);
|
||||
|
||||
fill_rule = get_enum_value (GSK_TYPE_FILL_RULE, _("fill rule"), fill);
|
||||
get_color (&fg, fg_color);
|
||||
get_color (&bg, bg_color);
|
||||
|
||||
line_cap = get_enum_value (GSK_TYPE_LINE_CAP, _("line cap"), cap);
|
||||
line_join = get_enum_value (GSK_TYPE_LINE_JOIN, _("line join"), join);
|
||||
|
||||
stroke = gsk_stroke_new (line_width);
|
||||
gsk_stroke_set_line_cap (stroke, line_cap);
|
||||
gsk_stroke_set_line_join (stroke, line_join);
|
||||
|
||||
gsk_stroke_set_miter_limit (stroke, miter_limit);
|
||||
|
||||
if (dashes != NULL)
|
||||
{
|
||||
GArray *d = g_array_new (FALSE, FALSE, sizeof (float));
|
||||
char **strings;
|
||||
|
||||
strings = g_strsplit (dashes, ",", 0);
|
||||
|
||||
for (unsigned int i = 0; strings[i]; i++)
|
||||
{
|
||||
char *end = NULL;
|
||||
float f;
|
||||
|
||||
f = (float) g_ascii_strtod (strings[i], &end);
|
||||
|
||||
if (*end != '\0')
|
||||
{
|
||||
char *msg = g_strdup_printf (_("Failed to parse '%s' as number"), strings[i]);
|
||||
g_printerr ("%s\n", msg);
|
||||
exit (1);
|
||||
}
|
||||
|
||||
g_array_append_val (d, f);
|
||||
}
|
||||
|
||||
g_strfreev (strings);
|
||||
|
||||
gsk_stroke_set_dash (stroke, (const float *)d->data, d->len);
|
||||
|
||||
g_array_unref (d);
|
||||
}
|
||||
|
||||
gsk_stroke_set_dash_offset (stroke, dash_offset);
|
||||
|
||||
if (do_stroke)
|
||||
show_path_stroke (path, stroke, &fg, &bg);
|
||||
else
|
||||
show_path_fill (path, fill_rule, &fg, &bg);
|
||||
|
||||
gsk_path_unref (path);
|
||||
|
||||
g_strfreev (args);
|
||||
}
|
||||
@@ -1,139 +0,0 @@
|
||||
/* 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 <gio/gio.h>
|
||||
#ifdef G_OS_UNIX
|
||||
#include <gio/gunixinputstream.h>
|
||||
#endif
|
||||
#include "gtk-path-tool.h"
|
||||
|
||||
#include <glib/gi18n-lib.h>
|
||||
|
||||
GskPath *
|
||||
get_path (const char *arg)
|
||||
{
|
||||
char *buffer = NULL;
|
||||
gsize len;
|
||||
GError *error = NULL;
|
||||
GskPath *path;
|
||||
|
||||
if (arg[0] == '.' || arg[0] == '/')
|
||||
{
|
||||
if (!g_file_get_contents (arg, &buffer, &len, &error))
|
||||
{
|
||||
g_printerr ("%s\n", error->message);
|
||||
exit (1);
|
||||
}
|
||||
}
|
||||
#ifdef G_OS_UNIX
|
||||
else if (strcmp (arg, "-") == 0)
|
||||
{
|
||||
GInputStream *in;
|
||||
GOutputStream *out;
|
||||
|
||||
in = g_unix_input_stream_new (0, FALSE);
|
||||
out = g_memory_output_stream_new (NULL, 0, g_realloc, g_free);
|
||||
|
||||
if (g_output_stream_splice (out, in, 0, NULL, &error) < 0)
|
||||
{
|
||||
g_printerr (_("Failed to read from standard input: %s\n"), error->message);
|
||||
exit (1);
|
||||
}
|
||||
|
||||
if (!g_output_stream_close (out, NULL, &error))
|
||||
{
|
||||
g_printerr (_("Error reading from standard input: %s\n"), error->message);
|
||||
exit (1);
|
||||
}
|
||||
|
||||
buffer = g_memory_output_stream_steal_data (G_MEMORY_OUTPUT_STREAM (out));
|
||||
|
||||
g_object_unref (out);
|
||||
g_object_unref (in);
|
||||
}
|
||||
#endif
|
||||
else
|
||||
buffer = g_strdup (arg);
|
||||
|
||||
g_strstrip (buffer);
|
||||
|
||||
path = gsk_path_parse (buffer);
|
||||
|
||||
if (path == NULL)
|
||||
{
|
||||
g_printerr (_("Failed to parse '%s' as path.\n"), arg);
|
||||
exit (1);
|
||||
}
|
||||
|
||||
g_free (buffer);
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
int
|
||||
get_enum_value (GType type,
|
||||
const char *type_nick,
|
||||
const char *str)
|
||||
{
|
||||
GEnumClass *class = g_type_class_ref (type);
|
||||
GEnumValue *value;
|
||||
int val;
|
||||
|
||||
value = g_enum_get_value_by_nick (class, str);
|
||||
if (value)
|
||||
val = value->value;
|
||||
else
|
||||
{
|
||||
GString *s;
|
||||
|
||||
s = g_string_new ("");
|
||||
g_string_append_printf (s, _("Failed to parse '%s' as %s."), str, type_nick);
|
||||
g_string_append (s, "\n");
|
||||
g_string_append (s, _("Possible values: "));
|
||||
|
||||
for (unsigned int i = 0; i < class->n_values; i++)
|
||||
{
|
||||
if (i > 0)
|
||||
g_string_append (s, ", ");
|
||||
g_string_append (s, class->values[i].value_nick);
|
||||
}
|
||||
g_printerr ("%s\n", s->str);
|
||||
g_string_free (s, TRUE);
|
||||
exit (1);
|
||||
}
|
||||
|
||||
g_type_class_unref (class);
|
||||
|
||||
return val;
|
||||
}
|
||||
|
||||
void
|
||||
get_color (GdkRGBA *rgba,
|
||||
const char *str)
|
||||
{
|
||||
if (!gdk_rgba_parse (rgba, str))
|
||||
{
|
||||
char *msg = g_strdup_printf (_("Could not parse '%s' as color"), str);
|
||||
g_printerr ("%s\n", msg);
|
||||
exit (1);
|
||||
}
|
||||
}
|
||||
@@ -1,139 +0,0 @@
|
||||
/* 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 <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <errno.h>
|
||||
|
||||
#include <glib/gi18n-lib.h>
|
||||
#include <glib/gprintf.h>
|
||||
#include <glib/gstdio.h>
|
||||
#include <gtk/gtk.h>
|
||||
#include "gtk-path-tool.h"
|
||||
|
||||
static void G_GNUC_NORETURN
|
||||
usage (void)
|
||||
{
|
||||
g_print (_("Usage:\n"
|
||||
" gtk4-path-tool [COMMAND] [OPTION…] PATH\n"
|
||||
"\n"
|
||||
"Perform various tasks on paths.\n"
|
||||
"\n"
|
||||
"Commands:\n"
|
||||
" decompose Decompose the path\n"
|
||||
" show Display the path in a window\n"
|
||||
" render Render the path as an image\n"
|
||||
" info Print information about the path\n"
|
||||
"\n"));
|
||||
exit (1);
|
||||
}
|
||||
|
||||
/* A simplified version of g_log_writer_default_would_drop(), to avoid
|
||||
* bumping up the required version of GLib to 2.68
|
||||
*/
|
||||
static gboolean
|
||||
would_drop (GLogLevelFlags level,
|
||||
const char *domain)
|
||||
{
|
||||
#if GLIB_CHECK_VERSION (2, 68, 0)
|
||||
return g_log_writer_default_would_drop (level, domain);
|
||||
#else
|
||||
return (level & (G_LOG_LEVEL_ERROR |
|
||||
G_LOG_LEVEL_CRITICAL |
|
||||
G_LOG_LEVEL_WARNING)) == 0;
|
||||
#endif
|
||||
}
|
||||
|
||||
static GLogWriterOutput
|
||||
log_writer_func (GLogLevelFlags level,
|
||||
const GLogField *fields,
|
||||
gsize n_fields,
|
||||
gpointer user_data)
|
||||
{
|
||||
gsize i;
|
||||
const char *domain = NULL;
|
||||
const char *message = NULL;
|
||||
|
||||
for (i = 0; i < n_fields; i++)
|
||||
{
|
||||
if (g_strcmp0 (fields[i].key, "GLIB_DOMAIN") == 0)
|
||||
domain = fields[i].value;
|
||||
else if (g_strcmp0 (fields[i].key, "MESSAGE") == 0)
|
||||
message = fields[i].value;
|
||||
}
|
||||
|
||||
if (message != NULL && !would_drop (level, domain))
|
||||
{
|
||||
const char *prefix;
|
||||
switch (level & G_LOG_LEVEL_MASK)
|
||||
{
|
||||
case G_LOG_LEVEL_ERROR:
|
||||
prefix = "ERROR";
|
||||
break;
|
||||
case G_LOG_LEVEL_CRITICAL:
|
||||
prefix = "CRITICAL";
|
||||
break;
|
||||
case G_LOG_LEVEL_WARNING:
|
||||
prefix = "WARNING";
|
||||
break;
|
||||
default:
|
||||
prefix = "INFO";
|
||||
break;
|
||||
}
|
||||
g_printerr ("%s-%s: %s\n", domain, prefix, message);
|
||||
}
|
||||
|
||||
return G_LOG_WRITER_HANDLED;
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, const char *argv[])
|
||||
{
|
||||
g_set_prgname ("gtk4-path-tool");
|
||||
|
||||
g_log_set_writer_func (log_writer_func, NULL, NULL);
|
||||
|
||||
gtk_init_check ();
|
||||
|
||||
gtk_test_register_all_types ();
|
||||
|
||||
if (argc < 2)
|
||||
usage ();
|
||||
|
||||
if (strcmp (argv[1], "--help") == 0)
|
||||
usage ();
|
||||
|
||||
argv++;
|
||||
argc--;
|
||||
|
||||
if (strcmp (argv[0], "decompose") == 0)
|
||||
do_decompose (&argc, &argv);
|
||||
else if (strcmp (argv[0], "info") == 0)
|
||||
do_info (&argc, &argv);
|
||||
else if (strcmp (argv[0], "render") == 0)
|
||||
do_render (&argc, &argv);
|
||||
else if (strcmp (argv[0], "show") == 0)
|
||||
do_show (&argc, &argv);
|
||||
else
|
||||
usage ();
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -1,13 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
void do_info (int *argc, const char ***argv);
|
||||
void do_decompose (int *argc, const char ***argv);
|
||||
void do_render (int *argc, const char ***argv);
|
||||
void do_show (int *argc, const char ***argv);
|
||||
|
||||
GskPath *get_path (const char *arg);
|
||||
int get_enum_value (GType type,
|
||||
const char *type_nick,
|
||||
const char *str);
|
||||
void get_color (GdkRGBA *rgba,
|
||||
const char *str);
|
||||
@@ -23,13 +23,6 @@ if win32_enabled
|
||||
endif
|
||||
|
||||
gtk_tools = [
|
||||
['gtk4-path-tool', ['gtk-path-tool.c',
|
||||
'gtk-path-tool-decompose.c',
|
||||
'gtk-path-tool-info.c',
|
||||
'gtk-path-tool-render.c',
|
||||
'gtk-path-tool-show.c',
|
||||
'gtk-path-tool-utils.c',
|
||||
'path-view.c'], [libgtk_dep]],
|
||||
['gtk4-query-settings', ['gtk-query-settings.c'], [libgtk_dep]],
|
||||
['gtk4-builder-tool', ['gtk-builder-tool.c',
|
||||
'gtk-builder-tool-simplify.c',
|
||||
|
||||
@@ -1,271 +0,0 @@
|
||||
/* 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 "path-view.h"
|
||||
|
||||
struct _PathView
|
||||
{
|
||||
GtkWidget parent_instance;
|
||||
|
||||
GskPath *path;
|
||||
GskStroke *stroke;
|
||||
graphene_rect_t bounds;
|
||||
GskFillRule fill_rule;
|
||||
GdkRGBA fg;
|
||||
GdkRGBA bg;
|
||||
int padding;
|
||||
gboolean do_fill;
|
||||
};
|
||||
|
||||
enum {
|
||||
PROP_PATH = 1,
|
||||
PROP_DO_FILL,
|
||||
PROP_STROKE,
|
||||
PROP_FILL_RULE,
|
||||
PROP_FG_COLOR,
|
||||
PROP_BG_COLOR,
|
||||
N_PROPERTIES
|
||||
};
|
||||
|
||||
static GParamSpec *properties[N_PROPERTIES] = { NULL, };
|
||||
|
||||
struct _PathViewClass
|
||||
{
|
||||
GtkWidgetClass parent_class;
|
||||
};
|
||||
|
||||
G_DEFINE_TYPE (PathView, path_view, GTK_TYPE_WIDGET)
|
||||
|
||||
static void
|
||||
path_view_init (PathView *self)
|
||||
{
|
||||
self->do_fill = TRUE;
|
||||
self->stroke = gsk_stroke_new (1);
|
||||
self->fill_rule = GSK_FILL_RULE_WINDING;
|
||||
self->fg = (GdkRGBA) { 0, 0, 0, 1};
|
||||
self->bg = (GdkRGBA) { 1, 1, 1, 1};
|
||||
self->padding = 10;
|
||||
}
|
||||
|
||||
static void
|
||||
path_view_dispose (GObject *object)
|
||||
{
|
||||
PathView *self = PATH_VIEW (object);
|
||||
|
||||
g_clear_pointer (&self->path, gsk_path_unref);
|
||||
g_clear_pointer (&self->stroke, gsk_stroke_free);
|
||||
|
||||
G_OBJECT_CLASS (path_view_parent_class)->dispose (object);
|
||||
}
|
||||
|
||||
static void
|
||||
path_view_get_property (GObject *object,
|
||||
guint prop_id,
|
||||
GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
PathView *self = PATH_VIEW (object);
|
||||
|
||||
switch (prop_id)
|
||||
{
|
||||
case PROP_PATH:
|
||||
g_value_set_boxed (value, self->path);
|
||||
break;
|
||||
|
||||
case PROP_DO_FILL:
|
||||
g_value_set_boolean (value, self->do_fill);
|
||||
break;
|
||||
|
||||
case PROP_STROKE:
|
||||
g_value_set_boxed (value, self->stroke);
|
||||
break;
|
||||
|
||||
case PROP_FILL_RULE:
|
||||
g_value_set_enum (value, self->fill_rule);
|
||||
break;
|
||||
|
||||
case PROP_FG_COLOR:
|
||||
g_value_set_boxed (value, &self->fg);
|
||||
break;
|
||||
|
||||
case PROP_BG_COLOR:
|
||||
g_value_set_boxed (value, &self->bg);
|
||||
break;
|
||||
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
update_bounds (PathView *self)
|
||||
{
|
||||
if (self->do_fill)
|
||||
gsk_path_get_bounds (self->path, &self->bounds);
|
||||
else
|
||||
gsk_path_get_stroke_bounds (self->path, self->stroke, &self->bounds);
|
||||
}
|
||||
|
||||
static void
|
||||
path_view_set_property (GObject *object,
|
||||
guint prop_id,
|
||||
const GValue *value,
|
||||
GParamSpec *pspec)
|
||||
{
|
||||
PathView *self = PATH_VIEW (object);
|
||||
|
||||
switch (prop_id)
|
||||
{
|
||||
|
||||
case PROP_PATH:
|
||||
g_clear_pointer (&self->path, gsk_path_unref);
|
||||
self->path = g_value_dup_boxed (value);
|
||||
update_bounds (self);
|
||||
gtk_widget_queue_resize (GTK_WIDGET (self));
|
||||
break;
|
||||
|
||||
case PROP_DO_FILL:
|
||||
self->do_fill = g_value_get_boolean (value);
|
||||
update_bounds (self);
|
||||
gtk_widget_queue_resize (GTK_WIDGET (self));
|
||||
break;
|
||||
|
||||
case PROP_STROKE:
|
||||
gsk_stroke_free (self->stroke);
|
||||
self->stroke = g_value_get_boxed (value);
|
||||
update_bounds (self);
|
||||
gtk_widget_queue_resize (GTK_WIDGET (self));
|
||||
break;
|
||||
|
||||
case PROP_FILL_RULE:
|
||||
self->fill_rule = g_value_get_enum (value);
|
||||
gtk_widget_queue_draw (GTK_WIDGET (self));
|
||||
break;
|
||||
|
||||
case PROP_FG_COLOR:
|
||||
self->fg = *(GdkRGBA *) g_value_get_boxed (value);
|
||||
gtk_widget_queue_draw (GTK_WIDGET (self));
|
||||
break;
|
||||
|
||||
case PROP_BG_COLOR:
|
||||
self->bg = *(GdkRGBA *) g_value_get_boxed (value);
|
||||
gtk_widget_queue_draw (GTK_WIDGET (self));
|
||||
break;
|
||||
|
||||
default:
|
||||
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
path_view_measure (GtkWidget *widget,
|
||||
GtkOrientation orientation,
|
||||
int for_size,
|
||||
int *minimum,
|
||||
int *natural,
|
||||
int *minimum_baseline,
|
||||
int *natural_baseline)
|
||||
{
|
||||
PathView *self = PATH_VIEW (widget);
|
||||
|
||||
if (orientation == GTK_ORIENTATION_HORIZONTAL)
|
||||
*minimum = *natural = (int) ceilf (self->bounds.size.width) + 2 * self->padding;
|
||||
else
|
||||
*minimum = *natural = (int) ceilf (self->bounds.size.height) + 2 * self->padding;
|
||||
}
|
||||
|
||||
static void
|
||||
path_view_snapshot (GtkWidget *widget,
|
||||
GtkSnapshot *snapshot)
|
||||
{
|
||||
PathView *self = PATH_VIEW (widget);
|
||||
graphene_rect_t bounds = self->bounds;
|
||||
|
||||
graphene_rect_inset (&bounds, - self->padding, - self->padding);
|
||||
|
||||
gtk_snapshot_save (snapshot);
|
||||
gtk_snapshot_append_color (snapshot, &self->bg, &self->bounds);
|
||||
gtk_snapshot_translate (snapshot, &GRAPHENE_POINT_INIT (self->padding, self->padding));
|
||||
if (self->do_fill)
|
||||
gtk_snapshot_push_fill (snapshot, self->path, self->fill_rule);
|
||||
else
|
||||
gtk_snapshot_push_stroke (snapshot, self->path, self->stroke);
|
||||
gtk_snapshot_append_color (snapshot, &self->fg, &self->bounds);
|
||||
gtk_snapshot_pop (snapshot);
|
||||
gtk_snapshot_restore (snapshot);
|
||||
}
|
||||
|
||||
static void
|
||||
path_view_class_init (PathViewClass *class)
|
||||
{
|
||||
GObjectClass *object_class = G_OBJECT_CLASS (class);
|
||||
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (class);
|
||||
|
||||
object_class->dispose = path_view_dispose;
|
||||
object_class->get_property = path_view_get_property;
|
||||
object_class->set_property = path_view_set_property;
|
||||
|
||||
widget_class->measure = path_view_measure;
|
||||
widget_class->snapshot = path_view_snapshot;
|
||||
|
||||
properties[PROP_PATH]
|
||||
= g_param_spec_boxed ("path", NULL, NULL,
|
||||
GSK_TYPE_PATH,
|
||||
G_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY);
|
||||
|
||||
properties[PROP_DO_FILL]
|
||||
= g_param_spec_boolean ("do-fill", NULL, NULL,
|
||||
TRUE,
|
||||
G_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY);
|
||||
|
||||
properties[PROP_STROKE]
|
||||
= g_param_spec_boxed ("stroke", NULL, NULL,
|
||||
GSK_TYPE_STROKE,
|
||||
G_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY);
|
||||
|
||||
properties[PROP_FILL_RULE]
|
||||
= g_param_spec_enum ("fill-rule", NULL, NULL,
|
||||
GSK_TYPE_FILL_RULE,
|
||||
GSK_FILL_RULE_WINDING,
|
||||
G_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY);
|
||||
|
||||
properties[PROP_FG_COLOR]
|
||||
= g_param_spec_boxed ("fg-color", NULL, NULL,
|
||||
GDK_TYPE_RGBA,
|
||||
G_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY);
|
||||
|
||||
properties[PROP_BG_COLOR]
|
||||
= g_param_spec_boxed ("bg-color", NULL, NULL,
|
||||
GDK_TYPE_RGBA,
|
||||
G_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY);
|
||||
|
||||
g_object_class_install_properties (object_class, N_PROPERTIES, properties);
|
||||
}
|
||||
|
||||
GtkWidget *
|
||||
path_view_new (GskPath *path)
|
||||
{
|
||||
return g_object_new (PATH_TYPE_VIEW,
|
||||
"path", path,
|
||||
NULL);
|
||||
}
|
||||
@@ -1,9 +0,0 @@
|
||||
#pragma once
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
#define PATH_TYPE_VIEW (path_view_get_type ())
|
||||
|
||||
G_DECLARE_FINAL_TYPE (PathView, path_view, PATH, VIEW, GtkWidget)
|
||||
|
||||
GtkWidget * path_view_new (GskPath *path);
|
||||