index f34a90b226960874617b12544e060ef21f47c644..6fd45d0d5a7afbcb31bda2f7eb90bdcfadad77c8 100644 (file)
-/*\r
- * A quick hack to use the Cairo renderer to write out a file. This\r
- * then makes 'save as...' PNG.\r
- *\r
- * Authors:\r
- * Ted Gould <ted@gould.cx>\r
- * Ulf Erikson <ulferikson@users.sf.net>\r
- *\r
- * Copyright (C) 2004-2006 Authors\r
- *\r
- * Released under GNU GPL, read the file 'COPYING' for more information\r
- */\r
-\r
-#ifdef HAVE_CONFIG_H\r
-# include <config.h>\r
-#endif\r
-\r
-#ifdef HAVE_CAIRO_PDF\r
-\r
-#include "cairo-png-out.h"\r
-#include "cairo-render-context.h"\r
-#include "cairo-renderer.h"\r
-#include <print.h>\r
-#include "extension/system.h"\r
-#include "extension/print.h"\r
-#include "extension/db.h"\r
-#include "extension/output.h"\r
-#include "display/nr-arena.h"\r
-#include "display/nr-arena-item.h"\r
-\r
-#include <libnr/n-art-bpath.h>\r
-\r
-#include "display/curve.h"\r
-#include "display/canvas-bpath.h"\r
-#include "sp-item.h"\r
-#include "style.h"\r
-#include "sp-root.h"\r
-#include "sp-shape.h"\r
-\r
-#include "io/sys.h"\r
-\r
-namespace Inkscape {\r
-namespace Extension {\r
-namespace Internal {\r
-\r
-bool\r
-CairoRendererOutput::check (Inkscape::Extension::Extension * module)\r
-{\r
- return TRUE;\r
-}\r
-\r
-static bool\r
-png_render_document_to_file(SPDocument *doc, gchar const *filename)\r
-{\r
- CairoRenderer *renderer;\r
- CairoRenderContext *ctx;\r
-\r
- sp_document_ensure_up_to_date(doc);\r
-\r
-/* Start */\r
- /* Create new arena */\r
- SPItem *base = SP_ITEM(sp_document_root(doc));\r
- NRArena *arena = NRArena::create();\r
- unsigned dkey = sp_item_display_key_new(1);\r
- NRArenaItem *root = sp_item_invoke_show(base, arena, dkey, SP_ITEM_SHOW_DISPLAY);\r
- \r
- /* Create renderer and context */\r
- renderer = new CairoRenderer();\r
- ctx = renderer->createContext();\r
-\r
- /* Render document */\r
- bool ret = renderer->setupDocument(ctx, doc);\r
- if (ret) {\r
- renderer->renderItem(ctx, base);\r
- ctx->saveAsPng(filename);\r
- ret = ctx->finish();\r
- }\r
- renderer->destroyContext(ctx);\r
-\r
- /* Release arena */\r
- sp_item_invoke_hide(base, dkey);\r
- nr_arena_item_unref(root);\r
- nr_object_unref((NRObject *) arena);\r
-/* end */\r
- delete renderer;\r
-\r
- return ret;\r
-}\r
-\r
-\r
-/**\r
- \brief This function calls the output module with the filename\r
- \param mod unused\r
- \param doc Document to be saved\r
- \param uri Filename to save to (probably will end in .png)\r
-*/\r
-void\r
-CairoRendererOutput::save (Inkscape::Extension::Output *mod, SPDocument *doc, const gchar *uri)\r
-{\r
- if (!png_render_document_to_file(doc, uri))\r
- throw Inkscape::Extension::Output::save_failed();\r
-\r
- return;\r
-}\r
-\r
-/**\r
- \brief A function allocate a copy of this function.\r
-\r
- This is the definition of Cairo PNG out. This function just\r
- calls the extension system with the memory allocated XML that\r
- describes the data.\r
-*/\r
-void\r
-CairoRendererOutput::init (void)\r
-{\r
- Inkscape::Extension::build_from_mem(\r
- "<inkscape-extension>\n"\r
- "<name>Cairo PNG Output</name>\n"\r
- "<id>org.inkscape.output.png.cairo</id>\n"\r
- "<output>\n"\r
- "<extension>.png</extension>\n"\r
- "<mimetype>image/png</mimetype>\n"\r
- "<filetypename>Cairo PNG (*.png)</filetypename>\n"\r
- "<filetypetooltip>PNG File</filetypetooltip>\n"\r
- "</output>\n"\r
- "</inkscape-extension>", new CairoRendererOutput());\r
-\r
- return;\r
-}\r
-\r
-} } } /* namespace Inkscape, Extension, Implementation */\r
-\r
-#endif /* HAVE_CAIRO_PDF */\r
+/*
+ * A quick hack to use the Cairo renderer to write out a file. This
+ * then makes 'save as...' PNG.
+ *
+ * Authors:
+ * Ted Gould <ted@gould.cx>
+ * Ulf Erikson <ulferikson@users.sf.net>
+ *
+ * Copyright (C) 2004-2006 Authors
+ *
+ * Released under GNU GPL, read the file 'COPYING' for more information
+ */
+
+#ifdef HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#ifdef HAVE_CAIRO_PDF
+
+#include "cairo-png-out.h"
+#include "cairo-render-context.h"
+#include "cairo-renderer.h"
+#include <print.h>
+#include "extension/system.h"
+#include "extension/print.h"
+#include "extension/db.h"
+#include "extension/output.h"
+#include "display/nr-arena.h"
+#include "display/nr-arena-item.h"
+
+#include <libnr/n-art-bpath.h>
+
+#include "display/curve.h"
+#include "display/canvas-bpath.h"
+#include "sp-item.h"
+#include "style.h"
+#include "sp-root.h"
+#include "sp-shape.h"
+
+#include "io/sys.h"
+
+namespace Inkscape {
+namespace Extension {
+namespace Internal {
+
+bool
+CairoRendererOutput::check (Inkscape::Extension::Extension * module)
+{
+ return TRUE;
+}
+
+static bool
+png_render_document_to_file(SPDocument *doc, gchar const *filename)
+{
+ CairoRenderer *renderer;
+ CairoRenderContext *ctx;
+
+ sp_document_ensure_up_to_date(doc);
+
+/* Start */
+ /* Create new arena */
+ SPItem *base = SP_ITEM(sp_document_root(doc));
+ NRArena *arena = NRArena::create();
+ unsigned dkey = sp_item_display_key_new(1);
+ NRArenaItem *root = sp_item_invoke_show(base, arena, dkey, SP_ITEM_SHOW_DISPLAY);
+
+ /* Create renderer and context */
+ renderer = new CairoRenderer();
+ ctx = renderer->createContext();
+
+ /* Render document */
+ bool ret = renderer->setupDocument(ctx, doc);
+ if (ret) {
+ renderer->renderItem(ctx, base);
+ ctx->saveAsPng(filename);
+ ret = ctx->finish();
+ }
+ renderer->destroyContext(ctx);
+
+ /* Release arena */
+ sp_item_invoke_hide(base, dkey);
+ nr_arena_item_unref(root);
+ nr_object_unref((NRObject *) arena);
+/* end */
+ delete renderer;
+
+ return ret;
+}
+
+
+/**
+ \brief This function calls the output module with the filename
+ \param mod unused
+ \param doc Document to be saved
+ \param uri Filename to save to (probably will end in .png)
+*/
+void
+CairoRendererOutput::save (Inkscape::Extension::Output *mod, SPDocument *doc, const gchar *uri)
+{
+ if (!png_render_document_to_file(doc, uri))
+ throw Inkscape::Extension::Output::save_failed();
+
+ return;
+}
+
+/**
+ \brief A function allocate a copy of this function.
+
+ This is the definition of Cairo PNG out. This function just
+ calls the extension system with the memory allocated XML that
+ describes the data.
+*/
+void
+CairoRendererOutput::init (void)
+{
+ Inkscape::Extension::build_from_mem(
+ "<inkscape-extension>\n"
+ "<name>Cairo PNG Output</name>\n"
+ "<id>org.inkscape.output.png.cairo</id>\n"
+ "<output>\n"
+ "<extension>.png</extension>\n"
+ "<mimetype>image/png</mimetype>\n"
+ "<filetypename>Cairo PNG (*.png)</filetypename>\n"
+ "<filetypetooltip>PNG File</filetypetooltip>\n"
+ "</output>\n"
+ "</inkscape-extension>", new CairoRendererOutput());
+
+ return;
+}
+
+} } } /* namespace Inkscape, Extension, Implementation */
+
+#endif /* HAVE_CAIRO_PDF */