Compare commits
55 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 244cdafe1b | |||
| a0d17418de | |||
| 093e6241e7 | |||
| 67b504f823 | |||
| 659bc813a4 | |||
| 293c0774b3 | |||
| 988062889b | |||
| 461922b495 | |||
| 7150a53ccb | |||
| 1e306b148e | |||
| 6af9dc8612 | |||
| 35b313f9b0 | |||
| fe84ce8686 | |||
| 02a4e5a457 | |||
| a548a91e6d | |||
| fc3c2e0942 | |||
| 60e07335a1 | |||
| cb6b968fb5 | |||
| 3aa3816125 | |||
| c37c29422a | |||
| db71c07f8f | |||
| bf1b97efd3 | |||
| 4d7277f72c | |||
| 3296f01edf | |||
| dbcbf0523b | |||
| 888abb6f24 | |||
| 9b916b329a | |||
| eb3ada6386 | |||
| 2a725b658b | |||
| 97f605f811 | |||
| 4e7d578881 | |||
| 438d936f57 | |||
| fc4a464b47 | |||
| 785b9541f6 | |||
| a4cbabb80f | |||
| 1b5dfcba7e | |||
| ba41edf531 | |||
| bf3892caed | |||
| 1e6a95aa1b | |||
| 70a9d08e21 | |||
| 7511d4e281 | |||
| 53ea97decb | |||
| 28190ded71 | |||
| 8083cb0e47 | |||
| d241ec4f3e | |||
| 544320a961 | |||
| ee5a95ba24 | |||
| 232260b86b | |||
| 857f50649c | |||
| a39d9d60a7 | |||
| 5f9bc97291 | |||
| 01b3b096fe | |||
| a483fb2d96 | |||
| d27e7e0180 | |||
| aa888c0b3f |
@@ -6,7 +6,7 @@ call "C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\VC\Auxiliar
|
||||
|
||||
:: FIXME: make warnings fatal
|
||||
pip3 install --upgrade --user meson~=0.64 || goto :error
|
||||
meson setup -Dbackend_max_links=1 -Ddebug=false -Dmedia-gstreamer=disabled _build || goto :error
|
||||
meson -Ddebug=false -Dmedia-gstreamer=disabled _build || goto :error
|
||||
ninja -C _build || goto :error
|
||||
|
||||
goto :EOF
|
||||
|
||||
@@ -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!
|
||||
@@ -1,45 +1,6 @@
|
||||
Overview of Changes in 4.12.1, 25-08-2023
|
||||
Overview of Changes in 4.13.0, xx-xx-xxxx
|
||||
=========================================
|
||||
|
||||
* GtkGridView:
|
||||
- Fix a crash when scrolling
|
||||
|
||||
* GtkColumnView:
|
||||
- Fix a refcounting issue in the new scroll_to api
|
||||
|
||||
* GtkTreeView
|
||||
- Fix style classes for sort arrows
|
||||
|
||||
* GtkEntry:
|
||||
- Improve tracking of user changes (for undo)
|
||||
|
||||
* GtkNotebook:
|
||||
- Fix a critical when switching pages
|
||||
|
||||
* GtkColor/FontDialogButton:
|
||||
- Make these widgets activatable
|
||||
|
||||
* GtkMenuButton:
|
||||
- Fix problems with focus handling
|
||||
- Fix problems with DND
|
||||
|
||||
* Printing
|
||||
- Fix the cpdb backend build
|
||||
|
||||
* MacOS:
|
||||
- Make file filters work again
|
||||
|
||||
* GSK:
|
||||
- Fix issues with color matrix nodes
|
||||
|
||||
* Wayland:
|
||||
- Fix a crash with compositors other than gnome-shell
|
||||
|
||||
* Translation updates:
|
||||
Polish
|
||||
Swedish
|
||||
|
||||
|
||||
Overview of Changes in 4.12.0, 05-08-2023
|
||||
=========================================
|
||||
|
||||
|
||||
@@ -335,6 +335,8 @@
|
||||
<file>paintable_symbolic.c</file>
|
||||
<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>
|
||||
@@ -420,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>
|
||||
|
||||
@@ -72,6 +72,8 @@ demos = files([
|
||||
'paintable_symbolic.c',
|
||||
'panes.c',
|
||||
'password_entry.c',
|
||||
'path_fill.c',
|
||||
'path_text.c',
|
||||
'peg_solitaire.c',
|
||||
'pickers.c',
|
||||
'printing.c',
|
||||
|
||||
@@ -0,0 +1,198 @@
|
||||
/* Path/Fill and Stroke
|
||||
*
|
||||
* This demo shows how to use GskPath to draw shapes that are (a bit)
|
||||
* more complex than a rounded rectangle.
|
||||
*/
|
||||
|
||||
#include <glib/gi18n.h>
|
||||
#include <gtk/gtk.h>
|
||||
|
||||
#include "paintable.h"
|
||||
|
||||
#define GTK_TYPE_LOGO_PAINTABLE (gtk_logo_paintable_get_type ())
|
||||
G_DECLARE_FINAL_TYPE (GtkLogoPaintable, gtk_logo_paintable, GTK, LOGO_PAINTABLE, GObject)
|
||||
|
||||
struct _GtkLogoPaintable
|
||||
{
|
||||
GObject parent_instance;
|
||||
|
||||
int width;
|
||||
int height;
|
||||
GskPath *path[3];
|
||||
GdkRGBA color[3];
|
||||
|
||||
GskPath *stroke_path;
|
||||
GskStroke *stroke1;
|
||||
GskStroke *stroke2;
|
||||
GdkRGBA stroke_color;
|
||||
};
|
||||
|
||||
struct _GtkLogoPaintableClass
|
||||
{
|
||||
GObjectClass parent_class;
|
||||
};
|
||||
|
||||
static int
|
||||
gtk_logo_paintable_get_intrinsic_width (GdkPaintable *paintable)
|
||||
{
|
||||
GtkLogoPaintable *self = GTK_LOGO_PAINTABLE (paintable);
|
||||
|
||||
return self->width;
|
||||
}
|
||||
|
||||
static int
|
||||
gtk_logo_paintable_get_intrinsic_height (GdkPaintable *paintable)
|
||||
{
|
||||
GtkLogoPaintable *self = GTK_LOGO_PAINTABLE (paintable);
|
||||
|
||||
return self->height;
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_logo_paintable_snapshot (GdkPaintable *paintable,
|
||||
GdkSnapshot *snapshot,
|
||||
double width,
|
||||
double height)
|
||||
{
|
||||
GtkLogoPaintable *self = GTK_LOGO_PAINTABLE (paintable);
|
||||
|
||||
for (unsigned int i = 0; i < 3; i++)
|
||||
{
|
||||
gtk_snapshot_push_fill (snapshot, self->path[i], GSK_FILL_RULE_WINDING);
|
||||
gtk_snapshot_append_color (snapshot,
|
||||
&self->color[i],
|
||||
&GRAPHENE_RECT_INIT (0, 0, width, height));
|
||||
gtk_snapshot_pop (snapshot);
|
||||
}
|
||||
for (unsigned int i = 0; i < 3; i++)
|
||||
{
|
||||
gtk_snapshot_push_stroke (snapshot, self->stroke_path, self->stroke1);
|
||||
gtk_snapshot_append_color (snapshot,
|
||||
&self->stroke_color,
|
||||
&GRAPHENE_RECT_INIT (0, 0, width, height));
|
||||
gtk_snapshot_pop (snapshot);
|
||||
}
|
||||
|
||||
gtk_snapshot_push_stroke (snapshot, self->stroke_path, self->stroke2);
|
||||
gtk_snapshot_append_color (snapshot,
|
||||
&self->stroke_color,
|
||||
&GRAPHENE_RECT_INIT (0, 0, width, height));
|
||||
gtk_snapshot_pop (snapshot);
|
||||
}
|
||||
|
||||
static GdkPaintableFlags
|
||||
gtk_logo_paintable_get_flags (GdkPaintable *paintable)
|
||||
{
|
||||
return GDK_PAINTABLE_STATIC_CONTENTS | GDK_PAINTABLE_STATIC_SIZE;
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_logo_paintable_paintable_init (GdkPaintableInterface *iface)
|
||||
{
|
||||
iface->get_intrinsic_width = gtk_logo_paintable_get_intrinsic_width;
|
||||
iface->get_intrinsic_height = gtk_logo_paintable_get_intrinsic_height;
|
||||
iface->snapshot = gtk_logo_paintable_snapshot;
|
||||
iface->get_flags = gtk_logo_paintable_get_flags;
|
||||
}
|
||||
|
||||
/* When defining the GType, we need to implement the GdkPaintable interface */
|
||||
G_DEFINE_TYPE_WITH_CODE (GtkLogoPaintable, gtk_logo_paintable, G_TYPE_OBJECT,
|
||||
G_IMPLEMENT_INTERFACE (GDK_TYPE_PAINTABLE,
|
||||
gtk_logo_paintable_paintable_init))
|
||||
|
||||
static void
|
||||
gtk_logo_paintable_dispose (GObject *object)
|
||||
{
|
||||
GtkLogoPaintable *self = GTK_LOGO_PAINTABLE (object);
|
||||
|
||||
for (unsigned int i = 0; i < 3; i++)
|
||||
gsk_path_unref (self->path[i]);
|
||||
|
||||
gsk_path_unref (self->stroke_path);
|
||||
|
||||
gsk_stroke_free (self->stroke1);
|
||||
gsk_stroke_free (self->stroke2);
|
||||
|
||||
G_OBJECT_CLASS (gtk_logo_paintable_parent_class)->dispose (object);
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_logo_paintable_class_init (GtkLogoPaintableClass *klass)
|
||||
{
|
||||
GObjectClass *object_class = G_OBJECT_CLASS (klass);
|
||||
|
||||
object_class->dispose = gtk_logo_paintable_dispose;
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_logo_paintable_init (GtkLogoPaintable *self)
|
||||
{
|
||||
}
|
||||
|
||||
static GdkPaintable *
|
||||
gtk_logo_paintable_new (void)
|
||||
{
|
||||
GtkLogoPaintable *self;
|
||||
graphene_rect_t bounds, bounds2;
|
||||
|
||||
self = g_object_new (GTK_TYPE_LOGO_PAINTABLE, NULL);
|
||||
|
||||
/* Paths and colors extracted from gtk-logo.svg */
|
||||
self->path[0] = gsk_path_parse ("m3.12,66.17 -2.06,-51.46 32.93,24.7 v55.58 l-30.87,-28.82 z");
|
||||
self->path[1] = gsk_path_parse ("m34,95 49.4,-20.58 4.12,-51.46 -53.52,16.47 v55.58 z");
|
||||
self->path[2] = gsk_path_parse ("m1.06,14.71 32.93,24.7 53.52,-16.47 -36.75,-21.88 -49.7,13.65 z");
|
||||
|
||||
gdk_rgba_parse (&self->color[0], "#e40000");
|
||||
gdk_rgba_parse (&self->color[1], "#7fe719");
|
||||
gdk_rgba_parse (&self->color[2], "#729fcf");
|
||||
|
||||
self->stroke_path = gsk_path_parse ("m50.6,51.3 -47.3,14 z l33,23 z v-50");
|
||||
self->stroke1 = gsk_stroke_new (2.12);
|
||||
self->stroke2 = gsk_stroke_new (1.25);
|
||||
gdk_rgba_parse (&self->stroke_color, "#ffffff");
|
||||
|
||||
gsk_path_get_stroke_bounds (self->path[0], self->stroke1, &bounds);
|
||||
gsk_path_get_stroke_bounds (self->path[1], self->stroke1, &bounds2);
|
||||
graphene_rect_union (&bounds, &bounds2, &bounds);
|
||||
gsk_path_get_stroke_bounds (self->path[2], self->stroke1, &bounds2);
|
||||
graphene_rect_union (&bounds, &bounds2, &bounds);
|
||||
gsk_path_get_stroke_bounds (self->stroke_path, self->stroke2, &bounds2);
|
||||
graphene_rect_union (&bounds, &bounds2, &bounds);
|
||||
|
||||
self->width = bounds.origin.x + bounds.size.width;
|
||||
self->height = bounds.origin.y + bounds.size.height;
|
||||
|
||||
return GDK_PAINTABLE (self);
|
||||
}
|
||||
|
||||
GtkWidget *
|
||||
do_path_fill (GtkWidget *do_widget)
|
||||
{
|
||||
static GtkWidget *window = NULL;
|
||||
|
||||
if (!window)
|
||||
{
|
||||
GtkWidget *picture;
|
||||
GdkPaintable *paintable;
|
||||
|
||||
window = gtk_window_new ();
|
||||
gtk_window_set_resizable (GTK_WINDOW (window), TRUE);
|
||||
gtk_window_set_title (GTK_WINDOW (window), "Path Fill");
|
||||
g_object_add_weak_pointer (G_OBJECT (window), (gpointer *)&window);
|
||||
|
||||
paintable = gtk_logo_paintable_new ();
|
||||
picture = gtk_picture_new_for_paintable (paintable);
|
||||
gtk_picture_set_content_fit (GTK_PICTURE (picture), GTK_CONTENT_FIT_CONTAIN);
|
||||
gtk_picture_set_can_shrink (GTK_PICTURE (picture), FALSE);
|
||||
g_object_unref (paintable);
|
||||
|
||||
gtk_window_set_child (GTK_WINDOW (window), picture);
|
||||
}
|
||||
|
||||
if (!gtk_widget_get_visible (window))
|
||||
gtk_window_present (GTK_WINDOW (window));
|
||||
else
|
||||
gtk_window_destroy (GTK_WINDOW (window));
|
||||
|
||||
return window;
|
||||
}
|
||||
@@ -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;
|
||||
}
|
||||
@@ -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>
|
||||
+1
-2
@@ -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
|
||||
|
||||
+2
-2
@@ -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,
|
||||
|
||||
+2
-16
@@ -25,12 +25,10 @@
|
||||
#include "gdkprivate.h"
|
||||
|
||||
/* HACK: So we don't need to include any (not-yet-created) GSK or GTK headers */
|
||||
GdkSnapshot * gtk_snapshot_new (void);
|
||||
void gtk_snapshot_push_debug (GdkSnapshot *snapshot,
|
||||
const char *message,
|
||||
...) G_GNUC_PRINTF (2, 3);
|
||||
void gtk_snapshot_pop (GdkSnapshot *snapshot);
|
||||
GdkPaintable * gtk_snapshot_free_to_paintable (GdkSnapshot *snapshot);
|
||||
|
||||
/**
|
||||
* GdkPaintable:
|
||||
@@ -104,21 +102,9 @@ gdk_paintable_default_snapshot (GdkPaintable *paintable,
|
||||
static GdkPaintable *
|
||||
gdk_paintable_default_get_current_image (GdkPaintable *paintable)
|
||||
{
|
||||
int width, height;
|
||||
GdkSnapshot *snapshot;
|
||||
g_warning ("FIXME: implement by snapshotting at default size and returning a GskRendererNodePaintable");
|
||||
|
||||
/* No need to check whether the paintable is static, as
|
||||
* gdk_paintable_get_current_image () takes care of that already. */
|
||||
|
||||
width = gdk_paintable_get_intrinsic_width (paintable);
|
||||
height = gdk_paintable_get_intrinsic_height (paintable);
|
||||
|
||||
if (width <= 0 || height <= 0)
|
||||
return gdk_paintable_new_empty (width, height);
|
||||
|
||||
snapshot = gtk_snapshot_new ();
|
||||
gdk_paintable_snapshot (paintable, snapshot, width, height);
|
||||
return gtk_snapshot_free_to_paintable (snapshot);
|
||||
return paintable;
|
||||
}
|
||||
|
||||
static GdkPaintableFlags
|
||||
|
||||
@@ -27,9 +27,7 @@
|
||||
#include "gdkmacosdisplay.h"
|
||||
#include "gdkmacossurface.h"
|
||||
|
||||
#import <OpenGL/OpenGL.h>
|
||||
#import <OpenGL/gl3.h>
|
||||
#import <AppKit/AppKit.h>
|
||||
#import <epoxy/gl.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
|
||||
@@ -21,7 +21,6 @@
|
||||
|
||||
#include "gdkconfig.h"
|
||||
|
||||
#include <OpenGL/gl3.h>
|
||||
#include <OpenGL/CGLIOSurface.h>
|
||||
#include <QuartzCore/QuartzCore.h>
|
||||
|
||||
@@ -499,7 +498,7 @@ gdk_macos_gl_context_begin_frame (GdkDrawContext *context,
|
||||
gdk_gl_context_make_current (GDK_GL_CONTEXT (self));
|
||||
gdk_macos_gl_context_allocate (self);
|
||||
|
||||
GDK_DRAW_CONTEXT_CLASS (gdk_macos_gl_context_parent_class)->begin_frame (context, prefers_high_depth, region);
|
||||
GDK_DRAW_CONTEXT_CLASS (gdk_macos_gl_context_parent_class)->begin_frame (context, depth, region);
|
||||
|
||||
gdk_gl_context_make_current (GDK_GL_CONTEXT (self));
|
||||
CHECK_GL (NULL, glBindFramebuffer (GL_FRAMEBUFFER, self->fbo));
|
||||
|
||||
@@ -93,8 +93,7 @@ gdk_wayland_app_launch_context_get_startup_notify_id (GAppLaunchContext *context
|
||||
id = app_launch_data.token;
|
||||
wl_event_queue_destroy (event_queue);
|
||||
}
|
||||
else if (display->gtk_shell &&
|
||||
gtk_shell1_get_version (display->gtk_shell) >= GTK_SHELL1_NOTIFY_LAUNCH_SINCE_VERSION)
|
||||
else if (gtk_shell1_get_version (display->gtk_shell) >= GTK_SHELL1_NOTIFY_LAUNCH_SINCE_VERSION)
|
||||
{
|
||||
id = g_uuid_string_random ();
|
||||
gtk_shell1_notify_launch (display->gtk_shell, id);
|
||||
|
||||
@@ -127,6 +127,3 @@ libgdk_wayland = static_library('gdk-wayland',
|
||||
link_with: [ libwayland_cursor, ],
|
||||
dependencies: [ gdk_deps, gdk_wayland_deps ],
|
||||
)
|
||||
|
||||
# Used to generate pkg-config Requires
|
||||
wayland_public_deps = [wlclientdep]
|
||||
|
||||
@@ -201,7 +201,7 @@ gdk_x11_clipboard_formats_to_targets (GdkContentFormats *formats)
|
||||
continue;
|
||||
|
||||
if (g_str_equal (mime_types[i], special_targets[j].mime_type))
|
||||
targets = g_slist_prepend (targets, (gpointer) g_intern_static_string (special_targets[j].x_target));
|
||||
targets = g_slist_prepend (targets, (gpointer) g_intern_string (special_targets[j].x_target));
|
||||
}
|
||||
targets = g_slist_prepend (targets, (gpointer) mime_types[i]);
|
||||
}
|
||||
@@ -238,8 +238,6 @@ gdk_x11_clipboard_formats_to_atoms (GdkDisplay *display,
|
||||
for (l = targets; l; l = l->next)
|
||||
atoms[i++] = gdk_x11_get_xatom_by_name_for_display (display, l->data);
|
||||
|
||||
g_slist_free (targets);
|
||||
|
||||
return atoms;
|
||||
}
|
||||
|
||||
|
||||
@@ -86,5 +86,3 @@ libgdk_x11 = static_library('gdk-x11',
|
||||
] + common_cflags,
|
||||
dependencies: [ gdk_deps, gdk_x11_deps, ],
|
||||
)
|
||||
|
||||
x11_public_deps = [x11_dep]
|
||||
|
||||
@@ -271,6 +271,8 @@ collect_reused_child_nodes (GskRenderer *renderer,
|
||||
case GSK_CROSS_FADE_NODE:
|
||||
case GSK_BLUR_NODE:
|
||||
case GSK_MASK_NODE:
|
||||
case GSK_FILL_NODE:
|
||||
case GSK_STROKE_NODE:
|
||||
|
||||
default:
|
||||
|
||||
@@ -859,6 +861,8 @@ gsk_broadway_renderer_add_node (GskRenderer *renderer,
|
||||
case GSK_CROSS_FADE_NODE:
|
||||
case GSK_BLUR_NODE:
|
||||
case GSK_GL_SHADER_NODE:
|
||||
case GSK_FILL_NODE:
|
||||
case GSK_STROKE_NODE:
|
||||
default:
|
||||
break; /* Fallback */
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
|
||||
+15
-3
@@ -255,6 +255,8 @@ node_supports_2d_transform (const GskRenderNode *node)
|
||||
case GSK_BLEND_NODE:
|
||||
case GSK_BLUR_NODE:
|
||||
case GSK_MASK_NODE:
|
||||
case GSK_FILL_NODE:
|
||||
case GSK_STROKE_NODE:
|
||||
return TRUE;
|
||||
|
||||
case GSK_SHADOW_NODE:
|
||||
@@ -309,6 +311,8 @@ node_supports_transform (const GskRenderNode *node)
|
||||
case GSK_BLEND_NODE:
|
||||
case GSK_BLUR_NODE:
|
||||
case GSK_MASK_NODE:
|
||||
case GSK_FILL_NODE:
|
||||
case GSK_STROKE_NODE:
|
||||
return TRUE;
|
||||
|
||||
case GSK_SHADOW_NODE:
|
||||
@@ -1241,9 +1245,9 @@ gsk_gl_render_job_visit_as_fallback (GskGLRenderJob *job,
|
||||
done:
|
||||
if (scale_x < 0 || scale_y < 0)
|
||||
{
|
||||
GskTransform *transform = gsk_transform_translate (NULL,
|
||||
&GRAPHENE_POINT_INIT (scale_x < 0 ? - surface_width : 0,
|
||||
scale_y < 0 ? - surface_height : 0));
|
||||
GskTransform *transform = gsk_transform_translate (gsk_transform_scale (NULL, scale_x < 0 ? -1 : 1, scale_y < 0 ? -1 : 1),
|
||||
&GRAPHENE_POINT_INIT (scale_x < 0 ? - (node->bounds.size.width + 2 * node->bounds.origin.x) : 0,
|
||||
scale_y < 0 ? - (node->bounds.size.height + 2 * node->bounds.origin.y) : 0));
|
||||
gsk_gl_render_job_push_modelview (job, transform);
|
||||
gsk_transform_unref (transform);
|
||||
}
|
||||
@@ -4089,6 +4093,14 @@ gsk_gl_render_job_visit_node (GskGLRenderJob *job,
|
||||
gsk_gl_render_job_visit_as_fallback (job, node);
|
||||
break;
|
||||
|
||||
case GSK_FILL_NODE:
|
||||
gsk_gl_render_job_visit_as_fallback (job, node);
|
||||
break;
|
||||
|
||||
case GSK_STROKE_NODE:
|
||||
gsk_gl_render_job_visit_as_fallback (job, node);
|
||||
break;
|
||||
|
||||
case GSK_NOT_A_RENDER_NODE:
|
||||
default:
|
||||
g_assert_not_reached ();
|
||||
|
||||
@@ -20,9 +20,14 @@
|
||||
#define __GSK_H_INSIDE__
|
||||
|
||||
#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>
|
||||
#include <gsk/gskroundedrect.h>
|
||||
#include <gsk/gskstroke.h>
|
||||
#include <gsk/gsktransform.h>
|
||||
#include <gsk/gskglshader.h>
|
||||
|
||||
|
||||
@@ -0,0 +1,115 @@
|
||||
#pragma once
|
||||
|
||||
#include <gsk/gsktypes.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
typedef struct _GskBoundingBox GskBoundingBox;
|
||||
|
||||
struct _GskBoundingBox {
|
||||
graphene_point_t min;
|
||||
graphene_point_t max;
|
||||
};
|
||||
|
||||
static inline GskBoundingBox *
|
||||
gsk_bounding_box_init (GskBoundingBox *self,
|
||||
const graphene_point_t *a,
|
||||
const graphene_point_t *b)
|
||||
{
|
||||
self->min.x = MIN (a->x, b->x);
|
||||
self->min.y = MIN (a->y, b->y);
|
||||
self->max.x = MAX (a->x, b->x);
|
||||
self->max.y = MAX (a->y, b->y);
|
||||
return self;
|
||||
}
|
||||
|
||||
static inline GskBoundingBox *
|
||||
gsk_bounding_box_init_copy (GskBoundingBox *self,
|
||||
const GskBoundingBox *src)
|
||||
{
|
||||
self->min = src->min;
|
||||
self->max = src->max;
|
||||
return self;
|
||||
}
|
||||
|
||||
static inline GskBoundingBox *
|
||||
gsk_bounding_box_init_from_rect (GskBoundingBox *self,
|
||||
const graphene_rect_t *bounds)
|
||||
{
|
||||
self->min = bounds->origin;
|
||||
self->max.x = bounds->origin.x + bounds->size.width;
|
||||
self->max.y = bounds->origin.y + bounds->size.height;
|
||||
return self;
|
||||
}
|
||||
|
||||
static inline void
|
||||
gsk_bounding_box_expand (GskBoundingBox *self,
|
||||
const graphene_point_t *p)
|
||||
{
|
||||
self->min.x = MIN (self->min.x, p->x);
|
||||
self->min.y = MIN (self->min.y, p->y);
|
||||
self->max.x = MAX (self->max.x, p->x);
|
||||
self->max.y = MAX (self->max.y, p->y);
|
||||
}
|
||||
|
||||
static inline graphene_rect_t *
|
||||
gsk_bounding_box_to_rect (const GskBoundingBox *self,
|
||||
graphene_rect_t *rect)
|
||||
{
|
||||
rect->origin = self->min;
|
||||
rect->size.width = self->max.x - self->min.x;
|
||||
rect->size.height = self->max.y - self->min.y;
|
||||
return rect;
|
||||
}
|
||||
|
||||
static inline gboolean
|
||||
gsk_bounding_box_contains_point (const GskBoundingBox *self,
|
||||
const graphene_point_t *p)
|
||||
{
|
||||
return self->min.x <= p->x && p->x <= self->max.x &&
|
||||
self->min.y <= p->y && p->y <= self->max.y;
|
||||
}
|
||||
|
||||
static inline gboolean
|
||||
gsk_bounding_box_contains_point_with_epsilon (const GskBoundingBox *self,
|
||||
const graphene_point_t *p,
|
||||
float epsilon)
|
||||
{
|
||||
return self->min.x - epsilon <= p->x && p->x <= self->max.x + epsilon &&
|
||||
self->min.y - epsilon <= p->y && p->y <= self->max.y + epsilon;
|
||||
}
|
||||
|
||||
static inline gboolean
|
||||
gsk_bounding_box_intersection (const GskBoundingBox *a,
|
||||
const GskBoundingBox *b,
|
||||
GskBoundingBox *res)
|
||||
{
|
||||
graphene_point_t min, max;
|
||||
|
||||
min.x = MAX (a->min.x, b->min.x);
|
||||
min.y = MAX (a->min.y, b->min.y);
|
||||
max.x = MIN (a->max.x, b->max.x);
|
||||
max.y = MIN (a->max.y, b->max.y);
|
||||
|
||||
if (res)
|
||||
gsk_bounding_box_init (res, &min, &max);
|
||||
|
||||
return min.x <= max.x && min.y <= max.y;
|
||||
}
|
||||
|
||||
static inline void
|
||||
gsk_bounding_box_union (const GskBoundingBox *a,
|
||||
const GskBoundingBox *b,
|
||||
GskBoundingBox *res)
|
||||
{
|
||||
graphene_point_t min, max;
|
||||
|
||||
min.x = MIN (a->min.x, b->min.x);
|
||||
min.y = MIN (a->min.y, b->min.y);
|
||||
max.x = MAX (a->max.x, b->max.x);
|
||||
max.y = MAX (a->max.y, b->max.y);
|
||||
|
||||
gsk_bounding_box_init (res, &min, &max);
|
||||
}
|
||||
|
||||
G_END_DECLS
|
||||
+1188
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,111 @@
|
||||
/*
|
||||
* 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
|
||||
|
||||
#include "gskpathprivate.h"
|
||||
#include "gskpathpointprivate.h"
|
||||
#include "gskpathopprivate.h"
|
||||
#include "gskboundingboxprivate.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
GskContour * gsk_standard_contour_new (GskPathFlags flags,
|
||||
const graphene_point_t *points,
|
||||
gsize n_points,
|
||||
const gskpathop *ops,
|
||||
gsize n_ops,
|
||||
gssize offset);
|
||||
|
||||
void gsk_contour_copy (GskContour * dest,
|
||||
const GskContour *src);
|
||||
GskContour * gsk_contour_dup (const GskContour *src);
|
||||
GskContour * gsk_contour_reverse (const GskContour *src);
|
||||
|
||||
gsize gsk_contour_get_size (const GskContour *self);
|
||||
GskPathFlags gsk_contour_get_flags (const GskContour *self);
|
||||
void gsk_contour_print (const GskContour *self,
|
||||
GString *string);
|
||||
gboolean gsk_contour_get_bounds (const GskContour *self,
|
||||
GskBoundingBox *bounds);
|
||||
gboolean gsk_contour_get_stroke_bounds (const GskContour *self,
|
||||
const GskStroke *stroke,
|
||||
GskBoundingBox *bounds);
|
||||
gboolean gsk_contour_foreach (const GskContour *self,
|
||||
float tolerance,
|
||||
GskPathForeachFunc func,
|
||||
gpointer user_data);
|
||||
void gsk_contour_get_start_end (const GskContour *self,
|
||||
graphene_point_t *start,
|
||||
graphene_point_t *end);
|
||||
int gsk_contour_get_winding (const GskContour *self,
|
||||
const graphene_point_t *point);
|
||||
|
||||
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,
|
||||
graphene_vec2_t *tangent);
|
||||
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
|
||||
+1533
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,157 @@
|
||||
/*
|
||||
* 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
|
||||
|
||||
#include "gskpathopprivate.h"
|
||||
#include "gskpath.h"
|
||||
#include "gskboundingboxprivate.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
typedef gpointer gskpathop;
|
||||
|
||||
typedef union _GskCurve GskCurve;
|
||||
|
||||
typedef struct _GskLineCurve GskLineCurve;
|
||||
typedef struct _GskQuadCurve GskQuadCurve;
|
||||
typedef struct _GskCubicCurve GskCubicCurve;
|
||||
|
||||
struct _GskLineCurve
|
||||
{
|
||||
GskPathOperation op;
|
||||
|
||||
gboolean padding;
|
||||
|
||||
graphene_point_t points[2];
|
||||
};
|
||||
|
||||
struct _GskQuadCurve
|
||||
{
|
||||
GskPathOperation op;
|
||||
|
||||
gboolean has_coefficients;
|
||||
|
||||
graphene_point_t points[3];
|
||||
|
||||
graphene_point_t coeffs[3];
|
||||
};
|
||||
|
||||
struct _GskCubicCurve
|
||||
{
|
||||
GskPathOperation op;
|
||||
|
||||
gboolean has_coefficients;
|
||||
|
||||
graphene_point_t points[4];
|
||||
|
||||
graphene_point_t coeffs[4];
|
||||
};
|
||||
|
||||
union _GskCurve
|
||||
{
|
||||
GskPathOperation op;
|
||||
GskLineCurve line;
|
||||
GskQuadCurve quad;
|
||||
GskCubicCurve cubic;
|
||||
};
|
||||
|
||||
typedef enum {
|
||||
GSK_CURVE_LINE_REASON_STRAIGHT,
|
||||
GSK_CURVE_LINE_REASON_SHORT
|
||||
} GskCurveLineReason;
|
||||
|
||||
typedef gboolean (* GskCurveAddLineFunc) (const graphene_point_t *from,
|
||||
const graphene_point_t *to,
|
||||
float from_progress,
|
||||
float to_progress,
|
||||
GskCurveLineReason reason,
|
||||
gpointer user_data);
|
||||
|
||||
typedef gboolean (* GskCurveAddCurveFunc) (GskPathOperation op,
|
||||
const graphene_point_t *pts,
|
||||
gsize n_pts,
|
||||
gpointer user_data);
|
||||
|
||||
void gsk_curve_init (GskCurve *curve,
|
||||
gskpathop op);
|
||||
void gsk_curve_init_foreach (GskCurve *curve,
|
||||
GskPathOperation op,
|
||||
const graphene_point_t *pts,
|
||||
gsize n_pts);
|
||||
|
||||
void gsk_curve_print (const GskCurve *curve,
|
||||
GString *string);
|
||||
|
||||
char * gsk_curve_to_string (const GskCurve *curve);
|
||||
|
||||
gskpathop gsk_curve_pathop (const GskCurve *curve);
|
||||
const graphene_point_t *gsk_curve_get_start_point (const GskCurve *curve);
|
||||
const graphene_point_t *gsk_curve_get_end_point (const GskCurve *curve);
|
||||
void gsk_curve_get_start_tangent (const GskCurve *curve,
|
||||
graphene_vec2_t *tangent);
|
||||
void gsk_curve_get_end_tangent (const GskCurve *curve,
|
||||
graphene_vec2_t *tangent);
|
||||
void gsk_curve_get_point (const GskCurve *curve,
|
||||
float progress,
|
||||
graphene_point_t *pos);
|
||||
void gsk_curve_get_tangent (const GskCurve *curve,
|
||||
float progress,
|
||||
graphene_vec2_t *tangent);
|
||||
void gsk_curve_reverse (const GskCurve *curve,
|
||||
GskCurve *reverse);
|
||||
void gsk_curve_split (const GskCurve *curve,
|
||||
float progress,
|
||||
GskCurve *start,
|
||||
GskCurve *end);
|
||||
void gsk_curve_segment (const GskCurve *curve,
|
||||
float start,
|
||||
float end,
|
||||
GskCurve *segment);
|
||||
gboolean gsk_curve_decompose (const GskCurve *curve,
|
||||
float tolerance,
|
||||
GskCurveAddLineFunc add_line_func,
|
||||
gpointer user_data);
|
||||
gboolean gsk_curve_decompose_curve (const GskCurve *curve,
|
||||
GskPathForeachFlags flags,
|
||||
float tolerance,
|
||||
GskCurveAddCurveFunc add_curve_func,
|
||||
gpointer user_data);
|
||||
|
||||
#define gsk_curve_builder_to(curve, builder) gsk_path_builder_pathop_to ((builder), gsk_curve_pathop (curve))
|
||||
|
||||
float gsk_curve_get_curvature (const GskCurve *curve,
|
||||
float t,
|
||||
graphene_point_t *center);
|
||||
void gsk_curve_get_bounds (const GskCurve *curve,
|
||||
GskBoundingBox *bounds);
|
||||
void gsk_curve_get_tight_bounds (const GskCurve *curve,
|
||||
GskBoundingBox *bounds);
|
||||
|
||||
int gsk_curve_get_crossing (const GskCurve *curve,
|
||||
const graphene_point_t *point);
|
||||
gboolean gsk_curve_get_closest_point (const GskCurve *curve,
|
||||
const graphene_point_t *point,
|
||||
float threshold,
|
||||
float *out_dist,
|
||||
float *out_t);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
+125
-1
@@ -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
|
||||
@@ -74,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,
|
||||
@@ -170,6 +174,127 @@ typedef enum {
|
||||
GSK_CORNER_BOTTOM_LEFT
|
||||
} GskCorner;
|
||||
|
||||
/**
|
||||
* GskFillRule:
|
||||
* @GSK_FILL_RULE_WINDING: If the path crosses the ray from
|
||||
* left-to-right, counts +1. If the path crosses the ray
|
||||
* from right to left, counts -1. (Left and right are determined
|
||||
* from the perspective of looking along the ray from the starting
|
||||
* point.) If the total count is non-zero, the point will be filled.
|
||||
* @GSK_FILL_RULE_EVEN_ODD: Counts the total number of
|
||||
* intersections, without regard to the orientation of the contour. If
|
||||
* the total number of intersections is odd, the point will be
|
||||
* filled.
|
||||
*
|
||||
* `GskFillRule` is used to select how paths are filled.
|
||||
*
|
||||
* Whether or not a point is included in the fill is determined by taking
|
||||
* a ray from that point to infinity and looking at intersections with the
|
||||
* path. The ray can be in any direction, as long as it doesn't pass through
|
||||
* the end point of a segment or have a tricky intersection such as
|
||||
* intersecting tangent to the path.
|
||||
*
|
||||
* (Note that filling is not actually implemented in this way. This
|
||||
* is just a description of the rule that is applied.)
|
||||
*
|
||||
* New entries may be added in future versions.
|
||||
*
|
||||
* Since: 4.14
|
||||
*/
|
||||
typedef enum {
|
||||
GSK_FILL_RULE_WINDING,
|
||||
GSK_FILL_RULE_EVEN_ODD
|
||||
} GskFillRule;
|
||||
|
||||
/**
|
||||
* GskLineCap:
|
||||
* @GSK_LINE_CAP_BUTT: Start and stop the line exactly at the start
|
||||
* and end point
|
||||
* @GSK_LINE_CAP_ROUND: Use a round ending, the center of the circle
|
||||
* is the start or end point
|
||||
* @GSK_LINE_CAP_SQUARE: use squared ending, the center of the square
|
||||
* is the start or end point
|
||||
*
|
||||
* Specifies how to render the start and end points of contours or
|
||||
* dashes when stroking.
|
||||
*
|
||||
* The default line cap style is `GSK_LINE_CAP_BUTT`.
|
||||
*
|
||||
* New entries may be added in future versions.
|
||||
*
|
||||
* Since: 4.14
|
||||
*/
|
||||
typedef enum {
|
||||
GSK_LINE_CAP_BUTT,
|
||||
GSK_LINE_CAP_ROUND,
|
||||
GSK_LINE_CAP_SQUARE
|
||||
} GskLineCap;
|
||||
|
||||
/**
|
||||
* GskLineJoin:
|
||||
* @GSK_LINE_JOIN_MITER: Use a sharp angled corner
|
||||
* @GSK_LINE_JOIN_ROUND: Use a round join, the center of the circle is
|
||||
* the join point
|
||||
* @GSK_LINE_JOIN_BEVEL: use a cut-off join, the join is cut off at half
|
||||
* the line width from the joint point
|
||||
*
|
||||
* Specifies how to render the junction of two lines when stroking.
|
||||
*
|
||||
* The default line join style is `GSK_LINE_JOIN_MITER`.
|
||||
*
|
||||
* New entries may be added in future versions.
|
||||
*
|
||||
* Since: 4.14
|
||||
*/
|
||||
typedef enum {
|
||||
GSK_LINE_JOIN_MITER,
|
||||
GSK_LINE_JOIN_ROUND,
|
||||
GSK_LINE_JOIN_BEVEL,
|
||||
} GskLineJoin;
|
||||
|
||||
/**
|
||||
* GskPathOperation:
|
||||
* @GSK_PATH_MOVE: A move-to operation, with 1 point describing the target point.
|
||||
* @GSK_PATH_CLOSE: A close operation ending the current contour with a line back
|
||||
* to the starting point. Two points describe the start and end of the line.
|
||||
* @GSK_PATH_LINE: A line-to operation, with 2 points describing the start and
|
||||
* end point of a straight line.
|
||||
* @GSK_PATH_QUAD: A curve-to operation describing a quadratic Bézier curve
|
||||
* with 3 points describing the start point, the control point and the end
|
||||
* point of the curve.
|
||||
* @GSK_PATH_CUBIC: A curve-to operation describing a cubic Bézier curve with 4
|
||||
* points describing the start point, the two control points and the end point
|
||||
* of the curve.
|
||||
*
|
||||
* Path operations are used to described segments of a `GskPath`.
|
||||
*
|
||||
* More values may be added in the future.
|
||||
*
|
||||
* Since: 4.14
|
||||
*/
|
||||
typedef enum {
|
||||
GSK_PATH_MOVE,
|
||||
GSK_PATH_CLOSE,
|
||||
GSK_PATH_LINE,
|
||||
GSK_PATH_QUAD,
|
||||
GSK_PATH_CUBIC,
|
||||
} GskPathOperation;
|
||||
|
||||
/**
|
||||
* GskPathDirection:
|
||||
* @GSK_PATH_START: The side that leads to the start of the path
|
||||
* @GSK_PATH_END: The side that leads to the end of the path
|
||||
*
|
||||
* The values of the `GskPathDirection` enum are used to pick one
|
||||
* of the two sides of the path that at a given point on the path.
|
||||
*
|
||||
* Since: 4.14
|
||||
*/
|
||||
typedef enum {
|
||||
GSK_PATH_START,
|
||||
GSK_PATH_END
|
||||
} GskPathDirection;
|
||||
|
||||
/**
|
||||
* GskSerializationError:
|
||||
* @GSK_SERIALIZATION_UNSUPPORTED_FORMAT: The format can not be identified
|
||||
@@ -274,4 +399,3 @@ typedef enum
|
||||
GSK_MASK_MODE_LUMINANCE,
|
||||
GSK_MASK_MODE_INVERTED_LUMINANCE
|
||||
} GskMaskMode;
|
||||
|
||||
|
||||
+1564
File diff suppressed because it is too large
Load Diff
+144
@@ -0,0 +1,144 @@
|
||||
/*
|
||||
* 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/gsktypes.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
/**
|
||||
* GskPathForeachFlags:
|
||||
* @GSK_PATH_FOREACH_ALLOW_ONLY_LINES: The default behavior, only allow lines.
|
||||
* @GSK_PATH_FOREACH_ALLOW_QUAD: Allow emission of `GSK_PATH_QUAD` operations
|
||||
* @GSK_PATH_FOREACH_ALLOW_CUBIC: Allow emission of `GSK_PATH_CUBIC` operations.
|
||||
* @GSK_PATH_FOREACH_ALLOW_ANY: Allow emission of any kind of operation.
|
||||
*
|
||||
* Flags that can be passed to gsk_path_foreach() to enable additional
|
||||
* features.
|
||||
*
|
||||
* 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`.
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
GSK_PATH_FOREACH_ALLOW_ONLY_LINES = 0,
|
||||
GSK_PATH_FOREACH_ALLOW_QUAD = (1 << 0),
|
||||
GSK_PATH_FOREACH_ALLOW_CUBIC = (1 << 1),
|
||||
} GskPathForeachFlags;
|
||||
|
||||
/**
|
||||
* GskPathForeachFunc:
|
||||
* @op: The operation to perform
|
||||
* @pts: The points of the operation
|
||||
* @n_pts: The number of points
|
||||
* @user_data: The user data provided with the function
|
||||
*
|
||||
* Prototype of the callback to iterate throught the operations of
|
||||
* a path.
|
||||
*
|
||||
* Returns: %TRUE to continue evaluating the path, %FALSE to
|
||||
* immediately abort and not call the function again.
|
||||
*/
|
||||
typedef gboolean (* GskPathForeachFunc) (GskPathOperation op,
|
||||
const graphene_point_t *pts,
|
||||
gsize n_pts,
|
||||
gpointer user_data);
|
||||
|
||||
#define GSK_TYPE_PATH (gsk_path_get_type ())
|
||||
|
||||
GDK_AVAILABLE_IN_4_14
|
||||
GType gsk_path_get_type (void) G_GNUC_CONST;
|
||||
|
||||
GDK_AVAILABLE_IN_4_14
|
||||
GskPath * gsk_path_ref (GskPath *self);
|
||||
GDK_AVAILABLE_IN_4_14
|
||||
void gsk_path_unref (GskPath *self);
|
||||
|
||||
GDK_AVAILABLE_IN_4_14
|
||||
void gsk_path_print (GskPath *self,
|
||||
GString *string);
|
||||
GDK_AVAILABLE_IN_4_14
|
||||
char * gsk_path_to_string (GskPath *self);
|
||||
|
||||
GDK_AVAILABLE_IN_4_14
|
||||
GskPath * gsk_path_parse (const char *string);
|
||||
|
||||
GDK_AVAILABLE_IN_4_14
|
||||
void gsk_path_to_cairo (GskPath *self,
|
||||
cairo_t *cr);
|
||||
|
||||
GDK_AVAILABLE_IN_4_14
|
||||
gboolean gsk_path_is_empty (GskPath *self);
|
||||
|
||||
GDK_AVAILABLE_IN_4_14
|
||||
gboolean gsk_path_is_closed (GskPath *self);
|
||||
|
||||
GDK_AVAILABLE_IN_4_14
|
||||
gboolean gsk_path_get_bounds (GskPath *self,
|
||||
graphene_rect_t *bounds);
|
||||
|
||||
GDK_AVAILABLE_IN_4_14
|
||||
gboolean gsk_path_get_stroke_bounds (GskPath *self,
|
||||
const GskStroke *stroke,
|
||||
graphene_rect_t *bounds);
|
||||
|
||||
GDK_AVAILABLE_IN_4_14
|
||||
gboolean gsk_path_in_fill (GskPath *self,
|
||||
const graphene_point_t *point,
|
||||
GskFillRule fill_rule);
|
||||
|
||||
GDK_AVAILABLE_IN_4_14
|
||||
gboolean gsk_path_get_closest_point (GskPath *self,
|
||||
const graphene_point_t *point,
|
||||
float threshold,
|
||||
GskPathPoint *result);
|
||||
|
||||
GDK_AVAILABLE_IN_4_14
|
||||
gboolean gsk_path_get_previous_point (GskPath *self,
|
||||
const GskPathPoint *point,
|
||||
GskPathPoint *result);
|
||||
|
||||
GDK_AVAILABLE_IN_4_14
|
||||
gboolean gsk_path_get_next_point (GskPath *self,
|
||||
const GskPathPoint *point,
|
||||
GskPathPoint *result);
|
||||
|
||||
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_foreach (GskPath *self,
|
||||
GskPathForeachFlags flags,
|
||||
GskPathForeachFunc func,
|
||||
gpointer user_data);
|
||||
|
||||
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GskPath, gsk_path_unref)
|
||||
|
||||
G_END_DECLS
|
||||
@@ -0,0 +1,985 @@
|
||||
/*
|
||||
* 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 <math.h>
|
||||
|
||||
#include "gskpathbuilder.h"
|
||||
|
||||
#include "gskpathprivate.h"
|
||||
#include "gskcontourprivate.h"
|
||||
#include "gsksplineprivate.h"
|
||||
|
||||
/**
|
||||
* GskPathBuilder:
|
||||
*
|
||||
* `GskPathBuilder` is an auxiliary object for constructing
|
||||
* `GskPath` objects.
|
||||
*
|
||||
* A path is constructed like this:
|
||||
*
|
||||
* |[<!-- language="C" -->
|
||||
* GskPath *
|
||||
* construct_path (void)
|
||||
* {
|
||||
* GskPathBuilder *builder;
|
||||
*
|
||||
* builder = gsk_path_builder_new ();
|
||||
*
|
||||
* // add contours to the path here
|
||||
*
|
||||
* return gsk_path_builder_free_to_path (builder);
|
||||
* ]|
|
||||
*
|
||||
* Adding contours to the path can be done in two ways.
|
||||
* The easiest option is to use the `gsk_path_builder_add_*` group
|
||||
* of functions that add predefined contours to the current path,
|
||||
* either common shapes like [method@Gsk.PathBuilder.add_circle]
|
||||
* or by adding from other paths like [method@Gsk.PathBuilder.add_path].
|
||||
*
|
||||
* 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
|
||||
* and then use multiple calls to any of the drawing functions to
|
||||
* move the pen along the plane. Once you are done, you can call
|
||||
* [method@Gsk.PathBuilder.close] to close the path by connecting it
|
||||
* back with a line to the starting point.
|
||||
*
|
||||
* This is similar for how paths are drawn in Cairo.
|
||||
*/
|
||||
|
||||
struct _GskPathBuilder
|
||||
{
|
||||
int ref_count;
|
||||
|
||||
GSList *contours; /* (reverse) list of already recorded contours */
|
||||
|
||||
GskPathFlags flags; /* flags for the current path */
|
||||
graphene_point_t current_point; /* the point all drawing ops start from */
|
||||
GArray *ops; /* operations for current contour - size == 0 means no current contour */
|
||||
GArray *points; /* points for the operations */
|
||||
};
|
||||
|
||||
G_DEFINE_BOXED_TYPE (GskPathBuilder,
|
||||
gsk_path_builder,
|
||||
gsk_path_builder_ref,
|
||||
gsk_path_builder_unref)
|
||||
|
||||
|
||||
/**
|
||||
* gsk_path_builder_new:
|
||||
*
|
||||
* Create a new `GskPathBuilder` object.
|
||||
*
|
||||
* The resulting builder would create an empty `GskPath`.
|
||||
* Use addition functions to add types to it.
|
||||
*
|
||||
* Returns: a new `GskPathBuilder`
|
||||
*
|
||||
* Since: 4.14
|
||||
*/
|
||||
GskPathBuilder *
|
||||
gsk_path_builder_new (void)
|
||||
{
|
||||
GskPathBuilder *self;
|
||||
|
||||
self = g_slice_new0 (GskPathBuilder);
|
||||
self->ref_count = 1;
|
||||
|
||||
self->ops = g_array_new (FALSE, FALSE, sizeof (gskpathop));
|
||||
self->points = g_array_new (FALSE, FALSE, sizeof (graphene_point_t));
|
||||
|
||||
/* Be explicit here */
|
||||
self->current_point = GRAPHENE_POINT_INIT (0, 0);
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
/**
|
||||
* gsk_path_builder_ref:
|
||||
* @self: a `GskPathBuilder`
|
||||
*
|
||||
* Acquires a reference on the given builder.
|
||||
*
|
||||
* This function is intended primarily for language bindings.
|
||||
* `GskPathBuilder` objects should not be kept around.
|
||||
*
|
||||
* Returns: (transfer none): the given `GskPathBuilder` with
|
||||
* its reference count increased
|
||||
*
|
||||
* Since: 4.14
|
||||
*/
|
||||
GskPathBuilder *
|
||||
gsk_path_builder_ref (GskPathBuilder *self)
|
||||
{
|
||||
g_return_val_if_fail (self != NULL, NULL);
|
||||
g_return_val_if_fail (self->ref_count > 0, NULL);
|
||||
|
||||
self->ref_count += 1;
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
/* We're cheating here. Out pathops are relative to the NULL pointer,
|
||||
* so that we can not care about the points GArray reallocating itself
|
||||
* until we create the contour.
|
||||
* This does however mean that we need to not use gsk_pathop_get_points()
|
||||
* without offsetting the returned pointer.
|
||||
*/
|
||||
static inline gskpathop
|
||||
gsk_pathop_encode_index (GskPathOperation op,
|
||||
gsize index)
|
||||
{
|
||||
return gsk_pathop_encode (op, ((graphene_point_t *) NULL) + index);
|
||||
}
|
||||
|
||||
static void
|
||||
gsk_path_builder_ensure_current (GskPathBuilder *self)
|
||||
{
|
||||
if (self->ops->len != 0)
|
||||
return;
|
||||
|
||||
self->flags = GSK_PATH_FLAT;
|
||||
g_array_append_vals (self->ops, (gskpathop[1]) { gsk_pathop_encode_index (GSK_PATH_MOVE, 0) }, 1);
|
||||
g_array_append_val (self->points, self->current_point);
|
||||
}
|
||||
|
||||
static void
|
||||
gsk_path_builder_append_current (GskPathBuilder *self,
|
||||
GskPathOperation op,
|
||||
gsize n_points,
|
||||
const graphene_point_t *points)
|
||||
{
|
||||
gsk_path_builder_ensure_current (self);
|
||||
|
||||
g_array_append_vals (self->ops, (gskpathop[1]) { gsk_pathop_encode_index (op, self->points->len - 1) }, 1);
|
||||
g_array_append_vals (self->points, points, n_points);
|
||||
|
||||
self->current_point = points[n_points - 1];
|
||||
}
|
||||
|
||||
static void
|
||||
gsk_path_builder_end_current (GskPathBuilder *self)
|
||||
{
|
||||
GskContour *contour;
|
||||
|
||||
if (self->ops->len == 0)
|
||||
return;
|
||||
|
||||
contour = gsk_standard_contour_new (self->flags,
|
||||
(graphene_point_t *) self->points->data,
|
||||
self->points->len,
|
||||
(gskpathop *) self->ops->data,
|
||||
self->ops->len,
|
||||
(graphene_point_t *) self->points->data - (graphene_point_t *) NULL);
|
||||
|
||||
g_array_set_size (self->ops, 0);
|
||||
g_array_set_size (self->points, 0);
|
||||
|
||||
/* do this at the end to avoid inflooping when add_contour calls back here */
|
||||
gsk_path_builder_add_contour (self, contour);
|
||||
}
|
||||
|
||||
static void
|
||||
gsk_path_builder_clear (GskPathBuilder *self)
|
||||
{
|
||||
gsk_path_builder_end_current (self);
|
||||
|
||||
g_slist_free_full (self->contours, g_free);
|
||||
self->contours = NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* gsk_path_builder_unref:
|
||||
* @self: a `GskPathBuilder`
|
||||
*
|
||||
* Releases a reference on the given builder.
|
||||
*
|
||||
* Since: 4.14
|
||||
*/
|
||||
void
|
||||
gsk_path_builder_unref (GskPathBuilder *self)
|
||||
{
|
||||
g_return_if_fail (self != NULL);
|
||||
g_return_if_fail (self->ref_count > 0);
|
||||
|
||||
self->ref_count -= 1;
|
||||
|
||||
if (self->ref_count > 0)
|
||||
return;
|
||||
|
||||
gsk_path_builder_clear (self);
|
||||
g_array_unref (self->ops);
|
||||
g_array_unref (self->points);
|
||||
g_slice_free (GskPathBuilder, self);
|
||||
}
|
||||
|
||||
/**
|
||||
* gsk_path_builder_free_to_path: (skip)
|
||||
* @self: a `GskPathBuilder`
|
||||
*
|
||||
* Creates a new `GskPath` from the current state of the
|
||||
* given builder, and frees the @builder instance.
|
||||
*
|
||||
* Returns: (transfer full): the newly created `GskPath`
|
||||
* with all the contours added to the builder
|
||||
*
|
||||
* Since: 4.14
|
||||
*/
|
||||
GskPath *
|
||||
gsk_path_builder_free_to_path (GskPathBuilder *self)
|
||||
{
|
||||
GskPath *res;
|
||||
|
||||
g_return_val_if_fail (self != NULL, NULL);
|
||||
|
||||
res = gsk_path_builder_to_path (self);
|
||||
|
||||
gsk_path_builder_unref (self);
|
||||
|
||||
return res;
|
||||
}
|
||||
|
||||
/**
|
||||
* gsk_path_builder_to_path:
|
||||
* @self: a `GskPathBuilder`
|
||||
*
|
||||
* Creates a new `GskPath` from the given builder.
|
||||
*
|
||||
* The given `GskPathBuilder` is reset once this function returns;
|
||||
* you cannot call this function multiple times on the same builder
|
||||
* instance.
|
||||
*
|
||||
* This function is intended primarily for language bindings.
|
||||
* C code should use [method@Gsk.PathBuilder.free_to_path].
|
||||
*
|
||||
* Returns: (transfer full): the newly created `GskPath`
|
||||
* with all the contours added to the builder
|
||||
*
|
||||
* Since: 4.14
|
||||
*/
|
||||
GskPath *
|
||||
gsk_path_builder_to_path (GskPathBuilder *self)
|
||||
{
|
||||
GskPath *path;
|
||||
|
||||
g_return_val_if_fail (self != NULL, NULL);
|
||||
|
||||
gsk_path_builder_end_current (self);
|
||||
|
||||
self->contours = g_slist_reverse (self->contours);
|
||||
|
||||
path = gsk_path_new_from_contours (self->contours);
|
||||
|
||||
gsk_path_builder_clear (self);
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
void
|
||||
gsk_path_builder_add_contour (GskPathBuilder *self,
|
||||
GskContour *contour)
|
||||
{
|
||||
gsk_path_builder_end_current (self);
|
||||
|
||||
self->contours = g_slist_prepend (self->contours, contour);
|
||||
}
|
||||
|
||||
/**
|
||||
* gsk_path_builder_get_current_point:
|
||||
* @self: a `GskPathBuilder`
|
||||
*
|
||||
* Gets the current point. The current point is used for relative
|
||||
* drawing commands and updated after every operation.
|
||||
*
|
||||
* When the builder is created, the default current point is set to (0, 0).
|
||||
* Note that this is different from cairo, which starts out without
|
||||
* a current point.
|
||||
*
|
||||
* Returns: (transfer none): The current point
|
||||
*
|
||||
* Since: 4.14
|
||||
*/
|
||||
const graphene_point_t *
|
||||
gsk_path_builder_get_current_point (GskPathBuilder *self)
|
||||
{
|
||||
g_return_val_if_fail (self != NULL, NULL);
|
||||
|
||||
return &self->current_point;
|
||||
}
|
||||
|
||||
/**
|
||||
* gsk_path_builder_add_path:
|
||||
* @self: a `GskPathBuilder`
|
||||
* @path: (transfer none): the path to append
|
||||
*
|
||||
* Appends all of @path to the builder.
|
||||
*
|
||||
* Since: 4.14
|
||||
*/
|
||||
void
|
||||
gsk_path_builder_add_path (GskPathBuilder *self,
|
||||
GskPath *path)
|
||||
{
|
||||
g_return_if_fail (self != NULL);
|
||||
g_return_if_fail (path != NULL);
|
||||
|
||||
for (gsize i = 0; i < gsk_path_get_n_contours (path); i++)
|
||||
{
|
||||
const GskContour *contour = gsk_path_get_contour (path, i);
|
||||
|
||||
gsk_path_builder_add_contour (self, gsk_contour_dup (contour));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* gsk_path_builder_add_reverse_path:
|
||||
* @self: a `GskPathBuilder`
|
||||
* @path: (transfer none): the path to append
|
||||
*
|
||||
* Appends all of @path to the builder, in reverse order.
|
||||
*
|
||||
* Since: 4.14
|
||||
*/
|
||||
void
|
||||
gsk_path_builder_add_reverse_path (GskPathBuilder *self,
|
||||
GskPath *path)
|
||||
{
|
||||
g_return_if_fail (self != NULL);
|
||||
g_return_if_fail (path != NULL);
|
||||
|
||||
for (gsize i = gsk_path_get_n_contours (path); i > 0; i--)
|
||||
{
|
||||
const GskContour *contour = gsk_path_get_contour (path, i - 1);
|
||||
|
||||
gsk_path_builder_add_contour (self, gsk_contour_reverse (contour));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* gsk_path_builder_add_cairo_path:
|
||||
* @self: a `GskPathBuilder`
|
||||
*
|
||||
* Adds a Cairo path to the builder.
|
||||
*
|
||||
* You can use cairo_copy_path() to access the path
|
||||
* from a Cairo context.
|
||||
*
|
||||
* Since: 4.14
|
||||
*/
|
||||
void
|
||||
gsk_path_builder_add_cairo_path (GskPathBuilder *self,
|
||||
const cairo_path_t *path)
|
||||
{
|
||||
g_return_if_fail (self != NULL);
|
||||
g_return_if_fail (path != NULL);
|
||||
|
||||
for (gsize i = 0; i < path->num_data; i += path->data[i].header.length)
|
||||
{
|
||||
const cairo_path_data_t *data = &path->data[i];
|
||||
|
||||
switch (data->header.type)
|
||||
{
|
||||
case CAIRO_PATH_MOVE_TO:
|
||||
gsk_path_builder_move_to (self, data[1].point.x, data[1].point.y);
|
||||
break;
|
||||
|
||||
case CAIRO_PATH_LINE_TO:
|
||||
gsk_path_builder_line_to (self, data[1].point.x, data[1].point.y);
|
||||
break;
|
||||
|
||||
case CAIRO_PATH_CURVE_TO:
|
||||
gsk_path_builder_cubic_to (self,
|
||||
data[1].point.x, data[1].point.y,
|
||||
data[2].point.x, data[2].point.y,
|
||||
data[3].point.x, data[3].point.y);
|
||||
break;
|
||||
|
||||
case CAIRO_PATH_CLOSE_PATH:
|
||||
gsk_path_builder_close (self);
|
||||
break;
|
||||
|
||||
default:
|
||||
g_assert_not_reached ();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* gsk_path_builder_add_rect:
|
||||
* @self: A `GskPathBuilder`
|
||||
* @rect: The rectangle to create a path for
|
||||
*
|
||||
* Adds @rect as a new contour to the path built by the builder.
|
||||
*
|
||||
* If the width or height of the rectangle is negative, the start
|
||||
* point will be on the right or bottom, respectively.
|
||||
*
|
||||
* If the the width or height are 0, the path will be a closed
|
||||
* horizontal or vertical line. If both are 0, it'll be a closed dot.
|
||||
*
|
||||
* Since: 4.14
|
||||
*/
|
||||
void
|
||||
gsk_path_builder_add_rect (GskPathBuilder *self,
|
||||
const graphene_rect_t *rect)
|
||||
{
|
||||
g_return_if_fail (self != NULL);
|
||||
|
||||
gsk_path_builder_move_to (self, rect->origin.x, rect->origin.y);
|
||||
|
||||
gsk_path_builder_rel_line_to (self, rect->size.width, 0);
|
||||
gsk_path_builder_rel_line_to (self, 0, rect->size.height);
|
||||
gsk_path_builder_rel_line_to (self, - rect->size.width, 0);
|
||||
|
||||
gsk_path_builder_close (self);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
circle_contour_curve (const graphene_point_t pts[4],
|
||||
gpointer data)
|
||||
{
|
||||
GskPathBuilder *self = data;
|
||||
|
||||
gsk_path_builder_cubic_to (self,
|
||||
pts[1].x, pts[1].y,
|
||||
pts[2].x, pts[2].y,
|
||||
pts[3].x, pts[3].y);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* gsk_path_builder_add_circle:
|
||||
* @self: a `GskPathBuilder`
|
||||
* @center: the center of the circle
|
||||
* @radius: the radius of the circle
|
||||
*
|
||||
* Adds a circle with the @center and @radius.
|
||||
*
|
||||
* Since: 4.14
|
||||
*/
|
||||
void
|
||||
gsk_path_builder_add_circle (GskPathBuilder *self,
|
||||
const graphene_point_t *center,
|
||||
float radius)
|
||||
{
|
||||
g_return_if_fail (self != NULL);
|
||||
g_return_if_fail (center != NULL);
|
||||
g_return_if_fail (radius > 0);
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
/**
|
||||
* gsk_path_builder_move_to:
|
||||
* @self: a `GskPathBuilder`
|
||||
* @x: x coordinate
|
||||
* @y: y coordinate
|
||||
*
|
||||
* Starts a new contour by placing the pen at @x, @y.
|
||||
*
|
||||
* If this function is called twice in succession, the first
|
||||
* call will result in a contour made up of a single point.
|
||||
* The second call will start a new contour.
|
||||
*
|
||||
* Since: 4.14
|
||||
*/
|
||||
void
|
||||
gsk_path_builder_move_to (GskPathBuilder *self,
|
||||
float x,
|
||||
float y)
|
||||
{
|
||||
g_return_if_fail (self != NULL);
|
||||
|
||||
gsk_path_builder_end_current (self);
|
||||
|
||||
self->current_point = GRAPHENE_POINT_INIT(x, y);
|
||||
|
||||
gsk_path_builder_ensure_current (self);
|
||||
}
|
||||
|
||||
/**
|
||||
* gsk_path_builder_rel_move_to:
|
||||
* @self: a `GskPathBuilder`
|
||||
* @x: x offset
|
||||
* @y: y offset
|
||||
*
|
||||
* Starts a new contour by placing the pen at @x, @y relative to the current
|
||||
* point.
|
||||
*
|
||||
* This is the relative version of [method@Gsk.PathBuilder.move_to].
|
||||
*
|
||||
* Since: 4.14
|
||||
*/
|
||||
void
|
||||
gsk_path_builder_rel_move_to (GskPathBuilder *self,
|
||||
float x,
|
||||
float y)
|
||||
{
|
||||
g_return_if_fail (self != NULL);
|
||||
|
||||
gsk_path_builder_move_to (self,
|
||||
self->current_point.x + x,
|
||||
self->current_point.y + y);
|
||||
}
|
||||
|
||||
/**
|
||||
* gsk_path_builder_line_to:
|
||||
* @self: a `GskPathBuilder`
|
||||
* @x: x coordinate
|
||||
* @y: y coordinate
|
||||
*
|
||||
* Draws a line from the current point to @x, @y and makes it
|
||||
* the new current point.
|
||||
*
|
||||
* Since: 4.14
|
||||
*/
|
||||
void
|
||||
gsk_path_builder_line_to (GskPathBuilder *self,
|
||||
float x,
|
||||
float y)
|
||||
{
|
||||
g_return_if_fail (self != NULL);
|
||||
|
||||
/* skip the line if it goes to the same point */
|
||||
if (graphene_point_equal (&self->current_point,
|
||||
&GRAPHENE_POINT_INIT (x, y)))
|
||||
return;
|
||||
|
||||
gsk_path_builder_append_current (self,
|
||||
GSK_PATH_LINE,
|
||||
1, (graphene_point_t[1]) {
|
||||
GRAPHENE_POINT_INIT (x, y)
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* gsk_path_builder_rel_line_to:
|
||||
* @self: a `GskPathBuilder`
|
||||
* @x: x offset
|
||||
* @y: y offset
|
||||
*
|
||||
* Draws a line from the current point to a point offset to it by @x, @y
|
||||
* and makes it the new current point.
|
||||
*
|
||||
* This is the relative version of [method@Gsk.PathBuilder.line_to].
|
||||
*
|
||||
* Since: 4.14
|
||||
*/
|
||||
void
|
||||
gsk_path_builder_rel_line_to (GskPathBuilder *self,
|
||||
float x,
|
||||
float y)
|
||||
{
|
||||
g_return_if_fail (self != NULL);
|
||||
|
||||
gsk_path_builder_line_to (self,
|
||||
self->current_point.x + x,
|
||||
self->current_point.y + y);
|
||||
}
|
||||
|
||||
/**
|
||||
* gsk_path_builder_quad_to:
|
||||
* @self: a #GskPathBuilder
|
||||
* @x1: x coordinate of control point
|
||||
* @y1: y coordinate of control point
|
||||
* @x2: x coordinate of the end of the curve
|
||||
* @y2: y coordinate of the end of the curve
|
||||
*
|
||||
* Adds a [quadratic Bézier curve](https://en.wikipedia.org/wiki/B%C3%A9zier_curve)
|
||||
* from the current point to @x2, @y2 with @x1, @y1 as the control point.
|
||||
*
|
||||
* After this, @x2, @y2 will be the new current point.
|
||||
*
|
||||
* Since: 4.14
|
||||
*/
|
||||
void
|
||||
gsk_path_builder_quad_to (GskPathBuilder *self,
|
||||
float x1,
|
||||
float y1,
|
||||
float x2,
|
||||
float y2)
|
||||
{
|
||||
g_return_if_fail (self != NULL);
|
||||
|
||||
self->flags &= ~GSK_PATH_FLAT;
|
||||
gsk_path_builder_append_current (self,
|
||||
GSK_PATH_QUAD,
|
||||
2, (graphene_point_t[2]) {
|
||||
GRAPHENE_POINT_INIT (x1, y1),
|
||||
GRAPHENE_POINT_INIT (x2, y2)
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* gsk_path_builder_rel_quad_to:
|
||||
* @self: a `GskPathBuilder`
|
||||
* @x1: x offset of control point
|
||||
* @y1: y offset of control point
|
||||
* @x2: x offset of the end of the curve
|
||||
* @y2: y offset of the end of the curve
|
||||
*
|
||||
* Adds a [quadratic Bézier curve](https://en.wikipedia.org/wiki/B%C3%A9zier_curve)
|
||||
* from the current point to @x2, @y2 with @x1, @y1 the control point.
|
||||
*
|
||||
* All coordinates are given relative to the current point.
|
||||
*
|
||||
* This is the relative version of [method@Gsk.PathBuilder.quad_to].
|
||||
*
|
||||
* Since: 4.14
|
||||
*/
|
||||
void
|
||||
gsk_path_builder_rel_quad_to (GskPathBuilder *self,
|
||||
float x1,
|
||||
float y1,
|
||||
float x2,
|
||||
float y2)
|
||||
{
|
||||
g_return_if_fail (self != NULL);
|
||||
|
||||
gsk_path_builder_quad_to (self,
|
||||
self->current_point.x + x1,
|
||||
self->current_point.y + y1,
|
||||
self->current_point.x + x2,
|
||||
self->current_point.y + y2);
|
||||
}
|
||||
|
||||
/**
|
||||
* gsk_path_builder_cubic_to:
|
||||
* @self: a `GskPathBuilder`
|
||||
* @x1: x coordinate of first control point
|
||||
* @y1: y coordinate of first control point
|
||||
* @x2: x coordinate of second control point
|
||||
* @y2: y coordinate of second control point
|
||||
* @x3: x coordinate of the end of the curve
|
||||
* @y3: y coordinate of the end of the curve
|
||||
*
|
||||
* Adds a [cubic Bézier curve](https://en.wikipedia.org/wiki/B%C3%A9zier_curve)
|
||||
* from the current point to @x3, @y3 with @x1, @y1 and @x2, @y2 as the control
|
||||
* points.
|
||||
*
|
||||
* After this, @x3, @y3 will be the new current point.
|
||||
*
|
||||
* Since: 4.14
|
||||
*/
|
||||
void
|
||||
gsk_path_builder_cubic_to (GskPathBuilder *self,
|
||||
float x1,
|
||||
float y1,
|
||||
float x2,
|
||||
float y2,
|
||||
float x3,
|
||||
float y3)
|
||||
{
|
||||
g_return_if_fail (self != NULL);
|
||||
|
||||
self->flags &= ~GSK_PATH_FLAT;
|
||||
gsk_path_builder_append_current (self,
|
||||
GSK_PATH_CUBIC,
|
||||
3, (graphene_point_t[3]) {
|
||||
GRAPHENE_POINT_INIT (x1, y1),
|
||||
GRAPHENE_POINT_INIT (x2, y2),
|
||||
GRAPHENE_POINT_INIT (x3, y3)
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* gsk_path_builder_rel_cubic_to:
|
||||
* @self: a `GskPathBuilder`
|
||||
* @x1: x offset of first control point
|
||||
* @y1: y offset of first control point
|
||||
* @x2: x offset of second control point
|
||||
* @y2: y offset of second control point
|
||||
* @x3: x offset of the end of the curve
|
||||
* @y3: y offset of the end of the curve
|
||||
*
|
||||
* Adds a [cubic Bézier curve](https://en.wikipedia.org/wiki/B%C3%A9zier_curve)
|
||||
* from the current point to @x3, @y3 with @x1, @y1 and @x2, @y2 as the control
|
||||
* points. All coordinates are given relative to the current point.
|
||||
*
|
||||
* This is the relative version of [method@Gsk.PathBuilder.cubic_to].
|
||||
*
|
||||
* Since: 4.14
|
||||
*/
|
||||
void
|
||||
gsk_path_builder_rel_cubic_to (GskPathBuilder *self,
|
||||
float x1,
|
||||
float y1,
|
||||
float x2,
|
||||
float y2,
|
||||
float x3,
|
||||
float y3)
|
||||
{
|
||||
g_return_if_fail (self != NULL);
|
||||
|
||||
gsk_path_builder_cubic_to (self,
|
||||
self->current_point.x + x1,
|
||||
self->current_point.y + y1,
|
||||
self->current_point.x + x2,
|
||||
self->current_point.y + y2,
|
||||
self->current_point.x + x3,
|
||||
self->current_point.y + y3);
|
||||
}
|
||||
|
||||
/**
|
||||
* gsk_path_builder_close:
|
||||
* @self: a `GskPathBuilder`
|
||||
*
|
||||
* Ends the current contour with a line back to the start point.
|
||||
*
|
||||
* Note that this is different from calling [method@Gsk.PathBuilder.line_to]
|
||||
* with the start point in that the contour will be closed. A closed
|
||||
* contour behaves different from an open one when stroking its start
|
||||
* and end point are considered connected, so they will be joined
|
||||
* via the line join, and not ended with line caps.
|
||||
*
|
||||
* Since: 4.14
|
||||
*/
|
||||
void
|
||||
gsk_path_builder_close (GskPathBuilder *self)
|
||||
{
|
||||
g_return_if_fail (self != NULL);
|
||||
|
||||
if (self->ops->len == 0)
|
||||
return;
|
||||
|
||||
self->flags |= GSK_PATH_CLOSED;
|
||||
gsk_path_builder_append_current (self,
|
||||
GSK_PATH_CLOSE,
|
||||
1, (graphene_point_t[1]) {
|
||||
g_array_index (self->points, graphene_point_t, 0)
|
||||
});
|
||||
|
||||
gsk_path_builder_end_current (self);
|
||||
}
|
||||
|
||||
static void
|
||||
arc_segment (GskPathBuilder *self,
|
||||
double cx,
|
||||
double cy,
|
||||
double rx,
|
||||
double ry,
|
||||
double sin_phi,
|
||||
double cos_phi,
|
||||
double sin_th0,
|
||||
double cos_th0,
|
||||
double sin_th1,
|
||||
double cos_th1,
|
||||
double t)
|
||||
{
|
||||
double x1, y1, x2, y2, x3, y3;
|
||||
|
||||
x1 = rx * (cos_th0 - t * sin_th0);
|
||||
y1 = ry * (sin_th0 + t * cos_th0);
|
||||
x3 = rx * cos_th1;
|
||||
y3 = ry * sin_th1;
|
||||
x2 = x3 + rx * (t * sin_th1);
|
||||
y2 = y3 + ry * (-t * cos_th1);
|
||||
|
||||
gsk_path_builder_cubic_to (self,
|
||||
cx + cos_phi * x1 - sin_phi * y1,
|
||||
cy + sin_phi * x1 + cos_phi * y1,
|
||||
cx + cos_phi * x2 - sin_phi * y2,
|
||||
cy + sin_phi * x2 + cos_phi * y2,
|
||||
cx + cos_phi * x3 - sin_phi * y3,
|
||||
cy + sin_phi * x3 + cos_phi * y3);
|
||||
}
|
||||
|
||||
static inline void
|
||||
_sincos (double angle,
|
||||
double *y,
|
||||
double *x)
|
||||
{
|
||||
#ifdef HAVE_SINCOS
|
||||
sincos (angle, y, x);
|
||||
#else
|
||||
*x = cos (angle);
|
||||
*y = sin (angle);
|
||||
#endif
|
||||
}
|
||||
|
||||
void
|
||||
gsk_path_builder_svg_arc_to (GskPathBuilder *self,
|
||||
float rx,
|
||||
float ry,
|
||||
float x_axis_rotation,
|
||||
gboolean large_arc,
|
||||
gboolean positive_sweep,
|
||||
float x,
|
||||
float y)
|
||||
{
|
||||
graphene_point_t *current;
|
||||
double x1, y1, x2, y2;
|
||||
double phi, sin_phi, cos_phi;
|
||||
double mid_x, mid_y;
|
||||
double lambda;
|
||||
double d;
|
||||
double k;
|
||||
double x1_, y1_;
|
||||
double cx_, cy_;
|
||||
double cx, cy;
|
||||
double ux, uy, u_len;
|
||||
double cos_theta1, theta1;
|
||||
double vx, vy, v_len;
|
||||
double dp_uv;
|
||||
double cos_delta_theta, delta_theta;
|
||||
int i, n_segs;
|
||||
double d_theta, theta;
|
||||
double sin_th0, cos_th0;
|
||||
double sin_th1, cos_th1;
|
||||
double th_half;
|
||||
double t;
|
||||
|
||||
if (self->points->len > 0)
|
||||
{
|
||||
current = &g_array_index (self->points, graphene_point_t, self->points->len - 1);
|
||||
x1 = current->x;
|
||||
y1 = current->y;
|
||||
}
|
||||
else
|
||||
{
|
||||
x1 = 0;
|
||||
y1 = 0;
|
||||
}
|
||||
x2 = x;
|
||||
y2 = y;
|
||||
|
||||
phi = x_axis_rotation * M_PI / 180.0;
|
||||
_sincos (phi, &sin_phi, &cos_phi);
|
||||
|
||||
rx = fabs (rx);
|
||||
ry = fabs (ry);
|
||||
|
||||
mid_x = (x1 - x2) / 2;
|
||||
mid_y = (y1 - y2) / 2;
|
||||
|
||||
x1_ = cos_phi * mid_x + sin_phi * mid_y;
|
||||
y1_ = - sin_phi * mid_x + cos_phi * mid_y;
|
||||
|
||||
lambda = (x1_ / rx) * (x1_ / rx) + (y1_ / ry) * (y1_ / ry);
|
||||
if (lambda > 1)
|
||||
{
|
||||
lambda = sqrt (lambda);
|
||||
rx *= lambda;
|
||||
ry *= lambda;
|
||||
}
|
||||
|
||||
d = (rx * y1_) * (rx * y1_) + (ry * x1_) * (ry * x1_);
|
||||
if (d == 0)
|
||||
return;
|
||||
|
||||
k = sqrt (fabs ((rx * ry) * (rx * ry) / d - 1.0));
|
||||
if (positive_sweep == large_arc)
|
||||
k = -k;
|
||||
|
||||
cx_ = k * rx * y1_ / ry;
|
||||
cy_ = -k * ry * x1_ / rx;
|
||||
|
||||
cx = cos_phi * cx_ - sin_phi * cy_ + (x1 + x2) / 2;
|
||||
cy = sin_phi * cx_ + cos_phi * cy_ + (y1 + y2) / 2;
|
||||
|
||||
ux = (x1_ - cx_) / rx;
|
||||
uy = (y1_ - cy_) / ry;
|
||||
u_len = sqrt (ux * ux + uy * uy);
|
||||
if (u_len == 0)
|
||||
return;
|
||||
|
||||
cos_theta1 = CLAMP (ux / u_len, -1, 1);
|
||||
theta1 = acos (cos_theta1);
|
||||
if (uy < 0)
|
||||
theta1 = - theta1;
|
||||
|
||||
vx = (- x1_ - cx_) / rx;
|
||||
vy = (- y1_ - cy_) / ry;
|
||||
v_len = sqrt (vx * vx + vy * vy);
|
||||
if (v_len == 0)
|
||||
return;
|
||||
|
||||
dp_uv = ux * vx + uy * vy;
|
||||
cos_delta_theta = CLAMP (dp_uv / (u_len * v_len), -1, 1);
|
||||
delta_theta = acos (cos_delta_theta);
|
||||
if (ux * vy - uy * vx < 0)
|
||||
delta_theta = - delta_theta;
|
||||
if (positive_sweep && delta_theta < 0)
|
||||
delta_theta += 2 * M_PI;
|
||||
else if (!positive_sweep && delta_theta > 0)
|
||||
delta_theta -= 2 * M_PI;
|
||||
|
||||
n_segs = ceil (fabs (delta_theta / (M_PI_2 + 0.001)));
|
||||
d_theta = delta_theta / n_segs;
|
||||
theta = theta1;
|
||||
_sincos (theta1, &sin_th1, &cos_th1);
|
||||
|
||||
th_half = d_theta / 2;
|
||||
t = (8.0 / 3.0) * sin (th_half / 2) * sin (th_half / 2) / sin (th_half);
|
||||
|
||||
for (i = 0; i < n_segs; i++)
|
||||
{
|
||||
theta = theta1;
|
||||
theta1 = theta + d_theta;
|
||||
sin_th0 = sin_th1;
|
||||
cos_th0 = cos_th1;
|
||||
_sincos (theta1, &sin_th1, &cos_th1);
|
||||
arc_segment (self,
|
||||
cx, cy, rx, ry,
|
||||
sin_phi, cos_phi,
|
||||
sin_th0, cos_th0,
|
||||
sin_th1, cos_th1,
|
||||
t);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* gsk_path_builder_add_layout:
|
||||
* @self: a #GskPathBuilder
|
||||
* @layout: the pango layout to add
|
||||
*
|
||||
* Adds the outlines for the glyphs in @layout to
|
||||
* the builder.
|
||||
*
|
||||
* Since: 4.14
|
||||
*/
|
||||
void
|
||||
gsk_path_builder_add_layout (GskPathBuilder *self,
|
||||
PangoLayout *layout)
|
||||
{
|
||||
cairo_surface_t *surface;
|
||||
cairo_t *cr;
|
||||
cairo_path_t *cairo_path;
|
||||
|
||||
surface = cairo_recording_surface_create (CAIRO_CONTENT_COLOR_ALPHA, NULL);
|
||||
cr = cairo_create (surface);
|
||||
|
||||
pango_cairo_layout_path (cr, layout);
|
||||
cairo_path = cairo_copy_path (cr);
|
||||
|
||||
gsk_path_builder_add_cairo_path (self, cairo_path);
|
||||
|
||||
cairo_path_destroy (cairo_path);
|
||||
cairo_destroy (cr);
|
||||
cairo_surface_destroy (surface);
|
||||
}
|
||||
@@ -0,0 +1,125 @@
|
||||
/*
|
||||
* 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/gskroundedrect.h>
|
||||
#include <gsk/gsktypes.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define GSK_TYPE_PATH_BUILDER (gsk_path_builder_get_type ())
|
||||
|
||||
GDK_AVAILABLE_IN_4_14
|
||||
GType gsk_path_builder_get_type (void) G_GNUC_CONST;
|
||||
|
||||
GDK_AVAILABLE_IN_4_14
|
||||
GskPathBuilder * gsk_path_builder_new (void);
|
||||
GDK_AVAILABLE_IN_4_14
|
||||
GskPathBuilder * gsk_path_builder_ref (GskPathBuilder *self);
|
||||
GDK_AVAILABLE_IN_4_14
|
||||
void gsk_path_builder_unref (GskPathBuilder *self);
|
||||
GDK_AVAILABLE_IN_4_14
|
||||
GskPath * gsk_path_builder_free_to_path (GskPathBuilder *self) G_GNUC_WARN_UNUSED_RESULT;
|
||||
GDK_AVAILABLE_IN_4_14
|
||||
GskPath * gsk_path_builder_to_path (GskPathBuilder *self) G_GNUC_WARN_UNUSED_RESULT;
|
||||
|
||||
GDK_AVAILABLE_IN_4_14
|
||||
const graphene_point_t *gsk_path_builder_get_current_point (GskPathBuilder *self);
|
||||
|
||||
GDK_AVAILABLE_IN_4_14
|
||||
void gsk_path_builder_add_path (GskPathBuilder *self,
|
||||
GskPath *path);
|
||||
GDK_AVAILABLE_IN_4_14
|
||||
void gsk_path_builder_add_reverse_path (GskPathBuilder *self,
|
||||
GskPath *path);
|
||||
GDK_AVAILABLE_IN_4_14
|
||||
void gsk_path_builder_add_cairo_path (GskPathBuilder *self,
|
||||
const cairo_path_t *path);
|
||||
GDK_AVAILABLE_IN_4_14
|
||||
void gsk_path_builder_add_layout (GskPathBuilder *self,
|
||||
PangoLayout *layout);
|
||||
|
||||
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_circle (GskPathBuilder *self,
|
||||
const graphene_point_t *center,
|
||||
float radius);
|
||||
GDK_AVAILABLE_IN_4_14
|
||||
void gsk_path_builder_add_segment (GskPathBuilder *self,
|
||||
GskPath *path,
|
||||
const GskPathPoint *start,
|
||||
const GskPathPoint *end);
|
||||
GDK_AVAILABLE_IN_4_14
|
||||
void gsk_path_builder_move_to (GskPathBuilder *self,
|
||||
float x,
|
||||
float y);
|
||||
GDK_AVAILABLE_IN_4_14
|
||||
void gsk_path_builder_rel_move_to (GskPathBuilder *self,
|
||||
float x,
|
||||
float y);
|
||||
GDK_AVAILABLE_IN_4_14
|
||||
void gsk_path_builder_line_to (GskPathBuilder *self,
|
||||
float x,
|
||||
float y);
|
||||
GDK_AVAILABLE_IN_4_14
|
||||
void gsk_path_builder_rel_line_to (GskPathBuilder *self,
|
||||
float x,
|
||||
float y);
|
||||
GDK_AVAILABLE_IN_4_14
|
||||
void gsk_path_builder_quad_to (GskPathBuilder *self,
|
||||
float x1,
|
||||
float y1,
|
||||
float x2,
|
||||
float y2);
|
||||
GDK_AVAILABLE_IN_4_14
|
||||
void gsk_path_builder_rel_quad_to (GskPathBuilder *self,
|
||||
float x1,
|
||||
float y1,
|
||||
float x2,
|
||||
float y2);
|
||||
GDK_AVAILABLE_IN_4_14
|
||||
void gsk_path_builder_cubic_to (GskPathBuilder *self,
|
||||
float x1,
|
||||
float y1,
|
||||
float x2,
|
||||
float y2,
|
||||
float x3,
|
||||
float y3);
|
||||
GDK_AVAILABLE_IN_4_14
|
||||
void gsk_path_builder_rel_cubic_to (GskPathBuilder *self,
|
||||
float x1,
|
||||
float y1,
|
||||
float x2,
|
||||
float y2,
|
||||
float x3,
|
||||
float y3);
|
||||
GDK_AVAILABLE_IN_4_14
|
||||
void gsk_path_builder_close (GskPathBuilder *self);
|
||||
|
||||
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GskPathBuilder, gsk_path_builder_unref)
|
||||
|
||||
G_END_DECLS
|
||||
@@ -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);
|
||||
}
|
||||
@@ -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
|
||||
@@ -0,0 +1,172 @@
|
||||
/*
|
||||
* 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
|
||||
|
||||
#include "gskpath.h"
|
||||
#include "gskpathbuilder.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
typedef gpointer gskpathop;
|
||||
|
||||
static inline
|
||||
gskpathop gsk_pathop_encode (GskPathOperation op,
|
||||
const graphene_point_t *pts);
|
||||
static inline
|
||||
const graphene_point_t *gsk_pathop_points (gskpathop pop);
|
||||
static inline
|
||||
GskPathOperation gsk_pathop_op (gskpathop pop);
|
||||
|
||||
static inline
|
||||
gboolean gsk_pathop_foreach (gskpathop pop,
|
||||
GskPathForeachFunc func,
|
||||
gpointer user_data);
|
||||
|
||||
/* included inline so tests can use them */
|
||||
static inline
|
||||
void gsk_path_builder_pathop_to (GskPathBuilder *builder,
|
||||
gskpathop op);
|
||||
static inline
|
||||
void gsk_path_builder_pathop_reverse_to (GskPathBuilder *builder,
|
||||
gskpathop op);
|
||||
|
||||
/* IMPLEMENTATION */
|
||||
|
||||
#define GSK_PATHOP_OPERATION_MASK (0x7)
|
||||
|
||||
static inline gskpathop
|
||||
gsk_pathop_encode (GskPathOperation op,
|
||||
const graphene_point_t *pts)
|
||||
{
|
||||
/* g_assert (op & GSK_PATHOP_OPERATION_MASK == op); */
|
||||
g_assert ((GPOINTER_TO_SIZE (pts) & GSK_PATHOP_OPERATION_MASK) == 0);
|
||||
|
||||
return GSIZE_TO_POINTER (GPOINTER_TO_SIZE (pts) | op);
|
||||
}
|
||||
|
||||
static inline const graphene_point_t *
|
||||
gsk_pathop_points (gskpathop pop)
|
||||
{
|
||||
return GSIZE_TO_POINTER (GPOINTER_TO_SIZE (pop) & ~GSK_PATHOP_OPERATION_MASK);
|
||||
}
|
||||
|
||||
static inline
|
||||
GskPathOperation gsk_pathop_op (gskpathop pop)
|
||||
{
|
||||
return GPOINTER_TO_SIZE (pop) & GSK_PATHOP_OPERATION_MASK;
|
||||
}
|
||||
|
||||
static inline gboolean
|
||||
gsk_pathop_foreach (gskpathop pop,
|
||||
GskPathForeachFunc func,
|
||||
gpointer user_data)
|
||||
{
|
||||
switch (gsk_pathop_op (pop))
|
||||
{
|
||||
case GSK_PATH_MOVE:
|
||||
return func (gsk_pathop_op (pop), gsk_pathop_points (pop), 1, user_data);
|
||||
|
||||
case GSK_PATH_CLOSE:
|
||||
case GSK_PATH_LINE:
|
||||
return func (gsk_pathop_op (pop), gsk_pathop_points (pop), 2, user_data);
|
||||
|
||||
case GSK_PATH_QUAD:
|
||||
return func (gsk_pathop_op (pop), gsk_pathop_points (pop), 3, user_data);
|
||||
|
||||
case GSK_PATH_CUBIC:
|
||||
return func (gsk_pathop_op (pop), gsk_pathop_points (pop), 4, user_data);
|
||||
|
||||
default:
|
||||
g_assert_not_reached ();
|
||||
return TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
static inline void
|
||||
gsk_path_builder_pathop_to (GskPathBuilder *builder,
|
||||
gskpathop op)
|
||||
{
|
||||
const graphene_point_t *pts = gsk_pathop_points (op);
|
||||
|
||||
switch (gsk_pathop_op (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 ();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
static inline void
|
||||
gsk_path_builder_pathop_reverse_to (GskPathBuilder *builder,
|
||||
gskpathop op)
|
||||
{
|
||||
const graphene_point_t *pts = gsk_pathop_points (op);
|
||||
|
||||
switch (gsk_pathop_op (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_line_to (builder, pts[0].x, pts[0].y);
|
||||
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[0].x, pts[0].y);
|
||||
break;
|
||||
|
||||
case GSK_PATH_CUBIC:
|
||||
gsk_path_builder_cubic_to (builder, pts[2].x, pts[2].y, pts[1].x, pts[1].y, pts[0].x, pts[0].y);
|
||||
break;
|
||||
|
||||
default:
|
||||
g_assert_not_reached ();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
G_END_DECLS
|
||||
@@ -0,0 +1,157 @@
|
||||
/*
|
||||
* Copyright © 2023 Red Hat, Inc.
|
||||
*
|
||||
* 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: Matthias Clasen <mclasen@redhat.com>
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "gskpathpointprivate.h"
|
||||
|
||||
#include "gskcontourprivate.h"
|
||||
#include "gskpathmeasure.h"
|
||||
|
||||
#include "gdk/gdkprivate.h"
|
||||
|
||||
/**
|
||||
* GskPathPoint:
|
||||
*
|
||||
* `GskPathPoint` is an opaque type representing a point on a path.
|
||||
*
|
||||
* 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]
|
||||
* 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.
|
||||
*/
|
||||
|
||||
G_DEFINE_BOXED_TYPE (GskPathPoint, gsk_path_point,
|
||||
gsk_path_point_copy,
|
||||
gsk_path_point_free)
|
||||
|
||||
|
||||
GskPathPoint *
|
||||
gsk_path_point_copy (GskPathPoint *point)
|
||||
{
|
||||
GskPathPoint *copy;
|
||||
|
||||
copy = g_new0 (GskPathPoint, 1);
|
||||
|
||||
memcpy (copy, point, sizeof (GskRealPathPoint));
|
||||
|
||||
return copy;
|
||||
}
|
||||
|
||||
void
|
||||
gsk_path_point_free (GskPathPoint *point)
|
||||
{
|
||||
g_free (point);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*
|
||||
* Gets the position of the point.
|
||||
*
|
||||
* Since: 4.14
|
||||
*/
|
||||
void
|
||||
gsk_path_point_get_position (GskPath *path,
|
||||
const GskPathPoint *point,
|
||||
graphene_point_t *position)
|
||||
{
|
||||
GskRealPathPoint *self = (GskRealPathPoint *) point;
|
||||
const GskContour *contour = gsk_path_get_contour (path, self->contour);
|
||||
|
||||
g_return_if_fail (path == self->path);
|
||||
g_return_if_fail (contour != NULL);
|
||||
|
||||
gsk_contour_get_position (contour, self, position);
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*
|
||||
* Gets the tangent of the path at the 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.
|
||||
*
|
||||
* Since: 4.14
|
||||
*/
|
||||
void
|
||||
gsk_path_point_get_tangent (GskPath *path,
|
||||
const GskPathPoint *point,
|
||||
GskPathDirection direction,
|
||||
graphene_vec2_t *tangent)
|
||||
{
|
||||
GskRealPathPoint *self = (GskRealPathPoint *) point;
|
||||
const GskContour *contour = gsk_path_get_contour (path, self->contour);
|
||||
|
||||
g_return_if_fail (path == self->path);
|
||||
g_return_if_fail (contour != NULL);
|
||||
|
||||
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);
|
||||
}
|
||||
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
* Copyright © 2023 Red Hat, Inc.
|
||||
*
|
||||
* 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: Matthias Clasen <mclasen@redhat.com>
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#if !defined (__GSK_H_INSIDE__) && !defined (GTK_COMPILATION)
|
||||
#error "Only <gsk/gsk.h> can be included directly."
|
||||
#endif
|
||||
|
||||
|
||||
#include <gsk/gsktypes.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define GSK_TYPE_PATH_POINT (gsk_path_point_get_type ())
|
||||
|
||||
typedef struct _GskPathPoint GskPathPoint;
|
||||
struct _GskPathPoint {
|
||||
/*< private >*/
|
||||
union {
|
||||
float f[8];
|
||||
gpointer p[8];
|
||||
} data;
|
||||
};
|
||||
|
||||
GDK_AVAILABLE_IN_4_14
|
||||
GType gsk_path_point_get_type (void) G_GNUC_CONST;
|
||||
|
||||
GDK_AVAILABLE_IN_4_14
|
||||
GskPathPoint * gsk_path_point_copy (GskPathPoint *point);
|
||||
|
||||
GDK_AVAILABLE_IN_4_14
|
||||
void gsk_path_point_free (GskPathPoint *point);
|
||||
|
||||
GDK_AVAILABLE_IN_4_14
|
||||
void gsk_path_point_get_position (GskPath *path,
|
||||
const GskPathPoint *point,
|
||||
graphene_point_t *position);
|
||||
|
||||
GDK_AVAILABLE_IN_4_14
|
||||
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
|
||||
@@ -0,0 +1,24 @@
|
||||
#pragma once
|
||||
|
||||
#include "gskpathpoint.h"
|
||||
#include "gskcontourprivate.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
struct _GskRealPathPoint
|
||||
{
|
||||
GskPath *path;
|
||||
gsize contour;
|
||||
|
||||
union {
|
||||
struct {
|
||||
unsigned int idx;
|
||||
float t;
|
||||
} std;
|
||||
} data;
|
||||
};
|
||||
|
||||
G_STATIC_ASSERT (sizeof (GskRealPathPoint) <= sizeof (GskPathPoint));
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
@@ -0,0 +1,70 @@
|
||||
/*
|
||||
* 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
|
||||
|
||||
#include "gskpath.h"
|
||||
|
||||
#include "gskpathopprivate.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
typedef enum
|
||||
{
|
||||
GSK_PATH_FLAT,
|
||||
GSK_PATH_CLOSED
|
||||
} GskPathFlags;
|
||||
|
||||
typedef struct _GskContour GskContour;
|
||||
typedef struct _GskRealPathPoint GskRealPathPoint;
|
||||
|
||||
/* Same as Skia, so looks like a good value. ¯\_(ツ)_/¯ */
|
||||
#define GSK_PATH_TOLERANCE_DEFAULT (0.5)
|
||||
|
||||
GskPath * gsk_path_new_from_contours (const GSList *contours);
|
||||
|
||||
gsize gsk_path_get_n_contours (const GskPath *self);
|
||||
const GskContour * gsk_path_get_contour (const GskPath *self,
|
||||
gsize i);
|
||||
|
||||
GskPathFlags gsk_path_get_flags (const GskPath *self);
|
||||
|
||||
gboolean gsk_path_foreach_with_tolerance (GskPath *self,
|
||||
GskPathForeachFlags flags,
|
||||
double tolerance,
|
||||
GskPathForeachFunc func,
|
||||
gpointer user_data);
|
||||
|
||||
|
||||
void gsk_path_builder_add_contour (GskPathBuilder *builder,
|
||||
GskContour *contour);
|
||||
|
||||
void gsk_path_builder_svg_arc_to (GskPathBuilder *builder,
|
||||
float rx,
|
||||
float ry,
|
||||
float x_axis_rotation,
|
||||
gboolean large_arc,
|
||||
gboolean positive_sweep,
|
||||
float x,
|
||||
float y);
|
||||
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
#pragma once
|
||||
|
||||
#include <graphene.h>
|
||||
|
||||
static inline void G_GNUC_PURE
|
||||
gsk_point_interpolate (const graphene_point_t *p1,
|
||||
const graphene_point_t *p2,
|
||||
float t,
|
||||
graphene_point_t *p)
|
||||
{
|
||||
p->x = p1->x * (1 - t) + p2->x * t;
|
||||
p->Y = p1->y * (1 - t) + p2->y * t;
|
||||
}
|
||||
|
||||
static inline float G_GNUC_PURE
|
||||
gsk_point_distance (const graphene_point_t *p1,
|
||||
const graphene_point_t *p2)
|
||||
{
|
||||
return sqrtf ((p1->x - p2->x)*(p1->x - p2->x) + (p1->y - p2->y)*(p1->y - p2->y));
|
||||
}
|
||||
@@ -158,6 +158,8 @@ GskRenderNode * gsk_render_node_deserialize (GBytes
|
||||
#define GSK_TYPE_REPEAT_NODE (gsk_repeat_node_get_type())
|
||||
#define GSK_TYPE_CLIP_NODE (gsk_clip_node_get_type())
|
||||
#define GSK_TYPE_ROUNDED_CLIP_NODE (gsk_rounded_clip_node_get_type())
|
||||
#define GSK_TYPE_FILL_NODE (gsk_fill_node_get_type())
|
||||
#define GSK_TYPE_STROKE_NODE (gsk_stroke_node_get_type())
|
||||
#define GSK_TYPE_SHADOW_NODE (gsk_shadow_node_get_type())
|
||||
#define GSK_TYPE_BLEND_NODE (gsk_blend_node_get_type())
|
||||
#define GSK_TYPE_CROSS_FADE_NODE (gsk_cross_fade_node_get_type())
|
||||
@@ -186,6 +188,8 @@ typedef struct _GskColorMatrixNode GskColorMatrixNode;
|
||||
typedef struct _GskRepeatNode GskRepeatNode;
|
||||
typedef struct _GskClipNode GskClipNode;
|
||||
typedef struct _GskRoundedClipNode GskRoundedClipNode;
|
||||
typedef struct _GskFillNode GskFillNode;
|
||||
typedef struct _GskStrokeNode GskStrokeNode;
|
||||
typedef struct _GskShadowNode GskShadowNode;
|
||||
typedef struct _GskBlendNode GskBlendNode;
|
||||
typedef struct _GskCrossFadeNode GskCrossFadeNode;
|
||||
@@ -459,6 +463,32 @@ GskRenderNode * gsk_rounded_clip_node_get_child (const GskRender
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
const GskRoundedRect * gsk_rounded_clip_node_get_clip (const GskRenderNode *node) G_GNUC_PURE;
|
||||
|
||||
GDK_AVAILABLE_IN_4_14
|
||||
GType gsk_fill_node_get_type (void) G_GNUC_CONST;
|
||||
GDK_AVAILABLE_IN_4_14
|
||||
GskRenderNode * gsk_fill_node_new (GskRenderNode *child,
|
||||
GskPath *path,
|
||||
GskFillRule fill_rule);
|
||||
GDK_AVAILABLE_IN_4_14
|
||||
GskRenderNode * gsk_fill_node_get_child (const GskRenderNode *node);
|
||||
GDK_AVAILABLE_IN_4_14
|
||||
GskPath * gsk_fill_node_get_path (const GskRenderNode *node);
|
||||
GDK_AVAILABLE_IN_4_14
|
||||
GskFillRule gsk_fill_node_get_fill_rule (const GskRenderNode *node);
|
||||
|
||||
GDK_AVAILABLE_IN_4_14
|
||||
GType gsk_stroke_node_get_type (void) G_GNUC_CONST;
|
||||
GDK_AVAILABLE_IN_4_14
|
||||
GskRenderNode * gsk_stroke_node_new (GskRenderNode *child,
|
||||
GskPath *path,
|
||||
const GskStroke *stroke);
|
||||
GDK_AVAILABLE_IN_4_14
|
||||
GskRenderNode * gsk_stroke_node_get_child (const GskRenderNode *node);
|
||||
GDK_AVAILABLE_IN_4_14
|
||||
GskPath * gsk_stroke_node_get_path (const GskRenderNode *node);
|
||||
GDK_AVAILABLE_IN_4_14
|
||||
const GskStroke * gsk_stroke_node_get_stroke (const GskRenderNode *node);
|
||||
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
GType gsk_shadow_node_get_type (void) G_GNUC_CONST;
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
|
||||
+415
-4
@@ -25,8 +25,11 @@
|
||||
#include "gskdebugprivate.h"
|
||||
#include "gskdiffprivate.h"
|
||||
#include "gl/gskglrenderer.h"
|
||||
#include "gskpathprivate.h"
|
||||
#include "gskrectprivate.h"
|
||||
#include "gskrendererprivate.h"
|
||||
#include "gskroundedrectprivate.h"
|
||||
#include "gskstrokeprivate.h"
|
||||
#include "gsktransformprivate.h"
|
||||
|
||||
#include "gdk/gdktextureprivate.h"
|
||||
@@ -3838,12 +3841,11 @@ gsk_color_matrix_node_class_init (gpointer g_class,
|
||||
* Creates a `GskRenderNode` that will drawn the @child with
|
||||
* @color_matrix.
|
||||
*
|
||||
* In particular, the node will transform colors by applying
|
||||
* In particular, the node will transform the operation
|
||||
*
|
||||
* pixel = transpose(color_matrix) * pixel + color_offset
|
||||
* pixel = color_matrix * pixel + color_offset
|
||||
*
|
||||
* for every pixel. The transformation operates on unpremultiplied
|
||||
* colors, with color components ordered R, G, B, A.
|
||||
* for every pixel.
|
||||
*
|
||||
* Returns: (transfer full) (type GskColorMatrixNode): A new `GskRenderNode`
|
||||
*/
|
||||
@@ -4367,6 +4369,403 @@ gsk_rounded_clip_node_get_clip (const GskRenderNode *node)
|
||||
return &self->clip;
|
||||
}
|
||||
|
||||
/* }}} */
|
||||
/* {{{ GSK_FILL_NODE */
|
||||
|
||||
struct _GskFillNode
|
||||
{
|
||||
GskRenderNode render_node;
|
||||
|
||||
GskRenderNode *child;
|
||||
GskPath *path;
|
||||
GskFillRule fill_rule;
|
||||
};
|
||||
|
||||
static void
|
||||
gsk_fill_node_finalize (GskRenderNode *node)
|
||||
{
|
||||
GskFillNode *self = (GskFillNode *) node;
|
||||
GskRenderNodeClass *parent_class = g_type_class_peek (g_type_parent (GSK_TYPE_FILL_NODE));
|
||||
|
||||
gsk_render_node_unref (self->child);
|
||||
gsk_path_unref (self->path);
|
||||
|
||||
parent_class->finalize (node);
|
||||
}
|
||||
|
||||
static void
|
||||
gsk_fill_node_draw (GskRenderNode *node,
|
||||
cairo_t *cr)
|
||||
{
|
||||
GskFillNode *self = (GskFillNode *) node;
|
||||
|
||||
cairo_save (cr);
|
||||
|
||||
switch (self->fill_rule)
|
||||
{
|
||||
case GSK_FILL_RULE_WINDING:
|
||||
cairo_set_fill_rule (cr, CAIRO_FILL_RULE_WINDING);
|
||||
break;
|
||||
case GSK_FILL_RULE_EVEN_ODD:
|
||||
cairo_set_fill_rule (cr, CAIRO_FILL_RULE_EVEN_ODD);
|
||||
break;
|
||||
default:
|
||||
g_assert_not_reached ();
|
||||
break;
|
||||
}
|
||||
gsk_path_to_cairo (self->path, cr);
|
||||
if (gsk_render_node_get_node_type (self->child) == GSK_COLOR_NODE &&
|
||||
gsk_rect_contains_rect (&self->child->bounds, &node->bounds))
|
||||
{
|
||||
gdk_cairo_set_source_rgba (cr, gsk_color_node_get_color (self->child));
|
||||
cairo_fill (cr);
|
||||
}
|
||||
else
|
||||
{
|
||||
cairo_clip (cr);
|
||||
gsk_render_node_draw (self->child, cr);
|
||||
}
|
||||
|
||||
cairo_restore (cr);
|
||||
}
|
||||
|
||||
static void
|
||||
gsk_fill_node_diff (GskRenderNode *node1,
|
||||
GskRenderNode *node2,
|
||||
cairo_region_t *region)
|
||||
{
|
||||
GskFillNode *self1 = (GskFillNode *) node1;
|
||||
GskFillNode *self2 = (GskFillNode *) node2;
|
||||
|
||||
if (self1->path == self2->path)
|
||||
{
|
||||
cairo_region_t *sub;
|
||||
cairo_rectangle_int_t clip_rect;
|
||||
|
||||
sub = cairo_region_create();
|
||||
gsk_render_node_diff (self1->child, self2->child, sub);
|
||||
rectangle_init_from_graphene (&clip_rect, &node1->bounds);
|
||||
cairo_region_intersect_rectangle (sub, &clip_rect);
|
||||
cairo_region_union (region, sub);
|
||||
cairo_region_destroy (sub);
|
||||
}
|
||||
else
|
||||
{
|
||||
gsk_render_node_diff_impossible (node1, node2, region);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
gsk_fill_node_class_init (gpointer g_class,
|
||||
gpointer class_data)
|
||||
{
|
||||
GskRenderNodeClass *node_class = g_class;
|
||||
|
||||
node_class->node_type = GSK_FILL_NODE;
|
||||
|
||||
node_class->finalize = gsk_fill_node_finalize;
|
||||
node_class->draw = gsk_fill_node_draw;
|
||||
node_class->diff = gsk_fill_node_diff;
|
||||
}
|
||||
|
||||
/**
|
||||
* gsk_fill_node_new:
|
||||
* @child: The node to fill the area with
|
||||
* @path: The path describing the area to fill
|
||||
* @fill_rule: The fill rule to use
|
||||
*
|
||||
* Creates a `GskRenderNode` that will fill the @child in the area
|
||||
* given by @path and @fill_rule.
|
||||
*
|
||||
* Returns: (transfer none) (type GskFillNode): A new `GskRenderNode`
|
||||
*
|
||||
* Since: 4.14
|
||||
*/
|
||||
GskRenderNode *
|
||||
gsk_fill_node_new (GskRenderNode *child,
|
||||
GskPath *path,
|
||||
GskFillRule fill_rule)
|
||||
{
|
||||
GskFillNode *self;
|
||||
GskRenderNode *node;
|
||||
graphene_rect_t path_bounds;
|
||||
|
||||
g_return_val_if_fail (GSK_IS_RENDER_NODE (child), NULL);
|
||||
g_return_val_if_fail (path != NULL, NULL);
|
||||
|
||||
self = gsk_render_node_alloc (GSK_FILL_NODE);
|
||||
node = (GskRenderNode *) self;
|
||||
|
||||
self->child = gsk_render_node_ref (child);
|
||||
self->path = gsk_path_ref (path);
|
||||
self->fill_rule = fill_rule;
|
||||
|
||||
if (gsk_path_get_bounds (path, &path_bounds))
|
||||
graphene_rect_intersection (&path_bounds, &child->bounds, &node->bounds);
|
||||
else
|
||||
graphene_rect_init_from_rect (&node->bounds, graphene_rect_zero ());
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
/**
|
||||
* gsk_fill_node_get_child:
|
||||
* @node: (type GskFillNode): a fill `GskRenderNode`
|
||||
*
|
||||
* Gets the child node that is getting drawn by the given @node.
|
||||
*
|
||||
* Returns: (transfer none): The child that is getting drawn
|
||||
*
|
||||
* Since: 4.14
|
||||
*/
|
||||
GskRenderNode *
|
||||
gsk_fill_node_get_child (const GskRenderNode *node)
|
||||
{
|
||||
const GskFillNode *self = (const GskFillNode *) node;
|
||||
|
||||
g_return_val_if_fail (GSK_IS_RENDER_NODE_TYPE (node, GSK_FILL_NODE), NULL);
|
||||
|
||||
return self->child;
|
||||
}
|
||||
|
||||
/**
|
||||
* gsk_fill_node_get_path:
|
||||
* @node: (type GskFillNode): a fill `GskRenderNode`
|
||||
*
|
||||
* Retrieves the path used to describe the area filled with the contents of
|
||||
* the @node.
|
||||
*
|
||||
* Returns: (transfer none): a `GskPath`
|
||||
*
|
||||
* Since: 4.14
|
||||
*/
|
||||
GskPath *
|
||||
gsk_fill_node_get_path (const GskRenderNode *node)
|
||||
{
|
||||
const GskFillNode *self = (const GskFillNode *) node;
|
||||
|
||||
g_return_val_if_fail (GSK_IS_RENDER_NODE_TYPE (node, GSK_FILL_NODE), NULL);
|
||||
|
||||
return self->path;
|
||||
}
|
||||
|
||||
/**
|
||||
* gsk_fill_node_get_fill_rule:
|
||||
* @node: (type GskFillNode): a fill `GskRenderNode`
|
||||
*
|
||||
* Retrieves the fill rule used to determine how the path is filled.
|
||||
*
|
||||
* Returns: a `GskFillRule`
|
||||
*
|
||||
* Since: 4.14
|
||||
*/
|
||||
GskFillRule
|
||||
gsk_fill_node_get_fill_rule (const GskRenderNode *node)
|
||||
{
|
||||
const GskFillNode *self = (const GskFillNode *) node;
|
||||
|
||||
g_return_val_if_fail (GSK_IS_RENDER_NODE_TYPE (node, GSK_FILL_NODE), GSK_FILL_RULE_WINDING);
|
||||
|
||||
return self->fill_rule;
|
||||
}
|
||||
|
||||
/* }}} */
|
||||
/* {{{ GSK_STROKE_NODE */
|
||||
|
||||
struct _GskStrokeNode
|
||||
{
|
||||
GskRenderNode render_node;
|
||||
|
||||
GskRenderNode *child;
|
||||
GskPath *path;
|
||||
GskStroke stroke;
|
||||
};
|
||||
|
||||
static void
|
||||
gsk_stroke_node_finalize (GskRenderNode *node)
|
||||
{
|
||||
GskStrokeNode *self = (GskStrokeNode *) node;
|
||||
GskRenderNodeClass *parent_class = g_type_class_peek (g_type_parent (GSK_TYPE_STROKE_NODE));
|
||||
|
||||
gsk_render_node_unref (self->child);
|
||||
gsk_path_unref (self->path);
|
||||
gsk_stroke_clear (&self->stroke);
|
||||
|
||||
parent_class->finalize (node);
|
||||
}
|
||||
|
||||
static void
|
||||
gsk_stroke_node_draw (GskRenderNode *node,
|
||||
cairo_t *cr)
|
||||
{
|
||||
GskStrokeNode *self = (GskStrokeNode *) node;
|
||||
|
||||
cairo_save (cr);
|
||||
|
||||
if (gsk_render_node_get_node_type (self->child) == GSK_COLOR_NODE &&
|
||||
gsk_rect_contains_rect (&self->child->bounds, &node->bounds))
|
||||
{
|
||||
gdk_cairo_set_source_rgba (cr, gsk_color_node_get_color (self->child));
|
||||
}
|
||||
else
|
||||
{
|
||||
gsk_cairo_rectangle (cr, &self->child->bounds);
|
||||
cairo_clip (cr);
|
||||
cairo_push_group (cr);
|
||||
gsk_render_node_draw (self->child, cr);
|
||||
cairo_pop_group_to_source (cr);
|
||||
}
|
||||
|
||||
gsk_stroke_to_cairo (&self->stroke, cr);
|
||||
|
||||
gsk_path_to_cairo (self->path, cr);
|
||||
cairo_stroke (cr);
|
||||
|
||||
cairo_restore (cr);
|
||||
}
|
||||
|
||||
static void
|
||||
gsk_stroke_node_diff (GskRenderNode *node1,
|
||||
GskRenderNode *node2,
|
||||
cairo_region_t *region)
|
||||
{
|
||||
GskStrokeNode *self1 = (GskStrokeNode *) node1;
|
||||
GskStrokeNode *self2 = (GskStrokeNode *) node2;
|
||||
|
||||
if (self1->path == self2->path &&
|
||||
gsk_stroke_equal (&self1->stroke, &self2->stroke))
|
||||
{
|
||||
cairo_region_t *sub;
|
||||
cairo_rectangle_int_t clip_rect;
|
||||
|
||||
sub = cairo_region_create();
|
||||
gsk_render_node_diff (self1->child, self2->child, sub);
|
||||
rectangle_init_from_graphene (&clip_rect, &node1->bounds);
|
||||
cairo_region_intersect_rectangle (sub, &clip_rect);
|
||||
cairo_region_union (region, sub);
|
||||
cairo_region_destroy (sub);
|
||||
}
|
||||
else
|
||||
{
|
||||
gsk_render_node_diff_impossible (node1, node2, region);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
gsk_stroke_node_class_init (gpointer g_class,
|
||||
gpointer class_data)
|
||||
{
|
||||
GskRenderNodeClass *node_class = g_class;
|
||||
|
||||
node_class->node_type = GSK_STROKE_NODE;
|
||||
|
||||
node_class->finalize = gsk_stroke_node_finalize;
|
||||
node_class->draw = gsk_stroke_node_draw;
|
||||
node_class->diff = gsk_stroke_node_diff;
|
||||
}
|
||||
|
||||
/**
|
||||
* gsk_stroke_node_new:
|
||||
* @child: The node to stroke the area with
|
||||
* @path: (transfer none): The path describing the area to stroke
|
||||
* @stroke: (transfer none): The stroke attributes to use
|
||||
*
|
||||
* 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
|
||||
*
|
||||
* Since: 4.14
|
||||
*/
|
||||
GskRenderNode *
|
||||
gsk_stroke_node_new (GskRenderNode *child,
|
||||
GskPath *path,
|
||||
const GskStroke *stroke)
|
||||
{
|
||||
GskStrokeNode *self;
|
||||
GskRenderNode *node;
|
||||
graphene_rect_t stroke_bounds;
|
||||
|
||||
g_return_val_if_fail (GSK_IS_RENDER_NODE (child), NULL);
|
||||
g_return_val_if_fail (path != NULL, NULL);
|
||||
g_return_val_if_fail (stroke != NULL, NULL);
|
||||
|
||||
self = gsk_render_node_alloc (GSK_STROKE_NODE);
|
||||
node = (GskRenderNode *) self;
|
||||
|
||||
self->child = gsk_render_node_ref (child);
|
||||
self->path = gsk_path_ref (path);
|
||||
gsk_stroke_init_copy (&self->stroke, stroke);
|
||||
|
||||
if (gsk_path_get_stroke_bounds (self->path, &self->stroke, &stroke_bounds))
|
||||
graphene_rect_intersection (&stroke_bounds, &child->bounds, &node->bounds);
|
||||
else
|
||||
graphene_rect_init_from_rect (&node->bounds, graphene_rect_zero ());
|
||||
|
||||
return node;
|
||||
}
|
||||
|
||||
/**
|
||||
* gsk_stroke_node_get_child:
|
||||
* @node: (type GskStrokeNode): a stroke #GskRenderNode
|
||||
*
|
||||
* Gets the child node that is getting drawn by the given @node.
|
||||
*
|
||||
* Returns: (transfer none): The child that is getting drawn
|
||||
*
|
||||
* Since: 4.14
|
||||
*/
|
||||
GskRenderNode *
|
||||
gsk_stroke_node_get_child (const GskRenderNode *node)
|
||||
{
|
||||
const GskStrokeNode *self = (const GskStrokeNode *) node;
|
||||
|
||||
g_return_val_if_fail (GSK_IS_RENDER_NODE_TYPE (node, GSK_STROKE_NODE), NULL);
|
||||
|
||||
return self->child;
|
||||
}
|
||||
|
||||
/**
|
||||
* gsk_stroke_node_get_path:
|
||||
* @node: (type GskStrokeNode): a stroke #GskRenderNode
|
||||
*
|
||||
* Retrieves the path that will be stroked with the contents of
|
||||
* the @node.
|
||||
*
|
||||
* Returns: (transfer none): a #GskPath
|
||||
*
|
||||
* Since: 4.14
|
||||
*/
|
||||
GskPath *
|
||||
gsk_stroke_node_get_path (const GskRenderNode *node)
|
||||
{
|
||||
const GskStrokeNode *self = (const GskStrokeNode *) node;
|
||||
|
||||
g_return_val_if_fail (GSK_IS_RENDER_NODE_TYPE (node, GSK_STROKE_NODE), NULL);
|
||||
|
||||
return self->path;
|
||||
}
|
||||
|
||||
/**
|
||||
* gsk_stroke_node_get_stroke:
|
||||
* @node: (type GskStrokeNode): a stroke #GskRenderNode
|
||||
*
|
||||
* Retrieves the stroke attributes used in this @node.
|
||||
*
|
||||
* Returns: a #GskStroke
|
||||
*
|
||||
* Since: 4.14
|
||||
*/
|
||||
const GskStroke *
|
||||
gsk_stroke_node_get_stroke (const GskRenderNode *node)
|
||||
{
|
||||
const GskStrokeNode *self = (const GskStrokeNode *) node;
|
||||
|
||||
g_return_val_if_fail (GSK_IS_RENDER_NODE_TYPE (node, GSK_STROKE_NODE), NULL);
|
||||
|
||||
return &self->stroke;
|
||||
}
|
||||
|
||||
/* }}} */
|
||||
/* {{{ GSK_SHADOW_NODE */
|
||||
|
||||
@@ -6260,6 +6659,8 @@ GSK_DEFINE_RENDER_NODE_TYPE (gsk_color_matrix_node, GSK_COLOR_MATRIX_NODE)
|
||||
GSK_DEFINE_RENDER_NODE_TYPE (gsk_repeat_node, GSK_REPEAT_NODE)
|
||||
GSK_DEFINE_RENDER_NODE_TYPE (gsk_clip_node, GSK_CLIP_NODE)
|
||||
GSK_DEFINE_RENDER_NODE_TYPE (gsk_rounded_clip_node, GSK_ROUNDED_CLIP_NODE)
|
||||
GSK_DEFINE_RENDER_NODE_TYPE (gsk_fill_node, GSK_FILL_NODE)
|
||||
GSK_DEFINE_RENDER_NODE_TYPE (gsk_stroke_node, GSK_STROKE_NODE)
|
||||
GSK_DEFINE_RENDER_NODE_TYPE (gsk_shadow_node, GSK_SHADOW_NODE)
|
||||
GSK_DEFINE_RENDER_NODE_TYPE (gsk_blend_node, GSK_BLEND_NODE)
|
||||
GSK_DEFINE_RENDER_NODE_TYPE (gsk_cross_fade_node, GSK_CROSS_FADE_NODE)
|
||||
@@ -6408,6 +6809,16 @@ gsk_render_node_init_types_once (void)
|
||||
sizeof (GskDebugNode),
|
||||
gsk_debug_node_class_init);
|
||||
gsk_render_node_types[GSK_DEBUG_NODE] = node_type;
|
||||
|
||||
node_type = gsk_render_node_type_register_static (I_("GskFillNode"),
|
||||
sizeof (GskFillNode),
|
||||
gsk_fill_node_class_init);
|
||||
gsk_render_node_types[GSK_FILL_NODE] = node_type;
|
||||
|
||||
node_type = gsk_render_node_type_register_static (I_("GskStrokeNode"),
|
||||
sizeof (GskStrokeNode),
|
||||
gsk_stroke_node_class_init);
|
||||
gsk_render_node_types[GSK_STROKE_NODE] = node_type;
|
||||
}
|
||||
|
||||
static void
|
||||
|
||||
+278
-3
@@ -23,9 +23,13 @@
|
||||
|
||||
#include "gskrendernodeparserprivate.h"
|
||||
|
||||
#include "gskpath.h"
|
||||
#include "gskpathbuilder.h"
|
||||
#include "gskroundedrectprivate.h"
|
||||
#include "gskrendernodeprivate.h"
|
||||
#include "gskstroke.h"
|
||||
#include "gsktransformprivate.h"
|
||||
#include "gskenumtypes.h"
|
||||
|
||||
#include "gdk/gdkrgbaprivate.h"
|
||||
#include "gdk/gdktextureprivate.h"
|
||||
@@ -1174,6 +1178,26 @@ create_default_render_node (void)
|
||||
return gsk_color_node_new (&GDK_RGBA("FF00CC"), &GRAPHENE_RECT_INIT (0, 0, 50, 50));
|
||||
}
|
||||
|
||||
static GskPath *
|
||||
create_default_path (void)
|
||||
{
|
||||
GskPathBuilder *builder;
|
||||
guint i;
|
||||
|
||||
builder = gsk_path_builder_new ();
|
||||
|
||||
gsk_path_builder_move_to (builder, 25, 0);
|
||||
for (i = 1; i < 5; i++)
|
||||
{
|
||||
gsk_path_builder_line_to (builder,
|
||||
sin (i * G_PI * 0.8) * 25 + 25,
|
||||
-cos (i * G_PI * 0.8) * 25 + 25);
|
||||
}
|
||||
gsk_path_builder_close (builder);
|
||||
|
||||
return gsk_path_builder_free_to_path (builder);
|
||||
}
|
||||
|
||||
static GskRenderNode *
|
||||
parse_color_node (GtkCssParser *parser,
|
||||
Context *context)
|
||||
@@ -2097,6 +2121,165 @@ parse_rounded_clip_node (GtkCssParser *parser,
|
||||
return result;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
parse_path (GtkCssParser *parser,
|
||||
Context *context,
|
||||
gpointer out_path)
|
||||
{
|
||||
GskPath *path;
|
||||
char *str = NULL;
|
||||
|
||||
if (!parse_string (parser, context, &str))
|
||||
return FALSE;
|
||||
|
||||
path = gsk_path_parse (str);
|
||||
g_free (str);
|
||||
|
||||
if (path == NULL)
|
||||
{
|
||||
gtk_css_parser_error_value (parser, "Invalid path");
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
*((GskPath **) out_path) = path;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
clear_path (gpointer inout_path)
|
||||
{
|
||||
g_clear_pointer ((GskPath **) inout_path, gsk_path_unref);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
parse_enum (GtkCssParser *parser,
|
||||
GType type,
|
||||
gpointer out_value)
|
||||
{
|
||||
GEnumClass *class;
|
||||
GEnumValue *v;
|
||||
char *enum_name;
|
||||
|
||||
enum_name = gtk_css_parser_consume_ident (parser);
|
||||
if (enum_name == NULL)
|
||||
return FALSE;
|
||||
|
||||
class = g_type_class_ref (type);
|
||||
|
||||
v = g_enum_get_value_by_nick (class, enum_name);
|
||||
if (v == NULL)
|
||||
{
|
||||
gtk_css_parser_error_value (parser, "Unknown value \"%s\" for enum \"%s\"",
|
||||
enum_name, g_type_name (type));
|
||||
g_free (enum_name);
|
||||
g_type_class_unref (class);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
*(int*)out_value = v->value;
|
||||
|
||||
g_free (enum_name);
|
||||
g_type_class_unref (class);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
parse_fill_rule (GtkCssParser *parser,
|
||||
Context *context,
|
||||
gpointer out_rule)
|
||||
{
|
||||
return parse_enum (parser, GSK_TYPE_FILL_RULE, out_rule);
|
||||
}
|
||||
|
||||
static GskRenderNode *
|
||||
parse_fill_node (GtkCssParser *parser,
|
||||
Context *context)
|
||||
{
|
||||
GskRenderNode *child = NULL;
|
||||
GskPath *path = NULL;
|
||||
int rule = GSK_FILL_RULE_WINDING;
|
||||
const Declaration declarations[] = {
|
||||
{ "child", parse_node, clear_node, &child },
|
||||
{ "path", parse_path, clear_path, &path },
|
||||
{ "fill-rule", parse_fill_rule, NULL, &rule },
|
||||
};
|
||||
GskRenderNode *result;
|
||||
|
||||
parse_declarations (parser, context, declarations, G_N_ELEMENTS (declarations));
|
||||
if (child == NULL)
|
||||
child = create_default_render_node ();
|
||||
if (path == NULL)
|
||||
path = create_default_path ();
|
||||
|
||||
result = gsk_fill_node_new (child, path, rule);
|
||||
|
||||
gsk_path_unref (path);
|
||||
|
||||
gsk_render_node_unref (child);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static gboolean
|
||||
parse_line_cap (GtkCssParser *parser,
|
||||
Context *context,
|
||||
gpointer out)
|
||||
{
|
||||
return parse_enum (parser, GSK_TYPE_LINE_CAP, out);
|
||||
}
|
||||
|
||||
static gboolean
|
||||
parse_line_join (GtkCssParser *parser,
|
||||
Context *context,
|
||||
gpointer out)
|
||||
{
|
||||
return parse_enum (parser, GSK_TYPE_LINE_JOIN, out);
|
||||
}
|
||||
|
||||
static GskRenderNode *
|
||||
parse_stroke_node (GtkCssParser *parser,
|
||||
Context *context)
|
||||
{
|
||||
GskRenderNode *child = NULL;
|
||||
GskPath *path = NULL;
|
||||
double line_width = 1.0;
|
||||
int line_cap = GSK_LINE_CAP_BUTT;
|
||||
int line_join = GSK_LINE_JOIN_MITER;
|
||||
double miter_limit = 4.0;
|
||||
GskStroke *stroke;
|
||||
|
||||
const Declaration declarations[] = {
|
||||
{ "child", parse_node, clear_node, &child },
|
||||
{ "path", parse_path, clear_path, &path },
|
||||
{ "line-width", parse_positive_double, NULL, &line_width },
|
||||
{ "line-cap", parse_line_cap, NULL, &line_cap },
|
||||
{ "line-join", parse_line_join, NULL, &line_join },
|
||||
{ "miter-limit", parse_positive_double, NULL, &miter_limit }
|
||||
};
|
||||
GskRenderNode *result;
|
||||
|
||||
parse_declarations (parser, context, declarations, G_N_ELEMENTS (declarations));
|
||||
if (child == NULL)
|
||||
child = create_default_render_node ();
|
||||
if (path == NULL)
|
||||
path = create_default_path ();
|
||||
|
||||
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);
|
||||
|
||||
result = gsk_stroke_node_new (child, path, stroke);
|
||||
|
||||
gsk_path_unref (path);
|
||||
gsk_stroke_free (stroke);
|
||||
gsk_render_node_unref (child);
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
static GskRenderNode *
|
||||
parse_shadow_node (GtkCssParser *parser,
|
||||
Context *context)
|
||||
@@ -2179,6 +2362,8 @@ parse_node (GtkCssParser *parser,
|
||||
{ "repeating-linear-gradient", parse_repeating_linear_gradient_node },
|
||||
{ "repeating-radial-gradient", parse_repeating_radial_gradient_node },
|
||||
{ "rounded-clip", parse_rounded_clip_node },
|
||||
{ "fill", parse_fill_node },
|
||||
{ "stroke", parse_stroke_node },
|
||||
{ "shadow", parse_shadow_node },
|
||||
{ "text", parse_text_node },
|
||||
{ "texture", parse_texture_node },
|
||||
@@ -2433,6 +2618,14 @@ printer_init_duplicates_for_node (Printer *printer,
|
||||
printer_init_duplicates_for_node (printer, gsk_debug_node_get_child (node));
|
||||
break;
|
||||
|
||||
case GSK_FILL_NODE:
|
||||
printer_init_duplicates_for_node (printer, gsk_fill_node_get_child (node));
|
||||
break;
|
||||
|
||||
case GSK_STROKE_NODE:
|
||||
printer_init_duplicates_for_node (printer, gsk_stroke_node_get_child (node));
|
||||
break;
|
||||
|
||||
case GSK_BLEND_NODE:
|
||||
printer_init_duplicates_for_node (printer, gsk_blend_node_get_bottom_child (node));
|
||||
printer_init_duplicates_for_node (printer, gsk_blend_node_get_top_child (node));
|
||||
@@ -2658,7 +2851,7 @@ append_float_param (Printer *p,
|
||||
float value,
|
||||
float default_value)
|
||||
{
|
||||
/* Don't approximate-compare here, better be topo verbose */
|
||||
/* Don't approximate-compare here, better be too verbose */
|
||||
if (value == default_value)
|
||||
return;
|
||||
|
||||
@@ -2833,8 +3026,11 @@ append_escaping_newlines (GString *str,
|
||||
len = strcspn (string, "\n");
|
||||
g_string_append_len (str, string, len);
|
||||
string += len;
|
||||
g_string_append (str, "\\\n");
|
||||
string++;
|
||||
if (*string)
|
||||
{
|
||||
g_string_append (str, "\\\n");
|
||||
string++;
|
||||
}
|
||||
} while (*string);
|
||||
}
|
||||
|
||||
@@ -3035,6 +3231,55 @@ gsk_text_node_serialize_glyphs (GskRenderNode *node,
|
||||
pango_glyph_string_free (ascii);
|
||||
}
|
||||
|
||||
static const char *
|
||||
enum_to_nick (GType type,
|
||||
int value)
|
||||
{
|
||||
GEnumClass *class;
|
||||
GEnumValue *v;
|
||||
|
||||
class = g_type_class_ref (type);
|
||||
v = g_enum_get_value (class, value);
|
||||
g_type_class_unref (class);
|
||||
|
||||
return v->value_nick;
|
||||
}
|
||||
|
||||
static void
|
||||
append_enum_param (Printer *p,
|
||||
const char *param_name,
|
||||
GType type,
|
||||
int value)
|
||||
{
|
||||
_indent (p);
|
||||
g_string_append_printf (p->str, "%s: ", param_name);
|
||||
g_string_append (p->str, enum_to_nick (type, value));
|
||||
g_string_append_c (p->str, ';');
|
||||
g_string_append_c (p->str, '\n');
|
||||
}
|
||||
|
||||
static void
|
||||
append_path_param (Printer *p,
|
||||
const char *param_name,
|
||||
GskPath *path)
|
||||
{
|
||||
char *str, *s;
|
||||
|
||||
_indent (p);
|
||||
g_string_append (p->str, "path: \"\\\n");
|
||||
str = gsk_path_to_string (path);
|
||||
/* Put each command on a new line */
|
||||
for (s = str; *s; s++)
|
||||
{
|
||||
if (*s == ' ' &&
|
||||
(s[1] == 'M' || s[1] == 'C' || s[1] == 'Z' || s[1] == 'L'))
|
||||
*s = '\n';
|
||||
}
|
||||
append_escaping_newlines (p->str, str);
|
||||
g_string_append (p->str, "\";\n");
|
||||
g_free (str);
|
||||
}
|
||||
|
||||
static void
|
||||
render_node_print (Printer *p,
|
||||
GskRenderNode *node)
|
||||
@@ -3204,6 +3449,36 @@ render_node_print (Printer *p,
|
||||
append_rounded_rect_param (p, "clip", gsk_rounded_clip_node_get_clip (node));
|
||||
append_node_param (p, "child", gsk_rounded_clip_node_get_child (node));
|
||||
|
||||
end_node (p);
|
||||
}
|
||||
break;
|
||||
|
||||
case GSK_FILL_NODE:
|
||||
{
|
||||
start_node (p, "fill", node_name);
|
||||
|
||||
append_node_param (p, "child", gsk_fill_node_get_child (node));
|
||||
append_path_param (p, "path", gsk_fill_node_get_path (node));
|
||||
append_enum_param (p, "fill-rule", GSK_TYPE_FILL_RULE, gsk_fill_node_get_fill_rule (node));
|
||||
|
||||
end_node (p);
|
||||
}
|
||||
break;
|
||||
|
||||
case GSK_STROKE_NODE:
|
||||
{
|
||||
const GskStroke *stroke;
|
||||
|
||||
start_node (p, "stroke", node_name);
|
||||
|
||||
append_node_param (p, "child", gsk_stroke_node_get_child (node));
|
||||
append_path_param (p, "path", gsk_stroke_node_get_path (node));
|
||||
|
||||
stroke = gsk_stroke_node_get_stroke (node);
|
||||
append_float_param (p, "line-width", gsk_stroke_get_line_width (stroke), 0.0f);
|
||||
append_enum_param (p, "line-cap", GSK_TYPE_LINE_CAP, gsk_stroke_get_line_cap (stroke));
|
||||
append_enum_param (p, "line-join", GSK_TYPE_LINE_JOIN, gsk_stroke_get_line_join (stroke));
|
||||
append_float_param (p, "miter-limit", gsk_stroke_get_miter_limit (stroke), 4.0f);
|
||||
|
||||
end_node (p);
|
||||
}
|
||||
|
||||
+208
@@ -0,0 +1,208 @@
|
||||
/*
|
||||
* Copyright © 2002 University of Southern California
|
||||
* 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>
|
||||
* Carl D. Worth <cworth@cworth.org>
|
||||
*/
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "gsksplineprivate.h"
|
||||
|
||||
#include <math.h>
|
||||
|
||||
/* Spline deviation from the circle in radius would be given by:
|
||||
|
||||
error = sqrt (x**2 + y**2) - 1
|
||||
|
||||
A simpler error function to work with is:
|
||||
|
||||
e = x**2 + y**2 - 1
|
||||
|
||||
From "Good approximation of circles by curvature-continuous Bezier
|
||||
curves", Tor Dokken and Morten Daehlen, Computer Aided Geometric
|
||||
Design 8 (1990) 22-41, we learn:
|
||||
|
||||
abs (max(e)) = 4/27 * sin**6(angle/4) / cos**2(angle/4)
|
||||
|
||||
and
|
||||
abs (error) =~ 1/2 * e
|
||||
|
||||
Of course, this error value applies only for the particular spline
|
||||
approximation that is used in _cairo_gstate_arc_segment.
|
||||
*/
|
||||
static float
|
||||
arc_error_normalized (float angle)
|
||||
{
|
||||
return 2.0/27.0 * pow (sin (angle / 4), 6) / pow (cos (angle / 4), 2);
|
||||
}
|
||||
|
||||
static float
|
||||
arc_max_angle_for_tolerance_normalized (float tolerance)
|
||||
{
|
||||
float angle, error;
|
||||
guint i;
|
||||
|
||||
/* Use table lookup to reduce search time in most cases. */
|
||||
struct {
|
||||
float angle;
|
||||
float error;
|
||||
} table[] = {
|
||||
{ G_PI / 1.0, 0.0185185185185185036127 },
|
||||
{ G_PI / 2.0, 0.000272567143730179811158 },
|
||||
{ G_PI / 3.0, 2.38647043651461047433e-05 },
|
||||
{ G_PI / 4.0, 4.2455377443222443279e-06 },
|
||||
{ G_PI / 5.0, 1.11281001494389081528e-06 },
|
||||
{ G_PI / 6.0, 3.72662000942734705475e-07 },
|
||||
{ G_PI / 7.0, 1.47783685574284411325e-07 },
|
||||
{ G_PI / 8.0, 6.63240432022601149057e-08 },
|
||||
{ G_PI / 9.0, 3.2715520137536980553e-08 },
|
||||
{ G_PI / 10.0, 1.73863223499021216974e-08 },
|
||||
{ G_PI / 11.0, 9.81410988043554039085e-09 },
|
||||
};
|
||||
|
||||
for (i = 0; i < G_N_ELEMENTS (table); i++)
|
||||
{
|
||||
if (table[i].error < tolerance)
|
||||
return table[i].angle;
|
||||
}
|
||||
|
||||
i++;
|
||||
do {
|
||||
angle = G_PI / i++;
|
||||
error = arc_error_normalized (angle);
|
||||
} while (error > tolerance);
|
||||
|
||||
return angle;
|
||||
}
|
||||
|
||||
static guint
|
||||
arc_segments_needed (float angle,
|
||||
float radius,
|
||||
float tolerance)
|
||||
{
|
||||
float max_angle;
|
||||
|
||||
/* the error is amplified by at most the length of the
|
||||
* major axis of the circle; see cairo-pen.c for a more detailed analysis
|
||||
* of this. */
|
||||
max_angle = arc_max_angle_for_tolerance_normalized (tolerance / radius);
|
||||
|
||||
return ceil (fabs (angle) / max_angle);
|
||||
}
|
||||
|
||||
/* We want to draw a single spline approximating a circular arc radius
|
||||
R from angle A to angle B. Since we want a symmetric spline that
|
||||
matches the endpoints of the arc in position and slope, we know
|
||||
that the spline control points must be:
|
||||
|
||||
(R * cos(A), R * sin(A))
|
||||
(R * cos(A) - h * sin(A), R * sin(A) + h * cos (A))
|
||||
(R * cos(B) + h * sin(B), R * sin(B) - h * cos (B))
|
||||
(R * cos(B), R * sin(B))
|
||||
|
||||
for some value of h.
|
||||
|
||||
"Approximation of circular arcs by cubic polynomials", Michael
|
||||
Goldapp, Computer Aided Geometric Design 8 (1991) 227-238, provides
|
||||
various values of h along with error analysis for each.
|
||||
|
||||
From that paper, a very practical value of h is:
|
||||
|
||||
h = 4/3 * R * tan(angle/4)
|
||||
|
||||
This value does not give the spline with minimal error, but it does
|
||||
provide a very good approximation, (6th-order convergence), and the
|
||||
error expression is quite simple, (see the comment for
|
||||
_arc_error_normalized).
|
||||
*/
|
||||
static gboolean
|
||||
gsk_spline_decompose_arc_segment (const graphene_point_t *center,
|
||||
float radius,
|
||||
float angle_A,
|
||||
float angle_B,
|
||||
GskSplineAddCurveFunc curve_func,
|
||||
gpointer user_data)
|
||||
{
|
||||
float r_sin_A, r_cos_A;
|
||||
float r_sin_B, r_cos_B;
|
||||
float h;
|
||||
|
||||
r_sin_A = radius * sin (angle_A);
|
||||
r_cos_A = radius * cos (angle_A);
|
||||
r_sin_B = radius * sin (angle_B);
|
||||
r_cos_B = radius * cos (angle_B);
|
||||
|
||||
h = 4.0/3.0 * tan ((angle_B - angle_A) / 4.0);
|
||||
|
||||
return curve_func ((graphene_point_t[4]) {
|
||||
GRAPHENE_POINT_INIT (
|
||||
center->x + r_cos_A,
|
||||
center->y + r_sin_A
|
||||
),
|
||||
GRAPHENE_POINT_INIT (
|
||||
center->x + r_cos_A - h * r_sin_A,
|
||||
center->y + r_sin_A + h * r_cos_A
|
||||
),
|
||||
GRAPHENE_POINT_INIT (
|
||||
center->x + r_cos_B + h * r_sin_B,
|
||||
center->y + r_sin_B - h * r_cos_B
|
||||
),
|
||||
GRAPHENE_POINT_INIT (
|
||||
center->x + r_cos_B,
|
||||
center->y + r_sin_B
|
||||
)
|
||||
},
|
||||
user_data);
|
||||
}
|
||||
|
||||
gboolean
|
||||
gsk_spline_decompose_arc (const graphene_point_t *center,
|
||||
float radius,
|
||||
float tolerance,
|
||||
float start_angle,
|
||||
float end_angle,
|
||||
GskSplineAddCurveFunc curve_func,
|
||||
gpointer user_data)
|
||||
{
|
||||
float step = start_angle - end_angle;
|
||||
guint i, n_segments;
|
||||
|
||||
/* Recurse if drawing arc larger than pi */
|
||||
if (ABS (step) > G_PI)
|
||||
{
|
||||
float mid_angle = (start_angle + end_angle) / 2.0;
|
||||
|
||||
return gsk_spline_decompose_arc (center, radius, tolerance, start_angle, mid_angle, curve_func, user_data)
|
||||
&& gsk_spline_decompose_arc (center, radius, tolerance, mid_angle, end_angle, curve_func, user_data);
|
||||
}
|
||||
else if (ABS (step) < tolerance)
|
||||
{
|
||||
return gsk_spline_decompose_arc_segment (center, radius, start_angle, end_angle, curve_func, user_data);
|
||||
}
|
||||
|
||||
n_segments = arc_segments_needed (ABS (step), radius, tolerance);
|
||||
step = (end_angle - start_angle) / n_segments;
|
||||
|
||||
for (i = 0; i < n_segments - 1; i++, start_angle += step)
|
||||
{
|
||||
if (!gsk_spline_decompose_arc_segment (center, radius, start_angle, start_angle + step, curve_func, user_data))
|
||||
return FALSE;
|
||||
}
|
||||
return gsk_spline_decompose_arc_segment (center, radius, start_angle, end_angle, curve_func, user_data);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,41 @@
|
||||
/*
|
||||
* 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>
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __GSK_SPLINE_PRIVATE_H__
|
||||
#define __GSK_SPLINE_PRIVATE_H__
|
||||
|
||||
#include "gskpath.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
typedef gboolean (* GskSplineAddCurveFunc) (const graphene_point_t curve[4],
|
||||
gpointer user_data);
|
||||
gboolean gsk_spline_decompose_arc (const graphene_point_t *center,
|
||||
float radius,
|
||||
float tolerance,
|
||||
float start_angle,
|
||||
float end_angle,
|
||||
GskSplineAddCurveFunc curve_func,
|
||||
gpointer user_data);
|
||||
|
||||
G_END_DECLS
|
||||
|
||||
#endif /* __GSK_SPLINE_PRIVATE_H__ */
|
||||
|
||||
+535
@@ -0,0 +1,535 @@
|
||||
/*
|
||||
* 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 "gskstrokeprivate.h"
|
||||
|
||||
/**
|
||||
* GskStroke:
|
||||
*
|
||||
* A `GskStroke` struct collects the parameters that influence
|
||||
* the operation of stroking a path.
|
||||
*/
|
||||
|
||||
G_DEFINE_BOXED_TYPE (GskStroke, gsk_stroke, gsk_stroke_copy, gsk_stroke_free)
|
||||
|
||||
|
||||
/**
|
||||
* gsk_stroke_new:
|
||||
* @line_width: line width of the stroke. Must be > 0
|
||||
*
|
||||
* Creates a new `GskStroke` with the given @line_width.
|
||||
*
|
||||
* Returns: a new `GskStroke`
|
||||
*
|
||||
* Since: 4.14
|
||||
*/
|
||||
GskStroke *
|
||||
gsk_stroke_new (float line_width)
|
||||
{
|
||||
GskStroke *self;
|
||||
|
||||
g_return_val_if_fail (line_width > 0, NULL);
|
||||
|
||||
self = g_new0 (GskStroke, 1);
|
||||
|
||||
self->line_width = line_width;
|
||||
self->line_cap = GSK_LINE_CAP_BUTT;
|
||||
self->line_join = GSK_LINE_JOIN_MITER;
|
||||
self->miter_limit = 4.f; /* following svg */
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
/**
|
||||
* gsk_stroke_copy:
|
||||
* @other: `GskStroke` to copy
|
||||
*
|
||||
* Creates a copy of the given @other stroke.
|
||||
*
|
||||
* Returns: a new `GskStroke`. Use [method@Gsk.Stroke.free] to free it
|
||||
*
|
||||
* Since: 4.14
|
||||
*/
|
||||
GskStroke *
|
||||
gsk_stroke_copy (const GskStroke *other)
|
||||
{
|
||||
GskStroke *self;
|
||||
|
||||
g_return_val_if_fail (other != NULL, NULL);
|
||||
|
||||
self = g_new (GskStroke, 1);
|
||||
|
||||
gsk_stroke_init_copy (self, other);
|
||||
|
||||
return self;
|
||||
}
|
||||
|
||||
/**
|
||||
* gsk_stroke_free:
|
||||
* @self: a `GskStroke`
|
||||
*
|
||||
* Frees a `GskStroke`.
|
||||
*
|
||||
* Since: 4.14
|
||||
*/
|
||||
void
|
||||
gsk_stroke_free (GskStroke *self)
|
||||
{
|
||||
if (self == NULL)
|
||||
return;
|
||||
|
||||
gsk_stroke_clear (self);
|
||||
|
||||
g_free (self);
|
||||
}
|
||||
|
||||
/**
|
||||
* gsk_stroke_to_cairo:
|
||||
* @self: a `GskStroke`
|
||||
* @cr: the cairo context to configure
|
||||
*
|
||||
* A helper function that sets the stroke parameters
|
||||
* of @cr from the values found in @self.
|
||||
*
|
||||
* Since: 4.14
|
||||
*/
|
||||
void
|
||||
gsk_stroke_to_cairo (const GskStroke *self,
|
||||
cairo_t *cr)
|
||||
{
|
||||
cairo_set_line_width (cr, self->line_width);
|
||||
|
||||
/* gcc can optimize that to a direct case. This catches later additions to the enum */
|
||||
switch (self->line_cap)
|
||||
{
|
||||
case GSK_LINE_CAP_BUTT:
|
||||
cairo_set_line_cap (cr, CAIRO_LINE_CAP_BUTT);
|
||||
break;
|
||||
case GSK_LINE_CAP_ROUND:
|
||||
cairo_set_line_cap (cr, CAIRO_LINE_CAP_ROUND);
|
||||
break;
|
||||
case GSK_LINE_CAP_SQUARE:
|
||||
cairo_set_line_cap (cr, CAIRO_LINE_CAP_SQUARE);
|
||||
break;
|
||||
default:
|
||||
g_assert_not_reached ();
|
||||
break;
|
||||
}
|
||||
|
||||
/* gcc can optimize that to a direct case. This catches later additions to the enum */
|
||||
switch (self->line_join)
|
||||
{
|
||||
case GSK_LINE_JOIN_MITER:
|
||||
cairo_set_line_join (cr, CAIRO_LINE_JOIN_MITER);
|
||||
break;
|
||||
case GSK_LINE_JOIN_ROUND:
|
||||
cairo_set_line_join (cr, CAIRO_LINE_JOIN_ROUND);
|
||||
break;
|
||||
case GSK_LINE_JOIN_BEVEL:
|
||||
cairo_set_line_join (cr, CAIRO_LINE_JOIN_BEVEL);
|
||||
break;
|
||||
default:
|
||||
g_assert_not_reached ();
|
||||
break;
|
||||
}
|
||||
|
||||
cairo_set_miter_limit (cr, self->miter_limit);
|
||||
|
||||
if (self->dash_length)
|
||||
{
|
||||
gsize i;
|
||||
double *dash = g_newa (double, self->n_dash);
|
||||
|
||||
for (i = 0; i < self->n_dash; i++)
|
||||
{
|
||||
dash[i] = self->dash[i];
|
||||
}
|
||||
cairo_set_dash (cr, dash, self->n_dash, self->dash_offset);
|
||||
}
|
||||
else
|
||||
cairo_set_dash (cr, NULL, 0, 0.0);
|
||||
}
|
||||
|
||||
/**
|
||||
* gsk_stroke_equal:
|
||||
* @stroke1: the first `GskStroke`
|
||||
* @stroke2: the second `GskStroke`
|
||||
*
|
||||
* Checks if 2 strokes are identical.
|
||||
*
|
||||
* Returns: `TRUE` if the 2 strokes are equal, `FALSE` otherwise
|
||||
*
|
||||
* Since: 4.14
|
||||
*/
|
||||
gboolean
|
||||
gsk_stroke_equal (gconstpointer stroke1,
|
||||
gconstpointer stroke2)
|
||||
{
|
||||
const GskStroke *self1 = stroke1;
|
||||
const GskStroke *self2 = stroke2;
|
||||
|
||||
if (self1->line_width != self2->line_width ||
|
||||
self1->line_cap != self2->line_cap ||
|
||||
self1->line_join != self2->line_join ||
|
||||
self1->miter_limit != self2->miter_limit ||
|
||||
self1->n_dash != self2->n_dash ||
|
||||
self1->dash_offset != self2->dash_offset)
|
||||
return FALSE;
|
||||
|
||||
for (gsize i = 0; i < self1->n_dash; i++)
|
||||
if (self1->dash[i] != self2->dash[i])
|
||||
return FALSE;
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* gsk_stroke_set_line_width:
|
||||
* @self: a `GskStroke`
|
||||
* @line_width: width of the line in pixels
|
||||
*
|
||||
* Sets the line width to be used when stroking.
|
||||
*
|
||||
* The line width must be > 0.
|
||||
*
|
||||
* Since: 4.14
|
||||
*/
|
||||
void
|
||||
gsk_stroke_set_line_width (GskStroke *self,
|
||||
float line_width)
|
||||
{
|
||||
g_return_if_fail (self != NULL);
|
||||
g_return_if_fail (line_width > 0);
|
||||
|
||||
self->line_width = line_width;
|
||||
}
|
||||
|
||||
/**
|
||||
* gsk_stroke_get_line_width:
|
||||
* @self: a `GskStroke`
|
||||
*
|
||||
* Gets the line width used.
|
||||
*
|
||||
* Returns: The line width
|
||||
*
|
||||
* Since: 4.14
|
||||
*/
|
||||
float
|
||||
gsk_stroke_get_line_width (const GskStroke *self)
|
||||
{
|
||||
g_return_val_if_fail (self != NULL, 0.0);
|
||||
|
||||
return self->line_width;
|
||||
}
|
||||
|
||||
/**
|
||||
* gsk_stroke_set_line_cap:
|
||||
* @self: a`GskStroke`
|
||||
* @line_cap: the `GskLineCap`
|
||||
*
|
||||
* Sets the line cap to be used when stroking.
|
||||
*
|
||||
* See [enum@Gsk.LineCap] for details.
|
||||
*
|
||||
* Since: 4.14
|
||||
*/
|
||||
void
|
||||
gsk_stroke_set_line_cap (GskStroke *self,
|
||||
GskLineCap line_cap)
|
||||
{
|
||||
g_return_if_fail (self != NULL);
|
||||
|
||||
self->line_cap = line_cap;
|
||||
}
|
||||
|
||||
/**
|
||||
* gsk_stroke_get_line_cap:
|
||||
* @self: a `GskStroke`
|
||||
*
|
||||
* Gets the line cap used.
|
||||
*
|
||||
* See [enum@Gsk.LineCap] for details.
|
||||
*
|
||||
* Returns: The line cap
|
||||
*
|
||||
* Since: 4.14
|
||||
*/
|
||||
GskLineCap
|
||||
gsk_stroke_get_line_cap (const GskStroke *self)
|
||||
{
|
||||
g_return_val_if_fail (self != NULL, 0.0);
|
||||
|
||||
return self->line_cap;
|
||||
}
|
||||
|
||||
/**
|
||||
* gsk_stroke_set_line_join:
|
||||
* @self: a `GskStroke`
|
||||
* @line_join: The line join to use
|
||||
*
|
||||
* Sets the line join to be used when stroking.
|
||||
*
|
||||
* See [enum@Gsk.LineJoin] for details.
|
||||
*
|
||||
* Since: 4.14
|
||||
*/
|
||||
void
|
||||
gsk_stroke_set_line_join (GskStroke *self,
|
||||
GskLineJoin line_join)
|
||||
{
|
||||
g_return_if_fail (self != NULL);
|
||||
|
||||
self->line_join = line_join;
|
||||
}
|
||||
|
||||
/**
|
||||
* gsk_stroke_get_line_join:
|
||||
* @self: a `GskStroke`
|
||||
*
|
||||
* Gets the line join used.
|
||||
*
|
||||
* See [enum@Gsk.LineJoin] for details.
|
||||
*
|
||||
* Returns: The line join
|
||||
*
|
||||
* Since: 4.14
|
||||
*/
|
||||
GskLineJoin
|
||||
gsk_stroke_get_line_join (const GskStroke *self)
|
||||
{
|
||||
g_return_val_if_fail (self != NULL, 0.0);
|
||||
|
||||
return self->line_join;
|
||||
}
|
||||
|
||||
/**
|
||||
* gsk_stroke_set_miter_limit:
|
||||
* @self: a `GskStroke`
|
||||
* @limit: the miter limit
|
||||
*
|
||||
* Sets the limit for the distance from the corner where sharp
|
||||
* turns of joins get cut off.
|
||||
*
|
||||
* The miter limit is in units of line width and must be non-negative.
|
||||
*
|
||||
* For joins of type `GSK_LINE_JOIN_MITER` that exceed the miter
|
||||
* limit, the join gets rendered as if it was of type
|
||||
* `GSK_LINE_JOIN_BEVEL`.
|
||||
*
|
||||
* Since: 4.14
|
||||
*/
|
||||
void
|
||||
gsk_stroke_set_miter_limit (GskStroke *self,
|
||||
float limit)
|
||||
{
|
||||
g_return_if_fail (self != NULL);
|
||||
g_return_if_fail (limit >= 0);
|
||||
|
||||
self->miter_limit = limit;
|
||||
}
|
||||
|
||||
/**
|
||||
* gsk_stroke_get_miter_limit:
|
||||
* @self: a `GskStroke`
|
||||
*
|
||||
* Returns the miter limit of a `GskStroke`.
|
||||
*
|
||||
* Since: 4.14
|
||||
*/
|
||||
float
|
||||
gsk_stroke_get_miter_limit (const GskStroke *self)
|
||||
{
|
||||
g_return_val_if_fail (self != NULL, 4.f);
|
||||
|
||||
return self->miter_limit;
|
||||
}
|
||||
|
||||
/**
|
||||
* gsk_stroke_set_dash:
|
||||
* @self: a `GskStroke`
|
||||
* @dash: (array length=n_dash) (transfer none) (nullable):
|
||||
* the array of dashes
|
||||
* @n_dash: number of elements in @dash
|
||||
*
|
||||
* Sets the dash pattern to use by this stroke.
|
||||
*
|
||||
* A dash pattern is specified by an array of alternating non-negative
|
||||
* values. Each value provides the length of alternate "on" and "off"
|
||||
* portions of the stroke.
|
||||
*
|
||||
* Each "on" segment will have caps applied as if the segment were a
|
||||
* separate contour. In particular, it is valid to use an "on" length
|
||||
* of 0 with `GSK_LINE_CAP_ROUND` or `GSK_LINE_CAP_SQUARE` to draw dots
|
||||
* or squares along a path.
|
||||
*
|
||||
* If @n_dash is 0, if all elements in @dash are 0, or if there are
|
||||
* negative values in @dash, then dashing is disabled.
|
||||
*
|
||||
* If @n_dash is 1, an alternating "on" and "off" pattern with the
|
||||
* single dash length provided is assumed.
|
||||
*
|
||||
* If @n_dash is uneven, the dash array will be used with the first
|
||||
* element in @dash defining an "on" or "off" in alternating passes
|
||||
* through the array.
|
||||
*
|
||||
* You can specify a starting offset into the dash with
|
||||
* [method@Gsk.Stroke.set_dash_offset].
|
||||
*
|
||||
* Since: 4.14
|
||||
*/
|
||||
void
|
||||
gsk_stroke_set_dash (GskStroke *self,
|
||||
const float *dash,
|
||||
gsize n_dash)
|
||||
{
|
||||
float dash_length;
|
||||
gsize i;
|
||||
|
||||
g_return_if_fail (self != NULL);
|
||||
g_return_if_fail (dash != NULL || n_dash == 0);
|
||||
|
||||
dash_length = 0;
|
||||
for (i = 0; i < n_dash; i++)
|
||||
{
|
||||
if (!(dash[i] >= 0)) /* should catch NaN */
|
||||
{
|
||||
g_critical ("invalid value in dash array at position %zu", i);
|
||||
return;
|
||||
}
|
||||
dash_length += dash[i];
|
||||
}
|
||||
|
||||
self->dash_length = dash_length;
|
||||
g_free (self->dash);
|
||||
self->dash = g_memdup (dash, sizeof (gfloat) * n_dash);
|
||||
self->n_dash = n_dash;
|
||||
}
|
||||
|
||||
/**
|
||||
* gsk_stroke_get_dash:
|
||||
* @self: a `GskStroke`
|
||||
* @n_dash: (out caller-allocates): number of elements
|
||||
* in the array returned
|
||||
*
|
||||
* Gets the dash array in use or `NULL` if dashing is disabled.
|
||||
*
|
||||
* Returns: (array length=n_dash) (transfer none) (nullable):
|
||||
* The dash array or `NULL` if the dash array is empty.
|
||||
*
|
||||
* Since: 4.14
|
||||
*/
|
||||
const float *
|
||||
gsk_stroke_get_dash (const GskStroke *self,
|
||||
gsize *n_dash)
|
||||
{
|
||||
g_return_val_if_fail (self != NULL, NULL);
|
||||
g_return_val_if_fail (n_dash != NULL, NULL);
|
||||
|
||||
*n_dash = self->n_dash;
|
||||
|
||||
return self->dash;
|
||||
}
|
||||
|
||||
/**
|
||||
* gsk_stroke_set_dash_offset:
|
||||
* @self: a `GskStroke`
|
||||
* @offset: offset into the dash pattern
|
||||
*
|
||||
* Sets the offset into the dash pattern where dashing should begin.
|
||||
*
|
||||
* This is an offset into the length of the path, not an index into
|
||||
* the array values of the dash array.
|
||||
*
|
||||
* See [method@Gsk.Stroke.set_dash] for more details on dashing.
|
||||
*
|
||||
* Since: 4.14
|
||||
*/
|
||||
void
|
||||
gsk_stroke_set_dash_offset (GskStroke *self,
|
||||
float offset)
|
||||
{
|
||||
g_return_if_fail (self != NULL);
|
||||
|
||||
self->dash_offset = offset;
|
||||
}
|
||||
|
||||
/**
|
||||
* gsk_stroke_get_dash_offset:
|
||||
* @self: a `GskStroke`
|
||||
*
|
||||
* Returns the dash_offset of a `GskStroke`.
|
||||
*
|
||||
* Since: 4.14
|
||||
*/
|
||||
float
|
||||
gsk_stroke_get_dash_offset (const GskStroke *self)
|
||||
{
|
||||
g_return_val_if_fail (self != NULL, 4.f);
|
||||
|
||||
return self->dash_offset;
|
||||
}
|
||||
|
||||
/*< private >
|
||||
* gsk_stroke_get_join_width:
|
||||
* @stroke: a `GskStroke`
|
||||
*
|
||||
* Return a width that is sufficient to use
|
||||
* when calculating stroke bounds around joins
|
||||
* and caps.
|
||||
*
|
||||
* Returns: the join width
|
||||
*/
|
||||
float
|
||||
gsk_stroke_get_join_width (const GskStroke *stroke)
|
||||
{
|
||||
float width;
|
||||
|
||||
switch (stroke->line_cap)
|
||||
{
|
||||
case GSK_LINE_CAP_BUTT:
|
||||
width = 0;
|
||||
break;
|
||||
case GSK_LINE_CAP_ROUND:
|
||||
width = stroke->line_width;
|
||||
break;
|
||||
case GSK_LINE_CAP_SQUARE:
|
||||
width = G_SQRT2 * stroke->line_width;
|
||||
break;
|
||||
default:
|
||||
g_assert_not_reached ();
|
||||
}
|
||||
|
||||
switch (stroke->line_join)
|
||||
{
|
||||
case GSK_LINE_JOIN_MITER:
|
||||
width = MAX (width, MAX (stroke->miter_limit, 1.f) * stroke->line_width);
|
||||
break;
|
||||
case GSK_LINE_JOIN_ROUND:
|
||||
case GSK_LINE_JOIN_BEVEL:
|
||||
width = MAX (width, stroke->line_width);
|
||||
break;
|
||||
default:
|
||||
g_assert_not_reached ();
|
||||
}
|
||||
|
||||
return width;
|
||||
}
|
||||
|
||||
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
* 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/gsktypes.h>
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
#define GSK_TYPE_STROKE (gsk_stroke_get_type ())
|
||||
|
||||
GDK_AVAILABLE_IN_4_14
|
||||
GType gsk_stroke_get_type (void) G_GNUC_CONST;
|
||||
GDK_AVAILABLE_IN_4_14
|
||||
GskStroke * gsk_stroke_new (float line_width);
|
||||
GDK_AVAILABLE_IN_4_14
|
||||
GskStroke * gsk_stroke_copy (const GskStroke *other);
|
||||
GDK_AVAILABLE_IN_4_14
|
||||
void gsk_stroke_free (GskStroke *self);
|
||||
|
||||
GDK_AVAILABLE_IN_4_14
|
||||
gboolean gsk_stroke_equal (gconstpointer stroke1,
|
||||
gconstpointer stroke2);
|
||||
|
||||
GDK_AVAILABLE_IN_4_14
|
||||
void gsk_stroke_set_line_width (GskStroke *self,
|
||||
float line_width);
|
||||
GDK_AVAILABLE_IN_4_14
|
||||
float gsk_stroke_get_line_width (const GskStroke *self);
|
||||
GDK_AVAILABLE_IN_4_14
|
||||
void gsk_stroke_set_line_cap (GskStroke *self,
|
||||
GskLineCap line_cap);
|
||||
GDK_AVAILABLE_IN_4_14
|
||||
GskLineCap gsk_stroke_get_line_cap (const GskStroke *self);
|
||||
GDK_AVAILABLE_IN_4_14
|
||||
void gsk_stroke_set_line_join (GskStroke *self,
|
||||
GskLineJoin line_join);
|
||||
GDK_AVAILABLE_IN_4_14
|
||||
GskLineJoin gsk_stroke_get_line_join (const GskStroke *self);
|
||||
|
||||
GDK_AVAILABLE_IN_4_14
|
||||
void gsk_stroke_set_miter_limit (GskStroke *self,
|
||||
float limit);
|
||||
GDK_AVAILABLE_IN_4_14
|
||||
float gsk_stroke_get_miter_limit (const GskStroke *self);
|
||||
|
||||
GDK_AVAILABLE_IN_4_14
|
||||
void gsk_stroke_set_dash (GskStroke *self,
|
||||
const float *dash,
|
||||
gsize n_dash);
|
||||
GDK_AVAILABLE_IN_4_14
|
||||
const float * gsk_stroke_get_dash (const GskStroke *self,
|
||||
gsize *n_dash);
|
||||
|
||||
GDK_AVAILABLE_IN_4_14
|
||||
void gsk_stroke_set_dash_offset (GskStroke *self,
|
||||
float offset);
|
||||
GDK_AVAILABLE_IN_4_14
|
||||
float gsk_stroke_get_dash_offset (const GskStroke *self);
|
||||
|
||||
GDK_AVAILABLE_IN_4_14
|
||||
void gsk_stroke_to_cairo (const GskStroke *self,
|
||||
cairo_t *cr);
|
||||
|
||||
|
||||
G_END_DECLS
|
||||
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* 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
|
||||
|
||||
#include "gskstroke.h"
|
||||
|
||||
G_BEGIN_DECLS
|
||||
|
||||
struct _GskStroke
|
||||
{
|
||||
float line_width;
|
||||
GskLineCap line_cap;
|
||||
GskLineJoin line_join;
|
||||
float miter_limit;
|
||||
|
||||
float *dash;
|
||||
gsize n_dash;
|
||||
float dash_length; /* sum of all dashes in the array */
|
||||
float dash_offset;
|
||||
};
|
||||
|
||||
static inline void
|
||||
gsk_stroke_init_copy (GskStroke *stroke,
|
||||
const GskStroke *other)
|
||||
{
|
||||
*stroke = *other;
|
||||
|
||||
stroke->dash = g_memdup (other->dash, stroke->n_dash * sizeof (float));
|
||||
}
|
||||
|
||||
static inline void
|
||||
gsk_stroke_clear (GskStroke *stroke)
|
||||
{
|
||||
g_clear_pointer (&stroke->dash, g_free);
|
||||
stroke->n_dash = 0; /* better safe than sorry */
|
||||
}
|
||||
|
||||
float gsk_stroke_get_join_width (const GskStroke *stroke);
|
||||
|
||||
G_END_DECLS
|
||||
@@ -25,6 +25,11 @@
|
||||
#include <gdk/gdk.h>
|
||||
#include <gsk/gskenums.h>
|
||||
|
||||
typedef struct _GskPath GskPath;
|
||||
typedef struct _GskPathBuilder GskPathBuilder;
|
||||
typedef struct _GskPathMeasure GskPathMeasure;
|
||||
typedef struct _GskPathPoint GskPathPoint;
|
||||
typedef struct _GskRenderer GskRenderer;
|
||||
typedef struct _GskStroke GskStroke;
|
||||
typedef struct _GskTransform GskTransform;
|
||||
|
||||
|
||||
+20
-2
@@ -23,23 +23,31 @@ gsk_private_gl_shaders = [
|
||||
]
|
||||
|
||||
gsk_public_sources = files([
|
||||
'gskdiff.c',
|
||||
'gskcairorenderer.c',
|
||||
'gskdiff.c',
|
||||
'gskglshader.c',
|
||||
'gskpath.c',
|
||||
'gskpathbuilder.c',
|
||||
'gskpathmeasure.c',
|
||||
'gskpathpoint.c',
|
||||
'gskrenderer.c',
|
||||
'gskrendernode.c',
|
||||
'gskrendernodeimpl.c',
|
||||
'gskrendernodeparser.c',
|
||||
'gskroundedrect.c',
|
||||
'gskstroke.c',
|
||||
'gsktransform.c',
|
||||
'gl/gskglrenderer.c',
|
||||
])
|
||||
|
||||
gsk_private_sources = files([
|
||||
'gskcairoblur.c',
|
||||
'gskcontour.c',
|
||||
'gskcurve.c',
|
||||
'gskdebug.c',
|
||||
'gskprivate.c',
|
||||
'gskprofiler.c',
|
||||
'gskspline.c',
|
||||
'gl/gskglattachmentstate.c',
|
||||
'gl/gskglbuffer.c',
|
||||
'gl/gskglcommandqueue.c',
|
||||
@@ -66,9 +74,14 @@ gsk_public_headers = files([
|
||||
'gskcairorenderer.h',
|
||||
'gskenums.h',
|
||||
'gskglshader.h',
|
||||
'gskpath.h',
|
||||
'gskpathbuilder.h',
|
||||
'gskpathmeasure.h',
|
||||
'gskpathpoint.h',
|
||||
'gskrenderer.h',
|
||||
'gskrendernode.h',
|
||||
'gskroundedrect.h',
|
||||
'gskstroke.h',
|
||||
'gsktransform.h',
|
||||
'gsktypes.h',
|
||||
])
|
||||
@@ -97,6 +110,10 @@ if have_vulkan
|
||||
endif
|
||||
|
||||
gsk_private_vulkan_shaders = []
|
||||
# This is an odd split because we use configure_file() below to workaround
|
||||
# a limitation in meson preventing using custom_target() with gnome.compile_resources()
|
||||
# and that requires file paths, but we also need to have dependencies during development
|
||||
# on constantly regenerated files.
|
||||
gsk_private_vulkan_compiled_shaders = []
|
||||
gsk_private_vulkan_compiled_shaders_deps = []
|
||||
gsk_private_vulkan_shader_headers = []
|
||||
@@ -144,7 +161,7 @@ if get_variable('broadway_enabled')
|
||||
])
|
||||
endif
|
||||
|
||||
gsk_resources_xml = custom_target(output: 'gsk.resources.xml',
|
||||
gsk_resources_xml = configure_file(output: 'gsk.resources.xml',
|
||||
input: 'gen-gsk-gresources-xml.py',
|
||||
command: [
|
||||
find_program('gen-gsk-gresources-xml.py'),
|
||||
@@ -180,6 +197,7 @@ gsk_deps = [
|
||||
pango_dep,
|
||||
cairo_dep,
|
||||
cairo_csi_dep,
|
||||
pixbuf_dep,
|
||||
libgdk_dep,
|
||||
]
|
||||
|
||||
|
||||
@@ -1260,6 +1260,8 @@ static const GskVulkanRenderPassNodeFunc nodes_vtable[] = {
|
||||
[GSK_GL_SHADER_NODE] = NULL,
|
||||
[GSK_TEXTURE_SCALE_NODE] = gsk_vulkan_render_pass_add_texture_scale_node,
|
||||
[GSK_MASK_NODE] = gsk_vulkan_render_pass_add_mask_node,
|
||||
[GSK_FILL_NODE] = NULL,
|
||||
[GSK_STROKE_NODE] = NULL,
|
||||
};
|
||||
|
||||
static void
|
||||
|
||||
@@ -93,12 +93,12 @@ foreach shader: gsk_private_vulkan_shaders
|
||||
endforeach
|
||||
|
||||
foreach shader: gsk_private_vulkan_vertex_shaders
|
||||
shader_header = custom_target(output: '@0@.h'.format(shader),
|
||||
input: shader,
|
||||
command: [
|
||||
find_program('generate-header.py'),
|
||||
'@INPUT@',
|
||||
],
|
||||
capture: true)
|
||||
shader_header = configure_file(output: '@0@.h'.format(shader),
|
||||
input: shader,
|
||||
command: [
|
||||
find_program('generate-header.py'),
|
||||
'@INPUT@',
|
||||
],
|
||||
capture: true)
|
||||
gsk_private_vulkan_shader_headers += shader_header
|
||||
endforeach
|
||||
|
||||
@@ -257,6 +257,8 @@ static guint tree_model_signals[LAST_SIGNAL] = { 0 };
|
||||
* GtkTreePath:
|
||||
*
|
||||
* An opaque structure representing a path to a row in a model.
|
||||
*
|
||||
* Deprecated: 4.10
|
||||
*/
|
||||
struct _GtkTreePath
|
||||
{
|
||||
|
||||
@@ -69,6 +69,8 @@ typedef gboolean (* GtkTreeModelForeachFunc) (GtkTreeModel *model, GtkTreePath *
|
||||
* static for the lifetime of the object. A more complete description
|
||||
* of %GTK_TREE_MODEL_ITERS_PERSIST can be found in the overview of
|
||||
* this section.
|
||||
*
|
||||
* Deprecated: 4.10
|
||||
*/
|
||||
typedef enum
|
||||
{
|
||||
@@ -88,6 +90,8 @@ typedef enum
|
||||
* integer in the @stamp member, and put
|
||||
* model-specific data in the three @user_data
|
||||
* members.
|
||||
*
|
||||
* Deprecated: 4.10
|
||||
*/
|
||||
struct _GtkTreeIter
|
||||
{
|
||||
@@ -251,6 +255,8 @@ gboolean gtk_tree_path_is_descendant (GtkTreePath *path,
|
||||
* A GtkTreeRowReference tracks model changes so that it always refers to the
|
||||
* same row (a `GtkTreePath` refers to a position, not a fixed row). Create a
|
||||
* new GtkTreeRowReference with gtk_tree_row_reference_new().
|
||||
*
|
||||
* Deprecated: 4.10: Use [iface@Gio.ListModel] instead
|
||||
*/
|
||||
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
|
||||
@@ -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");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+1
-2
@@ -459,8 +459,7 @@ gsk_pango_renderer_release (GskPangoRenderer *renderer)
|
||||
*
|
||||
* Creates render nodes for rendering @layout in the given foregound @color
|
||||
* and appends them to the current node of @snapshot without changing the
|
||||
* current node. The current theme's foreground color for a widget can be
|
||||
* obtained with [method@Gtk.Widget.get_color].
|
||||
* current node.
|
||||
*
|
||||
* Note that if the layout does not produce any visible output, then nodes
|
||||
* may not be added to the @snapshot.
|
||||
|
||||
@@ -45,7 +45,6 @@ static GdkContentProvider *
|
||||
double x,
|
||||
double y,
|
||||
GtkColorDialogButton *self);
|
||||
static void activated (GtkColorDialogButton *self);
|
||||
static void button_clicked (GtkColorDialogButton *self);
|
||||
static void update_button_sensitivity
|
||||
(GtkColorDialogButton *self);
|
||||
@@ -97,17 +96,8 @@ enum
|
||||
NUM_PROPERTIES
|
||||
};
|
||||
|
||||
/* Signals */
|
||||
enum
|
||||
{
|
||||
SIGNAL_ACTIVATE = 1,
|
||||
NUM_SIGNALS
|
||||
};
|
||||
|
||||
static GParamSpec *properties[NUM_PROPERTIES];
|
||||
|
||||
static unsigned int color_dialog_button_signals[NUM_SIGNALS] = { 0 };
|
||||
|
||||
G_DEFINE_TYPE (GtkColorDialogButton, gtk_color_dialog_button, GTK_TYPE_WIDGET)
|
||||
|
||||
static void
|
||||
@@ -118,8 +108,6 @@ gtk_color_dialog_button_init (GtkColorDialogButton *self)
|
||||
GtkDragSource *source;
|
||||
GtkDropTarget *dest;
|
||||
|
||||
g_signal_connect_swapped (self, "activate", G_CALLBACK (activated), self);
|
||||
|
||||
self->color = GDK_RGBA ("00000000");
|
||||
|
||||
self->button = gtk_button_new ();
|
||||
@@ -290,27 +278,6 @@ gtk_color_dialog_button_class_init (GtkColorDialogButtonClass *class)
|
||||
|
||||
g_object_class_install_properties (object_class, NUM_PROPERTIES, properties);
|
||||
|
||||
/**
|
||||
* GtkColorDialogButton::activate:
|
||||
* @widget: the object which received the signal
|
||||
*
|
||||
* Emitted when the color dialog button is activated.
|
||||
*
|
||||
* The `::activate` signal on `GtkColorDialogButton` is an action signal
|
||||
* and emitting it causes the button to pop up its dialog.
|
||||
*
|
||||
* Since: 4.14
|
||||
*/
|
||||
color_dialog_button_signals[SIGNAL_ACTIVATE] =
|
||||
g_signal_new (I_ ("activate"),
|
||||
G_TYPE_FROM_CLASS (class),
|
||||
G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
|
||||
0,
|
||||
NULL, NULL,
|
||||
NULL,
|
||||
G_TYPE_NONE, 0);
|
||||
|
||||
gtk_widget_class_set_activate_signal (widget_class, color_dialog_button_signals[SIGNAL_ACTIVATE]);
|
||||
gtk_widget_class_set_layout_manager_type (widget_class, GTK_TYPE_BIN_LAYOUT);
|
||||
gtk_widget_class_set_css_name (widget_class, "colorbutton");
|
||||
gtk_widget_class_set_accessible_role (widget_class, GTK_ACCESSIBLE_ROLE_GROUP);
|
||||
@@ -399,12 +366,6 @@ color_chosen (GObject *source,
|
||||
update_button_sensitivity (self);
|
||||
}
|
||||
|
||||
static void
|
||||
activated (GtkColorDialogButton *self)
|
||||
{
|
||||
gtk_widget_activate (self->button);
|
||||
}
|
||||
|
||||
static void
|
||||
button_clicked (GtkColorDialogButton *self)
|
||||
{
|
||||
|
||||
+1
-8
@@ -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);
|
||||
}
|
||||
|
||||
|
||||
@@ -43,8 +43,6 @@
|
||||
|
||||
G_GNUC_BEGIN_IGNORE_DEPRECATIONS
|
||||
|
||||
@class FilterComboBox;
|
||||
|
||||
typedef struct {
|
||||
GtkFileChooserNative *self;
|
||||
|
||||
@@ -70,33 +68,31 @@ typedef struct {
|
||||
|
||||
NSMutableArray *filters;
|
||||
NSMutableArray *filter_names;
|
||||
FilterComboBox *filter_popup_button;
|
||||
NSComboBox *filter_combo_box;
|
||||
|
||||
GSList *files;
|
||||
int response;
|
||||
} FileChooserQuartzData;
|
||||
|
||||
@interface FilterComboBox : NSPopUpButton
|
||||
@interface FilterComboBox : NSObject<NSComboBoxDelegate>
|
||||
{
|
||||
FileChooserQuartzData *data;
|
||||
}
|
||||
- (id) initWithData:(FileChooserQuartzData *) quartz_data;
|
||||
- (void) popUpButtonSelectionChanged:(id) sender;
|
||||
- (void)comboBoxSelectionDidChange:(NSNotification *)notification;
|
||||
@end
|
||||
|
||||
@implementation FilterComboBox
|
||||
|
||||
- (id) initWithData:(FileChooserQuartzData *) quartz_data
|
||||
{
|
||||
[super initWithFrame:NSMakeRect(0, 0, 200, 24)];
|
||||
[self setTarget:self];
|
||||
[self setAction:@selector(popUpButtonSelectionChanged:)];
|
||||
[super init];
|
||||
data = quartz_data;
|
||||
return self;
|
||||
}
|
||||
- (void)popUpButtonSelectionChanged:(id)sender
|
||||
- (void)comboBoxSelectionDidChange:(NSNotification *)notification
|
||||
{
|
||||
NSInteger selected_index = [data->filter_popup_button indexOfSelectedItem];
|
||||
NSInteger selected_index = [data->filter_combo_box indexOfSelectedItem];
|
||||
NSArray *filter = [data->filters objectAtIndex:selected_index];
|
||||
// check for empty strings in filter -> indicates all filetypes should be allowed!
|
||||
if ([filter containsObject:@""])
|
||||
@@ -306,8 +302,10 @@ filechooser_quartz_launch (FileChooserQuartzData *data)
|
||||
if (data->filters)
|
||||
{
|
||||
// when filters have been provided, a combobox needs to be added
|
||||
data->filter_popup_button = [[FilterComboBox alloc] initWithData:data];
|
||||
[data->filter_popup_button addItemsWithTitles:data->filter_names];
|
||||
data->filter_combo_box = [[NSComboBox alloc] initWithFrame:NSMakeRect(0, 0, 200, 24)];
|
||||
[data->filter_combo_box addItemsWithObjectValues:data->filter_names];
|
||||
[data->filter_combo_box setEditable:NO];
|
||||
[data->filter_combo_box setDelegate:[[FilterComboBox alloc] initWithData:data]];
|
||||
|
||||
if (data->self->current_filter)
|
||||
{
|
||||
@@ -331,18 +329,16 @@ filechooser_quartz_launch (FileChooserQuartzData *data)
|
||||
g_object_unref (filters);
|
||||
|
||||
if (current_filter_index != GTK_INVALID_LIST_POSITION)
|
||||
[data->filter_popup_button selectItemAtIndex:current_filter_index];
|
||||
[data->filter_combo_box selectItemAtIndex:current_filter_index];
|
||||
else
|
||||
[data->filter_popup_button selectItemAtIndex:0];
|
||||
[data->filter_combo_box selectItemAtIndex:0];
|
||||
}
|
||||
else
|
||||
{
|
||||
[data->filter_popup_button selectItemAtIndex:0];
|
||||
[data->filter_combo_box selectItemAtIndex:0];
|
||||
}
|
||||
|
||||
[data->filter_popup_button popUpButtonSelectionChanged:NULL];
|
||||
[data->filter_popup_button setToolTip:[NSString stringWithUTF8String:_("Select which types of files are shown")]];
|
||||
[data->panel setAccessoryView:data->filter_popup_button];
|
||||
[data->filter_combo_box setToolTip:[NSString stringWithUTF8String:_("Select which types of files are shown")]];
|
||||
[data->panel setAccessoryView:data->filter_combo_box];
|
||||
if ([data->panel isKindOfClass:[NSOpenPanel class]] && [data->panel respondsToSelector:@selector(setAccessoryViewDisclosed:)])
|
||||
{
|
||||
[(id<CanSetAccessoryViewDisclosed>) data->panel setAccessoryViewDisclosed:YES];
|
||||
@@ -582,3 +578,4 @@ gtk_file_chooser_native_quartz_hide (GtkFileChooserNative *self)
|
||||
}
|
||||
data->panel = NULL;
|
||||
}
|
||||
|
||||
|
||||
+5
-2
@@ -758,6 +758,8 @@ gtk_file_filter_get_attributes (GtkFileFilter *filter)
|
||||
|
||||
#ifdef GDK_WINDOWING_MACOS
|
||||
|
||||
#import <Foundation/Foundation.h>
|
||||
|
||||
NSArray * _gtk_file_filter_get_as_pattern_nsstrings (GtkFileFilter *filter)
|
||||
{
|
||||
NSMutableArray *array = [[NSMutableArray alloc] init];
|
||||
@@ -771,8 +773,9 @@ NSArray * _gtk_file_filter_get_as_pattern_nsstrings (GtkFileFilter *filter)
|
||||
{
|
||||
case FILTER_RULE_MIME_TYPE:
|
||||
{
|
||||
// GContentType from GIO use UTI on macOS since glib version 2.51
|
||||
NSString *uti_nsstring = [NSString stringWithUTF8String: rule->u.content_types[0]];
|
||||
// convert mime-types to UTI
|
||||
NSString *mime_type_nsstring = [NSString stringWithUTF8String: rule->u.content_types[0]];
|
||||
NSString *uti_nsstring = (NSString *) UTTypeCreatePreferredIdentifierForTag (kUTTagClassMIMEType, (CFStringRef) mime_type_nsstring, NULL);
|
||||
if (uti_nsstring == NULL)
|
||||
{
|
||||
[array release];
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
#include "gtkwidgetprivate.h"
|
||||
#include "gtktypebuiltins.h"
|
||||
|
||||
static void activated (GtkFontDialogButton *self);
|
||||
|
||||
static void button_clicked (GtkFontDialogButton *self);
|
||||
static void update_button_sensitivity
|
||||
(GtkFontDialogButton *self);
|
||||
@@ -100,17 +100,8 @@ enum
|
||||
NUM_PROPERTIES
|
||||
};
|
||||
|
||||
/* Signals */
|
||||
enum
|
||||
{
|
||||
SIGNAL_ACTIVATE = 1,
|
||||
NUM_SIGNALS
|
||||
};
|
||||
|
||||
static GParamSpec *properties[NUM_PROPERTIES];
|
||||
|
||||
static unsigned int font_dialog_button_signals[NUM_SIGNALS] = { 0 };
|
||||
|
||||
G_DEFINE_TYPE (GtkFontDialogButton, gtk_font_dialog_button, GTK_TYPE_WIDGET)
|
||||
|
||||
static void
|
||||
@@ -119,8 +110,6 @@ gtk_font_dialog_button_init (GtkFontDialogButton *self)
|
||||
GtkWidget *box;
|
||||
PangoFontDescription *font_desc;
|
||||
|
||||
g_signal_connect_swapped (self, "activate", G_CALLBACK (activated), self);
|
||||
|
||||
self->button = gtk_button_new ();
|
||||
g_signal_connect_swapped (self->button, "clicked", G_CALLBACK (button_clicked), self);
|
||||
self->font_label = gtk_label_new (_("Font"));
|
||||
@@ -394,27 +383,6 @@ gtk_font_dialog_button_class_init (GtkFontDialogButtonClass *class)
|
||||
|
||||
g_object_class_install_properties (object_class, NUM_PROPERTIES, properties);
|
||||
|
||||
/**
|
||||
* GtkFontDialogButton::activate:
|
||||
* @widget: The object which received the signal
|
||||
*
|
||||
* Emitted when the font dialog button is activated.
|
||||
*
|
||||
* The `::activate` signal on `GtkFontDialogButton` is an action signal
|
||||
* and emitting it causes the button to pop up its dialog.
|
||||
*
|
||||
* Since: 4.14
|
||||
*/
|
||||
font_dialog_button_signals[SIGNAL_ACTIVATE] =
|
||||
g_signal_new (I_ ("activate"),
|
||||
G_TYPE_FROM_CLASS (class),
|
||||
G_SIGNAL_RUN_FIRST | G_SIGNAL_ACTION,
|
||||
0,
|
||||
NULL, NULL,
|
||||
NULL,
|
||||
G_TYPE_NONE, 0);
|
||||
|
||||
gtk_widget_class_set_activate_signal (widget_class, font_dialog_button_signals[SIGNAL_ACTIVATE]);
|
||||
gtk_widget_class_set_layout_manager_type (widget_class, GTK_TYPE_BIN_LAYOUT);
|
||||
gtk_widget_class_set_css_name (widget_class, "fontbutton");
|
||||
gtk_widget_class_set_accessible_role (widget_class, GTK_ACCESSIBLE_ROLE_GROUP);
|
||||
@@ -531,12 +499,6 @@ font_and_features_chosen (GObject *source,
|
||||
update_button_sensitivity (self);
|
||||
}
|
||||
|
||||
static void
|
||||
activated (GtkFontDialogButton *self)
|
||||
{
|
||||
gtk_widget_activate (self->button);
|
||||
}
|
||||
|
||||
static void
|
||||
button_clicked (GtkFontDialogButton *self)
|
||||
{
|
||||
|
||||
+1
-1
@@ -1202,7 +1202,7 @@ my_pango_layout_get_width_for_height (PangoLayout *layout,
|
||||
else if (text_height > for_height)
|
||||
min = mid + 1;
|
||||
else
|
||||
max = mid;
|
||||
max = text_width;
|
||||
}
|
||||
|
||||
return min * PANGO_SCALE;
|
||||
|
||||
+2
-2
@@ -121,7 +121,7 @@ static GParamSpec *properties[N_PROPS] = { NULL, };
|
||||
* @self: a `GtkListBase`
|
||||
* @across: position in pixels in the direction cross to the list
|
||||
* @along: position in pixels in the direction of the list
|
||||
* @pos: (out): set to the looked up position
|
||||
* @pos: (out caller-allocates): set to the looked up position
|
||||
* @area: (out caller-allocates) (optional): set to the area occupied
|
||||
* by the returned position
|
||||
*
|
||||
@@ -1519,7 +1519,7 @@ gtk_list_base_allocate_children (GtkListBase *self,
|
||||
GtkListBasePrivate *priv = gtk_list_base_get_instance_private (self);
|
||||
GtkListTile *tile;
|
||||
int dx, dy;
|
||||
|
||||
|
||||
gtk_list_base_get_adjustment_values (self, OPPOSITE_ORIENTATION (priv->orientation), &dx, NULL, NULL);
|
||||
gtk_list_base_get_adjustment_values (self, priv->orientation, &dy, NULL, NULL);
|
||||
|
||||
|
||||
+3
-3
@@ -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
|
||||
*/
|
||||
|
||||
+3
-4
@@ -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]
|
||||
|
||||
+18
-18
@@ -1353,35 +1353,35 @@ gtk_menu_button_get_use_underline (GtkMenuButton *menu_button)
|
||||
}
|
||||
|
||||
static GList *
|
||||
get_menu_bars (GtkWidget *toplevel)
|
||||
get_menu_bars (GtkWindow *window)
|
||||
{
|
||||
return g_object_get_data (G_OBJECT (toplevel), "gtk-menu-bar-list");
|
||||
return g_object_get_data (G_OBJECT (window), "gtk-menu-bar-list");
|
||||
}
|
||||
|
||||
static void
|
||||
set_menu_bars (GtkWidget *toplevel,
|
||||
set_menu_bars (GtkWindow *window,
|
||||
GList *menubars)
|
||||
{
|
||||
g_object_set_data (G_OBJECT (toplevel), I_("gtk-menu-bar-list"), menubars);
|
||||
g_object_set_data (G_OBJECT (window), I_("gtk-menu-bar-list"), menubars);
|
||||
}
|
||||
|
||||
static void
|
||||
add_to_toplevel (GtkWidget *toplevel,
|
||||
GtkMenuButton *button)
|
||||
add_to_window (GtkWindow *window,
|
||||
GtkMenuButton *button)
|
||||
{
|
||||
GList *menubars = get_menu_bars (toplevel);
|
||||
GList *menubars = get_menu_bars (window);
|
||||
|
||||
set_menu_bars (toplevel, g_list_prepend (menubars, button));
|
||||
set_menu_bars (window, g_list_prepend (menubars, button));
|
||||
}
|
||||
|
||||
static void
|
||||
remove_from_toplevel (GtkWidget *toplevel,
|
||||
GtkMenuButton *button)
|
||||
remove_from_window (GtkWindow *window,
|
||||
GtkMenuButton *button)
|
||||
{
|
||||
GList *menubars = get_menu_bars (toplevel);
|
||||
GList *menubars = get_menu_bars (window);
|
||||
|
||||
menubars = g_list_remove (menubars, button);
|
||||
set_menu_bars (toplevel, menubars);
|
||||
set_menu_bars (window, menubars);
|
||||
}
|
||||
|
||||
static void
|
||||
@@ -1394,7 +1394,7 @@ gtk_menu_button_root (GtkWidget *widget)
|
||||
if (button->primary)
|
||||
{
|
||||
GtkWidget *toplevel = GTK_WIDGET (gtk_widget_get_root (widget));
|
||||
add_to_toplevel (toplevel, button);
|
||||
add_to_window (GTK_WINDOW (toplevel), button);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1404,7 +1404,7 @@ gtk_menu_button_unroot (GtkWidget *widget)
|
||||
GtkWidget *toplevel;
|
||||
|
||||
toplevel = GTK_WIDGET (gtk_widget_get_root (widget));
|
||||
remove_from_toplevel (toplevel, GTK_MENU_BUTTON (widget));
|
||||
remove_from_window (GTK_WINDOW (toplevel), GTK_MENU_BUTTON (widget));
|
||||
|
||||
GTK_WIDGET_CLASS (gtk_menu_button_parent_class)->unroot (widget);
|
||||
}
|
||||
@@ -1437,9 +1437,9 @@ gtk_menu_button_set_primary (GtkMenuButton *menu_button,
|
||||
if (toplevel)
|
||||
{
|
||||
if (menu_button->primary)
|
||||
add_to_toplevel (GTK_WIDGET (toplevel), menu_button);
|
||||
add_to_window (GTK_WINDOW (toplevel), menu_button);
|
||||
else
|
||||
remove_from_toplevel (GTK_WIDGET (toplevel), menu_button);
|
||||
remove_from_window (GTK_WINDOW (toplevel), menu_button);
|
||||
}
|
||||
|
||||
g_object_notify_by_pspec (G_OBJECT (menu_button), menu_button_props[PROP_PRIMARY]);
|
||||
@@ -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);
|
||||
|
||||
+1
-3
@@ -5409,9 +5409,7 @@ gtk_notebook_real_switch_page (GtkNotebook *notebook,
|
||||
if (notebook->cur_page)
|
||||
{
|
||||
GtkRoot *root = gtk_widget_get_root (GTK_WIDGET (notebook));
|
||||
GtkWidget *focus = NULL;
|
||||
if (root)
|
||||
focus = gtk_root_get_focus (root);
|
||||
GtkWidget *focus = gtk_root_get_focus (root);
|
||||
if (focus)
|
||||
child_has_focus = gtk_widget_is_ancestor (focus, notebook->cur_page->child);
|
||||
gtk_widget_unset_state_flags (notebook->cur_page->tab_widget, GTK_STATE_FLAG_CHECKED);
|
||||
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
|
||||
+12
-13
@@ -70,31 +70,30 @@
|
||||
* # CSS nodes
|
||||
*
|
||||
* ```
|
||||
* popover.background[.menu]
|
||||
* popover[.menu]
|
||||
* ├── arrow
|
||||
* ╰── contents
|
||||
* ╰── contents.background
|
||||
* ╰── <child>
|
||||
* ```
|
||||
*
|
||||
* `GtkPopover` has a main node with name `popover`, an arrow with name `arrow`,
|
||||
* and another node for the content named `contents`. The `popover` node always
|
||||
* gets the `.background` style class. It also gets the `.menu` style class
|
||||
* if the popover is menu-like, e.g. is a [class@Gtk.PopoverMenu].
|
||||
* The contents child node always gets the .background style class
|
||||
* and the popover itself gets the .menu style class if the popover
|
||||
* is menu-like (i.e. `GtkPopoverMenu`).
|
||||
*
|
||||
* Particular uses of `GtkPopover`, such as touch selection popups or
|
||||
* magnifiers in `GtkEntry` or `GtkTextView` get style classes like
|
||||
* `.touch-selection` or `.magnifier` to differentiate from plain popovers.
|
||||
* .touch-selection or .magnifier to differentiate from plain popovers.
|
||||
*
|
||||
* When styling a popover directly, the `popover` node should usually
|
||||
* When styling a popover directly, the popover node should usually
|
||||
* not have any background. The visible part of the popover can have
|
||||
* a shadow. To specify it in CSS, set the box-shadow of the `contents` node.
|
||||
* a shadow. To specify it in CSS, set the box-shadow of the contents node.
|
||||
*
|
||||
* Note that, in order to accomplish appropriate arrow visuals, `GtkPopover`
|
||||
* uses custom drawing for the `arrow` node. This makes it possible for the
|
||||
* uses custom drawing for the arrow node. This makes it possible for the
|
||||
* arrow to change its shape dynamically, but it also limits the possibilities
|
||||
* of styling it using CSS. In particular, the `arrow` gets drawn over the
|
||||
* `content` node's border and shadow, so they look like one shape, which
|
||||
* means that the border width of the `content` node and the `arrow` node should
|
||||
* of styling it using CSS. In particular, the arrow gets drawn over the
|
||||
* content node's border and shadow, so they look like one shape, which
|
||||
* means that the border width of the content node and the arrow node should
|
||||
* be the same. The arrow also does not support any border shape other than
|
||||
* solid, no border-radius, only one border width (border-bottom-width is
|
||||
* used) and no box-shadow.
|
||||
|
||||
@@ -135,14 +135,7 @@
|
||||
*
|
||||
* `GtkPopoverMenu` is just a subclass of `GtkPopover` that adds custom content
|
||||
* to it, therefore it has the same CSS nodes. It is one of the cases that add
|
||||
* a `.menu` style class to the main `popover` node.
|
||||
*
|
||||
* Menu items have nodes with name `button` and class `.model`. If a section
|
||||
* display-hint is set, the section gets a node `box` with class `horizontal`
|
||||
* plus a class with the same text as the display hint. Note that said box may
|
||||
* not be the direct ancestor of the item `button`s. Thus, for example, to style
|
||||
* items in an `inline-buttons` section, select `.inline-buttons button.model`.
|
||||
* Other things that may be of interest to style in menus include `label` nodes.
|
||||
* a .menu style class to the popover's main node.
|
||||
*
|
||||
* # Accessibility
|
||||
*
|
||||
|
||||
@@ -29,7 +29,6 @@
|
||||
#error "Only <gtk/gtk.h> can be included directly."
|
||||
#endif
|
||||
|
||||
#include <gtk/gtkborder.h>
|
||||
#include <gtk/gtkwidget.h>
|
||||
|
||||
|
||||
|
||||
@@ -113,9 +113,10 @@ gtk_section_model_default_init (GtkSectionModelInterface *iface)
|
||||
* gtk_section_model_get_section:
|
||||
* @self: a `GtkSectionModel`
|
||||
* @position: the position of the item to query
|
||||
* @out_start: (out): the position of the first item in the section
|
||||
* @out_end: (out): the position of the first item not part of the section
|
||||
* anymore.
|
||||
* @out_start: (out caller-allocates): the position of the first
|
||||
* item in the section
|
||||
* @out_end: (out caller-allocates): the position of the first
|
||||
* item not part of the section anymore.
|
||||
*
|
||||
* Query the section that covers the given position. The number of
|
||||
* items in the section can be computed by `out_end - out_start`.
|
||||
|
||||
@@ -29,7 +29,7 @@
|
||||
* GtkSignalListItemFactory:
|
||||
*
|
||||
* `GtkSignalListItemFactory` is a `GtkListItemFactory` that emits signals
|
||||
* to manage listitems.
|
||||
* to to manage listitems.
|
||||
*
|
||||
* Signals are emitted for every listitem in the same order:
|
||||
*
|
||||
@@ -216,9 +216,9 @@ gtk_signal_list_item_factory_class_init (GtkSignalListItemFactoryClass *klass)
|
||||
* @self: The `GtkSignalListItemFactory`
|
||||
* @object: The `GObject` to unbind
|
||||
*
|
||||
* Emitted when an object has been unbound from its item, for example when
|
||||
* Emitted when a object has been unbound from its item, for example when
|
||||
* a listitem was removed from use in a list widget
|
||||
* and its [property@Gtk.ListItem:item] is about to be unset.
|
||||
* and its new [property@Gtk.ListItem:item] is about to be unset.
|
||||
*
|
||||
* This signal is the opposite of the [signal@Gtk.SignalListItemFactory::bind]
|
||||
* signal and should be used to undo everything done in that signal.
|
||||
|
||||
+157
-18
@@ -30,6 +30,7 @@
|
||||
|
||||
#include "gsk/gskrendernodeprivate.h"
|
||||
#include "gsk/gskroundedrectprivate.h"
|
||||
#include "gsk/gskstrokeprivate.h"
|
||||
|
||||
#include "gtk/gskpangoprivate.h"
|
||||
|
||||
@@ -105,6 +106,14 @@ struct _GtkSnapshotState {
|
||||
struct {
|
||||
GskRoundedRect bounds;
|
||||
} rounded_clip;
|
||||
struct {
|
||||
GskPath *path;
|
||||
GskFillRule fill_rule;
|
||||
} fill;
|
||||
struct {
|
||||
GskPath *path;
|
||||
GskStroke stroke;
|
||||
} stroke;
|
||||
struct {
|
||||
gsize n_shadows;
|
||||
GskShadow *shadows;
|
||||
@@ -558,29 +567,29 @@ merge_color_matrix_nodes (const graphene_matrix_t *matrix2,
|
||||
const graphene_vec4_t *offset2,
|
||||
GskRenderNode *child)
|
||||
{
|
||||
const graphene_matrix_t *matrix1 = gsk_color_matrix_node_get_color_matrix (child);
|
||||
const graphene_matrix_t *mat1 = gsk_color_matrix_node_get_color_matrix (child);
|
||||
const graphene_vec4_t *offset1 = gsk_color_matrix_node_get_color_offset (child);
|
||||
graphene_matrix_t matrix;
|
||||
graphene_vec4_t offset;
|
||||
graphene_matrix_t mat2 = *matrix2;
|
||||
graphene_vec4_t off2 = *offset2;
|
||||
GskRenderNode *result;
|
||||
|
||||
g_assert (gsk_render_node_get_node_type (child) == GSK_COLOR_MATRIX_NODE);
|
||||
|
||||
/* color matrix node: color = trans(mat) * p + offset; for a pixel p.
|
||||
* color = trans(mat2) * (trans(mat1) * p + offset1) + offset2
|
||||
* = trans(mat2) * trans(mat1) * p + trans(mat2) * offset1 + offset2
|
||||
* = trans(mat1 * mat2) * p + (trans(mat2) * offset1 + offset2)
|
||||
/* color matrix node: color = mat * p + offset; for a pixel p.
|
||||
* color = mat1 * (mat2 * p + offset2) + offset1;
|
||||
* = mat1 * mat2 * p + offset2 * mat1 + offset1
|
||||
* = (mat1 * mat2) * p + (offset2 * mat1 + offset1)
|
||||
* Which this code does.
|
||||
* mat1 and offset1 come from @child.
|
||||
*/
|
||||
|
||||
graphene_matrix_transform_vec4 (matrix2, offset1, &offset);
|
||||
graphene_vec4_add (&offset, offset2, &offset);
|
||||
graphene_matrix_transform_vec4 (mat1, offset2, &off2);
|
||||
graphene_vec4_add (&off2, offset1, &off2);
|
||||
|
||||
graphene_matrix_multiply (matrix1, matrix2, &matrix);
|
||||
graphene_matrix_multiply (mat1, &mat2, &mat2);
|
||||
|
||||
result = gsk_color_matrix_node_new (gsk_color_matrix_node_get_child (child),
|
||||
&matrix, &offset);
|
||||
&mat2, &off2);
|
||||
|
||||
return result;
|
||||
}
|
||||
@@ -647,13 +656,6 @@ gtk_snapshot_collect_color_matrix (GtkSnapshot *snapshot,
|
||||
* Modifies the colors of an image by applying an affine transformation
|
||||
* in RGB space.
|
||||
*
|
||||
* In particular, the colors will be transformed by applying
|
||||
*
|
||||
* pixel = transpose(color_matrix) * pixel + color_offset
|
||||
*
|
||||
* for every pixel. The transformation operates on unpremultiplied
|
||||
* colors, with color components ordered R, G, B, A.
|
||||
*
|
||||
* The image is recorded until the next call to [method@Gtk.Snapshot.pop].
|
||||
*/
|
||||
void
|
||||
@@ -1103,6 +1105,143 @@ gtk_snapshot_push_rounded_clip (GtkSnapshot *snapshot,
|
||||
gsk_rounded_rect_scale_affine (&state->data.rounded_clip.bounds, bounds, scale_x, scale_y, dx, dy);
|
||||
}
|
||||
|
||||
static GskRenderNode *
|
||||
gtk_snapshot_collect_fill (GtkSnapshot *snapshot,
|
||||
GtkSnapshotState *state,
|
||||
GskRenderNode **nodes,
|
||||
guint n_nodes)
|
||||
{
|
||||
GskRenderNode *node, *fill_node;
|
||||
|
||||
node = gtk_snapshot_collect_default (snapshot, state, nodes, n_nodes);
|
||||
if (node == NULL)
|
||||
return NULL;
|
||||
|
||||
fill_node = gsk_fill_node_new (node,
|
||||
state->data.fill.path,
|
||||
state->data.fill.fill_rule);
|
||||
|
||||
if (fill_node->bounds.size.width == 0 ||
|
||||
fill_node->bounds.size.height == 0)
|
||||
{
|
||||
gsk_render_node_unref (node);
|
||||
gsk_render_node_unref (fill_node);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
gsk_render_node_unref (node);
|
||||
|
||||
return fill_node;
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_snapshot_clear_fill (GtkSnapshotState *state)
|
||||
{
|
||||
gsk_path_unref (state->data.fill.path);
|
||||
}
|
||||
|
||||
/**
|
||||
* gtk_snapshot_push_fill:
|
||||
* @snapshot: a `GtkSnapshot`
|
||||
* @path: The path describing the area to fill
|
||||
* @fill_rule: The fill rule to use
|
||||
*
|
||||
* Fills the area given by @path and @fill_rule with an image and discards everything
|
||||
* outside of it.
|
||||
*
|
||||
* The image is recorded until the next call to [method@Gtk.Snapshot.pop].
|
||||
*
|
||||
* Since: 4.14
|
||||
*/
|
||||
void
|
||||
gtk_snapshot_push_fill (GtkSnapshot *snapshot,
|
||||
GskPath *path,
|
||||
GskFillRule fill_rule)
|
||||
{
|
||||
GtkSnapshotState *state;
|
||||
|
||||
gtk_snapshot_ensure_identity (snapshot);
|
||||
|
||||
state = gtk_snapshot_push_state (snapshot,
|
||||
gtk_snapshot_get_current_state (snapshot)->transform,
|
||||
gtk_snapshot_collect_fill,
|
||||
gtk_snapshot_clear_fill);
|
||||
|
||||
state->data.fill.path = gsk_path_ref (path);
|
||||
state->data.fill.fill_rule = fill_rule;
|
||||
}
|
||||
|
||||
static GskRenderNode *
|
||||
gtk_snapshot_collect_stroke (GtkSnapshot *snapshot,
|
||||
GtkSnapshotState *state,
|
||||
GskRenderNode **nodes,
|
||||
guint n_nodes)
|
||||
{
|
||||
GskRenderNode *node, *stroke_node;
|
||||
|
||||
node = gtk_snapshot_collect_default (snapshot, state, nodes, n_nodes);
|
||||
if (node == NULL)
|
||||
return NULL;
|
||||
|
||||
stroke_node = gsk_stroke_node_new (node,
|
||||
state->data.stroke.path,
|
||||
&state->data.stroke.stroke);
|
||||
|
||||
if (stroke_node->bounds.size.width == 0 ||
|
||||
stroke_node->bounds.size.height == 0)
|
||||
{
|
||||
gsk_render_node_unref (node);
|
||||
gsk_render_node_unref (stroke_node);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
gsk_render_node_unref (node);
|
||||
|
||||
return stroke_node;
|
||||
}
|
||||
|
||||
static void
|
||||
gtk_snapshot_clear_stroke (GtkSnapshotState *state)
|
||||
{
|
||||
gsk_path_unref (state->data.stroke.path);
|
||||
gsk_stroke_clear (&state->data.stroke.stroke);
|
||||
}
|
||||
|
||||
/**
|
||||
* gtk_snapshot_push_stroke:
|
||||
* @snapshot: a #GtkSnapshot
|
||||
* @path: The path to stroke
|
||||
* @stroke: The stroke attributes
|
||||
*
|
||||
* Strokes the given @path with the attributes given by @stroke and
|
||||
* an image.
|
||||
*
|
||||
* The image is recorded until the next call to [method@Gtk.Snapshot.pop].
|
||||
*
|
||||
* Note that the strokes are subject to the same transformation as
|
||||
* everything else, so uneven scaling will cause horizontal and vertical
|
||||
* strokes to have different widths.
|
||||
*
|
||||
* Since: 4.14
|
||||
*/
|
||||
void
|
||||
gtk_snapshot_push_stroke (GtkSnapshot *snapshot,
|
||||
GskPath *path,
|
||||
const GskStroke *stroke)
|
||||
{
|
||||
GtkSnapshotState *state;
|
||||
|
||||
gtk_snapshot_ensure_identity (snapshot);
|
||||
|
||||
state = gtk_snapshot_push_state (snapshot,
|
||||
gtk_snapshot_get_current_state (snapshot)->transform,
|
||||
gtk_snapshot_collect_stroke,
|
||||
gtk_snapshot_clear_stroke);
|
||||
|
||||
state->data.stroke.path = gsk_path_ref (path);
|
||||
gsk_stroke_init_copy (&state->data.stroke.stroke, stroke);
|
||||
}
|
||||
|
||||
static GskRenderNode *
|
||||
gtk_snapshot_collect_shadow (GtkSnapshot *snapshot,
|
||||
GtkSnapshotState *state,
|
||||
|
||||
@@ -87,6 +87,14 @@ void gtk_snapshot_push_clip (GtkSnapshot
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
void gtk_snapshot_push_rounded_clip (GtkSnapshot *snapshot,
|
||||
const GskRoundedRect *bounds);
|
||||
GDK_AVAILABLE_IN_4_14
|
||||
void gtk_snapshot_push_fill (GtkSnapshot *snapshot,
|
||||
GskPath *path,
|
||||
GskFillRule fill_rule);
|
||||
GDK_AVAILABLE_IN_4_14
|
||||
void gtk_snapshot_push_stroke (GtkSnapshot *snapshot,
|
||||
GskPath *path,
|
||||
const GskStroke *stroke);
|
||||
GDK_AVAILABLE_IN_ALL
|
||||
void gtk_snapshot_push_shadow (GtkSnapshot *snapshot,
|
||||
const GskShadow *shadow,
|
||||
|
||||
+5
-25
@@ -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);
|
||||
}
|
||||
|
||||
@@ -1100,18 +1100,6 @@ gtk_text_history_modified_changed (GtkTextHistory *self,
|
||||
peek->is_modified_set = TRUE;
|
||||
}
|
||||
|
||||
if ((peek = g_queue_peek_head (&self->redo_queue)))
|
||||
{
|
||||
if (peek->kind == ACTION_KIND_BARRIER)
|
||||
{
|
||||
if (!(peek = peek->link.next->data))
|
||||
return;
|
||||
}
|
||||
|
||||
peek->is_modified = TRUE;
|
||||
peek->is_modified_set = TRUE;
|
||||
}
|
||||
|
||||
self->is_modified = !!modified;
|
||||
self->is_modified_set = TRUE;
|
||||
|
||||
|
||||
+2
-1
@@ -30,7 +30,8 @@
|
||||
|
||||
#include <gdk/gdk.h>
|
||||
#include <gsk/gsk.h>
|
||||
#include <gtk/gtkenums.h>
|
||||
#include <gtk/gtkaccelgroup.h>
|
||||
#include <gtk/gtkborder.h>
|
||||
#include <gtk/gtkshortcut.h>
|
||||
#include <gtk/gtkshortcutaction.h>
|
||||
#include <gtk/gtktypes.h>
|
||||
|
||||
@@ -28,7 +28,6 @@
|
||||
|
||||
#include "gtkactionmuxerprivate.h"
|
||||
#include "gtkatcontextprivate.h"
|
||||
#include "gtkborder.h"
|
||||
#include "gtkcsstypesprivate.h"
|
||||
#include "gtkeventcontrollerprivate.h"
|
||||
#include "gtklistlistmodelprivate.h"
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -298,6 +298,12 @@ create_list_model_for_render_node (GskRenderNode *node)
|
||||
case GSK_ROUNDED_CLIP_NODE:
|
||||
return create_render_node_list_model ((GskRenderNode *[1]) { gsk_rounded_clip_node_get_child (node) }, 1);
|
||||
|
||||
case GSK_FILL_NODE:
|
||||
return create_render_node_list_model ((GskRenderNode *[1]) { gsk_fill_node_get_child (node) }, 1);
|
||||
|
||||
case GSK_STROKE_NODE:
|
||||
return create_render_node_list_model ((GskRenderNode *[1]) { gsk_stroke_node_get_child (node) }, 1);
|
||||
|
||||
case GSK_SHADOW_NODE:
|
||||
return create_render_node_list_model ((GskRenderNode *[1]) { gsk_shadow_node_get_child (node) }, 1);
|
||||
|
||||
@@ -425,6 +431,10 @@ node_type_name (GskRenderNodeType type)
|
||||
return "Clip";
|
||||
case GSK_ROUNDED_CLIP_NODE:
|
||||
return "Rounded Clip";
|
||||
case GSK_FILL_NODE:
|
||||
return "Fill";
|
||||
case GSK_STROKE_NODE:
|
||||
return "Stroke";
|
||||
case GSK_SHADOW_NODE:
|
||||
return "Shadow";
|
||||
case GSK_BLEND_NODE:
|
||||
@@ -466,6 +476,8 @@ node_name (GskRenderNode *node)
|
||||
case GSK_REPEAT_NODE:
|
||||
case GSK_CLIP_NODE:
|
||||
case GSK_ROUNDED_CLIP_NODE:
|
||||
case GSK_FILL_NODE:
|
||||
case GSK_STROKE_NODE:
|
||||
case GSK_SHADOW_NODE:
|
||||
case GSK_BLEND_NODE:
|
||||
case GSK_MASK_NODE:
|
||||
@@ -894,6 +906,20 @@ add_float_row (GListStore *store,
|
||||
g_free (text);
|
||||
}
|
||||
|
||||
static const char *
|
||||
enum_to_nick (GType type,
|
||||
int value)
|
||||
{
|
||||
GEnumClass *class;
|
||||
GEnumValue *v;
|
||||
|
||||
class = g_type_class_ref (type);
|
||||
v = g_enum_get_value (class, value);
|
||||
g_type_class_unref (class);
|
||||
|
||||
return v->value_nick;
|
||||
}
|
||||
|
||||
static void
|
||||
populate_render_node_properties (GListStore *store,
|
||||
GskRenderNode *node)
|
||||
@@ -1133,9 +1159,7 @@ populate_render_node_properties (GListStore *store,
|
||||
case GSK_BLEND_NODE:
|
||||
{
|
||||
GskBlendMode mode = gsk_blend_node_get_blend_mode (node);
|
||||
tmp = g_enum_to_string (GSK_TYPE_BLEND_MODE, mode);
|
||||
add_text_row (store, "Blendmode", tmp);
|
||||
g_free (tmp);
|
||||
add_text_row (store, "Blendmode", enum_to_nick (GSK_TYPE_BLEND_MODE, mode));
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -1377,6 +1401,39 @@ populate_render_node_properties (GListStore *store,
|
||||
}
|
||||
break;
|
||||
|
||||
case GSK_FILL_NODE:
|
||||
{
|
||||
GskPath *path = gsk_fill_node_get_path (node);
|
||||
GskFillRule fill_rule = gsk_fill_node_get_fill_rule (node);
|
||||
|
||||
tmp = gsk_path_to_string (path);
|
||||
add_text_row (store, "Path", tmp);
|
||||
g_free (tmp);
|
||||
|
||||
add_text_row (store, "Fill rule", enum_to_nick (GSK_TYPE_FILL_RULE, fill_rule));
|
||||
}
|
||||
break;
|
||||
|
||||
case GSK_STROKE_NODE:
|
||||
{
|
||||
GskPath *path = gsk_stroke_node_get_path (node);
|
||||
const GskStroke *stroke = gsk_stroke_node_get_stroke (node);
|
||||
GskLineCap line_cap = gsk_stroke_get_line_cap (stroke);
|
||||
GskLineJoin line_join = gsk_stroke_get_line_join (stroke);
|
||||
|
||||
tmp = gsk_path_to_string (path);
|
||||
add_text_row (store, "Path", tmp);
|
||||
g_free (tmp);
|
||||
|
||||
tmp = g_strdup_printf ("%.2f", gsk_stroke_get_line_width (stroke));
|
||||
add_text_row (store, "Line width", tmp);
|
||||
g_free (tmp);
|
||||
|
||||
add_text_row (store, "Line cap", enum_to_nick (GSK_TYPE_LINE_CAP, line_cap));
|
||||
add_text_row (store, "Line join", enum_to_nick (GSK_TYPE_LINE_JOIN, line_join));
|
||||
}
|
||||
break;
|
||||
|
||||
case GSK_CONTAINER_NODE:
|
||||
tmp = g_strdup_printf ("%d", gsk_container_node_get_n_children (node));
|
||||
add_text_row (store, "Children", tmp);
|
||||
|
||||
@@ -1075,6 +1075,7 @@ endif
|
||||
if macos_enabled
|
||||
gtk_macos_frameworks = [
|
||||
'AppKit',
|
||||
'Foundation',
|
||||
]
|
||||
gtk_deps += [dependency('appleframeworks', modules: gtk_macos_frameworks)]
|
||||
endif
|
||||
|
||||
+20
-9
@@ -1,5 +1,5 @@
|
||||
project('gtk', 'c',
|
||||
version: '4.12.1',
|
||||
version: '4.13.0',
|
||||
default_options: [
|
||||
'buildtype=debugoptimized',
|
||||
'warning_level=1',
|
||||
@@ -309,7 +309,6 @@ elif cc.get_id() == 'gcc' or cc.get_id() == 'clang'
|
||||
'missing-declarations',
|
||||
'missing-prototypes',
|
||||
'nonnull',
|
||||
'override-init',
|
||||
'pointer-to-int-cast',
|
||||
'redundant-decls',
|
||||
'return-type',
|
||||
@@ -818,15 +817,28 @@ endif
|
||||
gsk_packages = [ 'graphene-gobject-1.0 @0@'.format(graphene_req) ]
|
||||
gtk_packages = [ 'gio-2.0 @0@'.format(glib_req) ]
|
||||
|
||||
enabled_backends = []
|
||||
gio_pkgname = os_unix ? 'gio-unix-2.0' : 'gio-2.0'
|
||||
gdk_private_packages = [
|
||||
'@0@ @1@'.format(gio_pkgname, glib_req),
|
||||
'epoxy @0@'.format(epoxy_req),
|
||||
] + x11_pkgs + wayland_pkgs + cairo_backends
|
||||
gsk_private_packages = [] # all already in gdk_private_packages
|
||||
pangoft2_pkgs = (wayland_enabled or x11_enabled) ? ['pangoft2'] : []
|
||||
gtk_private_packages = pangoft2_pkgs
|
||||
|
||||
pkgs = []
|
||||
pkg_targets = []
|
||||
display_backends = []
|
||||
foreach backend: [ 'broadway', 'macos', 'wayland', 'win32', 'x11', ]
|
||||
if get_variable('@0@_enabled'.format(backend))
|
||||
enabled_backends += backend
|
||||
pkgs += ['gtk4-@0@'.format(backend)]
|
||||
pkg_targets += backend
|
||||
display_backends += [ backend ]
|
||||
endif
|
||||
endforeach
|
||||
|
||||
common_pc_variables = [
|
||||
'targets=@0@'.format(' '.join(enabled_backends)),
|
||||
'targets=@0@'.format(' '.join(pkg_targets)),
|
||||
'gtk_binary_version=@0@'.format(gtk_binary_version),
|
||||
'gtk_host=@0@-@1@'.format(host_machine.cpu_family(), host_machine.system()), # FIXME
|
||||
]
|
||||
@@ -841,14 +853,13 @@ pkg_config.generate(libgtk,
|
||||
)
|
||||
meson.override_dependency('gtk4', libgtk_dep)
|
||||
|
||||
foreach backend: enabled_backends
|
||||
pkg = 'gtk4-@0@'.format(backend)
|
||||
foreach pkg: pkgs
|
||||
pkg_config.generate(
|
||||
filebase: pkg,
|
||||
unescaped_variables: common_pc_variables,
|
||||
name: 'GTK',
|
||||
description: 'GTK Graphical UI Library',
|
||||
requires: ['gtk4', get_variable('@0@_public_deps'.format(backend), [])],
|
||||
requires: 'gtk4',
|
||||
)
|
||||
meson.override_dependency(pkg, libgtk_dep)
|
||||
endforeach
|
||||
@@ -893,7 +904,7 @@ endif
|
||||
|
||||
#### Summary ####
|
||||
|
||||
summary('Display backends', enabled_backends, section: 'Components')
|
||||
summary('Display backends', display_backends, section: 'Components')
|
||||
summary('Print backends', print_backends, section: 'Components')
|
||||
summary('Media backends', media_backends, section: 'Components')
|
||||
|
||||
|
||||
@@ -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__ */
|
||||
@@ -16,8 +16,8 @@ msgid ""
|
||||
msgstr ""
|
||||
"Project-Id-Version: gtk\n"
|
||||
"Report-Msgid-Bugs-To: https://gitlab.gnome.org/GNOME/gtk/-/issues/\n"
|
||||
"POT-Creation-Date: 2023-08-24 14:40+0000\n"
|
||||
"PO-Revision-Date: 2023-08-24 16:47+0200\n"
|
||||
"POT-Creation-Date: 2023-08-05 15:54+0000\n"
|
||||
"PO-Revision-Date: 2023-08-06 14:20+0200\n"
|
||||
"Last-Translator: Piotr Drąg <piotrdrag@gmail.com>\n"
|
||||
"Language-Team: Polish <community-poland@mozilla.org>\n"
|
||||
"Language: pl\n"
|
||||
@@ -141,7 +141,7 @@ msgstr "Program nie obsługuje API %s"
|
||||
|
||||
#. translators: This is about OpenGL backend names, like
|
||||
#. * "Trying to use X11 GLX, but EGL is already in use"
|
||||
#: gdk/gdkglcontext.c:1864
|
||||
#: gdk/gdkglcontext.c:1863
|
||||
#, c-format
|
||||
msgid "Trying to use %s, but %s is already in use"
|
||||
msgstr "Próbowanie użycia %s, ale %s jest już używane"
|
||||
@@ -573,7 +573,7 @@ msgstr "Odczytanie danych nie powiodło się w %d. rzędzie"
|
||||
#: gdk/macos/gdkmacospasteboard.c:211 gdk/wayland/gdkclipboard-wayland.c:240
|
||||
#: gdk/wayland/gdkdrop-wayland.c:207 gdk/wayland/gdkprimary-wayland.c:343
|
||||
#: gdk/win32/gdkdrop-win32.c:1018 gdk/win32/gdkdrop-win32.c:1063
|
||||
#: gdk/x11/gdkclipboard-x11.c:807 gdk/x11/gdkdrop-x11.c:235
|
||||
#: gdk/x11/gdkclipboard-x11.c:805 gdk/x11/gdkdrop-x11.c:235
|
||||
msgid "No compatible transfer format found"
|
||||
msgstr "Nie odnaleziono zgodnego formatu przesyłania"
|
||||
|
||||
@@ -801,11 +801,11 @@ msgstr[0] "Otwieranie %d elementu"
|
||||
msgstr[1] "Otwieranie %d elementów"
|
||||
msgstr[2] "Otwieranie %d elementów"
|
||||
|
||||
#: gdk/x11/gdkclipboard-x11.c:477
|
||||
#: gdk/x11/gdkclipboard-x11.c:475
|
||||
msgid "Clipboard manager could not store selection."
|
||||
msgstr "Menedżer schowka nie może przechować zaznaczenia."
|
||||
|
||||
#: gdk/x11/gdkclipboard-x11.c:657
|
||||
#: gdk/x11/gdkclipboard-x11.c:655
|
||||
msgid "Cannot store clipboard. No clipboard manager is active."
|
||||
msgstr "Nie można przechować schowka. Żaden menedżer schowka nie jest aktywny."
|
||||
|
||||
@@ -1073,13 +1073,13 @@ msgid "Pick a Color"
|
||||
msgstr "Wybór koloru"
|
||||
|
||||
#: gtk/deprecated/gtkcolorbutton.c:502 gtk/gtkcolorchooserwidget.c:313
|
||||
#: gtk/gtkcolordialogbutton.c:335
|
||||
#: gtk/gtkcolordialogbutton.c:302
|
||||
#, c-format
|
||||
msgid "Red %d%%, Green %d%%, Blue %d%%, Alpha %d%%"
|
||||
msgstr "Czerwony %d%%, zielony %d%%, niebieski %d%%, alfa %d%%"
|
||||
|
||||
#: gtk/deprecated/gtkcolorbutton.c:508 gtk/gtkcolorchooserwidget.c:319
|
||||
#: gtk/gtkcolordialogbutton.c:341
|
||||
#: gtk/gtkcolordialogbutton.c:308
|
||||
#, c-format
|
||||
msgid "Red %d%%, Green %d%%, Blue %d%%"
|
||||
msgstr "Czerwony %d%%, zielony %d%%, niebieski %d%%"
|
||||
@@ -1094,11 +1094,11 @@ msgid "Pick a Font"
|
||||
msgstr "Wybór czcionki"
|
||||
|
||||
#: gtk/deprecated/gtkfontbutton.c:597 gtk/gtkfilechooserwidget.c:3871
|
||||
#: gtk/gtkfontdialogbutton.c:126 gtk/inspector/visual.ui:169
|
||||
#: gtk/gtkfontdialogbutton.c:115 gtk/inspector/visual.ui:169
|
||||
msgid "Font"
|
||||
msgstr "Czcionka"
|
||||
|
||||
#: gtk/deprecated/gtkfontbutton.c:1152 gtk/gtkfontdialogbutton.c:652
|
||||
#: gtk/deprecated/gtkfontbutton.c:1152 gtk/gtkfontdialogbutton.c:614
|
||||
msgctxt "font"
|
||||
msgid "None"
|
||||
msgstr "Brak"
|
||||
@@ -2249,7 +2249,7 @@ msgstr "_Otwórz"
|
||||
msgid "_Save"
|
||||
msgstr "_Zapisz"
|
||||
|
||||
#: gtk/gtkfilechoosernativequartz.c:344 gtk/ui/gtkfilechooserwidget.ui:288
|
||||
#: gtk/gtkfilechoosernativequartz.c:340 gtk/ui/gtkfilechooserwidget.ui:288
|
||||
msgid "Select which types of files are shown"
|
||||
msgstr "Wybór typów wyświetlanych plików"
|
||||
|
||||
@@ -2322,7 +2322,7 @@ msgid "If you delete an item, it will be permanently lost."
|
||||
msgstr "Jeśli element zostanie usunięty, to zostanie on bezpowrotnie utracony."
|
||||
|
||||
#: gtk/gtkfilechooserwidget.c:1185 gtk/gtkfilechooserwidget.c:1815
|
||||
#: gtk/gtklabel.c:5695 gtk/gtktext.c:6145 gtk/gtktextview.c:9018
|
||||
#: gtk/gtklabel.c:5695 gtk/gtktext.c:6125 gtk/gtktextview.c:9018
|
||||
msgid "_Delete"
|
||||
msgstr "_Usuń"
|
||||
|
||||
@@ -2463,7 +2463,7 @@ msgstr "Program"
|
||||
msgid "Audio"
|
||||
msgstr "Dźwięk"
|
||||
|
||||
#: gtk/gtkfilechooserwidget.c:3872 gtk/gtkfilefilter.c:1032
|
||||
#: gtk/gtkfilechooserwidget.c:3872 gtk/gtkfilefilter.c:1035
|
||||
msgid "Image"
|
||||
msgstr "Obraz"
|
||||
|
||||
@@ -2574,7 +2574,7 @@ msgstr "Wybór katalogów"
|
||||
msgid "Select a Folder"
|
||||
msgstr "Wybór katalogu"
|
||||
|
||||
#: gtk/gtkfilefilter.c:1045
|
||||
#: gtk/gtkfilefilter.c:1048
|
||||
msgid "Unspecified"
|
||||
msgstr "Nieokreślone"
|
||||
|
||||
@@ -2662,19 +2662,19 @@ msgstr "Zamknij"
|
||||
msgid "Close the infobar"
|
||||
msgstr "Zamknij pasek informacyjny"
|
||||
|
||||
#: gtk/gtklabel.c:5692 gtk/gtktext.c:6133 gtk/gtktextview.c:9006
|
||||
#: gtk/gtklabel.c:5692 gtk/gtktext.c:6113 gtk/gtktextview.c:9006
|
||||
msgid "Cu_t"
|
||||
msgstr "_Wytnij"
|
||||
|
||||
#: gtk/gtklabel.c:5693 gtk/gtktext.c:6137 gtk/gtktextview.c:9010
|
||||
#: gtk/gtklabel.c:5693 gtk/gtktext.c:6117 gtk/gtktextview.c:9010
|
||||
msgid "_Copy"
|
||||
msgstr "S_kopiuj"
|
||||
|
||||
#: gtk/gtklabel.c:5694 gtk/gtktext.c:6141 gtk/gtktextview.c:9014
|
||||
#: gtk/gtklabel.c:5694 gtk/gtktext.c:6121 gtk/gtktextview.c:9014
|
||||
msgid "_Paste"
|
||||
msgstr "Wk_lej"
|
||||
|
||||
#: gtk/gtklabel.c:5700 gtk/gtktext.c:6154 gtk/gtktextview.c:9039
|
||||
#: gtk/gtklabel.c:5700 gtk/gtktext.c:6134 gtk/gtktextview.c:9039
|
||||
msgid "Select _All"
|
||||
msgstr "Z_aznacz wszystko"
|
||||
|
||||
@@ -2890,7 +2890,7 @@ msgstr "Poprzednia karta"
|
||||
msgid "Next tab"
|
||||
msgstr "Następna karta"
|
||||
|
||||
#: gtk/gtknotebook.c:4331 gtk/gtknotebook.c:6541
|
||||
#: gtk/gtknotebook.c:4331 gtk/gtknotebook.c:6539
|
||||
#, c-format
|
||||
msgid "Page %u"
|
||||
msgstr "%u. strona"
|
||||
@@ -3626,7 +3626,7 @@ msgctxt "accessibility"
|
||||
msgid "Sidebar"
|
||||
msgstr "Panel boczny"
|
||||
|
||||
#: gtk/gtktext.c:6159 gtk/gtktextview.c:9044
|
||||
#: gtk/gtktext.c:6139 gtk/gtktextview.c:9044
|
||||
msgid "Insert _Emoji"
|
||||
msgstr "Wstaw _emoji"
|
||||
|
||||
|
||||
@@ -0,0 +1,92 @@
|
||||
/*
|
||||
* Copyright © 2023 Red Hat, Inc.
|
||||
*
|
||||
* 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: Matthias Clasen <mclasen@redhat.com>
|
||||
*/
|
||||
|
||||
#include <gtk/gtk.h>
|
||||
#include <gsk/gskboundingboxprivate.h>
|
||||
|
||||
static void
|
||||
init_random_rect (graphene_rect_t *r)
|
||||
{
|
||||
r->origin.x = g_test_rand_double_range (0, 1000);
|
||||
r->origin.y = g_test_rand_double_range (0, 1000);
|
||||
r->size.width = g_test_rand_double_range (0, 1000);
|
||||
r->size.height = g_test_rand_double_range (0, 1000);
|
||||
}
|
||||
|
||||
static void
|
||||
test_to_rect (void)
|
||||
{
|
||||
graphene_rect_t rect, rect2;
|
||||
GskBoundingBox bb;
|
||||
graphene_point_t p, p2;
|
||||
|
||||
for (unsigned int i = 0; i < 100; i++)
|
||||
{
|
||||
init_random_rect (&rect);
|
||||
|
||||
gsk_bounding_box_init_from_rect (&bb, &rect);
|
||||
gsk_bounding_box_to_rect (&bb, &rect2);
|
||||
|
||||
graphene_rect_get_top_left (&rect, &p);
|
||||
graphene_rect_get_top_left (&rect2, &p2);
|
||||
|
||||
/* Note: that we can't assert equality here is the reason
|
||||
* GskBoundingBox exists.
|
||||
*/
|
||||
g_assert_true (graphene_point_near (&p, &p2, 0.001));
|
||||
|
||||
graphene_rect_get_bottom_right (&rect, &p);
|
||||
graphene_rect_get_bottom_right (&rect2, &p2);
|
||||
|
||||
g_assert_true (graphene_point_near (&p, &p2, 0.001));
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
test_contains (void)
|
||||
{
|
||||
graphene_rect_t rect;
|
||||
GskBoundingBox bb;
|
||||
graphene_point_t p;
|
||||
|
||||
for (unsigned int i = 0; i < 100; i++)
|
||||
{
|
||||
init_random_rect (&rect);
|
||||
|
||||
gsk_bounding_box_init_from_rect (&bb, &rect);
|
||||
|
||||
g_assert_true (gsk_bounding_box_contains_point (&bb, &bb.min));
|
||||
g_assert_true (gsk_bounding_box_contains_point (&bb, &bb.max));
|
||||
|
||||
graphene_point_interpolate (&bb.min, &bb.max, 0.5, &p);
|
||||
g_assert_true (gsk_bounding_box_contains_point (&bb, &p));
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc,
|
||||
char *argv[])
|
||||
{
|
||||
gtk_test_init (&argc, &argv, NULL);
|
||||
|
||||
g_test_add_func ("/bounding-box/to-rect", test_to_rect);
|
||||
g_test_add_func ("/bounding-box/contains", test_contains);
|
||||
|
||||
return g_test_run ();
|
||||
}
|
||||
@@ -0,0 +1,13 @@
|
||||
fill {
|
||||
child: color {
|
||||
bounds: 0 0 100 100;
|
||||
color: rgb(255,0,0);
|
||||
}
|
||||
path: "\
|
||||
M 10 10\
|
||||
L 90 10\
|
||||
L 90 90\
|
||||
L 10 90\
|
||||
Z";
|
||||
fill-rule: winding;
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 250 B |
@@ -0,0 +1,19 @@
|
||||
color {
|
||||
bounds: 0 0 100 100;
|
||||
color: rgb(0,0,0);
|
||||
}
|
||||
stroke {
|
||||
child: color {
|
||||
bounds: 0 0 100 100;
|
||||
color: rgb(255,0,0);
|
||||
}
|
||||
path: "\
|
||||
M 10 10\
|
||||
L 90 10\
|
||||
L 90 90\
|
||||
L 10 90\
|
||||
Z";
|
||||
line-width: 2;
|
||||
line-cap: butt;
|
||||
line-join: miter;
|
||||
}
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 346 B |
@@ -0,0 +1,159 @@
|
||||
/*
|
||||
* 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>
|
||||
|
||||
#include "gsk/gskcurveprivate.h"
|
||||
|
||||
static void
|
||||
test_curve_tangents (void)
|
||||
{
|
||||
GskCurve c;
|
||||
graphene_point_t p[4];
|
||||
graphene_vec2_t t;
|
||||
|
||||
graphene_point_init (&p[0], 0, 0);
|
||||
graphene_point_init (&p[1], 100, 0);
|
||||
gsk_curve_init (&c, gsk_pathop_encode (GSK_PATH_LINE, p));
|
||||
|
||||
gsk_curve_get_start_tangent (&c, &t);
|
||||
g_assert_true (graphene_vec2_near (&t, graphene_vec2_x_axis (), 0.0001));
|
||||
gsk_curve_get_end_tangent (&c, &t);
|
||||
g_assert_true (graphene_vec2_near (&t, graphene_vec2_x_axis (), 0.0001));
|
||||
|
||||
graphene_point_init (&p[0], 0, 0);
|
||||
graphene_point_init (&p[1], 0, 100);
|
||||
gsk_curve_init (&c, gsk_pathop_encode (GSK_PATH_LINE, p));
|
||||
|
||||
gsk_curve_get_start_tangent (&c, &t);
|
||||
g_assert_true (graphene_vec2_near (&t, graphene_vec2_y_axis (), 0.0001));
|
||||
gsk_curve_get_end_tangent (&c, &t);
|
||||
g_assert_true (graphene_vec2_near (&t, graphene_vec2_y_axis (), 0.0001));
|
||||
|
||||
graphene_point_init (&p[0], 0, 0);
|
||||
graphene_point_init (&p[1], 50, 0);
|
||||
graphene_point_init (&p[2], 100, 50);
|
||||
graphene_point_init (&p[3], 100, 100);
|
||||
gsk_curve_init (&c, gsk_pathop_encode (GSK_PATH_CUBIC, p));
|
||||
|
||||
gsk_curve_get_start_tangent (&c, &t);
|
||||
g_assert_true (graphene_vec2_near (&t, graphene_vec2_x_axis (), 0.0001));
|
||||
gsk_curve_get_end_tangent (&c, &t);
|
||||
g_assert_true (graphene_vec2_near (&t, graphene_vec2_y_axis (), 0.0001));
|
||||
}
|
||||
|
||||
static void
|
||||
test_curve_degenerate_tangents (void)
|
||||
{
|
||||
GskCurve c;
|
||||
graphene_point_t p[4];
|
||||
graphene_vec2_t t;
|
||||
|
||||
graphene_point_init (&p[0], 0, 0);
|
||||
graphene_point_init (&p[1], 0, 0);
|
||||
graphene_point_init (&p[2], 100, 0);
|
||||
graphene_point_init (&p[3], 100, 0);
|
||||
gsk_curve_init (&c, gsk_pathop_encode (GSK_PATH_CUBIC, p));
|
||||
|
||||
gsk_curve_get_start_tangent (&c, &t);
|
||||
g_assert_true (graphene_vec2_near (&t, graphene_vec2_x_axis (), 0.0001));
|
||||
gsk_curve_get_end_tangent (&c, &t);
|
||||
g_assert_true (graphene_vec2_near (&t, graphene_vec2_x_axis (), 0.0001));
|
||||
|
||||
graphene_point_init (&p[0], 0, 0);
|
||||
graphene_point_init (&p[1], 50, 0);
|
||||
graphene_point_init (&p[2], 50, 0);
|
||||
graphene_point_init (&p[3], 100, 0);
|
||||
gsk_curve_init (&c, gsk_pathop_encode (GSK_PATH_CUBIC, p));
|
||||
|
||||
gsk_curve_get_start_tangent (&c, &t);
|
||||
g_assert_true (graphene_vec2_near (&t, graphene_vec2_x_axis (), 0.0001));
|
||||
gsk_curve_get_end_tangent (&c, &t);
|
||||
g_assert_true (graphene_vec2_near (&t, graphene_vec2_x_axis (), 0.0001));
|
||||
}
|
||||
|
||||
static gboolean
|
||||
pathop_cb (GskPathOperation op,
|
||||
const graphene_point_t *pts,
|
||||
gsize n_pts,
|
||||
gpointer user_data)
|
||||
{
|
||||
GskCurve *curve = user_data;
|
||||
|
||||
g_assert (op != GSK_PATH_CLOSE);
|
||||
|
||||
if (op == GSK_PATH_MOVE)
|
||||
return TRUE;
|
||||
|
||||
gsk_curve_init_foreach (curve, op, pts, n_pts);
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
static void
|
||||
parse_curve (GskCurve *c,
|
||||
const char *str)
|
||||
{
|
||||
GskPath *path = gsk_path_parse (str);
|
||||
|
||||
gsk_path_foreach (path, -1, pathop_cb, c);
|
||||
|
||||
gsk_path_unref (path);
|
||||
}
|
||||
|
||||
static void
|
||||
test_curve_crossing (void)
|
||||
{
|
||||
struct {
|
||||
const char *c;
|
||||
const graphene_point_t p;
|
||||
int crossing;
|
||||
} tests[] = {
|
||||
{ "M 0 0 L 200 200", { 200, 100 }, 0 },
|
||||
{ "M 0 0 L 200 200", { 0, 100 }, 1 },
|
||||
{ "M 0 200 L 200 0", { 0, 100 }, -1 },
|
||||
{ "M 0 0 C 100 100 200 200 300 300", { 200, 100 }, 0 },
|
||||
{ "M 0 0 C 100 100 200 200 300 300", { 0, 100 }, 1 },
|
||||
{ "M 0 300 C 100 200 200 100 300 0", { 0, 100 }, -1 },
|
||||
{ "M 0 0 C 100 600 200 -300 300 300", { 0, 150 }, 1 },
|
||||
{ "M 0 0 C 100 600 200 -300 300 300", { 100, 150 }, 0 },
|
||||
{ "M 0 0 C 100 600 200 -300 300 300", { 200, 150 }, 1 },
|
||||
};
|
||||
|
||||
for (unsigned int i = 0; i < G_N_ELEMENTS (tests); i++)
|
||||
{
|
||||
GskCurve c;
|
||||
|
||||
parse_curve (&c, tests[i].c);
|
||||
|
||||
g_assert_true (gsk_curve_get_crossing (&c, &tests[i].p) == tests[i].crossing);
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc,
|
||||
char *argv[])
|
||||
{
|
||||
gtk_test_init (&argc, &argv, NULL);
|
||||
|
||||
g_test_add_func ("/curve/special/tangents", test_curve_tangents);
|
||||
g_test_add_func ("/curve/special/degenerate-tangents", test_curve_degenerate_tangents);
|
||||
g_test_add_func ("/curve/special/crossing", test_curve_crossing);
|
||||
|
||||
return g_test_run ();
|
||||
}
|
||||
@@ -0,0 +1,337 @@
|
||||
#include <gtk/gtk.h>
|
||||
#include "gsk/gskcurveprivate.h"
|
||||
|
||||
static void
|
||||
init_random_point (graphene_point_t *p)
|
||||
{
|
||||
p->x = g_test_rand_double_range (0, 1000);
|
||||
p->y = g_test_rand_double_range (0, 1000);
|
||||
}
|
||||
|
||||
static void
|
||||
init_random_curve_with_op (GskCurve *curve,
|
||||
GskPathOperation min_op,
|
||||
GskPathOperation max_op)
|
||||
{
|
||||
switch (g_test_rand_int_range (min_op, max_op + 1))
|
||||
{
|
||||
case GSK_PATH_LINE:
|
||||
{
|
||||
graphene_point_t p[2];
|
||||
|
||||
init_random_point (&p[0]);
|
||||
init_random_point (&p[1]);
|
||||
gsk_curve_init (curve, gsk_pathop_encode (GSK_PATH_LINE, p));
|
||||
}
|
||||
break;
|
||||
|
||||
case GSK_PATH_QUAD:
|
||||
{
|
||||
graphene_point_t p[3];
|
||||
|
||||
init_random_point (&p[0]);
|
||||
init_random_point (&p[1]);
|
||||
init_random_point (&p[2]);
|
||||
gsk_curve_init (curve, gsk_pathop_encode (GSK_PATH_QUAD, p));
|
||||
}
|
||||
break;
|
||||
|
||||
case GSK_PATH_CUBIC:
|
||||
{
|
||||
graphene_point_t p[4];
|
||||
|
||||
init_random_point (&p[0]);
|
||||
init_random_point (&p[1]);
|
||||
init_random_point (&p[2]);
|
||||
init_random_point (&p[3]);
|
||||
gsk_curve_init (curve, gsk_pathop_encode (GSK_PATH_CUBIC, p));
|
||||
}
|
||||
break;
|
||||
|
||||
default:
|
||||
g_assert_not_reached ();
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
init_random_curve (GskCurve *curve)
|
||||
{
|
||||
init_random_curve_with_op (curve, GSK_PATH_LINE, GSK_PATH_CUBIC);
|
||||
}
|
||||
|
||||
static void
|
||||
test_curve_tangents (void)
|
||||
{
|
||||
for (int i = 0; i < 100; i++)
|
||||
{
|
||||
GskCurve c;
|
||||
graphene_vec2_t vec, exact;
|
||||
|
||||
init_random_curve (&c);
|
||||
|
||||
gsk_curve_get_tangent (&c, 0, &vec);
|
||||
g_assert_cmpfloat_with_epsilon (graphene_vec2_length (&vec), 1.0f, 0.00001);
|
||||
gsk_curve_get_start_tangent (&c, &exact);
|
||||
g_assert_cmpfloat_with_epsilon (graphene_vec2_length (&exact), 1.0f, 0.00001);
|
||||
g_assert_true (graphene_vec2_near (&vec, &exact, 0.05));
|
||||
|
||||
gsk_curve_get_tangent (&c, 1, &vec);
|
||||
g_assert_cmpfloat_with_epsilon (graphene_vec2_length (&vec), 1.0f, 0.00001);
|
||||
gsk_curve_get_end_tangent (&c, &exact);
|
||||
g_assert_cmpfloat_with_epsilon (graphene_vec2_length (&exact), 1.0f, 0.00001);
|
||||
g_assert_true (graphene_vec2_near (&vec, &exact, 0.05));
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
test_curve_points (void)
|
||||
{
|
||||
for (int i = 0; i < 100; i++)
|
||||
{
|
||||
GskCurve c;
|
||||
graphene_point_t p;
|
||||
|
||||
init_random_curve (&c);
|
||||
|
||||
/* We can assert equality here because evaluating the polynomials with 0
|
||||
* has no effect on accuracy.
|
||||
*/
|
||||
gsk_curve_get_point (&c, 0, &p);
|
||||
g_assert_true (graphene_point_equal (gsk_curve_get_start_point (&c), &p));
|
||||
/* But here we evaluate the polynomials with 1 which gives the highest possible
|
||||
* accuracy error. So we'll just be generous here.
|
||||
*/
|
||||
gsk_curve_get_point (&c, 1, &p);
|
||||
g_assert_true (graphene_point_near (gsk_curve_get_end_point (&c), &p, 0.05));
|
||||
}
|
||||
}
|
||||
|
||||
/* at this point the subdivision stops and the decomposer
|
||||
* violates tolerance rules
|
||||
*/
|
||||
#define MIN_PROGRESS (1/1024.f)
|
||||
|
||||
typedef struct
|
||||
{
|
||||
graphene_point_t p;
|
||||
float t;
|
||||
} PointOnLine;
|
||||
|
||||
static gboolean
|
||||
add_line_to_array (const graphene_point_t *from,
|
||||
const graphene_point_t *to,
|
||||
float from_progress,
|
||||
float to_progress,
|
||||
GskCurveLineReason reason,
|
||||
gpointer user_data)
|
||||
{
|
||||
GArray *array = user_data;
|
||||
PointOnLine *last = &g_array_index (array, PointOnLine, array->len - 1);
|
||||
|
||||
g_assert_true (array->len > 0);
|
||||
g_assert_cmpfloat (from_progress, >=, 0.0f);
|
||||
g_assert_cmpfloat (from_progress, <, to_progress);
|
||||
g_assert_cmpfloat (to_progress, <=, 1.0f);
|
||||
|
||||
g_assert_true (graphene_point_equal (&last->p, from));
|
||||
g_assert_cmpfloat (last->t, ==, from_progress);
|
||||
|
||||
g_array_append_vals (array, (PointOnLine[1]) { { *to, to_progress } }, 1);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
test_curve_decompose (void)
|
||||
{
|
||||
static const float tolerance = 0.5;
|
||||
|
||||
for (int i = 0; i < 100; i++)
|
||||
{
|
||||
GArray *array;
|
||||
GskCurve c;
|
||||
|
||||
init_random_curve (&c);
|
||||
|
||||
array = g_array_new (FALSE, FALSE, sizeof (PointOnLine));
|
||||
g_array_append_vals (array, (PointOnLine[1]) { { *gsk_curve_get_start_point (&c), 0.f } }, 1);
|
||||
|
||||
g_assert_true (gsk_curve_decompose (&c, tolerance, add_line_to_array, array));
|
||||
|
||||
g_assert_cmpint (array->len, >=, 2); /* We at least got a line to the end */
|
||||
g_assert_cmpfloat (g_array_index (array, PointOnLine, array->len - 1).t, ==, 1.0);
|
||||
|
||||
for (int j = 0; j < array->len; j++)
|
||||
{
|
||||
PointOnLine *pol = &g_array_index (array, PointOnLine, j);
|
||||
graphene_point_t p;
|
||||
|
||||
/* Check that the points we got are actually on the line */
|
||||
gsk_curve_get_point (&c, pol->t, &p);
|
||||
g_assert_true (graphene_point_near (&pol->p, &p, 0.05));
|
||||
|
||||
/* Check that the mid point is not further than the tolerance */
|
||||
if (j > 0)
|
||||
{
|
||||
PointOnLine *last = &g_array_index (array, PointOnLine, j - 1);
|
||||
graphene_point_t mid;
|
||||
|
||||
if (pol->t - last->t > MIN_PROGRESS)
|
||||
{
|
||||
graphene_point_interpolate (&last->p, &pol->p, 0.5, &mid);
|
||||
gsk_curve_get_point (&c, (pol->t + last->t) / 2, &p);
|
||||
/* The decomposer does this cheaper Manhattan distance test,
|
||||
* so graphene_point_near() does not work */
|
||||
g_assert_cmpfloat (fabs (mid.x - p.x), <=, tolerance);
|
||||
g_assert_cmpfloat (fabs (mid.y - p.y), <=, tolerance);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
g_array_unref (array);
|
||||
}
|
||||
}
|
||||
|
||||
static gboolean
|
||||
add_curve_to_array (GskPathOperation op,
|
||||
const graphene_point_t *pts,
|
||||
gsize n_pts,
|
||||
gpointer user_data)
|
||||
{
|
||||
GArray *array = user_data;
|
||||
GskCurve c;
|
||||
|
||||
gsk_curve_init_foreach (&c, op, pts, n_pts);
|
||||
g_array_append_val (array, c);
|
||||
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
static void
|
||||
test_curve_decompose_into (GskPathForeachFlags flags)
|
||||
{
|
||||
for (int i = 0; i < 100; i++)
|
||||
{
|
||||
GskCurve c;
|
||||
GskPathBuilder *builder;
|
||||
const graphene_point_t *s;
|
||||
GskPath *path;
|
||||
GArray *array;
|
||||
|
||||
init_random_curve (&c);
|
||||
|
||||
builder = gsk_path_builder_new ();
|
||||
|
||||
s = gsk_curve_get_start_point (&c);
|
||||
gsk_path_builder_move_to (builder, s->x, s->y);
|
||||
gsk_curve_builder_to (&c, builder);
|
||||
path = gsk_path_builder_free_to_path (builder);
|
||||
|
||||
array = g_array_new (FALSE, FALSE, sizeof (GskCurve));
|
||||
|
||||
g_assert_true (gsk_curve_decompose_curve (&c, flags, 0.1, add_curve_to_array, array));
|
||||
|
||||
g_assert_cmpint (array->len, >=, 1);
|
||||
|
||||
for (int j = 0; j < array->len; j++)
|
||||
{
|
||||
GskCurve *c2 = &g_array_index (array, GskCurve, j);
|
||||
|
||||
switch (c2->op)
|
||||
{
|
||||
case GSK_PATH_MOVE:
|
||||
case GSK_PATH_CLOSE:
|
||||
case GSK_PATH_LINE:
|
||||
break;
|
||||
case GSK_PATH_QUAD:
|
||||
g_assert_true (flags & GSK_PATH_FOREACH_ALLOW_QUAD);
|
||||
break;
|
||||
case GSK_PATH_CUBIC:
|
||||
g_assert_true (flags & GSK_PATH_FOREACH_ALLOW_CUBIC);
|
||||
break;
|
||||
default:
|
||||
g_assert_not_reached ();
|
||||
}
|
||||
}
|
||||
|
||||
g_array_unref (array);
|
||||
gsk_path_unref (path);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
test_curve_decompose_into_line (void)
|
||||
{
|
||||
test_curve_decompose_into (0);
|
||||
}
|
||||
|
||||
static void
|
||||
test_curve_decompose_into_quad (void)
|
||||
{
|
||||
test_curve_decompose_into (GSK_PATH_FOREACH_ALLOW_QUAD);
|
||||
}
|
||||
|
||||
static void
|
||||
test_curve_decompose_into_cubic (void)
|
||||
{
|
||||
test_curve_decompose_into (GSK_PATH_FOREACH_ALLOW_CUBIC);
|
||||
}
|
||||
|
||||
/* Some sanity checks for splitting curves. */
|
||||
static void
|
||||
test_curve_split (void)
|
||||
{
|
||||
for (int i = 0; i < 100; i++)
|
||||
{
|
||||
GskCurve c;
|
||||
GskCurve c1, c2;
|
||||
graphene_point_t p;
|
||||
graphene_vec2_t t, t1, t2;
|
||||
|
||||
init_random_curve (&c);
|
||||
|
||||
gsk_curve_split (&c, 0.5, &c1, &c2);
|
||||
|
||||
g_assert_true (c1.op == c.op);
|
||||
g_assert_true (c2.op == c.op);
|
||||
|
||||
g_assert_true (graphene_point_near (gsk_curve_get_start_point (&c),
|
||||
gsk_curve_get_start_point (&c1), 0.005));
|
||||
g_assert_true (graphene_point_near (gsk_curve_get_end_point (&c1),
|
||||
gsk_curve_get_start_point (&c2), 0.005));
|
||||
g_assert_true (graphene_point_near (gsk_curve_get_end_point (&c),
|
||||
gsk_curve_get_end_point (&c2), 0.005));
|
||||
gsk_curve_get_point (&c, 0.5, &p);
|
||||
gsk_curve_get_tangent (&c, 0.5, &t);
|
||||
g_assert_true (graphene_point_near (gsk_curve_get_end_point (&c1), &p, 0.005));
|
||||
g_assert_true (graphene_point_near (gsk_curve_get_start_point (&c2), &p, 0.005));
|
||||
|
||||
gsk_curve_get_start_tangent (&c, &t1);
|
||||
gsk_curve_get_start_tangent (&c1, &t2);
|
||||
g_assert_true (graphene_vec2_near (&t1, &t2, 0.005));
|
||||
gsk_curve_get_end_tangent (&c1, &t1);
|
||||
gsk_curve_get_start_tangent (&c2, &t2);
|
||||
g_assert_true (graphene_vec2_near (&t1, &t2, 0.005));
|
||||
g_assert_true (graphene_vec2_near (&t, &t1, 0.005));
|
||||
g_assert_true (graphene_vec2_near (&t, &t2, 0.005));
|
||||
gsk_curve_get_end_tangent (&c, &t1);
|
||||
gsk_curve_get_end_tangent (&c2, &t2);
|
||||
g_assert_true (graphene_vec2_near (&t1, &t2, 0.005));
|
||||
}
|
||||
}
|
||||
|
||||
int
|
||||
main (int argc, char *argv[])
|
||||
{
|
||||
(g_test_init) (&argc, &argv, NULL);
|
||||
|
||||
g_test_add_func ("/curve/points", test_curve_points);
|
||||
g_test_add_func ("/curve/tangents", test_curve_tangents);
|
||||
g_test_add_func ("/curve/decompose", test_curve_decompose);
|
||||
g_test_add_func ("/curve/decompose/into/line", test_curve_decompose_into_line);
|
||||
g_test_add_func ("/curve/decompose/into/quad", test_curve_decompose_into_quad);
|
||||
g_test_add_func ("/curve/decompose/into/cubic", test_curve_decompose_into_cubic);
|
||||
g_test_add_func ("/curve/split", test_curve_split);
|
||||
|
||||
return g_test_run ();
|
||||
}
|
||||
@@ -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 ();
|
||||
}
|
||||
@@ -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 ();
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user