Initial style lookup
authorThomas White <taw@bitwiz.me.uk>
Wed, 17 Oct 2018 13:28:59 +0000 (15:28 +0200)
committerThomas White <taw@bitwiz.me.uk>
Wed, 17 Oct 2018 13:28:59 +0000 (15:28 +0200)
src/sc_interp.c
stylesheet.json [new file with mode: 0644]
tests/meson.build

index ed49597..b603c61 100644 (file)
@@ -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 (file)
index 0000000..518c21b
--- /dev/null
@@ -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"
+               }
+       }
+}
index c919e35..dee9a47 100644 (file)
@@ -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',