2
* A quick hack to use the Cairo renderer to write out a file. This
3
* then makes 'save as...' PS.
6
* Ted Gould <ted@gould.cx>
7
* Ulf Erikson <ulferikson@users.sf.net>
8
* Adib Taraben <theAdib@yahoo.com>
10
* Copyright (C) 2004-2006 Authors
12
* Released under GNU GPL, read the file 'COPYING' for more information
21
#include "cairo-ps-out.h"
22
#include "cairo-render-context.h"
23
#include "cairo-renderer.h"
25
#include "extension/system.h"
26
#include "extension/print.h"
27
#include "extension/db.h"
28
#include "extension/output.h"
29
#include "display/nr-arena.h"
30
#include "display/nr-arena-item.h"
32
#include "display/curve.h"
33
#include "display/canvas-bpath.h"
46
CairoPsOutput::check (Inkscape::Extension::Extension * module)
48
if (NULL == Inkscape::Extension::db.get(SP_MODULE_KEY_PRINT_CAIRO_PS))
55
CairoEpsOutput::check (Inkscape::Extension::Extension * module)
57
if (NULL == Inkscape::Extension::db.get(SP_MODULE_KEY_PRINT_CAIRO_EPS))
64
ps_print_document_to_file(SPDocument *doc, gchar const *filename, unsigned int level, bool texttopath, bool filtertobitmap, int resolution, const gchar * const exportId, bool exportDrawing, bool exportCanvas, bool eps = false)
66
sp_document_ensure_up_to_date(doc);
70
bool pageBoundingBox = TRUE;
71
if (exportId && strcmp(exportId, "")) {
72
// we want to export the given item only
73
base = SP_ITEM(doc->getObjectById(exportId));
74
pageBoundingBox = exportCanvas;
77
// we want to export the entire document from root
78
base = SP_ITEM(sp_document_root(doc));
79
pageBoundingBox = !exportDrawing;
85
/* Create new arena */
86
NRArena *arena = NRArena::create();
87
unsigned dkey = sp_item_display_key_new(1);
88
sp_item_invoke_show(base, arena, dkey, SP_ITEM_SHOW_DISPLAY);
90
/* Create renderer and context */
91
CairoRenderer *renderer = new CairoRenderer();
92
CairoRenderContext *ctx = renderer->createContext();
93
ctx->setPSLevel(level);
95
ctx->setTextToPath(texttopath);
96
ctx->setFilterToBitmap(filtertobitmap);
97
ctx->setBitmapResolution(resolution);
99
bool ret = ctx->setPsTarget(filename);
101
/* Render document */
102
ret = renderer->setupDocument(ctx, doc, pageBoundingBox, base);
104
renderer->renderItem(ctx, base);
110
sp_item_invoke_hide(base, dkey);
111
nr_object_unref((NRObject *) arena);
113
renderer->destroyContext(ctx);
121
\brief This function calls the output module with the filename
123
\param doc Document to be saved
124
\param filename Filename to save to (probably will end in .ps)
127
CairoPsOutput::save(Inkscape::Extension::Output *mod, SPDocument *doc, gchar const *filename)
129
Inkscape::Extension::Extension * ext;
132
ext = Inkscape::Extension::db.get(SP_MODULE_KEY_PRINT_CAIRO_PS);
136
const gchar *new_level = NULL;
137
int level = CAIRO_PS_LEVEL_2;
139
new_level = mod->get_param_enum("PSlevel");
140
if((new_level != NULL) && !(g_ascii_strcasecmp("PS3", new_level) == 0))
141
level = CAIRO_PS_LEVEL_3;
144
bool new_textToPath = FALSE;
146
new_textToPath = mod->get_param_bool("textToPath");
149
bool new_blurToBitmap = FALSE;
151
new_blurToBitmap = mod->get_param_bool("blurToBitmap");
154
int new_bitmapResolution = 72;
156
new_bitmapResolution = mod->get_param_int("resolution");
159
bool new_areaCanvas = true;
161
new_areaCanvas = mod->get_param_bool("areaCanvas");
164
bool new_areaDrawing = true;
166
new_areaDrawing = mod->get_param_bool("areaDrawing");
169
const gchar *new_exportId = NULL;
171
new_exportId = mod->get_param_string("exportId");
175
final_name = g_strdup_printf("> %s", filename);
176
ret = ps_print_document_to_file(doc, final_name, level, new_textToPath, new_blurToBitmap, new_bitmapResolution, new_exportId, new_areaDrawing, new_areaCanvas);
180
throw Inkscape::Extension::Output::save_failed();
185
\brief This function calls the output module with the filename
187
\param doc Document to be saved
188
\param filename Filename to save to (probably will end in .ps)
191
CairoEpsOutput::save(Inkscape::Extension::Output *mod, SPDocument *doc, gchar const *filename)
193
Inkscape::Extension::Extension * ext;
196
ext = Inkscape::Extension::db.get(SP_MODULE_KEY_PRINT_CAIRO_PS);
200
const gchar *new_level = NULL;
201
int level = CAIRO_PS_LEVEL_2;
203
new_level = mod->get_param_enum("PSlevel");
204
if((new_level != NULL) && !(g_ascii_strcasecmp("PS3", new_level) == 0))
205
level = CAIRO_PS_LEVEL_3;
208
bool new_textToPath = FALSE;
210
new_textToPath = mod->get_param_bool("textToPath");
213
bool new_blurToBitmap = FALSE;
215
new_blurToBitmap = mod->get_param_bool("blurToBitmap");
218
int new_bitmapResolution = 72;
220
new_bitmapResolution = mod->get_param_int("resolution");
223
bool new_areaCanvas = true;
225
new_areaCanvas = mod->get_param_bool("areaCanvas");
228
bool new_areaDrawing = true;
230
new_areaDrawing = mod->get_param_bool("areaDrawing");
233
const gchar *new_exportId = NULL;
235
new_exportId = mod->get_param_string("exportId");
239
final_name = g_strdup_printf("> %s", filename);
240
ret = ps_print_document_to_file(doc, final_name, level, new_textToPath, new_blurToBitmap, new_bitmapResolution, new_exportId, new_areaDrawing, new_areaCanvas, true);
244
throw Inkscape::Extension::Output::save_failed();
249
CairoPsOutput::textToPath(Inkscape::Extension::Print * ext)
251
return ext->get_param_bool("textToPath");
255
CairoEpsOutput::textToPath(Inkscape::Extension::Print * ext)
257
return ext->get_param_bool("textToPath");
260
#include "clear-n_.h"
263
\brief A function allocate a copy of this function.
265
This is the definition of Cairo PS out. This function just
266
calls the extension system with the memory allocated XML that
270
CairoPsOutput::init (void)
272
Inkscape::Extension::build_from_mem(
273
"<inkscape-extension xmlns=\"" INKSCAPE_EXTENSION_URI "\">\n"
274
"<name>" N_("PostScript") "</name>\n"
275
"<id>" SP_MODULE_KEY_PRINT_CAIRO_PS "</id>\n"
276
"<param name=\"PSlevel\" gui-text=\"" N_("Restrict to PS level") "\" type=\"enum\" >\n"
277
"<_item value='PS3'>" N_("PostScript level 3") "</_item>\n"
278
#if (CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1, 5, 2))
279
"<_item value='PS2'>" N_("PostScript level 2") "</_item>\n"
282
"<param name=\"areaCanvas\" gui-text=\"" N_("Export area is whole canvas") "\" type=\"boolean\">true</param>\n"
283
"<param name=\"areaDrawing\" gui-text=\"" N_("Export area is the drawing") "\" type=\"boolean\">true</param>\n"
284
"<param name=\"textToPath\" gui-text=\"" N_("Convert texts to paths") "\" type=\"boolean\">false</param>\n"
285
"<param name=\"blurToBitmap\" gui-text=\"" N_("Rasterize filter effects") "\" type=\"boolean\">true</param>\n"
286
"<param name=\"resolution\" gui-text=\"" N_("Resolution for rasterization (dpi)") "\" type=\"int\" min=\"1\" max=\"10000\">90</param>\n"
287
"<param name=\"exportId\" gui-text=\"" N_("Limit export to the object with ID") "\" type=\"string\"></param>\n"
289
"<extension>.ps</extension>\n"
290
"<mimetype>image/x-postscript</mimetype>\n"
291
"<filetypename>" N_("PostScript (*.ps)") "</filetypename>\n"
292
"<filetypetooltip>" N_("PostScript File") "</filetypetooltip>\n"
294
"</inkscape-extension>", new CairoPsOutput());
300
\brief A function allocate a copy of this function.
302
This is the definition of Cairo EPS out. This function just
303
calls the extension system with the memory allocated XML that
307
CairoEpsOutput::init (void)
309
Inkscape::Extension::build_from_mem(
310
"<inkscape-extension xmlns=\"" INKSCAPE_EXTENSION_URI "\">\n"
311
"<name>" N_("Encapsulated PostScript") "</name>\n"
312
"<id>" SP_MODULE_KEY_PRINT_CAIRO_EPS "</id>\n"
313
"<param name=\"PSlevel\" gui-text=\"" N_("Restrict to PS level") "\" type=\"enum\" >\n"
314
"<_item value='PS3'>" N_("PostScript level 3") "</_item>\n"
315
#if (CAIRO_VERSION >= CAIRO_VERSION_ENCODE(1, 5, 2))
316
"<_item value='PS2'>" N_("PostScript level 2") "</_item>\n"
319
"<param name=\"areaCanvas\" gui-text=\"" N_("Export area is whole canvas") "\" type=\"boolean\">true</param>\n"
320
"<param name=\"areaDrawing\" gui-text=\"" N_("Export area is the drawing") "\" type=\"boolean\">true</param>\n"
321
"<param name=\"textToPath\" gui-text=\"" N_("Convert texts to paths") "\" type=\"boolean\">false</param>\n"
322
"<param name=\"blurToBitmap\" gui-text=\"" N_("Rasterize filter effects") "\" type=\"boolean\">true</param>\n"
323
"<param name=\"resolution\" gui-text=\"" N_("Resolution for rasterization (dpi)") "\" type=\"int\" min=\"1\" max=\"10000\">90</param>\n"
324
"<param name=\"exportId\" gui-text=\"" N_("Limit export to the object with ID") "\" type=\"string\"></param>\n"
326
"<extension>.eps</extension>\n"
327
"<mimetype>image/x-e-postscript</mimetype>\n"
328
"<filetypename>" N_("Encapsulated PostScript (*.eps)") "</filetypename>\n"
329
"<filetypetooltip>" N_("Encapsulated PostScript File") "</filetypetooltip>\n"
331
"</inkscape-extension>", new CairoEpsOutput());
336
} } } /* namespace Inkscape, Extension, Implementation */
338
#endif /* HAVE_CAIRO_PDF */