aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas White <taw@bitwiz.me.uk>2018-12-19 19:41:13 +0100
committerThomas White <taw@bitwiz.me.uk>2018-12-19 19:41:13 +0100
commitacdafca75a2ba0cc2b759e682add882a782f6cd0 (patch)
tree16476c5cca2942ea74a058133edccdf9daa35d0f
parentc41fa6a9efb39e4fd0a964b7a83000647e4d32bf (diff)
Maths stuffwip
-rw-r--r--src/sc_interp.c25
-rw-r--r--src/sc_parse.c24
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; i<ml; i++ ) {
if ( sc[i] == bk[0] ) {
bct++;
- } else if ( sc[i] == bk[1] ) {
- bct--;
+ } else if ( sc[i] == bk[1] ) { /* closing bracket? */
+ if ( !((i>0) && (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';