aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorThomas White <taw@bitwiz.me.uk>2019-02-22 22:03:22 +0100
committerThomas White <taw@bitwiz.me.uk>2019-02-22 22:03:22 +0100
commit3ff425d840876c0db965b23826998161ee87c1fd (patch)
tree982ff6ad78cee6dbbac278df4b67f8642d1b11f5
parentcce16c01a4ef4280b260b72e9bbf9cb4a400d122 (diff)
Rendering stuff
-rw-r--r--data/demo.sc1
-rw-r--r--libstorycode/cairo/render.c15
-rw-r--r--libstorycode/cairo/render.h11
-rw-r--r--libstorycode/presentation.c7
-rw-r--r--libstorycode/presentation.h1
-rw-r--r--libstorycode/slide.c22
-rw-r--r--libstorycode/slide.h3
-rw-r--r--libstorycode/storycode.l1
-rw-r--r--libstorycode/storycode.y8
-rw-r--r--meson.build3
-rw-r--r--src/pdfstorycode.c24
11 files changed, 66 insertions, 30 deletions
diff --git a/data/demo.sc b/data/demo.sc
index 70cb747..413a1e9 100644
--- a/data/demo.sc
+++ b/data/demo.sc
@@ -5,6 +5,7 @@ STYLES {
}
}
SLIDE {
+ SIZE 1820u x 720u
PRESTITLE {
TYPE: TEXT[1fx90u+0+0]
FONT: Cantarell Regular 64
diff --git a/libstorycode/cairo/render.c b/libstorycode/cairo/render.c
index 32b9596..0d3fd6f 100644
--- a/libstorycode/cairo/render.c
+++ b/libstorycode/cairo/render.c
@@ -1,7 +1,7 @@
/*
* render.c
*
- * Copyright © 2013-2018 Thomas White <taw@bitwiz.org.uk>
+ * Copyright © 2013-2019 Thomas White <taw@bitwiz.org.uk>
*
* This file is part of Colloquium.
*
@@ -38,13 +38,16 @@
#include "stylesheet.h"
-int slide_render(Slide *s, cairo_t *cr, double log_w, double log_h,
- Stylesheet *stylesheet, int slide_number, PangoLanguage *lang,
- PangoContext *pc)
+int cairo_render_slide(Slide *s, cairo_t *cr, Stylesheet *stylesheet,
+ int slide_number, PangoLanguage *lang, PangoContext *pc)
{
- cairo_scale(cr, 1.0/log_w, 1.0/log_h);
+ double w, h;
+ int i;
- cairo_rectangle(cr, 0.0, 0.0, log_w, log_h);
+ slide_get_logical_size(s, &w, &h);
+
+ /* Overall default background */
+ cairo_rectangle(cr, 0.0, 0.0, w, h);
cairo_set_source_rgb(cr, 1.0, 1.0, 1.0);
cairo_fill(cr);
diff --git a/libstorycode/cairo/render.h b/libstorycode/cairo/render.h
index 6e5f4ad..15fcc0c 100644
--- a/libstorycode/cairo/render.h
+++ b/libstorycode/cairo/render.h
@@ -1,7 +1,7 @@
/*
* render.h
*
- * Copyright © 2013-2018 Thomas White <taw@bitwiz.org.uk>
+ * Copyright © 2013-2019 Thomas White <taw@bitwiz.org.uk>
*
* This file is part of Colloquium.
*
@@ -28,12 +28,9 @@
#endif
#include "presentation.h"
-#include "imagestore.h"
-#include "sc_interp.h"
-#include "frame.h"
-extern int render_cairo_slide(Slide *s, cairo_t *cr, double log_w, double log_h,
- Stylesheet *stylesheet, int slide_number,
- PangoLanguage *lang, PangoContext *pc);
+extern int cairo_render_slide(Slide *s, cairo_t *cr, Stylesheet *stylesheet,
+ int slide_number, PangoLanguage *lang,
+ PangoContext *pc);
#endif /* RENDER_H */
diff --git a/libstorycode/presentation.c b/libstorycode/presentation.c
index cafb368..6a4d019 100644
--- a/libstorycode/presentation.c
+++ b/libstorycode/presentation.c
@@ -109,3 +109,10 @@ Slide *presentation_slide(Presentation *p, int i)
if ( i < 0 ) return NULL;
return p->slides[i];
}
+
+
+Stylesheet *presentation_get_stylesheet(Presentation *p)
+{
+ if ( p == NULL ) return NULL;
+ return p->stylesheet;
+}
diff --git a/libstorycode/presentation.h b/libstorycode/presentation.h
index 24e5e92..80c6186 100644
--- a/libstorycode/presentation.h
+++ b/libstorycode/presentation.h
@@ -41,5 +41,6 @@ extern void presentation_add_slide(Presentation *p, Slide *s);
extern int presentation_num_slides(Presentation *p);
extern Slide *presentation_slide(Presentation *p, int i);
+extern Stylesheet *presentation_get_stylesheet(Presentation *p);
#endif /* PRESENTATION_H */
diff --git a/libstorycode/slide.c b/libstorycode/slide.c
index 3f65ca8..400b614 100644
--- a/libstorycode/slide.c
+++ b/libstorycode/slide.c
@@ -62,6 +62,8 @@ struct slide_item
struct _slide
{
+ double logical_w;
+ double logical_h;
int n_items;
struct slide_item *items;
};
@@ -74,6 +76,8 @@ Slide *slide_new()
if ( s == NULL ) return NULL;
s->n_items = 0;
s->items = NULL;
+ s->logical_w = 1024.0;
+ s->logical_h = 768.0;
return s;
}
@@ -184,3 +188,21 @@ void describe_slide(Slide *s)
printf("item %i: %i\n", i, s->items[i].type);
}
}
+
+
+int slide_set_logical_size(Slide *s, double w, double h)
+{
+ if ( s == NULL ) return 1;
+ s->logical_w = w;
+ s->logical_h = h;
+ return 0;
+}
+
+
+int slide_get_logical_size(Slide *s, double *w, double *h)
+{
+ if ( s == NULL ) return 1;
+ *w = s->logical_w;
+ *h = s->logical_h;
+ return 0;
+}
diff --git a/libstorycode/slide.h b/libstorycode/slide.h
index f42562b..a7574e1 100644
--- a/libstorycode/slide.h
+++ b/libstorycode/slide.h
@@ -61,6 +61,9 @@ 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_footer(Slide *s);
extern int slide_add_slidetitle(Slide *s, char *slidetitle);
+extern int slide_set_logical_size(Slide *s, double w, double h);
+
+extern int slide_get_logical_size(Slide *s, double *w, double *h);
/* For debugging, not really part of API */
extern void describe_slide(Slide *s);
diff --git a/libstorycode/storycode.l b/libstorycode/storycode.l
index f68026d..46237e5 100644
--- a/libstorycode/storycode.l
+++ b/libstorycode/storycode.l
@@ -52,6 +52,7 @@ PAD { return SC_PAD; }
ALIGN { return SC_ALIGN; }
FGCOL { return SC_FGCOL; }
BGCOL { return SC_BGCOL; }
+SIZE { return SC_SIZE; }
(?i:left) { return SC_LEFT; }
(?i:center) { return SC_CENTER; }
(?i:right) { return SC_RIGHT; }
diff --git a/libstorycode/storycode.y b/libstorycode/storycode.y
index 1f163f3..b04acf4 100644
--- a/libstorycode/storycode.y
+++ b/libstorycode/storycode.y
@@ -72,7 +72,7 @@
%token OPENBRACE CLOSEBRACE
%token SQOPEN SQCLOSE
%token PLUS TIMES
-%token UNIT VALUE
+%token UNIT VALUE SIZE
%type <p> presentation
%type <n> narrative
@@ -84,6 +84,7 @@
%type <str> bulletpoint
%type <str> frameopt
%type <geom> geometry
+%type <geom> style_slidesize
%type <len> length
%type <str> slidetitle
%type <character> UNIT
@@ -276,9 +277,14 @@ style_slide:
style_slide_def:
%empty
| style_slide_def style_prestitle
+| style_slide_def style_slidesize
| style_slide_def styledef
;
+style_slidesize:
+ SIZE length TIMES length { $$.w = $2; $$.h = $4; $$.x.len = 0.0; $$.y.len = 0.0; }
+;
+
style_prestitle:
PRESTITLE OPENBRACE styledefs CLOSEBRACE { printf("prestitle style\n"); }
;
diff --git a/meson.build b/meson.build
index 1fea778..420c5b1 100644
--- a/meson.build
+++ b/meson.build
@@ -24,6 +24,7 @@ glib_dep = dependency('glib-2.0', required : true)
gio_dep = dependency('gio-2.0', required : true)
cairo_dep = dependency('cairo', required : true)
pango_dep = dependency('pango', required : true)
+pangocairo_dep = dependency('pangocairo', required : true)
gdkpixbuf_dep = dependency('gdk-pixbuf-2.0', required : true)
cc = meson.get_compiler('c')
@@ -80,6 +81,7 @@ libstorycode_cairo = library('storycode-cairo',
],
include_directories : libstorycode_cairo_includes,
dependencies : [cairo_dep, pango_dep, gdkpixbuf_dep,
+ pangocairo_dep,
libstorycode_dep],
install : true)
@@ -109,6 +111,7 @@ executable('pdfstorycode',
],
gresources,
dependencies : [glib_dep, gio_dep, cairo_dep, pango_dep,
+ pangocairo_dep,
libstorycode_dep, libstorycode_cairo_dep])
diff --git a/src/pdfstorycode.c b/src/pdfstorycode.c
index 5e82d5b..e24b970 100644
--- a/src/pdfstorycode.c
+++ b/src/pdfstorycode.c
@@ -37,6 +37,7 @@
#include "storycode.h"
#include "presentation.h"
#include "slide.h"
+#include "cairo/render.h"
#include <libintl.h>
#define _(x) gettext(x)
@@ -45,7 +46,6 @@
static int render_slides_to_pdf(Presentation *p, const char *filename)
{
double w = 2048.0;
- double scale;
cairo_surface_t *surf;
cairo_t *cr;
int i;
@@ -63,26 +63,19 @@ static int render_slides_to_pdf(Presentation *p, const char *filename)
for ( i=0; i<presentation_num_slides(p); i++ )
{
Slide *s;
+ double log_w, log_h;
s = presentation_slide(p, i);
+ slide_get_logical_size(s, &log_w, &log_h);
- cairo_pdf_surface_set_size(surf, w, h);
+ cairo_pdf_surface_set_size(surf, w, w*(log_h/log_w));
cairo_save(cr);
-
- cairo_scale(cr, scale, scale);
-
- cairo_rectangle(cr, 0.0, 0.0, p->slide_width, p->slide_height);
- cairo_set_source_rgb(cr, 1.0, 1.0, 1.0);
- cairo_fill(cr);
-
- slide_render(s, cr, p->slide_width,
- p->slide_height, p->stylesheet, NULL,
- p->is, i, p->lang, pc);
-
- cairo_restore(cr);
-
+ cairo_scale(cr, w/log_w, w/log_w);
+ cairo_render_slide(s, cr, presentation_get_stylesheet(p),
+ i, pango_language_get_default(), pc);
cairo_show_page(cr);
+ cairo_restore(cr);
}
g_object_unref(pc);
@@ -100,7 +93,6 @@ int main(int argc, char *argv[])
const char *text;
size_t len;
Presentation *p;
- int i;
file = g_file_new_for_commandline_arg(argv[1]);
bytes = g_file_load_bytes(file, NULL, NULL, NULL);