]> Creatis software - clitk.git/blob - utilities/CxImage/ximawmf.h
fb59452872687850194f0eccd913852c55d4da4d
[clitk.git] / utilities / CxImage / ximawmf.h
1 /*\r
2 *********************************************************************\r
3  * File:        ximawmf.h\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
8  */\r
9 \r
10 /*\r
11 *********************************************************************\r
12         Notes by Author:\r
13 *********************************************************************\r
14 \r
15         Limitations:\r
16         ============\r
17 \r
18         a) Transparency:\r
19 \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
24         handle this:\r
25 \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
28 \r
29           below #define XMF_SUPPORT_TRANSPARENCY 0\r
30                         #define XMF_COLOR_BACK RGB(Background color you like)\r
31 \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
34 \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
39 \r
40         b) Resolution\r
41 \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
45 \r
46         c) Size\r
47 \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
55 \r
56         I have choosen, to limit the size of the Bitmap to max.\r
57         screensize, to avoid memory problems.\r
58 \r
59         If you want something else,\r
60         modify #define XMF_MAXSIZE_CX / XMF_MAXSIZE_CY below\r
61 \r
62 *********************************************************************\r
63 */\r
64 \r
65 #ifndef _XIMAWMF_H\r
66 #define _XIMAWMF_H\r
67 \r
68 #include "ximage.h"\r
69 \r
70 #if CXIMAGE_SUPPORT_WMF && CXIMAGE_SUPPORT_WINDOWS\r
71 \r
72 class CxImageWMF: public CxImage\r
73 {\r
74 \r
75 #pragma pack(1)\r
76 \r
77 typedef struct tagRECT16\r
78 {\r
79         short int       left;\r
80         short int       top;\r
81         short int       right;\r
82         short int       bottom;\r
83 } RECT16;\r
84 \r
85 // taken from Windos 3.11 SDK Documentation (Programmer's Reference Volume 4: Resources)\r
86 typedef struct tagMETAFILEHEADER\r
87 {\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
94 } METAFILEHEADER;\r
95 \r
96 #pragma pack()\r
97 \r
98 public:\r
99         CxImageWMF(): CxImage(CXIMAGE_FORMAT_WMF) { }\r
100 \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
104 \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
109 \r
110 protected:\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
115 \r
116 };\r
117 \r
118 #define METAFILEKEY     0x9ac6cdd7L\r
119 \r
120 // Background color definition (if no transparency). see Notes above\r
121 #define XMF_COLOR_BACK  GetSysColor(COLOR_WINDOW)\r
122 // alternatives\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
126 \r
127 \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
133 // don't change\r
134 #define XMF_COLOR_TRANSPARENT           RGB (XMF_COLOR_TRANSPARENT_R, \\r
135                                                                                  XMF_COLOR_TRANSPARENT_G, \\r
136                                                                                  XMF_COLOR_TRANSPARENT_B)\r
137 // don't change\r
138 #define XMF_RGBQUAD_TRANSPARENT         XMF_COLOR_TRANSPARENT_B, \\r
139                                                                         XMF_COLOR_TRANSPARENT_G, \\r
140                                                                         XMF_COLOR_TRANSPARENT_R, \\r
141                                                                         0\r
142 // max. size. see Notes above\r
143 // alternatives\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
150 \r
151 \r
152 #endif\r
153 \r
154 #endif\r