diff options
author | Thomas White <taw@bitwiz.org.uk> | 2014-01-29 00:06:59 +0100 |
---|---|---|
committer | Thomas White <taw@bitwiz.org.uk> | 2014-01-29 00:06:59 +0100 |
commit | e03c16edbfcaaa03337899dd2c46208e2f9040a5 (patch) | |
tree | 59d2b1bc2de7dd1b15f2c5df0e992fd4d01458ef | |
parent | b4f193ef70435485dbd83b2051cabb85a821dadd (diff) |
Work on rendering pipeline
-rw-r--r-- | src/render.c | 46 | ||||
-rw-r--r-- | src/sc_interp.c | 38 | ||||
-rw-r--r-- | src/sc_interp.h | 3 | ||||
-rw-r--r-- | tests/render_test.c | 3 | ||||
-rw-r--r-- | tests/render_test_sc1.c | 3 |
5 files changed, 60 insertions, 33 deletions
diff --git a/src/render.c b/src/render.c index 63b3804..49ff5c3 100644 --- a/src/render.c +++ b/src/render.c @@ -1,7 +1,7 @@ /* * render.c * - * Copyright © 2013 Thomas White <taw@bitwiz.org.uk> + * Copyright © 2013-2014 Thomas White <taw@bitwiz.org.uk> * * This file is part of Colloquium. * @@ -281,14 +281,35 @@ static int draw_frame(cairo_t *cr, struct frame *fr, ImageStore *is, } +static int recursive_wrap_and_draw(struct frame *fr, cairo_t *cr, + ImageStore *is, enum is_size isz) +{ + int i; + + /* Wrap boxes -> wrap lines */ + wrap_contents(fr); + + /* Actually draw the lines */ + draw_frame(cr, fr, is, isz); + + for ( i=0; i<fr->num_children; i++ ) { + cairo_save(cr); + cairo_translate(cr, fr->children[i]->x, fr->children[i]->y); + recursive_wrap_and_draw(fr->children[i], cr, is, isz); + cairo_restore(cr); + } + + return 0; +} + + static int render_frame(cairo_t *cr, struct frame *fr, ImageStore *is, enum is_size isz, struct slide_constants *scc, struct presentation_constants *pcc, - PangoContext *pc) + PangoContext *pc, SCBlock *scblocks) { SCInterpreter *scin; int i; - SCBlock *bl = fr->scblocks; scin = sc_interp_new(pc, fr); if ( scin == NULL ) { @@ -312,20 +333,9 @@ static int render_frame(cairo_t *cr, struct frame *fr, ImageStore *is, initialise_line(fr->boxes); /* SCBlocks -> frames and wrap boxes (preferably re-using frames) */ - sc_interp_add_blocks(scin, bl); + sc_interp_add_blocks(scin, scblocks, fr->scblocks); - /* Wrap boxes -> wrap lines */ - wrap_contents(fr); - - /* Actually draw the lines */ - draw_frame(cr, fr, is, isz); - - for ( i=0; i<fr->num_children; i++ ) { - cairo_save(cr); - cairo_translate(cr, fr->children[i]->x, fr->children[i]->y); - render_frame(cr, fr->children[i], is, isz, scc, pcc, pc); - cairo_restore(cr); - } + recursive_wrap_and_draw(fr, cr, is, isz); sc_interp_destroy(scin); @@ -416,7 +426,7 @@ cairo_surface_t *render_slide(struct slide *s, int w, double ww, double hh, pango_cairo_update_context(cr, pc); render_frame(cr, s->top, is, isz, s->constants, - s->parent->constants, pc); + s->parent->constants, pc, s->parent->scblocks); cairo_font_options_destroy(fopts); g_object_unref(pc); @@ -479,7 +489,7 @@ int export_pdf(struct presentation *p, const char *filename) s->top->h = w*r; render_frame(cr, s->top, p->is, ISZ_SLIDESHOW, s->constants, - s->parent->constants, pc); + s->parent->constants, pc, s->parent->scblocks); cairo_show_page(cr); diff --git a/src/sc_interp.c b/src/sc_interp.c index 5f025c0..78a5589 100644 --- a/src/sc_interp.c +++ b/src/sc_interp.c @@ -71,6 +71,8 @@ struct _scinterp struct sc_state *state; int j; /* Index of the current state */ int max_state; + + int output; }; @@ -255,6 +257,8 @@ SCInterpreter *sc_interp_new(PangoContext *pc, struct frame *top) scin->s_constants = NULL; scin->p_constants = NULL; + scin->output = 0; + /* FIXME: Determine proper language (somehow...) */ scin->lang = pango_language_from_string("en_GB"); @@ -428,7 +432,6 @@ static int parse_image_option(const char *opt, struct frame *parent, } - static int parse_image_options(const char *opth, struct frame *parent, double *wp, double *hp, char **filenamep) { @@ -497,12 +500,16 @@ static int check_outputs(SCBlock *bl, SCInterpreter *scin) } } else if ( strcmp(name, "slidenumber")==0) { - char *tmp = malloc(64); - if ( tmp != NULL ) { - snprintf(tmp, 63, "%i", - scin->s_constants->slide_number); - split_words(sc_interp_get_frame(scin)->boxes, - scin->pc, tmp, scin->lang, 0, scin); + if ( scin->s_constants != NULL ) { + char *tmp = malloc(64); + if ( tmp != NULL ) { + snprintf(tmp, 63, "%i", + scin->s_constants->slide_number); + split_words(sc_interp_get_frame(scin)->boxes, + scin->pc, tmp, scin->lang, 0, scin); + } + } else { + printf("No slide constants.\n"); } } else if ( strcmp(name, "f")==0 ) { @@ -538,7 +545,7 @@ static int check_outputs(SCBlock *bl, SCInterpreter *scin) } -int sc_interp_add_blocks(SCInterpreter *scin, SCBlock *bl) +int sc_interp_add_blocks(SCInterpreter *scin, SCBlock *bl, SCBlock *output) { while ( bl != NULL ) { @@ -546,11 +553,16 @@ int sc_interp_add_blocks(SCInterpreter *scin, SCBlock *bl) const char *options = sc_block_options(bl); SCBlock *child = sc_block_child(bl); + if ( bl == output ) { + scin->output = 1; + show_sc_block(bl, ""); + } + if ( child != NULL ) { sc_interp_save(scin); } - if ( (sc_interp_get_frame(scin) != NULL) + if ( scin->output && (sc_interp_get_frame(scin) != NULL) && check_outputs(bl, scin) ) { /* Block handled as output thing */ @@ -565,15 +577,17 @@ int sc_interp_add_blocks(SCInterpreter *scin, SCBlock *bl) } else { - fprintf(stderr, "Don't know what to do with this:\n"); - show_sc_block(bl, ""); + //fprintf(stderr, "Don't know what to do with this:\n"); + //show_sc_block(bl, ""); } if ( child != NULL ) { - sc_interp_add_blocks(scin, child); + sc_interp_add_blocks(scin, child, output); sc_interp_restore(scin); } + + if ( bl == output ) return 0; bl = sc_block_next(bl); } diff --git a/src/sc_interp.h b/src/sc_interp.h index 80b1e70..648df91 100644 --- a/src/sc_interp.h +++ b/src/sc_interp.h @@ -37,7 +37,8 @@ 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, SCBlock *bl); +extern int sc_interp_add_blocks(SCInterpreter *scin, SCBlock *bl, + SCBlock *last); /* Get the current state of the interpreter */ extern struct frame *sc_interp_get_frame(SCInterpreter *scin); diff --git a/tests/render_test.c b/tests/render_test.c index 88bcf6a..deaacca 100644 --- a/tests/render_test.c +++ b/tests/render_test.c @@ -38,7 +38,7 @@ #include "../src/presentation.h" -const char *sc = "\\font[Sorts Mill Goudy 32]Lorem ipsum dolor sit amet, consect-etur adipiscing elit.\n\\font[Serif 17]Donec a diam lectus. Sed sit amet ipsum mauris. Maecenas congue ligula ac quam viverra nec consectetur ante hendrerit. Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. \\font[Edrip 32]{Nam tincidunt congue enim, ut porta lorem \\font[Edrip Bold 32]{lacinia} consectetur.} Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean ut gravida lorem. Ut turpis felis, pulvinar a semper sed, adipiscing id dolor. Pellentesque auctor nisi id magna consequat sagittis. Curabitur dapibus enim sit amet elit pharetra tincidunt feugiat nisl imperdiet. Ut convallis libero in urna ultrices accumsan. Donec sed odio eros. Donec viverra mi quis quam pulvinar at malesuada arcu rhoncus. \\font[Serif Bold 17]{Cum sociis natoque penatibus et magnis dis parturient} montes, nascetur ridiculus mus. In rutrum accumsan ultricies. Mauris vitae nisi at sem facilisis semper ac in est."; +const char *sc = "\\demo{\\font[Sorts Mill Goudy 32]Lorem ipsum dolor sit amet, consect-etur adipiscing elit.\n\\font[Serif 17]Donec a diam lectus. Sed sit amet ipsum mauris. Maecenas congue ligula ac quam viverra nec consectetur ante hendrerit. Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. \\font[Edrip 32]{Nam tincidunt congue enim, ut porta lorem \\font[Edrip Bold 32]{lacinia} consectetur.} Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit. \\wibble{Aenean} ut gravida lorem. Ut turpis felis, pulvinar a semper sed, adipiscing id dolor. Pellentesque auctor nisi id magna consequat sagittis. Curabitur dapibus enim sit amet elit pharetra tincidunt feugiat nisl imperdiet. Ut convallis libero in urna ultrices accumsan. Donec sed odio eros. Donec viverra mi quis quam pulvinar at malesuada arcu rhoncus. \\font[Serif Bold 17]{Cum sociis natoque penatibus et magnis dis parturient} montes, nascetur ridiculus mus. In rutrum accumsan ultricies. Mauris vitae nisi at sem facilisis semper ac in est.}"; static gint mw_destroy(GtkWidget *w, void *p) { @@ -100,6 +100,7 @@ int main(int argc, char *argv[]) s.parent = &p; p.constants = NULL; + p.scblocks = fr->scblocks; window = gtk_window_new(GTK_WINDOW_TOPLEVEL); diff --git a/tests/render_test_sc1.c b/tests/render_test_sc1.c index 63c59d7..6a3dd51 100644 --- a/tests/render_test_sc1.c +++ b/tests/render_test_sc1.c @@ -36,7 +36,7 @@ #include "../src/frame.h" -const char *sc = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec a diam lectus. Sed sit amet ipsum mauris. Maecenas congue ligula ac quam viverra nec consectetur ante hendrerit. Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. \\f[0.5fx0.5f+100+40]{\\bgcol[#ff00ff]Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean ut gravida lorem. Ut turpis felis, pulvinar a semper sed, adipiscing id dolor. Pellentesque auctor nisi id magna consequat sagittis. Curabitur dapibus enim sit amet elit pharetra tincidunt feugiat nisl imperdiet. Ut convallis libero in urna ultrices accumsan. Donec sed odio eros.} Donec viverra mi quis quam pulvinar at malesuada arcu rhoncus. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. In rutrum accumsan ultricies. Mauris vitae nisi at sem facilisis semper ac in est."; +const char *sc = "\\demo{Lorem ipsum dolor sit amet, consectetur adipiscing elit. Donec a diam lectus. Sed sit amet ipsum mauris. Maecenas congue ligula ac quam viverra nec consectetur ante hendrerit. Donec et mollis dolor. Praesent et diam eget libero egestas mattis sit amet vitae augue. Nam tincidunt congue enim, ut porta lorem lacinia consectetur. \\f[0.5fx0.5f+100+40]{\\bgcol[#ff00ff]Donec ut libero sed arcu vehicula ultricies a non tortor. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean ut gravida lorem. Ut turpis felis, pulvinar a semper sed, adipiscing id dolor. Pellentesque auctor nisi id magna consequat sagittis. Curabitur dapibus enim sit amet elit pharetra tincidunt feugiat nisl imperdiet. Ut convallis libero in urna ultrices accumsan. Donec sed odio eros.} Donec viverra mi quis quam pulvinar at malesuada arcu rhoncus. Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. In rutrum accumsan ultricies. Mauris vitae nisi at sem facilisis semper ac in est.}"; static gint mw_destroy(GtkWidget *w, void *p) @@ -98,6 +98,7 @@ int main(int argc, char *argv[]) s.constants = NULL; p.constants = NULL; + p.scblocks = fr->scblocks; window = gtk_window_new(GTK_WINDOW_TOPLEVEL); |