[gtk/css-line-height2: 2/5] css: Add line-height property




commit 6e31d6479ad57b6f639d49623120e71f626e78eb
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/gtkcssenumvalue.c         | 19 +++++++++++++++++++
 gtk/gtkcssenumvalueprivate.h  |  2 ++
 gtk/gtkcssstaticstyle.c       |  6 +++++-
 gtk/gtkcssstyle.c             |  2 ++
 gtk/gtkcssstyle.h             |  0
 gtk/gtkcssstyleprivate.h      |  1 +
 gtk/gtkcssstylepropertyimpl.c | 18 ++++++++++++++++++
 gtk/gtkcsstypesprivate.h      |  1 +
 9 files changed, 52 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/gtkcssenumvalue.c b/gtk/gtkcssenumvalue.c
index ce96a23e0c..f87a7e7746 100644
--- a/gtk/gtkcssenumvalue.c
+++ b/gtk/gtkcssenumvalue.c
@@ -1568,3 +1568,22 @@ _gtk_css_font_variant_east_asian_value_get (const GtkCssValue *value)
 
   return value->value;
 }
+
+static const GtkCssValueClass GTK_CSS_VALUE_LINE_HEIGHT = {
+  "GtkCssLineHeightValue",
+  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 normal_line_height = { &GTK_CSS_VALUE_LINE_HEIGHT, 1, TRUE, 0, "normal" };
+
+GtkCssValue *
+gtk_css_line_height_value_get (void)
+{
+  return &normal_line_height;
+}
diff --git a/gtk/gtkcssenumvalueprivate.h b/gtk/gtkcssenumvalueprivate.h
index a102a8650b..a4378fd3c8 100644
--- a/gtk/gtkcssenumvalueprivate.h
+++ b/gtk/gtkcssenumvalueprivate.h
@@ -115,6 +115,8 @@ 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_line_height_value_get (void);
+
 G_END_DECLS
 
 #endif /* __GTK_CSS_ENUM_VALUE_PRIVATE_H__ */
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..e757bde49f 100644
--- a/gtk/gtkcssstylepropertyimpl.c
+++ b/gtk/gtkcssstylepropertyimpl.c
@@ -812,6 +812,18 @@ transform_origin_parse (GtkCssStyleProperty *property,
   return _gtk_css_position_value_parse (parser);
 }
 
+static GtkCssValue *
+parse_line_height (GtkCssStyleProperty *property,
+                   GtkCssParser        *parser)
+{
+  if (gtk_css_parser_try_ident (parser, "normal"))
+    return gtk_css_line_height_value_get ();
+  else
+    return _gtk_css_number_value_parse (parser, GTK_CSS_PARSE_NUMBER |
+                                                 GTK_CSS_PARSE_PERCENT |
+                                                 GTK_CSS_POSITIVE_ONLY);
+}
+
 /*** REGISTRATION ***/
 
 G_STATIC_ASSERT (GTK_CSS_PROPERTY_COLOR == 0);
@@ -1401,4 +1413,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_ATTRS | GTK_CSS_AFFECTS_TEXT_SIZE,
+                                          parse_line_height,
+                                          _gtk_css_value_ref (gtk_css_line_height_value_get ()));
 }
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]