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