Commit e0584a4b authored by Matthias Clasen's avatar Matthias Clasen
Browse files

Add pango_justify_last_line

Add a way to justify the last line in a justified
paragraph.

Fixes: #74
parent 770fd4d4
......@@ -58,6 +58,7 @@ struct _PangoLayout
float line_spacing; /* factor to apply to line height */
guint justify : 1;
guint justify_last_line : 1;
guint alignment : 2;
guint single_paragraph : 1;
guint auto_dir : 1;
......
......@@ -214,6 +214,7 @@ pango_layout_init (PangoLayout *layout)
layout->alignment = PANGO_ALIGN_LEFT;
layout->justify = FALSE;
layout->justify_last_line = FALSE;
layout->auto_dir = TRUE;
layout->single_paragraph = FALSE;
......@@ -805,6 +806,8 @@ pango_layout_get_font_description (PangoLayout *layout)
* Note that this setting is not implemented and so is ignored in
* Pango older than 1.18.
*
* Also see [method@Pango.Layout.set_justify_last_line].
*
* The default value is %FALSE.
*/
void
......@@ -817,7 +820,9 @@ pango_layout_set_justify (PangoLayout *layout,
{
layout->justify = justify;
if (layout->is_ellipsized || layout->is_wrapped)
if (layout->is_ellipsized ||
layout->is_wrapped ||
layout->justify_last_line)
layout_changed (layout);
}
}
......@@ -838,6 +843,54 @@ pango_layout_get_justify (PangoLayout *layout)
return layout->justify;
}
/**
* pango_layout_set_justify_last_line:
* @layout: a `PangoLayout`
* @justify: whether the last line in the layout should be justified
*
* Sets whether the last line should be stretched to fill the
* entire width of the layout.
*
* This only has an effect if [method@Pango.Layout.set_justify] has
* been called as well.
*
* The default value is %FALSE.
*
* Since: 1.50
*/
void
pango_layout_set_justify_last_line (PangoLayout *layout,
gboolean justify)
{
g_return_if_fail (layout != NULL);
if (justify != layout->justify_last_line)
{
layout->justify_last_line = justify;
if (layout->justify)
layout_changed (layout);
}
}
/**
* pango_layout_get_justify_last_line:
* @layout: a `PangoLayout`
*
* Gets whether the last line should be stretched
* to fill the entire width of the layout.
*
* Return value: the justify value
*
* Since: 1.50
*/
gboolean
pango_layout_get_justify_last_line (PangoLayout *layout)
{
g_return_val_if_fail (layout != NULL, FALSE);
return layout->justify_last_line;
}
/**
* pango_layout_set_auto_dir:
* @layout: a `PangoLayout`
......@@ -6055,7 +6108,7 @@ pango_layout_line_postprocess (PangoLayoutLine *line,
/* Distribute extra space between words if justifying and line was wrapped
*/
if (line->layout->justify && (wrapped || ellipsized))
if (line->layout->justify && (wrapped || ellipsized || line->layout->justify_last_line))
{
/* if we ellipsized, we don't have remaining_width set */
if (state->remaining_width < 0)
......
......@@ -223,9 +223,14 @@ PANGO_AVAILABLE_IN_1_44
float pango_layout_get_line_spacing (PangoLayout *layout);
PANGO_AVAILABLE_IN_ALL
void pango_layout_set_justify (PangoLayout *layout,
gboolean justify);
gboolean justify);
PANGO_AVAILABLE_IN_ALL
gboolean pango_layout_get_justify (PangoLayout *layout);
PANGO_AVAILABLE_IN_1_50
void pango_layout_set_justify_last_line (PangoLayout *layout,
gboolean justify);
PANGO_AVAILABLE_IN_1_50
gboolean pango_layout_get_justify_last_line (PangoLayout *layout);
PANGO_AVAILABLE_IN_1_4
void pango_layout_set_auto_dir (PangoLayout *layout,
gboolean auto_dir);
......
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