[pango] Improve justify_cluster() some more
- From: Behdad Esfahbod <behdad src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [pango] Improve justify_cluster() some more
- Date: Fri, 21 Aug 2015 15:28:09 +0000 (UTC)
commit aa12788659f2a65314bdcc005d50105a5f4a63cd
Author: Behdad Esfahbod <behdad behdad org>
Date: Fri Aug 21 16:27:31 2015 +0100
Improve justify_cluster() some more
Much better now.
Now I see issues in justify_words() again :(.
pango/pango-layout.c | 55 ++++++++++++++++++++++++++++++++++++-------------
1 files changed, 40 insertions(+), 15 deletions(-)
---
diff --git a/pango/pango-layout.c b/pango/pango-layout.c
index a9241c1..57e8e8f 100644
--- a/pango/pango-layout.c
+++ b/pango/pango-layout.c
@@ -5188,6 +5188,11 @@ justify_clusters (PangoLayoutLine *line,
for (mode = MEASURE; mode <= ADJUST; mode++)
{
+ gboolean leftedge = TRUE;
+ PangoGlyphString *rightmost_glyphs = NULL;
+ int rightmost_space;
+ int residual = 0;
+
added_so_far = 0;
gaps_so_far = 0;
@@ -5197,9 +5202,10 @@ justify_clusters (PangoLayoutLine *line,
PangoGlyphString *glyphs = run->glyphs;
PangoGlyphItemIter cluster_iter;
gboolean have_cluster;
+ int dir;
int offset;
- gboolean first_run = run_iter == line->runs;
- gboolean last_run = run_iter->next == NULL;
+
+ dir = run->item->analysis.level % 2 == 0 ? +1 : -1;
/* We need character offset of the start of the run. We don't have this.
* Compute by counting from the beginning of the line. The naming is
@@ -5214,20 +5220,21 @@ justify_clusters (PangoLayoutLine *line,
+ pango_utf8_strlen (text + state->line_start_index,
run->item->offset - state->line_start_index);
- for (have_cluster = pango_glyph_item_iter_init_start (&cluster_iter, run, text);
+ for (have_cluster = dir > 0 ?
+ pango_glyph_item_iter_init_start (&cluster_iter, run, text) :
+ pango_glyph_item_iter_init_end (&cluster_iter, run, text);
have_cluster;
- have_cluster = pango_glyph_item_iter_next_cluster (&cluster_iter))
+ have_cluster = dir > 0 ?
+ pango_glyph_item_iter_next_cluster (&cluster_iter) :
+ pango_glyph_item_iter_prev_cluster (&cluster_iter))
{
int i;
- int dir;
int width = 0;
/* don't expand in the middle of graphemes */
if (!log_attrs[offset + cluster_iter.start_char].is_cursor_position)
continue;
- dir = (cluster_iter.start_glyph < cluster_iter.end_glyph) ? 1 : -1;
-
for (i = cluster_iter.start_glyph; i != cluster_iter.end_glyph; i += dir)
width += glyphs->glyphs[i].geometry.width;
@@ -5242,9 +5249,13 @@ justify_clusters (PangoLayoutLine *line,
int leftmost, rightmost;
int adjustment, space_left, space_right;
- adjustment = ((gaps_so_far * total_remaining_width) - total_remaining_width/2) / total_gaps
- added_so_far;
+ adjustment = total_remaining_width / total_gaps + residual;
if (is_hinted)
+ {
+ int old_adjustment = adjustment;
adjustment = PANGO_UNITS_ROUND (adjustment);
+ residual = old_adjustment - adjustment;
+ }
/* distribute to before/after */
distribute_letter_spacing (adjustment, &space_left, &space_right);
@@ -5260,17 +5271,23 @@ justify_clusters (PangoLayoutLine *line,
leftmost = cluster_iter.end_glyph + 1;
rightmost = cluster_iter.start_glyph;
}
- /* Don't add to left-side of left-most glyph of left-most run. */
- if (!first_run || leftmost)
+ /* Don't add to left-side of left-most glyph of left-most non-zero run. */
+ if (leftedge)
+ leftedge = FALSE;
+ else
{
- added_so_far += adjustment;
- glyphs->glyphs[leftmost ].geometry.width += space_left ;
- glyphs->glyphs[leftmost ].geometry.x_offset += space_left ;
+ glyphs->glyphs[leftmost].geometry.width += space_left ;
+ glyphs->glyphs[leftmost].geometry.x_offset += space_left ;
+ added_so_far += space_left;
}
- /* Don't add to right-side of right-most glyph of right-most run. */
- if (!last_run || rightmost != glyphs->num_glyphs - 1)
+ /* Don't add to right-side of right-most glyph of right-most non-zero run. */
{
+ /* Save so we can undo later. */
+ rightmost_glyphs = glyphs;
+ rightmost_space = space_right;
+
glyphs->glyphs[rightmost].geometry.width += space_right;
+ added_so_far += space_right;
}
}
}
@@ -5286,6 +5303,14 @@ justify_clusters (PangoLayoutLine *line,
return;
}
}
+ else /* mode == ADJUST */
+ {
+ if (rightmost_glyphs)
+ {
+ rightmost_glyphs->glyphs[rightmost_glyphs->num_glyphs - 1].geometry.width -= rightmost_space;
+ added_so_far -= rightmost_space;
+ }
+ }
}
state->remaining_width -= added_so_far;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]