~ubuntu-branches/ubuntu/raring/gnome-photo-printer/raring

« back to all changes in this revision

Viewing changes to src/gpp_print.c

  • Committer: Bazaar Package Importer
  • Author(s): Michael Schlueter
  • Date: 2006-12-04 20:34:59 UTC
  • mfrom: (1.2.2 upstream)
  • Revision ID: james.westby@ubuntu.com-20061204203459-iezl9zaj52l0ufb4
Tags: 0.6.7-1
* New upstream release
* Bug fix: "gnome-photo-printer: changing bottom margin has no effect on
  output", thanks to Rick Pasotto (Closes: #394545).

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
 * This file is part of Gnome Photo Printer.
3
 
 * 
 
3
 *
4
4
 * Gnome Photo Printer is free software; you can redistribute it and/or
5
5
 * modify it under the terms of the GNU General Public License as
6
6
 * published by the Free Software Foundation; either version 2 of the
7
7
 * License, or (at your option) any later version.
8
 
 * 
 
8
 *
9
9
 * Gnome Photo Printer is distributed in the hope that it will be useful,
10
10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12
12
 * General Public License for more details.
13
 
 * 
14
 
 * You should have received a copy of the GNU General Public License along 
 
13
 *
 
14
 * You should have received a copy of the GNU General Public License along
15
15
 * with Gnome Photo Printer; if not, write to the Free Software
16
 
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 
 
16
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
17
 */
18
18
 
19
19
#include <stdio.h>
26
26
#include <libgnomeprint/gnome-print.h>
27
27
#include <libgnomeprint/gnome-print-job.h>
28
28
#include <libgnomeprintui/gnome-print-dialog.h>
 
29
#include <glib/gprintf.h>
29
30
#include "gpp_print.h"
30
31
#include "gpp_functions.h"
31
32
#include "gpp_widget.h"
34
35
 
35
36
/*
36
37
 * Prints the Pixbuf to the drawing area (Taken from libgnomeprint ->
37
 
 * examples 
 
38
 * examples
38
39
 */
39
40
void
40
41
gpp_print_pixbuf (GdkPixbuf * pixbuf)
58
59
}
59
60
 
60
61
/*
61
 
 * Prints the Pictures 
 
62
 * Prints the Pictures
62
63
 */
63
64
void
64
65
gpp_print_pictures (gchar * name)
71
72
        file_name = gnome_vfs_unescape_string (name, G_DIR_SEPARATOR_S);
72
73
 
73
74
        /*
74
 
         * Load the image into a pixbuf 
 
75
         * Load the image into a pixbuf
75
76
         */
76
77
        error = NULL;
77
78
        pixbuf = gdk_pixbuf_new_from_file (file_name, &error);
82
83
        }
83
84
 
84
85
        /*
85
 
         * Rotate if nescassary 
 
86
         * Rotate if nescassary
86
87
         */
87
88
        if (((gpp_definition->layout_x < gpp_definition->layout_y)
88
89
             && (gdk_pixbuf_get_width (pixbuf) >
93
94
                pixbuf = gpp_gdk_rotate_pixbuf_90 (pixbuf);
94
95
 
95
96
        /*
96
 
         * Save the graphic context, scale, print the image and restore 
 
97
         * Save the graphic context, scale, print the image and restore
97
98
         */
98
99
        gnome_print_gsave (gpp_context);
99
100
 
100
101
        /*
101
 
         * Scale to requested Size 
 
102
         * Scale to requested Size
102
103
         */
103
104
        if (gpp_definition->image_scale_with_ratio)
104
105
        {
113
114
                        shift = gpp_definition->layout_y *(1.0 - scale_y / scale_x)/2.0;
114
115
                        /*
115
116
                         * Just for debugging g_printf ("shift: %g \n", shift);
116
 
                         */                        
 
117
                         */
117
118
                        gnome_print_translate (gpp_context, 0.0, shift);
118
119
                        gnome_print_scale (gpp_context,
119
120
                                           gpp_definition->layout_x,
125
126
                        shift = gpp_definition->layout_x *(1.0 - scale_x / scale_y)/2.0;
126
127
                        /*
127
128
                         * Just for debugging g_printf ("shift: %g \n", shift);
128
 
                         */                        
 
129
                         */
129
130
                        gnome_print_translate (gpp_context, shift, 0.0);
130
131
                        gnome_print_scale (gpp_context,
131
132
                                           gpp_definition->layout_x *
140
141
        }
141
142
 
142
143
        /*
143
 
         * Print to graphic context 
 
144
         * Print to graphic context
144
145
         */
145
146
        gpp_print_pixbuf (pixbuf);
146
147
 
147
148
        /*
148
 
         * Restore the graphic context 
 
149
         * Restore the graphic context
149
150
         */
150
151
        gnome_print_grestore (gpp_context);
151
152
        g_object_unref (G_OBJECT (pixbuf));
152
153
}
153
154
 
154
155
/*
155
 
 * Arranges the Pictures on a Page by given Layout 
 
156
 * Arranges the Pictures on a Page by given Layout
156
157
 */
157
158
void
158
159
gpp_arrange_pictures (GtkWidget * progress_bar)
162
163
        gboolean valid, rotate;
163
164
        gint i, j, x, y, num_x, num_y, f = 0;
164
165
        gdouble space_x, space_y, pos_x = 0, pos_y = 0, old_pos_x = 0, old_pos_y = 0, progress = 0;
 
166
        gdouble ml, mb;
165
167
 
166
168
        /* check which orientation to favour */
167
169
        /* ...normal orientation */
182
184
                j = -1;
183
185
 
184
186
        /* page is too small! */
185
 
        if (i == -1 && j == -1) 
 
187
        if (i == -1 && j == -1)
186
188
        {
187
189
                g_printf("paper size is to small!\n");
188
190
                return;
189
191
        }
190
192
 
191
 
        /* take orientation, which is valid 
 
193
        /* take orientation, which is valid
192
194
           and requires fewer pages */
193
195
        if (i == -1) rotate = 1;
194
196
        else if (j == -1) rotate = 0;
195
197
        else if ( i <= j ) rotate = 0;
196
198
        else rotate = 1;
197
199
 
198
 
        if ( !rotate ) 
 
200
        if ( !rotate )
199
201
        {
200
202
                rotate = 0;
201
203
                gpp_definition->layout_x = x;
204
206
 
205
207
        tree = GTK_TREE_MODEL (gpp_definition->file_names);
206
208
        valid = gtk_tree_model_get_iter_first (tree, &iter);
207
 
        
 
209
 
 
210
        gnome_print_config_get_length (gpp_config, GNOME_PRINT_KEY_PAGE_MARGIN_LEFT, &ml, NULL);
 
211
        gnome_print_config_get_length (gpp_config, GNOME_PRINT_KEY_PAGE_MARGIN_BOTTOM, &mb, NULL);
 
212
 
208
213
        space_x =
209
214
                gpp_calculate_space_between_pics (gpp_definition->
210
215
                                                  paper_size_x,
223
228
         * Just Debug Information to print on console g_printf ("Space X:
224
229
         * %f\n", space_x); g_printf ("Space Y: %f\n", space_y); g_printf
225
230
         * ("Number of Pages: %d\n", gpp_calculate_number_of_sites ());
226
 
         * g_printf ("Pics on page: %d\n", gpp_calculate_pics_on_page ()); 
 
231
         * g_printf ("Pics on page: %d\n", gpp_calculate_pics_on_page ());
227
232
         */
228
233
 
229
234
        /*
230
 
         * Arrange the Pictures 
 
235
         * Arrange the Pictures
231
236
         */
232
237
        for (i = 0; i < gpp_calculate_number_of_sites (); i++)
233
238
        {
235
240
 
236
241
                for (y = 0; y < num_y; y++)
237
242
                {
238
 
                        pos_y = y * (gpp_definition->layout_y + space_y) + space_y;
 
243
                        pos_y = y * (gpp_definition->layout_y + space_y) + mb;
239
244
                        for (x = 0; x < num_x; x++)
240
245
                        {
241
246
                                f++;
242
 
                                pos_x = x * (gpp_definition->layout_x + space_x) + space_x;
 
247
                                pos_x = x * (gpp_definition->layout_x + space_x) + ml;
243
248
                                /*
244
 
                                 * Just for debugging g_printf ("X: %f, Y: %f \n", pos_x, 
245
 
                                 * pos_y); 
 
249
                                 * Just for debugging g_printf ("X: %f, Y: %f \n", pos_x,
 
250
                                 * pos_y);
246
251
                                 */
247
252
                                if (valid)
248
253
                                {
257
262
                                        /*
258
263
                                         * Just for debugging g_printf("File Names to print:
259
264
                                         * %s",g_locale_from_utf8
260
 
                                         * (str_data,-1,NULL,NULL,NULL)); 
 
265
                                         * (str_data,-1,NULL,NULL,NULL));
261
266
                                         */
262
267
                                        gtk_progress_bar_set_fraction
263
268
                                                (GTK_PROGRESS_BAR
288
293
                gnome_print_showpage (gpp_context);
289
294
        }
290
295
 
291
 
        if (rotate) 
 
296
        if (rotate)
292
297
        {
293
 
                x = gpp_definition->layout_x;
 
298
                x = gpp_definition->layout_x;
294
299
                gpp_definition->layout_x = gpp_definition->layout_y;
295
300
                gpp_definition->layout_y = x;
296
301
        }
298
303
 
299
304
/*
300
305
 * Starts Printing. FIXME soon as libgnomeprint gets fixed! Look at
301
 
 * gpp_get_settings_from_libgnomeprint () for getting a clue 
 
306
 * gpp_get_settings_from_libgnomeprint () for getting a clue
302
307
 */
303
308
void
304
309
gpp_start_printing ()
310
315
         * Should look this way! if (gpp_definition->to_file == TRUE) {
311
316
         * g_printf ("Printing to File!\n"); gnome_print_job_print_to_file
312
317
         * (gpp_job, gpp_definition-> output_file_name); } else { g_printf
313
 
         * ("Printing to Printer!\n"); } 
 
318
         * ("Printing to Printer!\n"); }
314
319
         */
315
320
 
316
321
        gpp_start_printing_done ();
317
322
}
318
323
 
319
324
/*
320
 
 * Finishes Printing 
 
325
 * Finishes Printing
321
326
 */
322
327
void
323
328
gpp_start_printing_done ()