aboutsummaryrefslogtreecommitdiff
path: root/src/wrap.c
diff options
context:
space:
mode:
authorThomas White <taw@bitwiz.org.uk>2015-10-19 20:16:09 +0100
committerThomas White <taw@bitwiz.org.uk>2015-10-19 20:16:17 +0100
commit5fec4438867ec944f02d1fdff46c70e1e36fb18a (patch)
tree2d3d8b3fc7541f876416f6f8205f3817e497589d /src/wrap.c
parent6b4ac5c656fd35a13a74ad1ed215a7182046fa1f (diff)
Paragraph start lines (sort of)
Diffstat (limited to 'src/wrap.c')
-rw-r--r--src/wrap.c38
1 files changed, 33 insertions, 5 deletions
diff --git a/src/wrap.c b/src/wrap.c
index d1048cd..a71434e 100644
--- a/src/wrap.c
+++ b/src/wrap.c
@@ -879,6 +879,34 @@ void show_boxes(struct wrap_line *boxes)
}
+static int wrap_everything(struct frame *fr, double wrap_w)
+{
+ int i;
+
+ fr->paragraph_start_lines = malloc(fr->n_paragraphs*sizeof(int));
+ if ( fr->paragraph_start_lines == NULL ) {
+ fprintf(stderr, "Failed to allocate paragraph start lines\n");
+ return 1;
+ }
+
+ /* Split paragraphs into lines */
+ fr->paragraph_start_lines[0] = 0;
+ for ( i=0; i<fr->n_paragraphs; i++ ) {
+
+ //int n;
+
+ /* Choose wrapping algorithm here */
+ //knuth_suboptimal_fit(para, wrap_w, fr, rho);
+ first_fit(fr->paragraphs[i], wrap_w, fr);
+
+ //fr->paragraph_start_lines = n;
+
+ }
+
+ return 0;
+}
+
+
/* Wrap the StoryCode inside "fr->sc" so that it fits within width "fr->w",
* and generate fr->lines */
int wrap_contents(struct frame *fr)
@@ -921,11 +949,11 @@ int wrap_contents(struct frame *fr)
}
} 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 ( fr->n_paragraphs > 0 ) {
+ if ( wrap_everything(fr, wrap_w) ) return 1;
+ } else {
+ fr->paragraph_start_lines = NULL;
+ return 0;
}
/* If the last paragraph ended with an EOP, add an extra line */