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.
This commit is contained in:
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user