]>
git.saurik.com Git - wxWidgets.git/blob - src/stubs/metafile.cpp
1 /////////////////////////////////////////////////////////////////////////////
3 // Purpose: wxMetaFile, wxMetaFileDC etc. These classes are optional.
8 // Copyright: (c) AUTHOR
9 // Licence: wxWindows licence
10 /////////////////////////////////////////////////////////////////////////////
13 #pragma implementation "metafile.h"
16 #include "wx/object.h"
17 #include "wx/string.h"
19 #include "wx/stubs/metafile.h"
20 #include "wx/clipbrd.h"
22 extern bool wxClipboardIsOpen
;
24 IMPLEMENT_DYNAMIC_CLASS(wxMetaFile
, wxObject
)
25 IMPLEMENT_ABSTRACT_CLASS(wxMetaFileDC
, wxDC
)
27 wxMetaFile::wxMetaFile(const wxString
& file
)
32 wxMetaFile::~wxMetaFile()
37 bool wxMetaFile::SetClipboard(int width
, int height
)
39 bool alreadyOpen
=wxClipboardOpen();
43 if (!wxEmptyClipboard()) return FALSE
;
45 bool success
= wxSetClipboardData(wxDF_METAFILE
,this, width
,height
);
46 if (!alreadyOpen
) wxCloseClipboard();
47 return (bool) success
;
50 bool wxMetaFile::Play(wxDC
*dc
)
57 * Metafile device context
61 // Original constructor that does not takes origin and extent. If you use this,
62 // *DO* give origin/extent arguments to wxMakeMetaFilePlaceable.
63 wxMetaFileDC::wxMetaFileDC(const wxString
& file
)
68 // New constructor that takes origin and extent. If you use this, don't
69 // give origin/extent arguments to wxMakeMetaFilePlaceable.
70 wxMetaFileDC::wxMetaFileDC(const wxString
& file
, int xext
, int yext
, int xorg
, int yorg
)
75 wxMetaFileDC::~wxMetaFileDC()
79 void wxMetaFileDC::GetTextExtent(const wxString
& string
, float *x
, float *y
,
80 float *descent
, float *externalLeading
, wxFont
*theFont
, bool use16bit
)
85 wxMetaFile
*wxMetaFileDC::Close()
91 void wxMetaFileDC::SetMapMode(int mode
)
107 struct mfPLACEABLEHEADER
{
116 struct mfPLACEABLEHEADER
{
127 * Pass filename of existing non-placeable metafile, and bounding box.
128 * Adds a placeable metafile header, sets the mapping mode to anisotropic,
129 * and sets the window origin and extent to mimic the wxMM_TEXT mapping mode.
133 bool wxMakeMetaFilePlaceable(const wxString
& filename
, float scale
)
135 return wxMakeMetaFilePlaceable(filename
, 0, 0, 0, 0, scale
, FALSE
);
138 bool wxMakeMetaFilePlaceable(const wxString
& filename
, int x1
, int y1
, int x2
, int y2
, float scale
, bool useOriginAndExtent
)
140 // I'm not sure if this is the correct way of suggesting a scale
141 // to the client application, but it's the only way I can find.
142 int unitsPerInch
= (int)(576/scale
);
144 mfPLACEABLEHEADER header
;
145 header
.key
= 0x9AC6CDD7L
;
147 header
.bbox
.left
= (int)(x1
);
148 header
.bbox
.top
= (int)(y1
);
149 header
.bbox
.right
= (int)(x2
);
150 header
.bbox
.bottom
= (int)(y2
);
151 header
.inch
= unitsPerInch
;
154 // Calculate checksum
156 mfPLACEABLEHEADER
*pMFHead
= &header
;
157 for (p
=(WORD
*)pMFHead
,pMFHead
-> checksum
= 0;
158 p
< (WORD
*)&pMFHead
->checksum
; ++p
)
159 pMFHead
->checksum
^= *p
;
161 FILE *fd
= fopen((char *)(const char *)filename
, "rb");
162 if (!fd
) return FALSE
;
164 char tempFileBuf
[256];
165 wxGetTempFileName("mf", tempFileBuf
);
166 FILE *fHandle
= fopen(tempFileBuf
, "wb");
169 fwrite((void *)&header
, sizeof(unsigned char), sizeof(mfPLACEABLEHEADER
), fHandle
);
171 // Calculate origin and extent
174 int extentX
= x2
- x1
;
175 int extentY
= (y2
- y1
);
177 // Read metafile header and write
178 METAHEADER metaHeader
;
179 fread((void *)&metaHeader
, sizeof(unsigned char), sizeof(metaHeader
), fd
);
181 if (useOriginAndExtent
)
182 metaHeader
.mtSize
+= 15;
184 metaHeader
.mtSize
+= 5;
186 fwrite((void *)&metaHeader
, sizeof(unsigned char), sizeof(metaHeader
), fHandle
);
188 // Write SetMapMode, SetWindowOrigin and SetWindowExt records
190 char originBuffer
[10];
191 char extentBuffer
[10];
192 METARECORD
*modeRecord
= (METARECORD
*)&modeBuffer
;
194 METARECORD
*originRecord
= (METARECORD
*)&originBuffer
;
195 METARECORD
*extentRecord
= (METARECORD
*)&extentBuffer
;
197 modeRecord
->rdSize
= 4;
198 modeRecord
->rdFunction
= META_SETMAPMODE
;
199 modeRecord
->rdParm
[0] = MM_ANISOTROPIC
;
201 originRecord
->rdSize
= 5;
202 originRecord
->rdFunction
= META_SETWINDOWORG
;
203 originRecord
->rdParm
[0] = originY
;
204 originRecord
->rdParm
[1] = originX
;
206 extentRecord
->rdSize
= 5;
207 extentRecord
->rdFunction
= META_SETWINDOWEXT
;
208 extentRecord
->rdParm
[0] = extentY
;
209 extentRecord
->rdParm
[1] = extentX
;
211 fwrite((void *)modeBuffer
, sizeof(char), 8, fHandle
);
213 if (useOriginAndExtent
)
215 fwrite((void *)originBuffer
, sizeof(char), 10, fHandle
);
216 fwrite((void *)extentBuffer
, sizeof(char), 10, fHandle
);
230 wxRemoveFile(filename
);
231 wxCopyFile(tempFileBuf
, filename
);
232 wxRemoveFile(tempFileBuf
);