diff options
author | Thomas White <taw@physics.org> | 2015-10-16 10:48:24 +0200 |
---|---|---|
committer | Thomas White <taw@physics.org> | 2015-10-16 10:48:24 +0200 |
commit | e7fc7858e8118de0da38bddbc70d3914b7f0cfcc (patch) | |
tree | 78507d2f774662e48bbdec53bb8810e8ddaee1cb | |
parent | 779a3436b14d3152e376949fb1294cb62e46a4d7 (diff) |
Allocate boxes in line properly during wrapping
-rw-r--r-- | src/wrap.c | 15 | ||||
-rw-r--r-- | src/wrap.h | 4 |
2 files changed, 15 insertions, 4 deletions
@@ -55,17 +55,18 @@ static void alloc_lines(struct frame *fr) } -void alloc_boxes(struct wrap_line *l) +int alloc_boxes(struct wrap_line *l) { struct wrap_box *boxes_new; boxes_new = realloc(l->boxes, l->max_boxes * sizeof(struct wrap_box)); if ( boxes_new == NULL ) { fprintf(stderr, "Couldn't allocate memory for boxes!\n"); - return; + return 1; } l->boxes = boxes_new; + return 0; } @@ -734,6 +735,15 @@ static struct wrap_line *new_line(struct frame *fr) } +static int maybe_extend_line(struct wrap_line *l) +{ + if ( l->n_boxes < l->max_boxes ) return 0; + + l->max_boxes += 32; + return alloc_boxes(l); +} + + static void first_fit(struct wrap_line *boxes, double line_length, struct frame *fr) { @@ -759,6 +769,7 @@ static void first_fit(struct wrap_line *boxes, double line_length, line->boxes[line->n_boxes] = boxes->boxes[j]; line->boxes[line->n_boxes].cf = &boxes->boxes[j]; line->n_boxes++; + if ( maybe_extend_line(line) ) return; j++; if ( (j > 0) && (boxes->boxes[j-1].type != WRAP_BOX_SENTINEL) ) @@ -3,7 +3,7 @@ * * Text wrapping, hyphenation, justification and shaping * - * Copyright © 2014 Thomas White <taw@bitwiz.org.uk> + * Copyright © 2014-2015 Thomas White <taw@bitwiz.org.uk> * * This file is part of Colloquium. * @@ -116,7 +116,7 @@ extern void get_cursor_pos(struct wrap_box *box, int pos, extern void find_cursor(struct frame *fr, double xposd, double yposd, int *line, int *box, int *pos); -extern void alloc_boxes(struct wrap_line *l); +extern int alloc_boxes(struct wrap_line *l); extern void initialise_line(struct wrap_line *l); extern void wrap_line_free(struct wrap_line *l); |