]>
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/metafile.h"
17 #include "wx/clipbrd.h"
19 extern bool wxClipboardIsOpen
;
21 #if !USE_SHARED_LIBRARY
22 IMPLEMENT_DYNAMIC_CLASS(wxMetaFile
, wxObject
)
23 IMPLEMENT_ABSTRACT_CLASS(wxMetaFileDC
, wxDC
)
26 wxMetaFile::wxMetaFile(const wxString
& file
)
31 wxMetaFile::~wxMetaFile()
36 bool wxMetaFile::SetClipboard(int width
, int height
)
38 bool alreadyOpen
=wxClipboardOpen();
42 if (!wxEmptyClipboard()) return FALSE
;
44 bool success
= wxSetClipboardData(wxDF_METAFILE
,this, width
,height
);
45 if (!alreadyOpen
) wxCloseClipboard();
46 return (bool) success
;
49 bool wxMetaFile::Play(wxDC
*dc
)
56 * Metafile device context
60 // Original constructor that does not takes origin and extent. If you use this,
61 // *DO* give origin/extent arguments to wxMakeMetaFilePlaceable.
62 wxMetaFileDC::wxMetaFileDC(const wxString
& file
)
67 // New constructor that takes origin and extent. If you use this, don't
68 // give origin/extent arguments to wxMakeMetaFilePlaceable.
69 wxMetaFileDC::wxMetaFileDC(const wxString
& file
, int xext
, int yext
, int xorg
, int yorg
)
74 wxMetaFileDC::~wxMetaFileDC()
78 void wxMetaFileDC::GetTextExtent(const wxString
& string
, float *x
, float *y
,
79 float *descent
, float *externalLeading
, wxFont
*theFont
, bool use16bit
)
84 wxMetaFile
*wxMetaFileDC::Close()
90 void wxMetaFileDC::SetMapMode(int mode
)
106 struct mfPLACEABLEHEADER
{
115 struct mfPLACEABLEHEADER
{
126 * Pass filename of existing non-placeable metafile, and bounding box.
127 * Adds a placeable metafile header, sets the mapping mode to anisotropic,
128 * and sets the window origin and extent to mimic the MM_TEXT mapping mode.
132 bool wxMakeMetaFilePlaceable(const wxString
& filename
, float scale
)
134 return wxMakeMetaFilePlaceable(filename
, 0, 0, 0, 0, scale
, FALSE
);
137 bool wxMakeMetaFilePlaceable(const wxString
& filename
, int x1
, int y1
, int x2
, int y2
, float scale
, bool useOriginAndExtent
)
139 // I'm not sure if this is the correct way of suggesting a scale
140 // to the client application, but it's the only way I can find.
141 int unitsPerInch
= (int)(576/scale
);
143 mfPLACEABLEHEADER header
;
144 header
.key
= 0x9AC6CDD7L
;
146 header
.bbox
.left
= (int)(x1
);
147 header
.bbox
.top
= (int)(y1
);
148 header
.bbox
.right
= (int)(x2
);
149 header
.bbox
.bottom
= (int)(y2
);
150 header
.inch
= unitsPerInch
;
153 // Calculate checksum
155 mfPLACEABLEHEADER
*pMFHead
= &header
;
156 for (p
=(WORD
*)pMFHead
,pMFHead
-> checksum
= 0;
157 p
< (WORD
*)&pMFHead
->checksum
; ++p
)
158 pMFHead
->checksum
^= *p
;
160 FILE *fd
= fopen((char *)(const char *)filename
, "rb");
161 if (!fd
) return FALSE
;
163 char tempFileBuf
[256];
164 wxGetTempFileName("mf", tempFileBuf
);
165 FILE *fHandle
= fopen(tempFileBuf
, "wb");
168 fwrite((void *)&header
, sizeof(unsigned char), sizeof(mfPLACEABLEHEADER
), fHandle
);
170 // Calculate origin and extent
173 int extentX
= x2
- x1
;
174 int extentY
= (y2
- y1
);
176 // Read metafile header and write
177 METAHEADER metaHeader
;
178 fread((void *)&metaHeader
, sizeof(unsigned char), sizeof(metaHeader
), fd
);
180 if (useOriginAndExtent
)
181 metaHeader
.mtSize
+= 15;
183 metaHeader
.mtSize
+= 5;
185 fwrite((void *)&metaHeader
, sizeof(unsigned char), sizeof(metaHeader
), fHandle
);
187 // Write SetMapMode, SetWindowOrigin and SetWindowExt records
189 char originBuffer
[10];
190 char extentBuffer
[10];
191 METARECORD
*modeRecord
= (METARECORD
*)&modeBuffer
;
193 METARECORD
*originRecord
= (METARECORD
*)&originBuffer
;
194 METARECORD
*extentRecord
= (METARECORD
*)&extentBuffer
;
196 modeRecord
->rdSize
= 4;
197 modeRecord
->rdFunction
= META_SETMAPMODE
;
198 modeRecord
->rdParm
[0] = MM_ANISOTROPIC
;
200 originRecord
->rdSize
= 5;
201 originRecord
->rdFunction
= META_SETWINDOWORG
;
202 originRecord
->rdParm
[0] = originY
;
203 originRecord
->rdParm
[1] = originX
;
205 extentRecord
->rdSize
= 5;
206 extentRecord
->rdFunction
= META_SETWINDOWEXT
;
207 extentRecord
->rdParm
[0] = extentY
;
208 extentRecord
->rdParm
[1] = extentX
;
210 fwrite((void *)modeBuffer
, sizeof(char), 8, fHandle
);
212 if (useOriginAndExtent
)
214 fwrite((void *)originBuffer
, sizeof(char), 10, fHandle
);
215 fwrite((void *)extentBuffer
, sizeof(char), 10, fHandle
);
229 wxRemoveFile(filename
);
230 wxCopyFile(tempFileBuf
, filename
);
231 wxRemoveFile(tempFileBuf
);