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
|
|
|
|
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 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>
|
|
|
|
|
1999-05-02 12:15:16 +02:00
|
|
|
#include "bitmap.h"
|
2002-03-27 22:13:40 +01:00
|
|
|
#include "enhmfdrv/enhmetafiledrv.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
|
|
|
|
|
|
|
/***********************************************************************
|
2002-03-28 23:22:05 +01:00
|
|
|
* EMFDRV_SelectBitmap
|
1999-05-02 12:15:16 +02:00
|
|
|
*/
|
2002-03-28 23:22:05 +01: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);
|
2002-03-28 23:22:05 +01:00
|
|
|
emr.ihBrush = index = EMFDRV_AddHandleDC( dev );
|
2001-07-23 01:34:21 +02:00
|
|
|
emr.lb = logbrush;
|
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_DIBPATTERN:
|
|
|
|
{
|
|
|
|
EMRCREATEDIBPATTERNBRUSHPT *emr;
|
|
|
|
DWORD bmSize, biSize, size;
|
2001-07-23 01:34:21 +02:00
|
|
|
BITMAPINFO *info = GlobalLock16(logbrush.lbHatch);
|
1999-05-02 12:15:16 +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-05-02 12:15:16 +02:00
|
|
|
size = sizeof(EMRCREATEDIBPATTERNBRUSHPT) + biSize + bmSize;
|
2000-02-16 23:47:24 +01:00
|
|
|
emr = HeapAlloc( GetProcessHeap(), 0, size );
|
|
|
|
if(!emr) break;
|
1999-05-02 12:15:16 +02:00
|
|
|
emr->emr.iType = EMR_CREATEDIBPATTERNBRUSHPT;
|
|
|
|
emr->emr.nSize = size;
|
2002-03-28 23:22:05 +01:00
|
|
|
emr->ihBrush = index = EMFDRV_AddHandleDC( dev );
|
2001-07-23 01:34:21 +02:00
|
|
|
emr->iUsage = LOWORD(logbrush.lbColor);
|
1999-05-02 12:15:16 +02:00
|
|
|
emr->offBmi = sizeof(EMRCREATEDIBPATTERNBRUSHPT);
|
|
|
|
emr->cbBmi = biSize;
|
|
|
|
emr->offBits = sizeof(EMRCREATEDIBPATTERNBRUSHPT) + biSize;
|
2002-08-17 02:26:57 +02:00
|
|
|
emr->cbBits = bmSize;
|
1999-05-02 12:15:16 +02:00
|
|
|
memcpy((char *)emr + sizeof(EMRCREATEDIBPATTERNBRUSHPT), info,
|
2002-06-01 01:06:46 +02:00
|
|
|
biSize + bmSize );
|
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;
|
2000-02-16 23:47:24 +01:00
|
|
|
HeapFree( GetProcessHeap(), 0, emr );
|
2001-07-23 01:34:21 +02:00
|
|
|
GlobalUnlock16(logbrush.lbHatch);
|
1999-05-02 12:15:16 +02:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case BS_PATTERN:
|
1999-06-26 21:09:08 +02:00
|
|
|
FIXME("Unsupported style %x\n",
|
2001-07-23 01:34:21 +02:00
|
|
|
logbrush.lbStyle);
|
1999-05-02 12:15:16 +02:00
|
|
|
break;
|
|
|
|
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
|
|
|
*/
|
2002-03-28 23:22:05 +01:00
|
|
|
HBRUSH EMFDRV_SelectBrush(PHYSDEV dev, HBRUSH hBrush )
|
1999-05-02 12:15:16 +02:00
|
|
|
{
|
|
|
|
EMRSELECTOBJECT emr;
|
|
|
|
DWORD index;
|
2001-08-17 02:07:13 +02:00
|
|
|
int i;
|
|
|
|
|
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.
|
|
|
|
*/
|
2001-08-17 02:07:13 +02:00
|
|
|
for (i = WHITE_BRUSH; i <= NULL_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
|
|
|
}
|
2002-03-28 23:22:05 +01:00
|
|
|
if (!(index = EMFDRV_CreateBrushIndirect(dev, hBrush ))) return 0;
|
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;
|
2002-03-28 23:22:05 +01:00
|
|
|
emr.ihFont = index = EMFDRV_AddHandleDC( dev );
|
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
|
|
|
*/
|
2002-03-28 23:22:05 +01:00
|
|
|
HFONT EMFDRV_SelectFont( PHYSDEV dev, HFONT hFont )
|
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
|
|
|
|
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
|
|
|
}
|
2002-08-16 02:42:06 +02:00
|
|
|
if (!(index = EMFDRV_CreateFontIndirect(dev, hFont ))) return HGDI_ERROR;
|
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 ))
|
2002-08-16 02:42:06 +02:00
|
|
|
return HGDI_ERROR;
|
2002-03-28 23:22:05 +01:00
|
|
|
return 0;
|
1999-05-02 12:15:16 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* EMFDRV_CreatePenIndirect
|
|
|
|
*/
|
2002-03-28 23:22:05 +01:00
|
|
|
static HPEN EMFDRV_CreatePenIndirect(PHYSDEV dev, HPEN hPen )
|
1999-05-02 12:15:16 +02:00
|
|
|
{
|
|
|
|
EMRCREATEPEN emr;
|
|
|
|
DWORD index = 0;
|
|
|
|
|
2001-07-23 01:34:21 +02:00
|
|
|
if (!GetObjectA( hPen, sizeof(emr.lopn), &emr.lopn )) return 0;
|
|
|
|
|
1999-05-02 12:15:16 +02:00
|
|
|
emr.emr.iType = EMR_CREATEPEN;
|
|
|
|
emr.emr.nSize = sizeof(emr);
|
2002-03-28 23:22:05 +01:00
|
|
|
emr.ihPen = index = EMFDRV_AddHandleDC( dev );
|
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;
|
2002-11-21 22:50:04 +01:00
|
|
|
return (HPEN)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
|
|
|
*/
|
2002-03-28 23:22:05 +01:00
|
|
|
HPEN EMFDRV_SelectPen(PHYSDEV dev, HPEN hPen )
|
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
|
|
|
|
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.
|
|
|
|
*/
|
|
|
|
|
2001-08-17 02:07:13 +02:00
|
|
|
for (i = WHITE_PEN; i <= NULL_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
|
|
|
}
|
2002-11-21 22:50:04 +01:00
|
|
|
if (!(index = (DWORD)EMFDRV_CreatePenIndirect(dev, hPen ))) return 0;
|
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
|
|
|
|
|
|
|
|
|
|
|
/******************************************************************
|
|
|
|
* EMFDRV_GdiComment
|
|
|
|
*/
|
|
|
|
BOOL EMFDRV_GdiComment(PHYSDEV dev, UINT bytes, CONST BYTE *buffer)
|
|
|
|
{
|
|
|
|
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;
|
|
|
|
}
|