4 * Copyright (C) 2008 - 2010 The Geeqie Team
8 * This software is released under the GNU General Public License (GNU GPL).
9 * Please read the included file COPYING for more information.
10 * This software comes with no warranty of any kind, use at your own risk!
18 #include "image-load.h"
19 #include "pixbuf_util.h"
22 #include "ui_bookmark.h"
25 #include "ui_utildlg.h"
26 #include "ui_fileops.h"
27 #include "ui_spinner.h"
28 #include "ui_tabcomp.h"
32 #include <glib/gprintf.h>
34 #define PRINT_LPR_COMMAND "lpr"
35 #define PRINT_LPR_CUSTOM "lpr -P %s"
36 #define PRINT_LPR_QUERY "lpstat -p"
38 #define PRINT_DLG_WIDTH 600
39 #define PRINT_DLG_HEIGHT 400
41 #define PRINT_DLG_PREVIEW_WIDTH 270
42 #define PRINT_DLG_PREVIEW_HEIGHT -1
44 /* these are in point units */
45 #define PRINT_MIN_WIDTH 100
46 #define PRINT_MIN_HEIGHT 100
47 #define PRINT_MAX_WIDTH 4000
48 #define PRINT_MAX_HEIGHT 4000
50 #define PRINT_MARGIN_DEFAULT 36
52 #define PRINT_PROOF_MIN_SIZE 8
53 #define PRINT_PROOF_MAX_SIZE 720
54 #define PRINT_PROOF_DEFAULT_SIZE 144
55 #define PRINT_PROOF_MARGIN 5
57 /* default page size */
58 #define PAGE_LAYOUT_WIDTH 850
59 #define PAGE_LAYOUT_HEIGHT 1100
61 /* preview uses 1 pixel = PRINT_PREVIEW_SCALE points */
62 #define PRINT_PREVIEW_SCALE 4
64 /* default dpi to use for printing ps image data */
65 #define PRINT_PS_DPI_DEFAULT 300.0
66 #define PRINT_PS_DPI_MIN 150.0
67 /* method to use when scaling down image data */
68 #define PRINT_PS_MAX_INTERP GDK_INTERP_BILINEAR
69 /* color to use as mask when printing transparent images */
70 #define PRINT_PS_MASK_R 255
71 #define PRINT_PS_MASK_G 255
72 #define PRINT_PS_MASK_B 255
74 /* padding between objects */
75 #define PRINT_TEXT_PADDING 3.0
77 /* locale for postscript portability */
78 #define POSTSCRIPT_LOCALE "C"
81 /* group and keys for saving prefs */
82 #define PRINT_PREF_GROUP "print_settings"
84 #define PRINT_PREF_SAVE "save_settings"
86 #define PRINT_PREF_OUTPUT "output"
87 #define PRINT_PREF_FORMAT "format"
88 #define PRINT_PREF_DPI "dpi"
89 #define PRINT_PREF_UNITS "units"
90 #define PRINT_PREF_SIZE "size"
91 #define PRINT_PREF_ORIENTATION "orientation"
93 #define PRINT_PREF_CUSTOM_WIDTH "custom_width"
94 #define PRINT_PREF_CUSTOM_HEIGHT "custom_height"
95 #define PRINT_PREF_MARGIN_LEFT "margin_left"
96 #define PRINT_PREF_MARGIN_RIGHT "margin_right"
97 #define PRINT_PREF_MARGIN_TOP "margin_top"
98 #define PRINT_PREF_MARGIN_BOTTOM "margin_bottom"
99 #define PRINT_PREF_PROOF_WIDTH "proof_width"
100 #define PRINT_PREF_PROOF_HEIGHT "proof_height"
102 #define PRINT_PREF_PRINTERC "custom_printer"
104 #define PRINT_PREF_TEXT "text"
105 #define PRINT_PREF_TEXTSIZE "textsize"
106 #define PRINT_PREF_TEXTCOLOR_R "textcolor_r"
107 #define PRINT_PREF_TEXTCOLOR_G "textcolor_g"
108 #define PRINT_PREF_TEXTCOLOR_B "textcolor_b"
110 #define PRINT_PREF_SOURCE "source"
111 #define PRINT_PREF_LAYOUT "layout"
113 #define PRINT_PREF_IMAGE_SCALE "image_scale"
116 PRINT_SOURCE_IMAGE = 0,
117 PRINT_SOURCE_SELECTION,
122 const gchar *print_source_text[] = {
130 PRINT_LAYOUT_IMAGE = 0,
135 const gchar *print_layout_text[] = {
136 N_("One image per page"),
142 PRINT_OUTPUT_PS_LPR = 0,
143 PRINT_OUTPUT_PS_CUSTOM,
144 PRINT_OUTPUT_PS_FILE,
145 PRINT_OUTPUT_RGB_FILE,
149 const gchar *print_output_text[] = {
150 N_("Default printer"),
151 N_("Custom printer"),
152 N_("PostScript file"),
159 PRINT_FILE_JPG_LOW = 0,
160 PRINT_FILE_JPG_NORMAL,
166 const gchar *print_file_format_text[] = {
167 N_("jpeg, low quality"),
168 N_("jpeg, normal quality"),
169 N_("jpeg, high quality"),
175 RENDER_FORMAT_PREVIEW,
181 TEXT_INFO_FILENAME = 1 << 0,
182 TEXT_INFO_FILEDATE = 1 << 1,
183 TEXT_INFO_FILESIZE = 1 << 2,
184 TEXT_INFO_DIMENSIONS = 1 << 3,
185 TEXT_INFO_FILEPATH = 1 << 4
189 PAPER_UNIT_POINTS = 0,
198 PAPER_ORIENTATION_PORTRAIT = 0,
199 PAPER_ORIENTATION_LANDSCAPE,
200 PAPER_ORIENTATION_COUNT
204 typedef struct _PrintWindow PrintWindow;
207 GenericDialog *dialog;
210 GList *source_selection;
218 gchar *output_custom;
220 PrintFileFormat output_format;
226 GtkWidget *path_entry;
227 GtkWidget *custom_entry;
228 GtkWidget *path_format_menu;
229 GtkWidget *max_dpi_menu;
231 ImageWindow *layout_image;
232 gdouble layout_width;
233 gdouble layout_height;
235 guint layout_idle_id; /* event source id */
239 GtkWidget *image_scale_spin;
242 gdouble proof_height;
249 GtkWidget *proof_group;
250 GtkWidget *proof_width_spin;
251 GtkWidget *proof_height_spin;
253 GtkWidget *paper_menu;
254 GtkWidget *paper_width_spin;
255 GtkWidget *paper_height_spin;
256 GtkWidget *paper_units_menu;
257 GtkWidget *paper_orientation_menu;
259 GtkWidget *margin_left_spin;
260 GtkWidget *margin_right_spin;
261 GtkWidget *margin_top_spin;
262 GtkWidget *margin_bottom_spin;
264 PaperUnits paper_units;
267 gdouble paper_height;
268 PaperOrientation paper_orientation;
271 gdouble margin_right;
273 gdouble margin_bottom;
275 GtkWidget *button_back;
276 GtkWidget *button_next;
277 GtkWidget *page_label;
278 GtkWidget *print_button;
280 gdouble single_scale;
284 GtkWidget *single_scale_spin;
286 TextInfo text_fields;
296 GenericDialog *job_dialog;
297 GtkWidget *job_progress;
298 GtkWidget *job_progress_label;
300 RenderFormat job_format;
301 PrintOutput job_output;
307 GdkPixbuf *job_pixbuf;
310 ImageLoader *job_loader;
314 static void print_job_throw_error(PrintWindow *pw, const gchar *message);
315 static gint print_job_start(PrintWindow *pw, RenderFormat format, PrintOutput output);
316 static void print_job_close(PrintWindow *pw, gint error);
317 static void print_window_close(PrintWindow *pw);
322 static gboolean clip_region(gdouble x1, gdouble y1, gdouble w1, gdouble h1,
323 gdouble x2, gdouble y2, gdouble w2, gdouble h2,
324 gdouble *rx, gdouble *ry, gdouble *rw, gdouble *rh)
326 if (x2 + w2 <= x1 || x2 >= x1 + w1 ||
327 y2 + h2 <= y1 || y2 >= y1 + h1)
333 *rw = MIN((x1 + w1), (x2 + w2)) - *rx;
336 *rh = MIN((y1 + h1), (y2 + h2)) - *ry;
341 static const gchar *print_output_name(PrintOutput output)
343 if (output >= PRINT_OUTPUT_COUNT) return "";
345 return _(print_output_text[output]);
350 *-----------------------------------------------------------------------------
352 *-----------------------------------------------------------------------------
356 typedef struct _PaperSize PaperSize;
361 PaperOrientation orientation;
364 const gchar *print_paper_units[] = {
373 const gchar *print_paper_orientation[] = {
379 PaperSize print_paper_sizes[] = {
380 { N_("Custom"), 360, 720, PAPER_ORIENTATION_PORTRAIT },
381 { N_("Letter"), 612, 792, PAPER_ORIENTATION_PORTRAIT }, /* in 8.5 x 11 */
382 { N_("Legal"), 612, 1008, PAPER_ORIENTATION_PORTRAIT }, /* in 8.5 x 14 */
383 { N_("Executive"), 522, 756, PAPER_ORIENTATION_PORTRAIT }, /* in 7.25x 10.5 */
384 { "A0", 2384, 3370, PAPER_ORIENTATION_PORTRAIT }, /* mm 841 x 1189 */
385 { "A1", 1684, 2384, PAPER_ORIENTATION_PORTRAIT }, /* mm 594 x 841 */
386 { "A2", 1191, 1684, PAPER_ORIENTATION_PORTRAIT }, /* mm 420 x 594 */
387 { "A3", 842, 1191, PAPER_ORIENTATION_PORTRAIT }, /* mm 297 x 420 */
388 { "A4", 595, 842, PAPER_ORIENTATION_PORTRAIT }, /* mm 210 x 297 */
389 { "A5", 420, 595, PAPER_ORIENTATION_PORTRAIT }, /* mm 148 x 210 */
390 { "A6", 298, 420, PAPER_ORIENTATION_PORTRAIT }, /* mm 105 x 148 */
391 { "B3", 1001, 1417, PAPER_ORIENTATION_PORTRAIT }, /* mm 353 x 500 */
392 { "B4", 709, 1001, PAPER_ORIENTATION_PORTRAIT }, /* mm 250 x 353 */
393 { "B5", 499, 709, PAPER_ORIENTATION_PORTRAIT }, /* mm 176 x 250 */
394 { "B6", 354, 499, PAPER_ORIENTATION_PORTRAIT }, /* mm 125 x 176 */
395 { N_("Envelope #10"), 297, 684, PAPER_ORIENTATION_LANDSCAPE }, /* in 4.125 x 9.5 */
396 { N_("Envelope #9"), 279, 639, PAPER_ORIENTATION_LANDSCAPE }, /* in 3.875 x 8.875 */
397 { N_("Envelope C4"), 649, 918, PAPER_ORIENTATION_LANDSCAPE }, /* mm 229 x 324 */
398 { N_("Envelope C5"), 459, 649, PAPER_ORIENTATION_LANDSCAPE }, /* mm 162 x 229 */
399 { N_("Envelope C6"), 323, 459, PAPER_ORIENTATION_LANDSCAPE }, /* mm 114 x 162 */
400 { N_("Photo 6x4"), 432, 288, PAPER_ORIENTATION_PORTRAIT }, /* in 6 x 4 */
401 { N_("Photo 8x10"), 576, 720, PAPER_ORIENTATION_PORTRAIT }, /* in 8 x 10 */
402 { N_("Postcard"), 284, 419, PAPER_ORIENTATION_LANDSCAPE }, /* mm 100 x 148 */
403 { N_("Tabloid"), 792, 1224, PAPER_ORIENTATION_PORTRAIT }, /* in 11 x 17 */
408 static PaperSize *print_paper_size_nth(gint n)
410 PaperSize *ps = NULL;
413 while (i <= n && print_paper_sizes[i].description)
415 ps = &print_paper_sizes[i];
422 static gint print_paper_size_lookup(gint n, gdouble *width, gdouble *height)
427 ps = print_paper_size_nth(n);
428 if (!ps) return FALSE;
430 if (ps->orientation == PAPER_ORIENTATION_PORTRAIT)
441 if (width) *width = w;
442 if (height) *height = h;
447 static gdouble print_paper_size_convert_units(gdouble value, PaperUnits src, PaperUnits dst)
451 if (src == dst) return value;
456 ret = value / 25.4 * 72.0;
459 ret = value / 2.54 * 72.0;
461 case PAPER_UNIT_INCH:
464 case PAPER_UNIT_PICAS:
467 case PAPER_UNIT_POINTS:
476 ret = ret / 72.0 * 25.4;
479 ret = ret / 72.0 * 2.54;
481 case PAPER_UNIT_INCH:
484 case PAPER_UNIT_PICAS:
487 case PAPER_UNIT_POINTS:
495 static PaperUnits paper_unit_default(void)
499 /* this is not used because it is not even slightly portable */
500 #include <langinfo.h>
502 result = nl_langinfo(_NL_MEASUREMENT_MEASUREMENT);
503 if (result[0] == '2') return PAPER_UNIT_INCH;
506 #ifdef LC_MEASUREMENT
507 result = setlocale(LC_MEASUREMENT, NULL);
509 result = setlocale(LC_ALL, NULL);
512 (strstr(result, "_US") || strstr(result, "_PR")) )
514 return PAPER_UNIT_INCH;
517 return PAPER_UNIT_CM;
521 *-----------------------------------------------------------------------------
523 *-----------------------------------------------------------------------------
526 static gint print_layout_page_count(PrintWindow *pw);
529 static gint print_preview_unit(gdouble points)
531 return (gint)(points / PRINT_PREVIEW_SCALE);
534 static void print_proof_size(PrintWindow *pw, gdouble *width, gdouble *height)
536 if (width) *width = pw->proof_width + PRINT_PROOF_MARGIN * 2;
541 h = pw->proof_height + PRINT_PROOF_MARGIN * 2;
542 if (pw->text_fields != 0) h += PRINT_TEXT_PADDING;
543 if (pw->text_fields & TEXT_INFO_FILENAME) h+= (gdouble)pw->text_points * 1.25;
544 if (pw->text_fields & TEXT_INFO_DIMENSIONS) h+= (gdouble)pw->text_points * 1.25;
545 if (pw->text_fields & TEXT_INFO_FILEDATE) h+= (gdouble)pw->text_points * 1.25;
546 if (pw->text_fields & TEXT_INFO_FILESIZE) h+= (gdouble)pw->text_points * 1.25;
551 static void print_window_layout_status(PrintWindow *pw)
556 total = print_layout_page_count(pw);
557 pw->proof_page = CLAMP(pw->proof_page, 0, total - 1);
559 buf = g_strdup_printf(_("page %d of %d"), pw->proof_page + 1, (total > 0) ? total : 1);
560 gtk_label_set_text(GTK_LABEL(pw->page_label), buf);
563 gtk_widget_set_sensitive(pw->page_label, (total > 0));
565 gtk_widget_set_sensitive(pw->button_back, (pw->proof_page > 0));
566 gtk_widget_set_sensitive(pw->button_next, (pw->proof_page < total - 1));
568 gtk_widget_set_sensitive(pw->print_button, total > 0);
571 static void print_window_layout_render_stop(PrintWindow *pw)
573 if (pw->layout_idle_id)
575 g_source_remove(pw->layout_idle_id);
576 pw->layout_idle_id = 0;
580 static gboolean print_window_layout_render_idle(gpointer data)
582 PrintWindow *pw = data;
584 print_job_close(pw, FALSE);
585 print_job_start(pw, RENDER_FORMAT_PREVIEW, 0);
587 pw->layout_idle_id = 0;
591 static void print_window_layout_render(PrintWindow *pw)
593 gdouble proof_w, proof_h;
595 print_proof_size(pw, &proof_w, &proof_h);
596 pw->proof_columns = (pw->layout_width - pw->margin_left - pw->margin_right) / proof_w;
597 pw->proof_rows = (pw->layout_height - pw->margin_top - pw->margin_bottom) / proof_h;
599 print_window_layout_status(pw);
601 if (!pw->layout_idle_id)
603 pw->layout_idle_id = g_idle_add(print_window_layout_render_idle, pw);
607 static void print_window_layout_size(PrintWindow *pw)
614 if (!pw->layout_image) return;
616 if (pw->paper_orientation == PAPER_ORIENTATION_LANDSCAPE)
618 width = pw->paper_height;
619 height = pw->paper_width;
623 width = pw->paper_width;
624 height = pw->paper_height;
627 pw->layout_width = width;
628 pw->layout_height = height;
630 sw = print_preview_unit(width);
631 sh = print_preview_unit(height);
632 pixbuf = image_get_pixbuf(pw->layout_image);
634 gdk_pixbuf_get_width(pixbuf) != sw ||
635 gdk_pixbuf_get_height(pixbuf) != sh)
637 pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, FALSE, 8, sw, sh);
638 image_change_pixbuf(pw->layout_image, pixbuf, 0.0, FALSE);
639 g_object_unref(pixbuf);
642 print_window_layout_render(pw);
643 print_window_layout_status(pw);
646 static gint print_layout_page_count(PrintWindow *pw)
649 gint images_per_page;
652 if (pw->layout_width - pw->margin_left - pw->margin_right <= 0.0 ||
653 pw->layout_height - pw->margin_top - pw->margin_bottom <= 0.0)
660 case PRINT_SOURCE_ALL:
661 images = g_list_length(pw->source_list);
663 case PRINT_SOURCE_SELECTION:
664 images = g_list_length(pw->source_selection);
666 case PRINT_SOURCE_IMAGE:
668 images = (pw->source_fd) ? 1 : 0;
674 case PRINT_LAYOUT_PROOF:
675 images_per_page = pw->proof_columns * pw->proof_rows;
677 case PRINT_LAYOUT_IMAGE:
683 if (images < 1 || images_per_page < 1) return 0;
685 pages = images / images_per_page;
686 if (pages * images_per_page < images) pages++;
691 static void print_layout_page_step(PrintWindow *pw, gint step)
696 max = print_layout_page_count(pw);
697 page = pw->proof_page + step;
699 if (page >= max) page = max - 1;
700 if (page < 0) page = 0;
702 if (page == pw->proof_page) return;
704 pw->proof_page = page;
705 print_window_layout_size(pw);
708 static void print_layout_page_back_cb(GtkWidget *widget, gpointer data)
710 PrintWindow *pw = data;
712 print_layout_page_step(pw, -1);
715 static void print_layout_page_next_cb(GtkWidget *widget, gpointer data)
717 PrintWindow *pw = data;
719 print_layout_page_step(pw, 1);
722 static void print_layout_zoom_in_cb(GtkWidget *widget, gpointer data)
724 PrintWindow *pw = data;
725 image_zoom_adjust(pw->layout_image, 0.25);
728 static void print_layout_zoom_out_cb(GtkWidget *widget, gpointer data)
730 PrintWindow *pw = data;
731 image_zoom_adjust(pw->layout_image, -0.25);
734 static void print_layout_zoom_original_cb(GtkWidget *widget, gpointer data)
736 PrintWindow *pw = data;
739 zoom = image_zoom_get(pw->layout_image);
740 image_zoom_set(pw->layout_image, (zoom == 1.0) ? 0.0 : 1.0);
743 static GtkWidget *print_window_layout_setup(PrintWindow *pw, GtkWidget *box)
750 vbox = pref_box_new(box, TRUE, GTK_ORIENTATION_VERTICAL, PREF_PAD_GAP);
751 group = pref_frame_new(vbox, TRUE, _("Preview"), GTK_ORIENTATION_VERTICAL, PREF_PAD_GAP);
753 pw->layout_idle_id = 0;
755 pw->layout_image = image_new(FALSE);
756 gtk_widget_set_size_request(pw->layout_image->widget, PRINT_DLG_PREVIEW_WIDTH, PRINT_DLG_PREVIEW_HEIGHT);
758 gtk_box_pack_start(GTK_BOX(group), pw->layout_image->widget, TRUE, TRUE, 0);
759 gtk_widget_show(pw->layout_image->widget);
761 hbox = pref_box_new(group, FALSE, GTK_ORIENTATION_HORIZONTAL, PREF_PAD_GAP);
762 pw->button_back = pref_button_new(hbox, GTK_STOCK_GO_BACK, NULL, TRUE,
763 G_CALLBACK(print_layout_page_back_cb), pw);
764 pw->button_next = pref_button_new(hbox, GTK_STOCK_GO_FORWARD, NULL, TRUE,
765 G_CALLBACK(print_layout_page_next_cb), pw);
766 pw->page_label = pref_label_new(hbox, "");
768 button = pref_button_new(NULL, GTK_STOCK_ZOOM_OUT, NULL, TRUE,
769 G_CALLBACK(print_layout_zoom_out_cb), pw);
770 gtk_box_pack_end(GTK_BOX(hbox), button, FALSE, FALSE, 0);
771 gtk_widget_show(button);
772 button = pref_button_new(NULL, GTK_STOCK_ZOOM_IN, NULL, TRUE,
773 G_CALLBACK(print_layout_zoom_in_cb), pw);
774 gtk_box_pack_end(GTK_BOX(hbox), button, FALSE, FALSE, 0);
775 gtk_widget_show(button);
776 button = pref_button_new(NULL, GTK_STOCK_ZOOM_100, NULL, TRUE,
777 G_CALLBACK(print_layout_zoom_original_cb), pw);
778 gtk_box_pack_end(GTK_BOX(hbox), button, FALSE, FALSE, 0);
779 gtk_widget_show(button);
781 print_window_layout_size(pw);
786 static void print_window_spin_set(GtkSpinButton *spin, gpointer block_data,
787 gdouble value, gdouble min, gdouble max,
788 gdouble step, gdouble page, gint digits)
790 if (block_data) g_signal_handlers_block_matched(G_OBJECT(spin), G_SIGNAL_MATCH_DATA,
791 0, 0, NULL, NULL, block_data);
792 gtk_spin_button_set_digits(spin, digits);
793 gtk_spin_button_set_increments(spin, step, page);
794 gtk_spin_button_set_range(spin, min, max);
795 gtk_spin_button_set_value(spin, value);
797 if (block_data) g_signal_handlers_unblock_matched(G_OBJECT(spin), G_SIGNAL_MATCH_DATA,
798 0, 0, NULL, NULL, block_data);
801 static void print_window_layout_sync_layout(PrintWindow *pw)
803 gtk_widget_set_sensitive(pw->image_scale_spin, (pw->layout == PRINT_LAYOUT_IMAGE));
804 gtk_widget_set_sensitive(pw->proof_group, (pw->layout == PRINT_LAYOUT_PROOF));
807 static void print_window_layout_sync_paper(PrintWindow *pw)
809 gdouble width, height;
814 gtk_widget_set_sensitive(pw->paper_width_spin, (pw->paper_size == 0));
815 gtk_widget_set_sensitive(pw->paper_height_spin, (pw->paper_size == 0));
817 width = print_paper_size_convert_units((gdouble)pw->paper_width, PAPER_UNIT_POINTS, pw->paper_units);
818 height = print_paper_size_convert_units((gdouble)pw->paper_height, PAPER_UNIT_POINTS, pw->paper_units);
820 switch (pw->paper_units)
832 case PAPER_UNIT_INCH:
837 case PAPER_UNIT_PICAS:
842 case PAPER_UNIT_POINTS:
850 print_window_spin_set(GTK_SPIN_BUTTON(pw->paper_width_spin), pw, width,
851 print_paper_size_convert_units(PRINT_MIN_WIDTH, PAPER_UNIT_POINTS, pw->paper_units),
852 print_paper_size_convert_units(PRINT_MAX_WIDTH, PAPER_UNIT_POINTS, pw->paper_units),
855 print_window_spin_set(GTK_SPIN_BUTTON(pw->paper_height_spin), pw, height,
856 print_paper_size_convert_units(PRINT_MIN_HEIGHT, PAPER_UNIT_POINTS, pw->paper_units),
857 print_paper_size_convert_units(PRINT_MAX_HEIGHT, PAPER_UNIT_POINTS, pw->paper_units),
860 print_window_spin_set(GTK_SPIN_BUTTON(pw->margin_left_spin), pw,
861 print_paper_size_convert_units(pw->margin_left, PAPER_UNIT_POINTS, pw->paper_units),
863 print_paper_size_convert_units(PRINT_MAX_WIDTH, PAPER_UNIT_POINTS, pw->paper_units),
866 print_window_spin_set(GTK_SPIN_BUTTON(pw->margin_right_spin), pw,
867 print_paper_size_convert_units(pw->margin_right, PAPER_UNIT_POINTS, pw->paper_units),
869 print_paper_size_convert_units(PRINT_MAX_WIDTH, PAPER_UNIT_POINTS, pw->paper_units),
872 print_window_spin_set(GTK_SPIN_BUTTON(pw->margin_top_spin), pw,
873 print_paper_size_convert_units(pw->margin_top, PAPER_UNIT_POINTS, pw->paper_units),
875 print_paper_size_convert_units(PRINT_MAX_HEIGHT, PAPER_UNIT_POINTS, pw->paper_units),
878 print_window_spin_set(GTK_SPIN_BUTTON(pw->margin_bottom_spin), pw,
879 print_paper_size_convert_units(pw->margin_bottom, PAPER_UNIT_POINTS, pw->paper_units),
881 print_paper_size_convert_units(PRINT_MAX_HEIGHT, PAPER_UNIT_POINTS, pw->paper_units),
884 print_window_spin_set(GTK_SPIN_BUTTON(pw->proof_width_spin), pw,
885 print_paper_size_convert_units(pw->proof_width, PAPER_UNIT_POINTS, pw->paper_units),
886 print_paper_size_convert_units(PRINT_PROOF_MIN_SIZE, PAPER_UNIT_POINTS, pw->paper_units),
887 print_paper_size_convert_units(PRINT_PROOF_MAX_SIZE, PAPER_UNIT_POINTS, pw->paper_units),
890 print_window_spin_set(GTK_SPIN_BUTTON(pw->proof_height_spin), pw,
891 print_paper_size_convert_units(pw->proof_height, PAPER_UNIT_POINTS, pw->paper_units),
892 print_paper_size_convert_units(PRINT_PROOF_MIN_SIZE, PAPER_UNIT_POINTS, pw->paper_units),
893 print_paper_size_convert_units(PRINT_PROOF_MAX_SIZE, PAPER_UNIT_POINTS, pw->paper_units),
897 static void print_window_layout_set_size(PrintWindow *pw, gdouble width, gdouble height)
899 pw->paper_width = width;
900 pw->paper_height = height;
902 print_window_layout_sync_paper(pw);
904 print_window_layout_size(pw);
907 static void print_window_layout_set_orientation(PrintWindow *pw, PaperOrientation o)
909 if (pw->paper_orientation == o) return;
911 pw->paper_orientation = o;
913 print_window_layout_size(pw);
917 *-----------------------------------------------------------------------------
919 *-----------------------------------------------------------------------------
922 static GList *print_window_list_printers(void)
928 p = popen(PRINT_LPR_QUERY, "r");
931 while (fgets(buffer, sizeof(buffer), p) != NULL)
937 if (strncmp(ptr, "printer ", 8) != 0) continue;
938 if (strstr(ptr, "enabled") == NULL) continue;
941 while (*end != '\0' && *end != '\n' && *end != ' ' && *end != '\t') end++;
943 list = g_list_append(list, g_strdup(ptr));
944 DEBUG_1("adding printer: %s", ptr);
953 *-----------------------------------------------------------------------------
955 *-----------------------------------------------------------------------------
958 typedef struct _PipeError PipeError;
960 struct sigaction old_action;
964 static sig_atomic_t pipe_handler_error = FALSE;
965 static PipeError *pipe_handler_data = NULL;
967 static void pipe_handler_sigpipe_cb(gint fd)
969 pipe_handler_error = TRUE;
972 static PipeError *pipe_handler_new(void)
974 struct sigaction new_action;
977 if (pipe_handler_data)
979 log_printf("warning SIGPIPE handler already in use\n");
983 pe = g_new0(PipeError, 1);
985 pipe_handler_error = FALSE;
986 pe->error = &pipe_handler_error;
988 new_action.sa_handler = pipe_handler_sigpipe_cb;
989 sigemptyset(&new_action.sa_mask);
990 new_action.sa_flags = 0;
992 /* setup our signal handler */
993 sigaction(SIGPIPE, &new_action, &pe->old_action);
995 pipe_handler_data = pe;
999 static void pipe_handler_free(PipeError *pe)
1002 if (pe != pipe_handler_data) log_printf("warning SIGPIPE handler not closing same data\n");
1004 /* restore the original signal handler */
1005 sigaction(SIGPIPE, &pe->old_action, NULL);
1007 pipe_handler_data = NULL;
1011 static gboolean pipe_handler_check(PipeError *pe)
1013 if (!pe) return FALSE;
1014 return !!(*pe->error);
1017 static FILE *print_job_ps_fd(PrintWindow *pw)
1019 if (pw->job_file) return pw->job_file;
1020 if (pw->job_pipe) return pw->job_pipe;
1024 static gboolean print_job_ps_init(PrintWindow *pw)
1028 const gchar *cmd = NULL;
1029 const gchar *path = NULL;
1033 if (pw->job_file != NULL || pw->job_pipe != NULL) return FALSE;
1035 switch (pw->job_output)
1037 case PRINT_OUTPUT_PS_LPR:
1038 cmd = PRINT_LPR_COMMAND;
1040 case PRINT_OUTPUT_PS_CUSTOM:
1041 cmd = pw->output_custom;
1043 case PRINT_OUTPUT_PS_FILE:
1044 path = pw->output_path;
1053 pw->job_pipe = popen(cmd, "w");
1059 buf = g_strdup_printf(_("Unable to open pipe for writing.\n\"%s\""), cmd);
1060 print_job_throw_error(pw, buf);
1074 buf = g_strdup_printf(_("A file with name %s already exists."), path);
1075 print_job_throw_error(pw, buf);
1081 pathl = path_from_utf8(path);
1082 pw->job_file = fopen(pathl, "w");
1089 buf = g_strdup_printf(_("Failure writing to file %s"), path);
1090 print_job_throw_error(pw, buf);
1096 g_free(pw->job_path);
1097 pw->job_path = g_strdup(path);
1100 f = print_job_ps_fd(pw);
1101 if (!f) return FALSE;
1103 lc_pointer = g_strdup(setlocale(LC_NUMERIC, NULL));
1104 setlocale(LC_NUMERIC, POSTSCRIPT_LOCALE);
1106 pe = pipe_handler_new();
1108 /* comments, etc. */
1109 g_fprintf(f, "%%!PS-Adobe-3.0\n");
1110 g_fprintf(f, "%%%%Creator: %s Version %s\n", GQ_APPNAME, VERSION);
1111 g_fprintf(f, "%%%%CreationDate: \n");
1112 g_fprintf(f, "%%%%LanguageLevel 2\n");
1113 g_fprintf(f, "%%%%DocumentMedia: \n");
1114 g_fprintf(f, "%%%%Orientation: %s\n",
1115 (pw->paper_orientation == PAPER_ORIENTATION_PORTRAIT) ? "Portrait" : "Landscape");
1116 g_fprintf(f, "%%%%BoundingBox: %f %f %f %f\n",
1117 0.0, 0.0, pw->paper_width, pw->paper_height);
1118 g_fprintf(f, "%%%%Pages: %d\n", print_layout_page_count(pw));
1119 g_fprintf(f, "%%%%PageOrder: Ascend\n");
1120 g_fprintf(f, "%%%%Title:\n");
1122 /* setup page size, coordinates (do we really need this?) */
1123 /* enabled for 1.0beta2 https://bugzilla.redhat.com/222639 */
1125 g_fprintf(f, "<<\n");
1126 g_fprintf(f, "/PageSize [%f %f]\n", pw->layout_width, pw->layout_height);
1127 g_fprintf(f, "/ImagingBBox [%f %f %f %f]\n", /* l b r t */
1128 pw->margin_left, pw->margin_bottom,
1129 pw->layout_width - pw->margin_right, pw->layout_height - pw->margin_top);
1130 g_fprintf(f, "/Orientation %d\n",
1131 (pw->paper_orientation == PAPER_ORIENTATION_PORTRAIT) ? 0 : 1);
1132 g_fprintf(f, ">> setpagedevice\n");
1135 ret = !pipe_handler_check(pe);
1136 pipe_handler_free(pe);
1140 setlocale(LC_NUMERIC, lc_pointer);
1144 if (!ret) print_job_throw_error(pw, _("SIGPIPE error writing to printer."));
1149 static gboolean print_job_ps_page_new(PrintWindow *pw, gint page)
1156 f= print_job_ps_fd(pw);
1157 if (!f) return FALSE;
1159 lc_pointer = g_strdup(setlocale(LC_NUMERIC, NULL));
1160 setlocale(LC_NUMERIC, POSTSCRIPT_LOCALE);
1162 pe = pipe_handler_new();
1164 g_fprintf(f, "%%%% page %d\n", page + 1);
1166 if (pw->paper_orientation == PAPER_ORIENTATION_LANDSCAPE)
1168 g_fprintf(f, "/pagelevel save def\n");
1169 g_fprintf(f, "%d 0 translate 90 rotate\n", (gint)pw->layout_height);
1172 ret = !pipe_handler_check(pe);
1173 pipe_handler_free(pe);
1177 setlocale(LC_NUMERIC, lc_pointer);
1181 if (!ret) print_job_throw_error(pw, _("SIGPIPE error writing to printer."));
1186 static gboolean print_job_ps_page_done(PrintWindow *pw)
1193 f = print_job_ps_fd(pw);
1194 if (!f) return FALSE;
1196 lc_pointer = g_strdup(setlocale(LC_NUMERIC, NULL));
1197 setlocale(LC_NUMERIC, POSTSCRIPT_LOCALE);
1199 pe = pipe_handler_new();
1201 if (pw->paper_orientation == PAPER_ORIENTATION_LANDSCAPE)
1203 g_fprintf(f, "pagelevel restore\n");
1206 g_fprintf(f, "showpage\n");
1208 ret = !pipe_handler_check(pe);
1209 pipe_handler_free(pe);
1213 setlocale(LC_NUMERIC, lc_pointer);
1217 if (!ret) print_job_throw_error(pw, _("SIGPIPE error writing to printer."));
1222 static void print_job_ps_page_image_pixel(FILE *f, guchar *pix)
1224 static gchar hex_digits[] = "0123456789abcdef";
1228 for (i = 0; i < 3; i++)
1230 text[i*2] = hex_digits[pix[i] >> 4];
1231 text[i*2+1] = hex_digits[pix[i] & 0xf];
1235 g_fprintf(f, "%s", text);
1237 static gboolean print_job_ps_page_image(PrintWindow *pw, GdkPixbuf *pixbuf,
1238 gdouble x, gdouble y, gdouble w, gdouble h,
1239 gdouble offx, gdouble offy)
1254 if (!pixbuf) return TRUE;
1256 f = print_job_ps_fd(pw);
1257 if (!f) return FALSE;
1259 sw = gdk_pixbuf_get_width(pixbuf);
1260 sh = gdk_pixbuf_get_height(pixbuf);
1262 if (pw->max_dpi >= PRINT_PS_DPI_MIN &&
1263 sw / pw->max_dpi > w / 72.0)
1265 pixbuf = gdk_pixbuf_scale_simple(pixbuf,
1266 (gint)(w / 72.0 * pw->max_dpi),
1267 (gint)(h / 72.0 * pw->max_dpi),
1268 PRINT_PS_MAX_INTERP);
1269 sw = gdk_pixbuf_get_width(pixbuf);
1270 sh = gdk_pixbuf_get_height(pixbuf);
1274 g_object_ref(G_OBJECT(pixbuf));
1277 bps = (gdk_pixbuf_get_has_alpha(pixbuf)) ? 4 : 3;
1278 rowstride = gdk_pixbuf_get_rowstride(pixbuf);
1279 pix = gdk_pixbuf_get_pixels(pixbuf);
1281 lc_pointer = g_strdup(setlocale(LC_NUMERIC, NULL));
1282 setlocale(LC_NUMERIC, POSTSCRIPT_LOCALE);
1284 pe = pipe_handler_new();
1286 g_fprintf(f, "gsave\n");
1287 g_fprintf(f, "[%f 0 0 %f %f %f] concat\n", w, h, x, pw->layout_height - h - y);
1288 g_fprintf(f, "/buf %d string def\n", sw * 3);
1289 g_fprintf(f, "%d %d %d\n", sw, sh, 8);
1290 g_fprintf(f, "[%d 0 0 -%d 0 %d]\n", sw, sh, sh);
1291 g_fprintf(f, "{ currentfile buf readhexstring pop }\n");
1292 g_fprintf(f, "false %d colorimage\n", 3);
1295 for (j = 0; j < sh; j++)
1297 p = pix + j * rowstride;
1298 for (i = 0; i < sw; i++)
1302 print_job_ps_page_image_pixel(f, p);
1306 bps_buf[0] = (p[0] * p[3] + PRINT_PS_MASK_R * (256 - p[3])) >> 8;
1307 bps_buf[1] = (p[1] * p[3] + PRINT_PS_MASK_G * (256 - p[3])) >> 8;
1308 bps_buf[2] = (p[2] * p[3] + PRINT_PS_MASK_B * (256 - p[3])) >> 8;
1309 print_job_ps_page_image_pixel(f, bps_buf);
1320 if (c > 0) g_fprintf(f, "\n");
1321 g_fprintf(f, "grestore\n");
1323 ret = !pipe_handler_check(pe);
1324 pipe_handler_free(pe);
1328 setlocale(LC_NUMERIC, lc_pointer);
1332 g_object_unref(G_OBJECT(pixbuf));
1334 if (!ret) print_job_throw_error(pw, _("SIGPIPE error writing to printer."));
1339 static gdouble convert_pango_dpi(gdouble points);
1341 static gboolean print_job_ps_page_text(PrintWindow *pw, const gchar *text, gdouble point_size,
1342 gdouble x, gdouble y, gdouble width,
1343 guint8 r, guint8 g, guint8 b)
1345 PangoLayout *layout;
1346 PangoFontDescription *desc;
1350 gdouble scale_to_max_dpi = (pw->max_dpi >= PRINT_PS_DPI_MIN) ? pw->max_dpi / 72.0 : 1200.0 / 72.0;
1352 layout = gtk_widget_create_pango_layout(pw->dialog->dialog, NULL);
1354 desc = pango_font_description_new();
1355 pango_font_description_set_size(desc, convert_pango_dpi(point_size) * PANGO_SCALE * scale_to_max_dpi);
1356 pango_layout_set_font_description(layout, desc);
1357 pango_font_description_free(desc);
1359 pango_layout_set_alignment(layout, PANGO_ALIGN_CENTER);
1360 pango_layout_set_text(layout, text, -1);
1362 pango_layout_get_pixel_size(layout, &lw, &lh);
1363 x = x - (gdouble)lw / 2.0 / scale_to_max_dpi;
1365 pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, lw, lh);
1366 gdk_pixbuf_fill(pixbuf, 0xffffffff);
1367 pixbuf_draw_layout(pixbuf, layout, pw->dialog->dialog, 0, 0, r, g, b, 255);
1368 g_object_unref(G_OBJECT(layout));
1370 ret = print_job_ps_page_image(pw, pixbuf, x, y,
1371 /* do not allow rescaling of the pixbuf due to rounding errors */
1372 ((gdouble)lw + 0.01) / scale_to_max_dpi,
1373 ((gdouble)lh + 0.01) / scale_to_max_dpi,
1376 g_object_unref(G_OBJECT(pixbuf));
1381 static gboolean print_job_ps_end(PrintWindow *pw)
1388 f = print_job_ps_fd(pw);
1389 if (!f) return FALSE;
1391 lc_pointer = g_strdup(setlocale(LC_NUMERIC, NULL));
1392 setlocale(LC_NUMERIC, POSTSCRIPT_LOCALE);
1394 pe = pipe_handler_new();
1396 g_fprintf(f, "%%%%EOF\n");
1398 ret = !pipe_handler_check(pe);
1399 pipe_handler_free(pe);
1403 setlocale(LC_NUMERIC, lc_pointer);
1407 if (!ret) print_job_throw_error(pw, _("SIGPIPE error writing to printer."));
1413 *-----------------------------------------------------------------------------
1415 *-----------------------------------------------------------------------------
1418 static gboolean print_job_rgb_page_new(PrintWindow *pw, gint page)
1424 pixbuf_set_rect_fill(pw->job_pixbuf, 0, 0,
1425 gdk_pixbuf_get_width(pw->job_pixbuf),
1426 gdk_pixbuf_get_height(pw->job_pixbuf),
1427 255, 255, 255, 255);
1430 g_free(pw->job_path);
1431 pw->job_path = NULL;
1433 total = print_layout_page_count(pw);
1435 if (!pw->output_path ||
1436 page < 0 || page >= total) return FALSE;
1443 ext = extension_from_path(pw->output_path);
1447 base = g_strndup(pw->output_path, ext - pw->output_path);
1451 base = g_strdup(pw->output_path);
1454 pw->job_path = g_strdup_printf("%s_%03d%s", base, page + 1, ext);
1459 pw->job_path = g_strdup(pw->output_path);
1462 if (isfile(pw->job_path))
1466 buf = g_strdup_printf(_("A file with name %s already exists."), pw->job_path);
1467 print_job_throw_error(pw, buf);
1470 g_free(pw->job_path);
1471 pw->job_path = NULL;
1474 return (pw->job_path != NULL);
1477 static gboolean print_job_rgb_page_done(PrintWindow *pw)
1480 gboolean ret = FALSE;
1482 if (!pw->job_pixbuf) return FALSE;
1484 pathl = path_from_utf8(pw->job_path);
1486 if (pw->output_format == PRINT_FILE_PNG)
1488 ret = pixbuf_to_file_as_png(pw->job_pixbuf, pathl);
1494 switch (pw->output_format)
1496 case PRINT_FILE_JPG_LOW:
1499 case PRINT_FILE_JPG_NORMAL:
1502 case PRINT_FILE_JPG_HIGH:
1511 ret = pixbuf_to_file_as_jpg(pw->job_pixbuf, pathl, quality);
1521 buf = g_strdup_printf(_("Failure writing to file %s"), pw->job_path);
1522 print_job_throw_error(pw, buf);
1529 static gboolean print_job_rgb_page_image(PrintWindow *pw, GdkPixbuf *pixbuf,
1530 gdouble x, gdouble y, gdouble w, gdouble h,
1531 gdouble offx, gdouble offy)
1535 gdouble rx, ry, rw, rh;
1537 if (!pw->job_pixbuf) return FALSE;
1538 if (!pixbuf) return TRUE;
1540 sw = (gdouble)gdk_pixbuf_get_width(pixbuf);
1541 sh = (gdouble)gdk_pixbuf_get_height(pixbuf);
1543 dw = (gdouble)gdk_pixbuf_get_width(pw->job_pixbuf);
1544 dh = (gdouble)gdk_pixbuf_get_height(pw->job_pixbuf);
1546 if (clip_region(x, y, w, h,
1548 &rx, &ry, &rw, &rh))
1550 gdk_pixbuf_composite(pixbuf, pw->job_pixbuf, rx, ry, rw, rh,
1553 (w / sw < 0.01 || h / sh < 0.01) ? GDK_INTERP_NEAREST : GDK_INTERP_BILINEAR, 255);
1559 static gdouble convert_pango_dpi(gdouble points)
1561 static gdouble dpi = 0.0;
1565 GtkSettings *settings;
1566 GObjectClass *klass;
1568 settings = gtk_settings_get_default();
1569 klass = G_OBJECT_CLASS(GTK_SETTINGS_GET_CLASS(settings));
1570 if (g_object_class_find_property(klass, "gtk-xft-dpi"))
1573 g_object_get(settings, "gtk-xft-dpi", &int_dpi, NULL);
1574 dpi = (gdouble)int_dpi / PANGO_SCALE;
1579 static gboolean warned = FALSE;
1580 gdouble fallback_dpi = 96.0;
1586 log_printf("pango dpi unknown, assuming %.0f\n", fallback_dpi);
1590 log_printf("pango dpi reported as %.0f ignored, assuming %.0f\n", dpi, fallback_dpi);
1599 if (dpi == 0) return points;
1600 return points * 72.0 / dpi;
1603 static gboolean print_job_rgb_page_text(PrintWindow *pw, const gchar *text, gdouble point_size,
1604 gdouble x, gdouble y, gdouble width,
1605 guint8 r, guint8 g, guint8 b)
1607 PangoLayout *layout;
1608 PangoFontDescription *desc;
1611 if (!pw->job_pixbuf) return FALSE;
1613 layout = gtk_widget_create_pango_layout(pw->dialog->dialog, NULL);
1615 desc = pango_font_description_new();
1616 pango_font_description_set_size(desc, convert_pango_dpi(point_size) * PANGO_SCALE);
1617 pango_layout_set_font_description(layout, desc);
1618 pango_font_description_free(desc);
1620 pango_layout_set_alignment(layout, PANGO_ALIGN_CENTER);
1621 pango_layout_set_text(layout, text, -1);
1623 pango_layout_get_pixel_size(layout, &lw, &lh);
1624 x = x - (gdouble)lw / 2.0;
1626 pixbuf_draw_layout(pw->job_pixbuf, layout, pw->dialog->dialog, x, y, r, g, b, 255);
1627 g_object_unref(G_OBJECT(layout));
1632 static gboolean print_job_rgb_init(PrintWindow *pw)
1634 if (pw->job_pixbuf) g_object_unref(pw->job_pixbuf);
1635 pw->job_pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, FALSE, 8,
1636 (gint)pw->layout_width, (gint)pw->layout_height);
1638 return print_job_rgb_page_new(pw, pw->job_page);
1642 *-----------------------------------------------------------------------------
1644 *-----------------------------------------------------------------------------
1647 static gboolean print_job_preview_page_new(PrintWindow *pw, gint page)
1653 pixbuf = pw->job_pixbuf;
1654 if (!pixbuf) return FALSE;
1656 w = print_preview_unit(pw->layout_width);
1657 h = print_preview_unit(pw->layout_height);
1658 l = print_preview_unit(pw->margin_left);
1659 r = print_preview_unit(pw->margin_right);
1660 t = print_preview_unit(pw->margin_top);
1661 b = print_preview_unit(pw->margin_bottom);
1663 /* fill background */
1664 pixbuf_set_rect_fill(pixbuf, 0, 0, w, h,
1665 255, 255, 255, 255);
1667 /* draw cm or inch grid */
1674 units = (pw->paper_units == PAPER_UNIT_MM ||
1675 pw->paper_units == PAPER_UNIT_CM) ? PAPER_UNIT_CM : PAPER_UNIT_INCH;
1677 grid = print_paper_size_convert_units(1.0, units, PAPER_UNIT_POINTS);
1678 for (i = grid ; i < pw->layout_width; i += grid)
1680 pixbuf_draw_rect_fill(pixbuf, print_preview_unit(i), 0, 1, h, 0, 0, 0, 16);
1682 for (i = grid; i < pw->layout_height; i += grid)
1684 pixbuf_draw_rect_fill(pixbuf, 0, print_preview_unit(i), w, 1, 0, 0, 0, 16);
1688 /* proof sheet grid */
1689 if (pw->layout == PRINT_LAYOUT_PROOF)
1692 gdouble proof_w, proof_h;
1695 print_proof_size(pw, &proof_w, &proof_h);
1696 uw = print_preview_unit(proof_w + PRINT_PREVIEW_SCALE - 0.1);
1697 uh = print_preview_unit(proof_h + PRINT_PREVIEW_SCALE - 0.1);
1699 for (i = 0; i < pw->proof_columns; i++)
1700 for (j = 0; j < pw->proof_rows; j++)
1704 x = pw->margin_left + (pw->layout_width - pw->margin_left - pw->margin_right - (pw->proof_columns * proof_w)) / 2 + i * proof_w;
1705 y = pw->margin_top + j * proof_h;
1707 pixbuf_draw_rect(pixbuf, print_preview_unit(x), print_preview_unit(y), uw, uh,
1708 255, 0, 0, 64, 1, 1, 1, 1);
1712 /* non-printable region (margins) */
1713 pixbuf_draw_rect(pixbuf, 0, 0, w, h,
1718 pixbuf_draw_rect(pixbuf, l, 0, w - l - r, h,
1721 pixbuf_draw_rect(pixbuf, 0, t, w, h - t - b,
1726 pixbuf_draw_rect(pixbuf, 0, 0, w, h,
1730 image_area_changed(pw->layout_image, 0, 0, w, h);
1735 static gboolean print_job_preview_page_done(PrintWindow *pw)
1740 static gboolean print_job_preview_page_image(PrintWindow *pw, GdkPixbuf *pixbuf,
1741 gdouble x, gdouble y, gdouble w, gdouble h,
1742 gdouble offx, gdouble offy)
1746 gdouble rx, ry, rw, rh;
1748 if (!pw->job_pixbuf) return FALSE;
1749 if (!pixbuf) return TRUE;
1751 sw = (gdouble)gdk_pixbuf_get_width(pixbuf);
1752 sh = (gdouble)gdk_pixbuf_get_height(pixbuf);
1754 dw = (gdouble)gdk_pixbuf_get_width(pw->job_pixbuf);
1755 dh = (gdouble)gdk_pixbuf_get_height(pw->job_pixbuf);
1757 x = print_preview_unit(x);
1758 y = print_preview_unit(y);
1759 w = print_preview_unit(w);
1760 h = print_preview_unit(h);
1761 offx = print_preview_unit(offx);
1762 offy = print_preview_unit(offy);
1764 if (clip_region(x, y, w, h,
1766 &rx, &ry, &rw, &rh))
1768 gdk_pixbuf_composite(pixbuf, pw->job_pixbuf, rx, ry, rw, rh,
1771 (w / sw < 0.01 || h / sh < 0.01) ? GDK_INTERP_NEAREST : GDK_INTERP_BILINEAR, 255);
1773 image_area_changed(pw->layout_image, rx, ry, rw, rh);
1779 static gboolean print_job_preview_page_text(PrintWindow *pw, const gchar *text, gdouble point_size,
1780 gdouble x, gdouble y, gdouble width,
1781 guint8 r, guint8 g, guint8 b)
1783 PangoLayout *layout;
1784 PangoFontDescription *desc;
1788 if (!pw->job_pixbuf) return FALSE;
1790 layout = gtk_widget_create_pango_layout(pw->dialog->dialog, NULL);
1792 desc = pango_font_description_new();
1793 pango_font_description_set_size(desc, convert_pango_dpi(point_size) * PANGO_SCALE);
1794 pango_layout_set_font_description(layout, desc);
1795 pango_font_description_free(desc);
1797 pango_layout_set_alignment(layout, PANGO_ALIGN_CENTER);
1798 pango_layout_set_text(layout, text, -1);
1800 pango_layout_get_pixel_size(layout, &lw, &lh);
1801 x = x - (gdouble)lw / 2.0;
1803 pixbuf = gdk_pixbuf_new(GDK_COLORSPACE_RGB, TRUE, 8, lw, lh);
1804 pixbuf_set_rect_fill(pixbuf, 0, 0, lw, lh, 0, 0, 0, 0);
1805 pixbuf_draw_layout(pixbuf, layout, pw->dialog->dialog, 0, 0, r, g, b, 255);
1806 g_object_unref(G_OBJECT(layout));
1808 print_job_preview_page_image(pw, pixbuf, x, y, (gdouble)lw, (gdouble)lh, 0, 0);
1809 g_object_unref(pixbuf);
1814 static gboolean print_job_preview_init(PrintWindow *pw)
1816 if (pw->job_pixbuf) g_object_unref(pw->job_pixbuf);
1817 pw->job_pixbuf = image_get_pixbuf(pw->layout_image);
1818 g_object_ref(pw->job_pixbuf);
1820 return print_job_preview_page_new(pw, pw->job_page);
1825 *-----------------------------------------------------------------------------
1827 *-----------------------------------------------------------------------------
1830 static gboolean print_job_page_new(PrintWindow *pw)
1832 switch (pw->job_format)
1834 case RENDER_FORMAT_RGB:
1835 return print_job_rgb_page_new(pw, pw->job_page);
1836 case RENDER_FORMAT_PS:
1837 return print_job_ps_page_new(pw, pw->job_page);
1838 case RENDER_FORMAT_PREVIEW:
1839 return print_job_preview_page_new(pw, pw->job_page);
1845 static gboolean print_job_page_done(PrintWindow *pw)
1847 switch (pw->job_format)
1849 case RENDER_FORMAT_RGB:
1850 return print_job_rgb_page_done(pw);
1851 case RENDER_FORMAT_PS:
1852 return print_job_ps_page_done(pw);
1853 case RENDER_FORMAT_PREVIEW:
1854 return print_job_preview_page_done(pw);
1860 static gboolean print_job_page_image(PrintWindow *pw, GdkPixbuf *pixbuf,
1861 gdouble x, gdouble y, gdouble w, gdouble h,
1862 gdouble offx, gdouble offy)
1864 gboolean success = FALSE;
1866 if (w <= 0.0 || h <= 0.0) return TRUE;
1868 switch (pw->job_format)
1870 case RENDER_FORMAT_RGB:
1871 success = print_job_rgb_page_image(pw, pixbuf, x, y, w, h, offx, offy);
1873 case RENDER_FORMAT_PS:
1874 success = print_job_ps_page_image(pw, pixbuf, x, y, w, h, offx, offy);
1876 case RENDER_FORMAT_PREVIEW:
1877 success = print_job_preview_page_image(pw, pixbuf, x, y, w, h, offx, offy);
1884 static gboolean print_job_page_text(PrintWindow *pw, const gchar *text, gdouble point_size,
1885 gdouble x, gdouble y, gdouble width,
1886 guint8 r, guint8 g, guint8 b)
1888 gboolean success = TRUE;
1890 if (!text) return TRUE;
1892 switch (pw->job_format)
1894 case RENDER_FORMAT_RGB:
1895 success = print_job_rgb_page_text(pw, text, point_size, x, y, width, r, g, b);
1897 case RENDER_FORMAT_PS:
1898 success = print_job_ps_page_text(pw, text, point_size, x, y, width, r, g, b);
1900 case RENDER_FORMAT_PREVIEW:
1901 success = print_job_preview_page_text(pw, text, point_size, x, y, width, r, g, b);
1909 *-----------------------------------------------------------------------------
1911 *-----------------------------------------------------------------------------
1914 static gboolean print_job_render_image(PrintWindow *pw);
1915 static gboolean print_job_render_proof(PrintWindow *pw);
1918 static void print_job_status(PrintWindow *pw)
1925 if (!pw->job_progress) return;
1927 page = pw->job_page;
1928 total = print_layout_page_count(pw);
1930 if (pw->layout == PRINT_LAYOUT_PROOF && pw->proof_point)
1934 start = g_list_first(pw->proof_point);
1935 value = (gdouble)g_list_position(start, pw->proof_point) / g_list_length(start);
1939 value = (total > 0) ? (gdouble)page / total : 0.0;
1942 buf = g_strdup_printf(_("Page %d"), page + 1);
1943 gtk_progress_bar_set_text(GTK_PROGRESS_BAR(pw->job_progress), buf);
1946 if (pw->job_path && pw->job_progress_label)
1948 gtk_label_set_text(GTK_LABEL(pw->job_progress_label), pw->job_path);
1951 gtk_progress_bar_set_fraction(GTK_PROGRESS_BAR(pw->job_progress), value);
1954 static void print_job_throw_error(PrintWindow *pw, const gchar *message)
1957 GtkWidget *parent = NULL;
1962 #if GTK_CHECK_VERSION(2,20,0)
1963 if (gtk_widget_get_visible(pw->dialog->dialog)) parent = pw->dialog->dialog;
1965 if (GTK_WIDGET_VISIBLE(pw->dialog->dialog)) parent = pw->dialog->dialog;
1968 gd = generic_dialog_new(_("Printing error"), "print_warning",
1969 parent, TRUE, NULL, NULL);
1970 generic_dialog_add_button(gd, GTK_STOCK_OK, NULL, NULL, TRUE);
1972 buf = g_strdup_printf(_("An error occured printing to %s."), print_output_name(pw->output));
1973 generic_dialog_add_message(gd, GTK_STOCK_DIALOG_ERROR, _("Printing error"), buf);
1976 group = pref_group_new(gd->vbox, FALSE, _("Details"), GTK_ORIENTATION_VERTICAL);
1977 label = pref_label_new(group, message);
1978 gtk_misc_set_alignment(GTK_MISC(label), 0.0, 0.5);
1980 gtk_widget_show(gd->dialog);
1983 static void print_job_done(PrintWindow *pw)
1985 print_job_close(pw, FALSE);
1988 static gboolean print_job_text_image(PrintWindow *pw, const gchar *path,
1989 gdouble x, gdouble y, gdouble width,
1990 gint sw, gint sh, gint proof)
1993 gboolean space = FALSE;
1994 gboolean newline = FALSE;
1997 if (pw->text_fields == 0) return TRUE;
1999 string = g_string_new("");
2000 path = image_loader_get_fd(pw->job_loader)->path;
2002 if (pw->text_fields & TEXT_INFO_FILENAME)
2004 if (pw->text_fields & TEXT_INFO_FILEPATH)
2005 g_string_append(string, path);
2007 g_string_append(string, filename_from_path(path));
2010 else if (pw->text_fields & TEXT_INFO_FILEPATH)
2012 gchar *dirname = g_path_get_dirname(path);
2014 g_string_append_printf(string, "%s%s", dirname, G_DIR_SEPARATOR_S);
2018 if (pw->text_fields & TEXT_INFO_DIMENSIONS)
2020 if (newline) g_string_append(string, "\n");
2021 g_string_append_printf(string, "%d x %d", (gint)sw, (gint)sh);
2025 if (pw->text_fields & TEXT_INFO_FILEDATE)
2027 if (newline) g_string_append(string, "\n");
2028 if (space) g_string_append(string, " - ");
2029 g_string_append(string, text_from_time(filetime(image_loader_get_fd(pw->job_loader)->path)));
2033 if (pw->text_fields & TEXT_INFO_FILESIZE)
2037 if (newline) g_string_append(string, "\n");
2038 if (space) g_string_append(string, " - ");
2039 size = text_from_size_abrev(filesize(image_loader_get_fd(pw->job_loader)->path));
2040 g_string_append(string, size);
2044 ret = print_job_page_text(pw, string->str, pw->text_points, x, y, width,
2045 pw->text_r, pw->text_g, pw->text_b);
2047 g_string_free(string, TRUE);
2052 static void print_job_render_image_loader_done(ImageLoader *il, gpointer data)
2054 PrintWindow *pw = data;
2056 gboolean success = TRUE;
2058 pixbuf = image_loader_get_pixbuf(il);
2067 sw = (gdouble)gdk_pixbuf_get_width(pixbuf);
2068 sh = (gdouble)gdk_pixbuf_get_height(pixbuf);
2070 dw = pw->layout_width - pw->margin_left - pw->margin_right;
2071 dh = pw->layout_height - pw->margin_top - pw->margin_bottom;
2073 if (dw / sw < dh / sh)
2086 if (pw->image_scale >= 5.0)
2088 w = w * pw->image_scale / 100.0;
2089 h = h * pw->image_scale / 100.0;
2092 x = pw->margin_left + (dw / 2) - (w / 2);
2093 y = pw->margin_top + (dh / 2) - (h / 2);
2103 if (x + w >= pw->layout_width) w = pw->layout_width - x;
2111 if (y + h >= pw->layout_height) h = pw->layout_height - y;
2113 success = (success &&
2114 print_job_page_image(pw, pixbuf, x, y, w, h, offx, offy));
2117 y = y + h + PRINT_TEXT_PADDING;
2119 success = (success &&
2120 print_job_text_image(pw, image_loader_get_fd(pw->job_loader)->path, x, y, dw, sw, sh, FALSE));
2123 image_loader_free(pw->job_loader);
2124 pw->job_loader = NULL;
2126 if (pw->job_format == RENDER_FORMAT_PREVIEW)
2132 success = (success && print_job_page_done(pw));
2135 print_job_close(pw, TRUE);
2140 print_job_status(pw);
2142 if (print_job_render_image(pw))
2144 if (!print_job_page_new(pw)) print_job_close(pw, TRUE);
2152 static gboolean print_job_render_image(PrintWindow *pw)
2154 FileData *fd = NULL;
2158 case PRINT_SOURCE_SELECTION:
2159 fd = g_list_nth_data(pw->source_selection, pw->job_page);
2161 case PRINT_SOURCE_ALL:
2162 fd = g_list_nth_data(pw->source_list, pw->job_page);
2164 case PRINT_SOURCE_IMAGE:
2166 if (pw->job_page == 0) fd = pw->source_fd;
2170 image_loader_free(pw->job_loader);
2171 pw->job_loader = NULL;
2173 if (!fd) return FALSE;
2175 pw->job_loader = image_loader_new(fd);
2176 g_signal_connect(G_OBJECT(pw->job_loader), "done", (GCallback)print_job_render_image_loader_done, pw);
2177 if (!image_loader_start(pw->job_loader))
2179 image_loader_free(pw->job_loader);
2180 pw->job_loader= NULL;
2186 static void print_job_render_proof_loader_done(ImageLoader *il, gpointer data)
2188 PrintWindow *pw = data;
2192 gdouble proof_w, proof_h;
2193 gdouble icon_w, icon_h;
2195 gboolean success = TRUE;
2197 if (pw->proof_columns < 1 || pw->proof_rows < 1)
2199 image_loader_free(pw->job_loader);
2200 pw->job_loader = NULL;
2207 pixbuf = image_loader_get_pixbuf(il);
2209 w = gdk_pixbuf_get_width(pixbuf);
2210 h = gdk_pixbuf_get_height(pixbuf);
2212 if (pw->proof_width / w < pw->proof_height / h)
2214 icon_w = pw->proof_width;
2215 icon_h = pw->proof_width / w * h;
2220 icon_h = pw->proof_height;
2221 icon_w = pw->proof_height / h * w;
2225 y = pw->proof_position / pw->proof_columns;
2226 x = pw->proof_position - (y * pw->proof_columns);
2228 print_proof_size(pw, &proof_w, &proof_h);
2232 x += pw->margin_left + (pw->layout_width - pw->margin_left - pw->margin_right - (pw->proof_columns * proof_w)) / 2 + (proof_w - icon_w) / 2;
2233 y += pw->margin_top + PRINT_PROOF_MARGIN + (pw->proof_height - icon_h) / 2;
2235 success = (success &&
2236 print_job_page_image(pw, pixbuf, x, y, icon_w, icon_h, 0, 0));
2239 y = y + icon_h + (pw->proof_height - icon_h) / 2 + PRINT_TEXT_PADDING;
2241 success = (success &&
2242 print_job_text_image(pw, image_loader_get_fd(pw->job_loader)->path, x, y, icon_w + PRINT_PROOF_MARGIN * 2, w, h, TRUE));
2246 print_job_close(pw, TRUE);
2250 if (pw->proof_point) pw->proof_point = pw->proof_point->next;
2252 pw->proof_position++;
2253 if (pw->proof_position >= pw->proof_columns * pw->proof_rows)
2255 if (pw->job_format == RENDER_FORMAT_PREVIEW)
2261 if (!print_job_page_done(pw))
2263 print_job_close(pw, TRUE);
2267 pw->proof_position = 0;
2269 if (print_job_render_proof(pw))
2271 if (!print_job_page_new(pw))
2273 print_job_close(pw, TRUE);
2276 print_job_status(pw);
2285 if (print_job_render_proof(pw))
2287 print_job_status(pw);
2291 if (print_job_page_done(pw))
2297 print_job_close(pw, TRUE);
2303 static gboolean print_job_render_proof(PrintWindow *pw)
2305 FileData *fd = NULL;
2307 if (pw->proof_columns < 1 || pw->proof_rows < 1) return FALSE;
2309 if (!pw->proof_point && pw->proof_position == 0 && pw->source == PRINT_SOURCE_IMAGE)
2313 else if (pw->proof_point &&
2314 pw->proof_position < pw->proof_columns * pw->proof_rows)
2316 fd = pw->proof_point->data;
2319 if (!fd) return FALSE;
2321 image_loader_free(pw->job_loader);
2322 pw->job_loader = image_loader_new(fd);
2323 g_signal_connect(G_OBJECT(pw->job_loader), "done", (GCallback)print_job_render_proof_loader_done, pw);
2324 if (!image_loader_start(pw->job_loader))
2326 image_loader_free(pw->job_loader);
2327 pw->job_loader = NULL;
2333 static void print_job_render(PrintWindow *pw)
2335 gdouble proof_w, proof_h;
2338 pw->proof_position = 0;
2342 case PRINT_SOURCE_SELECTION:
2343 pw->proof_point = pw->source_selection;
2345 case PRINT_SOURCE_ALL:
2346 pw->proof_point = pw->source_list;
2348 case PRINT_SOURCE_IMAGE:
2350 pw->proof_point = NULL;
2354 print_proof_size(pw, &proof_w, &proof_h);
2355 pw->proof_columns = (pw->layout_width - pw->margin_left - pw->margin_right) / proof_w;
2356 pw->proof_rows = (pw->layout_height - pw->margin_top - pw->margin_bottom) / proof_h;
2358 if (pw->job_format == RENDER_FORMAT_PREVIEW)
2362 total = print_layout_page_count(pw);
2363 if (pw->job_page < 0 || pw->job_page >= total)
2369 if (pw->proof_point && pw->job_page > 0)
2371 pw->proof_point = g_list_nth(pw->proof_point, pw->job_page * pw->proof_columns * pw->proof_rows);
2375 if (!print_job_page_new(pw))
2377 print_job_close(pw, TRUE);
2381 if (pw->layout == PRINT_LAYOUT_IMAGE)
2383 finished = !print_job_render_image(pw);
2387 finished = !print_job_render_proof(pw);
2390 if (finished) print_job_done(pw);
2393 static gboolean print_job_init(PrintWindow *pw)
2395 gboolean success = FALSE;
2399 switch (pw->job_format)
2401 case RENDER_FORMAT_RGB:
2402 success = print_job_rgb_init(pw);
2404 case RENDER_FORMAT_PS:
2405 success = print_job_ps_init(pw);
2407 case RENDER_FORMAT_PREVIEW:
2408 pw->job_page = pw->proof_page;
2409 success = print_job_preview_init(pw);
2416 static gboolean print_job_finish(PrintWindow *pw)
2418 gboolean success = FALSE;
2420 switch (pw->job_format)
2422 case RENDER_FORMAT_RGB:
2425 case RENDER_FORMAT_PS:
2426 print_job_ps_end(pw);
2428 case RENDER_FORMAT_PREVIEW:
2436 static void print_job_close_file(PrintWindow *pw)
2440 fclose(pw->job_file);
2441 pw->job_file = NULL;
2448 pe = pipe_handler_new();
2449 pclose(pw->job_pipe);
2450 pipe_handler_free(pe);
2452 pw->job_pipe = NULL;
2456 static gboolean print_job_close_finish_cb(gpointer data)
2458 PrintWindow *pw = data;
2460 print_window_close(pw);
2464 static void print_job_close(PrintWindow *pw, gint error)
2466 if (!error) print_job_finish(pw);
2468 print_job_close_file(pw);
2469 g_free(pw->job_path);
2470 pw->job_path = NULL;
2474 generic_dialog_close(pw->job_dialog);
2475 pw->job_dialog = NULL;
2476 pw->job_progress = NULL;
2479 image_loader_free(pw->job_loader);
2480 pw->job_loader = NULL;
2484 g_object_unref(pw->job_pixbuf);
2485 pw->job_pixbuf = NULL;
2488 #if GTK_CHECK_VERSION(2,20,0)
2489 if (pw->dialog && !gtk_widget_get_visible(pw->dialog->dialog))
2491 if (pw->dialog && !GTK_WIDGET_VISIBLE(pw->dialog->dialog))
2494 g_idle_add_full(G_PRIORITY_HIGH_IDLE, print_job_close_finish_cb, pw, NULL);
2498 static void print_job_cancel_cb(GenericDialog *gd, gpointer data)
2500 PrintWindow *pw = data;
2502 print_job_close(pw, FALSE);
2505 static void print_pref_store(PrintWindow *pw)
2508 pref_list_int_set(PRINT_PREF_GROUP, PRINT_PREF_SAVE, pw->save_settings);
2510 if (!pw->save_settings) return;
2512 /* only store values that are actually used in this print job, hence the if()s */
2514 pref_list_int_set(PRINT_PREF_GROUP, PRINT_PREF_OUTPUT, pw->output);
2516 if (pw->output == PRINT_OUTPUT_RGB_FILE)
2518 pref_list_int_set(PRINT_PREF_GROUP, PRINT_PREF_FORMAT, pw->output_format);
2521 if (pw->job_format == RENDER_FORMAT_PS)
2523 pref_list_double_set(PRINT_PREF_GROUP, PRINT_PREF_DPI, pw->max_dpi);
2526 pref_list_int_set(PRINT_PREF_GROUP, PRINT_PREF_UNITS, pw->paper_units);
2527 pref_list_int_set(PRINT_PREF_GROUP, PRINT_PREF_SIZE, pw->paper_size);
2528 pref_list_int_set(PRINT_PREF_GROUP, PRINT_PREF_ORIENTATION, pw->paper_orientation);
2530 if (pw->paper_size == 0)
2532 pref_list_double_set(PRINT_PREF_GROUP, PRINT_PREF_CUSTOM_WIDTH, pw->paper_width);
2533 pref_list_double_set(PRINT_PREF_GROUP, PRINT_PREF_CUSTOM_HEIGHT, pw->paper_height);
2536 pref_list_double_set(PRINT_PREF_GROUP, PRINT_PREF_MARGIN_LEFT, pw->margin_left);
2537 pref_list_double_set(PRINT_PREF_GROUP, PRINT_PREF_MARGIN_RIGHT, pw->margin_right);
2538 pref_list_double_set(PRINT_PREF_GROUP, PRINT_PREF_MARGIN_TOP, pw->margin_top);
2539 pref_list_double_set(PRINT_PREF_GROUP, PRINT_PREF_MARGIN_BOTTOM, pw->margin_bottom);
2541 if (pw->layout == PRINT_LAYOUT_PROOF)
2543 pref_list_double_set(PRINT_PREF_GROUP, PRINT_PREF_PROOF_WIDTH, pw->proof_width);
2544 pref_list_double_set(PRINT_PREF_GROUP, PRINT_PREF_PROOF_HEIGHT, pw->proof_height);
2547 if (pw->output == PRINT_OUTPUT_PS_CUSTOM)
2549 pref_list_string_set(PRINT_PREF_GROUP, PRINT_PREF_PRINTERC, pw->output_custom);
2552 if (pw->output == PRINT_OUTPUT_RGB_FILE ||
2553 pw->output == PRINT_OUTPUT_PS_FILE)
2555 tab_completion_append_to_history(pw->path_entry, pw->output_path);
2558 pref_list_int_set(PRINT_PREF_GROUP, PRINT_PREF_TEXT, pw->text_fields);
2559 pref_list_int_set(PRINT_PREF_GROUP, PRINT_PREF_TEXTSIZE, pw->text_points);
2560 pref_list_int_set(PRINT_PREF_GROUP, PRINT_PREF_TEXTCOLOR_R, pw->text_r);
2561 pref_list_int_set(PRINT_PREF_GROUP, PRINT_PREF_TEXTCOLOR_G, pw->text_g);
2562 pref_list_int_set(PRINT_PREF_GROUP, PRINT_PREF_TEXTCOLOR_B, pw->text_b);
2564 pref_list_int_set(PRINT_PREF_GROUP, PRINT_PREF_SOURCE, pw->source);
2565 pref_list_int_set(PRINT_PREF_GROUP, PRINT_PREF_LAYOUT, pw->layout);
2567 pref_list_double_set(PRINT_PREF_GROUP, PRINT_PREF_IMAGE_SCALE, pw->image_scale);
2570 static gboolean print_job_start(PrintWindow *pw, RenderFormat format, PrintOutput output)
2576 if (pw->job_dialog) return FALSE;
2578 pw->job_format = format;
2579 pw->job_output = output;
2581 if (!print_job_init(pw))
2583 print_job_close(pw, TRUE);
2587 if (format == RENDER_FORMAT_PREVIEW)
2589 print_job_render(pw);
2593 print_pref_store(pw);
2595 gtk_widget_hide(pw->dialog->dialog);
2597 pw->job_dialog = file_util_gen_dlg(_("Print"), "print_job_dialog",
2598 (GtkWidget *)gtk_window_get_transient_for(GTK_WINDOW(pw->dialog->dialog)), FALSE,
2599 print_job_cancel_cb, pw);
2601 msg = g_strdup_printf(_("Printing %d pages to %s."), print_layout_page_count(pw), print_output_name(pw->output));
2602 generic_dialog_add_message(pw->job_dialog, NULL, msg, NULL);
2605 if (pw->job_output == PRINT_OUTPUT_PS_FILE ||
2606 pw->job_output == PRINT_OUTPUT_RGB_FILE)
2608 hbox = pref_box_new(pw->job_dialog->vbox, FALSE, GTK_ORIENTATION_HORIZONTAL, PREF_PAD_SPACE);
2609 pref_label_new(hbox, _("Filename:"));
2611 pw->job_progress_label = pref_label_new(hbox, "");
2615 pw->job_progress_label = NULL;
2618 pref_spacer(pw->job_dialog->vbox, PREF_PAD_SPACE);
2620 hbox = pref_box_new(pw->job_dialog->vbox, FALSE, GTK_ORIENTATION_HORIZONTAL, PREF_PAD_SPACE);
2622 pw->job_progress = gtk_progress_bar_new();
2623 gtk_box_pack_start(GTK_BOX(hbox), pw->job_progress, TRUE, TRUE, 0);
2624 gtk_widget_show(pw->job_progress);
2626 spinner = spinner_new(NULL, SPINNER_SPEED);
2627 gtk_box_pack_start(GTK_BOX(hbox), spinner, FALSE, FALSE, 0);
2628 gtk_widget_show(spinner);
2630 gtk_widget_show(pw->job_dialog->dialog);
2632 print_job_render(pw);
2633 print_job_status(pw);
2638 static void print_window_print_start(PrintWindow *pw)
2640 RenderFormat format;
2644 case PRINT_OUTPUT_RGB_FILE:
2645 format = RENDER_FORMAT_RGB;
2647 case PRINT_OUTPUT_PS_FILE:
2648 case PRINT_OUTPUT_PS_CUSTOM:
2649 case PRINT_OUTPUT_PS_LPR:
2651 format = RENDER_FORMAT_PS;
2655 print_job_start(pw, format, pw->output);
2660 *-----------------------------------------------------------------------------
2662 *-----------------------------------------------------------------------------
2665 static GtkWidget *print_combo_menu(const gchar *text[], gint count, gint preferred,
2666 GCallback func, gpointer data)
2671 combo = gtk_combo_box_new_text();
2673 for (i = 0 ; i < count; i++)
2675 gtk_combo_box_append_text(GTK_COMBO_BOX(combo), _(text[i]));
2678 if (preferred >= 0 && preferred < count)
2680 gtk_combo_box_set_active(GTK_COMBO_BOX(combo), preferred);
2683 if (func) g_signal_connect(G_OBJECT(combo), "changed", func, data);
2690 *-----------------------------------------------------------------------------
2692 *-----------------------------------------------------------------------------
2695 static GtkWidget *print_paper_menu(GtkWidget *table, gint column, gint row,
2696 PaperOrientation preferred, GCallback func, gpointer data)
2701 pref_table_label(table, column, row, (_("Format:")), 1.0);
2703 combo = gtk_combo_box_new_text();
2706 while (print_paper_sizes[i].description)
2708 gtk_combo_box_append_text(GTK_COMBO_BOX(combo), _(print_paper_sizes[i].description));
2712 gtk_combo_box_set_active(GTK_COMBO_BOX(combo), preferred);
2713 if (func) g_signal_connect(G_OBJECT(combo), "changed", func, data);
2715 gtk_table_attach(GTK_TABLE(table), combo, column + 1, column + 2, row, row + 1,
2716 GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
2717 gtk_widget_show(combo);
2722 static void print_paper_select_cb(GtkWidget *combo, gpointer data)
2724 PrintWindow *pw = data;
2728 n = gtk_combo_box_get_active(GTK_COMBO_BOX(combo));
2729 ps = print_paper_size_nth(n);
2735 if (pw->paper_size == 0)
2737 print_window_layout_sync_paper(pw);
2741 if (ps->orientation == PAPER_ORIENTATION_PORTRAIT)
2743 print_window_layout_set_size(pw, ps->width, ps->height);
2747 print_window_layout_set_size(pw, ps->height, ps->width);
2751 static void print_paper_size_cb(GtkWidget *spin, gpointer data)
2753 PrintWindow *pw = data;
2756 value = print_paper_size_convert_units(gtk_spin_button_get_value(GTK_SPIN_BUTTON(spin)),
2757 pw->paper_units, PAPER_UNIT_POINTS);
2759 if (spin == pw->paper_width_spin)
2761 pw->paper_width = value;
2765 pw->paper_height = value;
2768 print_window_layout_set_size(pw, pw->paper_width, pw->paper_height);
2771 static GtkWidget *print_paper_units_menu(GtkWidget *table, gint column, gint row,
2772 PaperUnits units, GCallback func, gpointer data)
2776 pref_table_label(table, column, row, (_("Units:")), 1.0);
2778 combo = print_combo_menu(print_paper_units, PAPER_UNIT_COUNT, units, func, data);
2780 gtk_table_attach(GTK_TABLE(table), combo, column + 1, column + 2, row, row + 1,
2781 GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
2782 gtk_widget_show(combo);
2787 static void print_paper_units_set(PrintWindow *pw, PaperUnits units)
2789 PaperUnits old_units;
2791 if (units >= PAPER_UNIT_COUNT) return;
2793 old_units = pw->paper_units;
2794 pw->paper_units = units;
2795 print_window_layout_sync_paper(pw);
2797 if ((units == PAPER_UNIT_MM || units == PAPER_UNIT_CM) !=
2798 (old_units == PAPER_UNIT_MM || old_units == PAPER_UNIT_CM))
2800 print_window_layout_render(pw);
2804 static void print_paper_units_cb(GtkWidget *combo, gpointer data)
2806 PrintWindow *pw = data;
2809 units = gtk_combo_box_get_active(GTK_COMBO_BOX(combo));
2811 print_paper_units_set(pw, units);
2814 static GtkWidget *print_paper_orientation_menu(GtkWidget *table, gint column, gint row,
2815 PaperOrientation preferred,
2816 GCallback func, gpointer data)
2820 pref_table_label(table, column, row, (_("Orientation:")), 1.0);
2822 combo = print_combo_menu(print_paper_orientation, PAPER_ORIENTATION_COUNT, preferred, func, data);
2824 gtk_table_attach(GTK_TABLE(table), combo, column + 1, column + 2, row, row + 1,
2825 GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
2826 gtk_widget_show(combo);
2831 static void print_paper_orientation_cb(GtkWidget *combo, gpointer data)
2833 PrintWindow *pw = data;
2836 o = gtk_combo_box_get_active(GTK_COMBO_BOX(combo));
2838 print_window_layout_set_orientation(pw, o);
2841 static void print_paper_margin_cb(GtkWidget *spin, gpointer data)
2843 PrintWindow *pw = data;
2846 value = print_paper_size_convert_units(gtk_spin_button_get_value(GTK_SPIN_BUTTON(spin)),
2847 pw->paper_units, PAPER_UNIT_POINTS);
2849 if (spin == pw->margin_left_spin)
2851 pw->margin_left = CLAMP(value, 0.0, pw->paper_width);
2853 else if (spin == pw->margin_right_spin)
2855 pw->margin_right = CLAMP(value, 0.0, pw->paper_width);
2857 else if (spin == pw->margin_top_spin)
2859 pw->margin_top = CLAMP(value, 0.0, pw->paper_height);
2861 else if (spin == pw->margin_bottom_spin)
2863 pw->margin_bottom = CLAMP(value, 0.0, pw->paper_height);
2866 print_window_layout_set_size(pw, pw->paper_width, pw->paper_height);
2869 static GtkWidget *print_misc_menu(GtkWidget *parent_box, gint preferred,
2870 const gchar *title, const gchar *key,
2871 gint count, const gchar **text,
2872 GCallback func, gpointer data)
2875 GtkWidget *button = NULL;
2878 box = pref_group_new(parent_box, FALSE, title, GTK_ORIENTATION_VERTICAL);
2880 for (i = 0; i < count; i++)
2882 button = gtk_radio_button_new_with_label_from_widget(GTK_RADIO_BUTTON(button), _(text[i]));
2885 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), TRUE);
2887 g_object_set_data(G_OBJECT(button), key, GINT_TO_POINTER(i));
2888 if (func) g_signal_connect(G_OBJECT(button), "clicked", func, data);
2889 gtk_box_pack_start(GTK_BOX(box), button, FALSE, FALSE, 0);
2890 gtk_widget_show(button);
2896 static void print_source_select_cb(GtkWidget *widget, gpointer data)
2898 PrintWindow *pw = data;
2900 if (!gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget))) return;
2902 pw->source = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(widget), "print_source"));
2903 print_window_layout_size(pw);
2906 static void print_layout_select_cb(GtkWidget *widget, gpointer data)
2908 PrintWindow *pw = data;
2910 if (!gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget))) return;
2912 pw->layout = GPOINTER_TO_INT(g_object_get_data(G_OBJECT(widget), "print_layout"));
2914 print_window_layout_sync_layout(pw);
2915 print_window_layout_size(pw);
2918 static void print_image_scale_cb(GtkWidget *spin, gpointer data)
2920 PrintWindow *pw = data;
2922 pw->image_scale = gtk_spin_button_get_value(GTK_SPIN_BUTTON(spin));
2924 print_window_layout_set_size(pw, pw->paper_width, pw->paper_height);
2927 static void print_proof_size_cb(GtkWidget *spin, gpointer data)
2929 PrintWindow *pw = data;
2932 value = print_paper_size_convert_units(gtk_spin_button_get_value(GTK_SPIN_BUTTON(spin)),
2933 pw->paper_units, PAPER_UNIT_POINTS);
2935 if (spin == pw->proof_width_spin)
2937 pw->proof_width = value;
2941 pw->proof_height = value;
2944 print_window_layout_render(pw);
2947 static GtkWidget *print_output_menu(GtkWidget *table, gint column, gint row,
2948 PrintOutput preferred, GCallback func, gpointer data)
2952 pref_table_label(table, column, row, (_("Destination:")), 1.0);
2954 combo = print_combo_menu(print_output_text, PRINT_OUTPUT_COUNT, preferred, func, data);
2956 gtk_table_attach(GTK_TABLE(table), combo, column + 1, column + 2, row, row + 1,
2957 GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
2958 gtk_widget_show(combo);
2963 static void print_custom_entry_set(PrintWindow *pw, GtkWidget *combo)
2965 GtkListStore *store;
2970 store = GTK_LIST_STORE(gtk_combo_box_get_model(GTK_COMBO_BOX(combo)));
2971 gtk_list_store_clear(store);
2973 list = print_window_list_printers();
2983 buf = g_strdup_printf(PRINT_LPR_CUSTOM, name);
2984 gtk_combo_box_append_text(GTK_COMBO_BOX(combo), buf);
2987 string_list_free(list);
2989 if (pref_list_string_get(PRINT_PREF_GROUP, PRINT_PREF_PRINTERC, &text))
2991 gtk_entry_set_text(GTK_ENTRY(pw->custom_entry), text);
2995 text = gtk_entry_get_text(GTK_ENTRY(pw->custom_entry));
2996 if (!text || strlen(text) == 0)
3000 buf = g_strdup_printf(PRINT_LPR_CUSTOM, _("<printer name>"));
3001 gtk_entry_set_text(GTK_ENTRY(pw->custom_entry), buf);
3007 static void print_output_set(PrintWindow *pw, PrintOutput output)
3009 gboolean use_file = FALSE;
3010 gboolean use_custom = FALSE;
3011 gboolean use_format = FALSE;
3013 pw->output = output;
3017 case PRINT_OUTPUT_RGB_FILE:
3021 case PRINT_OUTPUT_PS_FILE:
3024 case PRINT_OUTPUT_PS_CUSTOM:
3027 case PRINT_OUTPUT_PS_LPR:
3032 gtk_widget_set_sensitive(gtk_widget_get_parent(pw->path_entry), use_file);
3033 gtk_widget_set_sensitive(gtk_widget_get_parent(pw->custom_entry), use_custom);
3034 gtk_widget_set_sensitive(pw->path_format_menu, use_format);
3035 gtk_widget_set_sensitive(pw->max_dpi_menu, !use_format);
3038 static void print_output_cb(GtkWidget *combo, gpointer data)
3040 PrintWindow *pw = data;
3043 output = gtk_combo_box_get_active(GTK_COMBO_BOX(combo));
3045 print_output_set(pw, output);
3048 static GtkWidget *print_output_format_menu(GtkWidget * table, gint column, gint row,
3049 PrintFileFormat preferred, GCallback func, gpointer data)
3053 combo = print_combo_menu(print_file_format_text, PRINT_FILE_COUNT, preferred, func, data);
3055 gtk_table_attach(GTK_TABLE(table), combo, column, column + 1, row, row + 1,
3056 GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
3057 gtk_widget_show(combo);
3062 static void print_output_format_cb(GtkWidget *combo, gpointer data)
3064 PrintWindow *pw = data;
3066 pw->output_format = gtk_combo_box_get_active(GTK_COMBO_BOX(combo));
3069 static GtkWidget *print_output_dpi_menu(GtkWidget * table, gint column, gint row,
3070 gdouble dpi, GCallback func, gpointer data)
3072 static gint dpilist[] = { 150, 300, 600, 1200, 0, -1};
3074 GtkListStore *store;
3075 GtkCellRenderer *renderer;
3079 store = gtk_list_store_new(2, G_TYPE_STRING, G_TYPE_INT);
3082 while (dpilist[i] != -1)
3087 if (dpilist[i] == 0)
3089 text = g_strdup(_("Unlimited"));
3093 text = g_strdup_printf("%d", dpilist[i]);
3096 gtk_list_store_append(store, &iter);
3097 gtk_list_store_set(store, &iter, 0, text, 1, dpilist[i], -1);
3100 if (dpi == (gdouble)dpilist[i]) current = i;
3105 combo = gtk_combo_box_new_with_model(GTK_TREE_MODEL(store));
3106 g_object_unref(store);
3108 gtk_combo_box_set_active(GTK_COMBO_BOX(combo), current);
3109 if (func) g_signal_connect(G_OBJECT(combo), "changed", func, data);
3111 renderer = gtk_cell_renderer_text_new();
3112 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(combo), renderer, TRUE);
3113 gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(combo), renderer, "text", 0, NULL);
3115 gtk_table_attach(GTK_TABLE(table), combo, column, column + 1, row, row + 1,
3116 GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
3117 gtk_widget_show(combo);
3122 static void print_output_dpi_cb(GtkWidget *combo, gpointer data)
3124 PrintWindow *pw = data;
3125 GtkTreeModel *store;
3129 store = gtk_combo_box_get_model(GTK_COMBO_BOX(combo));
3130 if (!gtk_combo_box_get_active_iter(GTK_COMBO_BOX(combo), &iter)) return;
3131 gtk_tree_model_get(store, &iter, 1, &n, -1);
3133 pw->max_dpi = (gdouble)n;
3136 static void print_text_field_set(PrintWindow *pw, TextInfo field, gboolean active)
3140 pw->text_fields |= field;
3144 pw->text_fields &= ~field;
3147 print_window_layout_render(pw);
3150 static void print_text_cb_name(GtkWidget *widget, gpointer data)
3152 PrintWindow *pw = data;
3155 active = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
3156 print_text_field_set(pw, TEXT_INFO_FILENAME, active);
3159 static void print_text_cb_path(GtkWidget *widget, gpointer data)
3161 PrintWindow *pw = data;
3164 active = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
3165 print_text_field_set(pw, TEXT_INFO_FILEPATH, active);
3168 static void print_text_cb_date(GtkWidget *widget, gpointer data)
3170 PrintWindow *pw = data;
3173 active = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
3174 print_text_field_set(pw, TEXT_INFO_FILEDATE, active);
3177 static void print_text_cb_size(GtkWidget *widget, gpointer data)
3179 PrintWindow *pw = data;
3182 active = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
3183 print_text_field_set(pw, TEXT_INFO_FILESIZE, active);
3186 static void print_text_cb_dims(GtkWidget *widget, gpointer data)
3188 PrintWindow *pw = data;
3191 active = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget));
3192 print_text_field_set(pw, TEXT_INFO_DIMENSIONS, active);
3195 static void print_text_cb_points(GtkWidget *widget, gpointer data)
3197 PrintWindow *pw = data;
3199 pw->text_points = gtk_spin_button_get_value_as_int(GTK_SPIN_BUTTON(widget));
3200 print_window_layout_render(pw);
3203 static void print_text_menu(GtkWidget *box, PrintWindow *pw)
3207 group = pref_group_new(box, FALSE, _("Show"), GTK_ORIENTATION_VERTICAL);
3209 pref_checkbox_new(group, _("Name"), (pw->text_fields & TEXT_INFO_FILENAME),
3210 G_CALLBACK(print_text_cb_name), pw);
3211 pref_checkbox_new(group, _("Path"), (pw->text_fields & TEXT_INFO_FILEPATH),
3212 G_CALLBACK(print_text_cb_path), pw);
3213 pref_checkbox_new(group, _("Date"), (pw->text_fields & TEXT_INFO_FILEDATE),
3214 G_CALLBACK(print_text_cb_date), pw);
3215 pref_checkbox_new(group, _("Size"), (pw->text_fields & TEXT_INFO_FILESIZE),
3216 G_CALLBACK(print_text_cb_size), pw);
3217 pref_checkbox_new(group, _("Dimensions"), (pw->text_fields & TEXT_INFO_DIMENSIONS),
3218 G_CALLBACK(print_text_cb_dims), pw);
3220 group = pref_group_new(box, FALSE, _("Font"), GTK_ORIENTATION_VERTICAL);
3222 pref_spin_new(group, _("Size:"), _("points"),
3223 8.0, 100.0, 1.0, 0, pw->text_points,
3224 G_CALLBACK(print_text_cb_points), pw);
3227 button = color_selection_new();
3228 gtk_box_pack_start(GTK_BOX(group), button, FALSE, FALSE, 0);
3229 gtk_widget_show(button);
3234 *-----------------------------------------------------------------------------
3236 *-----------------------------------------------------------------------------
3239 static void print_window_close(PrintWindow *pw)
3241 print_window_layout_render_stop(pw);
3243 generic_dialog_close(pw->dialog);
3246 print_job_close(pw, FALSE);
3248 file_data_unref(pw->source_fd);
3249 filelist_free(pw->source_selection);
3250 filelist_free(pw->source_list);
3252 g_free(pw->output_path);
3253 g_free(pw->output_custom);
3258 static void print_window_print_cb(GenericDialog *gd, gpointer data)
3260 PrintWindow *pw = data;
3264 case PRINT_OUTPUT_RGB_FILE:
3265 case PRINT_OUTPUT_PS_FILE:
3266 g_free(pw->output_path);
3267 pw->output_path = g_strdup(gtk_entry_get_text(GTK_ENTRY(pw->path_entry)));
3269 case PRINT_OUTPUT_PS_CUSTOM:
3270 g_free(pw->output_custom);
3271 pw->output_custom = g_strdup(gtk_entry_get_text(GTK_ENTRY(pw->custom_entry)));
3273 case PRINT_OUTPUT_PS_LPR:
3278 print_window_print_start(pw);
3281 static void print_window_cancel_cb(GenericDialog *gd, gpointer data)
3283 PrintWindow *pw = data;
3285 print_window_close(pw);
3288 static gint print_pref_int(const gchar *key, gint fallback)
3292 if (pref_list_int_get(PRINT_PREF_GROUP, key, &value)) return value;
3296 static gdouble print_pref_double(const gchar *key, gdouble fallback)
3300 if (pref_list_double_get(PRINT_PREF_GROUP, key, &value)) return value;
3304 void print_window_new(FileData *fd, GList *selection, GList *list, GtkWidget *parent)
3307 GdkGeometry geometry;
3308 GtkWidget *main_box;
3315 pw = g_new0(PrintWindow, 1);
3317 pw->source_fd = file_data_ref(fd);
3318 pw->source_selection = file_data_process_groups_in_selection(selection, FALSE, NULL);
3319 pw->source_list = list;
3321 pw->source = print_pref_int(PRINT_PREF_SOURCE, PRINT_SOURCE_SELECTION);
3322 pw->layout = print_pref_int(PRINT_PREF_LAYOUT, PRINT_LAYOUT_IMAGE);
3324 pw->image_scale = print_pref_double(PRINT_PREF_IMAGE_SCALE, 100.0);
3326 pw->output = print_pref_int(PRINT_PREF_OUTPUT, PRINT_OUTPUT_PS_LPR);
3327 pw->output_format = print_pref_int(PRINT_PREF_FORMAT, PRINT_FILE_JPG_NORMAL);
3329 pw->max_dpi = print_pref_double(PRINT_PREF_DPI, PRINT_PS_DPI_DEFAULT);
3331 pw->paper_units = print_pref_int(PRINT_PREF_UNITS, paper_unit_default());
3332 pw->paper_size = print_pref_int(PRINT_PREF_SIZE, 1);
3333 if (pw->paper_size == 0 ||
3334 !print_paper_size_lookup(pw->paper_size, &pw->paper_width, &pw->paper_height))
3336 pw->paper_width = print_pref_double(PRINT_PREF_CUSTOM_WIDTH, 360.0);
3337 pw->paper_height = print_pref_double(PRINT_PREF_CUSTOM_HEIGHT, 720.0);
3339 pw->paper_orientation = print_pref_int(PRINT_PREF_ORIENTATION, PAPER_ORIENTATION_PORTRAIT);
3341 pw->margin_left = print_pref_double(PRINT_PREF_MARGIN_LEFT, PRINT_MARGIN_DEFAULT);
3342 pw->margin_right = print_pref_double(PRINT_PREF_MARGIN_RIGHT, PRINT_MARGIN_DEFAULT);
3343 pw->margin_top = print_pref_double(PRINT_PREF_MARGIN_TOP, PRINT_MARGIN_DEFAULT);
3344 pw->margin_bottom = print_pref_double(PRINT_PREF_MARGIN_BOTTOM, PRINT_MARGIN_DEFAULT);
3346 pw->proof_width = print_pref_double(PRINT_PREF_PROOF_WIDTH, PRINT_PROOF_DEFAULT_SIZE);
3347 pw->proof_height = print_pref_double(PRINT_PREF_PROOF_HEIGHT, PRINT_PROOF_DEFAULT_SIZE);
3349 pw->text_fields = print_pref_int(PRINT_PREF_TEXT, TEXT_INFO_FILENAME);
3350 pw->text_points = print_pref_int(PRINT_PREF_TEXTSIZE, 10);
3351 pw->text_r = print_pref_int(PRINT_PREF_TEXTCOLOR_R, 0);
3352 pw->text_g = print_pref_int(PRINT_PREF_TEXTCOLOR_G, 0);
3353 pw->text_b = print_pref_int(PRINT_PREF_TEXTCOLOR_B, 0);
3355 pw->save_settings = print_pref_int(PRINT_PREF_SAVE, TRUE);
3357 pw->dialog = file_util_gen_dlg(_("Print"), "print_dialog",
3359 print_window_cancel_cb, pw);
3361 geometry.min_width = DEFAULT_MINIMAL_WINDOW_SIZE;
3362 geometry.min_height = DEFAULT_MINIMAL_WINDOW_SIZE;
3363 geometry.base_width = PRINT_DLG_WIDTH;
3364 geometry.base_height = PRINT_DLG_HEIGHT;
3365 gtk_window_set_geometry_hints(GTK_WINDOW(pw->dialog->dialog), NULL, &geometry,
3366 GDK_HINT_MIN_SIZE | GDK_HINT_BASE_SIZE);
3368 pw->print_button = generic_dialog_add_button(pw->dialog, GTK_STOCK_PRINT, NULL, print_window_print_cb, TRUE);
3370 main_box = pref_box_new(pw->dialog->vbox, TRUE, GTK_ORIENTATION_HORIZONTAL, PREF_PAD_GAP);
3372 pw->notebook = gtk_notebook_new();
3373 gtk_notebook_set_tab_pos(GTK_NOTEBOOK(pw->notebook), GTK_POS_TOP);
3374 gtk_box_pack_start(GTK_BOX(main_box), pw->notebook, FALSE, FALSE, 0);
3378 vbox = gtk_vbox_new(FALSE, 0);
3379 gtk_container_set_border_width(GTK_CONTAINER(vbox), PREF_PAD_BORDER);
3380 gtk_widget_show(vbox);
3381 label = gtk_label_new(_("Layout"));
3382 gtk_notebook_append_page(GTK_NOTEBOOK(pw->notebook), vbox, label);
3384 print_misc_menu(vbox, pw->source, _("Source"), "print_source",
3385 PRINT_SOURCE_COUNT, print_source_text,
3386 G_CALLBACK(print_source_select_cb), pw);
3388 box = print_misc_menu(vbox, pw->layout, _("Layout"), "print_layout",
3389 PRINT_LAYOUT_COUNT, print_layout_text,
3390 G_CALLBACK(print_layout_select_cb), pw);
3392 pref_spacer(box, PREF_PAD_GROUP);
3394 table = pref_table_new(box, 2, 2, FALSE, FALSE);
3396 pw->image_scale_spin = pref_table_spin(table, 0, 0, _("Image size:"), "%",
3397 5.0, 100.0, 1.0, 0, pw->image_scale,
3398 G_CALLBACK(print_image_scale_cb), pw);
3400 label = pref_table_label(table, 0, 1, _("Proof size:"), 1.0);
3401 pw->proof_group = pref_table_box(table, 1, 1, GTK_ORIENTATION_HORIZONTAL, NULL);
3402 pref_link_sensitivity(label, pw->proof_group);
3404 pw->proof_width_spin = pref_spin_new(pw->proof_group, NULL, NULL,
3405 0.0, 50.0, 0.1, 3, 0.0,
3406 G_CALLBACK(print_proof_size_cb), pw);
3407 pw->proof_height_spin = pref_spin_new(pw->proof_group, "x", NULL,
3408 0.0, 50.0, 0.1, 3, 0.0,
3409 G_CALLBACK(print_proof_size_cb), pw);
3413 vbox = gtk_vbox_new(FALSE, 0);
3414 gtk_container_set_border_width(GTK_CONTAINER(vbox), PREF_PAD_BORDER);
3415 gtk_widget_show(vbox);
3416 label = gtk_label_new(_("Text"));
3417 gtk_notebook_append_page(GTK_NOTEBOOK(pw->notebook), vbox, label);
3419 print_text_menu(vbox, pw);
3423 vbox = gtk_vbox_new(FALSE, 0);
3424 gtk_container_set_border_width(GTK_CONTAINER(vbox), PREF_PAD_BORDER);
3425 gtk_widget_show(vbox);
3426 label = gtk_label_new(_("Paper"));
3427 gtk_notebook_append_page(GTK_NOTEBOOK(pw->notebook), vbox, label);
3429 table = pref_table_new(vbox, 2, 4, FALSE, FALSE);
3431 print_paper_menu(table, 0, 0, pw->paper_size, G_CALLBACK(print_paper_select_cb), pw);
3433 label = pref_table_label(table, 0, 1, (_("Size:")), 1.0);
3434 box = pref_table_box(table, 1, 1, GTK_ORIENTATION_HORIZONTAL, NULL);
3435 pw->paper_width_spin = pref_spin_new(box, NULL, NULL,
3436 1.0, 10000.0, 1.0, 2, 66,
3437 G_CALLBACK(print_paper_size_cb), pw);
3438 pw->paper_height_spin = pref_spin_new(box, "x", NULL,
3439 1.0, 10000.0, 1.0, 2, 66,
3440 G_CALLBACK(print_paper_size_cb), pw);
3441 pref_link_sensitivity(label, pw->paper_width_spin);
3443 pw->paper_units_menu = print_paper_units_menu(table, 0, 2, pw->paper_units,
3444 G_CALLBACK(print_paper_units_cb), pw);
3446 print_paper_orientation_menu(table, 0, 3, pw->paper_orientation,
3447 G_CALLBACK(print_paper_orientation_cb), pw);
3449 box = pref_group_new(vbox, FALSE, _("Margins"), GTK_ORIENTATION_VERTICAL);
3450 table = pref_table_new(box, 4, 2, FALSE, FALSE);
3451 pw->margin_left_spin = pref_table_spin(table, 0, 0, _("Left:"), NULL,
3452 0.0, 50.0, 0.1, 3, 0.0,
3453 G_CALLBACK(print_paper_margin_cb), pw);
3454 pw->margin_right_spin = pref_table_spin(table, 2, 0, _("Right:"), NULL,
3455 0.0, 50.0, 0.1, 3, 0.0,
3456 G_CALLBACK(print_paper_margin_cb), pw);
3457 pw->margin_top_spin = pref_table_spin(table, 0, 1, _("Top:"), NULL,
3458 0.0, 50.0, 0.1, 3, 0.0,
3459 G_CALLBACK(print_paper_margin_cb), pw);
3460 pw->margin_bottom_spin = pref_table_spin(table, 2, 1, _("Bottom:"), NULL,
3461 0.0, 50.0, 0.1, 3, 0.0,
3462 G_CALLBACK(print_paper_margin_cb), pw);
3466 vbox = gtk_vbox_new(FALSE, 0);
3467 gtk_container_set_border_width(GTK_CONTAINER(vbox), PREF_PAD_BORDER);
3468 gtk_widget_show(vbox);
3469 label = gtk_label_new(_("Printer"));
3470 gtk_notebook_append_page(GTK_NOTEBOOK(pw->notebook), vbox, label);
3472 table = pref_table_new(vbox, 2, 5, FALSE, FALSE);
3473 print_output_menu(table, 0, 0, pw->output, G_CALLBACK(print_output_cb), pw);
3475 label = pref_table_label(table, 0, 1, _("Custom printer:"), 1.0);
3476 combo = history_combo_new(&pw->custom_entry, NULL, "print_custom", -1);
3477 print_custom_entry_set(pw, combo);
3478 gtk_table_attach(GTK_TABLE(table), combo, 1, 2, 1, 2,
3479 GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
3480 gtk_widget_show(combo);
3482 pref_link_sensitivity(label, combo);
3484 label = pref_table_label(table, 0, 2, _("File:"), 1.0);
3485 combo = tab_completion_new_with_history(&pw->path_entry, NULL, "print_path", -1, NULL, pw);
3486 tab_completion_add_select_button(pw->path_entry, NULL, FALSE);
3487 gtk_table_attach(GTK_TABLE(table), combo, 1, 2, 2, 3,
3488 GTK_EXPAND | GTK_FILL, GTK_EXPAND | GTK_FILL, 0, 0);
3489 gtk_widget_show(combo);
3491 pref_link_sensitivity(label, combo);
3493 label = pref_table_label(table, 0, 3, _("File format:"), 1.0);
3494 pw->path_format_menu = print_output_format_menu(table, 1, 3, pw->output_format,
3495 G_CALLBACK(print_output_format_cb), pw);
3496 pref_link_sensitivity(label, pw->path_format_menu);
3498 label = pref_table_label(table, 0, 4, _("DPI:"), 1.0);
3499 pw->max_dpi_menu = print_output_dpi_menu(table, 1, 4, pw->max_dpi,
3500 G_CALLBACK(print_output_dpi_cb), pw);
3501 pref_link_sensitivity(label, pw->max_dpi_menu);
3503 print_output_set(pw, pw->output);
3505 vbox = print_window_layout_setup(pw, main_box);
3506 pref_checkbox_new_int(vbox, _("Remember print settings"), pw->save_settings, &pw->save_settings);
3508 print_window_layout_sync_layout(pw);
3509 print_window_layout_sync_paper(pw);
3511 gtk_widget_show(pw->notebook);
3512 gtk_widget_show(pw->dialog->dialog);
3514 /* vim: set shiftwidth=8 softtabstop=0 cindent cinoptions={1s: */