Code

624021c9a38291c728448fb5c0ef5a210abb4801
[inkscape.git] / src / print.cpp
1 #define __SP_PRINT_C__
3 /** \file
4  * Frontend to printing
5  */
6 /*
7  * Author:
8  *   Lauris Kaplinski <lauris@kaplinski.com>
9  *
10  * This code is in public domain
11  */
13 #ifdef HAVE_CONFIG_H
14 # include "config.h"
15 #endif
19 #include "sp-item.h"
20 #include "extension/print.h"
21 #include "extension/system.h"
22 #include "print.h"
24 #if 0
25 # include <extension/internal/ps.h>
27 # ifdef WIN32
28 #  include <extension/internal/win32.h>
29 # endif
31 # ifdef WITH_GNOME_PRINT
32 #  include <extension/internal/gnome.h>
33 # endif
34 #endif
36 /* Identity typedef */
38 unsigned int sp_print_bind(SPPrintContext *ctx, NR::Matrix const &transform, float opacity)
39 {
40     NRMatrix const ntransform(transform);
41     return sp_print_bind(ctx, &ntransform, opacity);
42 }
44 unsigned int
45 sp_print_bind(SPPrintContext *ctx, NRMatrix const *transform, float opacity)
46 {
47     return ctx->module->bind(transform, opacity);
48 }
50 unsigned int
51 sp_print_release(SPPrintContext *ctx)
52 {
53     return ctx->module->release();
54 }
56 unsigned int
57 sp_print_comment(SPPrintContext *ctx, char const *comment)
58 {
59     return ctx->module->comment(comment);
60 }
62 unsigned int
63 sp_print_fill(SPPrintContext *ctx, NRBPath const *bpath, NRMatrix const *ctm, SPStyle const *style,
64               NRRect const *pbox, NRRect const *dbox, NRRect const *bbox)
65 {
66     return ctx->module->fill(bpath, ctm, style, pbox, dbox, bbox);
67 }
69 unsigned int
70 sp_print_stroke(SPPrintContext *ctx, NRBPath const *bpath, NRMatrix const *ctm, SPStyle const *style,
71                 NRRect const *pbox, NRRect const *dbox, NRRect const *bbox)
72 {
73     return ctx->module->stroke(bpath, ctm, style, pbox, dbox, bbox);
74 }
76 unsigned int
77 sp_print_image_R8G8B8A8_N(SPPrintContext *ctx,
78                           guchar *px, unsigned int w, unsigned int h, unsigned int rs,
79                           NRMatrix const *transform, SPStyle const *style)
80 {
81     return ctx->module->image(px, w, h, rs, transform, style);
82 }
84 unsigned int sp_print_text(SPPrintContext *ctx, char const *text, NR::Point p,
85                            SPStyle const *style)
86 {
87     return ctx->module->text(text, p, style);
88 }
90 #include "display/nr-arena.h"
91 #include "display/nr-arena-item.h"
93 /* UI */
95 void
96 sp_print_preview_document(SPDocument *doc)
97 {
98     Inkscape::Extension::Print *mod;
99     unsigned int ret;
101     sp_document_ensure_up_to_date(doc);
103     mod = Inkscape::Extension::get_print(SP_MODULE_KEY_PRINT_DEFAULT);
105     ret = mod->set_preview();
107     if (ret) {
108         SPPrintContext context;
109         context.module = mod;
111         /* fixme: This has to go into module constructor somehow */
112         /* Create new arena */
113         mod->base = SP_ITEM(sp_document_root(doc));
114         mod->arena = NRArena::create();
115         mod->dkey = sp_item_display_key_new(1);
116         mod->root = sp_item_invoke_show(mod->base, mod->arena, mod->dkey, SP_ITEM_SHOW_DISPLAY);
117         /* Print document */
118         ret = mod->begin(doc);
119         sp_item_invoke_print(mod->base, &context);
120         ret = mod->finish();
121         /* Release arena */
122         sp_item_invoke_hide(mod->base, mod->dkey);
123         mod->base = NULL;
124         nr_arena_item_unref(mod->root);
125         mod->root = NULL;
126         nr_object_unref((NRObject *) mod->arena);
127         mod->arena = NULL;
128     }
130     return;
133 void
134 sp_print_document(SPDocument *doc, unsigned int direct)
136     Inkscape::Extension::Print *mod;
137     unsigned int ret;
139     sp_document_ensure_up_to_date(doc);
141     if (direct) {
142         mod = Inkscape::Extension::get_print(SP_MODULE_KEY_PRINT_PS);
143     } else {
144         mod = Inkscape::Extension::get_print(SP_MODULE_KEY_PRINT_DEFAULT);
145     }
147     ret = mod->setup();
149     if (ret) {
150         SPPrintContext context;
151         context.module = mod;
153         /* fixme: This has to go into module constructor somehow */
154         /* Create new arena */
155         mod->base = SP_ITEM(sp_document_root(doc));
156         mod->arena = NRArena::create();
157         mod->dkey = sp_item_display_key_new(1);
158         mod->root = sp_item_invoke_show(mod->base, mod->arena, mod->dkey, SP_ITEM_SHOW_DISPLAY);
159         /* Print document */
160         ret = mod->begin(doc);
161         sp_item_invoke_print(mod->base, &context);
162         ret = mod->finish();
163         /* Release arena */
164         sp_item_invoke_hide(mod->base, mod->dkey);
165         mod->base = NULL;
166         nr_arena_item_unref(mod->root);
167         mod->root = NULL;
168         nr_object_unref((NRObject *) mod->arena);
169         mod->arena = NULL;
170     }
172     return;
175 void
176 sp_print_document_to_file(SPDocument *doc, gchar const *filename)
178     Inkscape::Extension::Print *mod;
179     SPPrintContext context;
180     gchar const *oldconst;
181     gchar *oldoutput;
182     unsigned int ret;
184     sp_document_ensure_up_to_date(doc);
186     mod = Inkscape::Extension::get_print(SP_MODULE_KEY_PRINT_PS);
187     oldconst = mod->get_param_string("destination");
188     oldoutput = g_strdup(oldconst);
189     mod->set_param_string("destination", (gchar *)filename);
191 /* Start */
192     context.module = mod;
193     /* fixme: This has to go into module constructor somehow */
194     /* Create new arena */
195     mod->base = SP_ITEM(sp_document_root(doc));
196     mod->arena = NRArena::create();
197     mod->dkey = sp_item_display_key_new(1);
198     mod->root = sp_item_invoke_show(mod->base, mod->arena, mod->dkey, SP_ITEM_SHOW_DISPLAY);
199     /* Print document */
200     ret = mod->begin(doc);
201     sp_item_invoke_print(mod->base, &context);
202     ret = mod->finish();
203     /* Release arena */
204     sp_item_invoke_hide(mod->base, mod->dkey);
205     mod->base = NULL;
206     nr_arena_item_unref(mod->root);
207     mod->root = NULL;
208     nr_object_unref((NRObject *) mod->arena);
209     mod->arena = NULL;
210 /* end */
212     mod->set_param_string("destination", oldoutput);
213     g_free(oldoutput);
215     return;
219 /*
220   Local Variables:
221   mode:c++
222   c-file-style:"stroustrup"
223   c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
224   indent-tabs-mode:nil
225   fill-column:99
226   End:
227 */
228 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :