summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBehdad Esfahbod <behdad@gnome.org>2007-05-03 00:44:53 +0000
committerBehdad Esfahbod <behdad@src.gnome.org>2007-05-03 00:44:53 +0000
commitf8e2adf40c0497682c614cb0d547ee574645adee (patch)
treed049288cb9cf4560cee1cf2179d46c59cfc8f016
parente3eee491d7434dda314b78fad127880943d9c1ba (diff)
downloadpango-f8e2adf40c0497682c614cb0d547ee574645adee.tar.gz
Bug 64538 – pango_layout_set_justify() doesn't work
2007-05-02 Behdad Esfahbod <behdad@gnome.org> Bug 64538 – pango_layout_set_justify() doesn't work * pango/pango-layout.c (process_item), (justify_clusters), (justify_words): If no space found, justify by inserting space between clusters. svn path=/trunk/; revision=2254
-rw-r--r--ChangeLog8
-rw-r--r--pango/pango-layout.c100
2 files changed, 104 insertions, 4 deletions
diff --git a/ChangeLog b/ChangeLog
index 567c9e1a..9be37cc7 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,13 @@
2007-05-02 Behdad Esfahbod <behdad@gnome.org>
+ Bug 64538 – pango_layout_set_justify() doesn't work
+
+ * pango/pango-layout.c (process_item), (justify_clusters),
+ (justify_words): If no space found, justify by inserting space
+ between clusters.
+
+2007-05-02 Behdad Esfahbod <behdad@gnome.org>
+
* pango/pango-glyph-item.c (pango_glyph_item_letter_space):
* pango/pango-item.c (pango_item_split):
* pango/pango-layout.c (distribute_letter_spacing), (shape_run),
diff --git a/pango/pango-layout.c b/pango/pango-layout.c
index 0993adc2..7ba34642 100644
--- a/pango/pango-layout.c
+++ b/pango/pango-layout.c
@@ -3273,13 +3273,16 @@ process_item (PangoLayout *layout,
new_item = pango_item_split (item, length, break_num_chars);
- /* reshaping may slightly change the item width */
+ /* reshaping may slightly change the item width. update
+ * remaining_with if we are justifying */
state->remaining_width += break_width;
insert_run (line, state, new_item, FALSE);
- break_width = pango_glyph_string_get_width (((PangoGlyphItem *)(line->runs->data))->glyphs);
+ if (layout->justify)
+ break_width = pango_glyph_string_get_width (((PangoGlyphItem *)(line->runs->data))->glyphs);
+
state->remaining_width -= break_width;
state->log_widths_offset += break_num_chars;
@@ -4828,7 +4831,93 @@ static void
justify_clusters (PangoLayoutLine *line,
ParaBreakState *state)
{
+ int offset;
+ int total_remaining_width, total_gaps = 0;
+ int added_so_far, gaps_so_far;
+ gboolean is_hinted;
+ GSList *run_iter;
+ enum {
+ MEASURE,
+ ADJUST
+ } mode;
+ total_remaining_width = state->remaining_width;
+ if (total_remaining_width <= 0)
+ return;
+
+ /* hint to full pixel if total remaining width was so */
+ is_hinted = (total_remaining_width & (PANGO_SCALE - 1)) == 0;
+
+ for (mode = MEASURE; mode <= ADJUST; mode++)
+ {
+ added_so_far = 0;
+ gaps_so_far = 0;
+
+ for (run_iter = line->runs; run_iter; run_iter = run_iter->next)
+ {
+ PangoLayoutRun *run = run_iter->data;
+ PangoGlyphString *glyphs = run->glyphs;
+ PangoGlyphItemIter cluster_iter;
+ gboolean have_cluster;
+ gboolean is_first_gap = TRUE;
+
+ int i;
+
+ for (i = 0; i < glyphs->num_glyphs; i++)
+ {
+ if (!glyphs->glyphs[i].attr.is_cluster_start)
+ continue;
+
+ /* also don't expand zero-width spaces at the end of runs */
+ if (glyphs->glyphs[i].geometry.width == 0)
+ {
+ if (i == glyphs->num_glyphs -1)
+ continue;
+
+ if (i == 0 && glyphs->num_glyphs > 1 && glyphs->glyphs[i+1].attr.is_cluster_start)
+ continue;
+ }
+
+ if (is_first_gap)
+ {
+ is_first_gap = FALSE;
+ continue;
+ }
+
+ gaps_so_far++;
+
+ if (mode == ADJUST)
+ {
+ int adjustment, space_left, space_right;
+
+ adjustment = (gaps_so_far * total_remaining_width) / total_gaps - added_so_far;
+ if (is_hinted)
+ adjustment = PANGO_UNITS_ROUND (adjustment);
+ /* distribute to before/after */
+ distribute_letter_spacing (adjustment, &space_left, &space_right);
+
+ glyphs->glyphs[i-1].geometry.width += space_left ;
+ glyphs->glyphs[i ].geometry.width += space_right;
+ glyphs->glyphs[i ].geometry.x_offset += space_right;
+
+ added_so_far += adjustment;
+ }
+ }
+ }
+
+ if (mode == MEASURE)
+ {
+ total_gaps = gaps_so_far;
+
+ if (total_gaps == 0)
+ {
+ /* a single cluster, can't really justify it */
+ return;
+ }
+ }
+ }
+
+ state->remaining_width -= added_so_far;
}
static void
@@ -4841,6 +4930,7 @@ justify_words (PangoLayoutLine *line,
int offset;
int total_remaining_width, total_space_width = 0;
int added_so_far, spaces_so_far;
+ gboolean is_hinted;
GSList *run_iter;
enum {
MEASURE,
@@ -4851,6 +4941,9 @@ justify_words (PangoLayoutLine *line,
if (total_remaining_width <= 0)
return;
+ /* hint to full pixel if total remaining width was so */
+ is_hinted = (total_remaining_width & (PANGO_SCALE - 1)) == 0;
+
for (mode = MEASURE; mode <= ADJUST; mode++)
{
added_so_far = 0;
@@ -4889,8 +4982,7 @@ justify_words (PangoLayoutLine *line,
int adjustment;
adjustment = ((guint64) spaces_so_far * total_remaining_width) / total_space_width - added_so_far;
- /* hint to full pixel if original space was so */
- if ((glyph_width & (PANGO_SCALE - 1)) == 0)
+ if (is_hinted)
adjustment = PANGO_UNITS_ROUND (adjustment);
glyphs->glyphs[i].geometry.width += adjustment;