1 | /* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ |
---|
2 | /* |
---|
3 | * example_04.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 <libgnomeprint/gnome-print.h> |
---|
31 | #include <libgnomeprint/gnome-print-job.h> |
---|
32 | #include <libgnomeprintui/gnome-print-dialog.h> |
---|
33 | #include <gtk/gtkwidget.h> |
---|
34 | #include <gtk/gtkdialog.h> |
---|
35 | #include <gtk/gtkmain.h> |
---|
36 | #include <string.h> |
---|
37 | |
---|
38 | static void |
---|
39 | my_draw (GnomePrintContext *gpc) |
---|
40 | { |
---|
41 | GnomeFont *font; |
---|
42 | const guchar *font_name; |
---|
43 | /* Make some UTF-8 strings */ |
---|
44 | const guchar acented [] = {0xC3, 0xA0, 0xC3, 0xA8, 0xC3, 0xAC, |
---|
45 | 0xC3, 0xB2, 0xC3, 0xB9, 0x20, 0xC3, |
---|
46 | 0xB1, 0xC3, 0x91, 0x20, 0xC3, 0xBB, |
---|
47 | 0xC3, 0xB4, 0x20, 0x0A, 0x00}; |
---|
48 | const guchar cyrillic[] = {0xD0, 0xA1, 0xD0, 0xBE, 0xD0, 0xBC, 0xD0, 0xB5, |
---|
49 | 0x20, 0xD1, 0x80, 0xD0, 0xB0, 0xD0, 0xBD, |
---|
50 | 0xD0, 0xB4, 0xD0, 0xBE, 0xD0, 0xBC, 0x20, 0xD1, |
---|
51 | 0x86, 0xD1, 0x8B, 0xD1, 0x80, 0xD1, 0x83, |
---|
52 | 0xD0, 0xBB, 0xD0, 0xBB, 0xD0, 0xB8, 0xD1, 0x86, |
---|
53 | 0x20, 0xD1, 0x87, 0xD0, 0xB0, 0xD1, 0x80, |
---|
54 | 0xD1, 0x81, 0x00}; |
---|
55 | |
---|
56 | /* Get this font from: |
---|
57 | * http://bibliofile.mc.duke.edu/gww/fonts/Unicode.html |
---|
58 | * I used the TTF Caslon Roman. |
---|
59 | */ |
---|
60 | font = gnome_font_find_closest ("Caslon Roman", 12); |
---|
61 | font_name = gnome_font_get_name (font); |
---|
62 | g_print ("Found: %s\n", font_name); |
---|
63 | if (strcmp (font_name, "Caslon Roman") != 0) { |
---|
64 | g_print ("You might not see cyrillic characters because Caslon Roman was not found.\n"); |
---|
65 | } |
---|
66 | |
---|
67 | gnome_print_beginpage (gpc, "1"); |
---|
68 | |
---|
69 | gnome_print_setfont (gpc, font); |
---|
70 | |
---|
71 | gnome_print_moveto (gpc, 100, 700); |
---|
72 | gnome_print_show (gpc, "Some acented characters:"); |
---|
73 | gnome_print_moveto (gpc, 100, 680); |
---|
74 | gnome_print_show (gpc, acented); |
---|
75 | |
---|
76 | gnome_print_moveto (gpc, 100, 650); |
---|
77 | gnome_print_show (gpc, "Some cyrillic:"); |
---|
78 | gnome_print_moveto (gpc, 100, 630); |
---|
79 | gnome_print_show (gpc, cyrillic); |
---|
80 | |
---|
81 | gnome_print_showpage (gpc); |
---|
82 | |
---|
83 | g_object_unref (G_OBJECT (font)); |
---|
84 | } |
---|
85 | |
---|
86 | static void |
---|
87 | my_print (void) |
---|
88 | { |
---|
89 | GnomePrintJob *job; |
---|
90 | GnomePrintContext *gpc; |
---|
91 | |
---|
92 | job = gnome_print_job_new (NULL); |
---|
93 | gpc = gnome_print_job_get_context (job); |
---|
94 | |
---|
95 | my_draw (gpc); |
---|
96 | |
---|
97 | gnome_print_job_close (job); |
---|
98 | gnome_print_job_print (job); |
---|
99 | |
---|
100 | g_object_unref (G_OBJECT (gpc)); |
---|
101 | g_object_unref (G_OBJECT (job)); |
---|
102 | } |
---|
103 | |
---|
104 | int |
---|
105 | main (int argc, char * argv[]) |
---|
106 | { |
---|
107 | gtk_init (&argc, &argv); |
---|
108 | |
---|
109 | my_print (); |
---|
110 | |
---|
111 | g_print ("Done...\n"); |
---|
112 | |
---|
113 | return 0; |
---|
114 | } |
---|