diff --git a/gsk/gskpath.c b/gsk/gskpath.c index c220e01116..0762969754 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 195a849f66..10ff4245f0 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 e6066239c6..dfaacb6897 100644 --- a/gsk/gskpathbuilder.c +++ b/gsk/gskpathbuilder.c @@ -338,6 +338,55 @@ gsk_path_builder_add_path (GskPathBuilder *self, } } +/** + * 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: * @self: A #GskPathBuilder @@ -966,18 +1015,14 @@ gsk_path_builder_add_layout (GskPathBuilder *self, 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 (self, path); - - gsk_path_unref (path); + gsk_path_builder_add_cairo_path (self, cairo_path); cairo_path_destroy (cairo_path); cairo_destroy (cr); diff --git a/gsk/gskpathbuilder.h b/gsk/gskpathbuilder.h index 12522c3c3a..1200a712a1 100644 --- a/gsk/gskpathbuilder.h +++ b/gsk/gskpathbuilder.h @@ -53,6 +53,9 @@ GDK_AVAILABLE_IN_ALL void gsk_path_builder_add_path (GskPathBuilder *self, 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 *self, PangoLayout *layout); GDK_AVAILABLE_IN_ALL