source: trunk/third/libgnomeprintui/examples/example_11.c @ 20964

Revision 20964, 2.8 KB checked in by ghudson, 20 years ago (diff)
This commit was generated by cvs2svn to compensate for changes in r20963, which included commits to RCS files with non-trunk default branches.
RevLine 
[20963]1/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
2/*
3 *  example_11.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 *    Chris Lahey <clahey@ximian.com>
22 *
23 *  Copyright (C) 2002, 2003 Ximian Inc. and authors
24 *
25 */
26
27/*
28 * See README
29 */
30
31#define GNOME_PRINT_UNSTABLE_API
32
33#define TEMP_FILE "temp.ps"
34
35#include <stdio.h>
36#include <string.h>
37#include <libgnomeprint/gnome-print.h>
38#include <libgnomeprint/gnome-print-job.h>
39#include <libgnomeprintui/gnome-print-job-preview.h>
40#include <libgnomeprintui/gnome-print-dialog.h>
41
42char *format = "%! PS-Adobe-3.0 \n"
43"1 setlinewidth\n"
44"newpath\n"
45"100 100 moveto\n"
46"600 600 lineto\n"
47"stroke\n"
48"/Helvetica findfont\n"
49"24 scalefont setfont\n"
50"100 230 moveto\n"
51"(My page size is %fx%f) show\n"
52"showpage";
53
54static void
55my_print (GnomePrintJob *job, gboolean preview)
56{
57        FILE *file;
58        char *output, *str;
59        int bytes;
60        double width, height;
61        GnomePrintConfig *config;
62
63        file = fopen (TEMP_FILE, "w");
64        g_assert (file);
65
66        config = gnome_print_job_get_config(job);
67        gnome_print_config_get_page_size (config, &width, &height);
68
69        output = g_strdup_printf (format, width, height);
70        str = output;
71
72        bytes = strlen (str);
73        str += bytes;
74        while (bytes > 0)
75                bytes -=  fwrite (str - bytes, sizeof (gchar), bytes < 1024 ? bytes : 1024, file);
76        fclose (file);
77        g_free (output);
78
79        gnome_print_job_set_file (job, TEMP_FILE);
80
81        if (!preview) {
82                gnome_print_job_print (job);
83        } else {
84                gtk_widget_show (gnome_print_job_preview_new (job, "Title goes here"));
85        }
86
87        g_object_unref (G_OBJECT (job));
88}
89
90int
91main (int argc, char * argv[])
92{
93        GnomePrintJob *job;
94        GtkWidget *dialog;
95        gint response;
96
97        gtk_init (&argc, &argv);
98
99        job    = gnome_print_job_new (NULL);
100        dialog = gnome_print_dialog_new (job, "Sample print dialog", 0);
101
102        /* Run the dialog */
103        response = gtk_dialog_run (GTK_DIALOG (dialog));
104        gtk_widget_destroy (dialog);
105        switch (response) {
106        case GNOME_PRINT_DIALOG_RESPONSE_PRINT:
107                my_print (job, FALSE);
108                break;
109        case GNOME_PRINT_DIALOG_RESPONSE_PREVIEW:
110                my_print (job, TRUE);
111                break;
112        }
113        return 0;
114}
Note: See TracBrowser for help on using the repository browser.