[pango/ellipsis-shape: 1/2] Use shape flags for ellipsis
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pango/ellipsis-shape: 1/2] Use shape flags for ellipsis
- Date: Sun, 3 Nov 2019 14:29:09 +0000 (UTC)
commit 5b7b3684e18b636bce901688085226694d44adf4
Author: Matthias Clasen <mclasen redhat com>
Date: Sun Nov 3 12:27:34 2019 +0000
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 …
pango/ellipsize.c | 23 ++++++++++++++++++-----
pango/pango-layout-private.h | 1 +
pango/pango-layout.c | 7 ++++++-
3 files changed, 25 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);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]