Commit 3964aa4a authored by Alexandre Julliard's avatar Alexandre Julliard

gdi32: Get rid of the METAFILEOBJ type, instead store a pointer to the metafile data.

parent 89ecf02c
...@@ -71,12 +71,6 @@ typedef struct ...@@ -71,12 +71,6 @@ typedef struct
} METAHEADERDISK; } METAHEADERDISK;
#include "poppack.h" #include "poppack.h"
typedef struct
{
GDIOBJHDR header;
METAHEADER *mh;
} METAFILEOBJ;
/****************************************************************** /******************************************************************
* MF_AddHandle * MF_AddHandle
...@@ -108,31 +102,7 @@ static int MF_AddHandle(HANDLETABLE *ht, UINT htlen, HGDIOBJ hobj) ...@@ -108,31 +102,7 @@ static int MF_AddHandle(HANDLETABLE *ht, UINT htlen, HGDIOBJ hobj)
*/ */
HMETAFILE MF_Create_HMETAFILE(METAHEADER *mh) HMETAFILE MF_Create_HMETAFILE(METAHEADER *mh)
{ {
HMETAFILE hmf; return alloc_gdi_handle( mh, OBJ_METAFILE, NULL );
METAFILEOBJ *metaObj;
if (!(metaObj = HeapAlloc( GetProcessHeap(), 0, sizeof(*metaObj) ))) return 0;
metaObj->mh = mh;
if (!(hmf = alloc_gdi_handle( &metaObj->header, OBJ_METAFILE, NULL )))
HeapFree( GetProcessHeap(), 0, metaObj );
return hmf;
}
/******************************************************************
* MF_GetMetaHeader
*
* Returns ptr to METAHEADER associated with HMETAFILE
*/
static METAHEADER *MF_GetMetaHeader( HMETAFILE hmf )
{
METAHEADER *ret = NULL;
METAFILEOBJ * metaObj = GDI_GetObjPtr( hmf, OBJ_METAFILE );
if (metaObj)
{
ret = metaObj->mh;
GDI_ReleaseObj( hmf );
}
return ret;
} }
/****************************************************************** /******************************************************************
...@@ -164,10 +134,9 @@ static POINT *convert_points( UINT count, const POINTS *pts ) ...@@ -164,10 +134,9 @@ static POINT *convert_points( UINT count, const POINTS *pts )
BOOL WINAPI DeleteMetaFile( HMETAFILE hmf ) BOOL WINAPI DeleteMetaFile( HMETAFILE hmf )
{ {
METAFILEOBJ * metaObj = free_gdi_handle( hmf ); METAHEADER *mh = free_gdi_handle( hmf );
if (!metaObj) return FALSE; if (!mh) return FALSE;
HeapFree( GetProcessHeap(), 0, metaObj->mh ); return HeapFree( GetProcessHeap(), 0, mh );
return HeapFree( GetProcessHeap(), 0, metaObj );
} }
/****************************************************************** /******************************************************************
...@@ -312,6 +281,24 @@ METAHEADER *MF_CreateMetaHeaderDisk(METAHEADER *mh, LPCVOID filename, BOOL uni ) ...@@ -312,6 +281,24 @@ METAHEADER *MF_CreateMetaHeaderDisk(METAHEADER *mh, LPCVOID filename, BOOL uni )
return mh; return mh;
} }
/* return a copy of the metafile bits, to be freed with HeapFree */
static METAHEADER *get_metafile_bits( HMETAFILE hmf )
{
METAHEADER *ret, *mh = GDI_GetObjPtr( hmf, OBJ_METAFILE );
if (!mh) return NULL;
if (mh->mtType != METAFILE_DISK)
{
ret = HeapAlloc( GetProcessHeap(), 0, mh->mtSize * 2 );
if (ret) memcpy( ret, mh, mh->mtSize * 2 );
}
else ret = MF_LoadDiskBasedMetaFile( mh );
GDI_ReleaseObj( hmf );
return ret;
}
/****************************************************************** /******************************************************************
* CopyMetaFileW (GDI32.@) * CopyMetaFileW (GDI32.@)
* *
...@@ -331,33 +318,25 @@ METAHEADER *MF_CreateMetaHeaderDisk(METAHEADER *mh, LPCVOID filename, BOOL uni ) ...@@ -331,33 +318,25 @@ METAHEADER *MF_CreateMetaHeaderDisk(METAHEADER *mh, LPCVOID filename, BOOL uni )
*/ */
HMETAFILE WINAPI CopyMetaFileW( HMETAFILE hSrcMetaFile, LPCWSTR lpFilename ) HMETAFILE WINAPI CopyMetaFileW( HMETAFILE hSrcMetaFile, LPCWSTR lpFilename )
{ {
METAHEADER *mh = MF_GetMetaHeader( hSrcMetaFile ); METAHEADER *mh = get_metafile_bits( hSrcMetaFile );
METAHEADER *mh2 = NULL;
HANDLE hFile; HANDLE hFile;
TRACE("(%p,%s)\n", hSrcMetaFile, debugstr_w(lpFilename)); TRACE("(%p,%s)\n", hSrcMetaFile, debugstr_w(lpFilename));
if(!mh) return 0; if(!mh) return 0;
if(mh->mtType == METAFILE_DISK)
mh2 = MF_LoadDiskBasedMetaFile(mh);
else {
mh2 = HeapAlloc( GetProcessHeap(), 0, mh->mtSize * 2 );
memcpy( mh2, mh, mh->mtSize * 2 );
}
if(lpFilename) { /* disk based metafile */ if(lpFilename) { /* disk based metafile */
DWORD w; DWORD w;
if((hFile = CreateFileW(lpFilename, GENERIC_WRITE, 0, NULL, if((hFile = CreateFileW(lpFilename, GENERIC_WRITE, 0, NULL,
CREATE_ALWAYS, 0, 0)) == INVALID_HANDLE_VALUE) { CREATE_ALWAYS, 0, 0)) == INVALID_HANDLE_VALUE) {
HeapFree( GetProcessHeap(), 0, mh2 ); HeapFree( GetProcessHeap(), 0, mh );
return 0; return 0;
} }
WriteFile(hFile, mh2, mh2->mtSize * 2, &w, NULL); WriteFile(hFile, mh, mh->mtSize * 2, &w, NULL);
CloseHandle(hFile); CloseHandle(hFile);
} }
return MF_Create_HMETAFILE( mh2 ); return MF_Create_HMETAFILE( mh );
} }
...@@ -380,14 +359,23 @@ HMETAFILE WINAPI CopyMetaFileA( HMETAFILE hSrcMetaFile, LPCSTR lpFilename ) ...@@ -380,14 +359,23 @@ HMETAFILE WINAPI CopyMetaFileA( HMETAFILE hSrcMetaFile, LPCSTR lpFilename )
return ret; return ret;
} }
/******************************************************************* /******************************************************************
* MF_PlayMetaFile * PlayMetaFile (GDI32.@)
*
* Renders the metafile specified by hmf in the DC specified by
* hdc. Returns FALSE on failure, TRUE on success.
*
* PARAMS
* hdc [I] handle of DC to render in
* hmf [I] handle of metafile to render
* *
* Helper for PlayMetaFile * RETURNS
* Success: TRUE
* Failure: FALSE
*/ */
static BOOL MF_PlayMetaFile( HDC hdc, METAHEADER *mh) BOOL WINAPI PlayMetaFile( HDC hdc, HMETAFILE hmf )
{ {
METAHEADER *mh = get_metafile_bits( hmf );
METARECORD *mr; METARECORD *mr;
HANDLETABLE *ht; HANDLETABLE *ht;
unsigned int offset = 0; unsigned int offset = 0;
...@@ -396,14 +384,8 @@ static BOOL MF_PlayMetaFile( HDC hdc, METAHEADER *mh) ...@@ -396,14 +384,8 @@ static BOOL MF_PlayMetaFile( HDC hdc, METAHEADER *mh)
HBRUSH hBrush; HBRUSH hBrush;
HPALETTE hPal; HPALETTE hPal;
HRGN hRgn; HRGN hRgn;
BOOL loaded = FALSE;
if (!mh) return FALSE; if (!mh) return FALSE;
if(mh->mtType == METAFILE_DISK) { /* Create a memory-based copy */
mh = MF_LoadDiskBasedMetaFile(mh);
if(!mh) return FALSE;
loaded = TRUE;
}
/* save DC */ /* save DC */
hPen = GetCurrentObject(hdc, OBJ_PEN); hPen = GetCurrentObject(hdc, OBJ_PEN);
...@@ -420,7 +402,11 @@ static BOOL MF_PlayMetaFile( HDC hdc, METAHEADER *mh) ...@@ -420,7 +402,11 @@ static BOOL MF_PlayMetaFile( HDC hdc, METAHEADER *mh)
/* create the handle table */ /* create the handle table */
ht = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY, ht = HeapAlloc( GetProcessHeap(), HEAP_ZERO_MEMORY,
sizeof(HANDLETABLE) * mh->mtNoObjects); sizeof(HANDLETABLE) * mh->mtNoObjects);
if(!ht) return FALSE; if(!ht)
{
HeapFree( GetProcessHeap(), 0, mh );
return FALSE;
}
/* loop through metafile playing records */ /* loop through metafile playing records */
offset = mh->mtHeaderSize * 2; offset = mh->mtHeaderSize * 2;
...@@ -455,34 +441,12 @@ static BOOL MF_PlayMetaFile( HDC hdc, METAHEADER *mh) ...@@ -455,34 +441,12 @@ static BOOL MF_PlayMetaFile( HDC hdc, METAHEADER *mh)
if(*(ht->objectHandle + i) != 0) if(*(ht->objectHandle + i) != 0)
DeleteObject(*(ht->objectHandle + i)); DeleteObject(*(ht->objectHandle + i));
/* free handle table */
HeapFree( GetProcessHeap(), 0, ht ); HeapFree( GetProcessHeap(), 0, ht );
if(loaded)
HeapFree( GetProcessHeap(), 0, mh ); HeapFree( GetProcessHeap(), 0, mh );
return TRUE; return TRUE;
} }
/****************************************************************** /******************************************************************
* PlayMetaFile (GDI32.@)
*
* Renders the metafile specified by hmf in the DC specified by
* hdc. Returns FALSE on failure, TRUE on success.
*
* PARAMS
* hdc [I] handle of DC to render in
* hmf [I] handle of metafile to render
*
* RETURNS
* Success: TRUE
* Failure: FALSE
*/
BOOL WINAPI PlayMetaFile( HDC hdc, HMETAFILE hmf )
{
METAHEADER *mh = MF_GetMetaHeader( hmf );
return MF_PlayMetaFile( hdc, mh );
}
/******************************************************************
* EnumMetaFile (GDI32.@) * EnumMetaFile (GDI32.@)
* *
* Loop through the metafile records in hmf, calling the user-specified * Loop through the metafile records in hmf, calling the user-specified
...@@ -495,7 +459,7 @@ BOOL WINAPI PlayMetaFile( HDC hdc, HMETAFILE hmf ) ...@@ -495,7 +459,7 @@ BOOL WINAPI PlayMetaFile( HDC hdc, HMETAFILE hmf )
*/ */
BOOL WINAPI EnumMetaFile(HDC hdc, HMETAFILE hmf, MFENUMPROC lpEnumFunc, LPARAM lpData) BOOL WINAPI EnumMetaFile(HDC hdc, HMETAFILE hmf, MFENUMPROC lpEnumFunc, LPARAM lpData)
{ {
METAHEADER *mhTemp = NULL, *mh = MF_GetMetaHeader(hmf); METAHEADER *mh = get_metafile_bits( hmf );
METARECORD *mr; METARECORD *mr;
HANDLETABLE *ht; HANDLETABLE *ht;
BOOL result = TRUE; BOOL result = TRUE;
...@@ -505,14 +469,9 @@ BOOL WINAPI EnumMetaFile(HDC hdc, HMETAFILE hmf, MFENUMPROC lpEnumFunc, LPARAM l ...@@ -505,14 +469,9 @@ BOOL WINAPI EnumMetaFile(HDC hdc, HMETAFILE hmf, MFENUMPROC lpEnumFunc, LPARAM l
HBRUSH hBrush; HBRUSH hBrush;
HFONT hFont; HFONT hFont;
TRACE("(%p,%p,%p,%p)\n", hdc, hmf, lpEnumFunc, (void*)lpData); TRACE("(%p,%p,%p,%lx)\n", hdc, hmf, lpEnumFunc, lpData);
if (!mh) return 0; if (!mh) return 0;
if(mh->mtType == METAFILE_DISK)
{
/* Create a memory-based copy */
if (!(mhTemp = MF_LoadDiskBasedMetaFile(mh))) return FALSE;
mh = mhTemp;
}
/* save the current pen, brush and font */ /* save the current pen, brush and font */
hPen = GetCurrentObject(hdc, OBJ_PEN); hPen = GetCurrentObject(hdc, OBJ_PEN);
...@@ -534,7 +493,7 @@ BOOL WINAPI EnumMetaFile(HDC hdc, HMETAFILE hmf, MFENUMPROC lpEnumFunc, LPARAM l ...@@ -534,7 +493,7 @@ BOOL WINAPI EnumMetaFile(HDC hdc, HMETAFILE hmf, MFENUMPROC lpEnumFunc, LPARAM l
} }
TRACE("Calling EnumFunc with record type %x\n", TRACE("Calling EnumFunc with record type %x\n",
mr->rdFunction); mr->rdFunction);
if (!lpEnumFunc( hdc, ht, mr, mh->mtNoObjects, (LONG)lpData )) if (!lpEnumFunc( hdc, ht, mr, mh->mtNoObjects, lpData ))
{ {
result = FALSE; result = FALSE;
break; break;
...@@ -553,10 +512,8 @@ BOOL WINAPI EnumMetaFile(HDC hdc, HMETAFILE hmf, MFENUMPROC lpEnumFunc, LPARAM l ...@@ -553,10 +512,8 @@ BOOL WINAPI EnumMetaFile(HDC hdc, HMETAFILE hmf, MFENUMPROC lpEnumFunc, LPARAM l
if(*(ht->objectHandle + i) != 0) if(*(ht->objectHandle + i) != 0)
DeleteObject(*(ht->objectHandle + i)); DeleteObject(*(ht->objectHandle + i));
/* free handle table */
HeapFree( GetProcessHeap(), 0, ht); HeapFree( GetProcessHeap(), 0, ht);
/* free a copy of metafile */ HeapFree( GetProcessHeap(), 0, mh);
HeapFree( GetProcessHeap(), 0, mhTemp );
return result; return result;
} }
...@@ -1129,7 +1086,7 @@ HMETAFILE WINAPI SetMetaFileBitsEx( UINT size, const BYTE *lpData ) ...@@ -1129,7 +1086,7 @@ HMETAFILE WINAPI SetMetaFileBitsEx( UINT size, const BYTE *lpData )
*/ */
UINT WINAPI GetMetaFileBitsEx( HMETAFILE hmf, UINT nSize, LPVOID buf ) UINT WINAPI GetMetaFileBitsEx( HMETAFILE hmf, UINT nSize, LPVOID buf )
{ {
METAHEADER *mh = MF_GetMetaHeader(hmf); METAHEADER *mh = GDI_GetObjPtr( hmf, OBJ_METAFILE );
UINT mfSize; UINT mfSize;
TRACE("(%p,%d,%p)\n", hmf, nSize, buf); TRACE("(%p,%d,%p)\n", hmf, nSize, buf);
...@@ -1137,12 +1094,13 @@ UINT WINAPI GetMetaFileBitsEx( HMETAFILE hmf, UINT nSize, LPVOID buf ) ...@@ -1137,12 +1094,13 @@ UINT WINAPI GetMetaFileBitsEx( HMETAFILE hmf, UINT nSize, LPVOID buf )
if(mh->mtType == METAFILE_DISK) if(mh->mtType == METAFILE_DISK)
FIXME("Disk-based metafile?\n"); FIXME("Disk-based metafile?\n");
mfSize = mh->mtSize * 2; mfSize = mh->mtSize * 2;
if (!buf) { if (buf)
TRACE("returning size %d\n", mfSize); {
return mfSize;
}
if(mfSize > nSize) mfSize = nSize; if(mfSize > nSize) mfSize = nSize;
memmove(buf, mh, mfSize); memmove(buf, mh, mfSize);
}
GDI_ReleaseObj( hmf );
TRACE("returning size %d\n", mfSize);
return mfSize; return mfSize;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment