summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (from parent 1: f2660b0)
raw | patch | inline | side by side (from parent 1: f2660b0)
author | miklosh <miklosh@users.sourceforge.net> | |
Sun, 1 Oct 2006 14:12:04 +0000 (14:12 +0000) | ||
committer | miklosh <miklosh@users.sourceforge.net> | |
Sun, 1 Oct 2006 14:12:04 +0000 (14:12 +0000) |
src/extension/internal/cairo-png-out.cpp | [new file with mode: 0644] | patch | blob |
diff --git a/src/extension/internal/cairo-png-out.cpp b/src/extension/internal/cairo-png-out.cpp
--- /dev/null
@@ -0,0 +1,128 @@
+/*\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
+#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