X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=src%2Fextension%2Finternal%2Femf-win32-inout.cpp;h=34cdecdcae44a063d0a98a8ff89c1704fd7d4e77;hb=b2240fc6ae4c426379a3f477acd08a6b14c68aad;hp=7c2aa919208493f83f1a73e3023a344df468e27e;hpb=b13f78e60a09501e35a3f00c2fe0af27da300442;p=inkscape.git diff --git a/src/extension/internal/emf-win32-inout.cpp b/src/extension/internal/emf-win32-inout.cpp index 7c2aa9192..34cdecdca 100644 --- a/src/extension/internal/emf-win32-inout.cpp +++ b/src/extension/internal/emf-win32-inout.cpp @@ -1,15 +1,15 @@ -/** \file - * Enhanced Metafile Input and Output. +/** @file + * @brief Windows-only Enhanced Metafile input and output. */ -/* - * Authors: +/* Authors: * Ulf Erikson + * Jon A. Cruz + * Abhishek Sharma * * 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/ @@ -27,44 +27,47 @@ # include "config.h" #endif -#include "win32.h" -#include "emf-win32-print.h" -#include "emf-win32-inout.h" -#include "inkscape.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 "color.h" +//#include "display/curve.h" +//#include "libnr/nr-point-matrix-ops.h" +//#include "gtk/gtk.h" #include "print.h" -#include "glibmm/i18n.h" -#include "extension/extension.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 "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 "libnr/nr-rect.h" +//#include "libnr/nr-matrix.h" +//#include "libnr/nr-pixblock.h" -#include -#include +//#include +//#include -#include -#include +//#include +//#include -#include "io/sys.h" +//#include "io/sys.h" #include "unit-constants.h" #include "clear-n_.h" +#define WIN32_LEAN_AND_MEAN +#include + +#include "win32.h" +#include "emf-win32-print.h" +#include "emf-win32-inout.h" + #define PRINT_EMF_WIN32 "org.inkscape.print.emf.win32" @@ -91,7 +94,7 @@ EmfWin32::~EmfWin32 (void) //The destructor bool -EmfWin32::check (Inkscape::Extension::Extension * module) +EmfWin32::check (Inkscape::Extension::Extension * /*module*/) { if (NULL == Inkscape::Extension::db.get(PRINT_EMF_WIN32)) return FALSE; @@ -108,32 +111,32 @@ emf_print_document_to_file(SPDocument *doc, gchar const *filename) gchar *oldoutput; unsigned int ret; - sp_document_ensure_up_to_date(doc); + doc->ensureUpToDate(); 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); + mod->set_param_string("destination", 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->base = SP_ITEM(doc->getRoot()); 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); + mod->dkey = SPItem::display_key_new(1); + mod->root = mod->base->invoke_show(mod->arena, mod->dkey, SP_ITEM_SHOW_DISPLAY); /* Print document */ ret = mod->begin(doc); if (ret) { + g_free(oldoutput); throw Inkscape::Extension::Output::save_failed(); } - sp_item_invoke_print(mod->base, &context); + mod->base->invoke_print(&context); ret = mod->finish(); /* Release arena */ - sp_item_invoke_hide(mod->base, mod->dkey); + mod->base->invoke_hide(mod->dkey); mod->base = NULL; - nr_arena_item_unref(mod->root); mod->root = NULL; nr_object_unref((NRObject *) mod->arena); mod->arena = NULL; @@ -147,7 +150,7 @@ emf_print_document_to_file(SPDocument *doc, gchar const *filename) void -EmfWin32::save (Inkscape::Extension::Output *mod, SPDocument *doc, const gchar *uri) +EmfWin32::save(Inkscape::Extension::Output *mod, SPDocument *doc, gchar const *filename) { Inkscape::Extension::Extension * ext; @@ -159,10 +162,7 @@ EmfWin32::save (Inkscape::Extension::Output *mod, SPDocument *doc, const gchar * 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); + emf_print_document_to_file(doc, filename); ext->set_param_bool("textToPath", old_textToPath); @@ -173,36 +173,51 @@ EmfWin32::save (Inkscape::Extension::Output *mod, SPDocument *doc, const gchar * typedef struct { int type; + int level; ENHMETARECORD *lpEMFR; } EMF_OBJECT, *PEMF_OBJECT; -typedef struct emf_callback_data { - Glib::ustring *outsvg; - Glib::ustring *path; +typedef struct emf_device_context { struct SPStyle style; class SPTextStyle tstyle; bool stroke_set; bool fill_set; - double xDPI, yDPI; - bool pathless_stroke; - bool inpath; SIZEL sizeWnd; SIZEL sizeView; - float PixelsX; - float PixelsY; - float MMX; - float MMY; - float dwInchesX; - float dwInchesY; + float PixelsInX, PixelsInY; + float PixelsOutX, PixelsOutY; POINTL winorg; POINTL vieworg; - double ScaleX, ScaleY; + double ScaleInX, ScaleInY; + double ScaleOutX, ScaleOutY; COLORREF textColor; bool textColorSet; DWORD textAlign; XFORM worldTransform; + POINTL cur; +} EMF_DEVICE_CONTEXT, *PEMF_DEVICE_CONTEXT; + +#define EMF_MAX_DC 128 + +typedef struct emf_callback_data { + Glib::ustring *outsvg; + Glib::ustring *path; + + EMF_DEVICE_CONTEXT dc[EMF_MAX_DC+1]; // FIXME: This should be dynamic.. + int level; + + double xDPI, yDPI; + bool pathless_stroke; + bool inpath; + + float MMX; + float MMY; + float dwInchesX; + float dwInchesY; + unsigned int id; + CHAR *pDesc; int n_obj; PEMF_OBJECT emf_obj; @@ -217,15 +232,15 @@ output_style(PEMF_CALLBACK_DATA d, int iType) char tmp[1024] = {0}; float fill_rgb[3]; - sp_color_get_rgb_floatv( &(d->style.fill.value.color), fill_rgb ); + sp_color_get_rgb_floatv( &(d->dc[d->level].style.fill.value.color), fill_rgb ); float stroke_rgb[3]; - sp_color_get_rgb_floatv(&(d->style.stroke.value.color), stroke_rgb); + sp_color_get_rgb_floatv(&(d->dc[d->level].style.stroke.value.color), stroke_rgb); tmp_id << "\n\tid=\"" << (d->id++) << "\""; *(d->outsvg) += tmp_id.str().c_str(); *(d->outsvg) += "\n\tstyle=\""; - if (iType == EMR_STROKEPATH || !d->fill_set) { + if (iType == EMR_STROKEPATH || !d->dc[d->level].fill_set) { tmp_style << "fill:none;"; } else { snprintf(tmp, 1023, @@ -236,18 +251,18 @@ output_style(PEMF_CALLBACK_DATA d, int iType) tmp_style << tmp; snprintf(tmp, 1023, "fill-rule:%s;", - d->style.fill_rule.value == 0 ? "evenodd" : "nonzero"); + d->dc[d->level].style.fill_rule.value == 0 ? "evenodd" : "nonzero"); tmp_style << tmp; tmp_style << "fill-opacity:1;"; - if (d->fill_set && d->stroke_set && d->style.stroke_width.value == 1 && + if (d->dc[d->level].fill_set && d->dc[d->level].stroke_set && d->dc[d->level].style.stroke_width.value == 1 && fill_rgb[0]==stroke_rgb[0] && fill_rgb[1]==stroke_rgb[1] && fill_rgb[2]==stroke_rgb[2]) { - d->stroke_set = false; + d->dc[d->level].stroke_set = false; } } - if (iType == EMR_FILLPATH || !d->stroke_set) { + if (iType == EMR_FILLPATH || !d->dc[d->level].stroke_set) { tmp_style << "stroke:none;"; } else { snprintf(tmp, 1023, @@ -258,33 +273,33 @@ output_style(PEMF_CALLBACK_DATA d, int iType) tmp_style << tmp; tmp_style << "stroke-width:" << - MAX( 0.001, d->style.stroke_width.value ) << "px;"; + MAX( 0.001, d->dc[d->level].style.stroke_width.value ) << "px;"; tmp_style << "stroke-linecap:" << - (d->style.stroke_linecap.computed == 0 ? "butt" : - d->style.stroke_linecap.computed == 1 ? "round" : - d->style.stroke_linecap.computed == 2 ? "square" : + (d->dc[d->level].style.stroke_linecap.computed == 0 ? "butt" : + d->dc[d->level].style.stroke_linecap.computed == 1 ? "round" : + d->dc[d->level].style.stroke_linecap.computed == 2 ? "square" : "unknown") << ";"; 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" : + (d->dc[d->level].style.stroke_linejoin.computed == 0 ? "miter" : + d->dc[d->level].style.stroke_linejoin.computed == 1 ? "round" : + d->dc[d->level].style.stroke_linejoin.computed == 2 ? "bevel" : "unknown") << ";"; - if (d->style.stroke_linejoin.computed == 0) { + if (d->dc[d->level].style.stroke_linejoin.computed == 0) { tmp_style << "stroke-miterlimit:" << - MAX( 0.01, d->style.stroke_miterlimit.value ) << ";"; + MAX( 0.01, d->dc[d->level].style.stroke_miterlimit.value ) << ";"; } - if (d->style.stroke_dasharray_set && - d->style.stroke_dash.n_dash && d->style.stroke_dash.dash) + if (d->dc[d->level].style.stroke_dasharray_set && + d->dc[d->level].style.stroke_dash.n_dash && d->dc[d->level].style.stroke_dash.dash) { tmp_style << "stroke-dasharray:"; - for (int i=0; istyle.stroke_dash.n_dash; i++) { + for (int i=0; idc[d->level].style.stroke_dash.n_dash; i++) { if (i) tmp_style << ","; - tmp_style << d->style.stroke_dash.dash[i]; + tmp_style << d->dc[d->level].style.stroke_dash.dash[i]; } tmp_style << ";"; tmp_style << "stroke-dashoffset:0;"; @@ -302,18 +317,18 @@ output_style(PEMF_CALLBACK_DATA d, int iType) static double _pix_x_to_point(PEMF_CALLBACK_DATA d, double px) { - double tmp = px - d->winorg.x; - tmp *= d->ScaleX ? (double) PX_PER_IN / d->ScaleX : 1.0; - tmp += d->vieworg.x; + double tmp = px - d->dc[d->level].winorg.x; + tmp *= d->dc[d->level].ScaleInX ? d->dc[d->level].ScaleInX : 1.0; + tmp += d->dc[d->level].vieworg.x; return tmp; } static double _pix_y_to_point(PEMF_CALLBACK_DATA d, double px) { - double tmp = px - d->winorg.y; - tmp *= d->ScaleY ? (double) PX_PER_IN / d->ScaleY : 1.0; - tmp += d->vieworg.y; + double tmp = px - d->dc[d->level].winorg.y; + tmp *= d->dc[d->level].ScaleInY ? d->dc[d->level].ScaleInY : 1.0; + tmp += d->dc[d->level].vieworg.y; return tmp; } @@ -324,7 +339,8 @@ pix_to_x_point(PEMF_CALLBACK_DATA d, double px, double py) double ppx = _pix_x_to_point(d, px); double ppy = _pix_y_to_point(d, py); - double x = ppx * d->worldTransform.eM11 + ppy * d->worldTransform.eM21 + d->worldTransform.eDx; + double x = ppx * d->dc[d->level].worldTransform.eM11 + ppy * d->dc[d->level].worldTransform.eM21 + d->dc[d->level].worldTransform.eDx; + x *= d->dc[d->level].ScaleOutX ? d->dc[d->level].ScaleOutX : DEVICESCALE; return x; } @@ -335,26 +351,23 @@ pix_to_y_point(PEMF_CALLBACK_DATA d, double px, double py) double ppx = _pix_x_to_point(d, px); double ppy = _pix_y_to_point(d, py); - double y = ppx * d->worldTransform.eM12 + ppy * d->worldTransform.eM22 + d->worldTransform.eDy; + double y = ppx * d->dc[d->level].worldTransform.eM12 + ppy * d->dc[d->level].worldTransform.eM22 + d->dc[d->level].worldTransform.eDy; + y *= d->dc[d->level].ScaleOutY ? d->dc[d->level].ScaleOutY : DEVICESCALE; return y; } - static double -_pix_size_to_point(PEMF_CALLBACK_DATA d, double px) +pix_to_size_point(PEMF_CALLBACK_DATA d, double px) { - double tmp = px; - tmp *= d->ScaleX ? (double) PX_PER_IN / d->ScaleX : 1.0; - return tmp; -} + double ppx = px * (d->dc[d->level].ScaleInX ? d->dc[d->level].ScaleInX : 1.0); + double ppy = 0; + double dx = ppx * d->dc[d->level].worldTransform.eM11 + ppy * d->dc[d->level].worldTransform.eM21; + dx *= d->dc[d->level].ScaleOutX ? d->dc[d->level].ScaleOutX : DEVICESCALE; + double dy = ppx * d->dc[d->level].worldTransform.eM12 + ppy * d->dc[d->level].worldTransform.eM22; + dy *= d->dc[d->level].ScaleOutY ? d->dc[d->level].ScaleOutY : DEVICESCALE; -static double -pix_to_size_point(PEMF_CALLBACK_DATA d, double px) -{ - double dx = pix_to_x_point(d, px, 0); - double dy = pix_to_y_point(d, px, 0); double tmp = sqrt(dx * dx + dy * dy); return tmp; } @@ -379,32 +392,32 @@ select_pen(PEMF_CALLBACK_DATA d, int index) { int i = 0; int penstyle = (pEmr->lopn.lopnStyle & PS_STYLE_MASK); - d->style.stroke_dash.n_dash = + d->dc[d->level].style.stroke_dash.n_dash = penstyle == PS_DASHDOTDOT ? 6 : penstyle == PS_DASHDOT ? 4 : 2; - if (d->style.stroke_dash.dash) - delete[] d->style.stroke_dash.dash; - d->style.stroke_dash.dash = new double[d->style.stroke_dash.n_dash]; + if (d->dc[d->level].style.stroke_dash.dash && (d->level==0 || (d->level>0 && d->dc[d->level].style.stroke_dash.dash!=d->dc[d->level-1].style.stroke_dash.dash))) + delete[] d->dc[d->level].style.stroke_dash.dash; + d->dc[d->level].style.stroke_dash.dash = new double[d->dc[d->level].style.stroke_dash.n_dash]; if (penstyle==PS_DASH || penstyle==PS_DASHDOT || penstyle==PS_DASHDOTDOT) { - d->style.stroke_dash.dash[i++] = 3; - d->style.stroke_dash.dash[i++] = 1; + d->dc[d->level].style.stroke_dash.dash[i++] = 3; + d->dc[d->level].style.stroke_dash.dash[i++] = 1; } if (penstyle==PS_DOT || penstyle==PS_DASHDOT || penstyle==PS_DASHDOTDOT) { - d->style.stroke_dash.dash[i++] = 1; - d->style.stroke_dash.dash[i++] = 1; + d->dc[d->level].style.stroke_dash.dash[i++] = 1; + d->dc[d->level].style.stroke_dash.dash[i++] = 1; } if (penstyle==PS_DASHDOTDOT) { - d->style.stroke_dash.dash[i++] = 1; - d->style.stroke_dash.dash[i++] = 1; + d->dc[d->level].style.stroke_dash.dash[i++] = 1; + d->dc[d->level].style.stroke_dash.dash[i++] = 1; } - d->style.stroke_dasharray_set = 1; + d->dc[d->level].style.stroke_dasharray_set = 1; break; } case PS_SOLID: default: { - d->style.stroke_dasharray_set = 0; + d->dc[d->level].style.stroke_dasharray_set = 0; break; } } @@ -412,18 +425,18 @@ select_pen(PEMF_CALLBACK_DATA d, int index) switch (pEmr->lopn.lopnStyle & PS_ENDCAP_MASK) { case PS_ENDCAP_ROUND: { - d->style.stroke_linecap.computed = 1; + d->dc[d->level].style.stroke_linecap.computed = 1; break; } case PS_ENDCAP_SQUARE: { - d->style.stroke_linecap.computed = 2; + d->dc[d->level].style.stroke_linecap.computed = 2; break; } case PS_ENDCAP_FLAT: default: { - d->style.stroke_linecap.computed = 0; + d->dc[d->level].style.stroke_linecap.computed = 0; break; } } @@ -431,39 +444,47 @@ select_pen(PEMF_CALLBACK_DATA d, int index) switch (pEmr->lopn.lopnStyle & PS_JOIN_MASK) { case PS_JOIN_BEVEL: { - d->style.stroke_linejoin.computed = 2; + d->dc[d->level].style.stroke_linejoin.computed = 2; break; } case PS_JOIN_MITER: { - d->style.stroke_linejoin.computed = 0; + d->dc[d->level].style.stroke_linejoin.computed = 0; break; } case PS_JOIN_ROUND: default: { - d->style.stroke_linejoin.computed = 1; + d->dc[d->level].style.stroke_linejoin.computed = 1; break; } } - d->stroke_set = true; + d->dc[d->level].stroke_set = true; if (pEmr->lopn.lopnStyle == PS_NULL) { - d->style.stroke_width.value = 0; - d->stroke_set = false; + d->dc[d->level].style.stroke_width.value = 0; + d->dc[d->level].stroke_set = false; } else if (pEmr->lopn.lopnWidth.x) { - d->style.stroke_width.value = pix_to_size_point( d, pEmr->lopn.lopnWidth.x ); + int cur_level = d->level; + d->level = d->emf_obj[index].level; + double pen_width = pix_to_size_point( d, pEmr->lopn.lopnWidth.x ); + d->level = cur_level; + d->dc[d->level].style.stroke_width.value = pen_width; } 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; - d->style.stroke_width.value = pix_to_size_point( d, 1 ); + //d->dc[d->level].style.stroke_width.value = 1.0; + int cur_level = d->level; + d->level = d->emf_obj[index].level; + double pen_width = pix_to_size_point( d, 1 ); + d->level = cur_level; + d->dc[d->level].style.stroke_width.value = pen_width; } 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) ); - d->style.stroke.value.color.set( r, g, b ); + d->dc[d->level].style.stroke.value.color.set( r, g, b ); } @@ -482,16 +503,20 @@ select_extpen(PEMF_CALLBACK_DATA d, int index) 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]; + d->dc[d->level].style.stroke_dash.n_dash = pEmr->elp.elpNumEntries; + if (d->dc[d->level].style.stroke_dash.dash && (d->level==0 || (d->level>0 && d->dc[d->level].style.stroke_dash.dash!=d->dc[d->level-1].style.stroke_dash.dash))) + delete[] d->dc[d->level].style.stroke_dash.dash; + d->dc[d->level].style.stroke_dash.dash = new double[pEmr->elp.elpNumEntries]; for (unsigned int i=0; ielp.elpNumEntries; i++) { - d->style.stroke_dash.dash[i] = pix_to_size_point( d, pEmr->elp.elpStyleEntry[i] ); + int cur_level = d->level; + d->level = d->emf_obj[index].level; + double dash_length = pix_to_size_point( d, pEmr->elp.elpStyleEntry[i] ); + d->level = cur_level; + d->dc[d->level].style.stroke_dash.dash[i] = dash_length; } - d->style.stroke_dasharray_set = 1; + d->dc[d->level].style.stroke_dasharray_set = 1; } else { - d->style.stroke_dasharray_set = 0; + d->dc[d->level].style.stroke_dasharray_set = 0; } break; } @@ -503,32 +528,32 @@ select_extpen(PEMF_CALLBACK_DATA d, int index) { int i = 0; int penstyle = (pEmr->elp.elpPenStyle & PS_STYLE_MASK); - d->style.stroke_dash.n_dash = + d->dc[d->level].style.stroke_dash.n_dash = penstyle == PS_DASHDOTDOT ? 6 : penstyle == PS_DASHDOT ? 4 : 2; - if (d->style.stroke_dash.dash) - delete[] d->style.stroke_dash.dash; - d->style.stroke_dash.dash = new double[d->style.stroke_dash.n_dash]; + if (d->dc[d->level].style.stroke_dash.dash && (d->level==0 || (d->level>0 && d->dc[d->level].style.stroke_dash.dash!=d->dc[d->level-1].style.stroke_dash.dash))) + delete[] d->dc[d->level].style.stroke_dash.dash; + d->dc[d->level].style.stroke_dash.dash = new double[d->dc[d->level].style.stroke_dash.n_dash]; if (penstyle==PS_DASH || penstyle==PS_DASHDOT || penstyle==PS_DASHDOTDOT) { - d->style.stroke_dash.dash[i++] = 3; - d->style.stroke_dash.dash[i++] = 2; + d->dc[d->level].style.stroke_dash.dash[i++] = 3; + d->dc[d->level].style.stroke_dash.dash[i++] = 2; } if (penstyle==PS_DOT || penstyle==PS_DASHDOT || penstyle==PS_DASHDOTDOT) { - d->style.stroke_dash.dash[i++] = 1; - d->style.stroke_dash.dash[i++] = 2; + d->dc[d->level].style.stroke_dash.dash[i++] = 1; + d->dc[d->level].style.stroke_dash.dash[i++] = 2; } if (penstyle==PS_DASHDOTDOT) { - d->style.stroke_dash.dash[i++] = 1; - d->style.stroke_dash.dash[i++] = 2; + d->dc[d->level].style.stroke_dash.dash[i++] = 1; + d->dc[d->level].style.stroke_dash.dash[i++] = 2; } - d->style.stroke_dasharray_set = 1; + d->dc[d->level].style.stroke_dasharray_set = 1; break; } case PS_SOLID: default: { - d->style.stroke_dasharray_set = 0; + d->dc[d->level].style.stroke_dasharray_set = 0; break; } } @@ -536,18 +561,18 @@ select_extpen(PEMF_CALLBACK_DATA d, int index) switch (pEmr->elp.elpPenStyle & PS_ENDCAP_MASK) { case PS_ENDCAP_ROUND: { - d->style.stroke_linecap.computed = 1; + d->dc[d->level].style.stroke_linecap.computed = 1; break; } case PS_ENDCAP_SQUARE: { - d->style.stroke_linecap.computed = 2; + d->dc[d->level].style.stroke_linecap.computed = 2; break; } case PS_ENDCAP_FLAT: default: { - d->style.stroke_linecap.computed = 0; + d->dc[d->level].style.stroke_linecap.computed = 0; break; } } @@ -555,32 +580,40 @@ select_extpen(PEMF_CALLBACK_DATA d, int index) switch (pEmr->elp.elpPenStyle & PS_JOIN_MASK) { case PS_JOIN_BEVEL: { - d->style.stroke_linejoin.computed = 2; + d->dc[d->level].style.stroke_linejoin.computed = 2; break; } case PS_JOIN_MITER: { - d->style.stroke_linejoin.computed = 0; + d->dc[d->level].style.stroke_linejoin.computed = 0; break; } case PS_JOIN_ROUND: default: { - d->style.stroke_linejoin.computed = 1; + d->dc[d->level].style.stroke_linejoin.computed = 1; break; } } - d->stroke_set = true; + d->dc[d->level].stroke_set = true; if (pEmr->elp.elpPenStyle == PS_NULL) { - d->style.stroke_width.value = 0; - d->stroke_set = false; + d->dc[d->level].style.stroke_width.value = 0; + d->dc[d->level].stroke_set = false; } else if (pEmr->elp.elpWidth) { - d->style.stroke_width.value = pix_to_size_point( d, pEmr->elp.elpWidth ); + int cur_level = d->level; + d->level = d->emf_obj[index].level; + double pen_width = pix_to_size_point( d, pEmr->elp.elpWidth ); + d->level = cur_level; + d->dc[d->level].style.stroke_width.value = pen_width; } 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; - d->style.stroke_width.value = pix_to_size_point( d, 1 ); + //d->dc[d->level].style.stroke_width.value = 1.0; + int cur_level = d->level; + d->level = d->emf_obj[index].level; + double pen_width = pix_to_size_point( d, 1 ); + d->level = cur_level; + d->dc[d->level].style.stroke_width.value = pen_width; } double r, g, b; @@ -588,7 +621,7 @@ select_extpen(PEMF_CALLBACK_DATA d, int index) g = SP_COLOR_U_TO_F( GetGValue(pEmr->elp.elpColor) ); b = SP_COLOR_U_TO_F( GetBValue(pEmr->elp.elpColor) ); - d->style.stroke.value.color.set( r, g, b ); + d->dc[d->level].style.stroke.value.color.set( r, g, b ); } @@ -608,10 +641,10 @@ select_brush(PEMF_CALLBACK_DATA d, int index) 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) ); - d->style.fill.value.color.set( r, g, b ); + d->dc[d->level].style.fill.value.color.set( r, g, b ); } - d->fill_set = true; + d->dc[d->level].fill_set = true; } @@ -626,8 +659,12 @@ select_font(PEMF_CALLBACK_DATA d, int index) if (!pEmr) return; - d->style.font_size.computed = pix_to_size_point( d, pEmr->elfw.elfLogFont.lfHeight ); - d->style.font_weight.value = + int cur_level = d->level; + d->level = d->emf_obj[index].level; + double font_size = pix_to_size_point( d, pEmr->elfw.elfLogFont.lfHeight ); + d->level = cur_level; + d->dc[d->level].style.font_size.computed = font_size; + d->dc[d->level].style.font_weight.value = pEmr->elfw.elfLogFont.lfWeight == FW_THIN ? SP_CSS_FONT_WEIGHT_100 : pEmr->elfw.elfLogFont.lfWeight == FW_EXTRALIGHT ? SP_CSS_FONT_WEIGHT_200 : pEmr->elfw.elfLogFont.lfWeight == FW_LIGHT ? SP_CSS_FONT_WEIGHT_300 : @@ -642,13 +679,14 @@ select_font(PEMF_CALLBACK_DATA d, int index) pEmr->elfw.elfLogFont.lfWeight == FW_EXTRALIGHT ? SP_CSS_FONT_WEIGHT_LIGHTER : pEmr->elfw.elfLogFont.lfWeight == FW_EXTRABOLD ? SP_CSS_FONT_WEIGHT_BOLDER : FW_NORMAL; - d->style.font_style.value = (pEmr->elfw.elfLogFont.lfItalic ? SP_CSS_FONT_STYLE_ITALIC : SP_CSS_FONT_STYLE_NORMAL); - d->style.text_decoration.underline = pEmr->elfw.elfLogFont.lfUnderline; - d->style.text_decoration.line_through = pEmr->elfw.elfLogFont.lfStrikeOut; - if (d->tstyle.font_family.value) - g_free(d->tstyle.font_family.value); - d->tstyle.font_family.value = + d->dc[d->level].style.font_style.value = (pEmr->elfw.elfLogFont.lfItalic ? SP_CSS_FONT_STYLE_ITALIC : SP_CSS_FONT_STYLE_NORMAL); + d->dc[d->level].style.text_decoration.underline = pEmr->elfw.elfLogFont.lfUnderline; + d->dc[d->level].style.text_decoration.line_through = pEmr->elfw.elfLogFont.lfStrikeOut; + if (d->dc[d->level].tstyle.font_family.value) + g_free(d->dc[d->level].tstyle.font_family.value); + d->dc[d->level].tstyle.font_family.value = (gchar *) g_utf16_to_utf8( (gunichar2*) pEmr->elfw.elfLogFont.lfFaceName, -1, NULL, NULL, NULL ); + d->dc[d->level].style.text_transform.value = ((pEmr->elfw.elfLogFont.lfEscapement + 3600) % 3600) / 10; } static void @@ -669,15 +707,16 @@ 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].level = d->level; d->emf_obj[index].lpEMFR = pObj; } } static void -assert_empty_path(PEMF_CALLBACK_DATA d, const char *fun) +assert_empty_path(PEMF_CALLBACK_DATA d, const char * /*fun*/) { if (!d->path->empty()) { - g_debug("emf-win32-inout: assert_empty_path failed for %s\n", fun); + // g_debug("emf-win32-inout: assert_empty_path failed for %s\n", fun); *(d->outsvg) += "\n"; + + *(d->outsvg) += "\n"; + + if (d->pDesc) { + *(d->outsvg) += "\n"; + } + ENHMETAHEADER *pEmr = (ENHMETAHEADER *) lpEMFR; tmp_outsvg << "xDPI = 2540; d->yDPI = 2540; - d->PixelsX = pEmr->rclFrame.right - pEmr->rclFrame.left; - d->PixelsY = pEmr->rclFrame.bottom - pEmr->rclFrame.top; + d->dc[d->level].PixelsInX = pEmr->rclFrame.right - pEmr->rclFrame.left; + d->dc[d->level].PixelsInY = pEmr->rclFrame.bottom - pEmr->rclFrame.top; - d->MMX = d->PixelsX / 100.0; - d->MMY = d->PixelsY / 100.0; + d->MMX = d->dc[d->level].PixelsInX / 100.0; + d->MMY = d->dc[d->level].PixelsInY / 100.0; + d->dc[d->level].PixelsOutX = d->MMX * PX_PER_MM; + d->dc[d->level].PixelsOutY = d->MMY * PX_PER_MM; + tmp_outsvg << " width=\"" << d->MMX << "mm\"\n" << - " height=\"" << d->MMY << "mm\">\n"; - tmp_outsvg << "\n"; + " height=\"" << d->MMY << "mm\"\n"; + tmp_outsvg << + " id=\"" << (d->id++) << "\">\n"; + + tmp_outsvg << + "id++) << "\">\n"; if (pEmr->nHandles) { d->n_obj = pEmr->nHandles; @@ -751,7 +812,7 @@ myEnhMetaFileProc(HDC hDC, HANDLETABLE *lpHTable, ENHMETARECORD *lpEMFR, int nOb // dynamic allocation succeeded. if ( d->emf_obj != NULL ) { - for( unsigned int i=0; i < d->n_obj; ++i ) + for( int i=0; i < d->n_obj; ++i ) d->emf_obj[i].lpEMFR = NULL; } //if @@ -763,6 +824,8 @@ myEnhMetaFileProc(HDC hDC, HANDLETABLE *lpHTable, ENHMETARECORD *lpEMFR, int nOb } case EMR_POLYBEZIER: { + dbg_str << "\n"; + PEMRPOLYBEZIER pEmr = (PEMRPOLYBEZIER) lpEMFR; DWORD i,j; @@ -803,6 +866,8 @@ myEnhMetaFileProc(HDC hDC, HANDLETABLE *lpHTable, ENHMETARECORD *lpEMFR, int nOb } case EMR_POLYGON: { + dbg_str << "\n"; + EMRPOLYGON *pEmr = (EMRPOLYGON *) lpEMFR; DWORD i; @@ -834,6 +899,8 @@ myEnhMetaFileProc(HDC hDC, HANDLETABLE *lpHTable, ENHMETARECORD *lpEMFR, int nOb } case EMR_POLYLINE: { + dbg_str << "\n"; + EMRPOLYLINE *pEmr = (EMRPOLYLINE *) lpEMFR; DWORD i; @@ -872,6 +939,8 @@ myEnhMetaFileProc(HDC hDC, HANDLETABLE *lpHTable, ENHMETARECORD *lpEMFR, int nOb } case EMR_POLYBEZIERTO: { + dbg_str << "\n"; + PEMRPOLYBEZIERTO pEmr = (PEMRPOLYBEZIERTO) lpEMFR; DWORD i,j; @@ -893,6 +962,8 @@ myEnhMetaFileProc(HDC hDC, HANDLETABLE *lpHTable, ENHMETARECORD *lpEMFR, int nOb } case EMR_POLYLINETO: { + dbg_str << "\n"; + PEMRPOLYLINETO pEmr = (PEMRPOLYLINETO) lpEMFR; DWORD i; @@ -913,6 +984,11 @@ myEnhMetaFileProc(HDC hDC, HANDLETABLE *lpHTable, ENHMETARECORD *lpEMFR, int nOb case EMR_POLYPOLYLINE: case EMR_POLYPOLYGON: { + if (lpEMFR->iType == EMR_POLYPOLYLINE) + dbg_str << "\n"; + if (lpEMFR->iType == EMR_POLYPOLYGON) + dbg_str << "\n"; + PEMRPOLYPOLYGON pEmr = (PEMRPOLYPOLYGON) lpEMFR; unsigned int n, i, j; @@ -960,130 +1036,176 @@ myEnhMetaFileProc(HDC hDC, HANDLETABLE *lpHTable, ENHMETARECORD *lpEMFR, int nOb } case EMR_SETWINDOWEXTEX: { + dbg_str << "\n"; + PEMRSETWINDOWEXTEX pEmr = (PEMRSETWINDOWEXTEX) lpEMFR; - *(d->outsvg) += "\n"; + d->dc[d->level].sizeWnd = pEmr->szlExtent; + + if (!d->dc[d->level].sizeWnd.cx || !d->dc[d->level].sizeWnd.cy) { + d->dc[d->level].sizeWnd = d->dc[d->level].sizeView; + if (!d->dc[d->level].sizeWnd.cx || !d->dc[d->level].sizeWnd.cy) { + d->dc[d->level].sizeWnd.cx = d->dc[d->level].PixelsOutX; + d->dc[d->level].sizeWnd.cy = d->dc[d->level].PixelsOutY; + } + } + + if (!d->dc[d->level].sizeView.cx || !d->dc[d->level].sizeView.cy) { + d->dc[d->level].sizeView = d->dc[d->level].sizeWnd; + } - d->sizeWnd = pEmr->szlExtent; - d->PixelsX = d->sizeWnd.cx; - d->PixelsY = d->sizeWnd.cy; + d->dc[d->level].PixelsInX = d->dc[d->level].sizeWnd.cx; + d->dc[d->level].PixelsInY = d->dc[d->level].sizeWnd.cy; + + if (d->dc[d->level].PixelsInX && d->dc[d->level].PixelsInY) { + d->dc[d->level].ScaleInX = (double) d->dc[d->level].sizeView.cx / (double) d->dc[d->level].PixelsInX; + d->dc[d->level].ScaleInY = (double) d->dc[d->level].sizeView.cy / (double) d->dc[d->level].PixelsInY; + } + else { + d->dc[d->level].ScaleInX = 1; + d->dc[d->level].ScaleInY = 1; + } - d->ScaleX = d->xDPI / (100*d->MMX / d->PixelsX); - d->ScaleY = d->yDPI / (100*d->MMY / d->PixelsY); + if (d->dc[d->level].sizeView.cx && d->dc[d->level].sizeView.cy) { + d->dc[d->level].ScaleOutX = (double) d->dc[d->level].PixelsOutX / (double) d->dc[d->level].sizeView.cx; + d->dc[d->level].ScaleOutY = (double) d->dc[d->level].PixelsOutY / (double) d->dc[d->level].sizeView.cy; + } + else { + d->dc[d->level].ScaleOutX = DEVICESCALE; + d->dc[d->level].ScaleOutY = DEVICESCALE; + } break; } case EMR_SETWINDOWORGEX: { + dbg_str << "\n"; + PEMRSETWINDOWORGEX pEmr = (PEMRSETWINDOWORGEX) lpEMFR; - d->winorg = pEmr->ptlOrigin; + d->dc[d->level].winorg = pEmr->ptlOrigin; break; } case EMR_SETVIEWPORTEXTEX: { + dbg_str << "\n"; + PEMRSETVIEWPORTEXTEX pEmr = (PEMRSETVIEWPORTEXTEX) lpEMFR; - *(d->outsvg) += "\n"; - - 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->dc[d->level].sizeView = pEmr->szlExtent; + + if (!d->dc[d->level].sizeView.cx || !d->dc[d->level].sizeView.cy) { + d->dc[d->level].sizeView = d->dc[d->level].sizeWnd; + if (!d->dc[d->level].sizeView.cx || !d->dc[d->level].sizeView.cy) { + d->dc[d->level].sizeView.cx = d->dc[d->level].PixelsOutX; + d->dc[d->level].sizeView.cy = d->dc[d->level].PixelsOutY; } + } - d->MMX = d->dwInchesX * MM_PER_IN; - d->MMY = d->dwInchesY * MM_PER_IN; + if (!d->dc[d->level].sizeWnd.cx || !d->dc[d->level].sizeWnd.cy) { + d->dc[d->level].sizeWnd = d->dc[d->level].sizeView; + } + + d->dc[d->level].PixelsInX = d->dc[d->level].sizeWnd.cx; + d->dc[d->level].PixelsInY = d->dc[d->level].sizeWnd.cy; + + if (d->dc[d->level].PixelsInX && d->dc[d->level].PixelsInY) { + d->dc[d->level].ScaleInX = (double) d->dc[d->level].sizeView.cx / (double) d->dc[d->level].PixelsInX; + d->dc[d->level].ScaleInY = (double) d->dc[d->level].sizeView.cy / (double) d->dc[d->level].PixelsInY; + } + else { + d->dc[d->level].ScaleInX = 1; + d->dc[d->level].ScaleInY = 1; + } + + if (d->dc[d->level].sizeView.cx && d->dc[d->level].sizeView.cy) { + d->dc[d->level].ScaleOutX = (double) d->dc[d->level].PixelsOutX / (double) d->dc[d->level].sizeView.cx; + d->dc[d->level].ScaleOutY = (double) d->dc[d->level].PixelsOutY / (double) d->dc[d->level].sizeView.cy; + } + else { + d->dc[d->level].ScaleOutX = DEVICESCALE; + d->dc[d->level].ScaleOutY = DEVICESCALE; } break; } case EMR_SETVIEWPORTORGEX: { + dbg_str << "\n"; + PEMRSETVIEWPORTORGEX pEmr = (PEMRSETVIEWPORTORGEX) lpEMFR; - d->vieworg = pEmr->ptlOrigin; + d->dc[d->level].vieworg = pEmr->ptlOrigin; break; } case EMR_SETBRUSHORGEX: - *(d->outsvg) += "\n"; + dbg_str << "\n"; break; case EMR_EOF: { + dbg_str << "\n"; + assert_empty_path(d, "EMR_EOF"); tmp_outsvg << "\n"; tmp_outsvg << "\n"; break; } case EMR_SETPIXELV: - *(d->outsvg) += "\n"; + dbg_str << "\n"; break; case EMR_SETMAPPERFLAGS: - *(d->outsvg) += "\n"; + dbg_str << "\n"; break; case EMR_SETMAPMODE: - *(d->outsvg) += "\n"; + dbg_str << "\n"; break; case EMR_SETBKMODE: - *(d->outsvg) += "\n"; + dbg_str << "\n"; break; case EMR_SETPOLYFILLMODE: { + dbg_str << "\n"; + PEMRSETPOLYFILLMODE pEmr = (PEMRSETPOLYFILLMODE) lpEMFR; - d->style.fill_rule.value = + d->dc[d->level].style.fill_rule.value = (pEmr->iMode == ALTERNATE ? 0 : pEmr->iMode == WINDING ? 1 : 0); break; } case EMR_SETROP2: - *(d->outsvg) += "\n"; + dbg_str << "\n"; break; case EMR_SETSTRETCHBLTMODE: - *(d->outsvg) += "\n"; + dbg_str << "\n"; break; case EMR_SETTEXTALIGN: { + dbg_str << "\n"; + PEMRSETTEXTALIGN pEmr = (PEMRSETTEXTALIGN) lpEMFR; - d->textAlign = pEmr->iMode; + d->dc[d->level].textAlign = pEmr->iMode; break; } case EMR_SETCOLORADJUSTMENT: - *(d->outsvg) += "\n"; + dbg_str << "\n"; break; case EMR_SETTEXTCOLOR: { + dbg_str << "\n"; + PEMRSETTEXTCOLOR pEmr = (PEMRSETTEXTCOLOR) lpEMFR; - d->textColor = pEmr->crColor; - d->textColorSet = true; + d->dc[d->level].textColor = pEmr->crColor; + d->dc[d->level].textColorSet = true; break; } case EMR_SETBKCOLOR: - *(d->outsvg) += "\n"; + dbg_str << "\n"; break; case EMR_OFFSETCLIPRGN: - *(d->outsvg) += "\n"; + dbg_str << "\n"; break; case EMR_MOVETOEX: { + dbg_str << "\n"; + PEMRMOVETOEX pEmr = (PEMRMOVETOEX) lpEMFR; if (d->path->empty()) { @@ -1091,6 +1213,8 @@ myEnhMetaFileProc(HDC hDC, HANDLETABLE *lpHTable, ENHMETARECORD *lpEMFR, int nOb *(d->path) = "d=\""; } + d->dc[d->level].cur = pEmr->ptl; + tmp_path << "\n\tM " << pix_to_x_point( d, pEmr->ptl.x, pEmr->ptl.y ) << " " << @@ -1098,48 +1222,75 @@ myEnhMetaFileProc(HDC hDC, HANDLETABLE *lpHTable, ENHMETARECORD *lpEMFR, int nOb break; } case EMR_SETMETARGN: - *(d->outsvg) += "\n"; + dbg_str << "\n"; break; case EMR_EXCLUDECLIPRECT: - *(d->outsvg) += "\n"; + dbg_str << "\n"; break; case EMR_INTERSECTCLIPRECT: - *(d->outsvg) += "\n"; + dbg_str << "\n"; break; case EMR_SCALEVIEWPORTEXTEX: - *(d->outsvg) += "\n"; + dbg_str << "\n"; break; case EMR_SCALEWINDOWEXTEX: - *(d->outsvg) += "\n"; + dbg_str << "\n"; break; case EMR_SAVEDC: - *(d->outsvg) += "\n"; + dbg_str << "\n"; + + if (d->level < EMF_MAX_DC) { + d->dc[d->level + 1] = d->dc[d->level]; + d->level = d->level + 1; + } break; case EMR_RESTOREDC: - *(d->outsvg) += "\n"; + { + dbg_str << "\n"; + + PEMRRESTOREDC pEmr = (PEMRRESTOREDC) lpEMFR; + int old_level = d->level; + if (pEmr->iRelative >= 0) { + if (pEmr->iRelative < d->level) + d->level = pEmr->iRelative; + } + else { + if (d->level + pEmr->iRelative >= 0) + d->level = d->level + pEmr->iRelative; + } + while (old_level > d->level) { + if (d->dc[old_level].style.stroke_dash.dash && (old_level==0 || (old_level>0 && d->dc[old_level].style.stroke_dash.dash!=d->dc[old_level-1].style.stroke_dash.dash))) + delete[] d->dc[old_level].style.stroke_dash.dash; + old_level--; + } break; + } case EMR_SETWORLDTRANSFORM: { + dbg_str << "\n"; + PEMRSETWORLDTRANSFORM pEmr = (PEMRSETWORLDTRANSFORM) lpEMFR; - d->worldTransform = pEmr->xform; + d->dc[d->level].worldTransform = pEmr->xform; break; } case EMR_MODIFYWORLDTRANSFORM: { + dbg_str << "\n"; + PEMRMODIFYWORLDTRANSFORM pEmr = (PEMRMODIFYWORLDTRANSFORM) lpEMFR; switch (pEmr->iMode) { case MWT_IDENTITY: - d->worldTransform.eM11 = 1.0; - d->worldTransform.eM12 = 0.0; - d->worldTransform.eM21 = 0.0; - d->worldTransform.eM22 = 1.0; - d->worldTransform.eDx = 0.0; - d->worldTransform.eDy = 0.0; + d->dc[d->level].worldTransform.eM11 = 1.0; + d->dc[d->level].worldTransform.eM12 = 0.0; + d->dc[d->level].worldTransform.eM21 = 0.0; + d->dc[d->level].worldTransform.eM22 = 1.0; + d->dc[d->level].worldTransform.eDx = 0.0; + d->dc[d->level].worldTransform.eDy = 0.0; break; case MWT_LEFTMULTIPLY: { -// d->worldTransform = pEmr->xform * worldTransform; +// d->dc[d->level].worldTransform = pEmr->xform * worldTransform; float a11 = pEmr->xform.eM11; float a12 = pEmr->xform.eM12; @@ -1151,14 +1302,14 @@ myEnhMetaFileProc(HDC hDC, HANDLETABLE *lpHTable, ENHMETARECORD *lpEMFR, int nOb float a32 = pEmr->xform.eDy; float a33 = 1.0; - float b11 = d->worldTransform.eM11; - float b12 = d->worldTransform.eM12; + float b11 = d->dc[d->level].worldTransform.eM11; + float b12 = d->dc[d->level].worldTransform.eM12; //float b13 = 0.0; - float b21 = d->worldTransform.eM21; - float b22 = d->worldTransform.eM22; + float b21 = d->dc[d->level].worldTransform.eM21; + float b22 = d->dc[d->level].worldTransform.eM22; //float b23 = 0.0; - float b31 = d->worldTransform.eDx; - float b32 = d->worldTransform.eDy; + float b31 = d->dc[d->level].worldTransform.eDx; + float b32 = d->dc[d->level].worldTransform.eDy; //float b33 = 1.0; float c11 = a11*b11 + a12*b21 + a13*b31;; @@ -1171,27 +1322,27 @@ myEnhMetaFileProc(HDC hDC, HANDLETABLE *lpHTable, ENHMETARECORD *lpEMFR, int nOb float c32 = a31*b12 + a32*b22 + a33*b32;; //float c33 = a31*b13 + a32*b23 + a33*b33;; - d->worldTransform.eM11 = c11;; - d->worldTransform.eM12 = c12;; - d->worldTransform.eM21 = c21;; - d->worldTransform.eM22 = c22;; - d->worldTransform.eDx = c31; - d->worldTransform.eDy = c32; + d->dc[d->level].worldTransform.eM11 = c11;; + d->dc[d->level].worldTransform.eM12 = c12;; + d->dc[d->level].worldTransform.eM21 = c21;; + d->dc[d->level].worldTransform.eM22 = c22;; + d->dc[d->level].worldTransform.eDx = c31; + d->dc[d->level].worldTransform.eDy = c32; break; } case MWT_RIGHTMULTIPLY: { -// d->worldTransform = worldTransform * pEmr->xform; +// d->dc[d->level].worldTransform = worldTransform * pEmr->xform; - float a11 = d->worldTransform.eM11; - float a12 = d->worldTransform.eM12; + float a11 = d->dc[d->level].worldTransform.eM11; + float a12 = d->dc[d->level].worldTransform.eM12; float a13 = 0.0; - float a21 = d->worldTransform.eM21; - float a22 = d->worldTransform.eM22; + float a21 = d->dc[d->level].worldTransform.eM21; + float a22 = d->dc[d->level].worldTransform.eM22; float a23 = 0.0; - float a31 = d->worldTransform.eDx; - float a32 = d->worldTransform.eDy; + float a31 = d->dc[d->level].worldTransform.eDx; + float a32 = d->dc[d->level].worldTransform.eDy; float a33 = 1.0; float b11 = pEmr->xform.eM11; @@ -1214,24 +1365,26 @@ myEnhMetaFileProc(HDC hDC, HANDLETABLE *lpHTable, ENHMETARECORD *lpEMFR, int nOb float c32 = a31*b12 + a32*b22 + a33*b32;; //float c33 = a31*b13 + a32*b23 + a33*b33;; - d->worldTransform.eM11 = c11;; - d->worldTransform.eM12 = c12;; - d->worldTransform.eM21 = c21;; - d->worldTransform.eM22 = c22;; - d->worldTransform.eDx = c31; - d->worldTransform.eDy = c32; + d->dc[d->level].worldTransform.eM11 = c11;; + d->dc[d->level].worldTransform.eM12 = c12;; + d->dc[d->level].worldTransform.eM21 = c21;; + d->dc[d->level].worldTransform.eM22 = c22;; + d->dc[d->level].worldTransform.eDx = c31; + d->dc[d->level].worldTransform.eDy = c32; break; } // case MWT_SET: default: - d->worldTransform = pEmr->xform; + d->dc[d->level].worldTransform = pEmr->xform; break; } break; } case EMR_SELECTOBJECT: { + dbg_str << "\n"; + PEMRSELECTOBJECT pEmr = (PEMRSELECTOBJECT) lpEMFR; unsigned int index = pEmr->ihObject; @@ -1239,7 +1392,7 @@ myEnhMetaFileProc(HDC hDC, HANDLETABLE *lpHTable, ENHMETARECORD *lpEMFR, int nOb index -= ENHMETA_STOCK_OBJECT; switch (index) { case NULL_BRUSH: - d->fill_set = false; + d->dc[d->level].fill_set = false; break; case BLACK_BRUSH: case DKGRAY_BRUSH: @@ -1265,23 +1418,23 @@ myEnhMetaFileProc(HDC hDC, HANDLETABLE *lpHTable, ENHMETARECORD *lpEMFR, int nOb val = 255.0 / 255.0; break; } - d->style.fill.value.color.set( val, val, val ); + d->dc[d->level].style.fill.value.color.set( val, val, val ); - d->fill_set = true; + d->dc[d->level].fill_set = true; break; } case NULL_PEN: - d->stroke_set = false; + d->dc[d->level].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; - d->style.stroke.value.color.set( val, val, val ); + d->dc[d->level].style.stroke_dasharray_set = 0; + d->dc[d->level].style.stroke_width.value = 1.0; + d->dc[d->level].style.stroke.value.color.set( val, val, val ); - d->stroke_set = true; + d->dc[d->level].stroke_set = true; break; } @@ -1309,6 +1462,8 @@ myEnhMetaFileProc(HDC hDC, HANDLETABLE *lpHTable, ENHMETARECORD *lpEMFR, int nOb } case EMR_CREATEPEN: { + dbg_str << "\n"; + PEMRCREATEPEN pEmr = (PEMRCREATEPEN) lpEMFR; int index = pEmr->ihPen; @@ -1321,6 +1476,8 @@ myEnhMetaFileProc(HDC hDC, HANDLETABLE *lpHTable, ENHMETARECORD *lpEMFR, int nOb } case EMR_CREATEBRUSHINDIRECT: { + dbg_str << "\n"; + PEMRCREATEBRUSHINDIRECT pEmr = (PEMRCREATEBRUSHINDIRECT) lpEMFR; int index = pEmr->ihBrush; @@ -1332,12 +1489,15 @@ myEnhMetaFileProc(HDC hDC, HANDLETABLE *lpHTable, ENHMETARECORD *lpEMFR, int nOb break; } case EMR_DELETEOBJECT: + dbg_str << "\n"; break; case EMR_ANGLEARC: - *(d->outsvg) += "\n"; + dbg_str << "\n"; break; case EMR_ELLIPSE: { + dbg_str << "\n"; + PEMRELLIPSE pEmr = (PEMRELLIPSE) lpEMFR; RECTL rclBox = pEmr->rclBox; @@ -1369,6 +1529,8 @@ myEnhMetaFileProc(HDC hDC, HANDLETABLE *lpHTable, ENHMETARECORD *lpEMFR, int nOb } case EMR_RECTANGLE: { + dbg_str << "\n"; + PEMRRECTANGLE pEmr = (PEMRRECTANGLE) lpEMFR; RECTL rc = pEmr->rclBox; @@ -1396,37 +1558,39 @@ myEnhMetaFileProc(HDC hDC, HANDLETABLE *lpHTable, ENHMETARECORD *lpEMFR, int nOb break; } case EMR_ROUNDRECT: - *(d->outsvg) += "\n"; + dbg_str << "\n"; break; case EMR_ARC: - *(d->outsvg) += "\n"; + dbg_str << "\n"; break; case EMR_CHORD: - *(d->outsvg) += "\n"; + dbg_str << "\n"; break; case EMR_PIE: - *(d->outsvg) += "\n"; + dbg_str << "\n"; break; case EMR_SELECTPALETTE: - *(d->outsvg) += "\n"; + dbg_str << "\n"; break; case EMR_CREATEPALETTE: - *(d->outsvg) += "\n"; + dbg_str << "\n"; break; case EMR_SETPALETTEENTRIES: - *(d->outsvg) += "\n"; + dbg_str << "\n"; break; case EMR_RESIZEPALETTE: - *(d->outsvg) += "\n"; + dbg_str << "\n"; break; case EMR_REALIZEPALETTE: - *(d->outsvg) += "\n"; + dbg_str << "\n"; break; case EMR_EXTFLOODFILL: - *(d->outsvg) += "\n"; + dbg_str << "\n"; break; case EMR_LINETO: { + dbg_str << "\n"; + PEMRLINETO pEmr = (PEMRLINETO) lpEMFR; if (d->path->empty()) { @@ -1441,26 +1605,31 @@ myEnhMetaFileProc(HDC hDC, HANDLETABLE *lpHTable, ENHMETARECORD *lpEMFR, int nOb break; } case EMR_ARCTO: - *(d->outsvg) += "\n"; + dbg_str << "\n"; break; case EMR_POLYDRAW: - *(d->outsvg) += "\n"; + dbg_str << "\n"; break; case EMR_SETARCDIRECTION: - *(d->outsvg) += "\n"; + dbg_str << "\n"; break; case EMR_SETMITERLIMIT: { - PEMRSETMITERLIMIT pEmr = (PEMRSETMITERLIMIT) lpEMFR; - d->style.stroke_miterlimit.value = pix_to_size_point( d, pEmr->eMiterLimit ); + dbg_str << "\n"; - if (d->style.stroke_miterlimit.value < 1) - d->style.stroke_miterlimit.value = 1.0; + PEMRSETMITERLIMIT pEmr = (PEMRSETMITERLIMIT) lpEMFR; + float miterlimit = pEmr->eMiterLimit; + miterlimit = miterlimit * 4.0 / 10.0; + d->dc[d->level].style.stroke_miterlimit.value = pix_to_size_point( d, miterlimit ); + if (d->dc[d->level].style.stroke_miterlimit.value < 1) + d->dc[d->level].style.stroke_miterlimit.value = 4.0; break; } case EMR_BEGINPATH: { + dbg_str << "\n"; + tmp_path << "d=\""; *(d->path) = ""; d->inpath = true; @@ -1468,12 +1637,16 @@ myEnhMetaFileProc(HDC hDC, HANDLETABLE *lpHTable, ENHMETARECORD *lpEMFR, int nOb } case EMR_ENDPATH: { + dbg_str << "\n"; + tmp_path << "\""; d->inpath = false; break; } case EMR_CLOSEFIGURE: { + dbg_str << "\n"; + tmp_path << "\n\tz"; break; } @@ -1481,6 +1654,13 @@ myEnhMetaFileProc(HDC hDC, HANDLETABLE *lpHTable, ENHMETARECORD *lpEMFR, int nOb case EMR_STROKEANDFILLPATH: case EMR_STROKEPATH: { + if (lpEMFR->iType == EMR_FILLPATH) + dbg_str << "\n"; + if (lpEMFR->iType == EMR_STROKEANDFILLPATH) + dbg_str << "\n"; + if (lpEMFR->iType == EMR_STROKEPATH) + dbg_str << "\n"; + *(d->outsvg) += " iType); *(d->outsvg) += "\n\t"; @@ -1490,55 +1670,79 @@ myEnhMetaFileProc(HDC hDC, HANDLETABLE *lpHTable, ENHMETARECORD *lpEMFR, int nOb break; } case EMR_FLATTENPATH: - *(d->outsvg) += "\n"; + dbg_str << "\n"; break; case EMR_WIDENPATH: - *(d->outsvg) += "\n"; + dbg_str << "\n"; break; case EMR_SELECTCLIPPATH: - *(d->outsvg) += "\n"; + dbg_str << "\n"; break; case EMR_ABORTPATH: - *(d->outsvg) += "\n"; + dbg_str << "\n"; break; case EMR_GDICOMMENT: - *(d->outsvg) += "\n"; + { + dbg_str << "\n"; + + PEMRGDICOMMENT pEmr = (PEMRGDICOMMENT) lpEMFR; + + CHAR *szTxt = (CHAR *) pEmr->Data; + + for (DWORD i = 0; i < pEmr->cbData; i++) { + if ( *szTxt) { + if ( *szTxt >= ' ' && *szTxt < 'z' && *szTxt != '<' && *szTxt != '>' ) { + tmp_str << *szTxt; + } + szTxt++; + } + } + + if (0 && strlen(tmp_str.str().c_str())) { + tmp_outsvg << " \n"; + } + break; + } case EMR_FILLRGN: - *(d->outsvg) += "\n"; + dbg_str << "\n"; break; case EMR_FRAMERGN: - *(d->outsvg) += "\n"; + dbg_str << "\n"; break; case EMR_INVERTRGN: - *(d->outsvg) += "\n"; + dbg_str << "\n"; break; case EMR_PAINTRGN: - *(d->outsvg) += "\n"; + dbg_str << "\n"; break; case EMR_EXTSELECTCLIPRGN: - *(d->outsvg) += "\n"; + dbg_str << "\n"; break; case EMR_BITBLT: - *(d->outsvg) += "\n"; + dbg_str << "\n"; break; case EMR_STRETCHBLT: - *(d->outsvg) += "\n"; + dbg_str << "\n"; break; case EMR_MASKBLT: - *(d->outsvg) += "\n"; + dbg_str << "\n"; break; case EMR_PLGBLT: - *(d->outsvg) += "\n"; + dbg_str << "\n"; break; case EMR_SETDIBITSTODEVICE: - *(d->outsvg) += "\n"; + dbg_str << "\n"; break; case EMR_STRETCHDIBITS: - *(d->outsvg) += "\n"; + dbg_str << "\n"; break; case EMR_EXTCREATEFONTINDIRECTW: { + dbg_str << "\n"; + PEMREXTCREATEFONTINDIRECTW pEmr = (PEMREXTCREATEFONTINDIRECTW) lpEMFR; int index = pEmr->ihFont; @@ -1546,23 +1750,29 @@ myEnhMetaFileProc(HDC hDC, HANDLETABLE *lpHTable, ENHMETARECORD *lpEMFR, int nOb (EMREXTCREATEFONTINDIRECTW *) malloc( sizeof(EMREXTCREATEFONTINDIRECTW) ); pFont->elfw = pEmr->elfw; insert_object(d, index, EMR_EXTCREATEFONTINDIRECTW, (ENHMETARECORD *) pFont); - break; } case EMR_EXTTEXTOUTA: { - *(d->outsvg) += "\n"; + dbg_str << "\n"; break; } case EMR_EXTTEXTOUTW: { + dbg_str << "\n"; + PEMREXTTEXTOUTW pEmr = (PEMREXTTEXTOUTW) lpEMFR; double x1 = pEmr->emrtext.ptlReference.x; double y1 = pEmr->emrtext.ptlReference.y; - if (!(d->textAlign & TA_BOTTOM)) - y1 += fabs(d->style.font_size.computed); + if (d->dc[d->level].textAlign & TA_UPDATECP) { + x1 = d->dc[d->level].cur.x; + y1 = d->dc[d->level].cur.y; + } + + if (!(d->dc[d->level].textAlign & TA_BOTTOM)) + y1 += fabs(d->dc[d->level].style.font_size.computed); double x = pix_to_x_point(d, x1, y1); double y = pix_to_y_point(d, x1, y1); @@ -1588,10 +1798,10 @@ myEnhMetaFileProc(HDC hDC, HANDLETABLE *lpHTable, ENHMETARECORD *lpEMFR, int nOb gchar *escaped_text = g_markup_escape_text(ansi_text, -1); float text_rgb[3]; - sp_color_get_rgb_floatv( &(d->style.fill.value.color), text_rgb ); + sp_color_get_rgb_floatv( &(d->dc[d->level].style.fill.value.color), text_rgb ); - if (!d->textColorSet) { - d->textColor = RGB(SP_COLOR_F_TO_U(text_rgb[0]), + if (!d->dc[d->level].textColorSet) { + d->dc[d->level].textColor = RGB(SP_COLOR_F_TO_U(text_rgb[0]), SP_COLOR_F_TO_U(text_rgb[1]), SP_COLOR_F_TO_U(text_rgb[2])); } @@ -1599,15 +1809,15 @@ myEnhMetaFileProc(HDC hDC, HANDLETABLE *lpHTable, ENHMETARECORD *lpEMFR, int nOb char tmp[128]; snprintf(tmp, 127, "fill:#%02x%02x%02x;", - GetRValue(d->textColor), - GetGValue(d->textColor), - GetBValue(d->textColor)); + GetRValue(d->dc[d->level].textColor), + GetGValue(d->dc[d->level].textColor), + GetBValue(d->dc[d->level].textColor)); - bool i = (d->style.font_style.value == SP_CSS_FONT_STYLE_ITALIC); - //bool o = (d->style.font_style.value == SP_CSS_FONT_STYLE_OBLIQUE); - bool b = (d->style.font_weight.value == SP_CSS_FONT_WEIGHT_BOLD) || - (d->style.font_weight.value >= SP_CSS_FONT_WEIGHT_500 && d->style.font_weight.value <= SP_CSS_FONT_WEIGHT_900); - int lcr = ((d->textAlign & TA_CENTER) == TA_CENTER) ? 2 : ((d->textAlign & TA_RIGHT) == TA_RIGHT) ? 1 : 0; + bool i = (d->dc[d->level].style.font_style.value == SP_CSS_FONT_STYLE_ITALIC); + //bool o = (d->dc[d->level].style.font_style.value == SP_CSS_FONT_STYLE_OBLIQUE); + bool b = (d->dc[d->level].style.font_weight.value == SP_CSS_FONT_WEIGHT_BOLD) || + (d->dc[d->level].style.font_weight.value >= SP_CSS_FONT_WEIGHT_500 && d->dc[d->level].style.font_weight.value <= SP_CSS_FONT_WEIGHT_900); + int lcr = ((d->dc[d->level].textAlign & TA_CENTER) == TA_CENTER) ? 2 : ((d->dc[d->level].textAlign & TA_RIGHT) == TA_RIGHT) ? 1 : 0; assert_empty_path(d, "EMR_EXTTEXTOUTW"); @@ -1616,14 +1826,20 @@ myEnhMetaFileProc(HDC hDC, HANDLETABLE *lpHTable, ENHMETARECORD *lpEMFR, int nOb ts << " xml:space=\"preserve\"\n"; ts << " x=\"" << x << "\"\n"; ts << " y=\"" << y << "\"\n"; + if (d->dc[d->level].style.text_transform.value) { + ts << " transform=\"" + << "rotate(-" << d->dc[d->level].style.text_transform.value + << " " << x << " " << y << ")" + << "\"\n"; + } ts << " style=\"" - << "font-size:" << fabs(d->style.font_size.computed) << "px;" + << "font-size:" << fabs(d->dc[d->level].style.font_size.computed) << "px;" << tmp << "font-style:" << (i ? "italic" : "normal") << ";" << "font-weight:" << (b ? "bold" : "normal") << ";" << "text-align:" << (lcr==2 ? "center" : lcr==1 ? "end" : "start") << ";" << "text-anchor:" << (lcr==2 ? "middle" : lcr==1 ? "end" : "start") << ";" - << "font-family:" << d->tstyle.font_family.value << ";" + << "font-family:" << d->dc[d->level].tstyle.font_family.value << ";" << "\"\n"; ts << " >"; ts << escaped_text; @@ -1639,6 +1855,8 @@ myEnhMetaFileProc(HDC hDC, HANDLETABLE *lpHTable, ENHMETARECORD *lpEMFR, int nOb } case EMR_POLYBEZIER16: { + dbg_str << "\n"; + PEMRPOLYBEZIER16 pEmr = (PEMRPOLYBEZIER16) lpEMFR; POINTS *apts = (POINTS *) pEmr->apts; // Bug in MinGW wingdi.h ? DWORD i,j; @@ -1680,6 +1898,8 @@ myEnhMetaFileProc(HDC hDC, HANDLETABLE *lpHTable, ENHMETARECORD *lpEMFR, int nOb } case EMR_POLYGON16: { + dbg_str << "\n"; + PEMRPOLYGON16 pEmr = (PEMRPOLYGON16) lpEMFR; POINTS *apts = (POINTS *) pEmr->apts; // Bug in MinGW wingdi.h ? SVGOStringStream tmp_poly; @@ -1710,6 +1930,8 @@ myEnhMetaFileProc(HDC hDC, HANDLETABLE *lpHTable, ENHMETARECORD *lpEMFR, int nOb } case EMR_POLYLINE16: { + dbg_str << "\n"; + EMRPOLYLINE16 *pEmr = (EMRPOLYLINE16 *) lpEMFR; POINTS *apts = (POINTS *) pEmr->apts; // Bug in MinGW wingdi.h ? DWORD i; @@ -1749,6 +1971,8 @@ myEnhMetaFileProc(HDC hDC, HANDLETABLE *lpHTable, ENHMETARECORD *lpEMFR, int nOb } case EMR_POLYBEZIERTO16: { + dbg_str << "\n"; + PEMRPOLYBEZIERTO16 pEmr = (PEMRPOLYBEZIERTO16) lpEMFR; POINTS *apts = (POINTS *) pEmr->apts; // Bug in MinGW wingdi.h ? DWORD i,j; @@ -1771,6 +1995,8 @@ myEnhMetaFileProc(HDC hDC, HANDLETABLE *lpHTable, ENHMETARECORD *lpEMFR, int nOb } case EMR_POLYLINETO16: { + dbg_str << "\n"; + PEMRPOLYLINETO16 pEmr = (PEMRPOLYLINETO16) lpEMFR; POINTS *apts = (POINTS *) pEmr->apts; // Bug in MinGW wingdi.h ? DWORD i; @@ -1792,6 +2018,11 @@ myEnhMetaFileProc(HDC hDC, HANDLETABLE *lpHTable, ENHMETARECORD *lpEMFR, int nOb case EMR_POLYPOLYLINE16: case EMR_POLYPOLYGON16: { + if (lpEMFR->iType == EMR_POLYPOLYLINE16) + dbg_str << "\n"; + if (lpEMFR->iType == EMR_POLYPOLYGON16) + dbg_str << "\n"; + PEMRPOLYPOLYGON16 pEmr = (PEMRPOLYPOLYGON16) lpEMFR; unsigned int n, i, j; @@ -1838,16 +2069,18 @@ myEnhMetaFileProc(HDC hDC, HANDLETABLE *lpHTable, ENHMETARECORD *lpEMFR, int nOb break; } case EMR_POLYDRAW16: - *(d->outsvg) += "\n"; + dbg_str << "\n"; break; case EMR_CREATEMONOBRUSH: - *(d->outsvg) += "\n"; + dbg_str << "\n"; break; case EMR_CREATEDIBPATTERNBRUSHPT: - *(d->outsvg) += "\n"; + dbg_str << "\n"; break; case EMR_EXTCREATEPEN: { + dbg_str << "\n"; + PEMREXTCREATEPEN pEmr = (PEMREXTCREATEPEN) lpEMFR; int index = pEmr->ihPen; @@ -1868,34 +2101,38 @@ myEnhMetaFileProc(HDC hDC, HANDLETABLE *lpHTable, ENHMETARECORD *lpEMFR, int nOb break; } case EMR_POLYTEXTOUTA: - *(d->outsvg) += "\n"; + dbg_str << "\n"; break; case EMR_POLYTEXTOUTW: - *(d->outsvg) += "\n"; + dbg_str << "\n"; break; case EMR_SETICMMODE: - *(d->outsvg) += "\n"; + dbg_str << "\n"; break; case EMR_CREATECOLORSPACE: - *(d->outsvg) += "\n"; + dbg_str << "\n"; break; case EMR_SETCOLORSPACE: - *(d->outsvg) += "\n"; + dbg_str << "\n"; break; case EMR_DELETECOLORSPACE: - *(d->outsvg) += "\n"; + dbg_str << "\n"; break; case EMR_GLSRECORD: - *(d->outsvg) += "\n"; + dbg_str << "\n"; break; case EMR_GLSBOUNDEDRECORD: - *(d->outsvg) += "\n"; + dbg_str << "\n"; break; case EMR_PIXELFORMAT: - *(d->outsvg) += "\n"; + dbg_str << "\n"; + break; + default: + dbg_str << "\n"; break; } +// *(d->outsvg) += dbg_str.str().c_str(); *(d->outsvg) += tmp_outsvg.str().c_str(); *(d->path) += tmp_path.str().c_str(); @@ -1903,7 +2140,7 @@ myEnhMetaFileProc(HDC hDC, HANDLETABLE *lpHTable, ENHMETARECORD *lpEMFR, int nOb } static int CALLBACK -myMetaFileProc(HDC hDC, HANDLETABLE *lpHTable, METARECORD *lpMFR, int nObj, LPARAM lpData) +myMetaFileProc(HDC /*hDC*/, HANDLETABLE * /*lpHTable*/, METARECORD * /*lpMFR*/, int /*nObj*/, LPARAM /*lpData*/) { g_warning("Unable to import Windows Meta File.\n"); return 0; @@ -1918,29 +2155,29 @@ myMetaFileProc(HDC hDC, HANDLETABLE *lpHTable, METARECORD *lpMFR, int nObj, LPAR #pragma pack( 2 ) typedef struct { - DWORD dwKey; - WORD hmf; - SMALL_RECT bbox; - WORD wInch; - DWORD dwReserved; - WORD wCheckSum; + 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 ) +EmfWin32::open( Inkscape::Extension::Input * /*mod*/, const gchar *uri ) { EMF_CALLBACK_DATA d; memset(&d, 0, sizeof(d)); - d.worldTransform.eM11 = 1.0; - d.worldTransform.eM12 = 0.0; - d.worldTransform.eM21 = 0.0; - d.worldTransform.eM22 = 1.0; - d.worldTransform.eDx = 0.0; - d.worldTransform.eDy = 0.0; + d.dc[0].worldTransform.eM11 = 1.0; + d.dc[0].worldTransform.eM12 = 0.0; + d.dc[0].worldTransform.eM21 = 0.0; + d.dc[0].worldTransform.eM22 = 1.0; + d.dc[0].worldTransform.eDx = 0.0; + d.dc[0].worldTransform.eDy = 0.0; gsize bytesRead = 0; gsize bytesWritten = 0; @@ -1990,8 +2227,8 @@ EmfWin32::open( Inkscape::Extension::Input *mod, const gchar *uri ) else hmf = GetMetaFileA(ansi_uri); - METAFILEPICT mp; - HDC hDC; + METAFILEPICT mp; + HDC hDC; if (!hmf) { if (PrintWin32::is_os_wide()) { @@ -2106,18 +2343,33 @@ EmfWin32::open( Inkscape::Extension::Input *mod, const gchar *uri ) return NULL; } + d.pDesc = NULL; + if (hemf) { - EnumEnhMetaFile(NULL, hemf, myEnhMetaFileProc, (LPVOID) &d, NULL); + DWORD dwNeeded = GetEnhMetaFileDescriptionA( hemf, 0, NULL ); + if ( dwNeeded > 0 ) { + d.pDesc = (CHAR *) malloc( dwNeeded + 1 ); + if ( GetEnhMetaFileDescription( hemf, dwNeeded, d.pDesc ) == 0 ) + lstrcpy( d.pDesc, "" ); + if ( lstrlen( d.pDesc ) > 1 ) + d.pDesc[lstrlen(d.pDesc)] = '#'; + } + + // This ugly reinterpret_cast is to prevent old versions of gcc from whining about a mismatch in the const-ness of the arguments + EnumEnhMetaFile(NULL, hemf, reinterpret_cast(myEnhMetaFileProc), (LPVOID) &d, NULL); DeleteEnhMetaFile(hemf); } else { EnumMetaFile(NULL, hmf, myMetaFileProc, (LPARAM) &d); DeleteMetaFile(hmf); } + + if (d.pDesc) + free( d.pDesc ); // 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); + SPDocument *doc = SPDocument::createNewDocFromMem(d.outsvg->c_str(), d.outsvg->length(), TRUE); delete d.outsvg; delete d.path; @@ -2129,8 +2381,8 @@ EmfWin32::open( Inkscape::Extension::Input *mod, const gchar *uri ) delete[] d.emf_obj; } - if (d.style.stroke_dash.dash) - delete[] d.style.stroke_dash.dash; + if (d.dc[0].style.stroke_dash.dash) + delete[] d.dc[0].style.stroke_dash.dash; if (local_fn) g_free(local_fn); @@ -2194,17 +2446,14 @@ EmfWin32::init (void) } } } /* namespace Inkscape, Extension, Implementation */ - #endif /* WIN32 */ - - /* Local Variables: - mode:cpp + mode:c++ c-file-style:"stroustrup" - c-file-offsets:((innamespace . 0)(inline-open . 0)) + 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 : +// vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :