diff options
author | Matthias Clasen <mclasen@redhat.com> | 2019-11-04 07:43:28 +0000 |
---|---|---|
committer | Matthias Clasen <mclasen@redhat.com> | 2019-11-04 07:43:28 +0000 |
commit | a75d5390ebf4a0dd9840ed3357fd58380f49e2fc (patch) | |
tree | 2edc158603c3a6c4778a5788a5d8b315d8aff083 | |
parent | 0e76389fbbd4679b39bdc3dd78f6f8701f50b29a (diff) | |
parent | e9b44ac0959ea01b2248c887b9f3fecf22112f7e (diff) | |
download | pango-a75d5390ebf4a0dd9840ed3357fd58380f49e2fc.tar.gz |
Merge branch 'ellipsis-shape' into 'master'
Ellipsis shape
See merge request GNOME/pango!158
-rw-r--r-- | pango/ellipsize.c | 23 | ||||
-rw-r--r-- | pango/pango-layout-private.h | 1 | ||||
-rw-r--r-- | pango/pango-layout.c | 7 | ||||
-rw-r--r-- | tests/test-ellipsize.c | 29 |
4 files changed, 54 insertions, 6 deletions
diff --git a/pango/ellipsize.c b/pango/ellipsize.c index 304d89fc..cfe34d14 100644 --- a/pango/ellipsize.c +++ b/pango/ellipsize.c @@ -105,14 +105,17 @@ struct _EllipsizeState LineIter gap_end_iter; /* Iterator pointing to last cluster in gap */ int gap_end_x; /* x position of end of gap, in Pango units */ + + PangoShapeFlags shape_flags; }; /* Compute global information needed for the itemization process */ static void init_state (EllipsizeState *state, - PangoLayoutLine *line, - PangoAttrList *attrs) + PangoLayoutLine *line, + PangoAttrList *attrs, + PangoShapeFlags shape_flags) { GSList *l; int i; @@ -124,6 +127,8 @@ init_state (EllipsizeState *state, else state->attrs = pango_attr_list_new (); + state->shape_flags = shape_flags; + state->n_runs = g_slist_length (line->runs); state->run_info = g_new (RunInfo, state->n_runs); @@ -301,6 +306,7 @@ shape_ellipsis (EllipsizeState *state) GSList *l; PangoAttribute *fallback; const char *ellipsis_text; + int len; int i; /* Create/reset state->ellipsis_run @@ -370,12 +376,17 @@ shape_ellipsis (EllipsizeState *state) */ glyphs = state->ellipsis_run->glyphs; - pango_shape (ellipsis_text, strlen (ellipsis_text), - &item->analysis, glyphs); + len = strlen (ellipsis_text); + pango_shape_with_flags (ellipsis_text, len, + ellipsis_text, len, + &item->analysis, glyphs, + state->shape_flags); state->ellipsis_width = 0; for (i = 0; i < glyphs->num_glyphs; i++) state->ellipsis_width += glyphs->glyphs[i].geometry.width; + + g_print ("ellipsis width %d\n", state->ellipsis_width); } /* Helper function to advance a PangoAttrIterator to a particular @@ -722,6 +733,7 @@ current_width (EllipsizeState *state) * _pango_layout_line_ellipsize: * @line: a #PangoLayoutLine * @attrs: Attributes being used for itemization/shaping + * #shape_flags: Flags to use when shaping * * Given a #PangoLayoutLine with the runs still in logical order, ellipsize * it according the layout's policy to fit within the set width of the layout. @@ -731,6 +743,7 @@ current_width (EllipsizeState *state) gboolean _pango_layout_line_ellipsize (PangoLayoutLine *line, PangoAttrList *attrs, + PangoShapeFlags shape_flags, int goal_width) { EllipsizeState state; @@ -738,7 +751,7 @@ _pango_layout_line_ellipsize (PangoLayoutLine *line, g_return_val_if_fail (line->layout->ellipsize != PANGO_ELLIPSIZE_NONE && goal_width >= 0, is_ellipsized); - init_state (&state, line, attrs); + init_state (&state, line, attrs, shape_flags); if (state.total_width <= goal_width) goto out; diff --git a/pango/pango-layout-private.h b/pango/pango-layout-private.h index 38e2e196..63e4139e 100644 --- a/pango/pango-layout-private.h +++ b/pango/pango-layout-private.h @@ -144,6 +144,7 @@ struct _PangoLayoutIter gboolean _pango_layout_line_ellipsize (PangoLayoutLine *line, PangoAttrList *attrs, + PangoShapeFlags shape_flags, int goal_width); void _pango_layout_get_iter (PangoLayout *layout, diff --git a/pango/pango-layout.c b/pango/pango-layout.c index df47f0f6..44d59367 100644 --- a/pango/pango-layout.c +++ b/pango/pango-layout.c @@ -5819,7 +5819,12 @@ pango_layout_line_postprocess (PangoLayoutLine *line, if (G_UNLIKELY (state->line_width >= 0 && should_ellipsize_current_line (line->layout, state))) { - ellipsized = _pango_layout_line_ellipsize (line, state->attrs, state->line_width); + PangoShapeFlags shape_flags = PANGO_SHAPE_NONE; + + if (pango_context_get_round_glyph_positions (line->layout->context)) + shape_flags |= PANGO_SHAPE_ROUND_POSITIONS; + + ellipsized = _pango_layout_line_ellipsize (line, state->attrs, shape_flags, state->line_width); } DEBUG ("after removing final space", line, state); diff --git a/tests/test-ellipsize.c b/tests/test-ellipsize.c index 20819d0b..a9441d5a 100644 --- a/tests/test-ellipsize.c +++ b/tests/test-ellipsize.c @@ -78,6 +78,34 @@ test_ellipsize_crash (void) g_object_unref (layout); } +/* Check that the width of a fully ellipsized paragraph + * is the same as that of an explicit ellipsis. + */ +static void +test_ellipsize_fully (void) +{ + PangoLayout *layout; + PangoRectangle ink, logical; + PangoRectangle ink2, logical2; + + layout = pango_layout_new (context); + + pango_layout_set_text (layout, "…", -1); + pango_layout_get_extents (layout, &ink, &logical); + + pango_layout_set_text (layout, "ellipsized", -1); + + pango_layout_set_width (layout, 10 * PANGO_SCALE); + pango_layout_set_ellipsize (layout, PANGO_ELLIPSIZE_END); + + pango_layout_get_extents (layout, &ink2, &logical2); + + g_assert_cmpint (ink.width, ==, ink2.width); + g_assert_cmpint (logical.width, ==, logical2.width); + + g_object_unref (layout); +} + int main (int argc, char *argv[]) { @@ -90,6 +118,7 @@ main (int argc, char *argv[]) g_test_add_func ("/layout/ellipsize/height", test_ellipsize_height); g_test_add_func ("/layout/ellipsize/crash", test_ellipsize_crash); + g_test_add_func ("/layout/ellipsize/fully", test_ellipsize_fully); return g_test_run (); } |