[gtk/wip/matthiasc/lottie-stroke: 2/9] Add gsk_path_to_stroke




commit 2bd9e41473cbfa5634d03c7de38484c0b3833315
Author: Matthias Clasen <mclasen redhat com>
Date:   Sat Dec 5 13:37:53 2020 -0500

    Add gsk_path_to_stroke
    
    Add the plumbing that will let us do special-case stroking
    for rectangles, circles and other special contours. There
    is no implementation yet.

 gsk/gskcontour.c        | 42 +++++++++++++++++++++++++++++++++++++++---
 gsk/gskcontourprivate.h |  6 ++++++
 gsk/gskpathmeasure.c    | 27 +++++++++++++++++++++++++++
 3 files changed, 72 insertions(+), 3 deletions(-)
---
diff --git a/gsk/gskcontour.c b/gsk/gskcontour.c
index 359356d838..dd665d9c51 100644
--- a/gsk/gskcontour.c
+++ b/gsk/gskcontour.c
@@ -80,6 +80,9 @@ struct _GskContourClass
                                                  gpointer                measure_data,
                                                  const graphene_point_t *point,
                                                  gboolean               *on_edge);
+  void                  (* add_stroke)          (const GskContour       *contour,
+                                                 GskPathBuilder         *builder,
+                                                 GskStroke              *stroke);
 };
 
 static gsize
@@ -468,6 +471,14 @@ gsk_rect_contour_get_winding (const GskContour       *contour,
   return 0;
 }
 
+static void
+gsk_rect_contour_add_stroke (const GskContour *contour,
+                             GskPathBuilder   *builder,
+                             GskStroke        *stroke)
+{
+  gsk_contour_default_add_stroke (contour, builder, stroke);
+}
+
 static const GskContourClass GSK_RECT_CONTOUR_CLASS =
 {
   sizeof (GskRectContour),
@@ -484,7 +495,8 @@ static const GskContourClass GSK_RECT_CONTOUR_CLASS =
   gsk_rect_contour_get_closest_point,
   gsk_rect_contour_copy,
   gsk_rect_contour_add_segment,
-  gsk_rect_contour_get_winding
+  gsk_rect_contour_get_winding,
+  gsk_rect_contour_add_stroke
 };
 
 GskContour *
@@ -817,6 +829,13 @@ gsk_circle_contour_get_winding (const GskContour       *contour,
   return 0;
 }
 
+static void
+gsk_circle_contour_add_stroke (const GskContour *contour,
+                               GskPathBuilder   *builder,
+                               GskStroke        *stroke)
+{
+}
+
 static const GskContourClass GSK_CIRCLE_CONTOUR_CLASS =
 {
   sizeof (GskCircleContour),
@@ -833,7 +852,8 @@ static const GskContourClass GSK_CIRCLE_CONTOUR_CLASS =
   gsk_circle_contour_get_closest_point,
   gsk_circle_contour_copy,
   gsk_circle_contour_add_segment,
-  gsk_circle_contour_get_winding
+  gsk_circle_contour_get_winding,
+  gsk_circle_contour_add_stroke
 };
 
 GskContour *
@@ -1596,6 +1616,13 @@ gsk_standard_contour_get_winding (const GskContour       *contour,
   return winding;
 }
 
+static void
+gsk_standard_contour_add_stroke (const GskContour *contour,
+                                 GskPathBuilder   *builder,
+                                 GskStroke        *stroke)
+{
+}
+
 static const GskContourClass GSK_STANDARD_CONTOUR_CLASS =
 {
   sizeof (GskStandardContour),
@@ -1612,7 +1639,8 @@ static const GskContourClass GSK_STANDARD_CONTOUR_CLASS =
   gsk_standard_contour_get_closest_point,
   gsk_standard_contour_copy,
   gsk_standard_contour_add_segment,
-  gsk_standard_contour_get_winding
+  gsk_standard_contour_get_winding,
+  gsk_standard_contour_add_stroke
 };
 
 /* You must ensure the contour has enough size allocated,
@@ -1775,6 +1803,14 @@ gsk_contour_get_winding (const GskContour       *self,
   return self->klass->get_winding (self, measure_data, point, on_edge);
 }
 
+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)
diff --git a/gsk/gskcontourprivate.h b/gsk/gskcontourprivate.h
index bce0689d17..a3f9bb48ee 100644
--- a/gsk/gskcontourprivate.h
+++ b/gsk/gskcontourprivate.h
@@ -92,6 +92,12 @@ void                    gsk_contour_add_segment                 (const GskContou
                                                                  gpointer                measure_data,
                                                                  float                   start,
                                                                  float                   end);
+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
 
diff --git a/gsk/gskpathmeasure.c b/gsk/gskpathmeasure.c
index b834ea0642..2357d42a3a 100644
--- a/gsk/gskpathmeasure.c
+++ b/gsk/gskpathmeasure.c
@@ -476,3 +476,30 @@ gsk_path_builder_add_segment (GskPathBuilder *self,
     }
 }
 
+/**
+ * gsk_path_measure_stroke:
+ * @self: a #GskPathMeasure
+ * @stroke: stroke parameters
+ *
+ * Create a new path that follows the outline of the area
+ * that would be affected by stroking along the path of
+ * @self with the given stroke parameters.
+ *
+ * Returns: a new #GskPath
+ */
+GskPath *
+gsk_path_measure_stroke (GskPathMeasure *self,
+                         GskStroke      *stroke)
+{
+  GskPathBuilder *builder;
+  int i;
+
+  builder = gsk_path_builder_new ();
+
+  for (i = 0; i < self->n_contours; i++)
+    {
+      gsk_contour_add_stroke (gsk_path_get_contour (self->path, i), builder, stroke);
+    }
+
+  return gsk_path_builder_free_to_path (builder);
+}


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]