diff --git a/gtk/gskpango.c b/gtk/gskpango.c index 9d169b88d8..b976b0614d 100644 --- a/gtk/gskpango.c +++ b/gtk/gskpango.c @@ -68,11 +68,11 @@ get_color (GskPangoRenderer *crenderer, rgba->red = color->red / 65535.; rgba->green = color->green / 65535.; rgba->blue = color->blue / 65535.; - rgba->alpha = a ? a / 65535. : crenderer->fg_color->alpha; + rgba->alpha = a ? a / 65535. : crenderer->fg_color.alpha; } else { - *rgba = *crenderer->fg_color; + gdk_color_to_float (&crenderer->fg_color, GDK_COLOR_STATE_SRGB, (float *) rgba); if (a) rgba->alpha = a / 65535.; } @@ -489,6 +489,32 @@ void gtk_snapshot_append_layout (GtkSnapshot *snapshot, PangoLayout *layout, const GdkRGBA *color) +{ + GdkColor color2; + + gdk_color_init_from_rgba (&color2, color); + gtk_snapshot_append_layout2 (snapshot, layout, &color2); + gdk_color_finish (&color2); +} + +/* < private > + * gtk_snapshot_append_layout2: + * @snapshot: a `GtkSnapshot` + * @layout: the `PangoLayout` to render + * @color: the foreground color to render the layout in + * + * 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. The current theme's foreground color for a widget can be + * obtained with [method@Gtk.Widget.get_color]. + * + * Note that if the layout does not produce any visible output, then nodes + * may not be added to the @snapshot. + **/ +void +gtk_snapshot_append_layout2 (GtkSnapshot *snapshot, + PangoLayout *layout, + const GdkColor *color) { GskPangoRenderer *crenderer; @@ -498,9 +524,11 @@ gtk_snapshot_append_layout (GtkSnapshot *snapshot, crenderer = gsk_pango_renderer_acquire (); crenderer->snapshot = snapshot; - crenderer->fg_color = color; + gdk_color_init_copy (&crenderer->fg_color, color); pango_renderer_draw_layout (PANGO_RENDERER (crenderer), layout, 0, 0); + gdk_color_finish (&crenderer->fg_color); + gsk_pango_renderer_release (crenderer); } diff --git a/gtk/gskpangoprivate.h b/gtk/gskpangoprivate.h index 6b8e2d7618..7db648427d 100644 --- a/gtk/gskpangoprivate.h +++ b/gtk/gskpangoprivate.h @@ -58,7 +58,7 @@ struct _GskPangoRenderer GtkWidget *widget; GtkSnapshot *snapshot; - const GdkRGBA *fg_color; + GdkColor fg_color; GtkCssStyle *shadow_style; /* Error underline color for this widget */ diff --git a/gtk/gtksnapshot.c b/gtk/gtksnapshot.c index fcd587a438..700d5a665c 100644 --- a/gtk/gtksnapshot.c +++ b/gtk/gtksnapshot.c @@ -2473,16 +2473,31 @@ gtk_snapshot_append_text (GtkSnapshot *snapshot, const GdkRGBA *color, float x, float y) +{ + GdkColor color2; + + gdk_color_init_from_rgba (&color2, color); + gtk_snapshot_append_text2 (snapshot, font, glyphs, &color2, x, y); + gdk_color_finish (&color2); +} + +void +gtk_snapshot_append_text2 (GtkSnapshot *snapshot, + PangoFont *font, + PangoGlyphString *glyphs, + const GdkColor *color, + float x, + float y) { GskRenderNode *node; float dx, dy; gtk_snapshot_ensure_translate (snapshot, &dx, &dy); - node = gsk_text_node_new (font, - glyphs, - color, - &GRAPHENE_POINT_INIT (x + dx, y + dy)); + node = gsk_text_node_new2 (font, + glyphs, + color, + &GRAPHENE_POINT_INIT (x + dx, y + dy)); if (node == NULL) return; diff --git a/gtk/gtksnapshotprivate.h b/gtk/gtksnapshotprivate.h index 39fdd5d0ca..e1d5803199 100644 --- a/gtk/gtksnapshotprivate.h +++ b/gtk/gtksnapshotprivate.h @@ -30,6 +30,16 @@ void gtk_snapshot_append_text (GtkSnapshot const GdkRGBA *color, float x, float y); +void gtk_snapshot_append_text2 (GtkSnapshot *snapshot, + PangoFont *font, + PangoGlyphString *glyphs, + const GdkColor *color, + float x, + float y); + +void gtk_snapshot_append_layout2 (GtkSnapshot *snapshot, + PangoLayout *layout, + const GdkColor *color); void gtk_snapshot_push_collect (GtkSnapshot *snapshot); GskRenderNode * gtk_snapshot_pop_collect (GtkSnapshot *snapshot); diff --git a/gtk/gtktextlayout.c b/gtk/gtktextlayout.c index c15c6dd0a7..177584f42b 100644 --- a/gtk/gtktextlayout.c +++ b/gtk/gtktextlayout.c @@ -4159,7 +4159,7 @@ gtk_text_layout_snapshot (GtkTextLayout *layout, crenderer->widget = widget; crenderer->snapshot = snapshot; - crenderer->fg_color = color; + gdk_color_init_from_rgba (&crenderer->fg_color, color); have_selection = gtk_text_buffer_get_selection_bounds (layout->buffer, &selection_start, @@ -4335,6 +4335,8 @@ gtk_text_layout_snapshot (GtkTextLayout *layout, /* Only update eviction source once per snapshot */ gtk_text_line_display_cache_delay_eviction (priv->cache); + gdk_color_finish (&crenderer->fg_color); + gsk_pango_renderer_release (crenderer); }