[pango/pango2: 90/201] Tweak PangoAlignment
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pango/pango2: 90/201] Tweak PangoAlignment
- Date: Sat, 11 Jun 2022 02:22:29 +0000 (UTC)
commit b8aa8519369febccb8d9ed9a00eba7354bfce3d5
Author: Matthias Clasen <mclasen redhat com>
Date: Sun Jun 5 23:39:30 2022 -0400
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.
pango/pango-layout.c | 44 +++++++++++++++++++++++++++++++-------------
pango/pango-types.h | 11 +++++------
pango/serializer.c | 4 ++--
tests/testserialize.c | 2 +-
4 files changed, 39 insertions(+), 22 deletions(-)
---
diff --git a/pango/pango-layout.c b/pango/pango-layout.c
index 817c1306..ced0e9c1 100644
--- a/pango/pango-layout.c
+++ b/pango/pango-layout.c
@@ -120,7 +120,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;
@@ -457,11 +457,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);
/**
@@ -651,24 +651,42 @@ 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_line_is_paragraph_end (line))
+ {
+ line = pango_line_justify (line, width);
+ break;
+ }
+ G_GNUC_FALLTHROUGH;
+
+ case PANGO_ALIGN_NATURAL:
+ {
+ PangoLine *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_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_line_is_paragraph_end (line))
- line = pango_line_justify (line, width);
- break;
- case PANGO_ALIGN_JUSTIFY_ALL:
- line = pango_line_justify (line, width);
- break;
- default: g_assert_not_reached ();
+
+ default:
+ g_assert_not_reached ();
}
pango_lines_add_line (layout->lines, line, x + offset, y - ext.y);
@@ -1333,7 +1351,7 @@ pango_layout_get_indent (PangoLayout *layout)
* The alignment determines how short lines are
* positioned within the available horizontal space.
*
- * The default alignment is `PANGO_ALIGN_LEFT`.
+ * The default alignment is `PANGO_ALIGN_NATURAL`.
*/
void
pango_layout_set_alignment (PangoLayout *layout,
@@ -1364,7 +1382,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 ff21144d..b75f6fc3 100644
--- a/pango/pango-types.h
+++ b/pango/pango-types.h
@@ -246,10 +246,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.
@@ -259,8 +258,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;
/**
diff --git a/pango/serializer.c b/pango/serializer.c
index cfc9931d..b8e19543 100644
--- a/pango/serializer.c
+++ b/pango/serializer.c
@@ -244,8 +244,8 @@ static const char *alignment_names[] = {
"left",
"center",
"right",
+ "natural",
"justify",
- "justify-all",
NULL
};
@@ -806,7 +806,7 @@ layout_to_json (GtkJsonPrinter *printer,
if (!pango_layout_get_auto_dir (layout))
gtk_json_printer_add_boolean (printer, "auto-dir", FALSE);
- if (pango_layout_get_alignment (layout) != PANGO_ALIGN_LEFT)
+ if (pango_layout_get_alignment (layout) != PANGO_ALIGN_NATURAL)
gtk_json_printer_add_string (printer, "alignment", alignment_names[pango_layout_get_alignment (layout)]);
if (pango_layout_get_wrap (layout) != PANGO_WRAP_WORD)
diff --git a/tests/testserialize.c b/tests/testserialize.c
index dabcf798..0219d91a 100644
--- a/tests/testserialize.c
+++ b/tests/testserialize.c
@@ -205,7 +205,7 @@ test_serialize_layout_minimal (void)
g_assert_null (pango_layout_get_attributes (layout));
g_assert_null (pango_layout_get_tabs (layout));
g_assert_null (pango_layout_get_font_description (layout));
- g_assert_cmpint (pango_layout_get_alignment (layout), ==, PANGO_ALIGN_LEFT);
+ g_assert_cmpint (pango_layout_get_alignment (layout), ==, PANGO_ALIGN_NATURAL);
g_assert_cmpint (pango_layout_get_width (layout), ==, -1);
out_bytes = pango_layout_serialize (layout, PANGO_LAYOUT_SERIALIZE_DEFAULT);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]