[18603] | 1 | /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ |
---|
| 2 | /* |
---|
| 3 | * test-preview.c: Test the print preview |
---|
| 4 | * |
---|
| 5 | * This program is free software; you can redistribute it and/or |
---|
| 6 | * modify it under the terms of the GNU Library General Public License |
---|
| 7 | * as published by the Free Software Foundation; either version 2 of |
---|
| 8 | * the License, or (at your option) any later version. |
---|
| 9 | * |
---|
| 10 | * This program is distributed in the hope that it will be useful, |
---|
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
---|
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
---|
| 13 | * GNU Library General Public License for more details. |
---|
| 14 | * |
---|
| 15 | * You should have received a copy of the GNU Library General Public |
---|
| 16 | * License along with this program; if not, write to the Free Software |
---|
| 17 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
---|
| 18 | * |
---|
| 19 | * Authors: |
---|
| 20 | * Chema Celorio <chema@ximian.com> |
---|
| 21 | * |
---|
| 22 | * Copyright (C) 2002 Ximian Inc. and authors |
---|
| 23 | * |
---|
| 24 | */ |
---|
| 25 | |
---|
| 26 | #include <popt.h> |
---|
| 27 | #include <gtk/gtk.h> |
---|
| 28 | #include <libgnomeprint/gnome-print.h> |
---|
| 29 | #include <libgnomeprintui/gnome-print-job-preview.h> |
---|
| 30 | |
---|
| 31 | poptContext popt; |
---|
| 32 | gboolean option_timeout_kill; |
---|
| 33 | gboolean option_theme_colors; |
---|
| 34 | |
---|
| 35 | static struct poptOption options[] = { |
---|
| 36 | { "kill", '\0', POPT_ARG_NONE, &option_timeout_kill, 0, |
---|
| 37 | "Kill ourselves after 1 second timeout", NULL}, |
---|
| 38 | { "theme-colors", '\0', POPT_ARG_NONE, &option_theme_colors, 0, |
---|
| 39 | "Use only the theme colors", NULL}, |
---|
| 40 | POPT_AUTOHELP |
---|
| 41 | { NULL } |
---|
| 42 | }; |
---|
| 43 | |
---|
| 44 | static void |
---|
[20963] | 45 | my_draw (GnomePrintContext *pc, guint page) |
---|
[18603] | 46 | { |
---|
| 47 | gint i, j; |
---|
| 48 | gint max_i = 10; |
---|
| 49 | gint max_j = 10; |
---|
| 50 | gint size, spacing, x, y; |
---|
| 51 | GnomeFont *font; |
---|
[20963] | 52 | gchar *txt; |
---|
[18603] | 53 | |
---|
| 54 | gnome_print_beginpage (pc, "1"); |
---|
| 55 | |
---|
| 56 | font = gnome_font_find_closest ("Times New Roman", 44); |
---|
| 57 | gnome_print_setfont (pc, font); |
---|
| 58 | |
---|
| 59 | gnome_print_moveto (pc, 50, 50); |
---|
| 60 | gnome_print_show (pc, "Print Preview test"); |
---|
| 61 | |
---|
[20963] | 62 | txt = g_strdup_printf ("Page %i", page); |
---|
| 63 | gnome_print_moveto (pc, 50, 800); |
---|
| 64 | gnome_print_show (pc, txt); |
---|
| 65 | g_free (txt); |
---|
| 66 | |
---|
[18603] | 67 | gnome_print_moveto (pc, 50, 100); |
---|
| 68 | gnome_print_lineto (pc, 450, 100); |
---|
| 69 | gnome_print_lineto (pc, 450, 150); |
---|
| 70 | gnome_print_lineto (pc, 50, 150); |
---|
| 71 | gnome_print_closepath (pc); |
---|
| 72 | gnome_print_fill (pc); |
---|
| 73 | |
---|
| 74 | |
---|
| 75 | gnome_print_setrgbcolor (pc, 1, 1, 1); |
---|
| 76 | gnome_print_moveto (pc, 55, 105); |
---|
| 77 | gnome_print_show (pc, "Inverted text"); |
---|
| 78 | |
---|
| 79 | gnome_print_setrgbcolor (pc, 1, 0, 0); |
---|
| 80 | gnome_print_moveto (pc, 55, 160); |
---|
| 81 | gnome_print_show (pc, "Red"); |
---|
| 82 | |
---|
| 83 | gnome_print_setrgbcolor (pc, 0, 1, 0); |
---|
| 84 | gnome_print_moveto (pc, 155, 160); |
---|
| 85 | gnome_print_show (pc, "Green"); |
---|
| 86 | |
---|
| 87 | gnome_print_setrgbcolor (pc, 0, 0, 1); |
---|
| 88 | gnome_print_moveto (pc, 305, 160); |
---|
| 89 | gnome_print_show (pc, "Blue"); |
---|
| 90 | |
---|
| 91 | for (i = 0; i < max_i; i++) { |
---|
| 92 | for (j = 0; j < max_j; j++) { |
---|
| 93 | gdouble r; |
---|
| 94 | gdouble g; |
---|
| 95 | gdouble b; |
---|
| 96 | |
---|
| 97 | r = ((gdouble) i) / ((gdouble) max_i); |
---|
| 98 | g = ((gdouble) j) / ((gdouble) max_j); |
---|
| 99 | b = 1 - r; |
---|
| 100 | |
---|
| 101 | size = 15; |
---|
| 102 | spacing = size + 2; |
---|
| 103 | x = 100; |
---|
| 104 | y = 250; |
---|
| 105 | |
---|
| 106 | gnome_print_setrgbcolor (pc, r, g, b); |
---|
| 107 | gnome_print_moveto (pc, x + (i * spacing), y + (j * spacing)); |
---|
| 108 | gnome_print_lineto (pc, x + (i * spacing), y + (j * spacing) + size); |
---|
| 109 | gnome_print_lineto (pc, x + (i * spacing) + size, y + (j * spacing) + size); |
---|
| 110 | gnome_print_lineto (pc, x + (i * spacing) + size, y + (j * spacing)); |
---|
| 111 | gnome_print_closepath (pc); |
---|
| 112 | gnome_print_fill (pc); |
---|
| 113 | } |
---|
| 114 | } |
---|
| 115 | |
---|
| 116 | for (i = 0; i < max_i; i++) { |
---|
| 117 | for (j = 0; j < max_j; j++) { |
---|
| 118 | gdouble r; |
---|
| 119 | gdouble g; |
---|
| 120 | gdouble b; |
---|
| 121 | |
---|
| 122 | r = ((gdouble) i) / ((gdouble) max_i); |
---|
| 123 | g = ((gdouble) j) / ((gdouble) max_j); |
---|
| 124 | b = 1 - r; |
---|
| 125 | |
---|
| 126 | size = 15; |
---|
| 127 | spacing = size + 2; |
---|
| 128 | x = 300; |
---|
| 129 | y = y; |
---|
| 130 | |
---|
| 131 | gnome_print_setrgbcolor (pc, r, g, b); |
---|
| 132 | gnome_print_moveto (pc, x + (i * spacing), y + (j * spacing)); |
---|
| 133 | gnome_print_lineto (pc, x + (i * spacing), y + (j * spacing) + size); |
---|
| 134 | gnome_print_lineto (pc, x + (i * spacing) + size, y + (j * spacing) + size); |
---|
| 135 | gnome_print_lineto (pc, x + (i * spacing) + size, y + (j * spacing)); |
---|
| 136 | gnome_print_closepath (pc); |
---|
| 137 | gnome_print_stroke (pc); |
---|
| 138 | } |
---|
| 139 | } |
---|
| 140 | |
---|
| 141 | |
---|
| 142 | for (i = 0; i < max_i; i++) { |
---|
| 143 | for (j = 0; j < max_j; j++) { |
---|
| 144 | gdouble r; |
---|
| 145 | gdouble g; |
---|
| 146 | gdouble b; |
---|
| 147 | |
---|
| 148 | r = ((gdouble) i) / ((gdouble) max_i); |
---|
| 149 | g = r; |
---|
| 150 | b = r; |
---|
| 151 | |
---|
| 152 | size = 15; |
---|
| 153 | spacing = size + 2; |
---|
| 154 | x = 100; |
---|
| 155 | y = 450; |
---|
| 156 | |
---|
| 157 | gnome_print_setrgbcolor (pc, r, g, b); |
---|
| 158 | gnome_print_moveto (pc, x + (i * spacing), y + (j * spacing)); |
---|
| 159 | gnome_print_lineto (pc, x + (i * spacing), y + (j * spacing) + size); |
---|
| 160 | gnome_print_lineto (pc, x + (i * spacing) + size, y + (j * spacing) + size); |
---|
| 161 | gnome_print_lineto (pc, x + (i * spacing) + size, y + (j * spacing)); |
---|
| 162 | gnome_print_closepath (pc); |
---|
| 163 | gnome_print_stroke (pc); |
---|
| 164 | } |
---|
| 165 | } |
---|
| 166 | |
---|
| 167 | for (i = 0; i < max_i; i++) { |
---|
| 168 | for (j = 0; j < max_j; j++) { |
---|
| 169 | gdouble r; |
---|
| 170 | gdouble g; |
---|
| 171 | gdouble b; |
---|
| 172 | |
---|
| 173 | r = ((gdouble) i) / ((gdouble) max_i); |
---|
| 174 | g = r; |
---|
| 175 | b = r; |
---|
| 176 | |
---|
| 177 | size = 15; |
---|
| 178 | spacing = size + 2; |
---|
| 179 | x = 300; |
---|
| 180 | y = 450; |
---|
| 181 | |
---|
| 182 | gnome_print_setrgbcolor (pc, r, g, b); |
---|
| 183 | gnome_print_moveto (pc, x + (i * spacing), y + (j * spacing)); |
---|
| 184 | gnome_print_lineto (pc, x + (i * spacing), y + (j * spacing) + size); |
---|
| 185 | gnome_print_lineto (pc, x + (i * spacing) + size, y + (j * spacing) + size); |
---|
| 186 | gnome_print_lineto (pc, x + (i * spacing) + size, y + (j * spacing)); |
---|
| 187 | gnome_print_closepath (pc); |
---|
| 188 | gnome_print_fill (pc); |
---|
| 189 | } |
---|
| 190 | } |
---|
| 191 | |
---|
| 192 | |
---|
| 193 | gnome_print_showpage (pc); |
---|
| 194 | } |
---|
| 195 | |
---|
| 196 | static void |
---|
| 197 | my_print (void) |
---|
| 198 | { |
---|
| 199 | GnomePrintContext *gpc; |
---|
| 200 | GnomePrintJob *job; |
---|
| 201 | GtkWidget *preview; |
---|
[20963] | 202 | guint n; |
---|
[18603] | 203 | |
---|
| 204 | job = gnome_print_job_new (NULL); |
---|
| 205 | gpc = gnome_print_job_get_context (job); |
---|
| 206 | |
---|
[20963] | 207 | for (n = 0; n < 6; n++) my_draw (gpc, n + 1); |
---|
| 208 | |
---|
[18603] | 209 | gnome_print_job_close (job); |
---|
| 210 | |
---|
| 211 | preview = gnome_print_job_preview_new (job, "test-preview.c"); |
---|
| 212 | g_signal_connect (G_OBJECT (preview), "unrealize", |
---|
| 213 | G_CALLBACK (gtk_main_quit), NULL); |
---|
| 214 | |
---|
| 215 | gtk_widget_show (preview); |
---|
| 216 | |
---|
| 217 | } |
---|
| 218 | |
---|
| 219 | int |
---|
| 220 | main (int argc, char * argv[]) |
---|
| 221 | { |
---|
| 222 | popt = poptGetContext ("test-preview", argc, (const char **)argv, options, 0); |
---|
| 223 | poptGetNextOpt (popt); |
---|
| 224 | |
---|
| 225 | gtk_init (&argc, &argv); |
---|
| 226 | |
---|
| 227 | my_print (); |
---|
| 228 | |
---|
| 229 | if (option_timeout_kill) |
---|
| 230 | g_timeout_add (2000, (GSourceFunc) gtk_main_quit, NULL); |
---|
| 231 | |
---|
| 232 | gtk_main (); |
---|
| 233 | |
---|
| 234 | return 0; |
---|
| 235 | } |
---|