2 *********************************************************************
\r
4 * Purpose: Windows Metafile Class Loader and Writer
\r
5 * Author: Volker Horch - vhorch@gmx.de
\r
6 * created: 13-Jun-2002
\r
7 *********************************************************************
\r
11 *********************************************************************
\r
13 *********************************************************************
\r
20 A Metafile is vector graphics, which has transparency by design.
\r
21 This class always converts into a Bitmap format. Transparency is
\r
22 supported, but there is no good way to find out, which parts
\r
23 of the Metafile are transparent. There are two ways how we can
\r
26 - Clear the Background of the Bitmap with the background color
\r
27 you like (i have used COLOR_WINDOW) and don't support transparency.
\r
29 below #define XMF_SUPPORT_TRANSPARENCY 0
\r
30 #define XMF_COLOR_BACK RGB(Background color you like)
\r
32 - Clear the Background of the Bitmap with a very unusual color
\r
33 (which one ?) and use this color as the transparent color
\r
35 below #define XMF_SUPPORT_TRANSPARENCY 1
\r
36 #define XMF_COLOR_TRANSPARENT_R ...
\r
37 #define XMF_COLOR_TRANSPARENT_G ...
\r
38 #define XMF_COLOR_TRANSPARENT_B ...
\r
42 Once we have converted the Metafile into a Bitmap and we zoom in
\r
43 or out, the image may not look very good. If we still had the
\r
44 original Metafile, zooming would produce good results always.
\r
48 Although the filesize of a Metafile may be very small, it might
\r
49 produce a Bitmap with a bombastic size. Assume you have a Metafile
\r
50 with an image size of 6000*4000, which contains just one Metafile
\r
51 record ((e.g. a line from (0,0) to (6000, 4000)). The filesize
\r
52 of this Metafile would be let's say 100kB. If we convert it to
\r
53 a 6000*4000 Bitmap with 24 Bits/Pixes, the Bitmap would consume
\r
54 about 68MB of memory.
\r
56 I have choosen, to limit the size of the Bitmap to max.
\r
57 screensize, to avoid memory problems.
\r
59 If you want something else,
\r
60 modify #define XMF_MAXSIZE_CX / XMF_MAXSIZE_CY below
\r
62 *********************************************************************
\r
70 #if CXIMAGE_SUPPORT_WMF && CXIMAGE_SUPPORT_WINDOWS
\r
72 class CxImageWMF: public CxImage
\r
77 typedef struct tagRECT16
\r
85 // taken from Windos 3.11 SDK Documentation (Programmer's Reference Volume 4: Resources)
\r
86 typedef struct tagMETAFILEHEADER
\r
88 DWORD key; // always 0x9ac6cdd7
\r
89 WORD reserved1; // reserved = 0
\r
90 RECT16 bbox; // bounding rectangle in metafile units as defined in "inch"
\r
91 WORD inch; // number of metafile units per inch (should be < 1440)
\r
92 DWORD reserved2; // reserved = 0
\r
93 WORD checksum; // sum of the first 10 WORDS (using XOR operator)
\r
99 CxImageWMF(): CxImage(CXIMAGE_FORMAT_WMF) { }
\r
101 bool Decode(CxFile * hFile, long nForceWidth=0, long nForceHeight=0);
\r
102 bool Decode(FILE *hFile, long nForceWidth=0, long nForceHeight=0)
\r
103 { CxIOFile file(hFile); return Decode(&file,nForceWidth,nForceHeight); }
\r
105 #if CXIMAGE_SUPPORT_ENCODE
\r
106 bool Encode(CxFile * hFile);
\r
107 bool Encode(FILE *hFile) { CxIOFile file(hFile); return Encode(&file); }
\r
108 #endif // CXIMAGE_SUPPORT_ENCODE
\r
111 void ShrinkMetafile(int &cx, int &cy);
\r
112 BOOL CheckMetafileHeader(METAFILEHEADER *pmetafileheader);
\r
113 HENHMETAFILE ConvertWmfFiletoEmf(CxFile *pFile, METAFILEHEADER *pmetafileheader);
\r
114 HENHMETAFILE ConvertEmfFiletoEmf(CxFile *pFile, ENHMETAHEADER *pemfh);
\r
118 #define METAFILEKEY 0x9ac6cdd7L
\r
120 // Background color definition (if no transparency). see Notes above
\r
121 #define XMF_COLOR_BACK GetSysColor(COLOR_WINDOW)
\r
123 //#define XMF_COLOR_BACK RGB(192, 192, 192) // lite gray
\r
124 //#define XMF_COLOR_BACK RGB( 0, 0, 0) // black
\r
125 //#define XMF_COLOR_BACK RGB(255, 255, 255) // white
\r
128 // transparency support. see Notes above
\r
129 #define XMF_SUPPORT_TRANSPARENCY 0
\r
130 #define XMF_COLOR_TRANSPARENT_R 211
\r
131 #define XMF_COLOR_TRANSPARENT_G 121
\r
132 #define XMF_COLOR_TRANSPARENT_B 112
\r
134 #define XMF_COLOR_TRANSPARENT RGB (XMF_COLOR_TRANSPARENT_R, \
\r
135 XMF_COLOR_TRANSPARENT_G, \
\r
136 XMF_COLOR_TRANSPARENT_B)
\r
138 #define XMF_RGBQUAD_TRANSPARENT XMF_COLOR_TRANSPARENT_B, \
\r
139 XMF_COLOR_TRANSPARENT_G, \
\r
140 XMF_COLOR_TRANSPARENT_R, \
\r
142 // max. size. see Notes above
\r
144 //#define XMF_MAXSIZE_CX (GetSystemMetrics(SM_CXSCREEN)-10)
\r
145 //#define XMF_MAXSIZE_CY (GetSystemMetrics(SM_CYSCREEN)-50)
\r
146 //#define XMF_MAXSIZE_CX (2*GetSystemMetrics(SM_CXSCREEN)/3)
\r
147 //#define XMF_MAXSIZE_CY (2*GetSystemMetrics(SM_CYSCREEN)/3)
\r
148 #define XMF_MAXSIZE_CX 4000
\r
149 #define XMF_MAXSIZE_CY 4000
\r