diff options
author | Behdad Esfahbod <behdad@gnome.org> | 2007-05-02 06:47:16 +0000 |
---|---|---|
committer | Behdad Esfahbod <behdad@src.gnome.org> | 2007-05-02 06:47:16 +0000 |
commit | 8aa52af0fc687293abe4a316e5a58d38f7ea6628 (patch) | |
tree | bdd28192532ba91015199304f5901cb8db5ca563 | |
parent | dd259bd7098054220c14103a6f4af0b09a3ed8d6 (diff) | |
download | pango-8aa52af0fc687293abe4a316e5a58d38f7ea6628.tar.gz |
Bug 355789 – Pango misaligns word-wrapped text due to trailing
2007-05-02 Behdad Esfahbod <behdad@gnome.org>
Bug 355789 – Pango misaligns word-wrapped text due to trailing
whitespace
* pango/pango-layout.c (zero_line_final_space),
(pango_layout_line_postprocess): Make logical-final whitespace
on wrapped lines zero-width.
svn path=/trunk/; revision=2248
-rw-r--r-- | ChangeLog | 9 | ||||
-rw-r--r-- | pango/pango-layout.c | 34 |
2 files changed, 43 insertions, 0 deletions
@@ -1,5 +1,14 @@ 2007-05-02 Behdad Esfahbod <behdad@gnome.org> + Bug 355789 – Pango misaligns word-wrapped text due to trailing + whitespace + + * pango/pango-layout.c (zero_line_final_space), + (pango_layout_line_postprocess): Make logical-final whitespace + on wrapped lines zero-width. + +2007-05-02 Behdad Esfahbod <behdad@gnome.org> + * pango/pango-layout.c (process_line), (pango_layout_check_lines): Keep track of line start_offset in break state. diff --git a/pango/pango-layout.c b/pango/pango-layout.c index e6128576..bcc51081 100644 --- a/pango/pango-layout.c +++ b/pango/pango-layout.c @@ -4615,6 +4615,33 @@ is_tab_run (PangoLayout *layout, return (layout->text[run->item->offset] == '\t'); } +static void +zero_line_final_space (PangoLayoutLine *line, + ParaBreakState *state, + PangoLayoutRun *run) +{ + PangoLayout *layout = line->layout; + PangoItem *item = run->item; + PangoGlyphString *glyphs = run->glyphs; + int glyph = item->analysis.level % 2 ? 0 : glyphs->num_glyphs - 1; + const char *p; + int index; + + /* if the final char of line forms a cluster, and it's + * a whitespace char, zero its glyph's width as it's been wrapped + */ + + if (glyphs->num_glyphs < 1 || state->start_offset == 0 || + !layout->log_attrs[state->start_offset - 1].is_white) + return; + + p = g_utf8_prev_char (layout->text + item->offset + item->length); + if (p != layout->text + item->offset + glyphs->log_clusters[glyph]) + return; + + glyphs->glyphs[glyph].geometry.width = 0; +} + /* When doing shaping, we add the letter spacing value for a * run after every grapheme in the run. This produces ugly * asymmetrical results, so what this routine is redistributes @@ -4708,6 +4735,8 @@ pango_layout_line_postprocess (PangoLayoutLine *line, ParaBreakState *state, gboolean wrapped) { + PangoLayoutRun *last_run = line->runs->data; + /* NB: the runs are in reverse order at this point, since we prepended them to the list */ @@ -4720,6 +4749,11 @@ pango_layout_line_postprocess (PangoLayoutLine *line, if (_pango_layout_line_ellipsize (line, state->attrs)) line->layout->is_ellipsized = TRUE; + /* Truncate the logical-final whitespace in the line if we broke the line at it + */ + if (wrapped) + zero_line_final_space (line, state, last_run); + /* Now convert logical to visual order */ pango_layout_line_reorder (line); |