Commit a19331f2 authored by Paolo Borelli's avatar Paolo Borelli

label: add support for CSS letter-spacing property

Support letter-spacing CSS property on GtkLabel.
Reftest is included.
parent b92c530a
......@@ -610,6 +610,13 @@ bindings_value_assign (GtkCssStyleProperty *property,
return result;
}
static GtkCssValue *
parse_letter_spacing (GtkCssStyleProperty *property,
GtkCssParser *parser)
{
return _gtk_css_number_value_parse (parser, GTK_CSS_PARSE_LENGTH);
}
static GtkCssValue *
box_shadow_value_parse (GtkCssStyleProperty *property,
GtkCssParser *parser)
......@@ -1065,6 +1072,16 @@ _gtk_css_style_property_init_properties (void)
assign_pango_stretch,
_gtk_css_font_stretch_value_new (PANGO_STRETCH_NORMAL));
gtk_css_style_property_register ("letter-spacing",
GTK_CSS_PROPERTY_LETTER_SPACING,
G_TYPE_NONE,
GTK_STYLE_PROPERTY_INHERIT | GTK_STYLE_PROPERTY_ANIMATED,
GTK_CSS_AFFECTS_TEXT | GTK_CSS_AFFECTS_TEXT_ATTRS,
parse_letter_spacing,
NULL,
NULL,
_gtk_css_number_value_new (0.0, GTK_CSS_PX));
gtk_css_style_property_register ("text-shadow",
GTK_CSS_PROPERTY_TEXT_SHADOW,
G_TYPE_NONE,
......
......@@ -78,6 +78,7 @@ typedef enum { /*< skip >*/
* @GTK_CSS_AFFECTS_FONT: The font is affected and should be reloaded
* if it was cached.
* @GTK_CSS_AFFECTS_TEXT: Text rendering is affected.
* @GTK_CSS_AFFECTS_TEXT_ATTRS: Text attributes are affected.
* @GTK_CSS_AFFECTS_ICON: Icons and icon rendering is affected.
* @GTK_CSS_AFFECTS_OUTLINE: The outline styling is affected. Outlines
* only affect elements that can be focused.
......@@ -99,10 +100,11 @@ typedef enum {
GTK_CSS_AFFECTS_BORDER = (1 << 2),
GTK_CSS_AFFECTS_FONT = (1 << 3),
GTK_CSS_AFFECTS_TEXT = (1 << 4),
GTK_CSS_AFFECTS_ICON = (1 << 5),
GTK_CSS_AFFECTS_OUTLINE = (1 << 6),
GTK_CSS_AFFECTS_CLIP = (1 << 7),
GTK_CSS_AFFECTS_SIZE = (1 << 8)
GTK_CSS_AFFECTS_TEXT_ATTRS = (1 << 5),
GTK_CSS_AFFECTS_ICON = (1 << 6),
GTK_CSS_AFFECTS_OUTLINE = (1 << 7),
GTK_CSS_AFFECTS_CLIP = (1 << 8),
GTK_CSS_AFFECTS_SIZE = (1 << 9)
} GtkCssAffects;
enum { /*< skip >*/
......@@ -116,6 +118,7 @@ enum { /*< skip >*/
GTK_CSS_PROPERTY_FONT_VARIANT,
GTK_CSS_PROPERTY_FONT_WEIGHT,
GTK_CSS_PROPERTY_FONT_STRETCH,
GTK_CSS_PROPERTY_LETTER_SPACING,
GTK_CSS_PROPERTY_TEXT_SHADOW,
GTK_CSS_PROPERTY_BOX_SHADOW,
GTK_CSS_PROPERTY_MARGIN_TOP,
......
......@@ -35,6 +35,7 @@
#include "gtkbuilderprivate.h"
#include "gtkclipboard.h"
#include "gtkcssshadowsvalueprivate.h"
#include "gtkcssstylepropertyprivate.h"
#include "gtkdnd.h"
#include "gtkimage.h"
#include "gtkintl.h"
......@@ -3412,6 +3413,7 @@ gtk_label_update_layout_attributes (GtkLabel *label)
GtkWidget *widget = GTK_WIDGET (label);
GtkStyleContext *context;
PangoAttrList *attrs;
PangoAttrList *style_attrs;
if (priv->layout == NULL)
return;
......@@ -3462,6 +3464,17 @@ gtk_label_update_layout_attributes (GtkLabel *label)
else
attrs = NULL;
style_attrs = _gtk_style_context_get_pango_attributes (context);
if (style_attrs)
{
if (attrs)
_gtk_pango_attr_list_merge (attrs, style_attrs);
else
attrs = pango_attr_list_ref (style_attrs);
pango_attr_list_unref (style_attrs);
}
if (priv->markup_attrs)
{
if (attrs)
......@@ -4124,12 +4137,22 @@ gtk_label_state_flags_changed (GtkWidget *widget,
static void
gtk_label_style_updated (GtkWidget *widget)
{
static GtkBitmask *affects_text_attrs = NULL;
GtkLabel *label = GTK_LABEL (widget);
GtkLabelPrivate *priv = label->priv;
GtkStyleContext *context;
const GtkBitmask *changes;;
if (G_UNLIKELY (affects_text_attrs == NULL))
affects_text_attrs = _gtk_css_style_property_get_mask_affecting (GTK_CSS_AFFECTS_TEXT_ATTRS);
GTK_WIDGET_CLASS (gtk_label_parent_class)->style_updated (widget);
if (priv->select_info && priv->select_info->links)
context = gtk_widget_get_style_context (widget);
changes = _gtk_style_context_get_changes (context);
if (changes == NULL || _gtk_bitmask_intersects (changes, affects_text_attrs) ||
(priv->select_info && priv->select_info->links))
gtk_label_update_layout_attributes (label);
}
......
......@@ -3148,6 +3148,26 @@ _gtk_style_context_get_icon_extents (GtkStyleContext *context,
extents->height += border.top + border.bottom;
}
PangoAttrList *
_gtk_style_context_get_pango_attributes (GtkStyleContext *context)
{
gint letter_spacing;
PangoAttrList *attrs = NULL;
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);
}
return attrs;
}
static AtkAttributeSet *
add_attribute (AtkAttributeSet *attributes,
AtkTextAttribute attr,
......
......@@ -64,6 +64,8 @@ void _gtk_style_context_get_icon_extents (GtkStyleContext
gint width,
gint height);
PangoAttrList *_gtk_style_context_get_pango_attributes (GtkStyleContext *context);
/* Accessibility support */
AtkAttributeSet *_gtk_style_context_get_attributes (AtkAttributeSet *attributes,
GtkStyleContext *context,
......
......@@ -323,6 +323,9 @@ testdata = \
label-width-chars-dont-shrink.ui \
label-wrap-justify.ref.ui \
label-wrap-justify.ui \
letter-spacing.css \
letter-spacing.ui \
letter-spacing.ref.ui \
linear-gradient.css \
linear-gradient.ref.ui \
linear-gradient.ui \
......@@ -498,6 +501,7 @@ libreftest_la_LIBADD = $(gtk_reftest_LDADD)
libreftest_la_SOURCES = \
expand-expander.c \
label-text-shadow-changes-modify-clip.c \
letter-spacing.c \
set-default-direction.c \
statusbar-remove-all.c \
textview-border-windows.c \
......
/*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Library General Public
* License as published by the Free Software Foundation; either
* version 2 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Library General Public License for more details.
*
* You should have received a copy of the GNU Library General Public
* License along with this library. If not, see <http://www.gnu.org/licenses/>.
*/
#include "config.h"
#include <gtk/gtk.h>
G_MODULE_EXPORT void
set_letter_spacing (GtkLabel *label)
{
PangoAttrList *attrs;
attrs = pango_attr_list_new ();
pango_attr_list_insert (attrs, pango_attr_letter_spacing_new (10 * PANGO_SCALE));
gtk_label_set_attributes (label, attrs);
pango_attr_list_unref (attrs);
}
#spaced {
letter-spacing: 10px;
}
<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.18.1 -->
<interface>
<requires lib="gtk+" version="3.0"/>
<object class="GtkWindow" id="window1">
<property name="can_focus">False</property>
<property name="type">popup</property>
<child>
<object class="GtkLabel" id="label1">
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label">abc</property>
<signal name="map" handler="reftest:set_letter_spacing" swapped="no"/>
</object>
</child>
</object>
</interface>
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<!-- interface-requires gtk+ 3.0 -->
<object class="GtkWindow" id="window1">
<property name="can_focus">False</property>
<property name="type">popup</property>
<child>
<object class="GtkLabel" id="label1">
<property name="name">spaced</property>
<property name="visible">True</property>
<property name="can_focus">False</property>
<property name="label">abc</property>
</object>
</child>
</object>
</interface>
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