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 |
---|
45 | my_draw (GnomePrintContext *pc) |
---|
46 | { |
---|
47 | gint i, j; |
---|
48 | gint max_i = 10; |
---|
49 | gint max_j = 10; |
---|
50 | gint size, spacing, x, y; |
---|
51 | GnomeFont *font; |
---|
52 | |
---|
53 | gnome_print_beginpage (pc, "1"); |
---|
54 | |
---|
55 | font = gnome_font_find_closest ("Times New Roman", 44); |
---|
56 | gnome_print_setfont (pc, font); |
---|
57 | |
---|
58 | gnome_print_moveto (pc, 50, 50); |
---|
59 | gnome_print_show (pc, "Print Preview test"); |
---|
60 | |
---|
61 | gnome_print_moveto (pc, 50, 100); |
---|
62 | gnome_print_lineto (pc, 450, 100); |
---|
63 | gnome_print_lineto (pc, 450, 150); |
---|
64 | gnome_print_lineto (pc, 50, 150); |
---|
65 | gnome_print_closepath (pc); |
---|
66 | gnome_print_fill (pc); |
---|
67 | |
---|
68 | |
---|
69 | gnome_print_setrgbcolor (pc, 1, 1, 1); |
---|
70 | gnome_print_moveto (pc, 55, 105); |
---|
71 | gnome_print_show (pc, "Inverted text"); |
---|
72 | |
---|
73 | gnome_print_setrgbcolor (pc, 1, 0, 0); |
---|
74 | gnome_print_moveto (pc, 55, 160); |
---|
75 | gnome_print_show (pc, "Red"); |
---|
76 | |
---|
77 | gnome_print_setrgbcolor (pc, 0, 1, 0); |
---|
78 | gnome_print_moveto (pc, 155, 160); |
---|
79 | gnome_print_show (pc, "Green"); |
---|
80 | |
---|
81 | gnome_print_setrgbcolor (pc, 0, 0, 1); |
---|
82 | gnome_print_moveto (pc, 305, 160); |
---|
83 | gnome_print_show (pc, "Blue"); |
---|
84 | |
---|
85 | for (i = 0; i < max_i; i++) { |
---|
86 | for (j = 0; j < max_j; j++) { |
---|
87 | gdouble r; |
---|
88 | gdouble g; |
---|
89 | gdouble b; |
---|
90 | |
---|
91 | r = ((gdouble) i) / ((gdouble) max_i); |
---|
92 | g = ((gdouble) j) / ((gdouble) max_j); |
---|
93 | b = 1 - r; |
---|
94 | |
---|
95 | size = 15; |
---|
96 | spacing = size + 2; |
---|
97 | x = 100; |
---|
98 | y = 250; |
---|
99 | |
---|
100 | gnome_print_setrgbcolor (pc, r, g, b); |
---|
101 | gnome_print_moveto (pc, x + (i * spacing), y + (j * spacing)); |
---|
102 | gnome_print_lineto (pc, x + (i * spacing), y + (j * spacing) + size); |
---|
103 | gnome_print_lineto (pc, x + (i * spacing) + size, y + (j * spacing) + size); |
---|
104 | gnome_print_lineto (pc, x + (i * spacing) + size, y + (j * spacing)); |
---|
105 | gnome_print_closepath (pc); |
---|
106 | gnome_print_fill (pc); |
---|
107 | } |
---|
108 | } |
---|
109 | |
---|
110 | for (i = 0; i < max_i; i++) { |
---|
111 | for (j = 0; j < max_j; j++) { |
---|
112 | gdouble r; |
---|
113 | gdouble g; |
---|
114 | gdouble b; |
---|
115 | |
---|
116 | r = ((gdouble) i) / ((gdouble) max_i); |
---|
117 | g = ((gdouble) j) / ((gdouble) max_j); |
---|
118 | b = 1 - r; |
---|
119 | |
---|
120 | size = 15; |
---|
121 | spacing = size + 2; |
---|
122 | x = 300; |
---|
123 | y = y; |
---|
124 | |
---|
125 | gnome_print_setrgbcolor (pc, r, g, b); |
---|
126 | gnome_print_moveto (pc, x + (i * spacing), y + (j * spacing)); |
---|
127 | gnome_print_lineto (pc, x + (i * spacing), y + (j * spacing) + size); |
---|
128 | gnome_print_lineto (pc, x + (i * spacing) + size, y + (j * spacing) + size); |
---|
129 | gnome_print_lineto (pc, x + (i * spacing) + size, y + (j * spacing)); |
---|
130 | gnome_print_closepath (pc); |
---|
131 | gnome_print_stroke (pc); |
---|
132 | } |
---|
133 | } |
---|
134 | |
---|
135 | |
---|
136 | for (i = 0; i < max_i; i++) { |
---|
137 | for (j = 0; j < max_j; j++) { |
---|
138 | gdouble r; |
---|
139 | gdouble g; |
---|
140 | gdouble b; |
---|
141 | |
---|
142 | r = ((gdouble) i) / ((gdouble) max_i); |
---|
143 | g = r; |
---|
144 | b = r; |
---|
145 | |
---|
146 | size = 15; |
---|
147 | spacing = size + 2; |
---|
148 | x = 100; |
---|
149 | y = 450; |
---|
150 | |
---|
151 | gnome_print_setrgbcolor (pc, r, g, b); |
---|
152 | gnome_print_moveto (pc, x + (i * spacing), y + (j * spacing)); |
---|
153 | gnome_print_lineto (pc, x + (i * spacing), y + (j * spacing) + size); |
---|
154 | gnome_print_lineto (pc, x + (i * spacing) + size, y + (j * spacing) + size); |
---|
155 | gnome_print_lineto (pc, x + (i * spacing) + size, y + (j * spacing)); |
---|
156 | gnome_print_closepath (pc); |
---|
157 | gnome_print_stroke (pc); |
---|
158 | } |
---|
159 | } |
---|
160 | |
---|
161 | for (i = 0; i < max_i; i++) { |
---|
162 | for (j = 0; j < max_j; j++) { |
---|
163 | gdouble r; |
---|
164 | gdouble g; |
---|
165 | gdouble b; |
---|
166 | |
---|
167 | r = ((gdouble) i) / ((gdouble) max_i); |
---|
168 | g = r; |
---|
169 | b = r; |
---|
170 | |
---|
171 | size = 15; |
---|
172 | spacing = size + 2; |
---|
173 | x = 300; |
---|
174 | y = 450; |
---|
175 | |
---|
176 | gnome_print_setrgbcolor (pc, r, g, b); |
---|
177 | gnome_print_moveto (pc, x + (i * spacing), y + (j * spacing)); |
---|
178 | gnome_print_lineto (pc, x + (i * spacing), y + (j * spacing) + size); |
---|
179 | gnome_print_lineto (pc, x + (i * spacing) + size, y + (j * spacing) + size); |
---|
180 | gnome_print_lineto (pc, x + (i * spacing) + size, y + (j * spacing)); |
---|
181 | gnome_print_closepath (pc); |
---|
182 | gnome_print_fill (pc); |
---|
183 | } |
---|
184 | } |
---|
185 | |
---|
186 | |
---|
187 | gnome_print_showpage (pc); |
---|
188 | } |
---|
189 | |
---|
190 | static void |
---|
191 | my_print (void) |
---|
192 | { |
---|
193 | GnomePrintContext *gpc; |
---|
194 | GnomePrintJob *job; |
---|
195 | GtkWidget *preview; |
---|
196 | |
---|
197 | job = gnome_print_job_new (NULL); |
---|
198 | gpc = gnome_print_job_get_context (job); |
---|
199 | |
---|
200 | my_draw (gpc); |
---|
201 | |
---|
202 | gnome_print_job_close (job); |
---|
203 | |
---|
204 | preview = gnome_print_job_preview_new (job, "test-preview.c"); |
---|
205 | g_signal_connect (G_OBJECT (preview), "unrealize", |
---|
206 | G_CALLBACK (gtk_main_quit), NULL); |
---|
207 | |
---|
208 | gtk_widget_show (preview); |
---|
209 | |
---|
210 | } |
---|
211 | |
---|
212 | int |
---|
213 | main (int argc, char * argv[]) |
---|
214 | { |
---|
215 | popt = poptGetContext ("test-preview", argc, (const char **)argv, options, 0); |
---|
216 | poptGetNextOpt (popt); |
---|
217 | |
---|
218 | gtk_init (&argc, &argv); |
---|
219 | |
---|
220 | my_print (); |
---|
221 | |
---|
222 | if (option_timeout_kill) |
---|
223 | g_timeout_add (2000, (GSourceFunc) gtk_main_quit, NULL); |
---|
224 | |
---|
225 | gtk_main (); |
---|
226 | |
---|
227 | return 0; |
---|
228 | } |
---|