]> git.saurik.com Git - wxWidgets.git/blob - contrib/src/ogl/mfutils.cpp
wxX11 compilation fix.
[wxWidgets.git] / contrib / src / ogl / mfutils.cpp
1 /////////////////////////////////////////////////////////////////////////////
2 // Name: mfutils.cpp
3 // Purpose: Metafile utillities
4 // Author: Julian Smart
5 // Modified by:
6 // Created: 12/07/98
7 // RCS-ID: $Id$
8 // Copyright: (c) Julian Smart
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
11
12 #ifdef __GNUG__
13 #pragma implementation "mfutils.h"
14 #endif
15
16 // For compilers that support precompilation, includes "wx.h".
17 #include "wx/wxprec.h"
18
19 #ifdef __BORLANDC__
20 #pragma hdrstop
21 #endif
22
23 #ifndef WX_PRECOMP
24 #include <wx/wx.h>
25 #endif
26
27 #include <wx/metafile.h>
28 #include <wx/utils.h>
29
30 #include "wx/ogl/ogl.h"
31
32 #include <stdio.h>
33
34 static char _buf[1024]; // a temp buffer to use inplace of wxBuffer, which is deprecated.
35
36 static char hexArray[] = { '0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B',
37 'C', 'D', 'E', 'F' };
38
39 static void DecToHex(int dec, char *buf)
40 {
41 int firstDigit = (int)(dec/16.0);
42 int secondDigit = (int)(dec - (firstDigit*16.0));
43 buf[0] = hexArray[firstDigit];
44 buf[1] = hexArray[secondDigit];
45 buf[2] = 0;
46 }
47
48 // 16-bit unsigned integer
49 static unsigned int getshort(FILE *fp)
50 {
51 int c, c1;
52 c = getc(fp); c1 = getc(fp);
53 unsigned int res = ((unsigned int) c) + (((unsigned int) c1) << 8);
54 return res;
55 }
56
57 // 16-bit signed integer
58 static int getsignedshort(FILE *fp)
59 {
60 int c, c1;
61 c = getc(fp); c1 = getc(fp);
62 #if 0
63 // this is not used value, no need to execute it
64 int testRes = ((unsigned int) c) + (((unsigned int) c1) << 8);
65 #endif
66 unsigned long res1 = ((unsigned int) c) + (((unsigned int) c1) << 8);
67 int res = 0;
68 if (res1 > 32767)
69 res = (int)(res1 - 65536);
70 else
71 res = (int)(res1);
72 return res;
73 }
74
75 // 32-bit integer
76 static long getint(FILE *fp)
77 {
78 int c, c1, c2, c3;
79 c = getc(fp); c1 = getc(fp); c2 = getc(fp); c3 = getc(fp);
80 long res = (long)((long) c) +
81 (((long) c1) << 8) +
82 (((long) c2) << 16) +
83 (((long) c3) << 24);
84 return res;
85 }
86
87
88 /* Placeable metafile header
89 struct mfPLACEABLEHEADER {
90 DWORD key; // 32-bit
91 HANDLE hmf; // 16-bit
92 RECT bbox; // 4x16 bit
93 WORD inch; // 16-bit
94 DWORD reserved; // 32-bit
95 WORD checksum; // 16-bit
96 };
97 */
98
99 wxMetaRecord::~wxMetaRecord(void)
100 {
101 if (points) delete[] points;
102 if (stringParam) delete[] stringParam;
103 }
104
105 wxXMetaFile::wxXMetaFile(const wxChar *file)
106 {
107 ok = FALSE;
108 top = 0.0;
109 bottom = 0.0;
110 left = 0.0;
111 right = 0.0;
112
113 if (file)
114 ok = ReadFile(file);
115 }
116
117 /*
118 Handle table gdiObjects
119 ------------ ----------
120 [0] wxPen
121 [1]----param2--- wxBrush
122 [2] | wxFont
123 [3] | -> wxPen
124
125 The handle table works as follows.
126 When a GDI object is created whilst reading in the
127 metafile, the (e.g.) createpen record is added to the
128 first free entry in the handle table. The createpen
129 record's param1 is a pointer to the actual wxPen, and
130 its param2 is the index into the gdiObjects list, which only
131 grows and never shrinks (unlike the handle table.)
132
133 When SelectObject(index) is found, the index in the file
134 refers to the position in the handle table. BUT we then
135 set param2 to be the position of the wxPen in gdiObjects,
136 i.e. to param2 of the CreatePen record, itself found in
137 the handle table.
138
139 When an object is deleted, the entry in the handletable is
140 NULLed but the gdiObjects entry is not removed (no point, and
141 allows us to create all GDI objects in advance of playing the
142 metafile).
143 */
144
145
146 static wxMetaRecord *HandleTable[100];
147 static int HandleTableSize = 0;
148
149 void DeleteMetaRecordHandle(int index)
150 {
151 HandleTable[index] = NULL;
152 }
153
154 int AddMetaRecordHandle(wxMetaRecord *record)
155 {
156 for (int i = 0; i < HandleTableSize; i++)
157 if (!HandleTable[i])
158 {
159 HandleTable[i] = record;
160 return i;
161 }
162 // No free spaces in table, so append.
163
164 HandleTable[HandleTableSize] = record;
165 HandleTableSize ++;
166 return (HandleTableSize - 1);
167 }
168
169 bool wxXMetaFile::ReadFile(const wxChar *file)
170 {
171 HandleTableSize = 0;
172
173 FILE *handle = wxFopen(file, wxT("rb"));
174 if (!handle) return FALSE;
175
176 // Read placeable metafile header, if any
177 long key = getint(handle);
178
179 if (key == (long) 0x9AC6CDD7)
180 {
181 /* long hmf = */ getshort(handle);
182 int iLeft, iTop, iRight, iBottom;
183 iLeft = getsignedshort(handle);
184 iTop = getsignedshort(handle);
185 iRight = getsignedshort(handle);
186 iBottom = getsignedshort(handle);
187
188 left = (double)iLeft;
189 top = (double)iTop;
190 right = (double)iRight;
191 bottom = (double)iBottom;
192
193 /* int inch = */ getshort(handle);
194 /* long reserved = */ getint(handle);
195 /* int checksum = */ getshort(handle);
196 /*
197 double widthInUnits = (double)right - left;
198 double heightInUnits = (double)bottom - top;
199 *width = (int)((widthInUnits*1440.0)/inch);
200 *height = (int)((heightInUnits*1440.0)/inch);
201 */
202 }
203 else rewind(handle);
204
205 // Read METAHEADER
206 int mtType = getshort(handle);
207
208 if (mtType != 1 && mtType != 2)
209 {
210 fclose(handle);
211 return FALSE;
212 }
213
214 /* int mtHeaderSize = */ getshort(handle);
215 int mtVersion = getshort(handle);
216
217 if (mtVersion != 0x0300 && mtVersion != 0x0100)
218 {
219 fclose(handle);
220 return FALSE;
221 }
222
223 /* long mtSize = */ getint(handle);
224 /* int mtNoObjects = */ getshort(handle);
225 /* long mtMaxRecord = */ getint(handle);
226 /* int mtNoParameters = */ getshort(handle);
227
228 while (!feof(handle))
229 {
230 long rdSize = getint(handle); // 4 bytes
231 int rdFunction = getshort(handle); // 2 bytes
232 if (feof(handle))
233 break;
234
235 switch (rdFunction)
236 {
237 case META_SETBKCOLOR:
238 {
239 wxMetaRecord *rec = new wxMetaRecord(META_SETBKCOLOR);
240 long colorref = getint(handle); // COLORREF
241 rec->param1 = GetRValue(colorref);
242 rec->param2 = GetGValue(colorref);
243 rec->param3 = GetBValue(colorref);
244 metaRecords.Append(rec);
245 break;
246 }
247 case META_SETBKMODE:
248 {
249 wxMetaRecord *rec = new wxMetaRecord(META_SETBKMODE);
250 rec->param1 = getshort(handle); // Background mode
251 if (rec->param1 == OPAQUE) rec->param1 = wxSOLID;
252 else rec->param1 = wxTRANSPARENT;
253 metaRecords.Append(rec);
254 break;
255 }
256 case META_SETMAPMODE:
257 {
258 wxMetaRecord *rec = new wxMetaRecord(META_SETMAPMODE);
259 rec->param1 = getshort(handle);
260 metaRecords.Append(rec);
261 break;
262 }
263 // case META_SETROP2:
264 // case META_SETRELABS:
265 // case META_SETPOLYFILLMODE:
266 // case META_SETSTRETCHBLTMODE:
267 // case META_SETTEXTCHAREXTRA:
268 case META_SETTEXTCOLOR:
269 {
270 wxMetaRecord *rec = new wxMetaRecord(META_SETTEXTCOLOR);
271 long colorref = getint(handle); // COLORREF
272 rec->param1 = GetRValue(colorref);
273 rec->param2 = GetGValue(colorref);
274 rec->param3 = GetBValue(colorref);
275 metaRecords.Append(rec);
276 break;
277 }
278 // case META_SETTEXTJUSTIFICATION:
279 case META_SETWINDOWORG:
280 {
281 wxMetaRecord *rec = new wxMetaRecord(META_SETWINDOWORG);
282 rec->param2 = getshort(handle);
283 rec->param1 = getshort(handle);
284 metaRecords.Append(rec);
285 break;
286 }
287 case META_SETWINDOWEXT:
288 {
289 wxMetaRecord *rec = new wxMetaRecord(META_SETWINDOWEXT);
290 rec->param2 = getshort(handle);
291 rec->param1 = getshort(handle);
292 metaRecords.Append(rec);
293 break;
294 }
295 // case META_SETVIEWPORTORG:
296 // case META_SETVIEWPORTEXT:
297 // case META_OFFSETWINDOWORG:
298 // case META_SCALEWINDOWEXT:
299 // case META_OFFSETVIEWPORTORG:
300 // case META_SCALEVIEWPORTEXT:
301 case META_LINETO:
302 {
303 wxMetaRecord *rec = new wxMetaRecord(META_LINETO);
304 rec->param1 = getshort(handle); // x1
305 rec->param2 = getshort(handle); // y1
306 metaRecords.Append(rec);
307 break;
308 }
309 case META_MOVETO:
310 {
311 wxMetaRecord *rec = new wxMetaRecord(META_MOVETO);
312 rec->param1 = getshort(handle); // x1
313 rec->param2 = getshort(handle); // y1
314 metaRecords.Append(rec);
315 break;
316 }
317 case META_EXCLUDECLIPRECT:
318 {
319 wxMetaRecord *rec = new wxMetaRecord(META_EXCLUDECLIPRECT);
320 rec->param4 = getshort(handle); // y2
321 rec->param3 = getshort(handle); // x2
322 rec->param2 = getshort(handle); // y1
323 rec->param1 = getshort(handle); // x1
324 metaRecords.Append(rec);
325 break;
326 }
327 case META_INTERSECTCLIPRECT:
328 {
329 wxMetaRecord *rec = new wxMetaRecord(META_INTERSECTCLIPRECT);
330 rec->param4 = getshort(handle); // y2
331 rec->param3 = getshort(handle); // x2
332 rec->param2 = getshort(handle); // y1
333 rec->param1 = getshort(handle); // x1
334 metaRecords.Append(rec);
335 break;
336 }
337 // case META_ARC: // DO!!!
338 case META_ELLIPSE:
339 {
340 wxMetaRecord *rec = new wxMetaRecord(META_ELLIPSE);
341 rec->param4 = getshort(handle); // y2
342 rec->param3 = getshort(handle); // x2
343 rec->param2 = getshort(handle); // y1
344 rec->param1 = getshort(handle); // x1
345 metaRecords.Append(rec);
346 break;
347 }
348 // case META_FLOODFILL:
349 // case META_PIE: // DO!!!
350 case META_RECTANGLE:
351 {
352 wxMetaRecord *rec = new wxMetaRecord(META_RECTANGLE);
353 rec->param4 = getshort(handle); // y2
354 rec->param3 = getshort(handle); // x2
355 rec->param2 = getshort(handle); // y1
356 rec->param1 = getshort(handle); // x1
357 metaRecords.Append(rec);
358 break;
359 }
360 case META_ROUNDRECT:
361 {
362 wxMetaRecord *rec = new wxMetaRecord(META_ROUNDRECT);
363 rec->param6 = getshort(handle); // width
364 rec->param5 = getshort(handle); // height
365 rec->param4 = getshort(handle); // y2
366 rec->param3 = getshort(handle); // x2
367 rec->param2 = getshort(handle); // y1
368 rec->param1 = getshort(handle); // x1
369 metaRecords.Append(rec);
370 break;
371 }
372 // case META_PATBLT:
373 // case META_SAVEDC:
374 case META_SETPIXEL:
375 {
376 wxMetaRecord *rec = new wxMetaRecord(META_SETPIXEL);
377 rec->param1 = getshort(handle); // x1
378 rec->param2 = getshort(handle); // y1
379 rec->param3 = getint(handle); // COLORREF
380 metaRecords.Append(rec);
381 break;
382 }
383 // case META_OFFSETCLIPRGN:
384 case META_TEXTOUT:
385 {
386 wxMetaRecord *rec = new wxMetaRecord(META_TEXTOUT);
387 int count = getshort(handle);
388 rec->stringParam = new wxChar[count+1];
389 fread((void *)rec->stringParam, sizeof(wxChar), count, handle);
390 rec->stringParam[count] = 0;
391 rec->param2 = getshort(handle); // Y
392 rec->param1 = getshort(handle); // X
393 metaRecords.Append(rec);
394 break;
395 }
396 /*
397 case META_EXTTEXTOUT:
398 {
399 wxMetaRecord *rec = new wxMetaRecord(META_EXTTEXTOUT);
400 int cellSpacing = getshort(handle);
401 int count = getshort(handle);
402 rec->stringParam = new char[count+1];
403 fread((void *)rec->stringParam, sizeof(char), count, handle);
404 rec->stringParam[count] = 0;
405 // Rectangle
406 int rectY2 = getshort(handle);
407 int rectX2 = getshort(handle);
408 int rectY1 = getshort(handle);
409 int rectX1 = getshort(handle);
410 int rectType = getshort(handle);
411 rec->param2 = getshort(handle); // Y
412 rec->param1 = getshort(handle); // X
413 metaRecords.Append(rec);
414 break;
415 }
416 */
417 // case META_BITBLT:
418 // case META_STRETCHBLT:
419 case META_POLYGON:
420 {
421 wxMetaRecord *rec = new wxMetaRecord(META_POLYGON);
422 rec->param1 = getshort(handle);
423 rec->points = new wxRealPoint[(int)rec->param1];
424 for (int i = 0; i < rec->param1; i++)
425 {
426 rec->points[i].x = getshort(handle);
427 rec->points[i].y = getshort(handle);
428 }
429
430 metaRecords.Append(rec);
431 break;
432 }
433 case META_POLYLINE:
434 {
435 wxMetaRecord *rec = new wxMetaRecord(META_POLYLINE);
436 rec->param1 = (long)getshort(handle);
437 rec->points = new wxRealPoint[(int)rec->param1];
438 for (int i = 0; i < rec->param1; i++)
439 {
440 rec->points[i].x = getshort(handle);
441 rec->points[i].y = getshort(handle);
442 }
443
444 metaRecords.Append(rec);
445 break;
446 }
447 // case META_ESCAPE:
448 // case META_RESTOREDC:
449 // case META_FILLREGION:
450 // case META_FRAMEREGION:
451 // case META_INVERTREGION:
452 // case META_PAINTREGION:
453 // case META_SELECTCLIPREGION: // DO THIS!
454 case META_SELECTOBJECT:
455 {
456 wxMetaRecord *rec = new wxMetaRecord(META_SELECTOBJECT);
457 rec->param1 = (long)getshort(handle); // Position of object in gdiObjects list
458 metaRecords.Append(rec);
459 // param2 gives the index into gdiObjects, which is different from
460 // the index into the handle table.
461 rec->param2 = HandleTable[(int)rec->param1]->param2;
462 break;
463 }
464 // case META_SETTEXTALIGN:
465 // case META_DRAWTEXT:
466 // case META_CHORD:
467 // case META_SETMAPPERFLAGS:
468 // case META_EXTTEXTOUT:
469 // case META_SETDIBTODEV:
470 // case META_SELECTPALETTE:
471 // case META_REALIZEPALETTE:
472 // case META_ANIMATEPALETTE:
473 // case META_SETPALENTRIES:
474 // case META_POLYPOLYGON:
475 // case META_RESIZEPALETTE:
476 // case META_DIBBITBLT:
477 // case META_DIBSTRETCHBLT:
478 case META_DIBCREATEPATTERNBRUSH:
479 {
480 wxMetaRecord *rec = new wxMetaRecord(META_DIBCREATEPATTERNBRUSH);
481 fread((void *)_buf, sizeof(char), (int)((2*rdSize) - 6), handle);
482
483 metaRecords.Append(rec);
484 gdiObjects.Append(rec);
485 AddMetaRecordHandle(rec);
486 rec->param2 = (long)(gdiObjects.GetCount() - 1);
487 break;
488 }
489 // case META_STRETCHDIB:
490 // case META_EXTFLOODFILL:
491 // case META_RESETDC:
492 // case META_STARTDOC:
493 // case META_STARTPAGE:
494 // case META_ENDPAGE:
495 // case META_ABORTDOC:
496 // case META_ENDDOC:
497 case META_DELETEOBJECT:
498 {
499 int index = getshort(handle);
500 DeleteMetaRecordHandle(index);
501 break;
502 }
503 case META_CREATEPALETTE:
504 {
505 wxMetaRecord *rec = new wxMetaRecord(META_CREATEPALETTE);
506 fread((void *)_buf, sizeof(char), (int)((2*rdSize) - 6), handle);
507
508 metaRecords.Append(rec);
509 gdiObjects.Append(rec);
510 AddMetaRecordHandle(rec);
511 rec->param2 = (long)(gdiObjects.GetCount() - 1);
512 break;
513 }
514 case META_CREATEBRUSH:
515 {
516 wxMetaRecord *rec = new wxMetaRecord(META_CREATEBRUSH);
517 fread((void *)_buf, sizeof(char), (int)((2*rdSize) - 6), handle);
518 metaRecords.Append(rec);
519 gdiObjects.Append(rec);
520 AddMetaRecordHandle(rec);
521 rec->param2 = (long)(gdiObjects.GetCount() - 1);
522 break;
523 }
524 case META_CREATEPATTERNBRUSH:
525 {
526 wxMetaRecord *rec = new wxMetaRecord(META_CREATEPATTERNBRUSH);
527 fread((void *)_buf, sizeof(char), (int)((2*rdSize) - 6), handle);
528 metaRecords.Append(rec);
529 gdiObjects.Append(rec);
530 AddMetaRecordHandle(rec);
531 rec->param2 = (long)(gdiObjects.GetCount() - 1);
532 break;
533 }
534 case META_CREATEPENINDIRECT:
535 {
536 wxMetaRecord *rec = new wxMetaRecord(META_CREATEPENINDIRECT);
537 int msStyle = getshort(handle); // Style: 2 bytes
538 int x = getshort(handle); // X: 2 bytes
539 /* int y = */ getshort(handle); // Y: 2 bytes
540 long colorref = getint(handle); // COLORREF 4 bytes
541
542 int style;
543 if (msStyle == PS_DOT)
544 style = wxDOT;
545 else if (msStyle == PS_DASH)
546 style = wxSHORT_DASH;
547 else if (msStyle == PS_NULL)
548 style = wxTRANSPARENT;
549 else style = wxSOLID;
550
551 wxColour colour(GetRValue(colorref), GetGValue(colorref), GetBValue(colorref));
552 rec->param1 = (long)wxThePenList->FindOrCreatePen(colour, x, style);
553 metaRecords.Append(rec);
554 gdiObjects.Append(rec);
555
556 AddMetaRecordHandle(rec);
557 rec->param2 = (long)(gdiObjects.GetCount() - 1);
558
559 // For some reason, the size of this record is sometimes 9 words!!!
560 // instead of the usual 8. So read 2 characters extra.
561 if (rdSize == 9)
562 {
563 (void) getshort(handle);
564 }
565 break;
566 }
567 case META_CREATEFONTINDIRECT:
568 {
569 wxMetaRecord *rec = new wxMetaRecord(META_CREATEFONTINDIRECT);
570 int lfHeight = getshort(handle); // 2 bytes
571 /* int lfWidth = */ getshort(handle); // 2 bytes
572 /* int lfEsc = */ getshort(handle); // 2 bytes
573 /* int lfOrient = */ getshort(handle); // 2 bytes
574 int lfWeight = getshort(handle); // 2 bytes
575 char lfItalic = getc(handle); // 1 byte
576 char lfUnderline = getc(handle); // 1 byte
577 /* char lfStrikeout = */ getc(handle); // 1 byte
578 /* char lfCharSet = */ getc(handle); // 1 byte
579 /* char lfOutPrecision = */ getc(handle); // 1 byte
580 /* char lfClipPrecision = */ getc(handle); // 1 byte
581 /* char lfQuality = */ getc(handle); // 1 byte
582 char lfPitchAndFamily = getc(handle); // 1 byte (18th)
583 char lfFacename[32];
584 // Read the rest of the record, which is total record size
585 // minus the number of bytes already read (18 record, 6 metarecord
586 // header)
587 fread((void *)lfFacename, sizeof(char), (int)((2*rdSize) - 18 - 6), handle);
588
589 int family;
590 if (lfPitchAndFamily & FF_MODERN)
591 family = wxMODERN;
592 else if (lfPitchAndFamily & FF_MODERN)
593 family = wxMODERN;
594 else if (lfPitchAndFamily & FF_ROMAN)
595 family = wxROMAN;
596 else if (lfPitchAndFamily & FF_SWISS)
597 family = wxSWISS;
598 else if (lfPitchAndFamily & FF_DECORATIVE)
599 family = wxDECORATIVE;
600 else
601 family = wxDEFAULT;
602
603 int weight;
604 if (lfWeight == 300)
605 weight = wxLIGHT;
606 else if (lfWeight == 400)
607 weight = wxNORMAL;
608 else if (lfWeight == 900)
609 weight = wxBOLD;
610 else weight = wxNORMAL;
611
612 int style;
613 if (lfItalic != 0)
614 style = wxITALIC;
615 else
616 style = wxNORMAL;
617
618 // About how many pixels per inch???
619 int logPixelsY = 100;
620 int pointSize = (int)(lfHeight*72.0/logPixelsY);
621
622 wxFont *theFont =
623 wxTheFontList->FindOrCreateFont(pointSize, family, style, weight, (lfUnderline != 0));
624
625 rec->param1 = (long) theFont;
626 metaRecords.Append(rec);
627 gdiObjects.Append(rec);
628 AddMetaRecordHandle(rec);
629 rec->param2 = (long)(gdiObjects.GetCount() - 1);
630 break;
631 }
632 case META_CREATEBRUSHINDIRECT:
633 {
634 wxMetaRecord *rec = new wxMetaRecord(META_CREATEBRUSHINDIRECT);
635 int msStyle = getshort(handle); // Style: 2 bytes
636 long colorref = getint(handle); // COLORREF: 4 bytes
637 int hatchStyle = getshort(handle); // Hatch style 2 bytes
638
639 int style;
640 switch (msStyle)
641 {
642 case BS_HATCHED:
643 {
644 switch (hatchStyle)
645 {
646 case HS_BDIAGONAL:
647 style = wxBDIAGONAL_HATCH;
648 break;
649 case HS_DIAGCROSS:
650 style = wxCROSSDIAG_HATCH;
651 break;
652 case HS_FDIAGONAL:
653 style = wxFDIAGONAL_HATCH;
654 break;
655 case HS_HORIZONTAL:
656 style = wxHORIZONTAL_HATCH;
657 break;
658 case HS_VERTICAL:
659 style = wxVERTICAL_HATCH;
660 break;
661 default:
662 case HS_CROSS:
663 style = wxCROSS_HATCH;
664 break;
665 }
666 break;
667 }
668 case BS_SOLID:
669 default:
670 style = wxSOLID;
671 break;
672 }
673 if (msStyle == PS_DOT)
674 style = wxDOT;
675 else if (msStyle == PS_DASH)
676 style = wxSHORT_DASH;
677 else if (msStyle == PS_NULL)
678 style = wxTRANSPARENT;
679 else style = wxSOLID;
680
681 wxColour colour(GetRValue(colorref), GetGValue(colorref), GetBValue(colorref));
682 rec->param1 = (long)wxTheBrushList->FindOrCreateBrush(colour, style);
683 metaRecords.Append(rec);
684 gdiObjects.Append(rec);
685 AddMetaRecordHandle(rec);
686 rec->param2 = (long)(gdiObjects.GetCount() - 1);
687 break;
688 }
689 case META_CREATEBITMAPINDIRECT:
690 {
691 wxMetaRecord *rec = new wxMetaRecord(META_CREATEBITMAPINDIRECT);
692 fread((void *)_buf, sizeof(char), (int)((2*rdSize) - 6), handle);
693
694 metaRecords.Append(rec);
695 gdiObjects.Append(rec);
696 AddMetaRecordHandle(rec);
697 rec->param2 = (long)(gdiObjects.GetCount() - 1);
698 break;
699 }
700 case META_CREATEBITMAP:
701 {
702 wxMetaRecord *rec = new wxMetaRecord(META_CREATEBITMAP);
703 fread((void *)_buf, sizeof(char), (int)((2*rdSize) - 6), handle);
704
705 metaRecords.Append(rec);
706 gdiObjects.Append(rec);
707 AddMetaRecordHandle(rec);
708 rec->param2 = (long)(gdiObjects.GetCount() - 1);
709 break;
710 }
711 case META_CREATEREGION:
712 {
713 wxMetaRecord *rec = new wxMetaRecord(META_CREATEREGION);
714 fread((void *)_buf, sizeof(char), (int)((2*rdSize) - 6), handle);
715
716 metaRecords.Append(rec);
717 gdiObjects.Append(rec);
718 AddMetaRecordHandle(rec);
719 rec->param2 = (long)(gdiObjects.GetCount() - 1);
720 break;
721 }
722 default:
723 {
724 fread((void *)_buf, sizeof(char), (int)((2*rdSize) - 6), handle);
725 break;
726 }
727 }
728 }
729 fclose(handle);
730 return TRUE;
731 }
732
733 wxXMetaFile::~wxXMetaFile(void)
734 {
735 wxNode *node = metaRecords.GetFirst();
736 while (node)
737 {
738 wxMetaRecord *rec = (wxMetaRecord *)node->GetData();
739 delete rec;
740 wxNode *next = node->GetNext();
741 delete node;
742 node = next;
743 }
744 }
745
746 bool wxXMetaFile::SetClipboard(int WXUNUSED(width), int WXUNUSED(height))
747 {
748 return FALSE;
749 }
750
751 bool wxXMetaFile::Play(wxDC *dc)
752 {
753 wxNode *node = metaRecords.GetFirst();
754 while (node)
755 {
756 wxMetaRecord *rec = (wxMetaRecord *)node->GetData();
757 int rdFunction = rec->metaFunction;
758
759 switch (rdFunction)
760 {
761 case META_SETBKCOLOR:
762 {
763 break;
764 }
765 case META_SETBKMODE:
766 {
767 break;
768 }
769 case META_SETMAPMODE:
770 {
771 break;
772 }
773 // case META_SETROP2:
774 // case META_SETRELABS:
775 // case META_SETPOLYFILLMODE:
776 // case META_SETSTRETCHBLTMODE:
777 // case META_SETTEXTCHAREXTRA:
778 case META_SETTEXTCOLOR:
779 {
780 break;
781 }
782 // case META_SETTEXTJUSTIFICATION:
783 case META_SETWINDOWORG:
784 {
785 break;
786 }
787 case META_SETWINDOWEXT:
788 {
789 break;
790 }
791 // case META_SETVIEWPORTORG:
792 // case META_SETVIEWPORTEXT:
793 // case META_OFFSETWINDOWORG:
794 // case META_SCALEWINDOWEXT:
795 // case META_OFFSETVIEWPORTORG:
796 // case META_SCALEVIEWPORTEXT:
797 case META_LINETO:
798 {
799 long x1 = rec->param1;
800 long y1 = rec->param2;
801 dc->DrawLine((long) lastX, (long) lastY, x1, y1);
802 break;
803 }
804 case META_MOVETO:
805 {
806 lastX = (double)rec->param1;
807 lastY = (double)rec->param2;
808 break;
809 }
810 case META_EXCLUDECLIPRECT:
811 {
812 break;
813 }
814 case META_INTERSECTCLIPRECT:
815 {
816 break;
817 }
818 // case META_ARC: // DO!!!
819 case META_ELLIPSE:
820 {
821 break;
822 }
823 // case META_FLOODFILL:
824 // case META_PIE: // DO!!!
825 case META_RECTANGLE:
826 {
827 dc->DrawRectangle((long)rec->param1, (long)rec->param2,
828 (long)rec->param3 - rec->param1,
829 (long)rec->param4 - rec->param2);
830 break;
831 }
832 case META_ROUNDRECT:
833 {
834 dc->DrawRoundedRectangle((long)rec->param1, (long)rec->param2,
835 (long)rec->param3 - rec->param1,
836 (long)rec->param4 - rec->param2,
837 (long)rec->param5);
838 break;
839 }
840 // case META_PATBLT:
841 // case META_SAVEDC:
842 case META_SETPIXEL:
843 {
844 // rec->param1 = getshort(handle); // x1
845 // rec->param2 = getshort(handle); // y1
846 // rec->param3 = getint(handle); // COLORREF
847 break;
848 }
849 // case META_OFFSETCLIPRGN:
850 case META_TEXTOUT:
851 {
852 /*
853 int count = getshort(handle);
854 rec->stringParam = new char[count+1];
855 fread((void *)rec->stringParam, sizeof(char), count, handle);
856 rec->stringParam[count] = 0;
857 rec->param2 = getshort(handle); // Y
858 rec->param1 = getshort(handle); // X
859 */
860 break;
861 }
862 // case META_BITBLT:
863 // case META_STRETCHBLT:
864 case META_POLYGON:
865 {
866 /*
867 rec->param1 = getshort(handle);
868 rec->points = new wxRealPoint[(int)rec->param1];
869 for (int i = 0; i < rec->param1; i++)
870 {
871 rec->points[i].x = getshort(handle);
872 rec->points[i].y = getshort(handle);
873 }
874 */
875 break;
876 }
877 case META_POLYLINE:
878 {
879 /*
880 wxMetaRecord *rec = new wxMetaRecord(META_POLYLINE);
881 rec->param1 = (long)getshort(handle);
882 rec->points = new wxRealPoint[(int)rec->param1];
883 for (int i = 0; i < rec->param1; i++)
884 {
885 rec->points[i].x = getshort(handle);
886 rec->points[i].y = getshort(handle);
887 }
888 */
889 break;
890 }
891 // case META_ESCAPE:
892 // case META_RESTOREDC:
893 // case META_FILLREGION:
894 // case META_FRAMEREGION:
895 // case META_INVERTREGION:
896 // case META_PAINTREGION:
897 // case META_SELECTCLIPREGION: // DO THIS!
898 case META_SELECTOBJECT:
899 {
900 /*
901 wxMetaRecord *rec = new wxMetaRecord(META_SELECTOBJECT);
902 rec->param1 = (long)getshort(handle); // Position of object in gdiObjects list
903 */
904 break;
905 }
906 // case META_SETTEXTALIGN:
907 // case META_DRAWTEXT:
908 // case META_CHORD:
909 // case META_SETMAPPERFLAGS:
910 // case META_EXTTEXTOUT:
911 // case META_SETDIBTODEV:
912 // case META_SELECTPALETTE:
913 // case META_REALIZEPALETTE:
914 // case META_ANIMATEPALETTE:
915 // case META_SETPALENTRIES:
916 // case META_POLYPOLYGON:
917 // case META_RESIZEPALETTE:
918 // case META_DIBBITBLT:
919 // case META_DIBSTRETCHBLT:
920 case META_DIBCREATEPATTERNBRUSH:
921 {
922 /*
923 fread((void *)wxBuffer, sizeof(char), (int)(rdSize - 3), handle);
924 */
925 break;
926 }
927 // case META_STRETCHDIB:
928 // case META_EXTFLOODFILL:
929 // case META_RESETDC:
930 // case META_STARTDOC:
931 // case META_STARTPAGE:
932 // case META_ENDPAGE:
933 // case META_ABORTDOC:
934 // case META_ENDDOC:
935 // case META_DELETEOBJECT: // DO!!
936 case META_CREATEPALETTE:
937 {
938 /*
939 wxMetaRecord *rec = new wxMetaRecord(META_CREATEPALETTE);
940 fread((void *)wxBuffer, sizeof(char), (int)(rdSize - 3), handle);
941 */
942 break;
943 }
944 case META_CREATEBRUSH:
945 {
946 /*
947 fread((void *)wxBuffer, sizeof(char), (int)(rdSize - 3), handle);
948 */
949 break;
950 }
951 case META_CREATEPATTERNBRUSH:
952 {
953 /*
954 fread((void *)wxBuffer, sizeof(char), (int)(rdSize - 3), handle);
955 */
956 break;
957 }
958 case META_CREATEPENINDIRECT:
959 {
960 /*
961 int msStyle = getshort(handle); // Style: 2 bytes
962 int x = getshort(handle); // X: 2 bytes
963 int y = getshort(handle); // Y: 2 bytes
964 int colorref = getint(handle); // COLORREF 4 bytes
965
966 int style;
967 if (msStyle == PS_DOT)
968 style = wxDOT;
969 else if (msStyle == PS_DASH)
970 style = wxSHORT_DASH;
971 else if (msStyle == PS_NULL)
972 style = wxTRANSPARENT;
973 else style = wxSOLID;
974
975 wxColour colour(GetRValue(colorref), GetGValue(colorref), GetBValue(colorref));
976 rec->param1 = (long)wxThePenList->FindOrCreatePen(&colour, x, style);
977 */
978 break;
979 }
980 case META_CREATEFONTINDIRECT:
981 {
982 /*
983 int lfHeight = getshort(handle);
984 int lfWidth = getshort(handle);
985 int lfEsc = getshort(handle);
986 int lfOrient = getshort(handle);
987 int lfWeight = getshort(handle);
988 char lfItalic = getc(handle);
989 char lfUnderline = getc(handle);
990 char lfStrikeout = getc(handle);
991 char lfCharSet = getc(handle);
992 char lfOutPrecision = getc(handle);
993 char lfClipPrecision = getc(handle);
994 char lfQuality = getc(handle);
995 char lfPitchAndFamily = getc(handle);
996 char lfFacename[32];
997 fread((void *)lfFacename, sizeof(char), 32, handle);
998
999 int family;
1000 if (lfPitchAndFamily & FF_MODERN)
1001 family = wxMODERN;
1002 else if (lfPitchAndFamily & FF_MODERN)
1003 family = wxMODERN;
1004 else if (lfPitchAndFamily & FF_ROMAN)
1005 family = wxROMAN;
1006 else if (lfPitchAndFamily & FF_SWISS)
1007 family = wxSWISS;
1008 else if (lfPitchAndFamily & FF_DECORATIVE)
1009 family = wxDECORATIVE;
1010 else
1011 family = wxDEFAULT;
1012
1013 int weight;
1014 if (lfWeight == 300)
1015 weight = wxLIGHT;
1016 else if (lfWeight == 400)
1017 weight = wxNORMAL;
1018 else if (lfWeight == 900)
1019 weight = wxBOLD;
1020 else weight = wxNORMAL;
1021
1022 int style;
1023 if ((bool)lfItalic)
1024 style = wxITALIC;
1025 else
1026 style = wxNORMAL;
1027
1028 // About how many pixels per inch???
1029 int logPixelsY = 100;
1030 int pointSize = (int)(lfHeight*72.0/logPixelsY);
1031
1032 wxFont *theFont =
1033 wxTheFontList->FindOrCreateFont(pointSize, family, style, weight, (bool)lfUnderline);
1034
1035 rec->param1 = (long)theFont;
1036 */
1037 break;
1038 }
1039 case META_CREATEBRUSHINDIRECT:
1040 {
1041 /*
1042 int msStyle = getshort(handle); // Style: 2 bytes
1043 int colorref = getint(handle); // COLORREF: 4 bytes
1044 int hatchStyle = getshort(handle); // Hatch style 2 bytes
1045
1046 int style;
1047 if (msStyle == PS_DOT)
1048 style = wxDOT;
1049 else if (msStyle == PS_DASH)
1050 style = wxSHORT_DASH;
1051 else if (msStyle == PS_NULL)
1052 style = wxTRANSPARENT;
1053 else style = wxSOLID;
1054
1055 wxColour colour(GetRValue(colorref), GetGValue(colorref), GetBValue(colorref));
1056 rec->param1 = (long)wxTheBrushList->FindOrCreateBrush(&colour, wxSOLID);
1057 */
1058 break;
1059 }
1060 case META_CREATEBITMAPINDIRECT:
1061 {
1062 /*
1063 fread((void *)wxBuffer, sizeof(char), (int)(rdSize - 3), handle);
1064 */
1065 break;
1066 }
1067 case META_CREATEBITMAP:
1068 {
1069 /*
1070 fread((void *)wxBuffer, sizeof(char), (int)(rdSize - 3), handle);
1071 */
1072 break;
1073 }
1074 case META_CREATEREGION:
1075 {
1076 dc->DestroyClippingRegion();
1077 /*
1078 rec->param1 = getshort(handle); // Style: 2 bytes
1079 */
1080 break;
1081 }
1082 default:
1083 {
1084 break;
1085 }
1086 }
1087 node = node->GetNext();
1088 }
1089 return TRUE;
1090 }
1091