[gtk/wip/otte/lottie: 82/86] path: Move gsk_path_new_from_cairo() away




commit a732ac5b68518297644111238408d96e1795205f
Author: Benjamin Otte <otte redhat com>
Date:   Sun Dec 27 08:25:22 2020 +0100

    path: Move gsk_path_new_from_cairo() away
    
    This is a regular path creation API, so treat it that way.
    
    On top, it is rather awkward if the only constructor for a path that is
    immediately visible to people reading the docs is the one that takes a
    Cairo path - when we want to deprecate Cairo.

 docs/reference/gsk/gsk4-sections.txt |  2 +-
 gsk/gskpath.c                        | 54 -----------------------------------
 gsk/gskpath.h                        |  2 --
 gsk/gskpathbuilder.c                 | 55 ++++++++++++++++++++++++++++++++----
 gsk/gskpathbuilder.h                 |  3 ++
 5 files changed, 54 insertions(+), 62 deletions(-)
---
diff --git a/docs/reference/gsk/gsk4-sections.txt b/docs/reference/gsk/gsk4-sections.txt
index de50e2eb1b..13ec9b87cd 100644
--- a/docs/reference/gsk/gsk4-sections.txt
+++ b/docs/reference/gsk/gsk4-sections.txt
@@ -321,7 +321,6 @@ GskPath
 gsk_path_ref
 gsk_path_unref
 gsk_path_new_rect
-gsk_path_new_from_cairo
 gsk_path_parse
 <SUBSECTION>
 gsk_path_print
@@ -357,6 +356,7 @@ gsk_path_builder_add_rounded_rect
 gsk_path_builder_add_circle
 gsk_path_builder_add_ellipse
 gsk_path_builder_add_path
+gsk_path_builder_add_cairo_path
 gtk_path_builder_add_segment
 gtk_path_builder_add_layout
 <SUBSECTION>
diff --git a/gsk/gskpath.c b/gsk/gskpath.c
index fda323992e..59b90642fd 100644
--- a/gsk/gskpath.c
+++ b/gsk/gskpath.c
@@ -105,60 +105,6 @@ gsk_path_new_from_contours (const GSList *contours)
   return path;
 }
 
-/**
- * gsk_path_new_from_cairo:
- * @path: a Cairo path
- *
- * This is a convenience function that constructs a #GskPath from a Cairo path.
- *
- * You can use cairo_copy_path() to access the path from a Cairo context.
- *
- * Returns: a new #GskPath
- **/
-GskPath *
-gsk_path_new_from_cairo (const cairo_path_t *path)
-{
-  GskPathBuilder *builder;
-  gsize i;
-
-  g_return_val_if_fail (path != NULL, NULL);
-
-  builder = gsk_path_builder_new ();
-
-  for (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 (builder, data[1].point.x, data[1].point.y);
-          break;
-
-        case CAIRO_PATH_LINE_TO:
-          gsk_path_builder_line_to (builder, data[1].point.x, data[1].point.y);
-          break;
-
-        case CAIRO_PATH_CURVE_TO:
-          gsk_path_builder_curve_to (builder,
-                                     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 (builder);
-          break;
-
-        default:
-          g_assert_not_reached ();
-          break;
-      }
-    }
-
-  return gsk_path_builder_free_to_path (builder);
-}
-
 /**
  * gsk_path_ref:
  * @self: a #GskPath
diff --git a/gsk/gskpath.h b/gsk/gskpath.h
index 6df9250a33..ed31559608 100644
--- a/gsk/gskpath.h
+++ b/gsk/gskpath.h
@@ -73,8 +73,6 @@ typedef gboolean (* GskPathForeachFunc) (GskPathOperation        op,
 
 GDK_AVAILABLE_IN_ALL
 GType                   gsk_path_get_type                       (void) G_GNUC_CONST;
-GDK_AVAILABLE_IN_ALL
-GskPath *               gsk_path_new_from_cairo                 (const cairo_path_t     *path);
 
 GDK_AVAILABLE_IN_ALL
 GskPath *               gsk_path_ref                            (GskPath                *self);
diff --git a/gsk/gskpathbuilder.c b/gsk/gskpathbuilder.c
index 58700e77ef..f274b75b7c 100644
--- a/gsk/gskpathbuilder.c
+++ b/gsk/gskpathbuilder.c
@@ -338,6 +338,55 @@ gsk_path_builder_add_path (GskPathBuilder *builder,
     }
 }
 
+/**
+ * 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.
+ **/
+void
+gsk_path_builder_add_cairo_path (GskPathBuilder     *self,
+                                 const cairo_path_t *path)
+{
+  gsize i;
+
+  g_return_if_fail (self != NULL);
+  g_return_if_fail (path != NULL);
+
+  for (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_curve_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:
  * @builder: A #GskPathBuilder
@@ -957,18 +1006,14 @@ gsk_path_builder_add_layout (GskPathBuilder *builder,
   cairo_surface_t *surface;
   cairo_t *cr;
   cairo_path_t *cairo_path;
-  GskPath *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);
-  path = gsk_path_new_from_cairo (cairo_path);
-
-  gsk_path_builder_add_path (builder, path);
 
-  gsk_path_unref (path);
+  gsk_path_builder_add_cairo_path (builder, cairo_path);
 
   cairo_path_destroy (cairo_path);
   cairo_destroy (cr);
diff --git a/gsk/gskpathbuilder.h b/gsk/gskpathbuilder.h
index 44f9129ce3..afa0a2c0a6 100644
--- a/gsk/gskpathbuilder.h
+++ b/gsk/gskpathbuilder.h
@@ -53,6 +53,9 @@ GDK_AVAILABLE_IN_ALL
 void                    gsk_path_builder_add_path               (GskPathBuilder         *builder,
                                                                  GskPath                *path);
 GDK_AVAILABLE_IN_ALL
+void                    gsk_path_builder_add_cairo_path         (GskPathBuilder         *self,
+                                                                 const cairo_path_t     *path);
+GDK_AVAILABLE_IN_ALL
 void                    gsk_path_builder_add_layout             (GskPathBuilder         *builder,
                                                                  PangoLayout            *layout);
 


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