1 /** @file
2 * @brief Windows-only Enhanced Metafile input and output.
3 */
4 /* Authors:
5 * Ulf Erikson <ulferikson@users.sf.net>
6 * Jon A. Cruz <jon@joncruz.org>
7 * Abhishek Sharma
8 *
9 * Copyright (C) 2006-2008 Authors
10 *
11 * Released under GNU GPL, read the file 'COPYING' for more information
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 {
83 static float device_scale = DEVICESCALE;
85 EmfWin32::EmfWin32 (void) // The null constructor
86 {
87 return;
88 }
91 EmfWin32::~EmfWin32 (void) //The destructor
92 {
93 return;
94 }
97 bool
98 EmfWin32::check (Inkscape::Extension::Extension * /*module*/)
99 {
100 if (NULL == Inkscape::Extension::db.get(PRINT_EMF_WIN32))
101 return FALSE;
102 return TRUE;
103 }
106 static void
107 emf_print_document_to_file(SPDocument *doc, gchar const *filename)
108 {
109 Inkscape::Extension::Print *mod;
110 SPPrintContext context;
111 gchar const *oldconst;
112 gchar *oldoutput;
113 unsigned int ret;
115 doc->ensureUpToDate();
117 mod = Inkscape::Extension::get_print(PRINT_EMF_WIN32);
118 oldconst = mod->get_param_string("destination");
119 oldoutput = g_strdup(oldconst);
120 mod->set_param_string("destination", filename);
122 /* Start */
123 context.module = mod;
124 /* fixme: This has to go into module constructor somehow */
125 /* Create new arena */
126 mod->base = SP_ITEM(doc->getRoot());
127 mod->arena = NRArena::create();
128 mod->dkey = SPItem::display_key_new(1);
129 mod->root = mod->base->invoke_show(mod->arena, mod->dkey, SP_ITEM_SHOW_DISPLAY);
130 /* Print document */
131 ret = mod->begin(doc);
132 if (ret) {
133 g_free(oldoutput);
134 throw Inkscape::Extension::Output::save_failed();
135 }
136 mod->base->invoke_print(&context);
137 ret = mod->finish();
138 /* Release arena */
139 mod->base->invoke_hide(mod->dkey);
140 mod->base = NULL;
141 mod->root = NULL;
142 nr_object_unref((NRObject *) mod->arena);
143 mod->arena = NULL;
144 /* end */
146 mod->set_param_string("destination", oldoutput);
147 g_free(oldoutput);
149 return;
150 }
153 void
154 EmfWin32::save(Inkscape::Extension::Output *mod, SPDocument *doc, gchar const *filename)
155 {
156 Inkscape::Extension::Extension * ext;
158 ext = Inkscape::Extension::db.get(PRINT_EMF_WIN32);
159 if (ext == NULL)
160 return;
162 bool old_textToPath = ext->get_param_bool("textToPath");
163 bool new_val = mod->get_param_bool("textToPath");
164 ext->set_param_bool("textToPath", new_val);
166 emf_print_document_to_file(doc, filename);
168 ext->set_param_bool("textToPath", old_textToPath);
170 return;
171 }
175 typedef struct {
176 int type;
177 int level;
178 ENHMETARECORD *lpEMFR;
179 } EMF_OBJECT, *PEMF_OBJECT;
181 typedef struct emf_device_context {
182 struct SPStyle style;
183 class SPTextStyle tstyle;
184 bool stroke_set;
185 bool fill_set;
187 SIZEL sizeWnd;
188 SIZEL sizeView;
189 float PixelsInX, PixelsInY;
190 float PixelsOutX, PixelsOutY;
191 POINTL winorg;
192 POINTL vieworg;
193 double ScaleInX, ScaleInY;
194 double ScaleOutX, ScaleOutY;
195 COLORREF textColor;
196 bool textColorSet;
197 DWORD textAlign;
198 XFORM worldTransform;
199 POINTL cur;
200 } EMF_DEVICE_CONTEXT, *PEMF_DEVICE_CONTEXT;
202 #define EMF_MAX_DC 128
204 typedef struct emf_callback_data {
205 Glib::ustring *outsvg;
206 Glib::ustring *path;
208 EMF_DEVICE_CONTEXT dc[EMF_MAX_DC+1]; // FIXME: This should be dynamic..
209 int level;
211 double xDPI, yDPI;
212 bool pathless_stroke;
213 bool inpath;
215 float MMX;
216 float MMY;
217 float dwInchesX;
218 float dwInchesY;
220 unsigned int id;
221 CHAR *pDesc;
223 int n_obj;
224 PEMF_OBJECT emf_obj;
225 } EMF_CALLBACK_DATA, *PEMF_CALLBACK_DATA;
228 static void
229 output_style(PEMF_CALLBACK_DATA d, int iType)
230 {
231 SVGOStringStream tmp_id;
232 SVGOStringStream tmp_style;
233 char tmp[1024] = {0};
235 float fill_rgb[3];
236 sp_color_get_rgb_floatv( &(d->dc[d->level].style.fill.value.color), fill_rgb );
238 float stroke_rgb[3];
239 sp_color_get_rgb_floatv(&(d->dc[d->level].style.stroke.value.color), stroke_rgb);
241 tmp_id << "\n\tid=\"" << (d->id++) << "\"";
242 *(d->outsvg) += tmp_id.str().c_str();
243 *(d->outsvg) += "\n\tstyle=\"";
244 if (iType == EMR_STROKEPATH || !d->dc[d->level].fill_set) {
245 tmp_style << "fill:none;";
246 } else {
247 snprintf(tmp, 1023,
248 "fill:#%02x%02x%02x;",
249 SP_COLOR_F_TO_U(fill_rgb[0]),
250 SP_COLOR_F_TO_U(fill_rgb[1]),
251 SP_COLOR_F_TO_U(fill_rgb[2]));
252 tmp_style << tmp;
253 snprintf(tmp, 1023,
254 "fill-rule:%s;",
255 d->dc[d->level].style.fill_rule.value == 0 ? "evenodd" : "nonzero");
256 tmp_style << tmp;
257 tmp_style << "fill-opacity:1;";
259 if (d->dc[d->level].fill_set && d->dc[d->level].stroke_set && d->dc[d->level].style.stroke_width.value == 1 &&
260 fill_rgb[0]==stroke_rgb[0] && fill_rgb[1]==stroke_rgb[1] && fill_rgb[2]==stroke_rgb[2])
261 {
262 d->dc[d->level].stroke_set = false;
263 }
264 }
266 if (iType == EMR_FILLPATH || !d->dc[d->level].stroke_set) {
267 tmp_style << "stroke:none;";
268 } else {
269 snprintf(tmp, 1023,
270 "stroke:#%02x%02x%02x;",
271 SP_COLOR_F_TO_U(stroke_rgb[0]),
272 SP_COLOR_F_TO_U(stroke_rgb[1]),
273 SP_COLOR_F_TO_U(stroke_rgb[2]));
274 tmp_style << tmp;
276 tmp_style << "stroke-width:" <<
277 MAX( 0.001, d->dc[d->level].style.stroke_width.value ) << "px;";
279 tmp_style << "stroke-linecap:" <<
280 (d->dc[d->level].style.stroke_linecap.computed == 0 ? "butt" :
281 d->dc[d->level].style.stroke_linecap.computed == 1 ? "round" :
282 d->dc[d->level].style.stroke_linecap.computed == 2 ? "square" :
283 "unknown") << ";";
285 tmp_style << "stroke-linejoin:" <<
286 (d->dc[d->level].style.stroke_linejoin.computed == 0 ? "miter" :
287 d->dc[d->level].style.stroke_linejoin.computed == 1 ? "round" :
288 d->dc[d->level].style.stroke_linejoin.computed == 2 ? "bevel" :
289 "unknown") << ";";
291 if (d->dc[d->level].style.stroke_linejoin.computed == 0) {
292 tmp_style << "stroke-miterlimit:" <<
293 MAX( 0.01, d->dc[d->level].style.stroke_miterlimit.value ) << ";";
294 }
296 if (d->dc[d->level].style.stroke_dasharray_set &&
297 d->dc[d->level].style.stroke_dash.n_dash && d->dc[d->level].style.stroke_dash.dash)
298 {
299 tmp_style << "stroke-dasharray:";
300 for (int i=0; i<d->dc[d->level].style.stroke_dash.n_dash; i++) {
301 if (i)
302 tmp_style << ",";
303 tmp_style << d->dc[d->level].style.stroke_dash.dash[i];
304 }
305 tmp_style << ";";
306 tmp_style << "stroke-dashoffset:0;";
307 } else {
308 tmp_style << "stroke-dasharray:none;";
309 }
310 tmp_style << "stroke-opacity:1;";
311 }
312 tmp_style << "\" ";
314 *(d->outsvg) += tmp_style.str().c_str();
315 }
318 static double
319 _pix_x_to_point(PEMF_CALLBACK_DATA d, double px)
320 {
321 double tmp = px - d->dc[d->level].winorg.x;
322 tmp *= d->dc[d->level].ScaleInX ? d->dc[d->level].ScaleInX : 1.0;
323 tmp += d->dc[d->level].vieworg.x;
324 return tmp;
325 }
327 static double
328 _pix_y_to_point(PEMF_CALLBACK_DATA d, double px)
329 {
330 double tmp = px - d->dc[d->level].winorg.y;
331 tmp *= d->dc[d->level].ScaleInY ? d->dc[d->level].ScaleInY : 1.0;
332 tmp += d->dc[d->level].vieworg.y;
333 return tmp;
334 }
337 static double
338 pix_to_x_point(PEMF_CALLBACK_DATA d, double px, double py)
339 {
340 double ppx = _pix_x_to_point(d, px);
341 double ppy = _pix_y_to_point(d, py);
343 double x = ppx * d->dc[d->level].worldTransform.eM11 + ppy * d->dc[d->level].worldTransform.eM21 + d->dc[d->level].worldTransform.eDx;
344 x *= d->dc[d->level].ScaleOutX ? d->dc[d->level].ScaleOutX : device_scale;
346 return x;
347 }
349 static double
350 pix_to_y_point(PEMF_CALLBACK_DATA d, double px, double py)
351 {
352 double ppx = _pix_x_to_point(d, px);
353 double ppy = _pix_y_to_point(d, py);
355 double y = ppx * d->dc[d->level].worldTransform.eM12 + ppy * d->dc[d->level].worldTransform.eM22 + d->dc[d->level].worldTransform.eDy;
356 y *= d->dc[d->level].ScaleOutY ? d->dc[d->level].ScaleOutY : device_scale;
358 return y;
359 }
361 static double
362 pix_to_size_point(PEMF_CALLBACK_DATA d, double px)
363 {
364 double ppx = px * (d->dc[d->level].ScaleInX ? d->dc[d->level].ScaleInX : 1.0);
365 double ppy = 0;
367 double dx = ppx * d->dc[d->level].worldTransform.eM11 + ppy * d->dc[d->level].worldTransform.eM21;
368 dx *= d->dc[d->level].ScaleOutX ? d->dc[d->level].ScaleOutX : device_scale;
369 double dy = ppx * d->dc[d->level].worldTransform.eM12 + ppy * d->dc[d->level].worldTransform.eM22;
370 dy *= d->dc[d->level].ScaleOutY ? d->dc[d->level].ScaleOutY : device_scale;
372 double tmp = sqrt(dx * dx + dy * dy);
373 return tmp;
374 }
377 static void
378 select_pen(PEMF_CALLBACK_DATA d, int index)
379 {
380 PEMRCREATEPEN pEmr = NULL;
382 if (index >= 0 && index < d->n_obj)
383 pEmr = (PEMRCREATEPEN) d->emf_obj[index].lpEMFR;
385 if (!pEmr)
386 return;
388 switch (pEmr->lopn.lopnStyle & PS_STYLE_MASK) {
389 case PS_DASH:
390 case PS_DOT:
391 case PS_DASHDOT:
392 case PS_DASHDOTDOT:
393 {
394 int i = 0;
395 int penstyle = (pEmr->lopn.lopnStyle & PS_STYLE_MASK);
396 d->dc[d->level].style.stroke_dash.n_dash =
397 penstyle == PS_DASHDOTDOT ? 6 : penstyle == PS_DASHDOT ? 4 : 2;
398 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)))
399 delete[] d->dc[d->level].style.stroke_dash.dash;
400 d->dc[d->level].style.stroke_dash.dash = new double[d->dc[d->level].style.stroke_dash.n_dash];
401 if (penstyle==PS_DASH || penstyle==PS_DASHDOT || penstyle==PS_DASHDOTDOT) {
402 d->dc[d->level].style.stroke_dash.dash[i++] = 3;
403 d->dc[d->level].style.stroke_dash.dash[i++] = 1;
404 }
405 if (penstyle==PS_DOT || penstyle==PS_DASHDOT || penstyle==PS_DASHDOTDOT) {
406 d->dc[d->level].style.stroke_dash.dash[i++] = 1;
407 d->dc[d->level].style.stroke_dash.dash[i++] = 1;
408 }
409 if (penstyle==PS_DASHDOTDOT) {
410 d->dc[d->level].style.stroke_dash.dash[i++] = 1;
411 d->dc[d->level].style.stroke_dash.dash[i++] = 1;
412 }
414 d->dc[d->level].style.stroke_dasharray_set = 1;
415 break;
416 }
418 case PS_SOLID:
419 default:
420 {
421 d->dc[d->level].style.stroke_dasharray_set = 0;
422 break;
423 }
424 }
426 switch (pEmr->lopn.lopnStyle & PS_ENDCAP_MASK) {
427 case PS_ENDCAP_ROUND:
428 {
429 d->dc[d->level].style.stroke_linecap.computed = 1;
430 break;
431 }
432 case PS_ENDCAP_SQUARE:
433 {
434 d->dc[d->level].style.stroke_linecap.computed = 2;
435 break;
436 }
437 case PS_ENDCAP_FLAT:
438 default:
439 {
440 d->dc[d->level].style.stroke_linecap.computed = 0;
441 break;
442 }
443 }
445 switch (pEmr->lopn.lopnStyle & PS_JOIN_MASK) {
446 case PS_JOIN_BEVEL:
447 {
448 d->dc[d->level].style.stroke_linejoin.computed = 2;
449 break;
450 }
451 case PS_JOIN_MITER:
452 {
453 d->dc[d->level].style.stroke_linejoin.computed = 0;
454 break;
455 }
456 case PS_JOIN_ROUND:
457 default:
458 {
459 d->dc[d->level].style.stroke_linejoin.computed = 1;
460 break;
461 }
462 }
464 d->dc[d->level].stroke_set = true;
466 if (pEmr->lopn.lopnStyle == PS_NULL) {
467 d->dc[d->level].style.stroke_width.value = 0;
468 d->dc[d->level].stroke_set = false;
469 } else if (pEmr->lopn.lopnWidth.x) {
470 int cur_level = d->level;
471 d->level = d->emf_obj[index].level;
472 double pen_width = pix_to_size_point( d, pEmr->lopn.lopnWidth.x );
473 d->level = cur_level;
474 d->dc[d->level].style.stroke_width.value = pen_width;
475 } else { // this stroke should always be rendered as 1 pixel wide, independent of zoom level (can that be done in SVG?)
476 //d->dc[d->level].style.stroke_width.value = 1.0;
477 int cur_level = d->level;
478 d->level = d->emf_obj[index].level;
479 double pen_width = pix_to_size_point( d, 1 );
480 d->level = cur_level;
481 d->dc[d->level].style.stroke_width.value = pen_width;
482 }
484 double r, g, b;
485 r = SP_COLOR_U_TO_F( GetRValue(pEmr->lopn.lopnColor) );
486 g = SP_COLOR_U_TO_F( GetGValue(pEmr->lopn.lopnColor) );
487 b = SP_COLOR_U_TO_F( GetBValue(pEmr->lopn.lopnColor) );
488 d->dc[d->level].style.stroke.value.color.set( r, g, b );
489 }
492 static void
493 select_extpen(PEMF_CALLBACK_DATA d, int index)
494 {
495 PEMREXTCREATEPEN pEmr = NULL;
497 if (index >= 0 && index < d->n_obj)
498 pEmr = (PEMREXTCREATEPEN) d->emf_obj[index].lpEMFR;
500 if (!pEmr)
501 return;
503 switch (pEmr->elp.elpPenStyle & PS_STYLE_MASK) {
504 case PS_USERSTYLE:
505 {
506 if (pEmr->elp.elpNumEntries) {
507 d->dc[d->level].style.stroke_dash.n_dash = pEmr->elp.elpNumEntries;
508 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)))
509 delete[] d->dc[d->level].style.stroke_dash.dash;
510 d->dc[d->level].style.stroke_dash.dash = new double[pEmr->elp.elpNumEntries];
511 for (unsigned int i=0; i<pEmr->elp.elpNumEntries; i++) {
512 int cur_level = d->level;
513 d->level = d->emf_obj[index].level;
514 double dash_length = pix_to_size_point( d, pEmr->elp.elpStyleEntry[i] );
515 d->level = cur_level;
516 d->dc[d->level].style.stroke_dash.dash[i] = dash_length;
517 }
518 d->dc[d->level].style.stroke_dasharray_set = 1;
519 } else {
520 d->dc[d->level].style.stroke_dasharray_set = 0;
521 }
522 break;
523 }
525 case PS_DASH:
526 case PS_DOT:
527 case PS_DASHDOT:
528 case PS_DASHDOTDOT:
529 {
530 int i = 0;
531 int penstyle = (pEmr->elp.elpPenStyle & PS_STYLE_MASK);
532 d->dc[d->level].style.stroke_dash.n_dash =
533 penstyle == PS_DASHDOTDOT ? 6 : penstyle == PS_DASHDOT ? 4 : 2;
534 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)))
535 delete[] d->dc[d->level].style.stroke_dash.dash;
536 d->dc[d->level].style.stroke_dash.dash = new double[d->dc[d->level].style.stroke_dash.n_dash];
537 if (penstyle==PS_DASH || penstyle==PS_DASHDOT || penstyle==PS_DASHDOTDOT) {
538 d->dc[d->level].style.stroke_dash.dash[i++] = 3;
539 d->dc[d->level].style.stroke_dash.dash[i++] = 2;
540 }
541 if (penstyle==PS_DOT || penstyle==PS_DASHDOT || penstyle==PS_DASHDOTDOT) {
542 d->dc[d->level].style.stroke_dash.dash[i++] = 1;
543 d->dc[d->level].style.stroke_dash.dash[i++] = 2;
544 }
545 if (penstyle==PS_DASHDOTDOT) {
546 d->dc[d->level].style.stroke_dash.dash[i++] = 1;
547 d->dc[d->level].style.stroke_dash.dash[i++] = 2;
548 }
550 d->dc[d->level].style.stroke_dasharray_set = 1;
551 break;
552 }
554 case PS_SOLID:
555 default:
556 {
557 d->dc[d->level].style.stroke_dasharray_set = 0;
558 break;
559 }
560 }
562 switch (pEmr->elp.elpPenStyle & PS_ENDCAP_MASK) {
563 case PS_ENDCAP_ROUND:
564 {
565 d->dc[d->level].style.stroke_linecap.computed = 1;
566 break;
567 }
568 case PS_ENDCAP_SQUARE:
569 {
570 d->dc[d->level].style.stroke_linecap.computed = 2;
571 break;
572 }
573 case PS_ENDCAP_FLAT:
574 default:
575 {
576 d->dc[d->level].style.stroke_linecap.computed = 0;
577 break;
578 }
579 }
581 switch (pEmr->elp.elpPenStyle & PS_JOIN_MASK) {
582 case PS_JOIN_BEVEL:
583 {
584 d->dc[d->level].style.stroke_linejoin.computed = 2;
585 break;
586 }
587 case PS_JOIN_MITER:
588 {
589 d->dc[d->level].style.stroke_linejoin.computed = 0;
590 break;
591 }
592 case PS_JOIN_ROUND:
593 default:
594 {
595 d->dc[d->level].style.stroke_linejoin.computed = 1;
596 break;
597 }
598 }
600 d->dc[d->level].stroke_set = true;
602 if (pEmr->elp.elpPenStyle == PS_NULL) {
603 d->dc[d->level].style.stroke_width.value = 0;
604 d->dc[d->level].stroke_set = false;
605 } else if (pEmr->elp.elpWidth) {
606 int cur_level = d->level;
607 d->level = d->emf_obj[index].level;
608 double pen_width = pix_to_size_point( d, pEmr->elp.elpWidth );
609 d->level = cur_level;
610 d->dc[d->level].style.stroke_width.value = pen_width;
611 } else { // this stroke should always be rendered as 1 pixel wide, independent of zoom level (can that be done in SVG?)
612 //d->dc[d->level].style.stroke_width.value = 1.0;
613 int cur_level = d->level;
614 d->level = d->emf_obj[index].level;
615 double pen_width = pix_to_size_point( d, 1 );
616 d->level = cur_level;
617 d->dc[d->level].style.stroke_width.value = pen_width;
618 }
620 double r, g, b;
621 r = SP_COLOR_U_TO_F( GetRValue(pEmr->elp.elpColor) );
622 g = SP_COLOR_U_TO_F( GetGValue(pEmr->elp.elpColor) );
623 b = SP_COLOR_U_TO_F( GetBValue(pEmr->elp.elpColor) );
625 d->dc[d->level].style.stroke.value.color.set( r, g, b );
626 }
629 static void
630 select_brush(PEMF_CALLBACK_DATA d, int index)
631 {
632 PEMRCREATEBRUSHINDIRECT pEmr = NULL;
634 if (index >= 0 && index < d->n_obj)
635 pEmr = (PEMRCREATEBRUSHINDIRECT) d->emf_obj[index].lpEMFR;
637 if (!pEmr)
638 return;
640 if (pEmr->lb.lbStyle == BS_SOLID) {
641 double r, g, b;
642 r = SP_COLOR_U_TO_F( GetRValue(pEmr->lb.lbColor) );
643 g = SP_COLOR_U_TO_F( GetGValue(pEmr->lb.lbColor) );
644 b = SP_COLOR_U_TO_F( GetBValue(pEmr->lb.lbColor) );
645 d->dc[d->level].style.fill.value.color.set( r, g, b );
646 }
648 d->dc[d->level].fill_set = true;
649 }
652 static void
653 select_font(PEMF_CALLBACK_DATA d, int index)
654 {
655 PEMREXTCREATEFONTINDIRECTW pEmr = NULL;
657 if (index >= 0 && index < d->n_obj)
658 pEmr = (PEMREXTCREATEFONTINDIRECTW) d->emf_obj[index].lpEMFR;
660 if (!pEmr)
661 return;
663 int cur_level = d->level;
664 d->level = d->emf_obj[index].level;
665 double font_size = pix_to_size_point( d, pEmr->elfw.elfLogFont.lfHeight );
666 d->level = cur_level;
667 d->dc[d->level].style.font_size.computed = font_size;
668 d->dc[d->level].style.font_weight.value =
669 pEmr->elfw.elfLogFont.lfWeight == FW_THIN ? SP_CSS_FONT_WEIGHT_100 :
670 pEmr->elfw.elfLogFont.lfWeight == FW_EXTRALIGHT ? SP_CSS_FONT_WEIGHT_200 :
671 pEmr->elfw.elfLogFont.lfWeight == FW_LIGHT ? SP_CSS_FONT_WEIGHT_300 :
672 pEmr->elfw.elfLogFont.lfWeight == FW_NORMAL ? SP_CSS_FONT_WEIGHT_400 :
673 pEmr->elfw.elfLogFont.lfWeight == FW_MEDIUM ? SP_CSS_FONT_WEIGHT_500 :
674 pEmr->elfw.elfLogFont.lfWeight == FW_SEMIBOLD ? SP_CSS_FONT_WEIGHT_600 :
675 pEmr->elfw.elfLogFont.lfWeight == FW_BOLD ? SP_CSS_FONT_WEIGHT_700 :
676 pEmr->elfw.elfLogFont.lfWeight == FW_EXTRABOLD ? SP_CSS_FONT_WEIGHT_800 :
677 pEmr->elfw.elfLogFont.lfWeight == FW_HEAVY ? SP_CSS_FONT_WEIGHT_900 :
678 pEmr->elfw.elfLogFont.lfWeight == FW_NORMAL ? SP_CSS_FONT_WEIGHT_NORMAL :
679 pEmr->elfw.elfLogFont.lfWeight == FW_BOLD ? SP_CSS_FONT_WEIGHT_BOLD :
680 pEmr->elfw.elfLogFont.lfWeight == FW_EXTRALIGHT ? SP_CSS_FONT_WEIGHT_LIGHTER :
681 pEmr->elfw.elfLogFont.lfWeight == FW_EXTRABOLD ? SP_CSS_FONT_WEIGHT_BOLDER :
682 FW_NORMAL;
683 d->dc[d->level].style.font_style.value = (pEmr->elfw.elfLogFont.lfItalic ? SP_CSS_FONT_STYLE_ITALIC : SP_CSS_FONT_STYLE_NORMAL);
684 d->dc[d->level].style.text_decoration.underline = pEmr->elfw.elfLogFont.lfUnderline;
685 d->dc[d->level].style.text_decoration.line_through = pEmr->elfw.elfLogFont.lfStrikeOut;
686 if (d->dc[d->level].tstyle.font_family.value)
687 g_free(d->dc[d->level].tstyle.font_family.value);
688 d->dc[d->level].tstyle.font_family.value =
689 (gchar *) g_utf16_to_utf8( (gunichar2*) pEmr->elfw.elfLogFont.lfFaceName, -1, NULL, NULL, NULL );
690 d->dc[d->level].style.text_transform.value = ((pEmr->elfw.elfLogFont.lfEscapement + 3600) % 3600) / 10;
691 }
693 static void
694 delete_object(PEMF_CALLBACK_DATA d, int index)
695 {
696 if (index >= 0 && index < d->n_obj) {
697 d->emf_obj[index].type = 0;
698 if (d->emf_obj[index].lpEMFR)
699 free(d->emf_obj[index].lpEMFR);
700 d->emf_obj[index].lpEMFR = NULL;
701 }
702 }
705 static void
706 insert_object(PEMF_CALLBACK_DATA d, int index, int type, ENHMETARECORD *pObj)
707 {
708 if (index >= 0 && index < d->n_obj) {
709 delete_object(d, index);
710 d->emf_obj[index].type = type;
711 d->emf_obj[index].level = d->level;
712 d->emf_obj[index].lpEMFR = pObj;
713 }
714 }
716 static void
717 assert_empty_path(PEMF_CALLBACK_DATA d, const char * /*fun*/)
718 {
719 if (!d->path->empty()) {
720 // g_debug("emf-win32-inout: assert_empty_path failed for %s\n", fun);
722 *(d->outsvg) += "<!--\n";
723 *(d->outsvg) += " <path \t";
724 output_style(d, EMR_STROKEPATH);
725 if (strstr(d->path->c_str(), "d=\"") == NULL) {
726 *(d->outsvg) += "d=\"";
727 *(d->outsvg) += "\n\t";
728 }
729 *(d->outsvg) += *(d->path);
730 *(d->outsvg) += " \" /> \n";
731 *(d->outsvg) += "-->\n";
733 *(d->path) = "";
734 }
735 }
738 static int CALLBACK
739 myEnhMetaFileProc(HDC /*hDC*/, HANDLETABLE * /*lpHTable*/, ENHMETARECORD const *lpEMFR, int /*nObj*/, LPARAM lpData)
740 {
741 PEMF_CALLBACK_DATA d;
742 SVGOStringStream tmp_outsvg;
743 SVGOStringStream tmp_path;
744 SVGOStringStream tmp_str;
745 SVGOStringStream dbg_str;
747 d = (PEMF_CALLBACK_DATA) lpData;
749 if (d->pathless_stroke) {
750 if (lpEMFR->iType!=EMR_POLYBEZIERTO && lpEMFR->iType!=EMR_POLYBEZIERTO16 &&
751 lpEMFR->iType!=EMR_POLYLINETO && lpEMFR->iType!=EMR_POLYLINETO16 &&
752 lpEMFR->iType!=EMR_LINETO && lpEMFR->iType!=EMR_ARCTO &&
753 lpEMFR->iType!=EMR_SETBKCOLOR && lpEMFR->iType!=EMR_SETROP2 &&
754 lpEMFR->iType!=EMR_SETBKMODE)
755 {
756 *(d->outsvg) += " <path ";
757 output_style(d, EMR_STROKEPATH);
758 *(d->outsvg) += "\n\t";
759 *(d->outsvg) += *(d->path);
760 *(d->outsvg) += " \" /> \n";
761 *(d->path) = "";
762 d->pathless_stroke = false;
763 }
764 }
766 switch (lpEMFR->iType)
767 {
768 case EMR_HEADER:
769 {
770 dbg_str << "<!-- EMR_HEADER -->\n";
772 *(d->outsvg) += "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n";
774 if (d->pDesc) {
775 *(d->outsvg) += "<!-- ";
776 *(d->outsvg) += d->pDesc;
777 *(d->outsvg) += " -->\n";
778 }
780 ENHMETAHEADER *pEmr = (ENHMETAHEADER *) lpEMFR;
781 tmp_outsvg << "<svg\n";
782 tmp_outsvg << " xmlns:svg=\"http://www.w3.org/2000/svg\"\n";
783 tmp_outsvg << " xmlns=\"http://www.w3.org/2000/svg\"\n";
784 tmp_outsvg << " version=\"1.0\"\n";
786 d->xDPI = 2540;
787 d->yDPI = 2540;
789 d->dc[d->level].PixelsInX = pEmr->rclFrame.right; // - pEmr->rclFrame.left;
790 d->dc[d->level].PixelsInY = pEmr->rclFrame.bottom; // - pEmr->rclFrame.top;
792 d->MMX = d->dc[d->level].PixelsInX / 100.0;
793 d->MMY = d->dc[d->level].PixelsInY / 100.0;
795 d->dc[d->level].PixelsOutX = d->MMX * PX_PER_MM;
796 d->dc[d->level].PixelsOutY = d->MMY * PX_PER_MM;
798 // calculate ratio of Inkscape dpi/device dpi
799 if (pEmr->szlMillimeters.cx && pEmr->szlDevice.cx)
800 device_scale = PX_PER_MM*pEmr->szlMillimeters.cx/pEmr->szlDevice.cx;
802 tmp_outsvg <<
803 " width=\"" << d->MMX << "mm\"\n" <<
804 " height=\"" << d->MMY << "mm\"\n";
805 tmp_outsvg <<
806 " id=\"" << (d->id++) << "\">\n";
808 tmp_outsvg <<
809 "<g\n" <<
810 " id=\"" << (d->id++) << "\">\n";
812 if (pEmr->nHandles) {
813 d->n_obj = pEmr->nHandles;
814 d->emf_obj = new EMF_OBJECT[d->n_obj];
816 // Init the new emf_obj list elements to null, provided the
817 // dynamic allocation succeeded.
818 if ( d->emf_obj != NULL )
819 {
820 for( int i=0; i < d->n_obj; ++i )
821 d->emf_obj[i].lpEMFR = NULL;
822 } //if
824 } else {
825 d->emf_obj = NULL;
826 }
828 break;
829 }
830 case EMR_POLYBEZIER:
831 {
832 dbg_str << "<!-- EMR_POLYBEZIER -->\n";
834 PEMRPOLYBEZIER pEmr = (PEMRPOLYBEZIER) lpEMFR;
835 DWORD i,j;
837 if (pEmr->cptl<4)
838 break;
840 if (!d->inpath) {
841 assert_empty_path(d, "EMR_POLYBEZIER");
843 *(d->outsvg) += " <path ";
844 output_style(d, EMR_STROKEPATH);
845 *(d->outsvg) += "\n\td=\"";
846 }
848 tmp_str <<
849 "\n\tM " <<
850 pix_to_x_point( d, pEmr->aptl[0].x, pEmr->aptl[0].y ) << " " <<
851 pix_to_y_point( d, pEmr->aptl[0].x, pEmr->aptl[0].y) << " ";
853 for (i=1; i<pEmr->cptl; ) {
854 tmp_str << "\n\tC ";
855 for (j=0; j<3 && i<pEmr->cptl; j++,i++) {
856 tmp_str <<
857 pix_to_x_point( d, pEmr->aptl[i].x, pEmr->aptl[i].y ) << " " <<
858 pix_to_y_point( d, pEmr->aptl[i].x, pEmr->aptl[i].y ) << " ";
859 }
860 }
862 if (d->inpath) {
863 tmp_path << tmp_str.str().c_str();
864 }
865 else {
866 *(d->outsvg) += tmp_str.str().c_str();
867 *(d->outsvg) += " \" /> \n";
868 }
870 break;
871 }
872 case EMR_POLYGON:
873 {
874 dbg_str << "<!-- EMR_POLYGON -->\n";
876 EMRPOLYGON *pEmr = (EMRPOLYGON *) lpEMFR;
877 DWORD i;
879 if (pEmr->cptl < 2)
880 break;
882 assert_empty_path(d, "EMR_POLYGON");
884 *(d->outsvg) += " <path ";
885 output_style(d, EMR_STROKEANDFILLPATH);
886 *(d->outsvg) += "\n\td=\"";
888 tmp_str <<
889 "\n\tM " <<
890 pix_to_x_point( d, pEmr->aptl[0].x, pEmr->aptl[0].y ) << " " <<
891 pix_to_y_point( d, pEmr->aptl[0].x, pEmr->aptl[0].y ) << " ";
893 for (i=1; i<pEmr->cptl; i++) {
894 tmp_str <<
895 "\n\tL " <<
896 pix_to_x_point( d, pEmr->aptl[i].x, pEmr->aptl[i].y ) << " " <<
897 pix_to_y_point( d, pEmr->aptl[i].x, pEmr->aptl[i].y ) << " ";
898 }
900 *(d->outsvg) += tmp_str.str().c_str();
901 *(d->outsvg) += " z \" /> \n";
903 break;
904 }
905 case EMR_POLYLINE:
906 {
907 dbg_str << "<!-- EMR_POLYLINE -->\n";
909 EMRPOLYLINE *pEmr = (EMRPOLYLINE *) lpEMFR;
910 DWORD i;
912 if (pEmr->cptl<2)
913 break;
915 if (!d->inpath) {
916 assert_empty_path(d, "EMR_POLYLINE");
918 *(d->outsvg) += " <path ";
919 output_style(d, EMR_STROKEPATH);
920 *(d->outsvg) += "\n\td=\"";
921 }
923 tmp_str <<
924 "\n\tM " <<
925 pix_to_x_point( d, pEmr->aptl[0].x, pEmr->aptl[0].y ) << " " <<
926 pix_to_y_point( d, pEmr->aptl[0].x, pEmr->aptl[0].y ) << " ";
928 for (i=1; i<pEmr->cptl; i++) {
929 tmp_str <<
930 "\n\tL " <<
931 pix_to_x_point( d, pEmr->aptl[i].x, pEmr->aptl[i].y ) << " " <<
932 pix_to_y_point( d, pEmr->aptl[i].x, pEmr->aptl[i].y ) << " ";
933 }
935 if (d->inpath) {
936 tmp_path << tmp_str.str().c_str();
937 }
938 else {
939 *(d->outsvg) += tmp_str.str().c_str();
940 *(d->outsvg) += " \" /> \n";
941 }
943 break;
944 }
945 case EMR_POLYBEZIERTO:
946 {
947 dbg_str << "<!-- EMR_POLYBEZIERTO -->\n";
949 PEMRPOLYBEZIERTO pEmr = (PEMRPOLYBEZIERTO) lpEMFR;
950 DWORD i,j;
952 if (d->path->empty()) {
953 d->pathless_stroke = true;
954 *(d->path) = "d=\"";
955 }
957 for (i=0; i<pEmr->cptl;) {
958 tmp_path << "\n\tC ";
959 for (j=0; j<3 && i<pEmr->cptl; j++,i++) {
960 tmp_path <<
961 pix_to_x_point( d, pEmr->aptl[i].x, pEmr->aptl[i].y ) << " " <<
962 pix_to_y_point( d, pEmr->aptl[i].x, pEmr->aptl[i].y ) << " ";
963 }
964 }
966 break;
967 }
968 case EMR_POLYLINETO:
969 {
970 dbg_str << "<!-- EMR_POLYLINETO -->\n";
972 PEMRPOLYLINETO pEmr = (PEMRPOLYLINETO) lpEMFR;
973 DWORD i;
975 if (d->path->empty()) {
976 d->pathless_stroke = true;
977 *(d->path) = "d=\"";
978 }
980 for (i=0; i<pEmr->cptl;i++) {
981 tmp_path <<
982 "\n\tL " <<
983 pix_to_x_point( d, pEmr->aptl[i].x, pEmr->aptl[i].y ) << " " <<
984 pix_to_y_point( d, pEmr->aptl[i].x, pEmr->aptl[i].y ) << " ";
985 }
987 break;
988 }
989 case EMR_POLYPOLYLINE:
990 case EMR_POLYPOLYGON:
991 {
992 if (lpEMFR->iType == EMR_POLYPOLYLINE)
993 dbg_str << "<!-- EMR_POLYPOLYLINE -->\n";
994 if (lpEMFR->iType == EMR_POLYPOLYGON)
995 dbg_str << "<!-- EMR_POLYPOLYGON -->\n";
997 PEMRPOLYPOLYGON pEmr = (PEMRPOLYPOLYGON) lpEMFR;
998 unsigned int n, i, j;
1000 if (!d->inpath) {
1001 assert_empty_path(d, lpEMFR->iType == EMR_POLYPOLYGON ? "EMR_POLYPOLYGON" : "EMR_POLYPOLYLINE");
1003 *(d->outsvg) += " <path ";
1004 output_style(d, lpEMFR->iType==EMR_POLYPOLYGON ? EMR_STROKEANDFILLPATH : EMR_STROKEPATH);
1005 *(d->outsvg) += "\n\td=\"";
1006 }
1008 POINTL *aptl = (POINTL *) &pEmr->aPolyCounts[pEmr->nPolys];
1010 i = 0;
1011 for (n=0; n<pEmr->nPolys && i<pEmr->cptl; n++) {
1012 SVGOStringStream poly_path;
1014 poly_path << "\n\tM " <<
1015 pix_to_x_point( d, aptl[i].x, aptl[i].y ) << " " <<
1016 pix_to_y_point( d, aptl[i].x, aptl[i].y ) << " ";
1017 i++;
1019 for (j=1; j<pEmr->aPolyCounts[n] && i<pEmr->cptl; j++) {
1020 poly_path << "\n\tL " <<
1021 pix_to_x_point( d, aptl[i].x, aptl[i].y ) << " " <<
1022 pix_to_y_point( d, aptl[i].x, aptl[i].y ) << " ";
1023 i++;
1024 }
1026 tmp_str << poly_path.str().c_str();
1027 if (lpEMFR->iType == EMR_POLYPOLYGON)
1028 tmp_str << " z";
1029 tmp_str << " \n";
1030 }
1032 if (d->inpath) {
1033 tmp_path << tmp_str.str().c_str();
1034 }
1035 else {
1036 *(d->outsvg) += tmp_str.str().c_str();
1037 *(d->outsvg) += " \" /> \n";
1038 }
1040 break;
1041 }
1042 case EMR_SETWINDOWEXTEX:
1043 {
1044 dbg_str << "<!-- EMR_SETWINDOWEXTEX -->\n";
1046 PEMRSETWINDOWEXTEX pEmr = (PEMRSETWINDOWEXTEX) lpEMFR;
1048 d->dc[d->level].sizeWnd = pEmr->szlExtent;
1050 if (!d->dc[d->level].sizeWnd.cx || !d->dc[d->level].sizeWnd.cy) {
1051 d->dc[d->level].sizeWnd = d->dc[d->level].sizeView;
1052 if (!d->dc[d->level].sizeWnd.cx || !d->dc[d->level].sizeWnd.cy) {
1053 d->dc[d->level].sizeWnd.cx = d->dc[d->level].PixelsOutX;
1054 d->dc[d->level].sizeWnd.cy = d->dc[d->level].PixelsOutY;
1055 }
1056 }
1058 if (!d->dc[d->level].sizeView.cx || !d->dc[d->level].sizeView.cy) {
1059 d->dc[d->level].sizeView = d->dc[d->level].sizeWnd;
1060 }
1062 d->dc[d->level].PixelsInX = d->dc[d->level].sizeWnd.cx;
1063 d->dc[d->level].PixelsInY = d->dc[d->level].sizeWnd.cy;
1065 if (d->dc[d->level].PixelsInX && d->dc[d->level].PixelsInY) {
1066 d->dc[d->level].ScaleInX = (double) d->dc[d->level].sizeView.cx / (double) d->dc[d->level].PixelsInX;
1067 d->dc[d->level].ScaleInY = (double) d->dc[d->level].sizeView.cy / (double) d->dc[d->level].PixelsInY;
1068 }
1069 else {
1070 d->dc[d->level].ScaleInX = 1;
1071 d->dc[d->level].ScaleInY = 1;
1072 }
1074 if (d->dc[d->level].sizeView.cx && d->dc[d->level].sizeView.cy) {
1075 d->dc[d->level].ScaleOutX = (double) d->dc[d->level].PixelsOutX / (double) d->dc[d->level].sizeView.cx;
1076 d->dc[d->level].ScaleOutY = (double) d->dc[d->level].PixelsOutY / (double) d->dc[d->level].sizeView.cy;
1077 }
1078 else {
1079 d->dc[d->level].ScaleOutX = device_scale;
1080 d->dc[d->level].ScaleOutY = device_scale;
1081 }
1083 break;
1084 }
1085 case EMR_SETWINDOWORGEX:
1086 {
1087 dbg_str << "<!-- EMR_SETWINDOWORGEX -->\n";
1089 PEMRSETWINDOWORGEX pEmr = (PEMRSETWINDOWORGEX) lpEMFR;
1090 d->dc[d->level].winorg = pEmr->ptlOrigin;
1091 break;
1092 }
1093 case EMR_SETVIEWPORTEXTEX:
1094 {
1095 dbg_str << "<!-- EMR_SETVIEWPORTEXTEX -->\n";
1097 PEMRSETVIEWPORTEXTEX pEmr = (PEMRSETVIEWPORTEXTEX) lpEMFR;
1099 d->dc[d->level].sizeView = pEmr->szlExtent;
1101 if (!d->dc[d->level].sizeView.cx || !d->dc[d->level].sizeView.cy) {
1102 d->dc[d->level].sizeView = d->dc[d->level].sizeWnd;
1103 if (!d->dc[d->level].sizeView.cx || !d->dc[d->level].sizeView.cy) {
1104 d->dc[d->level].sizeView.cx = d->dc[d->level].PixelsOutX;
1105 d->dc[d->level].sizeView.cy = d->dc[d->level].PixelsOutY;
1106 }
1107 }
1109 if (!d->dc[d->level].sizeWnd.cx || !d->dc[d->level].sizeWnd.cy) {
1110 d->dc[d->level].sizeWnd = d->dc[d->level].sizeView;
1111 }
1113 d->dc[d->level].PixelsInX = d->dc[d->level].sizeWnd.cx;
1114 d->dc[d->level].PixelsInY = d->dc[d->level].sizeWnd.cy;
1116 if (d->dc[d->level].PixelsInX && d->dc[d->level].PixelsInY) {
1117 d->dc[d->level].ScaleInX = (double) d->dc[d->level].sizeView.cx / (double) d->dc[d->level].PixelsInX;
1118 d->dc[d->level].ScaleInY = (double) d->dc[d->level].sizeView.cy / (double) d->dc[d->level].PixelsInY;
1119 }
1120 else {
1121 d->dc[d->level].ScaleInX = 1;
1122 d->dc[d->level].ScaleInY = 1;
1123 }
1125 if (d->dc[d->level].sizeView.cx && d->dc[d->level].sizeView.cy) {
1126 d->dc[d->level].ScaleOutX = (double) d->dc[d->level].PixelsOutX / (double) d->dc[d->level].sizeView.cx;
1127 d->dc[d->level].ScaleOutY = (double) d->dc[d->level].PixelsOutY / (double) d->dc[d->level].sizeView.cy;
1128 }
1129 else {
1130 d->dc[d->level].ScaleOutX = device_scale;
1131 d->dc[d->level].ScaleOutY = device_scale;
1132 }
1134 break;
1135 }
1136 case EMR_SETVIEWPORTORGEX:
1137 {
1138 dbg_str << "<!-- EMR_SETVIEWPORTORGEX -->\n";
1140 PEMRSETVIEWPORTORGEX pEmr = (PEMRSETVIEWPORTORGEX) lpEMFR;
1141 d->dc[d->level].vieworg = pEmr->ptlOrigin;
1142 break;
1143 }
1144 case EMR_SETBRUSHORGEX:
1145 dbg_str << "<!-- EMR_SETBRUSHORGEX -->\n";
1146 break;
1147 case EMR_EOF:
1148 {
1149 dbg_str << "<!-- EMR_EOF -->\n";
1151 assert_empty_path(d, "EMR_EOF");
1152 tmp_outsvg << "</g>\n";
1153 tmp_outsvg << "</svg>\n";
1154 break;
1155 }
1156 case EMR_SETPIXELV:
1157 dbg_str << "<!-- EMR_SETPIXELV -->\n";
1158 break;
1159 case EMR_SETMAPPERFLAGS:
1160 dbg_str << "<!-- EMR_SETMAPPERFLAGS -->\n";
1161 break;
1162 case EMR_SETMAPMODE:
1163 dbg_str << "<!-- EMR_SETMAPMODE -->\n";
1164 break;
1165 case EMR_SETBKMODE:
1166 dbg_str << "<!-- EMR_SETBKMODE -->\n";
1167 break;
1168 case EMR_SETPOLYFILLMODE:
1169 {
1170 dbg_str << "<!-- EMR_SETPOLYFILLMODE -->\n";
1172 PEMRSETPOLYFILLMODE pEmr = (PEMRSETPOLYFILLMODE) lpEMFR;
1173 d->dc[d->level].style.fill_rule.value =
1174 (pEmr->iMode == ALTERNATE ? 0 :
1175 pEmr->iMode == WINDING ? 1 : 0);
1176 break;
1177 }
1178 case EMR_SETROP2:
1179 dbg_str << "<!-- EMR_SETROP2 -->\n";
1180 break;
1181 case EMR_SETSTRETCHBLTMODE:
1182 dbg_str << "<!-- EMR_SETSTRETCHBLTMODE -->\n";
1183 break;
1184 case EMR_SETTEXTALIGN:
1185 {
1186 dbg_str << "<!-- EMR_SETTEXTALIGN -->\n";
1188 PEMRSETTEXTALIGN pEmr = (PEMRSETTEXTALIGN) lpEMFR;
1189 d->dc[d->level].textAlign = pEmr->iMode;
1190 break;
1191 }
1192 case EMR_SETCOLORADJUSTMENT:
1193 dbg_str << "<!-- EMR_SETCOLORADJUSTMENT -->\n";
1194 break;
1195 case EMR_SETTEXTCOLOR:
1196 {
1197 dbg_str << "<!-- EMR_SETTEXTCOLOR -->\n";
1199 PEMRSETTEXTCOLOR pEmr = (PEMRSETTEXTCOLOR) lpEMFR;
1200 d->dc[d->level].textColor = pEmr->crColor;
1201 d->dc[d->level].textColorSet = true;
1202 break;
1203 }
1204 case EMR_SETBKCOLOR:
1205 dbg_str << "<!-- EMR_SETBKCOLOR -->\n";
1206 break;
1207 case EMR_OFFSETCLIPRGN:
1208 dbg_str << "<!-- EMR_OFFSETCLIPRGN -->\n";
1209 break;
1210 case EMR_MOVETOEX:
1211 {
1212 dbg_str << "<!-- EMR_MOVETOEX -->\n";
1214 PEMRMOVETOEX pEmr = (PEMRMOVETOEX) lpEMFR;
1216 if (d->path->empty()) {
1217 d->pathless_stroke = true;
1218 *(d->path) = "d=\"";
1219 }
1221 d->dc[d->level].cur = pEmr->ptl;
1223 tmp_path <<
1224 "\n\tM " <<
1225 pix_to_x_point( d, pEmr->ptl.x, pEmr->ptl.y ) << " " <<
1226 pix_to_y_point( d, pEmr->ptl.x, pEmr->ptl.y ) << " ";
1227 break;
1228 }
1229 case EMR_SETMETARGN:
1230 dbg_str << "<!-- EMR_SETMETARGN -->\n";
1231 break;
1232 case EMR_EXCLUDECLIPRECT:
1233 dbg_str << "<!-- EMR_EXCLUDECLIPRECT -->\n";
1234 break;
1235 case EMR_INTERSECTCLIPRECT:
1236 dbg_str << "<!-- EMR_INTERSECTCLIPRECT -->\n";
1237 break;
1238 case EMR_SCALEVIEWPORTEXTEX:
1239 dbg_str << "<!-- EMR_SCALEVIEWPORTEXTEX -->\n";
1240 break;
1241 case EMR_SCALEWINDOWEXTEX:
1242 dbg_str << "<!-- EMR_SCALEWINDOWEXTEX -->\n";
1243 break;
1244 case EMR_SAVEDC:
1245 dbg_str << "<!-- EMR_SAVEDC -->\n";
1247 if (d->level < EMF_MAX_DC) {
1248 d->dc[d->level + 1] = d->dc[d->level];
1249 d->level = d->level + 1;
1250 }
1251 break;
1252 case EMR_RESTOREDC:
1253 {
1254 dbg_str << "<!-- EMR_RESTOREDC -->\n";
1256 PEMRRESTOREDC pEmr = (PEMRRESTOREDC) lpEMFR;
1257 int old_level = d->level;
1258 if (pEmr->iRelative >= 0) {
1259 if (pEmr->iRelative < d->level)
1260 d->level = pEmr->iRelative;
1261 }
1262 else {
1263 if (d->level + pEmr->iRelative >= 0)
1264 d->level = d->level + pEmr->iRelative;
1265 }
1266 while (old_level > d->level) {
1267 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)))
1268 delete[] d->dc[old_level].style.stroke_dash.dash;
1269 old_level--;
1270 }
1271 break;
1272 }
1273 case EMR_SETWORLDTRANSFORM:
1274 {
1275 dbg_str << "<!-- EMR_SETWORLDTRANSFORM -->\n";
1277 PEMRSETWORLDTRANSFORM pEmr = (PEMRSETWORLDTRANSFORM) lpEMFR;
1278 d->dc[d->level].worldTransform = pEmr->xform;
1279 break;
1280 }
1281 case EMR_MODIFYWORLDTRANSFORM:
1282 {
1283 dbg_str << "<!-- EMR_MODIFYWORLDTRANSFORM -->\n";
1285 PEMRMODIFYWORLDTRANSFORM pEmr = (PEMRMODIFYWORLDTRANSFORM) lpEMFR;
1286 switch (pEmr->iMode)
1287 {
1288 case MWT_IDENTITY:
1289 d->dc[d->level].worldTransform.eM11 = 1.0;
1290 d->dc[d->level].worldTransform.eM12 = 0.0;
1291 d->dc[d->level].worldTransform.eM21 = 0.0;
1292 d->dc[d->level].worldTransform.eM22 = 1.0;
1293 d->dc[d->level].worldTransform.eDx = 0.0;
1294 d->dc[d->level].worldTransform.eDy = 0.0;
1295 break;
1296 case MWT_LEFTMULTIPLY:
1297 {
1298 // d->dc[d->level].worldTransform = pEmr->xform * worldTransform;
1300 float a11 = pEmr->xform.eM11;
1301 float a12 = pEmr->xform.eM12;
1302 float a13 = 0.0;
1303 float a21 = pEmr->xform.eM21;
1304 float a22 = pEmr->xform.eM22;
1305 float a23 = 0.0;
1306 float a31 = pEmr->xform.eDx;
1307 float a32 = pEmr->xform.eDy;
1308 float a33 = 1.0;
1310 float b11 = d->dc[d->level].worldTransform.eM11;
1311 float b12 = d->dc[d->level].worldTransform.eM12;
1312 //float b13 = 0.0;
1313 float b21 = d->dc[d->level].worldTransform.eM21;
1314 float b22 = d->dc[d->level].worldTransform.eM22;
1315 //float b23 = 0.0;
1316 float b31 = d->dc[d->level].worldTransform.eDx;
1317 float b32 = d->dc[d->level].worldTransform.eDy;
1318 //float b33 = 1.0;
1320 float c11 = a11*b11 + a12*b21 + a13*b31;;
1321 float c12 = a11*b12 + a12*b22 + a13*b32;;
1322 //float c13 = a11*b13 + a12*b23 + a13*b33;;
1323 float c21 = a21*b11 + a22*b21 + a23*b31;;
1324 float c22 = a21*b12 + a22*b22 + a23*b32;;
1325 //float c23 = a21*b13 + a22*b23 + a23*b33;;
1326 float c31 = a31*b11 + a32*b21 + a33*b31;;
1327 float c32 = a31*b12 + a32*b22 + a33*b32;;
1328 //float c33 = a31*b13 + a32*b23 + a33*b33;;
1330 d->dc[d->level].worldTransform.eM11 = c11;;
1331 d->dc[d->level].worldTransform.eM12 = c12;;
1332 d->dc[d->level].worldTransform.eM21 = c21;;
1333 d->dc[d->level].worldTransform.eM22 = c22;;
1334 d->dc[d->level].worldTransform.eDx = c31;
1335 d->dc[d->level].worldTransform.eDy = c32;
1337 break;
1338 }
1339 case MWT_RIGHTMULTIPLY:
1340 {
1341 // d->dc[d->level].worldTransform = worldTransform * pEmr->xform;
1343 float a11 = d->dc[d->level].worldTransform.eM11;
1344 float a12 = d->dc[d->level].worldTransform.eM12;
1345 float a13 = 0.0;
1346 float a21 = d->dc[d->level].worldTransform.eM21;
1347 float a22 = d->dc[d->level].worldTransform.eM22;
1348 float a23 = 0.0;
1349 float a31 = d->dc[d->level].worldTransform.eDx;
1350 float a32 = d->dc[d->level].worldTransform.eDy;
1351 float a33 = 1.0;
1353 float b11 = pEmr->xform.eM11;
1354 float b12 = pEmr->xform.eM12;
1355 //float b13 = 0.0;
1356 float b21 = pEmr->xform.eM21;
1357 float b22 = pEmr->xform.eM22;
1358 //float b23 = 0.0;
1359 float b31 = pEmr->xform.eDx;
1360 float b32 = pEmr->xform.eDy;
1361 //float b33 = 1.0;
1363 float c11 = a11*b11 + a12*b21 + a13*b31;;
1364 float c12 = a11*b12 + a12*b22 + a13*b32;;
1365 //float c13 = a11*b13 + a12*b23 + a13*b33;;
1366 float c21 = a21*b11 + a22*b21 + a23*b31;;
1367 float c22 = a21*b12 + a22*b22 + a23*b32;;
1368 //float c23 = a21*b13 + a22*b23 + a23*b33;;
1369 float c31 = a31*b11 + a32*b21 + a33*b31;;
1370 float c32 = a31*b12 + a32*b22 + a33*b32;;
1371 //float c33 = a31*b13 + a32*b23 + a33*b33;;
1373 d->dc[d->level].worldTransform.eM11 = c11;;
1374 d->dc[d->level].worldTransform.eM12 = c12;;
1375 d->dc[d->level].worldTransform.eM21 = c21;;
1376 d->dc[d->level].worldTransform.eM22 = c22;;
1377 d->dc[d->level].worldTransform.eDx = c31;
1378 d->dc[d->level].worldTransform.eDy = c32;
1380 break;
1381 }
1382 // case MWT_SET:
1383 default:
1384 d->dc[d->level].worldTransform = pEmr->xform;
1385 break;
1386 }
1387 break;
1388 }
1389 case EMR_SELECTOBJECT:
1390 {
1391 dbg_str << "<!-- EMR_SELECTOBJECT -->\n";
1393 PEMRSELECTOBJECT pEmr = (PEMRSELECTOBJECT) lpEMFR;
1394 unsigned int index = pEmr->ihObject;
1396 if (index >= ENHMETA_STOCK_OBJECT) {
1397 index -= ENHMETA_STOCK_OBJECT;
1398 switch (index) {
1399 case NULL_BRUSH:
1400 d->dc[d->level].fill_set = false;
1401 break;
1402 case BLACK_BRUSH:
1403 case DKGRAY_BRUSH:
1404 case GRAY_BRUSH:
1405 case LTGRAY_BRUSH:
1406 case WHITE_BRUSH:
1407 {
1408 float val = 0;
1409 switch (index) {
1410 case BLACK_BRUSH:
1411 val = 0.0 / 255.0;
1412 break;
1413 case DKGRAY_BRUSH:
1414 val = 64.0 / 255.0;
1415 break;
1416 case GRAY_BRUSH:
1417 val = 128.0 / 255.0;
1418 break;
1419 case LTGRAY_BRUSH:
1420 val = 192.0 / 255.0;
1421 break;
1422 case WHITE_BRUSH:
1423 val = 255.0 / 255.0;
1424 break;
1425 }
1426 d->dc[d->level].style.fill.value.color.set( val, val, val );
1428 d->dc[d->level].fill_set = true;
1429 break;
1430 }
1431 case NULL_PEN:
1432 d->dc[d->level].stroke_set = false;
1433 break;
1434 case BLACK_PEN:
1435 case WHITE_PEN:
1436 {
1437 float val = index == BLACK_PEN ? 0 : 1;
1438 d->dc[d->level].style.stroke_dasharray_set = 0;
1439 d->dc[d->level].style.stroke_width.value = 1.0;
1440 d->dc[d->level].style.stroke.value.color.set( val, val, val );
1442 d->dc[d->level].stroke_set = true;
1444 break;
1445 }
1446 }
1447 } else {
1448 if ( /*index >= 0 &&*/ index < (unsigned int) d->n_obj) {
1449 switch (d->emf_obj[index].type)
1450 {
1451 case EMR_CREATEPEN:
1452 select_pen(d, index);
1453 break;
1454 case EMR_CREATEBRUSHINDIRECT:
1455 select_brush(d, index);
1456 break;
1457 case EMR_EXTCREATEPEN:
1458 select_extpen(d, index);
1459 break;
1460 case EMR_EXTCREATEFONTINDIRECTW:
1461 select_font(d, index);
1462 break;
1463 }
1464 }
1465 }
1466 break;
1467 }
1468 case EMR_CREATEPEN:
1469 {
1470 dbg_str << "<!-- EMR_CREATEPEN -->\n";
1472 PEMRCREATEPEN pEmr = (PEMRCREATEPEN) lpEMFR;
1473 int index = pEmr->ihPen;
1475 EMRCREATEPEN *pPen =
1476 (EMRCREATEPEN *) malloc( sizeof(EMRCREATEPEN) );
1477 pPen->lopn = pEmr->lopn;
1478 insert_object(d, index, EMR_CREATEPEN, (ENHMETARECORD *) pPen);
1480 break;
1481 }
1482 case EMR_CREATEBRUSHINDIRECT:
1483 {
1484 dbg_str << "<!-- EMR_CREATEBRUSHINDIRECT -->\n";
1486 PEMRCREATEBRUSHINDIRECT pEmr = (PEMRCREATEBRUSHINDIRECT) lpEMFR;
1487 int index = pEmr->ihBrush;
1489 EMRCREATEBRUSHINDIRECT *pBrush =
1490 (EMRCREATEBRUSHINDIRECT *) malloc( sizeof(EMRCREATEBRUSHINDIRECT) );
1491 pBrush->lb = pEmr->lb;
1492 insert_object(d, index, EMR_CREATEBRUSHINDIRECT, (ENHMETARECORD *) pBrush);
1494 break;
1495 }
1496 case EMR_DELETEOBJECT:
1497 dbg_str << "<!-- EMR_DELETEOBJECT -->\n";
1498 break;
1499 case EMR_ANGLEARC:
1500 dbg_str << "<!-- EMR_ANGLEARC -->\n";
1501 break;
1502 case EMR_ELLIPSE:
1503 {
1504 dbg_str << "<!-- EMR_ELLIPSE -->\n";
1506 PEMRELLIPSE pEmr = (PEMRELLIPSE) lpEMFR;
1507 RECTL rclBox = pEmr->rclBox;
1509 double l = pix_to_x_point( d, pEmr->rclBox.left, pEmr->rclBox.top );
1510 double t = pix_to_y_point( d, pEmr->rclBox.left, pEmr->rclBox.top );
1511 double r = pix_to_x_point( d, pEmr->rclBox.right, pEmr->rclBox.bottom );
1512 double b = pix_to_y_point( d, pEmr->rclBox.right, pEmr->rclBox.bottom );
1514 double cx = (l + r) / 2.0;
1515 double cy = (t + b) / 2.0;
1516 double rx = fabs(l - r) / 2.0;
1517 double ry = fabs(t - b) / 2.0;
1519 SVGOStringStream tmp_ellipse;
1520 tmp_ellipse << "cx=\"" << cx << "\" ";
1521 tmp_ellipse << "cy=\"" << cy << "\" ";
1522 tmp_ellipse << "rx=\"" << rx << "\" ";
1523 tmp_ellipse << "ry=\"" << ry << "\" ";
1525 assert_empty_path(d, "EMR_ELLIPSE");
1527 *(d->outsvg) += " <ellipse ";
1528 output_style(d, lpEMFR->iType);
1529 *(d->outsvg) += "\n\t";
1530 *(d->outsvg) += tmp_ellipse.str().c_str();
1531 *(d->outsvg) += "/> \n";
1532 *(d->path) = "";
1533 break;
1534 }
1535 case EMR_RECTANGLE:
1536 {
1537 dbg_str << "<!-- EMR_RECTANGLE -->\n";
1539 PEMRRECTANGLE pEmr = (PEMRRECTANGLE) lpEMFR;
1540 RECTL rc = pEmr->rclBox;
1542 double l = pix_to_x_point( d, rc.left, rc.top );
1543 double t = pix_to_y_point( d, rc.left, rc.top );
1544 double r = pix_to_x_point( d, rc.right, rc.bottom );
1545 double b = pix_to_y_point( d, rc.right, rc.bottom );
1547 SVGOStringStream tmp_rectangle;
1548 tmp_rectangle << "d=\"";
1549 tmp_rectangle << "\n\tM " << l << " " << t << " ";
1550 tmp_rectangle << "\n\tL " << r << " " << t << " ";
1551 tmp_rectangle << "\n\tL " << r << " " << b << " ";
1552 tmp_rectangle << "\n\tL " << l << " " << b << " ";
1553 tmp_rectangle << "\n\tz";
1555 assert_empty_path(d, "EMR_RECTANGLE");
1557 *(d->outsvg) += " <path ";
1558 output_style(d, lpEMFR->iType);
1559 *(d->outsvg) += "\n\t";
1560 *(d->outsvg) += tmp_rectangle.str().c_str();
1561 *(d->outsvg) += " \" /> \n";
1562 *(d->path) = "";
1563 break;
1564 }
1565 case EMR_ROUNDRECT:
1566 dbg_str << "<!-- EMR_ROUNDRECT -->\n";
1567 break;
1568 case EMR_ARC:
1569 dbg_str << "<!-- EMR_ARC -->\n";
1570 break;
1571 case EMR_CHORD:
1572 dbg_str << "<!-- EMR_CHORD -->\n";
1573 break;
1574 case EMR_PIE:
1575 dbg_str << "<!-- EMR_PIE -->\n";
1576 break;
1577 case EMR_SELECTPALETTE:
1578 dbg_str << "<!-- EMR_SELECTPALETTE -->\n";
1579 break;
1580 case EMR_CREATEPALETTE:
1581 dbg_str << "<!-- EMR_CREATEPALETTE -->\n";
1582 break;
1583 case EMR_SETPALETTEENTRIES:
1584 dbg_str << "<!-- EMR_SETPALETTEENTRIES -->\n";
1585 break;
1586 case EMR_RESIZEPALETTE:
1587 dbg_str << "<!-- EMR_RESIZEPALETTE -->\n";
1588 break;
1589 case EMR_REALIZEPALETTE:
1590 dbg_str << "<!-- EMR_REALIZEPALETTE -->\n";
1591 break;
1592 case EMR_EXTFLOODFILL:
1593 dbg_str << "<!-- EMR_EXTFLOODFILL -->\n";
1594 break;
1595 case EMR_LINETO:
1596 {
1597 dbg_str << "<!-- EMR_LINETO -->\n";
1599 PEMRLINETO pEmr = (PEMRLINETO) lpEMFR;
1601 if (d->path->empty()) {
1602 d->pathless_stroke = true;
1603 *(d->path) = "d=\"";
1604 }
1606 tmp_path <<
1607 "\n\tL " <<
1608 pix_to_x_point( d, pEmr->ptl.x, pEmr->ptl.y ) << " " <<
1609 pix_to_y_point( d, pEmr->ptl.x, pEmr->ptl.y ) << " ";
1610 break;
1611 }
1612 case EMR_ARCTO:
1613 dbg_str << "<!-- EMR_ARCTO -->\n";
1614 break;
1615 case EMR_POLYDRAW:
1616 dbg_str << "<!-- EMR_POLYDRAW -->\n";
1617 break;
1618 case EMR_SETARCDIRECTION:
1619 dbg_str << "<!-- EMR_SETARCDIRECTION -->\n";
1620 break;
1621 case EMR_SETMITERLIMIT:
1622 {
1623 dbg_str << "<!-- EMR_SETMITERLIMIT -->\n";
1625 PEMRSETMITERLIMIT pEmr = (PEMRSETMITERLIMIT) lpEMFR;
1627 float miterlimit = pEmr->eMiterLimit;
1628 miterlimit = miterlimit * 4.0 / 10.0;
1629 d->dc[d->level].style.stroke_miterlimit.value = pix_to_size_point( d, miterlimit );
1630 if (d->dc[d->level].style.stroke_miterlimit.value < 1)
1631 d->dc[d->level].style.stroke_miterlimit.value = 4.0;
1632 break;
1633 }
1634 case EMR_BEGINPATH:
1635 {
1636 dbg_str << "<!-- EMR_BEGINPATH -->\n";
1638 tmp_path << "d=\"";
1639 *(d->path) = "";
1640 d->inpath = true;
1641 break;
1642 }
1643 case EMR_ENDPATH:
1644 {
1645 dbg_str << "<!-- EMR_ENDPATH -->\n";
1647 tmp_path << "\"";
1648 d->inpath = false;
1649 break;
1650 }
1651 case EMR_CLOSEFIGURE:
1652 {
1653 dbg_str << "<!-- EMR_CLOSEFIGURE -->\n";
1655 tmp_path << "\n\tz";
1656 break;
1657 }
1658 case EMR_FILLPATH:
1659 case EMR_STROKEANDFILLPATH:
1660 case EMR_STROKEPATH:
1661 {
1662 if (lpEMFR->iType == EMR_FILLPATH)
1663 dbg_str << "<!-- EMR_FILLPATH -->\n";
1664 if (lpEMFR->iType == EMR_STROKEANDFILLPATH)
1665 dbg_str << "<!-- EMR_STROKEANDFILLPATH -->\n";
1666 if (lpEMFR->iType == EMR_STROKEPATH)
1667 dbg_str << "<!-- EMR_STROKEPATH -->\n";
1669 *(d->outsvg) += " <path ";
1670 output_style(d, lpEMFR->iType);
1671 *(d->outsvg) += "\n\t";
1672 *(d->outsvg) += *(d->path);
1673 *(d->outsvg) += " /> \n";
1674 *(d->path) = "";
1675 break;
1676 }
1677 case EMR_FLATTENPATH:
1678 dbg_str << "<!-- EMR_FLATTENPATH -->\n";
1679 break;
1680 case EMR_WIDENPATH:
1681 dbg_str << "<!-- EMR_WIDENPATH -->\n";
1682 break;
1683 case EMR_SELECTCLIPPATH:
1684 dbg_str << "<!-- EMR_SELECTCLIPPATH -->\n";
1685 break;
1686 case EMR_ABORTPATH:
1687 dbg_str << "<!-- EMR_ABORTPATH -->\n";
1688 break;
1689 case EMR_GDICOMMENT:
1690 {
1691 dbg_str << "<!-- EMR_GDICOMMENT -->\n";
1693 PEMRGDICOMMENT pEmr = (PEMRGDICOMMENT) lpEMFR;
1695 CHAR *szTxt = (CHAR *) pEmr->Data;
1697 for (DWORD i = 0; i < pEmr->cbData; i++) {
1698 if ( *szTxt) {
1699 if ( *szTxt >= ' ' && *szTxt < 'z' && *szTxt != '<' && *szTxt != '>' ) {
1700 tmp_str << *szTxt;
1701 }
1702 szTxt++;
1703 }
1704 }
1706 if (0 && strlen(tmp_str.str().c_str())) {
1707 tmp_outsvg << " <!-- \"";
1708 tmp_outsvg << tmp_str.str().c_str();
1709 tmp_outsvg << "\" -->\n";
1710 }
1712 break;
1713 }
1714 case EMR_FILLRGN:
1715 dbg_str << "<!-- EMR_FILLRGN -->\n";
1716 break;
1717 case EMR_FRAMERGN:
1718 dbg_str << "<!-- EMR_FRAMERGN -->\n";
1719 break;
1720 case EMR_INVERTRGN:
1721 dbg_str << "<!-- EMR_INVERTRGN -->\n";
1722 break;
1723 case EMR_PAINTRGN:
1724 dbg_str << "<!-- EMR_PAINTRGN -->\n";
1725 break;
1726 case EMR_EXTSELECTCLIPRGN:
1727 dbg_str << "<!-- EMR_EXTSELECTCLIPRGN -->\n";
1728 break;
1729 case EMR_BITBLT:
1730 dbg_str << "<!-- EMR_BITBLT -->\n";
1731 break;
1732 case EMR_STRETCHBLT:
1733 dbg_str << "<!-- EMR_STRETCHBLT -->\n";
1734 break;
1735 case EMR_MASKBLT:
1736 dbg_str << "<!-- EMR_MASKBLT -->\n";
1737 break;
1738 case EMR_PLGBLT:
1739 dbg_str << "<!-- EMR_PLGBLT -->\n";
1740 break;
1741 case EMR_SETDIBITSTODEVICE:
1742 dbg_str << "<!-- EMR_SETDIBITSTODEVICE -->\n";
1743 break;
1744 case EMR_STRETCHDIBITS:
1745 dbg_str << "<!-- EMR_STRETCHDIBITS -->\n";
1746 break;
1747 case EMR_EXTCREATEFONTINDIRECTW:
1748 {
1749 dbg_str << "<!-- EMR_EXTCREATEFONTINDIRECTW -->\n";
1751 PEMREXTCREATEFONTINDIRECTW pEmr = (PEMREXTCREATEFONTINDIRECTW) lpEMFR;
1752 int index = pEmr->ihFont;
1754 EMREXTCREATEFONTINDIRECTW *pFont =
1755 (EMREXTCREATEFONTINDIRECTW *) malloc( sizeof(EMREXTCREATEFONTINDIRECTW) );
1756 pFont->elfw = pEmr->elfw;
1757 insert_object(d, index, EMR_EXTCREATEFONTINDIRECTW, (ENHMETARECORD *) pFont);
1758 break;
1759 }
1760 case EMR_EXTTEXTOUTA:
1761 {
1762 dbg_str << "<!-- EMR_EXTTEXTOUTA -->\n";
1763 break;
1764 }
1765 case EMR_EXTTEXTOUTW:
1766 {
1767 dbg_str << "<!-- EMR_EXTTEXTOUTW -->\n";
1769 PEMREXTTEXTOUTW pEmr = (PEMREXTTEXTOUTW) lpEMFR;
1771 double x1 = pEmr->emrtext.ptlReference.x;
1772 double y1 = pEmr->emrtext.ptlReference.y;
1774 if (d->dc[d->level].textAlign & TA_UPDATECP) {
1775 x1 = d->dc[d->level].cur.x;
1776 y1 = d->dc[d->level].cur.y;
1777 }
1779 if (!(d->dc[d->level].textAlign & TA_BOTTOM))
1780 y1 += fabs(d->dc[d->level].style.font_size.computed);
1782 double x = pix_to_x_point(d, x1, y1);
1783 double y = pix_to_y_point(d, x1, y1);
1785 wchar_t *wide_text = (wchar_t *) ((char *) pEmr + pEmr->emrtext.offString);
1787 gchar *ansi_text =
1788 (gchar *) g_utf16_to_utf8( (gunichar2 *) wide_text, pEmr->emrtext.nChars, NULL, NULL, NULL );
1790 if (ansi_text) {
1791 gchar *p = ansi_text;
1792 while (*p) {
1793 if (*p < 32 || *p >= 127) {
1794 g_free(ansi_text);
1795 ansi_text = g_strdup("");
1796 break;
1797 }
1798 p++;
1799 }
1801 SVGOStringStream ts;
1803 gchar *escaped_text = g_markup_escape_text(ansi_text, -1);
1805 float text_rgb[3];
1806 sp_color_get_rgb_floatv( &(d->dc[d->level].style.fill.value.color), text_rgb );
1808 if (!d->dc[d->level].textColorSet) {
1809 d->dc[d->level].textColor = RGB(SP_COLOR_F_TO_U(text_rgb[0]),
1810 SP_COLOR_F_TO_U(text_rgb[1]),
1811 SP_COLOR_F_TO_U(text_rgb[2]));
1812 }
1814 char tmp[128];
1815 snprintf(tmp, 127,
1816 "fill:#%02x%02x%02x;",
1817 GetRValue(d->dc[d->level].textColor),
1818 GetGValue(d->dc[d->level].textColor),
1819 GetBValue(d->dc[d->level].textColor));
1821 bool i = (d->dc[d->level].style.font_style.value == SP_CSS_FONT_STYLE_ITALIC);
1822 //bool o = (d->dc[d->level].style.font_style.value == SP_CSS_FONT_STYLE_OBLIQUE);
1823 bool b = (d->dc[d->level].style.font_weight.value == SP_CSS_FONT_WEIGHT_BOLD) ||
1824 (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);
1825 int lcr = ((d->dc[d->level].textAlign & TA_CENTER) == TA_CENTER) ? 2 : ((d->dc[d->level].textAlign & TA_RIGHT) == TA_RIGHT) ? 1 : 0;
1827 assert_empty_path(d, "EMR_EXTTEXTOUTW");
1829 ts << " <text\n";
1830 ts << " id=\"" << (d->id++) << "\"\n";
1831 ts << " xml:space=\"preserve\"\n";
1832 ts << " x=\"" << x << "\"\n";
1833 ts << " y=\"" << y << "\"\n";
1834 if (d->dc[d->level].style.text_transform.value) {
1835 ts << " transform=\""
1836 << "rotate(-" << d->dc[d->level].style.text_transform.value
1837 << " " << x << " " << y << ")"
1838 << "\"\n";
1839 }
1840 ts << " style=\""
1841 << "font-size:" << fabs(d->dc[d->level].style.font_size.computed) << "px;"
1842 << tmp
1843 << "font-style:" << (i ? "italic" : "normal") << ";"
1844 << "font-weight:" << (b ? "bold" : "normal") << ";"
1845 << "text-align:" << (lcr==2 ? "center" : lcr==1 ? "end" : "start") << ";"
1846 << "text-anchor:" << (lcr==2 ? "middle" : lcr==1 ? "end" : "start") << ";"
1847 << "font-family:" << d->dc[d->level].tstyle.font_family.value << ";"
1848 << "\"\n";
1849 ts << " >";
1850 ts << escaped_text;
1851 ts << "</text>\n";
1853 *(d->outsvg) += ts.str().c_str();
1855 g_free(escaped_text);
1856 g_free(ansi_text);
1857 }
1859 break;
1860 }
1861 case EMR_POLYBEZIER16:
1862 {
1863 dbg_str << "<!-- EMR_POLYBEZIER16 -->\n";
1865 PEMRPOLYBEZIER16 pEmr = (PEMRPOLYBEZIER16) lpEMFR;
1866 POINTS *apts = (POINTS *) pEmr->apts; // Bug in MinGW wingdi.h ?
1867 DWORD i,j;
1869 if (pEmr->cpts<4)
1870 break;
1872 if (!d->inpath) {
1873 assert_empty_path(d, "EMR_POLYBEZIER16");
1875 *(d->outsvg) += " <path ";
1876 output_style(d, EMR_STROKEPATH);
1877 *(d->outsvg) += "\n\td=\"";
1878 }
1880 tmp_str <<
1881 "\n\tM " <<
1882 pix_to_x_point( d, apts[0].x, apts[0].y ) << " " <<
1883 pix_to_y_point( d, apts[0].x, apts[0].y ) << " ";
1885 for (i=1; i<pEmr->cpts; ) {
1886 tmp_str << "\n\tC ";
1887 for (j=0; j<3 && i<pEmr->cpts; j++,i++) {
1888 tmp_str <<
1889 pix_to_x_point( d, apts[i].x, apts[i].y ) << " " <<
1890 pix_to_y_point( d, apts[i].x, apts[i].y ) << " ";
1891 }
1892 }
1894 if (d->inpath) {
1895 tmp_path << tmp_str.str().c_str();
1896 }
1897 else {
1898 *(d->outsvg) += tmp_str.str().c_str();
1899 *(d->outsvg) += " \" /> \n";
1900 }
1902 break;
1903 }
1904 case EMR_POLYGON16:
1905 {
1906 dbg_str << "<!-- EMR_POLYGON16 -->\n";
1908 PEMRPOLYGON16 pEmr = (PEMRPOLYGON16) lpEMFR;
1909 POINTS *apts = (POINTS *) pEmr->apts; // Bug in MinGW wingdi.h ?
1910 SVGOStringStream tmp_poly;
1911 unsigned int i;
1912 unsigned int first = 0;
1914 assert_empty_path(d, "EMR_POLYGON16");
1916 *(d->outsvg) += " <path ";
1917 output_style(d, EMR_STROKEANDFILLPATH);
1918 *(d->outsvg) += "\n\td=\"";
1920 // skip the first point?
1921 tmp_poly << "\n\tM " <<
1922 pix_to_x_point( d, apts[first].x, apts[first].y ) << " " <<
1923 pix_to_y_point( d, apts[first].x, apts[first].y ) << " ";
1925 for (i=first+1; i<pEmr->cpts; i++) {
1926 tmp_poly << "\n\tL " <<
1927 pix_to_x_point( d, apts[i].x, apts[i].y ) << " " <<
1928 pix_to_y_point( d, apts[i].x, apts[i].y ) << " ";
1929 }
1931 *(d->outsvg) += tmp_poly.str().c_str();
1932 *(d->outsvg) += " z \" /> \n";
1934 break;
1935 }
1936 case EMR_POLYLINE16:
1937 {
1938 dbg_str << "<!-- EMR_POLYLINE16 -->\n";
1940 EMRPOLYLINE16 *pEmr = (EMRPOLYLINE16 *) lpEMFR;
1941 POINTS *apts = (POINTS *) pEmr->apts; // Bug in MinGW wingdi.h ?
1942 DWORD i;
1944 if (pEmr->cpts<2)
1945 break;
1947 if (!d->inpath) {
1948 assert_empty_path(d, "EMR_POLYLINE16");
1950 *(d->outsvg) += " <path ";
1951 output_style(d, EMR_STROKEPATH);
1952 *(d->outsvg) += "\n\td=\"";
1953 }
1955 tmp_str <<
1956 "\n\tM " <<
1957 pix_to_x_point( d, apts[0].x, apts[0].y ) << " " <<
1958 pix_to_y_point( d, apts[0].x, apts[0].y ) << " ";
1960 for (i=1; i<pEmr->cpts; i++) {
1961 tmp_str <<
1962 "\n\tL " <<
1963 pix_to_x_point( d, apts[i].x, apts[i].y ) << " " <<
1964 pix_to_y_point( d, apts[i].x, apts[i].y ) << " ";
1965 }
1967 if (d->inpath) {
1968 tmp_path << tmp_str.str().c_str();
1969 }
1970 else {
1971 *(d->outsvg) += tmp_str.str().c_str();
1972 *(d->outsvg) += " \" /> \n";
1973 }
1975 break;
1976 }
1977 case EMR_POLYBEZIERTO16:
1978 {
1979 dbg_str << "<!-- EMR_POLYBEZIERTO16 -->\n";
1981 PEMRPOLYBEZIERTO16 pEmr = (PEMRPOLYBEZIERTO16) lpEMFR;
1982 POINTS *apts = (POINTS *) pEmr->apts; // Bug in MinGW wingdi.h ?
1983 DWORD i,j;
1985 if (d->path->empty()) {
1986 d->pathless_stroke = true;
1987 *(d->path) = "d=\"";
1988 }
1990 for (i=0; i<pEmr->cpts;) {
1991 tmp_path << "\n\tC ";
1992 for (j=0; j<3 && i<pEmr->cpts; j++,i++) {
1993 tmp_path <<
1994 pix_to_x_point( d, apts[i].x, apts[i].y ) << " " <<
1995 pix_to_y_point( d, apts[i].x, apts[i].y ) << " ";
1996 }
1997 }
1999 break;
2000 }
2001 case EMR_POLYLINETO16:
2002 {
2003 dbg_str << "<!-- EMR_POLYLINETO16 -->\n";
2005 PEMRPOLYLINETO16 pEmr = (PEMRPOLYLINETO16) lpEMFR;
2006 POINTS *apts = (POINTS *) pEmr->apts; // Bug in MinGW wingdi.h ?
2007 DWORD i;
2009 if (d->path->empty()) {
2010 d->pathless_stroke = true;
2011 *(d->path) = "d=\"";
2012 }
2014 for (i=0; i<pEmr->cpts;i++) {
2015 tmp_path <<
2016 "\n\tL " <<
2017 pix_to_x_point( d, apts[i].x, apts[i].y ) << " " <<
2018 pix_to_y_point( d, apts[i].x, apts[i].y ) << " ";
2019 }
2021 break;
2022 }
2023 case EMR_POLYPOLYLINE16:
2024 case EMR_POLYPOLYGON16:
2025 {
2026 if (lpEMFR->iType == EMR_POLYPOLYLINE16)
2027 dbg_str << "<!-- EMR_POLYPOLYLINE16 -->\n";
2028 if (lpEMFR->iType == EMR_POLYPOLYGON16)
2029 dbg_str << "<!-- EMR_POLYPOLYGON16 -->\n";
2031 PEMRPOLYPOLYGON16 pEmr = (PEMRPOLYPOLYGON16) lpEMFR;
2032 unsigned int n, i, j;
2034 if (!d->inpath) {
2035 assert_empty_path(d, lpEMFR->iType == EMR_POLYPOLYGON16 ? "EMR_POLYPOLYGON16" : "EMR_POLYPOLYLINE16");
2037 *(d->outsvg) += " <path ";
2038 output_style(d, lpEMFR->iType==EMR_POLYPOLYGON16 ? EMR_STROKEANDFILLPATH : EMR_STROKEPATH);
2039 *(d->outsvg) += "\n\td=\"";
2040 }
2042 POINTS *apts = (POINTS *) &pEmr->aPolyCounts[pEmr->nPolys];
2044 i = 0;
2045 for (n=0; n<pEmr->nPolys && i<pEmr->cpts; n++) {
2046 SVGOStringStream poly_path;
2048 poly_path << "\n\tM " <<
2049 pix_to_x_point( d, apts[i].x, apts[i].y ) << " " <<
2050 pix_to_y_point( d, apts[i].x, apts[i].y ) << " ";
2051 i++;
2053 for (j=1; j<pEmr->aPolyCounts[n] && i<pEmr->cpts; j++) {
2054 poly_path << "\n\tL " <<
2055 pix_to_x_point( d, apts[i].x, apts[i].y ) << " " <<
2056 pix_to_y_point( d, apts[i].x, apts[i].y ) << " ";
2057 i++;
2058 }
2060 tmp_str << poly_path.str().c_str();
2061 if (lpEMFR->iType == EMR_POLYPOLYGON16)
2062 tmp_str << " z";
2063 tmp_str << " \n";
2064 }
2066 if (d->inpath) {
2067 tmp_path << tmp_str.str().c_str();
2068 }
2069 else {
2070 *(d->outsvg) += tmp_str.str().c_str();
2071 *(d->outsvg) += " \" /> \n";
2072 }
2074 break;
2075 }
2076 case EMR_POLYDRAW16:
2077 dbg_str << "<!-- EMR_POLYDRAW16 -->\n";
2078 break;
2079 case EMR_CREATEMONOBRUSH:
2080 dbg_str << "<!-- EMR_CREATEMONOBRUSH -->\n";
2081 break;
2082 case EMR_CREATEDIBPATTERNBRUSHPT:
2083 dbg_str << "<!-- EMR_CREATEDIBPATTERNBRUSHPT -->\n";
2084 break;
2085 case EMR_EXTCREATEPEN:
2086 {
2087 dbg_str << "<!-- EMR_EXTCREATEPEN -->\n";
2089 PEMREXTCREATEPEN pEmr = (PEMREXTCREATEPEN) lpEMFR;
2090 int index = pEmr->ihPen;
2092 EMREXTCREATEPEN *pPen =
2093 (EMREXTCREATEPEN *) malloc( sizeof(EMREXTCREATEPEN) +
2094 sizeof(DWORD) * pEmr->elp.elpNumEntries );
2095 pPen->ihPen = pEmr->ihPen;
2096 pPen->offBmi = pEmr->offBmi;
2097 pPen->cbBmi = pEmr->cbBmi;
2098 pPen->offBits = pEmr->offBits;
2099 pPen->cbBits = pEmr->cbBits;
2100 pPen->elp = pEmr->elp;
2101 for (unsigned int i=0; i<pEmr->elp.elpNumEntries; i++) {
2102 pPen->elp.elpStyleEntry[i] = pEmr->elp.elpStyleEntry[i];
2103 }
2104 insert_object(d, index, EMR_EXTCREATEPEN, (ENHMETARECORD *) pPen);
2106 break;
2107 }
2108 case EMR_POLYTEXTOUTA:
2109 dbg_str << "<!-- EMR_POLYTEXTOUTA -->\n";
2110 break;
2111 case EMR_POLYTEXTOUTW:
2112 dbg_str << "<!-- EMR_POLYTEXTOUTW -->\n";
2113 break;
2114 case EMR_SETICMMODE:
2115 dbg_str << "<!-- EMR_SETICMMODE -->\n";
2116 break;
2117 case EMR_CREATECOLORSPACE:
2118 dbg_str << "<!-- EMR_CREATECOLORSPACE -->\n";
2119 break;
2120 case EMR_SETCOLORSPACE:
2121 dbg_str << "<!-- EMR_SETCOLORSPACE -->\n";
2122 break;
2123 case EMR_DELETECOLORSPACE:
2124 dbg_str << "<!-- EMR_DELETECOLORSPACE -->\n";
2125 break;
2126 case EMR_GLSRECORD:
2127 dbg_str << "<!-- EMR_GLSRECORD -->\n";
2128 break;
2129 case EMR_GLSBOUNDEDRECORD:
2130 dbg_str << "<!-- EMR_GLSBOUNDEDRECORD -->\n";
2131 break;
2132 case EMR_PIXELFORMAT:
2133 dbg_str << "<!-- EMR_PIXELFORMAT -->\n";
2134 break;
2135 default:
2136 dbg_str << "<!-- EMR_??? -->\n";
2137 break;
2138 }
2140 // *(d->outsvg) += dbg_str.str().c_str();
2141 *(d->outsvg) += tmp_outsvg.str().c_str();
2142 *(d->path) += tmp_path.str().c_str();
2144 return 1;
2145 }
2147 static int CALLBACK
2148 myMetaFileProc(HDC /*hDC*/, HANDLETABLE * /*lpHTable*/, METARECORD * /*lpMFR*/, int /*nObj*/, LPARAM /*lpData*/)
2149 {
2150 g_warning("Unable to import Windows Meta File.\n");
2151 return 0;
2152 }
2154 // Aldus Placeable Header ===================================================
2155 // Since we are a 32bit app, we have to be sure this structure compiles to
2156 // be identical to a 16 bit app's version. To do this, we use the #pragma
2157 // to adjust packing, we use a WORD for the hmf handle, and a SMALL_RECT
2158 // for the bbox rectangle.
2159 #pragma pack( push )
2160 #pragma pack( 2 )
2161 typedef struct
2162 {
2163 DWORD dwKey;
2164 WORD hmf;
2165 SMALL_RECT bbox;
2166 WORD wInch;
2167 DWORD dwReserved;
2168 WORD wCheckSum;
2169 } APMHEADER, *PAPMHEADER;
2170 #pragma pack( pop )
2173 SPDocument *
2174 EmfWin32::open( Inkscape::Extension::Input * /*mod*/, const gchar *uri )
2175 {
2176 EMF_CALLBACK_DATA d;
2178 memset(&d, 0, sizeof(d));
2180 d.dc[0].worldTransform.eM11 = 1.0;
2181 d.dc[0].worldTransform.eM12 = 0.0;
2182 d.dc[0].worldTransform.eM21 = 0.0;
2183 d.dc[0].worldTransform.eM22 = 1.0;
2184 d.dc[0].worldTransform.eDx = 0.0;
2185 d.dc[0].worldTransform.eDy = 0.0;
2187 gsize bytesRead = 0;
2188 gsize bytesWritten = 0;
2189 GError* error = NULL;
2190 gchar *local_fn =
2191 g_filename_from_utf8( uri, -1, &bytesRead, &bytesWritten, &error );
2193 if (local_fn == NULL) {
2194 return NULL;
2195 }
2197 d.outsvg = new Glib::ustring("");
2198 d.path = new Glib::ustring("");
2200 CHAR *ansi_uri = (CHAR *) local_fn;
2201 gunichar2 *unicode_fn = g_utf8_to_utf16( local_fn, -1, NULL, NULL, NULL );
2202 WCHAR *unicode_uri = (WCHAR *) unicode_fn;
2204 DWORD filesize = 0;
2205 HANDLE fp = NULL;
2207 HMETAFILE hmf;
2208 HENHMETAFILE hemf;
2210 if (PrintWin32::is_os_wide()) {
2211 fp = CreateFileW(unicode_uri, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
2212 }
2213 else {
2214 fp = CreateFileA(ansi_uri, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
2215 }
2217 if ( fp != INVALID_HANDLE_VALUE ) {
2218 filesize = GetFileSize(fp, NULL);
2219 CloseHandle(fp);
2220 }
2222 // Try open as Enhanced Metafile
2223 if (PrintWin32::is_os_wide())
2224 hemf = GetEnhMetaFileW(unicode_uri);
2225 else
2226 hemf = GetEnhMetaFileA(ansi_uri);
2228 if (!hemf) {
2229 // Try open as Windows Metafile
2230 if (PrintWin32::is_os_wide())
2231 hmf = GetMetaFileW(unicode_uri);
2232 else
2233 hmf = GetMetaFileA(ansi_uri);
2235 METAFILEPICT mp;
2236 HDC hDC;
2238 if (!hmf) {
2239 if (PrintWin32::is_os_wide()) {
2240 WCHAR szTemp[MAX_PATH];
2242 DWORD dw = GetShortPathNameW( unicode_uri, szTemp, MAX_PATH );
2243 if (dw) {
2244 hmf = GetMetaFileW( szTemp );
2245 }
2246 } else {
2247 CHAR szTemp[MAX_PATH];
2249 DWORD dw = GetShortPathNameA( ansi_uri, szTemp, MAX_PATH );
2250 if (dw) {
2251 hmf = GetMetaFileA( szTemp );
2252 }
2253 }
2254 }
2256 if (hmf) {
2257 DWORD nSize = GetMetaFileBitsEx( hmf, 0, NULL );
2259 if (!nSize)
2260 nSize = filesize;
2262 if (nSize) {
2263 BYTE *lpvData = new BYTE[nSize];
2264 if (lpvData) {
2265 DWORD dw = GetMetaFileBitsEx( hmf, nSize, lpvData );
2266 if (dw) {
2267 // Fill out a METAFILEPICT structure
2268 mp.mm = MM_ANISOTROPIC;
2269 mp.xExt = 1000;
2270 mp.yExt = 1000;
2271 mp.hMF = NULL;
2272 // Get a reference DC
2273 hDC = GetDC( NULL );
2274 // Make an enhanced metafile from the windows metafile
2275 hemf = SetWinMetaFileBits( nSize, lpvData, hDC, &mp );
2276 // Clean up
2277 ReleaseDC( NULL, hDC );
2278 DeleteMetaFile( hmf );
2279 hmf = NULL;
2280 }
2281 else {
2282 // EnumMetaFile
2283 }
2284 delete[] lpvData;
2285 }
2286 else {
2287 DeleteMetaFile( hmf );
2288 hmf = NULL;
2289 }
2290 }
2291 else {
2292 DeleteMetaFile( hmf );
2293 hmf = NULL;
2294 }
2295 }
2296 else {
2297 // Try open as Aldus Placeable Metafile
2298 HANDLE hFile;
2299 if (PrintWin32::is_os_wide())
2300 hFile = CreateFileW( unicode_uri, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL );
2301 else
2302 hFile = CreateFileA( ansi_uri, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL );
2304 if (hFile != INVALID_HANDLE_VALUE) {
2305 DWORD nSize = GetFileSize( hFile, NULL );
2306 if (nSize) {
2307 BYTE *lpvData = new BYTE[nSize];
2308 if (lpvData) {
2309 DWORD dw = ReadFile( hFile, lpvData, nSize, &nSize, NULL );
2310 if (dw) {
2311 if ( ((PAPMHEADER)lpvData)->dwKey == 0x9ac6cdd7l ) {
2312 // Fill out a METAFILEPICT structure
2313 mp.mm = MM_ANISOTROPIC;
2314 mp.xExt = ((PAPMHEADER)lpvData)->bbox.Right - ((PAPMHEADER)lpvData)->bbox.Left;
2315 mp.xExt = ( mp.xExt * 2540l ) / (DWORD)(((PAPMHEADER)lpvData)->wInch);
2316 mp.yExt = ((PAPMHEADER)lpvData)->bbox.Bottom - ((PAPMHEADER)lpvData)->bbox.Top;
2317 mp.yExt = ( mp.yExt * 2540l ) / (DWORD)(((PAPMHEADER)lpvData)->wInch);
2318 mp.hMF = NULL;
2319 // Get a reference DC
2320 hDC = GetDC( NULL );
2321 // Create an enhanced metafile from the bits
2322 hemf = SetWinMetaFileBits( nSize, lpvData+sizeof(APMHEADER), hDC, &mp );
2323 // Clean up
2324 ReleaseDC( NULL, hDC );
2325 }
2326 }
2327 delete[] lpvData;
2328 }
2329 }
2330 CloseHandle( hFile );
2331 }
2332 }
2333 }
2335 if ((!hemf && !hmf) || !d.outsvg || !d.path) {
2336 if (d.outsvg)
2337 delete d.outsvg;
2338 if (d.path)
2339 delete d.path;
2340 if (local_fn)
2341 g_free(local_fn);
2342 if (unicode_fn)
2343 g_free(unicode_fn);
2344 if (hemf)
2345 DeleteEnhMetaFile(hemf);
2346 if (hmf)
2347 DeleteMetaFile(hmf);
2348 return NULL;
2349 }
2351 d.pDesc = NULL;
2353 if (hemf) {
2354 DWORD dwNeeded = GetEnhMetaFileDescriptionA( hemf, 0, NULL );
2355 if ( dwNeeded > 0 ) {
2356 d.pDesc = (CHAR *) malloc( dwNeeded + 1 );
2357 if ( GetEnhMetaFileDescription( hemf, dwNeeded, d.pDesc ) == 0 )
2358 lstrcpy( d.pDesc, "" );
2359 if ( lstrlen( d.pDesc ) > 1 )
2360 d.pDesc[lstrlen(d.pDesc)] = '#';
2361 }
2363 // This ugly reinterpret_cast is to prevent old versions of gcc from whining about a mismatch in the const-ness of the arguments
2364 EnumEnhMetaFile(NULL, hemf, reinterpret_cast<ENHMFENUMPROC>(myEnhMetaFileProc), (LPVOID) &d, NULL);
2365 DeleteEnhMetaFile(hemf);
2366 }
2367 else {
2368 EnumMetaFile(NULL, hmf, myMetaFileProc, (LPARAM) &d);
2369 DeleteMetaFile(hmf);
2370 }
2372 if (d.pDesc)
2373 free( d.pDesc );
2375 // std::cout << "SVG Output: " << std::endl << *(d.outsvg) << std::endl;
2377 SPDocument *doc = SPDocument::createNewDocFromMem(d.outsvg->c_str(), d.outsvg->length(), TRUE);
2379 delete d.outsvg;
2380 delete d.path;
2382 if (d.emf_obj) {
2383 int i;
2384 for (i=0; i<d.n_obj; i++)
2385 delete_object(&d, i);
2386 delete[] d.emf_obj;
2387 }
2389 if (d.dc[0].style.stroke_dash.dash)
2390 delete[] d.dc[0].style.stroke_dash.dash;
2392 if (local_fn)
2393 g_free(local_fn);
2394 if (unicode_fn)
2395 g_free(unicode_fn);
2397 return doc;
2398 }
2401 void
2402 EmfWin32::init (void)
2403 {
2404 Inkscape::Extension::Extension * ext;
2406 /* EMF in */
2407 ext = Inkscape::Extension::build_from_mem(
2408 "<inkscape-extension xmlns=\"" INKSCAPE_EXTENSION_URI "\">\n"
2409 "<name>" N_("EMF Input") "</name>\n"
2410 "<id>org.inkscape.input.emf.win32</id>\n"
2411 "<input>\n"
2412 "<extension>.emf</extension>\n"
2413 "<mimetype>image/x-emf</mimetype>\n"
2414 "<filetypename>" N_("Enhanced Metafiles (*.emf)") "</filetypename>\n"
2415 "<filetypetooltip>" N_("Enhanced Metafiles") "</filetypetooltip>\n"
2416 "<output_extension>org.inkscape.output.emf.win32</output_extension>\n"
2417 "</input>\n"
2418 "</inkscape-extension>", new EmfWin32());
2420 /* WMF in */
2421 ext = Inkscape::Extension::build_from_mem(
2422 "<inkscape-extension xmlns=\"" INKSCAPE_EXTENSION_URI "\">\n"
2423 "<name>" N_("WMF Input") "</name>\n"
2424 "<id>org.inkscape.input.wmf.win32</id>\n"
2425 "<input>\n"
2426 "<extension>.wmf</extension>\n"
2427 "<mimetype>image/x-wmf</mimetype>\n"
2428 "<filetypename>" N_("Windows Metafiles (*.wmf)") "</filetypename>\n"
2429 "<filetypetooltip>" N_("Windows Metafiles") "</filetypetooltip>\n"
2430 "<output_extension>org.inkscape.output.emf.win32</output_extension>\n"
2431 "</input>\n"
2432 "</inkscape-extension>", new EmfWin32());
2434 /* EMF out */
2435 ext = Inkscape::Extension::build_from_mem(
2436 "<inkscape-extension xmlns=\"" INKSCAPE_EXTENSION_URI "\">\n"
2437 "<name>" N_("EMF Output") "</name>\n"
2438 "<id>org.inkscape.output.emf.win32</id>\n"
2439 "<param name=\"textToPath\" gui-text=\"" N_("Convert texts to paths") "\" type=\"boolean\">true</param>\n"
2440 "<output>\n"
2441 "<extension>.emf</extension>\n"
2442 "<mimetype>image/x-emf</mimetype>\n"
2443 "<filetypename>" N_("Enhanced Metafile (*.emf)") "</filetypename>\n"
2444 "<filetypetooltip>" N_("Enhanced Metafile") "</filetypetooltip>\n"
2445 "</output>\n"
2446 "</inkscape-extension>", new EmfWin32());
2448 return;
2449 }
2452 } } } /* namespace Inkscape, Extension, Implementation */
2454 #endif /* WIN32 */
2455 /*
2456 Local Variables:
2457 mode:c++
2458 c-file-style:"stroustrup"
2459 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
2460 indent-tabs-mode:nil
2461 fill-column:99
2462 End:
2463 */
2464 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :