Created
July 28, 2010 04:44
-
-
Save onlyshk/493412 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include "printing.h" | |
static GList* list; | |
static GtkPrintSettings *settings = NULL; | |
static void begin_print (GtkPrintOperation * oper, GtkPrintContext * context, | |
gint nr, gpointer user_data) | |
{ | |
cairo_t *cr = gtk_print_context_get_cairo_context (context); | |
GtkPrintSettings* settings = gtk_print_operation_get_print_settings(oper); | |
GtkPaperSize* page_size = gtk_print_settings_get_paper_size(settings); | |
gint page_width = (gint)gtk_paper_size_get_width(settings, GTK_UNIT_PIXEL); | |
gint page_height = (gint)gtk_paper_size_get_height(settings, GTK_UNIT_PIXEL); | |
GdkPixbuf* pixbuf = gdk_pixbuf_new_from_file(file_path_for_print,NULL); | |
int image_width = gdk_pixbuf_get_width(pixbuf); | |
int image_height = gdk_pixbuf_get_height(pixbuf); | |
int n_xpages = (image_width / page_width) + image_width % page_width; | |
int n_ypages = (image_height / page_height) + image_height % page_height; | |
int n_all_pages = n_xpages * n_ypages; | |
gtk_print_operation_set_n_pages(oper, 1); | |
} | |
static void draw_page (GtkPrintOperation * oper, GtkPrintContext * context, | |
gint nr, gpointer user_data) | |
{ | |
cairo_t *cr = gtk_print_context_get_cairo_context (context); | |
GdkPixbuf* pixbuf = gdk_pixbuf_new_from_file(file_path_for_print,NULL); | |
gdk_cairo_set_source_pixbuf(cr, pixbuf, 0, 0); | |
cairo_paint(cr); | |
} | |
void print_pixbuf(GtkWidget* widget, MainWin *mw) | |
{ | |
GtkPrintOperation *op; | |
GtkPrintOperationResult res; | |
op = gtk_print_operation_new (); | |
gtk_print_operation_set_unit (op, GTK_UNIT_PIXEL); | |
g_signal_connect (op, "begin-print", G_CALLBACK (begin_print),NULL); | |
g_signal_connect (op, "draw-page", G_CALLBACK (draw_page), NULL); | |
res = gtk_print_operation_run (op, GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG, NULL, NULL); | |
g_object_unref (op); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment