Release 20030408.
[wine/gsoc-2012-control.git] / dlls / gdi / enhmfdrv / objects.c
blobb994423c39655635f7e4aa272253dbd74f3ffe71
1 /*
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
21 #include <stdlib.h>
22 #include <stdio.h>
23 #include <string.h>
25 #include "bitmap.h"
26 #include "enhmfdrv/enhmetafiledrv.h"
27 #include "wine/debug.h"
29 WINE_DEFAULT_DEBUG_CHANNEL(enhmetafile);
31 /***********************************************************************
32 * EMFDRV_SelectBitmap
34 HBITMAP EMFDRV_SelectBitmap( PHYSDEV dev, HBITMAP hbitmap )
36 return 0;
40 /***********************************************************************
41 * EMFDRV_CreateBrushIndirect
43 DWORD EMFDRV_CreateBrushIndirect( PHYSDEV dev, HBRUSH hBrush )
45 DWORD index = 0;
46 LOGBRUSH logbrush;
48 if (!GetObjectA( hBrush, sizeof(logbrush), &logbrush )) return 0;
50 switch (logbrush.lbStyle) {
51 case BS_SOLID:
52 case BS_HATCHED:
53 case BS_NULL:
55 EMRCREATEBRUSHINDIRECT emr;
56 emr.emr.iType = EMR_CREATEBRUSHINDIRECT;
57 emr.emr.nSize = sizeof(emr);
58 emr.ihBrush = index = EMFDRV_AddHandleDC( dev );
59 emr.lb = logbrush;
61 if(!EMFDRV_WriteRecord( dev, &emr.emr ))
62 index = 0;
64 break;
65 case BS_DIBPATTERN:
67 EMRCREATEDIBPATTERNBRUSHPT *emr;
68 DWORD bmSize, biSize, size;
69 BITMAPINFO *info = GlobalLock16(logbrush.lbHatch);
71 if (info->bmiHeader.biCompression)
72 bmSize = info->bmiHeader.biSizeImage;
73 else
74 bmSize = DIB_GetDIBImageBytes(info->bmiHeader.biWidth,
75 info->bmiHeader.biHeight,
76 info->bmiHeader.biBitCount);
77 biSize = DIB_BitmapInfoSize(info, LOWORD(logbrush.lbColor));
78 size = sizeof(EMRCREATEDIBPATTERNBRUSHPT) + biSize + bmSize;
79 emr = HeapAlloc( GetProcessHeap(), 0, size );
80 if(!emr) break;
81 emr->emr.iType = EMR_CREATEDIBPATTERNBRUSHPT;
82 emr->emr.nSize = size;
83 emr->ihBrush = index = EMFDRV_AddHandleDC( dev );
84 emr->iUsage = LOWORD(logbrush.lbColor);
85 emr->offBmi = sizeof(EMRCREATEDIBPATTERNBRUSHPT);
86 emr->cbBmi = biSize;
87 emr->offBits = sizeof(EMRCREATEDIBPATTERNBRUSHPT) + biSize;
88 emr->cbBits = bmSize;
89 memcpy((char *)emr + sizeof(EMRCREATEDIBPATTERNBRUSHPT), info,
90 biSize + bmSize );
92 if(!EMFDRV_WriteRecord( dev, &emr->emr ))
93 index = 0;
94 HeapFree( GetProcessHeap(), 0, emr );
95 GlobalUnlock16(logbrush.lbHatch);
97 break;
99 case BS_PATTERN:
100 FIXME("Unsupported style %x\n",
101 logbrush.lbStyle);
102 break;
103 default:
104 FIXME("Unknown style %x\n", logbrush.lbStyle);
105 break;
107 return index;
111 /***********************************************************************
112 * EMFDRV_SelectBrush
114 HBRUSH EMFDRV_SelectBrush(PHYSDEV dev, HBRUSH hBrush )
116 EMRSELECTOBJECT emr;
117 DWORD index;
118 int i;
120 /* If the object is a stock brush object, do not need to create it.
121 * See definitions in wingdi.h for range of stock brushes.
122 * We do however have to handle setting the higher order bit to
123 * designate that this is a stock object.
125 for (i = WHITE_BRUSH; i <= NULL_BRUSH; i++)
127 if (hBrush == GetStockObject(i))
129 index = i | 0x80000000;
130 goto found;
133 if (!(index = EMFDRV_CreateBrushIndirect(dev, hBrush ))) return 0;
135 found:
136 emr.emr.iType = EMR_SELECTOBJECT;
137 emr.emr.nSize = sizeof(emr);
138 emr.ihObject = index;
139 return EMFDRV_WriteRecord( dev, &emr.emr ) ? hBrush : 0;
143 /******************************************************************
144 * EMFDRV_CreateFontIndirect
146 static BOOL EMFDRV_CreateFontIndirect(PHYSDEV dev, HFONT hFont )
148 DWORD index = 0;
149 EMREXTCREATEFONTINDIRECTW emr;
150 int i;
152 if (!GetObjectW( hFont, sizeof(emr.elfw.elfLogFont), &emr.elfw.elfLogFont )) return 0;
154 emr.emr.iType = EMR_EXTCREATEFONTINDIRECTW;
155 emr.emr.nSize = (sizeof(emr) + 3) / 4 * 4;
156 emr.ihFont = index = EMFDRV_AddHandleDC( dev );
157 emr.elfw.elfFullName[0] = '\0';
158 emr.elfw.elfStyle[0] = '\0';
159 emr.elfw.elfVersion = 0;
160 emr.elfw.elfStyleSize = 0;
161 emr.elfw.elfMatch = 0;
162 emr.elfw.elfReserved = 0;
163 for(i = 0; i < ELF_VENDOR_SIZE; i++)
164 emr.elfw.elfVendorId[i] = 0;
165 emr.elfw.elfCulture = PAN_CULTURE_LATIN;
166 emr.elfw.elfPanose.bFamilyType = PAN_NO_FIT;
167 emr.elfw.elfPanose.bSerifStyle = PAN_NO_FIT;
168 emr.elfw.elfPanose.bWeight = PAN_NO_FIT;
169 emr.elfw.elfPanose.bProportion = PAN_NO_FIT;
170 emr.elfw.elfPanose.bContrast = PAN_NO_FIT;
171 emr.elfw.elfPanose.bStrokeVariation = PAN_NO_FIT;
172 emr.elfw.elfPanose.bArmStyle = PAN_NO_FIT;
173 emr.elfw.elfPanose.bLetterform = PAN_NO_FIT;
174 emr.elfw.elfPanose.bMidline = PAN_NO_FIT;
175 emr.elfw.elfPanose.bXHeight = PAN_NO_FIT;
177 if(!EMFDRV_WriteRecord( dev, &emr.emr ))
178 index = 0;
179 return index;
183 /***********************************************************************
184 * EMFDRV_SelectFont
186 HFONT EMFDRV_SelectFont( PHYSDEV dev, HFONT hFont )
188 EMRSELECTOBJECT emr;
189 DWORD index;
190 int i;
192 /* If the object is a stock font object, do not need to create it.
193 * See definitions in wingdi.h for range of stock fonts.
194 * We do however have to handle setting the higher order bit to
195 * designate that this is a stock object.
198 for (i = OEM_FIXED_FONT; i <= DEFAULT_GUI_FONT; i++)
200 if (i != DEFAULT_PALETTE && hFont == GetStockObject(i))
202 index = i | 0x80000000;
203 goto found;
206 if (!(index = EMFDRV_CreateFontIndirect(dev, hFont ))) return HGDI_ERROR;
207 found:
208 emr.emr.iType = EMR_SELECTOBJECT;
209 emr.emr.nSize = sizeof(emr);
210 emr.ihObject = index;
211 if(!EMFDRV_WriteRecord( dev, &emr.emr ))
212 return HGDI_ERROR;
213 return 0;
218 /******************************************************************
219 * EMFDRV_CreatePenIndirect
221 static HPEN EMFDRV_CreatePenIndirect(PHYSDEV dev, HPEN hPen )
223 EMRCREATEPEN emr;
224 DWORD index = 0;
226 if (!GetObjectA( hPen, sizeof(emr.lopn), &emr.lopn )) return 0;
228 emr.emr.iType = EMR_CREATEPEN;
229 emr.emr.nSize = sizeof(emr);
230 emr.ihPen = index = EMFDRV_AddHandleDC( dev );
232 if(!EMFDRV_WriteRecord( dev, &emr.emr ))
233 index = 0;
234 return (HPEN)index;
237 /******************************************************************
238 * EMFDRV_SelectPen
240 HPEN EMFDRV_SelectPen(PHYSDEV dev, HPEN hPen )
242 EMRSELECTOBJECT emr;
243 DWORD index;
244 int i;
246 /* If the object is a stock pen object, do not need to create it.
247 * See definitions in wingdi.h for range of stock pens.
248 * We do however have to handle setting the higher order bit to
249 * designate that this is a stock object.
252 for (i = WHITE_PEN; i <= NULL_PEN; i++)
254 if (hPen == GetStockObject(i))
256 index = i | 0x80000000;
257 goto found;
260 if (!(index = (DWORD)EMFDRV_CreatePenIndirect(dev, hPen ))) return 0;
261 found:
262 emr.emr.iType = EMR_SELECTOBJECT;
263 emr.emr.nSize = sizeof(emr);
264 emr.ihObject = index;
265 return EMFDRV_WriteRecord( dev, &emr.emr ) ? hPen : 0;