Merge branch 'matthiasc/for-main' into 'main'

node parser: Move parse_color even earlier

See merge request GNOME/gtk!7625
This commit is contained in:
Matthias Clasen 2024-08-17 23:35:44 +00:00
commit d9a0f3cfe2
2 changed files with 100 additions and 101 deletions

View File

@ -613,105 +613,6 @@ clear_string (gpointer inout_string)
g_clear_pointer ((char **) inout_string, g_free);
}
static gboolean
parse_stops (GtkCssParser *parser,
Context *context,
gpointer out_stops)
{
GArray *stops;
GskColorStop stop;
stops = g_array_new (FALSE, FALSE, sizeof (GskColorStop));
for (;;)
{
double dval;
if (!gtk_css_parser_consume_number (parser, &dval))
goto error;
stop.offset = dval;
if (!gdk_rgba_parser_parse (parser, &stop.color))
goto error;
if (stops->len == 0 && stop.offset < 0)
gtk_css_parser_error_value (parser, "Color stop offset must be >= 0");
else if (stops->len > 0 && stop.offset < g_array_index (stops, GskColorStop, stops->len - 1).offset)
gtk_css_parser_error_value (parser, "Color stop offset must be >= previous value");
else if (stop.offset > 1)
gtk_css_parser_error_value (parser, "Color stop offset must be <= 1");
else
g_array_append_val (stops, stop);
if (gtk_css_parser_has_token (parser, GTK_CSS_TOKEN_COMMA))
gtk_css_parser_skip (parser);
else
break;
}
if (stops->len < 2)
{
gtk_css_parser_error_value (parser, "At least 2 color stops need to be specified");
g_array_free (stops, TRUE);
return FALSE;
}
if (*(GArray **) out_stops)
g_array_free (*(GArray **) out_stops, TRUE);
*(GArray **) out_stops = stops;
return TRUE;
error:
g_array_free (stops, TRUE);
return FALSE;
}
static void
clear_stops (gpointer inout_stops)
{
GArray **stops = (GArray **) inout_stops;
if (*stops)
{
g_array_free (*stops, TRUE);
*stops = NULL;
}
}
static gboolean
parse_float4 (GtkCssParser *parser,
Context *context,
gpointer out_floats)
{
float *floats = (float *) out_floats;
double d[4];
int i;
for (i = 0; i < 4 && !gtk_css_parser_has_token (parser, GTK_CSS_TOKEN_EOF); i ++)
{
if (!gtk_css_parser_consume_number (parser, &d[i]))
return FALSE;
}
if (i == 0)
{
gtk_css_parser_error_syntax (parser, "Expected a color");
return FALSE;
}
for (; i < 4; i++)
{
d[i] = d[(i - 1) >> 1];
}
for (i = 0; i < 4; i++)
{
floats[i] = d[i];
}
return TRUE;
}
static gboolean
parse_color_state (GtkCssParser *parser,
Context *context,
@ -836,6 +737,104 @@ parse_color (GtkCssParser *parser,
return FALSE;
}
static gboolean
parse_stops (GtkCssParser *parser,
Context *context,
gpointer out_stops)
{
GArray *stops;
GskColorStop stop;
stops = g_array_new (FALSE, FALSE, sizeof (GskColorStop));
for (;;)
{
double dval;
if (!gtk_css_parser_consume_number (parser, &dval))
goto error;
stop.offset = dval;
if (!gdk_rgba_parser_parse (parser, &stop.color))
goto error;
if (stops->len == 0 && stop.offset < 0)
gtk_css_parser_error_value (parser, "Color stop offset must be >= 0");
else if (stops->len > 0 && stop.offset < g_array_index (stops, GskColorStop, stops->len - 1).offset)
gtk_css_parser_error_value (parser, "Color stop offset must be >= previous value");
else if (stop.offset > 1)
gtk_css_parser_error_value (parser, "Color stop offset must be <= 1");
else
g_array_append_val (stops, stop);
if (gtk_css_parser_has_token (parser, GTK_CSS_TOKEN_COMMA))
gtk_css_parser_skip (parser);
else
break;
}
if (stops->len < 2)
{
gtk_css_parser_error_value (parser, "At least 2 color stops need to be specified");
g_array_free (stops, TRUE);
return FALSE;
}
if (*(GArray **) out_stops)
g_array_free (*(GArray **) out_stops, TRUE);
*(GArray **) out_stops = stops;
return TRUE;
error:
g_array_free (stops, TRUE);
return FALSE;
}
static void
clear_stops (gpointer inout_stops)
{
GArray **stops = (GArray **) inout_stops;
if (*stops)
{
g_array_free (*stops, TRUE);
*stops = NULL;
}
}
static gboolean
parse_float4 (GtkCssParser *parser,
Context *context,
gpointer out_floats)
{
float *floats = (float *) out_floats;
double d[4];
int i;
for (i = 0; i < 4 && !gtk_css_parser_has_token (parser, GTK_CSS_TOKEN_EOF); i ++)
{
if (!gtk_css_parser_consume_number (parser, &d[i]))
return FALSE;
}
if (i == 0)
{
gtk_css_parser_error_syntax (parser, "Expected a color");
return FALSE;
}
for (; i < 4; i++)
{
d[i] = d[(i - 1) >> 1];
}
for (i = 0; i < 4; i++)
{
floats[i] = d[i];
}
return TRUE;
}
static gboolean
parse_shadows (GtkCssParser *parser,

View File

@ -699,12 +699,12 @@ static GskRenderNode *
make_dot (double x, double y)
{
GskRenderNode *fill, *dot;
GdkRGBA red = (GdkRGBA){ 1, 0, 0, 1 };
GdkColor red = GDK_COLOR_SRGB (1, 0, 0, 1);
graphene_rect_t rect = GRAPHENE_RECT_INIT (x - 3, y - 3, 6, 6);
graphene_size_t corner = GRAPHENE_SIZE_INIT (3, 3);
GskRoundedRect clip;
fill = gsk_color_node_new (&red, &rect);
fill = gsk_color_node_new2 (&red, &rect);
dot = gsk_rounded_clip_node_new (fill, gsk_rounded_rect_init (&clip, &rect,
&corner, &corner, &corner, &corner));
gsk_render_node_unref (fill);