[gtk/css-text-transform] css: Implement text-transform
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/css-text-transform] css: Implement text-transform
- Date: Fri, 20 Aug 2021 23:02:08 +0000 (UTC)
commit a8e15f4316948aa86c2c515edc98d1e94abd40a0
Author: Matthias Clasen <mclasen redhat com>
Date: Fri Aug 20 19:01:01 2021 -0400
css: Implement text-transform
Implement the text-transform property from
https://www.w3.org/TR/css-text-3/#text-transform-property
using a new Pango attribute.
gtk/gtkcssanimatedstyle.c | 4 ++++
gtk/gtkcssenumvalue.c | 52 +++++++++++++++++++++++++++++++++++++++++++
gtk/gtkcssenumvalueprivate.h | 3 +++
gtk/gtkcssstaticstyle.c | 5 +++++
gtk/gtkcssstyle.c | 26 ++++++++++++++++++++++
gtk/gtkcssstyleprivate.h | 1 +
gtk/gtkcssstylepropertyimpl.c | 18 +++++++++++++++
gtk/gtkcsstypesprivate.h | 8 +++++++
8 files changed, 117 insertions(+)
---
diff --git a/gtk/gtkcssanimatedstyle.c b/gtk/gtkcssanimatedstyle.c
index 52e0cabc3b..fd266f49be 100644
--- a/gtk/gtkcssanimatedstyle.c
+++ b/gtk/gtkcssanimatedstyle.c
@@ -216,6 +216,10 @@ gtk_css_animated_style_set_animated_value (GtkCssAnimatedStyle *animated,
unshare_font_variant (animated);
gtk_css_take_value (&style->font_variant->text_decoration_style, value);
break;
+ case GTK_CSS_PROPERTY_TEXT_TRANSFORM:
+ unshare_font_variant (animated);
+ gtk_css_take_value (&style->font_variant->text_transform, value);
+ break;
case GTK_CSS_PROPERTY_FONT_KERNING:
unshare_font_variant (animated);
gtk_css_take_value (&style->font_variant->font_kerning, value);
diff --git a/gtk/gtkcssenumvalue.c b/gtk/gtkcssenumvalue.c
index ce96a23e0c..dfb7a0d394 100644
--- a/gtk/gtkcssenumvalue.c
+++ b/gtk/gtkcssenumvalue.c
@@ -1568,3 +1568,55 @@ _gtk_css_font_variant_east_asian_value_get (const GtkCssValue *value)
return value->value;
}
+
+/* GtkTextTransform */
+
+static const GtkCssValueClass GTK_CSS_VALUE_TEXT_TRANSFORM = {
+ "GtkCssTextTransformValue",
+ gtk_css_value_enum_free,
+ gtk_css_value_enum_compute,
+ gtk_css_value_enum_equal,
+ gtk_css_value_enum_transition,
+ NULL,
+ NULL,
+ gtk_css_value_enum_print
+};
+
+static GtkCssValue text_transform_values[] = {
+ { >K_CSS_VALUE_TEXT_TRANSFORM, 1, TRUE, GTK_CSS_TEXT_TRANSFORM_NONE, "none" },
+ { >K_CSS_VALUE_TEXT_TRANSFORM, 1, TRUE, GTK_CSS_TEXT_TRANSFORM_LOWERCASE, "lowercase" },
+ { >K_CSS_VALUE_TEXT_TRANSFORM, 1, TRUE, GTK_CSS_TEXT_TRANSFORM_UPPERCASE, "uppercase" },
+ { >K_CSS_VALUE_TEXT_TRANSFORM, 1, TRUE, GTK_CSS_TEXT_TRANSFORM_CAPITALIZE, "capitalize" },
+};
+
+GtkCssValue *
+_gtk_css_text_transform_value_new (GtkTextTransform transform)
+{
+ g_return_val_if_fail (transform < G_N_ELEMENTS (text_transform_values), NULL);
+
+ return _gtk_css_value_ref (&text_transform_values[transform]);
+}
+
+GtkCssValue *
+_gtk_css_text_transform_value_try_parse (GtkCssParser *parser)
+{
+ guint i;
+
+ g_return_val_if_fail (parser != NULL, NULL);
+
+ for (i = 0; i < G_N_ELEMENTS (text_transform_values); i++)
+ {
+ if (gtk_css_parser_try_ident (parser, text_transform_values[i].name))
+ return _gtk_css_value_ref (&text_transform_values[i]);
+ }
+
+ return NULL;
+}
+
+GtkTextTransform
+_gtk_css_text_transform_value_get (const GtkCssValue *value)
+{
+ g_return_val_if_fail (value->class == >K_CSS_VALUE_TEXT_TRANSFORM, GTK_CSS_TEXT_TRANSFORM_NONE);
+
+ return value->value;
+}
diff --git a/gtk/gtkcssenumvalueprivate.h b/gtk/gtkcssenumvalueprivate.h
index a102a8650b..b6d3b0f757 100644
--- a/gtk/gtkcssenumvalueprivate.h
+++ b/gtk/gtkcssenumvalueprivate.h
@@ -115,6 +115,9 @@ GtkCssFontVariantEastAsian _gtk_css_font_variant_east_asian_try_parse_one (GtkCs
GtkCssFontVariantEastAsian base);
GtkCssFontVariantEastAsian _gtk_css_font_variant_east_asian_value_get (const GtkCssValue
*value);
+GtkCssValue * _gtk_css_text_transform_value_new (GtkTextTransform transform);
+GtkCssValue * _gtk_css_text_transform_value_try_parse (GtkCssParser *parser);
+GtkTextTransform _gtk_css_text_transform_value_get (const GtkCssValue *value);
G_END_DECLS
#endif /* __GTK_CSS_ENUM_VALUE_PRIVATE_H__ */
diff --git a/gtk/gtkcssstaticstyle.c b/gtk/gtkcssstaticstyle.c
index 1c8dd80c56..6bde87b7a4 100644
--- a/gtk/gtkcssstaticstyle.c
+++ b/gtk/gtkcssstaticstyle.c
@@ -117,6 +117,7 @@ static const int font_variant_props[] = {
GTK_CSS_PROPERTY_TEXT_DECORATION_LINE,
GTK_CSS_PROPERTY_TEXT_DECORATION_COLOR,
GTK_CSS_PROPERTY_TEXT_DECORATION_STYLE,
+ GTK_CSS_PROPERTY_TEXT_TRANSFORM,
GTK_CSS_PROPERTY_FONT_KERNING,
GTK_CSS_PROPERTY_FONT_VARIANT_LIGATURES,
GTK_CSS_PROPERTY_FONT_VARIANT_POSITION,
@@ -426,6 +427,9 @@ gtk_css_static_style_set_value (GtkCssStaticStyle *sstyle,
case GTK_CSS_PROPERTY_TEXT_DECORATION_STYLE:
gtk_css_take_value (&style->font_variant->text_decoration_style, value);
break;
+ case GTK_CSS_PROPERTY_TEXT_TRANSFORM:
+ gtk_css_take_value (&style->font_variant->text_transform, value);
+ break;
case GTK_CSS_PROPERTY_FONT_KERNING:
gtk_css_take_value (&style->font_variant->font_kerning, value);
break;
@@ -806,6 +810,7 @@ gtk_css_font_variant_create_initial_values (void)
values->text_decoration_line = _gtk_css_initial_value_new_compute (GTK_CSS_PROPERTY_TEXT_DECORATION_LINE,
NULL, NULL, NULL);
values->text_decoration_color = NULL;
values->text_decoration_style = _gtk_css_initial_value_new_compute
(GTK_CSS_PROPERTY_TEXT_DECORATION_STYLE, NULL, NULL, NULL);
+ values->text_transform = _gtk_css_initial_value_new_compute (GTK_CSS_PROPERTY_TEXT_TRANSFORM, NULL, NULL,
NULL);
values->font_kerning = _gtk_css_initial_value_new_compute (GTK_CSS_PROPERTY_FONT_KERNING, NULL, NULL,
NULL);
values->font_variant_ligatures = _gtk_css_initial_value_new_compute
(GTK_CSS_PROPERTY_FONT_VARIANT_LIGATURES, NULL, NULL, NULL);
values->font_variant_position = _gtk_css_initial_value_new_compute
(GTK_CSS_PROPERTY_FONT_VARIANT_POSITION, NULL, NULL, NULL);
diff --git a/gtk/gtkcssstyle.c b/gtk/gtkcssstyle.c
index 0f890a005d..18035917c5 100644
--- a/gtk/gtkcssstyle.c
+++ b/gtk/gtkcssstyle.c
@@ -123,6 +123,8 @@ gtk_css_style_get_value (GtkCssStyle *style,
return style->font_variant->text_decoration_color ? style->font_variant->text_decoration_color :
style->core->color;
case GTK_CSS_PROPERTY_TEXT_DECORATION_STYLE:
return style->font_variant->text_decoration_style;
+ case GTK_CSS_PROPERTY_TEXT_TRANSFORM:
+ return style->font_variant->text_transform;
case GTK_CSS_PROPERTY_FONT_KERNING:
return style->font_variant->font_kerning;
case GTK_CSS_PROPERTY_FONT_VARIANT_LIGATURES:
@@ -397,6 +399,24 @@ get_pango_underline_from_style (GtkTextDecorationStyle style)
g_return_val_if_reached (PANGO_UNDERLINE_SINGLE);
}
+static PangoTextTransform
+get_pango_text_transform_from_style (GtkTextTransform transform)
+{
+ switch (transform)
+ {
+ case GTK_CSS_TEXT_TRANSFORM_NONE:
+ return PANGO_TEXT_TRANSFORM_NONE;
+ case GTK_CSS_TEXT_TRANSFORM_LOWERCASE:
+ return PANGO_TEXT_TRANSFORM_LOWERCASE;
+ case GTK_CSS_TEXT_TRANSFORM_UPPERCASE:
+ return PANGO_TEXT_TRANSFORM_UPPERCASE;
+ case GTK_CSS_TEXT_TRANSFORM_CAPITALIZE:
+ return PANGO_TEXT_TRANSFORM_CAPITALIZE;
+ default:
+ return PANGO_TEXT_TRANSFORM_NONE;
+ }
+}
+
static PangoOverline
get_pango_overline_from_style (GtkTextDecorationStyle style)
{
@@ -442,6 +462,7 @@ gtk_css_style_get_pango_attributes (GtkCssStyle *style)
GtkCssFontVariantEastAsian east_asian;
GString *s;
char *settings;
+ GtkTextTransform transform;
/* text-decoration */
decoration_line = _gtk_css_text_decoration_line_value_get (style->font_variant->text_decoration_line);
@@ -640,6 +661,11 @@ gtk_css_style_get_pango_attributes (GtkCssStyle *style)
g_string_free (s, TRUE);
}
+ transform = _gtk_css_text_transform_value_get (style->font_variant->text_transform);
+
+ if (transform != GTK_CSS_TEXT_TRANSFORM_NONE)
+ attrs = add_pango_attr (attrs, pango_attr_text_transform_new (get_pango_text_transform_from_style
(transform)));
+
return attrs;
}
diff --git a/gtk/gtkcssstyleprivate.h b/gtk/gtkcssstyleprivate.h
index 27666e9978..d0780b0208 100644
--- a/gtk/gtkcssstyleprivate.h
+++ b/gtk/gtkcssstyleprivate.h
@@ -158,6 +158,7 @@ struct _GtkCssFontVariantValues {
GtkCssValue *text_decoration_line;
GtkCssValue *text_decoration_color; // NULL if currentColor
GtkCssValue *text_decoration_style;
+ GtkCssValue *text_transform;
GtkCssValue *font_kerning;
GtkCssValue *font_variant_ligatures;
GtkCssValue *font_variant_position;
diff --git a/gtk/gtkcssstylepropertyimpl.c b/gtk/gtkcssstylepropertyimpl.c
index 6df32116a8..11dca13de3 100644
--- a/gtk/gtkcssstylepropertyimpl.c
+++ b/gtk/gtkcssstylepropertyimpl.c
@@ -365,6 +365,18 @@ parse_text_decoration_style (GtkCssStyleProperty *property,
return value;
}
+static GtkCssValue *
+parse_text_transform (GtkCssStyleProperty *property,
+ GtkCssParser *parser)
+{
+ GtkCssValue *value = _gtk_css_text_transform_value_try_parse (parser);
+
+ if (value == NULL)
+ gtk_css_parser_error_syntax (parser, "unknown text transform value");
+
+ return value;
+}
+
static GtkCssValue *
parse_font_kerning (GtkCssStyleProperty *property,
GtkCssParser *parser)
@@ -909,6 +921,12 @@ _gtk_css_style_property_init_properties (void)
GTK_CSS_AFFECTS_TEXT_ATTRS,
parse_text_decoration_style,
_gtk_css_text_decoration_style_value_new
(GTK_CSS_TEXT_DECORATION_STYLE_SOLID));
+ gtk_css_style_property_register ("text-transform",
+ GTK_CSS_PROPERTY_TEXT_TRANSFORM,
+ 0,
+ GTK_CSS_AFFECTS_TEXT_ATTRS | GTK_CSS_AFFECTS_TEXT_SIZE,
+ parse_text_transform,
+ _gtk_css_text_transform_value_new (GTK_CSS_TEXT_TRANSFORM_NONE));
gtk_css_style_property_register ("font-kerning",
GTK_CSS_PROPERTY_FONT_KERNING,
0,
diff --git a/gtk/gtkcsstypesprivate.h b/gtk/gtkcsstypesprivate.h
index 35ae56a41c..39b21de5fa 100644
--- a/gtk/gtkcsstypesprivate.h
+++ b/gtk/gtkcsstypesprivate.h
@@ -198,6 +198,7 @@ enum { /*< skip >*/
GTK_CSS_PROPERTY_TEXT_DECORATION_LINE,
GTK_CSS_PROPERTY_TEXT_DECORATION_COLOR,
GTK_CSS_PROPERTY_TEXT_DECORATION_STYLE,
+ GTK_CSS_PROPERTY_TEXT_TRANSFORM,
GTK_CSS_PROPERTY_FONT_KERNING,
GTK_CSS_PROPERTY_FONT_VARIANT_LIGATURES,
GTK_CSS_PROPERTY_FONT_VARIANT_POSITION,
@@ -337,6 +338,13 @@ typedef enum /*< skip >*/ {
GTK_CSS_TEXT_DECORATION_STYLE_WAVY
} GtkTextDecorationStyle;
+typedef enum /*< skip >*/ {
+ GTK_CSS_TEXT_TRANSFORM_NONE,
+ GTK_CSS_TEXT_TRANSFORM_LOWERCASE,
+ GTK_CSS_TEXT_TRANSFORM_UPPERCASE,
+ GTK_CSS_TEXT_TRANSFORM_CAPITALIZE,
+} GtkTextTransform;
+
/* for the order in arrays */
typedef enum /*< skip >*/ {
GTK_CSS_TOP,
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]