Class Path
- All Implemented Interfaces:
Proxy
Paths can used for rendering (filling or stroking) and for animations (e.g. as trajectories).
GskPath is an immutable, opaque, reference-counted struct.
After creation, you cannot change the types it represents. Instead,
new GskPath objects have to be created. The Gsk.PathBuilder
structure is meant to help in this endeavor.
Conceptually, a path consists of zero or more contours (continuous, connected curves), each of which may or may not be closed. Contours are typically constructed from Bézier segments.

- Since:
- 4.14
-
Constructor Summary
ConstructorsConstructorDescriptionPath(MemorySegment address) Create a Path proxy instance for the provided memory address. -
Method Summary
Modifier and TypeMethodDescriptionbooleanforeach(Set<PathForeachFlags> flags, @Nullable PathForeachFunc func) Callsfuncfor every operation of the path.booleanforeach(PathForeachFlags flags, @Nullable PathForeachFunc func) Callsfuncfor every operation of the path.booleanforeachIntersection(@Nullable Path path2, @Nullable PathIntersectionFunc func) Finds intersections between two paths.booleanComputes the bounds of the given path.booleangetClosestPoint(Point point, float threshold, PathPoint result, @Nullable Out<Float> distance) Computes the closest point on the path to the given point.booleangetEndPoint(PathPoint result) Gets the end point of the path.booleangetStartPoint(PathPoint result) Gets the start point of the path.booleangetStrokeBounds(Stroke stroke, Rect bounds) Computes the bounds for stroking the given path with the given parameters.static @Nullable TypegetType()Get the GType of the Path classbooleanReturns whether a point is inside the fill area of a path.booleanisClosed()Returns if the path represents a single closed contour.booleanisEmpty()Checks if the path is empty, i.e.static @Nullable PathConstructs a path from a serialized form.voidConverts the path into a human-readable representation.ref()Increases the reference count of a path by one.voidtoCairo(org.freedesktop.cairo.Context cr) Appends the path to a cairo context for drawing with Cairo.toString()Converts the path into a human-readable string.voidunref()Decreases the reference count of a path by one.Methods inherited from class org.javagi.base.ProxyInstance
equals, handle, hashCode
-
Constructor Details
-
Path
Create a Path proxy instance for the provided memory address.- Parameters:
address- the memory address of the native object
-
-
Method Details
-
getType
-
parse
Constructs a path from a serialized form.The string is expected to be in (a superset of) SVG path syntax, as e.g. produced by
toString().A high-level summary of the syntax:
M x yMove to(x, y)L x yAdd a line from the current point to(x, y)Q x1 y1 x2 y2Add a quadratic Bézier from the current point to(x2, y2), with control point(x1, y1)C x1 y1 x2 y2 x3 y3Add a cubic Bézier from the current point to(x3, y3), with control points(x1, y1)and(x2, y2)ZClose the contour by drawing a line back to the start pointH xAdd a horizontal line from the current point to the given x valueV yAdd a vertical line from the current point to the given y valueT x2 y2Add a quadratic Bézier, using the reflection of the previous segments' control point as control pointS x2 y2 x3 y3Add a cubic Bézier, using the reflection of the previous segments' second control point as first control pointA rx ry r l s x yAdd an elliptical arc from the current point to(x, y)with radii rx and ry. See the SVG documentation for how the other parameters influence the arc.O x1 y1 x2 y2 wAdd a rational quadratic Bézier from the current point to(x2, y2)with control point(x1, y1)and weightw.
All the commands have lowercase variants that interpret coordinates relative to the current point.
The
Ocommand is an extension that is not supported in SVG.- Parameters:
string- a string- Returns:
- a new
GskPath, orNULLifstringcould not be parsed - Since:
- 4.14
-
foreach
Callsfuncfor every operation of the path.Note that this may only approximate
self,because paths can contain optimizations for various specialized contours, and depending on theflags,the path may be decomposed into simpler curves than the ones that it contained originally.This function serves two purposes:
- When the
flagsallow everything, it provides access to the raw, unmodified data of the path. - When the
flagsdisallow certain operations, it provides an approximation of the path using just the allowed operations.
- Parameters:
flags- flags to pass to the foreach functionfunc- the function to call for operations- Returns:
- false if
funcreturned false, true otherwise. - Since:
- 4.14
- When the
-
foreach
Callsfuncfor every operation of the path.Note that this may only approximate
self,because paths can contain optimizations for various specialized contours, and depending on theflags,the path may be decomposed into simpler curves than the ones that it contained originally.This function serves two purposes:
- When the
flagsallow everything, it provides access to the raw, unmodified data of the path. - When the
flagsdisallow certain operations, it provides an approximation of the path using just the allowed operations.
- Parameters:
flags- flags to pass to the foreach functionfunc- the function to call for operations- Returns:
- false if
funcreturned false, true otherwise. - Since:
- 4.14
- When the
-
foreachIntersection
Finds intersections between two paths.This function finds intersections between this Path and
path2,and callsfuncfor each of them, in increasing order forpath1.If
path2is not provided or equal topath1,the function finds non-trivial self-intersections ofpath1.When segments of the paths coincide, the callback is called once for the start of the segment, with
GSKPATHINTERSECTIONSTART,and once for the end of the segment, withGSKPATHINTERSECTIONEND.Note that other intersections may occur between the start and end of such a segment.If
funcreturnsFALSE, the iteration is stopped.- Parameters:
path2- the second pathfunc- the function to call for intersections- Returns:
FALSEiffuncreturned FALSE,TRUE` otherwise.- Since:
- 4.20
-
getBounds
Computes the bounds of the given path.The returned bounds may be larger than necessary, because this function aims to be fast, not accurate. The bounds are guaranteed to contain the path.
It is possible that the returned rectangle has 0 width and/or height. This can happen when the path only describes a point or an axis-aligned line.
If the path is empty, false is returned and
boundsare set to graphene_rect_zero(). This is different from the case where the path is a single point at the origin, where theboundswill also be set to the zero rectangle but true will be returned.- Parameters:
bounds- return location for the bounds- Returns:
- true if the path has bounds, false if the path is known to be empty and have no bounds
- Since:
- 4.14
-
getClosestPoint
public boolean getClosestPoint(Point point, float threshold, PathPoint result, @Nullable Out<Float> distance) Computes the closest point on the path to the given point.If there is no point closer than the given threshold, false is returned.
- Parameters:
point- the pointthreshold- maximum allowed distanceresult- return location for the closest pointdistance- return location for the distance- Returns:
- true if
pointwas set to the closest point onself,false if no point is closer thanthreshold - Since:
- 4.14
-
getEndPoint
Gets the end point of the path.An empty path has no points, so false is returned in this case.
- Parameters:
result- return location for point- Returns:
- true if
resultwas filled - Since:
- 4.14
-
getStartPoint
Gets the start point of the path.An empty path has no points, so false is returned in this case.
- Parameters:
result- return location for point- Returns:
- true if
resultwas filled - Since:
- 4.14
-
getStrokeBounds
Computes the bounds for stroking the given path with the given parameters.The returned bounds may be larger than necessary, because this function aims to be fast, not accurate. The bounds are guaranteed to contain the area affected by the stroke, including protrusions like miters.
- Parameters:
stroke- stroke parametersbounds- the bounds to fill in- Returns:
- true if the path has bounds, false if the path is known to be empty and have no bounds.
- Since:
- 4.14
-
inFill
Returns whether a point is inside the fill area of a path.Note that this function assumes that filling a contour implicitly closes it.
- Parameters:
point- the point to testfillRule- the fill rule to follow- Returns:
- true if
pointis inside - Since:
- 4.14
-
isClosed
public boolean isClosed()Returns if the path represents a single closed contour.- Returns:
- true if the path is closed
- Since:
- 4.14
-
isEmpty
public boolean isEmpty()Checks if the path is empty, i.e. contains no lines or curves.- Returns:
- true if the path is empty
- Since:
- 4.14
-
print
Converts the path into a human-readable representation.The string is compatible with (a superset of) SVG path syntax, see
parse(java.lang.String)for a summary of the syntax.- Parameters:
string- the string to print into- Since:
- 4.14
-
ref
Increases the reference count of a path by one.- Returns:
- the passed in
GskPath - Since:
- 4.14
-
toCairo
public void toCairo(org.freedesktop.cairo.Context cr) Appends the path to a cairo context for drawing with Cairo.This may cause some suboptimal conversions to be performed as Cairo does not support all features of
GskPath.This function does not clear the existing Cairo path. Call cairo_new_path() if you want this.
- Parameters:
cr- a cairo context- Since:
- 4.14
-
toString
Converts the path into a human-readable string.You can use this function in a debugger to get a quick overview of the path.
This is a wrapper around
print(java.lang.String), see that function for details. -
unref
public void unref()Decreases the reference count of a path by one.If the resulting reference count is zero, frees the path.
- Since:
- 4.14
-