From acdafca75a2ba0cc2b759e682add882a782f6cd0 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Wed, 19 Dec 2018 19:41:13 +0100 Subject: Maths stuff --- src/sc_interp.c | 25 +++++++++++++++++++++++++ src/sc_parse.c | 24 ++++++++++++++++++++++-- 2 files changed, 47 insertions(+), 2 deletions(-) diff --git a/src/sc_interp.c b/src/sc_interp.c index 07f09a5..ae746f6 100644 --- a/src/sc_interp.c +++ b/src/sc_interp.c @@ -986,6 +986,18 @@ static void output_frame(SCInterpreter *scin, SCBlock *bl, Stylesheet *ss, } +static cairo_surface_t *draw_maths(int w, int h, void *bvp, void *vp) +{ + SCBlock *bl = bvp; + cairo_surface_t *surf; + + surf = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, w, h); + printf("maths! '%s'\n", sc_block_contents(sc_block_child(bl))); + printf("render at %i x %i\n", w, h); + return surf; +} + + static int check_outputs(SCBlock *bl, SCInterpreter *scin, Stylesheet *ss) { const char *name = sc_block_name(bl); @@ -1009,6 +1021,19 @@ static int check_outputs(SCBlock *bl, SCInterpreter *scin, Stylesheet *ss) options); } + } else if ( (strcmp(name, "maths")==0) || (strcmp(name, "math")==0) ) { + double w, h; + char *filename; + if ( parse_image_options(options, sc_interp_get_frame(scin), + &w, &h, &filename) == 0 ) + { + add_callback_para(sc_interp_get_frame(scin), bl, + w, h, draw_maths, NULL, bl, NULL); + } else { + fprintf(stderr, _("Invalid image options '%s'\n"), + options); + } + } else if ( strcmp(name, "f")==0 ) { output_frame(scin, bl, ss, "$.slide.frame"); diff --git a/src/sc_parse.c b/src/sc_parse.c index 78f5799..b780046 100644 --- a/src/sc_parse.c +++ b/src/sc_parse.c @@ -480,8 +480,10 @@ static int get_subexpr(const char *sc, char *bk, char **pcontents, int *err) for ( i=0; i0) && (sc[i-1] == '\\')) ) { /* not escaped? */ + bct--; + } } if ( bct == 0 ) { found = 1; @@ -619,6 +621,17 @@ SCBlock *sc_parse(const char *sc) bl = NULL; len = strlen(sc); + + /* Starts and ends with '$' ---> no processing */ + if ( (sc[0] == '$') && (sc[len-1] == '$') ) { + char *nbl; + bl = sc_block_new(); + if ( bl == NULL ) return NULL; + nbl = strndup(sc+1, len-2); + sc_block_set_contents(bl, nbl); + return bl; + } + tbuf = malloc(len+1); if ( tbuf == NULL ) { sc_block_free(bl); @@ -642,6 +655,13 @@ SCBlock *sc_parse(const char *sc) continue; } + /* Escaped bracket? */ + if ( sc[i+1] == '}' ) { + tbuf[j++] = '}'; + i += 2; + continue; + } + /* No, it's a real block. Dispatch the previous block */ if ( j != 0 ) { tbuf[j] = '\0'; -- cgit v1.2.3