mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2025-01-14 06:10:21 +00:00
gtk: Add gtk_snapshot_append_text2/layout2
These are private snapshot functions that use the new constructor to create a text node with a given color state.
This commit is contained in:
parent
23922eebf1
commit
e323d2a93e
@ -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);
|
||||
}
|
||||
|
@ -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 */
|
||||
|
@ -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;
|
||||
|
||||
|
@ -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);
|
||||
|
@ -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);
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user