aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas White <taw@bitwiz.me.uk>2019-02-25 23:10:10 +0100
committerThomas White <taw@bitwiz.me.uk>2019-02-25 23:10:10 +0100
commitfd60b77df51cb24c33440ab7d9afe8043f9e43db (patch)
tree1085e56ec2686a3435c06fe01645aaa5b6d7ddb4
parent2cd7252202c10ef8918ce8885cdf26dd5fcf00f5 (diff)
Use padding
-rw-r--r--libstorycode/slide_render_cairo.c23
-rw-r--r--libstorycode/stylesheet.c11
-rw-r--r--libstorycode/stylesheet.h2
3 files changed, 31 insertions, 5 deletions
diff --git a/libstorycode/slide_render_cairo.c b/libstorycode/slide_render_cairo.c
index 81b78ef..307b4d4 100644
--- a/libstorycode/slide_render_cairo.c
+++ b/libstorycode/slide_render_cairo.c
@@ -69,6 +69,8 @@ static void render_text(struct slide_item *item, cairo_t *cr, PangoContext *pc,
{
int i;
double x, y, w, h;
+ double pad_l, pad_r, pad_t, pad_b;
+ struct length pad[4];
const char *font;
enum alignment align;
double fgcol[4];
@@ -81,6 +83,12 @@ static void render_text(struct slide_item *item, cairo_t *cr, PangoContext *pc,
w = lcalc(item->geom.w, parent_w);
h = lcalc(item->geom.h, parent_h);
+ if ( stylesheet_get_padding(ss, el, pad) ) return;
+ pad_l = lcalc(pad[0], parent_w);
+ pad_r = lcalc(pad[1], parent_w);
+ pad_t = lcalc(pad[2], parent_h);
+ pad_b = lcalc(pad[3], parent_h);
+
font = stylesheet_get_font(ss, el, fgcol, &align);
if ( font == NULL ) return;
@@ -102,13 +110,19 @@ static void render_text(struct slide_item *item, cairo_t *cr, PangoContext *pc,
palignment = to_pangoalignment(item->align);
}
+ /* FIXME: Apply background */
+
+ cairo_save(cr);
+ cairo_translate(cr, x, y);
+ cairo_translate(cr, pad_l, pad_t);
+
for ( i=0; i<item->n_paras; i++ ) {
if ( item->layouts[i] == NULL ) {
item->layouts[i] = pango_layout_new(pc);
}
pango_layout_set_width(item->layouts[i],
- pango_units_from_double(w));
+ pango_units_from_double(w-pad_l-pad_r));
pango_layout_set_text(item->layouts[i], item->paragraphs[i], -1);
pango_layout_set_alignment(item->layouts[i], palignment);
@@ -121,17 +135,16 @@ static void render_text(struct slide_item *item, cairo_t *cr, PangoContext *pc,
/* FIXME: Clip to w,h */
- cairo_save(cr);
cairo_set_source_rgba(cr, fgcol[0], fgcol[1], fgcol[2], fgcol[3]);
- cairo_translate(cr, x, y);
+ cairo_move_to(cr, 0.0, 0.0);
pango_cairo_update_layout(cr, item->layouts[i]);
pango_cairo_show_layout(cr, item->layouts[i]);
pango_layout_get_extents(item->layouts[i], NULL, &rect);
- y += pango_units_to_double(rect.height);
+ cairo_translate(cr, 0.0, pango_units_to_double(rect.height));
cairo_fill(cr);
- cairo_restore(cr);
}
+ cairo_restore(cr);
}
diff --git a/libstorycode/stylesheet.c b/libstorycode/stylesheet.c
index 7054a09..5d40f4b 100644
--- a/libstorycode/stylesheet.c
+++ b/libstorycode/stylesheet.c
@@ -262,3 +262,14 @@ int stylesheet_get_background(Stylesheet *s, enum style_element el,
*grad = sty->bggrad;
return 0;
}
+
+
+int stylesheet_get_padding(Stylesheet *s, enum style_element el,
+ struct length padding[4])
+{
+ int i;
+ struct style *sty = get_style(s, el);
+ if ( sty == NULL ) return 1;
+ for ( i=0; i<4; i++ ) padding[i] = sty->padding[i];
+ return 0;
+}
diff --git a/libstorycode/stylesheet.h b/libstorycode/stylesheet.h
index c5e385e..f050303 100644
--- a/libstorycode/stylesheet.h
+++ b/libstorycode/stylesheet.h
@@ -97,6 +97,8 @@ extern const char *stylesheet_get_font(Stylesheet *s, enum style_element el,
double fgcol[4], enum alignment *alignment);
extern int stylesheet_get_background(Stylesheet *s, enum style_element el,
enum gradient *grad, double *bgcol, double *bgcol2);
+extern int stylesheet_get_padding(Stylesheet *s, enum style_element el,
+ struct length padding[4]);
#endif /* STYLESHEET_H */