API: Add gsk_path_stroke

Add the plumbing that will let us do special-case stroking
for rectangles, circles and other special contours.

There is no implementation yet.
This commit is contained in:
Matthias Clasen
2020-12-05 13:37:53 -05:00
parent 2c856cb5e3
commit 41986e625f
4 changed files with 70 additions and 0 deletions

View File

@@ -90,6 +90,9 @@ struct _GskContourClass
const GskStroke *stroke,
graphene_rect_t *bounds);
GskContour * (* reverse) (const GskContour *contour);
void (* add_stroke) (const GskContour *contour,
GskPathBuilder *builder,
GskStroke *stroke);
};
static gsize
@@ -510,6 +513,13 @@ gsk_rect_contour_reverse (const GskContour *contour)
self->height));
}
static void
gsk_rect_contour_add_stroke (const GskContour *contour,
GskPathBuilder *builder,
GskStroke *stroke)
{
}
static const GskContourClass GSK_RECT_CONTOUR_CLASS =
{
sizeof (GskRectContour),
@@ -530,6 +540,7 @@ static const GskContourClass GSK_RECT_CONTOUR_CLASS =
gsk_rect_contour_get_winding,
gsk_rect_contour_get_stroke_bounds,
gsk_rect_contour_reverse,
gsk_rect_contour_add_stroke,
};
GskContour *
@@ -936,6 +947,13 @@ gsk_circle_contour_reverse (const GskContour *contour)
self->start_angle);
}
static void
gsk_circle_contour_add_stroke (const GskContour *contour,
GskPathBuilder *builder,
GskStroke *stroke)
{
}
static const GskContourClass GSK_CIRCLE_CONTOUR_CLASS =
{
sizeof (GskCircleContour),
@@ -956,6 +974,7 @@ static const GskContourClass GSK_CIRCLE_CONTOUR_CLASS =
gsk_circle_contour_get_winding,
gsk_circle_contour_get_stroke_bounds,
gsk_circle_contour_reverse,
gsk_circle_contour_add_stroke,
};
GskContour *
@@ -1793,6 +1812,13 @@ gsk_standard_contour_reverse (const GskContour *contour)
return res;
}
static void
gsk_standard_contour_add_stroke (const GskContour *contour,
GskPathBuilder *builder,
GskStroke *stroke)
{
}
static const GskContourClass GSK_STANDARD_CONTOUR_CLASS =
{
sizeof (GskStandardContour),
@@ -1813,6 +1839,7 @@ static const GskContourClass GSK_STANDARD_CONTOUR_CLASS =
gsk_standard_contour_get_winding,
gsk_standard_contour_get_stroke_bounds,
gsk_standard_contour_reverse,
gsk_standard_contour_add_stroke,
};
/* You must ensure the contour has enough size allocated,
@@ -1992,6 +2019,14 @@ gsk_contour_get_stroke_bounds (const GskContour *self,
return self->klass->get_stroke_bounds (self, stroke, bounds);
}
void
gsk_contour_add_stroke (const GskContour *self,
GskPathBuilder *builder,
GskStroke *stroke)
{
self->klass->add_stroke (self, builder, stroke);
}
void
gsk_contour_copy (GskContour *dest,
const GskContour *src)

View File

@@ -100,6 +100,12 @@ void gsk_contour_add_segment (const GskContou
gboolean gsk_contour_get_stroke_bounds (const GskContour *self,
const GskStroke *stroke,
graphene_rect_t *bounds);
void gsk_contour_add_stroke (const GskContour *contour,
GskPathBuilder *builder,
GskStroke *stroke);
void gsk_contour_default_add_stroke (const GskContour *contour,
GskPathBuilder *builder,
GskStroke *stroke);
G_END_DECLS

View File

@@ -1369,3 +1369,28 @@ gsk_path_transform (GskPath *self,
return gsk_path_builder_free_to_path (data.builder);
}
/**
* gsk_path_stroke:
* @self: a `GskPath`
* @stroke: stroke parameters
*
* Create a new path that follows the outline of the area
* that would be affected by stroking along @self with
* the given stroke parameters.
*
* Returns: a new `GskPath`
*/
GskPath *
gsk_path_stroke (GskPath *self,
GskStroke *stroke)
{
GskPathBuilder *builder;
builder = gsk_path_builder_new ();
for (int i = 0; i < self->n_contours; i++)
gsk_contour_add_stroke (gsk_path_get_contour (self, i), builder, stroke);
return gsk_path_builder_free_to_path (builder);
}

View File

@@ -117,6 +117,10 @@ GDK_AVAILABLE_IN_ALL
GskPath * gsk_path_transform (GskPath *self,
GskTransform *transform);
GDK_AVAILABLE_IN_ALL
GskPath * gsk_path_stroke (GskPath *self,
GskStroke *stroke);
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GskPath, gsk_path_unref)
G_END_DECLS