From d7cf85134ea2559de04fbb094b1308b80e51f336 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Wed, 17 Oct 2018 15:28:59 +0200 Subject: Initial style lookup --- src/sc_interp.c | 26 ++++++++++++++++++++++---- stylesheet.json | 56 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ tests/meson.build | 7 ++++--- 3 files changed, 82 insertions(+), 7 deletions(-) create mode 100644 stylesheet.json diff --git a/src/sc_interp.c b/src/sc_interp.c index ed49597..b603c61 100644 --- a/src/sc_interp.c +++ b/src/sc_interp.c @@ -1085,6 +1085,27 @@ static int check_outputs(SCBlock *bl, SCInterpreter *scin, Stylesheet *ss) } +static void apply_style(SCInterpreter *scin, Stylesheet *ss, const char *path) +{ + char fullpath[256]; + size_t len; + char *bgcol1; + + len = strlen(path); + if ( len > 160 ) { + fprintf(stderr, "Can't apply style: path too long.\n"); + return; + } + + strcpy(fullpath, path); + strcat(fullpath, ".bggradv"); + bgcol1 = stylesheet_lookup(ss, fullpath); + set_bggrad(scin, bgcol1, GRAD_VERT); + + update_bg(scin); +} + + int sc_interp_add_block(SCInterpreter *scin, SCBlock *bl, Stylesheet *ss) { const char *name = sc_block_name(bl); @@ -1107,10 +1128,7 @@ int sc_interp_add_block(SCInterpreter *scin, SCBlock *bl, Stylesheet *ss) } else if ( strcmp(name, "presentation") == 0 ) { maybe_recurse_before(scin, child); - set_bgcol(scin, "#ff00ff"); - update_bg(scin); - printf("pres\n"); - /* FIXME: Apply narrative style */ + apply_style(scin, ss, "$.narrative"); maybe_recurse_after(scin, child, ss); } else if ( strcmp(name, "slide") == 0 ) { diff --git a/stylesheet.json b/stylesheet.json new file mode 100644 index 0000000..518c21b --- /dev/null +++ b/stylesheet.json @@ -0,0 +1,56 @@ +{ + "narrative": { + "font": "Comfortaa 20", + "fgcol": "#000000", + "bggradv": "#729fcf,#d3d7cf" + }, + + "slide": { + "width": 1280, + "height": 720, + "bggrad": "vertical", + "bgcol1": "#729fcf", + "bgcol2": "#d3d7cf", + "frame": { + "font": "Comfortaa 20" + }, + "slidetitle": { + "width": "1f", + "height": "90u", + "posx": 0, + "posy": 0, + "padl": 30, + "padr": 30, + "padt": 30, + "padb": 30, + "fgcol": "#000000", + "font": "Comfortaa Bold 40" + }, + "prestitle": { + "width": "1f", + "height": "240u", + "posx": 0, + "posy": 160, + "padl": 50, + "padr": 50, + "padt": 50, + "padb": 50, + "fgcol": "#000000", + "font": "Comfortaa Bold 45", + "alignment": "center" + }, + "author": { + "width": "1f", + "height": "240u", + "posx": 0, + "posy": 360, + "padl": 80, + "padr": 80, + "padt": 80, + "padb": 80, + "fgcol": "#000000", + "font": "Comfortaa 20", + "alignment": "center" + } + } +} diff --git a/tests/meson.build b/tests/meson.build index c919e35..dee9a47 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -1,17 +1,18 @@ basic_rendering = ['../src/render.c', '../src/frame.c', '../src/sc_parse.c', '../src/imagestore.c', - '../src/sc_interp.c', '../src/utils.c'] + '../src/sc_interp.c', '../src/utils.c', + '../src/stylesheet.c'] e = executable('storycode_test', 'storycode_test.c', '../src/sc_parse.c', dependencies : [gtkdep]) test('Simple StoryCode parsing', e) e = executable('render_test', 'render_test.c', basic_rendering, - dependencies : [gtkdep, mdep]) + dependencies : [gtkdep, mdep, jsondep]) test('Simple rendering', e) e = executable('render_test_sc1', 'render_test_sc1.c', basic_rendering, - dependencies : [gtkdep, mdep]) + dependencies : [gtkdep, mdep, jsondep]) test('Simple StoryCode rendering', e) e = executable('json_test', 'json_test.c', '../src/sc_parse.c', -- cgit v1.2.3