summaryrefslogtreecommitdiff
path: root/gtk/gskpango.c
diff options
context:
space:
mode:
authorBenjamin Otte <otte@redhat.com>2018-03-26 04:23:11 +0200
committerBenjamin Otte <otte@redhat.com>2018-03-26 18:16:36 +0200
commit9b83116fcb05198e0fe5b41e57c0cd34eb41b167 (patch)
treed694b10ee7243b708eff66bf4f046c491efc1dc8 /gtk/gskpango.c
parente6d24f4c159320d59016598ed305677d64397c03 (diff)
downloadgtk+-9b83116fcb05198e0fe5b41e57c0cd34eb41b167.tar.gz
snapshot: Export gtk_snapshot_append_layout()
This is the equivalent snapshot function to pango_cairo_show_layout(). Not to be confused with gtk_snapshot_render_layout(), which is the equivalent to gtk_render_layout().
Diffstat (limited to 'gtk/gskpango.c')
-rw-r--r--gtk/gskpango.c42
1 files changed, 33 insertions, 9 deletions
diff --git a/gtk/gskpango.c b/gtk/gskpango.c
index 1b84c71357..7e7fa73ebe 100644
--- a/gtk/gskpango.c
+++ b/gtk/gskpango.c
@@ -45,6 +45,7 @@ struct _GskPangoRenderer
GtkSnapshot *snapshot;
GdkRGBA fg_color;
graphene_rect_t bounds;
+ char *name;
/* house-keeping options */
gboolean is_cached_renderer;
@@ -157,9 +158,9 @@ gsk_pango_renderer_show_text_glyphs (PangoRenderer *renderer,
if (gtk_snapshot_get_record_names (crenderer->snapshot))
{
- char name[64];
- g_snprintf (name, sizeof (name), "Glyphs<%d>", glyphs->num_glyphs);
- gsk_render_node_set_name (node, name);
+ char *s = g_strdup_printf ("%s<%d>", crenderer->name, glyphs->num_glyphs);
+ gsk_render_node_set_name (node, s);
+ g_free (s);
}
gtk_snapshot_append_node_internal (crenderer->snapshot, node);
@@ -427,6 +428,7 @@ release_renderer (GskPangoRenderer *renderer)
if (G_LIKELY (renderer->is_cached_renderer))
{
renderer->snapshot = NULL;
+ g_clear_pointer (&renderer->name, g_free);
G_UNLOCK (cached_renderer);
}
@@ -434,12 +436,24 @@ release_renderer (GskPangoRenderer *renderer)
g_object_unref (renderer);
}
-/* convenience wrappers using the default renderer */
-
+/**
+ * gtk_snapshot_append_layout:
+ * @snapshot: a #GtkSnapshot
+ * @layout: the #PangoLayout to render
+ * @color: the foreground color to render the layout in
+ * @name: (transfer none): a printf() style format string for the name for the new node
+ * @...: arguments to insert into the format string
+ *
+ * Creates render nodes for rendering @layout in the given foregound @color
+ * and appends them to the current node of @snapshot without changing the
+ * current node.
+ **/
void
-gsk_pango_show_layout (GtkSnapshot *snapshot,
- const GdkRGBA *fg_color,
- PangoLayout *layout)
+gtk_snapshot_append_layout (GtkSnapshot *snapshot,
+ PangoLayout *layout,
+ const GdkRGBA *color,
+ const char *name,
+ ...)
{
GskPangoRenderer *crenderer;
PangoRectangle ink_rect;
@@ -450,7 +464,17 @@ gsk_pango_show_layout (GtkSnapshot *snapshot,
crenderer = acquire_renderer ();
crenderer->snapshot = snapshot;
- crenderer->fg_color = *fg_color;
+ crenderer->fg_color = *color;
+ if (name && gtk_snapshot_get_record_names (crenderer->snapshot))
+ {
+ va_list args;
+
+ va_start (args, name);
+ crenderer->name = g_strdup_vprintf (name, args);
+ va_end (args);
+ }
+ else
+ crenderer->name = NULL;
pango_layout_get_pixel_extents (layout, &ink_rect, NULL);
graphene_rect_init (&crenderer->bounds, ink_rect.x, ink_rect.y, ink_rect.width, ink_rect.height);