2 * Enhanced MetaFile objects
4 * Copyright 1999 Huw D M Davies
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2.1 of the License, or (at your option) any later version.
11 * This library is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 #include "enhmfdrv/enhmetafiledrv.h"
27 #include "wine/debug.h"
29 WINE_DEFAULT_DEBUG_CHANNEL(enhmetafile);
32 /******************************************************************
35 static UINT EMFDRV_AddHandle( PHYSDEV dev, HGDIOBJ obj )
37 EMFDRV_PDEVICE *physDev = (EMFDRV_PDEVICE *)dev;
40 for(index = 0; index < physDev->handles_size; index++)
41 if(physDev->handles[index] == 0) break;
42 if(index == physDev->handles_size) {
43 physDev->handles_size += HANDLE_LIST_INC;
44 physDev->handles = HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
46 physDev->handles_size * sizeof(physDev->handles[0]));
48 physDev->handles[index] = obj;
50 physDev->cur_handles++;
51 if(physDev->cur_handles > physDev->emh->nHandles)
52 physDev->emh->nHandles++;
54 return index + 1; /* index 0 is reserved for the hmf, so we increment everything by 1 */
57 /******************************************************************
60 static UINT EMFDRV_FindObject( PHYSDEV dev, HGDIOBJ obj )
62 EMFDRV_PDEVICE *physDev = (EMFDRV_PDEVICE*) dev;
65 for(index = 0; index < physDev->handles_size; index++)
66 if(physDev->handles[index] == obj) break;
68 if(index == physDev->handles_size) return 0;
74 /******************************************************************
77 BOOL EMFDRV_DeleteObject( PHYSDEV dev, HGDIOBJ obj )
80 EMFDRV_PDEVICE *physDev = (EMFDRV_PDEVICE*) dev;
84 if(!(index = EMFDRV_FindObject(dev, obj))) return 0;
86 emr.emr.iType = EMR_DELETEOBJECT;
87 emr.emr.nSize = sizeof(emr);
90 if(!EMFDRV_WriteRecord( dev, &emr.emr ))
93 physDev->handles[index - 1] = 0;
94 physDev->cur_handles--;
99 /***********************************************************************
100 * EMFDRV_SelectBitmap
102 HBITMAP EMFDRV_SelectBitmap( PHYSDEV dev, HBITMAP hbitmap )
108 /***********************************************************************
109 * EMFDRV_CreateBrushIndirect
111 DWORD EMFDRV_CreateBrushIndirect( PHYSDEV dev, HBRUSH hBrush )
116 if (!GetObjectA( hBrush, sizeof(logbrush), &logbrush )) return 0;
118 switch (logbrush.lbStyle) {
123 EMRCREATEBRUSHINDIRECT emr;
124 emr.emr.iType = EMR_CREATEBRUSHINDIRECT;
125 emr.emr.nSize = sizeof(emr);
126 emr.ihBrush = index = EMFDRV_AddHandle( dev, hBrush );
129 if(!EMFDRV_WriteRecord( dev, &emr.emr ))
135 EMRCREATEDIBPATTERNBRUSHPT *emr;
136 DWORD bmSize, biSize, size;
137 BITMAPINFO *info = GlobalLock16(logbrush.lbHatch);
139 if (info->bmiHeader.biCompression)
140 bmSize = info->bmiHeader.biSizeImage;
142 bmSize = DIB_GetDIBImageBytes(info->bmiHeader.biWidth,
143 info->bmiHeader.biHeight,
144 info->bmiHeader.biBitCount);
145 biSize = DIB_BitmapInfoSize(info, LOWORD(logbrush.lbColor));
146 size = sizeof(EMRCREATEDIBPATTERNBRUSHPT) + biSize + bmSize;
147 emr = HeapAlloc( GetProcessHeap(), 0, size );
149 emr->emr.iType = EMR_CREATEDIBPATTERNBRUSHPT;
150 emr->emr.nSize = size;
151 emr->ihBrush = index = EMFDRV_AddHandle( dev, hBrush );
152 emr->iUsage = LOWORD(logbrush.lbColor);
153 emr->offBmi = sizeof(EMRCREATEDIBPATTERNBRUSHPT);
155 emr->offBits = sizeof(EMRCREATEDIBPATTERNBRUSHPT) + biSize;
156 emr->cbBits = bmSize;
157 memcpy((char *)emr + sizeof(EMRCREATEDIBPATTERNBRUSHPT), info,
160 if(!EMFDRV_WriteRecord( dev, &emr->emr ))
162 HeapFree( GetProcessHeap(), 0, emr );
163 GlobalUnlock16(logbrush.lbHatch);
168 FIXME("Unsupported style %x\n",
172 FIXME("Unknown style %x\n", logbrush.lbStyle);
179 /***********************************************************************
182 HBRUSH EMFDRV_SelectBrush(PHYSDEV dev, HBRUSH hBrush )
184 EMFDRV_PDEVICE *physDev = (EMFDRV_PDEVICE*)dev;
189 /* If the object is a stock brush object, do not need to create it.
190 * See definitions in wingdi.h for range of stock brushes.
191 * We do however have to handle setting the higher order bit to
192 * designate that this is a stock object.
194 for (i = WHITE_BRUSH; i <= NULL_BRUSH; i++)
196 if (hBrush == GetStockObject(i))
198 index = i | 0x80000000;
202 if((index = EMFDRV_FindObject(dev, hBrush)) != 0)
205 if (!(index = EMFDRV_CreateBrushIndirect(dev, hBrush ))) return 0;
206 GDI_hdc_using_object(hBrush, physDev->hdc);
209 emr.emr.iType = EMR_SELECTOBJECT;
210 emr.emr.nSize = sizeof(emr);
211 emr.ihObject = index;
212 return EMFDRV_WriteRecord( dev, &emr.emr ) ? hBrush : 0;
216 /******************************************************************
217 * EMFDRV_CreateFontIndirect
219 static BOOL EMFDRV_CreateFontIndirect(PHYSDEV dev, HFONT hFont )
222 EMREXTCREATEFONTINDIRECTW emr;
225 if (!GetObjectW( hFont, sizeof(emr.elfw.elfLogFont), &emr.elfw.elfLogFont )) return 0;
227 emr.emr.iType = EMR_EXTCREATEFONTINDIRECTW;
228 emr.emr.nSize = (sizeof(emr) + 3) / 4 * 4;
229 emr.ihFont = index = EMFDRV_AddHandle( dev, hFont );
230 emr.elfw.elfFullName[0] = '\0';
231 emr.elfw.elfStyle[0] = '\0';
232 emr.elfw.elfVersion = 0;
233 emr.elfw.elfStyleSize = 0;
234 emr.elfw.elfMatch = 0;
235 emr.elfw.elfReserved = 0;
236 for(i = 0; i < ELF_VENDOR_SIZE; i++)
237 emr.elfw.elfVendorId[i] = 0;
238 emr.elfw.elfCulture = PAN_CULTURE_LATIN;
239 emr.elfw.elfPanose.bFamilyType = PAN_NO_FIT;
240 emr.elfw.elfPanose.bSerifStyle = PAN_NO_FIT;
241 emr.elfw.elfPanose.bWeight = PAN_NO_FIT;
242 emr.elfw.elfPanose.bProportion = PAN_NO_FIT;
243 emr.elfw.elfPanose.bContrast = PAN_NO_FIT;
244 emr.elfw.elfPanose.bStrokeVariation = PAN_NO_FIT;
245 emr.elfw.elfPanose.bArmStyle = PAN_NO_FIT;
246 emr.elfw.elfPanose.bLetterform = PAN_NO_FIT;
247 emr.elfw.elfPanose.bMidline = PAN_NO_FIT;
248 emr.elfw.elfPanose.bXHeight = PAN_NO_FIT;
250 if(!EMFDRV_WriteRecord( dev, &emr.emr ))
256 /***********************************************************************
259 HFONT EMFDRV_SelectFont( PHYSDEV dev, HFONT hFont )
261 EMFDRV_PDEVICE *physDev = (EMFDRV_PDEVICE*)dev;
266 /* If the object is a stock font object, do not need to create it.
267 * See definitions in wingdi.h for range of stock fonts.
268 * We do however have to handle setting the higher order bit to
269 * designate that this is a stock object.
272 for (i = OEM_FIXED_FONT; i <= DEFAULT_GUI_FONT; i++)
274 if (i != DEFAULT_PALETTE && hFont == GetStockObject(i))
276 index = i | 0x80000000;
281 if((index = EMFDRV_FindObject(dev, hFont)) != 0)
284 if (!(index = EMFDRV_CreateFontIndirect(dev, hFont ))) return HGDI_ERROR;
285 GDI_hdc_using_object(hFont, physDev->hdc);
288 emr.emr.iType = EMR_SELECTOBJECT;
289 emr.emr.nSize = sizeof(emr);
290 emr.ihObject = index;
291 if(!EMFDRV_WriteRecord( dev, &emr.emr ))
298 /******************************************************************
299 * EMFDRV_CreatePenIndirect
301 static HPEN EMFDRV_CreatePenIndirect(PHYSDEV dev, HPEN hPen )
306 if (!GetObjectA( hPen, sizeof(emr.lopn), &emr.lopn )) return 0;
308 emr.emr.iType = EMR_CREATEPEN;
309 emr.emr.nSize = sizeof(emr);
310 emr.ihPen = index = EMFDRV_AddHandle( dev, hPen );
312 if(!EMFDRV_WriteRecord( dev, &emr.emr ))
317 /******************************************************************
320 HPEN EMFDRV_SelectPen(PHYSDEV dev, HPEN hPen )
322 EMFDRV_PDEVICE *physDev = (EMFDRV_PDEVICE*)dev;
327 /* If the object is a stock pen object, do not need to create it.
328 * See definitions in wingdi.h for range of stock pens.
329 * We do however have to handle setting the higher order bit to
330 * designate that this is a stock object.
333 for (i = WHITE_PEN; i <= NULL_PEN; i++)
335 if (hPen == GetStockObject(i))
337 index = i | 0x80000000;
341 if((index = EMFDRV_FindObject(dev, hPen)) != 0)
344 if (!(index = (DWORD)EMFDRV_CreatePenIndirect(dev, hPen ))) return 0;
345 GDI_hdc_using_object(hPen, physDev->hdc);
348 emr.emr.iType = EMR_SELECTOBJECT;
349 emr.emr.nSize = sizeof(emr);
350 emr.ihObject = index;
351 return EMFDRV_WriteRecord( dev, &emr.emr ) ? hPen : 0;
355 /******************************************************************
358 BOOL EMFDRV_GdiComment(PHYSDEV dev, UINT bytes, CONST BYTE *buffer)
361 UINT total, rounded_size;
364 rounded_size = (bytes+3) & ~3;
365 total = offsetof(EMRGDICOMMENT,Data) + rounded_size;
367 emr = HeapAlloc(GetProcessHeap(), 0, total);
368 emr->emr.iType = EMR_GDICOMMENT;
369 emr->emr.nSize = total;
371 memset(&emr->Data[bytes], 0, rounded_size - bytes);
372 memcpy(&emr->Data[0], buffer, bytes);
374 ret = EMFDRV_WriteRecord( dev, &emr->emr );
376 HeapFree(GetProcessHeap(), 0, emr);