1999-05-02 12:15:16 +02:00
|
|
|
/*
|
|
|
|
* Enhanced MetaFile objects
|
|
|
|
*
|
|
|
|
* Copyright 1999 Huw D M Davies
|
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
|
1999-05-02 12:15:16 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <stdio.h>
|
1999-07-31 19:36:48 +02:00
|
|
|
#include <string.h>
|
|
|
|
|
2002-03-27 22:13:40 +01:00
|
|
|
#include "enhmfdrv/enhmetafiledrv.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"
|
1999-05-02 12:15:16 +02:00
|
|
|
|
2002-03-10 00:29:33 +01:00
|
|
|
WINE_DEFAULT_DEBUG_CHANNEL(enhmetafile);
|
1999-05-02 12:15:16 +02:00
|
|
|
|
2003-11-25 06:03:09 +01:00
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* EMFDRV_AddHandle
|
|
|
|
*/
|
|
|
|
static UINT EMFDRV_AddHandle( PHYSDEV dev, HGDIOBJ obj )
|
|
|
|
{
|
|
|
|
EMFDRV_PDEVICE *physDev = (EMFDRV_PDEVICE *)dev;
|
|
|
|
UINT index;
|
|
|
|
|
|
|
|
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]));
|
|
|
|
}
|
2012-10-16 16:58:28 +02:00
|
|
|
physDev->handles[index] = get_full_gdi_handle( obj );
|
2003-11-25 06:03:09 +01:00
|
|
|
|
|
|
|
physDev->cur_handles++;
|
|
|
|
if(physDev->cur_handles > physDev->emh->nHandles)
|
|
|
|
physDev->emh->nHandles++;
|
|
|
|
|
|
|
|
return index + 1; /* index 0 is reserved for the hmf, so we increment everything by 1 */
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* EMFDRV_FindObject
|
|
|
|
*/
|
|
|
|
static UINT EMFDRV_FindObject( PHYSDEV dev, HGDIOBJ obj )
|
|
|
|
{
|
|
|
|
EMFDRV_PDEVICE *physDev = (EMFDRV_PDEVICE*) dev;
|
|
|
|
UINT index;
|
|
|
|
|
|
|
|
for(index = 0; index < physDev->handles_size; index++)
|
|
|
|
if(physDev->handles[index] == obj) break;
|
|
|
|
|
|
|
|
if(index == physDev->handles_size) return 0;
|
|
|
|
|
|
|
|
return index + 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* EMFDRV_DeleteObject
|
|
|
|
*/
|
2011-07-13 14:56:12 +02:00
|
|
|
BOOL EMFDRV_DeleteObject( PHYSDEV dev, HGDIOBJ obj )
|
2003-11-25 06:03:09 +01:00
|
|
|
{
|
|
|
|
EMRDELETEOBJECT emr;
|
|
|
|
EMFDRV_PDEVICE *physDev = (EMFDRV_PDEVICE*) dev;
|
|
|
|
UINT index;
|
|
|
|
BOOL ret = TRUE;
|
|
|
|
|
|
|
|
if(!(index = EMFDRV_FindObject(dev, obj))) return 0;
|
|
|
|
|
|
|
|
emr.emr.iType = EMR_DELETEOBJECT;
|
|
|
|
emr.emr.nSize = sizeof(emr);
|
|
|
|
emr.ihObject = index;
|
|
|
|
|
|
|
|
if(!EMFDRV_WriteRecord( dev, &emr.emr ))
|
|
|
|
ret = FALSE;
|
|
|
|
|
|
|
|
physDev->handles[index - 1] = 0;
|
|
|
|
physDev->cur_handles--;
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2004-11-22 19:22:20 +01:00
|
|
|
|
1999-05-02 12:15:16 +02:00
|
|
|
/***********************************************************************
|
2002-03-28 23:22:05 +01:00
|
|
|
* EMFDRV_SelectBitmap
|
1999-05-02 12:15:16 +02:00
|
|
|
*/
|
2011-07-13 14:56:12 +02:00
|
|
|
HBITMAP EMFDRV_SelectBitmap( PHYSDEV dev, HBITMAP hbitmap )
|
1999-05-02 12:15:16 +02:00
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
|
|
|
* EMFDRV_CreateBrushIndirect
|
|
|
|
*/
|
2002-03-28 23:22:05 +01:00
|
|
|
DWORD EMFDRV_CreateBrushIndirect( PHYSDEV dev, HBRUSH hBrush )
|
1999-05-02 12:15:16 +02:00
|
|
|
{
|
|
|
|
DWORD index = 0;
|
2001-07-23 01:34:21 +02:00
|
|
|
LOGBRUSH logbrush;
|
1999-05-02 12:15:16 +02:00
|
|
|
|
2001-07-23 01:34:21 +02:00
|
|
|
if (!GetObjectA( hBrush, sizeof(logbrush), &logbrush )) return 0;
|
|
|
|
|
|
|
|
switch (logbrush.lbStyle) {
|
1999-05-02 12:15:16 +02:00
|
|
|
case BS_SOLID:
|
|
|
|
case BS_HATCHED:
|
|
|
|
case BS_NULL:
|
|
|
|
{
|
|
|
|
EMRCREATEBRUSHINDIRECT emr;
|
|
|
|
emr.emr.iType = EMR_CREATEBRUSHINDIRECT;
|
|
|
|
emr.emr.nSize = sizeof(emr);
|
2003-11-25 06:03:09 +01:00
|
|
|
emr.ihBrush = index = EMFDRV_AddHandle( dev, hBrush );
|
2005-09-12 13:19:56 +02:00
|
|
|
emr.lb.lbStyle = logbrush.lbStyle;
|
|
|
|
emr.lb.lbColor = logbrush.lbColor;
|
|
|
|
emr.lb.lbHatch = logbrush.lbHatch;
|
1999-05-02 12:15:16 +02:00
|
|
|
|
2002-03-28 23:22:05 +01:00
|
|
|
if(!EMFDRV_WriteRecord( dev, &emr.emr ))
|
1999-05-02 12:15:16 +02:00
|
|
|
index = 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case BS_PATTERN:
|
2011-11-01 22:06:23 +01:00
|
|
|
case BS_DIBPATTERN:
|
2004-11-22 19:22:20 +01:00
|
|
|
{
|
|
|
|
EMRCREATEDIBPATTERNBRUSHPT *emr;
|
2011-08-03 13:08:34 +02:00
|
|
|
char buffer[FIELD_OFFSET( BITMAPINFO, bmiColors[256] )];
|
2011-11-01 22:06:23 +01:00
|
|
|
BITMAPINFO *info = (BITMAPINFO *)buffer;
|
2011-12-10 13:28:08 +01:00
|
|
|
DWORD info_size;
|
2011-11-01 22:06:23 +01:00
|
|
|
void *bits;
|
|
|
|
UINT usage;
|
2004-11-22 19:22:20 +01:00
|
|
|
|
2011-11-01 22:06:23 +01:00
|
|
|
if (!get_brush_bitmap_info( hBrush, info, &bits, &usage )) break;
|
2011-12-10 13:28:08 +01:00
|
|
|
info_size = get_dib_info_size( info, usage );
|
2004-11-22 19:22:20 +01:00
|
|
|
|
2011-12-10 13:28:08 +01:00
|
|
|
emr = HeapAlloc( GetProcessHeap(), 0,
|
|
|
|
sizeof(EMRCREATEDIBPATTERNBRUSHPT)+info_size+info->bmiHeader.biSizeImage );
|
2011-11-01 22:06:23 +01:00
|
|
|
if(!emr) break;
|
2004-11-22 19:22:20 +01:00
|
|
|
|
2011-11-01 22:06:23 +01:00
|
|
|
if (logbrush.lbStyle == BS_PATTERN && info->bmiHeader.biBitCount == 1)
|
2011-08-03 13:08:34 +02:00
|
|
|
{
|
2011-11-01 22:06:23 +01:00
|
|
|
/* Presumably to reduce the size of the written EMF, MS supports an
|
|
|
|
* undocumented iUsage value of 2, indicating a mono bitmap without the
|
|
|
|
* 8 byte 2 entry black/white palette. Stupidly, they could have saved
|
|
|
|
* over 20 bytes more by also ignoring the BITMAPINFO fields that are
|
|
|
|
* irrelevant/constant for monochrome bitmaps.
|
|
|
|
* FIXME: It may be that the DIB functions themselves accept this value.
|
|
|
|
*/
|
|
|
|
emr->emr.iType = EMR_CREATEMONOBRUSH;
|
|
|
|
usage = DIB_PAL_MONO;
|
|
|
|
/* FIXME: There is an extra DWORD written by native before the BMI.
|
|
|
|
* Not sure what its meant to contain.
|
|
|
|
*/
|
|
|
|
emr->offBmi = sizeof( EMRCREATEDIBPATTERNBRUSHPT ) + sizeof(DWORD);
|
|
|
|
emr->cbBmi = sizeof( BITMAPINFOHEADER );
|
2011-08-03 13:08:34 +02:00
|
|
|
}
|
2011-11-01 22:06:23 +01:00
|
|
|
else
|
|
|
|
{
|
|
|
|
emr->emr.iType = EMR_CREATEDIBPATTERNBRUSHPT;
|
|
|
|
emr->offBmi = sizeof( EMRCREATEDIBPATTERNBRUSHPT );
|
|
|
|
emr->cbBmi = info_size;
|
|
|
|
}
|
2004-11-22 19:22:20 +01:00
|
|
|
emr->ihBrush = index = EMFDRV_AddHandle( dev, hBrush );
|
2011-11-01 22:06:23 +01:00
|
|
|
emr->iUsage = usage;
|
2011-08-03 13:08:34 +02:00
|
|
|
emr->offBits = emr->offBmi + emr->cbBmi;
|
2011-12-10 13:28:08 +01:00
|
|
|
emr->cbBits = info->bmiHeader.biSizeImage;
|
2012-02-24 17:03:57 +01:00
|
|
|
emr->emr.nSize = emr->offBits + emr->cbBits;
|
2011-11-01 22:06:23 +01:00
|
|
|
|
|
|
|
memcpy( (BYTE *)emr + emr->offBmi, info, emr->cbBmi );
|
|
|
|
memcpy( (BYTE *)emr + emr->offBits, bits, emr->cbBits );
|
2004-11-22 19:22:20 +01:00
|
|
|
|
|
|
|
if(!EMFDRV_WriteRecord( dev, &emr->emr ))
|
|
|
|
index = 0;
|
|
|
|
HeapFree( GetProcessHeap(), 0, emr );
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
1999-05-02 12:15:16 +02:00
|
|
|
default:
|
2001-07-23 01:34:21 +02:00
|
|
|
FIXME("Unknown style %x\n", logbrush.lbStyle);
|
2000-08-19 23:38:55 +02:00
|
|
|
break;
|
1999-05-02 12:15:16 +02:00
|
|
|
}
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2002-03-28 23:22:05 +01:00
|
|
|
* EMFDRV_SelectBrush
|
1999-05-02 12:15:16 +02:00
|
|
|
*/
|
2011-12-29 19:49:41 +01:00
|
|
|
HBRUSH EMFDRV_SelectBrush( PHYSDEV dev, HBRUSH hBrush, const struct brush_pattern *pattern )
|
1999-05-02 12:15:16 +02:00
|
|
|
{
|
2003-11-25 06:03:09 +01:00
|
|
|
EMFDRV_PDEVICE *physDev = (EMFDRV_PDEVICE*)dev;
|
1999-05-02 12:15:16 +02:00
|
|
|
EMRSELECTOBJECT emr;
|
|
|
|
DWORD index;
|
2001-08-17 02:07:13 +02:00
|
|
|
int i;
|
|
|
|
|
2009-04-07 20:41:41 +02:00
|
|
|
if (physDev->restoring) return hBrush; /* don't output SelectObject records during RestoreDC */
|
|
|
|
|
2000-04-18 13:53:23 +02:00
|
|
|
/* If the object is a stock brush object, do not need to create it.
|
|
|
|
* See definitions in wingdi.h for range of stock brushes.
|
|
|
|
* We do however have to handle setting the higher order bit to
|
|
|
|
* designate that this is a stock object.
|
|
|
|
*/
|
2011-03-10 20:22:22 +01:00
|
|
|
for (i = WHITE_BRUSH; i <= DC_BRUSH; i++)
|
2000-04-18 13:53:23 +02:00
|
|
|
{
|
2001-08-17 02:07:13 +02:00
|
|
|
if (hBrush == GetStockObject(i))
|
|
|
|
{
|
|
|
|
index = i | 0x80000000;
|
|
|
|
goto found;
|
|
|
|
}
|
2000-04-18 13:53:23 +02:00
|
|
|
}
|
2003-11-25 06:03:09 +01:00
|
|
|
if((index = EMFDRV_FindObject(dev, hBrush)) != 0)
|
|
|
|
goto found;
|
|
|
|
|
2002-03-28 23:22:05 +01:00
|
|
|
if (!(index = EMFDRV_CreateBrushIndirect(dev, hBrush ))) return 0;
|
2011-04-04 12:27:09 +02:00
|
|
|
GDI_hdc_using_object(hBrush, dev->hdc);
|
2000-04-18 13:53:23 +02:00
|
|
|
|
2001-08-17 02:07:13 +02:00
|
|
|
found:
|
1999-05-02 12:15:16 +02:00
|
|
|
emr.emr.iType = EMR_SELECTOBJECT;
|
|
|
|
emr.emr.nSize = sizeof(emr);
|
|
|
|
emr.ihObject = index;
|
2002-03-28 23:22:05 +01:00
|
|
|
return EMFDRV_WriteRecord( dev, &emr.emr ) ? hBrush : 0;
|
1999-05-02 12:15:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* EMFDRV_CreateFontIndirect
|
|
|
|
*/
|
2002-03-28 23:22:05 +01:00
|
|
|
static BOOL EMFDRV_CreateFontIndirect(PHYSDEV dev, HFONT hFont )
|
1999-05-02 12:15:16 +02:00
|
|
|
{
|
|
|
|
DWORD index = 0;
|
|
|
|
EMREXTCREATEFONTINDIRECTW emr;
|
|
|
|
int i;
|
2001-07-23 01:34:21 +02:00
|
|
|
|
|
|
|
if (!GetObjectW( hFont, sizeof(emr.elfw.elfLogFont), &emr.elfw.elfLogFont )) return 0;
|
|
|
|
|
1999-05-02 12:15:16 +02:00
|
|
|
emr.emr.iType = EMR_EXTCREATEFONTINDIRECTW;
|
|
|
|
emr.emr.nSize = (sizeof(emr) + 3) / 4 * 4;
|
2003-11-25 06:03:09 +01:00
|
|
|
emr.ihFont = index = EMFDRV_AddHandle( dev, hFont );
|
1999-05-02 12:15:16 +02:00
|
|
|
emr.elfw.elfFullName[0] = '\0';
|
|
|
|
emr.elfw.elfStyle[0] = '\0';
|
|
|
|
emr.elfw.elfVersion = 0;
|
|
|
|
emr.elfw.elfStyleSize = 0;
|
|
|
|
emr.elfw.elfMatch = 0;
|
|
|
|
emr.elfw.elfReserved = 0;
|
|
|
|
for(i = 0; i < ELF_VENDOR_SIZE; i++)
|
|
|
|
emr.elfw.elfVendorId[i] = 0;
|
|
|
|
emr.elfw.elfCulture = PAN_CULTURE_LATIN;
|
|
|
|
emr.elfw.elfPanose.bFamilyType = PAN_NO_FIT;
|
|
|
|
emr.elfw.elfPanose.bSerifStyle = PAN_NO_FIT;
|
|
|
|
emr.elfw.elfPanose.bWeight = PAN_NO_FIT;
|
|
|
|
emr.elfw.elfPanose.bProportion = PAN_NO_FIT;
|
|
|
|
emr.elfw.elfPanose.bContrast = PAN_NO_FIT;
|
|
|
|
emr.elfw.elfPanose.bStrokeVariation = PAN_NO_FIT;
|
|
|
|
emr.elfw.elfPanose.bArmStyle = PAN_NO_FIT;
|
|
|
|
emr.elfw.elfPanose.bLetterform = PAN_NO_FIT;
|
|
|
|
emr.elfw.elfPanose.bMidline = PAN_NO_FIT;
|
|
|
|
emr.elfw.elfPanose.bXHeight = PAN_NO_FIT;
|
|
|
|
|
2002-03-28 23:22:05 +01:00
|
|
|
if(!EMFDRV_WriteRecord( dev, &emr.emr ))
|
1999-05-02 12:15:16 +02:00
|
|
|
index = 0;
|
|
|
|
return index;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/***********************************************************************
|
2002-03-28 23:22:05 +01:00
|
|
|
* EMFDRV_SelectFont
|
1999-05-02 12:15:16 +02:00
|
|
|
*/
|
2012-10-30 19:37:31 +01:00
|
|
|
HFONT EMFDRV_SelectFont( PHYSDEV dev, HFONT hFont, UINT *aa_flags )
|
1999-05-02 12:15:16 +02:00
|
|
|
{
|
2003-11-25 06:03:09 +01:00
|
|
|
EMFDRV_PDEVICE *physDev = (EMFDRV_PDEVICE*)dev;
|
1999-05-02 12:15:16 +02:00
|
|
|
EMRSELECTOBJECT emr;
|
|
|
|
DWORD index;
|
2001-08-17 02:07:13 +02:00
|
|
|
int i;
|
1999-05-02 12:15:16 +02:00
|
|
|
|
2011-10-18 13:10:58 +02:00
|
|
|
if (physDev->restoring) goto done; /* don't output SelectObject records during RestoreDC */
|
2009-04-07 20:41:41 +02:00
|
|
|
|
2000-04-18 13:53:23 +02:00
|
|
|
/* If the object is a stock font object, do not need to create it.
|
|
|
|
* See definitions in wingdi.h for range of stock fonts.
|
|
|
|
* We do however have to handle setting the higher order bit to
|
|
|
|
* designate that this is a stock object.
|
|
|
|
*/
|
|
|
|
|
2001-08-17 02:07:13 +02:00
|
|
|
for (i = OEM_FIXED_FONT; i <= DEFAULT_GUI_FONT; i++)
|
2000-04-18 13:53:23 +02:00
|
|
|
{
|
2001-08-17 02:07:13 +02:00
|
|
|
if (i != DEFAULT_PALETTE && hFont == GetStockObject(i))
|
|
|
|
{
|
|
|
|
index = i | 0x80000000;
|
|
|
|
goto found;
|
|
|
|
}
|
2000-04-18 13:53:23 +02:00
|
|
|
}
|
2003-11-25 06:03:09 +01:00
|
|
|
|
|
|
|
if((index = EMFDRV_FindObject(dev, hFont)) != 0)
|
|
|
|
goto found;
|
|
|
|
|
2011-10-18 13:10:58 +02:00
|
|
|
if (!(index = EMFDRV_CreateFontIndirect(dev, hFont ))) return 0;
|
2011-04-04 12:27:09 +02:00
|
|
|
GDI_hdc_using_object(hFont, dev->hdc);
|
2003-11-25 06:03:09 +01:00
|
|
|
|
2001-08-17 02:07:13 +02:00
|
|
|
found:
|
1999-05-02 12:15:16 +02:00
|
|
|
emr.emr.iType = EMR_SELECTOBJECT;
|
|
|
|
emr.emr.nSize = sizeof(emr);
|
|
|
|
emr.ihObject = index;
|
2002-03-28 23:22:05 +01:00
|
|
|
if(!EMFDRV_WriteRecord( dev, &emr.emr ))
|
2011-10-18 13:10:58 +02:00
|
|
|
return 0;
|
|
|
|
done:
|
2012-10-31 16:07:51 +01:00
|
|
|
*aa_flags = GGO_BITMAP; /* no point in anti-aliasing on metafiles */
|
2011-10-18 13:10:58 +02:00
|
|
|
dev = GET_NEXT_PHYSDEV( dev, pSelectFont );
|
2012-10-30 19:37:31 +01:00
|
|
|
dev->funcs->pSelectFont( dev, hFont, aa_flags );
|
2011-10-18 13:10:58 +02:00
|
|
|
return hFont;
|
1999-05-02 12:15:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* EMFDRV_CreatePenIndirect
|
|
|
|
*/
|
2007-05-30 10:51:47 +02:00
|
|
|
static DWORD EMFDRV_CreatePenIndirect(PHYSDEV dev, HPEN hPen)
|
1999-05-02 12:15:16 +02:00
|
|
|
{
|
|
|
|
EMRCREATEPEN emr;
|
|
|
|
DWORD index = 0;
|
|
|
|
|
2006-01-30 18:17:07 +01:00
|
|
|
if (!GetObjectW( hPen, sizeof(emr.lopn), &emr.lopn ))
|
|
|
|
{
|
|
|
|
/* must be an extended pen */
|
2006-03-09 08:12:43 +01:00
|
|
|
EXTLOGPEN *elp;
|
|
|
|
INT size = GetObjectW( hPen, 0, NULL );
|
|
|
|
|
|
|
|
if (!size) return 0;
|
|
|
|
|
|
|
|
elp = HeapAlloc( GetProcessHeap(), 0, size );
|
|
|
|
|
|
|
|
GetObjectW( hPen, size, elp );
|
|
|
|
/* FIXME: add support for user style pens */
|
|
|
|
emr.lopn.lopnStyle = elp->elpPenStyle;
|
|
|
|
emr.lopn.lopnWidth.x = elp->elpWidth;
|
2006-01-30 18:17:07 +01:00
|
|
|
emr.lopn.lopnWidth.y = 0;
|
2006-03-09 08:12:43 +01:00
|
|
|
emr.lopn.lopnColor = elp->elpColor;
|
|
|
|
|
|
|
|
HeapFree( GetProcessHeap(), 0, elp );
|
2006-01-30 18:17:07 +01:00
|
|
|
}
|
2001-07-23 01:34:21 +02:00
|
|
|
|
1999-05-02 12:15:16 +02:00
|
|
|
emr.emr.iType = EMR_CREATEPEN;
|
|
|
|
emr.emr.nSize = sizeof(emr);
|
2003-11-25 06:03:09 +01:00
|
|
|
emr.ihPen = index = EMFDRV_AddHandle( dev, hPen );
|
1999-05-02 12:15:16 +02:00
|
|
|
|
2002-03-28 23:22:05 +01:00
|
|
|
if(!EMFDRV_WriteRecord( dev, &emr.emr ))
|
1999-05-02 12:15:16 +02:00
|
|
|
index = 0;
|
2007-05-30 10:51:47 +02:00
|
|
|
return index;
|
1999-05-02 12:15:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
2002-03-28 23:22:05 +01:00
|
|
|
* EMFDRV_SelectPen
|
1999-05-02 12:15:16 +02:00
|
|
|
*/
|
2011-12-29 20:16:46 +01:00
|
|
|
HPEN EMFDRV_SelectPen(PHYSDEV dev, HPEN hPen, const struct brush_pattern *pattern )
|
1999-05-02 12:15:16 +02:00
|
|
|
{
|
2003-11-25 06:03:09 +01:00
|
|
|
EMFDRV_PDEVICE *physDev = (EMFDRV_PDEVICE*)dev;
|
1999-05-02 12:15:16 +02:00
|
|
|
EMRSELECTOBJECT emr;
|
|
|
|
DWORD index;
|
2001-08-17 02:07:13 +02:00
|
|
|
int i;
|
1999-05-02 12:15:16 +02:00
|
|
|
|
2009-04-07 20:41:41 +02:00
|
|
|
if (physDev->restoring) return hPen; /* don't output SelectObject records during RestoreDC */
|
|
|
|
|
2000-04-18 13:53:23 +02:00
|
|
|
/* If the object is a stock pen object, do not need to create it.
|
|
|
|
* See definitions in wingdi.h for range of stock pens.
|
|
|
|
* We do however have to handle setting the higher order bit to
|
|
|
|
* designate that this is a stock object.
|
|
|
|
*/
|
|
|
|
|
2011-03-10 20:22:22 +01:00
|
|
|
for (i = WHITE_PEN; i <= DC_PEN; i++)
|
2000-04-18 13:53:23 +02:00
|
|
|
{
|
2001-08-17 02:07:13 +02:00
|
|
|
if (hPen == GetStockObject(i))
|
|
|
|
{
|
|
|
|
index = i | 0x80000000;
|
|
|
|
goto found;
|
|
|
|
}
|
2000-04-18 13:53:23 +02:00
|
|
|
}
|
2003-11-25 06:03:09 +01:00
|
|
|
if((index = EMFDRV_FindObject(dev, hPen)) != 0)
|
|
|
|
goto found;
|
|
|
|
|
2007-05-30 10:51:47 +02:00
|
|
|
if (!(index = EMFDRV_CreatePenIndirect(dev, hPen))) return 0;
|
2011-04-04 12:27:09 +02:00
|
|
|
GDI_hdc_using_object(hPen, dev->hdc);
|
2003-11-25 06:03:09 +01:00
|
|
|
|
2001-08-17 02:07:13 +02:00
|
|
|
found:
|
1999-05-02 12:15:16 +02:00
|
|
|
emr.emr.iType = EMR_SELECTOBJECT;
|
|
|
|
emr.emr.nSize = sizeof(emr);
|
|
|
|
emr.ihObject = index;
|
2002-03-28 23:22:05 +01:00
|
|
|
return EMFDRV_WriteRecord( dev, &emr.emr ) ? hPen : 0;
|
1999-05-02 12:15:16 +02:00
|
|
|
}
|
2003-05-21 20:28:49 +02:00
|
|
|
|
|
|
|
|
2008-05-07 13:35:04 +02:00
|
|
|
/******************************************************************
|
|
|
|
* EMFDRV_CreatePalette
|
|
|
|
*/
|
|
|
|
static DWORD EMFDRV_CreatePalette(PHYSDEV dev, HPALETTE hPal)
|
|
|
|
{
|
|
|
|
WORD i;
|
|
|
|
struct {
|
|
|
|
EMRCREATEPALETTE hdr;
|
|
|
|
PALETTEENTRY entry[255];
|
|
|
|
} pal;
|
|
|
|
|
|
|
|
memset( &pal, 0, sizeof(pal) );
|
|
|
|
|
|
|
|
if (!GetObjectW( hPal, sizeof(pal.hdr.lgpl) + sizeof(pal.entry), &pal.hdr.lgpl ))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
for (i = 0; i < pal.hdr.lgpl.palNumEntries; i++)
|
|
|
|
pal.hdr.lgpl.palPalEntry[i].peFlags = 0;
|
|
|
|
|
|
|
|
pal.hdr.emr.iType = EMR_CREATEPALETTE;
|
|
|
|
pal.hdr.emr.nSize = sizeof(pal.hdr) + pal.hdr.lgpl.palNumEntries * sizeof(PALETTEENTRY);
|
|
|
|
pal.hdr.ihPal = EMFDRV_AddHandle( dev, hPal );
|
|
|
|
|
|
|
|
if (!EMFDRV_WriteRecord( dev, &pal.hdr.emr ))
|
|
|
|
pal.hdr.ihPal = 0;
|
|
|
|
return pal.hdr.ihPal;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* EMFDRV_SelectPalette
|
|
|
|
*/
|
2011-07-13 14:56:12 +02:00
|
|
|
HPALETTE EMFDRV_SelectPalette( PHYSDEV dev, HPALETTE hPal, BOOL force )
|
2008-05-07 13:35:04 +02:00
|
|
|
{
|
|
|
|
EMFDRV_PDEVICE *physDev = (EMFDRV_PDEVICE*)dev;
|
|
|
|
EMRSELECTPALETTE emr;
|
|
|
|
DWORD index;
|
|
|
|
|
2009-04-07 20:41:41 +02:00
|
|
|
if (physDev->restoring) return hPal; /* don't output SelectObject records during RestoreDC */
|
|
|
|
|
2008-05-07 13:35:04 +02:00
|
|
|
if (hPal == GetStockObject( DEFAULT_PALETTE ))
|
2008-05-09 12:02:21 +02:00
|
|
|
{
|
2008-05-07 13:35:04 +02:00
|
|
|
index = DEFAULT_PALETTE | 0x80000000;
|
|
|
|
goto found;
|
2008-05-09 12:02:21 +02:00
|
|
|
}
|
2008-05-07 13:35:04 +02:00
|
|
|
|
|
|
|
if ((index = EMFDRV_FindObject( dev, hPal )) != 0)
|
|
|
|
goto found;
|
|
|
|
|
|
|
|
if (!(index = EMFDRV_CreatePalette( dev, hPal ))) return 0;
|
2011-04-04 12:27:09 +02:00
|
|
|
GDI_hdc_using_object( hPal, dev->hdc );
|
2008-05-07 13:35:04 +02:00
|
|
|
|
|
|
|
found:
|
|
|
|
emr.emr.iType = EMR_SELECTPALETTE;
|
|
|
|
emr.emr.nSize = sizeof(emr);
|
|
|
|
emr.ihPal = index;
|
|
|
|
return EMFDRV_WriteRecord( dev, &emr.emr ) ? hPal : 0;
|
|
|
|
}
|
|
|
|
|
2011-03-10 20:22:22 +01:00
|
|
|
/******************************************************************
|
|
|
|
* EMFDRV_SetDCBrushColor
|
|
|
|
*/
|
2011-07-13 14:56:12 +02:00
|
|
|
COLORREF EMFDRV_SetDCBrushColor( PHYSDEV dev, COLORREF color )
|
2011-03-10 20:22:22 +01:00
|
|
|
{
|
|
|
|
EMFDRV_PDEVICE *physDev = (EMFDRV_PDEVICE*)dev;
|
|
|
|
EMRSELECTOBJECT emr;
|
|
|
|
DWORD index;
|
|
|
|
|
2011-04-04 12:27:09 +02:00
|
|
|
if (GetCurrentObject( dev->hdc, OBJ_BRUSH ) != GetStockObject( DC_BRUSH )) return color;
|
2011-03-10 20:22:22 +01:00
|
|
|
|
|
|
|
if (physDev->dc_brush) DeleteObject( physDev->dc_brush );
|
|
|
|
if (!(physDev->dc_brush = CreateSolidBrush( color ))) return CLR_INVALID;
|
|
|
|
if (!(index = EMFDRV_CreateBrushIndirect(dev, physDev->dc_brush ))) return CLR_INVALID;
|
2011-04-04 12:27:09 +02:00
|
|
|
GDI_hdc_using_object( physDev->dc_brush, dev->hdc );
|
2011-03-10 20:22:22 +01:00
|
|
|
emr.emr.iType = EMR_SELECTOBJECT;
|
|
|
|
emr.emr.nSize = sizeof(emr);
|
|
|
|
emr.ihObject = index;
|
|
|
|
return EMFDRV_WriteRecord( dev, &emr.emr ) ? color : CLR_INVALID;
|
|
|
|
}
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* EMFDRV_SetDCPenColor
|
|
|
|
*/
|
2011-07-13 14:56:12 +02:00
|
|
|
COLORREF EMFDRV_SetDCPenColor( PHYSDEV dev, COLORREF color )
|
2011-03-10 20:22:22 +01:00
|
|
|
{
|
|
|
|
EMFDRV_PDEVICE *physDev = (EMFDRV_PDEVICE*)dev;
|
|
|
|
EMRSELECTOBJECT emr;
|
|
|
|
DWORD index;
|
|
|
|
LOGPEN logpen = { PS_SOLID, { 0, 0 }, color };
|
|
|
|
|
2011-04-04 12:27:09 +02:00
|
|
|
if (GetCurrentObject( dev->hdc, OBJ_PEN ) != GetStockObject( DC_PEN )) return color;
|
2011-03-10 20:22:22 +01:00
|
|
|
|
|
|
|
if (physDev->dc_pen) DeleteObject( physDev->dc_pen );
|
|
|
|
if (!(physDev->dc_pen = CreatePenIndirect( &logpen ))) return CLR_INVALID;
|
|
|
|
if (!(index = EMFDRV_CreatePenIndirect(dev, physDev->dc_pen))) return CLR_INVALID;
|
2011-04-04 12:27:09 +02:00
|
|
|
GDI_hdc_using_object( physDev->dc_pen, dev->hdc );
|
2011-03-10 20:22:22 +01:00
|
|
|
emr.emr.iType = EMR_SELECTOBJECT;
|
|
|
|
emr.emr.nSize = sizeof(emr);
|
|
|
|
emr.ihObject = index;
|
|
|
|
return EMFDRV_WriteRecord( dev, &emr.emr ) ? color : CLR_INVALID;
|
|
|
|
}
|
2008-05-07 13:35:04 +02:00
|
|
|
|
2003-05-21 20:28:49 +02:00
|
|
|
/******************************************************************
|
|
|
|
* EMFDRV_GdiComment
|
|
|
|
*/
|
2011-07-13 14:56:12 +02:00
|
|
|
BOOL EMFDRV_GdiComment(PHYSDEV dev, UINT bytes, CONST BYTE *buffer)
|
2003-05-21 20:28:49 +02:00
|
|
|
{
|
|
|
|
EMRGDICOMMENT *emr;
|
|
|
|
UINT total, rounded_size;
|
|
|
|
BOOL ret;
|
|
|
|
|
|
|
|
rounded_size = (bytes+3) & ~3;
|
|
|
|
total = offsetof(EMRGDICOMMENT,Data) + rounded_size;
|
|
|
|
|
|
|
|
emr = HeapAlloc(GetProcessHeap(), 0, total);
|
|
|
|
emr->emr.iType = EMR_GDICOMMENT;
|
|
|
|
emr->emr.nSize = total;
|
|
|
|
emr->cbData = bytes;
|
|
|
|
memset(&emr->Data[bytes], 0, rounded_size - bytes);
|
|
|
|
memcpy(&emr->Data[0], buffer, bytes);
|
|
|
|
|
|
|
|
ret = EMFDRV_WriteRecord( dev, &emr->emr );
|
|
|
|
|
|
|
|
HeapFree(GetProcessHeap(), 0, emr);
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
}
|