diff options
author | Matthias Clasen <mclasen@redhat.com> | 2019-11-03 12:27:34 +0000 |
---|---|---|
committer | Matthias Clasen <mclasen@redhat.com> | 2019-11-03 12:27:34 +0000 |
commit | 5b7b3684e18b636bce901688085226694d44adf4 (patch) | |
tree | b4a48e7fdcdb7bd07941ea52030f6f6d3540d989 /pango/ellipsize.c | |
parent | 0e76389fbbd4679b39bdc3dd78f6f8701f50b29a (diff) | |
download | pango-5b7b3684e18b636bce901688085226694d44adf4.tar.gz |
Use shape flags for ellipsis
When shaping the ellipsis, use the same shape flags
we use for the rest of the layout, otherwise we end
up with subtle size differences between an ellipsized
text and a plain …
Diffstat (limited to 'pango/ellipsize.c')
-rw-r--r-- | pango/ellipsize.c | 23 |
1 files changed, 18 insertions, 5 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; |