1997-02-02 20:01:52 +01:00
|
|
|
/*
|
|
|
|
* GDI objects
|
|
|
|
*
|
|
|
|
* Copyright 1993 Alexandre Julliard
|
2002-03-10 00:29:33 +01:00
|
|
|
*
|
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
1997-02-02 20:01:52 +01:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
1999-07-31 19:36:48 +02:00
|
|
|
#include <string.h>
|
|
|
|
|
1997-02-02 20:01:52 +01:00
|
|
|
#include "bitmap.h"
|
|
|
|
#include "font.h"
|
2002-03-27 22:13:40 +01:00
|
|
|
#include "mfdrv/metafiledrv.h"
|
2002-03-10 00:29:33 +01:00
|
|
|
#include "wine/debug.h"
|
1997-02-02 20:01:52 +01:00
|
|
|
|
2002-03-10 00:29:33 +01:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(metafile);
|
2001-07-23 01:34:21 +02:00
|
|
|
|
1999-04-19 16:56:29 +02:00
|
|
|
|
1997-02-02 20:01:52 +01:00
|
|
|
/***********************************************************************
|
2002-03-28 23:22:05 +01:00
|
|
|
* MFDRV_SelectBitmap
|
1997-02-02 20:01:52 +01:00
|
|
|
*/
|
2002-03-28 23:22:05 +01:00
|
|
|
HBITMAP MFDRV_SelectBitmap( PHYSDEV dev, HBITMAP hbitmap )
|
1997-02-02 20:01:52 +01:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
1999-04-15 18:46:51 +02:00
|
|
|
/******************************************************************
|
|
|
|
* MFDRV_CreateBrushIndirect
|
|
|
|
*/
|
|
|
|
|
2002-03-28 23:22:05 +01:00
|
|
|
INT16 MFDRV_CreateBrushIndirect(PHYSDEV dev, HBRUSH hBrush )
|
1999-04-15 18:46:51 +02:00
|
|
|
{
|
2000-08-19 23:38:55 +02:00
|
|
|
INT16 index = -1;
|
1999-04-25 11:24:23 +02:00
|
|
|
DWORD size;
|
1999-04-15 18:46:51 +02:00
|
|
|
METARECORD *mr;
|
2001-07-23 01:34:21 +02:00
|
|
|
LOGBRUSH logbrush;
|
2002-03-28 23:22:05 +01:00
|
|
|
METAFILEDRV_PDEVICE *physDev = (METAFILEDRV_PDEVICE *)dev;
|
2001-07-23 01:34:21 +02:00
|
|
|
|
|
|
|
if (!GetObjectA( hBrush, sizeof(logbrush), &logbrush )) return -1;
|
|
|
|
|
|
|
|
switch(logbrush.lbStyle)
|
|
|
|
{
|
1999-04-25 11:24:23 +02:00
|
|
|
case BS_SOLID:
|
|
|
|
case BS_NULL:
|
|
|
|
case BS_HATCHED:
|
|
|
|
{
|
|
|
|
LOGBRUSH16 lb16;
|
|
|
|
|
2001-07-23 01:34:21 +02:00
|
|
|
lb16.lbStyle = logbrush.lbStyle;
|
|
|
|
lb16.lbColor = logbrush.lbColor;
|
|
|
|
lb16.lbHatch = logbrush.lbHatch;
|
1999-04-25 11:24:23 +02:00
|
|
|
size = sizeof(METARECORD) + sizeof(LOGBRUSH16) - 2;
|
2000-02-16 23:47:24 +01:00
|
|
|
mr = HeapAlloc( GetProcessHeap(), 0, size );
|
1999-04-25 11:24:23 +02:00
|
|
|
mr->rdSize = size / 2;
|
|
|
|
mr->rdFunction = META_CREATEBRUSHINDIRECT;
|
|
|
|
memcpy( mr->rdParm, &lb16, sizeof(LOGBRUSH));
|
|
|
|
break;
|
|
|
|
}
|
1999-04-15 18:46:51 +02:00
|
|
|
case BS_PATTERN:
|
|
|
|
{
|
|
|
|
BITMAP bm;
|
|
|
|
BYTE *bits;
|
1999-04-25 11:24:23 +02:00
|
|
|
BITMAPINFO *info;
|
|
|
|
DWORD bmSize;
|
1999-04-15 18:46:51 +02:00
|
|
|
|
2001-07-23 01:34:21 +02:00
|
|
|
GetObjectA(logbrush.lbHatch, sizeof(bm), &bm);
|
1999-04-15 18:46:51 +02:00
|
|
|
if(bm.bmBitsPixel != 1 || bm.bmPlanes != 1) {
|
1999-12-08 04:56:23 +01:00
|
|
|
FIXME("Trying to store a colour pattern brush\n");
|
2000-08-19 23:38:55 +02:00
|
|
|
goto done;
|
1999-04-15 18:46:51 +02:00
|
|
|
}
|
|
|
|
|
1999-04-18 14:07:00 +02:00
|
|
|
bmSize = DIB_GetDIBImageBytes(bm.bmWidth, bm.bmHeight, 1);
|
1999-04-15 18:46:51 +02:00
|
|
|
|
2002-06-01 01:06:46 +02:00
|
|
|
size = sizeof(METARECORD) + sizeof(WORD) + sizeof(BITMAPINFO) +
|
1999-04-15 18:46:51 +02:00
|
|
|
sizeof(RGBQUAD) + bmSize;
|
1999-04-25 11:24:23 +02:00
|
|
|
|
2000-02-16 23:47:24 +01:00
|
|
|
mr = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size);
|
2000-08-19 23:38:55 +02:00
|
|
|
if(!mr) goto done;
|
1999-04-15 18:46:51 +02:00
|
|
|
mr->rdFunction = META_DIBCREATEPATTERNBRUSH;
|
1999-04-25 11:24:23 +02:00
|
|
|
mr->rdSize = size / 2;
|
1999-04-15 18:46:51 +02:00
|
|
|
mr->rdParm[0] = BS_PATTERN;
|
|
|
|
mr->rdParm[1] = DIB_RGB_COLORS;
|
|
|
|
info = (BITMAPINFO *)(mr->rdParm + 2);
|
|
|
|
|
|
|
|
info->bmiHeader.biSize = sizeof(BITMAPINFOHEADER);
|
|
|
|
info->bmiHeader.biWidth = bm.bmWidth;
|
|
|
|
info->bmiHeader.biHeight = bm.bmHeight;
|
|
|
|
info->bmiHeader.biPlanes = 1;
|
|
|
|
info->bmiHeader.biBitCount = 1;
|
|
|
|
bits = ((BYTE *)info) + sizeof(BITMAPINFO) + sizeof(RGBQUAD);
|
|
|
|
|
2002-03-28 23:22:05 +01:00
|
|
|
GetDIBits(physDev->hdc, logbrush.lbHatch, 0, bm.bmHeight,
|
1999-04-25 11:24:23 +02:00
|
|
|
bits, info, DIB_RGB_COLORS);
|
1999-04-15 18:46:51 +02:00
|
|
|
*(DWORD *)info->bmiColors = 0;
|
|
|
|
*(DWORD *)(info->bmiColors + 1) = 0xffffff;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case BS_DIBPATTERN:
|
1999-04-25 11:24:23 +02:00
|
|
|
{
|
|
|
|
BITMAPINFO *info;
|
|
|
|
DWORD bmSize, biSize;
|
|
|
|
|
2001-07-23 01:34:21 +02:00
|
|
|
info = GlobalLock16((HGLOBAL16)logbrush.lbHatch);
|
1999-04-25 11:24:23 +02:00
|
|
|
if (info->bmiHeader.biCompression)
|
|
|
|
bmSize = info->bmiHeader.biSizeImage;
|
|
|
|
else
|
|
|
|
bmSize = DIB_GetDIBImageBytes(info->bmiHeader.biWidth,
|
|
|
|
info->bmiHeader.biHeight,
|
|
|
|
info->bmiHeader.biBitCount);
|
2001-07-23 01:34:21 +02:00
|
|
|
biSize = DIB_BitmapInfoSize(info, LOWORD(logbrush.lbColor));
|
1999-04-25 11:24:23 +02:00
|
|
|
size = sizeof(METARECORD) + biSize + bmSize + 2;
|
2000-02-16 23:47:24 +01:00
|
|
|
mr = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, size);
|
2000-08-19 23:38:55 +02:00
|
|
|
if(!mr) goto done;
|
1999-04-25 11:24:23 +02:00
|
|
|
mr->rdFunction = META_DIBCREATEPATTERNBRUSH;
|
|
|
|
mr->rdSize = size / 2;
|
2001-07-23 01:34:21 +02:00
|
|
|
*(mr->rdParm) = logbrush.lbStyle;
|
|
|
|
*(mr->rdParm + 1) = LOWORD(logbrush.lbColor);
|
1999-04-25 11:24:23 +02:00
|
|
|
memcpy(mr->rdParm + 2, info, biSize + bmSize);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
2001-07-23 01:34:21 +02:00
|
|
|
FIXME("Unkonwn brush style %x\n", logbrush.lbStyle);
|
1999-04-25 11:24:23 +02:00
|
|
|
return -1;
|
1999-04-15 18:46:51 +02:00
|
|
|
}
|
2002-03-28 23:22:05 +01:00
|
|
|
index = MFDRV_AddHandleDC( dev );
|
|
|
|
if(!MFDRV_WriteRecord( dev, mr, mr->rdSize * 2))
|
1999-04-25 11:24:23 +02:00
|
|
|
index = -1;
|
2000-02-16 23:47:24 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, mr);
|
2000-08-19 23:38:55 +02:00
|
|
|
done:
|
1999-04-25 11:24:23 +02:00
|
|
|
return index;
|
1999-04-15 18:46:51 +02:00
|
|
|
}
|
|
|
|
|
1999-04-25 11:24:23 +02:00
|
|
|
|
1997-02-02 20:01:52 +01:00
|
|
|
/***********************************************************************
|
2002-03-28 23:22:05 +01:00
|
|
|
* MFDRV_SelectBrush
|
1997-02-02 20:01:52 +01:00
|
|
|
*/
|
2002-03-28 23:22:05 +01:00
|
|
|
HBRUSH MFDRV_SelectBrush( PHYSDEV dev, HBRUSH hbrush )
|
1997-02-02 20:01:52 +01:00
|
|
|
{
|
1999-04-25 11:24:23 +02:00
|
|
|
INT16 index;
|
|
|
|
METARECORD mr;
|
|
|
|
|
2002-03-28 23:22:05 +01:00
|
|
|
index = MFDRV_CreateBrushIndirect( dev, hbrush );
|
1999-04-25 11:24:23 +02:00
|
|
|
if(index == -1) return 0;
|
|
|
|
|
|
|
|
mr.rdSize = sizeof(mr) / 2;
|
|
|
|
mr.rdFunction = META_SELECTOBJECT;
|
|
|
|
mr.rdParm[0] = index;
|
2002-03-28 23:22:05 +01:00
|
|
|
return MFDRV_WriteRecord( dev, &mr, mr.rdSize * 2) ? hbrush : 0;
|
1997-02-02 20:01:52 +01:00
|
|
|
}
|
|
|
|
|
1999-04-15 18:46:51 +02:00
|
|
|
/******************************************************************
|
|
|
|
* MFDRV_CreateFontIndirect
|
|
|
|
*/
|
|
|
|
|
2002-03-28 23:22:05 +01:00
|
|
|
static BOOL MFDRV_CreateFontIndirect(PHYSDEV dev, HFONT16 hFont, LOGFONT16 *logfont)
|
1999-04-15 18:46:51 +02:00
|
|
|
{
|
|
|
|
int index;
|
|
|
|
char buffer[sizeof(METARECORD) - 2 + sizeof(LOGFONT16)];
|
|
|
|
METARECORD *mr = (METARECORD *)&buffer;
|
|
|
|
|
|
|
|
mr->rdSize = (sizeof(METARECORD) + sizeof(LOGFONT16) - 2) / 2;
|
|
|
|
mr->rdFunction = META_CREATEFONTINDIRECT;
|
|
|
|
memcpy(&(mr->rdParm), logfont, sizeof(LOGFONT16));
|
2002-03-28 23:22:05 +01:00
|
|
|
if (!(MFDRV_WriteRecord( dev, mr, mr->rdSize * 2))) return FALSE;
|
1999-04-15 18:46:51 +02:00
|
|
|
|
|
|
|
mr->rdSize = sizeof(METARECORD) / 2;
|
|
|
|
mr->rdFunction = META_SELECTOBJECT;
|
|
|
|
|
2002-03-28 23:22:05 +01:00
|
|
|
if ((index = MFDRV_AddHandleDC( dev )) == -1) return FALSE;
|
1999-04-15 18:46:51 +02:00
|
|
|
*(mr->rdParm) = index;
|
2002-03-28 23:22:05 +01:00
|
|
|
return MFDRV_WriteRecord( dev, mr, mr->rdSize * 2);
|
1999-04-15 18:46:51 +02:00
|
|
|
}
|
|
|
|
|
1997-02-02 20:01:52 +01:00
|
|
|
|
|
|
|
/***********************************************************************
|
2002-03-28 23:22:05 +01:00
|
|
|
* MFDRV_SelectFont
|
1997-02-02 20:01:52 +01:00
|
|
|
*/
|
2002-03-28 23:22:05 +01:00
|
|
|
HFONT MFDRV_SelectFont( PHYSDEV dev, HFONT hfont )
|
1997-02-02 20:01:52 +01:00
|
|
|
{
|
2001-02-14 23:56:38 +01:00
|
|
|
LOGFONT16 lf16;
|
2001-07-23 01:34:21 +02:00
|
|
|
|
2001-09-12 22:21:06 +02:00
|
|
|
if (!GetObject16( hfont, sizeof(lf16), &lf16 )) return GDI_ERROR;
|
2002-03-28 23:22:05 +01:00
|
|
|
if (MFDRV_CreateFontIndirect(dev, hfont, &lf16)) return 0;
|
2002-08-16 02:42:06 +02:00
|
|
|
return HGDI_ERROR;
|
1997-02-02 20:01:52 +01:00
|
|
|
}
|
|
|
|
|
1999-04-15 18:46:51 +02:00
|
|
|
/******************************************************************
|
|
|
|
* MFDRV_CreatePenIndirect
|
|
|
|
*/
|
2002-03-28 23:22:05 +01:00
|
|
|
static BOOL MFDRV_CreatePenIndirect(PHYSDEV dev, HPEN16 hPen, LOGPEN16 *logpen)
|
1999-04-15 18:46:51 +02:00
|
|
|
{
|
|
|
|
int index;
|
|
|
|
char buffer[sizeof(METARECORD) - 2 + sizeof(*logpen)];
|
|
|
|
METARECORD *mr = (METARECORD *)&buffer;
|
|
|
|
|
|
|
|
mr->rdSize = (sizeof(METARECORD) + sizeof(*logpen) - 2) / 2;
|
|
|
|
mr->rdFunction = META_CREATEPENINDIRECT;
|
|
|
|
memcpy(&(mr->rdParm), logpen, sizeof(*logpen));
|
2002-03-28 23:22:05 +01:00
|
|
|
if (!(MFDRV_WriteRecord( dev, mr, mr->rdSize * 2))) return FALSE;
|
1999-04-15 18:46:51 +02:00
|
|
|
|
|
|
|
mr->rdSize = sizeof(METARECORD) / 2;
|
|
|
|
mr->rdFunction = META_SELECTOBJECT;
|
|
|
|
|
2002-03-28 23:22:05 +01:00
|
|
|
if ((index = MFDRV_AddHandleDC( dev )) == -1) return FALSE;
|
1999-04-15 18:46:51 +02:00
|
|
|
*(mr->rdParm) = index;
|
2002-03-28 23:22:05 +01:00
|
|
|
return MFDRV_WriteRecord( dev, mr, mr->rdSize * 2);
|
1999-04-15 18:46:51 +02:00
|
|
|
}
|
|
|
|
|
1997-02-02 20:01:52 +01:00
|
|
|
|
|
|
|
/***********************************************************************
|
2002-03-28 23:22:05 +01:00
|
|
|
* MFDRV_SelectPen
|
1997-02-02 20:01:52 +01:00
|
|
|
*/
|
2002-03-28 23:22:05 +01:00
|
|
|
HPEN MFDRV_SelectPen( PHYSDEV dev, HPEN hpen )
|
1997-02-02 20:01:52 +01:00
|
|
|
{
|
1999-04-22 18:27:50 +02:00
|
|
|
LOGPEN16 logpen;
|
|
|
|
|
2001-07-23 01:34:21 +02:00
|
|
|
if (!GetObject16( hpen, sizeof(logpen), &logpen )) return 0;
|
2002-03-28 23:22:05 +01:00
|
|
|
if (MFDRV_CreatePenIndirect( dev, hpen, &logpen )) return hpen;
|
2001-07-23 01:34:21 +02:00
|
|
|
return 0;
|
1997-02-02 20:01:52 +01:00
|
|
|
}
|