diff options
-rw-r--r-- | docs/reference/gtk/gtk4-sections.txt | 1 | ||||
-rw-r--r-- | gtk/gskpango.c | 42 | ||||
-rw-r--r-- | gtk/gskpango.h | 4 | ||||
-rw-r--r-- | gtk/gtksnapshot.c | 2 | ||||
-rw-r--r-- | gtk/gtksnapshot.h | 8 |
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, |