Created
July 22, 2010 09:41
-
-
Save onlyshk/485784 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
/*************************************************************************** | |
* Copyright (C) 2007 by PCMan (Hong Jen Yee) [email protected] * | |
* 2010 by shk (Kuleshov Alexander [email protected] * | |
* * | |
* This program is free software; you can redistribute it and/or modify * | |
* it under the terms of the GNU General Public License as published by * | |
* the Free Software Foundation; either version 2 of the License, or * | |
* (at your option) any later version. * | |
* * | |
* This program is distributed in the hope that it will be useful, * | |
* but WITHOUT ANY WARRANTY; without even the implied warranty of * | |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * | |
* GNU General Public License for more details. * | |
* * | |
* You should have received a copy of the GNU General Public License * | |
* along with this program; if not, write to the * | |
* Free Software Foundation, Inc., * | |
* 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * | |
***************************************************************************/ | |
#include "printing.h" | |
GList* list; | |
// 208 295 | |
static void draw_page (GtkPrintOperation * oper, GtkPrintContext * context, | |
gint nr, gpointer user_data) | |
{ | |
MainWin* mw = (MainWin*)user_data; | |
GdkPixbuf* pixbuf = gdk_pixbuf_new_from_file(image_list_get_current_file_path (mw->img_list), | |
NULL); | |
GdkPixbuf* sub_pixbuf = NULL; | |
cairo_t *cr = gtk_print_context_get_cairo_context (context); | |
cairo_t *cr1[65535]; | |
int i = 0; | |
int j = 0; | |
int k = 0; | |
int n = 0; | |
guint width = 0; | |
guint height = 0; | |
guint width1 = 0; | |
guint height1 = 0; | |
guint x = 210; | |
guint y = 297; | |
width = gdk_pixbuf_get_width(pixbuf); | |
height = gdk_pixbuf_get_height(pixbuf); | |
width1 = gdk_pixbuf_get_width(pixbuf); | |
height1 = gdk_pixbuf_get_height(pixbuf); | |
if (width < 210 && height < 300) | |
{ | |
gdk_cairo_set_source_pixbuf(cr, pixbuf, 0, 0); | |
} | |
else | |
{ | |
guint count_w = 0; | |
guint count_h = 0; | |
while (width >= 208) | |
{ | |
width -= 208; | |
++count_w; | |
} | |
while (height >= 295) | |
{ | |
height -= 295; | |
++count_h; | |
} | |
for (i; i <= count_h; i++) | |
{ | |
for (i; i <= count_w; i++) | |
{ | |
//if (i == count_w && i == count_h) | |
//{ | |
// pixbuf j height up/down | |
// sub_pixbuf = gdk_pixbuf_new_subpixbuf(pixbuf, j, k, width - 1 , height - 1); | |
// list = g_list_prepend (list, sub_pixbuf); | |
// break; | |
//} | |
//else | |
{ | |
sub_pixbuf = gdk_pixbuf_new_subpixbuf(pixbuf, j, k, 208, 295); | |
list = g_list_prepend (list, sub_pixbuf); | |
j += 208; | |
k += 295; | |
} | |
} | |
} | |
} | |
printf("%d", g_list_length(list)); | |
gdk_cairo_set_source_pixbuf(cr, g_list_nth_data(list,0), 0, 0); | |
cairo_paint (cr); | |
g_object_unref (pixbuf); | |
} | |
void print_pixbuf(GtkWidget* widget, MainWin* mw) | |
{ | |
GtkPrintOperation *op; | |
GtkPrintOperationResult res; | |
op = gtk_print_operation_new (); | |
gtk_print_operation_set_n_pages (op, 1); | |
gtk_print_operation_set_unit (op, GTK_UNIT_MM); | |
g_signal_connect (op, "draw_page", G_CALLBACK (draw_page), mw); | |
res = gtk_print_operation_run (op, GTK_PRINT_OPERATION_ACTION_PRINT_DIALOG, mw, NULL); | |
//g_object_unref (op); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment