summaryrefslogtreecommitdiffstats
path: root/src/extension/internal
diff options
context:
space:
mode:
authorJon A. Cruz <jon@joncruz.org>2007-02-19 20:48:09 +0000
committerjoncruz <joncruz@users.sourceforge.net>2007-02-19 20:48:09 +0000
commit6e272e78c148590660e3443caefce378800260c3 (patch)
tree6440f0b74ad32266110af6ae030f2823b12b898e /src/extension/internal
parentFixed unintialized variables and minor misc warnings (diff)
downloadinkscape-6e272e78c148590660e3443caefce378800260c3.tar.gz
inkscape-6e272e78c148590660e3443caefce378800260c3.zip
Cleaned up DOS line ends that had snuck in.
(bzr r2399)
Diffstat (limited to 'src/extension/internal')
-rw-r--r--src/extension/internal/cairo-pdf-out.cpp300
-rw-r--r--src/extension/internal/cairo-pdf-out.h100
-rw-r--r--src/extension/internal/cairo-png-out.cpp266
-rw-r--r--src/extension/internal/cairo-png-out.h100
-rw-r--r--src/extension/internal/cairo-renderer-pdf-out.cpp266
-rw-r--r--src/extension/internal/cairo-renderer-pdf-out.h100
-rw-r--r--src/extension/internal/emf-win32-inout.cpp2860
-rw-r--r--src/extension/internal/emf-win32-inout.h120
-rw-r--r--src/extension/internal/emf-win32-print.cpp1258
-rw-r--r--src/extension/internal/emf-win32-print.h214
-rw-r--r--src/extension/internal/libwpg/WPGOLEStream.h82
-rw-r--r--src/extension/internal/libwpg/WPGXParser.cpp206
-rw-r--r--src/extension/internal/libwpg/WPGXParser.h120
-rw-r--r--src/extension/internal/libwpg/WPGraphics.cpp166
-rw-r--r--src/extension/internal/libwpg/WPGraphics.h92
-rw-r--r--src/extension/internal/wpg-input.cpp730
16 files changed, 3490 insertions, 3490 deletions
diff --git a/src/extension/internal/cairo-pdf-out.cpp b/src/extension/internal/cairo-pdf-out.cpp
index 9ee1ae32f..88010e686 100644
--- a/src/extension/internal/cairo-pdf-out.cpp
+++ b/src/extension/internal/cairo-pdf-out.cpp
@@ -1,150 +1,150 @@
-/*
- * A quick hack to use the print output to write out a file. This
- * then makes 'save as...' PDF.
- *
- * 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-pdf-out.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 "sp-path.h"
-
-namespace Inkscape {
-namespace Extension {
-namespace Internal {
-
-bool
-CairoPdfOutput::check (Inkscape::Extension::Extension * module)
-{
- if (NULL == Inkscape::Extension::db.get(SP_MODULE_KEY_PRINT_CAIRO_PDF))
- return FALSE;
-
- return TRUE;
-}
-
-
-static unsigned int
-pdf_print_document_to_file(SPDocument *doc, gchar const *filename)
-{
- Inkscape::Extension::Print *mod;
- SPPrintContext context;
- gchar const *oldconst;
- gchar *oldoutput;
- unsigned int ret;
-
- sp_document_ensure_up_to_date(doc);
-
- mod = Inkscape::Extension::get_print(SP_MODULE_KEY_PRINT_CAIRO_PDF);
- oldconst = mod->get_param_string("destination");
- oldoutput = g_strdup(oldconst);
- mod->set_param_string("destination", (gchar *)filename);
-
-/* Start */
- context.module = mod;
- /* fixme: This has to go into module constructor somehow */
- /* Create new arena */
- mod->base = SP_ITEM(sp_document_root(doc));
- mod->arena = NRArena::create();
- mod->dkey = sp_item_display_key_new(1);
- mod->root = sp_item_invoke_show(mod->base, mod->arena, mod->dkey, SP_ITEM_SHOW_DISPLAY);
-
- /* Print document */
- ret = mod->begin(doc);
- if (ret) {
- sp_item_invoke_print(mod->base, &context);
- ret = mod->finish();
- }
-
- /* Release arena */
- sp_item_invoke_hide(mod->base, mod->dkey);
- mod->base = NULL;
- nr_arena_item_unref(mod->root);
- mod->root = NULL;
- nr_object_unref((NRObject *) mod->arena);
- mod->arena = NULL;
-/* end */
-
- mod->set_param_string("destination", oldoutput);
- g_free(oldoutput);
-
- return ret;
-}
-
-
-/**
- \brief This function calls the print system with the filename
- \param mod unused
- \param doc Document to be saved
- \param uri Filename to save to (probably will end in .pdf)
-
- The most interesting thing that this function does is just attach
- an '>' on the front of the filename. This is the syntax used to
- tell the printing system to save to file.
-*/
-void
-CairoPdfOutput::save (Inkscape::Extension::Output *mod, SPDocument *doc, const gchar *uri)
-{
- Inkscape::Extension::Extension * ext;
- unsigned int ret;
-
- ext = Inkscape::Extension::db.get(SP_MODULE_KEY_PRINT_CAIRO_PDF);
- if (ext == NULL)
- return;
-
- gchar * final_name;
- final_name = g_strdup_printf("> %s", uri);
- ret = pdf_print_document_to_file(doc, final_name);
- g_free(final_name);
-
- if (!ret)
- throw Inkscape::Extension::Output::save_failed();
-
- return;
-}
-
-/**
- \brief A function allocate a copy of this function.
-
- This is the definition of PDF out. This function just
- calls the extension system with the memory allocated XML that
- describes the data.
-*/
-void
-CairoPdfOutput::init (void)
-{
- Inkscape::Extension::build_from_mem(
- "<inkscape-extension>\n"
- "<name>Cairo PDF Output</name>\n"
- "<id>org.inkscape.output.pdf.cairo</id>\n"
- "<output>\n"
- "<extension>.pdf</extension>\n"
- "<mimetype>application/pdf</mimetype>\n"
- "<filetypename>Cairo PDF (*.pdf)</filetypename>\n"
- "<filetypetooltip>PDF File</filetypetooltip>\n"
- "</output>\n"
- "</inkscape-extension>", new CairoPdfOutput());
-
- return;
-}
-
-} } } /* namespace Inkscape, Extension, Implementation */
-
-#endif /* HAVE_CAIRO_PDF */
+/*
+ * A quick hack to use the print output to write out a file. This
+ * then makes 'save as...' PDF.
+ *
+ * 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-pdf-out.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 "sp-path.h"
+
+namespace Inkscape {
+namespace Extension {
+namespace Internal {
+
+bool
+CairoPdfOutput::check (Inkscape::Extension::Extension * module)
+{
+ if (NULL == Inkscape::Extension::db.get(SP_MODULE_KEY_PRINT_CAIRO_PDF))
+ return FALSE;
+
+ return TRUE;
+}
+
+
+static unsigned int
+pdf_print_document_to_file(SPDocument *doc, gchar const *filename)
+{
+ Inkscape::Extension::Print *mod;
+ SPPrintContext context;
+ gchar const *oldconst;
+ gchar *oldoutput;
+ unsigned int ret;
+
+ sp_document_ensure_up_to_date(doc);
+
+ mod = Inkscape::Extension::get_print(SP_MODULE_KEY_PRINT_CAIRO_PDF);
+ oldconst = mod->get_param_string("destination");
+ oldoutput = g_strdup(oldconst);
+ mod->set_param_string("destination", (gchar *)filename);
+
+/* Start */
+ context.module = mod;
+ /* fixme: This has to go into module constructor somehow */
+ /* Create new arena */
+ mod->base = SP_ITEM(sp_document_root(doc));
+ mod->arena = NRArena::create();
+ mod->dkey = sp_item_display_key_new(1);
+ mod->root = sp_item_invoke_show(mod->base, mod->arena, mod->dkey, SP_ITEM_SHOW_DISPLAY);
+
+ /* Print document */
+ ret = mod->begin(doc);
+ if (ret) {
+ sp_item_invoke_print(mod->base, &context);
+ ret = mod->finish();
+ }
+
+ /* Release arena */
+ sp_item_invoke_hide(mod->base, mod->dkey);
+ mod->base = NULL;
+ nr_arena_item_unref(mod->root);
+ mod->root = NULL;
+ nr_object_unref((NRObject *) mod->arena);
+ mod->arena = NULL;
+/* end */
+
+ mod->set_param_string("destination", oldoutput);
+ g_free(oldoutput);
+
+ return ret;
+}
+
+
+/**
+ \brief This function calls the print system with the filename
+ \param mod unused
+ \param doc Document to be saved
+ \param uri Filename to save to (probably will end in .pdf)
+
+ The most interesting thing that this function does is just attach
+ an '>' on the front of the filename. This is the syntax used to
+ tell the printing system to save to file.
+*/
+void
+CairoPdfOutput::save (Inkscape::Extension::Output *mod, SPDocument *doc, const gchar *uri)
+{
+ Inkscape::Extension::Extension * ext;
+ unsigned int ret;
+
+ ext = Inkscape::Extension::db.get(SP_MODULE_KEY_PRINT_CAIRO_PDF);
+ if (ext == NULL)
+ return;
+
+ gchar * final_name;
+ final_name = g_strdup_printf("> %s", uri);
+ ret = pdf_print_document_to_file(doc, final_name);
+ g_free(final_name);
+
+ if (!ret)
+ throw Inkscape::Extension::Output::save_failed();
+
+ return;
+}
+
+/**
+ \brief A function allocate a copy of this function.
+
+ This is the definition of PDF out. This function just
+ calls the extension system with the memory allocated XML that
+ describes the data.
+*/
+void
+CairoPdfOutput::init (void)
+{
+ Inkscape::Extension::build_from_mem(
+ "<inkscape-extension>\n"
+ "<name>Cairo PDF Output</name>\n"
+ "<id>org.inkscape.output.pdf.cairo</id>\n"
+ "<output>\n"
+ "<extension>.pdf</extension>\n"
+ "<mimetype>application/pdf</mimetype>\n"
+ "<filetypename>Cairo PDF (*.pdf)</filetypename>\n"
+ "<filetypetooltip>PDF File</filetypetooltip>\n"
+ "</output>\n"
+ "</inkscape-extension>", new CairoPdfOutput());
+
+ return;
+}
+
+} } } /* namespace Inkscape, Extension, Implementation */
+
+#endif /* HAVE_CAIRO_PDF */
diff --git a/src/extension/internal/cairo-pdf-out.h b/src/extension/internal/cairo-pdf-out.h
index f0e67f165..42cd9365c 100644
--- a/src/extension/internal/cairo-pdf-out.h
+++ b/src/extension/internal/cairo-pdf-out.h
@@ -1,50 +1,50 @@
-/*
- * A quick hack to use the print output to write out a file. This
- * then makes 'save as...' PDF.
- *
- * 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
- */
-
-#ifndef EXTENSION_INTERNAL_CAIRO_PDF_OUT_H
-#define EXTENSION_INTERNAL_CAIRO_PDF_OUT_H
-
-#include "extension/implementation/implementation.h"
-
-#ifdef HAVE_CAIRO_PDF
-
-namespace Inkscape {
-namespace Extension {
-namespace Internal {
-
-class CairoPdfOutput : Inkscape::Extension::Implementation::Implementation {
-
-public:
- bool check(Inkscape::Extension::Extension *module);
- void save(Inkscape::Extension::Output *mod,
- SPDocument *doc,
- gchar const *uri);
- static void init();
-};
-
-} } } /* namespace Inkscape, Extension, Implementation */
-
-#endif /* HAVE_CAIRO_PDF */
-
-#endif /* !EXTENSION_INTERNAL_CAIRO_PDF_OUT_H */
-
-/*
- Local Variables:
- mode:c++
- c-file-style:"stroustrup"
- c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
- indent-tabs-mode:nil
- fill-column:99
- End:
-*/
-// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :
+/*
+ * A quick hack to use the print output to write out a file. This
+ * then makes 'save as...' PDF.
+ *
+ * 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
+ */
+
+#ifndef EXTENSION_INTERNAL_CAIRO_PDF_OUT_H
+#define EXTENSION_INTERNAL_CAIRO_PDF_OUT_H
+
+#include "extension/implementation/implementation.h"
+
+#ifdef HAVE_CAIRO_PDF
+
+namespace Inkscape {
+namespace Extension {
+namespace Internal {
+
+class CairoPdfOutput : Inkscape::Extension::Implementation::Implementation {
+
+public:
+ bool check(Inkscape::Extension::Extension *module);
+ void save(Inkscape::Extension::Output *mod,
+ SPDocument *doc,
+ gchar const *uri);
+ static void init();
+};
+
+} } } /* namespace Inkscape, Extension, Implementation */
+
+#endif /* HAVE_CAIRO_PDF */
+
+#endif /* !EXTENSION_INTERNAL_CAIRO_PDF_OUT_H */
+
+/*
+ Local Variables:
+ mode:c++
+ c-file-style:"stroustrup"
+ c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
+ indent-tabs-mode:nil
+ fill-column:99
+ End:
+*/
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :
diff --git a/src/extension/internal/cairo-png-out.cpp b/src/extension/internal/cairo-png-out.cpp
index f34a90b22..6fd45d0d5 100644
--- a/src/extension/internal/cairo-png-out.cpp
+++ b/src/extension/internal/cairo-png-out.cpp
@@ -1,133 +1,133 @@
-/*
- * 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 */
+/*
+ * 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 */
diff --git a/src/extension/internal/cairo-png-out.h b/src/extension/internal/cairo-png-out.h
index 207786c88..625c53ffc 100644
--- a/src/extension/internal/cairo-png-out.h
+++ b/src/extension/internal/cairo-png-out.h
@@ -1,50 +1,50 @@
-/*
- * A quick hack to use the print output 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
- */
-
-#ifndef EXTENSION_INTERNAL_CAIRO_PNG_OUT_H
-#define EXTENSION_INTERNAL_CAIRO_PNG_OUT_H
-
-#include "extension/implementation/implementation.h"
-
-#ifdef HAVE_CAIRO_PDF
-
-namespace Inkscape {
-namespace Extension {
-namespace Internal {
-
-class CairoRendererOutput : Inkscape::Extension::Implementation::Implementation {
-
-public:
- bool check(Inkscape::Extension::Extension *module);
- void save(Inkscape::Extension::Output *mod,
- SPDocument *doc,
- gchar const *uri);
- static void init();
-};
-
-} } } /* namespace Inkscape, Extension, Implementation */
-
-#endif /* HAVE_CAIRO_PDF */
-
-#endif /* !EXTENSION_INTERNAL_CAIRO_PNG_OUT_H */
-
-/*
- Local Variables:
- mode:c++
- c-file-style:"stroustrup"
- c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
- indent-tabs-mode:nil
- fill-column:99
- End:
-*/
-// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :
+/*
+ * A quick hack to use the print output 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
+ */
+
+#ifndef EXTENSION_INTERNAL_CAIRO_PNG_OUT_H
+#define EXTENSION_INTERNAL_CAIRO_PNG_OUT_H
+
+#include "extension/implementation/implementation.h"
+
+#ifdef HAVE_CAIRO_PDF
+
+namespace Inkscape {
+namespace Extension {
+namespace Internal {
+
+class CairoRendererOutput : Inkscape::Extension::Implementation::Implementation {
+
+public:
+ bool check(Inkscape::Extension::Extension *module);
+ void save(Inkscape::Extension::Output *mod,
+ SPDocument *doc,
+ gchar const *uri);
+ static void init();
+};
+
+} } } /* namespace Inkscape, Extension, Implementation */
+
+#endif /* HAVE_CAIRO_PDF */
+
+#endif /* !EXTENSION_INTERNAL_CAIRO_PNG_OUT_H */
+
+/*
+ Local Variables:
+ mode:c++
+ c-file-style:"stroustrup"
+ c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
+ indent-tabs-mode:nil
+ fill-column:99
+ End:
+*/
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :
diff --git a/src/extension/internal/cairo-renderer-pdf-out.cpp b/src/extension/internal/cairo-renderer-pdf-out.cpp
index 5d2765660..82b736ad2 100644
--- a/src/extension/internal/cairo-renderer-pdf-out.cpp
+++ b/src/extension/internal/cairo-renderer-pdf-out.cpp
@@ -1,133 +1,133 @@
-/*
- * A quick hack to use the Cairo renderer to write out a file. This
- * then makes 'save as...' PDF.
- *
- * 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-renderer-pdf-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 "sp-root.h"
-
-namespace Inkscape {
-namespace Extension {
-namespace Internal {
-
-bool
-CairoRendererPdfOutput::check (Inkscape::Extension::Extension * module)
-{
- return TRUE;
-}
-
-static bool
-pdf_render_document_to_file(SPDocument *doc, gchar const *filename)
-{
- 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 */
- CairoRenderer *renderer = new CairoRenderer();
- CairoRenderContext *ctx = renderer->createContext();
- ctx->setPdfTarget (filename);
- bool ret = renderer->setupDocument(ctx, doc);
- if (ret) {
- renderer->renderItem(ctx, base);
- ret = ctx->finish();
- }
-
- /* Release arena */
- sp_item_invoke_hide(base, dkey);
- nr_arena_item_unref(root);
- nr_object_unref((NRObject *) arena);
-/* end */
- renderer->destroyContext(ctx);
- 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)
-
- The most interesting thing that this function does is just attach
- an '>' on the front of the filename. This is the syntax used to
- tell the printing system to save to file.
-*/
-void
-CairoRendererPdfOutput::save (Inkscape::Extension::Output *mod, SPDocument *doc, const gchar *uri)
-{
- gchar * final_name;
- final_name = g_strdup_printf("> %s", uri);
- bool ret = pdf_render_document_to_file(doc, final_name);
- g_free(final_name);
-
- if (!ret)
- throw Inkscape::Extension::Output::save_failed();
-
- return;
-}
-
-/**
- \brief A function allocate a copy of this function.
-
- This is the definition of Cairo PDF out. This function just
- calls the extension system with the memory allocated XML that
- describes the data.
-*/
-void
-CairoRendererPdfOutput::init (void)
-{
- Inkscape::Extension::build_from_mem(
- "<inkscape-extension>\n"
- "<name>Cairo PDF Output (experimental)</name>\n"
- "<id>org.inkscape.output.pdf.cairorenderer</id>\n"
- "<output>\n"
- "<extension>.pdf</extension>\n"
- "<mimetype>application/pdf</mimetype>\n"
- "<filetypename>Cairo PDF experimental (*.pdf)</filetypename>\n"
- "<filetypetooltip>PDF File</filetypetooltip>\n"
- "</output>\n"
- "</inkscape-extension>", new CairoRendererPdfOutput());
-
- return;
-}
-
-} } } /* namespace Inkscape, Extension, Internal */
-
-#endif /* HAVE_CAIRO_PDF */
+/*
+ * A quick hack to use the Cairo renderer to write out a file. This
+ * then makes 'save as...' PDF.
+ *
+ * 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-renderer-pdf-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 "sp-root.h"
+
+namespace Inkscape {
+namespace Extension {
+namespace Internal {
+
+bool
+CairoRendererPdfOutput::check (Inkscape::Extension::Extension * module)
+{
+ return TRUE;
+}
+
+static bool
+pdf_render_document_to_file(SPDocument *doc, gchar const *filename)
+{
+ 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 */
+ CairoRenderer *renderer = new CairoRenderer();
+ CairoRenderContext *ctx = renderer->createContext();
+ ctx->setPdfTarget (filename);
+ bool ret = renderer->setupDocument(ctx, doc);
+ if (ret) {
+ renderer->renderItem(ctx, base);
+ ret = ctx->finish();
+ }
+
+ /* Release arena */
+ sp_item_invoke_hide(base, dkey);
+ nr_arena_item_unref(root);
+ nr_object_unref((NRObject *) arena);
+/* end */
+ renderer->destroyContext(ctx);
+ 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)
+
+ The most interesting thing that this function does is just attach
+ an '>' on the front of the filename. This is the syntax used to
+ tell the printing system to save to file.
+*/
+void
+CairoRendererPdfOutput::save (Inkscape::Extension::Output *mod, SPDocument *doc, const gchar *uri)
+{
+ gchar * final_name;
+ final_name = g_strdup_printf("> %s", uri);
+ bool ret = pdf_render_document_to_file(doc, final_name);
+ g_free(final_name);
+
+ if (!ret)
+ throw Inkscape::Extension::Output::save_failed();
+
+ return;
+}
+
+/**
+ \brief A function allocate a copy of this function.
+
+ This is the definition of Cairo PDF out. This function just
+ calls the extension system with the memory allocated XML that
+ describes the data.
+*/
+void
+CairoRendererPdfOutput::init (void)
+{
+ Inkscape::Extension::build_from_mem(
+ "<inkscape-extension>\n"
+ "<name>Cairo PDF Output (experimental)</name>\n"
+ "<id>org.inkscape.output.pdf.cairorenderer</id>\n"
+ "<output>\n"
+ "<extension>.pdf</extension>\n"
+ "<mimetype>application/pdf</mimetype>\n"
+ "<filetypename>Cairo PDF experimental (*.pdf)</filetypename>\n"
+ "<filetypetooltip>PDF File</filetypetooltip>\n"
+ "</output>\n"
+ "</inkscape-extension>", new CairoRendererPdfOutput());
+
+ return;
+}
+
+} } } /* namespace Inkscape, Extension, Internal */
+
+#endif /* HAVE_CAIRO_PDF */
diff --git a/src/extension/internal/cairo-renderer-pdf-out.h b/src/extension/internal/cairo-renderer-pdf-out.h
index d7d5a6681..1c18519a0 100644
--- a/src/extension/internal/cairo-renderer-pdf-out.h
+++ b/src/extension/internal/cairo-renderer-pdf-out.h
@@ -1,50 +1,50 @@
-/*
- * A quick hack to use the Cairo renderer to write out a file. This
- * then makes 'save as...' PDF.
- *
- * 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
- */
-
-#ifndef EXTENSION_INTERNAL_CAIRO_RENDERER_PDF_OUT_H
-#define EXTENSION_INTERNAL_CAIRO_RENDERER_PDF_OUT_H
-
-#include "extension/implementation/implementation.h"
-
-#ifdef HAVE_CAIRO_PDF
-
-namespace Inkscape {
-namespace Extension {
-namespace Internal {
-
-class CairoRendererPdfOutput : Inkscape::Extension::Implementation::Implementation {
-
-public:
- bool check(Inkscape::Extension::Extension *module);
- void save(Inkscape::Extension::Output *mod,
- SPDocument *doc,
- gchar const *uri);
- static void init();
-};
-
-} } } /* namespace Inkscape, Extension, Internal */
-
-#endif /* HAVE_CAIRO_PDF */
-
-#endif /* !EXTENSION_INTERNAL_CAIRO_RENDERER_PDF_OUT_H */
-
-/*
- Local Variables:
- mode:c++
- c-file-style:"stroustrup"
- c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
- indent-tabs-mode:nil
- fill-column:99
- End:
-*/
-// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :
+/*
+ * A quick hack to use the Cairo renderer to write out a file. This
+ * then makes 'save as...' PDF.
+ *
+ * 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
+ */
+
+#ifndef EXTENSION_INTERNAL_CAIRO_RENDERER_PDF_OUT_H
+#define EXTENSION_INTERNAL_CAIRO_RENDERER_PDF_OUT_H
+
+#include "extension/implementation/implementation.h"
+
+#ifdef HAVE_CAIRO_PDF
+
+namespace Inkscape {
+namespace Extension {
+namespace Internal {
+
+class CairoRendererPdfOutput : Inkscape::Extension::Implementation::Implementation {
+
+public:
+ bool check(Inkscape::Extension::Extension *module);
+ void save(Inkscape::Extension::Output *mod,
+ SPDocument *doc,
+ gchar const *uri);
+ static void init();
+};
+
+} } } /* namespace Inkscape, Extension, Internal */
+
+#endif /* HAVE_CAIRO_PDF */
+
+#endif /* !EXTENSION_INTERNAL_CAIRO_RENDERER_PDF_OUT_H */
+
+/*
+ Local Variables:
+ mode:c++
+ c-file-style:"stroustrup"
+ c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
+ indent-tabs-mode:nil
+ fill-column:99
+ End:
+*/
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :
diff --git a/src/extension/internal/emf-win32-inout.cpp b/src/extension/internal/emf-win32-inout.cpp
index a39d1fb1d..b9d65f50c 100644
--- a/src/extension/internal/emf-win32-inout.cpp
+++ b/src/extension/internal/emf-win32-inout.cpp
@@ -1,1430 +1,1430 @@
-/** \file
- * Enhanced Metafile Input and Output.
- */
-/*
- * Authors:
- * Ulf Erikson <ulferikson@users.sf.net>
- *
- * Copyright (C) 2006 Authors
- *
- * Released under GNU GPL, read the file 'COPYING' for more information
- */
-/*
- * References:
- * - How to Create & Play Enhanced Metafiles in Win32
- * http://support.microsoft.com/kb/q145999/
- * - INFO: Windows Metafile Functions & Aldus Placeable Metafiles
- * http://support.microsoft.com/kb/q66949/
- * - Metafile Functions
- * http://msdn.microsoft.com/library/en-us/gdi/metafile_0whf.asp
- * - Metafile Structures
- * http://msdn.microsoft.com/library/en-us/gdi/metafile_5hkj.asp
- */
-
-#ifdef WIN32
-
-#ifdef HAVE_CONFIG_H
-# include "config.h"
-#endif
-
-#include "win32.h"
-#include "emf-win32-print.h"
-#include "emf-win32-inout.h"
-#include "inkscape.h"
-#include "sp-path.h"
-#include "style.h"
-#include "color.h"
-#include "display/curve.h"
-#include "libnr/n-art-bpath.h"
-#include "libnr/nr-point-matrix-ops.h"
-#include "gtk/gtk.h"
-#include "print.h"
-#include "glibmm/i18n.h"
-#include "extension/extension.h"
-#include "extension/system.h"
-#include "extension/print.h"
-#include "extension/db.h"
-#include "extension/output.h"
-#include "document.h"
-#include "display/nr-arena.h"
-#include "display/nr-arena-item.h"
-
-#include "libnr/nr-rect.h"
-#include "libnr/nr-matrix.h"
-#include "libnr/nr-pixblock.h"
-
-#include <stdio.h>
-#include <string.h>
-
-#include <vector>
-#include <string>
-
-#include "io/sys.h"
-
-#include "unit-constants.h"
-
-#include "clear-n_.h"
-
-
-#define PRINT_EMF_WIN32 "org.inkscape.print.emf.win32"
-
-#ifndef PS_JOIN_MASK
-#define PS_JOIN_MASK (PS_JOIN_BEVEL|PS_JOIN_MITER|PS_JOIN_ROUND)
-#endif
-
-
-namespace Inkscape {
-namespace Extension {
-namespace Internal {
-
-
-EmfWin32::EmfWin32 (void) // The null constructor
-{
- return;
-}
-
-
-EmfWin32::~EmfWin32 (void) //The destructor
-{
- return;
-}
-
-
-bool
-EmfWin32::check (Inkscape::Extension::Extension * module)
-{
- if (NULL == Inkscape::Extension::db.get(PRINT_EMF_WIN32))
- return FALSE;
- return TRUE;
-}
-
-
-static void
-emf_print_document_to_file(SPDocument *doc, gchar const *filename)
-{
- Inkscape::Extension::Print *mod;
- SPPrintContext context;
- gchar const *oldconst;
- gchar *oldoutput;
- unsigned int ret;
-
- sp_document_ensure_up_to_date(doc);
-
- mod = Inkscape::Extension::get_print(PRINT_EMF_WIN32);
- oldconst = mod->get_param_string("destination");
- oldoutput = g_strdup(oldconst);
- mod->set_param_string("destination", (gchar *)filename);
-
-/* Start */
- context.module = mod;
- /* fixme: This has to go into module constructor somehow */
- /* Create new arena */
- mod->base = SP_ITEM(sp_document_root(doc));
- mod->arena = NRArena::create();
- mod->dkey = sp_item_display_key_new(1);
- mod->root = sp_item_invoke_show(mod->base, mod->arena, mod->dkey, SP_ITEM_SHOW_DISPLAY);
- /* Print document */
- ret = mod->begin(doc);
- if (ret) {
- throw Inkscape::Extension::Output::save_failed();
- }
- sp_item_invoke_print(mod->base, &context);
- ret = mod->finish();
- /* Release arena */
- sp_item_invoke_hide(mod->base, mod->dkey);
- mod->base = NULL;
- nr_arena_item_unref(mod->root);
- mod->root = NULL;
- nr_object_unref((NRObject *) mod->arena);
- mod->arena = NULL;
-/* end */
-
- mod->set_param_string("destination", oldoutput);
- g_free(oldoutput);
-
- return;
-}
-
-
-void
-EmfWin32::save (Inkscape::Extension::Output *mod, SPDocument *doc, const gchar *uri)
-{
- Inkscape::Extension::Extension * ext;
-
- ext = Inkscape::Extension::db.get(PRINT_EMF_WIN32);
- if (ext == NULL)
- return;
-
-// bool old_textToPath = ext->get_param_bool("textToPath");
-// bool new_val = mod->get_param_bool("textToPath");
-// ext->set_param_bool("textToPath", new_val);
-
- gchar * final_name;
- final_name = g_strdup_printf("%s", uri);
- emf_print_document_to_file(doc, final_name);
- g_free(final_name);
-
-// ext->set_param_bool("textToPath", old_textToPath);
-
- return;
-}
-
-
-
-typedef struct {
- int type;
- ENHMETARECORD *lpEMFR;
-} EMF_OBJECT, *PEMF_OBJECT;
-
-typedef struct emf_callback_data {
- Glib::ustring *outsvg;
- Glib::ustring *path;
- struct SPStyle style;
- bool stroke_set;
- bool fill_set;
- double xDPI, yDPI;
-
- SIZEL sizeWnd;
- SIZEL sizeView;
- float PixelsX;
- float PixelsY;
- float MMX;
- float MMY;
- float dwInchesX;
- float dwInchesY;
- POINTL winorg;
- POINTL vieworg;
- double ScaleX, ScaleY;
-
- int n_obj;
- PEMF_OBJECT emf_obj;
-} EMF_CALLBACK_DATA, *PEMF_CALLBACK_DATA;
-
-
-static void
-output_style(PEMF_CALLBACK_DATA d, int iType)
-{
- SVGOStringStream tmp_style;
- char tmp[1024] = {0};
-
- *(d->outsvg) += "\n\tstyle=\"";
- if (iType == EMR_STROKEPATH || !d->fill_set) {
- tmp_style << "fill:none;";
- } else {
- float rgb[3];
- sp_color_get_rgb_floatv( &(d->style.fill.value.color), rgb );
- snprintf(tmp, 1023,
- "fill:#%02x%02x%02x;",
- SP_COLOR_F_TO_U(rgb[0]),
- SP_COLOR_F_TO_U(rgb[1]),
- SP_COLOR_F_TO_U(rgb[2]));
- tmp_style << tmp;
- snprintf(tmp, 1023,
- "fill-rule:%s;",
- d->style.fill_rule.value != 0 ? "evenodd" : "nonzero");
- tmp_style << tmp;
- tmp_style << "fill-opacity:1;";
- }
-
- if (iType == EMR_FILLPATH || !d->stroke_set) {
- tmp_style << "stroke:none;";
- } else {
- float rgb[3];
- sp_color_get_rgb_floatv(&(d->style.stroke.value.color), rgb);
- snprintf(tmp, 1023,
- "stroke:#%02x%02x%02x;",
- SP_COLOR_F_TO_U(rgb[0]),
- SP_COLOR_F_TO_U(rgb[1]),
- SP_COLOR_F_TO_U(rgb[2]));
- tmp_style << tmp;
-
- tmp_style << "stroke-width:" <<
- MAX( 0.001, d->style.stroke_width.value ) << "px;";
-
- tmp_style << "stroke-linejoin:" <<
- (d->style.stroke_linejoin.computed == 0 ? "miter" :
- d->style.stroke_linejoin.computed == 1 ? "round" :
- d->style.stroke_linejoin.computed == 2 ? "bevel" :
- "unknown") << ";";
-
- if (d->style.stroke_linejoin.computed == 0) {
- tmp_style << "stroke-miterlimit:" <<
- MAX( 0.01, d->style.stroke_miterlimit.value ) << ";";
- }
-
- if (d->style.stroke_dasharray_set &&
- d->style.stroke_dash.n_dash && d->style.stroke_dash.dash)
- {
- tmp_style << "stroke-dasharray:";
- for (int i=0; i<d->style.stroke_dash.n_dash; i++) {
- if (i)
- tmp_style << ",";
- tmp_style << d->style.stroke_dash.dash[i];
- }
- tmp_style << ";";
- tmp_style << "stroke-dashoffset:0;";
- } else {
- tmp_style << "stroke-dasharray:none;";
- }
- tmp_style << "stroke-opacity:1;";
- }
- tmp_style << "\" ";
-
- *(d->outsvg) += tmp_style.str().c_str();
-}
-
-
-static double
-pix_x_to_point(PEMF_CALLBACK_DATA d, double px)
-{
- double tmp = px - d->winorg.x;
- tmp *= (double) PX_PER_IN / d->ScaleX;
- tmp += d->vieworg.x;
- return tmp;
-}
-
-
-static double
-pix_y_to_point(PEMF_CALLBACK_DATA d, double px)
-{
- double tmp = px - d->winorg.y;
- tmp *= (double) PX_PER_IN / d->ScaleY;
- tmp += d->vieworg.y;
- return tmp;
-}
-
-
-static double
-pix_size_to_point(PEMF_CALLBACK_DATA d, double px)
-{
- double tmp = px;
- tmp *= (double) PX_PER_IN / d->ScaleX;
- return tmp;
-}
-
-
-static void
-select_pen(PEMF_CALLBACK_DATA d, int index)
-{
- PEMRCREATEPEN pEmr = NULL;
-
- if (index >= 0 && index < d->n_obj)
- pEmr = (PEMRCREATEPEN) d->emf_obj[index].lpEMFR;
-
- if (!pEmr)
- return;
-
- switch (pEmr->lopn.lopnStyle) {
- default:
- {
- d->style.stroke_dasharray_set = 0;
- break;
- }
- }
-
- if (pEmr->lopn.lopnWidth.x) {
- d->style.stroke_width.value = pix_size_to_point( d, pEmr->lopn.lopnWidth.x );
- } else { // this stroke should always be rendered as 1 pixel wide, independent of zoom level (can that be done in SVG?)
- d->style.stroke_width.value = 1.0;
- }
-
- double r, g, b;
- r = SP_COLOR_U_TO_F( GetRValue(pEmr->lopn.lopnColor) );
- g = SP_COLOR_U_TO_F( GetGValue(pEmr->lopn.lopnColor) );
- b = SP_COLOR_U_TO_F( GetBValue(pEmr->lopn.lopnColor) );
- sp_color_set_rgb_float( &(d->style.stroke.value.color), r,g,b );
-
- d->style.stroke_linejoin.computed = 1;
-
- d->stroke_set = true;
-}
-
-
-static void
-select_extpen(PEMF_CALLBACK_DATA d, int index)
-{
- PEMREXTCREATEPEN pEmr = NULL;
-
- if (index >= 0 && index < d->n_obj)
- pEmr = (PEMREXTCREATEPEN) d->emf_obj[index].lpEMFR;
-
- if (!pEmr)
- return;
-
- switch (pEmr->elp.elpPenStyle & PS_STYLE_MASK) {
- case PS_USERSTYLE:
- {
- if (pEmr->elp.elpNumEntries) {
- d->style.stroke_dash.n_dash = pEmr->elp.elpNumEntries;
- if (d->style.stroke_dash.dash)
- delete[] d->style.stroke_dash.dash;
- d->style.stroke_dash.dash = new double[pEmr->elp.elpNumEntries];
- for (unsigned int i=0; i<pEmr->elp.elpNumEntries; i++) {
- d->style.stroke_dash.dash[i] = pix_size_to_point( d, pEmr->elp.elpStyleEntry[i] );
- }
- d->style.stroke_dasharray_set = 1;
- } else {
- d->style.stroke_dasharray_set = 0;
- }
- break;
- }
- default:
- {
- d->style.stroke_dasharray_set = 0;
- break;
- }
- }
-
- switch (pEmr->elp.elpPenStyle & PS_ENDCAP_MASK) {
- case PS_ENDCAP_ROUND:
- {
- d->style.stroke_linecap.computed = 1;
- break;
- }
- case PS_ENDCAP_SQUARE:
- {
- d->style.stroke_linecap.computed = 2;
- break;
- }
- case PS_ENDCAP_FLAT:
- default:
- {
- d->style.stroke_linecap.computed = 0;
- break;
- }
- }
-
- switch (pEmr->elp.elpPenStyle & PS_JOIN_MASK) {
- case PS_JOIN_BEVEL:
- {
- d->style.stroke_linejoin.computed = 2;
- break;
- }
- case PS_JOIN_MITER:
- {
- d->style.stroke_linejoin.computed = 0;
- break;
- }
- case PS_JOIN_ROUND:
- default:
- {
- d->style.stroke_linejoin.computed = 1;
- break;
- }
- }
-
- d->style.stroke_width.value = pix_size_to_point( d, pEmr->elp.elpWidth );
-
- double r, g, b;
- r = SP_COLOR_U_TO_F( GetRValue(pEmr->elp.elpColor) );
- g = SP_COLOR_U_TO_F( GetGValue(pEmr->elp.elpColor) );
- b = SP_COLOR_U_TO_F( GetBValue(pEmr->elp.elpColor) );
-
- sp_color_set_rgb_float( &(d->style.stroke.value.color), r,g,b );
-
- d->stroke_set = true;
-}
-
-
-static void
-select_brush(PEMF_CALLBACK_DATA d, int index)
-{
- PEMRCREATEBRUSHINDIRECT pEmr = NULL;
-
- if (index >= 0 && index < d->n_obj)
- pEmr = (PEMRCREATEBRUSHINDIRECT) d->emf_obj[index].lpEMFR;
-
- if (!pEmr)
- return;
-
- if (pEmr->lb.lbStyle == BS_SOLID) {
- double r, g, b;
- r = SP_COLOR_U_TO_F( GetRValue(pEmr->lb.lbColor) );
- g = SP_COLOR_U_TO_F( GetGValue(pEmr->lb.lbColor) );
- b = SP_COLOR_U_TO_F( GetBValue(pEmr->lb.lbColor) );
- sp_color_set_rgb_float( &(d->style.fill.value.color), r,g,b );
- }
-
- d->fill_set = true;
-}
-
-
-static void
-delete_object(PEMF_CALLBACK_DATA d, int index)
-{
- if (index >= 0 && index < d->n_obj) {
- d->emf_obj[index].type = 0;
- if (d->emf_obj[index].lpEMFR)
- free(d->emf_obj[index].lpEMFR);
- d->emf_obj[index].lpEMFR = NULL;
- }
-}
-
-
-static void
-insert_object(PEMF_CALLBACK_DATA d, int index, int type, ENHMETARECORD *pObj)
-{
- if (index >= 0 && index < d->n_obj) {
- delete_object(d, index);
- d->emf_obj[index].type = type;
- d->emf_obj[index].lpEMFR = pObj;
- }
-}
-
-
-static int CALLBACK
-myEnhMetaFileProc(HDC hDC, HANDLETABLE *lpHTable, ENHMETARECORD *lpEMFR, int nObj, LPARAM lpData)
-{
- PEMF_CALLBACK_DATA d;
- SVGOStringStream tmp_outsvg;
- SVGOStringStream tmp_path;
- SVGOStringStream tmp_str;
-
- d = (PEMF_CALLBACK_DATA) lpData;
-
- switch (lpEMFR->iType)
- {
- case EMR_HEADER:
- {
- ENHMETAHEADER *pEmr = (ENHMETAHEADER *) lpEMFR;
- tmp_outsvg << "<svg\n";
-
- d->xDPI = 2540;
- d->yDPI = 2540;
-
- d->PixelsX = pEmr->rclFrame.right - pEmr->rclFrame.left;
- d->PixelsY = pEmr->rclFrame.bottom - pEmr->rclFrame.top;
-
- d->MMX = d->PixelsX / 100.0;
- d->MMY = d->PixelsY / 100.0;
-
- tmp_outsvg <<
- " width=\"" << d->MMX << "mm\"\n" <<
- " height=\"" << d->MMY << "mm\">\n";
-
- if (pEmr->nHandles) {
- d->n_obj = pEmr->nHandles;
- d->emf_obj = new EMF_OBJECT[d->n_obj];
- } else {
- d->emf_obj = NULL;
- }
-
- break;
- }
- case EMR_POLYBEZIER:
- {
- PEMRPOLYBEZIER pEmr = (PEMRPOLYBEZIER) lpEMFR;
- DWORD i,j;
-
- if (pEmr->cptl<4)
- break;
-
- *(d->outsvg) += " <path ";
- output_style(d, EMR_STROKEPATH);
- *(d->outsvg) += "\n\td=\"";
-
- tmp_str <<
- "\n\tM " <<
- pix_x_to_point( d, pEmr->aptl[0].x ) << " " <<
- pix_x_to_point( d, pEmr->aptl[0].y) << " ";
-
- for (i=1; i<pEmr->cptl; ) {
- tmp_str << "\n\tC ";
- for (j=0; j<3 && i<pEmr->cptl; j++,i++) {
- tmp_str <<
- pix_x_to_point( d, pEmr->aptl[i].x ) << " " <<
- pix_y_to_point( d, pEmr->aptl[i].y ) << " ";
- }
- }
-
- *(d->outsvg) += tmp_str.str().c_str();
- *(d->outsvg) += " \" /> \n";
-
- break;
- }
- case EMR_POLYGON:
- {
- EMRPOLYGON *pEmr = (EMRPOLYGON *) lpEMFR;
- DWORD i;
-
- if (pEmr->cptl < 2)
- break;
-
- *(d->outsvg) += " <path ";
- output_style(d, EMR_STROKEANDFILLPATH);
- *(d->outsvg) += "\n\td=\"";
-
- tmp_str <<
- "\n\tM " <<
- pix_x_to_point( d, pEmr->aptl[0].x ) << " " <<
- pix_y_to_point( d, pEmr->aptl[0].y ) << " ";
-
- for (i=1; i<pEmr->cptl; i++) {
- tmp_str <<
- "\n\tL " <<
- pix_x_to_point( d, pEmr->aptl[i].x ) << " " <<
- pix_y_to_point( d, pEmr->aptl[i].y ) << " ";
- }
-
- *(d->outsvg) += tmp_str.str().c_str();
- *(d->outsvg) += " z \" /> \n";
-
- break;
- }
- case EMR_POLYLINE:
- {
- EMRPOLYLINE *pEmr = (EMRPOLYLINE *) lpEMFR;
- DWORD i;
-
- if (pEmr->cptl<2)
- break;
-
- *(d->outsvg) += " <path ";
- output_style(d, EMR_STROKEPATH);
- *(d->outsvg) += "\n\td=\"";
-
- tmp_str <<
- "\n\tM " <<
- pix_x_to_point( d, pEmr->aptl[0].x ) << " " <<
- pix_y_to_point( d, pEmr->aptl[0].y ) << " ";
-
- for (i=1; i<pEmr->cptl; i++) {
- tmp_str <<
- "\n\tL " <<
- pix_x_to_point( d, pEmr->aptl[i].x ) << " " <<
- pix_y_to_point( d, pEmr->aptl[i].y ) << " ";
- }
-
- *(d->outsvg) += tmp_str.str().c_str();
- *(d->outsvg) += " \" /> \n";
-
- break;
- }
- case EMR_POLYBEZIERTO:
- {
- PEMRPOLYBEZIERTO pEmr = (PEMRPOLYBEZIERTO) lpEMFR;
- DWORD i,j;
-
- for (i=0; i<pEmr->cptl;) {
- tmp_path << "\n\tC ";
- for (j=0; j<3 && i<pEmr->cptl; j++,i++) {
- tmp_path <<
- pix_x_to_point( d, pEmr->aptl[i].x ) << " " <<
- pix_y_to_point( d, pEmr->aptl[i].y ) << " ";
- }
- }
-
- break;
- }
- case EMR_POLYLINETO:
- {
- PEMRPOLYLINETO pEmr = (PEMRPOLYLINETO) lpEMFR;
- DWORD i;
-
- for (i=0; i<pEmr->cptl;i++) {
- tmp_path <<
- "\n\tL " <<
- pix_x_to_point( d, pEmr->aptl[i].x ) << " " <<
- pix_y_to_point( d, pEmr->aptl[i].y ) << " ";
- }
-
- break;
- }
- case EMR_POLYPOLYLINE:
- break;
- case EMR_POLYPOLYGON:
- break;
- case EMR_SETWINDOWEXTEX:
- {
- PEMRSETWINDOWEXTEX pEmr = (PEMRSETWINDOWEXTEX) lpEMFR;
-
- d->sizeWnd = pEmr->szlExtent;
- d->PixelsX = d->sizeWnd.cx;
- d->PixelsY = d->sizeWnd.cy;
-
- d->ScaleX = d->xDPI / (100*d->MMX / d->PixelsX);
- d->ScaleY = d->yDPI / (100*d->MMY / d->PixelsY);
-
- break;
- }
- case EMR_SETWINDOWORGEX:
- {
- PEMRSETWINDOWORGEX pEmr = (PEMRSETWINDOWORGEX) lpEMFR;
- d->winorg = pEmr->ptlOrigin;
- break;
- }
- case EMR_SETVIEWPORTEXTEX:
- {
- PEMRSETVIEWPORTEXTEX pEmr = (PEMRSETVIEWPORTEXTEX) lpEMFR;
-
- d->sizeView = pEmr->szlExtent;
-
- if (d->sizeWnd.cx && d->sizeWnd.cy) {
- HDC hScreenDC = GetDC( NULL );
-
- float scrPixelsX = (float)GetDeviceCaps( hScreenDC, HORZRES );
- float scrPixelsY = (float)GetDeviceCaps( hScreenDC, VERTRES );
- float scrMMX = (float)GetDeviceCaps( hScreenDC, HORZSIZE );
- float scrMMY = (float)GetDeviceCaps( hScreenDC, VERTSIZE );
-
- ReleaseDC( NULL, hScreenDC );
-
- d->dwInchesX = d->sizeView.cx / (25.4f*scrPixelsX/scrMMX);
- d->dwInchesY = d->sizeView.cy / (25.4f*scrPixelsY/scrMMY);
- d->xDPI = d->sizeWnd.cx / d->dwInchesX;
- d->yDPI = d->sizeWnd.cy / d->dwInchesY;
-
- if (1) {
- d->xDPI = 2540;
- d->yDPI = 2540;
- d->dwInchesX = d->PixelsX / d->xDPI;
- d->dwInchesY = d->PixelsY / d->yDPI;
- d->ScaleX = d->xDPI;
- d->ScaleY = d->yDPI;
- }
-
- d->MMX = d->dwInchesX * MM_PER_IN;
- d->MMY = d->dwInchesY * MM_PER_IN;
- }
-
- break;
- }
- case EMR_SETVIEWPORTORGEX:
- {
- PEMRSETVIEWPORTORGEX pEmr = (PEMRSETVIEWPORTORGEX) lpEMFR;
- d->vieworg = pEmr->ptlOrigin;
- break;
- }
- case EMR_SETBRUSHORGEX:
- break;
- case EMR_EOF:
- {
- tmp_outsvg << "</svg>\n";
- break;
- }
- case EMR_SETPIXELV:
- break;
- case EMR_SETMAPPERFLAGS:
- break;
- case EMR_SETMAPMODE:
- break;
- case EMR_SETBKMODE:
- break;
- case EMR_SETPOLYFILLMODE:
- {
- PEMRSETPOLYFILLMODE pEmr = (PEMRSETPOLYFILLMODE) lpEMFR;
- d->style.fill_rule.value =
- (pEmr->iMode == WINDING ? 0 :
- pEmr->iMode == ALTERNATE ? 1 : 0);
- break;
- }
- case EMR_SETROP2:
- break;
- case EMR_SETSTRETCHBLTMODE:
- break;
- case EMR_SETTEXTALIGN:
- break;
- case EMR_SETCOLORADJUSTMENT:
- break;
- case EMR_SETTEXTCOLOR:
- break;
- case EMR_SETBKCOLOR:
- break;
- case EMR_OFFSETCLIPRGN:
- break;
- case EMR_MOVETOEX:
- {
- PEMRMOVETOEX pEmr = (PEMRMOVETOEX) lpEMFR;
- tmp_path <<
- "\n\tM " <<
- pix_x_to_point( d, pEmr->ptl.x ) << " " <<
- pix_y_to_point( d, pEmr->ptl.y ) << " ";
- break;
- }
- case EMR_SETMETARGN:
- break;
- case EMR_EXCLUDECLIPRECT:
- break;
- case EMR_INTERSECTCLIPRECT:
- break;
- case EMR_SCALEVIEWPORTEXTEX:
- break;
- case EMR_SCALEWINDOWEXTEX:
- break;
- case EMR_SAVEDC:
- break;
- case EMR_RESTOREDC:
- break;
- case EMR_SETWORLDTRANSFORM:
- break;
- case EMR_MODIFYWORLDTRANSFORM:
- break;
- case EMR_SELECTOBJECT:
- {
- PEMRSELECTOBJECT pEmr = (PEMRSELECTOBJECT) lpEMFR;
- unsigned int index = pEmr->ihObject;
-
- if (index >= ENHMETA_STOCK_OBJECT) {
- index -= ENHMETA_STOCK_OBJECT;
- switch (index) {
- case NULL_BRUSH:
- d->fill_set = false;
- break;
- case BLACK_BRUSH:
- case DKGRAY_BRUSH:
- case GRAY_BRUSH:
- case LTGRAY_BRUSH:
- case WHITE_BRUSH:
- {
- float val = 0;
- switch (index) {
- case BLACK_BRUSH:
- val = 0.0 / 255.0;
- break;
- case DKGRAY_BRUSH:
- val = 64.0 / 255.0;
- break;
- case GRAY_BRUSH:
- val = 128.0 / 255.0;
- break;
- case LTGRAY_BRUSH:
- val = 192.0 / 255.0;
- break;
- case WHITE_BRUSH:
- val = 255.0 / 255.0;
- break;
- }
- sp_color_set_rgb_float( &(d->style.fill.value.color), val,val,val );
-
- d->fill_set = true;
- break;
- }
- case NULL_PEN:
- d->stroke_set = false;
- break;
- case BLACK_PEN:
- case WHITE_PEN:
- {
- float val = index == BLACK_PEN ? 0 : 1;
- d->style.stroke_dasharray_set = 0;
- d->style.stroke_width.value = 1.0;
- sp_color_set_rgb_float( &(d->style.stroke.value.color), val,val,val );
-
- d->stroke_set = true;
-
- break;
- }
- }
- } else {
- if (index >= 0 && index < d->n_obj) {
- switch (d->emf_obj[index].type)
- {
- case EMR_CREATEPEN:
- select_pen(d, index);
- break;
- case EMR_CREATEBRUSHINDIRECT:
- select_brush(d, index);
- break;
- case EMR_EXTCREATEPEN:
- select_extpen(d, index);
- break;
- }
- }
- }
- break;
- }
- case EMR_CREATEPEN:
- {
- PEMRCREATEPEN pEmr = (PEMRCREATEPEN) lpEMFR;
- int index = pEmr->ihPen;
-
- EMRCREATEPEN *pPen =
- (EMRCREATEPEN *) malloc( sizeof(EMREXTCREATEPEN) );
- pPen->lopn = pEmr->lopn;
- insert_object(d, index, EMR_CREATEPEN, (ENHMETARECORD *) pPen);
-
- break;
- }
- case EMR_CREATEBRUSHINDIRECT:
- {
- PEMRCREATEBRUSHINDIRECT pEmr = (PEMRCREATEBRUSHINDIRECT) lpEMFR;
- int index = pEmr->ihBrush;
-
- EMRCREATEBRUSHINDIRECT *pBrush =
- (EMRCREATEBRUSHINDIRECT *) malloc( sizeof(EMRCREATEBRUSHINDIRECT) );
- pBrush->lb = pEmr->lb;
- insert_object(d, index, EMR_CREATEBRUSHINDIRECT, (ENHMETARECORD *) pBrush);
-
- break;
- }
- case EMR_DELETEOBJECT:
- break;
- case EMR_ANGLEARC:
- break;
- case EMR_ELLIPSE:
- break;
- case EMR_RECTANGLE:
- break;
- case EMR_ROUNDRECT:
- break;
- case EMR_ARC:
- break;
- case EMR_CHORD:
- break;
- case EMR_PIE:
- break;
- case EMR_SELECTPALETTE:
- break;
- case EMR_CREATEPALETTE:
- break;
- case EMR_SETPALETTEENTRIES:
- break;
- case EMR_RESIZEPALETTE:
- break;
- case EMR_REALIZEPALETTE:
- break;
- case EMR_EXTFLOODFILL:
- break;
- case EMR_LINETO:
- {
- PEMRLINETO pEmr = (PEMRLINETO) lpEMFR;
- tmp_path <<
- "\n\tL " <<
- pix_x_to_point( d, pEmr->ptl.x ) << " " <<
- pix_y_to_point( d, pEmr->ptl.y ) << " ";
- break;
- }
- case EMR_ARCTO:
- break;
- case EMR_POLYDRAW:
- break;
- case EMR_SETARCDIRECTION:
- break;
- case EMR_SETMITERLIMIT:
- {
- PEMRSETMITERLIMIT pEmr = (PEMRSETMITERLIMIT) lpEMFR;
- d->style.stroke_miterlimit.value = pix_size_to_point( d, pEmr->eMiterLimit );
-
- if (d->style.stroke_miterlimit.value < 1)
- d->style.stroke_miterlimit.value = 1.0;
-
- break;
- }
- case EMR_BEGINPATH:
- {
- tmp_path << " d=\"";
- *(d->path) = "";
- break;
- }
- case EMR_ENDPATH:
- {
- tmp_path << "\"";
- break;
- }
- case EMR_CLOSEFIGURE:
- {
- tmp_path << "\n\tz";
- break;
- }
- case EMR_FILLPATH:
- case EMR_STROKEANDFILLPATH:
- case EMR_STROKEPATH:
- {
- *(d->outsvg) += " <path ";
- output_style(d, lpEMFR->iType);
- *(d->outsvg) += "\n\t";
- *(d->outsvg) += *(d->path);
- *(d->outsvg) += " /> \n";
- break;
- }
- case EMR_FLATTENPATH:
- break;
- case EMR_WIDENPATH:
- break;
- case EMR_SELECTCLIPPATH:
- break;
- case EMR_ABORTPATH:
- break;
- case EMR_GDICOMMENT:
- break;
- case EMR_FILLRGN:
- break;
- case EMR_FRAMERGN:
- break;
- case EMR_INVERTRGN:
- break;
- case EMR_PAINTRGN:
- break;
- case EMR_EXTSELECTCLIPRGN:
- break;
- case EMR_BITBLT:
- break;
- case EMR_STRETCHBLT:
- break;
- case EMR_MASKBLT:
- break;
- case EMR_PLGBLT:
- break;
- case EMR_SETDIBITSTODEVICE:
- break;
- case EMR_STRETCHDIBITS:
- break;
- case EMR_EXTCREATEFONTINDIRECTW:
- break;
- case EMR_EXTTEXTOUTA:
- break;
- case EMR_EXTTEXTOUTW:
- break;
- case EMR_POLYBEZIER16:
- {
- PEMRPOLYBEZIER16 pEmr = (PEMRPOLYBEZIER16) lpEMFR;
- POINTS *apts = (POINTS *) pEmr->apts; // Bug in MinGW wingdi.h ?
- DWORD i,j;
-
- if (pEmr->cpts<4)
- break;
-
- *(d->outsvg) += " <path ";
- output_style(d, EMR_STROKEPATH);
- *(d->outsvg) += "\n\td=\"";
-
- tmp_str <<
- "\n\tM " <<
- pix_x_to_point( d, apts[0].x ) << " " <<
- pix_y_to_point( d, apts[0].y ) << " ";
-
- for (i=1; i<pEmr->cpts; ) {
- tmp_str << "\n\tC ";
- for (j=0; j<3 && i<pEmr->cpts; j++,i++) {
- tmp_str <<
- pix_x_to_point( d, apts[i].x ) << " " <<
- pix_y_to_point( d, apts[i].y ) << " ";
- }
- }
-
- *(d->outsvg) += tmp_str.str().c_str();
- *(d->outsvg) += " \" /> \n";
-
- break;
- }
- case EMR_POLYGON16:
- {
- PEMRPOLYGON16 pEmr = (PEMRPOLYGON16) lpEMFR;
- POINTS *apts = (POINTS *) pEmr->apts; // Bug in MinGW wingdi.h ?
- unsigned int i;
-
- *(d->outsvg) += "<path ";
- output_style(d, EMR_STROKEANDFILLPATH);
- *(d->outsvg) += "\n\td=\"";
-
- // skip the first point?
- tmp_path << "\n\tM " <<
- pix_x_to_point( d, apts[1].x ) << " " <<
- pix_y_to_point( d, apts[1].y ) << " ";
-
- for (i=2; i<pEmr->cpts; i++) {
- tmp_path << "\n\tL " <<
- pix_x_to_point( d, apts[i].x ) << " " <<
- pix_y_to_point( d, apts[i].y ) << " ";
- }
-
- *(d->outsvg) += tmp_path.str().c_str();
- *(d->outsvg) += " z \" /> \n";
-
- break;
- }
- case EMR_POLYLINE16:
- {
- EMRPOLYLINE16 *pEmr = (EMRPOLYLINE16 *) lpEMFR;
- POINTS *apts = (POINTS *) pEmr->apts; // Bug in MinGW wingdi.h ?
- DWORD i;
-
- if (pEmr->cpts<2)
- break;
-
- *(d->outsvg) += " <path ";
- output_style(d, EMR_STROKEPATH);
- *(d->outsvg) += "\n\td=\"";
-
- tmp_str <<
- "\n\tM " <<
- pix_x_to_point( d, apts[0].x ) << " " <<
- pix_y_to_point( d, apts[0].y ) << " ";
-
- for (i=1; i<pEmr->cpts; i++) {
- tmp_str <<
- "\n\tL " <<
- pix_x_to_point( d, apts[i].x ) << " " <<
- pix_y_to_point( d, apts[i].y ) << " ";
- }
-
- *(d->outsvg) += tmp_str.str().c_str();
- *(d->outsvg) += " \" /> \n";
-
- break;
- }
- case EMR_POLYBEZIERTO16:
- {
- PEMRPOLYBEZIERTO16 pEmr = (PEMRPOLYBEZIERTO16) lpEMFR;
- POINTS *apts = (POINTS *) pEmr->apts; // Bug in MinGW wingdi.h ?
- DWORD i,j;
-
- for (i=0; i<pEmr->cpts;) {
- tmp_path << "\n\tC ";
- for (j=0; j<3 && i<pEmr->cpts; j++,i++) {
- tmp_path <<
- pix_x_to_point( d, apts[i].x ) << " " <<
- pix_y_to_point( d, apts[i].y ) << " ";
- }
- }
-
- break;
- }
- case EMR_POLYLINETO16:
- {
- PEMRPOLYLINETO16 pEmr = (PEMRPOLYLINETO16) lpEMFR;
- POINTS *apts = (POINTS *) pEmr->apts; // Bug in MinGW wingdi.h ?
- DWORD i;
-
- for (i=0; i<pEmr->cpts;i++) {
- tmp_path <<
- "\n\tL " <<
- pix_x_to_point( d, apts[i].x ) << " " <<
- pix_y_to_point( d, apts[i].y ) << " ";
- }
-
- break;
- }
- case EMR_POLYPOLYLINE16:
- break;
- case EMR_POLYPOLYGON16:
- {
- PEMRPOLYPOLYGON16 pEmr = (PEMRPOLYPOLYGON16) lpEMFR;
- unsigned int n, i, j;
-
- *(d->outsvg) += "<path ";
- output_style(d, EMR_STROKEANDFILLPATH);
- *(d->outsvg) += "\n\td=\"";
-
- i = pEmr->nPolys-1; // ???
- for (n=0; n<pEmr->nPolys /*&& i<pEmr->cpts*/; n++) {
- SVGOStringStream poly_path;
-
- poly_path << "\n\tM " <<
- pix_x_to_point( d, pEmr->apts[i].x ) << " " <<
- pix_y_to_point( d, pEmr->apts[i].y ) << " ";
- i++;
-
- for (j=1; j<pEmr->aPolyCounts[n] /*&& i<pEmr->cpts*/; j++) {
- poly_path << "\n\tL " <<
- pix_x_to_point( d, pEmr->apts[i].x ) << " " <<
- pix_y_to_point( d, pEmr->apts[i].y ) << " ";
- i++;
- }
-
- *(d->outsvg) += poly_path.str().c_str();
- *(d->outsvg) += " z \n";
- }
-
- *(d->outsvg) += " \" /> \n";
- break;
- }
- case EMR_POLYDRAW16:
- break;
- case EMR_CREATEMONOBRUSH:
- break;
- case EMR_CREATEDIBPATTERNBRUSHPT:
- break;
- case EMR_EXTCREATEPEN:
- {
- PEMREXTCREATEPEN pEmr = (PEMREXTCREATEPEN) lpEMFR;
- int index = pEmr->ihPen;
-
- EMREXTCREATEPEN *pPen =
- (EMREXTCREATEPEN *) malloc( sizeof(EMREXTCREATEPEN) +
- sizeof(DWORD) * pEmr->elp.elpNumEntries );
- pPen->ihPen = pEmr->ihPen;
- pPen->offBmi = pEmr->offBmi;
- pPen->cbBmi = pEmr->cbBmi;
- pPen->offBits = pEmr->offBits;
- pPen->cbBits = pEmr->cbBits;
- pPen->elp = pEmr->elp;
- for (unsigned int i=0; i<pEmr->elp.elpNumEntries; i++) {
- pPen->elp.elpStyleEntry[i] = pEmr->elp.elpStyleEntry[i];
- }
- insert_object(d, index, EMR_EXTCREATEPEN, (ENHMETARECORD *) pPen);
-
- break;
- }
- case EMR_POLYTEXTOUTA:
- break;
- case EMR_POLYTEXTOUTW:
- break;
- case EMR_SETICMMODE:
- break;
- case EMR_CREATECOLORSPACE:
- break;
- case EMR_SETCOLORSPACE:
- break;
- case EMR_DELETECOLORSPACE:
- break;
- case EMR_GLSRECORD:
- break;
- case EMR_GLSBOUNDEDRECORD:
- break;
- case EMR_PIXELFORMAT:
- break;
- }
-
- *(d->outsvg) += tmp_outsvg.str().c_str();
- *(d->path) += tmp_path.str().c_str();
-
- return 1;
-}
-
-
-// Aldus Placeable Header ===================================================
-// Since we are a 32bit app, we have to be sure this structure compiles to
-// be identical to a 16 bit app's version. To do this, we use the #pragma
-// to adjust packing, we use a WORD for the hmf handle, and a SMALL_RECT
-// for the bbox rectangle.
-#pragma pack( push )
-#pragma pack( 2 )
-typedef struct
-{
- DWORD dwKey;
- WORD hmf;
- SMALL_RECT bbox;
- WORD wInch;
- DWORD dwReserved;
- WORD wCheckSum;
-} APMHEADER, *PAPMHEADER;
-#pragma pack( pop )
-
-
-SPDocument *
-EmfWin32::open( Inkscape::Extension::Input *mod, const gchar *uri )
-{
- EMF_CALLBACK_DATA d = {0};
-
- gsize bytesRead = 0;
- gsize bytesWritten = 0;
- GError* error = NULL;
- gchar *local_fn =
- g_filename_from_utf8( uri, -1, &bytesRead, &bytesWritten, &error );
-
- if (local_fn == NULL) {
- return NULL;
- }
-
- d.outsvg = new Glib::ustring("");
- d.path = new Glib::ustring("");
-
- CHAR *ansi_uri = (CHAR *) local_fn;
- gunichar2 *unicode_fn = g_utf8_to_utf16( local_fn, -1, NULL, NULL, NULL );
- WCHAR *unicode_uri = (WCHAR *) unicode_fn;
-
- // Try open as Enhanced Metafile
- HENHMETAFILE hemf;
- if (PrintWin32::is_os_wide())
- hemf = GetEnhMetaFileW(unicode_uri);
- else
- hemf = GetEnhMetaFileA(ansi_uri);
-
- if (!hemf) {
- // Try open as Windows Metafile
- HMETAFILE hmf;
- if (PrintWin32::is_os_wide())
- hmf = GetMetaFileW(unicode_uri);
- else
- hmf = GetMetaFileA(ansi_uri);
-
- METAFILEPICT mp;
- HDC hDC;
-
- if (!hmf) {
- if (PrintWin32::is_os_wide()) {
- WCHAR szTemp[MAX_PATH];
-
- DWORD dw = GetShortPathNameW( unicode_uri, szTemp, MAX_PATH );
- if (dw) {
- hmf = GetMetaFileW( szTemp );
- }
- } else {
- CHAR szTemp[MAX_PATH];
-
- DWORD dw = GetShortPathNameA( ansi_uri, szTemp, MAX_PATH );
- if (dw) {
- hmf = GetMetaFileA( szTemp );
- }
- }
- }
-
- if (hmf) {
- DWORD nSize = GetMetaFileBitsEx( hmf, 0, NULL );
- if (nSize) {
- BYTE *lpvData = new BYTE[nSize];
- if (lpvData) {
- DWORD dw = GetMetaFileBitsEx( hmf, nSize, lpvData );
- if (dw) {
- // Fill out a METAFILEPICT structure
- mp.mm = MM_ANISOTROPIC;
- mp.xExt = 1000;
- mp.yExt = 1000;
- mp.hMF = NULL;
- // Get a reference DC
- hDC = GetDC( NULL );
- // Make an enhanced metafile from the windows metafile
- hemf = SetWinMetaFileBits( nSize, lpvData, hDC, &mp );
- // Clean up
- ReleaseDC( NULL, hDC );
- }
- delete[] lpvData;
- }
- DeleteMetaFile( hmf );
- }
- } else {
- // Try open as Aldus Placeable Metafile
- HANDLE hFile;
- if (PrintWin32::is_os_wide())
- hFile = CreateFileW( unicode_uri, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL );
- else
- hFile = CreateFileA( ansi_uri, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL );
- if (hFile != INVALID_HANDLE_VALUE) {
- DWORD nSize = GetFileSize( hFile, NULL );
- if (nSize) {
- BYTE *lpvData = new BYTE[nSize];
- if (lpvData) {
- DWORD dw = ReadFile( hFile, lpvData, nSize, &nSize, NULL );
- if (dw) {
- if ( ((PAPMHEADER)lpvData)->dwKey == 0x9ac6cdd7l ) {
- // Fill out a METAFILEPICT structure
- mp.mm = MM_ANISOTROPIC;
- mp.xExt = ((PAPMHEADER)lpvData)->bbox.Right - ((PAPMHEADER)lpvData)->bbox.Left;
- mp.xExt = ( mp.xExt * 2540l ) / (DWORD)(((PAPMHEADER)lpvData)->wInch);
- mp.yExt = ((PAPMHEADER)lpvData)->bbox.Bottom - ((PAPMHEADER)lpvData)->bbox.Top;
- mp.yExt = ( mp.yExt * 2540l ) / (DWORD)(((PAPMHEADER)lpvData)->wInch);
- mp.hMF = NULL;
- // Get a reference DC
- hDC = GetDC( NULL );
- // Create an enhanced metafile from the bits
- hemf = SetWinMetaFileBits( nSize, lpvData+sizeof(APMHEADER), hDC, &mp );
- // Clean up
- ReleaseDC( NULL, hDC );
- }
- }
- delete[] lpvData;
- }
- }
- CloseHandle( hFile );
- }
- }
- }
-
- if (!hemf || !d.outsvg || !d.path) {
- if (d.outsvg)
- delete d.outsvg;
- if (d.path)
- delete d.path;
- if (local_fn)
- g_free(local_fn);
- if (unicode_fn)
- g_free(unicode_fn);
- return NULL;
- }
-
- EnumEnhMetaFile(NULL, hemf, myEnhMetaFileProc, (LPVOID) &d, NULL);
- DeleteEnhMetaFile(hemf);
-
-// std::cout << "SVG Output: " << std::endl << *(d.outsvg) << std::endl;
-
- SPDocument *doc = sp_document_new_from_mem(d.outsvg->c_str(), d.outsvg->length(), TRUE);
-
- delete d.outsvg;
- delete d.path;
-
- if (d.emf_obj) {
- int i;
- for (i=0; i<d.n_obj; i++)
- delete_object(&d, i);
- delete[] d.emf_obj;
- }
-
- if (d.style.stroke_dash.dash)
- delete[] d.style.stroke_dash.dash;
-
- if (local_fn)
- g_free(local_fn);
- if (unicode_fn)
- g_free(unicode_fn);
-
- return doc;
-}
-
-
-void
-EmfWin32::init (void)
-{
- Inkscape::Extension::Extension * ext;
-
- /* EMF in */
- ext = Inkscape::Extension::build_from_mem(
- "<inkscape-extension>\n"
- "<name>" N_("EMF Input") "</name>\n"
- "<id>org.inkscape.input.emf.win32</id>\n"
- "<input>\n"
- "<extension>.emf</extension>\n"
- "<mimetype>image/x-emf</mimetype>\n"
- "<filetypename>" N_("Enhanced Metafiles (*.emf)") "</filetypename>\n"
- "<filetypetooltip>" N_("Enhanced Metafiles") "</filetypetooltip>\n"
- "<output_extension>org.inkscape.output.emf.win32</output_extension>\n"
- "</input>\n"
- "</inkscape-extension>", new EmfWin32());
-
- /* WMF in */
- ext = Inkscape::Extension::build_from_mem(
- "<inkscape-extension>\n"
- "<name>" N_("WMF Input") "</name>\n"
- "<id>org.inkscape.input.wmf.win32</id>\n"
- "<input>\n"
- "<extension>.wmf</extension>\n"
- "<mimetype>image/x-wmf</mimetype>\n"
- "<filetypename>" N_("Windows Metafiles (*.wmf)") "</filetypename>\n"
- "<filetypetooltip>" N_("Windows Metafiles") "</filetypetooltip>\n"
- "<output_extension>org.inkscape.output.emf.win32</output_extension>\n"
- "</input>\n"
- "</inkscape-extension>", new EmfWin32());
-
- /* EMF out */
- ext = Inkscape::Extension::build_from_mem(
- "<inkscape-extension>\n"
- "<name>" N_("EMF Output") "</name>\n"
- "<id>org.inkscape.output.emf.win32</id>\n"
- "<output>\n"
- "<extension>.emf</extension>\n"
- "<mimetype>image/x-emf</mimetype>\n"
- "<filetypename>" N_("Enhanced Metafile (*.emf)") "</filetypename>\n"
- "<filetypetooltip>" N_("Enhanced Metafile") "</filetypetooltip>\n"
- "</output>\n"
- "</inkscape-extension>", new EmfWin32());
-
- return;
-}
-
-
-} } } /* namespace Inkscape, Extension, Implementation */
-
-
-#endif /* WIN32 */
-
-
-/*
- Local Variables:
- mode:cpp
- c-file-style:"stroustrup"
- c-file-offsets:((innamespace . 0)(inline-open . 0))
- indent-tabs-mode:nil
- fill-column:99
- End:
-*/
-// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :
+/** \file
+ * Enhanced Metafile Input and Output.
+ */
+/*
+ * Authors:
+ * Ulf Erikson <ulferikson@users.sf.net>
+ *
+ * Copyright (C) 2006 Authors
+ *
+ * Released under GNU GPL, read the file 'COPYING' for more information
+ */
+/*
+ * References:
+ * - How to Create & Play Enhanced Metafiles in Win32
+ * http://support.microsoft.com/kb/q145999/
+ * - INFO: Windows Metafile Functions & Aldus Placeable Metafiles
+ * http://support.microsoft.com/kb/q66949/
+ * - Metafile Functions
+ * http://msdn.microsoft.com/library/en-us/gdi/metafile_0whf.asp
+ * - Metafile Structures
+ * http://msdn.microsoft.com/library/en-us/gdi/metafile_5hkj.asp
+ */
+
+#ifdef WIN32
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include "win32.h"
+#include "emf-win32-print.h"
+#include "emf-win32-inout.h"
+#include "inkscape.h"
+#include "sp-path.h"
+#include "style.h"
+#include "color.h"
+#include "display/curve.h"
+#include "libnr/n-art-bpath.h"
+#include "libnr/nr-point-matrix-ops.h"
+#include "gtk/gtk.h"
+#include "print.h"
+#include "glibmm/i18n.h"
+#include "extension/extension.h"
+#include "extension/system.h"
+#include "extension/print.h"
+#include "extension/db.h"
+#include "extension/output.h"
+#include "document.h"
+#include "display/nr-arena.h"
+#include "display/nr-arena-item.h"
+
+#include "libnr/nr-rect.h"
+#include "libnr/nr-matrix.h"
+#include "libnr/nr-pixblock.h"
+
+#include <stdio.h>
+#include <string.h>
+
+#include <vector>
+#include <string>
+
+#include "io/sys.h"
+
+#include "unit-constants.h"
+
+#include "clear-n_.h"
+
+
+#define PRINT_EMF_WIN32 "org.inkscape.print.emf.win32"
+
+#ifndef PS_JOIN_MASK
+#define PS_JOIN_MASK (PS_JOIN_BEVEL|PS_JOIN_MITER|PS_JOIN_ROUND)
+#endif
+
+
+namespace Inkscape {
+namespace Extension {
+namespace Internal {
+
+
+EmfWin32::EmfWin32 (void) // The null constructor
+{
+ return;
+}
+
+
+EmfWin32::~EmfWin32 (void) //The destructor
+{
+ return;
+}
+
+
+bool
+EmfWin32::check (Inkscape::Extension::Extension * module)
+{
+ if (NULL == Inkscape::Extension::db.get(PRINT_EMF_WIN32))
+ return FALSE;
+ return TRUE;
+}
+
+
+static void
+emf_print_document_to_file(SPDocument *doc, gchar const *filename)
+{
+ Inkscape::Extension::Print *mod;
+ SPPrintContext context;
+ gchar const *oldconst;
+ gchar *oldoutput;
+ unsigned int ret;
+
+ sp_document_ensure_up_to_date(doc);
+
+ mod = Inkscape::Extension::get_print(PRINT_EMF_WIN32);
+ oldconst = mod->get_param_string("destination");
+ oldoutput = g_strdup(oldconst);
+ mod->set_param_string("destination", (gchar *)filename);
+
+/* Start */
+ context.module = mod;
+ /* fixme: This has to go into module constructor somehow */
+ /* Create new arena */
+ mod->base = SP_ITEM(sp_document_root(doc));
+ mod->arena = NRArena::create();
+ mod->dkey = sp_item_display_key_new(1);
+ mod->root = sp_item_invoke_show(mod->base, mod->arena, mod->dkey, SP_ITEM_SHOW_DISPLAY);
+ /* Print document */
+ ret = mod->begin(doc);
+ if (ret) {
+ throw Inkscape::Extension::Output::save_failed();
+ }
+ sp_item_invoke_print(mod->base, &context);
+ ret = mod->finish();
+ /* Release arena */
+ sp_item_invoke_hide(mod->base, mod->dkey);
+ mod->base = NULL;
+ nr_arena_item_unref(mod->root);
+ mod->root = NULL;
+ nr_object_unref((NRObject *) mod->arena);
+ mod->arena = NULL;
+/* end */
+
+ mod->set_param_string("destination", oldoutput);
+ g_free(oldoutput);
+
+ return;
+}
+
+
+void
+EmfWin32::save (Inkscape::Extension::Output *mod, SPDocument *doc, const gchar *uri)
+{
+ Inkscape::Extension::Extension * ext;
+
+ ext = Inkscape::Extension::db.get(PRINT_EMF_WIN32);
+ if (ext == NULL)
+ return;
+
+// bool old_textToPath = ext->get_param_bool("textToPath");
+// bool new_val = mod->get_param_bool("textToPath");
+// ext->set_param_bool("textToPath", new_val);
+
+ gchar * final_name;
+ final_name = g_strdup_printf("%s", uri);
+ emf_print_document_to_file(doc, final_name);
+ g_free(final_name);
+
+// ext->set_param_bool("textToPath", old_textToPath);
+
+ return;
+}
+
+
+
+typedef struct {
+ int type;
+ ENHMETARECORD *lpEMFR;
+} EMF_OBJECT, *PEMF_OBJECT;
+
+typedef struct emf_callback_data {
+ Glib::ustring *outsvg;
+ Glib::ustring *path;
+ struct SPStyle style;
+ bool stroke_set;
+ bool fill_set;
+ double xDPI, yDPI;
+
+ SIZEL sizeWnd;
+ SIZEL sizeView;
+ float PixelsX;
+ float PixelsY;
+ float MMX;
+ float MMY;
+ float dwInchesX;
+ float dwInchesY;
+ POINTL winorg;
+ POINTL vieworg;
+ double ScaleX, ScaleY;
+
+ int n_obj;
+ PEMF_OBJECT emf_obj;
+} EMF_CALLBACK_DATA, *PEMF_CALLBACK_DATA;
+
+
+static void
+output_style(PEMF_CALLBACK_DATA d, int iType)
+{
+ SVGOStringStream tmp_style;
+ char tmp[1024] = {0};
+
+ *(d->outsvg) += "\n\tstyle=\"";
+ if (iType == EMR_STROKEPATH || !d->fill_set) {
+ tmp_style << "fill:none;";
+ } else {
+ float rgb[3];
+ sp_color_get_rgb_floatv( &(d->style.fill.value.color), rgb );
+ snprintf(tmp, 1023,
+ "fill:#%02x%02x%02x;",
+ SP_COLOR_F_TO_U(rgb[0]),
+ SP_COLOR_F_TO_U(rgb[1]),
+ SP_COLOR_F_TO_U(rgb[2]));
+ tmp_style << tmp;
+ snprintf(tmp, 1023,
+ "fill-rule:%s;",
+ d->style.fill_rule.value != 0 ? "evenodd" : "nonzero");
+ tmp_style << tmp;
+ tmp_style << "fill-opacity:1;";
+ }
+
+ if (iType == EMR_FILLPATH || !d->stroke_set) {
+ tmp_style << "stroke:none;";
+ } else {
+ float rgb[3];
+ sp_color_get_rgb_floatv(&(d->style.stroke.value.color), rgb);
+ snprintf(tmp, 1023,
+ "stroke:#%02x%02x%02x;",
+ SP_COLOR_F_TO_U(rgb[0]),
+ SP_COLOR_F_TO_U(rgb[1]),
+ SP_COLOR_F_TO_U(rgb[2]));
+ tmp_style << tmp;
+
+ tmp_style << "stroke-width:" <<
+ MAX( 0.001, d->style.stroke_width.value ) << "px;";
+
+ tmp_style << "stroke-linejoin:" <<
+ (d->style.stroke_linejoin.computed == 0 ? "miter" :
+ d->style.stroke_linejoin.computed == 1 ? "round" :
+ d->style.stroke_linejoin.computed == 2 ? "bevel" :
+ "unknown") << ";";
+
+ if (d->style.stroke_linejoin.computed == 0) {
+ tmp_style << "stroke-miterlimit:" <<
+ MAX( 0.01, d->style.stroke_miterlimit.value ) << ";";
+ }
+
+ if (d->style.stroke_dasharray_set &&
+ d->style.stroke_dash.n_dash && d->style.stroke_dash.dash)
+ {
+ tmp_style << "stroke-dasharray:";
+ for (int i=0; i<d->style.stroke_dash.n_dash; i++) {
+ if (i)
+ tmp_style << ",";
+ tmp_style << d->style.stroke_dash.dash[i];
+ }
+ tmp_style << ";";
+ tmp_style << "stroke-dashoffset:0;";
+ } else {
+ tmp_style << "stroke-dasharray:none;";
+ }
+ tmp_style << "stroke-opacity:1;";
+ }
+ tmp_style << "\" ";
+
+ *(d->outsvg) += tmp_style.str().c_str();
+}
+
+
+static double
+pix_x_to_point(PEMF_CALLBACK_DATA d, double px)
+{
+ double tmp = px - d->winorg.x;
+ tmp *= (double) PX_PER_IN / d->ScaleX;
+ tmp += d->vieworg.x;
+ return tmp;
+}
+
+
+static double
+pix_y_to_point(PEMF_CALLBACK_DATA d, double px)
+{
+ double tmp = px - d->winorg.y;
+ tmp *= (double) PX_PER_IN / d->ScaleY;
+ tmp += d->vieworg.y;
+ return tmp;
+}
+
+
+static double
+pix_size_to_point(PEMF_CALLBACK_DATA d, double px)
+{
+ double tmp = px;
+ tmp *= (double) PX_PER_IN / d->ScaleX;
+ return tmp;
+}
+
+
+static void
+select_pen(PEMF_CALLBACK_DATA d, int index)
+{
+ PEMRCREATEPEN pEmr = NULL;
+
+ if (index >= 0 && index < d->n_obj)
+ pEmr = (PEMRCREATEPEN) d->emf_obj[index].lpEMFR;
+
+ if (!pEmr)
+ return;
+
+ switch (pEmr->lopn.lopnStyle) {
+ default:
+ {
+ d->style.stroke_dasharray_set = 0;
+ break;
+ }
+ }
+
+ if (pEmr->lopn.lopnWidth.x) {
+ d->style.stroke_width.value = pix_size_to_point( d, pEmr->lopn.lopnWidth.x );
+ } else { // this stroke should always be rendered as 1 pixel wide, independent of zoom level (can that be done in SVG?)
+ d->style.stroke_width.value = 1.0;
+ }
+
+ double r, g, b;
+ r = SP_COLOR_U_TO_F( GetRValue(pEmr->lopn.lopnColor) );
+ g = SP_COLOR_U_TO_F( GetGValue(pEmr->lopn.lopnColor) );
+ b = SP_COLOR_U_TO_F( GetBValue(pEmr->lopn.lopnColor) );
+ sp_color_set_rgb_float( &(d->style.stroke.value.color), r,g,b );
+
+ d->style.stroke_linejoin.computed = 1;
+
+ d->stroke_set = true;
+}
+
+
+static void
+select_extpen(PEMF_CALLBACK_DATA d, int index)
+{
+ PEMREXTCREATEPEN pEmr = NULL;
+
+ if (index >= 0 && index < d->n_obj)
+ pEmr = (PEMREXTCREATEPEN) d->emf_obj[index].lpEMFR;
+
+ if (!pEmr)
+ return;
+
+ switch (pEmr->elp.elpPenStyle & PS_STYLE_MASK) {
+ case PS_USERSTYLE:
+ {
+ if (pEmr->elp.elpNumEntries) {
+ d->style.stroke_dash.n_dash = pEmr->elp.elpNumEntries;
+ if (d->style.stroke_dash.dash)
+ delete[] d->style.stroke_dash.dash;
+ d->style.stroke_dash.dash = new double[pEmr->elp.elpNumEntries];
+ for (unsigned int i=0; i<pEmr->elp.elpNumEntries; i++) {
+ d->style.stroke_dash.dash[i] = pix_size_to_point( d, pEmr->elp.elpStyleEntry[i] );
+ }
+ d->style.stroke_dasharray_set = 1;
+ } else {
+ d->style.stroke_dasharray_set = 0;
+ }
+ break;
+ }
+ default:
+ {
+ d->style.stroke_dasharray_set = 0;
+ break;
+ }
+ }
+
+ switch (pEmr->elp.elpPenStyle & PS_ENDCAP_MASK) {
+ case PS_ENDCAP_ROUND:
+ {
+ d->style.stroke_linecap.computed = 1;
+ break;
+ }
+ case PS_ENDCAP_SQUARE:
+ {
+ d->style.stroke_linecap.computed = 2;
+ break;
+ }
+ case PS_ENDCAP_FLAT:
+ default:
+ {
+ d->style.stroke_linecap.computed = 0;
+ break;
+ }
+ }
+
+ switch (pEmr->elp.elpPenStyle & PS_JOIN_MASK) {
+ case PS_JOIN_BEVEL:
+ {
+ d->style.stroke_linejoin.computed = 2;
+ break;
+ }
+ case PS_JOIN_MITER:
+ {
+ d->style.stroke_linejoin.computed = 0;
+ break;
+ }
+ case PS_JOIN_ROUND:
+ default:
+ {
+ d->style.stroke_linejoin.computed = 1;
+ break;
+ }
+ }
+
+ d->style.stroke_width.value = pix_size_to_point( d, pEmr->elp.elpWidth );
+
+ double r, g, b;
+ r = SP_COLOR_U_TO_F( GetRValue(pEmr->elp.elpColor) );
+ g = SP_COLOR_U_TO_F( GetGValue(pEmr->elp.elpColor) );
+ b = SP_COLOR_U_TO_F( GetBValue(pEmr->elp.elpColor) );
+
+ sp_color_set_rgb_float( &(d->style.stroke.value.color), r,g,b );
+
+ d->stroke_set = true;
+}
+
+
+static void
+select_brush(PEMF_CALLBACK_DATA d, int index)
+{
+ PEMRCREATEBRUSHINDIRECT pEmr = NULL;
+
+ if (index >= 0 && index < d->n_obj)
+ pEmr = (PEMRCREATEBRUSHINDIRECT) d->emf_obj[index].lpEMFR;
+
+ if (!pEmr)
+ return;
+
+ if (pEmr->lb.lbStyle == BS_SOLID) {
+ double r, g, b;
+ r = SP_COLOR_U_TO_F( GetRValue(pEmr->lb.lbColor) );
+ g = SP_COLOR_U_TO_F( GetGValue(pEmr->lb.lbColor) );
+ b = SP_COLOR_U_TO_F( GetBValue(pEmr->lb.lbColor) );
+ sp_color_set_rgb_float( &(d->style.fill.value.color), r,g,b );
+ }
+
+ d->fill_set = true;
+}
+
+
+static void
+delete_object(PEMF_CALLBACK_DATA d, int index)
+{
+ if (index >= 0 && index < d->n_obj) {
+ d->emf_obj[index].type = 0;
+ if (d->emf_obj[index].lpEMFR)
+ free(d->emf_obj[index].lpEMFR);
+ d->emf_obj[index].lpEMFR = NULL;
+ }
+}
+
+
+static void
+insert_object(PEMF_CALLBACK_DATA d, int index, int type, ENHMETARECORD *pObj)
+{
+ if (index >= 0 && index < d->n_obj) {
+ delete_object(d, index);
+ d->emf_obj[index].type = type;
+ d->emf_obj[index].lpEMFR = pObj;
+ }
+}
+
+
+static int CALLBACK
+myEnhMetaFileProc(HDC hDC, HANDLETABLE *lpHTable, ENHMETARECORD *lpEMFR, int nObj, LPARAM lpData)
+{
+ PEMF_CALLBACK_DATA d;
+ SVGOStringStream tmp_outsvg;
+ SVGOStringStream tmp_path;
+ SVGOStringStream tmp_str;
+
+ d = (PEMF_CALLBACK_DATA) lpData;
+
+ switch (lpEMFR->iType)
+ {
+ case EMR_HEADER:
+ {
+ ENHMETAHEADER *pEmr = (ENHMETAHEADER *) lpEMFR;
+ tmp_outsvg << "<svg\n";
+
+ d->xDPI = 2540;
+ d->yDPI = 2540;
+
+ d->PixelsX = pEmr->rclFrame.right - pEmr->rclFrame.left;
+ d->PixelsY = pEmr->rclFrame.bottom - pEmr->rclFrame.top;
+
+ d->MMX = d->PixelsX / 100.0;
+ d->MMY = d->PixelsY / 100.0;
+
+ tmp_outsvg <<
+ " width=\"" << d->MMX << "mm\"\n" <<
+ " height=\"" << d->MMY << "mm\">\n";
+
+ if (pEmr->nHandles) {
+ d->n_obj = pEmr->nHandles;
+ d->emf_obj = new EMF_OBJECT[d->n_obj];
+ } else {
+ d->emf_obj = NULL;
+ }
+
+ break;
+ }
+ case EMR_POLYBEZIER:
+ {
+ PEMRPOLYBEZIER pEmr = (PEMRPOLYBEZIER) lpEMFR;
+ DWORD i,j;
+
+ if (pEmr->cptl<4)
+ break;
+
+ *(d->outsvg) += " <path ";
+ output_style(d, EMR_STROKEPATH);
+ *(d->outsvg) += "\n\td=\"";
+
+ tmp_str <<
+ "\n\tM " <<
+ pix_x_to_point( d, pEmr->aptl[0].x ) << " " <<
+ pix_x_to_point( d, pEmr->aptl[0].y) << " ";
+
+ for (i=1; i<pEmr->cptl; ) {
+ tmp_str << "\n\tC ";
+ for (j=0; j<3 && i<pEmr->cptl; j++,i++) {
+ tmp_str <<
+ pix_x_to_point( d, pEmr->aptl[i].x ) << " " <<
+ pix_y_to_point( d, pEmr->aptl[i].y ) << " ";
+ }
+ }
+
+ *(d->outsvg) += tmp_str.str().c_str();
+ *(d->outsvg) += " \" /> \n";
+
+ break;
+ }
+ case EMR_POLYGON:
+ {
+ EMRPOLYGON *pEmr = (EMRPOLYGON *) lpEMFR;
+ DWORD i;
+
+ if (pEmr->cptl < 2)
+ break;
+
+ *(d->outsvg) += " <path ";
+ output_style(d, EMR_STROKEANDFILLPATH);
+ *(d->outsvg) += "\n\td=\"";
+
+ tmp_str <<
+ "\n\tM " <<
+ pix_x_to_point( d, pEmr->aptl[0].x ) << " " <<
+ pix_y_to_point( d, pEmr->aptl[0].y ) << " ";
+
+ for (i=1; i<pEmr->cptl; i++) {
+ tmp_str <<
+ "\n\tL " <<
+ pix_x_to_point( d, pEmr->aptl[i].x ) << " " <<
+ pix_y_to_point( d, pEmr->aptl[i].y ) << " ";
+ }
+
+ *(d->outsvg) += tmp_str.str().c_str();
+ *(d->outsvg) += " z \" /> \n";
+
+ break;
+ }
+ case EMR_POLYLINE:
+ {
+ EMRPOLYLINE *pEmr = (EMRPOLYLINE *) lpEMFR;
+ DWORD i;
+
+ if (pEmr->cptl<2)
+ break;
+
+ *(d->outsvg) += " <path ";
+ output_style(d, EMR_STROKEPATH);
+ *(d->outsvg) += "\n\td=\"";
+
+ tmp_str <<
+ "\n\tM " <<
+ pix_x_to_point( d, pEmr->aptl[0].x ) << " " <<
+ pix_y_to_point( d, pEmr->aptl[0].y ) << " ";
+
+ for (i=1; i<pEmr->cptl; i++) {
+ tmp_str <<
+ "\n\tL " <<
+ pix_x_to_point( d, pEmr->aptl[i].x ) << " " <<
+ pix_y_to_point( d, pEmr->aptl[i].y ) << " ";
+ }
+
+ *(d->outsvg) += tmp_str.str().c_str();
+ *(d->outsvg) += " \" /> \n";
+
+ break;
+ }
+ case EMR_POLYBEZIERTO:
+ {
+ PEMRPOLYBEZIERTO pEmr = (PEMRPOLYBEZIERTO) lpEMFR;
+ DWORD i,j;
+
+ for (i=0; i<pEmr->cptl;) {
+ tmp_path << "\n\tC ";
+ for (j=0; j<3 && i<pEmr->cptl; j++,i++) {
+ tmp_path <<
+ pix_x_to_point( d, pEmr->aptl[i].x ) << " " <<
+ pix_y_to_point( d, pEmr->aptl[i].y ) << " ";
+ }
+ }
+
+ break;
+ }
+ case EMR_POLYLINETO:
+ {
+ PEMRPOLYLINETO pEmr = (PEMRPOLYLINETO) lpEMFR;
+ DWORD i;
+
+ for (i=0; i<pEmr->cptl;i++) {
+ tmp_path <<
+ "\n\tL " <<
+ pix_x_to_point( d, pEmr->aptl[i].x ) << " " <<
+ pix_y_to_point( d, pEmr->aptl[i].y ) << " ";
+ }
+
+ break;
+ }
+ case EMR_POLYPOLYLINE:
+ break;
+ case EMR_POLYPOLYGON:
+ break;
+ case EMR_SETWINDOWEXTEX:
+ {
+ PEMRSETWINDOWEXTEX pEmr = (PEMRSETWINDOWEXTEX) lpEMFR;
+
+ d->sizeWnd = pEmr->szlExtent;
+ d->PixelsX = d->sizeWnd.cx;
+ d->PixelsY = d->sizeWnd.cy;
+
+ d->ScaleX = d->xDPI / (100*d->MMX / d->PixelsX);
+ d->ScaleY = d->yDPI / (100*d->MMY / d->PixelsY);
+
+ break;
+ }
+ case EMR_SETWINDOWORGEX:
+ {
+ PEMRSETWINDOWORGEX pEmr = (PEMRSETWINDOWORGEX) lpEMFR;
+ d->winorg = pEmr->ptlOrigin;
+ break;
+ }
+ case EMR_SETVIEWPORTEXTEX:
+ {
+ PEMRSETVIEWPORTEXTEX pEmr = (PEMRSETVIEWPORTEXTEX) lpEMFR;
+
+ d->sizeView = pEmr->szlExtent;
+
+ if (d->sizeWnd.cx && d->sizeWnd.cy) {
+ HDC hScreenDC = GetDC( NULL );
+
+ float scrPixelsX = (float)GetDeviceCaps( hScreenDC, HORZRES );
+ float scrPixelsY = (float)GetDeviceCaps( hScreenDC, VERTRES );
+ float scrMMX = (float)GetDeviceCaps( hScreenDC, HORZSIZE );
+ float scrMMY = (float)GetDeviceCaps( hScreenDC, VERTSIZE );
+
+ ReleaseDC( NULL, hScreenDC );
+
+ d->dwInchesX = d->sizeView.cx / (25.4f*scrPixelsX/scrMMX);
+ d->dwInchesY = d->sizeView.cy / (25.4f*scrPixelsY/scrMMY);
+ d->xDPI = d->sizeWnd.cx / d->dwInchesX;
+ d->yDPI = d->sizeWnd.cy / d->dwInchesY;
+
+ if (1) {
+ d->xDPI = 2540;
+ d->yDPI = 2540;
+ d->dwInchesX = d->PixelsX / d->xDPI;
+ d->dwInchesY = d->PixelsY / d->yDPI;
+ d->ScaleX = d->xDPI;
+ d->ScaleY = d->yDPI;
+ }
+
+ d->MMX = d->dwInchesX * MM_PER_IN;
+ d->MMY = d->dwInchesY * MM_PER_IN;
+ }
+
+ break;
+ }
+ case EMR_SETVIEWPORTORGEX:
+ {
+ PEMRSETVIEWPORTORGEX pEmr = (PEMRSETVIEWPORTORGEX) lpEMFR;
+ d->vieworg = pEmr->ptlOrigin;
+ break;
+ }
+ case EMR_SETBRUSHORGEX:
+ break;
+ case EMR_EOF:
+ {
+ tmp_outsvg << "</svg>\n";
+ break;
+ }
+ case EMR_SETPIXELV:
+ break;
+ case EMR_SETMAPPERFLAGS:
+ break;
+ case EMR_SETMAPMODE:
+ break;
+ case EMR_SETBKMODE:
+ break;
+ case EMR_SETPOLYFILLMODE:
+ {
+ PEMRSETPOLYFILLMODE pEmr = (PEMRSETPOLYFILLMODE) lpEMFR;
+ d->style.fill_rule.value =
+ (pEmr->iMode == WINDING ? 0 :
+ pEmr->iMode == ALTERNATE ? 1 : 0);
+ break;
+ }
+ case EMR_SETROP2:
+ break;
+ case EMR_SETSTRETCHBLTMODE:
+ break;
+ case EMR_SETTEXTALIGN:
+ break;
+ case EMR_SETCOLORADJUSTMENT:
+ break;
+ case EMR_SETTEXTCOLOR:
+ break;
+ case EMR_SETBKCOLOR:
+ break;
+ case EMR_OFFSETCLIPRGN:
+ break;
+ case EMR_MOVETOEX:
+ {
+ PEMRMOVETOEX pEmr = (PEMRMOVETOEX) lpEMFR;
+ tmp_path <<
+ "\n\tM " <<
+ pix_x_to_point( d, pEmr->ptl.x ) << " " <<
+ pix_y_to_point( d, pEmr->ptl.y ) << " ";
+ break;
+ }
+ case EMR_SETMETARGN:
+ break;
+ case EMR_EXCLUDECLIPRECT:
+ break;
+ case EMR_INTERSECTCLIPRECT:
+ break;
+ case EMR_SCALEVIEWPORTEXTEX:
+ break;
+ case EMR_SCALEWINDOWEXTEX:
+ break;
+ case EMR_SAVEDC:
+ break;
+ case EMR_RESTOREDC:
+ break;
+ case EMR_SETWORLDTRANSFORM:
+ break;
+ case EMR_MODIFYWORLDTRANSFORM:
+ break;
+ case EMR_SELECTOBJECT:
+ {
+ PEMRSELECTOBJECT pEmr = (PEMRSELECTOBJECT) lpEMFR;
+ unsigned int index = pEmr->ihObject;
+
+ if (index >= ENHMETA_STOCK_OBJECT) {
+ index -= ENHMETA_STOCK_OBJECT;
+ switch (index) {
+ case NULL_BRUSH:
+ d->fill_set = false;
+ break;
+ case BLACK_BRUSH:
+ case DKGRAY_BRUSH:
+ case GRAY_BRUSH:
+ case LTGRAY_BRUSH:
+ case WHITE_BRUSH:
+ {
+ float val = 0;
+ switch (index) {
+ case BLACK_BRUSH:
+ val = 0.0 / 255.0;
+ break;
+ case DKGRAY_BRUSH:
+ val = 64.0 / 255.0;
+ break;
+ case GRAY_BRUSH:
+ val = 128.0 / 255.0;
+ break;
+ case LTGRAY_BRUSH:
+ val = 192.0 / 255.0;
+ break;
+ case WHITE_BRUSH:
+ val = 255.0 / 255.0;
+ break;
+ }
+ sp_color_set_rgb_float( &(d->style.fill.value.color), val,val,val );
+
+ d->fill_set = true;
+ break;
+ }
+ case NULL_PEN:
+ d->stroke_set = false;
+ break;
+ case BLACK_PEN:
+ case WHITE_PEN:
+ {
+ float val = index == BLACK_PEN ? 0 : 1;
+ d->style.stroke_dasharray_set = 0;
+ d->style.stroke_width.value = 1.0;
+ sp_color_set_rgb_float( &(d->style.stroke.value.color), val,val,val );
+
+ d->stroke_set = true;
+
+ break;
+ }
+ }
+ } else {
+ if (index >= 0 && index < d->n_obj) {
+ switch (d->emf_obj[index].type)
+ {
+ case EMR_CREATEPEN:
+ select_pen(d, index);
+ break;
+ case EMR_CREATEBRUSHINDIRECT:
+ select_brush(d, index);
+ break;
+ case EMR_EXTCREATEPEN:
+ select_extpen(d, index);
+ break;
+ }
+ }
+ }
+ break;
+ }
+ case EMR_CREATEPEN:
+ {
+ PEMRCREATEPEN pEmr = (PEMRCREATEPEN) lpEMFR;
+ int index = pEmr->ihPen;
+
+ EMRCREATEPEN *pPen =
+ (EMRCREATEPEN *) malloc( sizeof(EMREXTCREATEPEN) );
+ pPen->lopn = pEmr->lopn;
+ insert_object(d, index, EMR_CREATEPEN, (ENHMETARECORD *) pPen);
+
+ break;
+ }
+ case EMR_CREATEBRUSHINDIRECT:
+ {
+ PEMRCREATEBRUSHINDIRECT pEmr = (PEMRCREATEBRUSHINDIRECT) lpEMFR;
+ int index = pEmr->ihBrush;
+
+ EMRCREATEBRUSHINDIRECT *pBrush =
+ (EMRCREATEBRUSHINDIRECT *) malloc( sizeof(EMRCREATEBRUSHINDIRECT) );
+ pBrush->lb = pEmr->lb;
+ insert_object(d, index, EMR_CREATEBRUSHINDIRECT, (ENHMETARECORD *) pBrush);
+
+ break;
+ }
+ case EMR_DELETEOBJECT:
+ break;
+ case EMR_ANGLEARC:
+ break;
+ case EMR_ELLIPSE:
+ break;
+ case EMR_RECTANGLE:
+ break;
+ case EMR_ROUNDRECT:
+ break;
+ case EMR_ARC:
+ break;
+ case EMR_CHORD:
+ break;
+ case EMR_PIE:
+ break;
+ case EMR_SELECTPALETTE:
+ break;
+ case EMR_CREATEPALETTE:
+ break;
+ case EMR_SETPALETTEENTRIES:
+ break;
+ case EMR_RESIZEPALETTE:
+ break;
+ case EMR_REALIZEPALETTE:
+ break;
+ case EMR_EXTFLOODFILL:
+ break;
+ case EMR_LINETO:
+ {
+ PEMRLINETO pEmr = (PEMRLINETO) lpEMFR;
+ tmp_path <<
+ "\n\tL " <<
+ pix_x_to_point( d, pEmr->ptl.x ) << " " <<
+ pix_y_to_point( d, pEmr->ptl.y ) << " ";
+ break;
+ }
+ case EMR_ARCTO:
+ break;
+ case EMR_POLYDRAW:
+ break;
+ case EMR_SETARCDIRECTION:
+ break;
+ case EMR_SETMITERLIMIT:
+ {
+ PEMRSETMITERLIMIT pEmr = (PEMRSETMITERLIMIT) lpEMFR;
+ d->style.stroke_miterlimit.value = pix_size_to_point( d, pEmr->eMiterLimit );
+
+ if (d->style.stroke_miterlimit.value < 1)
+ d->style.stroke_miterlimit.value = 1.0;
+
+ break;
+ }
+ case EMR_BEGINPATH:
+ {
+ tmp_path << " d=\"";
+ *(d->path) = "";
+ break;
+ }
+ case EMR_ENDPATH:
+ {
+ tmp_path << "\"";
+ break;
+ }
+ case EMR_CLOSEFIGURE:
+ {
+ tmp_path << "\n\tz";
+ break;
+ }
+ case EMR_FILLPATH:
+ case EMR_STROKEANDFILLPATH:
+ case EMR_STROKEPATH:
+ {
+ *(d->outsvg) += " <path ";
+ output_style(d, lpEMFR->iType);
+ *(d->outsvg) += "\n\t";
+ *(d->outsvg) += *(d->path);
+ *(d->outsvg) += " /> \n";
+ break;
+ }
+ case EMR_FLATTENPATH:
+ break;
+ case EMR_WIDENPATH:
+ break;
+ case EMR_SELECTCLIPPATH:
+ break;
+ case EMR_ABORTPATH:
+ break;
+ case EMR_GDICOMMENT:
+ break;
+ case EMR_FILLRGN:
+ break;
+ case EMR_FRAMERGN:
+ break;
+ case EMR_INVERTRGN:
+ break;
+ case EMR_PAINTRGN:
+ break;
+ case EMR_EXTSELECTCLIPRGN:
+ break;
+ case EMR_BITBLT:
+ break;
+ case EMR_STRETCHBLT:
+ break;
+ case EMR_MASKBLT:
+ break;
+ case EMR_PLGBLT:
+ break;
+ case EMR_SETDIBITSTODEVICE:
+ break;
+ case EMR_STRETCHDIBITS:
+ break;
+ case EMR_EXTCREATEFONTINDIRECTW:
+ break;
+ case EMR_EXTTEXTOUTA:
+ break;
+ case EMR_EXTTEXTOUTW:
+ break;
+ case EMR_POLYBEZIER16:
+ {
+ PEMRPOLYBEZIER16 pEmr = (PEMRPOLYBEZIER16) lpEMFR;
+ POINTS *apts = (POINTS *) pEmr->apts; // Bug in MinGW wingdi.h ?
+ DWORD i,j;
+
+ if (pEmr->cpts<4)
+ break;
+
+ *(d->outsvg) += " <path ";
+ output_style(d, EMR_STROKEPATH);
+ *(d->outsvg) += "\n\td=\"";
+
+ tmp_str <<
+ "\n\tM " <<
+ pix_x_to_point( d, apts[0].x ) << " " <<
+ pix_y_to_point( d, apts[0].y ) << " ";
+
+ for (i=1; i<pEmr->cpts; ) {
+ tmp_str << "\n\tC ";
+ for (j=0; j<3 && i<pEmr->cpts; j++,i++) {
+ tmp_str <<
+ pix_x_to_point( d, apts[i].x ) << " " <<
+ pix_y_to_point( d, apts[i].y ) << " ";
+ }
+ }
+
+ *(d->outsvg) += tmp_str.str().c_str();
+ *(d->outsvg) += " \" /> \n";
+
+ break;
+ }
+ case EMR_POLYGON16:
+ {
+ PEMRPOLYGON16 pEmr = (PEMRPOLYGON16) lpEMFR;
+ POINTS *apts = (POINTS *) pEmr->apts; // Bug in MinGW wingdi.h ?
+ unsigned int i;
+
+ *(d->outsvg) += "<path ";
+ output_style(d, EMR_STROKEANDFILLPATH);
+ *(d->outsvg) += "\n\td=\"";
+
+ // skip the first point?
+ tmp_path << "\n\tM " <<
+ pix_x_to_point( d, apts[1].x ) << " " <<
+ pix_y_to_point( d, apts[1].y ) << " ";
+
+ for (i=2; i<pEmr->cpts; i++) {
+ tmp_path << "\n\tL " <<
+ pix_x_to_point( d, apts[i].x ) << " " <<
+ pix_y_to_point( d, apts[i].y ) << " ";
+ }
+
+ *(d->outsvg) += tmp_path.str().c_str();
+ *(d->outsvg) += " z \" /> \n";
+
+ break;
+ }
+ case EMR_POLYLINE16:
+ {
+ EMRPOLYLINE16 *pEmr = (EMRPOLYLINE16 *) lpEMFR;
+ POINTS *apts = (POINTS *) pEmr->apts; // Bug in MinGW wingdi.h ?
+ DWORD i;
+
+ if (pEmr->cpts<2)
+ break;
+
+ *(d->outsvg) += " <path ";
+ output_style(d, EMR_STROKEPATH);
+ *(d->outsvg) += "\n\td=\"";
+
+ tmp_str <<
+ "\n\tM " <<
+ pix_x_to_point( d, apts[0].x ) << " " <<
+ pix_y_to_point( d, apts[0].y ) << " ";
+
+ for (i=1; i<pEmr->cpts; i++) {
+ tmp_str <<
+ "\n\tL " <<
+ pix_x_to_point( d, apts[i].x ) << " " <<
+ pix_y_to_point( d, apts[i].y ) << " ";
+ }
+
+ *(d->outsvg) += tmp_str.str().c_str();
+ *(d->outsvg) += " \" /> \n";
+
+ break;
+ }
+ case EMR_POLYBEZIERTO16:
+ {
+ PEMRPOLYBEZIERTO16 pEmr = (PEMRPOLYBEZIERTO16) lpEMFR;
+ POINTS *apts = (POINTS *) pEmr->apts; // Bug in MinGW wingdi.h ?
+ DWORD i,j;
+
+ for (i=0; i<pEmr->cpts;) {
+ tmp_path << "\n\tC ";
+ for (j=0; j<3 && i<pEmr->cpts; j++,i++) {
+ tmp_path <<
+ pix_x_to_point( d, apts[i].x ) << " " <<
+ pix_y_to_point( d, apts[i].y ) << " ";
+ }
+ }
+
+ break;
+ }
+ case EMR_POLYLINETO16:
+ {
+ PEMRPOLYLINETO16 pEmr = (PEMRPOLYLINETO16) lpEMFR;
+ POINTS *apts = (POINTS *) pEmr->apts; // Bug in MinGW wingdi.h ?
+ DWORD i;
+
+ for (i=0; i<pEmr->cpts;i++) {
+ tmp_path <<
+ "\n\tL " <<
+ pix_x_to_point( d, apts[i].x ) << " " <<
+ pix_y_to_point( d, apts[i].y ) << " ";
+ }
+
+ break;
+ }
+ case EMR_POLYPOLYLINE16:
+ break;
+ case EMR_POLYPOLYGON16:
+ {
+ PEMRPOLYPOLYGON16 pEmr = (PEMRPOLYPOLYGON16) lpEMFR;
+ unsigned int n, i, j;
+
+ *(d->outsvg) += "<path ";
+ output_style(d, EMR_STROKEANDFILLPATH);
+ *(d->outsvg) += "\n\td=\"";
+
+ i = pEmr->nPolys-1; // ???
+ for (n=0; n<pEmr->nPolys /*&& i<pEmr->cpts*/; n++) {
+ SVGOStringStream poly_path;
+
+ poly_path << "\n\tM " <<
+ pix_x_to_point( d, pEmr->apts[i].x ) << " " <<
+ pix_y_to_point( d, pEmr->apts[i].y ) << " ";
+ i++;
+
+ for (j=1; j<pEmr->aPolyCounts[n] /*&& i<pEmr->cpts*/; j++) {
+ poly_path << "\n\tL " <<
+ pix_x_to_point( d, pEmr->apts[i].x ) << " " <<
+ pix_y_to_point( d, pEmr->apts[i].y ) << " ";
+ i++;
+ }
+
+ *(d->outsvg) += poly_path.str().c_str();
+ *(d->outsvg) += " z \n";
+ }
+
+ *(d->outsvg) += " \" /> \n";
+ break;
+ }
+ case EMR_POLYDRAW16:
+ break;
+ case EMR_CREATEMONOBRUSH:
+ break;
+ case EMR_CREATEDIBPATTERNBRUSHPT:
+ break;
+ case EMR_EXTCREATEPEN:
+ {
+ PEMREXTCREATEPEN pEmr = (PEMREXTCREATEPEN) lpEMFR;
+ int index = pEmr->ihPen;
+
+ EMREXTCREATEPEN *pPen =
+ (EMREXTCREATEPEN *) malloc( sizeof(EMREXTCREATEPEN) +
+ sizeof(DWORD) * pEmr->elp.elpNumEntries );
+ pPen->ihPen = pEmr->ihPen;
+ pPen->offBmi = pEmr->offBmi;
+ pPen->cbBmi = pEmr->cbBmi;
+ pPen->offBits = pEmr->offBits;
+ pPen->cbBits = pEmr->cbBits;
+ pPen->elp = pEmr->elp;
+ for (unsigned int i=0; i<pEmr->elp.elpNumEntries; i++) {
+ pPen->elp.elpStyleEntry[i] = pEmr->elp.elpStyleEntry[i];
+ }
+ insert_object(d, index, EMR_EXTCREATEPEN, (ENHMETARECORD *) pPen);
+
+ break;
+ }
+ case EMR_POLYTEXTOUTA:
+ break;
+ case EMR_POLYTEXTOUTW:
+ break;
+ case EMR_SETICMMODE:
+ break;
+ case EMR_CREATECOLORSPACE:
+ break;
+ case EMR_SETCOLORSPACE:
+ break;
+ case EMR_DELETECOLORSPACE:
+ break;
+ case EMR_GLSRECORD:
+ break;
+ case EMR_GLSBOUNDEDRECORD:
+ break;
+ case EMR_PIXELFORMAT:
+ break;
+ }
+
+ *(d->outsvg) += tmp_outsvg.str().c_str();
+ *(d->path) += tmp_path.str().c_str();
+
+ return 1;
+}
+
+
+// Aldus Placeable Header ===================================================
+// Since we are a 32bit app, we have to be sure this structure compiles to
+// be identical to a 16 bit app's version. To do this, we use the #pragma
+// to adjust packing, we use a WORD for the hmf handle, and a SMALL_RECT
+// for the bbox rectangle.
+#pragma pack( push )
+#pragma pack( 2 )
+typedef struct
+{
+ DWORD dwKey;
+ WORD hmf;
+ SMALL_RECT bbox;
+ WORD wInch;
+ DWORD dwReserved;
+ WORD wCheckSum;
+} APMHEADER, *PAPMHEADER;
+#pragma pack( pop )
+
+
+SPDocument *
+EmfWin32::open( Inkscape::Extension::Input *mod, const gchar *uri )
+{
+ EMF_CALLBACK_DATA d = {0};
+
+ gsize bytesRead = 0;
+ gsize bytesWritten = 0;
+ GError* error = NULL;
+ gchar *local_fn =
+ g_filename_from_utf8( uri, -1, &bytesRead, &bytesWritten, &error );
+
+ if (local_fn == NULL) {
+ return NULL;
+ }
+
+ d.outsvg = new Glib::ustring("");
+ d.path = new Glib::ustring("");
+
+ CHAR *ansi_uri = (CHAR *) local_fn;
+ gunichar2 *unicode_fn = g_utf8_to_utf16( local_fn, -1, NULL, NULL, NULL );
+ WCHAR *unicode_uri = (WCHAR *) unicode_fn;
+
+ // Try open as Enhanced Metafile
+ HENHMETAFILE hemf;
+ if (PrintWin32::is_os_wide())
+ hemf = GetEnhMetaFileW(unicode_uri);
+ else
+ hemf = GetEnhMetaFileA(ansi_uri);
+
+ if (!hemf) {
+ // Try open as Windows Metafile
+ HMETAFILE hmf;
+ if (PrintWin32::is_os_wide())
+ hmf = GetMetaFileW(unicode_uri);
+ else
+ hmf = GetMetaFileA(ansi_uri);
+
+ METAFILEPICT mp;
+ HDC hDC;
+
+ if (!hmf) {
+ if (PrintWin32::is_os_wide()) {
+ WCHAR szTemp[MAX_PATH];
+
+ DWORD dw = GetShortPathNameW( unicode_uri, szTemp, MAX_PATH );
+ if (dw) {
+ hmf = GetMetaFileW( szTemp );
+ }
+ } else {
+ CHAR szTemp[MAX_PATH];
+
+ DWORD dw = GetShortPathNameA( ansi_uri, szTemp, MAX_PATH );
+ if (dw) {
+ hmf = GetMetaFileA( szTemp );
+ }
+ }
+ }
+
+ if (hmf) {
+ DWORD nSize = GetMetaFileBitsEx( hmf, 0, NULL );
+ if (nSize) {
+ BYTE *lpvData = new BYTE[nSize];
+ if (lpvData) {
+ DWORD dw = GetMetaFileBitsEx( hmf, nSize, lpvData );
+ if (dw) {
+ // Fill out a METAFILEPICT structure
+ mp.mm = MM_ANISOTROPIC;
+ mp.xExt = 1000;
+ mp.yExt = 1000;
+ mp.hMF = NULL;
+ // Get a reference DC
+ hDC = GetDC( NULL );
+ // Make an enhanced metafile from the windows metafile
+ hemf = SetWinMetaFileBits( nSize, lpvData, hDC, &mp );
+ // Clean up
+ ReleaseDC( NULL, hDC );
+ }
+ delete[] lpvData;
+ }
+ DeleteMetaFile( hmf );
+ }
+ } else {
+ // Try open as Aldus Placeable Metafile
+ HANDLE hFile;
+ if (PrintWin32::is_os_wide())
+ hFile = CreateFileW( unicode_uri, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL );
+ else
+ hFile = CreateFileA( ansi_uri, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL );
+ if (hFile != INVALID_HANDLE_VALUE) {
+ DWORD nSize = GetFileSize( hFile, NULL );
+ if (nSize) {
+ BYTE *lpvData = new BYTE[nSize];
+ if (lpvData) {
+ DWORD dw = ReadFile( hFile, lpvData, nSize, &nSize, NULL );
+ if (dw) {
+ if ( ((PAPMHEADER)lpvData)->dwKey == 0x9ac6cdd7l ) {
+ // Fill out a METAFILEPICT structure
+ mp.mm = MM_ANISOTROPIC;
+ mp.xExt = ((PAPMHEADER)lpvData)->bbox.Right - ((PAPMHEADER)lpvData)->bbox.Left;
+ mp.xExt = ( mp.xExt * 2540l ) / (DWORD)(((PAPMHEADER)lpvData)->wInch);
+ mp.yExt = ((PAPMHEADER)lpvData)->bbox.Bottom - ((PAPMHEADER)lpvData)->bbox.Top;
+ mp.yExt = ( mp.yExt * 2540l ) / (DWORD)(((PAPMHEADER)lpvData)->wInch);
+ mp.hMF = NULL;
+ // Get a reference DC
+ hDC = GetDC( NULL );
+ // Create an enhanced metafile from the bits
+ hemf = SetWinMetaFileBits( nSize, lpvData+sizeof(APMHEADER), hDC, &mp );
+ // Clean up
+ ReleaseDC( NULL, hDC );
+ }
+ }
+ delete[] lpvData;
+ }
+ }
+ CloseHandle( hFile );
+ }
+ }
+ }
+
+ if (!hemf || !d.outsvg || !d.path) {
+ if (d.outsvg)
+ delete d.outsvg;
+ if (d.path)
+ delete d.path;
+ if (local_fn)
+ g_free(local_fn);
+ if (unicode_fn)
+ g_free(unicode_fn);
+ return NULL;
+ }
+
+ EnumEnhMetaFile(NULL, hemf, myEnhMetaFileProc, (LPVOID) &d, NULL);
+ DeleteEnhMetaFile(hemf);
+
+// std::cout << "SVG Output: " << std::endl << *(d.outsvg) << std::endl;
+
+ SPDocument *doc = sp_document_new_from_mem(d.outsvg->c_str(), d.outsvg->length(), TRUE);
+
+ delete d.outsvg;
+ delete d.path;
+
+ if (d.emf_obj) {
+ int i;
+ for (i=0; i<d.n_obj; i++)
+ delete_object(&d, i);
+ delete[] d.emf_obj;
+ }
+
+ if (d.style.stroke_dash.dash)
+ delete[] d.style.stroke_dash.dash;
+
+ if (local_fn)
+ g_free(local_fn);
+ if (unicode_fn)
+ g_free(unicode_fn);
+
+ return doc;
+}
+
+
+void
+EmfWin32::init (void)
+{
+ Inkscape::Extension::Extension * ext;
+
+ /* EMF in */
+ ext = Inkscape::Extension::build_from_mem(
+ "<inkscape-extension>\n"
+ "<name>" N_("EMF Input") "</name>\n"
+ "<id>org.inkscape.input.emf.win32</id>\n"
+ "<input>\n"
+ "<extension>.emf</extension>\n"
+ "<mimetype>image/x-emf</mimetype>\n"
+ "<filetypename>" N_("Enhanced Metafiles (*.emf)") "</filetypename>\n"
+ "<filetypetooltip>" N_("Enhanced Metafiles") "</filetypetooltip>\n"
+ "<output_extension>org.inkscape.output.emf.win32</output_extension>\n"
+ "</input>\n"
+ "</inkscape-extension>", new EmfWin32());
+
+ /* WMF in */
+ ext = Inkscape::Extension::build_from_mem(
+ "<inkscape-extension>\n"
+ "<name>" N_("WMF Input") "</name>\n"
+ "<id>org.inkscape.input.wmf.win32</id>\n"
+ "<input>\n"
+ "<extension>.wmf</extension>\n"
+ "<mimetype>image/x-wmf</mimetype>\n"
+ "<filetypename>" N_("Windows Metafiles (*.wmf)") "</filetypename>\n"
+ "<filetypetooltip>" N_("Windows Metafiles") "</filetypetooltip>\n"
+ "<output_extension>org.inkscape.output.emf.win32</output_extension>\n"
+ "</input>\n"
+ "</inkscape-extension>", new EmfWin32());
+
+ /* EMF out */
+ ext = Inkscape::Extension::build_from_mem(
+ "<inkscape-extension>\n"
+ "<name>" N_("EMF Output") "</name>\n"
+ "<id>org.inkscape.output.emf.win32</id>\n"
+ "<output>\n"
+ "<extension>.emf</extension>\n"
+ "<mimetype>image/x-emf</mimetype>\n"
+ "<filetypename>" N_("Enhanced Metafile (*.emf)") "</filetypename>\n"
+ "<filetypetooltip>" N_("Enhanced Metafile") "</filetypetooltip>\n"
+ "</output>\n"
+ "</inkscape-extension>", new EmfWin32());
+
+ return;
+}
+
+
+} } } /* namespace Inkscape, Extension, Implementation */
+
+
+#endif /* WIN32 */
+
+
+/*
+ Local Variables:
+ mode:cpp
+ c-file-style:"stroustrup"
+ c-file-offsets:((innamespace . 0)(inline-open . 0))
+ indent-tabs-mode:nil
+ fill-column:99
+ End:
+*/
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :
diff --git a/src/extension/internal/emf-win32-inout.h b/src/extension/internal/emf-win32-inout.h
index eff850049..3ec81b6b5 100644
--- a/src/extension/internal/emf-win32-inout.h
+++ b/src/extension/internal/emf-win32-inout.h
@@ -1,60 +1,60 @@
-/*
- * Enhanced Metafile Input/Output.
- *
- * Authors:
- * Ulf Erikson <ulferikson@users.sf.net>
- *
- * Copyright (C) 2006 Authors
- *
- * Released under GNU GPL, read the file 'COPYING' for more information
- */
-
-#ifndef EXTENSION_INTERNAL_EMF_WIN32_H
-#define EXTENSION_INTERNAL_EMF_WIN32_H
-
-#ifdef WIN32
-
-#include "extension/implementation/implementation.h"
-#include "style.h"
-
-namespace Inkscape {
-namespace Extension {
-namespace Internal {
-
-class EmfWin32 : Inkscape::Extension::Implementation::Implementation { //This is a derived class
-
-public:
- EmfWin32(); // Empty constructor
-
- virtual ~EmfWin32();//Destructor
-
- bool check(Inkscape::Extension::Extension *module); //Can this module load (always yes for now)
-
- void save(Inkscape::Extension::Output *mod, // Save the given document to the given filename
- SPDocument *doc,
- gchar const *uri);
-
- virtual SPDocument *open( Inkscape::Extension::Input *mod,
- const gchar *uri );
-
- static void init(void);//Initialize the class
-
-private:
-};
-
-} } } /* namespace Inkscape, Extension, Implementation */
-
-#endif /* WIN32 */
-
-#endif /* EXTENSION_INTERNAL_EMF_WIN32_H */
-
-/*
- Local Variables:
- mode:c++
- c-file-style:"stroustrup"
- c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
- indent-tabs-mode:nil
- fill-column:99
- End:
-*/
-// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :
+/*
+ * Enhanced Metafile Input/Output.
+ *
+ * Authors:
+ * Ulf Erikson <ulferikson@users.sf.net>
+ *
+ * Copyright (C) 2006 Authors
+ *
+ * Released under GNU GPL, read the file 'COPYING' for more information
+ */
+
+#ifndef EXTENSION_INTERNAL_EMF_WIN32_H
+#define EXTENSION_INTERNAL_EMF_WIN32_H
+
+#ifdef WIN32
+
+#include "extension/implementation/implementation.h"
+#include "style.h"
+
+namespace Inkscape {
+namespace Extension {
+namespace Internal {
+
+class EmfWin32 : Inkscape::Extension::Implementation::Implementation { //This is a derived class
+
+public:
+ EmfWin32(); // Empty constructor
+
+ virtual ~EmfWin32();//Destructor
+
+ bool check(Inkscape::Extension::Extension *module); //Can this module load (always yes for now)
+
+ void save(Inkscape::Extension::Output *mod, // Save the given document to the given filename
+ SPDocument *doc,
+ gchar const *uri);
+
+ virtual SPDocument *open( Inkscape::Extension::Input *mod,
+ const gchar *uri );
+
+ static void init(void);//Initialize the class
+
+private:
+};
+
+} } } /* namespace Inkscape, Extension, Implementation */
+
+#endif /* WIN32 */
+
+#endif /* EXTENSION_INTERNAL_EMF_WIN32_H */
+
+/*
+ Local Variables:
+ mode:c++
+ c-file-style:"stroustrup"
+ c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
+ indent-tabs-mode:nil
+ fill-column:99
+ End:
+*/
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :
diff --git a/src/extension/internal/emf-win32-print.cpp b/src/extension/internal/emf-win32-print.cpp
index b40eec462..9b1b77f16 100644
--- a/src/extension/internal/emf-win32-print.cpp
+++ b/src/extension/internal/emf-win32-print.cpp
@@ -1,629 +1,629 @@
-/** \file
- * Enhanced Metafile Printing.
- */
-/*
- * Authors:
- * Ulf Erikson <ulferikson@users.sf.net>
- *
- * Copyright (C) 2006 Authors
- *
- * Released under GNU GPL, read the file 'COPYING' for more information
- */
-/*
- * References:
- * - How to Create & Play Enhanced Metafiles in Win32
- * http://support.microsoft.com/kb/q145999/
- * - INFO: Windows Metafile Functions & Aldus Placeable Metafiles
- * http://support.microsoft.com/kb/q66949/
- * - Metafile Functions
- * http://msdn.microsoft.com/library/en-us/gdi/metafile_0whf.asp
- * - Metafile Structures
- * http://msdn.microsoft.com/library/en-us/gdi/metafile_5hkj.asp
- */
-
-#ifdef WIN32
-
-#ifdef HAVE_CONFIG_H
-# include "config.h"
-#endif
-
-#include <string.h>
-#include <signal.h>
-#include <errno.h>
-
-#include "libnr/n-art-bpath.h"
-#include "libnr/nr-point-matrix-ops.h"
-#include "libnr/nr-rect.h"
-#include "libnr/nr-matrix.h"
-#include "libnr/nr-matrix-fns.h"
-#include "libnr/nr-path.h"
-#include "libnr/nr-pixblock.h"
-#include "display/canvas-bpath.h"
-#include "sp-item.h"
-
-#include "glib.h"
-#include "gtk/gtkdialog.h"
-#include "gtk/gtkbox.h"
-#include "gtk/gtkstock.h"
-
-#include "glibmm/i18n.h"
-#include "enums.h"
-#include "document.h"
-#include "style.h"
-#include "sp-paint-server.h"
-#include "inkscape_version.h"
-
-#include "win32.h"
-#include "emf-win32-print.h"
-
-#include "unit-constants.h"
-
-#include "extension/extension.h"
-#include "extension/system.h"
-#include "extension/print.h"
-
-#include "io/sys.h"
-
-#include "macros.h"
-
-#define WIN32_LEAN_AND_MEAN
-#include <windows.h>
-
-namespace Inkscape {
-namespace Extension {
-namespace Internal {
-
-static float dwDPI = 2540;
-
-
-PrintEmfWin32::PrintEmfWin32 (void):
- hdc(NULL),
- hbrush(NULL),
- hpen(NULL),
- fill_path(NULL)
-{
-}
-
-
-PrintEmfWin32::~PrintEmfWin32 (void)
-{
- if (hdc) {
- HENHMETAFILE metafile = CloseEnhMetaFile( hdc );
- if ( metafile ) {
- DeleteEnhMetaFile( metafile );
- }
- DeleteDC( hdc );
- }
-
- /* restore default signal handling for SIGPIPE */
-#if !defined(_WIN32) && !defined(__WIN32__)
- (void) signal(SIGPIPE, SIG_DFL);
-#endif
- return;
-}
-
-
-unsigned int
-PrintEmfWin32::setup (Inkscape::Extension::Print *mod)
-{
- return TRUE;
-}
-
-
-unsigned int
-PrintEmfWin32::begin (Inkscape::Extension::Print *mod, SPDocument *doc)
-{
- gchar const *utf8_fn = mod->get_param_string("destination");
-
- gsize bytesRead = 0;
- gsize bytesWritten = 0;
- GError* error = NULL;
- gchar *local_fn =
- g_filename_from_utf8( utf8_fn, -1, &bytesRead, &bytesWritten, &error );
-
- if (local_fn == NULL) {
- return 1;
- }
-
- CHAR *ansi_uri = (CHAR *) local_fn;
- gunichar2 *unicode_fn = g_utf8_to_utf16( local_fn, -1, NULL, NULL, NULL );
- WCHAR *unicode_uri = (WCHAR *) unicode_fn;
-
- // width and height in px
- _width = sp_document_width(doc);
- _height = sp_document_height(doc);
-
- NRRect d;
- bool pageBoundingBox;
- pageBoundingBox = mod->get_param_bool("pageBoundingBox");
- if (pageBoundingBox) {
- d.x0 = d.y0 = 0;
- d.x1 = _width;
- d.y1 = _height;
- } else {
- SPItem* doc_item = SP_ITEM(sp_document_root(doc));
- sp_item_invoke_bbox(doc_item, &d, sp_item_i2r_affine(doc_item), TRUE);
- }
-
- d.x0 *= IN_PER_PX;
- d.y0 *= IN_PER_PX;
- d.x1 *= IN_PER_PX;
- d.y1 *= IN_PER_PX;
-
- float dwInchesX = (d.x1 - d.x0);
- float dwInchesY = (d.y1 - d.y0);
-
- // dwInchesX x dwInchesY in .01mm units
- SetRect( &rc, 0, 0, (int) ceil(dwInchesX*2540), (int) ceil(dwInchesY*2540) );
-
- // Get a Reference DC
- HDC hScreenDC = GetDC( NULL );
-
- // Get the physical characteristics of the reference DC
- float PixelsX = (float) GetDeviceCaps( hScreenDC, HORZRES );
- float PixelsY = (float) GetDeviceCaps( hScreenDC, VERTRES );
- float MMX = (float) GetDeviceCaps( hScreenDC, HORZSIZE );
- float MMY = (float) GetDeviceCaps( hScreenDC, VERTSIZE );
-
- // Create the Metafile
- if (PrintWin32::is_os_wide())
- hdc = CreateEnhMetaFileW( hScreenDC, unicode_uri, &rc, NULL );
- else
- hdc = CreateEnhMetaFileA( hScreenDC, ansi_uri, &rc, NULL );
-
- // Release the reference DC
- ReleaseDC( NULL, hScreenDC );
-
- // Did we get a good metafile?
- if (hdc == NULL)
- {
- g_free(local_fn);
- g_free(unicode_fn);
- return 1;
- }
-
- // Anisotropic mapping mode
- SetMapMode( hdc, MM_ANISOTROPIC );
-
- // Set the Windows extent
- SetWindowExtEx( hdc, (int) (dwInchesX*dwDPI), (int) (dwInchesY*dwDPI), NULL );
-
- // Set the viewport extent to reflect
- // dwInchesX" x dwInchesY" in device units
- SetViewportExtEx( hdc,
- (int) ((float) dwInchesX*25.4f*PixelsX/MMX),
- (int) ((float) dwInchesY*25.4f*PixelsY/MMY),
- NULL );
-
- SetRect( &rc, 0, 0, (int) ceil(dwInchesX*dwDPI), (int) ceil(dwInchesY*dwDPI) );
-
- g_free(local_fn);
- g_free(unicode_fn);
-
- return 0;
-}
-
-
-unsigned int
-PrintEmfWin32::finish (Inkscape::Extension::Print *mod)
-{
- if (!hdc) return 0;
-
- flush_fill(); // flush any pending fills
-
- HENHMETAFILE metafile = CloseEnhMetaFile( hdc );
- if ( metafile ) {
- DeleteEnhMetaFile( metafile );
- }
- DeleteDC( hdc );
-
- hdc = NULL;
-
- return 0;
-}
-
-
-unsigned int
-PrintEmfWin32::comment (Inkscape::Extension::Print * module,
- const char *comment)
-{
- if (!hdc) return 0;
-
- flush_fill(); // flush any pending fills
-
- return 0;
-}
-
-
-void
-PrintEmfWin32::create_brush(SPStyle const *style)
-{
- float rgb[3];
-
- if (style) {
- sp_color_get_rgb_floatv( &style->fill.value.color, rgb );
- hbrush = CreateSolidBrush( RGB(255*rgb[0], 255*rgb[1], 255*rgb[2]) );
- hbrushOld = (HBRUSH) SelectObject( hdc, hbrush );
-
- SetPolyFillMode( hdc,
- style->fill_rule.computed == 0 ? WINDING :
- style->fill_rule.computed == 2 ? ALTERNATE : ALTERNATE );
- } else { // if (!style)
- hbrush = CreateSolidBrush( RGB(255, 255, 255) );
- hbrushOld = (HBRUSH) SelectObject( hdc, hbrush );
- SetPolyFillMode( hdc, ALTERNATE );
- }
-}
-
-
-void
-PrintEmfWin32::destroy_brush()
-{
- SelectObject( hdc, hbrushOld );
- if (hbrush)
- DeleteObject( hbrush );
- hbrush = NULL;
-}
-
-
-void
-PrintEmfWin32::create_pen(SPStyle const *style)
-{
- if (style) {
- float rgb[3];
-
- sp_color_get_rgb_floatv(&style->stroke.value.color, rgb);
-
- LOGBRUSH lb = {0};
- lb.lbStyle = BS_SOLID;
- lb.lbColor = RGB( 255*rgb[0], 255*rgb[1], 255*rgb[2] );
-
- int linestyle = PS_SOLID;
- int linecap = 0;
- int linejoin = 0;
- DWORD n_dash = 0;
- DWORD *dash = NULL;
- float oldmiterlimit;
-
- DWORD linewidth = MAX( 1, (DWORD) (style->stroke_width.computed * IN_PER_PX * dwDPI) );
-
- if (style->stroke_linecap.computed == 0) {
- linecap = PS_ENDCAP_FLAT;
- }
- else if (style->stroke_linecap.computed == 1) {
- linecap = PS_ENDCAP_ROUND;
- }
- else if (style->stroke_linecap.computed == 2) {
- linecap = PS_ENDCAP_SQUARE;
- }
-
- if (style->stroke_linejoin.computed == 0) {
- linejoin = PS_JOIN_MITER;
- }
- else if (style->stroke_linejoin.computed == 1) {
- linejoin = PS_JOIN_ROUND;
- }
- else if (style->stroke_linejoin.computed == 2) {
- linejoin = PS_JOIN_BEVEL;
- }
-
- if (style->stroke_dash.n_dash &&
- style->stroke_dash.dash )
- {
- int i = 0;
- while (linestyle != PS_USERSTYLE &&
- (i < style->stroke_dash.n_dash)) {
- if (style->stroke_dash.dash[i] > 0.00000001)
- linestyle = PS_USERSTYLE;
- i++;
- }
-
- if (linestyle == PS_USERSTYLE) {
- n_dash = style->stroke_dash.n_dash;
- dash = new DWORD[n_dash];
- for (i = 0; i < style->stroke_dash.n_dash; i++) {
- dash[i] = (DWORD) (style->stroke_dash.dash[i] * IN_PER_PX * dwDPI);
- }
- }
- }
-
- hpen = ExtCreatePen(
- PS_GEOMETRIC | linestyle | linecap | linejoin,
- linewidth,
- &lb,
- n_dash,
- dash );
-
- if ( !hpen && linestyle == PS_USERSTYLE ) {
- hpen = ExtCreatePen(
- PS_GEOMETRIC | PS_SOLID | linecap | linejoin,
- linewidth,
- &lb,
- 0,
- NULL );
- }
-
- if ( !hpen ) {
- hpen = CreatePen(
- PS_SOLID,
- linewidth,
- lb.lbColor );
- }
-
- hpenOld = (HPEN) SelectObject( hdc, hpen );
-
- if (linejoin == PS_JOIN_MITER) {
- float miterlimit = style->stroke_miterlimit.value;
- if (miterlimit < 1)
- miterlimit = 4.0;
- SetMiterLimit(
- hdc,
- miterlimit * IN_PER_PX * dwDPI,
- &oldmiterlimit );
- }
-
- if (n_dash) {
- delete[] dash;
- }
- }
- else { // if (!style)
- hpen = CreatePen( PS_SOLID, 1, RGB(0, 0, 0) );
- hpenOld = (HPEN) SelectObject( hdc, hpen );
- }
-}
-
-
-void
-PrintEmfWin32::destroy_pen()
-{
- SelectObject( hdc, hpenOld );
- if (hpen)
- DeleteObject( hpen );
- hpen = NULL;
-}
-
-
-void
-PrintEmfWin32::flush_fill()
-{
- if (fill_path) {
- print_bpath(fill_path, &fill_transform, &fill_pbox);
- FillPath( hdc );
- destroy_brush();
- delete[] fill_path;
- fill_path = NULL;
- }
-}
-
-
-NArtBpath *
-PrintEmfWin32::copy_bpath(const NArtBpath *bp)
-{
- NArtBpath *tmp = (NArtBpath *) bp;
- int num = 1;
-
- while (tmp->code != NR_END) {
- num++;
- tmp += 1;
- }
-
- tmp = new NArtBpath[num];
- while (num--) {
- tmp[num] = bp[num];
- }
-
- return tmp;
-}
-
-
-int
-PrintEmfWin32::cmp_bpath(const NArtBpath *bp1, const NArtBpath *bp2)
-{
- if (!bp1 || !bp2) {
- return 1;
- }
-
- while (bp1->code != NR_END && bp2->code != NR_END) {
- if (bp1->code != bp2->code) {
- return 1;
- }
-
- if ( fabs(bp1->x1 - bp2->x1) > 0.00000001 ||
- fabs(bp1->y1 - bp2->y1) > 0.00000001 ||
- fabs(bp1->x2 - bp2->x2) > 0.00000001 ||
- fabs(bp1->y2 - bp2->y2) > 0.00000001 ||
- fabs(bp1->x3 - bp2->x3) > 0.00000001 ||
- fabs(bp1->y3 - bp2->y3) > 0.00000001 )
- {
- return 1;
- }
-
- bp1 += 1;
- bp2 += 1;
- }
-
- return bp1->code != NR_END || bp2->code != NR_END;
-}
-
-
-unsigned int
-PrintEmfWin32::fill(Inkscape::Extension::Print *mod,
- NRBPath const *bpath, NRMatrix const *transform, SPStyle const *style,
- NRRect const *pbox, NRRect const *dbox, NRRect const *bbox)
-{
- if (!hdc) return 0;
-
- flush_fill(); // flush any pending fills
-
- if (style->fill.type == SP_PAINT_TYPE_COLOR) {
- create_brush(style);
- } else {
- // create_brush(NULL);
- return 0;
- }
-
- fill_path = copy_bpath( bpath->path );
- fill_transform = *transform;
- fill_pbox = *pbox;
-
- // postpone fill in case of stroke-and-fill
-
- return 0;
-}
-
-
-unsigned int
-PrintEmfWin32::stroke (Inkscape::Extension::Print *mod,
- const NRBPath *bpath, const NRMatrix *transform, const SPStyle *style,
- const NRRect *pbox, const NRRect *dbox, const NRRect *bbox)
-{
- if (!hdc) return 0;
-
- bool stroke_and_fill = ( cmp_bpath( bpath->path, fill_path ) == 0 );
-
- if (!stroke_and_fill) {
- flush_fill(); // flush any pending fills
- }
-
- if (style->stroke.type == SP_PAINT_TYPE_COLOR) {
- create_pen(style);
- } else {
- // create_pen(NULL);
- return 0;
- }
-
- print_bpath(bpath->path, transform, pbox);
-
- if (stroke_and_fill) {
- StrokeAndFillPath( hdc );
- destroy_brush();
- delete[] fill_path;
- fill_path = NULL;
- } else {
- StrokePath( hdc );
- }
-
- destroy_pen();
-
- return 0;
-}
-
-
-unsigned int
-PrintEmfWin32::print_bpath(const NArtBpath *bp, const NRMatrix *transform, NRRect const *pbox)
-{
- unsigned int closed;
- NR::Matrix tf = *transform;
-
- BeginPath( hdc );
- closed = FALSE;
- while (bp->code != NR_END) {
- using NR::X;
- using NR::Y;
-
- NR::Point p1(bp->c(1) * tf);
- NR::Point p2(bp->c(2) * tf);
- NR::Point p3(bp->c(3) * tf);
-
- p1[X] = (p1[X] * IN_PER_PX * dwDPI);
- p2[X] = (p2[X] * IN_PER_PX * dwDPI);
- p3[X] = (p3[X] * IN_PER_PX * dwDPI);
- p1[Y] = (p1[Y] * IN_PER_PX * dwDPI);
- p2[Y] = (p2[Y] * IN_PER_PX * dwDPI);
- p3[Y] = (p3[Y] * IN_PER_PX * dwDPI);
-
- LONG const x1 = (LONG) round(p1[X]);
- LONG const y1 = (LONG) round(rc.bottom-p1[Y]);
- LONG const x2 = (LONG) round(p2[X]);
- LONG const y2 = (LONG) round(rc.bottom-p2[Y]);
- LONG const x3 = (LONG) round(p3[X]);
- LONG const y3 = (LONG) round(rc.bottom-p3[Y]);
-
- switch (bp->code) {
- case NR_MOVETO:
- if (closed) {
- CloseFigure( hdc );
- }
- closed = TRUE;
- MoveToEx( hdc, x3, y3, NULL );
- break;
- case NR_MOVETO_OPEN:
- if (closed) {
- CloseFigure( hdc );
- }
- closed = FALSE;
- MoveToEx( hdc, x3, y3, NULL );
- break;
- case NR_LINETO:
- LineTo( hdc, x3, y3 );
- break;
- case NR_CURVETO:
- {
- POINT pt[3];
- pt[0].x = x1;
- pt[0].y = y1;
- pt[1].x = x2;
- pt[1].y = y2;
- pt[2].x = x3;
- pt[2].y = y3;
-
- PolyBezierTo( hdc, pt, 3 );
- break;
- }
- default:
- break;
- }
- bp += 1;
- }
- if (closed) {
- CloseFigure( hdc );
- }
- EndPath( hdc );
-
- return closed;
-}
-
-
-bool
-PrintEmfWin32::textToPath(Inkscape::Extension::Print * ext)
-{
- return ext->get_param_bool("textToPath");
-}
-
-
-void
-PrintEmfWin32::init (void)
-{
- Inkscape::Extension::Extension * ext;
-
- /* EMF print */
- ext = Inkscape::Extension::build_from_mem(
- "<inkscape-extension>\n"
- "<name>Enhanced Metafile Print</name>\n"
- "<id>org.inkscape.print.emf.win32</id>\n"
- "<param name=\"destination\" type=\"string\"></param>\n"
- "<param name=\"textToPath\" type=\"boolean\">TRUE</param>\n"
- "<param name=\"pageBoundingBox\" type=\"boolean\">TRUE</param>\n"
- "<print/>\n"
- "</inkscape-extension>", new PrintEmfWin32());
-
- return;
-}
-
-
-} /* namespace Internal */
-} /* namespace Extension */
-} /* namespace Inkscape */
-
-#endif /* WIN32 */
-
-/*
- Local Variables:
- mode:c++
- c-file-style:"stroustrup"
- c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
- indent-tabs-mode:nil
- fill-column:99
- End:
-*/
-// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :
+/** \file
+ * Enhanced Metafile Printing.
+ */
+/*
+ * Authors:
+ * Ulf Erikson <ulferikson@users.sf.net>
+ *
+ * Copyright (C) 2006 Authors
+ *
+ * Released under GNU GPL, read the file 'COPYING' for more information
+ */
+/*
+ * References:
+ * - How to Create & Play Enhanced Metafiles in Win32
+ * http://support.microsoft.com/kb/q145999/
+ * - INFO: Windows Metafile Functions & Aldus Placeable Metafiles
+ * http://support.microsoft.com/kb/q66949/
+ * - Metafile Functions
+ * http://msdn.microsoft.com/library/en-us/gdi/metafile_0whf.asp
+ * - Metafile Structures
+ * http://msdn.microsoft.com/library/en-us/gdi/metafile_5hkj.asp
+ */
+
+#ifdef WIN32
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include <string.h>
+#include <signal.h>
+#include <errno.h>
+
+#include "libnr/n-art-bpath.h"
+#include "libnr/nr-point-matrix-ops.h"
+#include "libnr/nr-rect.h"
+#include "libnr/nr-matrix.h"
+#include "libnr/nr-matrix-fns.h"
+#include "libnr/nr-path.h"
+#include "libnr/nr-pixblock.h"
+#include "display/canvas-bpath.h"
+#include "sp-item.h"
+
+#include "glib.h"
+#include "gtk/gtkdialog.h"
+#include "gtk/gtkbox.h"
+#include "gtk/gtkstock.h"
+
+#include "glibmm/i18n.h"
+#include "enums.h"
+#include "document.h"
+#include "style.h"
+#include "sp-paint-server.h"
+#include "inkscape_version.h"
+
+#include "win32.h"
+#include "emf-win32-print.h"
+
+#include "unit-constants.h"
+
+#include "extension/extension.h"
+#include "extension/system.h"
+#include "extension/print.h"
+
+#include "io/sys.h"
+
+#include "macros.h"
+
+#define WIN32_LEAN_AND_MEAN
+#include <windows.h>
+
+namespace Inkscape {
+namespace Extension {
+namespace Internal {
+
+static float dwDPI = 2540;
+
+
+PrintEmfWin32::PrintEmfWin32 (void):
+ hdc(NULL),
+ hbrush(NULL),
+ hpen(NULL),
+ fill_path(NULL)
+{
+}
+
+
+PrintEmfWin32::~PrintEmfWin32 (void)
+{
+ if (hdc) {
+ HENHMETAFILE metafile = CloseEnhMetaFile( hdc );
+ if ( metafile ) {
+ DeleteEnhMetaFile( metafile );
+ }
+ DeleteDC( hdc );
+ }
+
+ /* restore default signal handling for SIGPIPE */
+#if !defined(_WIN32) && !defined(__WIN32__)
+ (void) signal(SIGPIPE, SIG_DFL);
+#endif
+ return;
+}
+
+
+unsigned int
+PrintEmfWin32::setup (Inkscape::Extension::Print *mod)
+{
+ return TRUE;
+}
+
+
+unsigned int
+PrintEmfWin32::begin (Inkscape::Extension::Print *mod, SPDocument *doc)
+{
+ gchar const *utf8_fn = mod->get_param_string("destination");
+
+ gsize bytesRead = 0;
+ gsize bytesWritten = 0;
+ GError* error = NULL;
+ gchar *local_fn =
+ g_filename_from_utf8( utf8_fn, -1, &bytesRead, &bytesWritten, &error );
+
+ if (local_fn == NULL) {
+ return 1;
+ }
+
+ CHAR *ansi_uri = (CHAR *) local_fn;
+ gunichar2 *unicode_fn = g_utf8_to_utf16( local_fn, -1, NULL, NULL, NULL );
+ WCHAR *unicode_uri = (WCHAR *) unicode_fn;
+
+ // width and height in px
+ _width = sp_document_width(doc);
+ _height = sp_document_height(doc);
+
+ NRRect d;
+ bool pageBoundingBox;
+ pageBoundingBox = mod->get_param_bool("pageBoundingBox");
+ if (pageBoundingBox) {
+ d.x0 = d.y0 = 0;
+ d.x1 = _width;
+ d.y1 = _height;
+ } else {
+ SPItem* doc_item = SP_ITEM(sp_document_root(doc));
+ sp_item_invoke_bbox(doc_item, &d, sp_item_i2r_affine(doc_item), TRUE);
+ }
+
+ d.x0 *= IN_PER_PX;
+ d.y0 *= IN_PER_PX;
+ d.x1 *= IN_PER_PX;
+ d.y1 *= IN_PER_PX;
+
+ float dwInchesX = (d.x1 - d.x0);
+ float dwInchesY = (d.y1 - d.y0);
+
+ // dwInchesX x dwInchesY in .01mm units
+ SetRect( &rc, 0, 0, (int) ceil(dwInchesX*2540), (int) ceil(dwInchesY*2540) );
+
+ // Get a Reference DC
+ HDC hScreenDC = GetDC( NULL );
+
+ // Get the physical characteristics of the reference DC
+ float PixelsX = (float) GetDeviceCaps( hScreenDC, HORZRES );
+ float PixelsY = (float) GetDeviceCaps( hScreenDC, VERTRES );
+ float MMX = (float) GetDeviceCaps( hScreenDC, HORZSIZE );
+ float MMY = (float) GetDeviceCaps( hScreenDC, VERTSIZE );
+
+ // Create the Metafile
+ if (PrintWin32::is_os_wide())
+ hdc = CreateEnhMetaFileW( hScreenDC, unicode_uri, &rc, NULL );
+ else
+ hdc = CreateEnhMetaFileA( hScreenDC, ansi_uri, &rc, NULL );
+
+ // Release the reference DC
+ ReleaseDC( NULL, hScreenDC );
+
+ // Did we get a good metafile?
+ if (hdc == NULL)
+ {
+ g_free(local_fn);
+ g_free(unicode_fn);
+ return 1;
+ }
+
+ // Anisotropic mapping mode
+ SetMapMode( hdc, MM_ANISOTROPIC );
+
+ // Set the Windows extent
+ SetWindowExtEx( hdc, (int) (dwInchesX*dwDPI), (int) (dwInchesY*dwDPI), NULL );
+
+ // Set the viewport extent to reflect
+ // dwInchesX" x dwInchesY" in device units
+ SetViewportExtEx( hdc,
+ (int) ((float) dwInchesX*25.4f*PixelsX/MMX),
+ (int) ((float) dwInchesY*25.4f*PixelsY/MMY),
+ NULL );
+
+ SetRect( &rc, 0, 0, (int) ceil(dwInchesX*dwDPI), (int) ceil(dwInchesY*dwDPI) );
+
+ g_free(local_fn);
+ g_free(unicode_fn);
+
+ return 0;
+}
+
+
+unsigned int
+PrintEmfWin32::finish (Inkscape::Extension::Print *mod)
+{
+ if (!hdc) return 0;
+
+ flush_fill(); // flush any pending fills
+
+ HENHMETAFILE metafile = CloseEnhMetaFile( hdc );
+ if ( metafile ) {
+ DeleteEnhMetaFile( metafile );
+ }
+ DeleteDC( hdc );
+
+ hdc = NULL;
+
+ return 0;
+}
+
+
+unsigned int
+PrintEmfWin32::comment (Inkscape::Extension::Print * module,
+ const char *comment)
+{
+ if (!hdc) return 0;
+
+ flush_fill(); // flush any pending fills
+
+ return 0;
+}
+
+
+void
+PrintEmfWin32::create_brush(SPStyle const *style)
+{
+ float rgb[3];
+
+ if (style) {
+ sp_color_get_rgb_floatv( &style->fill.value.color, rgb );
+ hbrush = CreateSolidBrush( RGB(255*rgb[0], 255*rgb[1], 255*rgb[2]) );
+ hbrushOld = (HBRUSH) SelectObject( hdc, hbrush );
+
+ SetPolyFillMode( hdc,
+ style->fill_rule.computed == 0 ? WINDING :
+ style->fill_rule.computed == 2 ? ALTERNATE : ALTERNATE );
+ } else { // if (!style)
+ hbrush = CreateSolidBrush( RGB(255, 255, 255) );
+ hbrushOld = (HBRUSH) SelectObject( hdc, hbrush );
+ SetPolyFillMode( hdc, ALTERNATE );
+ }
+}
+
+
+void
+PrintEmfWin32::destroy_brush()
+{
+ SelectObject( hdc, hbrushOld );
+ if (hbrush)
+ DeleteObject( hbrush );
+ hbrush = NULL;
+}
+
+
+void
+PrintEmfWin32::create_pen(SPStyle const *style)
+{
+ if (style) {
+ float rgb[3];
+
+ sp_color_get_rgb_floatv(&style->stroke.value.color, rgb);
+
+ LOGBRUSH lb = {0};
+ lb.lbStyle = BS_SOLID;
+ lb.lbColor = RGB( 255*rgb[0], 255*rgb[1], 255*rgb[2] );
+
+ int linestyle = PS_SOLID;
+ int linecap = 0;
+ int linejoin = 0;
+ DWORD n_dash = 0;
+ DWORD *dash = NULL;
+ float oldmiterlimit;
+
+ DWORD linewidth = MAX( 1, (DWORD) (style->stroke_width.computed * IN_PER_PX * dwDPI) );
+
+ if (style->stroke_linecap.computed == 0) {
+ linecap = PS_ENDCAP_FLAT;
+ }
+ else if (style->stroke_linecap.computed == 1) {
+ linecap = PS_ENDCAP_ROUND;
+ }
+ else if (style->stroke_linecap.computed == 2) {
+ linecap = PS_ENDCAP_SQUARE;
+ }
+
+ if (style->stroke_linejoin.computed == 0) {
+ linejoin = PS_JOIN_MITER;
+ }
+ else if (style->stroke_linejoin.computed == 1) {
+ linejoin = PS_JOIN_ROUND;
+ }
+ else if (style->stroke_linejoin.computed == 2) {
+ linejoin = PS_JOIN_BEVEL;
+ }
+
+ if (style->stroke_dash.n_dash &&
+ style->stroke_dash.dash )
+ {
+ int i = 0;
+ while (linestyle != PS_USERSTYLE &&
+ (i < style->stroke_dash.n_dash)) {
+ if (style->stroke_dash.dash[i] > 0.00000001)
+ linestyle = PS_USERSTYLE;
+ i++;
+ }
+
+ if (linestyle == PS_USERSTYLE) {
+ n_dash = style->stroke_dash.n_dash;
+ dash = new DWORD[n_dash];
+ for (i = 0; i < style->stroke_dash.n_dash; i++) {
+ dash[i] = (DWORD) (style->stroke_dash.dash[i] * IN_PER_PX * dwDPI);
+ }
+ }
+ }
+
+ hpen = ExtCreatePen(
+ PS_GEOMETRIC | linestyle | linecap | linejoin,
+ linewidth,
+ &lb,
+ n_dash,
+ dash );
+
+ if ( !hpen && linestyle == PS_USERSTYLE ) {
+ hpen = ExtCreatePen(
+ PS_GEOMETRIC | PS_SOLID | linecap | linejoin,
+ linewidth,
+ &lb,
+ 0,
+ NULL );
+ }
+
+ if ( !hpen ) {
+ hpen = CreatePen(
+ PS_SOLID,
+ linewidth,
+ lb.lbColor );
+ }
+
+ hpenOld = (HPEN) SelectObject( hdc, hpen );
+
+ if (linejoin == PS_JOIN_MITER) {
+ float miterlimit = style->stroke_miterlimit.value;
+ if (miterlimit < 1)
+ miterlimit = 4.0;
+ SetMiterLimit(
+ hdc,
+ miterlimit * IN_PER_PX * dwDPI,
+ &oldmiterlimit );
+ }
+
+ if (n_dash) {
+ delete[] dash;
+ }
+ }
+ else { // if (!style)
+ hpen = CreatePen( PS_SOLID, 1, RGB(0, 0, 0) );
+ hpenOld = (HPEN) SelectObject( hdc, hpen );
+ }
+}
+
+
+void
+PrintEmfWin32::destroy_pen()
+{
+ SelectObject( hdc, hpenOld );
+ if (hpen)
+ DeleteObject( hpen );
+ hpen = NULL;
+}
+
+
+void
+PrintEmfWin32::flush_fill()
+{
+ if (fill_path) {
+ print_bpath(fill_path, &fill_transform, &fill_pbox);
+ FillPath( hdc );
+ destroy_brush();
+ delete[] fill_path;
+ fill_path = NULL;
+ }
+}
+
+
+NArtBpath *
+PrintEmfWin32::copy_bpath(const NArtBpath *bp)
+{
+ NArtBpath *tmp = (NArtBpath *) bp;
+ int num = 1;
+
+ while (tmp->code != NR_END) {
+ num++;
+ tmp += 1;
+ }
+
+ tmp = new NArtBpath[num];
+ while (num--) {
+ tmp[num] = bp[num];
+ }
+
+ return tmp;
+}
+
+
+int
+PrintEmfWin32::cmp_bpath(const NArtBpath *bp1, const NArtBpath *bp2)
+{
+ if (!bp1 || !bp2) {
+ return 1;
+ }
+
+ while (bp1->code != NR_END && bp2->code != NR_END) {
+ if (bp1->code != bp2->code) {
+ return 1;
+ }
+
+ if ( fabs(bp1->x1 - bp2->x1) > 0.00000001 ||
+ fabs(bp1->y1 - bp2->y1) > 0.00000001 ||
+ fabs(bp1->x2 - bp2->x2) > 0.00000001 ||
+ fabs(bp1->y2 - bp2->y2) > 0.00000001 ||
+ fabs(bp1->x3 - bp2->x3) > 0.00000001 ||
+ fabs(bp1->y3 - bp2->y3) > 0.00000001 )
+ {
+ return 1;
+ }
+
+ bp1 += 1;
+ bp2 += 1;
+ }
+
+ return bp1->code != NR_END || bp2->code != NR_END;
+}
+
+
+unsigned int
+PrintEmfWin32::fill(Inkscape::Extension::Print *mod,
+ NRBPath const *bpath, NRMatrix const *transform, SPStyle const *style,
+ NRRect const *pbox, NRRect const *dbox, NRRect const *bbox)
+{
+ if (!hdc) return 0;
+
+ flush_fill(); // flush any pending fills
+
+ if (style->fill.type == SP_PAINT_TYPE_COLOR) {
+ create_brush(style);
+ } else {
+ // create_brush(NULL);
+ return 0;
+ }
+
+ fill_path = copy_bpath( bpath->path );
+ fill_transform = *transform;
+ fill_pbox = *pbox;
+
+ // postpone fill in case of stroke-and-fill
+
+ return 0;
+}
+
+
+unsigned int
+PrintEmfWin32::stroke (Inkscape::Extension::Print *mod,
+ const NRBPath *bpath, const NRMatrix *transform, const SPStyle *style,
+ const NRRect *pbox, const NRRect *dbox, const NRRect *bbox)
+{
+ if (!hdc) return 0;
+
+ bool stroke_and_fill = ( cmp_bpath( bpath->path, fill_path ) == 0 );
+
+ if (!stroke_and_fill) {
+ flush_fill(); // flush any pending fills
+ }
+
+ if (style->stroke.type == SP_PAINT_TYPE_COLOR) {
+ create_pen(style);
+ } else {
+ // create_pen(NULL);
+ return 0;
+ }
+
+ print_bpath(bpath->path, transform, pbox);
+
+ if (stroke_and_fill) {
+ StrokeAndFillPath( hdc );
+ destroy_brush();
+ delete[] fill_path;
+ fill_path = NULL;
+ } else {
+ StrokePath( hdc );
+ }
+
+ destroy_pen();
+
+ return 0;
+}
+
+
+unsigned int
+PrintEmfWin32::print_bpath(const NArtBpath *bp, const NRMatrix *transform, NRRect const *pbox)
+{
+ unsigned int closed;
+ NR::Matrix tf = *transform;
+
+ BeginPath( hdc );
+ closed = FALSE;
+ while (bp->code != NR_END) {
+ using NR::X;
+ using NR::Y;
+
+ NR::Point p1(bp->c(1) * tf);
+ NR::Point p2(bp->c(2) * tf);
+ NR::Point p3(bp->c(3) * tf);
+
+ p1[X] = (p1[X] * IN_PER_PX * dwDPI);
+ p2[X] = (p2[X] * IN_PER_PX * dwDPI);
+ p3[X] = (p3[X] * IN_PER_PX * dwDPI);
+ p1[Y] = (p1[Y] * IN_PER_PX * dwDPI);
+ p2[Y] = (p2[Y] * IN_PER_PX * dwDPI);
+ p3[Y] = (p3[Y] * IN_PER_PX * dwDPI);
+
+ LONG const x1 = (LONG) round(p1[X]);
+ LONG const y1 = (LONG) round(rc.bottom-p1[Y]);
+ LONG const x2 = (LONG) round(p2[X]);
+ LONG const y2 = (LONG) round(rc.bottom-p2[Y]);
+ LONG const x3 = (LONG) round(p3[X]);
+ LONG const y3 = (LONG) round(rc.bottom-p3[Y]);
+
+ switch (bp->code) {
+ case NR_MOVETO:
+ if (closed) {
+ CloseFigure( hdc );
+ }
+ closed = TRUE;
+ MoveToEx( hdc, x3, y3, NULL );
+ break;
+ case NR_MOVETO_OPEN:
+ if (closed) {
+ CloseFigure( hdc );
+ }
+ closed = FALSE;
+ MoveToEx( hdc, x3, y3, NULL );
+ break;
+ case NR_LINETO:
+ LineTo( hdc, x3, y3 );
+ break;
+ case NR_CURVETO:
+ {
+ POINT pt[3];
+ pt[0].x = x1;
+ pt[0].y = y1;
+ pt[1].x = x2;
+ pt[1].y = y2;
+ pt[2].x = x3;
+ pt[2].y = y3;
+
+ PolyBezierTo( hdc, pt, 3 );
+ break;
+ }
+ default:
+ break;
+ }
+ bp += 1;
+ }
+ if (closed) {
+ CloseFigure( hdc );
+ }
+ EndPath( hdc );
+
+ return closed;
+}
+
+
+bool
+PrintEmfWin32::textToPath(Inkscape::Extension::Print * ext)
+{
+ return ext->get_param_bool("textToPath");
+}
+
+
+void
+PrintEmfWin32::init (void)
+{
+ Inkscape::Extension::Extension * ext;
+
+ /* EMF print */
+ ext = Inkscape::Extension::build_from_mem(
+ "<inkscape-extension>\n"
+ "<name>Enhanced Metafile Print</name>\n"
+ "<id>org.inkscape.print.emf.win32</id>\n"
+ "<param name=\"destination\" type=\"string\"></param>\n"
+ "<param name=\"textToPath\" type=\"boolean\">TRUE</param>\n"
+ "<param name=\"pageBoundingBox\" type=\"boolean\">TRUE</param>\n"
+ "<print/>\n"
+ "</inkscape-extension>", new PrintEmfWin32());
+
+ return;
+}
+
+
+} /* namespace Internal */
+} /* namespace Extension */
+} /* namespace Inkscape */
+
+#endif /* WIN32 */
+
+/*
+ Local Variables:
+ mode:c++
+ c-file-style:"stroustrup"
+ c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
+ indent-tabs-mode:nil
+ fill-column:99
+ End:
+*/
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :
diff --git a/src/extension/internal/emf-win32-print.h b/src/extension/internal/emf-win32-print.h
index d1ac81939..305507824 100644
--- a/src/extension/internal/emf-win32-print.h
+++ b/src/extension/internal/emf-win32-print.h
@@ -1,107 +1,107 @@
-#ifndef __INKSCAPE_EXTENSION_INTERNAL_PRINT_EMF_WIN32_H__
-#define __INKSCAPE_EXTENSION_INTERNAL_PRINT_EMF_WIN32_H__
-
-/*
- * Enhanced Metafile Printing.
- *
- * Author:
- * Ulf Erikson <ulferikson@users.sf.net>
- *
- * Copyright (C) 2006 Authors
- *
- * Released under GNU GPL, read the file 'COPYING' for more information
- */
-
-#ifdef WIN32
-
-#ifdef HAVE_CONFIG_H
-# include "config.h"
-#endif
-
-#include "extension/implementation/implementation.h"
-#include "extension/extension.h"
-
-#include "svg/stringstream.h"
-#include "libnr/nr-matrix.h"
-#include "libnr/nr-rect.h"
-
-#define WIN32_LEAN_AND_MEAN
-#include <windows.h>
-
-namespace Inkscape {
-namespace Extension {
-namespace Internal {
-
-class PrintEmfWin32 : public Inkscape::Extension::Implementation::Implementation
-{
- double _width;
- double _height;
- HDC hdc;
- RECT rc;
-
- HBRUSH hbrush, hbrushOld;
- HPEN hpen, hpenOld;
-
- NArtBpath *fill_path;
- NArtBpath *fill_path_copy;
- NRMatrix fill_transform;
- NRRect fill_pbox;
-
- unsigned int print_bpath (const NArtBpath *bp, const NRMatrix *transform, NRRect const *pbox);
-
-public:
- PrintEmfWin32 (void);
- virtual ~PrintEmfWin32 (void);
-
- /* Print functions */
- virtual unsigned int setup (Inkscape::Extension::Print * module);
-
- virtual unsigned int begin (Inkscape::Extension::Print * module, SPDocument *doc);
- virtual unsigned int finish (Inkscape::Extension::Print * module);
-
- /* Rendering methods */
- virtual unsigned int fill (Inkscape::Extension::Print * module,
- const NRBPath *bpath, const NRMatrix *ctm, const SPStyle *style,
- const NRRect *pbox, const NRRect *dbox, const NRRect *bbox);
- virtual unsigned int stroke (Inkscape::Extension::Print * module,
- const NRBPath *bpath, const NRMatrix *transform, const SPStyle *style,
- const NRRect *pbox, const NRRect *dbox, const NRRect *bbox);
- virtual unsigned int comment(Inkscape::Extension::Print *module, const char * comment);
- bool textToPath (Inkscape::Extension::Print * ext);
-
- static void init (void);
-
-protected:
- void create_brush(SPStyle const *style);
-
- void destroy_brush();
-
- void create_pen(SPStyle const *style);
-
- void destroy_pen();
-
- void flush_fill();
-
- NArtBpath *copy_bpath(const NArtBpath *bp);
- int cmp_bpath(const NArtBpath *bp1, const NArtBpath *bp2);
-
-};
-
-} /* namespace Internal */
-} /* namespace Extension */
-} /* namespace Inkscape */
-
-#endif /* WIN32 */
-
-#endif /* __INKSCAPE_EXTENSION_INTERNAL_PRINT_EMF_WIN32_H__ */
-
-/*
- Local Variables:
- mode:cpp
- c-file-style:"stroustrup"
- c-file-offsets:((innamespace . 0)(inline-open . 0))
- indent-tabs-mode:nil
- fill-column:99
- End:
-*/
-// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :
+#ifndef __INKSCAPE_EXTENSION_INTERNAL_PRINT_EMF_WIN32_H__
+#define __INKSCAPE_EXTENSION_INTERNAL_PRINT_EMF_WIN32_H__
+
+/*
+ * Enhanced Metafile Printing.
+ *
+ * Author:
+ * Ulf Erikson <ulferikson@users.sf.net>
+ *
+ * Copyright (C) 2006 Authors
+ *
+ * Released under GNU GPL, read the file 'COPYING' for more information
+ */
+
+#ifdef WIN32
+
+#ifdef HAVE_CONFIG_H
+# include "config.h"
+#endif
+
+#include "extension/implementation/implementation.h"
+#include "extension/extension.h"
+
+#include "svg/stringstream.h"
+#include "libnr/nr-matrix.h"
+#include "libnr/nr-rect.h"
+
+#define WIN32_LEAN_AND_MEAN
+#include <windows.h>
+
+namespace Inkscape {
+namespace Extension {
+namespace Internal {
+
+class PrintEmfWin32 : public Inkscape::Extension::Implementation::Implementation
+{
+ double _width;
+ double _height;
+ HDC hdc;
+ RECT rc;
+
+ HBRUSH hbrush, hbrushOld;
+ HPEN hpen, hpenOld;
+
+ NArtBpath *fill_path;
+ NArtBpath *fill_path_copy;
+ NRMatrix fill_transform;
+ NRRect fill_pbox;
+
+ unsigned int print_bpath (const NArtBpath *bp, const NRMatrix *transform, NRRect const *pbox);
+
+public:
+ PrintEmfWin32 (void);
+ virtual ~PrintEmfWin32 (void);
+
+ /* Print functions */
+ virtual unsigned int setup (Inkscape::Extension::Print * module);
+
+ virtual unsigned int begin (Inkscape::Extension::Print * module, SPDocument *doc);
+ virtual unsigned int finish (Inkscape::Extension::Print * module);
+
+ /* Rendering methods */
+ virtual unsigned int fill (Inkscape::Extension::Print * module,
+ const NRBPath *bpath, const NRMatrix *ctm, const SPStyle *style,
+ const NRRect *pbox, const NRRect *dbox, const NRRect *bbox);
+ virtual unsigned int stroke (Inkscape::Extension::Print * module,
+ const NRBPath *bpath, const NRMatrix *transform, const SPStyle *style,
+ const NRRect *pbox, const NRRect *dbox, const NRRect *bbox);
+ virtual unsigned int comment(Inkscape::Extension::Print *module, const char * comment);
+ bool textToPath (Inkscape::Extension::Print * ext);
+
+ static void init (void);
+
+protected:
+ void create_brush(SPStyle const *style);
+
+ void destroy_brush();
+
+ void create_pen(SPStyle const *style);
+
+ void destroy_pen();
+
+ void flush_fill();
+
+ NArtBpath *copy_bpath(const NArtBpath *bp);
+ int cmp_bpath(const NArtBpath *bp1, const NArtBpath *bp2);
+
+};
+
+} /* namespace Internal */
+} /* namespace Extension */
+} /* namespace Inkscape */
+
+#endif /* WIN32 */
+
+#endif /* __INKSCAPE_EXTENSION_INTERNAL_PRINT_EMF_WIN32_H__ */
+
+/*
+ Local Variables:
+ mode:cpp
+ c-file-style:"stroustrup"
+ c-file-offsets:((innamespace . 0)(inline-open . 0))
+ indent-tabs-mode:nil
+ fill-column:99
+ End:
+*/
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :
diff --git a/src/extension/internal/libwpg/WPGOLEStream.h b/src/extension/internal/libwpg/WPGOLEStream.h
index 49562bfd6..af4a3d02f 100644
--- a/src/extension/internal/libwpg/WPGOLEStream.h
+++ b/src/extension/internal/libwpg/WPGOLEStream.h
@@ -1,28 +1,28 @@
/* POLE - Portable C++ library to access OLE Storage
Copyright (C) 2002-2005 Ariya Hidayat <ariya@kde.org>
-
- Redistribution and use in source and binary forms, with or without
- modification, are permitted provided that the following conditions
- are met:
- * Redistributions of source code must retain the above copyright notice,
- this list of conditions and the following disclaimer.
- * Redistributions in binary form must reproduce the above copyright notice,
- this list of conditions and the following disclaimer in the documentation
- and/or other materials provided with the distribution.
- * Neither the name of the authors nor the names of its contributors may be
- used to endorse or promote products derived from this software without
- specific prior written permission.
-
- THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
- AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
- LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
- CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
- SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
- INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
- CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
- ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
+
+ Redistribution and use in source and binary forms, with or without
+ modification, are permitted provided that the following conditions
+ are met:
+ * Redistributions of source code must retain the above copyright notice,
+ this list of conditions and the following disclaimer.
+ * Redistributions in binary form must reproduce the above copyright notice,
+ this list of conditions and the following disclaimer in the documentation
+ and/or other materials provided with the distribution.
+ * Neither the name of the authors nor the names of its contributors may be
+ used to endorse or promote products derived from this software without
+ specific prior written permission.
+
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
THE POSSIBILITY OF SUCH DAMAGE.
*/
@@ -46,10 +46,10 @@ class Storage
friend class Stream;
public:
-
+
// for Storage::result()
- enum { Ok, OpenFailed, NotOLE, BadOLE, UnknownError };
-
+ enum { Ok, OpenFailed, NotOLE, BadOLE, UnknownError };
+
/**
* Constructs a storage with data.
**/
@@ -84,19 +84,19 @@ class Stream
friend class Storage;
friend class StorageIO;
-public:
-
- /**
- * Creates a new stream.
- */
- // name must be absolute, e.g "/PerfectOffice_MAIN"
- Stream( Storage* storage, const std::string& name );
-
- /**
- * Destroys the stream.
- */
+public:
+
+ /**
+ * Creates a new stream.
+ */
+ // name must be absolute, e.g "/PerfectOffice_MAIN"
+ Stream( Storage* storage, const std::string& name );
+
+ /**
+ * Destroys the stream.
+ */
~Stream();
-
+
/**
* Returns the stream size.
**/
@@ -105,11 +105,11 @@ public:
/**
* Reads a block of data.
**/
- unsigned long read( unsigned char* data, unsigned long maxlen );
-
+ unsigned long read( unsigned char* data, unsigned long maxlen );
+
private:
StreamIO* io;
-
+
// no copy or assign
Stream( const Stream& );
Stream& operator=( const Stream& );
diff --git a/src/extension/internal/libwpg/WPGXParser.cpp b/src/extension/internal/libwpg/WPGXParser.cpp
index dcdc44c50..e25b53aab 100644
--- a/src/extension/internal/libwpg/WPGXParser.cpp
+++ b/src/extension/internal/libwpg/WPGXParser.cpp
@@ -1,103 +1,103 @@
-/* libwpg
- * Copyright (C) 2006 Ariya Hidayat (ariya@kde.org)
- * Copyright (C) 2004 Marc Oude Kotte (marc@solcon.nl)
- * Copyright (C) 2005 Fridrich Strba (fridrich.strba@bluewin.ch)
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- * Boston, MA 02111-1301 USA
- *
- * For further information visit http://libwpg.sourceforge.net
- */
-
-/* "This product is not manufactured, approved, or supported by
- * Corel Corporation or Corel Corporation Limited."
- */
-
-#include "WPGXParser.h"
-
-using namespace libwpg;
-
-WPGXParser::WPGXParser(WPGInputStream *input, WPGPaintInterface* painter):
- m_input(input), m_painter(painter)
-{
-}
-
-unsigned char WPGXParser::readU8()
-{
- return m_input->getc();
-}
-
-unsigned short WPGXParser::readU16()
-{
- unsigned short p0 = (unsigned short)readU8();
- unsigned short p1 = (unsigned short)readU8();
- return p0|(p1<<8);
-}
-
-unsigned long WPGXParser::readU32()
-{
- unsigned long p0 = (unsigned short)readU8();
- unsigned long p1 = (unsigned short)readU8();
- unsigned long p2 = (unsigned short)readU8();
- unsigned long p3 = (unsigned short)readU8();
- return p0|(p1<<8)|(p2<<16)|(p3<<24);
-}
-
-char WPGXParser::readS8()
-{
- return (char)m_input->getc();
-}
-
-short WPGXParser::readS16()
-{
- short p0 = readU8();
- short p1 = readS8();
- return p0|(p1<<8);
-}
-
-long WPGXParser::readS32()
-{
- long p0 = readU8();
- long p1 = readU8();
- long p2 = readU8();
- long p3 = readS8();
- return p0|(p1<<8)|(p2<<16)|(p3<<24);
-}
-
-unsigned int WPGXParser::readVariableLengthInteger()
-{
- // read a byte
- unsigned char value8 = readU8();
- // if it's in the range 0-0xFE, then we have a 8-bit value
- if (value8<=0xFE) {
- return (unsigned int)value8;
- } else {
- // now read a 16 bit value
- unsigned short value16 = readU16();
- // if the MSB is 1, we have a 32 bit value
- if (value16>>15) {
- // read the next 16 bit value (LSB part, in value16 resides the MSB part)
- unsigned long lvalue16 = readU16();
- unsigned long value32 = value16 & 0x7fff; // mask out the MSB
- return (value32<<16)+lvalue16;
- } else {
- // we have a 16 bit value, return it
- return (unsigned int)value16;
- }
- }
-
- // unreachable
- return 0;
-}
+/* libwpg
+ * Copyright (C) 2006 Ariya Hidayat (ariya@kde.org)
+ * Copyright (C) 2004 Marc Oude Kotte (marc@solcon.nl)
+ * Copyright (C) 2005 Fridrich Strba (fridrich.strba@bluewin.ch)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02111-1301 USA
+ *
+ * For further information visit http://libwpg.sourceforge.net
+ */
+
+/* "This product is not manufactured, approved, or supported by
+ * Corel Corporation or Corel Corporation Limited."
+ */
+
+#include "WPGXParser.h"
+
+using namespace libwpg;
+
+WPGXParser::WPGXParser(WPGInputStream *input, WPGPaintInterface* painter):
+ m_input(input), m_painter(painter)
+{
+}
+
+unsigned char WPGXParser::readU8()
+{
+ return m_input->getc();
+}
+
+unsigned short WPGXParser::readU16()
+{
+ unsigned short p0 = (unsigned short)readU8();
+ unsigned short p1 = (unsigned short)readU8();
+ return p0|(p1<<8);
+}
+
+unsigned long WPGXParser::readU32()
+{
+ unsigned long p0 = (unsigned short)readU8();
+ unsigned long p1 = (unsigned short)readU8();
+ unsigned long p2 = (unsigned short)readU8();
+ unsigned long p3 = (unsigned short)readU8();
+ return p0|(p1<<8)|(p2<<16)|(p3<<24);
+}
+
+char WPGXParser::readS8()
+{
+ return (char)m_input->getc();
+}
+
+short WPGXParser::readS16()
+{
+ short p0 = readU8();
+ short p1 = readS8();
+ return p0|(p1<<8);
+}
+
+long WPGXParser::readS32()
+{
+ long p0 = readU8();
+ long p1 = readU8();
+ long p2 = readU8();
+ long p3 = readS8();
+ return p0|(p1<<8)|(p2<<16)|(p3<<24);
+}
+
+unsigned int WPGXParser::readVariableLengthInteger()
+{
+ // read a byte
+ unsigned char value8 = readU8();
+ // if it's in the range 0-0xFE, then we have a 8-bit value
+ if (value8<=0xFE) {
+ return (unsigned int)value8;
+ } else {
+ // now read a 16 bit value
+ unsigned short value16 = readU16();
+ // if the MSB is 1, we have a 32 bit value
+ if (value16>>15) {
+ // read the next 16 bit value (LSB part, in value16 resides the MSB part)
+ unsigned long lvalue16 = readU16();
+ unsigned long value32 = value16 & 0x7fff; // mask out the MSB
+ return (value32<<16)+lvalue16;
+ } else {
+ // we have a 16 bit value, return it
+ return (unsigned int)value16;
+ }
+ }
+
+ // unreachable
+ return 0;
+}
diff --git a/src/extension/internal/libwpg/WPGXParser.h b/src/extension/internal/libwpg/WPGXParser.h
index 71c78d2c0..d7fd4cb5a 100644
--- a/src/extension/internal/libwpg/WPGXParser.h
+++ b/src/extension/internal/libwpg/WPGXParser.h
@@ -1,60 +1,60 @@
-/* libwpg
- * Copyright (C) 2006 Ariya Hidayat (ariya@kde.org)
- * Copyright (C) 2004 Marc Oude Kotte (marc@solcon.nl)
- * Copyright (C) 2005 Fridrich Strba (fridrich.strba@bluewin.ch)
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- * Boston, MA 02111-1301 USA
- *
- * For further information visit http://libwpg.sourceforge.net
- */
-
-/* "This product is not manufactured, approved, or supported by
- * Corel Corporation or Corel Corporation Limited."
- */
-
-#ifndef __WPGXPARSER_H__
-#define __WPGXPARSER_H__
-
-#include "WPGPaintInterface.h"
-#include "WPGStream.h"
-#include "WPGColor.h"
-
-#include <map>
-
-using namespace libwpg;
-
-class WPGXParser
-{
-public:
- WPGXParser(WPGInputStream *input, WPGPaintInterface* painter);
- virtual ~WPGXParser() {}
- virtual bool parse() = 0;
-
- unsigned char readU8();
- unsigned short readU16();
- unsigned long readU32();
- char readS8();
- short readS16();
- long readS32();
- unsigned int readVariableLengthInteger();
-
-protected:
- WPGInputStream* m_input;
- WPGPaintInterface* m_painter;
- std::map<int,WPGColor> m_colorPalette;
-};
-
-#endif // __WPGXPARSER_H__
+/* libwpg
+ * Copyright (C) 2006 Ariya Hidayat (ariya@kde.org)
+ * Copyright (C) 2004 Marc Oude Kotte (marc@solcon.nl)
+ * Copyright (C) 2005 Fridrich Strba (fridrich.strba@bluewin.ch)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02111-1301 USA
+ *
+ * For further information visit http://libwpg.sourceforge.net
+ */
+
+/* "This product is not manufactured, approved, or supported by
+ * Corel Corporation or Corel Corporation Limited."
+ */
+
+#ifndef __WPGXPARSER_H__
+#define __WPGXPARSER_H__
+
+#include "WPGPaintInterface.h"
+#include "WPGStream.h"
+#include "WPGColor.h"
+
+#include <map>
+
+using namespace libwpg;
+
+class WPGXParser
+{
+public:
+ WPGXParser(WPGInputStream *input, WPGPaintInterface* painter);
+ virtual ~WPGXParser() {}
+ virtual bool parse() = 0;
+
+ unsigned char readU8();
+ unsigned short readU16();
+ unsigned long readU32();
+ char readS8();
+ short readS16();
+ long readS32();
+ unsigned int readVariableLengthInteger();
+
+protected:
+ WPGInputStream* m_input;
+ WPGPaintInterface* m_painter;
+ std::map<int,WPGColor> m_colorPalette;
+};
+
+#endif // __WPGXPARSER_H__
diff --git a/src/extension/internal/libwpg/WPGraphics.cpp b/src/extension/internal/libwpg/WPGraphics.cpp
index a7454d2a1..e120b802e 100644
--- a/src/extension/internal/libwpg/WPGraphics.cpp
+++ b/src/extension/internal/libwpg/WPGraphics.cpp
@@ -1,83 +1,83 @@
-/* libwpg
- * Copyright (C) 2006 Ariya Hidayat (ariya@kde.org)
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- * Boston, MA 02111-1301 USA
- *
- * For further information visit http://libwpg.sourceforge.net
- */
-
-/* "This product is not manufactured, approved, or supported by
- * Corel Corporation or Corel Corporation Limited."
- */
-
-#include "WPGraphics.h"
-#include "WPGHeader.h"
-#include "WPGStream.h"
-#include "WPGXParser.h"
-#include "WPG1Parser.h"
-#include "WPG2Parser.h"
-#include "libwpg_utils.h"
-
-using namespace libwpg;
-
-bool WPGraphics::isSupported(WPGInputStream* input)
-{
- WPGHeader header;
- if(!header.load(input))
- return false;
-
- return header.isSupported();
-}
-
-bool WPGraphics::parse(WPGInputStream* input, WPGPaintInterface* painter)
-{
- WPGXParser *parser = 0;
-
- WPG_DEBUG_MSG(("Loading header...\n"));
- WPGHeader header;
- if(!header.load(input))
- return false;
-
- if(!header.isSupported())
- {
- WPG_DEBUG_MSG(("Unsupported file format!\n"));
- return false;
- }
-
- // seek to the start of document
- input->seek(header.startOfDocument());
-
- switch (header.majorVersion()) {
- case 0x01: // WPG1
- WPG_DEBUG_MSG(("Parsing WPG1\n"));
- parser = new WPG1Parser(input, painter);
- parser->parse();
- break;
- case 0x02: // WPG2
- WPG_DEBUG_MSG(("Parsing WPG2\n"));
- parser = new WPG2Parser(input, painter);
- parser->parse();
- break;
- default: // other :-)
- WPG_DEBUG_MSG(("Unknown format\n"));
- break;
- }
-
- delete parser;
-
- return false;
-}
-
+/* libwpg
+ * Copyright (C) 2006 Ariya Hidayat (ariya@kde.org)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02111-1301 USA
+ *
+ * For further information visit http://libwpg.sourceforge.net
+ */
+
+/* "This product is not manufactured, approved, or supported by
+ * Corel Corporation or Corel Corporation Limited."
+ */
+
+#include "WPGraphics.h"
+#include "WPGHeader.h"
+#include "WPGStream.h"
+#include "WPGXParser.h"
+#include "WPG1Parser.h"
+#include "WPG2Parser.h"
+#include "libwpg_utils.h"
+
+using namespace libwpg;
+
+bool WPGraphics::isSupported(WPGInputStream* input)
+{
+ WPGHeader header;
+ if(!header.load(input))
+ return false;
+
+ return header.isSupported();
+}
+
+bool WPGraphics::parse(WPGInputStream* input, WPGPaintInterface* painter)
+{
+ WPGXParser *parser = 0;
+
+ WPG_DEBUG_MSG(("Loading header...\n"));
+ WPGHeader header;
+ if(!header.load(input))
+ return false;
+
+ if(!header.isSupported())
+ {
+ WPG_DEBUG_MSG(("Unsupported file format!\n"));
+ return false;
+ }
+
+ // seek to the start of document
+ input->seek(header.startOfDocument());
+
+ switch (header.majorVersion()) {
+ case 0x01: // WPG1
+ WPG_DEBUG_MSG(("Parsing WPG1\n"));
+ parser = new WPG1Parser(input, painter);
+ parser->parse();
+ break;
+ case 0x02: // WPG2
+ WPG_DEBUG_MSG(("Parsing WPG2\n"));
+ parser = new WPG2Parser(input, painter);
+ parser->parse();
+ break;
+ default: // other :-)
+ WPG_DEBUG_MSG(("Unknown format\n"));
+ break;
+ }
+
+ delete parser;
+
+ return false;
+}
+
diff --git a/src/extension/internal/libwpg/WPGraphics.h b/src/extension/internal/libwpg/WPGraphics.h
index 3226835ca..21abddd1b 100644
--- a/src/extension/internal/libwpg/WPGraphics.h
+++ b/src/extension/internal/libwpg/WPGraphics.h
@@ -1,46 +1,46 @@
-/* libwpg
- * Copyright (C) 2006 Ariya Hidayat (ariya@kde.org)
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public
- * License along with this library; if not, write to the
- * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
- * Boston, MA 02111-1301 USA
- *
- * For further information visit http://libwpg.sourceforge.net
- */
-
-/* "This product is not manufactured, approved, or supported by
- * Corel Corporation or Corel Corporation Limited."
- */
-
-#ifndef __WPGRAPHICS_H__
-#define __WPGRAPHICS_H__
-
-namespace libwpg
-{
-
-class WPGInputStream;
-class WPGPaintInterface;
-
-class WPGraphics
-{
-public:
-
- static bool isSupported(WPGInputStream* input);
-
- static bool parse(WPGInputStream* input, WPGPaintInterface* painter);
-};
-
-} // namespace libwpg
-
-#endif // __WPGRAPHICS_H__
+/* libwpg
+ * Copyright (C) 2006 Ariya Hidayat (ariya@kde.org)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ * Boston, MA 02111-1301 USA
+ *
+ * For further information visit http://libwpg.sourceforge.net
+ */
+
+/* "This product is not manufactured, approved, or supported by
+ * Corel Corporation or Corel Corporation Limited."
+ */
+
+#ifndef __WPGRAPHICS_H__
+#define __WPGRAPHICS_H__
+
+namespace libwpg
+{
+
+class WPGInputStream;
+class WPGPaintInterface;
+
+class WPGraphics
+{
+public:
+
+ static bool isSupported(WPGInputStream* input);
+
+ static bool parse(WPGInputStream* input, WPGPaintInterface* painter);
+};
+
+} // namespace libwpg
+
+#endif // __WPGRAPHICS_H__
diff --git a/src/extension/internal/wpg-input.cpp b/src/extension/internal/wpg-input.cpp
index 28e947614..0326b150a 100644
--- a/src/extension/internal/wpg-input.cpp
+++ b/src/extension/internal/wpg-input.cpp
@@ -1,365 +1,365 @@
-/*
- * This file came from libwpg as a source, their utility wpg2svg
- * specifically. It has been modified to work as an Inkscape extension.
- * The Inkscape extension code is covered by this copyright, but the
- * rest is covered by the one bellow.
- *
- * Authors:
- * Ted Gould <ted@gould.cx>
- *
- * Copyright (C) 2006 Authors
- *
- * Released under GNU GPL, read the file 'COPYING' for more information
- *
- */
-
-/* libwpg
- * Copyright (C) 2006 Ariya Hidayat (ariya@kde.org)
- * Copyright (C) 2005 Fridrich Strba (fridrich.strba@bluewin.ch)
- *
- * This library is free software; you can redistribute it and/or
- * modify it under the terms of the GNU Library General Public
- * License as published by the Free Software Foundation; either
- * version 2 of the License, or (at your option) any later version.
- *
- * This library is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Library General Public License for more details.
- *
- * You should have received a copy of the GNU Library General Public
- * License along with this library; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- * For further information visit http://libwpg.sourceforge.net
- */
-
-/* "This product is not manufactured, approved, or supported by
- * Corel Corporation or Corel Corporation Limited."
- */
-
-#include <stdio.h>
-
-#include "wpg-input.h"
-#include "extension/system.h"
-#include "extension/input.h"
-#include "document.h"
-
-#include "libwpg/libwpg.h"
-#include "libwpg/WPGStreamImplementation.h"
-
-using namespace libwpg;
-
-namespace Inkscape {
-namespace Extension {
-namespace Internal {
-
-class InkscapePainter : public libwpg::WPGPaintInterface {
-public:
- InkscapePainter();
-
- void startDocument(double imageWidth, double imageHeight);
- void endDocument();
- void startLayer(unsigned int id);
- void endLayer(unsigned int id);
-
- void setPen(const WPGPen& pen);
- void setBrush(const WPGBrush& brush);
- void setFillRule(FillRule rule);
-
- void drawRectangle(const WPGRect& rect, double rx, double ry);
- void drawEllipse(const WPGPoint& center, double rx, double ry);
- void drawPolygon(const WPGPointArray& vertices);
- void drawPath(const WPGPath& path);
-
-private:
- WPGPen m_pen;
- WPGBrush m_brush;
- FillRule m_fillRule;
- int m_gradientIndex;
- void writeStyle();
- void printf (char * fmt, ...) {
- va_list args;
- va_start(args, fmt);
- gchar * buf = g_strdup_vprintf(fmt, args);
- va_end(args);
- if (buf) {
- document += buf;
- g_free(buf);
- }
- }
-
-public:
- Glib::ustring document;
-};
-
-InkscapePainter::InkscapePainter(): m_fillRule(AlternatingFill), m_gradientIndex(1)
-{
-}
-
-void InkscapePainter::startDocument(double width, double height)
-{
- document = "";
- printf("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n");
- printf("<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"");
- printf(" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n");
-
-// printf("<!-- Created with wpg2svg/libwpg %s -->\n", LIBWPG_VERSION_STRING);
-
- printf("<svg version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\" ");
- printf("xmlns:xlink=\"http://www.w3.org/1999/xlink\" ");
- printf("width=\"%g\" height=\"%f\" >\n", 72*width, 72*height);
-
- m_gradientIndex = 1;
-}
-
-void InkscapePainter::endDocument()
-{
- printf("</svg>\n");
-}
-
-void InkscapePainter::setPen(const WPGPen& pen)
-{
- m_pen = pen;
-}
-
-void InkscapePainter::setBrush(const WPGBrush& brush)
-{
- m_brush = brush;
-
- if(m_brush.style == WPGBrush::Gradient)
- {
- double angle = m_brush.gradient.angle();
-
- printf("<defs>\n");
- printf(" <linearGradient id=\"grad%d\" >\n", m_gradientIndex++);
- for(unsigned c = 0; c < m_brush.gradient.count(); c++)
- {
- // round to nearest percentage
- int ofs = (int)(100.0*m_brush.gradient.stopOffset(c)+0.5);
-
- WPGColor color = m_brush.gradient.stopColor(c);
- printf(" <stop offset=\"%d%%\" stop-color=\"#%02x%02x%02x\" />\n",
- ofs, color.red, color.green, color.blue);
- }
- printf(" </linearGradient>\n");
-
- // not a simple horizontal gradient
- if(angle != -90.0)
- {
- printf(" <linearGradient xlink:href=\"#grad%d\"", m_gradientIndex-1);
- printf(" id=\"grad%d\" ", m_gradientIndex++);
- printf("x1=\"0\" y1=\"0\" x2=\"0\" y2=\"1\" ");
- printf("gradientTransform=\"rotate(%f)\" ", angle);
- printf("gradientUnits=\"objectBoundingBox\" >\n");
- printf(" </linearGradient>\n");
- }
-
- printf("</defs>\n");
- }
-}
-
-void InkscapePainter::setFillRule(FillRule rule)
-{
- m_fillRule = rule;
-}
-
-void InkscapePainter::startLayer(unsigned int id)
-{
- printf("<g id=\"Layer%d\" >\n", id);
-}
-
-void InkscapePainter::endLayer(unsigned int)
-{
- printf("</g>\n");
-}
-
-void InkscapePainter::drawRectangle(const WPGRect& rect, double rx, double ry)
-{
- printf("<rect ");
- printf("x=\"%f\" y=\"%f\" ", 72*rect.x1, 72*rect.y1);
- printf("width=\"%f\" height=\"%f\" ", 72*rect.width(), 72*rect.height());
- if((rx !=0) || (ry !=0))
- printf("rx=\"%f\" ry=\"%f\" ", 72*rx, 72*ry);
- writeStyle();
- printf("/>\n");
-}
-
-void InkscapePainter::drawEllipse(const WPGPoint& center, double rx, double ry)
-{
- printf("<ellipse ");
- printf("cx=\"%f\" cy=\"%f\" ", 72*center.x, 72*center.y);
- printf("rx=\"%f\" ry=\"%f\" ", 72*rx, 72*ry);
- writeStyle();
- printf("/>\n");
-}
-
-void InkscapePainter::drawPolygon(const WPGPointArray& vertices)
-{
- if(vertices.count() < 2)
- return;
-
- if(vertices.count() == 2)
- {
- const WPGPoint& p1 = vertices[0];
- const WPGPoint& p2 = vertices[1];
- printf("<line ");
- printf("x1=\"%f\" y1=\"%f\" ", 72*p1.x, 72*p1.y);
- printf("x2=\"%f\" y2=\"%f\"\n", 72*p2.x, 72*p2.y);
- writeStyle();
- printf("/>\n");
- }
- else
- {
- printf("<polyline ");
- printf("points=\"");
- for(unsigned i = 0; i < vertices.count(); i++)
- {
- printf("%f %f", 72*vertices[i].x, 72*vertices[i].y);
- if(i < vertices.count()-1) printf(", ");
- }
- printf("\"\n");
- writeStyle();
- printf("/>\n");
- }
-}
-
-void InkscapePainter::drawPath(const WPGPath& path)
-{
- printf("<path d=\"");
- for(unsigned i = 0; i < path.count(); i++)
- {
- WPGPathElement element = path.element(i);
- WPGPoint point = element.point;
- switch(element.type)
- {
- case WPGPathElement::MoveToElement:
- printf("\n M%f,%f ", 72*point.x, 72*point.y );
- break;
-
- case WPGPathElement::LineToElement:
- printf("\n L%f,%f ", 72*point.x, 72*point.y );
- break;
-
- case WPGPathElement::CurveToElement:
- printf("C");
- printf("%f,%f ", 72*element.extra1.x, 72*element.extra1.y );
- printf("%f,%f ", 72*element.extra2.x, 72*element.extra2.y );
- printf("%f,%f", 72*point.x, 72*point.y );
- break;
-
- default:
- break;
- }
- }
-
- if(path.closed)
- printf("Z");
-
- printf("\" \n");
- writeStyle();
- printf("/>\n");
-}
-
-// create "style" attribute based on current pen and brush
-void InkscapePainter::writeStyle()
-{
- printf("style=\"");
-
- const WPGColor& color = m_pen.foreColor;
- printf("stroke-width: %f; ", 72*m_pen.width);
- if(m_pen.width > 0.0)
- {
- printf("stroke: rgb(%d,%d,%d); ", color.red, color.green, color.blue);
- if(color.alpha != 0)
- // alpha = 0 means opacity = 1.0, alpha = 256 means opacity = 0
- printf("stroke-opacity: %f; ", 1.0-(color.alpha/256.0));
- }
-
- if(!m_pen.solid)
- {
- printf("stroke-dasharray: ");
- for(unsigned i = 0; i < m_pen.dashArray.count(); i++)
- {
- printf("%f", 72*m_pen.dashArray.at(i)*m_pen.width);
- if(i < m_pen.dashArray.count()-1)
- printf(", ");
- }
- printf("; ");
- }
-
- if(m_brush.style == WPGBrush::NoBrush)
- printf("fill: none; ");
-
- if(m_fillRule == InkscapePainter::WindingFill)
- printf("fill-rule: nonzero; ");
- else if(m_fillRule == InkscapePainter::AlternatingFill)
- printf("fill-rule: evenodd; ");
-
- if(m_brush.style == WPGBrush::Gradient)
- printf("fill: url(#grad%d); ", m_gradientIndex-1);
-
- if(m_brush.style == WPGBrush::Solid)
- printf("fill: rgb(%d,%d,%d); ", m_brush.foreColor.red,
- m_brush.foreColor.green, m_brush.foreColor.blue);
-
- printf("\""); // style
-}
-
-SPDocument *
-WpgInput::open(Inkscape::Extension::Input * mod, const gchar * uri) {
- WPGInputStream* input = new WPGFileStream(uri);
- if (input->isOle()) {
- WPGInputStream* olestream = input->getWPGOleStream();
- if (olestream) {
- delete input;
- input = olestream;
- }
- }
-
- if (!WPGraphics::isSupported(input)) {
- //! \todo Dialog here
- // fprintf(stderr, "ERROR: Unsupported file format (unsupported version) or file is encrypted!\n");
- // printf("I'm giving up not supported\n");
- return NULL;
- }
-
- InkscapePainter painter;
- WPGraphics::parse(input, &painter);
-
- //printf("I've got a doc: \n%s", painter.document.c_str());
-
- return sp_document_new_from_mem(painter.document.c_str(), strlen(painter.document.c_str()), TRUE);
-}
-
-#include "clear-n_.h"
-
-void
-WpgInput::init(void) {
- Inkscape::Extension::Extension * ext;
-
- ext = Inkscape::Extension::build_from_mem(
- "<inkscape-extension>\n"
- "<name>" N_("WPG Input") "</name>\n"
- "<id>org.inkscape.input.wpg</id>\n"
- "<input>\n"
- "<extension>.wpg</extension>\n"
- "<mimetype>image/x-wpg</mimetype>\n"
- "<filetypename>" N_("WordPerfect Graphics (*.wpg)") "</filetypename>\n"
- "<filetypetooltip>" N_("Vector graphics format used by Corel WordPerfect") "</filetypetooltip>\n"
- "</input>\n"
- "</inkscape-extension>", new WpgInput());
-} // init
-
-} } } /* namespace Inkscape, Extension, Implementation */
-
-/*
- Local Variables:
- mode:c++
- c-file-style:"stroustrup"
- c-file-offsets:((innamespace . 0)(inline-open . 0))
- indent-tabs-mode:nil
- fill-column:99
- End:
-*/
-// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :
+/*
+ * This file came from libwpg as a source, their utility wpg2svg
+ * specifically. It has been modified to work as an Inkscape extension.
+ * The Inkscape extension code is covered by this copyright, but the
+ * rest is covered by the one bellow.
+ *
+ * Authors:
+ * Ted Gould <ted@gould.cx>
+ *
+ * Copyright (C) 2006 Authors
+ *
+ * Released under GNU GPL, read the file 'COPYING' for more information
+ *
+ */
+
+/* libwpg
+ * Copyright (C) 2006 Ariya Hidayat (ariya@kde.org)
+ * Copyright (C) 2005 Fridrich Strba (fridrich.strba@bluewin.ch)
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 of the License, or (at your option) any later version.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ *
+ * For further information visit http://libwpg.sourceforge.net
+ */
+
+/* "This product is not manufactured, approved, or supported by
+ * Corel Corporation or Corel Corporation Limited."
+ */
+
+#include <stdio.h>
+
+#include "wpg-input.h"
+#include "extension/system.h"
+#include "extension/input.h"
+#include "document.h"
+
+#include "libwpg/libwpg.h"
+#include "libwpg/WPGStreamImplementation.h"
+
+using namespace libwpg;
+
+namespace Inkscape {
+namespace Extension {
+namespace Internal {
+
+class InkscapePainter : public libwpg::WPGPaintInterface {
+public:
+ InkscapePainter();
+
+ void startDocument(double imageWidth, double imageHeight);
+ void endDocument();
+ void startLayer(unsigned int id);
+ void endLayer(unsigned int id);
+
+ void setPen(const WPGPen& pen);
+ void setBrush(const WPGBrush& brush);
+ void setFillRule(FillRule rule);
+
+ void drawRectangle(const WPGRect& rect, double rx, double ry);
+ void drawEllipse(const WPGPoint& center, double rx, double ry);
+ void drawPolygon(const WPGPointArray& vertices);
+ void drawPath(const WPGPath& path);
+
+private:
+ WPGPen m_pen;
+ WPGBrush m_brush;
+ FillRule m_fillRule;
+ int m_gradientIndex;
+ void writeStyle();
+ void printf (char * fmt, ...) {
+ va_list args;
+ va_start(args, fmt);
+ gchar * buf = g_strdup_vprintf(fmt, args);
+ va_end(args);
+ if (buf) {
+ document += buf;
+ g_free(buf);
+ }
+ }
+
+public:
+ Glib::ustring document;
+};
+
+InkscapePainter::InkscapePainter(): m_fillRule(AlternatingFill), m_gradientIndex(1)
+{
+}
+
+void InkscapePainter::startDocument(double width, double height)
+{
+ document = "";
+ printf("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n");
+ printf("<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\"");
+ printf(" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd\">\n");
+
+// printf("<!-- Created with wpg2svg/libwpg %s -->\n", LIBWPG_VERSION_STRING);
+
+ printf("<svg version=\"1.1\" xmlns=\"http://www.w3.org/2000/svg\" ");
+ printf("xmlns:xlink=\"http://www.w3.org/1999/xlink\" ");
+ printf("width=\"%g\" height=\"%f\" >\n", 72*width, 72*height);
+
+ m_gradientIndex = 1;
+}
+
+void InkscapePainter::endDocument()
+{
+ printf("</svg>\n");
+}
+
+void InkscapePainter::setPen(const WPGPen& pen)
+{
+ m_pen = pen;
+}
+
+void InkscapePainter::setBrush(const WPGBrush& brush)
+{
+ m_brush = brush;
+
+ if(m_brush.style == WPGBrush::Gradient)
+ {
+ double angle = m_brush.gradient.angle();
+
+ printf("<defs>\n");
+ printf(" <linearGradient id=\"grad%d\" >\n", m_gradientIndex++);
+ for(unsigned c = 0; c < m_brush.gradient.count(); c++)
+ {
+ // round to nearest percentage
+ int ofs = (int)(100.0*m_brush.gradient.stopOffset(c)+0.5);
+
+ WPGColor color = m_brush.gradient.stopColor(c);
+ printf(" <stop offset=\"%d%%\" stop-color=\"#%02x%02x%02x\" />\n",
+ ofs, color.red, color.green, color.blue);
+ }
+ printf(" </linearGradient>\n");
+
+ // not a simple horizontal gradient
+ if(angle != -90.0)
+ {
+ printf(" <linearGradient xlink:href=\"#grad%d\"", m_gradientIndex-1);
+ printf(" id=\"grad%d\" ", m_gradientIndex++);
+ printf("x1=\"0\" y1=\"0\" x2=\"0\" y2=\"1\" ");
+ printf("gradientTransform=\"rotate(%f)\" ", angle);
+ printf("gradientUnits=\"objectBoundingBox\" >\n");
+ printf(" </linearGradient>\n");
+ }
+
+ printf("</defs>\n");
+ }
+}
+
+void InkscapePainter::setFillRule(FillRule rule)
+{
+ m_fillRule = rule;
+}
+
+void InkscapePainter::startLayer(unsigned int id)
+{
+ printf("<g id=\"Layer%d\" >\n", id);
+}
+
+void InkscapePainter::endLayer(unsigned int)
+{
+ printf("</g>\n");
+}
+
+void InkscapePainter::drawRectangle(const WPGRect& rect, double rx, double ry)
+{
+ printf("<rect ");
+ printf("x=\"%f\" y=\"%f\" ", 72*rect.x1, 72*rect.y1);
+ printf("width=\"%f\" height=\"%f\" ", 72*rect.width(), 72*rect.height());
+ if((rx !=0) || (ry !=0))
+ printf("rx=\"%f\" ry=\"%f\" ", 72*rx, 72*ry);
+ writeStyle();
+ printf("/>\n");
+}
+
+void InkscapePainter::drawEllipse(const WPGPoint& center, double rx, double ry)
+{
+ printf("<ellipse ");
+ printf("cx=\"%f\" cy=\"%f\" ", 72*center.x, 72*center.y);
+ printf("rx=\"%f\" ry=\"%f\" ", 72*rx, 72*ry);
+ writeStyle();
+ printf("/>\n");
+}
+
+void InkscapePainter::drawPolygon(const WPGPointArray& vertices)
+{
+ if(vertices.count() < 2)
+ return;
+
+ if(vertices.count() == 2)
+ {
+ const WPGPoint& p1 = vertices[0];
+ const WPGPoint& p2 = vertices[1];
+ printf("<line ");
+ printf("x1=\"%f\" y1=\"%f\" ", 72*p1.x, 72*p1.y);
+ printf("x2=\"%f\" y2=\"%f\"\n", 72*p2.x, 72*p2.y);
+ writeStyle();
+ printf("/>\n");
+ }
+ else
+ {
+ printf("<polyline ");
+ printf("points=\"");
+ for(unsigned i = 0; i < vertices.count(); i++)
+ {
+ printf("%f %f", 72*vertices[i].x, 72*vertices[i].y);
+ if(i < vertices.count()-1) printf(", ");
+ }
+ printf("\"\n");
+ writeStyle();
+ printf("/>\n");
+ }
+}
+
+void InkscapePainter::drawPath(const WPGPath& path)
+{
+ printf("<path d=\"");
+ for(unsigned i = 0; i < path.count(); i++)
+ {
+ WPGPathElement element = path.element(i);
+ WPGPoint point = element.point;
+ switch(element.type)
+ {
+ case WPGPathElement::MoveToElement:
+ printf("\n M%f,%f ", 72*point.x, 72*point.y );
+ break;
+
+ case WPGPathElement::LineToElement:
+ printf("\n L%f,%f ", 72*point.x, 72*point.y );
+ break;
+
+ case WPGPathElement::CurveToElement:
+ printf("C");
+ printf("%f,%f ", 72*element.extra1.x, 72*element.extra1.y );
+ printf("%f,%f ", 72*element.extra2.x, 72*element.extra2.y );
+ printf("%f,%f", 72*point.x, 72*point.y );
+ break;
+
+ default:
+ break;
+ }
+ }
+
+ if(path.closed)
+ printf("Z");
+
+ printf("\" \n");
+ writeStyle();
+ printf("/>\n");
+}
+
+// create "style" attribute based on current pen and brush
+void InkscapePainter::writeStyle()
+{
+ printf("style=\"");
+
+ const WPGColor& color = m_pen.foreColor;
+ printf("stroke-width: %f; ", 72*m_pen.width);
+ if(m_pen.width > 0.0)
+ {
+ printf("stroke: rgb(%d,%d,%d); ", color.red, color.green, color.blue);
+ if(color.alpha != 0)
+ // alpha = 0 means opacity = 1.0, alpha = 256 means opacity = 0
+ printf("stroke-opacity: %f; ", 1.0-(color.alpha/256.0));
+ }
+
+ if(!m_pen.solid)
+ {
+ printf("stroke-dasharray: ");
+ for(unsigned i = 0; i < m_pen.dashArray.count(); i++)
+ {
+ printf("%f", 72*m_pen.dashArray.at(i)*m_pen.width);
+ if(i < m_pen.dashArray.count()-1)
+ printf(", ");
+ }
+ printf("; ");
+ }
+
+ if(m_brush.style == WPGBrush::NoBrush)
+ printf("fill: none; ");
+
+ if(m_fillRule == InkscapePainter::WindingFill)
+ printf("fill-rule: nonzero; ");
+ else if(m_fillRule == InkscapePainter::AlternatingFill)
+ printf("fill-rule: evenodd; ");
+
+ if(m_brush.style == WPGBrush::Gradient)
+ printf("fill: url(#grad%d); ", m_gradientIndex-1);
+
+ if(m_brush.style == WPGBrush::Solid)
+ printf("fill: rgb(%d,%d,%d); ", m_brush.foreColor.red,
+ m_brush.foreColor.green, m_brush.foreColor.blue);
+
+ printf("\""); // style
+}
+
+SPDocument *
+WpgInput::open(Inkscape::Extension::Input * mod, const gchar * uri) {
+ WPGInputStream* input = new WPGFileStream(uri);
+ if (input->isOle()) {
+ WPGInputStream* olestream = input->getWPGOleStream();
+ if (olestream) {
+ delete input;
+ input = olestream;
+ }
+ }
+
+ if (!WPGraphics::isSupported(input)) {
+ //! \todo Dialog here
+ // fprintf(stderr, "ERROR: Unsupported file format (unsupported version) or file is encrypted!\n");
+ // printf("I'm giving up not supported\n");
+ return NULL;
+ }
+
+ InkscapePainter painter;
+ WPGraphics::parse(input, &painter);
+
+ //printf("I've got a doc: \n%s", painter.document.c_str());
+
+ return sp_document_new_from_mem(painter.document.c_str(), strlen(painter.document.c_str()), TRUE);
+}
+
+#include "clear-n_.h"
+
+void
+WpgInput::init(void) {
+ Inkscape::Extension::Extension * ext;
+
+ ext = Inkscape::Extension::build_from_mem(
+ "<inkscape-extension>\n"
+ "<name>" N_("WPG Input") "</name>\n"
+ "<id>org.inkscape.input.wpg</id>\n"
+ "<input>\n"
+ "<extension>.wpg</extension>\n"
+ "<mimetype>image/x-wpg</mimetype>\n"
+ "<filetypename>" N_("WordPerfect Graphics (*.wpg)") "</filetypename>\n"
+ "<filetypetooltip>" N_("Vector graphics format used by Corel WordPerfect") "</filetypetooltip>\n"
+ "</input>\n"
+ "</inkscape-extension>", new WpgInput());
+} // init
+
+} } } /* namespace Inkscape, Extension, Implementation */
+
+/*
+ Local Variables:
+ mode:c++
+ c-file-style:"stroustrup"
+ c-file-offsets:((innamespace . 0)(inline-open . 0))
+ indent-tabs-mode:nil
+ fill-column:99
+ End:
+*/
+// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :