diff options
Diffstat (limited to 'libstorycode')
-rw-r--r-- | libstorycode/slide.c | 5 | ||||
-rw-r--r-- | libstorycode/slide.h | 3 | ||||
-rw-r--r-- | libstorycode/slide_render_cairo.c | 12 | ||||
-rw-r--r-- | libstorycode/storycode.y | 6 | ||||
-rw-r--r-- | libstorycode/stylesheet.c | 3 | ||||
-rw-r--r-- | libstorycode/stylesheet.h | 1 |
6 files changed, 24 insertions, 6 deletions
diff --git a/libstorycode/slide.c b/libstorycode/slide.c index ca40347..4ee02c9 100644 --- a/libstorycode/slide.c +++ b/libstorycode/slide.c @@ -89,7 +89,8 @@ int slide_add_image(Slide *s, char *filename, struct frame_geom geom) } -int slide_add_text(Slide *s, char **text, int n_text, struct frame_geom geom) +int slide_add_text(Slide *s, char **text, int n_text, struct frame_geom geom, + enum alignment alignment) { int i; struct slide_item *item; @@ -111,7 +112,7 @@ int slide_add_text(Slide *s, char **text, int n_text, struct frame_geom geom) item->n_paras = n_text; item->geom = geom; - item->align = ALIGN_LEFT; + item->align = alignment; return 0; } diff --git a/libstorycode/slide.h b/libstorycode/slide.h index ca67c2a..f4a5542 100644 --- a/libstorycode/slide.h +++ b/libstorycode/slide.h @@ -37,7 +37,8 @@ extern void slide_free(Slide *s); extern int slide_add_prestitle(Slide *s, char *prestitle); extern int slide_add_image(Slide *s, char *filename, struct frame_geom geom); -extern int slide_add_text(Slide *s, char **text, int n_text, struct frame_geom geom); +extern int slide_add_text(Slide *s, char **text, int n_text, + struct frame_geom geom, enum alignment alignment); extern int slide_add_footer(Slide *s); extern int slide_add_slidetitle(Slide *s, char *slidetitle); extern int slide_set_logical_size(Slide *s, double w, double h); diff --git a/libstorycode/slide_render_cairo.c b/libstorycode/slide_render_cairo.c index b7e3f15..7942d27 100644 --- a/libstorycode/slide_render_cairo.c +++ b/libstorycode/slide_render_cairo.c @@ -73,6 +73,7 @@ static void render_text(struct slide_item *item, cairo_t *cr, PangoContext *pc, double fgcol[4]; PangoRectangle rect; PangoFontDescription *fontdesc; + PangoAlignment palignment; x = lcalc(item->geom.x, parent_w); y = lcalc(item->geom.y, parent_h); @@ -92,6 +93,14 @@ static void render_text(struct slide_item *item, cairo_t *cr, PangoContext *pc, } } + if ( item->align == ALIGN_INHERIT ) { + /* Use value from stylesheet */ + palignment = to_pangoalignment(align); + } else { + /* Use item-specific value */ + palignment = to_pangoalignment(item->align); + } + for ( i=0; i<item->n_paras; i++ ) { if ( item->layouts[i] == NULL ) { @@ -101,8 +110,7 @@ static void render_text(struct slide_item *item, cairo_t *cr, PangoContext *pc, pango_units_from_double(w)); pango_layout_set_text(item->layouts[i], item->paragraphs[i], -1); - pango_layout_set_alignment(item->layouts[i], - to_pangoalignment(item->align)); + pango_layout_set_alignment(item->layouts[i], palignment); pango_layout_set_font_description(item->layouts[i], fontdesc); diff --git a/libstorycode/storycode.y b/libstorycode/storycode.y index 66e69a1..3744cc4 100644 --- a/libstorycode/storycode.y +++ b/libstorycode/storycode.y @@ -144,6 +144,8 @@ static int hex_to_double(const char *v, double *r) void str_reset(struct scpctx *ctx) { ctx->n_str = 0; + ctx->mask = 0; + ctx->alignment = ALIGN_INHERIT; } void add_str(struct scpctx *ctx, char *str) @@ -168,6 +170,7 @@ void set_style(struct scpctx *ctx, enum style_element element) if ( ctx->mask & STYMASK_BGCOL ) stylesheet_set_background(ctx->ss, element, ctx->bggrad, ctx->bgcol, ctx->bgcol2); ctx->mask = 0; + ctx->alignment = ALIGN_INHERIT; } %} @@ -223,7 +226,8 @@ slide_part: slide_prestitle { slide_add_prestitle(ctx->s, $1); str_reset(ctx); } | imageframe { slide_add_image(ctx->s, $1, ctx->geom); str_reset(ctx); } -| textframe { slide_add_text(ctx->s, ctx->str, ctx->n_str, ctx->geom); +| textframe { slide_add_text(ctx->s, ctx->str, ctx->n_str, + ctx->geom, ctx->alignment); str_reset(ctx); } | FOOTER { slide_add_footer(ctx->s); } | slidetitle { slide_add_slidetitle(ctx->s, $1); str_reset(ctx); } diff --git a/libstorycode/stylesheet.c b/libstorycode/stylesheet.c index 142d8a7..4d650c1 100644 --- a/libstorycode/stylesheet.c +++ b/libstorycode/stylesheet.c @@ -27,6 +27,7 @@ #include <stdlib.h> #include <string.h> +#include <assert.h> #include "stylesheet.h" @@ -69,6 +70,7 @@ static void default_style(struct style *s) s->geom.h.unit = LENGTH_FRAC; s->font = strdup("Sans 12"); + s->alignment = ALIGN_LEFT; s->fgcol[0] = 0.0; s->fgcol[1] = 0.0; @@ -227,6 +229,7 @@ int stylesheet_set_alignment(Stylesheet *s, enum style_element el, enum alignmen { struct style *sty = get_style(s, el); if ( sty == NULL ) return 1; + assert(align != ALIGN_INHERIT); sty->alignment = align; return 0; } diff --git a/libstorycode/stylesheet.h b/libstorycode/stylesheet.h index f192e8f..c5e385e 100644 --- a/libstorycode/stylesheet.h +++ b/libstorycode/stylesheet.h @@ -31,6 +31,7 @@ typedef struct _stylesheet Stylesheet; enum alignment { + ALIGN_INHERIT, /* use whatever the stylesheet says */ ALIGN_LEFT, ALIGN_RIGHT, ALIGN_CENTER |