From a352e79c37b7f35875473d8c9b517272f4f693e0 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Mon, 13 Jan 2014 08:35:29 +0100 Subject: Handle font/colour changes and actually draw the lines --- src/render.c | 31 +++++++++++---------------- src/sc_interp.c | 65 +++++++++++++++++++++++++++++---------------------------- src/sc_interp.h | 5 ++++- src/sc_parse.c | 6 ++++++ src/sc_parse.h | 1 + 5 files changed, 56 insertions(+), 52 deletions(-) diff --git a/src/render.c b/src/render.c index ce23f0c..a4fbd51 100644 --- a/src/render.c +++ b/src/render.c @@ -265,35 +265,23 @@ static void render_lines(struct frame *fr, cairo_t *cr, ImageStore *is, cairo_fill(cr); #endif -#if 0 -/* Render Level 1 Storycode (no subframes) */ -static int render_sc(cairo_t *cr, struct frame *fr, ImageStore *is, - enum is_size isz, struct slide_constants *scc, - struct presentation_constants *pcc, PangoContext *pc) +static int draw_frame(cairo_t *cr, struct frame *fr, ImageStore *is, + enum is_size isz) { - - /* Set up lines */ - if ( wrap_contents(fr, pc, scc, pcc) ) { - fprintf(stderr, "Failed to wrap lines.\n"); - return 1; - } - if ( fr->trouble ) { cairo_new_path(cr); cairo_rectangle(cr, 0.0, 0.0, fr->w, fr->h); cairo_set_source_rgb(cr, 1.0, 0.0, 0.0); cairo_set_line_width(cr, 2.0); cairo_stroke(cr); - printf("SC: '%s'\n", fr->sc); } /* Actually render the lines */ - cairo_translate(cr, fr->lop.pad_l, fr->lop.pad_t); + cairo_translate(cr, fr->pad_l, fr->pad_t); render_lines(fr, cr, is, isz); return 0; } -#endif static int render_frame(cairo_t *cr, struct frame *fr, ImageStore *is, @@ -305,7 +293,7 @@ static int render_frame(cairo_t *cr, struct frame *fr, ImageStore *is, int i; SCBlock *bl = fr->scblocks; - scin = sc_interp_new(); + scin = sc_interp_new(pc); if ( scin == NULL ) { fprintf(stderr, "Failed to set up interpreter.\n"); return 1; @@ -319,9 +307,14 @@ static int render_frame(cairo_t *cr, struct frame *fr, ImageStore *is, fr->n_lines = 0; fr->max_lines = 0; - while ( bl != NULL ) { - bl = sc_block_next(bl); - } + /* 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)); + + /* Actually draw the lines */ + draw_frame(cr, fr, is, isz); sc_interp_destroy(scin); diff --git a/src/sc_interp.c b/src/sc_interp.c index 65b113e..0aae963 100644 --- a/src/sc_interp.c +++ b/src/sc_interp.c @@ -47,6 +47,8 @@ struct _scinterp struct sc_font *fontstack; int n_fonts; int max_fonts; + + struct wrap_line *boxes; }; @@ -161,7 +163,7 @@ static void pop_font_or_colour(SCInterpreter *scin) } -SCInterpreter *sc_interp_new() +SCInterpreter *sc_interp_new(PangoContext *pc) { SCInterpreter *scin; @@ -172,13 +174,20 @@ SCInterpreter *sc_interp_new() scin->n_fonts = 0; scin->max_fonts = 0; - scin->pc = NULL; + scin->pc = pc; scin->s_constants = NULL; scin->p_constants = NULL; /* 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 */ push_font(scin, "Sans 12"); set_colour(scin, "#000000"); @@ -200,49 +209,35 @@ void sc_interp_destroy(SCInterpreter *scin) int sc_interp_add_blocks(SCInterpreter *scin, const SCBlock *bl) { - struct wrap_line *boxes; - - boxes = malloc(sizeof(struct wrap_line)); - if ( boxes == NULL ) { - fprintf(stderr, "Failed to allocate boxes.\n"); - return 1; - } - initialise_line(boxes); - while ( bl != NULL ) { const char *name = sc_block_name(bl); + const char *options = sc_block_options(bl); const char *contents = sc_block_contents(bl); + SCBlock *child = sc_block_child(bl); if ( name == NULL ) { - split_words(boxes, scin->pc, contents, + split_words(scin->boxes, scin->pc, contents, scin->lang, 1, &scin->fontstack[scin->n_fonts-1]); -#if 0 - /* FIXME ... ! */ - - } else if ( (strcmp(name, "font")==0) && (contents == NULL) ) { - set_font(fonts, b->options, pc); + } else if ( (strcmp(name, "font")==0) && (child == NULL) ) { + set_font(scin, options); - } else if ( (strcmp(name, "font")==0) && (contents != NULL) ) { - push_font(fonts, b->options, pc); - run_sc(b->contents, fonts, pc, boxes, lang, offset, - editable, fr, slide_constants, - presentation_constants); - pop_font_or_colour(fonts); + } else if ( (strcmp(name, "font")==0) && (child != NULL) ) { + push_font(scin, options); + sc_interp_add_blocks(scin, child); + pop_font_or_colour(scin); - } else if ( (strcmp(name, "fgcol")==0) - && (contents == NULL) ) { - set_colour(fonts, b->options); + } else if ( (strcmp(name, "fgcol")==0) && (child == NULL) ) { + set_colour(scin, options); - } else if ( (strcmp(name, "fgcol")==0) && (contents != NULL) ) { - push_colour(fonts, b->options); - run_sc(b->contents, fonts, pc, boxes, lang, offset, - editable, fr, slide_constants, - presentation_constants); - pop_font_or_colour(fonts); + } else if ( (strcmp(name, "fgcol")==0) && (child != NULL) ) { + push_colour(scin, options); + sc_interp_add_blocks(scin, child); + pop_font_or_colour(scin); +#if 0 } else if ( (strcmp(name, "image")==0) && (contents != NULL) && (b->options != NULL) ) { int w, h; @@ -271,3 +266,9 @@ int sc_interp_add_blocks(SCInterpreter *scin, const SCBlock *bl) 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 ad59193..05504f0 100644 --- a/src/sc_interp.h +++ b/src/sc_interp.h @@ -27,6 +27,8 @@ #include #endif +#include + struct sc_font { @@ -40,12 +42,13 @@ struct sc_font typedef struct _scinterp SCInterpreter; -extern SCInterpreter *sc_interp_new(void); +extern SCInterpreter *sc_interp_new(PangoContext *pc); extern void sc_interp_destroy(SCInterpreter *scin); extern void sc_interp_save(SCInterpreter *scin); extern void sc_interp_restore(SCInterpreter *scin); extern int sc_interp_add_blocks(SCInterpreter *scin, const SCBlock *bl); +extern struct wrap_line *sc_interp_get_boxes(SCInterpreter *scin); #endif /* SC_INTERP_H */ diff --git a/src/sc_parse.c b/src/sc_parse.c index 69755c7..328e397 100644 --- a/src/sc_parse.c +++ b/src/sc_parse.c @@ -62,6 +62,12 @@ SCBlock *sc_block_next(const SCBlock *bl) } +SCBlock *sc_block_child(const SCBlock *bl) +{ + return bl->child; +} + + const char *sc_block_name(const SCBlock *bl) { return bl->name; diff --git a/src/sc_parse.h b/src/sc_parse.h index ac4ce35..7640970 100644 --- a/src/sc_parse.h +++ b/src/sc_parse.h @@ -34,6 +34,7 @@ extern SCBlock *sc_parse(const char *sc); extern void sc_block_free(SCBlock *bl); extern SCBlock *sc_block_next(const SCBlock *bl); +extern SCBlock *sc_block_child(const SCBlock *bl); extern const char *sc_block_name(const SCBlock *bl); extern const char *sc_block_options(const SCBlock *bl); extern const char *sc_block_contents(const SCBlock *bl); -- cgit v1.2.3