diff --git a/src/extension/internal/emf-win32-print.cpp b/src/extension/internal/emf-win32-print.cpp
index b40eec46297f540cddbde7e5764009ac2a066b07..6e0a7bf0b6e13bd59de1e24c36813617ee62ad47 100644 (file)
-/** \file\r
- * Enhanced Metafile Printing.\r
- */\r
-/*\r
- * Authors:\r
- * Ulf Erikson <ulferikson@users.sf.net>\r
- *\r
- * Copyright (C) 2006 Authors\r
- *\r
- * Released under GNU GPL, read the file 'COPYING' for more information\r
- */\r
-/*\r
- * References:\r
- * - How to Create & Play Enhanced Metafiles in Win32\r
- * http://support.microsoft.com/kb/q145999/\r
- * - INFO: Windows Metafile Functions & Aldus Placeable Metafiles\r
- * http://support.microsoft.com/kb/q66949/\r
- * - Metafile Functions\r
- * http://msdn.microsoft.com/library/en-us/gdi/metafile_0whf.asp\r
- * - Metafile Structures\r
- * http://msdn.microsoft.com/library/en-us/gdi/metafile_5hkj.asp\r
- */\r
-\r
-#ifdef WIN32\r
-\r
-#ifdef HAVE_CONFIG_H\r
-# include "config.h"\r
-#endif\r
-\r
-#include <string.h>\r
-#include <signal.h>\r
-#include <errno.h>\r
-\r
-#include "libnr/n-art-bpath.h"\r
-#include "libnr/nr-point-matrix-ops.h"\r
-#include "libnr/nr-rect.h"\r
-#include "libnr/nr-matrix.h"\r
-#include "libnr/nr-matrix-fns.h"\r
-#include "libnr/nr-path.h"\r
-#include "libnr/nr-pixblock.h"\r
-#include "display/canvas-bpath.h"\r
-#include "sp-item.h"\r
-\r
-#include "glib.h"\r
-#include "gtk/gtkdialog.h"\r
-#include "gtk/gtkbox.h"\r
-#include "gtk/gtkstock.h"\r
-\r
-#include "glibmm/i18n.h"\r
-#include "enums.h"\r
-#include "document.h"\r
-#include "style.h"\r
-#include "sp-paint-server.h"\r
-#include "inkscape_version.h"\r
-\r
-#include "win32.h"\r
-#include "emf-win32-print.h"\r
-\r
-#include "unit-constants.h"\r
-\r
-#include "extension/extension.h"\r
-#include "extension/system.h"\r
-#include "extension/print.h"\r
-\r
-#include "io/sys.h"\r
-\r
-#include "macros.h"\r
-\r
-#define WIN32_LEAN_AND_MEAN\r
-#include <windows.h>\r
-\r
-namespace Inkscape {\r
-namespace Extension {\r
-namespace Internal {\r
-\r
-static float dwDPI = 2540;\r
-\r
-\r
-PrintEmfWin32::PrintEmfWin32 (void):\r
- hdc(NULL),\r
- hbrush(NULL),\r
- hpen(NULL),\r
- fill_path(NULL)\r
-{\r
-}\r
-\r
-\r
-PrintEmfWin32::~PrintEmfWin32 (void)\r
-{\r
- if (hdc) {\r
- HENHMETAFILE metafile = CloseEnhMetaFile( hdc );\r
- if ( metafile ) {\r
- DeleteEnhMetaFile( metafile );\r
- }\r
- DeleteDC( hdc );\r
- }\r
-\r
- /* restore default signal handling for SIGPIPE */\r
-#if !defined(_WIN32) && !defined(__WIN32__)\r
- (void) signal(SIGPIPE, SIG_DFL);\r
-#endif\r
- return;\r
-}\r
-\r
-\r
-unsigned int\r
-PrintEmfWin32::setup (Inkscape::Extension::Print *mod)\r
-{\r
- return TRUE;\r
-}\r
-\r
-\r
-unsigned int\r
-PrintEmfWin32::begin (Inkscape::Extension::Print *mod, SPDocument *doc)\r
-{\r
- gchar const *utf8_fn = mod->get_param_string("destination");\r
-\r
- gsize bytesRead = 0;\r
- gsize bytesWritten = 0;\r
- GError* error = NULL;\r
- gchar *local_fn =\r
- g_filename_from_utf8( utf8_fn, -1, &bytesRead, &bytesWritten, &error );\r
-\r
- if (local_fn == NULL) {\r
- return 1;\r
- }\r
-\r
- CHAR *ansi_uri = (CHAR *) local_fn;\r
- gunichar2 *unicode_fn = g_utf8_to_utf16( local_fn, -1, NULL, NULL, NULL );\r
- WCHAR *unicode_uri = (WCHAR *) unicode_fn;\r
-\r
- // width and height in px\r
- _width = sp_document_width(doc);\r
- _height = sp_document_height(doc);\r
-\r
- NRRect d;\r
- bool pageBoundingBox;\r
- pageBoundingBox = mod->get_param_bool("pageBoundingBox");\r
- if (pageBoundingBox) {\r
- d.x0 = d.y0 = 0;\r
- d.x1 = _width;\r
- d.y1 = _height;\r
- } else {\r
- SPItem* doc_item = SP_ITEM(sp_document_root(doc));\r
- sp_item_invoke_bbox(doc_item, &d, sp_item_i2r_affine(doc_item), TRUE);\r
- }\r
-\r
- d.x0 *= IN_PER_PX;\r
- d.y0 *= IN_PER_PX;\r
- d.x1 *= IN_PER_PX;\r
- d.y1 *= IN_PER_PX;\r
-\r
- float dwInchesX = (d.x1 - d.x0);\r
- float dwInchesY = (d.y1 - d.y0);\r
-\r
- // dwInchesX x dwInchesY in .01mm units\r
- SetRect( &rc, 0, 0, (int) ceil(dwInchesX*2540), (int) ceil(dwInchesY*2540) );\r
-\r
- // Get a Reference DC\r
- HDC hScreenDC = GetDC( NULL );\r
-\r
- // Get the physical characteristics of the reference DC\r
- float PixelsX = (float) GetDeviceCaps( hScreenDC, HORZRES );\r
- float PixelsY = (float) GetDeviceCaps( hScreenDC, VERTRES );\r
- float MMX = (float) GetDeviceCaps( hScreenDC, HORZSIZE );\r
- float MMY = (float) GetDeviceCaps( hScreenDC, VERTSIZE );\r
-\r
- // Create the Metafile\r
- if (PrintWin32::is_os_wide())\r
- hdc = CreateEnhMetaFileW( hScreenDC, unicode_uri, &rc, NULL );\r
- else\r
- hdc = CreateEnhMetaFileA( hScreenDC, ansi_uri, &rc, NULL );\r
-\r
- // Release the reference DC\r
- ReleaseDC( NULL, hScreenDC );\r
-\r
- // Did we get a good metafile?\r
- if (hdc == NULL)\r
- {\r
- g_free(local_fn);\r
- g_free(unicode_fn);\r
- return 1;\r
- }\r
-\r
- // Anisotropic mapping mode\r
- SetMapMode( hdc, MM_ANISOTROPIC );\r
-\r
- // Set the Windows extent\r
- SetWindowExtEx( hdc, (int) (dwInchesX*dwDPI), (int) (dwInchesY*dwDPI), NULL );\r
-\r
- // Set the viewport extent to reflect\r
- // dwInchesX" x dwInchesY" in device units\r
- SetViewportExtEx( hdc,\r
- (int) ((float) dwInchesX*25.4f*PixelsX/MMX),\r
- (int) ((float) dwInchesY*25.4f*PixelsY/MMY),\r
- NULL );\r
-\r
- SetRect( &rc, 0, 0, (int) ceil(dwInchesX*dwDPI), (int) ceil(dwInchesY*dwDPI) );\r
-\r
- g_free(local_fn);\r
- g_free(unicode_fn);\r
-\r
- return 0;\r
-}\r
-\r
-\r
-unsigned int\r
-PrintEmfWin32::finish (Inkscape::Extension::Print *mod)\r
-{\r
- if (!hdc) return 0;\r
-\r
- flush_fill(); // flush any pending fills\r
-\r
- HENHMETAFILE metafile = CloseEnhMetaFile( hdc );\r
- if ( metafile ) {\r
- DeleteEnhMetaFile( metafile );\r
- }\r
- DeleteDC( hdc );\r
-\r
- hdc = NULL;\r
-\r
- return 0;\r
-}\r
-\r
-\r
-unsigned int\r
-PrintEmfWin32::comment (Inkscape::Extension::Print * module,\r
- const char *comment)\r
-{\r
- if (!hdc) return 0;\r
-\r
- flush_fill(); // flush any pending fills\r
-\r
- return 0;\r
-}\r
-\r
-\r
-void\r
-PrintEmfWin32::create_brush(SPStyle const *style)\r
-{\r
- float rgb[3];\r
-\r
- if (style) {\r
- sp_color_get_rgb_floatv( &style->fill.value.color, rgb );\r
- hbrush = CreateSolidBrush( RGB(255*rgb[0], 255*rgb[1], 255*rgb[2]) );\r
- hbrushOld = (HBRUSH) SelectObject( hdc, hbrush );\r
-\r
- SetPolyFillMode( hdc,\r
- style->fill_rule.computed == 0 ? WINDING :\r
- style->fill_rule.computed == 2 ? ALTERNATE : ALTERNATE );\r
- } else { // if (!style)\r
- hbrush = CreateSolidBrush( RGB(255, 255, 255) );\r
- hbrushOld = (HBRUSH) SelectObject( hdc, hbrush );\r
- SetPolyFillMode( hdc, ALTERNATE );\r
- }\r
-}\r
-\r
-\r
-void\r
-PrintEmfWin32::destroy_brush()\r
-{\r
- SelectObject( hdc, hbrushOld );\r
- if (hbrush)\r
- DeleteObject( hbrush );\r
- hbrush = NULL;\r
-}\r
-\r
-\r
-void\r
-PrintEmfWin32::create_pen(SPStyle const *style)\r
-{\r
- if (style) {\r
- float rgb[3];\r
-\r
- sp_color_get_rgb_floatv(&style->stroke.value.color, rgb);\r
-\r
- LOGBRUSH lb = {0};\r
- lb.lbStyle = BS_SOLID;\r
- lb.lbColor = RGB( 255*rgb[0], 255*rgb[1], 255*rgb[2] );\r
-\r
- int linestyle = PS_SOLID;\r
- int linecap = 0;\r
- int linejoin = 0;\r
- DWORD n_dash = 0;\r
- DWORD *dash = NULL;\r
- float oldmiterlimit;\r
-\r
- DWORD linewidth = MAX( 1, (DWORD) (style->stroke_width.computed * IN_PER_PX * dwDPI) );\r
-\r
- if (style->stroke_linecap.computed == 0) {\r
- linecap = PS_ENDCAP_FLAT;\r
- }\r
- else if (style->stroke_linecap.computed == 1) {\r
- linecap = PS_ENDCAP_ROUND;\r
- }\r
- else if (style->stroke_linecap.computed == 2) {\r
- linecap = PS_ENDCAP_SQUARE;\r
- }\r
-\r
- if (style->stroke_linejoin.computed == 0) {\r
- linejoin = PS_JOIN_MITER;\r
- }\r
- else if (style->stroke_linejoin.computed == 1) {\r
- linejoin = PS_JOIN_ROUND;\r
- }\r
- else if (style->stroke_linejoin.computed == 2) {\r
- linejoin = PS_JOIN_BEVEL;\r
- }\r
-\r
- if (style->stroke_dash.n_dash &&\r
- style->stroke_dash.dash )\r
- {\r
- int i = 0;\r
- while (linestyle != PS_USERSTYLE &&\r
- (i < style->stroke_dash.n_dash)) {\r
- if (style->stroke_dash.dash[i] > 0.00000001)\r
- linestyle = PS_USERSTYLE;\r
- i++;\r
- }\r
-\r
- if (linestyle == PS_USERSTYLE) {\r
- n_dash = style->stroke_dash.n_dash;\r
- dash = new DWORD[n_dash];\r
- for (i = 0; i < style->stroke_dash.n_dash; i++) {\r
- dash[i] = (DWORD) (style->stroke_dash.dash[i] * IN_PER_PX * dwDPI);\r
- }\r
- }\r
- }\r
-\r
- hpen = ExtCreatePen(\r
- PS_GEOMETRIC | linestyle | linecap | linejoin,\r
- linewidth,\r
- &lb,\r
- n_dash,\r
- dash );\r
-\r
- if ( !hpen && linestyle == PS_USERSTYLE ) {\r
- hpen = ExtCreatePen(\r
- PS_GEOMETRIC | PS_SOLID | linecap | linejoin,\r
- linewidth,\r
- &lb,\r
- 0,\r
- NULL );\r
- }\r
-\r
- if ( !hpen ) {\r
- hpen = CreatePen(\r
- PS_SOLID,\r
- linewidth,\r
- lb.lbColor );\r
- }\r
-\r
- hpenOld = (HPEN) SelectObject( hdc, hpen );\r
-\r
- if (linejoin == PS_JOIN_MITER) {\r
- float miterlimit = style->stroke_miterlimit.value;\r
- if (miterlimit < 1)\r
- miterlimit = 4.0;\r
- SetMiterLimit(\r
- hdc,\r
- miterlimit * IN_PER_PX * dwDPI,\r
- &oldmiterlimit );\r
- }\r
-\r
- if (n_dash) {\r
- delete[] dash;\r
- }\r
- }\r
- else { // if (!style)\r
- hpen = CreatePen( PS_SOLID, 1, RGB(0, 0, 0) );\r
- hpenOld = (HPEN) SelectObject( hdc, hpen );\r
- }\r
-}\r
-\r
-\r
-void\r
-PrintEmfWin32::destroy_pen()\r
-{\r
- SelectObject( hdc, hpenOld );\r
- if (hpen)\r
- DeleteObject( hpen );\r
- hpen = NULL;\r
-}\r
-\r
-\r
-void\r
-PrintEmfWin32::flush_fill()\r
-{\r
- if (fill_path) {\r
- print_bpath(fill_path, &fill_transform, &fill_pbox);\r
- FillPath( hdc );\r
- destroy_brush();\r
- delete[] fill_path;\r
- fill_path = NULL;\r
- }\r
-}\r
-\r
-\r
-NArtBpath *\r
-PrintEmfWin32::copy_bpath(const NArtBpath *bp)\r
-{\r
- NArtBpath *tmp = (NArtBpath *) bp;\r
- int num = 1;\r
- \r
- while (tmp->code != NR_END) {\r
- num++;\r
- tmp += 1;\r
- }\r
-\r
- tmp = new NArtBpath[num];\r
- while (num--) {\r
- tmp[num] = bp[num];\r
- }\r
-\r
- return tmp;\r
-}\r
-\r
-\r
-int\r
-PrintEmfWin32::cmp_bpath(const NArtBpath *bp1, const NArtBpath *bp2)\r
-{\r
- if (!bp1 || !bp2) {\r
- return 1;\r
- }\r
- \r
- while (bp1->code != NR_END && bp2->code != NR_END) {\r
- if (bp1->code != bp2->code) {\r
- return 1;\r
- }\r
-\r
- if ( fabs(bp1->x1 - bp2->x1) > 0.00000001 ||\r
- fabs(bp1->y1 - bp2->y1) > 0.00000001 ||\r
- fabs(bp1->x2 - bp2->x2) > 0.00000001 ||\r
- fabs(bp1->y2 - bp2->y2) > 0.00000001 ||\r
- fabs(bp1->x3 - bp2->x3) > 0.00000001 ||\r
- fabs(bp1->y3 - bp2->y3) > 0.00000001 )\r
- {\r
- return 1;\r
- }\r
- \r
- bp1 += 1;\r
- bp2 += 1;\r
- }\r
- \r
- return bp1->code != NR_END || bp2->code != NR_END;\r
-}\r
-\r
-\r
-unsigned int\r
-PrintEmfWin32::fill(Inkscape::Extension::Print *mod,\r
- NRBPath const *bpath, NRMatrix const *transform, SPStyle const *style,\r
- NRRect const *pbox, NRRect const *dbox, NRRect const *bbox)\r
-{\r
- if (!hdc) return 0;\r
-\r
- flush_fill(); // flush any pending fills\r
-\r
- if (style->fill.type == SP_PAINT_TYPE_COLOR) {\r
- create_brush(style);\r
- } else {\r
- // create_brush(NULL);\r
- return 0;\r
- }\r
-\r
- fill_path = copy_bpath( bpath->path );\r
- fill_transform = *transform;\r
- fill_pbox = *pbox;\r
-\r
- // postpone fill in case of stroke-and-fill\r
-\r
- return 0;\r
-}\r
-\r
-\r
-unsigned int\r
-PrintEmfWin32::stroke (Inkscape::Extension::Print *mod,\r
- const NRBPath *bpath, const NRMatrix *transform, const SPStyle *style,\r
- const NRRect *pbox, const NRRect *dbox, const NRRect *bbox)\r
-{\r
- if (!hdc) return 0;\r
-\r
- bool stroke_and_fill = ( cmp_bpath( bpath->path, fill_path ) == 0 );\r
-\r
- if (!stroke_and_fill) {\r
- flush_fill(); // flush any pending fills\r
- }\r
-\r
- if (style->stroke.type == SP_PAINT_TYPE_COLOR) {\r
- create_pen(style);\r
- } else {\r
- // create_pen(NULL);\r
- return 0;\r
- }\r
-\r
- print_bpath(bpath->path, transform, pbox);\r
-\r
- if (stroke_and_fill) {\r
- StrokeAndFillPath( hdc );\r
- destroy_brush();\r
- delete[] fill_path;\r
- fill_path = NULL;\r
- } else {\r
- StrokePath( hdc );\r
- }\r
-\r
- destroy_pen();\r
-\r
- return 0;\r
-}\r
-\r
-\r
-unsigned int\r
-PrintEmfWin32::print_bpath(const NArtBpath *bp, const NRMatrix *transform, NRRect const *pbox)\r
-{\r
- unsigned int closed;\r
- NR::Matrix tf = *transform;\r
-\r
- BeginPath( hdc );\r
- closed = FALSE;\r
- while (bp->code != NR_END) {\r
- using NR::X;\r
- using NR::Y;\r
-\r
- NR::Point p1(bp->c(1) * tf);\r
- NR::Point p2(bp->c(2) * tf);\r
- NR::Point p3(bp->c(3) * tf);\r
-\r
- p1[X] = (p1[X] * IN_PER_PX * dwDPI);\r
- p2[X] = (p2[X] * IN_PER_PX * dwDPI);\r
- p3[X] = (p3[X] * IN_PER_PX * dwDPI);\r
- p1[Y] = (p1[Y] * IN_PER_PX * dwDPI);\r
- p2[Y] = (p2[Y] * IN_PER_PX * dwDPI);\r
- p3[Y] = (p3[Y] * IN_PER_PX * dwDPI);\r
-\r
- LONG const x1 = (LONG) round(p1[X]);\r
- LONG const y1 = (LONG) round(rc.bottom-p1[Y]);\r
- LONG const x2 = (LONG) round(p2[X]);\r
- LONG const y2 = (LONG) round(rc.bottom-p2[Y]);\r
- LONG const x3 = (LONG) round(p3[X]);\r
- LONG const y3 = (LONG) round(rc.bottom-p3[Y]);\r
-\r
- switch (bp->code) {\r
- case NR_MOVETO:\r
- if (closed) {\r
- CloseFigure( hdc );\r
- }\r
- closed = TRUE;\r
- MoveToEx( hdc, x3, y3, NULL );\r
- break;\r
- case NR_MOVETO_OPEN:\r
- if (closed) {\r
- CloseFigure( hdc );\r
- }\r
- closed = FALSE;\r
- MoveToEx( hdc, x3, y3, NULL );\r
- break;\r
- case NR_LINETO:\r
- LineTo( hdc, x3, y3 );\r
- break;\r
- case NR_CURVETO:\r
- {\r
- POINT pt[3];\r
- pt[0].x = x1;\r
- pt[0].y = y1;\r
- pt[1].x = x2;\r
- pt[1].y = y2;\r
- pt[2].x = x3;\r
- pt[2].y = y3;\r
-\r
- PolyBezierTo( hdc, pt, 3 );\r
- break;\r
- }\r
- default:\r
- break;\r
- }\r
- bp += 1;\r
- }\r
- if (closed) {\r
- CloseFigure( hdc );\r
- }\r
- EndPath( hdc );\r
-\r
- return closed;\r
-}\r
-\r
-\r
-bool\r
-PrintEmfWin32::textToPath(Inkscape::Extension::Print * ext)\r
-{\r
- return ext->get_param_bool("textToPath");\r
-}\r
-\r
-\r
-void\r
-PrintEmfWin32::init (void)\r
-{\r
- Inkscape::Extension::Extension * ext;\r
-\r
- /* EMF print */\r
- ext = Inkscape::Extension::build_from_mem(\r
- "<inkscape-extension>\n"\r
- "<name>Enhanced Metafile Print</name>\n"\r
- "<id>org.inkscape.print.emf.win32</id>\n"\r
- "<param name=\"destination\" type=\"string\"></param>\n"\r
- "<param name=\"textToPath\" type=\"boolean\">TRUE</param>\n"\r
- "<param name=\"pageBoundingBox\" type=\"boolean\">TRUE</param>\n"\r
- "<print/>\n"\r
- "</inkscape-extension>", new PrintEmfWin32());\r
-\r
- return;\r
-}\r
-\r
-\r
-} /* namespace Internal */\r
-} /* namespace Extension */\r
-} /* namespace Inkscape */\r
-\r
-#endif /* WIN32 */\r
-\r
-/*\r
- Local Variables:\r
- mode:c++\r
- c-file-style:"stroustrup"\r
- c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))\r
- indent-tabs-mode:nil\r
- fill-column:99\r
- End:\r
-*/\r
-// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=99 :\r
+/** \file
+ * Enhanced Metafile Printing.
+ */
+/*
+ * Authors:
+ * Ulf Erikson <ulferikson@users.sf.net>
+ *
+ * Copyright (C) 2006-2008 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-ops.h"
+#include "libnr/nr-matrix-scale-ops.h"
+#include "libnr/nr-matrix-translate-ops.h"
+#include "libnr/nr-scale-translate-ops.h"
+#include "libnr/nr-translate-scale-ops.h"
+#include "libnr/nr-matrix-fns.h"
+#include "libnr/nr-path.h"
+#include "libnr/nr-pixblock.h"
+#include <libnr/n-art-bpath-2geom.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 "libnrtype/FontFactory.h"
+#include "libnrtype/font-instance.h"
+#include "libnrtype/font-style-to-pos.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),
+ hbrushOld(NULL),
+ hpen(NULL),
+ fill_path(NULL),
+ stroke_and_fill(false),
+ fill_only(false),
+ simple_shape(false)
+{
+}
+
+
+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
+ int PixelsX = GetDeviceCaps( hScreenDC, HORZRES );
+ int PixelsY = GetDeviceCaps( hScreenDC, VERTRES );
+ int MMX = GetDeviceCaps( hScreenDC, HORZSIZE );
+ int MMY = GetDeviceCaps( hScreenDC, VERTSIZE );
+
+ CHAR buff[1024];
+ ZeroMemory(buff, sizeof(buff));
+ snprintf(buff, sizeof(buff)-1, "Inkscape %s (%s)", INKSCAPE_VERSION, __DATE__);
+ INT len = strlen(buff);
+ CHAR *p1 = strrchr(ansi_uri, '\\');
+ CHAR *p2 = strrchr(ansi_uri, '/');
+ CHAR *p = MAX(p1, p2);
+ if (p)
+ p++;
+ else
+ p = ansi_uri;
+ snprintf(buff+len+1, sizeof(buff)-len-2, "%s", p);
+
+ // Create the Metafile
+ if (PrintWin32::is_os_wide()) {
+ WCHAR wbuff[1024];
+ ZeroMemory(wbuff, sizeof(wbuff));
+ MultiByteToWideChar(CP_ACP, MB_PRECOMPOSED, buff, sizeof(buff)/sizeof(buff[0]), wbuff, sizeof(wbuff)/sizeof(wbuff[0]));
+ hdc = CreateEnhMetaFileW( hScreenDC, unicode_uri, &rc, wbuff );
+ }
+ else {
+ hdc = CreateEnhMetaFileA( hScreenDC, ansi_uri, &rc, buff );
+ }
+
+ // 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
+ int windowextX = (int) ceil(dwInchesX*dwDPI);
+ int windowextY = (int) ceil(dwInchesY*dwDPI);
+ SetWindowExtEx( hdc, windowextX, windowextY, NULL );
+
+ // Set the viewport extent to reflect
+ // dwInchesX" x dwInchesY" in device units
+ int viewportextX = (int)((float)dwInchesX*25.4f*(float)PixelsX/(float)MMX);
+ int viewportextY = (int)((float)dwInchesY*25.4f*(float)PixelsY/(float)MMY);
+ SetViewportExtEx( hdc, viewportextX, viewportextY, NULL );
+
+ if (1) {
+ snprintf(buff, sizeof(buff)-1, "Screen=%dx%dpx, %dx%dmm", PixelsX, PixelsY, MMX, MMY);
+ GdiComment(hdc, strlen(buff), (BYTE*) buff);
+
+ snprintf(buff, sizeof(buff)-1, "Drawing=%.1lfx%.1lfpx, %.1lfx%.1lfmm", _width, _height, dwInchesX * MM_PER_IN, dwInchesY * MM_PER_IN);
+ GdiComment(hdc, strlen(buff), (BYTE*) buff);
+ }
+
+ SetRect( &rc, 0, 0, (int) ceil(dwInchesX*dwDPI), (int) ceil(dwInchesY*dwDPI) );
+
+ g_free(local_fn);
+ g_free(unicode_fn);
+
+ m_tr_stack.push( NR::scale(1, -1) * NR::translate(0, sp_document_height(doc)));
+
+ 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;
+}
+
+
+int
+PrintEmfWin32::create_brush(SPStyle const *style)
+{
+ float rgb[3];
+
+ if (style) {
+ float opacity = SP_SCALE24_TO_FLOAT(style->fill_opacity.value);
+ if (opacity <= 0.0)
+ return 1;
+
+ 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 );
+ }
+
+ return 0;
+}
+
+
+void
+PrintEmfWin32::destroy_brush()
+{
+ SelectObject( hdc, hbrushOld );
+ if (hbrush)
+ DeleteObject( hbrush );
+ hbrush = NULL;
+ hbrushOld = NULL;
+}
+
+
+void
+PrintEmfWin32::create_pen(SPStyle const *style, const NR::Matrix *transform)
+{
+ 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;
+
+ using NR::X;
+ using NR::Y;
+
+ NR::Matrix tf = *transform;
+
+ NR::Point zero(0, 0);
+ NR::Point one(1, 1);
+ NR::Point p0(zero * tf);
+ NR::Point p1(one * tf);
+ NR::Point p(p1 - p0);
+
+ double scale = sqrt( (p[X]*p[X]) + (p[Y]*p[Y]) ) / sqrt(2);
+
+ DWORD linewidth = MAX( 1, (DWORD) (scale * 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) {
+ stroke_and_fill = false;
+ fill_only = true;
+ print_bpath(fill_path, &fill_transform, &fill_pbox);
+ fill_only = false;
+ if (!simple_shape)
+ 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::bind(Inkscape::Extension::Print *mod, NR::Matrix const *transform, float opacity)
+{
+ NR::Matrix tr = *transform;
+
+ if (m_tr_stack.size()) {
+ NR::Matrix tr_top = m_tr_stack.top();
+ m_tr_stack.push(tr * tr_top);
+ } else {
+ m_tr_stack.push(tr);
+ }
+
+ return 1;
+}
+
+unsigned int
+PrintEmfWin32::release(Inkscape::Extension::Print *mod)
+{
+ m_tr_stack.pop();
+ return 1;
+}
+
+unsigned int
+PrintEmfWin32::fill(Inkscape::Extension::Print *mod,
+ Geom::PathVector const &pathv, NR::Matrix const *transform, SPStyle const *style,
+ NRRect const *pbox, NRRect const *dbox, NRRect const *bbox)
+{
+ if (!hdc) return 0;
+
+ NR::Matrix tf = m_tr_stack.top();
+
+ flush_fill(); // flush any pending fills
+
+ if (style->fill.isColor()) {
+ if (create_brush(style))
+ return 0;
+ } else {
+ // create_brush(NULL);
+ return 0;
+ }
+
+ NArtBpath * bpath = BPath_from_2GeomPath(pathv);
+ fill_path = copy_bpath( bpath );
+ g_free(bpath);
+ fill_transform = tf;
+ fill_pbox = *pbox;
+
+ // postpone fill in case of stroke-and-fill
+
+ return 0;
+}
+
+
+unsigned int
+PrintEmfWin32::stroke (Inkscape::Extension::Print *mod,
+ Geom::PathVector const &pathv, const NR::Matrix *transform, const SPStyle *style,
+ const NRRect *pbox, const NRRect *dbox, const NRRect *bbox)
+{
+ if (!hdc) return 0;
+
+ NR::Matrix tf = m_tr_stack.top();
+
+ NArtBpath * bpath = BPath_from_2GeomPath(pathv);
+
+ stroke_and_fill = ( cmp_bpath( bpath, fill_path ) == 0 );
+
+ if (!stroke_and_fill) {
+ flush_fill(); // flush any pending fills
+ }
+
+ if (style->stroke.isColor()) {
+ create_pen(style, &tf);
+ } else {
+ // create_pen(NULL, &tf);
+ return 0;
+ }
+
+ print_bpath(bpath, &tf, pbox);
+
+ if (stroke_and_fill) {
+ if (!simple_shape)
+ StrokeAndFillPath( hdc );
+ destroy_brush();
+ delete[] fill_path;
+ fill_path = NULL;
+ } else {
+ if (!simple_shape)
+ StrokePath( hdc );
+ }
+
+ g_free(bpath);
+ destroy_pen();
+
+ return 0;
+}
+
+
+bool
+PrintEmfWin32::print_simple_shape(const NArtBpath *bpath, const NR::Matrix *transform, NRRect const *pbox)
+{
+ NR::Matrix tf = *transform;
+ const NArtBpath *bp = bpath;
+
+ int nodes = 0;
+ int moves = 0;
+ int lines = 0;
+ int curves = 0;
+
+ while (bp->code != NR_END) {
+ nodes++;
+ switch (bp->code) {
+ case NR_MOVETO:
+ case NR_MOVETO_OPEN:
+ moves++;
+ break;
+ case NR_LINETO:
+ lines++;
+ break;
+ case NR_CURVETO:
+ curves++;
+ break;
+ }
+ bp += 1;
+ }
+
+ if (!nodes)
+ return false;
+
+ POINT *lpPoints = new POINT[moves + lines + curves*3];
+ int i = 0;
+ bp = bpath;
+ 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:
+ case NR_MOVETO_OPEN:
+ case NR_LINETO:
+ lpPoints[i].x = x3;
+ lpPoints[i].y = y3;
+ i = i + 1;
+ break;
+ case NR_CURVETO:
+ lpPoints[i].x = x1;
+ lpPoints[i].y = y1;
+ lpPoints[i+1].x = x2;
+ lpPoints[i+1].y = y2;
+ lpPoints[i+2].x = x3;
+ lpPoints[i+2].y = y3;
+ i = i + 3;
+ break;
+ }
+
+ bp += 1;
+ }
+
+ bool done = false;
+ bool closed = (lpPoints[0].x == lpPoints[i-1].x) && (lpPoints[0].y == lpPoints[i-1].y);
+ bool polygon = false;
+ bool polyline = false;
+ bool rectangle = false;
+ bool ellipse = false;
+
+ if (moves == 1 && moves+lines == nodes && closed) {
+ polygon = true;
+ if (nodes==5) {
+ if (lpPoints[0].x == lpPoints[3].x && lpPoints[1].x == lpPoints[2].x &&
+ lpPoints[0].y == lpPoints[1].y && lpPoints[2].y == lpPoints[3].y)
+ {
+ rectangle = true;
+ }
+ }
+ }
+ else if (moves == 1 && moves+lines == nodes) {
+ polyline = true;
+ }
+ else if (moves == 1 && nodes == 5 && moves+curves == nodes && closed) {
+ if (lpPoints[0].x == lpPoints[1].x && lpPoints[1].x == lpPoints[11].x &&
+ lpPoints[5].x == lpPoints[6].x && lpPoints[6].x == lpPoints[7].x &&
+ lpPoints[2].x == lpPoints[10].x && lpPoints[3].x == lpPoints[9].x && lpPoints[4].x == lpPoints[8].x &&
+ lpPoints[2].y == lpPoints[3].y && lpPoints[3].y == lpPoints[4].y &&
+ lpPoints[8].y == lpPoints[9].y && lpPoints[9].y == lpPoints[10].y &&
+ lpPoints[5].y == lpPoints[1].y && lpPoints[6].y == lpPoints[0].y && lpPoints[7].y == lpPoints[11].y)
+ {
+ ellipse = true;
+ }
+ }
+
+ if (polygon || polyline || ellipse) {
+ HPEN hpenTmp = NULL;
+ HPEN hpenOld = NULL;
+ HBRUSH hbrushTmp = NULL;
+ HBRUSH hbrushOld = NULL;
+
+ if (!stroke_and_fill) {
+ if (fill_only) {
+ hpenTmp = (HPEN) GetStockObject(NULL_PEN);
+ hpenOld = (HPEN) SelectObject( hdc, hpenTmp );
+ }
+ else { // if (stroke_only)
+ hbrushTmp = (HBRUSH) GetStockObject(NULL_BRUSH);
+ hbrushOld = (HBRUSH) SelectObject( hdc, hbrushTmp );
+ }
+ }
+
+ if (polygon) {
+ if (rectangle)
+ Rectangle( hdc, lpPoints[0].x, lpPoints[0].y, lpPoints[2].x, lpPoints[2].y );
+ else
+ Polygon( hdc, lpPoints, nodes );
+ }
+ else if (polyline) {
+ Polyline( hdc, lpPoints, nodes );
+ }
+ else if (ellipse) {
+ Ellipse( hdc, lpPoints[6].x, lpPoints[3].y, lpPoints[0].x, lpPoints[9].y);
+ }
+
+ done = true;
+
+ if (hpenOld)
+ SelectObject( hdc, hpenOld );
+ if (hpenTmp)
+ DeleteObject( hpenTmp );
+ if (hbrushOld)
+ SelectObject( hdc, hbrushOld );
+ if (hbrushTmp)
+ DeleteObject( hbrushTmp );
+ }
+
+ delete[] lpPoints;
+
+ return done;
+}
+
+unsigned int
+PrintEmfWin32::print_bpath(const NArtBpath *bp, const NR::Matrix *transform, NRRect const *pbox)
+{
+ unsigned int closed;
+ NR::Matrix tf = *transform;
+
+ simple_shape = print_simple_shape(bp, &tf, pbox);
+
+ if (simple_shape)
+ return TRUE;
+
+ 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");
+}
+
+unsigned int
+PrintEmfWin32::text(Inkscape::Extension::Print *mod, char const *text, NR::Point p,
+ SPStyle const *const style)
+{
+ if (!hdc) return 0;
+
+ HFONT hfont = NULL;
+
+#ifdef USE_PANGO_WIN32
+/*
+ font_instance *tf = (font_factory::Default())->Face(style->text->font_family.value, font_style_to_pos(*style));
+ if (tf) {
+ LOGFONT *lf = pango_win32_font_logfont(tf->pFont);
+ tf->Unref();
+ hfont = CreateFontIndirect(lf);
+ g_free(lf);
+ }
+*/
+#endif
+
+ if (!hfont) {
+ if (PrintWin32::is_os_wide()) {
+ LOGFONTW *lf = (LOGFONTW*)g_malloc(sizeof(LOGFONTW));
+ g_assert(lf != NULL);
+
+ lf->lfHeight = style->font_size.computed * IN_PER_PX * dwDPI;
+ lf->lfWidth = 0;
+ lf->lfEscapement = 0;
+ lf->lfOrientation = 0;
+ lf->lfWeight =
+ style->font_weight.computed == SP_CSS_FONT_WEIGHT_100 ? FW_THIN :
+ style->font_weight.computed == SP_CSS_FONT_WEIGHT_200 ? FW_EXTRALIGHT :
+ style->font_weight.computed == SP_CSS_FONT_WEIGHT_300 ? FW_LIGHT :
+ style->font_weight.computed == SP_CSS_FONT_WEIGHT_400 ? FW_NORMAL :
+ style->font_weight.computed == SP_CSS_FONT_WEIGHT_500 ? FW_MEDIUM :
+ style->font_weight.computed == SP_CSS_FONT_WEIGHT_600 ? FW_SEMIBOLD :
+ style->font_weight.computed == SP_CSS_FONT_WEIGHT_700 ? FW_BOLD :
+ style->font_weight.computed == SP_CSS_FONT_WEIGHT_800 ? FW_EXTRABOLD :
+ style->font_weight.computed == SP_CSS_FONT_WEIGHT_900 ? FW_HEAVY :
+ FW_NORMAL;
+ lf->lfItalic = (style->font_style.computed == SP_CSS_FONT_STYLE_ITALIC);
+ lf->lfUnderline = style->text_decoration.underline;
+ lf->lfStrikeOut = style->text_decoration.line_through;
+ lf->lfCharSet = DEFAULT_CHARSET;
+ lf->lfOutPrecision = OUT_DEFAULT_PRECIS;
+ lf->lfClipPrecision = CLIP_DEFAULT_PRECIS;
+ lf->lfQuality = DEFAULT_QUALITY;
+ lf->lfPitchAndFamily = DEFAULT_PITCH | FF_DONTCARE;
+
+ gunichar2 *unicode_name = g_utf8_to_utf16( style->text->font_family.value, -1, NULL, NULL, NULL );
+ wcsncpy(lf->lfFaceName, (wchar_t*) unicode_name, LF_FACESIZE-1);
+ g_free(unicode_name);
+
+ hfont = CreateFontIndirectW(lf);
+
+ g_free(lf);
+ }
+ else {
+ LOGFONTA *lf = (LOGFONTA*)g_malloc(sizeof(LOGFONTA));
+ g_assert(lf != NULL);
+
+ lf->lfHeight = style->font_size.computed * IN_PER_PX * dwDPI;
+ lf->lfWidth = 0;
+ lf->lfEscapement = 0;
+ lf->lfOrientation = 0;
+ lf->lfWeight =
+ style->font_weight.computed == SP_CSS_FONT_WEIGHT_100 ? FW_THIN :
+ style->font_weight.computed == SP_CSS_FONT_WEIGHT_200 ? FW_EXTRALIGHT :
+ style->font_weight.computed == SP_CSS_FONT_WEIGHT_300 ? FW_LIGHT :
+ style->font_weight.computed == SP_CSS_FONT_WEIGHT_400 ? FW_NORMAL :
+ style->font_weight.computed == SP_CSS_FONT_WEIGHT_500 ? FW_MEDIUM :
+ style->font_weight.computed == SP_CSS_FONT_WEIGHT_600 ? FW_SEMIBOLD :
+ style->font_weight.computed == SP_CSS_FONT_WEIGHT_700 ? FW_BOLD :
+ style->font_weight.computed == SP_CSS_FONT_WEIGHT_800 ? FW_EXTRABOLD :
+ style->font_weight.computed == SP_CSS_FONT_WEIGHT_900 ? FW_HEAVY :
+ FW_NORMAL;
+ lf->lfItalic = (style->font_style.computed == SP_CSS_FONT_STYLE_ITALIC);
+ lf->lfUnderline = style->text_decoration.underline;
+ lf->lfStrikeOut = style->text_decoration.line_through;
+ lf->lfCharSet = DEFAULT_CHARSET;
+ lf->lfOutPrecision = OUT_DEFAULT_PRECIS;
+ lf->lfClipPrecision = CLIP_DEFAULT_PRECIS;
+ lf->lfQuality = DEFAULT_QUALITY;
+ lf->lfPitchAndFamily = DEFAULT_PITCH | FF_DONTCARE;
+
+ strncpy(lf->lfFaceName, (char*) style->text->font_family.value, LF_FACESIZE-1);
+
+ hfont = CreateFontIndirectA(lf);
+
+ g_free(lf);
+ }
+ }
+
+ HFONT hfontOld = (HFONT) SelectObject(hdc, hfont);
+
+ float rgb[3];
+ sp_color_get_rgb_floatv( &style->fill.value.color, rgb );
+ SetTextColor(hdc, RGB(255*rgb[0], 255*rgb[1], 255*rgb[2]));
+
+ // Text alignment:
+ // - (x,y) coordinates received by this filter are those of the point where the text
+ // actually starts, and already takes into account the text object's alignment;
+ // - for this reason, the EMF text alignment must always be TA_BASELINE|TA_LEFT.
+ SetTextAlign(hdc, TA_BASELINE | TA_LEFT);
+
+ // Transparent text background
+ SetBkMode(hdc, TRANSPARENT);
+
+ NR::Matrix tf = m_tr_stack.top();
+
+ p = p * tf;
+ p[NR::X] = (p[NR::X] * IN_PER_PX * dwDPI);
+ p[NR::Y] = (p[NR::Y] * IN_PER_PX * dwDPI);
+
+ LONG const xpos = (LONG) round(p[NR::X]);
+ LONG const ypos = (LONG) round(rc.bottom-p[NR::Y]);
+
+ if (PrintWin32::is_os_wide()) {
+ gunichar2 *unicode_text = g_utf8_to_utf16( text, -1, NULL, NULL, NULL );
+ TextOutW(hdc, xpos, ypos, (WCHAR*)unicode_text, wcslen((wchar_t*)unicode_text));
+ }
+ else {
+ TextOutA(hdc, xpos, ypos, (CHAR*)text, strlen((char*)text));
+ }
+
+ SelectObject(hdc, hfontOld);
+ DeleteObject(hfont);
+
+ return 0;
+}
+
+void
+PrintEmfWin32::init (void)
+{
+ Inkscape::Extension::Extension * ext;
+
+ /* EMF print */
+ ext = Inkscape::Extension::build_from_mem(
+ "<inkscape-extension xmlns=\"" INKSCAPE_EXTENSION_URI "\">\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 :