diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/mainwindow.c | 47 | ||||
-rw-r--r-- | src/slide_render.c | 54 | ||||
-rw-r--r-- | src/slide_render.h | 2 |
3 files changed, 94 insertions, 9 deletions
diff --git a/src/mainwindow.c b/src/mainwindow.c index 15d8025..f82db7b 100644 --- a/src/mainwindow.c +++ b/src/mainwindow.c @@ -290,6 +290,51 @@ static gint save_ss_sig(GtkWidget *widget, struct presentation *p) } +static gint export_pdf_response_sig(GtkWidget *d, gint response, + struct presentation *p) +{ + if ( response == GTK_RESPONSE_ACCEPT ) { + + char *filename; + + filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(d)); + + if ( export_pdf(p, filename) ) { + show_error(p, "Failed to export as PDF"); + } + + g_free(filename); + + } + + gtk_widget_destroy(d); + + return 0; +} + + +static gint export_pdf_sig(GtkWidget *widget, struct presentation *p) +{ + GtkWidget *d; + + d = gtk_file_chooser_dialog_new("Export PDF", + GTK_WINDOW(p->window), + GTK_FILE_CHOOSER_ACTION_SAVE, + GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, + GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT, + NULL); + gtk_file_chooser_set_do_overwrite_confirmation(GTK_FILE_CHOOSER(d), + TRUE); + + g_signal_connect(G_OBJECT(d), "response", + G_CALLBACK(export_pdf_response_sig), p); + + gtk_widget_show_all(d); + + return 0; +} + + static gint about_sig(GtkWidget *widget, struct presentation *p) { GtkWidget *window; @@ -502,6 +547,8 @@ static void add_menu_bar(struct presentation *p, GtkWidget *vbox) NULL, NULL, G_CALLBACK(saveas_sig) }, { "SaveStyleAction", GTK_STOCK_SAVE_AS, "Save St_ylesheet", NULL, NULL, G_CALLBACK(save_ss_sig) }, + { "ExportPDFAction", GTK_STOCK_SAVE_AS, "Export PDF", + NULL, NULL, G_CALLBACK(export_pdf_sig) }, { "QuitAction", GTK_STOCK_QUIT, "_Quit", NULL, NULL, G_CALLBACK(quit_sig) }, diff --git a/src/slide_render.c b/src/slide_render.c index 32c4a28..7f83ec8 100644 --- a/src/slide_render.c +++ b/src/slide_render.c @@ -26,6 +26,7 @@ #endif #include <cairo.h> +#include <cairo-pdf.h> #include <pango/pangocairo.h> #include <assert.h> @@ -100,18 +101,11 @@ static void render_bgblock(cairo_t *cr, struct bgblock *b) } -static cairo_surface_t *render_slide(struct slide *s, int w, int h) +static void render_slide_bits(struct slide *s, cairo_t *cr) { - cairo_surface_t *surf; - cairo_t *cr; int i; cairo_font_options_t *fopts; - surf = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, w, h); - - cr = cairo_create(surf); - cairo_scale(cr, w/s->parent->slide_width, h/s->parent->slide_height); - fopts = cairo_font_options_create(); cairo_font_options_set_hint_style(fopts, CAIRO_HINT_STYLE_NONE); cairo_font_options_set_hint_metrics(fopts, CAIRO_HINT_METRICS_OFF); @@ -130,8 +124,22 @@ static cairo_surface_t *render_slide(struct slide *s, int w, int h) } - cairo_destroy(cr); cairo_font_options_destroy(fopts); +} + +static cairo_surface_t *render_slide(struct slide *s, int w, int h) +{ + cairo_surface_t *surf; + cairo_t *cr; + + surf = cairo_image_surface_create(CAIRO_FORMAT_ARGB32, w, h); + + cr = cairo_create(surf); + cairo_scale(cr, w/s->parent->slide_width, h/s->parent->slide_height); + + render_slide_bits(s, cr); + + cairo_destroy(cr); return surf; } @@ -232,3 +240,31 @@ void draw_editing_box(cairo_t *cr, double xmin, double ymin, cairo_set_dash(cr, NULL, 0, 0.0); } + + +int export_pdf(struct presentation *p, const char *filename) +{ + int i; + cairo_surface_t *surf; + cairo_t *cr; + + surf = cairo_pdf_surface_create(filename, p->slide_width, + p->slide_height); + + if ( cairo_surface_status(surf) != CAIRO_STATUS_SUCCESS ) { + fprintf(stderr, "Couldn't create Cairo surface\n"); + return 1; + } + + cr = cairo_create(surf); + + for ( i=0; i<p->num_slides; i++ ) { + render_slide_bits(p->slides[i], cr); + cairo_surface_show_page(surf); + } + + cairo_surface_finish(surf); + cairo_destroy(cr); + + return 0; +} diff --git a/src/slide_render.h b/src/slide_render.h index 6218924..395ef96 100644 --- a/src/slide_render.h +++ b/src/slide_render.h @@ -40,4 +40,6 @@ extern void draw_resize_handle(cairo_t *cr, double x, double y); extern void draw_editing_box(cairo_t *cr, double xmin, double ymin, double width, double height); +extern int export_pdf(struct presentation *p, const char *filename); + #endif /* SLIDE_RENDER_H */ |