aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/frame.c8
-rw-r--r--src/frame.h3
-rw-r--r--src/wrap.c36
3 files changed, 36 insertions, 11 deletions
diff --git a/src/frame.c b/src/frame.c
index ebd30ce..5b16f32 100644
--- a/src/frame.c
+++ b/src/frame.c
@@ -90,6 +90,14 @@ void frame_free(struct frame *fr)
}
free(fr->lines);
+ /* Free paragraphs */
+ if ( fr->paragraphs != NULL ) {
+ for ( i=0; i<fr->n_paragraphs; i++ ) {
+ free(fr->paragraphs[i]->boxes);
+ free(fr->paragraphs[i]);
+ }
+ free(fr->paragraphs);
+ }
/* Free unwrapped boxes */
if ( fr->boxes != NULL ) {
free(fr->boxes->boxes);
diff --git a/src/frame.h b/src/frame.h
index 8b59dde..8cb0e79 100644
--- a/src/frame.h
+++ b/src/frame.h
@@ -62,6 +62,9 @@ struct frame
int max_lines;
struct wrap_line *lines;
+ int n_paragraphs;
+ struct wrap_line **paragraphs;
+
/* The rectangle allocated to this frame, determined by the renderer */
double x;
double y;
diff --git a/src/wrap.c b/src/wrap.c
index acfb58d..39f631c 100644
--- a/src/wrap.c
+++ b/src/wrap.c
@@ -873,6 +873,7 @@ int wrap_contents(struct frame *fr)
int i, eop = 0;
//const double rho = 2.0;
const double wrap_w = fr->w - fr->pad_l - fr->pad_r;
+ int max_para = 64;
/* Clear lines */
fr->n_lines = 0;
@@ -883,23 +884,36 @@ int wrap_contents(struct frame *fr)
/* Split text into paragraphs */
i = 0;
+ fr->n_paragraphs = 0;
+ fr->paragraphs = malloc(max_para * sizeof(struct wrap_line *));
+ if ( fr->paragraphs == NULL ) {
+ fprintf(stderr, "Failed to allocate paragraphs\n");
+ return 1;
+ }
do {
-
para = split_paragraph(fr->boxes, &i, &eop);
-
- /* Split paragraphs into lines */
if ( para != NULL ) {
-
- //knuth_suboptimal_fit(para, wrap_w, fr, rho);
- first_fit(para, wrap_w, fr);
-
- free(para->boxes);
- free(para);
-
+ fr->paragraphs[fr->n_paragraphs++] = para;
+ }
+ if ( fr->n_paragraphs == max_para ) {
+ max_para += 64;
+ fr->paragraphs = realloc(fr->paragraphs,
+ max_para*sizeof(struct wrap_line *));
+ if ( fr->paragraphs == NULL ) {
+ fprintf(stderr, "Failed to allocate space"
+ " for paragraphs\n");
+ return 1;
+ }
}
-
} while ( para != NULL );
+ /* Split paragraphs into lines */
+ for ( i=0; i<fr->n_paragraphs; i++ ) {
+ /* Choose wrapping algorithm here */
+ //knuth_suboptimal_fit(para, wrap_w, fr, rho);
+ first_fit(fr->paragraphs[i], wrap_w, fr);
+ }
+
/* If the last paragraph ended with an EOP, add an extra line */
if ( eop || (fr->n_lines == 0) ) {