summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBehdad Esfahbod <behdad@behdad.org>2015-08-21 16:27:31 +0100
committerBehdad Esfahbod <behdad@behdad.org>2015-08-21 16:27:31 +0100
commitaa12788659f2a65314bdcc005d50105a5f4a63cd (patch)
tree13d8616011ab911ef6856ce81e9780899e2af0fb
parentc7bca3b1431e50e8f01e4d4f952b38dee86ec0fd (diff)
downloadpango-aa12788659f2a65314bdcc005d50105a5f4a63cd.tar.gz
Improve justify_cluster() some more
Much better now. Now I see issues in justify_words() again :(.
-rw-r--r--pango/pango-layout.c55
1 files changed, 40 insertions, 15 deletions
diff --git a/pango/pango-layout.c b/pango/pango-layout.c
index a9241c1f..57e8e8f5 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;