summaryrefslogtreecommitdiff
path: root/gtk/gtkcssenumvalue.c
diff options
context:
space:
mode:
authorBenjamin Otte <otte@redhat.com>2015-02-15 05:02:33 +0100
committerBenjamin Otte <otte@redhat.com>2015-02-16 23:57:03 +0100
commit0c4a42e6295bd2546263502fb9867c3f075a2bf4 (patch)
treecba3e3a9143cb61a96bd793e8c6a111fb31c6296 /gtk/gtkcssenumvalue.c
parenta414faa99736fba99c8488f2e497d492a717c667 (diff)
downloadgtk+-0c4a42e6295bd2546263502fb9867c3f075a2bf4.tar.gz
css: Implement "bolder" and "lighter" font weights
Diffstat (limited to 'gtk/gtkcssenumvalue.c')
-rw-r--r--gtk/gtkcssenumvalue.c60
1 files changed, 58 insertions, 2 deletions
diff --git a/gtk/gtkcssenumvalue.c b/gtk/gtkcssenumvalue.c
index 49833df092..502df3e59e 100644
--- a/gtk/gtkcssenumvalue.c
+++ b/gtk/gtkcssenumvalue.c
@@ -368,15 +368,68 @@ _gtk_css_font_variant_value_get (const GtkCssValue *value)
/* PangoWeight */
+#define BOLDER -1
+#define LIGHTER -2
+
+static GtkCssValue *
+gtk_css_value_font_weight_compute (GtkCssValue *value,
+ guint property_id,
+ GtkStyleProviderPrivate *provider,
+ GtkCssStyle *style,
+ GtkCssStyle *parent_style,
+ GtkCssDependencies *dependencies)
+{
+ PangoWeight new_weight;
+ int parent_value;
+
+ if (value->value >= 0)
+ return _gtk_css_value_ref (value);
+
+ *dependencies = GTK_CSS_DEPENDS_ON_PARENT;
+
+ if (parent_style)
+ parent_value = gtk_css_style_get_value (parent_style, property_id)->value;
+ else
+ parent_value = 400;
+
+ if (value->value == BOLDER)
+ {
+ if (parent_value < 400)
+ new_weight = PANGO_WEIGHT_NORMAL;
+ else if (parent_value < 600)
+ new_weight = PANGO_WEIGHT_BOLD;
+ else
+ new_weight = PANGO_WEIGHT_HEAVY;
+ }
+ else if (value->value == LIGHTER)
+ {
+ if (parent_value > 700)
+ new_weight = PANGO_WEIGHT_BOLD;
+ else if (parent_value > 500)
+ new_weight = PANGO_WEIGHT_NORMAL;
+ else
+ new_weight = PANGO_WEIGHT_THIN;
+ }
+ else
+ {
+ g_assert_not_reached ();
+ new_weight = PANGO_WEIGHT_NORMAL;
+ }
+
+ return _gtk_css_font_weight_value_new (new_weight);
+}
+
static const GtkCssValueClass GTK_CSS_VALUE_FONT_WEIGHT = {
gtk_css_value_enum_free,
- gtk_css_value_enum_compute,
+ gtk_css_value_font_weight_compute,
gtk_css_value_enum_equal,
gtk_css_value_enum_transition,
gtk_css_value_enum_print
};
static GtkCssValue font_weight_values[] = {
+ { &GTK_CSS_VALUE_FONT_WEIGHT, 1, BOLDER, "bolder" },
+ { &GTK_CSS_VALUE_FONT_WEIGHT, 1, LIGHTER, "lighter" },
{ &GTK_CSS_VALUE_FONT_WEIGHT, 1, PANGO_WEIGHT_THIN, "100" },
{ &GTK_CSS_VALUE_FONT_WEIGHT, 1, PANGO_WEIGHT_ULTRALIGHT, "200" },
{ &GTK_CSS_VALUE_FONT_WEIGHT, 1, PANGO_WEIGHT_LIGHT, "300" },
@@ -396,7 +449,7 @@ _gtk_css_font_weight_value_new (PangoWeight font_weight)
w = ((font_weight + 50) / 100) * 100;
- for (i = 0; i < G_N_ELEMENTS (font_weight_values); i++)
+ for (i = 2; i < G_N_ELEMENTS (font_weight_values); i++)
{
if (font_weight_values[i].value == w)
return _gtk_css_value_ref (&font_weight_values[i]);
@@ -434,6 +487,9 @@ _gtk_css_font_weight_value_get (const GtkCssValue *value)
return value->value;
}
+#undef BOLDER
+#undef LIGHTER
+
/* PangoStretch */
static const GtkCssValueClass GTK_CSS_VALUE_FONT_STRETCH = {