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
|
2006-05-18 14:49:52 +02:00
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, 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>
|
2004-03-04 21:41:12 +01:00
|
|
|
#include <stdarg.h>
|
1999-07-31 19:36:48 +02:00
|
|
|
|
2004-03-04 21:41:12 +01:00
|
|
|
#include "windef.h"
|
|
|
|
#include "winbase.h"
|
|
|
|
#include "wingdi.h"
|
2009-12-05 11:45:31 +01:00
|
|
|
#include "wine/wingdi16.h"
|
2002-03-27 22:13:40 +01:00
|
|
|
#include "mfdrv/metafiledrv.h"
|
2004-01-15 01:35:38 +01:00
|
|
|
#include "gdi_private.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
|
|
|
|
2003-11-26 04:38:11 +01:00
|
|
|
/******************************************************************
|
|
|
|
* MFDRV_AddHandle
|
|
|
|
*/
|
|
|
|
UINT MFDRV_AddHandle( PHYSDEV dev, HGDIOBJ obj )
|
|
|
|
{
|
|
|
|
METAFILEDRV_PDEVICE *physDev = (METAFILEDRV_PDEVICE *)dev;
|
2004-09-08 03:23:57 +02:00
|
|
|
UINT16 index;
|
2003-11-26 04:38:11 +01:00
|
|
|
|
|
|
|
for(index = 0; index < physDev->handles_size; index++)
|
|
|
|
if(physDev->handles[index] == 0) break;
|
|
|
|
if(index == physDev->handles_size) {
|
|
|
|
physDev->handles_size += HANDLE_LIST_INC;
|
|
|
|
physDev->handles = HeapReAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,
|
|
|
|
physDev->handles,
|
|
|
|
physDev->handles_size * sizeof(physDev->handles[0]));
|
|
|
|
}
|
|
|
|
physDev->handles[index] = obj;
|
|
|
|
|
|
|
|
physDev->cur_handles++;
|
|
|
|
if(physDev->cur_handles > physDev->mh->mtNoObjects)
|
|
|
|
physDev->mh->mtNoObjects++;
|
|
|
|
|
|
|
|
return index ; /* index 0 is not reserved for metafiles */
|
|
|
|
}
|
|
|
|
|
2007-01-02 17:09:10 +01:00
|
|
|
/******************************************************************
|
|
|
|
* MFDRV_RemoveHandle
|
|
|
|
*/
|
|
|
|
BOOL MFDRV_RemoveHandle( PHYSDEV dev, UINT index )
|
|
|
|
{
|
|
|
|
METAFILEDRV_PDEVICE *physDev = (METAFILEDRV_PDEVICE *)dev;
|
|
|
|
BOOL ret = FALSE;
|
|
|
|
|
|
|
|
if (index < physDev->handles_size && physDev->handles[index])
|
|
|
|
{
|
|
|
|
physDev->handles[index] = 0;
|
|
|
|
physDev->cur_handles--;
|
|
|
|
ret = TRUE;
|
|
|
|
}
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2003-11-26 04:38:11 +01:00
|
|
|
/******************************************************************
|
|
|
|
* MFDRV_FindObject
|
|
|
|
*/
|
|
|
|
static INT16 MFDRV_FindObject( PHYSDEV dev, HGDIOBJ obj )
|
|
|
|
{
|
|
|
|
METAFILEDRV_PDEVICE *physDev = (METAFILEDRV_PDEVICE *)dev;
|
|
|
|
INT16 index;
|
|
|
|
|
|
|
|
for(index = 0; index < physDev->handles_size; index++)
|
|
|
|
if(physDev->handles[index] == obj) break;
|
|
|
|
|
|
|
|
if(index == physDev->handles_size) return -1;
|
|
|
|
|
|
|
|
return index ;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* MFDRV_DeleteObject
|
|
|
|
*/
|
2011-07-13 14:56:12 +02:00
|
|
|
BOOL MFDRV_DeleteObject( PHYSDEV dev, HGDIOBJ obj )
|
2008-12-16 14:18:49 +01:00
|
|
|
{
|
2003-11-26 04:38:11 +01:00
|
|
|
METARECORD mr;
|
|
|
|
METAFILEDRV_PDEVICE *physDev = (METAFILEDRV_PDEVICE *)dev;
|
|
|
|
INT16 index;
|
|
|
|
BOOL ret = TRUE;
|
|
|
|
|
|
|
|
index = MFDRV_FindObject(dev, obj);
|
|
|
|
if( index < 0 )
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
mr.rdSize = sizeof mr / 2;
|
|
|
|
mr.rdFunction = META_DELETEOBJECT;
|
|
|
|
mr.rdParm[0] = index;
|
|
|
|
|
|
|
|
if(!MFDRV_WriteRecord( dev, &mr, mr.rdSize*2 ))
|
|
|
|
ret = FALSE;
|
|
|
|
|
|
|
|
physDev->handles[index] = 0;
|
|
|
|
physDev->cur_handles--;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* MFDRV_SelectObject
|
|
|
|
*/
|
|
|
|
static BOOL MFDRV_SelectObject( PHYSDEV dev, INT16 index)
|
|
|
|
{
|
|
|
|
METARECORD mr;
|
|
|
|
|
|
|
|
mr.rdSize = sizeof mr / 2;
|
|
|
|
mr.rdFunction = META_SELECTOBJECT;
|
|
|
|
mr.rdParm[0] = index;
|
|
|
|
|
|
|
|
return MFDRV_WriteRecord( dev, &mr, mr.rdSize*2 );
|
|
|
|
}
|
|
|
|
|
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
|
|
|
*/
|
2011-07-13 14:56:12 +02: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
|
|
|
{
|
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;
|
2003-11-26 04:38:11 +01:00
|
|
|
BOOL r;
|
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;
|
2003-11-26 04:38:11 +01:00
|
|
|
memcpy( mr->rdParm, &lb16, sizeof(LOGBRUSH16));
|
1999-04-25 11:24:23 +02:00
|
|
|
break;
|
|
|
|
}
|
1999-04-15 18:46:51 +02:00
|
|
|
case BS_PATTERN:
|
|
|
|
{
|
2011-08-03 13:01:29 +02:00
|
|
|
char buffer[FIELD_OFFSET( BITMAPINFO, bmiColors[256] )];
|
|
|
|
BITMAPINFO *dst_info, *src_info = (BITMAPINFO *)buffer;
|
|
|
|
struct gdi_image_bits bits;
|
2005-01-14 16:12:59 +01:00
|
|
|
COLORREF cref;
|
1999-04-15 18:46:51 +02:00
|
|
|
|
2011-08-03 13:01:29 +02:00
|
|
|
if (!get_bitmap_image( (HANDLE)logbrush.lbHatch, src_info, &bits )) goto done;
|
|
|
|
if (src_info->bmiHeader.biBitCount != 1)
|
|
|
|
{
|
1999-12-08 04:56:23 +01:00
|
|
|
FIXME("Trying to store a colour pattern brush\n");
|
2011-08-03 13:01:29 +02:00
|
|
|
if (bits.free) bits.free( &bits );
|
2000-08-19 23:38:55 +02:00
|
|
|
goto done;
|
1999-04-15 18:46:51 +02:00
|
|
|
}
|
|
|
|
|
2011-08-03 13:01:29 +02:00
|
|
|
size = FIELD_OFFSET( METARECORD, rdParm[2] ) +
|
|
|
|
FIELD_OFFSET( BITMAPINFO, bmiColors[2] ) + src_info->bmiHeader.biSizeImage;
|
1999-04-15 18:46:51 +02:00
|
|
|
|
2011-08-03 13:01:29 +02:00
|
|
|
if (!(mr = HeapAlloc( GetProcessHeap(), 0, size )))
|
|
|
|
{
|
|
|
|
if (bits.free) bits.free( &bits );
|
|
|
|
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;
|
2011-08-03 13:01:29 +02:00
|
|
|
dst_info = (BITMAPINFO *)(mr->rdParm + 2);
|
|
|
|
dst_info->bmiHeader = src_info->bmiHeader;
|
2011-08-30 20:48:51 +02:00
|
|
|
dst_info->bmiHeader.biClrUsed = 0;
|
2011-04-04 12:27:02 +02:00
|
|
|
cref = GetTextColor( dev->hdc );
|
2011-08-03 13:01:29 +02:00
|
|
|
dst_info->bmiColors[0].rgbRed = GetRValue(cref);
|
|
|
|
dst_info->bmiColors[0].rgbGreen = GetGValue(cref);
|
|
|
|
dst_info->bmiColors[0].rgbBlue = GetBValue(cref);
|
|
|
|
dst_info->bmiColors[0].rgbReserved = 0;
|
2011-04-04 12:27:02 +02:00
|
|
|
cref = GetBkColor( dev->hdc );
|
2011-08-03 13:01:29 +02:00
|
|
|
dst_info->bmiColors[1].rgbRed = GetRValue(cref);
|
|
|
|
dst_info->bmiColors[1].rgbGreen = GetGValue(cref);
|
|
|
|
dst_info->bmiColors[1].rgbBlue = GetBValue(cref);
|
|
|
|
dst_info->bmiColors[1].rgbReserved = 0;
|
|
|
|
|
|
|
|
/* always return a bottom-up DIB */
|
|
|
|
if (dst_info->bmiHeader.biHeight < 0)
|
|
|
|
{
|
|
|
|
int i, width_bytes = get_dib_stride( dst_info->bmiHeader.biWidth,
|
|
|
|
dst_info->bmiHeader.biBitCount );
|
|
|
|
char *dst_ptr = (char *)&dst_info->bmiColors[2];
|
|
|
|
dst_info->bmiHeader.biHeight = -dst_info->bmiHeader.biHeight;
|
|
|
|
dst_ptr += (dst_info->bmiHeader.biHeight - 1) * width_bytes;
|
|
|
|
for (i = 0; i < dst_info->bmiHeader.biHeight; i++, dst_ptr -= width_bytes)
|
|
|
|
memcpy( dst_ptr, (char *)bits.ptr + i * width_bytes, width_bytes );
|
|
|
|
}
|
|
|
|
else memcpy( &dst_info->bmiColors[2], bits.ptr, dst_info->bmiHeader.biSizeImage );
|
|
|
|
if (bits.free) bits.free( &bits );
|
1999-04-15 18:46:51 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
case BS_DIBPATTERN:
|
1999-04-25 11:24:23 +02:00
|
|
|
{
|
|
|
|
BITMAPINFO *info;
|
|
|
|
DWORD bmSize, biSize;
|
|
|
|
|
2009-09-26 13:30:06 +02:00
|
|
|
info = GlobalLock( (HGLOBAL)logbrush.lbHatch );
|
1999-04-25 11:24:23 +02:00
|
|
|
if (info->bmiHeader.biCompression)
|
|
|
|
bmSize = info->bmiHeader.biSizeImage;
|
|
|
|
else
|
2011-07-19 14:09:03 +02:00
|
|
|
bmSize = get_dib_image_size( info );
|
2008-05-02 13:35:40 +02:00
|
|
|
biSize = bitmap_info_size(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);
|
2009-09-26 13:30:06 +02:00
|
|
|
if (!mr)
|
|
|
|
{
|
|
|
|
GlobalUnlock( (HGLOBAL)logbrush.lbHatch );
|
|
|
|
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);
|
2009-09-26 13:30:06 +02:00
|
|
|
GlobalUnlock( (HGLOBAL)logbrush.lbHatch );
|
1999-04-25 11:24:23 +02:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
default:
|
2001-07-23 01:34:21 +02:00
|
|
|
FIXME("Unkonwn brush style %x\n", logbrush.lbStyle);
|
2003-11-26 04:38:11 +01:00
|
|
|
return 0;
|
1999-04-15 18:46:51 +02:00
|
|
|
}
|
2003-11-26 04:38:11 +01:00
|
|
|
r = MFDRV_WriteRecord( dev, mr, mr->rdSize * 2);
|
2000-02-16 23:47:24 +01:00
|
|
|
HeapFree(GetProcessHeap(), 0, mr);
|
2003-11-26 04:38:11 +01:00
|
|
|
if( !r )
|
|
|
|
return -1;
|
2000-08-19 23:38:55 +02:00
|
|
|
done:
|
2003-11-26 04:38:11 +01:00
|
|
|
return MFDRV_AddHandle( dev, hBrush );
|
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
|
|
|
*/
|
2011-07-13 14:56:12 +02: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;
|
|
|
|
|
2003-11-26 04:38:11 +01:00
|
|
|
index = MFDRV_FindObject(dev, hbrush);
|
|
|
|
if( index < 0 )
|
|
|
|
{
|
|
|
|
index = MFDRV_CreateBrushIndirect( dev, hbrush );
|
|
|
|
if( index < 0 )
|
|
|
|
return 0;
|
2011-04-04 12:27:02 +02:00
|
|
|
GDI_hdc_using_object(hbrush, dev->hdc);
|
2003-11-26 04:38:11 +01:00
|
|
|
}
|
|
|
|
return MFDRV_SelectObject( dev, index ) ? hbrush : HGDI_ERROR;
|
1997-02-02 20:01:52 +01:00
|
|
|
}
|
|
|
|
|
1999-04-15 18:46:51 +02:00
|
|
|
/******************************************************************
|
|
|
|
* MFDRV_CreateFontIndirect
|
|
|
|
*/
|
|
|
|
|
2008-02-18 18:07:51 +01:00
|
|
|
static UINT16 MFDRV_CreateFontIndirect(PHYSDEV dev, HFONT hFont, LOGFONTW *logfont)
|
1999-04-15 18:46:51 +02:00
|
|
|
{
|
|
|
|
char buffer[sizeof(METARECORD) - 2 + sizeof(LOGFONT16)];
|
|
|
|
METARECORD *mr = (METARECORD *)&buffer;
|
2008-02-18 18:07:51 +01:00
|
|
|
LOGFONT16 *font16;
|
2010-02-03 15:33:06 +01:00
|
|
|
INT written;
|
1999-04-15 18:46:51 +02:00
|
|
|
|
|
|
|
mr->rdSize = (sizeof(METARECORD) + sizeof(LOGFONT16) - 2) / 2;
|
|
|
|
mr->rdFunction = META_CREATEFONTINDIRECT;
|
2008-02-18 18:07:51 +01:00
|
|
|
font16 = (LOGFONT16 *)&mr->rdParm;
|
|
|
|
|
|
|
|
font16->lfHeight = logfont->lfHeight;
|
|
|
|
font16->lfWidth = logfont->lfWidth;
|
|
|
|
font16->lfEscapement = logfont->lfEscapement;
|
|
|
|
font16->lfOrientation = logfont->lfOrientation;
|
|
|
|
font16->lfWeight = logfont->lfWeight;
|
|
|
|
font16->lfItalic = logfont->lfItalic;
|
|
|
|
font16->lfUnderline = logfont->lfUnderline;
|
|
|
|
font16->lfStrikeOut = logfont->lfStrikeOut;
|
|
|
|
font16->lfCharSet = logfont->lfCharSet;
|
|
|
|
font16->lfOutPrecision = logfont->lfOutPrecision;
|
|
|
|
font16->lfClipPrecision = logfont->lfClipPrecision;
|
|
|
|
font16->lfQuality = logfont->lfQuality;
|
|
|
|
font16->lfPitchAndFamily = logfont->lfPitchAndFamily;
|
2010-02-03 15:33:06 +01:00
|
|
|
written = WideCharToMultiByte( CP_ACP, 0, logfont->lfFaceName, -1, font16->lfFaceName, LF_FACESIZE - 1, NULL, NULL );
|
|
|
|
/* Zero pad the facename buffer, so that we don't write uninitialized data to disk */
|
|
|
|
memset(font16->lfFaceName + written, 0, LF_FACESIZE - written);
|
2008-02-18 18:07:51 +01:00
|
|
|
|
2003-11-26 04:38:11 +01:00
|
|
|
if (!(MFDRV_WriteRecord( dev, mr, mr->rdSize * 2)))
|
|
|
|
return 0;
|
|
|
|
return MFDRV_AddHandle( dev, hFont );
|
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
|
|
|
*/
|
2011-07-13 14:56:12 +02:00
|
|
|
HFONT MFDRV_SelectFont( PHYSDEV dev, HFONT hfont, HANDLE gdiFont )
|
1997-02-02 20:01:52 +01:00
|
|
|
{
|
2008-02-18 18:07:51 +01:00
|
|
|
LOGFONTW font;
|
2003-11-26 04:38:11 +01:00
|
|
|
INT16 index;
|
2001-07-23 01:34:21 +02:00
|
|
|
|
2003-11-26 04:38:11 +01:00
|
|
|
index = MFDRV_FindObject(dev, hfont);
|
|
|
|
if( index < 0 )
|
|
|
|
{
|
2008-02-18 18:07:51 +01:00
|
|
|
if (!GetObjectW( hfont, sizeof(font), &font ))
|
2003-11-26 04:38:11 +01:00
|
|
|
return HGDI_ERROR;
|
2008-02-18 18:07:51 +01:00
|
|
|
index = MFDRV_CreateFontIndirect(dev, hfont, &font);
|
2003-11-26 04:38:11 +01:00
|
|
|
if( index < 0 )
|
|
|
|
return HGDI_ERROR;
|
2011-04-04 12:27:02 +02:00
|
|
|
GDI_hdc_using_object(hfont, dev->hdc);
|
2003-11-26 04:38:11 +01:00
|
|
|
}
|
|
|
|
return MFDRV_SelectObject( dev, index ) ? hfont : HGDI_ERROR;
|
1997-02-02 20:01:52 +01:00
|
|
|
}
|
|
|
|
|
1999-04-15 18:46:51 +02:00
|
|
|
/******************************************************************
|
|
|
|
* MFDRV_CreatePenIndirect
|
|
|
|
*/
|
2003-11-26 04:38:11 +01:00
|
|
|
static UINT16 MFDRV_CreatePenIndirect(PHYSDEV dev, HPEN hPen, LOGPEN16 *logpen)
|
1999-04-15 18:46:51 +02:00
|
|
|
{
|
|
|
|
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));
|
2003-11-26 04:38:11 +01:00
|
|
|
if (!(MFDRV_WriteRecord( dev, mr, mr->rdSize * 2)))
|
|
|
|
return 0;
|
|
|
|
return MFDRV_AddHandle( dev, hPen );
|
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
|
|
|
*/
|
2011-07-13 14:56:12 +02: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;
|
2003-11-26 04:38:11 +01:00
|
|
|
INT16 index;
|
1999-04-22 18:27:50 +02:00
|
|
|
|
2003-11-26 04:38:11 +01:00
|
|
|
index = MFDRV_FindObject(dev, hpen);
|
|
|
|
if( index < 0 )
|
|
|
|
{
|
2008-02-18 18:07:51 +01:00
|
|
|
/* must be an extended pen */
|
|
|
|
INT size = GetObjectW( hpen, 0, NULL );
|
|
|
|
|
|
|
|
if (!size) return 0;
|
2006-03-09 08:12:43 +01:00
|
|
|
|
2008-02-18 18:07:51 +01:00
|
|
|
if (size == sizeof(LOGPEN))
|
|
|
|
{
|
|
|
|
LOGPEN pen;
|
2006-03-09 08:12:43 +01:00
|
|
|
|
2008-02-18 18:07:51 +01:00
|
|
|
GetObjectW( hpen, sizeof(pen), &pen );
|
|
|
|
logpen.lopnStyle = pen.lopnStyle;
|
|
|
|
logpen.lopnWidth.x = pen.lopnWidth.x;
|
|
|
|
logpen.lopnWidth.y = pen.lopnWidth.y;
|
|
|
|
logpen.lopnColor = pen.lopnColor;
|
|
|
|
}
|
|
|
|
else /* must be an extended pen */
|
|
|
|
{
|
|
|
|
EXTLOGPEN *elp = HeapAlloc( GetProcessHeap(), 0, size );
|
2006-03-09 08:12:43 +01:00
|
|
|
|
|
|
|
GetObjectW( hpen, size, elp );
|
|
|
|
/* FIXME: add support for user style pens */
|
|
|
|
logpen.lopnStyle = elp->elpPenStyle;
|
|
|
|
logpen.lopnWidth.x = elp->elpWidth;
|
2006-01-30 18:17:07 +01:00
|
|
|
logpen.lopnWidth.y = 0;
|
2006-03-09 08:12:43 +01:00
|
|
|
logpen.lopnColor = elp->elpColor;
|
|
|
|
|
|
|
|
HeapFree( GetProcessHeap(), 0, elp );
|
2006-01-30 18:17:07 +01:00
|
|
|
}
|
|
|
|
|
2003-11-26 04:38:11 +01:00
|
|
|
index = MFDRV_CreatePenIndirect( dev, hpen, &logpen );
|
|
|
|
if( index < 0 )
|
|
|
|
return 0;
|
2011-04-04 12:27:02 +02:00
|
|
|
GDI_hdc_using_object(hpen, dev->hdc);
|
2003-11-26 04:38:11 +01:00
|
|
|
}
|
|
|
|
return MFDRV_SelectObject( dev, index ) ? hpen : HGDI_ERROR;
|
1997-02-02 20:01:52 +01:00
|
|
|
}
|
2003-08-30 02:15:12 +02:00
|
|
|
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* MFDRV_CreatePalette
|
|
|
|
*/
|
|
|
|
static BOOL MFDRV_CreatePalette(PHYSDEV dev, HPALETTE hPalette, LOGPALETTE* logPalette, int sizeofPalette)
|
|
|
|
{
|
|
|
|
int index;
|
|
|
|
BOOL ret;
|
|
|
|
METARECORD *mr;
|
|
|
|
|
|
|
|
mr = HeapAlloc( GetProcessHeap(), 0, sizeof(METARECORD) + sizeofPalette - sizeof(WORD) );
|
|
|
|
mr->rdSize = (sizeof(METARECORD) + sizeofPalette - sizeof(WORD)) / sizeof(WORD);
|
|
|
|
mr->rdFunction = META_CREATEPALETTE;
|
|
|
|
memcpy(&(mr->rdParm), logPalette, sizeofPalette);
|
|
|
|
if (!(MFDRV_WriteRecord( dev, mr, mr->rdSize * sizeof(WORD))))
|
|
|
|
{
|
|
|
|
HeapFree(GetProcessHeap(), 0, mr);
|
|
|
|
return FALSE;
|
|
|
|
}
|
|
|
|
|
|
|
|
mr->rdSize = sizeof(METARECORD) / sizeof(WORD);
|
|
|
|
mr->rdFunction = META_SELECTPALETTE;
|
|
|
|
|
2003-11-26 04:38:11 +01:00
|
|
|
if ((index = MFDRV_AddHandle( dev, hPalette )) == -1) ret = FALSE;
|
2003-08-30 02:15:12 +02:00
|
|
|
else
|
|
|
|
{
|
|
|
|
*(mr->rdParm) = index;
|
|
|
|
ret = MFDRV_WriteRecord( dev, mr, mr->rdSize * sizeof(WORD));
|
|
|
|
}
|
|
|
|
HeapFree(GetProcessHeap(), 0, mr);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* MFDRV_SelectPalette
|
|
|
|
*/
|
2011-07-13 14:56:12 +02:00
|
|
|
HPALETTE MFDRV_SelectPalette( PHYSDEV dev, HPALETTE hPalette, BOOL bForceBackground )
|
2003-08-30 02:15:12 +02:00
|
|
|
{
|
|
|
|
#define PALVERSION 0x0300
|
|
|
|
|
|
|
|
PLOGPALETTE logPalette;
|
|
|
|
WORD wNumEntries = 0;
|
|
|
|
BOOL creationSucceed;
|
|
|
|
int sizeofPalette;
|
|
|
|
|
2009-01-26 11:01:12 +01:00
|
|
|
GetObjectA(hPalette, sizeof(WORD), &wNumEntries);
|
2003-08-30 02:15:12 +02:00
|
|
|
|
|
|
|
if (wNumEntries == 0) return 0;
|
|
|
|
|
|
|
|
sizeofPalette = sizeof(LOGPALETTE) + ((wNumEntries-1) * sizeof(PALETTEENTRY));
|
|
|
|
logPalette = HeapAlloc( GetProcessHeap(), 0, sizeofPalette );
|
|
|
|
|
|
|
|
if (logPalette == NULL) return 0;
|
|
|
|
|
|
|
|
logPalette->palVersion = PALVERSION;
|
|
|
|
logPalette->palNumEntries = wNumEntries;
|
|
|
|
|
|
|
|
GetPaletteEntries(hPalette, 0, wNumEntries, logPalette->palPalEntry);
|
|
|
|
|
|
|
|
creationSucceed = MFDRV_CreatePalette( dev, hPalette, logPalette, sizeofPalette );
|
|
|
|
|
|
|
|
HeapFree( GetProcessHeap(), 0, logPalette );
|
|
|
|
|
|
|
|
if (creationSucceed)
|
|
|
|
return hPalette;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* MFDRV_RealizePalette
|
|
|
|
*/
|
2011-07-13 14:56:12 +02:00
|
|
|
UINT MFDRV_RealizePalette(PHYSDEV dev, HPALETTE hPalette, BOOL dummy)
|
2003-08-30 02:15:12 +02:00
|
|
|
{
|
|
|
|
char buffer[sizeof(METARECORD) - sizeof(WORD)];
|
|
|
|
METARECORD *mr = (METARECORD *)&buffer;
|
|
|
|
|
|
|
|
mr->rdSize = (sizeof(METARECORD) - sizeof(WORD)) / sizeof(WORD);
|
|
|
|
mr->rdFunction = META_REALIZEPALETTE;
|
|
|
|
|
|
|
|
if (!(MFDRV_WriteRecord( dev, mr, mr->rdSize * sizeof(WORD)))) return 0;
|
|
|
|
|
|
|
|
/* The return value is suppose to be the number of entries
|
|
|
|
in the logical palette mapped to the system palette or 0
|
|
|
|
if the function failed. Since it's not trivial here to
|
|
|
|
get that kind of information and since it's of little
|
|
|
|
use in the case of metafiles, we'll always return 1. */
|
|
|
|
return 1;
|
|
|
|
}
|