2
* A quick hack to use the Cairo renderer to write out a file. This
3
* then makes 'save as...' PNG.
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-png-out.h"
21
#include "cairo-render-context.h"
22
#include "cairo-renderer.h"
24
#include "extension/system.h"
25
#include "extension/print.h"
26
#include "extension/db.h"
27
#include "extension/output.h"
28
#include "display/nr-arena.h"
29
#include "display/nr-arena-item.h"
31
#include <libnr/n-art-bpath.h>
33
#include "display/curve.h"
34
#include "display/canvas-bpath.h"
47
CairoRendererOutput::check (Inkscape::Extension::Extension * module)
53
png_render_document_to_file(SPDocument *doc, gchar const *filename)
55
CairoRenderer *renderer;
56
CairoRenderContext *ctx;
58
sp_document_ensure_up_to_date(doc);
61
/* Create new arena */
62
SPItem *base = SP_ITEM(sp_document_root(doc));
63
NRArena *arena = NRArena::create();
64
unsigned dkey = sp_item_display_key_new(1);
65
NRArenaItem *root = sp_item_invoke_show(base, arena, dkey, SP_ITEM_SHOW_DISPLAY);
67
/* Create renderer and context */
68
renderer = new CairoRenderer();
69
ctx = renderer->createContext();
72
bool ret = renderer->setupDocument(ctx, doc);
74
renderer->renderItem(ctx, base);
75
ctx->saveAsPng(filename);
78
renderer->destroyContext(ctx);
81
sp_item_invoke_hide(base, dkey);
82
nr_arena_item_unref(root);
83
nr_object_unref((NRObject *) arena);
92
\brief This function calls the output module with the filename
94
\param doc Document to be saved
95
\param uri Filename to save to (probably will end in .png)
98
CairoRendererOutput::save (Inkscape::Extension::Output *mod, SPDocument *doc, const gchar *uri)
100
if (!png_render_document_to_file(doc, uri))
101
throw Inkscape::Extension::Output::save_failed();
107
\brief A function allocate a copy of this function.
109
This is the definition of Cairo PNG out. This function just
110
calls the extension system with the memory allocated XML that
114
CairoRendererOutput::init (void)
116
Inkscape::Extension::build_from_mem(
117
"<inkscape-extension>\n"
118
"<name>Cairo PNG Output</name>\n"
119
"<id>org.inkscape.output.png.cairo</id>\n"
121
"<extension>.png</extension>\n"
122
"<mimetype>image/png</mimetype>\n"
123
"<filetypename>Cairo PNG (*.png)</filetypename>\n"
124
"<filetypetooltip>PNG File</filetypetooltip>\n"
126
"</inkscape-extension>", new CairoRendererOutput());
131
} } } /* namespace Inkscape, Extension, Implementation */
133
#endif /* HAVE_CAIRO_PDF */