aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas White <taw@physics.org>2015-10-16 10:48:24 +0200
committerThomas White <taw@physics.org>2015-10-16 10:48:24 +0200
commite7fc7858e8118de0da38bddbc70d3914b7f0cfcc (patch)
tree78507d2f774662e48bbdec53bb8810e8ddaee1cb
parent779a3436b14d3152e376949fb1294cb62e46a4d7 (diff)
Allocate boxes in line properly during wrapping
-rw-r--r--src/wrap.c15
-rw-r--r--src/wrap.h4
2 files changed, 15 insertions, 4 deletions
diff --git a/src/wrap.c b/src/wrap.c
index 3e2e62e..d1048cd 100644
--- a/src/wrap.c
+++ b/src/wrap.c
@@ -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) )
diff --git a/src/wrap.h b/src/wrap.h
index ca30e05..d95c9e2 100644
--- a/src/wrap.h
+++ b/src/wrap.h
@@ -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);