aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorThomas White <taw@bitwiz.org.uk>2014-01-17 10:13:46 +0100
committerThomas White <taw@bitwiz.org.uk>2014-01-17 10:13:46 +0100
commit93956372d317fc90f8751e6b319e0055507c2519 (patch)
tree9c290978d9ad8a05a1da66ffc4839232b3102899 /src
parentbc49b9f3fd00ebc3bd62a51bb2321822618e838d (diff)
Unwrapped text belongs to frame, not interpreter
Diffstat (limited to 'src')
-rw-r--r--src/frame.c16
-rw-r--r--src/frame.h1
-rw-r--r--src/render.c11
-rw-r--r--src/sc_interp.c28
-rw-r--r--src/sc_interp.h2
-rw-r--r--src/wrap.c7
-rw-r--r--src/wrap.h2
7 files changed, 39 insertions, 28 deletions
diff --git a/src/frame.c b/src/frame.c
index 40daa86..2906c40 100644
--- a/src/frame.c
+++ b/src/frame.c
@@ -31,6 +31,7 @@
#include "sc_parse.h"
#include "frame.h"
+#include "wrap.h"
static int alloc_ro(struct frame *fr)
@@ -56,12 +57,23 @@ struct frame *frame_new()
n->children = NULL;
n->max_children = 32;
- alloc_ro(n);
-
+ if ( alloc_ro(n) ) {
+ fprintf(stderr, "Couldn't allocate children\n");
+ free(n);
+ return NULL;
+ }
n->num_children = 0;
n->scblocks = NULL;
+ n->boxes = malloc(sizeof(struct wrap_line));
+ if ( n->boxes == NULL ) {
+ fprintf(stderr, "Failed to allocate boxes.\n");
+ free(n);
+ return NULL;
+ }
+ initialise_line(n->boxes);
+
return n;
}
diff --git a/src/frame.h b/src/frame.h
index f71794b..e1cfccd 100644
--- a/src/frame.h
+++ b/src/frame.h
@@ -47,6 +47,7 @@ struct frame
int max_children;
SCBlock *scblocks;
+ struct wrap_line *boxes; /* The unwrapped boxes */
int n_lines;
int max_lines;
diff --git a/src/render.c b/src/render.c
index 4509152..8c28536 100644
--- a/src/render.c
+++ b/src/render.c
@@ -297,18 +297,25 @@ static int render_frame(cairo_t *cr, struct frame *fr, ImageStore *is,
}
for ( i=0; i<fr->n_lines; i++ ) {
- wrap_line_free(&fr->lines[i]);
+ // wrap_line_free(&fr->lines[i]);
}
free(fr->lines);
fr->lines = NULL;
fr->n_lines = 0;
fr->max_lines = 0;
+ if ( fr->boxes != NULL ) {
+ free(fr->boxes->boxes);
+ free(fr->boxes);
+ }
+ fr->boxes = malloc(sizeof(struct wrap_line));
+ initialise_line(fr->boxes);
+
/* SCBlocks -> frames and wrap boxes (preferably re-using frames) */
sc_interp_add_blocks(scin, bl);
/* Wrap boxes -> wrap lines */
- wrap_contents(fr, sc_interp_get_boxes(scin));
+ wrap_contents(fr);
/* Actually draw the lines */
draw_frame(cr, fr, is, isz);
diff --git a/src/sc_interp.c b/src/sc_interp.c
index 9fd6b24..5e1be23 100644
--- a/src/sc_interp.c
+++ b/src/sc_interp.c
@@ -60,8 +60,6 @@ struct _scinterp
struct sc_state *state;
int j; /* Index of the current state */
int max_state;
-
- struct wrap_line *boxes;
};
@@ -249,13 +247,6 @@ SCInterpreter *sc_interp_new(PangoContext *pc, struct frame *top)
/* FIXME: Determine proper language (somehow...) */
scin->lang = pango_language_from_string("en_GB");
- scin->boxes = malloc(sizeof(struct wrap_line));
- if ( scin->boxes == NULL ) {
- fprintf(stderr, "Failed to allocate boxes.\n");
- return NULL;
- }
- initialise_line(scin->boxes);
-
/* The "ultimate" default font */
set_font(scin, "Sans 12");
set_colour(scin, "#000000");
@@ -411,8 +402,8 @@ int sc_interp_add_blocks(SCInterpreter *scin, SCBlock *bl)
}
if ( name == NULL ) {
- split_words(scin->boxes, scin->pc, contents,
- scin->lang, 1, scin);
+ split_words(sc_interp_get_frame(scin)->boxes, scin->pc,
+ contents, scin->lang, 1, scin);
} else if ( strcmp(name, "font") == 0 ) {
set_font(scin, options);
@@ -444,7 +435,16 @@ int sc_interp_add_blocks(SCInterpreter *scin, SCBlock *bl)
#endif
} else if ( strcmp(name, "f")==0 ) {
+
struct frame *fr = sc_block_frame(bl);
+
+ if ( fr != NULL ) {
+ free(fr->boxes->boxes);
+ free(fr->boxes);
+ fr->boxes = malloc(sizeof(struct wrap_line));
+ initialise_line(fr->boxes);
+ }
+
if ( fr == NULL ) {
fr = add_subframe(sc_interp_get_frame(scin));
sc_block_set_frame(bl, fr);
@@ -454,6 +454,7 @@ int sc_interp_add_blocks(SCInterpreter *scin, SCBlock *bl)
fprintf(stderr, "Failed to add frame.\n");
goto next;
}
+
parse_frame_options(fr, sc_interp_get_frame(scin),
options);
set_frame(scin, fr);
@@ -477,8 +478,3 @@ next:
return 0;
}
-
-struct wrap_line *sc_interp_get_boxes(SCInterpreter *scin)
-{
- return scin->boxes;
-}
diff --git a/src/sc_interp.h b/src/sc_interp.h
index 78f32d9..80b1e70 100644
--- a/src/sc_interp.h
+++ b/src/sc_interp.h
@@ -39,8 +39,6 @@ extern void sc_interp_restore(SCInterpreter *scin);
extern int sc_interp_add_blocks(SCInterpreter *scin, SCBlock *bl);
-extern struct wrap_line *sc_interp_get_boxes(SCInterpreter *scin);
-
/* Get the current state of the interpreter */
extern struct frame *sc_interp_get_frame(SCInterpreter *scin);
extern PangoFont *sc_interp_get_font(SCInterpreter *scin);
diff --git a/src/wrap.c b/src/wrap.c
index 25f5d4d..782828a 100644
--- a/src/wrap.c
+++ b/src/wrap.c
@@ -803,7 +803,7 @@ void show_boxes(struct wrap_line *boxes)
/* Wrap the StoryCode inside "fr->sc" so that it fits within width "fr->w",
* and generate fr->lines */
-int wrap_contents(struct frame *fr, struct wrap_line *boxes)
+int wrap_contents(struct frame *fr)
{
struct wrap_line *para;
int i;
@@ -821,7 +821,7 @@ int wrap_contents(struct frame *fr, struct wrap_line *boxes)
i = 0;
do {
- para = split_paragraph(boxes, &i);
+ para = split_paragraph(fr->boxes, &i);
/* Split paragraphs into lines */
if ( para != NULL ) {
@@ -835,9 +835,6 @@ int wrap_contents(struct frame *fr, struct wrap_line *boxes)
} while ( para != NULL );
- free(boxes->boxes);
- free(boxes);
-
for ( i=0; i<fr->n_lines; i++ ) {
distribute_spaces(&fr->lines[i], wrap_w, rho);
calc_line_geometry(&fr->lines[i]);
diff --git a/src/wrap.h b/src/wrap.h
index f29e0dc..8fc057a 100644
--- a/src/wrap.h
+++ b/src/wrap.h
@@ -99,7 +99,7 @@ struct wrap_line
};
-extern int wrap_contents(struct frame *fr, struct wrap_line *boxes);
+extern int wrap_contents(struct frame *fr);
extern void get_cursor_pos(struct frame *fr, size_t pos,
double *xposd, double *yposd, double *line_height);