]>
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 #if !USE_SHARED_LIBRARY
25 IMPLEMENT_DYNAMIC_CLASS(wxMetaFile
, wxObject
)
26 IMPLEMENT_ABSTRACT_CLASS(wxMetaFileDC
, wxDC
)
29 wxMetaFile::wxMetaFile(const wxString
& file
)
34 wxMetaFile::~wxMetaFile()
39 bool wxMetaFile::SetClipboard(int width
, int height
)
41 bool alreadyOpen
=wxClipboardOpen();
45 if (!wxEmptyClipboard()) return FALSE
;
47 bool success
= wxSetClipboardData(wxDF_METAFILE
,this, width
,height
);
48 if (!alreadyOpen
) wxCloseClipboard();
49 return (bool) success
;
52 bool wxMetaFile::Play(wxDC
*dc
)
59 * Metafile device context
63 // Original constructor that does not takes origin and extent. If you use this,
64 // *DO* give origin/extent arguments to wxMakeMetaFilePlaceable.
65 wxMetaFileDC::wxMetaFileDC(const wxString
& file
)
70 // New constructor that takes origin and extent. If you use this, don't
71 // give origin/extent arguments to wxMakeMetaFilePlaceable.
72 wxMetaFileDC::wxMetaFileDC(const wxString
& file
, int xext
, int yext
, int xorg
, int yorg
)
77 wxMetaFileDC::~wxMetaFileDC()
81 void wxMetaFileDC::GetTextExtent(const wxString
& string
, float *x
, float *y
,
82 float *descent
, float *externalLeading
, wxFont
*theFont
, bool use16bit
)
87 wxMetaFile
*wxMetaFileDC::Close()
93 void wxMetaFileDC::SetMapMode(int mode
)
109 struct mfPLACEABLEHEADER
{
118 struct mfPLACEABLEHEADER
{
129 * Pass filename of existing non-placeable metafile, and bounding box.
130 * Adds a placeable metafile header, sets the mapping mode to anisotropic,
131 * and sets the window origin and extent to mimic the MM_TEXT mapping mode.
135 bool wxMakeMetaFilePlaceable(const wxString
& filename
, float scale
)
137 return wxMakeMetaFilePlaceable(filename
, 0, 0, 0, 0, scale
, FALSE
);
140 bool wxMakeMetaFilePlaceable(const wxString
& filename
, int x1
, int y1
, int x2
, int y2
, float scale
, bool useOriginAndExtent
)
142 // I'm not sure if this is the correct way of suggesting a scale
143 // to the client application, but it's the only way I can find.
144 int unitsPerInch
= (int)(576/scale
);
146 mfPLACEABLEHEADER header
;
147 header
.key
= 0x9AC6CDD7L
;
149 header
.bbox
.left
= (int)(x1
);
150 header
.bbox
.top
= (int)(y1
);
151 header
.bbox
.right
= (int)(x2
);
152 header
.bbox
.bottom
= (int)(y2
);
153 header
.inch
= unitsPerInch
;
156 // Calculate checksum
158 mfPLACEABLEHEADER
*pMFHead
= &header
;
159 for (p
=(WORD
*)pMFHead
,pMFHead
-> checksum
= 0;
160 p
< (WORD
*)&pMFHead
->checksum
; ++p
)
161 pMFHead
->checksum
^= *p
;
163 FILE *fd
= fopen((char *)(const char *)filename
, "rb");
164 if (!fd
) return FALSE
;
166 char tempFileBuf
[256];
167 wxGetTempFileName("mf", tempFileBuf
);
168 FILE *fHandle
= fopen(tempFileBuf
, "wb");
171 fwrite((void *)&header
, sizeof(unsigned char), sizeof(mfPLACEABLEHEADER
), fHandle
);
173 // Calculate origin and extent
176 int extentX
= x2
- x1
;
177 int extentY
= (y2
- y1
);
179 // Read metafile header and write
180 METAHEADER metaHeader
;
181 fread((void *)&metaHeader
, sizeof(unsigned char), sizeof(metaHeader
), fd
);
183 if (useOriginAndExtent
)
184 metaHeader
.mtSize
+= 15;
186 metaHeader
.mtSize
+= 5;
188 fwrite((void *)&metaHeader
, sizeof(unsigned char), sizeof(metaHeader
), fHandle
);
190 // Write SetMapMode, SetWindowOrigin and SetWindowExt records
192 char originBuffer
[10];
193 char extentBuffer
[10];
194 METARECORD
*modeRecord
= (METARECORD
*)&modeBuffer
;
196 METARECORD
*originRecord
= (METARECORD
*)&originBuffer
;
197 METARECORD
*extentRecord
= (METARECORD
*)&extentBuffer
;
199 modeRecord
->rdSize
= 4;
200 modeRecord
->rdFunction
= META_SETMAPMODE
;
201 modeRecord
->rdParm
[0] = MM_ANISOTROPIC
;
203 originRecord
->rdSize
= 5;
204 originRecord
->rdFunction
= META_SETWINDOWORG
;
205 originRecord
->rdParm
[0] = originY
;
206 originRecord
->rdParm
[1] = originX
;
208 extentRecord
->rdSize
= 5;
209 extentRecord
->rdFunction
= META_SETWINDOWEXT
;
210 extentRecord
->rdParm
[0] = extentY
;
211 extentRecord
->rdParm
[1] = extentX
;
213 fwrite((void *)modeBuffer
, sizeof(char), 8, fHandle
);
215 if (useOriginAndExtent
)
217 fwrite((void *)originBuffer
, sizeof(char), 10, fHandle
);
218 fwrite((void *)extentBuffer
, sizeof(char), 10, fHandle
);
232 wxRemoveFile(filename
);
233 wxCopyFile(tempFileBuf
, filename
);
234 wxRemoveFile(tempFileBuf
);