~danieljabailey/inkscape/arc_node_editor

« back to all changes in this revision

Viewing changes to src/print.cpp

  • Committer: scislac
  • Date: 2009-08-12 07:57:52 UTC
  • Revision ID: scislac@users.sourceforge.net-20090812075752-3zt99jgeqr3bm16j
much better quality multi-size windows icon, thanks ChrisMorgan

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#define __SP_PRINT_C__
 
2
 
1
3
/** \file
2
4
 * Frontend to printing
3
5
 */
5
7
 * Author:
6
8
 *   Lauris Kaplinski <lauris@kaplinski.com>
7
9
 *   Kees Cook <kees@outflux.net>
8
 
 *   Jon A. Cruz <jon@joncruz.org>
9
 
 *   Abhishek Sharma
10
10
 *
11
11
 * This code is in public domain
12
12
 */
15
15
# include "config.h"
16
16
#endif
17
17
 
18
 
#include "ui/dialog/print.h"
19
 
#include "print.h"
20
 
#include "display/drawing.h"
21
 
#include "display/drawing-item.h"
22
18
#include "inkscape.h"
23
19
#include "desktop.h"
24
 
#include "document.h"
25
20
#include "sp-item.h"
26
21
#include "extension/print.h"
27
22
#include "extension/system.h"
28
 
#include "sp-root.h"
29
 
 
 
23
#include "print.h"
 
24
 
 
25
#include "ui/dialog/print.h"
 
26
 
 
27
 
 
28
/* Identity typedef */
 
29
 
 
30
unsigned int sp_print_bind(SPPrintContext *ctx, Geom::Matrix const &transform, float opacity)
 
31
{
 
32
    Geom::Matrix const ntransform(transform);
 
33
    return sp_print_bind(ctx, &ntransform, opacity);
 
34
}
30
35
 
31
36
unsigned int
32
 
sp_print_bind(SPPrintContext *ctx, Geom::Affine const &transform, float opacity)
 
37
sp_print_bind(SPPrintContext *ctx, Geom::Matrix const *transform, float opacity)
33
38
{
34
39
    return ctx->module->bind(transform, opacity);
35
40
}
47
52
}
48
53
 
49
54
unsigned int
50
 
sp_print_fill(SPPrintContext *ctx, Geom::PathVector const &pathv, Geom::Affine const &ctm, SPStyle const *style,
51
 
              Geom::OptRect const &pbox, Geom::OptRect const &dbox, Geom::OptRect const &bbox)
 
55
sp_print_fill(SPPrintContext *ctx, Geom::PathVector const &pathv, Geom::Matrix const *ctm, SPStyle const *style,
 
56
              NRRect const *pbox, NRRect const *dbox, NRRect const *bbox)
52
57
{
53
58
    return ctx->module->fill(pathv, ctm, style, pbox, dbox, bbox);
54
59
}
55
60
 
56
61
unsigned int
57
 
sp_print_stroke(SPPrintContext *ctx, Geom::PathVector const &pathv, Geom::Affine const &ctm, SPStyle const *style,
58
 
                Geom::OptRect const &pbox, Geom::OptRect const &dbox, Geom::OptRect const &bbox)
 
62
sp_print_stroke(SPPrintContext *ctx, Geom::PathVector const &pathv, Geom::Matrix const *ctm, SPStyle const *style,
 
63
                NRRect const *pbox, NRRect const *dbox, NRRect const *bbox)
59
64
{
60
65
    return ctx->module->stroke(pathv, ctm, style, pbox, dbox, bbox);
61
66
}
63
68
unsigned int
64
69
sp_print_image_R8G8B8A8_N(SPPrintContext *ctx,
65
70
                          guchar *px, unsigned int w, unsigned int h, unsigned int rs,
66
 
                          Geom::Affine const &transform, SPStyle const *style)
 
71
                          Geom::Matrix const *transform, SPStyle const *style)
67
72
{
68
73
    return ctx->module->image(px, w, h, rs, transform, style);
69
74
}
74
79
    return ctx->module->text(text, p, style);
75
80
}
76
81
 
 
82
#include "display/nr-arena.h"
 
83
#include "display/nr-arena-item.h"
 
84
 
77
85
/* UI */
78
86
 
79
87
void
 
88
sp_print_preview_document(SPDocument *doc)
 
89
{
 
90
    Inkscape::Extension::Print *mod;
 
91
    unsigned int ret;
 
92
 
 
93
    sp_document_ensure_up_to_date(doc);
 
94
 
 
95
    mod = Inkscape::Extension::get_print(SP_MODULE_KEY_PRINT_DEFAULT);
 
96
 
 
97
    ret = mod->set_preview();
 
98
 
 
99
    if (ret) {
 
100
        SPPrintContext context;
 
101
        context.module = mod;
 
102
 
 
103
        /* fixme: This has to go into module constructor somehow */
 
104
        /* Create new arena */
 
105
        mod->base = SP_ITEM(sp_document_root(doc));
 
106
        mod->arena = NRArena::create();
 
107
        mod->dkey = sp_item_display_key_new(1);
 
108
        mod->root = sp_item_invoke_show(mod->base, mod->arena, mod->dkey, SP_ITEM_SHOW_DISPLAY);
 
109
        /* Print document */
 
110
        ret = mod->begin(doc);
 
111
        sp_item_invoke_print(mod->base, &context);
 
112
        ret = mod->finish();
 
113
        /* Release arena */
 
114
        sp_item_invoke_hide(mod->base, mod->dkey);
 
115
        mod->base = NULL;
 
116
        mod->root = NULL;
 
117
        nr_object_unref((NRObject *) mod->arena);
 
118
        mod->arena = NULL;
 
119
    }
 
120
 
 
121
    return;
 
122
}
 
123
 
 
124
void
80
125
sp_print_document(Gtk::Window& parentWindow, SPDocument *doc)
81
126
{
82
 
    doc->ensureUpToDate();
 
127
    sp_document_ensure_up_to_date(doc);
83
128
 
84
129
    // Build arena
85
 
    SPItem      *base = doc->getRoot();
 
130
    SPItem      *base = SP_ITEM(sp_document_root(doc));
 
131
    NRArena    *arena = NRArena::create();
 
132
    unsigned int dkey = sp_item_display_key_new(1);
 
133
    NRArenaItem *root = sp_item_invoke_show(base, arena, dkey, SP_ITEM_SHOW_DISPLAY);
86
134
 
87
135
    // Run print dialog
88
136
    Inkscape::UI::Dialog::Print printop(doc,base);
89
137
    Gtk::PrintOperationResult res = printop.run(Gtk::PRINT_OPERATION_ACTION_PRINT_DIALOG, parentWindow);
90
138
    (void)res; // TODO handle this
 
139
 
 
140
    // Release arena
 
141
    sp_item_invoke_hide(base, dkey);
 
142
    nr_object_unref((NRObject *) arena);
91
143
}
92
144
 
93
 
void sp_print_document_to_file(SPDocument *doc, gchar const *filename)
 
145
void
 
146
sp_print_document_to_file(SPDocument *doc, gchar const *filename)
94
147
{
95
 
    doc->ensureUpToDate();
96
 
 
97
 
    Inkscape::Extension::Print *mod = Inkscape::Extension::get_print(SP_MODULE_KEY_PRINT_PS);
 
148
    Inkscape::Extension::Print *mod;
98
149
    SPPrintContext context;
99
 
    gchar const *oldconst = mod->get_param_string("destination");
100
 
    gchar *oldoutput = g_strdup(oldconst);
101
 
 
 
150
    gchar const *oldconst;
 
151
    gchar *oldoutput;
 
152
    unsigned int ret;
 
153
 
 
154
    sp_document_ensure_up_to_date(doc);
 
155
 
 
156
    mod = Inkscape::Extension::get_print(SP_MODULE_KEY_PRINT_PS);
 
157
    oldconst = mod->get_param_string("destination");
 
158
    oldoutput = g_strdup(oldconst);
102
159
    mod->set_param_string("destination", (gchar *)filename);
103
160
 
104
161
/* Start */
105
162
    context.module = mod;
106
163
    /* fixme: This has to go into module constructor somehow */
107
 
    /* Create new drawing */
108
 
    mod->base = doc->getRoot();
109
 
    Inkscape::Drawing drawing;
110
 
    mod->dkey = SPItem::display_key_new(1);
111
 
    mod->root = (mod->base)->invoke_show(drawing, mod->dkey, SP_ITEM_SHOW_DISPLAY);
112
 
    drawing.setRoot(mod->root);
 
164
    /* Create new arena */
 
165
    mod->base = SP_ITEM(sp_document_root(doc));
 
166
    mod->arena = NRArena::create();
 
167
    mod->dkey = sp_item_display_key_new(1);
 
168
    mod->root = sp_item_invoke_show(mod->base, mod->arena, mod->dkey, SP_ITEM_SHOW_DISPLAY);
113
169
    /* Print document */
114
 
    mod->begin(doc);
115
 
    (mod->base)->invoke_print(&context);
116
 
    mod->finish();
117
 
    /* Release drawing items */
118
 
    (mod->base)->invoke_hide(mod->dkey);
 
170
    ret = mod->begin(doc);
 
171
    sp_item_invoke_print(mod->base, &context);
 
172
    ret = mod->finish();
 
173
    /* Release arena */
 
174
    sp_item_invoke_hide(mod->base, mod->dkey);
119
175
    mod->base = NULL;
120
 
    mod->root = NULL; // should be deleted by invoke_hide
 
176
    mod->root = NULL;
 
177
    nr_object_unref((NRObject *) mod->arena);
 
178
    mod->arena = NULL;
121
179
/* end */
122
180
 
123
181
    mod->set_param_string("destination", oldoutput);
124
182
    g_free(oldoutput);
 
183
 
 
184
    return;
125
185
}
126
186
 
127
187
 
134
194
  fill-column:99
135
195
  End:
136
196
*/
137
 
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :
 
197
// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :