From 5c3a5761b48518f397f6d5befbea64212866b57d Mon Sep 17 00:00:00 2001 From: Matthias Clasen Date: Sun, 27 Dec 2020 00:59:02 -0500 Subject: [PATCH] gsk: Add gsk_path_builder_add_layout This api makes it easy to turn text into a path that can be further manipulated. The implementation currently goes via cairo. --- gsk/gskpathbuilder.c | 33 +++++++++++++++++++++++++++++++++ gsk/gskpathbuilder.h | 3 +++ 2 files changed, 36 insertions(+) diff --git a/gsk/gskpathbuilder.c b/gsk/gskpathbuilder.c index 7752635420..e6066239c6 100644 --- a/gsk/gskpathbuilder.c +++ b/gsk/gskpathbuilder.c @@ -950,3 +950,36 @@ gsk_path_builder_svg_arc_to (GskPathBuilder *self, t); } } + +/** + * gsk_path_builder_add_layout: + * @self: a #GskPathBuilder + * @layout: the pango layout to add + * + * Adds the outlines for the glyphs in @layout to + * the builder. + */ +void +gsk_path_builder_add_layout (GskPathBuilder *self, + PangoLayout *layout) +{ + 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); + + cairo_path_destroy (cairo_path); + cairo_destroy (cr); + cairo_surface_destroy (surface); +} diff --git a/gsk/gskpathbuilder.h b/gsk/gskpathbuilder.h index ab1aec55b8..12522c3c3a 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_layout (GskPathBuilder *self, + PangoLayout *layout); +GDK_AVAILABLE_IN_ALL void gsk_path_builder_add_rect (GskPathBuilder *self, const graphene_rect_t *rect); GDK_AVAILABLE_IN_ALL