Merge branch 'css-color-hookup-5' into 'main'

Make non-srgb css colors work for text nodes

See merge request GNOME/gtk!7558
This commit is contained in:
Matthias Clasen 2024-08-10 16:28:31 +00:00
commit 798883f21a
14 changed files with 247 additions and 165 deletions

View File

@ -4221,10 +4221,12 @@ gsk_gl_render_job_visit_node (GskGLRenderJob *job,
break;
case GSK_TEXT_NODE:
gsk_gl_render_job_visit_text_node (job,
node,
gsk_text_node_get_color (node),
FALSE);
{
GdkRGBA rgba;
gdk_color_to_float (gsk_text_node_get_color2 (node), GDK_COLOR_STATE_SRGB, (float *) &rgba);
gsk_gl_render_job_visit_text_node (job, node, &rgba, FALSE);
}
break;
case GSK_TEXTURE_NODE:

View File

@ -2960,7 +2960,6 @@ gsk_gpu_node_processor_add_glyph_node (GskGpuNodeProcessor *self,
graphene_point_t offset;
guint i, num_glyphs;
float scale;
GdkColor color;
float align_scale_x, align_scale_y;
float inv_align_scale_x, inv_align_scale_y;
unsigned int flags_mask;
@ -2976,7 +2975,6 @@ gsk_gpu_node_processor_add_glyph_node (GskGpuNodeProcessor *self,
cache = gsk_gpu_device_get_cache (gsk_gpu_frame_get_device (self->frame));
gdk_color_init_from_rgba (&color, gsk_text_node_get_color (node));
num_glyphs = gsk_text_node_get_num_glyphs (node);
glyphs = gsk_text_node_get_glyphs (node, NULL);
font = gsk_text_node_get_font (node);
@ -3063,12 +3061,10 @@ gsk_gpu_node_processor_add_glyph_node (GskGpuNodeProcessor *self,
&glyph_bounds,
&glyph_tex_rect
},
&color);
gsk_text_node_get_color2 (node));
offset.x += glyphs[i].geometry.width * inv_pango_scale;
}
gdk_color_finish (&color);
}
static void

View File

@ -81,13 +81,6 @@ gsk_color_stops_are_opaque (const GskColorStop *stops,
return TRUE;
}
/* FIXME: Replace this once GdkColor lands */
static inline GdkMemoryDepth
my_color_get_depth (const GdkRGBA *rgba)
{
return gdk_color_state_get_depth (GDK_COLOR_STATE_SRGB);
}
/* FIXME: Replace this once GdkColor lands */
static inline GdkMemoryDepth
my_color_stops_get_depth (const GskColorStop *stops,
@ -6353,7 +6346,7 @@ struct _GskTextNode
PangoFont *font;
gboolean has_color_glyphs;
GdkRGBA color;
GdkColor color;
graphene_point_t offset;
guint num_glyphs;
@ -6369,6 +6362,7 @@ gsk_text_node_finalize (GskRenderNode *node)
g_object_unref (self->font);
g_object_unref (self->fontmap);
g_free (self->glyphs);
gdk_color_finish (&self->color);
parent_class->finalize (node);
}
@ -6394,7 +6388,7 @@ gsk_text_node_draw (GskRenderNode *node,
}
else
{
gdk_cairo_set_source_rgba_ccs (cr, ccs, &self->color);
gdk_cairo_set_source_color (cr, ccs, &self->color);
cairo_translate (cr, self->offset.x, self->offset.y);
pango_cairo_show_glyph_string (cr, self->font, &glyphs);
}
@ -6411,7 +6405,7 @@ gsk_text_node_diff (GskRenderNode *node1,
GskTextNode *self2 = (GskTextNode *) node2;
if (self1->font == self2->font &&
gdk_rgba_equal (&self1->color, &self2->color) &&
gdk_color_equal (&self1->color, &self2->color) &&
graphene_point_equal (&self1->offset, &self2->offset) &&
self1->num_glyphs == self2->num_glyphs)
{
@ -6478,6 +6472,36 @@ gsk_text_node_new (PangoFont *font,
PangoGlyphString *glyphs,
const GdkRGBA *color,
const graphene_point_t *offset)
{
GdkColor color2;
GskRenderNode *node;
gdk_color_init_from_rgba (&color2, color);
node = gsk_text_node_new2 (font, glyphs, &color2, offset);
gdk_color_finish (&color2);
return node;
}
/*< private >
* gsk_text_node_new2:
* @font: the `PangoFont` containing the glyphs
* @glyphs: the `PangoGlyphString` to render
* @color: the foreground color to render with
* @offset: offset of the baseline
*
* Creates a render node that renders the given glyphs.
*
* Note that @color may not be used if the font contains
* color glyphs.
*
* Returns: (nullable) (transfer full) (type GskTextNode): a new `GskRenderNode`
*/
GskRenderNode *
gsk_text_node_new2 (PangoFont *font,
PangoGlyphString *glyphs,
const GdkColor *color,
const graphene_point_t *offset)
{
GskTextNode *self;
GskRenderNode *node;
@ -6494,11 +6518,12 @@ gsk_text_node_new (PangoFont *font,
self = gsk_render_node_alloc (GSK_TEXT_NODE);
node = (GskRenderNode *) self;
node->offscreen_for_opacity = FALSE;
node->preferred_depth = my_color_get_depth (color);
node->preferred_depth = gdk_color_get_depth (color);
node->is_hdr = color_state_is_hdr (color->color_state);
self->fontmap = g_object_ref (pango_font_get_font_map (font));
self->font = g_object_ref (font);
self->color = *color;
gdk_color_init_copy (&self->color, color);
self->offset = *offset;
self->has_color_glyphs = FALSE;
@ -6531,12 +6556,16 @@ gsk_text_node_new (PangoFont *font,
return node;
}
/**
* gsk_text_node_get_color:
* @node: (type GskTextNode): a text `GskRenderNode`
*
* Retrieves the color used by the text @node.
*
* The value returned by this function will not be correct
* if the render node was created for a non-sRGB color.
*
* Returns: (transfer none): the text color
*/
const GdkRGBA *
@ -6544,6 +6573,23 @@ gsk_text_node_get_color (const GskRenderNode *node)
{
const GskTextNode *self = (const GskTextNode *) node;
/* NOTE: This is only correct for nodes with sRGB colors */
return (const GdkRGBA *) &self->color;
}
/*< private >
* gsk_text_node_get_color2:
* @node: (type GskTextNode): a `GskRenderNode`
*
* Retrieves the color of the given @node.
*
* Returns: (transfer none): the color of the node
*/
const GdkColor *
gsk_text_node_get_color2 (const GskRenderNode *node)
{
GskTextNode *self = (GskTextNode *) node;
return &self->color;
}

View File

@ -493,14 +493,6 @@ parse_rounded_rect (GtkCssParser *parser,
return TRUE;
}
static gboolean
parse_color (GtkCssParser *parser,
Context *context,
gpointer out_color)
{
return gdk_rgba_parser_parse (parser, out_color);
}
static gboolean
parse_double (GtkCssParser *parser,
Context *context,
@ -2578,7 +2570,7 @@ parse_text_node (GtkCssParser *parser,
{
PangoFont *font = NULL;
graphene_point_t offset = GRAPHENE_POINT_INIT (0, 0);
GdkRGBA color = GDK_RGBA("000000");
GdkColor color = GDK_COLOR_SRGB (0, 0, 0, 1);
PangoGlyphString *glyphs = NULL;
cairo_hint_style_t hint_style = CAIRO_HINT_STYLE_SLIGHT;
cairo_antialias_t antialias = CAIRO_ANTIALIAS_GRAY;
@ -2587,7 +2579,7 @@ parse_text_node (GtkCssParser *parser,
const Declaration declarations[] = {
{ "font", parse_font, clear_font, &font },
{ "offset", parse_point, NULL, &offset },
{ "color", parse_color, NULL, &color },
{ "color", parse_color2, NULL, &color },
{ "glyphs", parse_glyphs, clear_glyphs, &glyphs },
{ "hint-style", parse_hint_style, NULL, &hint_style },
{ "antialias", parse_antialias, NULL, &antialias },
@ -2630,7 +2622,7 @@ parse_text_node (GtkCssParser *parser,
}
else
{
result = gsk_text_node_new (font, glyphs, &color, &offset);
result = gsk_text_node_new2 (font, glyphs, &color, &offset);
if (result == NULL)
{
gtk_css_parser_error_value (parser, "Glyphs result in empty text");
@ -2644,6 +2636,8 @@ parse_text_node (GtkCssParser *parser,
if (result == NULL)
result = create_default_render_node ();
gdk_color_finish (&color);
return result;
}
@ -3301,6 +3295,7 @@ printer_init_duplicates_for_node (Printer *printer,
{
case GSK_TEXT_NODE:
printer_init_collect_font_info (printer, node);
printer_init_check_color_state (printer, gsk_text_node_get_color2 (node)->color_state);
break;
case GSK_COLOR_NODE:
@ -3633,18 +3628,6 @@ append_unsigned_param (Printer *p,
g_string_append_printf (p->str, "%s: %u;\n", param_name, value);
}
static void
append_rgba_param (Printer *p,
const char *param_name,
const GdkRGBA *value)
{
_indent (p);
g_string_append_printf (p->str, "%s: ", param_name);
gdk_rgba_print (value, p->str);
g_string_append_c (p->str, ';');
g_string_append_c (p->str, '\n');
}
static void
print_color (Printer *p,
const GdkColor *color)
@ -4588,12 +4571,12 @@ render_node_print (Printer *p,
case GSK_TEXT_NODE:
{
const graphene_point_t *offset = gsk_text_node_get_offset (node);
const GdkRGBA *color = gsk_text_node_get_color (node);
const GdkColor *color = gsk_text_node_get_color2 (node);
start_node (p, "text", node_name);
if (!gdk_rgba_equal (color, &GDK_RGBA ("000000")))
append_rgba_param (p, "color", color);
if (!gdk_color_equal (color, &GDK_COLOR_SRGB (0, 0, 0, 1)))
append_color_param (p, "color", color);
_indent (p);
g_string_append (p->str, "font: ");

View File

@ -164,6 +164,11 @@ GskRenderNode * gsk_shadow_node_new2 (GskRenderNode *c
const GskShadow2 *gsk_shadow_node_get_shadow2 (const GskRenderNode *node,
gsize i);
GskRenderNode * gsk_text_node_new2 (PangoFont *font,
PangoGlyphString *glyphs,
const GdkColor *color,
const graphene_point_t *offset);
const GdkColor *gsk_text_node_get_color2 (const GskRenderNode *node);
G_END_DECLS

View File

@ -28,6 +28,8 @@
#include "gtkwidgetprivate.h"
#include "gtkcsscolorvalueprivate.h"
#include "gdk/gdkrgbaprivate.h"
#include "gdk/gdkcolorprivate.h"
#include "gdk/gdkcairoprivate.h"
#include "gtkcssshadowvalueprivate.h"
#include <math.h>
@ -58,23 +60,26 @@ gsk_pango_renderer_set_shape_handler (GskPangoRenderer *crenderer,
static void
get_color (GskPangoRenderer *crenderer,
PangoRenderPart part,
GdkRGBA *rgba)
GdkColor *out_color)
{
const PangoColor *color = pango_renderer_get_color ((PangoRenderer *) (crenderer), part);
const guint16 a = pango_renderer_get_alpha ((PangoRenderer *) (crenderer), part);
if (color)
{
rgba->red = color->red / 65535.;
rgba->green = color->green / 65535.;
rgba->blue = color->blue / 65535.;
rgba->alpha = a ? a / 65535. : crenderer->fg_color->alpha;
gdk_color_init (out_color, GDK_COLOR_STATE_SRGB,
(float[]) {
color->red / 65535.,
color->green / 65535.,
color->blue / 65535.,
a ? a / 65535. : crenderer->fg_color.alpha,
});
}
else
{
*rgba = *crenderer->fg_color;
gdk_color_init_copy (out_color, &crenderer->fg_color);
if (a)
rgba->alpha = a / 65535.;
out_color->alpha = a / 65535.;
}
}
@ -83,10 +88,11 @@ set_color (GskPangoRenderer *crenderer,
PangoRenderPart part,
cairo_t *cr)
{
GdkRGBA rgba = { 0, 0, 0, 1 };
GdkColor color;
get_color (crenderer, part, &rgba);
gdk_cairo_set_source_rgba (cr, &rgba);
get_color (crenderer, part, &color);
gdk_cairo_set_source_color (cr, GDK_COLOR_STATE_SRGB, &color);
gdk_color_finish (&color);
}
static void
@ -97,7 +103,7 @@ gsk_pango_renderer_draw_glyph_item (PangoRenderer *renderer,
int y)
{
GskPangoRenderer *crenderer = (GskPangoRenderer *) (renderer);
GdkRGBA color;
GdkColor color;
gboolean has_shadow = FALSE;
if (crenderer->shadow_style)
@ -106,12 +112,14 @@ gsk_pango_renderer_draw_glyph_item (PangoRenderer *renderer,
get_color (crenderer, PANGO_RENDER_PART_FOREGROUND, &color);
gtk_snapshot_append_text (crenderer->snapshot,
glyph_item->item->analysis.font,
glyph_item->glyphs,
&color,
(float) x / PANGO_SCALE,
(float) y / PANGO_SCALE);
gtk_snapshot_append_text2 (crenderer->snapshot,
glyph_item->item->analysis.font,
glyph_item->glyphs,
&color,
(float) x / PANGO_SCALE,
(float) y / PANGO_SCALE);
gdk_color_finish (&color);
if (has_shadow)
gtk_snapshot_pop (crenderer->snapshot);
@ -126,16 +134,18 @@ gsk_pango_renderer_draw_rectangle (PangoRenderer *renderer,
int height)
{
GskPangoRenderer *crenderer = (GskPangoRenderer *) (renderer);
GdkRGBA rgba;
GdkColor color;
get_color (crenderer, part, &rgba);
get_color (crenderer, part, &color);
gtk_snapshot_append_color (crenderer->snapshot,
&rgba,
&GRAPHENE_RECT_INIT ((double)x / PANGO_SCALE,
(double)y / PANGO_SCALE,
(double)width / PANGO_SCALE,
(double)height / PANGO_SCALE));
gtk_snapshot_append_color2 (crenderer->snapshot,
&color,
&GRAPHENE_RECT_INIT ((double)x / PANGO_SCALE,
(double)y / PANGO_SCALE,
(double)width / PANGO_SCALE,
(double)height / PANGO_SCALE));
gdk_color_finish (&color);
}
static void
@ -189,7 +199,7 @@ gsk_pango_renderer_draw_error_underline (PangoRenderer *renderer,
{
GskPangoRenderer *crenderer = (GskPangoRenderer *) (renderer);
double xx, yy, ww, hh;
GdkRGBA rgba;
GdkColor color;
GskRoundedRect dot;
xx = (double)x / PANGO_SCALE;
@ -197,7 +207,7 @@ gsk_pango_renderer_draw_error_underline (PangoRenderer *renderer,
ww = (double)width / PANGO_SCALE;
hh = (double)height / PANGO_SCALE;
get_color (crenderer, PANGO_RENDER_PART_UNDERLINE, &rgba);
get_color (crenderer, PANGO_RENDER_PART_UNDERLINE, &color);
gtk_snapshot_push_repeat (crenderer->snapshot,
&GRAPHENE_RECT_INIT (xx, yy, ww, hh),
@ -208,11 +218,13 @@ gsk_pango_renderer_draw_error_underline (PangoRenderer *renderer,
hh / 2);
gtk_snapshot_push_rounded_clip (crenderer->snapshot, &dot);
gtk_snapshot_append_color (crenderer->snapshot, &rgba, &dot.bounds);
gtk_snapshot_append_color2 (crenderer->snapshot, &color, &dot.bounds);
gtk_snapshot_pop (crenderer->snapshot);
gtk_snapshot_append_color (crenderer->snapshot,
&GDK_RGBA_TRANSPARENT,
&GRAPHENE_RECT_INIT (xx, yy, 1.5 * hh, hh));
gtk_snapshot_append_color2 (crenderer->snapshot,
&GDK_COLOR_SRGB (0, 0, 0, 0),
&GRAPHENE_RECT_INIT (xx, yy, 1.5 * hh, hh));
gdk_color_finish (&color);
gtk_snapshot_pop (crenderer->snapshot);
}
@ -489,6 +501,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 +536,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);
}

View File

@ -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 */

View File

@ -22,9 +22,10 @@
#include "gtkcsscolorvalueprivate.h"
#include "gtkcssshadowvalueprivate.h"
#include "gtkpangoprivate.h"
#include "gtksnapshot.h"
#include "gtksnapshotprivate.h"
#include "gtktypebuiltins.h"
#include "gtksettings.h"
#include "gdkcairoprivate.h"
void
@ -35,7 +36,7 @@ gtk_css_style_snapshot_layout (GtkCssBoxes *boxes,
PangoLayout *layout)
{
GtkCssStyle *style;
const GdkRGBA *color;
GdkColor color;
gboolean has_shadow;
gtk_snapshot_push_debug (snapshot, "Layout");
@ -47,11 +48,11 @@ gtk_css_style_snapshot_layout (GtkCssBoxes *boxes,
}
style = boxes->style;
color = gtk_css_color_value_get_rgba (style->used->color);
gtk_css_color_to_color (gtk_css_color_value_get_color (style->used->color), &color);
has_shadow = gtk_css_shadow_value_push_snapshot (style->used->text_shadow, snapshot);
gtk_snapshot_append_layout (snapshot, layout, color);
gtk_snapshot_append_layout2 (snapshot, layout, &color);
if (has_shadow)
gtk_snapshot_pop (snapshot);
@ -59,6 +60,8 @@ gtk_css_style_snapshot_layout (GtkCssBoxes *boxes,
if (x != 0 || y != 0)
gtk_snapshot_restore (snapshot);
gdk_color_finish (&color);
gtk_snapshot_pop (snapshot);
}
@ -69,7 +72,7 @@ draw_insertion_cursor (cairo_t *cr,
double width,
double height,
double aspect_ratio,
const GdkRGBA *color,
const GdkColor *color,
PangoDirection direction,
gboolean draw_arrow)
{
@ -81,7 +84,7 @@ draw_insertion_cursor (cairo_t *cr,
cairo_save (cr);
cairo_new_path (cr);
gdk_cairo_set_source_rgba (cr, color);
gdk_cairo_set_source_color (cr, GDK_COLOR_STATE_SRGB, color);
stem_width = height * aspect_ratio + 1;
@ -188,12 +191,12 @@ snapshot_insertion_cursor (GtkSnapshot *snapshot,
PangoDirection direction,
gboolean draw_arrow)
{
const GdkRGBA *color;
GdkColor color;
if (is_primary)
color = gtk_css_color_value_get_rgba (style->used->caret_color);
else
color = gtk_css_color_value_get_rgba (style->used->secondary_caret_color);
gtk_css_color_to_color (is_primary
? gtk_css_color_value_get_color (style->used->caret_color)
: gtk_css_color_value_get_color (style->used->secondary_caret_color),
&color);
if (width != 0 || draw_arrow)
{
@ -203,7 +206,7 @@ snapshot_insertion_cursor (GtkSnapshot *snapshot,
get_insertion_cursor_bounds (width, height, aspect_ratio, direction, draw_arrow, &bounds);
cr = gtk_snapshot_append_cairo (snapshot, &bounds);
draw_insertion_cursor (cr, 0, 0, width, height, aspect_ratio, color, direction, draw_arrow);
draw_insertion_cursor (cr, 0, 0, width, height, aspect_ratio, &color, direction, draw_arrow);
cairo_destroy (cr);
}
@ -220,9 +223,9 @@ snapshot_insertion_cursor (GtkSnapshot *snapshot,
else
offset = stem_width - stem_width / 2;
gtk_snapshot_append_color (snapshot,
color,
&GRAPHENE_RECT_INIT (- offset, 0, stem_width, height));
gtk_snapshot_append_color2 (snapshot,
&color,
&GRAPHENE_RECT_INIT (- offset, 0, stem_width, height));
}
}

View File

@ -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;

View File

@ -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);

View File

@ -3867,7 +3867,7 @@ render_para (GskPangoRenderer *crenderer,
GtkTextLineDisplay *line_display,
int selection_start_index,
int selection_end_index,
const GdkRGBA *selection,
const GdkColor *selection_color,
gboolean draw_selection_text,
float cursor_alpha)
{
@ -3921,11 +3921,11 @@ render_para (GskPangoRenderer *crenderer,
*/
if (selection_start_index < byte_offset &&
selection_end_index > pango_layout_line_get_length (line) + byte_offset &&
selection->alpha >= 1)
gdk_color_is_opaque (selection_color))
{
gtk_snapshot_append_color (crenderer->snapshot,
selection,
&GRAPHENE_RECT_INIT (line_display->left_margin,
gtk_snapshot_append_color2 (crenderer->snapshot,
selection_color,
&GRAPHENE_RECT_INIT (line_display->left_margin,
selection_y,
screen_width,
selection_height));
@ -3990,7 +3990,7 @@ render_para (GskPangoRenderer *crenderer,
PANGO_PIXELS (line_rect.width) -
bounds.origin.x);
gtk_snapshot_append_color (crenderer->snapshot, selection, &bounds);
gtk_snapshot_append_color2 (crenderer->snapshot, selection_color, &bounds);
if (draw_selection_text)
{
@ -4009,12 +4009,12 @@ render_para (GskPangoRenderer *crenderer,
if (line_rect.x > line_display->left_margin * PANGO_SCALE &&
((line_display->direction == GTK_TEXT_DIR_LTR && selection_start_index < byte_offset) ||
(line_display->direction == GTK_TEXT_DIR_RTL && selection_end_index > byte_offset + pango_layout_line_get_length (line))))
gtk_snapshot_append_color (crenderer->snapshot,
selection,
&GRAPHENE_RECT_INIT (line_display->left_margin,
selection_y,
PANGO_PIXELS (line_rect.x) - line_display->left_margin,
selection_height));
gtk_snapshot_append_color2 (crenderer->snapshot,
selection_color,
&GRAPHENE_RECT_INIT (line_display->left_margin,
selection_y,
PANGO_PIXELS (line_rect.x) - line_display->left_margin,
selection_height));
if (line_rect.x + line_rect.width <
(screen_width + line_display->left_margin) * PANGO_SCALE &&
@ -4025,9 +4025,9 @@ render_para (GskPangoRenderer *crenderer,
+ screen_width
- PANGO_PIXELS (line_rect.x)
- PANGO_PIXELS (line_rect.width);
gtk_snapshot_append_color (crenderer->snapshot,
selection,
&GRAPHENE_RECT_INIT (PANGO_PIXELS (line_rect.x) + PANGO_PIXELS (line_rect.width),
gtk_snapshot_append_color2 (crenderer->snapshot,
selection_color,
&GRAPHENE_RECT_INIT (PANGO_PIXELS (line_rect.x) + PANGO_PIXELS (line_rect.width),
selection_y,
nonlayout_width,
selection_height));
@ -4042,7 +4042,7 @@ render_para (GskPangoRenderer *crenderer,
{
GtkCssNode *node;
GtkCssStyle *style;
const GdkRGBA *cursor_color;
GdkColor cursor_color;
graphene_rect_t bounds = {
.origin.x = line_display->x_offset + line_display->block_cursor.x,
.origin.y = line_display->block_cursor.y + line_display->top_margin,
@ -4056,10 +4056,11 @@ render_para (GskPangoRenderer *crenderer,
node = gtk_widget_get_css_node (crenderer->widget);
style = gtk_css_node_get_style (node);
cursor_color = gtk_css_color_value_get_rgba (style->used->caret_color);
gtk_css_color_to_color (gtk_css_color_value_get_color (style->used->caret_color),
&cursor_color);
gtk_snapshot_push_opacity (crenderer->snapshot, cursor_alpha);
gtk_snapshot_append_color (crenderer->snapshot, cursor_color, &bounds);
gtk_snapshot_append_color2 (crenderer->snapshot, &cursor_color, &bounds);
/* draw text under the cursor if any */
if (!line_display->cursor_at_line_end)
@ -4114,8 +4115,7 @@ gtk_text_layout_snapshot (GtkTextLayout *layout,
int selection_end_line;
gboolean have_selection;
gboolean draw_selection_text;
const GdkRGBA *selection;
const GdkRGBA *color;
GdkColor selection_color;
GtkSnapshot *cursor_snapshot;
GtkTextBTree *btree;
GtkTextLine *first_line;
@ -4146,8 +4146,6 @@ gtk_text_layout_snapshot (GtkTextLayout *layout,
node = gtk_widget_get_css_node (widget);
style = gtk_css_node_get_style (node);
color = gtk_css_color_value_get_rgba (style->used->color);
gtk_snapshot_translate (snapshot, &GRAPHENE_POINT_INIT (0, offset_y));
offset_y = 0;
@ -4159,7 +4157,8 @@ gtk_text_layout_snapshot (GtkTextLayout *layout,
crenderer->widget = widget;
crenderer->snapshot = snapshot;
crenderer->fg_color = color;
gtk_css_color_to_color (gtk_css_color_value_get_color (style->used->color),
&crenderer->fg_color);
have_selection = gtk_text_buffer_get_selection_bounds (layout->buffer,
&selection_start,
@ -4167,7 +4166,6 @@ gtk_text_layout_snapshot (GtkTextLayout *layout,
if (have_selection)
{
GtkCssNode *selection_node;
const GdkRGBA *text_color;
selection_start_line = gtk_text_iter_get_line (&selection_start);
selection_end_line = gtk_text_iter_get_line (&selection_end);
@ -4175,16 +4173,16 @@ gtk_text_layout_snapshot (GtkTextLayout *layout,
selection_node = gtk_text_view_get_selection_node ((GtkTextView*)widget);
style = gtk_css_node_get_style (selection_node);
selection = gtk_css_color_value_get_rgba (style->used->background_color);
text_color = gtk_css_color_value_get_rgba (style->used->color);
gtk_css_color_to_color (gtk_css_color_value_get_color (style->used->background_color),
&selection_color);
draw_selection_text = text_color->alpha > 0;
draw_selection_text = !gdk_color_is_clear (&crenderer->fg_color);
}
else
{
selection_start_line = -1;
selection_end_line = -1;
selection = NULL;
gdk_color_init (&selection_color, GDK_COLOR_STATE_SRGB, (float[]) { 0, 0, 0, 0 });
draw_selection_text = FALSE;
}
@ -4260,7 +4258,7 @@ gtk_text_layout_snapshot (GtkTextLayout *layout,
gtk_snapshot_push_collect (snapshot);
render_para (crenderer, line_display,
selection_start_index, selection_end_index,
selection,
&selection_color,
draw_selection_text,
cursor_alpha);
line_display->node = gtk_snapshot_pop_collect (snapshot);
@ -4335,6 +4333,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);
}

View File

@ -826,19 +826,6 @@ get_color2_texture (const GdkColor *color)
return texture;
}
static GdkTexture *
get_color_texture (const GdkRGBA *rgba)
{
GdkColor color;
GdkTexture *texture;
gdk_color_init_from_rgba (&color, rgba);
texture = get_color2_texture (&color);
gdk_color_finish (&color);
return texture;
}
static GdkTexture *
get_linear_gradient_texture (gsize n_stops, const GskColorStop *stops)
{
@ -907,24 +894,9 @@ add_text_row (GListStore *store,
}
static void
add_color_row (GListStore *store,
const char *name,
const GdkRGBA *color)
{
char *text;
GdkTexture *texture;
text = gdk_rgba_to_string (color);
texture = get_color_texture (color);
list_store_add_object_property (store, name, text, texture);
g_free (text);
g_object_unref (texture);
}
static void
add_color2_row (GListStore *store,
const char *name,
const GdkColor *color)
add_color_row (GListStore *store,
const char *name,
const GdkColor *color)
{
char *text;
GdkTexture *texture;
@ -1112,7 +1084,7 @@ populate_render_node_properties (GListStore *store,
break;
case GSK_COLOR_NODE:
add_color2_row (store, "Color", gsk_color_node_get_color2 (node));
add_color_row (store, "Color", gsk_color_node_get_color2 (node));
break;
case GSK_LINEAR_GRADIENT_NODE:
@ -1210,7 +1182,6 @@ populate_render_node_properties (GListStore *store,
case GSK_TEXT_NODE:
{
const PangoFont *font = gsk_text_node_get_font (node);
const GdkRGBA *color = gsk_text_node_get_color (node);
const graphene_point_t *offset = gsk_text_node_get_offset (node);
PangoFontDescription *desc;
GString *s;
@ -1229,7 +1200,7 @@ populate_render_node_properties (GListStore *store,
add_text_row (store, "Position", "%.2f %.2f", offset->x, offset->y);
add_color_row (store, "Color", color);
add_color_row (store, "Color", gsk_text_node_get_color2 (node));
}
break;
@ -1375,7 +1346,7 @@ G_GNUC_END_IGNORE_DEPRECATIONS
float spread = gsk_inset_shadow_node_get_spread (node);
float radius = gsk_inset_shadow_node_get_blur_radius (node);
add_color2_row (store, "Color", color);
add_color_row (store, "Color", color);
add_text_row (store, "Offset", "%.2f %.2f", dx, dy);
@ -1399,7 +1370,7 @@ G_GNUC_END_IGNORE_DEPRECATIONS
"%.2f x %.2f + %.2f + %.2f",
rect[2], rect[3], rect[0], rect[1]);
add_color2_row (store, "Color", color);
add_color_row (store, "Color", color);
add_text_row (store, "Offset", "%.2f %.2f", dx, dy);
@ -1535,7 +1506,7 @@ G_GNUC_END_IGNORE_DEPRECATIONS
const GskShadow2 *shadow = gsk_shadow_node_get_shadow2 (node, i);
label = g_strdup_printf ("Color %d", i);
add_color2_row (store, label, &shadow->color);
add_color_row (store, label, &shadow->color);
g_free (label);
label = g_strdup_printf ("Offset %d", i);

View File

@ -3,3 +3,9 @@ text {
font: "Cantarell 300px";
glyphs: 50 312, 2712 0 -156 -29 color;
}
text {
color: color(srgb-linear 0.3 0.4 1 / 0.5);
font: "Cantarell 300px";
glyphs: 50 312, 2712 0 -156 -29 color;
}

View File

@ -3,3 +3,8 @@ text {
font: "Cantarell 300px";
glyphs: 50 312, 2712 0 -156 -29 color;
}
text {
color: color(srgb-linear 0.3 0.4 1 / 0.5);
font: "Cantarell 300px";
glyphs: 50 312, 2712 0 -156 -29 color;
}