]> Creatis software - clitk.git/blob - utilities/CxImage/ximawmf.h
cosmetic
[clitk.git] / utilities / CxImage / ximawmf.h
1 /*
2 *********************************************************************
3  * File:        ximawmf.h
4  * Purpose:     Windows Metafile Class Loader and Writer
5  * Author:      Volker Horch - vhorch@gmx.de
6  * created:     13-Jun-2002
7 *********************************************************************
8  */
9
10 /*
11 *********************************************************************
12         Notes by Author:
13 *********************************************************************
14
15         Limitations:
16         ============
17
18         a) Transparency:
19
20         A Metafile is vector graphics, which has transparency by design.
21         This class always converts into a Bitmap format. Transparency is
22         supported, but there is no good way to find out, which parts
23         of the Metafile are transparent. There are two ways how we can
24         handle this:
25
26         - Clear the Background of the Bitmap with the background color
27           you like (i have used COLOR_WINDOW) and don't support transparency.
28
29           below #define XMF_SUPPORT_TRANSPARENCY 0
30                         #define XMF_COLOR_BACK RGB(Background color you like)
31
32         - Clear the Background of the Bitmap with a very unusual color
33           (which one ?) and use this color as the transparent color
34
35           below #define XMF_SUPPORT_TRANSPARENCY 1
36                         #define XMF_COLOR_TRANSPARENT_R ...
37                         #define XMF_COLOR_TRANSPARENT_G ...
38                         #define XMF_COLOR_TRANSPARENT_B ...
39
40         b) Resolution
41
42         Once we have converted the Metafile into a Bitmap and we zoom in
43         or out, the image may not look very good. If we still had the
44         original Metafile, zooming would produce good results always.
45
46         c) Size
47
48         Although the filesize of a Metafile may be very small, it might
49         produce a Bitmap with a bombastic size. Assume you have a Metafile
50         with an image size of 6000*4000, which contains just one Metafile
51         record ((e.g. a line from (0,0) to (6000, 4000)). The filesize
52         of this Metafile would be let's say 100kB. If we convert it to
53         a 6000*4000 Bitmap with 24 Bits/Pixes, the Bitmap would consume
54         about 68MB of memory.
55
56         I have choosen, to limit the size of the Bitmap to max.
57         screensize, to avoid memory problems.
58
59         If you want something else,
60         modify #define XMF_MAXSIZE_CX / XMF_MAXSIZE_CY below
61
62 *********************************************************************
63 */
64
65 #ifndef _XIMAWMF_H
66 #define _XIMAWMF_H
67
68 #include "ximage.h"
69
70 #if CXIMAGE_SUPPORT_WMF && CXIMAGE_SUPPORT_WINDOWS
71
72 class CxImageWMF: public CxImage
73 {
74
75 #pragma pack(1)
76
77 typedef struct tagRECT16
78 {
79         short int       left;
80         short int       top;
81         short int       right;
82         short int       bottom;
83 } RECT16;
84
85 // taken from Windos 3.11 SDK Documentation (Programmer's Reference Volume 4: Resources)
86 typedef struct tagMETAFILEHEADER
87 {
88         DWORD   key;            // always 0x9ac6cdd7
89         WORD    reserved1;      // reserved = 0
90         RECT16  bbox;           // bounding rectangle in metafile units as defined in "inch"
91         WORD    inch;           // number of metafile units per inch (should be < 1440)
92         DWORD   reserved2;      // reserved = 0
93         WORD    checksum;       // sum of the first 10 WORDS (using XOR operator)
94 } METAFILEHEADER;
95
96 #pragma pack()
97
98 public:
99         CxImageWMF(): CxImage(CXIMAGE_FORMAT_WMF) { }
100
101         bool Decode(CxFile * hFile, long nForceWidth=0, long nForceHeight=0);
102         bool Decode(FILE *hFile, long nForceWidth=0, long nForceHeight=0)
103                         { CxIOFile file(hFile); return Decode(&file,nForceWidth,nForceHeight); }
104
105 #if CXIMAGE_SUPPORT_ENCODE
106         bool Encode(CxFile * hFile);
107         bool Encode(FILE *hFile) { CxIOFile file(hFile); return Encode(&file); }
108 #endif // CXIMAGE_SUPPORT_ENCODE
109
110 protected:
111         void ShrinkMetafile(int &cx, int &cy);
112         BOOL CheckMetafileHeader(METAFILEHEADER *pmetafileheader);
113         HENHMETAFILE ConvertWmfFiletoEmf(CxFile *pFile, METAFILEHEADER *pmetafileheader);
114         HENHMETAFILE ConvertEmfFiletoEmf(CxFile *pFile, ENHMETAHEADER *pemfh);
115
116 };
117
118 #define METAFILEKEY     0x9ac6cdd7L
119
120 // Background color definition (if no transparency). see Notes above
121 #define XMF_COLOR_BACK  GetSysColor(COLOR_WINDOW)
122 // alternatives
123 //#define       XMF_COLOR_BACK  RGB(192, 192, 192)      // lite gray
124 //#define       XMF_COLOR_BACK  RGB(  0,   0,   0)      // black
125 //#define       XMF_COLOR_BACK  RGB(255, 255, 255)      // white
126
127
128 // transparency support. see Notes above
129 #define XMF_SUPPORT_TRANSPARENCY        0
130 #define XMF_COLOR_TRANSPARENT_R         211
131 #define XMF_COLOR_TRANSPARENT_G         121
132 #define XMF_COLOR_TRANSPARENT_B         112
133 // don't change
134 #define XMF_COLOR_TRANSPARENT           RGB (XMF_COLOR_TRANSPARENT_R, \
135                                                                                  XMF_COLOR_TRANSPARENT_G, \
136                                                                                  XMF_COLOR_TRANSPARENT_B)
137 // don't change
138 #define XMF_RGBQUAD_TRANSPARENT         XMF_COLOR_TRANSPARENT_B, \
139                                                                         XMF_COLOR_TRANSPARENT_G, \
140                                                                         XMF_COLOR_TRANSPARENT_R, \
141                                                                         0
142 // max. size. see Notes above
143 // alternatives
144 //#define       XMF_MAXSIZE_CX  (GetSystemMetrics(SM_CXSCREEN)-10)
145 //#define       XMF_MAXSIZE_CY  (GetSystemMetrics(SM_CYSCREEN)-50)
146 //#define       XMF_MAXSIZE_CX  (2*GetSystemMetrics(SM_CXSCREEN)/3)
147 //#define       XMF_MAXSIZE_CY  (2*GetSystemMetrics(SM_CYSCREEN)/3)
148 #define XMF_MAXSIZE_CX  4000
149 #define XMF_MAXSIZE_CY  4000
150
151
152 #endif
153
154 #endif