From c1b0437dd1f1bc6df338ad9fc15d270b9cc33884 Mon Sep 17 00:00:00 2001 From: Thomas White Date: Tue, 30 Apr 2019 17:51:31 +0200 Subject: Create stylesheet with narrative This means there'll ALWAYS be a default stylesheet present, avoiding crashes and a lot of special cases. --- libstorycode/narrative.c | 2 +- libstorycode/scparse_priv.h | 1 - libstorycode/storycode.y | 31 +++++++++++++++++++------------ 3 files changed, 20 insertions(+), 14 deletions(-) (limited to 'libstorycode') diff --git a/libstorycode/narrative.c b/libstorycode/narrative.c index 9488285..c14ac6d 100644 --- a/libstorycode/narrative.c +++ b/libstorycode/narrative.c @@ -56,7 +56,7 @@ Narrative *narrative_new() if ( n == NULL ) return NULL; n->n_items = 0; n->items = NULL; - n->stylesheet = NULL; + n->stylesheet = stylesheet_new(); n->imagestore = imagestore_new("."); /* FIXME: From app config */ n->saved = 1; #ifdef HAVE_PANGO diff --git a/libstorycode/scparse_priv.h b/libstorycode/scparse_priv.h index 22be698..3d97ead 100644 --- a/libstorycode/scparse_priv.h +++ b/libstorycode/scparse_priv.h @@ -40,7 +40,6 @@ enum style_mask struct scpctx { Narrative *n; - Stylesheet *ss; Slide *s; int n_str; diff --git a/libstorycode/storycode.y b/libstorycode/storycode.y index 5d22826..fce8d37 100644 --- a/libstorycode/storycode.y +++ b/libstorycode/storycode.y @@ -101,9 +101,8 @@ { ctx->n = narrative_new(); - /* These are the objects currently being created. They will be - * added to the narrative when they're complete */ - ctx->ss = stylesheet_new(); + /* The slide currently being created. + * Will be added to the narrative when complete */ ctx->s = slide_new(); ctx->max_str = 32; @@ -164,13 +163,20 @@ void add_str(struct scpctx *ctx, char *str) void set_style(struct scpctx *ctx, const char *element) { - if ( ctx->mask & STYMASK_GEOM ) stylesheet_set_geometry(ctx->ss, element, ctx->geom); - if ( ctx->mask & STYMASK_FONT ) stylesheet_set_font(ctx->ss, element, ctx->font); - if ( ctx->mask & STYMASK_ALIGNMENT ) stylesheet_set_alignment(ctx->ss, element, ctx->alignment); - if ( ctx->mask & STYMASK_PADDING ) stylesheet_set_padding(ctx->ss, element, ctx->padding); - if ( ctx->mask & STYMASK_PARASPACE ) stylesheet_set_paraspace(ctx->ss, element, ctx->paraspace); - if ( ctx->mask & STYMASK_FGCOL ) stylesheet_set_fgcol(ctx->ss, element, ctx->fgcol); - if ( ctx->mask & STYMASK_BGCOL ) stylesheet_set_background(ctx->ss, element, ctx->bggrad, + if ( ctx->mask & STYMASK_GEOM ) stylesheet_set_geometry(narrative_get_stylesheet(ctx->n), + element, ctx->geom); + if ( ctx->mask & STYMASK_FONT ) stylesheet_set_font(narrative_get_stylesheet(ctx->n), + element, ctx->font); + if ( ctx->mask & STYMASK_ALIGNMENT ) stylesheet_set_alignment(narrative_get_stylesheet(ctx->n), + element, ctx->alignment); + if ( ctx->mask & STYMASK_PADDING ) stylesheet_set_padding(narrative_get_stylesheet(ctx->n), + element, ctx->padding); + if ( ctx->mask & STYMASK_PARASPACE ) stylesheet_set_paraspace(narrative_get_stylesheet(ctx->n), + element, ctx->paraspace); + if ( ctx->mask & STYMASK_FGCOL ) stylesheet_set_fgcol(narrative_get_stylesheet(ctx->n), + element, ctx->fgcol); + if ( ctx->mask & STYMASK_BGCOL ) stylesheet_set_background(narrative_get_stylesheet(ctx->n), + element, ctx->bggrad, ctx->bgcol, ctx->bgcol2); ctx->mask = 0; ctx->alignment = ALIGN_INHERIT; @@ -330,7 +336,7 @@ stylesheet: STYLES '{' style_narrative style_slide - '}' { narrative_add_stylesheet(ctx->n, ctx->ss); } + '}' { } ; style_narrative: @@ -374,7 +380,8 @@ style_slidesize: { fprintf(stderr, "Wrong slide size units\n"); } else { - stylesheet_set_slide_default_size(ctx->ss, $2.len, $4.len); + stylesheet_set_slide_default_size(narrative_get_stylesheet(ctx->n), + $2.len, $4.len); } } ; -- cgit v1.2.3