Moved SystemHeap allocations to the process heap.
[wine.git] / graphics / enhmetafiledrv / objects.c
blobf373cebcf7c5f80357c06f42a4984c07d0633463
1 /*
2 * Enhanced MetaFile objects
4 * Copyright 1999 Huw D M Davies
5 */
7 #include <stdlib.h>
8 #include <stdio.h>
9 #include <string.h>
11 #include "bitmap.h"
12 #include "brush.h"
13 #include "font.h"
14 #include "enhmetafiledrv.h"
15 #include "pen.h"
16 #include "debugtools.h"
17 #include "heap.h"
19 DEFAULT_DEBUG_CHANNEL(enhmetafile)
21 /***********************************************************************
22 * EMFDRV_BITMAP_SelectObject
24 static HBITMAP EMFDRV_BITMAP_SelectObject( DC * dc, HBITMAP hbitmap )
26 return 0;
30 /***********************************************************************
31 * EMFDRV_CreateBrushIndirect
33 DWORD EMFDRV_CreateBrushIndirect( DC *dc, HBRUSH hBrush )
35 DWORD index = 0;
36 BRUSHOBJ *brushObj = (BRUSHOBJ *)GDI_GetObjPtr( hBrush, BRUSH_MAGIC );
38 switch (brushObj->logbrush.lbStyle) {
39 case BS_SOLID:
40 case BS_HATCHED:
41 case BS_NULL:
43 EMRCREATEBRUSHINDIRECT emr;
44 emr.emr.iType = EMR_CREATEBRUSHINDIRECT;
45 emr.emr.nSize = sizeof(emr);
46 emr.ihBrush = index = EMFDRV_AddHandleDC( dc );
47 emr.lb = brushObj->logbrush;
49 if(!EMFDRV_WriteRecord( dc, &emr.emr ))
50 index = 0;
52 break;
53 case BS_DIBPATTERN:
55 EMRCREATEDIBPATTERNBRUSHPT *emr;
56 DWORD bmSize, biSize, size;
57 BITMAPINFO *info = GlobalLock16(brushObj->logbrush.lbHatch);
59 if (info->bmiHeader.biCompression)
60 bmSize = info->bmiHeader.biSizeImage;
61 else
62 bmSize = DIB_GetDIBImageBytes(info->bmiHeader.biWidth,
63 info->bmiHeader.biHeight,
64 info->bmiHeader.biBitCount);
65 biSize = DIB_BitmapInfoSize(info, LOWORD(brushObj->logbrush.lbColor));
66 size = sizeof(EMRCREATEDIBPATTERNBRUSHPT) + biSize + bmSize;
67 emr = HeapAlloc( GetProcessHeap(), 0, size );
68 if(!emr) break;
69 emr->emr.iType = EMR_CREATEDIBPATTERNBRUSHPT;
70 emr->emr.nSize = size;
71 emr->ihBrush = index = EMFDRV_AddHandleDC( dc );
72 emr->iUsage = LOWORD(brushObj->logbrush.lbColor);
73 emr->offBmi = sizeof(EMRCREATEDIBPATTERNBRUSHPT);
74 emr->cbBmi = biSize;
75 emr->offBits = sizeof(EMRCREATEDIBPATTERNBRUSHPT) + biSize;
76 memcpy((char *)emr + sizeof(EMRCREATEDIBPATTERNBRUSHPT), info,
77 biSize + bmSize );
79 if(!EMFDRV_WriteRecord( dc, &emr->emr ))
80 index = 0;
81 HeapFree( GetProcessHeap(), 0, emr );
82 GlobalUnlock16(brushObj->logbrush.lbHatch);
84 break;
86 case BS_PATTERN:
87 FIXME("Unsupported style %x\n",
88 brushObj->logbrush.lbStyle);
89 break;
90 default:
91 FIXME("Unknown style %x\n", brushObj->logbrush.lbStyle);
92 return FALSE;
94 GDI_HEAP_UNLOCK( hBrush );
95 return index;
99 /***********************************************************************
100 * EMFDRV_BRUSH_SelectObject
102 static HBRUSH EMFDRV_BRUSH_SelectObject(DC *dc, HBRUSH hBrush )
104 EMRSELECTOBJECT emr;
105 DWORD index;
106 HBRUSH hOldBrush;
108 index = EMFDRV_CreateBrushIndirect(dc, hBrush );
109 if(!index) return FALSE;
111 emr.emr.iType = EMR_SELECTOBJECT;
112 emr.emr.nSize = sizeof(emr);
113 emr.ihObject = index;
114 if(!EMFDRV_WriteRecord( dc, &emr.emr ))
115 return FALSE;
117 hOldBrush = dc->w.hBrush;
118 dc->w.hBrush = hBrush;
119 return hOldBrush;
123 /******************************************************************
124 * EMFDRV_CreateFontIndirect
126 static BOOL EMFDRV_CreateFontIndirect(DC *dc, HFONT hFont )
128 DWORD index = 0;
129 FONTOBJ *fontObj = (FONTOBJ *)GDI_GetObjPtr( hFont, FONT_MAGIC );
130 EMREXTCREATEFONTINDIRECTW emr;
131 int i;
132 emr.emr.iType = EMR_EXTCREATEFONTINDIRECTW;
133 emr.emr.nSize = (sizeof(emr) + 3) / 4 * 4;
134 emr.ihFont = index = EMFDRV_AddHandleDC( dc );
135 FONT_LogFont16To32W( &(fontObj->logfont), &(emr.elfw.elfLogFont) );
136 emr.elfw.elfFullName[0] = '\0';
137 emr.elfw.elfStyle[0] = '\0';
138 emr.elfw.elfVersion = 0;
139 emr.elfw.elfStyleSize = 0;
140 emr.elfw.elfMatch = 0;
141 emr.elfw.elfReserved = 0;
142 for(i = 0; i < ELF_VENDOR_SIZE; i++)
143 emr.elfw.elfVendorId[i] = 0;
144 emr.elfw.elfCulture = PAN_CULTURE_LATIN;
145 emr.elfw.elfPanose.bFamilyType = PAN_NO_FIT;
146 emr.elfw.elfPanose.bSerifStyle = PAN_NO_FIT;
147 emr.elfw.elfPanose.bWeight = PAN_NO_FIT;
148 emr.elfw.elfPanose.bProportion = PAN_NO_FIT;
149 emr.elfw.elfPanose.bContrast = PAN_NO_FIT;
150 emr.elfw.elfPanose.bStrokeVariation = PAN_NO_FIT;
151 emr.elfw.elfPanose.bArmStyle = PAN_NO_FIT;
152 emr.elfw.elfPanose.bLetterform = PAN_NO_FIT;
153 emr.elfw.elfPanose.bMidline = PAN_NO_FIT;
154 emr.elfw.elfPanose.bXHeight = PAN_NO_FIT;
156 if(!EMFDRV_WriteRecord( dc, &emr.emr ))
157 index = 0;
158 GDI_HEAP_UNLOCK( hFont );
159 return index;
163 /***********************************************************************
164 * EMFDRV_FONT_SelectObject
166 static HFONT EMFDRV_FONT_SelectObject( DC * dc, HFONT hFont )
168 EMRSELECTOBJECT emr;
169 DWORD index;
170 HFONT hOldFont;
172 index = EMFDRV_CreateFontIndirect(dc, hFont );
173 if(!index) return FALSE;
175 emr.emr.iType = EMR_SELECTOBJECT;
176 emr.emr.nSize = sizeof(emr);
177 emr.ihObject = index;
178 if(!EMFDRV_WriteRecord( dc, &emr.emr ))
179 return FALSE;
181 hOldFont = dc->w.hFont;
182 dc->w.hFont = hFont;
183 return hOldFont;
188 /******************************************************************
189 * EMFDRV_CreatePenIndirect
191 static HPEN EMFDRV_CreatePenIndirect(DC *dc, HPEN hPen )
193 EMRCREATEPEN emr;
194 PENOBJ *penObj = (PENOBJ *)GDI_GetObjPtr( hPen, PEN_MAGIC );
195 DWORD index = 0;
197 emr.emr.iType = EMR_CREATEPEN;
198 emr.emr.nSize = sizeof(emr);
199 emr.ihPen = index = EMFDRV_AddHandleDC( dc );
200 emr.lopn = penObj->logpen;
202 if(!EMFDRV_WriteRecord( dc, &emr.emr ))
203 index = 0;
204 GDI_HEAP_UNLOCK( hPen );
205 return index;
208 /******************************************************************
209 * EMFDRV_PEN_SelectObject
211 static HPEN EMFDRV_PEN_SelectObject(DC *dc, HPEN hPen )
213 EMRSELECTOBJECT emr;
214 DWORD index;
215 HFONT hOldPen;
217 index = EMFDRV_CreatePenIndirect(dc, hPen );
218 if(!index) return FALSE;
220 emr.emr.iType = EMR_SELECTOBJECT;
221 emr.emr.nSize = sizeof(emr);
222 emr.ihObject = index;
223 if(!EMFDRV_WriteRecord( dc, &emr.emr ))
224 return FALSE;
226 hOldPen = dc->w.hPen;
227 dc->w.hPen = hPen;
228 return hOldPen;
232 /***********************************************************************
233 * EMFDRV_SelectObject
235 HGDIOBJ EMFDRV_SelectObject( DC *dc, HGDIOBJ handle )
237 GDIOBJHDR * ptr = GDI_GetObjPtr( handle, MAGIC_DONTCARE );
238 HGDIOBJ ret = 0;
240 if (!ptr) return 0;
241 TRACE("hdc=%04x %04x\n", dc->hSelf, handle );
243 switch(ptr->wMagic)
245 case PEN_MAGIC:
246 ret = EMFDRV_PEN_SelectObject( dc, handle );
247 break;
248 case BRUSH_MAGIC:
249 ret = EMFDRV_BRUSH_SelectObject( dc, handle );
250 break;
251 case FONT_MAGIC:
252 ret = EMFDRV_FONT_SelectObject( dc, handle );
253 break;
254 case BITMAP_MAGIC:
255 ret = EMFDRV_BITMAP_SelectObject( dc, handle );
256 break;
258 GDI_HEAP_UNLOCK( handle );
259 return ret;