aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas White <taw@bitwiz.me.uk>2019-02-22 23:24:22 +0100
committerThomas White <taw@bitwiz.me.uk>2019-02-22 23:24:22 +0100
commite38820b6adb2be0dafabd517026fd7f8571107b2 (patch)
treefea9d8327e7994bce988648e76a2e59942ec40c7
parentaee387068f5b9013687250e8d655b56a0c5776f2 (diff)
Fundamentals of rendering
-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
-rw-r--r--src/pdfstorycode.c1
5 files changed, 76 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; }
;
diff --git a/src/pdfstorycode.c b/src/pdfstorycode.c
index 04d2b82..a0d9115 100644
--- a/src/pdfstorycode.c
+++ b/src/pdfstorycode.c
@@ -66,6 +66,7 @@ static int render_slides_to_pdf(Presentation *p, const char *filename)
double log_w, log_h;
s = presentation_slide(p, i);
+ describe_slide(s);
slide_get_logical_size(s, &log_w, &log_h);
cairo_pdf_surface_set_size(surf, w, w*(log_h/log_w));