2
* A quick hack to use the print output to write out a file. This
3
* then makes 'save as...' PDF.
6
* Ted Gould <ted@gould.cx>
7
* Ulf Erikson <ulferikson@users.sf.net>
9
* Copyright (C) 2004-2006 Authors
11
* Released under GNU GPL, read the file 'COPYING' for more information
20
#include "cairo-pdf-out.h"
22
#include "extension/system.h"
23
#include "extension/print.h"
24
#include "extension/db.h"
25
#include "extension/output.h"
26
#include "display/nr-arena.h"
27
#include "display/nr-arena-item.h"
35
CairoPdfOutput::check (Inkscape::Extension::Extension * module)
37
if (NULL == Inkscape::Extension::db.get(SP_MODULE_KEY_PRINT_CAIRO_PDF))
45
pdf_print_document_to_file(SPDocument *doc, gchar const *filename, unsigned int pdf_level, bool texttopath, bool filtertobitmap)
47
Inkscape::Extension::Print *mod;
48
SPPrintContext context;
49
gchar const *oldconst;
53
sp_document_ensure_up_to_date(doc);
55
mod = Inkscape::Extension::get_print(SP_MODULE_KEY_PRINT_CAIRO_PDF);
56
oldconst = mod->get_param_string("destination");
57
oldoutput = g_strdup(oldconst);
58
mod->set_param_string("destination", (gchar *)filename);
62
/* fixme: This has to go into module constructor somehow */
63
/* Create new arena */
64
mod->base = SP_ITEM(sp_document_root(doc));
65
mod->arena = NRArena::create();
66
mod->dkey = sp_item_display_key_new(1);
67
mod->root = sp_item_invoke_show(mod->base, mod->arena, mod->dkey, SP_ITEM_SHOW_DISPLAY);
70
ret = mod->begin(doc);
72
sp_item_invoke_print(mod->base, &context);
77
sp_item_invoke_hide(mod->base, mod->dkey);
79
nr_arena_item_unref(mod->root);
81
nr_object_unref((NRObject *) mod->arena);
85
mod->set_param_string("destination", oldoutput);
93
\brief This function calls the print system with the filename
95
\param doc Document to be saved
96
\param uri Filename to save to (probably will end in .pdf)
98
The most interesting thing that this function does is just attach
99
an '>' on the front of the filename. This is the syntax used to
100
tell the printing system to save to file.
103
CairoPdfOutput::save (Inkscape::Extension::Output *mod, SPDocument *doc, const gchar *uri)
105
Inkscape::Extension::Extension * ext;
108
ext = Inkscape::Extension::db.get(SP_MODULE_KEY_PRINT_CAIRO_PDF);
112
bool old_textToPath = FALSE;
113
bool new_textToPath = FALSE;
115
old_textToPath = ext->get_param_bool("textToPath");
116
new_textToPath = mod->get_param_bool("textToPath");
117
ext->set_param_bool("textToPath", new_textToPath);
120
g_warning("Parameter <textToPath> might not exists");
124
final_name = g_strdup_printf("> %s", uri);
125
ret = pdf_print_document_to_file(doc, final_name, 0, new_textToPath, false);
129
ext->set_param_bool("textToPath", old_textToPath);
132
g_warning("Parameter <textToPath> might not exists");
136
throw Inkscape::Extension::Output::save_failed();
141
#include "clear-n_.h"
143
\brief A function allocate a copy of this function.
145
This is the definition of PDF out. This function just
146
calls the extension system with the memory allocated XML that
150
CairoPdfOutput::init (void)
152
Inkscape::Extension::build_from_mem(
153
"<inkscape-extension>\n"
154
"<name>" N_("Cairo PDF Output") "</name>\n"
155
"<id>org.inkscape.output.pdf.cairo</id>\n"
156
"<param name=\"PDFversion\" gui-text=\"" N_("Restrict to PDF version") "\" type=\"enum\" >\n"
157
"<_item value='PDF14'>" N_("PDF 1.4") "</_item>\n"
159
"<param name=\"textToPath\" gui-text=\"" N_("Convert texts to paths") "\" type=\"boolean\">false</param>\n"
161
"<extension>.pdf</extension>\n"
162
"<mimetype>application/pdf</mimetype>\n"
163
"<filetypename>" N_("PDF via Cairo (*.pdf)") "</filetypename>\n"
164
"<filetypetooltip>" N_("PDF File") "</filetypetooltip>\n"
166
"</inkscape-extension>", new CairoPdfOutput());
171
} } } /* namespace Inkscape, Extension, Implementation */
173
#endif /* HAVE_CAIRO_PDF */