2 * Enhanced MetaFile objects
4 * Copyright 1999 Huw D M Davies
12 #include "enhmetafiledrv.h"
13 #include "debugtools.h"
15 DEFAULT_DEBUG_CHANNEL(enhmetafile
);
17 /***********************************************************************
18 * EMFDRV_BITMAP_SelectObject
20 static HBITMAP
EMFDRV_BITMAP_SelectObject( DC
* dc
, HBITMAP hbitmap
)
26 /***********************************************************************
27 * EMFDRV_CreateBrushIndirect
29 DWORD
EMFDRV_CreateBrushIndirect( DC
*dc
, HBRUSH hBrush
)
34 if (!GetObjectA( hBrush
, sizeof(logbrush
), &logbrush
)) return 0;
36 switch (logbrush
.lbStyle
) {
41 EMRCREATEBRUSHINDIRECT emr
;
42 emr
.emr
.iType
= EMR_CREATEBRUSHINDIRECT
;
43 emr
.emr
.nSize
= sizeof(emr
);
44 emr
.ihBrush
= index
= EMFDRV_AddHandleDC( dc
);
47 if(!EMFDRV_WriteRecord( dc
, &emr
.emr
))
53 EMRCREATEDIBPATTERNBRUSHPT
*emr
;
54 DWORD bmSize
, biSize
, size
;
55 BITMAPINFO
*info
= GlobalLock16(logbrush
.lbHatch
);
57 if (info
->bmiHeader
.biCompression
)
58 bmSize
= info
->bmiHeader
.biSizeImage
;
60 bmSize
= DIB_GetDIBImageBytes(info
->bmiHeader
.biWidth
,
61 info
->bmiHeader
.biHeight
,
62 info
->bmiHeader
.biBitCount
);
63 biSize
= DIB_BitmapInfoSize(info
, LOWORD(logbrush
.lbColor
));
64 size
= sizeof(EMRCREATEDIBPATTERNBRUSHPT
) + biSize
+ bmSize
;
65 emr
= HeapAlloc( GetProcessHeap(), 0, size
);
67 emr
->emr
.iType
= EMR_CREATEDIBPATTERNBRUSHPT
;
68 emr
->emr
.nSize
= size
;
69 emr
->ihBrush
= index
= EMFDRV_AddHandleDC( dc
);
70 emr
->iUsage
= LOWORD(logbrush
.lbColor
);
71 emr
->offBmi
= sizeof(EMRCREATEDIBPATTERNBRUSHPT
);
73 emr
->offBits
= sizeof(EMRCREATEDIBPATTERNBRUSHPT
) + biSize
;
74 memcpy((char *)emr
+ sizeof(EMRCREATEDIBPATTERNBRUSHPT
), info
,
77 if(!EMFDRV_WriteRecord( dc
, &emr
->emr
))
79 HeapFree( GetProcessHeap(), 0, emr
);
80 GlobalUnlock16(logbrush
.lbHatch
);
85 FIXME("Unsupported style %x\n",
89 FIXME("Unknown style %x\n", logbrush
.lbStyle
);
96 /***********************************************************************
97 * EMFDRV_BRUSH_SelectObject
99 static HBRUSH
EMFDRV_BRUSH_SelectObject(DC
*dc
, HBRUSH hBrush
)
106 /* If the object is a stock brush object, do not need to create it.
107 * See definitions in wingdi.h for range of stock brushes.
108 * We do however have to handle setting the higher order bit to
109 * designate that this is a stock object.
111 for (i
= WHITE_BRUSH
; i
<= NULL_BRUSH
; i
++)
113 if (hBrush
== GetStockObject(i
))
115 index
= i
| 0x80000000;
119 if (!(index
= EMFDRV_CreateBrushIndirect(dc
, hBrush
))) return 0;
122 emr
.emr
.iType
= EMR_SELECTOBJECT
;
123 emr
.emr
.nSize
= sizeof(emr
);
124 emr
.ihObject
= index
;
125 if(!EMFDRV_WriteRecord( dc
, &emr
.emr
))
128 hOldBrush
= dc
->hBrush
;
134 /******************************************************************
135 * EMFDRV_CreateFontIndirect
137 static BOOL
EMFDRV_CreateFontIndirect(DC
*dc
, HFONT hFont
)
140 EMREXTCREATEFONTINDIRECTW emr
;
143 if (!GetObjectW( hFont
, sizeof(emr
.elfw
.elfLogFont
), &emr
.elfw
.elfLogFont
)) return 0;
145 emr
.emr
.iType
= EMR_EXTCREATEFONTINDIRECTW
;
146 emr
.emr
.nSize
= (sizeof(emr
) + 3) / 4 * 4;
147 emr
.ihFont
= index
= EMFDRV_AddHandleDC( dc
);
148 emr
.elfw
.elfFullName
[0] = '\0';
149 emr
.elfw
.elfStyle
[0] = '\0';
150 emr
.elfw
.elfVersion
= 0;
151 emr
.elfw
.elfStyleSize
= 0;
152 emr
.elfw
.elfMatch
= 0;
153 emr
.elfw
.elfReserved
= 0;
154 for(i
= 0; i
< ELF_VENDOR_SIZE
; i
++)
155 emr
.elfw
.elfVendorId
[i
] = 0;
156 emr
.elfw
.elfCulture
= PAN_CULTURE_LATIN
;
157 emr
.elfw
.elfPanose
.bFamilyType
= PAN_NO_FIT
;
158 emr
.elfw
.elfPanose
.bSerifStyle
= PAN_NO_FIT
;
159 emr
.elfw
.elfPanose
.bWeight
= PAN_NO_FIT
;
160 emr
.elfw
.elfPanose
.bProportion
= PAN_NO_FIT
;
161 emr
.elfw
.elfPanose
.bContrast
= PAN_NO_FIT
;
162 emr
.elfw
.elfPanose
.bStrokeVariation
= PAN_NO_FIT
;
163 emr
.elfw
.elfPanose
.bArmStyle
= PAN_NO_FIT
;
164 emr
.elfw
.elfPanose
.bLetterform
= PAN_NO_FIT
;
165 emr
.elfw
.elfPanose
.bMidline
= PAN_NO_FIT
;
166 emr
.elfw
.elfPanose
.bXHeight
= PAN_NO_FIT
;
168 if(!EMFDRV_WriteRecord( dc
, &emr
.emr
))
174 /***********************************************************************
175 * EMFDRV_FONT_SelectObject
177 static HFONT
EMFDRV_FONT_SelectObject( DC
* dc
, HFONT hFont
)
183 /* If the object is a stock font object, do not need to create it.
184 * See definitions in wingdi.h for range of stock fonts.
185 * We do however have to handle setting the higher order bit to
186 * designate that this is a stock object.
189 for (i
= OEM_FIXED_FONT
; i
<= DEFAULT_GUI_FONT
; i
++)
191 if (i
!= DEFAULT_PALETTE
&& hFont
== GetStockObject(i
))
193 index
= i
| 0x80000000;
197 if (!(index
= EMFDRV_CreateFontIndirect(dc
, hFont
))) return GDI_ERROR
;
199 emr
.emr
.iType
= EMR_SELECTOBJECT
;
200 emr
.emr
.nSize
= sizeof(emr
);
201 emr
.ihObject
= index
;
202 if(!EMFDRV_WriteRecord( dc
, &emr
.emr
))
210 /******************************************************************
211 * EMFDRV_CreatePenIndirect
213 static HPEN
EMFDRV_CreatePenIndirect(DC
*dc
, HPEN hPen
)
218 if (!GetObjectA( hPen
, sizeof(emr
.lopn
), &emr
.lopn
)) return 0;
220 emr
.emr
.iType
= EMR_CREATEPEN
;
221 emr
.emr
.nSize
= sizeof(emr
);
222 emr
.ihPen
= index
= EMFDRV_AddHandleDC( dc
);
224 if(!EMFDRV_WriteRecord( dc
, &emr
.emr
))
229 /******************************************************************
230 * EMFDRV_PEN_SelectObject
232 static HPEN
EMFDRV_PEN_SelectObject(DC
*dc
, HPEN hPen
)
239 /* If the object is a stock pen object, do not need to create it.
240 * See definitions in wingdi.h for range of stock pens.
241 * We do however have to handle setting the higher order bit to
242 * designate that this is a stock object.
245 for (i
= WHITE_PEN
; i
<= NULL_PEN
; i
++)
247 if (hPen
== GetStockObject(i
))
249 index
= i
| 0x80000000;
253 if (!(index
= EMFDRV_CreatePenIndirect(dc
, hPen
))) return 0;
255 emr
.emr
.iType
= EMR_SELECTOBJECT
;
256 emr
.emr
.nSize
= sizeof(emr
);
257 emr
.ihObject
= index
;
258 if(!EMFDRV_WriteRecord( dc
, &emr
.emr
))
267 /***********************************************************************
268 * EMFDRV_SelectObject
270 HGDIOBJ
EMFDRV_SelectObject( DC
*dc
, HGDIOBJ handle
)
272 GDIOBJHDR
* ptr
= GDI_GetObjPtr( handle
, MAGIC_DONTCARE
);
276 TRACE("hdc=%04x %04x\n", dc
->hSelf
, handle
);
278 switch(GDIMAGIC(ptr
->wMagic
))
281 ret
= EMFDRV_PEN_SelectObject( dc
, handle
);
284 ret
= EMFDRV_BRUSH_SelectObject( dc
, handle
);
287 ret
= EMFDRV_FONT_SelectObject( dc
, handle
);
290 ret
= EMFDRV_BITMAP_SelectObject( dc
, handle
);
293 GDI_ReleaseObj( handle
);