mirror of
https://gitlab.gnome.org/GNOME/gtk.git
synced 2024-12-27 22:20:24 +00:00
Merge branch 'css-relative-font' into 'main'
css: Fix relative font sizes Closes #6868 See merge request GNOME/gtk!7498
This commit is contained in:
commit
62f359a494
@ -978,7 +978,8 @@ gtk_css_color_value_new_relative (GtkCssValue *origin,
|
||||
{
|
||||
if (values[i])
|
||||
{
|
||||
if (!gtk_css_value_is_computed (values[i]))
|
||||
if (!gtk_css_value_is_computed (values[i]) &&
|
||||
!gtk_css_number_value_has_percent (values[i]))
|
||||
computed = FALSE;
|
||||
if (gtk_css_value_contains_current_color (values[i]))
|
||||
resolved = FALSE;
|
||||
|
@ -365,7 +365,6 @@ gtk_css_value_number_compute (GtkCssValue *number,
|
||||
}
|
||||
else
|
||||
{
|
||||
GtkCssValue *result;
|
||||
double value = number->dimension.value;
|
||||
|
||||
switch (number->dimension.unit)
|
||||
@ -374,68 +373,50 @@ gtk_css_value_number_compute (GtkCssValue *number,
|
||||
/* percentages for font sizes are computed, other percentages aren't */
|
||||
if (property_id == GTK_CSS_PROPERTY_FONT_SIZE)
|
||||
{
|
||||
result = gtk_css_dimension_value_new (value / 100.0 *
|
||||
get_base_font_size_px (property_id, provider, style, parent_style),
|
||||
GTK_CSS_PX);
|
||||
break;
|
||||
return gtk_css_dimension_value_new (value / 100.0 *
|
||||
get_base_font_size_px (property_id, provider, style, parent_style),
|
||||
GTK_CSS_PX);
|
||||
}
|
||||
G_GNUC_FALLTHROUGH;
|
||||
case GTK_CSS_NUMBER:
|
||||
case GTK_CSS_PX:
|
||||
case GTK_CSS_DEG:
|
||||
case GTK_CSS_S:
|
||||
result = gtk_css_dimension_value_new (value, number->dimension.unit);
|
||||
break;
|
||||
return gtk_css_dimension_value_new (value, number->dimension.unit);
|
||||
case GTK_CSS_PT:
|
||||
result = gtk_css_dimension_value_new (value * get_dpi (style) / 72.0, GTK_CSS_PX);
|
||||
break;
|
||||
return gtk_css_dimension_value_new (value * get_dpi (style) / 72.0, GTK_CSS_PX);
|
||||
case GTK_CSS_PC:
|
||||
result = gtk_css_dimension_value_new (value * get_dpi (style) / 72.0 * 12.0, GTK_CSS_PX);
|
||||
break;
|
||||
return gtk_css_dimension_value_new (value * get_dpi (style) / 72.0 * 12.0, GTK_CSS_PX);
|
||||
case GTK_CSS_IN:
|
||||
result = gtk_css_dimension_value_new (value * get_dpi (style), GTK_CSS_PX);
|
||||
break;
|
||||
return gtk_css_dimension_value_new (value * get_dpi (style), GTK_CSS_PX);
|
||||
case GTK_CSS_CM:
|
||||
result = gtk_css_dimension_value_new (value * get_dpi (style) * 0.39370078740157477, GTK_CSS_PX);
|
||||
break;
|
||||
return gtk_css_dimension_value_new (value * get_dpi (style) * 0.39370078740157477, GTK_CSS_PX);
|
||||
case GTK_CSS_MM:
|
||||
result = gtk_css_dimension_value_new (value * get_dpi (style) * 0.039370078740157477, GTK_CSS_PX);
|
||||
break;
|
||||
return gtk_css_dimension_value_new (value * get_dpi (style) * 0.039370078740157477, GTK_CSS_PX);
|
||||
case GTK_CSS_EM:
|
||||
result = gtk_css_dimension_value_new (value *
|
||||
get_base_font_size_px (property_id, provider, style, parent_style),
|
||||
GTK_CSS_PX);
|
||||
break;
|
||||
return gtk_css_dimension_value_new (value *
|
||||
get_base_font_size_px (property_id, provider, style, parent_style),
|
||||
GTK_CSS_PX);
|
||||
case GTK_CSS_EX:
|
||||
/* for now we pretend ex is half of em */
|
||||
result = gtk_css_dimension_value_new (value * 0.5 *
|
||||
get_base_font_size_px (property_id, provider, style, parent_style),
|
||||
GTK_CSS_PX);
|
||||
break;
|
||||
return gtk_css_dimension_value_new (value * 0.5 *
|
||||
get_base_font_size_px (property_id, provider, style, parent_style),
|
||||
GTK_CSS_PX);
|
||||
case GTK_CSS_REM:
|
||||
result = gtk_css_dimension_value_new (value *
|
||||
gtk_css_font_size_get_default_px (provider, style),
|
||||
GTK_CSS_PX);
|
||||
break;
|
||||
return gtk_css_dimension_value_new (value *
|
||||
gtk_css_font_size_get_default_px (provider, style),
|
||||
GTK_CSS_PX);
|
||||
case GTK_CSS_RAD:
|
||||
result = gtk_css_dimension_value_new (value * 360.0 / (2 * G_PI), GTK_CSS_DEG);
|
||||
break;
|
||||
return gtk_css_dimension_value_new (value * 360.0 / (2 * G_PI), GTK_CSS_DEG);
|
||||
case GTK_CSS_GRAD:
|
||||
result = gtk_css_dimension_value_new (value * 360.0 / 400.0, GTK_CSS_DEG);
|
||||
break;
|
||||
return gtk_css_dimension_value_new (value * 360.0 / 400.0, GTK_CSS_DEG);
|
||||
case GTK_CSS_TURN:
|
||||
result = gtk_css_dimension_value_new (value * 360.0, GTK_CSS_DEG);
|
||||
break;
|
||||
return gtk_css_dimension_value_new (value * 360.0, GTK_CSS_DEG);
|
||||
case GTK_CSS_MS:
|
||||
result = gtk_css_dimension_value_new (value / 1000.0, GTK_CSS_S);
|
||||
break;
|
||||
return gtk_css_dimension_value_new (value / 1000.0, GTK_CSS_S);
|
||||
default:
|
||||
g_assert_not_reached();
|
||||
}
|
||||
|
||||
result->is_computed = TRUE;
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
@ -720,9 +701,9 @@ gtk_css_dimension_value_new (double value,
|
||||
{ >K_CSS_VALUE_NUMBER, 1, 1, 0, 0, TYPE_DIMENSION, {{ GTK_CSS_PX, 64 }} },
|
||||
};
|
||||
static GtkCssValue percent_singletons[] = {
|
||||
{ >K_CSS_VALUE_NUMBER, 1, 1, 0, 0, TYPE_DIMENSION, {{ GTK_CSS_PERCENT, 0 }} },
|
||||
{ >K_CSS_VALUE_NUMBER, 1, 1, 0, 0, TYPE_DIMENSION, {{ GTK_CSS_PERCENT, 50 }} },
|
||||
{ >K_CSS_VALUE_NUMBER, 1, 1, 0, 0, TYPE_DIMENSION, {{ GTK_CSS_PERCENT, 100 }} },
|
||||
{ >K_CSS_VALUE_NUMBER, 1, 0, 0, 0, TYPE_DIMENSION, {{ GTK_CSS_PERCENT, 0 }} },
|
||||
{ >K_CSS_VALUE_NUMBER, 1, 0, 0, 0, TYPE_DIMENSION, {{ GTK_CSS_PERCENT, 50 }} },
|
||||
{ >K_CSS_VALUE_NUMBER, 1, 0, 0, 0, TYPE_DIMENSION, {{ GTK_CSS_PERCENT, 100 }} },
|
||||
};
|
||||
static GtkCssValue second_singletons[] = {
|
||||
{ >K_CSS_VALUE_NUMBER, 1, 1, 0, 0, TYPE_DIMENSION, {{ GTK_CSS_S, 0 }} },
|
||||
|
@ -108,7 +108,7 @@ test_number_value (gconstpointer data)
|
||||
if (test->is_computed)
|
||||
g_assert_true (res == value);
|
||||
|
||||
g_assert_true (gtk_css_value_is_computed (res));
|
||||
g_assert_true (gtk_css_number_value_has_percent (res) || gtk_css_value_is_computed (res));
|
||||
|
||||
if (test->computed)
|
||||
{
|
||||
@ -140,7 +140,7 @@ static CssColorValueTest color_tests[] = {
|
||||
{ "rgba(255, 255, 128, 0.1)", TRUE, FALSE, "rgba(255,255,128,0.1)", "rgba(255,255,128,0.1)" },
|
||||
{ "currentcolor", TRUE, TRUE, "currentcolor", "currentcolor", "color(srgb 1 0 0)", "color(srgb 1 0 0)" },
|
||||
{ "color(from color(srgb 0.5 0.5 0.2) srgb 0.5 calc(r * g) b / calc(alpha / 2))", TRUE, FALSE, "color(srgb 0.5 0.25 0.2 / 0.5)", "color(srgb 0.5 0.25 0.2 / 0.5)" },
|
||||
{ "rgb(from currentcolor r g 40% / 50%)", FALSE, TRUE, "color(from currentcolor srgb r g 40% / 50%)", "color(from currentcolor srgb r g 40% / 50%)", "color(srgb 1 0 0)", "color(srgb 1 0 0.4 / 0.5)" },
|
||||
{ "rgb(from currentcolor r g 40% / 50%)", TRUE, TRUE, "color(from currentcolor srgb r g 40% / 50%)", "color(from currentcolor srgb r g 40% / 50%)", "color(srgb 1 0 0)", "color(srgb 1 0 0.4 / 0.5)" },
|
||||
{ "rgb(from darkgoldenrod r g 100 / 50%)", TRUE, FALSE, "color(srgb 0.721569 0.52549 0.392157 / 0.5)", "color(srgb 0.721569 0.52549 0.392157 / 0.5)" },
|
||||
{ "rgb(from white 100% 100% 100% / 100%)", TRUE, FALSE, "color(srgb 1 1 1)", "color(srgb 1 1 1)" },
|
||||
{ "color(from white srgb 100% 100% 100% / 100%)", TRUE, FALSE, "color(srgb 1 1 1)", "color(srgb 1 1 1)" },
|
||||
|
Loading…
Reference in New Issue
Block a user