From 28bc23c38f2d8f88667671b5b78a79f22e56e6b0 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Wed, 17 Oct 2018 10:18:44 +0200 Subject: Add JSON stylesheet test --- meson.build | 1 + test.ss | 18 ++++++++++ tests/json_test.c | 102 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ tests/meson.build | 4 +++ 4 files changed, 125 insertions(+) create mode 100644 test.ss create mode 100644 tests/json_test.c diff --git a/meson.build b/meson.build index a2e3fb2..9fda400 100644 --- a/meson.build +++ b/meson.build @@ -19,6 +19,7 @@ subdir('po') # Dependencies gtkdep = dependency('gtk+-3.0') +jsondep = dependency('json-glib-1.0') cc = meson.get_compiler('c') mdep = cc.find_library('m', required : false) diff --git a/test.ss b/test.ss new file mode 100644 index 0000000..2dd2b40 --- /dev/null +++ b/test.ss @@ -0,0 +1,18 @@ +{ + "narrative": { + "font": "Cantarell Regular 14", + "fgcol": "#000000" + }, + + "slide": { + "bggrad": null, + "bgcol1": "#ffffff", + "frame": { + "font": "Cantarell Regular 14", + "bggrad": "vertical", + "bgcol1": "#000099", + "bgcol2": "#000000" + } + } +} + diff --git a/tests/json_test.c b/tests/json_test.c new file mode 100644 index 0000000..96323cb --- /dev/null +++ b/tests/json_test.c @@ -0,0 +1,102 @@ +/* + * storycode_test.c + * + * Colloquium - A tiny presentation program + * + * Copyright (c) 2012 Thomas White + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include +#include +#include +#include + +#include "../src/sc_parse.h" + +typedef struct { + JsonNode *root; +} Stylesheet; + + +Stylesheet *stylesheet_load(const char *filename) +{ + JsonParser *parser; + gboolean r; + GError *err = NULL; + Stylesheet *ss; + + ss = calloc(1, sizeof(Stylesheet)); + if ( ss == NULL ) return NULL; + + parser = json_parser_new(); + + r = json_parser_load_from_file(parser, filename, &err); + if ( r == FALSE ) { + fprintf(stderr, "Failed to load style sheet: '%s'\n", err->message); + return NULL; + } + + ss->root = json_parser_steal_root(parser); + g_object_unref(parser); + + return ss; +} + + +char *stylesheet_lookup(Stylesheet *ss, const char *path) +{ + JsonNode *node; + JsonArray *array; + GError *err = NULL; + char *ret; + const gchar *v; + + node = json_path_query(path, ss->root, &err); + array = json_node_get_array(node); + + v = json_array_get_string_element(array, 0); + if ( v == NULL ) return NULL; + + ret = strdup(v); + json_node_unref(node); + return ret; +} + + +int main(int argc, char *argv[]) +{ + SCBlock *bl; + Stylesheet *ss; + + ss = stylesheet_load("test.ss"); + printf("Frame background: '%s'\n", stylesheet_lookup(ss, "$.slide.frame.bgcol1")); + + bl = sc_parse("\\wibble{}\\f{wibble \\bg[muhu]{wobble\nwibble\nwabble}}\\frib[\\f] f"); + if ( bl == NULL ) { + printf("Failed to parse SC\n"); + return 1; + } + + show_sc_blocks(bl); + + return 0; +} diff --git a/tests/meson.build b/tests/meson.build index 427faae..c919e35 100644 --- a/tests/meson.build +++ b/tests/meson.build @@ -13,3 +13,7 @@ test('Simple rendering', e) e = executable('render_test_sc1', 'render_test_sc1.c', basic_rendering, dependencies : [gtkdep, mdep]) test('Simple StoryCode rendering', e) + +e = executable('json_test', 'json_test.c', '../src/sc_parse.c', + dependencies : [mdep, jsondep]) +test('JSON parsing', e) -- cgit v1.2.3 From 8ff33c21355382dd1e0697b8e3e9455d63c831f9 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Wed, 17 Oct 2018 11:14:22 +0200 Subject: Strip out macro system --- src/narrative_window.c | 11 +- src/presentation.c | 16 +-- src/render.c | 15 ++- src/sc_interp.c | 345 +----------------------------------------------- src/stylesheet_editor.c | 50 +------ 5 files changed, 19 insertions(+), 418 deletions(-) diff --git a/src/narrative_window.c b/src/narrative_window.c index e549fc1..1631f2f 100644 --- a/src/narrative_window.c +++ b/src/narrative_window.c @@ -187,14 +187,9 @@ static void delete_slide_sig(GSimpleAction *action, GVariant *parameter, static struct template_id *get_templates(SCBlock *ss, int *n) { - struct template_id *list; - SCInterpreter *scin; - - scin = sc_interp_new(NULL, NULL, NULL, NULL); - sc_interp_run_stylesheet(scin, ss); /* ss == NULL is OK */ - list = sc_interp_get_templates(scin, n); - sc_interp_destroy(scin); - return list; + /* FIXME: From JSON stylesheet */ + *n = 0; + return NULL; } diff --git a/src/presentation.c b/src/presentation.c index b8b4589..b3676b5 100644 --- a/src/presentation.c +++ b/src/presentation.c @@ -281,21 +281,7 @@ static void install_stylesheet(struct presentation *p) static void set_slide_size_from_stylesheet(struct presentation *p) { - SCInterpreter *scin; - double w, h; - int r; - - if ( p->stylesheet == NULL ) return; - - scin = sc_interp_new(NULL, NULL, NULL, NULL); - sc_interp_run_stylesheet(scin, p->stylesheet); /* ss == NULL is OK */ - r = sc_interp_get_slide_size(scin, &w, &h); - sc_interp_destroy(scin); - - if ( r == 0 ) { - p->slide_width = w; - p->slide_height = h; - } + /* FIXME: From JSON */ } diff --git a/src/render.c b/src/render.c index 580a4cd..0228a7b 100644 --- a/src/render.c +++ b/src/render.c @@ -183,7 +183,7 @@ struct frame *interp_and_shape(SCBlock *scblocks, SCBlock *stylesheet, PangoLanguage *lang) { SCInterpreter *scin; - char snum[64]; +// char snum[64]; struct frame *top; top = frame_new(); @@ -203,12 +203,13 @@ struct frame *interp_and_shape(SCBlock *scblocks, SCBlock *stylesheet, sc_interp_set_callbacks(scin, cbl); - snprintf(snum, 63, "%i", slide_number); - add_macro(scin, "slidenumber", snum); - - if ( stylesheet != NULL ) { - sc_interp_run_stylesheet(scin, stylesheet); - } + /* FIXME: Set up slide number and style sheet */ +// snprintf(snum, 63, "%i", slide_number); +// add_macro(scin, "slidenumber", snum); +// +// if ( stylesheet != NULL ) { +// sc_interp_run_stylesheet(scin, stylesheet); +// } top->fontdesc = pango_font_description_copy(sc_interp_get_fontdesc(scin)); top->col[0] = sc_interp_get_fgcol(scin)[0]; diff --git a/src/sc_interp.c b/src/sc_interp.c index dea8446..0ff04d7 100644 --- a/src/sc_interp.c +++ b/src/sc_interp.c @@ -38,14 +38,6 @@ #include "utils.h" -struct macro -{ - char *name; - SCBlock *bl; - struct macro *prev; /* Previous declaration, or NULL */ -}; - - struct template { char *name; @@ -72,24 +64,11 @@ struct sc_state struct frame *fr; /* The current frame */ - int n_macros; - int max_macros; - struct macro *macros; /* Contents need to be copied on push */ - - int n_styles; - int max_styles; - struct macro *styles; /* Contents need to be copied on push */ - int n_templates; int max_templates; struct template *templates; - - SCBlock *macro_contents; /* If running a macro, the child block of the caller */ - SCBlock *macro_real_block; /* If running a macro, the block which called the macro */ - int macro_editable; /* If running a macro, whether this bit can be edited or not */ }; - struct _scinterp { PangoContext *pc; @@ -245,9 +224,6 @@ static int check_callback(SCInterpreter *scin, SCBlock *bl) SCBlock *rbl; rbl = bl; - if ( sc_interp_get_macro_real_block(scin) != NULL ) { - bl = sc_interp_get_macro_real_block(scin); - } if ( strcmp(cbl->names[i], name) != 0 ) continue; r = cbl->box_funcs[i](scin, bl, &w, &h, &bvp, cbl->vps[i]); @@ -611,13 +587,6 @@ struct frame *sc_interp_get_frame(SCInterpreter *scin) } -SCBlock *sc_interp_get_macro_real_block(SCInterpreter *scin) -{ - struct sc_state *st = &scin->state[scin->j]; - return st->macro_real_block; -} - - static void set_frame(SCInterpreter *scin, struct frame *fr) { struct sc_state *st = &scin->state[scin->j]; @@ -649,22 +618,6 @@ SCInterpreter *sc_interp_new(PangoContext *pc, PangoLanguage *lang, scin->cbl = NULL; st = &scin->state[0]; - st->n_macros = 0; - st->max_macros = 16; - st->macros = malloc(16*sizeof(struct macro)); - if ( st->macros == NULL ) { - free(scin->state); - free(scin); - return NULL; - } - st->n_styles = 0; - st->max_styles = 16; - st->styles = malloc(16*sizeof(struct macro)); - if ( st->styles == NULL ) { - free(scin->state); - free(scin); - return NULL; - } st->n_templates = 0; st->max_templates = 16; st->templates = malloc(16*sizeof(struct template)); @@ -673,9 +626,6 @@ SCInterpreter *sc_interp_new(PangoContext *pc, PangoLanguage *lang, free(scin); return NULL; } - st->macro_contents = NULL; - st->macro_real_block = NULL; - st->macro_editable = 0; st->fr = NULL; st->paraspace[0] = 0.0; st->paraspace[1] = 0.0; @@ -713,7 +663,7 @@ SCInterpreter *sc_interp_new(PangoContext *pc, PangoLanguage *lang, void sc_interp_destroy(SCInterpreter *scin) { - /* FIXME: Free all templates and macros */ + /* FIXME: Free all templates */ /* Empty the stack */ while ( scin->j > 0 ) { @@ -1024,14 +974,6 @@ static void maybe_recurse_after(SCInterpreter *scin, SCBlock *child) } -static int in_macro(SCInterpreter *scin) -{ - struct sc_state *st = &scin->state[scin->j]; - if ( st->macro_contents == NULL ) return 0; - return 1; -} - - static void add_newpara(struct frame *fr, SCBlock *bl, SCBlock *mrb) { Paragraph *last_para; @@ -1065,9 +1007,6 @@ static int add_text(struct frame *fr, PangoContext *pc, SCBlock *bl, col = sc_interp_get_fgcol(scin); rbl = bl; - if ( st->macro_real_block != NULL ) { - bl = st->macro_real_block; - } para = last_para(fr); if ( (para == NULL) || (para_type(para) != PARA_TYPE_TEXT) ) { @@ -1085,26 +1024,11 @@ static int add_text(struct frame *fr, PangoContext *pc, SCBlock *bl, } -void sc_interp_run_style(SCInterpreter *scin, const char *sname) -{ - int i; - struct sc_state *st = &scin->state[scin->j]; - - for ( i=0; in_styles; i++ ) { - if ( strcmp(sname, st->styles[i].name) == 0 ) { - sc_interp_add_blocks(scin, st->styles[i].bl); - return; - } - } -} - - static int check_outputs(SCBlock *bl, SCInterpreter *scin) { const char *name = sc_block_name(bl); const char *options = sc_block_options(bl); SCBlock *child = sc_block_child(bl); - struct sc_state *st = &scin->state[scin->j]; if ( name == NULL ) { add_text(sc_interp_get_frame(scin), @@ -1117,9 +1041,6 @@ static int check_outputs(SCBlock *bl, SCInterpreter *scin) &w, &h, &filename) == 0 ) { SCBlock *rbl = bl; - if ( st->macro_real_block != NULL ) { - bl = st->macro_real_block; - } add_image_para(sc_interp_get_frame(scin), bl, rbl, filename, scin->is, w, h, 1); free(filename); @@ -1134,11 +1055,7 @@ static int check_outputs(SCBlock *bl, SCInterpreter *scin) fr = add_subframe(sc_interp_get_frame(scin)); fr->scblocks = bl; - if ( in_macro(scin) ) { - fr->resizable = 0; - } else { - fr->resizable = 1; - } + fr->resizable = 1; if ( fr == NULL ) { fprintf(stderr, _("Failed to add frame.\n")); return 1; @@ -1150,16 +1067,13 @@ static int check_outputs(SCBlock *bl, SCInterpreter *scin) maybe_recurse_before(scin, child); set_frame(scin, fr); - sc_interp_run_style(scin, "frame"); + /* FIXME: Set frame style */ maybe_recurse_after(scin, child); } else if ( strcmp(name, "newpara")==0 ) { struct frame *fr = sc_interp_get_frame(scin); SCBlock *rbl = bl; - if ( st->macro_real_block != NULL ) { - bl = st->macro_real_block; - } add_newpara(fr, bl, rbl); } else { @@ -1170,67 +1084,6 @@ static int check_outputs(SCBlock *bl, SCInterpreter *scin) } -static int check_macro(const char *name, SCInterpreter *scin) -{ - int i; - struct sc_state *st = &scin->state[scin->j]; - - if ( name == NULL ) return 0; - - for ( i=0; in_macros; i++ ) { - if ( strcmp(st->macros[i].name, name) == 0 ) { - return 1; - } - } - - return 0; -} - - -static void exec_macro(SCBlock *bl, SCInterpreter *scin, SCBlock *child) -{ - struct sc_state *st = &scin->state[scin->j]; - int i; - const char *name; - - name = sc_block_name(bl); - for ( i=0; in_macros; i++ ) { - if ( strcmp(st->macros[i].name, name) == 0 ) { - sc_interp_save(scin); - scin->state[scin->j].macro_real_block = bl; - scin->state[scin->j].macro_contents = child; - sc_interp_add_blocks(scin, scin->state[scin->j].macros[i].bl); - sc_interp_restore(scin); - break; /* Stop iterating, because "st" is now invalid */ - } - } -} - - -static void run_macro_contents(SCInterpreter *scin) -{ - struct sc_state *st = &scin->state[scin->j]; - SCBlock *contents = st->macro_contents; - - sc_interp_save(scin); - scin->state[scin->j].macro_real_block = NULL; - sc_interp_add_blocks(scin, contents); - sc_interp_restore(scin); -} - - -static void run_editable(SCInterpreter *scin, SCBlock *contents) -{ - //struct sc_state *st = &scin->state[scin->j]; - - sc_interp_save(scin); - //scin->state[scin->j].macro_real_block = NULL; - scin->state[scin->j].macro_editable = 1; - sc_interp_add_blocks(scin, contents); - sc_interp_restore(scin); -} - - int sc_interp_add_block(SCInterpreter *scin, SCBlock *bl) { const char *name = sc_block_name(bl); @@ -1241,12 +1094,7 @@ int sc_interp_add_block(SCInterpreter *scin, SCBlock *bl) //show_sc_blocks(bl); //printf("<------------\n"); - if ( check_macro(name, scin) ) { - sc_interp_save(scin); - exec_macro(bl, scin, child); - sc_interp_restore(scin); - - } else if ( check_callback(scin, bl) ) { + if ( check_callback(scin, bl) ) { /* Handled in check_callback, don't do anything else */ } else if ((sc_interp_get_frame(scin) != NULL) @@ -1258,7 +1106,7 @@ int sc_interp_add_block(SCInterpreter *scin, SCBlock *bl) } else if ( strcmp(name, "presentation") == 0 ) { maybe_recurse_before(scin, child); - sc_interp_run_style(scin, "narrative"); + /* FIXME: Apply narrative style */ maybe_recurse_after(scin, child); } else if ( strcmp(name, "stylesheet") == 0 ) { @@ -1266,7 +1114,7 @@ int sc_interp_add_block(SCInterpreter *scin, SCBlock *bl) } else if ( strcmp(name, "slide") == 0 ) { maybe_recurse_before(scin, child); - sc_interp_run_style(scin, "slide"); + /* FIXME: Apply slide style */ maybe_recurse_after(scin, child); } else if ( strcmp(name, "font") == 0 ) { @@ -1314,12 +1162,6 @@ int sc_interp_add_block(SCInterpreter *scin, SCBlock *bl) set_colour(scin, options); maybe_recurse_after(scin, child); - } else if ( strcmp(name, "contents") == 0 ) { - run_macro_contents(scin); - - } else if ( strcmp(name, "editable") == 0 ) { - run_editable(scin, child); - } else if ( strcmp(name, "pad") == 0 ) { maybe_recurse_before(scin, child); set_padding(sc_interp_get_frame(scin), options); @@ -1370,102 +1212,6 @@ int sc_interp_add_blocks(SCInterpreter *scin, SCBlock *bl) } -static int try_add_style(SCInterpreter *scin, const char *options, SCBlock *bl) -{ - struct sc_state *st = &scin->state[scin->j]; - char *nn; - char *comma; - int i; - - nn = strdup(options); - comma = strchr(nn, ','); - if ( comma != NULL ) { - comma[0] = '\0'; - } - - for ( i=0; in_styles; i++ ) { - if ( strcmp(st->styles[i].name, nn) == 0 ) { - st->styles[i].name = nn; - st->styles[i].bl = bl; - st->styles[i].prev = NULL; /* FIXME: Stacking */ - return 0; - } - } - - if ( st->max_styles == st->n_styles ) { - - struct macro *styles_new; - - styles_new = realloc(st->styles, sizeof(struct macro) - * (st->max_styles+16)); - if ( styles_new == NULL ) { - fprintf(stderr, _("Failed to add style.\n")); - return 1; - } - - st->styles = styles_new; - st->max_styles += 16; - - } - - i = st->n_styles++; - - st->styles[i].name = nn; - st->styles[i].bl = bl; - st->styles[i].prev = NULL; /* FIXME: Stacking */ - - return 0; -} - - -static int try_add_macro(SCInterpreter *scin, const char *options, SCBlock *bl) -{ - struct sc_state *st = &scin->state[scin->j]; - char *nn; - char *comma; - int i; - - nn = strdup(options); - comma = strchr(nn, ','); - if ( comma != NULL ) { - comma[0] = '\0'; - } - - for ( i=0; in_macros; i++ ) { - if ( strcmp(st->macros[i].name, nn) == 0 ) { - st->macros[i].name = nn; - st->macros[i].bl = bl; - st->macros[i].prev = NULL; /* FIXME: Stacking */ - return 0; - } - } - - if ( st->max_macros == st->n_macros ) { - - struct macro *macros_new; - - macros_new = realloc(st->macros, sizeof(struct macro) - * (st->max_macros+16)); - if ( macros_new == NULL ) { - fprintf(stderr, _("Failed to add macro.\n")); - return 1; - } - - st->macros = macros_new; - st->max_macros += 16; - - } - - i = st->n_macros++; - - st->macros[i].name = nn; - st->macros[i].bl = bl; - st->macros[i].prev = NULL; /* FIXME: Stacking */ - - return 0; -} - - static int try_add_template(SCInterpreter *scin, const char *options, SCBlock *bl) { struct sc_state *st = &scin->state[scin->j]; @@ -1510,85 +1256,6 @@ static int try_add_template(SCInterpreter *scin, const char *options, SCBlock *b return 0; } -void add_macro(SCInterpreter *scin, const char *mname, const char *contents) -{ - SCBlock *bl = sc_parse(contents); - try_add_macro(scin, mname, bl); -} - - -void sc_interp_run_stylesheet(SCInterpreter *scin, SCBlock *bl) -{ - if ( bl == NULL ) return; - - if ( strcmp(sc_block_name(bl), "stylesheet") != 0 ) { - fprintf(stderr, _("Style sheet isn't a style sheet.\n")); - return; - } - - bl = sc_block_child(bl); - - while ( bl != NULL ) { - - const char *name = sc_block_name(bl); - const char *options = sc_block_options(bl); - - if ( name == NULL ) { - - /* Do nothing */ - - } else if ( strcmp(name, "def") == 0 ) { - try_add_macro(scin, options, sc_block_child(bl)); - - } else if ( strcmp(name, "ss") == 0 ) { /* Backward compatibility */ - try_add_macro(scin, options, sc_block_child(bl)); - - } else if ( strcmp(name, "style") == 0 ) { - try_add_style(scin, options, sc_block_child(bl)); - - } else if ( strcmp(name, "template") == 0 ) { - try_add_template(scin, options, sc_block_child(bl)); - - } else if ( strcmp(name, "font") == 0 ) { - set_font(scin, options); - - } else if ( strcmp(name, "fgcol") == 0 ) { - set_colour(scin, options); - - } else if ( strcmp(name, "bgcol") == 0 ) { - set_bgcol(scin, options); - update_bg(scin); - - } else if ( strcmp(name, "bggradh") == 0 ) { - set_bggrad(scin, options, GRAD_HORIZ); - update_bg(scin); - - } else if ( strcmp(name, "bggradv") == 0 ) { - set_bggrad(scin, options, GRAD_VERT); - update_bg(scin); - - } else if ( strcmp(name, "paraspace") == 0 ) { - set_paraspace(scin, options); - - } else if ( strcmp(name, "slidesize") == 0 ) { - set_slide_size(scin, options); - - } - - bl = sc_block_next(bl); - - } -} - - -int sc_interp_get_slide_size(SCInterpreter *scin, double *w, double *h) -{ - if ( !scin->state->have_size ) return 1; - *w = scin->state->slide_width; - *h = scin->state->slide_height; - return 0; -} - struct template_id *sc_interp_get_templates(SCInterpreter *scin, int *np) { diff --git a/src/stylesheet_editor.c b/src/stylesheet_editor.c index 66e8afa..508ee6a 100644 --- a/src/stylesheet_editor.c +++ b/src/stylesheet_editor.c @@ -491,55 +491,7 @@ static void set_from_interp_font(SCInterpreter *scin, GtkWidget *w) static void set_values_from_presentation(StylesheetEditor *se) { - SCInterpreter *scin; - PangoContext *pc; - - pc = gdk_pango_context_get(); - - scin = sc_interp_new(pc, NULL, NULL, NULL); - sc_interp_run_stylesheet(scin, se->priv->p->stylesheet); /* NULL stylesheet is OK */ - - /* Narrative style */ - sc_interp_save(scin); - sc_interp_run_style(scin, "narrative"); - set_from_interp_font(scin, se->narrative_style_font); - set_from_interp_col(sc_interp_get_fgcol(scin), se->narrative_style_fgcol); - set_from_interp_col(sc_interp_get_bgcol(scin), se->narrative_style_bgcol); - gtk_color_chooser_get_rgba(GTK_COLOR_CHOOSER(se->narrative_style_bgcol), - &se->narrative_bgcol); - set_from_interp_col(sc_interp_get_bgcol2(scin), se->narrative_style_bgcol2); - gtk_color_chooser_get_rgba(GTK_COLOR_CHOOSER(se->narrative_style_bgcol2), - &se->narrative_bgcol2); - set_from_interp_bggrad(scin, se->narrative_style_bggrad); - sc_interp_restore(scin); - - /* Slide style */ - sc_interp_save(scin); - sc_interp_run_style(scin, "slide"); - set_from_interp_col(sc_interp_get_bgcol(scin), se->slide_style_bgcol); - gtk_color_chooser_get_rgba(GTK_COLOR_CHOOSER(se->slide_style_bgcol), - &se->slide_bgcol); - set_from_interp_col(sc_interp_get_bgcol2(scin), se->slide_style_bgcol2); - gtk_color_chooser_get_rgba(GTK_COLOR_CHOOSER(se->slide_style_bgcol2), - &se->slide_bgcol2); - set_from_interp_bggrad(scin, se->slide_style_bggrad); - sc_interp_restore(scin); - - /* Slide->Frame style */ - sc_interp_save(scin); - sc_interp_run_style(scin, "frame"); - set_from_interp_font(scin, se->frame_style_font); - set_from_interp_col(sc_interp_get_fgcol(scin), se->frame_style_fgcol); - set_from_interp_col(sc_interp_get_bgcol(scin), se->frame_style_bgcol); - gtk_color_chooser_get_rgba(GTK_COLOR_CHOOSER(se->frame_style_bgcol), - &se->frame_bgcol); - set_from_interp_col(sc_interp_get_bgcol2(scin), se->frame_style_bgcol2); - gtk_color_chooser_get_rgba(GTK_COLOR_CHOOSER(se->frame_style_bgcol2), - &se->frame_bgcol2); - set_from_interp_bggrad(scin, se->frame_style_bggrad); - sc_interp_restore(scin); - - sc_interp_destroy(scin); + /* FIXME: From JSON */ } -- cgit v1.2.3 From 8f7480255e76fc27bcab5ab10ef6c15368c5c495 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Wed, 17 Oct 2018 14:49:42 +0200 Subject: Add JSON dependency --- meson.build | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/meson.build b/meson.build index 9fda400..818c34d 100644 --- a/meson.build +++ b/meson.build @@ -48,7 +48,7 @@ executable('colloquium', 'src/stylesheet_editor.c', ], gresources, - dependencies : [gtkdep, mdep], + dependencies : [gtkdep, mdep, jsondep], install : true) # Desktop file -- cgit v1.2.3 From 2b2a139a94c932d50a5ad5a5ab91f997493e5b5a Mon Sep 17 00:00:00 2001 From: Thomas White Date: Wed, 17 Oct 2018 14:50:28 +0200 Subject: Switch to new Stylesheet type --- meson.build | 1 + src/narrative_window.c | 36 +++----- src/presentation.c | 56 +----------- src/presentation.h | 5 +- src/render.c | 6 +- src/render.h | 4 +- src/sc_editor.c | 4 +- src/sc_editor.h | 7 +- src/stylesheet.c | 91 ++++++++++++++++++++ src/stylesheet.h | 36 ++++++++ src/stylesheet_editor.c | 224 ++---------------------------------------------- 11 files changed, 160 insertions(+), 310 deletions(-) create mode 100644 src/stylesheet.c create mode 100644 src/stylesheet.h diff --git a/meson.build b/meson.build index 818c34d..52b9243 100644 --- a/meson.build +++ b/meson.build @@ -45,6 +45,7 @@ executable('colloquium', 'src/print.c', 'src/sc_parse.c', 'src/utils.c', + 'src/stylesheet.c', 'src/stylesheet_editor.c', ], gresources, diff --git a/src/narrative_window.c b/src/narrative_window.c index 1631f2f..7a19562 100644 --- a/src/narrative_window.c +++ b/src/narrative_window.c @@ -185,7 +185,7 @@ static void delete_slide_sig(GSimpleAction *action, GVariant *parameter, } -static struct template_id *get_templates(SCBlock *ss, int *n) +static struct template_id *get_templates(Stylesheet *ss, int *n) { /* FIXME: From JSON stylesheet */ *n = 0; @@ -210,7 +210,7 @@ static void update_template_menus(NarrativeWindow *nw) } -static SCBlock *get_slide_template(SCBlock *ss) +static SCBlock *get_slide_template(Stylesheet *ss) { struct template_id *templates; int i, n_templates; @@ -244,36 +244,20 @@ static gint load_ss_response_sig(GtkWidget *d, gint response, if ( response == GTK_RESPONSE_ACCEPT ) { char *filename; - char *stext; + Stylesheet *new_ss; filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(d)); - printf("Loading %s\n",filename); - stext = load_everything(filename); - if ( stext != NULL ) { + new_ss = stylesheet_load(filename); + if ( new_ss != NULL ) { - SCBlock *bl; - SCBlock *ss; - bl = sc_parse(stext); - free(stext); - ss = find_stylesheet(bl); + stylesheet_free(nw->p->stylesheet); + nw->p->stylesheet = new_ss; + sc_editor_set_stylesheet(nw->sceditor, new_ss); - if ( ss != NULL ) { + /* Full rerender */ + sc_editor_set_scblock(nw->sceditor, nw->dummy_top); - /* Substitute the style sheet in - * presentation Storycode */ - replace_stylesheet(nw->p, ss); - - sc_editor_set_stylesheet(nw->sceditor, ss); - - /* Full rerender, first block may have - * changed */ - sc_editor_set_scblock(nw->sceditor, - nw->dummy_top); - - } else { - fprintf(stderr, _("Not a style sheet\n")); - } } else { fprintf(stderr, _("Failed to load\n")); } diff --git a/src/presentation.c b/src/presentation.c index b3676b5..c3f0d07 100644 --- a/src/presentation.c +++ b/src/presentation.c @@ -226,59 +226,6 @@ SCBlock *prev_slide(struct presentation *p, SCBlock *sl) } -int replace_stylesheet(struct presentation *p, SCBlock *ss) -{ - /* Create style sheet from union of old and new, - * preferring items from the new one */ - - /* If there was no stylesheet before, add a dummy one */ - if ( p->stylesheet == NULL ) { - p->stylesheet = sc_block_append_end(p->scblocks, - "stylesheet", NULL, NULL); - } - - /* Cut the old stylesheet out of the presentation, - * and put in the new one */ - sc_block_substitute(&p->scblocks, p->stylesheet, ss); - p->stylesheet = ss; - - return 0; -} - - -SCBlock *find_stylesheet(SCBlock *bl) -{ - while ( bl != NULL ) { - - const char *name = sc_block_name(bl); - - if ( (name != NULL) && (strcmp(name, "stylesheet") == 0) ) { - return bl; - } - - bl = sc_block_next(bl); - - } - - return NULL; -} - - -static void install_stylesheet(struct presentation *p) -{ - if ( p->stylesheet != NULL ) { - fprintf(stderr, _("Duplicate style sheet!\n")); - return; - } - - p->stylesheet = find_stylesheet(p->scblocks); - - if ( p->stylesheet == NULL ) { - fprintf(stderr, _("No style sheet.\n")); - } -} - - static void set_slide_size_from_stylesheet(struct presentation *p) { /* FIXME: From JSON */ @@ -310,7 +257,8 @@ int load_presentation(struct presentation *p, GFile *file) return r; /* Error */ } - install_stylesheet(p); + p->stylesheet = stylesheet_load("stylesheet.json"); /* FIXME: ! */ + set_slide_size_from_stylesheet(p); assert(p->uri == NULL); diff --git a/src/presentation.h b/src/presentation.h index ed8a188..ea3780e 100644 --- a/src/presentation.h +++ b/src/presentation.h @@ -34,6 +34,7 @@ struct presentation; #include "slideshow.h" #include "narrative_window.h" #include "slide_window.h" +#include "stylesheet.h" struct menu_pl; @@ -56,15 +57,13 @@ struct presentation double slide_width; double slide_height; - SCBlock *stylesheet; SCBlock *scblocks; + Stylesheet *stylesheet; }; extern struct presentation *new_presentation(const char *imagestore); -extern SCBlock *find_stylesheet(SCBlock *bl); -extern int replace_stylesheet(struct presentation *p, SCBlock *ss); extern void free_presentation(struct presentation *p); extern char *get_titlebar_string(struct presentation *p); diff --git a/src/render.c b/src/render.c index 0228a7b..041f812 100644 --- a/src/render.c +++ b/src/render.c @@ -176,7 +176,7 @@ int recursive_wrap(struct frame *fr, PangoContext *pc) } -struct frame *interp_and_shape(SCBlock *scblocks, SCBlock *stylesheet, +struct frame *interp_and_shape(SCBlock *scblocks, Stylesheet *stylesheet, SCCallbackList *cbl, ImageStore *is, int slide_number, PangoContext *pc, double w, double h, @@ -227,7 +227,7 @@ struct frame *interp_and_shape(SCBlock *scblocks, SCBlock *stylesheet, static struct frame *render_sc_with_context(SCBlock *scblocks, cairo_t *cr, double log_w, double log_h, - SCBlock *stylesheet, SCCallbackList *cbl, + Stylesheet *stylesheet, SCCallbackList *cbl, ImageStore *is, int slide_number, PangoLanguage *lang, PangoContext *pc) @@ -251,7 +251,7 @@ static struct frame *render_sc_with_context(SCBlock *scblocks, cairo_surface_t *render_sc(SCBlock *scblocks, int w, int h, double log_w, double log_h, - SCBlock *stylesheet, SCCallbackList *cbl, + Stylesheet *stylesheet, SCCallbackList *cbl, ImageStore *is, int slide_number, struct frame **ptop, PangoLanguage *lang) diff --git a/src/render.h b/src/render.h index aadb033..0cfae26 100644 --- a/src/render.h +++ b/src/render.h @@ -35,7 +35,7 @@ /* Convienience function to run the entire pipeline */ extern cairo_surface_t *render_sc(SCBlock *scblocks, int w, int h, double log_w, double log_h, - SCBlock *stylesheet, SCCallbackList *cbl, + Stylesheet *stylesheet, SCCallbackList *cbl, ImageStore *is, int slide_number, struct frame **ptop, PangoLanguage *lang); @@ -44,7 +44,7 @@ extern cairo_surface_t *render_sc(SCBlock *scblocks, int w, int h, * Needs to be followed by: wrap_contents() (recursively) * recursive_draw() */ -extern struct frame *interp_and_shape(SCBlock *scblocks, SCBlock *stylesheet, +extern struct frame *interp_and_shape(SCBlock *scblocks, Stylesheet *stylesheet, SCCallbackList *cbl, ImageStore *is, int slide_number, PangoContext *pc, diff --git a/src/sc_editor.c b/src/sc_editor.c index 999f919..0431b7b 100644 --- a/src/sc_editor.c +++ b/src/sc_editor.c @@ -2033,7 +2033,7 @@ void sc_editor_set_top_frame_editable(SCEditor *e, int top_frame_editable) } -void sc_editor_set_stylesheet(SCEditor *e, SCBlock *stylesheet) +void sc_editor_set_stylesheet(SCEditor *e, Stylesheet *stylesheet) { e->stylesheet = stylesheet; } @@ -2125,7 +2125,7 @@ void sc_editor_set_imagestore(SCEditor *e, ImageStore *is) } -SCEditor *sc_editor_new(SCBlock *scblocks, SCBlock *stylesheet, +SCEditor *sc_editor_new(SCBlock *scblocks, Stylesheet *stylesheet, PangoLanguage *lang, const char *storename) { SCEditor *sceditor; diff --git a/src/sc_editor.h b/src/sc_editor.h index adbbaf2..35557d4 100644 --- a/src/sc_editor.h +++ b/src/sc_editor.h @@ -32,6 +32,7 @@ #include "frame.h" #include "sc_interp.h" +#include "stylesheet.h" struct presentation; @@ -94,7 +95,7 @@ struct _sceditor double log_w; /* Size of surface in "SC units" */ double log_h; SCBlock *scblocks; - SCBlock *stylesheet; + Stylesheet *stylesheet; ImageStore *is; SCCallbackList *cbl; struct frame *top; @@ -168,10 +169,10 @@ typedef struct _sceditor SCEditor; typedef struct _sceditorclass SCEditorClass; extern void sc_editor_set_scblock(SCEditor *e, SCBlock *scblocks); -extern void sc_editor_set_stylesheet(SCEditor *e, SCBlock *stylesheet); +extern void sc_editor_set_stylesheet(SCEditor *e, Stylesheet *stylesheet); extern SCBlock *sc_editor_get_scblock(SCEditor *e); extern GtkWidget *sc_editor_get_widget(SCEditor *e); -extern SCEditor *sc_editor_new(SCBlock *scblocks, SCBlock *stylesheet, +extern SCEditor *sc_editor_new(SCBlock *scblocks, Stylesheet *stylesheet, PangoLanguage *lang, const char *storename); extern void sc_editor_set_size(SCEditor *e, int w, int h); extern void sc_editor_set_logical_size(SCEditor *e, double w, double h); diff --git a/src/stylesheet.c b/src/stylesheet.c new file mode 100644 index 0000000..51cce6e --- /dev/null +++ b/src/stylesheet.c @@ -0,0 +1,91 @@ +/* + * stylesheet.c + * + * Copyright © 2013-2018 Thomas White + * + * This file is part of Colloquium. + * + * Colloquium is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include +#include +#include +#include + +#include "stylesheet.h" + + +struct _stylesheet { + JsonNode *root; +}; + + +Stylesheet *stylesheet_load(const char *filename) +{ + JsonParser *parser; + gboolean r; + GError *err = NULL; + Stylesheet *ss; + + ss = calloc(1, sizeof(Stylesheet)); + if ( ss == NULL ) return NULL; + + parser = json_parser_new(); + + r = json_parser_load_from_file(parser, filename, &err); + if ( r == FALSE ) { + fprintf(stderr, "Failed to load style sheet: '%s'\n", err->message); + return NULL; + } + + ss->root = json_parser_steal_root(parser); + g_object_unref(parser); + + return ss; +} + + +char *stylesheet_lookup(Stylesheet *ss, const char *path) +{ + JsonNode *node; + JsonArray *array; + GError *err = NULL; + char *ret; + const gchar *v; + + node = json_path_query(path, ss->root, &err); + array = json_node_get_array(node); + + v = json_array_get_string_element(array, 0); + if ( v == NULL ) return NULL; + + ret = strdup(v); + json_node_unref(node); + return ret; +} + + +void stylesheet_free(Stylesheet *ss) +{ + g_object_unref(ss->root); + free(ss); +} + diff --git a/src/stylesheet.h b/src/stylesheet.h new file mode 100644 index 0000000..59afa7d --- /dev/null +++ b/src/stylesheet.h @@ -0,0 +1,36 @@ +/* + * stylesheet.h + * + * Copyright © 2013-2018 Thomas White + * + * This file is part of Colloquium. + * + * Colloquium is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + * + */ + +#ifndef STYLESHEET_H +#define STYLESHEET_H + +#ifdef HAVE_CONFIG_H +#include +#endif + +typedef struct _stylesheet Stylesheet; + +extern Stylesheet *stylesheet_load(const char *filename); +extern char *stylesheet_lookup(Stylesheet *ss, const char *path); +extern void stylesheet_free(Stylesheet *ss); + +#endif /* STYLESHEET_H */ diff --git a/src/stylesheet_editor.c b/src/stylesheet_editor.c index 508ee6a..2b9d21e 100644 --- a/src/stylesheet_editor.c +++ b/src/stylesheet_editor.c @@ -38,7 +38,6 @@ G_DEFINE_TYPE_WITH_CODE(StylesheetEditor, stylesheet_editor, GTK_TYPE_DIALOG, NULL) -static void set_values_from_presentation(StylesheetEditor *se); struct _sspriv { @@ -46,176 +45,16 @@ struct _sspriv }; -static SCBlock *find_block(SCBlock *bl, const char *find) -{ - while ( bl != NULL ) { - - const char *name = sc_block_name(bl); - if ( (name != NULL) && (strcmp(name, find)==0) ) { - return bl; - } - - bl = sc_block_next(bl); - - } - - return NULL; -} - - -static void find_replace(SCBlock *parent, const char *find, const char *seti) -{ - SCBlock *bl = find_block(sc_block_child(parent), find); - - if ( bl != NULL ) { - - printf("replacing '%s' with '%s'\n", sc_block_options(bl), seti); - sc_block_set_options(bl, strdup(seti)); - - } else { - - /* Block not found -> create it */ - sc_block_append_inside(parent, strdup(find), strdup(seti), NULL); - - } -} - - -static SCBlock *find_or_create_style(struct presentation *p, const char *style_name) -{ - SCBlock *bl; - const char *name; - - /* If no stylesheet yet, create one now */ - if ( p->stylesheet == NULL ) { - p->stylesheet = sc_parse("\\stylesheet"); - if ( p->stylesheet == NULL ) { - fprintf(stderr, "WARNING: Couldn't create stylesheet\n"); - return NULL; - } - sc_block_append_p(p->stylesheet, p->scblocks); - p->scblocks = p->stylesheet; - } - bl = p->stylesheet; - - name = sc_block_name(bl); - if ( (name != NULL) && (strcmp(name, "stylesheet")==0) ) { - bl = sc_block_child(bl); - } - - while ( bl != NULL ) { - - const char *name = sc_block_name(bl); - const char *options = sc_block_options(bl); - if ( (name != NULL) && (strcmp(name, "style")==0) - && (strcmp(options, style_name)==0) ) - { - return bl; - } - - bl = sc_block_next(bl); - - } - - /* Not found -> add style */ - return sc_block_append_inside(p->stylesheet, strdup("style"), - strdup(style_name), NULL); -} - - -static void set_ss(struct presentation *p, const char *style_name, - const char *find, const char *seti) -{ - SCBlock *bl = find_or_create_style(p, style_name); - if ( bl == NULL ) { - fprintf(stderr, "WARNING: Couldn't find style\n"); - return; - } - find_replace(bl, find, seti); -} - - -static void set_ss_bg_block(SCBlock *bl, GradientType bggrad, - GdkRGBA col1, GdkRGBA col2) -{ - char tmp[64]; - - switch ( bggrad ) { - - case GRAD_NONE : - sc_block_set_name(bl, strdup("bgcol")); - snprintf(tmp, 63, "#%.2x%.2x%.2x", - (int)(col1.red*255), (int)(col1.green*255), (int)(col1.blue*255)); - sc_block_set_options(bl, strdup(tmp)); - break; - - case GRAD_VERT : - sc_block_set_name(bl, strdup("bggradv")); - snprintf(tmp, 63, "#%.2x%.2x%.2x,#%.2x%.2x%.2x", - (int)(col1.red*255), (int)(col1.green*255), (int)(col1.blue*255), - (int)(col2.red*255), (int)(col2.green*255), (int)(col2.blue*255)); - sc_block_set_options(bl, strdup(tmp)); - break; - - case GRAD_HORIZ : - sc_block_set_name(bl, strdup("bggradh")); - snprintf(tmp, 63, "#%.2x%.2x%.2x,#%.2x%.2x%.2x", - (int)(col1.red*255), (int)(col1.green*255), (int)(col1.blue*255), - (int)(col2.red*255), (int)(col2.green*255), (int)(col2.blue*255)); - sc_block_set_options(bl, strdup(tmp)); - break; - - case GRAD_NOBG : - printf("no bg\n"); - sc_block_set_name(bl, NULL); - sc_block_set_options(bl, NULL); - sc_block_set_contents(bl, NULL); - break; - - } -} - - -static int try_set_block(SCBlock **parent, const char *name, - GradientType bggrad, GdkRGBA col1, GdkRGBA col2) +static void set_values_from_presentation(StylesheetEditor *se) { - SCBlock *ibl; - - ibl = find_block(sc_block_child(*parent), name); - if ( ibl != NULL ) { - if ( bggrad != GRAD_NOBG ) { - set_ss_bg_block(ibl, bggrad, col1, col2); - return 1; - } else { - sc_block_delete(parent, ibl); - return 1; - } - } - - return 0; + /* FIXME: From JSON */ } static void update_bg(struct presentation *p, const char *style_name, GradientType bggrad, GdkRGBA col1, GdkRGBA col2) { - int done; - SCBlock *bl; - - bl = find_or_create_style(p, style_name); - if ( bl == NULL ) { - fprintf(stderr, "WARNING: Couldn't find style\n"); - return; - } - - /* FIXME: What if there are two of these? */ - done = try_set_block(&bl, "bgcol", bggrad, col1, col2); - if ( !done ) done = try_set_block(&bl, "bggradv", bggrad, col1, col2); - if ( !done ) done = try_set_block(&bl, "bggradh", bggrad, col1, col2); - if ( !done && bggrad != GRAD_NOBG ) { - SCBlock *ibl = sc_block_append_inside(bl, NULL, NULL, NULL); - set_ss_bg_block(ibl, bggrad, col1, col2); - } + /* FIXME: set in JSON */ } @@ -239,9 +78,9 @@ static GradientType id_to_gradtype(const gchar *id) static void set_font(GtkFontButton *widget, StylesheetEditor *se, const char *style_name) { - const gchar *font; - font = gtk_font_button_get_font_name(GTK_FONT_BUTTON(widget)); - set_ss(se->priv->p, style_name, "font", font); +// const gchar *font; +// font = gtk_font_button_get_font_name(GTK_FONT_BUTTON(widget)); + /* FIXME: set in JSON */ set_values_from_presentation(se); g_signal_emit_by_name(se, "changed"); } @@ -254,7 +93,7 @@ static void set_col(GtkColorButton *widget, StylesheetEditor *se, gchar *col; gtk_color_chooser_get_rgba(GTK_COLOR_CHOOSER(widget), &rgba); col = gdk_rgba_to_string(&rgba); - set_ss(se->priv->p, style_name, col_name, col); + /* FIXME: Set in JSON */ g_free(col); set_values_from_presentation(se); g_signal_emit_by_name(se, "changed"); @@ -446,55 +285,6 @@ void stylesheet_editor_class_init(StylesheetEditorClass *klass) } -static void set_from_interp_col(double *col, GtkWidget *w) -{ - GdkRGBA rgba; - - rgba.red = col[0]; - rgba.green = col[1]; - rgba.blue = col[2]; - rgba.alpha = col[3]; - gtk_color_chooser_set_rgba(GTK_COLOR_CHOOSER(w), &rgba); -} - - -static void set_from_interp_bggrad(SCInterpreter *scin, GtkWidget *w) -{ - GradientType grad; - const gchar *id; - - grad = sc_interp_get_bggrad(scin); - - switch ( grad ) { - case GRAD_NONE : id = "flat"; break; - case GRAD_HORIZ : id = "horiz"; break; - case GRAD_VERT : id = "vert"; break; - case GRAD_NOBG : id = "none"; break; - default : id = NULL; break; - } - - gtk_combo_box_set_active_id(GTK_COMBO_BOX(w), id); -} - - -static void set_from_interp_font(SCInterpreter *scin, GtkWidget *w) -{ - char *fontname; - PangoFontDescription *fontdesc; - - fontdesc = sc_interp_get_fontdesc(scin); - fontname = pango_font_description_to_string(fontdesc); - gtk_font_button_set_font_name(GTK_FONT_BUTTON(w), fontname); - g_free(fontname); -} - - -static void set_values_from_presentation(StylesheetEditor *se) -{ - /* FIXME: From JSON */ -} - - StylesheetEditor *stylesheet_editor_new(struct presentation *p) { StylesheetEditor *se; -- cgit v1.2.3 From 51e1d39d8eaaf02f23ed0b83695e0294a23496bb Mon Sep 17 00:00:00 2001 From: Thomas White Date: Wed, 17 Oct 2018 15:15:01 +0200 Subject: Pass stylesheet around --- src/render.c | 2 +- src/sc_interp.c | 55 ++++++++++++++++++++++++++++--------------------------- src/sc_interp.h | 5 +++-- 3 files changed, 32 insertions(+), 30 deletions(-) diff --git a/src/render.c b/src/render.c index 041f812..8aa7dbe 100644 --- a/src/render.c +++ b/src/render.c @@ -217,7 +217,7 @@ struct frame *interp_and_shape(SCBlock *scblocks, Stylesheet *stylesheet, top->col[2] = sc_interp_get_fgcol(scin)[2]; top->col[3] = sc_interp_get_fgcol(scin)[3]; - sc_interp_add_block(scin, scblocks); + sc_interp_add_block(scin, scblocks, stylesheet); sc_interp_destroy(scin); diff --git a/src/sc_interp.c b/src/sc_interp.c index 0ff04d7..ed49597 100644 --- a/src/sc_interp.c +++ b/src/sc_interp.c @@ -965,11 +965,12 @@ static void maybe_recurse_before(SCInterpreter *scin, SCBlock *child) } -static void maybe_recurse_after(SCInterpreter *scin, SCBlock *child) +static void maybe_recurse_after(SCInterpreter *scin, SCBlock *child, + Stylesheet *ss) { if ( child == NULL ) return; - sc_interp_add_blocks(scin, child); + sc_interp_add_blocks(scin, child, ss); sc_interp_restore(scin); } @@ -1024,7 +1025,7 @@ static int add_text(struct frame *fr, PangoContext *pc, SCBlock *bl, } -static int check_outputs(SCBlock *bl, SCInterpreter *scin) +static int check_outputs(SCBlock *bl, SCInterpreter *scin, Stylesheet *ss) { const char *name = sc_block_name(bl); const char *options = sc_block_options(bl); @@ -1068,7 +1069,7 @@ static int check_outputs(SCBlock *bl, SCInterpreter *scin) maybe_recurse_before(scin, child); set_frame(scin, fr); /* FIXME: Set frame style */ - maybe_recurse_after(scin, child); + maybe_recurse_after(scin, child, ss); } else if ( strcmp(name, "newpara")==0 ) { @@ -1084,7 +1085,7 @@ static int check_outputs(SCBlock *bl, SCInterpreter *scin) } -int sc_interp_add_block(SCInterpreter *scin, SCBlock *bl) +int sc_interp_add_block(SCInterpreter *scin, SCBlock *bl, Stylesheet *ss) { const char *name = sc_block_name(bl); const char *options = sc_block_options(bl); @@ -1098,7 +1099,7 @@ int sc_interp_add_block(SCInterpreter *scin, SCBlock *bl) /* Handled in check_callback, don't do anything else */ } else if ((sc_interp_get_frame(scin) != NULL) - && check_outputs(bl, scin) ) { + && check_outputs(bl, scin, ss) ) { /* Block handled as output thing */ } else if ( name == NULL ) { @@ -1106,89 +1107,89 @@ int sc_interp_add_block(SCInterpreter *scin, SCBlock *bl) } 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 */ - maybe_recurse_after(scin, child); - - } else if ( strcmp(name, "stylesheet") == 0 ) { - /* Ignore (see sc_interp_run_stylesheet) */ + maybe_recurse_after(scin, child, ss); } else if ( strcmp(name, "slide") == 0 ) { maybe_recurse_before(scin, child); /* FIXME: Apply slide style */ - maybe_recurse_after(scin, child); + maybe_recurse_after(scin, child, ss); } else if ( strcmp(name, "font") == 0 ) { maybe_recurse_before(scin, child); set_font(scin, options); - maybe_recurse_after(scin, child); + maybe_recurse_after(scin, child, ss); } else if ( strcmp(name, "fontsize") == 0 ) { maybe_recurse_before(scin, child); set_fontsize(scin, options); - maybe_recurse_after(scin, child); + maybe_recurse_after(scin, child, ss); } else if ( strcmp(name, "bold") == 0 ) { maybe_recurse_before(scin, child); set_bold(scin); - maybe_recurse_after(scin, child); + maybe_recurse_after(scin, child, ss); } else if ( strcmp(name, "oblique") == 0 ) { maybe_recurse_before(scin, child); set_oblique(scin); - maybe_recurse_after(scin, child); + maybe_recurse_after(scin, child, ss); } else if ( strcmp(name, "italic") == 0 ) { maybe_recurse_before(scin, child); set_italic(scin); - maybe_recurse_after(scin, child); + maybe_recurse_after(scin, child, ss); } else if ( strcmp(name, "lalign") == 0 ) { maybe_recurse_before(scin, child); set_alignment(scin, PANGO_ALIGN_LEFT); - maybe_recurse_after(scin, child); + maybe_recurse_after(scin, child, ss); } else if ( strcmp(name, "ralign") == 0 ) { maybe_recurse_before(scin, child); set_alignment(scin, PANGO_ALIGN_RIGHT); - maybe_recurse_after(scin, child); + maybe_recurse_after(scin, child, ss); } else if ( strcmp(name, "center") == 0 ) { maybe_recurse_before(scin, child); set_alignment(scin, PANGO_ALIGN_CENTER); - maybe_recurse_after(scin, child); + maybe_recurse_after(scin, child, ss); } else if ( strcmp(name, "fgcol") == 0 ) { maybe_recurse_before(scin, child); set_colour(scin, options); - maybe_recurse_after(scin, child); + maybe_recurse_after(scin, child, ss); } else if ( strcmp(name, "pad") == 0 ) { maybe_recurse_before(scin, child); set_padding(sc_interp_get_frame(scin), options); - maybe_recurse_after(scin, child); + maybe_recurse_after(scin, child, ss); } else if ( strcmp(name, "bgcol") == 0 ) { maybe_recurse_before(scin, child); set_bgcol(scin, options); update_bg(scin); - maybe_recurse_after(scin, child); + maybe_recurse_after(scin, child, ss); } else if ( strcmp(name, "bggradh") == 0 ) { maybe_recurse_before(scin, child); set_bggrad(scin, options, GRAD_HORIZ); update_bg(scin); - maybe_recurse_after(scin, child); + maybe_recurse_after(scin, child, ss); } else if ( strcmp(name, "bggradv") == 0 ) { maybe_recurse_before(scin, child); set_bggrad(scin, options, GRAD_VERT); update_bg(scin); - maybe_recurse_after(scin, child); + maybe_recurse_after(scin, child, ss); } else if ( strcmp(name, "paraspace") == 0 ) { maybe_recurse_before(scin, child); set_paraspace(scin, options); - maybe_recurse_after(scin, child); + maybe_recurse_after(scin, child, ss); } else { @@ -1201,10 +1202,10 @@ int sc_interp_add_block(SCInterpreter *scin, SCBlock *bl) } -int sc_interp_add_blocks(SCInterpreter *scin, SCBlock *bl) +int sc_interp_add_blocks(SCInterpreter *scin, SCBlock *bl, Stylesheet *ss) { while ( bl != NULL ) { - if ( sc_interp_add_block(scin, bl) ) return 1; + if ( sc_interp_add_block(scin, bl, ss) ) return 1; bl = sc_block_next(bl); } diff --git a/src/sc_interp.h b/src/sc_interp.h index 7b00aaa..b0bd689 100644 --- a/src/sc_interp.h +++ b/src/sc_interp.h @@ -41,6 +41,7 @@ typedef int (*SCCallbackClickFunc)(double x, double y, void *, void *); #include "frame.h" #include "imagestore.h" +#include "stylesheet.h" extern SCInterpreter *sc_interp_new(PangoContext *pc, PangoLanguage *lang, ImageStore *is, struct frame *top); @@ -49,8 +50,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_block(SCInterpreter *scin, SCBlock *bl); +extern int sc_interp_add_blocks(SCInterpreter *scin, SCBlock *bl, Stylesheet *ss); +extern int sc_interp_add_block(SCInterpreter *scin, SCBlock *bl, Stylesheet *ss); extern void sc_interp_run_stylesheet(SCInterpreter *scin, SCBlock *bl); extern void sc_interp_run_style(SCInterpreter *scin, const char *sname); -- cgit v1.2.3 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 From fc8081e6b052e2901aa56676c5cab61eaa5996e2 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Wed, 17 Oct 2018 22:41:03 +0200 Subject: Apply most styles --- src/sc_interp.c | 145 ++++++++++++++++++++++++++++++++++++++++--------------- src/stylesheet.c | 5 ++ stylesheet.json | 50 +++++++------------ 3 files changed, 127 insertions(+), 73 deletions(-) diff --git a/src/sc_interp.c b/src/sc_interp.c index b603c61..d7f7b6b 100644 --- a/src/sc_interp.c +++ b/src/sc_interp.c @@ -1025,11 +1025,107 @@ static int add_text(struct frame *fr, PangoContext *pc, SCBlock *bl, } +static void apply_style(SCInterpreter *scin, Stylesheet *ss, const char *path) +{ + char fullpath[256]; + size_t len; + char *result; + + len = strlen(path); + if ( len > 160 ) { + fprintf(stderr, "Can't apply style: path too long.\n"); + return; + } + + /* Font */ + strcpy(fullpath, path); + strcat(fullpath, ".font"); + result = stylesheet_lookup(ss, fullpath); + if ( result != NULL ) set_font(scin, result); + + /* Foreground colour */ + strcpy(fullpath, path); + strcat(fullpath, ".fgcol"); + result = stylesheet_lookup(ss, fullpath); + if ( result != NULL ) set_colour(scin, result); + + /* Background (vertical gradient) */ + strcpy(fullpath, path); + strcat(fullpath, ".bggradv"); + result = stylesheet_lookup(ss, fullpath); + if ( result != NULL ) set_bggrad(scin, result, GRAD_VERT); + + /* Background (horizontal gradient) */ + strcpy(fullpath, path); + strcat(fullpath, ".bggradh"); + result = stylesheet_lookup(ss, fullpath); + if ( result != NULL ) set_bggrad(scin, result, GRAD_HORIZ); + + /* Background (solid colour) */ + strcpy(fullpath, path); + strcat(fullpath, ".bgcol"); + result = stylesheet_lookup(ss, fullpath); + if ( result != NULL ) set_bgcol(scin, result); + + /* Padding */ + strcpy(fullpath, path); + strcat(fullpath, ".pad"); + result = stylesheet_lookup(ss, fullpath); + if ( result != NULL ) set_padding(sc_interp_get_frame(scin), result); + + update_bg(scin); +} + + +static void output_frame(SCInterpreter *scin, SCBlock *bl, Stylesheet *ss, + const char *stylename) +{ + struct frame *fr; + SCBlock *child = sc_block_child(bl); + const char *options = sc_block_options(bl); + char fullpath[256]; + size_t len; + char *result; + + len = strlen(stylename); + if ( len > 160 ) { + fprintf(stderr, "Can't apply style: path too long.\n"); + return; + } + + fr = add_subframe(sc_interp_get_frame(scin)); + fr->scblocks = bl; + fr->resizable = 1; + if ( fr == NULL ) { + fprintf(stderr, _("Failed to add frame.\n")); + return; + } + + /* Lowest priority: current state of interpreter */ + set_frame_default_style(fr, scin); + + /* Next priority: geometry from stylesheet */ + strcpy(fullpath, stylename); + strcat(fullpath, ".geometry"); + result = stylesheet_lookup(ss, fullpath); + if ( result != NULL ) { + parse_frame_options(fr, sc_interp_get_frame(scin), result); + } + + /* Highest priority: parameters to \f (or \slidetitle etc) */ + parse_frame_options(fr, sc_interp_get_frame(scin), options); + + maybe_recurse_before(scin, child); + set_frame(scin, fr); + apply_style(scin, ss, stylename); + maybe_recurse_after(scin, child, ss); +} + + static int check_outputs(SCBlock *bl, SCInterpreter *scin, Stylesheet *ss) { const char *name = sc_block_name(bl); const char *options = sc_block_options(bl); - SCBlock *child = sc_block_child(bl); if ( name == NULL ) { add_text(sc_interp_get_frame(scin), @@ -1051,28 +1147,18 @@ static int check_outputs(SCBlock *bl, SCInterpreter *scin, Stylesheet *ss) } } else if ( strcmp(name, "f")==0 ) { + output_frame(scin, bl, ss, "$.slide.frame"); - struct frame *fr; - - fr = add_subframe(sc_interp_get_frame(scin)); - fr->scblocks = bl; - fr->resizable = 1; - if ( fr == NULL ) { - fprintf(stderr, _("Failed to add frame.\n")); - return 1; - } + } else if ( strcmp(name, "slidetitle")==0 ) { + output_frame(scin, bl, ss, "$.slide.slidetitle"); - set_frame_default_style(fr, scin); + } else if ( strcmp(name, "prestitle")==0 ) { + output_frame(scin, bl, ss, "$.slide.prestitle"); - parse_frame_options(fr, sc_interp_get_frame(scin), options); - - maybe_recurse_before(scin, child); - set_frame(scin, fr); - /* FIXME: Set frame style */ - maybe_recurse_after(scin, child, ss); + } else if ( strcmp(name, "author")==0 ) { + output_frame(scin, bl, ss, "$.slide.author"); } else if ( strcmp(name, "newpara")==0 ) { - struct frame *fr = sc_interp_get_frame(scin); SCBlock *rbl = bl; add_newpara(fr, bl, rbl); @@ -1085,27 +1171,6 @@ 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); @@ -1133,7 +1198,7 @@ int sc_interp_add_block(SCInterpreter *scin, SCBlock *bl, Stylesheet *ss) } else if ( strcmp(name, "slide") == 0 ) { maybe_recurse_before(scin, child); - /* FIXME: Apply slide style */ + apply_style(scin, ss, "$.slide"); maybe_recurse_after(scin, child, ss); } else if ( strcmp(name, "font") == 0 ) { diff --git a/src/stylesheet.c b/src/stylesheet.c index 51cce6e..228c331 100644 --- a/src/stylesheet.c +++ b/src/stylesheet.c @@ -74,6 +74,11 @@ char *stylesheet_lookup(Stylesheet *ss, const char *path) node = json_path_query(path, ss->root, &err); array = json_node_get_array(node); + if ( json_array_get_length(array) < 1 ) { + json_node_unref(node); + return NULL; + } + v = json_array_get_string_element(array, 0); if ( v == NULL ) return NULL; diff --git a/stylesheet.json b/stylesheet.json index 518c21b..16649b9 100644 --- a/stylesheet.json +++ b/stylesheet.json @@ -1,56 +1,40 @@ { "narrative": { - "font": "Comfortaa 20", + "font": "Comfortaa 16", "fgcol": "#000000", - "bggradv": "#729fcf,#d3d7cf" + "pad": "10,10,10,10" }, "slide": { "width": 1280, "height": 720, - "bggrad": "vertical", - "bgcol1": "#729fcf", - "bgcol2": "#d3d7cf", + "bggradv": "#729fcf,#d3d7cf", "frame": { - "font": "Comfortaa 20" + "font": "Comfortaa 20", + "bgcol": "#ffffff00" }, "slidetitle": { - "width": "1f", - "height": "90u", - "posx": 0, - "posy": 0, - "padl": 30, - "padr": 30, - "padt": 30, - "padb": 30, + "geometry": "1fx90u+0+0", + "pad": "30,30,30,30", "fgcol": "#000000", - "font": "Comfortaa Bold 40" + "font": "Comfortaa Bold 40", + "bgcol": "#ffffff00" }, "prestitle": { - "width": "1f", - "height": "240u", - "posx": 0, - "posy": 160, - "padl": 50, - "padr": 50, - "padt": 50, - "padb": 50, + "geometry": "1fx240u+0+160", + "pad": "50,50,50,50", "fgcol": "#000000", "font": "Comfortaa Bold 45", - "alignment": "center" + "alignment": "center", + "bgcol": "#ffffff00" }, "author": { - "width": "1f", - "height": "240u", - "posx": 0, - "posy": 360, - "padl": 80, - "padr": 80, - "padt": 80, - "padb": 80, + "geometry": "1fx240u+0+360", + "pad": "80,80,80,80", "fgcol": "#000000", "font": "Comfortaa 20", - "alignment": "center" + "alignment": "center", + "bgcol": "#ffffff00" } } } -- cgit v1.2.3 From afad5f6ac5ba0e4b92158c35f23f41688f92b048 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Thu, 18 Oct 2018 08:54:14 +0200 Subject: Set slide size from stylesheet --- src/presentation.c | 11 ++++++++++- src/sc_interp.c | 28 ---------------------------- src/utils.c | 28 ++++++++++++++++++++++++++++ src/utils.h | 2 ++ 4 files changed, 40 insertions(+), 29 deletions(-) diff --git a/src/presentation.c b/src/presentation.c index c3f0d07..1aa126a 100644 --- a/src/presentation.c +++ b/src/presentation.c @@ -228,7 +228,16 @@ SCBlock *prev_slide(struct presentation *p, SCBlock *sl) static void set_slide_size_from_stylesheet(struct presentation *p) { - /* FIXME: From JSON */ + char *result; + + result = stylesheet_lookup(p->stylesheet, "$.slide.size"); + if ( result != NULL ) { + float v[2]; + if ( parse_double(result, v) == 0 ) { + p->slide_width = v[0]; + p->slide_height = v[1]; + } + } } diff --git a/src/sc_interp.c b/src/sc_interp.c index d7f7b6b..0b39d00 100644 --- a/src/sc_interp.c +++ b/src/sc_interp.c @@ -679,34 +679,6 @@ void sc_interp_destroy(SCInterpreter *scin) } -static int parse_double(const char *a, float v[2]) -{ - int nn; - - nn = sscanf(a, "%fx%f", &v[0], &v[1]); - if ( nn != 2 ) { - fprintf(stderr, _("Invalid size '%s'\n"), a); - return 1; - } - - return 0; -} - - -static int parse_tuple(const char *a, float v[4]) -{ - int nn; - - nn = sscanf(a, "%f,%f,%f,%f", &v[0], &v[1], &v[2], &v[3]); - if ( nn != 4 ) { - fprintf(stderr, _("Invalid tuple '%s'\n"), a); - return 1; - } - - return 0; -} - - static void set_padding(struct frame *fr, const char *opts) { float p[4]; diff --git a/src/utils.c b/src/utils.c index 9033466..bafbb99 100644 --- a/src/utils.c +++ b/src/utils.c @@ -109,6 +109,34 @@ static char *fgets_long(FILE *fh, size_t *lp) } +int parse_double(const char *a, float v[2]) +{ + int nn; + + nn = sscanf(a, "%fx%f", &v[0], &v[1]); + if ( nn != 2 ) { + fprintf(stderr, _("Invalid size '%s'\n"), a); + return 1; + } + + return 0; +} + + +int parse_tuple(const char *a, float v[4]) +{ + int nn; + + nn = sscanf(a, "%f,%f,%f,%f", &v[0], &v[1], &v[2], &v[3]); + if ( nn != 4 ) { + fprintf(stderr, _("Invalid tuple '%s'\n"), a); + return 1; + } + + return 0; +} + + char *load_everything(const char *filename) { FILE *fh; diff --git a/src/utils.h b/src/utils.h index bfc04c2..8870a98 100644 --- a/src/utils.h +++ b/src/utils.h @@ -30,6 +30,8 @@ extern void chomp(char *s); extern int safe_strcmp(const char *a, const char *b); +extern int parse_double(const char *a, float v[2]); +extern int parse_tuple(const char *a, float v[4]); extern char *load_everything(const char *filename); #include -- cgit v1.2.3 From 2001e70162967cbfcb6fec31ad54e55d28710141 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Thu, 18 Oct 2018 08:54:24 +0200 Subject: Set paragraph spacing from stylesheet --- src/sc_interp.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/sc_interp.c b/src/sc_interp.c index 0b39d00..e357150 100644 --- a/src/sc_interp.c +++ b/src/sc_interp.c @@ -1045,6 +1045,12 @@ static void apply_style(SCInterpreter *scin, Stylesheet *ss, const char *path) result = stylesheet_lookup(ss, fullpath); if ( result != NULL ) set_padding(sc_interp_get_frame(scin), result); + /* Paragraph spacing */ + strcpy(fullpath, path); + strcat(fullpath, ".paraspace"); + result = stylesheet_lookup(ss, fullpath); + if ( result != NULL ) set_paraspace(scin, result); + update_bg(scin); } -- cgit v1.2.3 From 73706985a1ea4ce55deaf89332288f18831b5e26 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Thu, 18 Oct 2018 08:54:33 +0200 Subject: Update template stylesheet --- stylesheet.json | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/stylesheet.json b/stylesheet.json index 16649b9..92c3a7e 100644 --- a/stylesheet.json +++ b/stylesheet.json @@ -2,12 +2,12 @@ "narrative": { "font": "Comfortaa 16", "fgcol": "#000000", - "pad": "10,10,10,10" + "pad": "10,10,10,10", + "paraspace": "5,5,5,5" }, "slide": { - "width": 1280, - "height": 720, + "size": "1280x720", "bggradv": "#729fcf,#d3d7cf", "frame": { "font": "Comfortaa 20", -- cgit v1.2.3 From de8ffb696a1dcc23f49bc63ea216f5f818172d33 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Fri, 19 Oct 2018 08:46:14 +0200 Subject: Get rid of remaining rscblock/rbl/mrb stuff Good riddance. --- src/debugger.c | 20 ++------ src/frame.c | 138 +++++++++++++------------------------------------------- src/frame.h | 11 ++--- src/sc_editor.c | 4 +- src/sc_interp.c | 22 +++------ 5 files changed, 48 insertions(+), 147 deletions(-) diff --git a/src/debugger.c b/src/debugger.c index edb79e1..c8cab67 100644 --- a/src/debugger.c +++ b/src/debugger.c @@ -109,21 +109,12 @@ static void debug_text_para(Paragraph *para, cairo_t *cr, double *ypos, for ( i=0; ifr->paras[i]); SCBlock *scblock = para_scblock(dbgw->fr->paras[i]); - SCBlock *rscblock = para_rscblock(dbgw->fr->paras[i]); plot_hr(cr, &ypos, width); snprintf(tmp, 255, "Paragraph %i: type %s", i, str_type(t)); plot_text(cr, &ypos, fontdesc, tmp); - if ( scblock == rscblock ) { - snprintf(tmp, 255, "SCBlock %p", scblock); - } else { - snprintf(tmp, 255, "SCBlock %p / %p", scblock, rscblock); - } + snprintf(tmp, 255, "SCBlock %p", scblock); plot_text(cr, &ypos, fontdesc, tmp); if ( t == PARA_TYPE_TEXT ) { diff --git a/src/frame.c b/src/frame.c index d4a5637..4ea97d4 100644 --- a/src/frame.c +++ b/src/frame.c @@ -39,7 +39,6 @@ struct text_run { SCBlock *scblock; /* If macro, this is \macro */ - SCBlock *rscblock; /* The block with the actual text */ PangoFontDescription *fontdesc; double col[4]; }; @@ -61,7 +60,6 @@ struct _paragraph /* For anything other than PARA_TYPE_TEXT * (for text paragraphs, these things are in the runs) */ SCBlock *scblock; - SCBlock *rscblock; /* For PARA_TYPE_IMAGE */ char *filename; @@ -279,17 +277,17 @@ static size_t run_text_len(const struct text_run *run) return 0; } - if ( run->rscblock == NULL ) { - fprintf(stderr, _("NULL rscblock in run_text_len\n")); + if ( run->scblock == NULL ) { + fprintf(stderr, _("NULL scblock in run_text_len\n")); return 0; } - if ( sc_block_contents(run->rscblock) == NULL ) { - fprintf(stderr, _("NULL rscblock contents in run_text_len\n")); + if ( sc_block_contents(run->scblock) == NULL ) { + fprintf(stderr, _("NULL scblock contents in run_text_len\n")); return 0; } - return strlen(sc_block_contents(run->rscblock)); + return strlen(sc_block_contents(run->scblock)); } @@ -340,7 +338,7 @@ void wrap_paragraph(Paragraph *para, PangoContext *pc, double w, size_t run_len; guint16 r, g, b; - run_text = sc_block_contents(para->runs[i].rscblock); + run_text = sc_block_contents(para->runs[i].scblock); run_len = strlen(run_text); attr = pango_attr_font_desc_new(para->runs[i].fontdesc); @@ -396,7 +394,7 @@ void set_newline_at_end(Paragraph *para, SCBlock *bl) } -void add_run(Paragraph *para, SCBlock *scblock, SCBlock *rscblock, +void add_run(Paragraph *para, SCBlock *scblock, PangoFontDescription *fdesc, double col[4]) { struct text_run *runs_new; @@ -410,7 +408,6 @@ void add_run(Paragraph *para, SCBlock *scblock, SCBlock *rscblock, para->runs = runs_new; para->runs[para->n_runs].scblock = scblock; - para->runs[para->n_runs].rscblock = rscblock; para->runs[para->n_runs].fontdesc = pango_font_description_copy(fdesc); para->runs[para->n_runs].col[0] = col[0]; para->runs[para->n_runs].col[1] = col[1]; @@ -421,7 +418,7 @@ void add_run(Paragraph *para, SCBlock *scblock, SCBlock *rscblock, } -Paragraph *create_paragraph(struct frame *fr, SCBlock *bl, SCBlock *rbl) +Paragraph *create_paragraph(struct frame *fr, SCBlock *bl) { Paragraph **paras_new; Paragraph *pnew; @@ -439,7 +436,6 @@ Paragraph *create_paragraph(struct frame *fr, SCBlock *bl, SCBlock *rbl) * However, this can easily be changed */ pnew->type = PARA_TYPE_TEXT; pnew->scblock = bl; - pnew->rscblock = rbl; pnew->n_runs = 0; pnew->runs = NULL; pnew->layout = NULL; @@ -481,8 +477,7 @@ Paragraph *insert_paragraph(struct frame *fr, int pos) } -Paragraph *add_callback_para(struct frame *fr, SCBlock *bl, SCBlock *rbl, - double w, double h, +Paragraph *add_callback_para(struct frame *fr, SCBlock *bl, double w, double h, SCCallbackDrawFunc draw_func, SCCallbackClickFunc click_func, void *bvp, void *vp) @@ -492,7 +487,7 @@ Paragraph *add_callback_para(struct frame *fr, SCBlock *bl, SCBlock *rbl, if ( (fr->n_paras > 0) && (fr->paras[fr->n_paras-1]->empty) ) { pnew = fr->paras[fr->n_paras-1]; } else { - pnew = create_paragraph(fr, bl, rbl); + pnew = create_paragraph(fr, bl); if ( pnew == NULL ) { fprintf(stderr, _("Failed to add callback paragraph\n")); return NULL; @@ -501,7 +496,6 @@ Paragraph *add_callback_para(struct frame *fr, SCBlock *bl, SCBlock *rbl, pnew->type = PARA_TYPE_CALLBACK; pnew->scblock = bl; - pnew->rscblock = rbl; pnew->cb_w = w; pnew->cb_h = h; pnew->draw_func = draw_func; @@ -515,7 +509,7 @@ Paragraph *add_callback_para(struct frame *fr, SCBlock *bl, SCBlock *rbl, } -void add_image_para(struct frame *fr, SCBlock *scblock, SCBlock *rscblock, +void add_image_para(struct frame *fr, SCBlock *scblock, const char *filename, ImageStore *is, double w, double h, int editable) { @@ -530,7 +524,7 @@ void add_image_para(struct frame *fr, SCBlock *scblock, SCBlock *rscblock, if ( (fr->n_paras > 0) && (fr->paras[fr->n_paras-1]->empty) ) { pnew = fr->paras[fr->n_paras-1]; } else { - pnew = create_paragraph(fr, scblock, rscblock); + pnew = create_paragraph(fr, scblock); if ( pnew == NULL ) { fprintf(stderr, _("Failed to add image paragraph\n")); return; @@ -545,7 +539,6 @@ void add_image_para(struct frame *fr, SCBlock *scblock, SCBlock *rscblock, pnew->type = PARA_TYPE_IMAGE; pnew->scblock = scblock; - pnew->rscblock = rscblock; pnew->filename = strdup(filename); pnew->image_w = w; pnew->image_h = h; @@ -726,11 +719,6 @@ void ensure_run(struct frame *fr, struct edit_pos cpos) if ( para->type != PARA_TYPE_TEXT ) return; - if ( para->scblock != para->rscblock ) { - fprintf(stderr, _("Need to add run, but paragraph not editable\n")); - return; - } - if ( para->scblock != NULL ) { bl = sc_block_prepend(para->scblock, fr->scblocks); @@ -750,8 +738,7 @@ void ensure_run(struct frame *fr, struct edit_pos cpos) } para->scblock = bl; - para->rscblock = bl; - add_run(para, bl, bl, fr->fontdesc, fr->col); + add_run(para, bl, fr->fontdesc, fr->col); wrap_paragraph(para, NULL, fr->w - fr->pad_l - fr->pad_r, 0, 0); } @@ -987,7 +974,7 @@ size_t pos_trail_to_offset(Paragraph *para, size_t offs, int trail) return 0; } - if ( sc_block_contents(run->rscblock) == NULL ) { + if ( sc_block_contents(run->scblock) == NULL ) { fprintf(stderr, _("pos_trail_to_offset: No contents " "(%p name=%s, options=%s)\n"), run->scblock, sc_block_name(run->scblock), @@ -996,7 +983,7 @@ size_t pos_trail_to_offset(Paragraph *para, size_t offs, int trail) } /* Get the text for the run */ - run_text = sc_block_contents(run->rscblock); + run_text = sc_block_contents(run->scblock); /* Turn the paragraph offset into a run offset */ para_offset_of_run = get_paragraph_offset(para, nrun); @@ -1035,11 +1022,6 @@ int position_editable(struct frame *fr, struct edit_pos cp) para = fr->paras[cp.para]; - if ( para->scblock != para->rscblock ) { - fprintf(stderr, _("Paragraph is not editable.\n")); - return 0; - } - if ( para->type != PARA_TYPE_TEXT ) { fprintf(stderr, _("Paragraph is not text.\n")); return 0; @@ -1052,7 +1034,7 @@ int position_editable(struct frame *fr, struct edit_pos cp) return 0; } - return (para->runs[run].scblock == para->runs[run].rscblock); + return 1; } @@ -1074,33 +1056,11 @@ void insert_text_in_paragraph(Paragraph *para, size_t offs, const char *t) size_t run_offs; run = ¶->runs[nrun]; run_offs = offs - get_paragraph_offset(para, nrun); - sc_insert_text(run->rscblock, run_offs, t); + sc_insert_text(run->scblock, run_offs, t); } } -static SCBlock *pos_to_rscblock(struct frame *fr, struct edit_pos p) -{ - int run; - size_t paraoffs; - Paragraph *para; - - para = fr->paras[p.para]; - - if ( para->type != PARA_TYPE_TEXT ) { - return NULL; - } - - paraoffs = pos_trail_to_offset(para, p.pos, p.trail); - - run = which_run(para, paraoffs); - assert(run < para->n_runs); - - return para->runs[run].rscblock; -} - - - static SCBlock *pos_to_scblock(struct frame *fr, struct edit_pos p, enum para_type *type) { @@ -1192,17 +1152,9 @@ static Paragraph *scan_runs_for_scblock(struct frame *fr, int pn1, int pn2, *run = 0; return fr->paras[i]; } - if ( fr->paras[i]->rscblock == bl ) { - *run = 0; - return fr->paras[i]; - } /* Check all runs */ for ( j=0; jparas[i]->n_runs; j++ ) { - if ( fr->paras[i]->runs[j].rscblock == bl ) { - *run = j; - return fr->paras[i]; - } if ( fr->paras[i]->runs[j].scblock == bl ) { *run = j; return fr->paras[i]; @@ -1440,7 +1392,6 @@ void delete_text_from_frame(struct frame *fr, struct edit_pos p1, struct edit_po { int i; SCBlock *p1scblock, *p2scblock; - SCBlock *p1rscblock, *p2rscblock; enum para_type type1, type2; size_t p2offs; SCBlock *scblock; @@ -1467,8 +1418,6 @@ void delete_text_from_frame(struct frame *fr, struct edit_pos p1, struct edit_po /* Find SC positions for start and end */ p1scblock = pos_to_scblock(fr, p1, &type1); p2scblock = pos_to_scblock(fr, p2, &type2); - p1rscblock = pos_to_rscblock(fr, p1); - p2rscblock = pos_to_rscblock(fr, p2); p2offs = pos_to_offset(fr, p2); wrap_end = p2.para; @@ -1512,9 +1461,9 @@ void delete_text_from_frame(struct frame *fr, struct edit_pos p1, struct edit_po printf(" offs %li\n", (long int)p1offs); if ( p1offs != 0 ) { printf("Partial delete\n"); - printf("contents '%s'\n", sc_block_contents(p1rscblock)); + printf("contents '%s'\n", sc_block_contents(p1scblock)); printf("from offs %li\n", (long int)p1offs); - scblock_delete_text(p1rscblock, p1offs, -1); + scblock_delete_text(p1scblock, p1offs, -1); } else { printf("Deleting the whole text SCBlock\n"); sc_block_delete(&fr->scblocks, p1scblock); @@ -1564,8 +1513,8 @@ void delete_text_from_frame(struct frame *fr, struct edit_pos p1, struct edit_po if ( type2 == PARA_TYPE_TEXT ) { size_t len; printf(" offs %li\n", (long int)p2offs); - if ( sc_block_contents(p2rscblock) != NULL ) { - len = strlen(sc_block_contents(p2rscblock)); + if ( sc_block_contents(p2scblock) != NULL ) { + len = strlen(sc_block_contents(p2scblock)); } else { len = 0; } @@ -1580,9 +1529,9 @@ void delete_text_from_frame(struct frame *fr, struct edit_pos p1, struct edit_po NULL); } else if ( p2offs > 0 ) { printf("Partial delete\n"); - printf("contents '%s'\n", sc_block_contents(p2rscblock)); + printf("contents '%s'\n", sc_block_contents(p2scblock)); printf("up to offs %li\n", (long int)p2offs); - scblock_delete_text(p2rscblock, 0, p2offs); + scblock_delete_text(p2scblock, 0, p2offs); } /* else do nothing */ } else { printf("Deleting the whole non-text SCBlock\n"); @@ -1610,10 +1559,10 @@ void show_para(Paragraph *p) printf(_("%i runs:\n"), p->n_runs); for ( i=0; in_runs; i++ ) { - printf(_(" Run %2i: SCBlock %p/%p %s '%s'\n"), - i, p->runs[i].scblock, p->runs[i].rscblock, + printf(_(" Run %2i: SCBlock %p %s '%s'\n"), + i, p->runs[i].scblock, pango_font_description_to_string(p->runs[i].fontdesc), - sc_block_contents(p->runs[i].rscblock)); + sc_block_contents(p->runs[i].scblock)); } } else if ( p->type == PARA_TYPE_IMAGE ) { @@ -1695,9 +1644,8 @@ static SCBlock *split_text_paragraph(struct frame *fr, int pn, size_t pos, end = sc_block_append(np, NULL, NULL, strdup(""), NULL); pnew->n_runs = 0; - add_run(pnew, end, end, fr->fontdesc, fr->col); + add_run(pnew, end, fr->fontdesc, fr->col); pnew->scblock = end; - pnew->rscblock = end; wrap_paragraph(pnew, pc, fr->w - fr->pad_l - fr->pad_r, 0, 0); @@ -1710,12 +1658,11 @@ static SCBlock *split_text_paragraph(struct frame *fr, int pn, size_t pos, /* Split the run (and SCBlock) into two */ double col[4] = {0,0,0,0}; struct text_run *rn; - int macro = 0; printf("Splitting run %i. Before:\n", run); show_para(para); - add_run(para, NULL, NULL, NULL, col); + add_run(para, NULL, NULL, col); /* -2 here because add_run increased para->n_runs by 1 */ memmove(¶->runs[run+2], ¶->runs[run+1], (para->n_runs - run - 2)*sizeof(struct text_run)); @@ -1723,19 +1670,7 @@ static SCBlock *split_text_paragraph(struct frame *fr, int pn, size_t pos, rr = ¶->runs[run]; /* Because add_run realloced the runs */ rn = ¶->runs[run+1]; - if ( rr->rscblock != rr->scblock) { - macro = 1; - } - - rn->rscblock = sc_block_split(rr->rscblock, run_offs); - - if ( !macro ) { - /* Literal text block */ - rn->scblock = rn->rscblock; - } else { - /* Macro block */ - rn->scblock = rr->scblock; - } + rn->scblock = sc_block_split(rr->scblock, run_offs); rn->fontdesc = pango_font_description_copy(rr->fontdesc); rn->col[0] = rr->col[0]; @@ -1752,11 +1687,10 @@ static SCBlock *split_text_paragraph(struct frame *fr, int pn, size_t pos, for ( i=run+1; in_runs; i++ ) { double col[4] = {0,0,0,0}; printf("Moving run %i to pos %i\n", i, pnew->n_runs); - add_run(pnew, NULL, NULL, NULL, col); + add_run(pnew, NULL, NULL, col); pnew->runs[pnew->n_runs-1] = para->runs[i]; } pnew->scblock = pnew->runs[0].scblock; - pnew->rscblock = pnew->runs[0].rscblock; /* Truncate the first paragraph at the appropriate position */ para->n_runs = run+1; @@ -1768,7 +1702,7 @@ static SCBlock *split_text_paragraph(struct frame *fr, int pn, size_t pos, show_para(pnew); /* Add a \newpara after the end of the first paragraph's SC */ - nnp = sc_block_append(rr->rscblock, strdup("newpara"), NULL, NULL, NULL); + nnp = sc_block_append(rr->scblock, strdup("newpara"), NULL, NULL, NULL); set_newline_at_end(pnew, get_newline_at_end(para)); set_newline_at_end(para, nnp); @@ -1853,12 +1787,6 @@ SCBlock *para_scblock(Paragraph *para) } -SCBlock *para_rscblock(Paragraph *para) -{ - return para->rscblock; -} - - enum para_type para_type(Paragraph *para) { return para->type; @@ -1872,13 +1800,11 @@ int para_debug_num_runs(Paragraph *para) } -int para_debug_run_info(Paragraph *para, int i, SCBlock **scblock, - SCBlock **rscblock) +int para_debug_run_info(Paragraph *para, int i, SCBlock **scblock) { if ( para->type != PARA_TYPE_TEXT ) return 1; if ( i >= para->n_runs ) return 1; *scblock = para->runs[i].scblock; - *rscblock = para->runs[i].rscblock; return 0; } diff --git a/src/frame.h b/src/frame.h index b50cfaf..f6a02b6 100644 --- a/src/frame.h +++ b/src/frame.h @@ -135,20 +135,19 @@ extern void set_newline_at_end(Paragraph *para, SCBlock *bl); extern void check_run(struct frame *fr, int pn); extern void show_edit_pos(struct edit_pos a); -extern void add_run(Paragraph *para, SCBlock *scblock, SCBlock *rscblock, +extern void add_run(Paragraph *para, SCBlock *scblock, PangoFontDescription *fdesc, double col[4]); extern Paragraph *insert_paragraph(struct frame *fr, int pos); extern Paragraph *add_callback_para(struct frame *fr, SCBlock *scblock, - SCBlock *rscblock, double w, double h, SCCallbackDrawFunc draw_func, SCCallbackClickFunc click_func, void *bvp, void *vp); extern void add_image_para(struct frame *fr, SCBlock *scblock, - SCBlock *rscblock, const char *filename, + const char *filename, ImageStore *is, double w, double h, int editable); extern void wrap_paragraph(Paragraph *para, PangoContext *pc, double w, @@ -198,14 +197,12 @@ extern int get_sc_pos(struct frame *fr, int pn, size_t pos, extern void *get_para_bvp(Paragraph *para); -extern Paragraph *create_paragraph(struct frame *fr, SCBlock *bl, SCBlock *rbl); +extern Paragraph *create_paragraph(struct frame *fr, SCBlock *bl); extern enum para_type para_type(Paragraph *para); extern SCBlock *para_scblock(Paragraph *para); -extern SCBlock *para_rscblock(Paragraph *para); extern int para_debug_num_runs(Paragraph *para); -extern int para_debug_run_info(Paragraph *para, int i, SCBlock **scblock, - SCBlock **rscblock); +extern int para_debug_run_info(Paragraph *para, int i, SCBlock **scblock); #endif /* FRAME_H */ diff --git a/src/sc_editor.c b/src/sc_editor.c index 0431b7b..0bf2dc2 100644 --- a/src/sc_editor.c +++ b/src/sc_editor.c @@ -999,7 +999,7 @@ static void insert_text(char *t, SCEditor *e) fprintf(stderr, _("Failed to insert paragraph\n")); return; } - add_run(pnew, ad, ad, e->cursor_frame->fontdesc, + add_run(pnew, ad, e->cursor_frame->fontdesc, e->cursor_frame->col); wrap_frame(e->cursor_frame, e->pc); @@ -1222,7 +1222,7 @@ static void check_paragraph(struct frame *fr, PangoContext *pc, } scblocks = sc_block_append(scblocks, NULL, NULL, strdup(""), NULL); - add_run(para, scblocks, scblocks, fr->fontdesc, fr->col); + add_run(para, scblocks, fr->fontdesc, fr->col); wrap_paragraph(para, pc, fr->w - fr->pad_l - fr->pad_r, 0, 0); } diff --git a/src/sc_interp.c b/src/sc_interp.c index e357150..7b996f6 100644 --- a/src/sc_interp.c +++ b/src/sc_interp.c @@ -221,9 +221,6 @@ static int check_callback(SCInterpreter *scin, SCBlock *bl) double w, h; int r; void *bvp; - SCBlock *rbl; - - rbl = bl; if ( strcmp(cbl->names[i], name) != 0 ) continue; r = cbl->box_funcs[i](scin, bl, &w, &h, &bvp, cbl->vps[i]); @@ -231,7 +228,7 @@ static int check_callback(SCInterpreter *scin, SCBlock *bl) struct sc_state *st = &scin->state[scin->j]; Paragraph *pnew; pnew = add_callback_para(sc_interp_get_frame(scin), - bl, rbl, w, h, + bl, w, h, cbl->draw_funcs[i], cbl->click_funcs[i], bvp, cbl->vps[i]); @@ -947,7 +944,7 @@ static void maybe_recurse_after(SCInterpreter *scin, SCBlock *child, } -static void add_newpara(struct frame *fr, SCBlock *bl, SCBlock *mrb) +static void add_newpara(struct frame *fr, SCBlock *bl) { Paragraph *last_para; @@ -958,7 +955,7 @@ static void add_newpara(struct frame *fr, SCBlock *bl, SCBlock *mrb) /* The block after the \newpara will always be the first one of the * next paragraph, by definition, even if it's \f or another \newpara */ - create_paragraph(fr, sc_block_next(mrb), sc_block_next(bl)); + create_paragraph(fr, sc_block_next(bl)); } @@ -970,7 +967,6 @@ static int add_text(struct frame *fr, PangoContext *pc, SCBlock *bl, PangoFontDescription *fontdesc; double *col; struct sc_state *st = &scin->state[scin->j]; - SCBlock *rbl; Paragraph *para; /* Empty block? */ @@ -979,18 +975,16 @@ static int add_text(struct frame *fr, PangoContext *pc, SCBlock *bl, fontdesc = sc_interp_get_fontdesc(scin); col = sc_interp_get_fgcol(scin); - rbl = bl; - para = last_para(fr); if ( (para == NULL) || (para_type(para) != PARA_TYPE_TEXT) ) { /* Last paragraph is not text. * or: no paragraphs yet. * Either way: Create the first one */ - para = create_paragraph(fr, bl, rbl); + para = create_paragraph(fr, bl); } set_para_alignment(para, st->alignment); - add_run(para, bl, rbl, fontdesc, col); + add_run(para, bl, fontdesc, col); set_para_spacing(para, st->paraspace); return 0; @@ -1115,8 +1109,7 @@ static int check_outputs(SCBlock *bl, SCInterpreter *scin, Stylesheet *ss) if ( parse_image_options(options, sc_interp_get_frame(scin), &w, &h, &filename) == 0 ) { - SCBlock *rbl = bl; - add_image_para(sc_interp_get_frame(scin), bl, rbl, + add_image_para(sc_interp_get_frame(scin), bl, filename, scin->is, w, h, 1); free(filename); } else { @@ -1138,8 +1131,7 @@ static int check_outputs(SCBlock *bl, SCInterpreter *scin, Stylesheet *ss) } else if ( strcmp(name, "newpara")==0 ) { struct frame *fr = sc_interp_get_frame(scin); - SCBlock *rbl = bl; - add_newpara(fr, bl, rbl); + add_newpara(fr, bl); } else { return 0; -- cgit v1.2.3 From 6f4dfee487a912ad8db247ca57cd0dc87488cdee Mon Sep 17 00:00:00 2001 From: Thomas White Date: Sat, 20 Oct 2018 10:01:57 +0200 Subject: Append new block inside frame top level block fr->scblocks is the block which created the frame, e.g. \f Therefore the new block at the end needs to be appended inside, not after. --- src/frame.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/frame.c b/src/frame.c index 4ea97d4..2f6d16b 100644 --- a/src/frame.c +++ b/src/frame.c @@ -733,7 +733,7 @@ void ensure_run(struct frame *fr, struct edit_pos cpos) /* If the paragraph's SCBlock is NULL, it means this paragraph * is right at the end of the document. The last thing in the * document is something like \newpara. */ - bl = sc_block_append_end(fr->scblocks, NULL, NULL, strdup("")); + bl = sc_block_append_inside(fr->scblocks, NULL, NULL, strdup("")); } -- cgit v1.2.3 From ae183124e9317f3d183da746b93d75909c7b89b5 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Sat, 20 Oct 2018 10:02:31 +0200 Subject: Remove template stuff --- src/narrative_window.c | 59 ++--------------------------------- src/sc_interp.c | 84 -------------------------------------------------- src/sc_interp.h | 11 ------- 3 files changed, 2 insertions(+), 152 deletions(-) diff --git a/src/narrative_window.c b/src/narrative_window.c index 7a19562..ead78bd 100644 --- a/src/narrative_window.c +++ b/src/narrative_window.c @@ -185,59 +185,6 @@ static void delete_slide_sig(GSimpleAction *action, GVariant *parameter, } -static struct template_id *get_templates(Stylesheet *ss, int *n) -{ - /* FIXME: From JSON stylesheet */ - *n = 0; - return NULL; -} - - -static void update_template_menus(NarrativeWindow *nw) -{ - struct template_id *templates; - int i, n_templates; - - templates = get_templates(nw->p->stylesheet, &n_templates); - - for ( i=0; isceditor); - /* Get the template */ - templ = get_slide_template(nw->p->stylesheet); /* our copy */ - show_sc_blocks(templ); + /* FIXME: Template from JSON */ + templ = sc_parse("\\slide{}"); /* Link the new SCBlock in */ if ( nsblock != NULL ) { @@ -865,7 +811,6 @@ NarrativeWindow *narrative_window_new(struct presentation *p, GApplication *papp "win.last"); update_toolbar(nw); - update_template_menus(nw); scroll = gtk_scrolled_window_new(NULL, NULL); gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(scroll), diff --git a/src/sc_interp.c b/src/sc_interp.c index 7b996f6..05e9325 100644 --- a/src/sc_interp.c +++ b/src/sc_interp.c @@ -38,13 +38,6 @@ #include "utils.h" -struct template -{ - char *name; - SCBlock *bl; -}; - - struct sc_state { PangoFontDescription *fontdesc; @@ -63,10 +56,6 @@ struct sc_state double slide_height; struct frame *fr; /* The current frame */ - - int n_templates; - int max_templates; - struct template *templates; }; struct _scinterp @@ -615,14 +604,6 @@ SCInterpreter *sc_interp_new(PangoContext *pc, PangoLanguage *lang, scin->cbl = NULL; st = &scin->state[0]; - st->n_templates = 0; - st->max_templates = 16; - st->templates = malloc(16*sizeof(struct template)); - if ( st->templates == NULL ) { - free(scin->state); - free(scin); - return NULL; - } st->fr = NULL; st->paraspace[0] = 0.0; st->paraspace[1] = 0.0; @@ -660,8 +641,6 @@ SCInterpreter *sc_interp_new(PangoContext *pc, PangoLanguage *lang, void sc_interp_destroy(SCInterpreter *scin) { - /* FIXME: Free all templates */ - /* Empty the stack */ while ( scin->j > 0 ) { sc_interp_restore(scin); @@ -1265,66 +1244,3 @@ int sc_interp_add_blocks(SCInterpreter *scin, SCBlock *bl, Stylesheet *ss) return 0; } - -static int try_add_template(SCInterpreter *scin, const char *options, SCBlock *bl) -{ - struct sc_state *st = &scin->state[scin->j]; - char *nn; - char *comma; - int i; - - nn = strdup(options); - comma = strchr(nn, ','); - if ( comma != NULL ) { - comma[0] = '\0'; - } - - for ( i=0; in_templates; i++ ) { - if ( strcmp(st->templates[i].name, nn) == 0 ) { - fprintf(stderr, _("Duplicate template '%s'\n"), nn); - return 0; - } - } - - if ( st->max_templates == st->n_templates ) { - - struct template *templates_new; - - templates_new = realloc(st->templates, sizeof(struct template) - * (st->max_templates+16)); - if ( templates_new == NULL ) { - fprintf(stderr, _("Failed to add templates\n")); - return 1; - } - - st->templates = templates_new; - st->max_templates += 16; - - } - - i = st->n_templates++; - - st->templates[i].name = nn; - st->templates[i].bl = bl; - - return 0; -} - - -struct template_id *sc_interp_get_templates(SCInterpreter *scin, int *np) -{ - struct template_id *list; - int i; - - list = malloc(sizeof(struct template_id)*scin->state->n_templates); - if ( list == NULL ) return NULL; - - for ( i=0; istate->n_templates; i++ ) { - list[i].name = strdup(scin->state->templates[i].name); - list[i].friendlyname = strdup(scin->state->templates[i].name); - list[i].scblock = sc_block_copy(scin->state->templates[i].bl); - } - - *np = scin->state->n_templates; - return list; -} diff --git a/src/sc_interp.h b/src/sc_interp.h index b0bd689..7593226 100644 --- a/src/sc_interp.h +++ b/src/sc_interp.h @@ -87,15 +87,4 @@ extern int sc_interp_get_height(SCInterpreter *scin); extern void update_geom(struct frame *fr); -struct template_id -{ - char *name; - char *friendlyname; - SCBlock *scblock; -}; - -extern struct template_id *sc_interp_get_templates(SCInterpreter *scin, - int *np); - - #endif /* SC_INTERP_H */ -- cgit v1.2.3 From 73433f7ee0ca0d86edacbe8544e95911a9856ddd Mon Sep 17 00:00:00 2001 From: Thomas White Date: Sat, 20 Oct 2018 10:09:38 +0200 Subject: Remove legacy API cruft --- src/colloquium.c | 6 ---- src/colloquium.h | 1 - src/debugger.c | 3 +- src/frame.c | 72 ++++++------------------------------------ src/frame.h | 13 ++------ src/sc_editor.c | 20 +----------- src/sc_editor.h | 4 --- src/sc_interp.c | 70 +++++++---------------------------------- src/sc_interp.h | 15 --------- src/sc_parse.c | 92 +----------------------------------------------------- src/sc_parse.h | 7 ----- src/slide_window.c | 2 +- src/slide_window.h | 1 - src/utils.c | 88 --------------------------------------------------- src/utils.h | 1 - 15 files changed, 29 insertions(+), 366 deletions(-) diff --git a/src/colloquium.c b/src/colloquium.c index 66e3dcb..a8da4d9 100644 --- a/src/colloquium.c +++ b/src/colloquium.c @@ -320,12 +320,6 @@ int colloquium_get_hidepointer(Colloquium *app) } -GtkBuilder *colloquium_get_uibuilder(Colloquium *app) -{ - return app->builder; -} - - static void colloquium_startup(GApplication *papp) { Colloquium *app = COLLOQUIUM(papp); diff --git a/src/colloquium.h b/src/colloquium.h index 4c8133f..89f600f 100644 --- a/src/colloquium.h +++ b/src/colloquium.h @@ -38,7 +38,6 @@ typedef struct _colloquium Colloquium; extern const char *colloquium_get_imagestore(Colloquium *app); extern int colloquium_get_hidepointer(Colloquium *app); -extern GtkBuilder *colloquium_get_uibuilder(Colloquium *app); extern void open_about_dialog(GtkWidget *parent); diff --git a/src/debugger.c b/src/debugger.c index c8cab67..12ef9d8 100644 --- a/src/debugger.c +++ b/src/debugger.c @@ -118,7 +118,8 @@ static void debug_text_para(Paragraph *para, cairo_t *cr, double *ypos, } } - snprintf(tmp, 255, "Newline at end: %p", get_newline_at_end(para)); + snprintf(tmp, 255, "Newline at end: %p", + para_debug_get_newline_at_end(para)); plot_text(cr, ypos, fontdesc, tmp); } diff --git a/src/frame.c b/src/frame.c index 2f6d16b..2926d4e 100644 --- a/src/frame.c +++ b/src/frame.c @@ -184,7 +184,7 @@ struct frame *add_subframe(struct frame *fr) } -void show_hierarchy(struct frame *fr, const char *t) +void show_frame_hierarchy(struct frame *fr, const char *t) { int i; char tn[1024]; @@ -195,65 +195,12 @@ void show_hierarchy(struct frame *fr, const char *t) printf(_("%s%p (%.2f x %.2f)\n"), t, fr, fr->w, fr->h); for ( i=0; inum_children; i++ ) { - show_hierarchy(fr->children[i], tn); + show_frame_hierarchy(fr->children[i], tn); } } -static struct frame *find_parent(struct frame *fr, struct frame *search) -{ - int i; - - for ( i=0; inum_children; i++ ) { - if ( fr->children[i] == search ) { - return fr; - } - } - - for ( i=0; inum_children; i++ ) { - struct frame *tt; - tt = find_parent(fr->children[i], search); - if ( tt != NULL ) return tt; - } - - return NULL; -} - - -void delete_subframe(struct frame *top, struct frame *fr) -{ - struct frame *parent; - int i, idx, found; - - parent = find_parent(top, fr); - if ( parent == NULL ) { - fprintf(stderr, _("Couldn't find parent when deleting frame.\n")); - return; - } - - found = 0; - for ( i=0; inum_children; i++ ) { - if ( parent->children[i] == fr ) { - idx = i; - found = 1; - break; - } - } - - if ( !found ) { - fprintf(stderr, _("Couldn't find child when deleting frame.\n")); - return; - } - - for ( i=idx; inum_children-1; i++ ) { - parent->children[i] = parent->children[i+1]; - } - - parent->num_children--; -} - - struct frame *find_frame_with_scblocks(struct frame *fr, SCBlock *scblocks) { int i; @@ -382,12 +329,18 @@ void wrap_paragraph(Paragraph *para, PangoContext *pc, double w, para->height = pango_units_to_double(rect.height); } -SCBlock *get_newline_at_end(Paragraph *para) +static SCBlock *get_newline_at_end(Paragraph *para) { return para->newline_at_end; } +SCBlock *para_debug_get_newline_at_end(Paragraph *para) +{ + return get_newline_at_end(para); +} + + void set_newline_at_end(Paragraph *para, SCBlock *bl) { para->newline_at_end = bl; @@ -655,7 +608,7 @@ void render_paragraph(cairo_t *cr, Paragraph *para, ImageStore *is) } -size_t end_offset_of_para(struct frame *fr, int pn) +static size_t end_offset_of_para(struct frame *fr, int pn) { int i; size_t total = 0; @@ -894,11 +847,6 @@ void cursor_moveh(struct frame *fr, struct edit_pos *cp, signed int dir) } -void cursor_movev(struct frame *fr, struct edit_pos *cp, signed int dir) -{ -} - - void check_callback_click(struct frame *fr, int para) { Paragraph *p = fr->paras[para]; diff --git a/src/frame.h b/src/frame.h index f6a02b6..b786065 100644 --- a/src/frame.h +++ b/src/frame.h @@ -115,8 +115,6 @@ struct frame extern struct frame *frame_new(void); extern void frame_free(struct frame *fr); extern struct frame *add_subframe(struct frame *fr); -extern void show_hierarchy(struct frame *fr, const char *t); -extern void delete_subframe(struct frame *top, struct frame *fr); extern struct frame *find_frame_with_scblocks(struct frame *top, SCBlock *scblocks); @@ -130,9 +128,7 @@ extern void set_para_alignment(Paragraph *para, PangoAlignment align); extern double paragraph_height(Paragraph *para); extern void render_paragraph(cairo_t *cr, Paragraph *para, ImageStore *is); -extern SCBlock *get_newline_at_end(Paragraph *para); extern void set_newline_at_end(Paragraph *para, SCBlock *bl); -extern void check_run(struct frame *fr, int pn); extern void show_edit_pos(struct edit_pos a); extern void add_run(Paragraph *para, SCBlock *scblock, @@ -153,8 +149,6 @@ extern void add_image_para(struct frame *fr, SCBlock *scblock, extern void wrap_paragraph(Paragraph *para, PangoContext *pc, double w, size_t sel_start, size_t sel_end); -extern size_t end_offset_of_para(struct frame *fr, int pn); - extern int find_cursor(struct frame *fr, double x, double y, struct edit_pos *pos); @@ -174,8 +168,6 @@ extern int get_cursor_pos(struct frame *fr, int cursor_para, int cursor_pos, extern void cursor_moveh(struct frame *fr, struct edit_pos *cp, signed int dir); -extern void cursor_movev(struct frame *fr, struct edit_pos *cp, signed int dir); - extern void check_callback_click(struct frame *fr, int para); extern size_t pos_trail_to_offset(Paragraph *para, size_t offs, int trail); @@ -186,12 +178,12 @@ extern void insert_text_in_paragraph(Paragraph *para, size_t offs, extern void delete_text_from_frame(struct frame *fr, struct edit_pos p1, struct edit_pos p2, double wrap_w); -extern size_t delete_text_in_paragraph(struct frame *fr, int npara, size_t offs0, ssize_t offs2); - extern SCBlock *split_paragraph(struct frame *fr, int pn, size_t pos, PangoContext *pc); extern SCBlock *block_at_cursor(struct frame *fr, int para, size_t pos); +extern void show_frame_hierarchy(struct frame *fr, const char *t); + extern int get_sc_pos(struct frame *fr, int pn, size_t pos, SCBlock **bl, size_t *ppos); @@ -202,6 +194,7 @@ extern Paragraph *create_paragraph(struct frame *fr, SCBlock *bl); extern enum para_type para_type(Paragraph *para); extern SCBlock *para_scblock(Paragraph *para); +extern SCBlock *para_debug_get_newline_at_end(Paragraph *para); extern int para_debug_num_runs(Paragraph *para); extern int para_debug_run_info(Paragraph *para, int i, SCBlock **scblock); diff --git a/src/sc_editor.c b/src/sc_editor.c index 0bf2dc2..e95beb4 100644 --- a/src/sc_editor.c +++ b/src/sc_editor.c @@ -384,7 +384,7 @@ void sc_editor_ensure_cursor(SCEditor *e) } -void sc_editor_remove_cursor(SCEditor *e) +static void sc_editor_remove_cursor(SCEditor *e) { e->cursor_frame = NULL; e->cpos.para = 0; @@ -1979,30 +1979,12 @@ void sc_editor_set_scblock(SCEditor *e, SCBlock *scblocks) } -SCBlock *sc_editor_get_scblock(SCEditor *e) -{ - return e->scblocks; -} - - static void update_size_request(SCEditor *e) { gtk_widget_set_size_request(GTK_WIDGET(e), 0, e->h + 2.0*e->min_border); } -void sc_editor_set_size(SCEditor *e, int w, int h) -{ - e->w = w; - e->h = h; - update_size_request(e); - if ( gtk_widget_get_mapped(GTK_WIDGET(e)) ) { - full_rerender(e); - sc_editor_redraw(e); - } -} - - void sc_editor_set_logical_size(SCEditor *e, double w, double h) { e->log_w = w; diff --git a/src/sc_editor.h b/src/sc_editor.h index 35557d4..d3c111b 100644 --- a/src/sc_editor.h +++ b/src/sc_editor.h @@ -170,11 +170,8 @@ typedef struct _sceditorclass SCEditorClass; extern void sc_editor_set_scblock(SCEditor *e, SCBlock *scblocks); extern void sc_editor_set_stylesheet(SCEditor *e, Stylesheet *stylesheet); -extern SCBlock *sc_editor_get_scblock(SCEditor *e); -extern GtkWidget *sc_editor_get_widget(SCEditor *e); extern SCEditor *sc_editor_new(SCBlock *scblocks, Stylesheet *stylesheet, PangoLanguage *lang, const char *storename); -extern void sc_editor_set_size(SCEditor *e, int w, int h); extern void sc_editor_set_logical_size(SCEditor *e, double w, double h); extern void sc_editor_set_flow(SCEditor *e, int flow); extern void sc_editor_set_scale(SCEditor *e, int scale); @@ -189,7 +186,6 @@ extern void sc_editor_paste(SCEditor *e); extern void sc_editor_add_storycode(SCEditor *e, const char *sc); extern void sc_editor_copy_selected_frame(SCEditor *e); extern void sc_editor_delete_selected_frame(SCEditor *e); -extern void sc_editor_remove_cursor(SCEditor *e); extern void sc_editor_ensure_cursor(SCEditor *e); extern SCBlock *split_paragraph_at_cursor(SCEditor *e); diff --git a/src/sc_interp.c b/src/sc_interp.c index 05e9325..780663f 100644 --- a/src/sc_interp.c +++ b/src/sc_interp.c @@ -86,6 +86,17 @@ struct _sccallbacklist }; +static int sc_interp_add_blocks(SCInterpreter *scin, SCBlock *bl, Stylesheet *ss) +{ + while ( bl != NULL ) { + if ( sc_interp_add_block(scin, bl, ss) ) return 1; + bl = sc_block_next(bl); + } + + return 0; +} + + SCCallbackList *sc_callback_list_new() { SCCallbackList *cbl; @@ -255,41 +266,6 @@ double *sc_interp_get_fgcol(SCInterpreter *scin) } -double *sc_interp_get_bgcol(SCInterpreter *scin) -{ - struct sc_state *st = &scin->state[scin->j]; - return st->bgcol; -} - - -double *sc_interp_get_bgcol2(SCInterpreter *scin) -{ - struct sc_state *st = &scin->state[scin->j]; - return st->bgcol2; -} - - -GradientType sc_interp_get_bggrad(SCInterpreter *scin) -{ - struct sc_state *st = &scin->state[scin->j]; - return st->bggrad; -} - - -int sc_interp_get_ascent(SCInterpreter *scin) -{ - struct sc_state *st = &scin->state[scin->j]; - return st->ascent; -} - - -int sc_interp_get_height(SCInterpreter *scin) -{ - struct sc_state *st = &scin->state[scin->j]; - return st->height; -} - - static void set_frame_default_style(struct frame *fr, SCInterpreter *scin) { if ( fr == NULL ) return; @@ -686,19 +662,6 @@ static void set_paraspace(SCInterpreter *scin, const char *opts) } -static void set_slide_size(SCInterpreter *scin, const char *opts) -{ - float p[2]; - struct sc_state *st = &scin->state[scin->j]; - - if ( parse_double(opts, p) ) return; - - st->slide_width = p[0]; - st->slide_height = p[1]; - st->have_size = 1; -} - - void update_geom(struct frame *fr) { char geom[256]; @@ -1233,14 +1196,3 @@ int sc_interp_add_block(SCInterpreter *scin, SCBlock *bl, Stylesheet *ss) return 0; } - -int sc_interp_add_blocks(SCInterpreter *scin, SCBlock *bl, Stylesheet *ss) -{ - while ( bl != NULL ) { - if ( sc_interp_add_block(scin, bl, ss) ) return 1; - bl = sc_block_next(bl); - } - - return 0; -} - diff --git a/src/sc_interp.h b/src/sc_interp.h index 7593226..418d6a6 100644 --- a/src/sc_interp.h +++ b/src/sc_interp.h @@ -50,14 +50,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, Stylesheet *ss); extern int sc_interp_add_block(SCInterpreter *scin, SCBlock *bl, Stylesheet *ss); -extern void sc_interp_run_stylesheet(SCInterpreter *scin, SCBlock *bl); -extern void sc_interp_run_style(SCInterpreter *scin, const char *sname); -extern void add_macro(SCInterpreter *scin, const char *mname, - const char *contents); - /* Callback lists */ extern SCCallbackList *sc_callback_list_new(); @@ -74,15 +68,6 @@ extern struct frame *sc_interp_get_frame(SCInterpreter *scin); extern PangoFont *sc_interp_get_font(SCInterpreter *scin); extern PangoFontDescription *sc_interp_get_fontdesc(SCInterpreter *scin); extern double *sc_interp_get_fgcol(SCInterpreter *scin); -extern double *sc_interp_get_bgcol(SCInterpreter *scin); -extern double *sc_interp_get_bgcol2(SCInterpreter *scin); -extern GradientType sc_interp_get_bggrad(SCInterpreter *scin); - -extern int sc_interp_get_slide_size(SCInterpreter *scin, double *w, double *h); -extern SCBlock *sc_interp_get_macro_real_block(SCInterpreter *scin); - -extern int sc_interp_get_ascent(SCInterpreter *scin); -extern int sc_interp_get_height(SCInterpreter *scin); extern void update_geom(struct frame *fr); diff --git a/src/sc_parse.c b/src/sc_parse.c index b66dc1f..e8904a0 100644 --- a/src/sc_parse.c +++ b/src/sc_parse.c @@ -264,26 +264,8 @@ static SCBlock *sc_find_parent(SCBlock *top, SCBlock *find) } -void sc_block_substitute(SCBlock **top, SCBlock *old, SCBlock *new) -{ - if ( old == NULL ) { - fprintf(stderr, _("Substituting nothing!\n")); - return; - } - - if ( old == *top ) { - /* It is the first block */ - new->next = old->next; - *top = new; - } else { - sc_block_unlink(top, old); - sc_block_append_p(*top, new); - } -} - - /* Unlink "deleteme", which is somewhere under "top" */ -int sc_block_unlink(SCBlock **top, SCBlock *deleteme) +static int sc_block_unlink(SCBlock **top, SCBlock *deleteme) { SCBlock *parent = sc_find_parent(*top, deleteme); if ( parent == NULL ) { @@ -413,36 +395,6 @@ char *serialise_sc_block(const SCBlock *bl) } -/* Serialise an entire chain of blocks */ -char *serialise_sc_block_chain(const SCBlock *bl) -{ - char *a = strdup(""); - size_t len = 1; - - if ( a == NULL ) return NULL; - - while ( bl != NULL ) { - - char *c = serialise_sc_block(bl); - if ( c == NULL ) { - free(a); - return NULL; - } - - len += strlen(c); - a = realloc(a, len); - if ( a == NULL ) return NULL; - strcat(a, c); - free(c); - - bl = bl->next; - - } - - return a; -} - - int save_sc_block(GOutputStream *fh, const SCBlock *bl) { while ( bl != NULL ) { @@ -770,17 +722,6 @@ void sc_block_set_contents(SCBlock *bl, char *con) } -SCBlock *find_last_child(SCBlock *bl) -{ - if ( bl == NULL ) return NULL; - if ( bl->child == NULL ) return NULL; - - bl = bl->child; - while ( bl->next != NULL ) bl = bl->next; - return bl; -} - - void sc_insert_text(SCBlock *b1, size_t o1, const char *t) { if ( b1->contents == NULL ) { @@ -850,37 +791,6 @@ size_t scblock_delete_text(SCBlock *b, ssize_t o1, ssize_t o2) } -/* Create a deep copy of "bl", including all its children */ -SCBlock *sc_block_copy(const SCBlock *bl) -{ - SCBlock *copy; - SCBlock *first_copy; - - first_copy = sc_block_new(); - - copy = first_copy; - do { - - if ( bl->name != NULL ) copy->name = strdup(bl->name); - if ( bl->options != NULL ) copy->options = strdup(bl->options); - if ( bl->contents != NULL ) copy->contents = strdup(bl->contents); - if ( bl->child != NULL ) copy->child = sc_block_copy(bl->child); - - bl = bl->next; - - if ( bl != NULL ) { - SCBlock *nn; - nn = sc_block_new(); - copy->next = nn; - copy = nn; - } - - } while ( bl != NULL ); - - return first_copy; -} - - static char *s_strdup(const char *a) { if ( a == NULL ) return NULL; diff --git a/src/sc_parse.h b/src/sc_parse.h index 9277ee6..17ce2dd 100644 --- a/src/sc_parse.h +++ b/src/sc_parse.h @@ -37,14 +37,11 @@ extern SCBlock *sc_parse(const char *sc); extern SCBlock *sc_block_new(void); extern void sc_block_free(SCBlock *bl); -extern SCBlock *sc_block_copy(const SCBlock *bl); - extern SCBlock *sc_block_next(const SCBlock *bl); extern SCBlock *sc_block_child(const SCBlock *bl); extern const char *sc_block_name(const SCBlock *bl); extern const char *sc_block_options(const SCBlock *bl); extern const char *sc_block_contents(const SCBlock *bl); -extern void sc_block_substitute(SCBlock **top, SCBlock *old, SCBlock *new); extern SCBlock *sc_block_append(SCBlock *bl, char *name, char *opt, char *contents, @@ -68,9 +65,6 @@ extern SCBlock *sc_block_insert_after(SCBlock *afterme, char *name, char *opt, char *contents); extern int sc_block_delete(SCBlock **top, SCBlock *deleteme); -extern int sc_block_unlink(SCBlock **top, SCBlock *deleteme); - -extern SCBlock *find_last_child(SCBlock *bl); extern void sc_block_set_name(SCBlock *bl, char *nam); @@ -84,7 +78,6 @@ extern void show_sc_blocks(const SCBlock *bl); extern void show_sc_block(const SCBlock *bl, const char *prefix); extern char *serialise_sc_block(const SCBlock *bl); -extern char *serialise_sc_block_chain(const SCBlock *bl); extern int save_sc_block(GOutputStream *fh, const SCBlock *bl); extern size_t scblock_delete_text(SCBlock *b, ssize_t o1, ssize_t o2); diff --git a/src/slide_window.c b/src/slide_window.c index b010d1b..e23a3d7 100644 --- a/src/slide_window.c +++ b/src/slide_window.c @@ -109,7 +109,7 @@ static void delete_frame_sig(GSimpleAction *action, GVariant *parameter, /* Change the editor's slide to "np" */ -void change_edit_slide(SlideWindow *sw, SCBlock *np) +static void change_edit_slide(SlideWindow *sw, SCBlock *np) { sc_editor_set_slidenum(sw->sceditor, slide_number(sw->p, np)); diff --git a/src/slide_window.h b/src/slide_window.h index 77de920..b1d39a8 100644 --- a/src/slide_window.h +++ b/src/slide_window.h @@ -31,6 +31,5 @@ typedef struct _slidewindow SlideWindow; extern SlideWindow *slide_window_open(struct presentation *p, SCBlock *scblocks, GApplication *app); -extern void change_edit_slide(SlideWindow *sw, SCBlock *np); #endif /* SLIDEWINDOW_H */ diff --git a/src/utils.c b/src/utils.c index bafbb99..277b3f1 100644 --- a/src/utils.c +++ b/src/utils.c @@ -54,61 +54,6 @@ int safe_strcmp(const char *a, const char *b) } -static char *fgets_long(FILE *fh, size_t *lp) -{ - char *line; - size_t la; - size_t l = 0; - - la = 1024; - line = malloc(la); - if ( line == NULL ) return NULL; - - do { - - int r; - - r = fgetc(fh); - if ( r == EOF ) { - if ( l == 0 ) { - free(line); - *lp = 0; - return NULL; - } else { - line[l++] = '\0'; - *lp = l; - return line; - } - } - - line[l++] = r; - - if ( r == '\n' ) { - line[l++] = '\0'; - *lp = l; - return line; - } - - if ( l == la ) { - - char *ln; - - la += 1024; - ln = realloc(line, la); - if ( ln == NULL ) { - free(line); - *lp = 0; - return NULL; - } - - line = ln; - - } - - } while ( 1 ); -} - - int parse_double(const char *a, float v[2]) { int nn; @@ -136,36 +81,3 @@ int parse_tuple(const char *a, float v[4]) return 0; } - -char *load_everything(const char *filename) -{ - FILE *fh; - size_t el = 1; - char *everything = strdup(""); - - fh = fopen(filename, "r"); - if ( fh == NULL ) return NULL; - - while ( !feof(fh) ) { - - size_t len = 0; - char *line = fgets_long(fh, &len); - - if ( line != NULL ) { - - everything = realloc(everything, el+len); - if ( everything == NULL ) { - fprintf(stderr, _("Failed to allocate memory\n")); - return NULL; - } - el += len; - - strcat(everything, line); - } - - } - - fclose(fh); - - return everything; -} diff --git a/src/utils.h b/src/utils.h index 8870a98..fc843c3 100644 --- a/src/utils.h +++ b/src/utils.h @@ -32,7 +32,6 @@ extern void chomp(char *s); extern int safe_strcmp(const char *a, const char *b); extern int parse_double(const char *a, float v[2]); extern int parse_tuple(const char *a, float v[4]); -extern char *load_everything(const char *filename); #include #define _(x) gettext(x) -- cgit v1.2.3 From a85c7fd76dd50d82841e01018b532ad790f8c564 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Sun, 21 Oct 2018 18:01:52 +0200 Subject: Update demo doc and remove old test stylesheets --- data/colloquium.gresource.xml | 1 + data/demo.sc | 23 +++-------------------- data/demo.ss | 37 +++++++++++++++++++++++++++++++++++++ stylesheet.json | 40 ---------------------------------------- test.ss | 18 ------------------ 5 files changed, 41 insertions(+), 78 deletions(-) create mode 100644 data/demo.ss delete mode 100644 stylesheet.json delete mode 100644 test.ss diff --git a/data/colloquium.gresource.xml b/data/colloquium.gresource.xml index 369144b..9c85e5b 100644 --- a/data/colloquium.gresource.xml +++ b/data/colloquium.gresource.xml @@ -5,6 +5,7 @@ menus.ui stylesheeteditor.ui demo.sc + demo.ss canvas.png alpha_warning.svg colloquium.svg diff --git a/data/demo.sc b/data/demo.sc index 805cfb4..e6a60a7 100644 --- a/data/demo.sc +++ b/data/demo.sc @@ -1,21 +1,4 @@ -\stylesheet{ - - \style[narrative]{\font[Cantarell Regular 16]\paraspace[0,0,10,10]\pad[10,10,10,10]\fgcol[#222222]\bgcol[#ffffff]} - \style[slide]{\bggradv[#333333,#000055]} - \style[frame]{\fgcol[#c5c5c5]} - \slidesize[1024x768] - - \def[prestitle]{\f[1fx140u+0+0]\pad[20,20,20,20]\fontsize[64]\fgcol[#eeeeee]\center\contents} - \def[slidetitle]{\f[1fx90u+0+0]\pad[20,20,20,20]\fontsize[36]\fgcol[#eeeeee]\contents} - \def[footer]{\f[0.97fx30u+0+740]{\ralign\editable{\fontsize[11]\bold{T. A. White} | \editable{A demonstration talk | 1 March 2018} | \bold{Slide} \slidenumber}}} - \def[credit]{\f[600ux30u+700+700]{\fontsize[11]\contents}} - \def[bp]{➤ } - - \template[slide]{\slide{\slidetitle{New slide}\footer}} - \template[bp,name="Bullet point"]{\bp{}} - \template[credit,name="Credit"]{\credit{Image: }} - -}\fontsize[40]{\bold{}Hi there, welcome to \bold{Colloquium}!} +\fontsize[40]{\bold{}Hi there, welcome to \bold{Colloquium}!} It looks like this is the first time you've used Colloquium. Keep reading to understand a little bit about how Colloquium works and how to use it. Colloquium works differently to other presentation programs. Colloquium makes \italic{narrative, not slides,} the centre of attention. Slides come when you need to illustrate something. This window is called the \oblique{narrative editor}. Your slides are embedded into the narrative text, like this:\slide{ \prestitle{Welcome to Colloquium} @@ -36,7 +19,7 @@ What is the narrative window for? Well, it's up to you! Here are some suggesti \bp{}Use it as a journal, adding slides whenever you have an illustration. You'll have a ready-made presentation on your activity, with no extra effort! Besides this, Colloquium has some features which will help you when you come to give your presentation. In the "Tools" menu, you'll find the presentation clock and the test card. Use the test card to make sure your computer is talking to the projector correctly. It shows you the resolution of the screen, where it thinks the edges are, and some colours. This helps you spot and fix all-too-common display problems early. -Now, a short warning:\slide{\slidetitle{Alpha test software}\footer\f[394.9ux428.0u+571.9+178.8]{Colloquium is "alpha test" software. +Now, a short warning:\slide{\slidetitle{Alpha test software}\footer\f[391.8ux473.5u+567.8+143.7]{Colloquium is "alpha test" software. It will probably crash and lose your work a few times. Save and back up your work as frequently as possible. @@ -45,5 +28,5 @@ However, in years of use it has \bold{never} crashed on me in front of an audien Creating a backup slide deck in PDF format (File->Export slides as PDF) is nevertheless a wise safety measure. Please report all bugs here: -https://www.bitwiz.me.uk/tracker}\f[452.2ux431.0u+64.8+168.9]{\image[1fx1f+0+0,filename="alpha_warning.svg"]{}}} +https://github.com/taw10/colloquium/issues}\f[452.2ux431.0u+64.8+168.9]{\image[1fx1f+0+0,filename="alpha_warning.svg"]{}}\f[2.1ux10.3u+959.6+665.7]{}\f[0.0ux31.0u+957.5+654.3]{}} That's enough to get you started. I hope you enjoy using Colloquium! diff --git a/data/demo.ss b/data/demo.ss new file mode 100644 index 0000000..507299d --- /dev/null +++ b/data/demo.ss @@ -0,0 +1,37 @@ +{ + "narrative": { + "font": "Cantarell Regular 16", + "fgcol": "#222222", + "pad": "10,10,10,10", + "paraspace": "0,0,10,10", + "bgcol": "#ffffff" + }, + + "slide": { + "size": "1024x768", + "bggradv": "#333333,#000055", + "frame": { + "font": "Cantarell Regular 14", + "pad": "0,0,0,0", + "fgcol": "#c5c5c5", + "bgcol": "#ffffff00", + "paraspace": "5,5,5,5" + }, + "slidetitle": { + "geometry": "1fx90u+0+0", + "pad": "20,20,20,20", + "fgcol": "#eeeeee", + "font": "Cantarell Regular 36", + "bgcol": "#ffffff00" + }, + "prestitle": { + "geometry": "1fx140u+0+0", + "pad": "20,20,20,20", + "fgcol": "#eeeeee", + "font": "Cantarell Regular 64", + "alignment": "center", + "bgcol": "#ffffff00" + }, + "_comment": "Add footer, credit and bp" + } +} diff --git a/stylesheet.json b/stylesheet.json deleted file mode 100644 index 92c3a7e..0000000 --- a/stylesheet.json +++ /dev/null @@ -1,40 +0,0 @@ -{ - "narrative": { - "font": "Comfortaa 16", - "fgcol": "#000000", - "pad": "10,10,10,10", - "paraspace": "5,5,5,5" - }, - - "slide": { - "size": "1280x720", - "bggradv": "#729fcf,#d3d7cf", - "frame": { - "font": "Comfortaa 20", - "bgcol": "#ffffff00" - }, - "slidetitle": { - "geometry": "1fx90u+0+0", - "pad": "30,30,30,30", - "fgcol": "#000000", - "font": "Comfortaa Bold 40", - "bgcol": "#ffffff00" - }, - "prestitle": { - "geometry": "1fx240u+0+160", - "pad": "50,50,50,50", - "fgcol": "#000000", - "font": "Comfortaa Bold 45", - "alignment": "center", - "bgcol": "#ffffff00" - }, - "author": { - "geometry": "1fx240u+0+360", - "pad": "80,80,80,80", - "fgcol": "#000000", - "font": "Comfortaa 20", - "alignment": "center", - "bgcol": "#ffffff00" - } - } -} diff --git a/test.ss b/test.ss deleted file mode 100644 index 2dd2b40..0000000 --- a/test.ss +++ /dev/null @@ -1,18 +0,0 @@ -{ - "narrative": { - "font": "Cantarell Regular 14", - "fgcol": "#000000" - }, - - "slide": { - "bggrad": null, - "bgcol1": "#ffffff", - "frame": { - "font": "Cantarell Regular 14", - "bggrad": "vertical", - "bgcol1": "#000099", - "bgcol2": "#000000" - } - } -} - -- cgit v1.2.3 From 27e08c96c71183edea9be3e189d7152c19b1beac Mon Sep 17 00:00:00 2001 From: Thomas White Date: Sun, 21 Oct 2018 18:03:01 +0200 Subject: Try .ss for stylesheet --- src/narrative_window.c | 8 ++++---- src/presentation.c | 20 +++++++++++++++++++- src/sc_interp.c | 2 ++ src/stylesheet.c | 14 ++++++++++++-- src/stylesheet.h | 4 +++- 5 files changed, 40 insertions(+), 8 deletions(-) diff --git a/src/narrative_window.c b/src/narrative_window.c index ead78bd..b287f61 100644 --- a/src/narrative_window.c +++ b/src/narrative_window.c @@ -190,12 +190,12 @@ static gint load_ss_response_sig(GtkWidget *d, gint response, { if ( response == GTK_RESPONSE_ACCEPT ) { - char *filename; + GFile *file; Stylesheet *new_ss; - filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(d)); + file = gtk_file_chooser_get_file(GTK_FILE_CHOOSER(d)); - new_ss = stylesheet_load(filename); + new_ss = stylesheet_load(file); if ( new_ss != NULL ) { stylesheet_free(nw->p->stylesheet); @@ -209,7 +209,7 @@ static gint load_ss_response_sig(GtkWidget *d, gint response, fprintf(stderr, _("Failed to load\n")); } - g_free(filename); + g_object_unref(file); } diff --git a/src/presentation.c b/src/presentation.c index 1aa126a..a33a541 100644 --- a/src/presentation.c +++ b/src/presentation.c @@ -245,6 +245,8 @@ int load_presentation(struct presentation *p, GFile *file) { int r = 0; char *everything; + GFile *ssfile; + gchar *ssuri; assert(p->completely_empty); @@ -266,7 +268,23 @@ int load_presentation(struct presentation *p, GFile *file) return r; /* Error */ } - p->stylesheet = stylesheet_load("stylesheet.json"); /* FIXME: ! */ + p->stylesheet = NULL; + ssuri = g_file_get_uri(file); + if ( ssuri != NULL ) { + size_t l = strlen(ssuri); + if ( ssuri[l-3] == '.' && ssuri[l-2] == 's' && ssuri[l-1] =='c' ) { + ssuri[l-1] = 's'; + ssfile = g_file_new_for_uri(ssuri); + p->stylesheet = stylesheet_load(ssfile); + g_object_unref(ssfile); + g_free(ssuri); + } + } + if ( p->stylesheet == NULL ) { + ssfile = g_file_new_for_path("./stylesheet.json"); + p->stylesheet = stylesheet_load(ssfile); + g_object_unref(ssfile); + } set_slide_size_from_stylesheet(p); diff --git a/src/sc_interp.c b/src/sc_interp.c index 780663f..010b100 100644 --- a/src/sc_interp.c +++ b/src/sc_interp.c @@ -945,6 +945,8 @@ static void apply_style(SCInterpreter *scin, Stylesheet *ss, const char *path) return; } + if ( ss == NULL ) return; + /* Font */ strcpy(fullpath, path); strcat(fullpath, ".font"); diff --git a/src/stylesheet.c b/src/stylesheet.c index 228c331..020107e 100644 --- a/src/stylesheet.c +++ b/src/stylesheet.c @@ -29,8 +29,10 @@ #include #include #include +#include #include "stylesheet.h" +#include "utils.h" struct _stylesheet { @@ -38,19 +40,27 @@ struct _stylesheet { }; -Stylesheet *stylesheet_load(const char *filename) +Stylesheet *stylesheet_load(GFile *file) { JsonParser *parser; gboolean r; GError *err = NULL; Stylesheet *ss; + char *everything; + gsize len; ss = calloc(1, sizeof(Stylesheet)); if ( ss == NULL ) return NULL; parser = json_parser_new(); - r = json_parser_load_from_file(parser, filename, &err); + if ( !g_file_load_contents(file, NULL, &everything, &len, NULL, NULL) ) { + fprintf(stderr, _("Failed to load stylesheet '%s'\n"), + g_file_get_uri(file)); + return NULL; + } + + r = json_parser_load_from_data(parser, everything, len, &err); if ( r == FALSE ) { fprintf(stderr, "Failed to load style sheet: '%s'\n", err->message); return NULL; diff --git a/src/stylesheet.h b/src/stylesheet.h index 59afa7d..aa5867f 100644 --- a/src/stylesheet.h +++ b/src/stylesheet.h @@ -27,9 +27,11 @@ #include #endif +#include + typedef struct _stylesheet Stylesheet; -extern Stylesheet *stylesheet_load(const char *filename); +extern Stylesheet *stylesheet_load(GFile *file); extern char *stylesheet_lookup(Stylesheet *ss, const char *path); extern void stylesheet_free(Stylesheet *ss); -- cgit v1.2.3 From 2236dea3df2e651a75788334c439f1ad312709f4 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Sun, 21 Oct 2018 18:08:06 +0200 Subject: Honour alignment in stylesheet --- src/sc_interp.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/src/sc_interp.c b/src/sc_interp.c index 010b100..ef3c7df 100644 --- a/src/sc_interp.c +++ b/src/sc_interp.c @@ -989,6 +989,22 @@ static void apply_style(SCInterpreter *scin, Stylesheet *ss, const char *path) result = stylesheet_lookup(ss, fullpath); if ( result != NULL ) set_paraspace(scin, result); + /* Alignment */ + strcpy(fullpath, path); + strcat(fullpath, ".alignment"); + result = stylesheet_lookup(ss, fullpath); + if ( result != NULL ) { + if ( strcmp(result, "center") == 0 ) { + set_alignment(scin, PANGO_ALIGN_CENTER); + } + if ( strcmp(result, "left") == 0 ) { + set_alignment(scin, PANGO_ALIGN_LEFT); + } + if ( strcmp(result, "right") == 0 ) { + set_alignment(scin, PANGO_ALIGN_RIGHT); + } + } + update_bg(scin); } -- cgit v1.2.3 From b79dad7a05ae97dffb3f5fd9ab48ff8ffbbf6ea7 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Sun, 21 Oct 2018 18:34:56 +0200 Subject: Full order of precedence for finding stylesheets --- data/colloquium.gresource.xml | 1 + data/default.ss | 37 +++++++++++++++++++++++++++++++++++++ src/presentation.c | 28 +++++++++++++++++++++++++++- src/stylesheet.c | 2 ++ 4 files changed, 67 insertions(+), 1 deletion(-) create mode 100644 data/default.ss diff --git a/data/colloquium.gresource.xml b/data/colloquium.gresource.xml index 9c85e5b..819a966 100644 --- a/data/colloquium.gresource.xml +++ b/data/colloquium.gresource.xml @@ -6,6 +6,7 @@ stylesheeteditor.ui demo.sc demo.ss + default.ss canvas.png alpha_warning.svg colloquium.svg diff --git a/data/default.ss b/data/default.ss new file mode 100644 index 0000000..5ea74f6 --- /dev/null +++ b/data/default.ss @@ -0,0 +1,37 @@ +{ + "narrative": { + "font": "Cantarell Regular 16", + "fgcol": "#222222", + "pad": "10,10,10,10", + "paraspace": "0,0,10,10", + "bgcol": "#ffffff" + }, + + "slide": { + "size": "1280x720", + "bggradv": "#333333,#000055", + "frame": { + "font": "Cantarell Regular 14", + "pad": "0,0,0,0", + "fgcol": "#c5c5c5", + "bgcol": "#ffffff00", + "paraspace": "5,5,5,5" + }, + "slidetitle": { + "geometry": "1fx90u+0+0", + "pad": "20,20,20,20", + "fgcol": "#eeeeee", + "font": "Cantarell Regular 36", + "bgcol": "#ffffff00" + }, + "prestitle": { + "geometry": "1fx140u+0+0", + "pad": "20,20,20,20", + "fgcol": "#eeeeee", + "font": "Cantarell Regular 64", + "alignment": "center", + "bgcol": "#ffffff00" + }, + "_comment": "Add footer, credit and bp" + } +} diff --git a/src/presentation.c b/src/presentation.c index a33a541..686c97d 100644 --- a/src/presentation.c +++ b/src/presentation.c @@ -246,6 +246,7 @@ int load_presentation(struct presentation *p, GFile *file) int r = 0; char *everything; GFile *ssfile; + GFile *parent; gchar *ssuri; assert(p->completely_empty); @@ -269,6 +270,8 @@ int load_presentation(struct presentation *p, GFile *file) } p->stylesheet = NULL; + + /* First choice: /same/directory/.ss */ ssuri = g_file_get_uri(file); if ( ssuri != NULL ) { size_t l = strlen(ssuri); @@ -280,12 +283,35 @@ int load_presentation(struct presentation *p, GFile *file) g_free(ssuri); } } + + /* Second choice: /same/directory/stylesheet.ss */ + if ( p->stylesheet == NULL ) { + parent = g_file_get_parent(file); + if ( parent != NULL ) { + ssfile = g_file_get_child(parent, "stylesheet.ss"); + if ( ssfile != NULL ) { + p->stylesheet = stylesheet_load(ssfile); + g_object_unref(ssfile); + } + } + } + + /* Third choice: /stylesheet.ss */ + if ( p->stylesheet == NULL ) { + ssfile = g_file_new_for_path("./stylesheet.ss"); + p->stylesheet = stylesheet_load(ssfile); + g_object_unref(ssfile); + } + + /* Fourth choice: internal default stylesheet */ if ( p->stylesheet == NULL ) { - ssfile = g_file_new_for_path("./stylesheet.json"); + ssfile = g_file_new_for_uri("resource:///uk/me/bitwiz/Colloquium/default.ss"); p->stylesheet = stylesheet_load(ssfile); g_object_unref(ssfile); } + /* Last resort is NULL stylesheet and SCInterpreter's defaults */ + set_slide_size_from_stylesheet(p); assert(p->uri == NULL); diff --git a/src/stylesheet.c b/src/stylesheet.c index 020107e..ed84905 100644 --- a/src/stylesheet.c +++ b/src/stylesheet.c @@ -49,6 +49,8 @@ Stylesheet *stylesheet_load(GFile *file) char *everything; gsize len; + printf("Trying stylesheet '%s'\n", g_file_get_uri(file)); + ss = calloc(1, sizeof(Stylesheet)); if ( ss == NULL ) return NULL; -- cgit v1.2.3 From ace5266b94dde5c90f3cc270abc1b698124fe343 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Mon, 22 Oct 2018 17:11:57 +0200 Subject: Remove struct print_stuff->{is,storename} --- src/print.c | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/print.c b/src/print.c index c50a3c5..18a083e 100644 --- a/src/print.c +++ b/src/print.c @@ -54,9 +54,6 @@ struct print_stuff struct frame *top; int start_paras[256]; int slide_number; - - ImageStore *is; - const char *storename; }; @@ -194,13 +191,11 @@ static void begin_narrative_print(GtkPrintOperation *op, GtkPrintContext *ctx, sc_callback_list_add_callback(cbl, "slide", print_create_thumbnail, print_render_thumbnail, NULL, ps); - ps->is = imagestore_new(ps->storename); - pc = gtk_print_context_create_pango_context(ctx); dummy_top = sc_block_new_parent(ps->p->scblocks, "presentation"); ps->top = interp_and_shape(dummy_top, ps->p->stylesheet, cbl, - ps->is, 0, pc, + ps->p->is, 0, pc, gtk_print_context_get_width(ctx), gtk_print_context_get_height(ctx), ps->p->lang); @@ -242,7 +237,7 @@ static void print_narrative(GtkPrintOperation *op, GtkPrintContext *ctx, h += paragraph_height(ps->top->paras[i]); if ( h > page_height ) return; - render_paragraph(cr, ps->top->paras[i], ps->is); + render_paragraph(cr, ps->top->paras[i], ps->p->is); cairo_translate(cr, 0.0, paragraph_height(ps->top->paras[i])); } -- cgit v1.2.3 From c355bcfac1e000fa8de99856af505a9208bb2f2c Mon Sep 17 00:00:00 2001 From: Thomas White Date: Mon, 22 Oct 2018 17:17:55 +0200 Subject: Wrap cairo_{save,restore} around paragraph rendering when printing narrative --- src/print.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/print.c b/src/print.c index 18a083e..43c967e 100644 --- a/src/print.c +++ b/src/print.c @@ -237,7 +237,10 @@ static void print_narrative(GtkPrintOperation *op, GtkPrintContext *ctx, h += paragraph_height(ps->top->paras[i]); if ( h > page_height ) return; + cairo_save(cr); render_paragraph(cr, ps->top->paras[i], ps->p->is); + cairo_restore(cr); + cairo_translate(cr, 0.0, paragraph_height(ps->top->paras[i])); } -- cgit v1.2.3 From d5f7ae9d6a28781051d7649a656dd2f93b6ea96d Mon Sep 17 00:00:00 2001 From: Thomas White Date: Thu, 25 Oct 2018 23:28:33 +0200 Subject: Set values in stylesheet editor --- data/stylesheeteditor.ui | 1141 +++++++++++++++++++--------------------------- src/stylesheet.c | 5 +- src/stylesheet_editor.c | 238 +++++++++- src/stylesheet_editor.h | 18 + 4 files changed, 736 insertions(+), 666 deletions(-) diff --git a/data/stylesheeteditor.ui b/data/stylesheeteditor.ui index 6e61d79..bfe08b6 100644 --- a/data/stylesheeteditor.ui +++ b/data/stylesheeteditor.ui @@ -2,6 +2,96 @@ + + 2000 + 1 + 10 + + + 2000 + 1 + 10 + + + 2000 + 1 + 10 + + + 2000 + 1 + 10 + + + 2000 + 1 + 10 + + + 2000 + 1 + 10 + + + 2000 + 1 + 10 + + + 2000 + 1 + 10 + + + 2000 + 1 + 10 + + + 2000 + 1 + 10 + + + 2000 + 1 + 10 + + + 2000 + 1 + 10 + + + 2000 + 1 + 10 + + + 2000 + 1 + 10 + + + 2000 + 1 + 10 + + + 2000 + 1 + 10 + + + 2000 + 1 + 10 + + + 2000 + 1 + 10 +