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 if (d->dc[d->level].style.text_transform.value) {
1781 x1 += std::sin(d->dc[d->level].style.text_transform.value*M_PI/180.0)*fabs(d->dc[d->level].style.font_size.computed);
1782 y1 += std::cos(d->dc[d->level].style.text_transform.value*M_PI/180.0)*fabs(d->dc[d->level].style.font_size.computed);
1783 }
1784 else
1785 y1 += fabs(d->dc[d->level].style.font_size.computed);
1787 double x = pix_to_x_point(d, x1, y1);
1788 double y = pix_to_y_point(d, x1, y1);
1790 wchar_t *wide_text = (wchar_t *) ((char *) pEmr + pEmr->emrtext.offString);
1792 gchar *ansi_text =
1793 (gchar *) g_utf16_to_utf8( (gunichar2 *) wide_text, pEmr->emrtext.nChars, NULL, NULL, NULL );
1795 if (ansi_text) {
1796 gchar *p = ansi_text;
1797 while (*p) {
1798 if (*p < 32 || *p >= 127) {
1799 g_free(ansi_text);
1800 ansi_text = g_strdup("");
1801 break;
1802 }
1803 p++;
1804 }
1806 SVGOStringStream ts;
1808 gchar *escaped_text = g_markup_escape_text(ansi_text, -1);
1810 float text_rgb[3];
1811 sp_color_get_rgb_floatv( &(d->dc[d->level].style.fill.value.color), text_rgb );
1813 if (!d->dc[d->level].textColorSet) {
1814 d->dc[d->level].textColor = RGB(SP_COLOR_F_TO_U(text_rgb[0]),
1815 SP_COLOR_F_TO_U(text_rgb[1]),
1816 SP_COLOR_F_TO_U(text_rgb[2]));
1817 }
1819 char tmp[128];
1820 snprintf(tmp, 127,
1821 "fill:#%02x%02x%02x;",
1822 GetRValue(d->dc[d->level].textColor),
1823 GetGValue(d->dc[d->level].textColor),
1824 GetBValue(d->dc[d->level].textColor));
1826 bool i = (d->dc[d->level].style.font_style.value == SP_CSS_FONT_STYLE_ITALIC);
1827 //bool o = (d->dc[d->level].style.font_style.value == SP_CSS_FONT_STYLE_OBLIQUE);
1828 bool b = (d->dc[d->level].style.font_weight.value == SP_CSS_FONT_WEIGHT_BOLD) ||
1829 (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);
1830 int lcr = ((d->dc[d->level].textAlign & TA_CENTER) == TA_CENTER) ? 2 : ((d->dc[d->level].textAlign & TA_RIGHT) == TA_RIGHT) ? 1 : 0;
1832 assert_empty_path(d, "EMR_EXTTEXTOUTW");
1834 ts << " <text\n";
1835 ts << " id=\"" << (d->id++) << "\"\n";
1836 ts << " xml:space=\"preserve\"\n";
1837 ts << " x=\"" << x << "\"\n";
1838 ts << " y=\"" << y << "\"\n";
1839 if (d->dc[d->level].style.text_transform.value) {
1840 ts << " transform=\""
1841 << "rotate(-" << d->dc[d->level].style.text_transform.value
1842 << " " << x << " " << y << ")"
1843 << "\"\n";
1844 }
1845 ts << " style=\""
1846 << "font-size:" << fabs(d->dc[d->level].style.font_size.computed) << "px;"
1847 << tmp
1848 << "font-style:" << (i ? "italic" : "normal") << ";"
1849 << "font-weight:" << (b ? "bold" : "normal") << ";"
1850 << "text-align:" << (lcr==2 ? "center" : lcr==1 ? "end" : "start") << ";"
1851 << "text-anchor:" << (lcr==2 ? "middle" : lcr==1 ? "end" : "start") << ";"
1852 << "font-family:" << d->dc[d->level].tstyle.font_family.value << ";"
1853 << "\"\n";
1854 ts << " >";
1855 ts << escaped_text;
1856 ts << "</text>\n";
1858 *(d->outsvg) += ts.str().c_str();
1860 g_free(escaped_text);
1861 g_free(ansi_text);
1862 }
1864 break;
1865 }
1866 case EMR_POLYBEZIER16:
1867 {
1868 dbg_str << "<!-- EMR_POLYBEZIER16 -->\n";
1870 PEMRPOLYBEZIER16 pEmr = (PEMRPOLYBEZIER16) lpEMFR;
1871 POINTS *apts = (POINTS *) pEmr->apts; // Bug in MinGW wingdi.h ?
1872 DWORD i,j;
1874 if (pEmr->cpts<4)
1875 break;
1877 if (!d->inpath) {
1878 assert_empty_path(d, "EMR_POLYBEZIER16");
1880 *(d->outsvg) += " <path ";
1881 output_style(d, EMR_STROKEPATH);
1882 *(d->outsvg) += "\n\td=\"";
1883 }
1885 tmp_str <<
1886 "\n\tM " <<
1887 pix_to_x_point( d, apts[0].x, apts[0].y ) << " " <<
1888 pix_to_y_point( d, apts[0].x, apts[0].y ) << " ";
1890 for (i=1; i<pEmr->cpts; ) {
1891 tmp_str << "\n\tC ";
1892 for (j=0; j<3 && i<pEmr->cpts; j++,i++) {
1893 tmp_str <<
1894 pix_to_x_point( d, apts[i].x, apts[i].y ) << " " <<
1895 pix_to_y_point( d, apts[i].x, apts[i].y ) << " ";
1896 }
1897 }
1899 if (d->inpath) {
1900 tmp_path << tmp_str.str().c_str();
1901 }
1902 else {
1903 *(d->outsvg) += tmp_str.str().c_str();
1904 *(d->outsvg) += " \" /> \n";
1905 }
1907 break;
1908 }
1909 case EMR_POLYGON16:
1910 {
1911 dbg_str << "<!-- EMR_POLYGON16 -->\n";
1913 PEMRPOLYGON16 pEmr = (PEMRPOLYGON16) lpEMFR;
1914 POINTS *apts = (POINTS *) pEmr->apts; // Bug in MinGW wingdi.h ?
1915 SVGOStringStream tmp_poly;
1916 unsigned int i;
1917 unsigned int first = 0;
1919 assert_empty_path(d, "EMR_POLYGON16");
1921 *(d->outsvg) += " <path ";
1922 output_style(d, EMR_STROKEANDFILLPATH);
1923 *(d->outsvg) += "\n\td=\"";
1925 // skip the first point?
1926 tmp_poly << "\n\tM " <<
1927 pix_to_x_point( d, apts[first].x, apts[first].y ) << " " <<
1928 pix_to_y_point( d, apts[first].x, apts[first].y ) << " ";
1930 for (i=first+1; i<pEmr->cpts; i++) {
1931 tmp_poly << "\n\tL " <<
1932 pix_to_x_point( d, apts[i].x, apts[i].y ) << " " <<
1933 pix_to_y_point( d, apts[i].x, apts[i].y ) << " ";
1934 }
1936 *(d->outsvg) += tmp_poly.str().c_str();
1937 *(d->outsvg) += " z \" /> \n";
1939 break;
1940 }
1941 case EMR_POLYLINE16:
1942 {
1943 dbg_str << "<!-- EMR_POLYLINE16 -->\n";
1945 EMRPOLYLINE16 *pEmr = (EMRPOLYLINE16 *) lpEMFR;
1946 POINTS *apts = (POINTS *) pEmr->apts; // Bug in MinGW wingdi.h ?
1947 DWORD i;
1949 if (pEmr->cpts<2)
1950 break;
1952 if (!d->inpath) {
1953 assert_empty_path(d, "EMR_POLYLINE16");
1955 *(d->outsvg) += " <path ";
1956 output_style(d, EMR_STROKEPATH);
1957 *(d->outsvg) += "\n\td=\"";
1958 }
1960 tmp_str <<
1961 "\n\tM " <<
1962 pix_to_x_point( d, apts[0].x, apts[0].y ) << " " <<
1963 pix_to_y_point( d, apts[0].x, apts[0].y ) << " ";
1965 for (i=1; i<pEmr->cpts; i++) {
1966 tmp_str <<
1967 "\n\tL " <<
1968 pix_to_x_point( d, apts[i].x, apts[i].y ) << " " <<
1969 pix_to_y_point( d, apts[i].x, apts[i].y ) << " ";
1970 }
1972 if (d->inpath) {
1973 tmp_path << tmp_str.str().c_str();
1974 }
1975 else {
1976 *(d->outsvg) += tmp_str.str().c_str();
1977 *(d->outsvg) += " \" /> \n";
1978 }
1980 break;
1981 }
1982 case EMR_POLYBEZIERTO16:
1983 {
1984 dbg_str << "<!-- EMR_POLYBEZIERTO16 -->\n";
1986 PEMRPOLYBEZIERTO16 pEmr = (PEMRPOLYBEZIERTO16) lpEMFR;
1987 POINTS *apts = (POINTS *) pEmr->apts; // Bug in MinGW wingdi.h ?
1988 DWORD i,j;
1990 if (d->path->empty()) {
1991 d->pathless_stroke = true;
1992 *(d->path) = "d=\"";
1993 }
1995 for (i=0; i<pEmr->cpts;) {
1996 tmp_path << "\n\tC ";
1997 for (j=0; j<3 && i<pEmr->cpts; j++,i++) {
1998 tmp_path <<
1999 pix_to_x_point( d, apts[i].x, apts[i].y ) << " " <<
2000 pix_to_y_point( d, apts[i].x, apts[i].y ) << " ";
2001 }
2002 }
2004 break;
2005 }
2006 case EMR_POLYLINETO16:
2007 {
2008 dbg_str << "<!-- EMR_POLYLINETO16 -->\n";
2010 PEMRPOLYLINETO16 pEmr = (PEMRPOLYLINETO16) lpEMFR;
2011 POINTS *apts = (POINTS *) pEmr->apts; // Bug in MinGW wingdi.h ?
2012 DWORD i;
2014 if (d->path->empty()) {
2015 d->pathless_stroke = true;
2016 *(d->path) = "d=\"";
2017 }
2019 for (i=0; i<pEmr->cpts;i++) {
2020 tmp_path <<
2021 "\n\tL " <<
2022 pix_to_x_point( d, apts[i].x, apts[i].y ) << " " <<
2023 pix_to_y_point( d, apts[i].x, apts[i].y ) << " ";
2024 }
2026 break;
2027 }
2028 case EMR_POLYPOLYLINE16:
2029 case EMR_POLYPOLYGON16:
2030 {
2031 if (lpEMFR->iType == EMR_POLYPOLYLINE16)
2032 dbg_str << "<!-- EMR_POLYPOLYLINE16 -->\n";
2033 if (lpEMFR->iType == EMR_POLYPOLYGON16)
2034 dbg_str << "<!-- EMR_POLYPOLYGON16 -->\n";
2036 PEMRPOLYPOLYGON16 pEmr = (PEMRPOLYPOLYGON16) lpEMFR;
2037 unsigned int n, i, j;
2039 if (!d->inpath) {
2040 assert_empty_path(d, lpEMFR->iType == EMR_POLYPOLYGON16 ? "EMR_POLYPOLYGON16" : "EMR_POLYPOLYLINE16");
2042 *(d->outsvg) += " <path ";
2043 output_style(d, lpEMFR->iType==EMR_POLYPOLYGON16 ? EMR_STROKEANDFILLPATH : EMR_STROKEPATH);
2044 *(d->outsvg) += "\n\td=\"";
2045 }
2047 POINTS *apts = (POINTS *) &pEmr->aPolyCounts[pEmr->nPolys];
2049 i = 0;
2050 for (n=0; n<pEmr->nPolys && i<pEmr->cpts; n++) {
2051 SVGOStringStream poly_path;
2053 poly_path << "\n\tM " <<
2054 pix_to_x_point( d, apts[i].x, apts[i].y ) << " " <<
2055 pix_to_y_point( d, apts[i].x, apts[i].y ) << " ";
2056 i++;
2058 for (j=1; j<pEmr->aPolyCounts[n] && i<pEmr->cpts; j++) {
2059 poly_path << "\n\tL " <<
2060 pix_to_x_point( d, apts[i].x, apts[i].y ) << " " <<
2061 pix_to_y_point( d, apts[i].x, apts[i].y ) << " ";
2062 i++;
2063 }
2065 tmp_str << poly_path.str().c_str();
2066 if (lpEMFR->iType == EMR_POLYPOLYGON16)
2067 tmp_str << " z";
2068 tmp_str << " \n";
2069 }
2071 if (d->inpath) {
2072 tmp_path << tmp_str.str().c_str();
2073 }
2074 else {
2075 *(d->outsvg) += tmp_str.str().c_str();
2076 *(d->outsvg) += " \" /> \n";
2077 }
2079 break;
2080 }
2081 case EMR_POLYDRAW16:
2082 dbg_str << "<!-- EMR_POLYDRAW16 -->\n";
2083 break;
2084 case EMR_CREATEMONOBRUSH:
2085 dbg_str << "<!-- EMR_CREATEMONOBRUSH -->\n";
2086 break;
2087 case EMR_CREATEDIBPATTERNBRUSHPT:
2088 dbg_str << "<!-- EMR_CREATEDIBPATTERNBRUSHPT -->\n";
2089 break;
2090 case EMR_EXTCREATEPEN:
2091 {
2092 dbg_str << "<!-- EMR_EXTCREATEPEN -->\n";
2094 PEMREXTCREATEPEN pEmr = (PEMREXTCREATEPEN) lpEMFR;
2095 int index = pEmr->ihPen;
2097 EMREXTCREATEPEN *pPen =
2098 (EMREXTCREATEPEN *) malloc( sizeof(EMREXTCREATEPEN) +
2099 sizeof(DWORD) * pEmr->elp.elpNumEntries );
2100 pPen->ihPen = pEmr->ihPen;
2101 pPen->offBmi = pEmr->offBmi;
2102 pPen->cbBmi = pEmr->cbBmi;
2103 pPen->offBits = pEmr->offBits;
2104 pPen->cbBits = pEmr->cbBits;
2105 pPen->elp = pEmr->elp;
2106 for (unsigned int i=0; i<pEmr->elp.elpNumEntries; i++) {
2107 pPen->elp.elpStyleEntry[i] = pEmr->elp.elpStyleEntry[i];
2108 }
2109 insert_object(d, index, EMR_EXTCREATEPEN, (ENHMETARECORD *) pPen);
2111 break;
2112 }
2113 case EMR_POLYTEXTOUTA:
2114 dbg_str << "<!-- EMR_POLYTEXTOUTA -->\n";
2115 break;
2116 case EMR_POLYTEXTOUTW:
2117 dbg_str << "<!-- EMR_POLYTEXTOUTW -->\n";
2118 break;
2119 case EMR_SETICMMODE:
2120 dbg_str << "<!-- EMR_SETICMMODE -->\n";
2121 break;
2122 case EMR_CREATECOLORSPACE:
2123 dbg_str << "<!-- EMR_CREATECOLORSPACE -->\n";
2124 break;
2125 case EMR_SETCOLORSPACE:
2126 dbg_str << "<!-- EMR_SETCOLORSPACE -->\n";
2127 break;
2128 case EMR_DELETECOLORSPACE:
2129 dbg_str << "<!-- EMR_DELETECOLORSPACE -->\n";
2130 break;
2131 case EMR_GLSRECORD:
2132 dbg_str << "<!-- EMR_GLSRECORD -->\n";
2133 break;
2134 case EMR_GLSBOUNDEDRECORD:
2135 dbg_str << "<!-- EMR_GLSBOUNDEDRECORD -->\n";
2136 break;
2137 case EMR_PIXELFORMAT:
2138 dbg_str << "<!-- EMR_PIXELFORMAT -->\n";
2139 break;
2140 default:
2141 dbg_str << "<!-- EMR_??? -->\n";
2142 break;
2143 }
2145 // *(d->outsvg) += dbg_str.str().c_str();
2146 *(d->outsvg) += tmp_outsvg.str().c_str();
2147 *(d->path) += tmp_path.str().c_str();
2149 return 1;
2150 }
2152 static int CALLBACK
2153 myMetaFileProc(HDC /*hDC*/, HANDLETABLE * /*lpHTable*/, METARECORD * /*lpMFR*/, int /*nObj*/, LPARAM /*lpData*/)
2154 {
2155 g_warning("Unable to import Windows Meta File.\n");
2156 return 0;
2157 }
2159 // Aldus Placeable Header ===================================================
2160 // Since we are a 32bit app, we have to be sure this structure compiles to
2161 // be identical to a 16 bit app's version. To do this, we use the #pragma
2162 // to adjust packing, we use a WORD for the hmf handle, and a SMALL_RECT
2163 // for the bbox rectangle.
2164 #pragma pack( push )
2165 #pragma pack( 2 )
2166 typedef struct
2167 {
2168 DWORD dwKey;
2169 WORD hmf;
2170 SMALL_RECT bbox;
2171 WORD wInch;
2172 DWORD dwReserved;
2173 WORD wCheckSum;
2174 } APMHEADER, *PAPMHEADER;
2175 #pragma pack( pop )
2178 SPDocument *
2179 EmfWin32::open( Inkscape::Extension::Input * /*mod*/, const gchar *uri )
2180 {
2181 EMF_CALLBACK_DATA d;
2183 memset(&d, 0, sizeof(d));
2185 d.dc[0].worldTransform.eM11 = 1.0;
2186 d.dc[0].worldTransform.eM12 = 0.0;
2187 d.dc[0].worldTransform.eM21 = 0.0;
2188 d.dc[0].worldTransform.eM22 = 1.0;
2189 d.dc[0].worldTransform.eDx = 0.0;
2190 d.dc[0].worldTransform.eDy = 0.0;
2192 gsize bytesRead = 0;
2193 gsize bytesWritten = 0;
2194 GError* error = NULL;
2195 gchar *local_fn =
2196 g_filename_from_utf8( uri, -1, &bytesRead, &bytesWritten, &error );
2198 if (local_fn == NULL) {
2199 return NULL;
2200 }
2202 d.outsvg = new Glib::ustring("");
2203 d.path = new Glib::ustring("");
2205 CHAR *ansi_uri = (CHAR *) local_fn;
2206 gunichar2 *unicode_fn = g_utf8_to_utf16( local_fn, -1, NULL, NULL, NULL );
2207 WCHAR *unicode_uri = (WCHAR *) unicode_fn;
2209 DWORD filesize = 0;
2210 HANDLE fp = NULL;
2212 HMETAFILE hmf;
2213 HENHMETAFILE hemf;
2215 if (PrintWin32::is_os_wide()) {
2216 fp = CreateFileW(unicode_uri, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
2217 }
2218 else {
2219 fp = CreateFileA(ansi_uri, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
2220 }
2222 if ( fp != INVALID_HANDLE_VALUE ) {
2223 filesize = GetFileSize(fp, NULL);
2224 CloseHandle(fp);
2225 }
2227 // Try open as Enhanced Metafile
2228 if (PrintWin32::is_os_wide())
2229 hemf = GetEnhMetaFileW(unicode_uri);
2230 else
2231 hemf = GetEnhMetaFileA(ansi_uri);
2233 if (!hemf) {
2234 // Try open as Windows Metafile
2235 if (PrintWin32::is_os_wide())
2236 hmf = GetMetaFileW(unicode_uri);
2237 else
2238 hmf = GetMetaFileA(ansi_uri);
2240 METAFILEPICT mp;
2241 HDC hDC;
2243 if (!hmf) {
2244 if (PrintWin32::is_os_wide()) {
2245 WCHAR szTemp[MAX_PATH];
2247 DWORD dw = GetShortPathNameW( unicode_uri, szTemp, MAX_PATH );
2248 if (dw) {
2249 hmf = GetMetaFileW( szTemp );
2250 }
2251 } else {
2252 CHAR szTemp[MAX_PATH];
2254 DWORD dw = GetShortPathNameA( ansi_uri, szTemp, MAX_PATH );
2255 if (dw) {
2256 hmf = GetMetaFileA( szTemp );
2257 }
2258 }
2259 }
2261 if (hmf) {
2262 DWORD nSize = GetMetaFileBitsEx( hmf, 0, NULL );
2264 if (!nSize)
2265 nSize = filesize;
2267 if (nSize) {
2268 BYTE *lpvData = new BYTE[nSize];
2269 if (lpvData) {
2270 DWORD dw = GetMetaFileBitsEx( hmf, nSize, lpvData );
2271 if (dw) {
2272 // Fill out a METAFILEPICT structure
2273 mp.mm = MM_ANISOTROPIC;
2274 mp.xExt = 1000;
2275 mp.yExt = 1000;
2276 mp.hMF = NULL;
2277 // Get a reference DC
2278 hDC = GetDC( NULL );
2279 // Make an enhanced metafile from the windows metafile
2280 hemf = SetWinMetaFileBits( nSize, lpvData, hDC, &mp );
2281 // Clean up
2282 ReleaseDC( NULL, hDC );
2283 DeleteMetaFile( hmf );
2284 hmf = NULL;
2285 }
2286 else {
2287 // EnumMetaFile
2288 }
2289 delete[] lpvData;
2290 }
2291 else {
2292 DeleteMetaFile( hmf );
2293 hmf = NULL;
2294 }
2295 }
2296 else {
2297 DeleteMetaFile( hmf );
2298 hmf = NULL;
2299 }
2300 }
2301 else {
2302 // Try open as Aldus Placeable Metafile
2303 HANDLE hFile;
2304 if (PrintWin32::is_os_wide())
2305 hFile = CreateFileW( unicode_uri, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL );
2306 else
2307 hFile = CreateFileA( ansi_uri, GENERIC_READ, 0, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL );
2309 if (hFile != INVALID_HANDLE_VALUE) {
2310 DWORD nSize = GetFileSize( hFile, NULL );
2311 if (nSize) {
2312 BYTE *lpvData = new BYTE[nSize];
2313 if (lpvData) {
2314 DWORD dw = ReadFile( hFile, lpvData, nSize, &nSize, NULL );
2315 if (dw) {
2316 if ( ((PAPMHEADER)lpvData)->dwKey == 0x9ac6cdd7l ) {
2317 // Fill out a METAFILEPICT structure
2318 mp.mm = MM_ANISOTROPIC;
2319 mp.xExt = ((PAPMHEADER)lpvData)->bbox.Right - ((PAPMHEADER)lpvData)->bbox.Left;
2320 mp.xExt = ( mp.xExt * 2540l ) / (DWORD)(((PAPMHEADER)lpvData)->wInch);
2321 mp.yExt = ((PAPMHEADER)lpvData)->bbox.Bottom - ((PAPMHEADER)lpvData)->bbox.Top;
2322 mp.yExt = ( mp.yExt * 2540l ) / (DWORD)(((PAPMHEADER)lpvData)->wInch);
2323 mp.hMF = NULL;
2324 // Get a reference DC
2325 hDC = GetDC( NULL );
2326 // Create an enhanced metafile from the bits
2327 hemf = SetWinMetaFileBits( nSize, lpvData+sizeof(APMHEADER), hDC, &mp );
2328 // Clean up
2329 ReleaseDC( NULL, hDC );
2330 }
2331 }
2332 delete[] lpvData;
2333 }
2334 }
2335 CloseHandle( hFile );
2336 }
2337 }
2338 }
2340 if ((!hemf && !hmf) || !d.outsvg || !d.path) {
2341 if (d.outsvg)
2342 delete d.outsvg;
2343 if (d.path)
2344 delete d.path;
2345 if (local_fn)
2346 g_free(local_fn);
2347 if (unicode_fn)
2348 g_free(unicode_fn);
2349 if (hemf)
2350 DeleteEnhMetaFile(hemf);
2351 if (hmf)
2352 DeleteMetaFile(hmf);
2353 return NULL;
2354 }
2356 d.pDesc = NULL;
2358 if (hemf) {
2359 DWORD dwNeeded = GetEnhMetaFileDescriptionA( hemf, 0, NULL );
2360 if ( dwNeeded > 0 ) {
2361 d.pDesc = (CHAR *) malloc( dwNeeded + 1 );
2362 if ( GetEnhMetaFileDescription( hemf, dwNeeded, d.pDesc ) == 0 )
2363 lstrcpy( d.pDesc, "" );
2364 if ( lstrlen( d.pDesc ) > 1 )
2365 d.pDesc[lstrlen(d.pDesc)] = '#';
2366 }
2368 // This ugly reinterpret_cast is to prevent old versions of gcc from whining about a mismatch in the const-ness of the arguments
2369 EnumEnhMetaFile(NULL, hemf, reinterpret_cast<ENHMFENUMPROC>(myEnhMetaFileProc), (LPVOID) &d, NULL);
2370 DeleteEnhMetaFile(hemf);
2371 }
2372 else {
2373 EnumMetaFile(NULL, hmf, myMetaFileProc, (LPARAM) &d);
2374 DeleteMetaFile(hmf);
2375 }
2377 if (d.pDesc)
2378 free( d.pDesc );
2380 // std::cout << "SVG Output: " << std::endl << *(d.outsvg) << std::endl;
2382 SPDocument *doc = SPDocument::createNewDocFromMem(d.outsvg->c_str(), d.outsvg->length(), TRUE);
2384 delete d.outsvg;
2385 delete d.path;
2387 if (d.emf_obj) {
2388 int i;
2389 for (i=0; i<d.n_obj; i++)
2390 delete_object(&d, i);
2391 delete[] d.emf_obj;
2392 }
2394 if (d.dc[0].style.stroke_dash.dash)
2395 delete[] d.dc[0].style.stroke_dash.dash;
2397 if (local_fn)
2398 g_free(local_fn);
2399 if (unicode_fn)
2400 g_free(unicode_fn);
2402 return doc;
2403 }
2406 void
2407 EmfWin32::init (void)
2408 {
2409 Inkscape::Extension::Extension * ext;
2411 /* EMF in */
2412 ext = Inkscape::Extension::build_from_mem(
2413 "<inkscape-extension xmlns=\"" INKSCAPE_EXTENSION_URI "\">\n"
2414 "<name>" N_("EMF Input") "</name>\n"
2415 "<id>org.inkscape.input.emf.win32</id>\n"
2416 "<input>\n"
2417 "<extension>.emf</extension>\n"
2418 "<mimetype>image/x-emf</mimetype>\n"
2419 "<filetypename>" N_("Enhanced Metafiles (*.emf)") "</filetypename>\n"
2420 "<filetypetooltip>" N_("Enhanced Metafiles") "</filetypetooltip>\n"
2421 "<output_extension>org.inkscape.output.emf.win32</output_extension>\n"
2422 "</input>\n"
2423 "</inkscape-extension>", new EmfWin32());
2425 /* WMF in */
2426 ext = Inkscape::Extension::build_from_mem(
2427 "<inkscape-extension xmlns=\"" INKSCAPE_EXTENSION_URI "\">\n"
2428 "<name>" N_("WMF Input") "</name>\n"
2429 "<id>org.inkscape.input.wmf.win32</id>\n"
2430 "<input>\n"
2431 "<extension>.wmf</extension>\n"
2432 "<mimetype>image/x-wmf</mimetype>\n"
2433 "<filetypename>" N_("Windows Metafiles (*.wmf)") "</filetypename>\n"
2434 "<filetypetooltip>" N_("Windows Metafiles") "</filetypetooltip>\n"
2435 "<output_extension>org.inkscape.output.emf.win32</output_extension>\n"
2436 "</input>\n"
2437 "</inkscape-extension>", new EmfWin32());
2439 /* EMF out */
2440 ext = Inkscape::Extension::build_from_mem(
2441 "<inkscape-extension xmlns=\"" INKSCAPE_EXTENSION_URI "\">\n"
2442 "<name>" N_("EMF Output") "</name>\n"
2443 "<id>org.inkscape.output.emf.win32</id>\n"
2444 "<param name=\"textToPath\" gui-text=\"" N_("Convert texts to paths") "\" type=\"boolean\">true</param>\n"
2445 "<output>\n"
2446 "<extension>.emf</extension>\n"
2447 "<mimetype>image/x-emf</mimetype>\n"
2448 "<filetypename>" N_("Enhanced Metafile (*.emf)") "</filetypename>\n"
2449 "<filetypetooltip>" N_("Enhanced Metafile") "</filetypetooltip>\n"
2450 "</output>\n"
2451 "</inkscape-extension>", new EmfWin32());
2453 return;
2454 }
2457 } } } /* namespace Inkscape, Extension, Implementation */
2459 #endif /* WIN32 */
2460 /*
2461 Local Variables:
2462 mode:c++
2463 c-file-style:"stroustrup"
2464 c-file-offsets:((innamespace . 0)(inline-open . 0)(case-label . +))
2465 indent-tabs-mode:nil
2466 fill-column:99
2467 End:
2468 */
2469 // vim: filetype=cpp:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:fileencoding=utf-8:textwidth=99 :