Commit 384df61c authored by Paolo Borelli's avatar Paolo Borelli

css: add support for text-decoration-line

parent 9e26fa9a
......@@ -553,6 +553,52 @@ _gtk_css_font_stretch_value_get (const GtkCssValue *value)
return value->value;
}
/* GtkTextDecorationLine */
static const GtkCssValueClass GTK_CSS_VALUE_TEXT_DECORATION_LINE = {
gtk_css_value_enum_free,
gtk_css_value_enum_compute,
gtk_css_value_enum_equal,
gtk_css_value_enum_transition,
gtk_css_value_enum_print
};
static GtkCssValue text_decoration_line_values[] = {
{ &GTK_CSS_VALUE_TEXT_DECORATION_LINE, 1, GTK_CSS_TEXT_DECORATION_LINE_NONE, "none" },
{ &GTK_CSS_VALUE_TEXT_DECORATION_LINE, 1, GTK_CSS_TEXT_DECORATION_LINE_UNDERLINE, "underline" },
{ &GTK_CSS_VALUE_TEXT_DECORATION_LINE, 1, GTK_CSS_TEXT_DECORATION_LINE_LINE_THROUGH, "line-through" },
};
GtkCssValue *
_gtk_css_text_decoration_line_value_new (GtkTextDecorationLine line)
{
g_return_val_if_fail (line < G_N_ELEMENTS (text_decoration_line_values), NULL);
return _gtk_css_value_ref (&text_decoration_line_values[line]);
}
GtkCssValue *_gtk_css_text_decoration_line_value_try_parse (GtkCssParser *parser)
{
guint i;
g_return_val_if_fail (parser != NULL, NULL);
for (i = 0; i < G_N_ELEMENTS (text_decoration_line_values); i++)
{
if (_gtk_css_parser_try (parser, text_decoration_line_values[i].name, TRUE))
return _gtk_css_value_ref (&text_decoration_line_values[i]);
}
return NULL;
}
GtkTextDecorationLine _gtk_css_text_decoration_line_value_get (const GtkCssValue *value)
{
g_return_val_if_fail (value->class == &GTK_CSS_VALUE_TEXT_DECORATION_LINE, GTK_CSS_TEXT_DECORATION_LINE_NONE);
return value->value;
}
/* GtkCssArea */
static const GtkCssValueClass GTK_CSS_VALUE_AREA = {
......
......@@ -52,6 +52,10 @@ GtkCssValue * _gtk_css_font_stretch_value_new (PangoStretch stretc
GtkCssValue * _gtk_css_font_stretch_value_try_parse (GtkCssParser *parser);
PangoStretch _gtk_css_font_stretch_value_get (const GtkCssValue *value);
GtkCssValue * _gtk_css_text_decoration_line_value_new (GtkTextDecorationLine line);
GtkCssValue * _gtk_css_text_decoration_line_value_try_parse (GtkCssParser *parser);
GtkTextDecorationLine _gtk_css_text_decoration_line_value_get (const GtkCssValue *value);
GtkCssValue * _gtk_css_area_value_new (GtkCssArea area);
GtkCssValue * _gtk_css_area_value_try_parse (GtkCssParser *parser);
GtkCssArea _gtk_css_area_value_get (const GtkCssValue *value);
......
......@@ -617,6 +617,18 @@ parse_letter_spacing (GtkCssStyleProperty *property,
return _gtk_css_number_value_parse (parser, GTK_CSS_PARSE_LENGTH);
}
static GtkCssValue *
parse_text_decoration_line (GtkCssStyleProperty *property,
GtkCssParser *parser)
{
GtkCssValue *value = _gtk_css_text_decoration_line_value_try_parse (parser);
if (value == NULL)
_gtk_css_parser_error (parser, "unknown value for property");
return value;
}
static GtkCssValue *
box_shadow_value_parse (GtkCssStyleProperty *property,
GtkCssParser *parser)
......@@ -1082,6 +1094,16 @@ _gtk_css_style_property_init_properties (void)
NULL,
_gtk_css_number_value_new (0.0, GTK_CSS_PX));
gtk_css_style_property_register ("text-decoration-line",
GTK_CSS_PROPERTY_TEXT_DECORATION_LINE,
G_TYPE_NONE,
0,
GTK_CSS_AFFECTS_TEXT | GTK_CSS_AFFECTS_TEXT_ATTRS,
parse_text_decoration_line,
NULL,
NULL,
_gtk_css_text_decoration_line_value_new (GTK_CSS_TEXT_DECORATION_LINE_NONE));
gtk_css_style_property_register ("text-shadow",
GTK_CSS_PROPERTY_TEXT_SHADOW,
G_TYPE_NONE,
......
......@@ -119,6 +119,7 @@ enum { /*< skip >*/
GTK_CSS_PROPERTY_FONT_WEIGHT,
GTK_CSS_PROPERTY_FONT_STRETCH,
GTK_CSS_PROPERTY_LETTER_SPACING,
GTK_CSS_PROPERTY_TEXT_DECORATION_LINE,
GTK_CSS_PROPERTY_TEXT_SHADOW,
GTK_CSS_PROPERTY_BOX_SHADOW,
GTK_CSS_PROPERTY_MARGIN_TOP,
......@@ -238,6 +239,12 @@ typedef enum /*< skip >*/ {
GTK_CSS_FONT_SIZE_XX_LARGE
} GtkCssFontSize;
typedef enum /*< skip >*/ {
GTK_CSS_TEXT_DECORATION_LINE_NONE,
GTK_CSS_TEXT_DECORATION_LINE_UNDERLINE,
GTK_CSS_TEXT_DECORATION_LINE_LINE_THROUGH
} GtkTextDecorationLine;
/* for the order in arrays */
typedef enum /*< skip >*/ {
GTK_CSS_TOP,
......
......@@ -3148,21 +3148,45 @@ _gtk_style_context_get_icon_extents (GtkStyleContext *context,
extents->height += border.top + border.bottom;
}
static PangoAttrList *
add_pango_attr(PangoAttrList *attrs, PangoAttribute *attr)
{
if (attrs == NULL)
attrs = pango_attr_list_new ();
pango_attr_list_insert (attrs, attr);
return attrs;
}
PangoAttrList *
_gtk_style_context_get_pango_attributes (GtkStyleContext *context)
{
gint letter_spacing;
PangoAttrList *attrs = NULL;
GtkTextDecorationLine decoration_line;
gint letter_spacing;
/* text-decoration */
decoration_line = _gtk_css_text_decoration_line_value_get (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_TEXT_DECORATION_LINE));
switch (decoration_line)
{
case GTK_CSS_TEXT_DECORATION_LINE_UNDERLINE:
attrs = add_pango_attr (attrs, pango_attr_underline_new (PANGO_UNDERLINE_SINGLE));
break;
case GTK_CSS_TEXT_DECORATION_LINE_LINE_THROUGH:
attrs = add_pango_attr (attrs, pango_attr_strikethrough_new (TRUE));
break;
case GTK_CSS_TEXT_DECORATION_LINE_NONE:
default:
break;
}
/* letter-spacing */
letter_spacing = _gtk_css_number_value_get (_gtk_style_context_peek_property (context, GTK_CSS_PROPERTY_LETTER_SPACING), 100);
if (letter_spacing != 0)
{
PangoAttribute *letter_spacing_attr;
letter_spacing_attr = pango_attr_letter_spacing_new (letter_spacing * PANGO_SCALE);
attrs = pango_attr_list_new ();
pango_attr_list_insert (attrs, letter_spacing_attr);
attrs = add_pango_attr (attrs, pango_attr_letter_spacing_new (letter_spacing * PANGO_SCALE));
}
return attrs;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment