summaryrefslogtreecommitdiff
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
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().
-rw-r--r--docs/reference/gtk/gtk4-sections.txt1
-rw-r--r--gtk/gskpango.c42
-rw-r--r--gtk/gskpango.h4
-rw-r--r--gtk/gtksnapshot.c2
-rw-r--r--gtk/gtksnapshot.h8
5 files changed, 43 insertions, 14 deletions
diff --git a/docs/reference/gtk/gtk4-sections.txt b/docs/reference/gtk/gtk4-sections.txt
index e5c06ac5e9..374124bc9a 100644
--- a/docs/reference/gtk/gtk4-sections.txt
+++ b/docs/reference/gtk/gtk4-sections.txt
@@ -4190,6 +4190,7 @@ gtk_snapshot_append_node
gtk_snapshot_append_cairo
gtk_snapshot_append_texture
gtk_snapshot_append_color
+gtk_snapshot_append_layout
gtk_snapshot_clips_rect
gtk_snapshot_render_background
gtk_snapshot_render_frame
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);
diff --git a/gtk/gskpango.h b/gtk/gskpango.h
index 80b80397ef..a97fdebea4 100644
--- a/gtk/gskpango.h
+++ b/gtk/gskpango.h
@@ -34,10 +34,6 @@ typedef struct _GskPangoRendererClass GskPangoRendererClass;
GType gsk_pango_renderer_get_type (void) G_GNUC_CONST;
-void gsk_pango_show_layout (GtkSnapshot *snapshot,
- const GdkRGBA *fg_color,
- PangoLayout *layout);
-
G_END_DECLS
#endif /* __GSK_PANGO_H__ */
diff --git a/gtk/gtksnapshot.c b/gtk/gtksnapshot.c
index 3299c4ccdc..609a0c6473 100644
--- a/gtk/gtksnapshot.c
+++ b/gtk/gtksnapshot.c
@@ -1728,7 +1728,7 @@ gtk_snapshot_render_layout (GtkSnapshot *snapshot,
shadows_value = _gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_TEXT_SHADOW);
has_shadow = gtk_css_shadows_value_push_snapshot (shadows_value, snapshot);
- gsk_pango_show_layout (snapshot, fg_color, layout);
+ gtk_snapshot_append_layout (snapshot, layout, fg_color, "RenderLayout");
if (has_shadow)
gtk_snapshot_pop (snapshot);
diff --git a/gtk/gtksnapshot.h b/gtk/gtksnapshot.h
index c8003956fe..db9d4e6d78 100644
--- a/gtk/gtksnapshot.h
+++ b/gtk/gtksnapshot.h
@@ -155,6 +155,14 @@ void gtk_snapshot_append_color (GtkSnapshot
const graphene_rect_t *bounds,
const char *name,
...) G_GNUC_PRINTF (4, 5);
+/* next function implemented in gskpango.c */
+GDK_AVAILABLE_IN_ALL
+void gtk_snapshot_append_layout (GtkSnapshot *snapshot,
+ PangoLayout *layout,
+ const GdkRGBA *color,
+ const char *name,
+ ...) G_GNUC_PRINTF (4, 5);
+
GDK_AVAILABLE_IN_ALL
gboolean gtk_snapshot_clips_rect (GtkSnapshot *snapshot,