summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2022-01-23 22:06:28 -0500
committerMatthias Clasen <mclasen@redhat.com>2022-01-25 15:29:16 -0500
commitc678041d82237dd07ecf5695ec283ce045b2e3ab (patch)
treecc00d936f2f32ba176f8b2c913153947198d0ab8
parentd2602cc0ee6a0b7abb982e27ccf90b0da98ebedf (diff)
downloadpango-c678041d82237dd07ecf5695ec283ce045b2e3ab.tar.gz
Tweak PangoAlignment
Remove the justify-all value, and drop the justify-last-line feature from PangoLayout. This can be done better using PangoLineBreaker now. On the flip side, add a 'natural' value, since that is what we want to fall back to for the last line in a justified paragraph. And CoreText has this value too. Make PANGO_ALIGN_NATURAL the default.
-rw-r--r--pango/pango-layout.c41
-rw-r--r--pango/pango-types.h11
2 files changed, 34 insertions, 18 deletions
diff --git a/pango/pango-layout.c b/pango/pango-layout.c
index 9671ab61..4d33bb83 100644
--- a/pango/pango-layout.c
+++ b/pango/pango-layout.c
@@ -72,7 +72,7 @@ pango_layout_init (PangoLayout *layout)
layout->height = -1;
layout->indent = 0;
layout->wrap = PANGO_WRAP_WORD;
- layout->alignment = PANGO_ALIGN_LEFT;
+ layout->alignment = PANGO_ALIGN_NATURAL;
layout->ellipsize = PANGO_ELLIPSIZE_NONE;
layout->line_spacing = 0.0;
layout->auto_dir = TRUE;
@@ -409,11 +409,11 @@ pango_layout_class_init (PangoLayoutClass *class)
*
* The alignment mode of this `PangoLayout.
*
- * The default value is `PANGO_ALIGNMENT_LEFT`.
+ * The default value is `PANGO_ALIGN_NATURAL`.
*/
props[PROP_ALIGNMENT] = g_param_spec_enum ("alignment", "alignment", "alignment",
PANGO_TYPE_ALIGNMENT,
- PANGO_ALIGN_LEFT,
+ PANGO_ALIGN_NATURAL,
G_PARAM_READWRITE | G_PARAM_EXPLICIT_NOTIFY);
/**
@@ -603,23 +603,40 @@ retry:
offset = 0;
switch (layout->alignment)
{
+
case PANGO_ALIGN_LEFT:
break;
+
case PANGO_ALIGN_CENTER:
if (ext.width < width)
offset = (width - ext.width) / 2;
break;
+
+ case PANGO_ALIGN_JUSTIFY:
+ if (!pango_layout_line_ends_paragraph (line))
+ {
+ line = pango_layout_line_justify (line, width);
+ break;
+ }
+ G_GNUC_FALLTHROUGH;
+
+ case PANGO_ALIGN_NATURAL:
+ {
+ PangoLayoutLine *first_line;
+ if (pango_lines_get_line_count (layout->lines) > 0)
+ first_line = pango_lines_get_line (layout->lines, 0, NULL, NULL);
+ else
+ first_line = line;
+ if (pango_layout_line_get_resolved_direction (first_line) == PANGO_DIRECTION_LTR)
+ break;
+ }
+ G_GNUC_FALLTHROUGH;
+
case PANGO_ALIGN_RIGHT:
if (ext.width < width)
offset = width - ext.width;
break;
- case PANGO_ALIGN_JUSTIFY:
- if (!pango_layout_line_ends_paragraph (line))
- line = pango_layout_line_justify (line, width);
- break;
- case PANGO_ALIGN_JUSTIFY_ALL:
- line = pango_layout_line_justify (line, width);
- break;
+
default: g_assert_not_reached ();
}
@@ -1278,7 +1295,7 @@ pango_layout_get_indent (PangoLayout *layout)
* Sets the alignment for the layout: how short lines are
* positioned within the horizontal space available.
*
- * The default alignment is `PANGO_ALIGN_LEFT`.
+ * The default alignment is `PANGO_ALIGN_NATURAL`.
*/
void
pango_layout_set_alignment (PangoLayout *layout,
@@ -1307,7 +1324,7 @@ pango_layout_set_alignment (PangoLayout *layout,
PangoAlignment
pango_layout_get_alignment (PangoLayout *layout)
{
- g_return_val_if_fail (PANGO_IS_LAYOUT (layout), PANGO_ALIGN_LEFT);
+ g_return_val_if_fail (PANGO_IS_LAYOUT (layout), PANGO_ALIGN_NATURAL);
return layout->alignment;
}
diff --git a/pango/pango-types.h b/pango/pango-types.h
index 9643245e..82892928 100644
--- a/pango/pango-types.h
+++ b/pango/pango-types.h
@@ -245,10 +245,9 @@ void pango_extents_to_pixels (PangoRectangle *inclusive,
* @PANGO_ALIGN_LEFT: Put all available space on the right
* @PANGO_ALIGN_CENTER: Center the line within the available space
* @PANGO_ALIGN_RIGHT: Put all available space on the left
- * @PANGO_ALIGN_JUSTIFY: Justify the content to fill the available
- * space, unless the line ends the paragraph
- * @PANGO_ALIGN_JUSTIFY_ALL: Justify the content to fill the available
- * space, even if the line ends the paragraph
+ * @PANGO_ALIGN_NATURAL: Use left or right alignment, depending
+ * on the text direction of the paragraph
+ * @PANGO_ALIGN_JUSTIFY: Justify the content to fill the available space
*
* `PangoAlignment` describes how to align the lines of a `PangoLayout`
* within the available space.
@@ -258,8 +257,8 @@ typedef enum
PANGO_ALIGN_LEFT,
PANGO_ALIGN_CENTER,
PANGO_ALIGN_RIGHT,
- PANGO_ALIGN_JUSTIFY,
- PANGO_ALIGN_JUSTIFY_ALL,
+ PANGO_ALIGN_NATURAL,
+ PANGO_ALIGN_JUSTIFY
} PangoAlignment;
/**