[gtk/css-line-height: 1/4] css: Add line-height property




commit 8eb82da896db5eb58bf1cf5c9ddcd6dfed72896a
Author: Matthias Clasen <mclasen redhat com>
Date:   Fri Aug 6 14:19:34 2021 -0400

    css: Add line-height property
    
    This adds the plumbing to parse the line-height
    property from CSS. Widgets are not picking it
    up yet.

 gtk/gtkcssanimatedstyle.c     |  4 ++++
 gtk/gtkcssstaticstyle.c       |  6 +++++-
 gtk/gtkcssstyle.c             |  2 ++
 gtk/gtkcssstyle.h             |  0
 gtk/gtkcssstyleprivate.h      |  1 +
 gtk/gtkcssstylepropertyimpl.c | 25 +++++++++++++++++++++++++
 gtk/gtkcsstypesprivate.h      |  1 +
 7 files changed, 38 insertions(+), 1 deletion(-)
---
diff --git a/gtk/gtkcssanimatedstyle.c b/gtk/gtkcssanimatedstyle.c
index 52e0cabc3b..eb62780360 100644
--- a/gtk/gtkcssanimatedstyle.c
+++ b/gtk/gtkcssanimatedstyle.c
@@ -204,6 +204,10 @@ gtk_css_animated_style_set_animated_value (GtkCssAnimatedStyle *animated,
       unshare_font (animated);
       gtk_css_take_value (&style->font->letter_spacing, value);
       break;
+    case GTK_CSS_PROPERTY_LINE_HEIGHT:
+      unshare_font (animated);
+      gtk_css_take_value (&style->font->line_height, value);
+      break;
     case GTK_CSS_PROPERTY_TEXT_DECORATION_LINE:
       unshare_font_variant (animated);
       gtk_css_take_value (&style->font_variant->text_decoration_line, value);
diff --git a/gtk/gtkcssstaticstyle.c b/gtk/gtkcssstaticstyle.c
index 1c8dd80c56..ad906431d8 100644
--- a/gtk/gtkcssstaticstyle.c
+++ b/gtk/gtkcssstaticstyle.c
@@ -107,11 +107,12 @@ static const int font_props[] = {
   GTK_CSS_PROPERTY_FONT_WEIGHT,
   GTK_CSS_PROPERTY_FONT_STRETCH,
   GTK_CSS_PROPERTY_LETTER_SPACING,
-  GTK_CSS_PROPERTY_TEXT_SHADOW,  
+  GTK_CSS_PROPERTY_TEXT_SHADOW,
   GTK_CSS_PROPERTY_CARET_COLOR,
   GTK_CSS_PROPERTY_SECONDARY_CARET_COLOR,
   GTK_CSS_PROPERTY_FONT_FEATURE_SETTINGS,
   GTK_CSS_PROPERTY_FONT_VARIATION_SETTINGS,
+  GTK_CSS_PROPERTY_LINE_HEIGHT,
 };
 static const int font_variant_props[] = {
   GTK_CSS_PROPERTY_TEXT_DECORATION_LINE,
@@ -417,6 +418,9 @@ gtk_css_static_style_set_value (GtkCssStaticStyle *sstyle,
     case GTK_CSS_PROPERTY_LETTER_SPACING:
       gtk_css_take_value (&style->font->letter_spacing, value);
       break;
+    case GTK_CSS_PROPERTY_LINE_HEIGHT:
+      gtk_css_take_value (&style->font->line_height, value);
+      break;
     case GTK_CSS_PROPERTY_TEXT_DECORATION_LINE:
       gtk_css_take_value (&style->font_variant->text_decoration_line, value);
       break;
diff --git a/gtk/gtkcssstyle.c b/gtk/gtkcssstyle.c
index 0f890a005d..54aa0e7d23 100644
--- a/gtk/gtkcssstyle.c
+++ b/gtk/gtkcssstyle.c
@@ -117,6 +117,8 @@ gtk_css_style_get_value (GtkCssStyle *style,
       return style->font->font_stretch;
     case GTK_CSS_PROPERTY_LETTER_SPACING:
       return style->font->letter_spacing;
+    case GTK_CSS_PROPERTY_LINE_HEIGHT:
+      return style->font->line_height;
     case GTK_CSS_PROPERTY_TEXT_DECORATION_LINE:
       return style->font_variant->text_decoration_line;
     case GTK_CSS_PROPERTY_TEXT_DECORATION_COLOR:
diff --git a/gtk/gtkcssstyle.h b/gtk/gtkcssstyle.h
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/gtk/gtkcssstyleprivate.h b/gtk/gtkcssstyleprivate.h
index 27666e9978..5a78d3d962 100644
--- a/gtk/gtkcssstyleprivate.h
+++ b/gtk/gtkcssstyleprivate.h
@@ -151,6 +151,7 @@ struct _GtkCssFontValues {
   GtkCssValue *secondary_caret_color; // NULL if currentColor
   GtkCssValue *font_feature_settings;
   GtkCssValue *font_variation_settings;
+  GtkCssValue *line_height;
 };
 
 struct _GtkCssFontVariantValues {
diff --git a/gtk/gtkcssstylepropertyimpl.c b/gtk/gtkcssstylepropertyimpl.c
index 6df32116a8..fbe9cb8c30 100644
--- a/gtk/gtkcssstylepropertyimpl.c
+++ b/gtk/gtkcssstylepropertyimpl.c
@@ -812,6 +812,25 @@ transform_origin_parse (GtkCssStyleProperty *property,
   return _gtk_css_position_value_parse (parser);
 }
 
+static GtkCssValue *
+parse_line_height (GtkCssStyleProperty *property,
+                   GtkCssParser        *parser)
+{
+  GtkCssValue *value = NULL;
+
+  if (gtk_css_parser_try_ident (parser, "normal"))
+    value = _gtk_css_ident_value_new ("normal");
+  else
+    value = _gtk_css_number_value_parse (parser, GTK_CSS_PARSE_NUMBER |
+                                                 GTK_CSS_PARSE_PERCENT |
+                                                 GTK_CSS_POSITIVE_ONLY);
+
+  if (value == NULL)
+    gtk_css_parser_error_syntax (parser, "Not a valid line-height value");
+
+  return value;
+}
+
 /*** REGISTRATION ***/
 
 G_STATIC_ASSERT (GTK_CSS_PROPERTY_COLOR == 0);
@@ -1401,4 +1420,10 @@ _gtk_css_style_property_init_properties (void)
                                           GTK_CSS_AFFECTS_TEXT_ATTRS | GTK_CSS_AFFECTS_TEXT_SIZE,
                                           parse_font_variation_settings,
                                           gtk_css_font_variations_value_new_default ());
+  gtk_css_style_property_register        ("line-height",
+                                          GTK_CSS_PROPERTY_LINE_HEIGHT,
+                                          GTK_STYLE_PROPERTY_INHERIT | GTK_STYLE_PROPERTY_ANIMATED,
+                                          GTK_CSS_AFFECTS_TEXT_SIZE,
+                                          parse_line_height,
+                                          _gtk_css_ident_value_new ("normal"));
 }
diff --git a/gtk/gtkcsstypesprivate.h b/gtk/gtkcsstypesprivate.h
index 35ae56a41c..1a2320a6bb 100644
--- a/gtk/gtkcsstypesprivate.h
+++ b/gtk/gtkcsstypesprivate.h
@@ -275,6 +275,7 @@ enum { /*< skip >*/
   GTK_CSS_PROPERTY_SECONDARY_CARET_COLOR,
   GTK_CSS_PROPERTY_FONT_FEATURE_SETTINGS,
   GTK_CSS_PROPERTY_FONT_VARIATION_SETTINGS,
+  GTK_CSS_PROPERTY_LINE_HEIGHT,
   /* add more */
   GTK_CSS_PROPERTY_N_PROPERTIES
 };


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]