diff options
author | Thomas White <taw@bitwiz.org.uk> | 2013-03-10 10:03:39 +0100 |
---|---|---|
committer | Thomas White <taw@bitwiz.org.uk> | 2013-03-10 10:03:39 +0100 |
commit | 4efac825dc45d4ccef7b5339bc2512ac95ef5500 (patch) | |
tree | ce91befba8a5b8162f5e7c1fe2918c79379fa390 /src | |
parent | 253195dca197ab4b2d349b5df974a3b2c21ff7e8 (diff) |
Distribute the space
Diffstat (limited to 'src')
-rw-r--r-- | src/render.c | 1 | ||||
-rw-r--r-- | src/wrap.c | 43 | ||||
-rw-r--r-- | src/wrap.h | 1 |
3 files changed, 35 insertions, 10 deletions
diff --git a/src/render.c b/src/render.c index 0aaee64..b11b4fd 100644 --- a/src/render.c +++ b/src/render.c @@ -92,6 +92,7 @@ static void render_boxes(struct wrap_line *line, cairo_t *cr) } x_pos += pango_units_to_double(line->boxes[j].width); + x_pos += pango_units_to_double(line->boxes[j].sp); cairo_restore(cr); @@ -141,6 +141,7 @@ static void calc_line_geometry(struct wrap_line *line) for ( i=0; i<line->n_boxes; i++ ) { struct wrap_box *box = &line->boxes[i]; line->width += box->width; + line->width += box->sp; if ( box->height > line->height ) line->height = box->height; if ( box->ascent > line->ascent ) line->ascent = box->ascent; } @@ -432,6 +433,27 @@ static void consider_break(double sigma_prime, double sigma_prime_max, } +static void distribute_spaces(struct wrap_line *l, double w) +{ + int i; + double total; + double sp; + + total = 0.0; + for ( i=0; i<l->n_boxes; i++ ) { + total += l->boxes[i].width; + } + + sp = (pango_units_from_double(w)-total) / (l->n_boxes-1); + + for ( i=0; i<l->n_boxes-1; i++ ) { + l->boxes[i].sp = sp; + printf("Calculated space %f\n", pango_units_to_double(sp)); + } + l->boxes[l->n_boxes-1].sp = 0.0; +} + + static void output(int a, int i, int *p, struct frame *fr, struct wrap_line *boxes) { @@ -439,10 +461,11 @@ static void output(int a, int i, int *p, struct frame *fr, int r; int s = 0; - fr->n_lines = 0; - fr->max_lines = 32; - fr->lines = NULL; - alloc_lines(fr); + if ( fr->n_lines + (i-a) + 1 > fr->max_lines ) { + fr->max_lines += 32; + alloc_lines(fr); + if ( fr->n_lines == fr->max_lines ) return; + } while ( q != a ) { r = p[q]; @@ -456,12 +479,6 @@ static void output(int a, int i, int *p, struct frame *fr, struct wrap_line *l; int j; - if ( fr->n_lines == fr->max_lines ) { - fr->max_lines += 32; - alloc_lines(fr); - if ( fr->n_lines == fr->max_lines ) return; - } - l = &fr->lines[fr->n_lines]; fr->n_lines++; initialise_line(l); @@ -472,6 +489,7 @@ static void output(int a, int i, int *p, struct frame *fr, l->boxes[l->n_boxes++] = boxes->boxes[j]; } + distribute_spaces(l, fr->w); calc_line_geometry(l); q = s; @@ -499,6 +517,11 @@ static void knuth_suboptimal_fit(struct wrap_line *boxes, double line_length, int n; int reject; + fr->n_lines = 0; + fr->max_lines = 32; + fr->lines = NULL; + alloc_lines(fr); + /* Add empty zero-width box at end */ if ( boxes->n_boxes == boxes->max_boxes ) { boxes->max_boxes += 32; @@ -64,6 +64,7 @@ struct wrap_box int ascent; enum wrap_box_space space; /* Type of "space" following box */ + double sp; /* Calculated space (Pango units) after box */ /* For type == WRAP_BOX_PANGO */ PangoGlyphString *glyphs; |