aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorThomas White <taw@bitwiz.me.uk>2019-02-21 22:34:53 +0100
committerThomas White <taw@bitwiz.me.uk>2019-02-21 22:34:53 +0100
commit108384e83edcfd22b09eefe1cc6013d0c4d93f54 (patch)
tree1378d9489d30c3dace9766b6e5f6647596bb3c82 /src
parent2a1e0fe6db0d2980b4c7a8e413a7c81aadbc0dd1 (diff)
Skeleton for libstorycode-cairo and libstorycode-gtk
Diffstat (limited to 'src')
-rw-r--r--src/pdfstorycode.c59
1 files changed, 54 insertions, 5 deletions
diff --git a/src/pdfstorycode.c b/src/pdfstorycode.c
index 4c379f4..6a4de05 100644
--- a/src/pdfstorycode.c
+++ b/src/pdfstorycode.c
@@ -26,10 +26,63 @@
#include <glib.h>
#include <glib/gstdio.h>
#include <gio/gio.h>
+#include <cairo.h>
#include "storycode.h"
#include "presentation.h"
+
+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;
+ PangoContext *pc;
+
+ surf = cairo_pdf_surface_create(filename, w, w);
+ if ( cairo_surface_status(surf) != CAIRO_STATUS_SUCCESS ) {
+ fprintf(stderr, _("Couldn't create Cairo surface\n"));
+ return 1;
+ }
+
+ cr = cairo_create(surf);
+ pc = pango_cairo_create_context(cr);
+
+ for ( i=0; i<presentation_num_slides(p); i++ )
+ {
+ Slide *s;
+
+ s = presentation_slide(p, i);
+
+ cairo_pdf_surface_set_size(surf, w, h);
+
+ 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_show_page(cr);
+ }
+
+ g_object_unref(pc);
+ cairo_surface_finish(surf);
+ cairo_destroy(cr);
+
+ return 0;
+}
+
+
int main(int argc, char *argv[])
{
GFile *file;
@@ -46,11 +99,7 @@ int main(int argc, char *argv[])
g_bytes_unref(bytes);
/* Render each slide to PDF */
- for ( i=0; i<presentation_num_slides(p); i++ ) {
- Slide *slide = presentation_slide(p, i);
- printf("slide %i:\n", i);
- describe_slide(slide);
- }
+ render_slides_to_pdf(p, "slides.pdf");
return 0;
}