aboutsummaryrefslogtreecommitdiff
path: root/libstorycode
diff options
context:
space:
mode:
Diffstat (limited to 'libstorycode')
-rw-r--r--libstorycode/slide.c13
-rw-r--r--libstorycode/slide_render_cairo.c61
-rw-r--r--libstorycode/storycode.l4
-rw-r--r--libstorycode/storycode.y6
4 files changed, 75 insertions, 9 deletions
diff --git a/libstorycode/slide.c b/libstorycode/slide.c
index 4e98ba2..9ce0930 100644
--- a/libstorycode/slide.c
+++ b/libstorycode/slide.c
@@ -143,6 +143,14 @@ int slide_add_slidetitle(Slide *s, char *slidetitle)
}
+static char units(enum length_unit u)
+{
+ if ( u == LENGTH_UNIT ) return 'u';
+ if ( u == LENGTH_FRAC ) return 'f';
+ return '?';
+}
+
+
void describe_slide(Slide *s)
{
int i;
@@ -150,6 +158,11 @@ void describe_slide(Slide *s)
printf(" %i items\n", s->n_items);
for ( i=0; i<s->n_items; i++ ) {
printf("item %i: %i\n", i, s->items[i].type);
+ printf("geom %f %c x %f %c + %f %c + %f %c\n",
+ s->items[i].geom.x.len, units(s->items[i].geom.x.unit),
+ s->items[i].geom.y.len, units(s->items[i].geom.y.unit),
+ s->items[i].geom.w.len, units(s->items[i].geom.w.unit),
+ s->items[i].geom.h.len, units(s->items[i].geom.h.unit));
}
}
diff --git a/libstorycode/slide_render_cairo.c b/libstorycode/slide_render_cairo.c
index c2819fa..e701aed 100644
--- a/libstorycode/slide_render_cairo.c
+++ b/libstorycode/slide_render_cairo.c
@@ -40,18 +40,71 @@
#include "slide_priv.h"
+static double lcalc(struct length l, double pd)
+{
+ if ( l.unit == LENGTH_UNIT ) {
+ return l.len;
+ } else {
+ return l.len * pd;
+ }
+}
+
+
+static void render_text(struct slide_item *item, cairo_t *cr,
+ double parent_w, double parent_h)
+{
+ cairo_rectangle(cr, lcalc(item->geom.x, parent_w),
+ lcalc(item->geom.y, parent_h),
+ lcalc(item->geom.w, parent_w),
+ lcalc(item->geom.h, parent_h));
+ cairo_set_source_rgb(cr, 0.0, 0.0, 0.0);
+ cairo_set_line_width(cr, 1.0);
+ cairo_stroke(cr);
+}
+
+
+static void render_image(struct slide_item *item, cairo_t *cr,
+ double parent_w, double parent_h)
+{
+ cairo_rectangle(cr, lcalc(item->geom.x, parent_w),
+ lcalc(item->geom.y, parent_h),
+ lcalc(item->geom.w, parent_w),
+ lcalc(item->geom.h, parent_h));
+ cairo_set_source_rgb(cr, 0.0, 0.0, 0.0);
+ cairo_set_line_width(cr, 1.0);
+ cairo_stroke_preserve(cr);
+ cairo_set_source_rgba(cr, 0.0, 0.5, 0.0, 0.5);
+ cairo_fill(cr);
+}
+
+
int slide_render_cairo(Slide *s, cairo_t *cr, Stylesheet *stylesheet,
int slide_number, PangoLanguage *lang, PangoContext *pc)
{
- double w, h;
int i;
- slide_get_logical_size(s, &w, &h);
-
/* Overall default background */
- cairo_rectangle(cr, 0.0, 0.0, w, h);
+ cairo_rectangle(cr, 0.0, 0.0, s->logical_w, s->logical_h);
cairo_set_source_rgb(cr, 1.0, 1.0, 1.0);
cairo_fill(cr);
+ for ( i=0; i<s->n_items; i++ ) {
+
+ switch ( s->items[i].type ) {
+
+ case SLIDE_ITEM_TEXT :
+ render_text(&s->items[i], cr, s->logical_w, s->logical_h);
+ break;
+
+ case SLIDE_ITEM_IMAGE :
+ render_image(&s->items[i], cr, s->logical_w, s->logical_h);
+ break;
+
+ default :
+ break;
+
+ }
+ }
+
return 0;
}
diff --git a/libstorycode/storycode.l b/libstorycode/storycode.l
index 46237e5..792637d 100644
--- a/libstorycode/storycode.l
+++ b/libstorycode/storycode.l
@@ -64,8 +64,8 @@ SIZE { return SC_SIZE; }
[{] { return SC_OPENBRACE; }
[}] { return SC_CLOSEBRACE; }
[.\n ] {}
-[0-9\.]+ { /* FIXME: lval */ return SC_VALUE; }
-[uf] { return SC_UNIT; }
+[0-9\.]+ { sclval.val = atof(yytext); return SC_VALUE; }
+[uf] { sclval.character = yytext[0]; return SC_UNIT; }
[+] { return SC_PLUS; }
[x] { return SC_TIMES; }
diff --git a/libstorycode/storycode.y b/libstorycode/storycode.y
index b04acf4..1062794 100644
--- a/libstorycode/storycode.y
+++ b/libstorycode/storycode.y
@@ -230,7 +230,7 @@ frameopt:
;
geometry:
- length TIMES length PLUS length PLUS length { $$.x = $1; $$.y = $3; $$.w = $5; $$.h = $7;
+ length TIMES length PLUS length PLUS length { $$.w = $1; $$.h = $3; $$.x = $5; $$.y = $7;
ctx->geom = $$; ctx->geom_set = 1; }
;
@@ -246,8 +246,8 @@ slidetitle:
length:
VALUE UNIT { $$.len = $VALUE;
- if ( $UNIT == 'f' ) $$.unit = LENGTH_UNIT;
- if ( $UNIT == 'u' ) $$.unit = LENGTH_FRAC; }
+ if ( $UNIT == 'u' ) $$.unit = LENGTH_UNIT;
+ if ( $UNIT == 'f' ) $$.unit = LENGTH_FRAC; }
;