1*c2c66affSColin Finck /*
2*c2c66affSColin Finck * GDI objects
3*c2c66affSColin Finck *
4*c2c66affSColin Finck * Copyright 1993 Alexandre Julliard
5*c2c66affSColin Finck *
6*c2c66affSColin Finck * This library is free software; you can redistribute it and/or
7*c2c66affSColin Finck * modify it under the terms of the GNU Lesser General Public
8*c2c66affSColin Finck * License as published by the Free Software Foundation; either
9*c2c66affSColin Finck * version 2.1 of the License, or (at your option) any later version.
10*c2c66affSColin Finck *
11*c2c66affSColin Finck * This library is distributed in the hope that it will be useful,
12*c2c66affSColin Finck * but WITHOUT ANY WARRANTY; without even the implied warranty of
13*c2c66affSColin Finck * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14*c2c66affSColin Finck * Lesser General Public License for more details.
15*c2c66affSColin Finck *
16*c2c66affSColin Finck * You should have received a copy of the GNU Lesser General Public
17*c2c66affSColin Finck * License along with this library; if not, write to the Free Software
18*c2c66affSColin Finck * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA
19*c2c66affSColin Finck */
20*c2c66affSColin Finck
21*c2c66affSColin Finck #include <stdlib.h>
22*c2c66affSColin Finck #include <stdio.h>
23*c2c66affSColin Finck #include <string.h>
24*c2c66affSColin Finck #include <stdarg.h>
25*c2c66affSColin Finck
26*c2c66affSColin Finck #include "windef.h"
27*c2c66affSColin Finck #include "winbase.h"
28*c2c66affSColin Finck #include "wingdi.h"
29*c2c66affSColin Finck #include "wine/wingdi16.h"
30*c2c66affSColin Finck #include "mfdrv/metafiledrv.h"
31*c2c66affSColin Finck #include "gdi_private.h"
32*c2c66affSColin Finck #include "wine/debug.h"
33*c2c66affSColin Finck
34*c2c66affSColin Finck WINE_DEFAULT_DEBUG_CHANNEL(metafile);
35*c2c66affSColin Finck
36*c2c66affSColin Finck /******************************************************************
37*c2c66affSColin Finck * MFDRV_AddHandle
38*c2c66affSColin Finck */
MFDRV_AddHandle(PHYSDEV dev,HGDIOBJ obj)39*c2c66affSColin Finck UINT MFDRV_AddHandle( PHYSDEV dev, HGDIOBJ obj )
40*c2c66affSColin Finck {
41*c2c66affSColin Finck METAFILEDRV_PDEVICE *physDev = (METAFILEDRV_PDEVICE *)dev;
42*c2c66affSColin Finck UINT16 index;
43*c2c66affSColin Finck
44*c2c66affSColin Finck for(index = 0; index < physDev->handles_size; index++)
45*c2c66affSColin Finck if(physDev->handles[index] == 0) break;
46*c2c66affSColin Finck if(index == physDev->handles_size) {
47*c2c66affSColin Finck physDev->handles_size += HANDLE_LIST_INC;
48*c2c66affSColin Finck physDev->handles = HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
49*c2c66affSColin Finck physDev->handles,
50*c2c66affSColin Finck physDev->handles_size * sizeof(physDev->handles[0]));
51*c2c66affSColin Finck }
52*c2c66affSColin Finck physDev->handles[index] = get_full_gdi_handle( obj );
53*c2c66affSColin Finck
54*c2c66affSColin Finck physDev->cur_handles++;
55*c2c66affSColin Finck if(physDev->cur_handles > physDev->mh->mtNoObjects)
56*c2c66affSColin Finck physDev->mh->mtNoObjects++;
57*c2c66affSColin Finck
58*c2c66affSColin Finck return index ; /* index 0 is not reserved for metafiles */
59*c2c66affSColin Finck }
60*c2c66affSColin Finck
61*c2c66affSColin Finck /******************************************************************
62*c2c66affSColin Finck * MFDRV_RemoveHandle
63*c2c66affSColin Finck */
MFDRV_RemoveHandle(PHYSDEV dev,UINT index)64*c2c66affSColin Finck BOOL MFDRV_RemoveHandle( PHYSDEV dev, UINT index )
65*c2c66affSColin Finck {
66*c2c66affSColin Finck METAFILEDRV_PDEVICE *physDev = (METAFILEDRV_PDEVICE *)dev;
67*c2c66affSColin Finck BOOL ret = FALSE;
68*c2c66affSColin Finck
69*c2c66affSColin Finck if (index < physDev->handles_size && physDev->handles[index])
70*c2c66affSColin Finck {
71*c2c66affSColin Finck physDev->handles[index] = 0;
72*c2c66affSColin Finck physDev->cur_handles--;
73*c2c66affSColin Finck ret = TRUE;
74*c2c66affSColin Finck }
75*c2c66affSColin Finck return ret;
76*c2c66affSColin Finck }
77*c2c66affSColin Finck
78*c2c66affSColin Finck /******************************************************************
79*c2c66affSColin Finck * MFDRV_FindObject
80*c2c66affSColin Finck */
MFDRV_FindObject(PHYSDEV dev,HGDIOBJ obj)81*c2c66affSColin Finck static INT16 MFDRV_FindObject( PHYSDEV dev, HGDIOBJ obj )
82*c2c66affSColin Finck {
83*c2c66affSColin Finck METAFILEDRV_PDEVICE *physDev = (METAFILEDRV_PDEVICE *)dev;
84*c2c66affSColin Finck INT16 index;
85*c2c66affSColin Finck
86*c2c66affSColin Finck for(index = 0; index < physDev->handles_size; index++)
87*c2c66affSColin Finck if(physDev->handles[index] == obj) break;
88*c2c66affSColin Finck
89*c2c66affSColin Finck if(index == physDev->handles_size) return -1;
90*c2c66affSColin Finck
91*c2c66affSColin Finck return index ;
92*c2c66affSColin Finck }
93*c2c66affSColin Finck
94*c2c66affSColin Finck
95*c2c66affSColin Finck /******************************************************************
96*c2c66affSColin Finck * MFDRV_DeleteObject
97*c2c66affSColin Finck */
MFDRV_DeleteObject(PHYSDEV dev,HGDIOBJ obj)98*c2c66affSColin Finck BOOL MFDRV_DeleteObject( PHYSDEV dev, HGDIOBJ obj )
99*c2c66affSColin Finck {
100*c2c66affSColin Finck METARECORD mr;
101*c2c66affSColin Finck METAFILEDRV_PDEVICE *physDev = (METAFILEDRV_PDEVICE *)dev;
102*c2c66affSColin Finck INT16 index;
103*c2c66affSColin Finck BOOL ret = TRUE;
104*c2c66affSColin Finck
105*c2c66affSColin Finck index = MFDRV_FindObject(dev, obj);
106*c2c66affSColin Finck if( index < 0 )
107*c2c66affSColin Finck return FALSE;
108*c2c66affSColin Finck
109*c2c66affSColin Finck mr.rdSize = sizeof mr / 2;
110*c2c66affSColin Finck mr.rdFunction = META_DELETEOBJECT;
111*c2c66affSColin Finck mr.rdParm[0] = index;
112*c2c66affSColin Finck
113*c2c66affSColin Finck if(!MFDRV_WriteRecord( dev, &mr, mr.rdSize*2 ))
114*c2c66affSColin Finck ret = FALSE;
115*c2c66affSColin Finck
116*c2c66affSColin Finck physDev->handles[index] = 0;
117*c2c66affSColin Finck physDev->cur_handles--;
118*c2c66affSColin Finck return ret;
119*c2c66affSColin Finck }
120*c2c66affSColin Finck
121*c2c66affSColin Finck
122*c2c66affSColin Finck /***********************************************************************
123*c2c66affSColin Finck * MFDRV_SelectObject
124*c2c66affSColin Finck */
MFDRV_SelectObject(PHYSDEV dev,INT16 index)125*c2c66affSColin Finck static BOOL MFDRV_SelectObject( PHYSDEV dev, INT16 index)
126*c2c66affSColin Finck {
127*c2c66affSColin Finck METARECORD mr;
128*c2c66affSColin Finck
129*c2c66affSColin Finck mr.rdSize = sizeof mr / 2;
130*c2c66affSColin Finck mr.rdFunction = META_SELECTOBJECT;
131*c2c66affSColin Finck mr.rdParm[0] = index;
132*c2c66affSColin Finck
133*c2c66affSColin Finck return MFDRV_WriteRecord( dev, &mr, mr.rdSize*2 );
134*c2c66affSColin Finck }
135*c2c66affSColin Finck
136*c2c66affSColin Finck
137*c2c66affSColin Finck /***********************************************************************
138*c2c66affSColin Finck * MFDRV_SelectBitmap
139*c2c66affSColin Finck */
MFDRV_SelectBitmap(PHYSDEV dev,HBITMAP hbitmap)140*c2c66affSColin Finck HBITMAP MFDRV_SelectBitmap( PHYSDEV dev, HBITMAP hbitmap )
141*c2c66affSColin Finck {
142*c2c66affSColin Finck return 0;
143*c2c66affSColin Finck }
144*c2c66affSColin Finck
145*c2c66affSColin Finck /******************************************************************
146*c2c66affSColin Finck * MFDRV_CreateBrushIndirect
147*c2c66affSColin Finck */
148*c2c66affSColin Finck
MFDRV_CreateBrushIndirect(PHYSDEV dev,HBRUSH hBrush)149*c2c66affSColin Finck INT16 MFDRV_CreateBrushIndirect(PHYSDEV dev, HBRUSH hBrush )
150*c2c66affSColin Finck {
151*c2c66affSColin Finck DWORD size;
152*c2c66affSColin Finck METARECORD *mr;
153*c2c66affSColin Finck LOGBRUSH logbrush;
154*c2c66affSColin Finck BOOL r;
155*c2c66affSColin Finck
156*c2c66affSColin Finck if (!GetObjectA( hBrush, sizeof(logbrush), &logbrush )) return -1;
157*c2c66affSColin Finck
158*c2c66affSColin Finck switch(logbrush.lbStyle)
159*c2c66affSColin Finck {
160*c2c66affSColin Finck case BS_SOLID:
161*c2c66affSColin Finck case BS_NULL:
162*c2c66affSColin Finck case BS_HATCHED:
163*c2c66affSColin Finck {
164*c2c66affSColin Finck LOGBRUSH16 lb16;
165*c2c66affSColin Finck
166*c2c66affSColin Finck lb16.lbStyle = logbrush.lbStyle;
167*c2c66affSColin Finck lb16.lbColor = logbrush.lbColor;
168*c2c66affSColin Finck lb16.lbHatch = logbrush.lbHatch;
169*c2c66affSColin Finck size = sizeof(METARECORD) + sizeof(LOGBRUSH16) - 2;
170*c2c66affSColin Finck mr = HeapAlloc( GetProcessHeap(), 0, size );
171*c2c66affSColin Finck mr->rdSize = size / 2;
172*c2c66affSColin Finck mr->rdFunction = META_CREATEBRUSHINDIRECT;
173*c2c66affSColin Finck memcpy( mr->rdParm, &lb16, sizeof(LOGBRUSH16));
174*c2c66affSColin Finck break;
175*c2c66affSColin Finck }
176*c2c66affSColin Finck case BS_PATTERN:
177*c2c66affSColin Finck case BS_DIBPATTERN:
178*c2c66affSColin Finck {
179*c2c66affSColin Finck #ifdef __REACTOS__
180*c2c66affSColin Finck char buffer[sizeof(BITMAPINFO) + 255 * sizeof(RGBQUAD)]; // ros
181*c2c66affSColin Finck #else
182*c2c66affSColin Finck char buffer[FIELD_OFFSET( BITMAPINFO, bmiColors[256] )];
183*c2c66affSColin Finck #endif
184*c2c66affSColin Finck BITMAPINFO *dst_info, *src_info = (BITMAPINFO *)buffer;
185*c2c66affSColin Finck DWORD info_size;
186*c2c66affSColin Finck char *dst_ptr;
187*c2c66affSColin Finck void *bits;
188*c2c66affSColin Finck UINT usage;
189*c2c66affSColin Finck
190*c2c66affSColin Finck if (!get_brush_bitmap_info( hBrush, src_info, &bits, &usage )) goto done;
191*c2c66affSColin Finck
192*c2c66affSColin Finck info_size = get_dib_info_size( src_info, usage );
193*c2c66affSColin Finck size = FIELD_OFFSET( METARECORD, rdParm[2] ) + info_size + src_info->bmiHeader.biSizeImage;
194*c2c66affSColin Finck
195*c2c66affSColin Finck if (!(mr = HeapAlloc( GetProcessHeap(), 0, size ))) goto done;
196*c2c66affSColin Finck mr->rdFunction = META_DIBCREATEPATTERNBRUSH;
197*c2c66affSColin Finck mr->rdSize = size / 2;
198*c2c66affSColin Finck mr->rdParm[0] = logbrush.lbStyle;
199*c2c66affSColin Finck mr->rdParm[1] = usage;
200*c2c66affSColin Finck dst_info = (BITMAPINFO *)(mr->rdParm + 2);
201*c2c66affSColin Finck memcpy( dst_info, src_info, info_size );
202*c2c66affSColin Finck if (dst_info->bmiHeader.biClrUsed == 1 << dst_info->bmiHeader.biBitCount)
203*c2c66affSColin Finck dst_info->bmiHeader.biClrUsed = 0;
204*c2c66affSColin Finck dst_ptr = (char *)dst_info + info_size;
205*c2c66affSColin Finck
206*c2c66affSColin Finck /* always return a bottom-up DIB */
207*c2c66affSColin Finck if (dst_info->bmiHeader.biHeight < 0)
208*c2c66affSColin Finck {
209*c2c66affSColin Finck int i, width_bytes = get_dib_stride( dst_info->bmiHeader.biWidth,
210*c2c66affSColin Finck dst_info->bmiHeader.biBitCount );
211*c2c66affSColin Finck dst_info->bmiHeader.biHeight = -dst_info->bmiHeader.biHeight;
212*c2c66affSColin Finck dst_ptr += (dst_info->bmiHeader.biHeight - 1) * width_bytes;
213*c2c66affSColin Finck for (i = 0; i < dst_info->bmiHeader.biHeight; i++, dst_ptr -= width_bytes)
214*c2c66affSColin Finck memcpy( dst_ptr, (char *)bits + i * width_bytes, width_bytes );
215*c2c66affSColin Finck }
216*c2c66affSColin Finck else memcpy( dst_ptr, bits, src_info->bmiHeader.biSizeImage );
217*c2c66affSColin Finck break;
218*c2c66affSColin Finck }
219*c2c66affSColin Finck
220*c2c66affSColin Finck default:
221*c2c66affSColin Finck FIXME("Unknown brush style %x\n", logbrush.lbStyle);
222*c2c66affSColin Finck return 0;
223*c2c66affSColin Finck }
224*c2c66affSColin Finck r = MFDRV_WriteRecord( dev, mr, mr->rdSize * 2);
225*c2c66affSColin Finck HeapFree(GetProcessHeap(), 0, mr);
226*c2c66affSColin Finck if( !r )
227*c2c66affSColin Finck return -1;
228*c2c66affSColin Finck done:
229*c2c66affSColin Finck return MFDRV_AddHandle( dev, hBrush );
230*c2c66affSColin Finck }
231*c2c66affSColin Finck
232*c2c66affSColin Finck
233*c2c66affSColin Finck /***********************************************************************
234*c2c66affSColin Finck * MFDRV_SelectBrush
235*c2c66affSColin Finck */
MFDRV_SelectBrush(PHYSDEV dev,HBRUSH hbrush,const struct brush_pattern * pattern)236*c2c66affSColin Finck HBRUSH MFDRV_SelectBrush( PHYSDEV dev, HBRUSH hbrush, const struct brush_pattern *pattern )
237*c2c66affSColin Finck {
238*c2c66affSColin Finck INT16 index;
239*c2c66affSColin Finck
240*c2c66affSColin Finck index = MFDRV_FindObject(dev, hbrush);
241*c2c66affSColin Finck if( index < 0 )
242*c2c66affSColin Finck {
243*c2c66affSColin Finck index = MFDRV_CreateBrushIndirect( dev, hbrush );
244*c2c66affSColin Finck if( index < 0 )
245*c2c66affSColin Finck return 0;
246*c2c66affSColin Finck GDI_hdc_using_object(hbrush, dev->hdc);
247*c2c66affSColin Finck }
248*c2c66affSColin Finck return MFDRV_SelectObject( dev, index ) ? hbrush : 0;
249*c2c66affSColin Finck }
250*c2c66affSColin Finck
251*c2c66affSColin Finck /******************************************************************
252*c2c66affSColin Finck * MFDRV_CreateFontIndirect
253*c2c66affSColin Finck */
254*c2c66affSColin Finck
MFDRV_CreateFontIndirect(PHYSDEV dev,HFONT hFont,LOGFONTW * logfont)255*c2c66affSColin Finck static UINT16 MFDRV_CreateFontIndirect(PHYSDEV dev, HFONT hFont, LOGFONTW *logfont)
256*c2c66affSColin Finck {
257*c2c66affSColin Finck char buffer[sizeof(METARECORD) - 2 + sizeof(LOGFONT16)];
258*c2c66affSColin Finck METARECORD *mr = (METARECORD *)&buffer;
259*c2c66affSColin Finck LOGFONT16 *font16;
260*c2c66affSColin Finck INT written;
261*c2c66affSColin Finck
262*c2c66affSColin Finck mr->rdSize = (sizeof(METARECORD) + sizeof(LOGFONT16) - 2) / 2;
263*c2c66affSColin Finck mr->rdFunction = META_CREATEFONTINDIRECT;
264*c2c66affSColin Finck font16 = (LOGFONT16 *)&mr->rdParm;
265*c2c66affSColin Finck
266*c2c66affSColin Finck font16->lfHeight = logfont->lfHeight;
267*c2c66affSColin Finck font16->lfWidth = logfont->lfWidth;
268*c2c66affSColin Finck font16->lfEscapement = logfont->lfEscapement;
269*c2c66affSColin Finck font16->lfOrientation = logfont->lfOrientation;
270*c2c66affSColin Finck font16->lfWeight = logfont->lfWeight;
271*c2c66affSColin Finck font16->lfItalic = logfont->lfItalic;
272*c2c66affSColin Finck font16->lfUnderline = logfont->lfUnderline;
273*c2c66affSColin Finck font16->lfStrikeOut = logfont->lfStrikeOut;
274*c2c66affSColin Finck font16->lfCharSet = logfont->lfCharSet;
275*c2c66affSColin Finck font16->lfOutPrecision = logfont->lfOutPrecision;
276*c2c66affSColin Finck font16->lfClipPrecision = logfont->lfClipPrecision;
277*c2c66affSColin Finck font16->lfQuality = logfont->lfQuality;
278*c2c66affSColin Finck font16->lfPitchAndFamily = logfont->lfPitchAndFamily;
279*c2c66affSColin Finck written = WideCharToMultiByte( CP_ACP, 0, logfont->lfFaceName, -1, font16->lfFaceName, LF_FACESIZE - 1, NULL, NULL );
280*c2c66affSColin Finck /* Zero pad the facename buffer, so that we don't write uninitialized data to disk */
281*c2c66affSColin Finck memset(font16->lfFaceName + written, 0, LF_FACESIZE - written);
282*c2c66affSColin Finck
283*c2c66affSColin Finck if (!(MFDRV_WriteRecord( dev, mr, mr->rdSize * 2)))
284*c2c66affSColin Finck return 0;
285*c2c66affSColin Finck return MFDRV_AddHandle( dev, hFont );
286*c2c66affSColin Finck }
287*c2c66affSColin Finck
288*c2c66affSColin Finck
289*c2c66affSColin Finck /***********************************************************************
290*c2c66affSColin Finck * MFDRV_SelectFont
291*c2c66affSColin Finck */
MFDRV_SelectFont(PHYSDEV dev,HFONT hfont,UINT * aa_flags)292*c2c66affSColin Finck HFONT MFDRV_SelectFont( PHYSDEV dev, HFONT hfont, UINT *aa_flags )
293*c2c66affSColin Finck {
294*c2c66affSColin Finck LOGFONTW font;
295*c2c66affSColin Finck INT16 index;
296*c2c66affSColin Finck
297*c2c66affSColin Finck *aa_flags = GGO_BITMAP; /* no point in anti-aliasing on metafiles */
298*c2c66affSColin Finck index = MFDRV_FindObject(dev, hfont);
299*c2c66affSColin Finck if( index < 0 )
300*c2c66affSColin Finck {
301*c2c66affSColin Finck if (!GetObjectW( hfont, sizeof(font), &font ))
302*c2c66affSColin Finck return 0;
303*c2c66affSColin Finck index = MFDRV_CreateFontIndirect(dev, hfont, &font);
304*c2c66affSColin Finck if( index < 0 )
305*c2c66affSColin Finck return 0;
306*c2c66affSColin Finck GDI_hdc_using_object(hfont, dev->hdc);
307*c2c66affSColin Finck }
308*c2c66affSColin Finck return MFDRV_SelectObject( dev, index ) ? hfont : 0;
309*c2c66affSColin Finck }
310*c2c66affSColin Finck
311*c2c66affSColin Finck /******************************************************************
312*c2c66affSColin Finck * MFDRV_CreatePenIndirect
313*c2c66affSColin Finck */
MFDRV_CreatePenIndirect(PHYSDEV dev,HPEN hPen,LOGPEN16 * logpen)314*c2c66affSColin Finck static UINT16 MFDRV_CreatePenIndirect(PHYSDEV dev, HPEN hPen, LOGPEN16 *logpen)
315*c2c66affSColin Finck {
316*c2c66affSColin Finck char buffer[sizeof(METARECORD) - 2 + sizeof(*logpen)];
317*c2c66affSColin Finck METARECORD *mr = (METARECORD *)&buffer;
318*c2c66affSColin Finck
319*c2c66affSColin Finck mr->rdSize = (sizeof(METARECORD) + sizeof(*logpen) - 2) / 2;
320*c2c66affSColin Finck mr->rdFunction = META_CREATEPENINDIRECT;
321*c2c66affSColin Finck memcpy(&(mr->rdParm), logpen, sizeof(*logpen));
322*c2c66affSColin Finck if (!(MFDRV_WriteRecord( dev, mr, mr->rdSize * 2)))
323*c2c66affSColin Finck return 0;
324*c2c66affSColin Finck return MFDRV_AddHandle( dev, hPen );
325*c2c66affSColin Finck }
326*c2c66affSColin Finck
327*c2c66affSColin Finck
328*c2c66affSColin Finck /***********************************************************************
329*c2c66affSColin Finck * MFDRV_SelectPen
330*c2c66affSColin Finck */
MFDRV_SelectPen(PHYSDEV dev,HPEN hpen,const struct brush_pattern * pattern)331*c2c66affSColin Finck HPEN MFDRV_SelectPen( PHYSDEV dev, HPEN hpen, const struct brush_pattern *pattern )
332*c2c66affSColin Finck {
333*c2c66affSColin Finck LOGPEN16 logpen;
334*c2c66affSColin Finck INT16 index;
335*c2c66affSColin Finck
336*c2c66affSColin Finck index = MFDRV_FindObject(dev, hpen);
337*c2c66affSColin Finck if( index < 0 )
338*c2c66affSColin Finck {
339*c2c66affSColin Finck /* must be an extended pen */
340*c2c66affSColin Finck INT size = GetObjectW( hpen, 0, NULL );
341*c2c66affSColin Finck
342*c2c66affSColin Finck if (!size) return 0;
343*c2c66affSColin Finck
344*c2c66affSColin Finck if (size == sizeof(LOGPEN))
345*c2c66affSColin Finck {
346*c2c66affSColin Finck LOGPEN pen;
347*c2c66affSColin Finck
348*c2c66affSColin Finck GetObjectW( hpen, sizeof(pen), &pen );
349*c2c66affSColin Finck logpen.lopnStyle = pen.lopnStyle;
350*c2c66affSColin Finck logpen.lopnWidth.x = pen.lopnWidth.x;
351*c2c66affSColin Finck logpen.lopnWidth.y = pen.lopnWidth.y;
352*c2c66affSColin Finck logpen.lopnColor = pen.lopnColor;
353*c2c66affSColin Finck }
354*c2c66affSColin Finck else /* must be an extended pen */
355*c2c66affSColin Finck {
356*c2c66affSColin Finck EXTLOGPEN *elp = HeapAlloc( GetProcessHeap(), 0, size );
357*c2c66affSColin Finck
358*c2c66affSColin Finck GetObjectW( hpen, size, elp );
359*c2c66affSColin Finck /* FIXME: add support for user style pens */
360*c2c66affSColin Finck logpen.lopnStyle = elp->elpPenStyle;
361*c2c66affSColin Finck logpen.lopnWidth.x = elp->elpWidth;
362*c2c66affSColin Finck logpen.lopnWidth.y = 0;
363*c2c66affSColin Finck logpen.lopnColor = elp->elpColor;
364*c2c66affSColin Finck
365*c2c66affSColin Finck HeapFree( GetProcessHeap(), 0, elp );
366*c2c66affSColin Finck }
367*c2c66affSColin Finck
368*c2c66affSColin Finck index = MFDRV_CreatePenIndirect( dev, hpen, &logpen );
369*c2c66affSColin Finck if( index < 0 )
370*c2c66affSColin Finck return 0;
371*c2c66affSColin Finck GDI_hdc_using_object(hpen, dev->hdc);
372*c2c66affSColin Finck }
373*c2c66affSColin Finck return MFDRV_SelectObject( dev, index ) ? hpen : 0;
374*c2c66affSColin Finck }
375*c2c66affSColin Finck
376*c2c66affSColin Finck
377*c2c66affSColin Finck /******************************************************************
378*c2c66affSColin Finck * MFDRV_CreatePalette
379*c2c66affSColin Finck */
MFDRV_CreatePalette(PHYSDEV dev,HPALETTE hPalette,LOGPALETTE * logPalette,int sizeofPalette)380*c2c66affSColin Finck static BOOL MFDRV_CreatePalette(PHYSDEV dev, HPALETTE hPalette, LOGPALETTE* logPalette, int sizeofPalette)
381*c2c66affSColin Finck {
382*c2c66affSColin Finck int index;
383*c2c66affSColin Finck BOOL ret;
384*c2c66affSColin Finck METARECORD *mr;
385*c2c66affSColin Finck
386*c2c66affSColin Finck mr = HeapAlloc( GetProcessHeap(), 0, sizeof(METARECORD) + sizeofPalette - sizeof(WORD) );
387*c2c66affSColin Finck mr->rdSize = (sizeof(METARECORD) + sizeofPalette - sizeof(WORD)) / sizeof(WORD);
388*c2c66affSColin Finck mr->rdFunction = META_CREATEPALETTE;
389*c2c66affSColin Finck memcpy(&(mr->rdParm), logPalette, sizeofPalette);
390*c2c66affSColin Finck if (!(MFDRV_WriteRecord( dev, mr, mr->rdSize * sizeof(WORD))))
391*c2c66affSColin Finck {
392*c2c66affSColin Finck HeapFree(GetProcessHeap(), 0, mr);
393*c2c66affSColin Finck return FALSE;
394*c2c66affSColin Finck }
395*c2c66affSColin Finck
396*c2c66affSColin Finck mr->rdSize = sizeof(METARECORD) / sizeof(WORD);
397*c2c66affSColin Finck mr->rdFunction = META_SELECTPALETTE;
398*c2c66affSColin Finck
399*c2c66affSColin Finck if ((index = MFDRV_AddHandle( dev, hPalette )) == -1) ret = FALSE;
400*c2c66affSColin Finck else
401*c2c66affSColin Finck {
402*c2c66affSColin Finck *(mr->rdParm) = index;
403*c2c66affSColin Finck ret = MFDRV_WriteRecord( dev, mr, mr->rdSize * sizeof(WORD));
404*c2c66affSColin Finck }
405*c2c66affSColin Finck HeapFree(GetProcessHeap(), 0, mr);
406*c2c66affSColin Finck return ret;
407*c2c66affSColin Finck }
408*c2c66affSColin Finck
409*c2c66affSColin Finck
410*c2c66affSColin Finck /***********************************************************************
411*c2c66affSColin Finck * MFDRV_SelectPalette
412*c2c66affSColin Finck */
MFDRV_SelectPalette(PHYSDEV dev,HPALETTE hPalette,BOOL bForceBackground)413*c2c66affSColin Finck HPALETTE MFDRV_SelectPalette( PHYSDEV dev, HPALETTE hPalette, BOOL bForceBackground )
414*c2c66affSColin Finck {
415*c2c66affSColin Finck #define PALVERSION 0x0300
416*c2c66affSColin Finck
417*c2c66affSColin Finck PLOGPALETTE logPalette;
418*c2c66affSColin Finck WORD wNumEntries = 0;
419*c2c66affSColin Finck BOOL creationSucceed;
420*c2c66affSColin Finck int sizeofPalette;
421*c2c66affSColin Finck
422*c2c66affSColin Finck GetObjectA(hPalette, sizeof(WORD), &wNumEntries);
423*c2c66affSColin Finck
424*c2c66affSColin Finck if (wNumEntries == 0) return 0;
425*c2c66affSColin Finck
426*c2c66affSColin Finck sizeofPalette = sizeof(LOGPALETTE) + ((wNumEntries-1) * sizeof(PALETTEENTRY));
427*c2c66affSColin Finck logPalette = HeapAlloc( GetProcessHeap(), 0, sizeofPalette );
428*c2c66affSColin Finck
429*c2c66affSColin Finck if (logPalette == NULL) return 0;
430*c2c66affSColin Finck
431*c2c66affSColin Finck logPalette->palVersion = PALVERSION;
432*c2c66affSColin Finck logPalette->palNumEntries = wNumEntries;
433*c2c66affSColin Finck
434*c2c66affSColin Finck GetPaletteEntries(hPalette, 0, wNumEntries, logPalette->palPalEntry);
435*c2c66affSColin Finck
436*c2c66affSColin Finck creationSucceed = MFDRV_CreatePalette( dev, hPalette, logPalette, sizeofPalette );
437*c2c66affSColin Finck
438*c2c66affSColin Finck HeapFree( GetProcessHeap(), 0, logPalette );
439*c2c66affSColin Finck
440*c2c66affSColin Finck if (creationSucceed)
441*c2c66affSColin Finck return hPalette;
442*c2c66affSColin Finck
443*c2c66affSColin Finck return 0;
444*c2c66affSColin Finck }
445*c2c66affSColin Finck
446*c2c66affSColin Finck /***********************************************************************
447*c2c66affSColin Finck * MFDRV_RealizePalette
448*c2c66affSColin Finck */
MFDRV_RealizePalette(PHYSDEV dev,HPALETTE hPalette,BOOL dummy)449*c2c66affSColin Finck UINT MFDRV_RealizePalette(PHYSDEV dev, HPALETTE hPalette, BOOL dummy)
450*c2c66affSColin Finck {
451*c2c66affSColin Finck char buffer[sizeof(METARECORD) - sizeof(WORD)];
452*c2c66affSColin Finck METARECORD *mr = (METARECORD *)&buffer;
453*c2c66affSColin Finck
454*c2c66affSColin Finck mr->rdSize = (sizeof(METARECORD) - sizeof(WORD)) / sizeof(WORD);
455*c2c66affSColin Finck mr->rdFunction = META_REALIZEPALETTE;
456*c2c66affSColin Finck
457*c2c66affSColin Finck if (!(MFDRV_WriteRecord( dev, mr, mr->rdSize * sizeof(WORD)))) return 0;
458*c2c66affSColin Finck
459*c2c66affSColin Finck /* The return value is suppose to be the number of entries
460*c2c66affSColin Finck in the logical palette mapped to the system palette or 0
461*c2c66affSColin Finck if the function failed. Since it's not trivial here to
462*c2c66affSColin Finck get that kind of information and since it's of little
463*c2c66affSColin Finck use in the case of metafiles, we'll always return 1. */
464*c2c66affSColin Finck return 1;
465*c2c66affSColin Finck }
466