Compare commits

...

2 Commits

Author SHA1 Message Date
Matthias Clasen
9fedf63c9c textview: Add a line-spacing property
This exposes a line-spacing property that corresponds
to the PangoLayout property of the same name.
2021-08-05 22:22:50 -04:00
Matthias Clasen
d1213c6e66 label: Add a line-spacing property
This exposes a line-spacing property that corresponds
to the PangoLayout property of the same name.
2021-08-05 22:22:21 -04:00
8 changed files with 212 additions and 1 deletions

View File

@@ -264,6 +264,7 @@ struct _GtkLabel
float xalign;
float yalign;
float line_spacing;
guint mnemonics_visible : 1;
guint jtype : 2;
@@ -391,6 +392,7 @@ enum {
PROP_XALIGN,
PROP_YALIGN,
PROP_EXTRA_MENU,
PROP_LINE_SPACING,
NUM_PROPERTIES
};
@@ -514,6 +516,9 @@ gtk_label_set_property (GObject *object,
case PROP_EXTRA_MENU:
gtk_label_set_extra_menu (self, g_value_get_object (value));
break;
case PROP_LINE_SPACING:
gtk_label_set_line_spacing (self, g_value_get_float (value));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -584,6 +589,9 @@ gtk_label_get_property (GObject *object,
case PROP_EXTRA_MENU:
g_value_set_object (value, gtk_label_get_extra_menu (self));
break;
case PROP_LINE_SPACING:
g_value_set_float (value, gtk_label_get_line_spacing (self));
break;
default:
G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
break;
@@ -600,6 +608,7 @@ gtk_label_init (GtkLabel *self)
self->xalign = 0.5;
self->yalign = 0.5;
self->line_spacing = 0.0;
self->jtype = GTK_JUSTIFY_LEFT;
self->wrap = FALSE;
@@ -2457,6 +2466,20 @@ gtk_label_class_init (GtkLabelClass *class)
G_TYPE_MENU_MODEL,
GTK_PARAM_READWRITE|G_PARAM_EXPLICIT_NOTIFY);
/**
* GtkLabel:line-spacing: (attributes org.gtk.Property.get=gtk_label_get_line_spacing org.gtk.Property.set=gtk_label_set_line_spacing)
*
* The line spacing factor that is applied between consecutive lines.
*
* Since: 4.4
*/
label_props[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);
g_object_class_install_properties (gobject_class, NUM_PROPERTIES, label_props);
/**
@@ -4005,6 +4028,7 @@ gtk_label_ensure_layout (GtkLabel *self)
pango_layout_set_alignment (self->layout, align);
pango_layout_set_ellipsize (self->layout, self->ellipsize);
pango_layout_set_wrap (self->layout, self->wrap_mode);
pango_layout_set_line_spacing (self->layout, self->line_spacing);
pango_layout_set_single_paragraph_mode (self->layout, self->single_line_mode);
if (self->lines > 0)
pango_layout_set_height (self->layout, - self->lines);
@@ -5778,3 +5802,56 @@ gtk_label_get_extra_menu (GtkLabel *self)
return self->extra_menu;
}
/**
* gtk_label_set_line_spacing: (attributes org.gtk.Method.set_property=line-spacing)
* @self: a `GtkLabel`
* @factor: the new line spacing factor
*
* Sets a 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), no spacing is applied.
*
* Since: 4.4
*/
void
gtk_label_set_line_spacing (GtkLabel *self,
float factor)
{
g_return_if_fail (GTK_IS_LABEL (self));
if (self->line_spacing == factor)
return;
self->line_spacing = factor;
gtk_label_clear_layout (self);
gtk_widget_queue_resize (GTK_WIDGET (self));
g_object_notify_by_pspec (G_OBJECT (self), label_props[PROP_LINE_SPACING]);
}
/**
* gtk_label_get_line_spacing: (attributes org.gtk.Method.get_property=line-spacing)
* @self: a `GtkLabel`
*
* Gets the line spacing factor of @self.
*
* Since: 4.4
*/
float
gtk_label_get_line_spacing (GtkLabel *self)
{
g_return_val_if_fail (GTK_IS_LABEL (self), 0.0);
return self->line_spacing;
}

View File

@@ -172,6 +172,12 @@ void gtk_label_set_extra_menu (GtkLabel *self,
GDK_AVAILABLE_IN_ALL
GMenuModel * gtk_label_get_extra_menu (GtkLabel *self);
GDK_AVAILABLE_IN_4_4
void gtk_label_set_line_spacing (GtkLabel *self,
float factor);
GDK_AVAILABLE_IN_4_4
float gtk_label_get_line_spacing (GtkLabel *self);
G_DEFINE_AUTOPTR_CLEANUP_FUNC(GtkLabel, g_object_unref)

View File

@@ -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 ||

View File

@@ -147,6 +147,8 @@ struct _GtkTextAttributes
int pixels_below_lines;
int pixels_inside_wrap;
float line_spacing;
int letter_spacing;
guint invisible : 1;

View File

@@ -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);

View File

@@ -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;

View File

@@ -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;

View File

@@ -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__ */