1 | /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ |
---|
2 | /* |
---|
3 | * example_05.c: sample gnome-print code |
---|
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 | /* |
---|
27 | * See README |
---|
28 | */ |
---|
29 | |
---|
30 | #include <string.h> |
---|
31 | #include <libgnomeprint/gnome-print.h> |
---|
32 | #include <libgnomeprint/gnome-print-job.h> |
---|
33 | #include <libgnomeprint/gnome-print-config.h> |
---|
34 | |
---|
35 | static void |
---|
36 | my_draw (GnomePrintContext *gpc) |
---|
37 | { |
---|
38 | gnome_print_beginpage (gpc, "1"); |
---|
39 | |
---|
40 | gnome_print_moveto (gpc, 100, 100); |
---|
41 | gnome_print_lineto (gpc, 200, 200); |
---|
42 | gnome_print_stroke (gpc); |
---|
43 | |
---|
44 | gnome_print_showpage (gpc); |
---|
45 | } |
---|
46 | |
---|
47 | static void |
---|
48 | my_set_names (GnomePrintJob *job) |
---|
49 | { |
---|
50 | GnomePrintConfig *config; |
---|
51 | gchar *printer; |
---|
52 | |
---|
53 | config = gnome_print_job_get_config (job); |
---|
54 | |
---|
55 | /* Set the printer */ |
---|
56 | gnome_print_config_set (config, "Printer", "GENERIC"); |
---|
57 | printer = gnome_print_config_get (config, "Printer"); |
---|
58 | if (strcmp (printer, "GENERIC") != 0) { |
---|
59 | g_warning ("Could not set printer to GENERIC Postscript"); |
---|
60 | return; |
---|
61 | } |
---|
62 | g_free (printer); |
---|
63 | |
---|
64 | gnome_print_job_print_to_file (job, "output_05.ps"); |
---|
65 | gnome_print_config_set (config, GNOME_PRINT_KEY_DOCUMENT_NAME, "Sample gnome-print document"); |
---|
66 | } |
---|
67 | |
---|
68 | static void |
---|
69 | my_dump_orientation (GnomePrintJob *job) |
---|
70 | { |
---|
71 | GnomePrintConfig *config; |
---|
72 | gchar *orientation; |
---|
73 | |
---|
74 | config = gnome_print_job_get_config (job); |
---|
75 | |
---|
76 | orientation = gnome_print_config_get (config, GNOME_PRINT_KEY_ORIENTATION); |
---|
77 | g_print ("Orientation is: %s\n", orientation); |
---|
78 | if (orientation) |
---|
79 | g_free (orientation); |
---|
80 | } |
---|
81 | |
---|
82 | static void |
---|
83 | my_print (void) |
---|
84 | { |
---|
85 | GnomePrintJob *job; |
---|
86 | GnomePrintContext *gpc; |
---|
87 | |
---|
88 | job = gnome_print_job_new (NULL); |
---|
89 | gpc = gnome_print_job_get_context (job); |
---|
90 | |
---|
91 | my_set_names (job); |
---|
92 | my_dump_orientation (job); |
---|
93 | |
---|
94 | my_draw (gpc); |
---|
95 | |
---|
96 | gnome_print_job_close (job); |
---|
97 | gnome_print_job_print (job); |
---|
98 | |
---|
99 | g_object_unref (G_OBJECT (gpc)); |
---|
100 | g_object_unref (G_OBJECT (job)); |
---|
101 | } |
---|
102 | |
---|
103 | int |
---|
104 | main (int argc, char * argv[]) |
---|
105 | { |
---|
106 | g_type_init (); |
---|
107 | |
---|
108 | my_print (); |
---|
109 | |
---|
110 | g_print ("Done...\n"); |
---|
111 | |
---|
112 | return 0; |
---|
113 | } |
---|