summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Clasen <mclasen@redhat.com>2019-11-03 12:27:34 +0000
committerMatthias Clasen <mclasen@redhat.com>2019-11-04 22:29:03 +0000
commit5483069c9897ce03305585cb9a218158fd582caf (patch)
tree9fce983972ed6cf11796db7f25ac834f790981c4
parentd915e942b8a3f99e297141b70ac7912d8da3e395 (diff)
downloadpango-5483069c9897ce03305585cb9a218158fd582caf.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 …
-rw-r--r--pango/ellipsize.c21
-rw-r--r--pango/pango-layout-private.h1
-rw-r--r--pango/pango-layout.c7
3 files changed, 23 insertions, 6 deletions
diff --git a/pango/ellipsize.c b/pango/ellipsize.c
index 304d89fc..4b27025e 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,8 +376,11 @@ 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++)
@@ -722,6 +731,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 +741,7 @@ current_width (EllipsizeState *state)
gboolean
_pango_layout_line_ellipsize (PangoLayoutLine *line,
PangoAttrList *attrs,
+ PangoShapeFlags shape_flags,
int goal_width)
{
EllipsizeState state;
@@ -738,7 +749,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 aa542786..a1ebfbcc 100644
--- a/pango/pango-layout.c
+++ b/pango/pango-layout.c
@@ -5784,7 +5784,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);