1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
|
#define __SP_PRINT_C__
/** \file
* Frontend to printing
*/
/*
* Author:
* Lauris Kaplinski <lauris@kaplinski.com>
*
* This code is in public domain
*/
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif
#include "sp-item.h"
#include "extension/print.h"
#include "extension/system.h"
#include "print.h"
#ifdef HAVE_GTK_UNIX_PRINT
#include <gtk/gtk.h>
#include <glibmm/i18n.h>
#include <gtk/gtkprintunixdialog.h>
#endif
#if 0
# include <extension/internal/ps.h>
# ifdef WIN32
# include <extension/internal/win32.h>
# endif
# ifdef WITH_GNOME_PRINT
# include <extension/internal/gnome.h>
# endif
#endif
/* Identity typedef */
unsigned int sp_print_bind(SPPrintContext *ctx, NR::Matrix const &transform, float opacity)
{
NRMatrix const ntransform(transform);
return sp_print_bind(ctx, &ntransform, opacity);
}
unsigned int
sp_print_bind(SPPrintContext *ctx, NRMatrix const *transform, float opacity)
{
return ctx->module->bind(transform, opacity);
}
unsigned int
sp_print_release(SPPrintContext *ctx)
{
return ctx->module->release();
}
unsigned int
sp_print_comment(SPPrintContext *ctx, char const *comment)
{
return ctx->module->comment(comment);
}
unsigned int
sp_print_fill(SPPrintContext *ctx, NRBPath const *bpath, NRMatrix const *ctm, SPStyle const *style,
NRRect const *pbox, NRRect const *dbox, NRRect const *bbox)
{
return ctx->module->fill(bpath, ctm, style, pbox, dbox, bbox);
}
unsigned int
sp_print_stroke(SPPrintContext *ctx, NRBPath const *bpath, NRMatrix const *ctm, SPStyle const *style,
NRRect const *pbox, NRRect const *dbox, NRRect const *bbox)
{
return ctx->module->stroke(bpath, ctm, style, pbox, dbox, bbox);
}
unsigned int
sp_print_image_R8G8B8A8_N(SPPrintContext *ctx,
guchar *px, unsigned int w, unsigned int h, unsigned int rs,
NRMatrix const *transform, SPStyle const *style)
{
return ctx->module->image(px, w, h, rs, transform, style);
}
unsigned int sp_print_text(SPPrintContext *ctx, char const *text, NR::Point p,
SPStyle const *style)
{
return ctx->module->text(text, p, style);
}
#include "display/nr-arena.h"
#include "display/nr-arena-item.h"
/* UI */
void
sp_print_preview_document(SPDocument *doc)
{
Inkscape::Extension::Print *mod;
unsigned int ret;
sp_document_ensure_up_to_date(doc);
mod = Inkscape::Extension::get_print(SP_MODULE_KEY_PRINT_DEFAULT);
ret = mod->set_preview();
if (ret) {
SPPrintContext context;
context.module = mod;
/* fixme: This has to go into module constructor somehow */
/* Create new arena */
mod->base = SP_ITEM(sp_document_root(doc));
mod->arena = NRArena::create();
mod->dkey = sp_item_display_key_new(1);
mod->root = sp_item_invoke_show(mod->base, mod->arena, mod->dkey, SP_ITEM_SHOW_DISPLAY);
/* Print document */
ret = mod->begin(doc);
sp_item_invoke_print(mod->base, &context);
ret = mod->finish();
/* Release arena */
sp_item_invoke_hide(mod->base, mod->dkey);
mod->base = NULL;
nr_arena_item_unref(mod->root);
mod->root = NULL;
nr_object_unref((NRObject *) mod->arena);
mod->arena = NULL;
}
return;
}
#ifdef HAVE_GTK_UNIX_PRINT
static void
unix_print_complete (GtkPrintJob *print_job,
gpointer user_data,
GError *error)
{
fprintf(stderr,"print job finished: %s\n",error ? error->message : "no error");
}
static void
unix_print_dialog (const gchar * ps_file, const gchar * jobname)
{
Glib::ustring title = _("Print");
title += " ";
title += jobname;
GtkWidget* dlg = gtk_print_unix_dialog_new(title.c_str(), NULL);
// force output system to only handle our pre-generated PS output
gtk_print_unix_dialog_set_manual_capabilities (GTK_PRINT_UNIX_DIALOG(dlg),
GTK_PRINT_CAPABILITY_GENERATE_PS);
/*
* It would be nice to merge the PrintPS::setup routine with a custom
* configuration dialog:
gtk_print_unix_dialog_add_custom_tab (GtkPrintUnixDialog *dialog,
GtkWidget *child,
GtkWidget *tab_label);
*/
int const response = gtk_dialog_run(GTK_DIALOG(dlg));
if (response == GTK_RESPONSE_OK) {
GtkPrinter* printer = gtk_print_unix_dialog_get_selected_printer(GTK_PRINT_UNIX_DIALOG(dlg));
if (gtk_printer_accepts_ps (printer)) {
GtkPrintJob* job = gtk_print_job_new (jobname, printer,
gtk_print_unix_dialog_get_settings(GTK_PRINT_UNIX_DIALOG(dlg)),
gtk_print_unix_dialog_get_page_setup(GTK_PRINT_UNIX_DIALOG(dlg)));
GError * error = NULL;
if ( gtk_print_job_set_source_file (job, ps_file, &error)) {
gtk_print_job_send (job, unix_print_complete, NULL, NULL);
}
else {
g_warning(_("Could not set print source: %s"),error ? error->message : _("unknown error"));
}
if (error) g_error_free(error);
}
else {
g_warning(_("Printer '%s' does not support PS output"), gtk_printer_get_name (printer));
}
}
else if (response == GTK_RESPONSE_APPLY) {
// since we didn't include the Preview capability,
// this should never happen.
g_warning(_("Print Preview not available"));
}
gtk_widget_destroy(dlg);
}
#endif // HAVE_GTK_UNIX_PRINT
void
sp_print_document(SPDocument *doc, unsigned int direct)
{
Inkscape::Extension::Print *mod;
unsigned int ret;
#ifdef HAVE_GTK_UNIX_PRINT
Glib::ustring tmpfile = "";
#endif
sp_document_ensure_up_to_date(doc);
if (direct) {
mod = Inkscape::Extension::get_print(SP_MODULE_KEY_PRINT_PS);
} else {
mod = Inkscape::Extension::get_print(SP_MODULE_KEY_PRINT_DEFAULT);
#ifdef HAVE_GTK_UNIX_PRINT
// unix print dialog reads from the exported tempfile
gchar *filename = NULL;
GError *error = NULL;
gint tmpfd = g_file_open_tmp("inkscape-ps-XXXXXX",
&filename,
&error);
if (tmpfd<0) {
g_warning(_("Failed to create tempfile for printing: %s"),
error ? error->message : _("unknown error"));
if (error) g_error_free(error);
return;
}
tmpfile = filename;
g_free(filename);
close(tmpfd);
Glib::ustring destination = ">" + tmpfile;
mod->set_param_string("destination", destination.c_str());
#endif
}
ret = mod->setup();
if (ret) {
SPPrintContext context;
context.module = mod;
/* fixme: This has to go into module constructor somehow */
/* Create new arena */
mod->base = SP_ITEM(sp_document_root(doc));
mod->arena = NRArena::create();
mod->dkey = sp_item_display_key_new(1);
mod->root = sp_item_invoke_show(mod->base, mod->arena, mod->dkey, SP_ITEM_SHOW_DISPLAY);
/* Print document */
ret = mod->begin(doc);
sp_item_invoke_print(mod->base, &context);
ret = mod->finish();
/* Release arena */
sp_item_invoke_hide(mod->base, mod->dkey);
mod->base = NULL;
nr_arena_item_unref(mod->root);
mod->root = NULL;
nr_object_unref((NRObject *) mod->arena);
mod->arena = NULL;
#ifdef HAVE_GTK_UNIX_PRINT
// redirect output to new print dialog
unix_print_dialog(tmpfile.c_str(),doc->name ? doc->name : _("SVG Document"));
unlink(tmpfile.c_str());
// end redirected new print dialog
#endif
}
return;
}
void
sp_print_document_to_file(SPDocument *doc, gchar const *filename)
{
Inkscape::Extension::Print *mod;
SPPrintContext context;
gchar const *oldconst;
gchar *oldoutput;
unsigned int ret;
sp_document_ensure_up_to_date(doc);
mod = Inkscape::Extension::get_print(SP_MODULE_KEY_PRINT_PS);
oldconst = mod->get_param_string("destination");
oldoutput = g_strdup(oldconst);
mod->set_param_string("destination", (gchar *)filename);
/* Start */
context.module = mod;
/* fixme: This has to go into module constructor somehow */
/* Create new arena */
mod->base = SP_ITEM(sp_document_root(doc));
mod->arena = NRArena::create();
mod->dkey = sp_item_display_key_new(1);
mod->root = sp_item_invoke_show(mod->base, mod->arena, mod->dkey, SP_ITEM_SHOW_DISPLAY);
/* Print document */
ret = mod->begin(doc);
sp_item_invoke_print(mod->base, &context);
ret = mod->finish();
/* Release arena */
sp_item_invoke_hide(mod->base, mod->dkey);
mod->base = NULL;
nr_arena_item_unref(mod->root);
mod->root = NULL;
nr_object_unref((NRObject *) mod->arena);
mod->arena = NULL;
/* end */
mod->set_param_string("destination", oldoutput);
g_free(oldoutput);
return;
}
/*
Local Variables:
mode:c++
c-file-style:"stroustrup"
c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
indent-tabs-mode:nil
fill-column:99
End:
*/
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :
|