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
)
105 /* If the object is a stock brush object, do not need to create it.
106 * See definitions in wingdi.h for range of stock brushes.
107 * We do however have to handle setting the higher order bit to
108 * designate that this is a stock object.
110 if (hBrush
>= FIRST_STOCK_HANDLE
&&
111 hBrush
<= FIRST_STOCK_HANDLE
+HOLLOW_BRUSH
)
113 DWORD brush_index
= hBrush
- FIRST_STOCK_HANDLE
;
114 index
= brush_index
| 0x80000000;
118 index
= EMFDRV_CreateBrushIndirect(dc
, hBrush
);
121 if(!index
) return FALSE
;
123 emr
.emr
.iType
= EMR_SELECTOBJECT
;
124 emr
.emr
.nSize
= sizeof(emr
);
125 emr
.ihObject
= index
;
126 if(!EMFDRV_WriteRecord( dc
, &emr
.emr
))
129 hOldBrush
= dc
->hBrush
;
135 /******************************************************************
136 * EMFDRV_CreateFontIndirect
138 static BOOL
EMFDRV_CreateFontIndirect(DC
*dc
, HFONT hFont
)
141 EMREXTCREATEFONTINDIRECTW emr
;
144 if (!GetObjectW( hFont
, sizeof(emr
.elfw
.elfLogFont
), &emr
.elfw
.elfLogFont
)) return 0;
146 emr
.emr
.iType
= EMR_EXTCREATEFONTINDIRECTW
;
147 emr
.emr
.nSize
= (sizeof(emr
) + 3) / 4 * 4;
148 emr
.ihFont
= index
= EMFDRV_AddHandleDC( dc
);
149 emr
.elfw
.elfFullName
[0] = '\0';
150 emr
.elfw
.elfStyle
[0] = '\0';
151 emr
.elfw
.elfVersion
= 0;
152 emr
.elfw
.elfStyleSize
= 0;
153 emr
.elfw
.elfMatch
= 0;
154 emr
.elfw
.elfReserved
= 0;
155 for(i
= 0; i
< ELF_VENDOR_SIZE
; i
++)
156 emr
.elfw
.elfVendorId
[i
] = 0;
157 emr
.elfw
.elfCulture
= PAN_CULTURE_LATIN
;
158 emr
.elfw
.elfPanose
.bFamilyType
= PAN_NO_FIT
;
159 emr
.elfw
.elfPanose
.bSerifStyle
= PAN_NO_FIT
;
160 emr
.elfw
.elfPanose
.bWeight
= PAN_NO_FIT
;
161 emr
.elfw
.elfPanose
.bProportion
= PAN_NO_FIT
;
162 emr
.elfw
.elfPanose
.bContrast
= PAN_NO_FIT
;
163 emr
.elfw
.elfPanose
.bStrokeVariation
= PAN_NO_FIT
;
164 emr
.elfw
.elfPanose
.bArmStyle
= PAN_NO_FIT
;
165 emr
.elfw
.elfPanose
.bLetterform
= PAN_NO_FIT
;
166 emr
.elfw
.elfPanose
.bMidline
= PAN_NO_FIT
;
167 emr
.elfw
.elfPanose
.bXHeight
= PAN_NO_FIT
;
169 if(!EMFDRV_WriteRecord( dc
, &emr
.emr
))
175 /***********************************************************************
176 * EMFDRV_FONT_SelectObject
178 static HFONT
EMFDRV_FONT_SelectObject( DC
* dc
, HFONT hFont
)
184 /* If the object is a stock font object, do not need to create it.
185 * See definitions in wingdi.h for range of stock fonts.
186 * We do however have to handle setting the higher order bit to
187 * designate that this is a stock object.
190 if (hFont
>= STOCK_OEM_FIXED_FONT
&&
191 hFont
<= STOCK_DEFAULT_GUI_FONT
&&
192 hFont
!= STOCK_DEFAULT_PALETTE
)
194 DWORD font_index
= hFont
- FIRST_STOCK_HANDLE
;
195 index
= font_index
| 0x80000000;
199 index
= EMFDRV_CreateFontIndirect(dc
, hFont
);
202 if(!index
) return FALSE
;
204 emr
.emr
.iType
= EMR_SELECTOBJECT
;
205 emr
.emr
.nSize
= sizeof(emr
);
206 emr
.ihObject
= index
;
207 if(!EMFDRV_WriteRecord( dc
, &emr
.emr
))
210 hOldFont
= dc
->hFont
;
217 /******************************************************************
218 * EMFDRV_CreatePenIndirect
220 static HPEN
EMFDRV_CreatePenIndirect(DC
*dc
, HPEN hPen
)
225 if (!GetObjectA( hPen
, sizeof(emr
.lopn
), &emr
.lopn
)) return 0;
227 emr
.emr
.iType
= EMR_CREATEPEN
;
228 emr
.emr
.nSize
= sizeof(emr
);
229 emr
.ihPen
= index
= EMFDRV_AddHandleDC( dc
);
231 if(!EMFDRV_WriteRecord( dc
, &emr
.emr
))
236 /******************************************************************
237 * EMFDRV_PEN_SelectObject
239 static HPEN
EMFDRV_PEN_SelectObject(DC
*dc
, HPEN hPen
)
245 /* If the object is a stock pen object, do not need to create it.
246 * See definitions in wingdi.h for range of stock pens.
247 * We do however have to handle setting the higher order bit to
248 * designate that this is a stock object.
251 if (hPen
>= STOCK_WHITE_PEN
&&
252 hPen
<= STOCK_NULL_PEN
)
254 DWORD pen_index
= hPen
- FIRST_STOCK_HANDLE
;
255 index
= pen_index
| 0x80000000;
259 index
= EMFDRV_CreatePenIndirect(dc
, hPen
);
262 if(!index
) return FALSE
;
264 emr
.emr
.iType
= EMR_SELECTOBJECT
;
265 emr
.emr
.nSize
= sizeof(emr
);
266 emr
.ihObject
= index
;
267 if(!EMFDRV_WriteRecord( dc
, &emr
.emr
))
276 /***********************************************************************
277 * EMFDRV_SelectObject
279 HGDIOBJ
EMFDRV_SelectObject( DC
*dc
, HGDIOBJ handle
)
281 GDIOBJHDR
* ptr
= GDI_GetObjPtr( handle
, MAGIC_DONTCARE
);
285 TRACE("hdc=%04x %04x\n", dc
->hSelf
, handle
);
287 switch(GDIMAGIC(ptr
->wMagic
))
290 ret
= EMFDRV_PEN_SelectObject( dc
, handle
);
293 ret
= EMFDRV_BRUSH_SelectObject( dc
, handle
);
296 ret
= EMFDRV_FONT_SelectObject( dc
, handle
);
299 ret
= EMFDRV_BITMAP_SelectObject( dc
, handle
);
302 GDI_ReleaseObj( handle
);