1 /** \file
2 * Enhanced Metafile Input and Output.
3 */
4 /*
5 * Authors:
6 * Ulf Erikson <ulferikson@users.sf.net>
7 *
8 * Copyright (C) 2006-2008 Authors
9 *
10 * Released under GNU GPL, read the file 'COPYING' for more information
11 */
12 /*
13 * References:
14 * - How to Create & Play Enhanced Metafiles in Win32
15 * http://support.microsoft.com/kb/q145999/
16 * - INFO: Windows Metafile Functions & Aldus Placeable Metafiles
17 * http://support.microsoft.com/kb/q66949/
18 * - Metafile Functions
19 * http://msdn.microsoft.com/library/en-us/gdi/metafile_0whf.asp
20 * - Metafile Structures
21 * http://msdn.microsoft.com/library/en-us/gdi/metafile_5hkj.asp
22 */
24 #ifdef WIN32
26 #ifdef HAVE_CONFIG_H
27 # include "config.h"
28 #endif
30 //#include "inkscape.h"
31 #include "sp-path.h"
32 #include "style.h"
33 //#include "color.h"
34 //#include "display/curve.h"
35 //#include "libnr/nr-point-matrix-ops.h"
36 //#include "gtk/gtk.h"
37 #include "print.h"
38 //#include "glibmm/i18n.h"
39 //#include "extension/extension.h"
40 #include "extension/system.h"
41 #include "extension/print.h"
42 #include "extension/db.h"
43 #include "extension/output.h"
44 //#include "document.h"
45 #include "display/nr-arena.h"
46 #include "display/nr-arena-item.h"
48 //#include "libnr/nr-rect.h"
49 //#include "libnr/nr-matrix.h"
50 //#include "libnr/nr-pixblock.h"
52 //#include <stdio.h>
53 //#include <string.h>
55 //#include <vector>
56 //#include <string>
58 //#include "io/sys.h"
60 #include "unit-constants.h"
62 #include "clear-n_.h"
64 #define WIN32_LEAN_AND_MEAN
65 #include <windows.h>
67 #include "win32.h"
68 #include "emf-win32-print.h"
69 #include "emf-win32-inout.h"
72 #define PRINT_EMF_WIN32 "org.inkscape.print.emf.win32"
74 #ifndef PS_JOIN_MASK
75 #define PS_JOIN_MASK (PS_JOIN_BEVEL|PS_JOIN_MITER|PS_JOIN_ROUND)
76 #endif
79 namespace Inkscape {
80 namespace Extension {
81 namespace Internal {
84 EmfWin32::EmfWin32 (void) // The null constructor
85 {
86 return;
87 }
90 EmfWin32::~EmfWin32 (void) //The destructor
91 {
92 return;
93 }
96 bool
97 EmfWin32::check (Inkscape::Extension::Extension * /*module*/)
98 {
99 if (NULL == Inkscape::Extension::db.get(PRINT_EMF_WIN32))
100 return FALSE;
101 return TRUE;
102 }
105 static void
106 emf_print_document_to_file(SPDocument *doc, gchar const *filename)
107 {
108 Inkscape::Extension::Print *mod;
109 SPPrintContext context;
110 gchar const *oldconst;
111 gchar *oldoutput;
112 unsigned int ret;
114 sp_document_ensure_up_to_date(doc);
116 mod = Inkscape::Extension::get_print(PRINT_EMF_WIN32);
117 oldconst = mod->get_param_string("destination");
118 oldoutput = g_strdup(oldconst);
119 mod->set_param_string("destination", (gchar *)filename);
121 /* Start */
122 context.module = mod;
123 /* fixme: This has to go into module constructor somehow */
124 /* Create new arena */
125 mod->base = SP_ITEM(sp_document_root(doc));
126 mod->arena = NRArena::create();
127 mod->dkey = sp_item_display_key_new(1);
128 mod->root = sp_item_invoke_show(mod->base, mod->arena, mod->dkey, SP_ITEM_SHOW_DISPLAY);
129 /* Print document */
130 ret = mod->begin(doc);
131 if (ret) {
132 throw Inkscape::Extension::Output::save_failed();
133 }
134 sp_item_invoke_print(mod->base, &context);
135 ret = mod->finish();
136 /* Release arena */
137 sp_item_invoke_hide(mod->base, mod->dkey);
138 mod->base = NULL;
139 mod->root = NULL;
140 nr_object_unref((NRObject *) mod->arena);
141 mod->arena = NULL;
142 /* end */
144 mod->set_param_string("destination", oldoutput);
145 g_free(oldoutput);
147 return;
148 }
151 void
152 EmfWin32::save (Inkscape::Extension::Output *mod, SPDocument *doc, const gchar *uri)
153 {
154 Inkscape::Extension::Extension * ext;
156 ext = Inkscape::Extension::db.get(PRINT_EMF_WIN32);
157 if (ext == NULL)
158 return;
160 bool old_textToPath = ext->get_param_bool("textToPath");
161 bool new_val = mod->get_param_bool("textToPath");
162 ext->set_param_bool("textToPath", new_val);
164 gchar * final_name;
165 final_name = g_strdup_printf("%s", uri);
166 emf_print_document_to_file(doc, final_name);
167 g_free(final_name);
169 ext->set_param_bool("textToPath", old_textToPath);
171 return;
172 }
176 typedef struct {
177 int type;
178 int level;
179 ENHMETARECORD *lpEMFR;
180 } EMF_OBJECT, *PEMF_OBJECT;
182 typedef struct emf_device_context {
183 struct SPStyle style;
184 class SPTextStyle tstyle;
185 bool stroke_set;
186 bool fill_set;
188 SIZEL sizeWnd;
189 SIZEL sizeView;
190 float PixelsInX, PixelsInY;
191 float PixelsOutX, PixelsOutY;
192 POINTL winorg;
193 POINTL vieworg;
194 double ScaleInX, ScaleInY;
195 double ScaleOutX, ScaleOutY;
196 COLORREF textColor;
197 bool textColorSet;
198 DWORD textAlign;
199 XFORM worldTransform;
200 POINTL cur;
201 } EMF_DEVICE_CONTEXT, *PEMF_DEVICE_CONTEXT;
203 #define EMF_MAX_DC 128
205 typedef struct emf_callback_data {
206 Glib::ustring *outsvg;
207 Glib::ustring *path;
209 EMF_DEVICE_CONTEXT dc[EMF_MAX_DC+1]; // FIXME: This should be dynamic..
210 int level;
212 double xDPI, yDPI;
213 bool pathless_stroke;
214 bool inpath;
216 float MMX;
217 float MMY;
218 float dwInchesX;
219 float dwInchesY;
221 unsigned int id;
222 CHAR *pDesc;
224 int n_obj;
225 PEMF_OBJECT emf_obj;
226 } EMF_CALLBACK_DATA, *PEMF_CALLBACK_DATA;
229 static void
230 output_style(PEMF_CALLBACK_DATA d, int iType)
231 {
232 SVGOStringStream tmp_id;
233 SVGOStringStream tmp_style;
234 char tmp[1024] = {0};
236 float fill_rgb[3];
237 sp_color_get_rgb_floatv( &(d->dc[d->level].style.fill.value.color), fill_rgb );
239 float stroke_rgb[3];
240 sp_color_get_rgb_floatv(&(d->dc[d->level].style.stroke.value.color), stroke_rgb);
242 tmp_id << "\n\tid=\"" << (d->id++) << "\"";
243 *(d->outsvg) += tmp_id.str().c_str();
244 *(d->outsvg) += "\n\tstyle=\"";
245 if (iType == EMR_STROKEPATH || !d->dc[d->level].fill_set) {
246 tmp_style << "fill:none;";
247 } else {
248 snprintf(tmp, 1023,
249 "fill:#%02x%02x%02x;",
250 SP_COLOR_F_TO_U(fill_rgb[0]),
251 SP_COLOR_F_TO_U(fill_rgb[1]),
252 SP_COLOR_F_TO_U(fill_rgb[2]));
253 tmp_style << tmp;
254 snprintf(tmp, 1023,
255 "fill-rule:%s;",
256 d->dc[d->level].style.fill_rule.value == 0 ? "evenodd" : "nonzero");
257 tmp_style << tmp;
258 tmp_style << "fill-opacity:1;";
260 if (d->dc[d->level].fill_set && d->dc[d->level].stroke_set && d->dc[d->level].style.stroke_width.value == 1 &&
261 fill_rgb[0]==stroke_rgb[0] && fill_rgb[1]==stroke_rgb[1] && fill_rgb[2]==stroke_rgb[2])
262 {
263 d->dc[d->level].stroke_set = false;
264 }
265 }
267 if (iType == EMR_FILLPATH || !d->dc[d->level].stroke_set) {
268 tmp_style << "stroke:none;";
269 } else {
270 snprintf(tmp, 1023,
271 "stroke:#%02x%02x%02x;",
272 SP_COLOR_F_TO_U(stroke_rgb[0]),
273 SP_COLOR_F_TO_U(stroke_rgb[1]),
274 SP_COLOR_F_TO_U(stroke_rgb[2]));
275 tmp_style << tmp;
277 tmp_style << "stroke-width:" <<
278 MAX( 0.001, d->dc[d->level].style.stroke_width.value ) << "px;";
280 tmp_style << "stroke-linecap:" <<
281 (d->dc[d->level].style.stroke_linecap.computed == 0 ? "butt" :
282 d->dc[d->level].style.stroke_linecap.computed == 1 ? "round" :
283 d->dc[d->level].style.stroke_linecap.computed == 2 ? "square" :
284 "unknown") << ";";
286 tmp_style << "stroke-linejoin:" <<
287 (d->dc[d->level].style.stroke_linejoin.computed == 0 ? "miter" :
288 d->dc[d->level].style.stroke_linejoin.computed == 1 ? "round" :
289 d->dc[d->level].style.stroke_linejoin.computed == 2 ? "bevel" :
290 "unknown") << ";";
292 if (d->dc[d->level].style.stroke_linejoin.computed == 0) {
293 tmp_style << "stroke-miterlimit:" <<
294 MAX( 0.01, d->dc[d->level].style.stroke_miterlimit.value ) << ";";
295 }
297 if (d->dc[d->level].style.stroke_dasharray_set &&
298 d->dc[d->level].style.stroke_dash.n_dash && d->dc[d->level].style.stroke_dash.dash)
299 {
300 tmp_style << "stroke-dasharray:";
301 for (int i=0; i<d->dc[d->level].style.stroke_dash.n_dash; i++) {
302 if (i)
303 tmp_style << ",";
304 tmp_style << d->dc[d->level].style.stroke_dash.dash[i];
305 }
306 tmp_style << ";";
307 tmp_style << "stroke-dashoffset:0;";
308 } else {
309 tmp_style << "stroke-dasharray:none;";
310 }
311 tmp_style << "stroke-opacity:1;";
312 }
313 tmp_style << "\" ";
315 *(d->outsvg) += tmp_style.str().c_str();
316 }
319 static double
320 _pix_x_to_point(PEMF_CALLBACK_DATA d, double px)
321 {
322 double tmp = px - d->dc[d->level].winorg.x;
323 tmp *= d->dc[d->level].ScaleInX ? d->dc[d->level].ScaleInX : 1.0;
324 tmp += d->dc[d->level].vieworg.x;
325 return tmp;
326 }
328 static double
329 _pix_y_to_point(PEMF_CALLBACK_DATA d, double px)
330 {
331 double tmp = px - d->dc[d->level].winorg.y;
332 tmp *= d->dc[d->level].ScaleInY ? d->dc[d->level].ScaleInY : 1.0;
333 tmp += d->dc[d->level].vieworg.y;
334 return tmp;
335 }
338 static double
339 pix_to_x_point(PEMF_CALLBACK_DATA d, double px, double py)
340 {
341 double ppx = _pix_x_to_point(d, px);
342 double ppy = _pix_y_to_point(d, py);
344 double x = ppx * d->dc[d->level].worldTransform.eM11 + ppy * d->dc[d->level].worldTransform.eM21 + d->dc[d->level].worldTransform.eDx;
345 x *= d->dc[d->level].ScaleOutX ? d->dc[d->level].ScaleOutX : DEVICESCALE;
347 return x;
348 }
350 static double
351 pix_to_y_point(PEMF_CALLBACK_DATA d, double px, double py)
352 {
353 double ppx = _pix_x_to_point(d, px);
354 double ppy = _pix_y_to_point(d, py);
356 double y = ppx * d->dc[d->level].worldTransform.eM12 + ppy * d->dc[d->level].worldTransform.eM22 + d->dc[d->level].worldTransform.eDy;
357 y *= d->dc[d->level].ScaleOutY ? d->dc[d->level].ScaleOutY : DEVICESCALE;
359 return y;
360 }
362 static double
363 pix_to_size_point(PEMF_CALLBACK_DATA d, double px)
364 {
365 double ppx = px * (d->dc[d->level].ScaleInX ? d->dc[d->level].ScaleInX : 1.0);
366 double ppy = 0;
368 double dx = ppx * d->dc[d->level].worldTransform.eM11 + ppy * d->dc[d->level].worldTransform.eM21;
369 dx *= d->dc[d->level].ScaleOutX ? d->dc[d->level].ScaleOutX : DEVICESCALE;
370 double dy = ppx * d->dc[d->level].worldTransform.eM12 + ppy * d->dc[d->level].worldTransform.eM22;
371 dy *= d->dc[d->level].ScaleOutY ? d->dc[d->level].ScaleOutY : DEVICESCALE;
373 double tmp = sqrt(dx * dx + dy * dy);
374 return tmp;
375 }
378 static void
379 select_pen(PEMF_CALLBACK_DATA d, int index)
380 {
381 PEMRCREATEPEN pEmr = NULL;
383 if (index >= 0 && index < d->n_obj)
384 pEmr = (PEMRCREATEPEN) d->emf_obj[index].lpEMFR;
386 if (!pEmr)
387 return;
389 switch (pEmr->lopn.lopnStyle & PS_STYLE_MASK) {
390 case PS_DASH:
391 case PS_DOT:
392 case PS_DASHDOT:
393 case PS_DASHDOTDOT:
394 {
395 int i = 0;
396 int penstyle = (pEmr->lopn.lopnStyle & PS_STYLE_MASK);
397 d->dc[d->level].style.stroke_dash.n_dash =
398 penstyle == PS_DASHDOTDOT ? 6 : penstyle == PS_DASHDOT ? 4 : 2;
399 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)))
400 delete[] d->dc[d->level].style.stroke_dash.dash;
401 d->dc[d->level].style.stroke_dash.dash = new double[d->dc[d->level].style.stroke_dash.n_dash];
402 if (penstyle==PS_DASH || penstyle==PS_DASHDOT || penstyle==PS_DASHDOTDOT) {
403 d->dc[d->level].style.stroke_dash.dash[i++] = 3;
404 d->dc[d->level].style.stroke_dash.dash[i++] = 1;
405 }
406 if (penstyle==PS_DOT || penstyle==PS_DASHDOT || penstyle==PS_DASHDOTDOT) {
407 d->dc[d->level].style.stroke_dash.dash[i++] = 1;
408 d->dc[d->level].style.stroke_dash.dash[i++] = 1;
409 }
410 if (penstyle==PS_DASHDOTDOT) {
411 d->dc[d->level].style.stroke_dash.dash[i++] = 1;
412 d->dc[d->level].style.stroke_dash.dash[i++] = 1;
413 }
415 d->dc[d->level].style.stroke_dasharray_set = 1;
416 break;
417 }
419 case PS_SOLID:
420 default:
421 {
422 d->dc[d->level].style.stroke_dasharray_set = 0;
423 break;
424 }
425 }
427 switch (pEmr->lopn.lopnStyle & PS_ENDCAP_MASK) {
428 case PS_ENDCAP_ROUND:
429 {
430 d->dc[d->level].style.stroke_linecap.computed = 1;
431 break;
432 }
433 case PS_ENDCAP_SQUARE:
434 {
435 d->dc[d->level].style.stroke_linecap.computed = 2;
436 break;
437 }
438 case PS_ENDCAP_FLAT:
439 default:
440 {
441 d->dc[d->level].style.stroke_linecap.computed = 0;
442 break;
443 }
444 }
446 switch (pEmr->lopn.lopnStyle & PS_JOIN_MASK) {
447 case PS_JOIN_BEVEL:
448 {
449 d->dc[d->level].style.stroke_linejoin.computed = 2;
450 break;
451 }
452 case PS_JOIN_MITER:
453 {
454 d->dc[d->level].style.stroke_linejoin.computed = 0;
455 break;
456 }
457 case PS_JOIN_ROUND:
458 default:
459 {
460 d->dc[d->level].style.stroke_linejoin.computed = 1;
461 break;
462 }
463 }
465 d->dc[d->level].stroke_set = true;
467 if (pEmr->lopn.lopnStyle == PS_NULL) {
468 d->dc[d->level].style.stroke_width.value = 0;
469 d->dc[d->level].stroke_set = false;
470 } else if (pEmr->lopn.lopnWidth.x) {
471 int cur_level = d->level;
472 d->level = d->emf_obj[index].level;
473 double pen_width = pix_to_size_point( d, pEmr->lopn.lopnWidth.x );
474 d->level = cur_level;
475 d->dc[d->level].style.stroke_width.value = pen_width;
476 } else { // this stroke should always be rendered as 1 pixel wide, independent of zoom level (can that be done in SVG?)
477 //d->dc[d->level].style.stroke_width.value = 1.0;
478 int cur_level = d->level;
479 d->level = d->emf_obj[index].level;
480 double pen_width = pix_to_size_point( d, 1 );
481 d->level = cur_level;
482 d->dc[d->level].style.stroke_width.value = pen_width;
483 }
485 double r, g, b;
486 r = SP_COLOR_U_TO_F( GetRValue(pEmr->lopn.lopnColor) );
487 g = SP_COLOR_U_TO_F( GetGValue(pEmr->lopn.lopnColor) );
488 b = SP_COLOR_U_TO_F( GetBValue(pEmr->lopn.lopnColor) );
489 d->dc[d->level].style.stroke.value.color.set( r, g, b );
490 }
493 static void
494 select_extpen(PEMF_CALLBACK_DATA d, int index)
495 {
496 PEMREXTCREATEPEN pEmr = NULL;
498 if (index >= 0 && index < d->n_obj)
499 pEmr = (PEMREXTCREATEPEN) d->emf_obj[index].lpEMFR;
501 if (!pEmr)
502 return;
504 switch (pEmr->elp.elpPenStyle & PS_STYLE_MASK) {
505 case PS_USERSTYLE:
506 {
507 if (pEmr->elp.elpNumEntries) {
508 d->dc[d->level].style.stroke_dash.n_dash = pEmr->elp.elpNumEntries;
509 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)))
510 delete[] d->dc[d->level].style.stroke_dash.dash;
511 d->dc[d->level].style.stroke_dash.dash = new double[pEmr->elp.elpNumEntries];
512 for (unsigned int i=0; i<pEmr->elp.elpNumEntries; i++) {
513 int cur_level = d->level;
514 d->level = d->emf_obj[index].level;
515 double dash_length = pix_to_size_point( d, pEmr->elp.elpStyleEntry[i] );
516 d->level = cur_level;
517 d->dc[d->level].style.stroke_dash.dash[i] = dash_length;
518 }
519 d->dc[d->level].style.stroke_dasharray_set = 1;
520 } else {
521 d->dc[d->level].style.stroke_dasharray_set = 0;
522 }
523 break;
524 }
526 case PS_DASH:
527 case PS_DOT:
528 case PS_DASHDOT:
529 case PS_DASHDOTDOT:
530 {
531 int i = 0;
532 int penstyle = (pEmr->elp.elpPenStyle & PS_STYLE_MASK);
533 d->dc[d->level].style.stroke_dash.n_dash =
534 penstyle == PS_DASHDOTDOT ? 6 : penstyle == PS_DASHDOT ? 4 : 2;
535 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)))
536 delete[] d->dc[d->level].style.stroke_dash.dash;
537 d->dc[d->level].style.stroke_dash.dash = new double[d->dc[d->level].style.stroke_dash.n_dash];
538 if (penstyle==PS_DASH || penstyle==PS_DASHDOT || penstyle==PS_DASHDOTDOT) {
539 d->dc[d->level].style.stroke_dash.dash[i++] = 3;
540 d->dc[d->level].style.stroke_dash.dash[i++] = 2;
541 }
542 if (penstyle==PS_DOT || penstyle==PS_DASHDOT || penstyle==PS_DASHDOTDOT) {
543 d->dc[d->level].style.stroke_dash.dash[i++] = 1;
544 d->dc[d->level].style.stroke_dash.dash[i++] = 2;
545 }
546 if (penstyle==PS_DASHDOTDOT) {
547 d->dc[d->level].style.stroke_dash.dash[i++] = 1;
548 d->dc[d->level].style.stroke_dash.dash[i++] = 2;
549 }
551 d->dc[d->level].style.stroke_dasharray_set = 1;
552 break;
553 }
555 case PS_SOLID:
556 default:
557 {
558 d->dc[d->level].style.stroke_dasharray_set = 0;
559 break;
560 }
561 }
563 switch (pEmr->elp.elpPenStyle & PS_ENDCAP_MASK) {
564 case PS_ENDCAP_ROUND:
565 {
566 d->dc[d->level].style.stroke_linecap.computed = 1;
567 break;
568 }
569 case PS_ENDCAP_SQUARE:
570 {
571 d->dc[d->level].style.stroke_linecap.computed = 2;
572 break;
573 }
574 case PS_ENDCAP_FLAT:
575 default:
576 {
577 d->dc[d->level].style.stroke_linecap.computed = 0;
578 break;
579 }
580 }
582 switch (pEmr->elp.elpPenStyle & PS_JOIN_MASK) {
583 case PS_JOIN_BEVEL:
584 {
585 d->dc[d->level].style.stroke_linejoin.computed = 2;
586 break;
587 }
588 case PS_JOIN_MITER:
589 {
590 d->dc[d->level].style.stroke_linejoin.computed = 0;
591 break;
592 }
593 case PS_JOIN_ROUND:
594 default:
595 {
596 d->dc[d->level].style.stroke_linejoin.computed = 1;
597 break;
598 }
599 }
601 d->dc[d->level].stroke_set = true;
603 if (pEmr->elp.elpPenStyle == PS_NULL) {
604 d->dc[d->level].style.stroke_width.value = 0;
605 d->dc[d->level].stroke_set = false;
606 } else if (pEmr->elp.elpWidth) {
607 int cur_level = d->level;
608 d->level = d->emf_obj[index].level;
609 double pen_width = pix_to_size_point( d, pEmr->elp.elpWidth );
610 d->level = cur_level;
611 d->dc[d->level].style.stroke_width.value = pen_width;
612 } else { // this stroke should always be rendered as 1 pixel wide, independent of zoom level (can that be done in SVG?)
613 //d->dc[d->level].style.stroke_width.value = 1.0;
614 int cur_level = d->level;
615 d->level = d->emf_obj[index].level;
616 double pen_width = pix_to_size_point( d, 1 );
617 d->level = cur_level;
618 d->dc[d->level].style.stroke_width.value = pen_width;
619 }
621 double r, g, b;
622 r = SP_COLOR_U_TO_F( GetRValue(pEmr->elp.elpColor) );
623 g = SP_COLOR_U_TO_F( GetGValue(pEmr->elp.elpColor) );
624 b = SP_COLOR_U_TO_F( GetBValue(pEmr->elp.elpColor) );
626 d->dc[d->level].style.stroke.value.color.set( r, g, b );
627 }
630 static void
631 select_brush(PEMF_CALLBACK_DATA d, int index)
632 {
633 PEMRCREATEBRUSHINDIRECT pEmr = NULL;
635 if (index >= 0 && index < d->n_obj)
636 pEmr = (PEMRCREATEBRUSHINDIRECT) d->emf_obj[index].lpEMFR;
638 if (!pEmr)
639 return;
641 if (pEmr->lb.lbStyle == BS_SOLID) {
642 double r, g, b;
643 r = SP_COLOR_U_TO_F( GetRValue(pEmr->lb.lbColor) );
644 g = SP_COLOR_U_TO_F( GetGValue(pEmr->lb.lbColor) );
645 b = SP_COLOR_U_TO_F( GetBValue(pEmr->lb.lbColor) );
646 d->dc[d->level].style.fill.value.color.set( r, g, b );
647 }
649 d->dc[d->level].fill_set = true;
650 }
653 static void
654 select_font(PEMF_CALLBACK_DATA d, int index)
655 {
656 PEMREXTCREATEFONTINDIRECTW pEmr = NULL;
658 if (index >= 0 && index < d->n_obj)
659 pEmr = (PEMREXTCREATEFONTINDIRECTW) d->emf_obj[index].lpEMFR;
661 if (!pEmr)
662 return;
664 int cur_level = d->level;
665 d->level = d->emf_obj[index].level;
666 double font_size = pix_to_size_point( d, pEmr->elfw.elfLogFont.lfHeight );
667 d->level = cur_level;
668 d->dc[d->level].style.font_size.computed = font_size;
669 d->dc[d->level].style.font_weight.value =
670 pEmr->elfw.elfLogFont.lfWeight == FW_THIN ? SP_CSS_FONT_WEIGHT_100 :
671 pEmr->elfw.elfLogFont.lfWeight == FW_EXTRALIGHT ? SP_CSS_FONT_WEIGHT_200 :
672 pEmr->elfw.elfLogFont.lfWeight == FW_LIGHT ? SP_CSS_FONT_WEIGHT_300 :
673 pEmr->elfw.elfLogFont.lfWeight == FW_NORMAL ? SP_CSS_FONT_WEIGHT_400 :
674 pEmr->elfw.elfLogFont.lfWeight == FW_MEDIUM ? SP_CSS_FONT_WEIGHT_500 :
675 pEmr->elfw.elfLogFont.lfWeight == FW_SEMIBOLD ? SP_CSS_FONT_WEIGHT_600 :
676 pEmr->elfw.elfLogFont.lfWeight == FW_BOLD ? SP_CSS_FONT_WEIGHT_700 :
677 pEmr->elfw.elfLogFont.lfWeight == FW_EXTRABOLD ? SP_CSS_FONT_WEIGHT_800 :
678 pEmr->elfw.elfLogFont.lfWeight == FW_HEAVY ? SP_CSS_FONT_WEIGHT_900 :
679 pEmr->elfw.elfLogFont.lfWeight == FW_NORMAL ? SP_CSS_FONT_WEIGHT_NORMAL :
680 pEmr->elfw.elfLogFont.lfWeight == FW_BOLD ? SP_CSS_FONT_WEIGHT_BOLD :
681 pEmr->elfw.elfLogFont.lfWeight == FW_EXTRALIGHT ? SP_CSS_FONT_WEIGHT_LIGHTER :
682 pEmr->elfw.elfLogFont.lfWeight == FW_EXTRABOLD ? SP_CSS_FONT_WEIGHT_BOLDER :
683 FW_NORMAL;
684 d->dc[d->level].style.font_style.value = (pEmr->elfw.elfLogFont.lfItalic ? SP_CSS_FONT_STYLE_ITALIC : SP_CSS_FONT_STYLE_NORMAL);
685 d->dc[d->level].style.text_decoration.underline = pEmr->elfw.elfLogFont.lfUnderline;
686 d->dc[d->level].style.text_decoration.line_through = pEmr->elfw.elfLogFont.lfStrikeOut;
687 if (d->dc[d->level].tstyle.font_family.value)
688 g_free(d->dc[d->level].tstyle.font_family.value);
689 d->dc[d->level].tstyle.font_family.value =
690 (gchar *) g_utf16_to_utf8( (gunichar2*) pEmr->elfw.elfLogFont.lfFaceName, -1, NULL, NULL, NULL );
691 d->dc[d->level].style.text_transform.value = ((pEmr->elfw.elfLogFont.lfEscapement + 3600) % 3600) / 10;
692 }
694 static void
695 delete_object(PEMF_CALLBACK_DATA d, int index)
696 {
697 if (index >= 0 && index < d->n_obj) {
698 d->emf_obj[index].type = 0;
699 if (d->emf_obj[index].lpEMFR)
700 free(d->emf_obj[index].lpEMFR);
701 d->emf_obj[index].lpEMFR = NULL;
702 }
703 }
706 static void
707 insert_object(PEMF_CALLBACK_DATA d, int index, int type, ENHMETARECORD *pObj)
708 {
709 if (index >= 0 && index < d->n_obj) {
710 delete_object(d, index);
711 d->emf_obj[index].type = type;
712 d->emf_obj[index].level = d->level;
713 d->emf_obj[index].lpEMFR = pObj;
714 }
715 }
717 static void
718 assert_empty_path(PEMF_CALLBACK_DATA d, const char * /*fun*/)
719 {
720 if (!d->path->empty()) {
721 // g_debug("emf-win32-inout: assert_empty_path failed for %s\n", fun);
723 *(d->outsvg) += "<!--\n";
724 *(d->outsvg) += " <path \t";
725 output_style(d, EMR_STROKEPATH);
726 if (strstr(d->path->c_str(), "d=\"") == NULL) {
727 *(d->outsvg) += "d=\"";
728 *(d->outsvg) += "\n\t";
729 }
730 *(d->outsvg) += *(d->path);
731 *(d->outsvg) += " \" /> \n";
732 *(d->outsvg) += "-->\n";
734 *(d->path) = "";
735 }
736 }
739 static int CALLBACK
740 myEnhMetaFileProc(HDC /*hDC*/, HANDLETABLE * /*lpHTable*/, ENHMETARECORD *lpEMFR, int /*nObj*/, LPARAM lpData)
741 {
742 PEMF_CALLBACK_DATA d;
743 SVGOStringStream tmp_outsvg;
744 SVGOStringStream tmp_path;
745 SVGOStringStream tmp_str;
746 SVGOStringStream dbg_str;
748 d = (PEMF_CALLBACK_DATA) lpData;
750 if (d->pathless_stroke) {
751 if (lpEMFR->iType!=EMR_POLYBEZIERTO && lpEMFR->iType!=EMR_POLYBEZIERTO16 &&
752 lpEMFR->iType!=EMR_POLYLINETO && lpEMFR->iType!=EMR_POLYLINETO16 &&
753 lpEMFR->iType!=EMR_LINETO && lpEMFR->iType!=EMR_ARCTO &&
754 lpEMFR->iType!=EMR_SETBKCOLOR && lpEMFR->iType!=EMR_SETROP2 &&
755 lpEMFR->iType!=EMR_SETBKMODE)
756 {
757 *(d->outsvg) += " <path ";
758 output_style(d, EMR_STROKEPATH);
759 *(d->outsvg) += "\n\t";
760 *(d->outsvg) += *(d->path);
761 *(d->outsvg) += " \" /> \n";
762 *(d->path) = "";
763 d->pathless_stroke = false;
764 }
765 }
767 switch (lpEMFR->iType)
768 {
769 case EMR_HEADER:
770 {
771 dbg_str << "<!-- EMR_HEADER -->\n";
773 *(d->outsvg) += "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n";
775 if (d->pDesc) {
776 *(d->outsvg) += "<!-- ";
777 *(d->outsvg) += d->pDesc;
778 *(d->outsvg) += " -->\n";
779 }
781 ENHMETAHEADER *pEmr = (ENHMETAHEADER *) lpEMFR;
782 tmp_outsvg << "<svg\n";
783 tmp_outsvg << " xmlns:svg=\"http://www.w3.org/2000/svg\"\n";
784 tmp_outsvg << " xmlns=\"http://www.w3.org/2000/svg\"\n";
785 tmp_outsvg << " version=\"1.0\"\n";
787 d->xDPI = 2540;
788 d->yDPI = 2540;
790 d->dc[d->level].PixelsInX = pEmr->rclFrame.right - pEmr->rclFrame.left;
791 d->dc[d->level].PixelsInY = pEmr->rclFrame.bottom - pEmr->rclFrame.top;
793 d->MMX = d->dc[d->level].PixelsInX / 100.0;
794 d->MMY = d->dc[d->level].PixelsInY / 100.0;
796 d->dc[d->level].PixelsOutX = d->MMX * PX_PER_MM;
797 d->dc[d->level].PixelsOutY = d->MMY * PX_PER_MM;
799 tmp_outsvg <<
800 " width=\"" << d->MMX << "mm\"\n" <<
801 " height=\"" << d->MMY << "mm\"\n";
802 tmp_outsvg <<
803 " id=\"" << (d->id++) << "\">\n";
805 tmp_outsvg <<
806 "<g\n" <<
807 " id=\"" << (d->id++) << "\">\n";
809 if (pEmr->nHandles) {
810 d->n_obj = pEmr->nHandles;
811 d->emf_obj = new EMF_OBJECT[d->n_obj];
813 // Init the new emf_obj list elements to null, provided the
814 // dynamic allocation succeeded.
815 if ( d->emf_obj != NULL )
816 {
817 for( int i=0; i < d->n_obj; ++i )
818 d->emf_obj[i].lpEMFR = NULL;
819 } //if
821 } else {
822 d->emf_obj = NULL;
823 }
825 break;
826 }
827 case EMR_POLYBEZIER:
828 {
829 dbg_str << "<!-- EMR_POLYBEZIER -->\n";
831 PEMRPOLYBEZIER pEmr = (PEMRPOLYBEZIER) lpEMFR;
832 DWORD i,j;
834 if (pEmr->cptl<4)
835 break;
837 if (!d->inpath) {
838 assert_empty_path(d, "EMR_POLYBEZIER");
840 *(d->outsvg) += " <path ";
841 output_style(d, EMR_STROKEPATH);
842 *(d->outsvg) += "\n\td=\"";
843 }
845 tmp_str <<
846 "\n\tM " <<
847 pix_to_x_point( d, pEmr->aptl[0].x, pEmr->aptl[0].y ) << " " <<
848 pix_to_y_point( d, pEmr->aptl[0].x, pEmr->aptl[0].y) << " ";
850 for (i=1; i<pEmr->cptl; ) {
851 tmp_str << "\n\tC ";
852 for (j=0; j<3 && i<pEmr->cptl; j++,i++) {
853 tmp_str <<
854 pix_to_x_point( d, pEmr->aptl[i].x, pEmr->aptl[i].y ) << " " <<
855 pix_to_y_point( d, pEmr->aptl[i].x, pEmr->aptl[i].y ) << " ";
856 }
857 }
859 if (d->inpath) {
860 tmp_path << tmp_str.str().c_str();
861 }
862 else {
863 *(d->outsvg) += tmp_str.str().c_str();
864 *(d->outsvg) += " \" /> \n";
865 }
867 break;
868 }
869 case EMR_POLYGON:
870 {
871 dbg_str << "<!-- EMR_POLYGON -->\n";
873 EMRPOLYGON *pEmr = (EMRPOLYGON *) lpEMFR;
874 DWORD i;
876 if (pEmr->cptl < 2)
877 break;
879 assert_empty_path(d, "EMR_POLYGON");
881 *(d->outsvg) += " <path ";
882 output_style(d, EMR_STROKEANDFILLPATH);
883 *(d->outsvg) += "\n\td=\"";
885 tmp_str <<
886 "\n\tM " <<
887 pix_to_x_point( d, pEmr->aptl[0].x, pEmr->aptl[0].y ) << " " <<
888 pix_to_y_point( d, pEmr->aptl[0].x, pEmr->aptl[0].y ) << " ";
890 for (i=1; i<pEmr->cptl; i++) {
891 tmp_str <<
892 "\n\tL " <<
893 pix_to_x_point( d, pEmr->aptl[i].x, pEmr->aptl[i].y ) << " " <<
894 pix_to_y_point( d, pEmr->aptl[i].x, pEmr->aptl[i].y ) << " ";
895 }
897 *(d->outsvg) += tmp_str.str().c_str();
898 *(d->outsvg) += " z \" /> \n";
900 break;
901 }
902 case EMR_POLYLINE:
903 {
904 dbg_str << "<!-- EMR_POLYLINE -->\n";
906 EMRPOLYLINE *pEmr = (EMRPOLYLINE *) lpEMFR;
907 DWORD i;
909 if (pEmr->cptl<2)
910 break;
912 if (!d->inpath) {
913 assert_empty_path(d, "EMR_POLYLINE");
915 *(d->outsvg) += " <path ";
916 output_style(d, EMR_STROKEPATH);
917 *(d->outsvg) += "\n\td=\"";
918 }
920 tmp_str <<
921 "\n\tM " <<
922 pix_to_x_point( d, pEmr->aptl[0].x, pEmr->aptl[0].y ) << " " <<
923 pix_to_y_point( d, pEmr->aptl[0].x, pEmr->aptl[0].y ) << " ";
925 for (i=1; i<pEmr->cptl; i++) {
926 tmp_str <<
927 "\n\tL " <<
928 pix_to_x_point( d, pEmr->aptl[i].x, pEmr->aptl[i].y ) << " " <<
929 pix_to_y_point( d, pEmr->aptl[i].x, pEmr->aptl[i].y ) << " ";
930 }
932 if (d->inpath) {
933 tmp_path << tmp_str.str().c_str();
934 }
935 else {
936 *(d->outsvg) += tmp_str.str().c_str();
937 *(d->outsvg) += " \" /> \n";
938 }
940 break;
941 }
942 case EMR_POLYBEZIERTO:
943 {
944 dbg_str << "<!-- EMR_POLYBEZIERTO -->\n";
946 PEMRPOLYBEZIERTO pEmr = (PEMRPOLYBEZIERTO) lpEMFR;
947 DWORD i,j;
949 if (d->path->empty()) {
950 d->pathless_stroke = true;
951 *(d->path) = "d=\"";
952 }
954 for (i=0; i<pEmr->cptl;) {
955 tmp_path << "\n\tC ";
956 for (j=0; j<3 && i<pEmr->cptl; j++,i++) {
957 tmp_path <<
958 pix_to_x_point( d, pEmr->aptl[i].x, pEmr->aptl[i].y ) << " " <<
959 pix_to_y_point( d, pEmr->aptl[i].x, pEmr->aptl[i].y ) << " ";
960 }
961 }
963 break;
964 }
965 case EMR_POLYLINETO:
966 {
967 dbg_str << "<!-- EMR_POLYLINETO -->\n";
969 PEMRPOLYLINETO pEmr = (PEMRPOLYLINETO) lpEMFR;
970 DWORD i;
972 if (d->path->empty()) {
973 d->pathless_stroke = true;
974 *(d->path) = "d=\"";
975 }
977 for (i=0; i<pEmr->cptl;i++) {
978 tmp_path <<
979 "\n\tL " <<
980 pix_to_x_point( d, pEmr->aptl[i].x, pEmr->aptl[i].y ) << " " <<
981 pix_to_y_point( d, pEmr->aptl[i].x, pEmr->aptl[i].y ) << " ";
982 }
984 break;
985 }
986 case EMR_POLYPOLYLINE:
987 case EMR_POLYPOLYGON:
988 {
989 if (lpEMFR->iType == EMR_POLYPOLYLINE)
990 dbg_str << "<!-- EMR_POLYPOLYLINE -->\n";
991 if (lpEMFR->iType == EMR_POLYPOLYGON)
992 dbg_str << "<!-- EMR_POLYPOLYGON -->\n";
994 PEMRPOLYPOLYGON pEmr = (PEMRPOLYPOLYGON) lpEMFR;
995 unsigned int n, i, j;
997 if (!d->inpath) {
998 assert_empty_path(d, lpEMFR->iType == EMR_POLYPOLYGON ? "EMR_POLYPOLYGON" : "EMR_POLYPOLYLINE");
1000 *(d->outsvg) += " <path ";
1001 output_style(d, lpEMFR->iType==EMR_POLYPOLYGON ? EMR_STROKEANDFILLPATH : EMR_STROKEPATH);
1002 *(d->outsvg) += "\n\td=\"";
1003 }
1005 POINTL *aptl = (POINTL *) &pEmr->aPolyCounts[pEmr->nPolys];
1007 i = 0;
1008 for (n=0; n<pEmr->nPolys && i<pEmr->cptl; n++) {
1009 SVGOStringStream poly_path;
1011 poly_path << "\n\tM " <<
1012 pix_to_x_point( d, aptl[i].x, aptl[i].y ) << " " <<
1013 pix_to_y_point( d, aptl[i].x, aptl[i].y ) << " ";
1014 i++;
1016 for (j=1; j<pEmr->aPolyCounts[n] && i<pEmr->cptl; j++) {
1017 poly_path << "\n\tL " <<
1018 pix_to_x_point( d, aptl[i].x, aptl[i].y ) << " " <<
1019 pix_to_y_point( d, aptl[i].x, aptl[i].y ) << " ";
1020 i++;
1021 }
1023 tmp_str << poly_path.str().c_str();
1024 if (lpEMFR->iType == EMR_POLYPOLYGON)
1025 tmp_str << " z";
1026 tmp_str << " \n";
1027 }
1029 if (d->inpath) {
1030 tmp_path << tmp_str.str().c_str();
1031 }
1032 else {
1033 *(d->outsvg) += tmp_str.str().c_str();
1034 *(d->outsvg) += " \" /> \n";
1035 }
1037 break;
1038 }
1039 case EMR_SETWINDOWEXTEX:
1040 {
1041 dbg_str << "<!-- EMR_SETWINDOWEXTEX -->\n";
1043 PEMRSETWINDOWEXTEX pEmr = (PEMRSETWINDOWEXTEX) lpEMFR;
1045 d->dc[d->level].sizeWnd = pEmr->szlExtent;
1047 if (!d->dc[d->level].sizeWnd.cx || !d->dc[d->level].sizeWnd.cy) {
1048 d->dc[d->level].sizeWnd = d->dc[d->level].sizeView;
1049 if (!d->dc[d->level].sizeWnd.cx || !d->dc[d->level].sizeWnd.cy) {
1050 d->dc[d->level].sizeWnd.cx = d->dc[d->level].PixelsOutX;
1051 d->dc[d->level].sizeWnd.cy = d->dc[d->level].PixelsOutY;
1052 }
1053 }
1055 if (!d->dc[d->level].sizeView.cx || !d->dc[d->level].sizeView.cy) {
1056 d->dc[d->level].sizeView = d->dc[d->level].sizeWnd;
1057 }
1059 d->dc[d->level].PixelsInX = d->dc[d->level].sizeWnd.cx;
1060 d->dc[d->level].PixelsInY = d->dc[d->level].sizeWnd.cy;
1062 if (d->dc[d->level].PixelsInX && d->dc[d->level].PixelsInY) {
1063 d->dc[d->level].ScaleInX = (double) d->dc[d->level].sizeView.cx / (double) d->dc[d->level].PixelsInX;
1064 d->dc[d->level].ScaleInY = (double) d->dc[d->level].sizeView.cy / (double) d->dc[d->level].PixelsInY;
1065 }
1066 else {
1067 d->dc[d->level].ScaleInX = 1;
1068 d->dc[d->level].ScaleInY = 1;
1069 }
1071 if (d->dc[d->level].sizeView.cx && d->dc[d->level].sizeView.cy) {
1072 d->dc[d->level].ScaleOutX = (double) d->dc[d->level].PixelsOutX / (double) d->dc[d->level].sizeView.cx;
1073 d->dc[d->level].ScaleOutY = (double) d->dc[d->level].PixelsOutY / (double) d->dc[d->level].sizeView.cy;
1074 }
1075 else {
1076 d->dc[d->level].ScaleOutX = DEVICESCALE;
1077 d->dc[d->level].ScaleOutY = DEVICESCALE;
1078 }
1080 break;
1081 }
1082 case EMR_SETWINDOWORGEX:
1083 {
1084 dbg_str << "<!-- EMR_SETWINDOWORGEX -->\n";
1086 PEMRSETWINDOWORGEX pEmr = (PEMRSETWINDOWORGEX) lpEMFR;
1087 d->dc[d->level].winorg = pEmr->ptlOrigin;
1088 break;
1089 }
1090 case EMR_SETVIEWPORTEXTEX:
1091 {
1092 dbg_str << "<!-- EMR_SETVIEWPORTEXTEX -->\n";
1094 PEMRSETVIEWPORTEXTEX pEmr = (PEMRSETVIEWPORTEXTEX) lpEMFR;
1096 d->dc[d->level].sizeView = pEmr->szlExtent;
1098 if (!d->dc[d->level].sizeView.cx || !d->dc[d->level].sizeView.cy) {
1099 d->dc[d->level].sizeView = d->dc[d->level].sizeWnd;
1100 if (!d->dc[d->level].sizeView.cx || !d->dc[d->level].sizeView.cy) {
1101 d->dc[d->level].sizeView.cx = d->dc[d->level].PixelsOutX;
1102 d->dc[d->level].sizeView.cy = d->dc[d->level].PixelsOutY;
1103 }
1104 }
1106 if (!d->dc[d->level].sizeWnd.cx || !d->dc[d->level].sizeWnd.cy) {
1107 d->dc[d->level].sizeWnd = d->dc[d->level].sizeView;
1108 }
1110 d->dc[d->level].PixelsInX = d->dc[d->level].sizeWnd.cx;
1111 d->dc[d->level].PixelsInY = d->dc[d->level].sizeWnd.cy;
1113 if (d->dc[d->level].PixelsInX && d->dc[d->level].PixelsInY) {
1114 d->dc[d->level].ScaleInX = (double) d->dc[d->level].sizeView.cx / (double) d->dc[d->level].PixelsInX;
1115 d->dc[d->level].ScaleInY = (double) d->dc[d->level].sizeView.cy / (double) d->dc[d->level].PixelsInY;
1116 }
1117 else {
1118 d->dc[d->level].ScaleInX = 1;
1119 d->dc[d->level].ScaleInY = 1;
1120 }
1122 if (d->dc[d->level].sizeView.cx && d->dc[d->level].sizeView.cy) {
1123 d->dc[d->level].ScaleOutX = (double) d->dc[d->level].PixelsOutX / (double) d->dc[d->level].sizeView.cx;
1124 d->dc[d->level].ScaleOutY = (double) d->dc[d->level].PixelsOutY / (double) d->dc[d->level].sizeView.cy;
1125 }
1126 else {
1127 d->dc[d->level].ScaleOutX = DEVICESCALE;
1128 d->dc[d->level].ScaleOutY = DEVICESCALE;
1129 }
1131 break;
1132 }
1133 case EMR_SETVIEWPORTORGEX:
1134 {
1135 dbg_str << "<!-- EMR_SETVIEWPORTORGEX -->\n";
1137 PEMRSETVIEWPORTORGEX pEmr = (PEMRSETVIEWPORTORGEX) lpEMFR;
1138 d->dc[d->level].vieworg = pEmr->ptlOrigin;
1139 break;
1140 }
1141 case EMR_SETBRUSHORGEX:
1142 dbg_str << "<!-- EMR_SETBRUSHORGEX -->\n";
1143 break;
1144 case EMR_EOF:
1145 {
1146 dbg_str << "<!-- EMR_EOF -->\n";
1148 assert_empty_path(d, "EMR_EOF");
1149 tmp_outsvg << "</g>\n";
1150 tmp_outsvg << "</svg>\n";
1151 break;
1152 }
1153 case EMR_SETPIXELV:
1154 dbg_str << "<!-- EMR_SETPIXELV -->\n";
1155 break;
1156 case EMR_SETMAPPERFLAGS:
1157 dbg_str << "<!-- EMR_SETMAPPERFLAGS -->\n";
1158 break;
1159 case EMR_SETMAPMODE:
1160 dbg_str << "<!-- EMR_SETMAPMODE -->\n";
1161 break;
1162 case EMR_SETBKMODE:
1163 dbg_str << "<!-- EMR_SETBKMODE -->\n";
1164 break;
1165 case EMR_SETPOLYFILLMODE:
1166 {
1167 dbg_str << "<!-- EMR_SETPOLYFILLMODE -->\n";
1169 PEMRSETPOLYFILLMODE pEmr = (PEMRSETPOLYFILLMODE) lpEMFR;
1170 d->dc[d->level].style.fill_rule.value =
1171 (pEmr->iMode == ALTERNATE ? 0 :
1172 pEmr->iMode == WINDING ? 1 : 0);
1173 break;
1174 }
1175 case EMR_SETROP2:
1176 dbg_str << "<!-- EMR_SETROP2 -->\n";
1177 break;
1178 case EMR_SETSTRETCHBLTMODE:
1179 dbg_str << "<!-- EMR_SETSTRETCHBLTMODE -->\n";
1180 break;
1181 case EMR_SETTEXTALIGN:
1182 {
1183 dbg_str << "<!-- EMR_SETTEXTALIGN -->\n";
1185 PEMRSETTEXTALIGN pEmr = (PEMRSETTEXTALIGN) lpEMFR;
1186 d->dc[d->level].textAlign = pEmr->iMode;
1187 break;
1188 }
1189 case EMR_SETCOLORADJUSTMENT:
1190 dbg_str << "<!-- EMR_SETCOLORADJUSTMENT -->\n";
1191 break;
1192 case EMR_SETTEXTCOLOR:
1193 {
1194 dbg_str << "<!-- EMR_SETTEXTCOLOR -->\n";
1196 PEMRSETTEXTCOLOR pEmr = (PEMRSETTEXTCOLOR) lpEMFR;
1197 d->dc[d->level].textColor = pEmr->crColor;
1198 d->dc[d->level].textColorSet = true;
1199 break;
1200 }
1201 case EMR_SETBKCOLOR:
1202 dbg_str << "<!-- EMR_SETBKCOLOR -->\n";
1203 break;
1204 case EMR_OFFSETCLIPRGN:
1205 dbg_str << "<!-- EMR_OFFSETCLIPRGN -->\n";
1206 break;
1207 case EMR_MOVETOEX:
1208 {
1209 dbg_str << "<!-- EMR_MOVETOEX -->\n";
1211 PEMRMOVETOEX pEmr = (PEMRMOVETOEX) lpEMFR;
1213 if (d->path->empty()) {
1214 d->pathless_stroke = true;
1215 *(d->path) = "d=\"";
1216 }
1218 d->dc[d->level].cur = pEmr->ptl;
1220 tmp_path <<
1221 "\n\tM " <<
1222 pix_to_x_point( d, pEmr->ptl.x, pEmr->ptl.y ) << " " <<
1223 pix_to_y_point( d, pEmr->ptl.x, pEmr->ptl.y ) << " ";
1224 break;
1225 }
1226 case EMR_SETMETARGN:
1227 dbg_str << "<!-- EMR_SETMETARGN -->\n";
1228 break;
1229 case EMR_EXCLUDECLIPRECT:
1230 dbg_str << "<!-- EMR_EXCLUDECLIPRECT -->\n";
1231 break;
1232 case EMR_INTERSECTCLIPRECT:
1233 dbg_str << "<!-- EMR_INTERSECTCLIPRECT -->\n";
1234 break;
1235 case EMR_SCALEVIEWPORTEXTEX:
1236 dbg_str << "<!-- EMR_SCALEVIEWPORTEXTEX -->\n";
1237 break;
1238 case EMR_SCALEWINDOWEXTEX:
1239 dbg_str << "<!-- EMR_SCALEWINDOWEXTEX -->\n";
1240 break;
1241 case EMR_SAVEDC:
1242 dbg_str << "<!-- EMR_SAVEDC -->\n";
1244 if (d->level < EMF_MAX_DC) {
1245 d->dc[d->level + 1] = d->dc[d->level];
1246 d->level = d->level + 1;
1247 }
1248 break;
1249 case EMR_RESTOREDC:
1250 {
1251 dbg_str << "<!-- EMR_RESTOREDC -->\n";
1253 PEMRRESTOREDC pEmr = (PEMRRESTOREDC) lpEMFR;
1254 int old_level = d->level;
1255 if (pEmr->iRelative >= 0) {
1256 if (pEmr->iRelative < d->level)
1257 d->level = pEmr->iRelative;
1258 }
1259 else {
1260 if (d->level + pEmr->iRelative >= 0)
1261 d->level = d->level + pEmr->iRelative;
1262 }
1263 while (old_level > d->level) {
1264 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)))
1265 delete[] d->dc[old_level].style.stroke_dash.dash;
1266 old_level--;
1267 }
1268 break;
1269 }
1270 case EMR_SETWORLDTRANSFORM:
1271 {
1272 dbg_str << "<!-- EMR_SETWORLDTRANSFORM -->\n";
1274 PEMRSETWORLDTRANSFORM pEmr = (PEMRSETWORLDTRANSFORM) lpEMFR;
1275 d->dc[d->level].worldTransform = pEmr->xform;
1276 break;
1277 }
1278 case EMR_MODIFYWORLDTRANSFORM:
1279 {
1280 dbg_str << "<!-- EMR_MODIFYWORLDTRANSFORM -->\n";
1282 PEMRMODIFYWORLDTRANSFORM pEmr = (PEMRMODIFYWORLDTRANSFORM) lpEMFR;
1283 switch (pEmr->iMode)
1284 {
1285 case MWT_IDENTITY:
1286 d->dc[d->level].worldTransform.eM11 = 1.0;
1287 d->dc[d->level].worldTransform.eM12 = 0.0;
1288 d->dc[d->level].worldTransform.eM21 = 0.0;
1289 d->dc[d->level].worldTransform.eM22 = 1.0;
1290 d->dc[d->level].worldTransform.eDx = 0.0;
1291 d->dc[d->level].worldTransform.eDy = 0.0;
1292 break;
1293 case MWT_LEFTMULTIPLY:
1294 {
1295 // d->dc[d->level].worldTransform = pEmr->xform * worldTransform;
1297 float a11 = pEmr->xform.eM11;
1298 float a12 = pEmr->xform.eM12;
1299 float a13 = 0.0;
1300 float a21 = pEmr->xform.eM21;
1301 float a22 = pEmr->xform.eM22;
1302 float a23 = 0.0;
1303 float a31 = pEmr->xform.eDx;
1304 float a32 = pEmr->xform.eDy;
1305 float a33 = 1.0;
1307 float b11 = d->dc[d->level].worldTransform.eM11;
1308 float b12 = d->dc[d->level].worldTransform.eM12;
1309 //float b13 = 0.0;
1310 float b21 = d->dc[d->level].worldTransform.eM21;
1311 float b22 = d->dc[d->level].worldTransform.eM22;
1312 //float b23 = 0.0;
1313 float b31 = d->dc[d->level].worldTransform.eDx;
1314 float b32 = d->dc[d->level].worldTransform.eDy;
1315 //float b33 = 1.0;
1317 float c11 = a11*b11 + a12*b21 + a13*b31;;
1318 float c12 = a11*b12 + a12*b22 + a13*b32;;
1319 //float c13 = a11*b13 + a12*b23 + a13*b33;;
1320 float c21 = a21*b11 + a22*b21 + a23*b31;;
1321 float c22 = a21*b12 + a22*b22 + a23*b32;;
1322 //float c23 = a21*b13 + a22*b23 + a23*b33;;
1323 float c31 = a31*b11 + a32*b21 + a33*b31;;
1324 float c32 = a31*b12 + a32*b22 + a33*b32;;
1325 //float c33 = a31*b13 + a32*b23 + a33*b33;;
1327 d->dc[d->level].worldTransform.eM11 = c11;;
1328 d->dc[d->level].worldTransform.eM12 = c12;;
1329 d->dc[d->level].worldTransform.eM21 = c21;;
1330 d->dc[d->level].worldTransform.eM22 = c22;;
1331 d->dc[d->level].worldTransform.eDx = c31;
1332 d->dc[d->level].worldTransform.eDy = c32;
1334 break;
1335 }
1336 case MWT_RIGHTMULTIPLY:
1337 {
1338 // d->dc[d->level].worldTransform = worldTransform * pEmr->xform;
1340 float a11 = d->dc[d->level].worldTransform.eM11;
1341 float a12 = d->dc[d->level].worldTransform.eM12;
1342 float a13 = 0.0;
1343 float a21 = d->dc[d->level].worldTransform.eM21;
1344 float a22 = d->dc[d->level].worldTransform.eM22;
1345 float a23 = 0.0;
1346 float a31 = d->dc[d->level].worldTransform.eDx;
1347 float a32 = d->dc[d->level].worldTransform.eDy;
1348 float a33 = 1.0;
1350 float b11 = pEmr->xform.eM11;
1351 float b12 = pEmr->xform.eM12;
1352 //float b13 = 0.0;
1353 float b21 = pEmr->xform.eM21;
1354 float b22 = pEmr->xform.eM22;
1355 //float b23 = 0.0;
1356 float b31 = pEmr->xform.eDx;
1357 float b32 = pEmr->xform.eDy;
1358 //float b33 = 1.0;
1360 float c11 = a11*b11 + a12*b21 + a13*b31;;
1361 float c12 = a11*b12 + a12*b22 + a13*b32;;
1362 //float c13 = a11*b13 + a12*b23 + a13*b33;;
1363 float c21 = a21*b11 + a22*b21 + a23*b31;;
1364 float c22 = a21*b12 + a22*b22 + a23*b32;;
1365 //float c23 = a21*b13 + a22*b23 + a23*b33;;
1366 float c31 = a31*b11 + a32*b21 + a33*b31;;
1367 float c32 = a31*b12 + a32*b22 + a33*b32;;
1368 //float c33 = a31*b13 + a32*b23 + a33*b33;;
1370 d->dc[d->level].worldTransform.eM11 = c11;;
1371 d->dc[d->level].worldTransform.eM12 = c12;;
1372 d->dc[d->level].worldTransform.eM21 = c21;;
1373 d->dc[d->level].worldTransform.eM22 = c22;;
1374 d->dc[d->level].worldTransform.eDx = c31;
1375 d->dc[d->level].worldTransform.eDy = c32;
1377 break;
1378 }
1379 // case MWT_SET:
1380 default:
1381 d->dc[d->level].worldTransform = pEmr->xform;
1382 break;
1383 }
1384 break;
1385 }
1386 case EMR_SELECTOBJECT:
1387 {
1388 dbg_str << "<!-- EMR_SELECTOBJECT -->\n";
1390 PEMRSELECTOBJECT pEmr = (PEMRSELECTOBJECT) lpEMFR;
1391 unsigned int index = pEmr->ihObject;
1393 if (index >= ENHMETA_STOCK_OBJECT) {
1394 index -= ENHMETA_STOCK_OBJECT;
1395 switch (index) {
1396 case NULL_BRUSH:
1397 d->dc[d->level].fill_set = false;
1398 break;
1399 case BLACK_BRUSH:
1400 case DKGRAY_BRUSH:
1401 case GRAY_BRUSH:
1402 case LTGRAY_BRUSH:
1403 case WHITE_BRUSH:
1404 {
1405 float val = 0;
1406 switch (index) {
1407 case BLACK_BRUSH:
1408 val = 0.0 / 255.0;
1409 break;
1410 case DKGRAY_BRUSH:
1411 val = 64.0 / 255.0;
1412 break;
1413 case GRAY_BRUSH:
1414 val = 128.0 / 255.0;
1415 break;
1416 case LTGRAY_BRUSH:
1417 val = 192.0 / 255.0;
1418 break;
1419 case WHITE_BRUSH:
1420 val = 255.0 / 255.0;
1421 break;
1422 }
1423 d->dc[d->level].style.fill.value.color.set( val, val, val );
1425 d->dc[d->level].fill_set = true;
1426 break;
1427 }
1428 case NULL_PEN:
1429 d->dc[d->level].stroke_set = false;
1430 break;
1431 case BLACK_PEN:
1432 case WHITE_PEN:
1433 {
1434 float val = index == BLACK_PEN ? 0 : 1;
1435 d->dc[d->level].style.stroke_dasharray_set = 0;
1436 d->dc[d->level].style.stroke_width.value = 1.0;
1437 d->dc[d->level].style.stroke.value.color.set( val, val, val );
1439 d->dc[d->level].stroke_set = true;
1441 break;
1442 }
1443 }
1444 } else {
1445 if ( /*index >= 0 &&*/ index < (unsigned int) d->n_obj) {
1446 switch (d->emf_obj[index].type)
1447 {
1448 case EMR_CREATEPEN:
1449 select_pen(d, index);
1450 break;
1451 case EMR_CREATEBRUSHINDIRECT:
1452 select_brush(d, index);
1453 break;
1454 case EMR_EXTCREATEPEN:
1455 select_extpen(d, index);
1456 break;
1457 case EMR_EXTCREATEFONTINDIRECTW:
1458 select_font(d, index);
1459 break;
1460 }
1461 }
1462 }
1463 break;
1464 }
1465 case EMR_CREATEPEN:
1466 {
1467 dbg_str << "<!-- EMR_CREATEPEN -->\n";
1469 PEMRCREATEPEN pEmr = (PEMRCREATEPEN) lpEMFR;
1470 int index = pEmr->ihPen;
1472 EMRCREATEPEN *pPen =
1473 (EMRCREATEPEN *) malloc( sizeof(EMRCREATEPEN) );
1474 pPen->lopn = pEmr->lopn;
1475 insert_object(d, index, EMR_CREATEPEN, (ENHMETARECORD *) pPen);
1477 break;
1478 }
1479 case EMR_CREATEBRUSHINDIRECT:
1480 {
1481 dbg_str << "<!-- EMR_CREATEBRUSHINDIRECT -->\n";
1483 PEMRCREATEBRUSHINDIRECT pEmr = (PEMRCREATEBRUSHINDIRECT) lpEMFR;
1484 int index = pEmr->ihBrush;
1486 EMRCREATEBRUSHINDIRECT *pBrush =
1487 (EMRCREATEBRUSHINDIRECT *) malloc( sizeof(EMRCREATEBRUSHINDIRECT) );
1488 pBrush->lb = pEmr->lb;
1489 insert_object(d, index, EMR_CREATEBRUSHINDIRECT, (ENHMETARECORD *) pBrush);
1491 break;
1492 }
1493 case EMR_DELETEOBJECT:
1494 dbg_str << "<!-- EMR_DELETEOBJECT -->\n";
1495 break;
1496 case EMR_ANGLEARC:
1497 dbg_str << "<!-- EMR_ANGLEARC -->\n";
1498 break;
1499 case EMR_ELLIPSE:
1500 {
1501 dbg_str << "<!-- EMR_ELLIPSE -->\n";
1503 PEMRELLIPSE pEmr = (PEMRELLIPSE) lpEMFR;
1504 RECTL rclBox = pEmr->rclBox;
1506 double l = pix_to_x_point( d, pEmr->rclBox.left, pEmr->rclBox.top );
1507 double t = pix_to_y_point( d, pEmr->rclBox.left, pEmr->rclBox.top );
1508 double r = pix_to_x_point( d, pEmr->rclBox.right, pEmr->rclBox.bottom );
1509 double b = pix_to_y_point( d, pEmr->rclBox.right, pEmr->rclBox.bottom );
1511 double cx = (l + r) / 2.0;
1512 double cy = (t + b) / 2.0;
1513 double rx = fabs(l - r) / 2.0;
1514 double ry = fabs(t - b) / 2.0;
1516 SVGOStringStream tmp_ellipse;
1517 tmp_ellipse << "cx=\"" << cx << "\" ";
1518 tmp_ellipse << "cy=\"" << cy << "\" ";
1519 tmp_ellipse << "rx=\"" << rx << "\" ";
1520 tmp_ellipse << "ry=\"" << ry << "\" ";
1522 assert_empty_path(d, "EMR_ELLIPSE");
1524 *(d->outsvg) += " <ellipse ";
1525 output_style(d, lpEMFR->iType);
1526 *(d->outsvg) += "\n\t";
1527 *(d->outsvg) += tmp_ellipse.str().c_str();
1528 *(d->outsvg) += "/> \n";
1529 *(d->path) = "";
1530 break;
1531 }
1532 case EMR_RECTANGLE:
1533 {
1534 dbg_str << "<!-- EMR_RECTANGLE -->\n";
1536 PEMRRECTANGLE pEmr = (PEMRRECTANGLE) lpEMFR;
1537 RECTL rc = pEmr->rclBox;
1539 double l = pix_to_x_point( d, rc.left, rc.top );
1540 double t = pix_to_y_point( d, rc.left, rc.top );
1541 double r = pix_to_x_point( d, rc.right, rc.bottom );
1542 double b = pix_to_y_point( d, rc.right, rc.bottom );
1544 SVGOStringStream tmp_rectangle;
1545 tmp_rectangle << "d=\"";
1546 tmp_rectangle << "\n\tM " << l << " " << t << " ";
1547 tmp_rectangle << "\n\tL " << r << " " << t << " ";
1548 tmp_rectangle << "\n\tL " << r << " " << b << " ";
1549 tmp_rectangle << "\n\tL " << l << " " << b << " ";
1550 tmp_rectangle << "\n\tz";
1552 assert_empty_path(d, "EMR_RECTANGLE");
1554 *(d->outsvg) += " <path ";
1555 output_style(d, lpEMFR->iType);
1556 *(d->outsvg) += "\n\t";
1557 *(d->outsvg) += tmp_rectangle.str().c_str();
1558 *(d->outsvg) += " \" /> \n";
1559 *(d->path) = "";
1560 break;
1561 }
1562 case EMR_ROUNDRECT:
1563 dbg_str << "<!-- EMR_ROUNDRECT -->\n";
1564 break;
1565 case EMR_ARC:
1566 dbg_str << "<!-- EMR_ARC -->\n";
1567 break;
1568 case EMR_CHORD:
1569 dbg_str << "<!-- EMR_CHORD -->\n";
1570 break;
1571 case EMR_PIE:
1572 dbg_str << "<!-- EMR_PIE -->\n";
1573 break;
1574 case EMR_SELECTPALETTE:
1575 dbg_str << "<!-- EMR_SELECTPALETTE -->\n";
1576 break;
1577 case EMR_CREATEPALETTE:
1578 dbg_str << "<!-- EMR_CREATEPALETTE -->\n";
1579 break;
1580 case EMR_SETPALETTEENTRIES:
1581 dbg_str << "<!-- EMR_SETPALETTEENTRIES -->\n";
1582 break;
1583 case EMR_RESIZEPALETTE:
1584 dbg_str << "<!-- EMR_RESIZEPALETTE -->\n";
1585 break;
1586 case EMR_REALIZEPALETTE:
1587 dbg_str << "<!-- EMR_REALIZEPALETTE -->\n";
1588 break;
1589 case EMR_EXTFLOODFILL:
1590 dbg_str << "<!-- EMR_EXTFLOODFILL -->\n";
1591 break;
1592 case EMR_LINETO:
1593 {
1594 dbg_str << "<!-- EMR_LINETO -->\n";
1596 PEMRLINETO pEmr = (PEMRLINETO) lpEMFR;
1598 if (d->path->empty()) {
1599 d->pathless_stroke = true;
1600 *(d->path) = "d=\"";
1601 }
1603 tmp_path <<
1604 "\n\tL " <<
1605 pix_to_x_point( d, pEmr->ptl.x, pEmr->ptl.y ) << " " <<
1606 pix_to_y_point( d, pEmr->ptl.x, pEmr->ptl.y ) << " ";
1607 break;
1608 }
1609 case EMR_ARCTO:
1610 dbg_str << "<!-- EMR_ARCTO -->\n";
1611 break;
1612 case EMR_POLYDRAW:
1613 dbg_str << "<!-- EMR_POLYDRAW -->\n";
1614 break;
1615 case EMR_SETARCDIRECTION:
1616 dbg_str << "<!-- EMR_SETARCDIRECTION -->\n";
1617 break;
1618 case EMR_SETMITERLIMIT:
1619 {
1620 dbg_str << "<!-- EMR_SETMITERLIMIT -->\n";
1622 PEMRSETMITERLIMIT pEmr = (PEMRSETMITERLIMIT) lpEMFR;
1624 float miterlimit = pEmr->eMiterLimit;
1625 miterlimit = miterlimit * 4.0 / 10.0;
1626 d->dc[d->level].style.stroke_miterlimit.value = pix_to_size_point( d, miterlimit );
1627 if (d->dc[d->level].style.stroke_miterlimit.value < 1)
1628 d->dc[d->level].style.stroke_miterlimit.value = 4.0;
1629 break;
1630 }
1631 case EMR_BEGINPATH:
1632 {
1633 dbg_str << "<!-- EMR_BEGINPATH -->\n";
1635 tmp_path << "d=\"";
1636 *(d->path) = "";
1637 d->inpath = true;
1638 break;
1639 }
1640 case EMR_ENDPATH:
1641 {
1642 dbg_str << "<!-- EMR_ENDPATH -->\n";
1644 tmp_path << "\"";
1645 d->inpath = false;
1646 break;
1647 }
1648 case EMR_CLOSEFIGURE:
1649 {
1650 dbg_str << "<!-- EMR_CLOSEFIGURE -->\n";
1652 tmp_path << "\n\tz";
1653 break;
1654 }
1655 case EMR_FILLPATH:
1656 case EMR_STROKEANDFILLPATH:
1657 case EMR_STROKEPATH:
1658 {
1659 if (lpEMFR->iType == EMR_FILLPATH)
1660 dbg_str << "<!-- EMR_FILLPATH -->\n";
1661 if (lpEMFR->iType == EMR_STROKEANDFILLPATH)
1662 dbg_str << "<!-- EMR_STROKEANDFILLPATH -->\n";
1663 if (lpEMFR->iType == EMR_STROKEPATH)
1664 dbg_str << "<!-- EMR_STROKEPATH -->\n";
1666 *(d->outsvg) += " <path ";
1667 output_style(d, lpEMFR->iType);
1668 *(d->outsvg) += "\n\t";
1669 *(d->outsvg) += *(d->path);
1670 *(d->outsvg) += " /> \n";
1671 *(d->path) = "";
1672 break;
1673 }
1674 case EMR_FLATTENPATH:
1675 dbg_str << "<!-- EMR_FLATTENPATH -->\n";
1676 break;
1677 case EMR_WIDENPATH:
1678 dbg_str << "<!-- EMR_WIDENPATH -->\n";
1679 break;
1680 case EMR_SELECTCLIPPATH:
1681 dbg_str << "<!-- EMR_SELECTCLIPPATH -->\n";
1682 break;
1683 case EMR_ABORTPATH:
1684 dbg_str << "<!-- EMR_ABORTPATH -->\n";
1685 break;
1686 case EMR_GDICOMMENT:
1687 {
1688 dbg_str << "<!-- EMR_GDICOMMENT -->\n";
1690 PEMRGDICOMMENT pEmr = (PEMRGDICOMMENT) lpEMFR;
1692 CHAR *szTxt = (CHAR *) pEmr->Data;
1694 for (DWORD i = 0; i < pEmr->cbData; i++) {
1695 if ( *szTxt) {
1696 if ( *szTxt >= ' ' && *szTxt < 'z' && *szTxt != '<' && *szTxt != '>' ) {
1697 tmp_str << *szTxt;
1698 }
1699 szTxt++;
1700 }
1701 }
1703 if (0 && strlen(tmp_str.str().c_str())) {
1704 tmp_outsvg << " <!-- \"";
1705 tmp_outsvg << tmp_str.str().c_str();
1706 tmp_outsvg << "\" -->\n";
1707 }
1709 break;
1710 }
1711 case EMR_FILLRGN:
1712 dbg_str << "<!-- EMR_FILLRGN -->\n";
1713 break;
1714 case EMR_FRAMERGN:
1715 dbg_str << "<!-- EMR_FRAMERGN -->\n";
1716 break;
1717 case EMR_INVERTRGN:
1718 dbg_str << "<!-- EMR_INVERTRGN -->\n";
1719 break;
1720 case EMR_PAINTRGN:
1721 dbg_str << "<!-- EMR_PAINTRGN -->\n";
1722 break;
1723 case EMR_EXTSELECTCLIPRGN:
1724 dbg_str << "<!-- EMR_EXTSELECTCLIPRGN -->\n";
1725 break;
1726 case EMR_BITBLT:
1727 dbg_str << "<!-- EMR_BITBLT -->\n";
1728 break;
1729 case EMR_STRETCHBLT:
1730 dbg_str << "<!-- EMR_STRETCHBLT -->\n";
1731 break;
1732 case EMR_MASKBLT:
1733 dbg_str << "<!-- EMR_MASKBLT -->\n";
1734 break;
1735 case EMR_PLGBLT:
1736 dbg_str << "<!-- EMR_PLGBLT -->\n";
1737 break;
1738 case EMR_SETDIBITSTODEVICE:
1739 dbg_str << "<!-- EMR_SETDIBITSTODEVICE -->\n";
1740 break;
1741 case EMR_STRETCHDIBITS:
1742 dbg_str << "<!-- EMR_STRETCHDIBITS -->\n";
1743 break;
1744 case EMR_EXTCREATEFONTINDIRECTW:
1745 {
1746 dbg_str << "<!-- EMR_EXTCREATEFONTINDIRECTW -->\n";
1748 PEMREXTCREATEFONTINDIRECTW pEmr = (PEMREXTCREATEFONTINDIRECTW) lpEMFR;
1749 int index = pEmr->ihFont;
1751 EMREXTCREATEFONTINDIRECTW *pFont =
1752 (EMREXTCREATEFONTINDIRECTW *) malloc( sizeof(EMREXTCREATEFONTINDIRECTW) );
1753 pFont->elfw = pEmr->elfw;
1754 insert_object(d, index, EMR_EXTCREATEFONTINDIRECTW, (ENHMETARECORD *) pFont);
1755 break;
1756 }
1757 case EMR_EXTTEXTOUTA:
1758 {
1759 dbg_str << "<!-- EMR_EXTTEXTOUTA -->\n";
1760 break;
1761 }
1762 case EMR_EXTTEXTOUTW:
1763 {
1764 dbg_str << "<!-- EMR_EXTTEXTOUTW -->\n";
1766 PEMREXTTEXTOUTW pEmr = (PEMREXTTEXTOUTW) lpEMFR;
1768 double x1 = pEmr->emrtext.ptlReference.x;
1769 double y1 = pEmr->emrtext.ptlReference.y;
1771 if (d->dc[d->level].textAlign & TA_UPDATECP) {
1772 x1 = d->dc[d->level].cur.x;
1773 y1 = d->dc[d->level].cur.y;
1774 }
1776 if (!(d->dc[d->level].textAlign & TA_BOTTOM))
1777 y1 += fabs(d->dc[d->level].style.font_size.computed);
1779 double x = pix_to_x_point(d, x1, y1);
1780 double y = pix_to_y_point(d, x1, y1);
1782 wchar_t *wide_text = (wchar_t *) ((char *) pEmr + pEmr->emrtext.offString);
1784 gchar *ansi_text =
1785 (gchar *) g_utf16_to_utf8( (gunichar2 *) wide_text, pEmr->emrtext.nChars, NULL, NULL, NULL );
1787 if (ansi_text) {
1788 gchar *p = ansi_text;
1789 while (*p) {
1790 if (*p < 32 || *p >= 127) {
1791 g_free(ansi_text);
1792 ansi_text = g_strdup("");
1793 break;
1794 }
1795 p++;
1796 }
1798 SVGOStringStream ts;
1800 gchar *escaped_text = g_markup_escape_text(ansi_text, -1);
1802 float text_rgb[3];
1803 sp_color_get_rgb_floatv( &(d->dc[d->level].style.fill.value.color), text_rgb );
1805 if (!d->dc[d->level].textColorSet) {
1806 d->dc[d->level].textColor = RGB(SP_COLOR_F_TO_U(text_rgb[0]),
1807 SP_COLOR_F_TO_U(text_rgb[1]),
1808 SP_COLOR_F_TO_U(text_rgb[2]));
1809 }
1811 char tmp[128];
1812 snprintf(tmp, 127,
1813 "fill:#%02x%02x%02x;",
1814 GetRValue(d->dc[d->level].textColor),
1815 GetGValue(d->dc[d->level].textColor),
1816 GetBValue(d->dc[d->level].textColor));
1818 bool i = (d->dc[d->level].style.font_style.value == SP_CSS_FONT_STYLE_ITALIC);
1819 //bool o = (d->dc[d->level].style.font_style.value == SP_CSS_FONT_STYLE_OBLIQUE);
1820 bool b = (d->dc[d->level].style.font_weight.value == SP_CSS_FONT_WEIGHT_BOLD) ||
1821 (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);
1822 int lcr = ((d->dc[d->level].textAlign & TA_CENTER) == TA_CENTER) ? 2 : ((d->dc[d->level].textAlign & TA_RIGHT) == TA_RIGHT) ? 1 : 0;
1824 assert_empty_path(d, "EMR_EXTTEXTOUTW");
1826 ts << " <text\n";
1827 ts << " id=\"" << (d->id++) << "\"\n";
1828 ts << " xml:space=\"preserve\"\n";
1829 ts << " x=\"" << x << "\"\n";
1830 ts << " y=\"" << y << "\"\n";
1831 if (d->dc[d->level].style.text_transform.value) {
1832 ts << " transform=\""
1833 << "rotate(-" << d->dc[d->level].style.text_transform.value
1834 << " " << x << " " << y << ")"
1835 << "\"\n";
1836 }
1837 ts << " style=\""
1838 << "font-size:" << fabs(d->dc[d->level].style.font_size.computed) << "px;"
1839 << tmp
1840 << "font-style:" << (i ? "italic" : "normal") << ";"
1841 << "font-weight:" << (b ? "bold" : "normal") << ";"
1842 << "text-align:" << (lcr==2 ? "center" : lcr==1 ? "end" : "start") << ";"
1843 << "text-anchor:" << (lcr==2 ? "middle" : lcr==1 ? "end" : "start") << ";"
1844 << "font-family:" << d->dc[d->level].tstyle.font_family.value << ";"
1845 << "\"\n";
1846 ts << " >";
1847 ts << escaped_text;
1848 ts << "</text>\n";
1850 *(d->outsvg) += ts.str().c_str();
1852 g_free(escaped_text);
1853 g_free(ansi_text);
1854 }
1856 break;
1857 }
1858 case EMR_POLYBEZIER16:
1859 {
1860 dbg_str << "<!-- EMR_POLYBEZIER16 -->\n";
1862 PEMRPOLYBEZIER16 pEmr = (PEMRPOLYBEZIER16) lpEMFR;
1863 POINTS *apts = (POINTS *) pEmr->apts; // Bug in MinGW wingdi.h ?
1864 DWORD i,j;
1866 if (pEmr->cpts<4)
1867 break;
1869 if (!d->inpath) {
1870 assert_empty_path(d, "EMR_POLYBEZIER16");
1872 *(d->outsvg) += " <path ";
1873 output_style(d, EMR_STROKEPATH);
1874 *(d->outsvg) += "\n\td=\"";
1875 }
1877 tmp_str <<
1878 "\n\tM " <<
1879 pix_to_x_point( d, apts[0].x, apts[0].y ) << " " <<
1880 pix_to_y_point( d, apts[0].x, apts[0].y ) << " ";
1882 for (i=1; i<pEmr->cpts; ) {
1883 tmp_str << "\n\tC ";
1884 for (j=0; j<3 && i<pEmr->cpts; j++,i++) {
1885 tmp_str <<
1886 pix_to_x_point( d, apts[i].x, apts[i].y ) << " " <<
1887 pix_to_y_point( d, apts[i].x, apts[i].y ) << " ";
1888 }
1889 }
1891 if (d->inpath) {
1892 tmp_path << tmp_str.str().c_str();
1893 }
1894 else {
1895 *(d->outsvg) += tmp_str.str().c_str();
1896 *(d->outsvg) += " \" /> \n";
1897 }
1899 break;
1900 }
1901 case EMR_POLYGON16:
1902 {
1903 dbg_str << "<!-- EMR_POLYGON16 -->\n";
1905 PEMRPOLYGON16 pEmr = (PEMRPOLYGON16) lpEMFR;
1906 POINTS *apts = (POINTS *) pEmr->apts; // Bug in MinGW wingdi.h ?
1907 SVGOStringStream tmp_poly;
1908 unsigned int i;
1909 unsigned int first = 0;
1911 assert_empty_path(d, "EMR_POLYGON16");
1913 *(d->outsvg) += " <path ";
1914 output_style(d, EMR_STROKEANDFILLPATH);
1915 *(d->outsvg) += "\n\td=\"";
1917 // skip the first point?
1918 tmp_poly << "\n\tM " <<
1919 pix_to_x_point( d, apts[first].x, apts[first].y ) << " " <<
1920 pix_to_y_point( d, apts[first].x, apts[first].y ) << " ";
1922 for (i=first+1; i<pEmr->cpts; i++) {
1923 tmp_poly << "\n\tL " <<
1924 pix_to_x_point( d, apts[i].x, apts[i].y ) << " " <<
1925 pix_to_y_point( d, apts[i].x, apts[i].y ) << " ";
1926 }
1928 *(d->outsvg) += tmp_poly.str().c_str();
1929 *(d->outsvg) += " z \" /> \n";
1931 break;
1932 }
1933 case EMR_POLYLINE16:
1934 {
1935 dbg_str << "<!-- EMR_POLYLINE16 -->\n";
1937 EMRPOLYLINE16 *pEmr = (EMRPOLYLINE16 *) lpEMFR;
1938 POINTS *apts = (POINTS *) pEmr->apts; // Bug in MinGW wingdi.h ?
1939 DWORD i;
1941 if (pEmr->cpts<2)
1942 break;
1944 if (!d->inpath) {
1945 assert_empty_path(d, "EMR_POLYLINE16");
1947 *(d->outsvg) += " <path ";
1948 output_style(d, EMR_STROKEPATH);
1949 *(d->outsvg) += "\n\td=\"";
1950 }
1952 tmp_str <<
1953 "\n\tM " <<
1954 pix_to_x_point( d, apts[0].x, apts[0].y ) << " " <<
1955 pix_to_y_point( d, apts[0].x, apts[0].y ) << " ";
1957 for (i=1; i<pEmr->cpts; i++) {
1958 tmp_str <<
1959 "\n\tL " <<
1960 pix_to_x_point( d, apts[i].x, apts[i].y ) << " " <<
1961 pix_to_y_point( d, apts[i].x, apts[i].y ) << " ";
1962 }
1964 if (d->inpath) {
1965 tmp_path << tmp_str.str().c_str();
1966 }
1967 else {
1968 *(d->outsvg) += tmp_str.str().c_str();
1969 *(d->outsvg) += " \" /> \n";
1970 }
1972 break;
1973 }
1974 case EMR_POLYBEZIERTO16:
1975 {
1976 dbg_str << "<!-- EMR_POLYBEZIERTO16 -->\n";
1978 PEMRPOLYBEZIERTO16 pEmr = (PEMRPOLYBEZIERTO16) lpEMFR;
1979 POINTS *apts = (POINTS *) pEmr->apts; // Bug in MinGW wingdi.h ?
1980 DWORD i,j;
1982 if (d->path->empty()) {
1983 d->pathless_stroke = true;
1984 *(d->path) = "d=\"";
1985 }
1987 for (i=0; i<pEmr->cpts;) {
1988 tmp_path << "\n\tC ";
1989 for (j=0; j<3 && i<pEmr->cpts; j++,i++) {
1990 tmp_path <<
1991 pix_to_x_point( d, apts[i].x, apts[i].y ) << " " <<
1992 pix_to_y_point( d, apts[i].x, apts[i].y ) << " ";
1993 }
1994 }
1996 break;
1997 }
1998 case EMR_POLYLINETO16:
1999 {
2000 dbg_str << "<!-- EMR_POLYLINETO16 -->\n";
2002 PEMRPOLYLINETO16 pEmr = (PEMRPOLYLINETO16) lpEMFR;
2003 POINTS *apts = (POINTS *) pEmr->apts; // Bug in MinGW wingdi.h ?
2004 DWORD i;
2006 if (d->path->empty()) {
2007 d->pathless_stroke = true;
2008 *(d->path) = "d=\"";
2009 }
2011 for (i=0; i<pEmr->cpts;i++) {
2012 tmp_path <<
2013 "\n\tL " <<
2014 pix_to_x_point( d, apts[i].x, apts[i].y ) << " " <<
2015 pix_to_y_point( d, apts[i].x, apts[i].y ) << " ";
2016 }
2018 break;
2019 }
2020 case EMR_POLYPOLYLINE16:
2021 case EMR_POLYPOLYGON16:
2022 {
2023 if (lpEMFR->iType == EMR_POLYPOLYLINE16)
2024 dbg_str << "<!-- EMR_POLYPOLYLINE16 -->\n";
2025 if (lpEMFR->iType == EMR_POLYPOLYGON16)
2026 dbg_str << "<!-- EMR_POLYPOLYGON16 -->\n";
2028 PEMRPOLYPOLYGON16 pEmr = (PEMRPOLYPOLYGON16) lpEMFR;
2029 unsigned int n, i, j;
2031 if (!d->inpath) {
2032 assert_empty_path(d, lpEMFR->iType == EMR_POLYPOLYGON16 ? "EMR_POLYPOLYGON16" : "EMR_POLYPOLYLINE16");
2034 *(d->outsvg) += " <path ";
2035 output_style(d, lpEMFR->iType==EMR_POLYPOLYGON16 ? EMR_STROKEANDFILLPATH : EMR_STROKEPATH);
2036 *(d->outsvg) += "\n\td=\"";
2037 }
2039 POINTS *apts = (POINTS *) &pEmr->aPolyCounts[pEmr->nPolys];
2041 i = 0;
2042 for (n=0; n<pEmr->nPolys && i<pEmr->cpts; n++) {
2043 SVGOStringStream poly_path;
2045 poly_path << "\n\tM " <<
2046 pix_to_x_point( d, apts[i].x, apts[i].y ) << " " <<
2047 pix_to_y_point( d, apts[i].x, apts[i].y ) << " ";
2048 i++;
2050 for (j=1; j<pEmr->aPolyCounts[n] && i<pEmr->cpts; j++) {
2051 poly_path << "\n\tL " <<
2052 pix_to_x_point( d, apts[i].x, apts[i].y ) << " " <<
2053 pix_to_y_point( d, apts[i].x, apts[i].y ) << " ";
2054 i++;
2055 }
2057 tmp_str << poly_path.str().c_str();
2058 if (lpEMFR->iType == EMR_POLYPOLYGON16)
2059 tmp_str << " z";
2060 tmp_str << " \n";
2061 }
2063 if (d->inpath) {
2064 tmp_path << tmp_str.str().c_str();
2065 }
2066 else {
2067 *(d->outsvg) += tmp_str.str().c_str();
2068 *(d->outsvg) += " \" /> \n";
2069 }
2071 break;
2072 }
2073 case EMR_POLYDRAW16:
2074 dbg_str << "<!-- EMR_POLYDRAW16 -->\n";
2075 break;
2076 case EMR_CREATEMONOBRUSH:
2077 dbg_str << "<!-- EMR_CREATEMONOBRUSH -->\n";
2078 break;
2079 case EMR_CREATEDIBPATTERNBRUSHPT:
2080 dbg_str << "<!-- EMR_CREATEDIBPATTERNBRUSHPT -->\n";
2081 break;
2082 case EMR_EXTCREATEPEN:
2083 {
2084 dbg_str << "<!-- EMR_EXTCREATEPEN -->\n";
2086 PEMREXTCREATEPEN pEmr = (PEMREXTCREATEPEN) lpEMFR;
2087 int index = pEmr->ihPen;
2089 EMREXTCREATEPEN *pPen =
2090 (EMREXTCREATEPEN *) malloc( sizeof(EMREXTCREATEPEN) +
2091 sizeof(DWORD) * pEmr->elp.elpNumEntries );
2092 pPen->ihPen = pEmr->ihPen;
2093 pPen->offBmi = pEmr->offBmi;
2094 pPen->cbBmi = pEmr->cbBmi;
2095 pPen->offBits = pEmr->offBits;
2096 pPen->cbBits = pEmr->cbBits;
2097 pPen->elp = pEmr->elp;
2098 for (unsigned int i=0; i<pEmr->elp.elpNumEntries; i++) {
2099 pPen->elp.elpStyleEntry[i] = pEmr->elp.elpStyleEntry[i];
2100 }
2101 insert_object(d, index, EMR_EXTCREATEPEN, (ENHMETARECORD *) pPen);
2103 break;
2104 }
2105 case EMR_POLYTEXTOUTA:
2106 dbg_str << "<!-- EMR_POLYTEXTOUTA -->\n";
2107 break;
2108 case EMR_POLYTEXTOUTW:
2109 dbg_str << "<!-- EMR_POLYTEXTOUTW -->\n";
2110 break;
2111 case EMR_SETICMMODE:
2112 dbg_str << "<!-- EMR_SETICMMODE -->\n";
2113 break;
2114 case EMR_CREATECOLORSPACE:
2115 dbg_str << "<!-- EMR_CREATECOLORSPACE -->\n";
2116 break;
2117 case EMR_SETCOLORSPACE:
2118 dbg_str << "<!-- EMR_SETCOLORSPACE -->\n";
2119 break;
2120 case EMR_DELETECOLORSPACE:
2121 dbg_str << "<!-- EMR_DELETECOLORSPACE -->\n";
2122 break;
2123 case EMR_GLSRECORD:
2124 dbg_str << "<!-- EMR_GLSRECORD -->\n";
2125 break;
2126 case EMR_GLSBOUNDEDRECORD:
2127 dbg_str << "<!-- EMR_GLSBOUNDEDRECORD -->\n";
2128 break;
2129 case EMR_PIXELFORMAT:
2130 dbg_str << "<!-- EMR_PIXELFORMAT -->\n";
2131 break;
2132 default:
2133 dbg_str << "<!-- EMR_??? -->\n";
2134 break;
2135 }
2137 // *(d->outsvg) += dbg_str.str().c_str();
2138 *(d->outsvg) += tmp_outsvg.str().c_str();
2139 *(d->path) += tmp_path.str().c_str();
2141 return 1;
2142 }
2144 static int CALLBACK
2145 myMetaFileProc(HDC /*hDC*/, HANDLETABLE * /*lpHTable*/, METARECORD * /*lpMFR*/, int /*nObj*/, LPARAM /*lpData*/)
2146 {
2147 g_warning("Unable to import Windows Meta File.\n");
2148 return 0;
2149 }
2151 // Aldus Placeable Header ===================================================
2152 // Since we are a 32bit app, we have to be sure this structure compiles to
2153 // be identical to a 16 bit app's version. To do this, we use the #pragma
2154 // to adjust packing, we use a WORD for the hmf handle, and a SMALL_RECT
2155 // for the bbox rectangle.
2156 #pragma pack( push )
2157 #pragma pack( 2 )
2158 typedef struct
2159 {
2160 DWORD dwKey;
2161 WORD hmf;
2162 SMALL_RECT bbox;
2163 WORD wInch;
2164 DWORD dwReserved;
2165 WORD wCheckSum;
2166 } APMHEADER, *PAPMHEADER;
2167 #pragma pack( pop )
2170 SPDocument *
2171 EmfWin32::open( Inkscape::Extension::Input * /*mod*/, const gchar *uri )
2172 {
2173 EMF_CALLBACK_DATA d;
2175 memset(&d, 0, sizeof(d));
2177 d.dc[0].worldTransform.eM11 = 1.0;
2178 d.dc[0].worldTransform.eM12 = 0.0;
2179 d.dc[0].worldTransform.eM21 = 0.0;
2180 d.dc[0].worldTransform.eM22 = 1.0;
2181 d.dc[0].worldTransform.eDx = 0.0;
2182 d.dc[0].worldTransform.eDy = 0.0;
2184 gsize bytesRead = 0;
2185 gsize bytesWritten = 0;
2186 GError* error = NULL;
2187 gchar *local_fn =
2188 g_filename_from_utf8( uri, -1, &bytesRead, &bytesWritten, &error );
2190 if (local_fn == NULL) {
2191 return NULL;
2192 }
2194 d.outsvg = new Glib::ustring("");
2195 d.path = new Glib::ustring("");
2197 CHAR *ansi_uri = (CHAR *) local_fn;
2198 gunichar2 *unicode_fn = g_utf8_to_utf16( local_fn, -1, NULL, NULL, NULL );
2199 WCHAR *unicode_uri = (WCHAR *) unicode_fn;
2201 DWORD filesize = 0;
2202 HANDLE fp = NULL;
2204 HMETAFILE hmf;
2205 HENHMETAFILE hemf;
2207 if (PrintWin32::is_os_wide()) {
2208 fp = CreateFileW(unicode_uri, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
2209 }
2210 else {
2211 fp = CreateFileA(ansi_uri, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
2212 }
2214 if ( fp != INVALID_HANDLE_VALUE ) {
2215 filesize = GetFileSize(fp, NULL);
2216 CloseHandle(fp);
2217 }
2219 // Try open as Enhanced Metafile
2220 if (PrintWin32::is_os_wide())
2221 hemf = GetEnhMetaFileW(unicode_uri);
2222 else
2223 hemf = GetEnhMetaFileA(ansi_uri);
2225 if (!hemf) {
2226 // Try open as Windows Metafile
2227 if (PrintWin32::is_os_wide())
2228 hmf = GetMetaFileW(unicode_uri);
2229 else
2230 hmf = GetMetaFileA(ansi_uri);
2232 METAFILEPICT mp;
2233 HDC hDC;
2235 if (!hmf) {
2236 if (PrintWin32::is_os_wide()) {
2237 WCHAR szTemp[MAX_PATH];
2239 DWORD dw = GetShortPathNameW( unicode_uri, szTemp, MAX_PATH );
2240 if (dw) {
2241 hmf = GetMetaFileW( szTemp );
2242 }
2243 } else {
2244 CHAR szTemp[MAX_PATH];
2246 DWORD dw = GetShortPathNameA( ansi_uri, szTemp, MAX_PATH );
2247 if (dw) {
2248 hmf = GetMetaFileA( szTemp );
2249 }
2250 }
2251 }
2253 if (hmf) {
2254 DWORD nSize = GetMetaFileBitsEx( hmf, 0, NULL );
2256 if (!nSize)
2257 nSize = filesize;
2259 if (nSize) {
2260 BYTE *lpvData = new BYTE[nSize];
2261 if (lpvData) {
2262 DWORD dw = GetMetaFileBitsEx( hmf, nSize, lpvData );
2263 if (dw) {
2264 // Fill out a METAFILEPICT structure
2265 mp.mm = MM_ANISOTROPIC;
2266 mp.xExt = 1000;
2267 mp.yExt = 1000;
2268 mp.hMF = NULL;
2269 // Get a reference DC
2270 hDC = GetDC( NULL );
2271 // Make an enhanced metafile from the windows metafile
2272 hemf = SetWinMetaFileBits( nSize, lpvData, hDC, &mp );
2273 // Clean up
2274 ReleaseDC( NULL, hDC );
2275 DeleteMetaFile( hmf );
2276 hmf = NULL;
2277 }
2278 else {
2279 // EnumMetaFile
2280 }
2281 delete[] lpvData;
2282 }
2283 else {
2284 DeleteMetaFile( hmf );
2285 hmf = NULL;
2286 }
2287 }
2288 else {
2289 DeleteMetaFile( hmf );
2290 hmf = NULL;
2291 }
2292 }
2293 else {
2294 // Try open as Aldus Placeable Metafile
2295 HANDLE hFile;
2296 if (PrintWin32::is_os_wide())
2297 hFile = CreateFileW( unicode_uri, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL );
2298 else
2299 hFile = CreateFileA( ansi_uri, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL );
2301 if (hFile != INVALID_HANDLE_VALUE) {
2302 DWORD nSize = GetFileSize( hFile, NULL );
2303 if (nSize) {
2304 BYTE *lpvData = new BYTE[nSize];
2305 if (lpvData) {
2306 DWORD dw = ReadFile( hFile, lpvData, nSize, &nSize, NULL );
2307 if (dw) {
2308 if ( ((PAPMHEADER)lpvData)->dwKey == 0x9ac6cdd7l ) {
2309 // Fill out a METAFILEPICT structure
2310 mp.mm = MM_ANISOTROPIC;
2311 mp.xExt = ((PAPMHEADER)lpvData)->bbox.Right - ((PAPMHEADER)lpvData)->bbox.Left;
2312 mp.xExt = ( mp.xExt * 2540l ) / (DWORD)(((PAPMHEADER)lpvData)->wInch);
2313 mp.yExt = ((PAPMHEADER)lpvData)->bbox.Bottom - ((PAPMHEADER)lpvData)->bbox.Top;
2314 mp.yExt = ( mp.yExt * 2540l ) / (DWORD)(((PAPMHEADER)lpvData)->wInch);
2315 mp.hMF = NULL;
2316 // Get a reference DC
2317 hDC = GetDC( NULL );
2318 // Create an enhanced metafile from the bits
2319 hemf = SetWinMetaFileBits( nSize, lpvData+sizeof(APMHEADER), hDC, &mp );
2320 // Clean up
2321 ReleaseDC( NULL, hDC );
2322 }
2323 }
2324 delete[] lpvData;
2325 }
2326 }
2327 CloseHandle( hFile );
2328 }
2329 }
2330 }
2332 if ((!hemf && !hmf) || !d.outsvg || !d.path) {
2333 if (d.outsvg)
2334 delete d.outsvg;
2335 if (d.path)
2336 delete d.path;
2337 if (local_fn)
2338 g_free(local_fn);
2339 if (unicode_fn)
2340 g_free(unicode_fn);
2341 if (hemf)
2342 DeleteEnhMetaFile(hemf);
2343 if (hmf)
2344 DeleteMetaFile(hmf);
2345 return NULL;
2346 }
2348 d.pDesc = NULL;
2350 if (hemf) {
2351 DWORD dwNeeded = GetEnhMetaFileDescriptionA( hemf, 0, NULL );
2352 if ( dwNeeded > 0 ) {
2353 d.pDesc = (CHAR *) malloc( dwNeeded + 1 );
2354 if ( GetEnhMetaFileDescription( hemf, dwNeeded, d.pDesc ) == 0 )
2355 lstrcpy( d.pDesc, "" );
2356 if ( lstrlen( d.pDesc ) > 1 )
2357 d.pDesc[lstrlen(d.pDesc)] = '#';
2358 }
2360 EnumEnhMetaFile(NULL, hemf, myEnhMetaFileProc, (LPVOID) &d, NULL);
2361 DeleteEnhMetaFile(hemf);
2362 }
2363 else {
2364 EnumMetaFile(NULL, hmf, myMetaFileProc, (LPARAM) &d);
2365 DeleteMetaFile(hmf);
2366 }
2368 if (d.pDesc)
2369 free( d.pDesc );
2371 // std::cout << "SVG Output: " << std::endl << *(d.outsvg) << std::endl;
2373 SPDocument *doc = sp_document_new_from_mem(d.outsvg->c_str(), d.outsvg->length(), TRUE);
2375 delete d.outsvg;
2376 delete d.path;
2378 if (d.emf_obj) {
2379 int i;
2380 for (i=0; i<d.n_obj; i++)
2381 delete_object(&d, i);
2382 delete[] d.emf_obj;
2383 }
2385 if (d.dc[0].style.stroke_dash.dash)
2386 delete[] d.dc[0].style.stroke_dash.dash;
2388 if (local_fn)
2389 g_free(local_fn);
2390 if (unicode_fn)
2391 g_free(unicode_fn);
2393 return doc;
2394 }
2397 void
2398 EmfWin32::init (void)
2399 {
2400 Inkscape::Extension::Extension * ext;
2402 /* EMF in */
2403 ext = Inkscape::Extension::build_from_mem(
2404 "<inkscape-extension xmlns=\"" INKSCAPE_EXTENSION_URI "\">\n"
2405 "<name>" N_("EMF Input") "</name>\n"
2406 "<id>org.inkscape.input.emf.win32</id>\n"
2407 "<input>\n"
2408 "<extension>.emf</extension>\n"
2409 "<mimetype>image/x-emf</mimetype>\n"
2410 "<filetypename>" N_("Enhanced Metafiles (*.emf)") "</filetypename>\n"
2411 "<filetypetooltip>" N_("Enhanced Metafiles") "</filetypetooltip>\n"
2412 "<output_extension>org.inkscape.output.emf.win32</output_extension>\n"
2413 "</input>\n"
2414 "</inkscape-extension>", new EmfWin32());
2416 /* WMF in */
2417 ext = Inkscape::Extension::build_from_mem(
2418 "<inkscape-extension xmlns=\"" INKSCAPE_EXTENSION_URI "\">\n"
2419 "<name>" N_("WMF Input") "</name>\n"
2420 "<id>org.inkscape.input.wmf.win32</id>\n"
2421 "<input>\n"
2422 "<extension>.wmf</extension>\n"
2423 "<mimetype>image/x-wmf</mimetype>\n"
2424 "<filetypename>" N_("Windows Metafiles (*.wmf)") "</filetypename>\n"
2425 "<filetypetooltip>" N_("Windows Metafiles") "</filetypetooltip>\n"
2426 "<output_extension>org.inkscape.output.emf.win32</output_extension>\n"
2427 "</input>\n"
2428 "</inkscape-extension>", new EmfWin32());
2430 /* EMF out */
2431 ext = Inkscape::Extension::build_from_mem(
2432 "<inkscape-extension xmlns=\"" INKSCAPE_EXTENSION_URI "\">\n"
2433 "<name>" N_("EMF Output") "</name>\n"
2434 "<id>org.inkscape.output.emf.win32</id>\n"
2435 "<param name=\"textToPath\" gui-text=\"" N_("Convert texts to paths") "\" type=\"boolean\">true</param>\n"
2436 "<output>\n"
2437 "<extension>.emf</extension>\n"
2438 "<mimetype>image/x-emf</mimetype>\n"
2439 "<filetypename>" N_("Enhanced Metafile (*.emf)") "</filetypename>\n"
2440 "<filetypetooltip>" N_("Enhanced Metafile") "</filetypetooltip>\n"
2441 "</output>\n"
2442 "</inkscape-extension>", new EmfWin32());
2444 return;
2445 }
2448 } } } /* namespace Inkscape, Extension, Implementation */
2451 #endif /* WIN32 */
2454 /*
2455 Local Variables:
2456 mode:cpp
2457 c-file-style:"stroustrup"
2458 c-file-offsets:((innamespace . 0)(inline-open . 0))
2459 indent-tabs-mode:nil
2460 fill-column:99
2461 End:
2462 */
2463 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4 :