[gtk/line-spacing: 2/2] textview: Add a line-spacing property
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk/line-spacing: 2/2] textview: Add a line-spacing property
- Date: Fri, 6 Aug 2021 02:23:49 +0000 (UTC)
commit 9fedf63c9c41393e7f5b77af1329a731c960fb8b
Author: Matthias Clasen <mclasen redhat com>
Date: Thu Aug 5 22:22:50 2021 -0400
textview: Add a line-spacing property
This exposes a line-spacing property that corresponds
to the PangoLayout property of the same name.
gtk/gtktextattributes.c | 4 +++
gtk/gtktextattributes.h | 2 ++
gtk/gtktexttag.c | 30 +++++++++++++++++
gtk/gtktexttagprivate.h | 1 +
gtk/gtktextview.c | 87 ++++++++++++++++++++++++++++++++++++++++++++++++-
gtk/gtktextview.h | 6 ++++
6 files changed, 129 insertions(+), 1 deletion(-)
---
diff --git a/gtk/gtktextattributes.c b/gtk/gtktextattributes.c
index 738caa6bc1..becbad4202 100644
--- a/gtk/gtktextattributes.c
+++ b/gtk/gtktextattributes.c
@@ -387,6 +387,9 @@ _gtk_text_attributes_fill_from_tags (GtkTextAttributes *dest,
if (tag->priv->pixels_inside_wrap_set)
dest->pixels_inside_wrap = vals->pixels_inside_wrap;
+ if (tag->priv->line_spacing_set)
+ dest->line_spacing = vals->line_spacing;
+
if (tag->priv->tabs_set)
{
if (dest->tabs)
@@ -457,6 +460,7 @@ _gtk_text_tag_affects_size (GtkTextTag *tag)
priv->pixels_above_lines_set ||
priv->pixels_below_lines_set ||
priv->pixels_inside_wrap_set ||
+ priv->line_spacing_set ||
priv->tabs_set ||
priv->underline_set ||
priv->overline_set ||
diff --git a/gtk/gtktextattributes.h b/gtk/gtktextattributes.h
index 05f7750247..479b961b3a 100644
--- a/gtk/gtktextattributes.h
+++ b/gtk/gtktextattributes.h
@@ -147,6 +147,8 @@ struct _GtkTextAttributes
int pixels_below_lines;
int pixels_inside_wrap;
+ float line_spacing;
+
int letter_spacing;
guint invisible : 1;
diff --git a/gtk/gtktexttag.c b/gtk/gtktexttag.c
index fdf17a6efc..273f8c0c78 100644
--- a/gtk/gtktexttag.c
+++ b/gtk/gtktexttag.c
@@ -107,6 +107,7 @@ enum {
PROP_PIXELS_ABOVE_LINES,
PROP_PIXELS_BELOW_LINES,
PROP_PIXELS_INSIDE_WRAP,
+ PROP_LINE_SPACING,
PROP_EDITABLE,
PROP_WRAP_MODE,
PROP_JUSTIFICATION,
@@ -150,6 +151,7 @@ enum {
PROP_PIXELS_ABOVE_LINES_SET,
PROP_PIXELS_BELOW_LINES_SET,
PROP_PIXELS_INSIDE_WRAP_SET,
+ PROP_LINE_SPACING_SET,
PROP_EDITABLE_SET,
PROP_WRAP_MODE_SET,
PROP_JUSTIFICATION_SET,
@@ -585,6 +587,8 @@ gtk_text_tag_class_init (GtkTextTagClass *klass)
* GtkTextTag:pixels-inside-wrap:
*
* Pixels of blank space between wrapped lines in a paragraph.
+ *
+ * Ignored if line-spacing is set.
*/
g_object_class_install_property (object_class,
PROP_PIXELS_INSIDE_WRAP,
@@ -596,6 +600,21 @@ gtk_text_tag_class_init (GtkTextTagClass *klass)
0,
GTK_PARAM_READWRITE));
+ /**
+ * GtkTextag:line-spacing:
+ *
+ * The line spacing factor that is applied between consecutive lines.
+ *
+ * Since: 4.4
+ */
+ g_object_class_install_property (object_class,
+ PROP_LINE_SPACING,
+ g_param_spec_float ("line-spacing",
+ P_("Linespacing"),
+ P_("The factor for spacing between lines"),
+ 0.0, 10.0, 0.0,
+ GTK_PARAM_READWRITE));
+
/**
* GtkTextTag:strikethrough:
*
@@ -936,6 +955,10 @@ gtk_text_tag_class_init (GtkTextTagClass *klass)
P_("Pixels inside wrap set"),
P_("Whether this tag affects the number of pixels between wrapped lines"));
+ ADD_SET_PROP ("line-spacing-set", PROP_LINE_SPACING_SET,
+ P_("Linespacing set"),
+ P_("Whether this tag affects spacing between wrapped lines"));
+
ADD_SET_PROP ("strikethrough-set", PROP_STRIKETHROUGH_SET,
P_("Strikethrough set"),
P_("Whether this tag affects strikethrough"));
@@ -1573,6 +1596,13 @@ gtk_text_tag_set_property (GObject *object,
size_changed = TRUE;
break;
+ case PROP_LINE_SPACING:
+ priv->line_spacing_set = TRUE;
+ priv->values->line_spacing = g_value_get_float (value);
+ g_object_notify (object, "line-spacing-set");
+ size_changed = TRUE;
+ break;
+
case PROP_EDITABLE:
priv->editable_set = TRUE;
priv->values->editable = g_value_get_boolean (value);
diff --git a/gtk/gtktexttagprivate.h b/gtk/gtktexttagprivate.h
index b0bd079532..f78eba76f0 100644
--- a/gtk/gtktexttagprivate.h
+++ b/gtk/gtktexttagprivate.h
@@ -71,6 +71,7 @@ struct _GtkTextTagPrivate
guint pixels_above_lines_set : 1;
guint pixels_below_lines_set : 1;
guint pixels_inside_wrap_set : 1;
+ guint line_spacing_set : 1;
guint tabs_set : 1;
guint underline_set : 1;
guint overline_set : 1;
diff --git a/gtk/gtktextview.c b/gtk/gtktextview.c
index d6673bed62..768ab2245e 100644
--- a/gtk/gtktextview.c
+++ b/gtk/gtktextview.c
@@ -173,6 +173,8 @@ struct _GtkTextViewPrivate
GtkWidget *selection_bubble;
guint selection_bubble_timeout_id;
+ float line_spacing;
+
GtkWidget *magnifier_popover;
GtkWidget *magnifier;
@@ -359,7 +361,8 @@ enum
PROP_INPUT_PURPOSE,
PROP_INPUT_HINTS,
PROP_MONOSPACE,
- PROP_EXTRA_MENU
+ PROP_EXTRA_MENU,
+ PROP_LINE_SPACING
};
static GQuark quark_text_selection_data = 0;
@@ -1153,6 +1156,21 @@ gtk_text_view_class_init (GtkTextViewClass *klass)
G_TYPE_MENU_MODEL,
GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY));
+ /**
+ * GtkTextView:line-spacing: (attributes org.gtk.Property.get=gtk_text_view_get_line_spacing
org.gtk.Property.set=gtk_text_view_set_line_spacing)
+ *
+ * The line spacing factor that is applied between consecutive lines.
+ *
+ * Since: 4.4
+ */
+ g_object_class_install_property (gobject_class,
+ PROP_LINE_SPACING,
+ g_param_spec_float ("line-spacing",
+ P_("Linespacing"),
+ P_("The factor for spacing between lines"),
+ 0.0, 10.0, 0.0,
+ GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY));
+
/* GtkScrollable interface */
g_object_class_override_property (gobject_class, PROP_HADJUSTMENT, "hadjustment");
g_object_class_override_property (gobject_class, PROP_VADJUSTMENT, "vadjustment");
@@ -3390,6 +3408,65 @@ gtk_text_view_get_pixels_inside_wrap (GtkTextView *text_view)
return text_view->priv->pixels_inside_wrap;
}
+/**
+ * gtk_text_view_set_line_spacing: (attributes org.gtk.Method.set_property=line-spacing)
+ * @self: a `GtkTextView`
+ * @factor: the new line spacing factor
+ *
+ * Sets the default factor for line spacing.
+ *
+ * Typical values are: 0, 1, 1.5, 2. The default values is 0.
+ *
+ * If @factor is non-zero, lines are placed so that
+ *
+ * baseline2 = baseline1 + factor * height2
+ *
+ * where height2 is the line height of the second line
+ * (as determined by the font(s)).
+ *
+ * If @factor is zero (the default), the pixels-inside-wrap value
+ * is used.
+ *
+ * Since: 4.4
+ */
+void
+gtk_text_view_set_line_spacing (GtkTextView *text_view,
+ float line_spacing)
+{
+ GtkTextViewPrivate *priv = text_view->priv;
+
+ g_return_if_fail (GTK_IS_TEXT_VIEW (text_view));
+
+ if (priv->line_spacing == line_spacing)
+ return;
+
+ priv->line_spacing = line_spacing;
+
+ if (priv->layout && priv->layout->default_style)
+ {
+ priv->layout->default_style->line_spacing = line_spacing;
+ gtk_text_layout_default_style_changed (priv->layout);
+ }
+
+ g_object_notify (G_OBJECT (text_view), "line-spacing");
+}
+
+/**
+ * gtk_text_view_get_line_spacing: (attributes org.gtk.Method.get_property=line-spacing)
+ * @self: a `GtkTextView`
+ *
+ * Gets the default line spacing factor of @text_view.
+ *
+ * Since: 4.4
+ */
+float
+gtk_text_view_get_line_spacing (GtkTextView *text_view)
+{
+ g_return_val_if_fail (GTK_IS_TEXT_VIEW (text_view), 0.0);
+
+ return text_view->priv->line_spacing;
+}
+
/**
* gtk_text_view_set_justification: (attributes org.gtk.Method.set_property=justification)
* @text_view: a `GtkTextView`
@@ -4105,6 +4182,10 @@ gtk_text_view_set_property (GObject *object,
gtk_text_view_set_extra_menu (text_view, g_value_get_object (value));
break;
+ case PROP_LINE_SPACING:
+ gtk_text_view_set_line_spacing (text_view, g_value_get_float (value));
+ break;
+
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -4225,6 +4306,10 @@ gtk_text_view_get_property (GObject *object,
g_value_set_object (value, gtk_text_view_get_extra_menu (text_view));
break;
+ case PROP_LINE_SPACING:
+ g_value_set_float (value, gtk_text_view_get_line_spacing (text_view));
+ break;
+
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
diff --git a/gtk/gtktextview.h b/gtk/gtktextview.h
index 325077a871..496ca09a2b 100644
--- a/gtk/gtktextview.h
+++ b/gtk/gtktextview.h
@@ -432,6 +432,12 @@ PangoContext *gtk_text_view_get_rtl_context (GtkTextView *text_vi
GDK_AVAILABLE_IN_ALL
PangoContext *gtk_text_view_get_ltr_context (GtkTextView *text_view);
+GDK_AVAILABLE_IN_4_4
+void gtk_text_view_set_line_spacing (GtkTextView *text_view,
+ float factor);
+GDK_AVAILABLE_IN_4_4
+float gtk_text_view_get_line_spacing (GtkTextView *text_view);
+
G_END_DECLS
#endif /* __GTK_TEXT_VIEW_H__ */
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]