From e6c0642e7907445c85993606117cbe91a9904fbb Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Tue, 24 Jul 2001 22:15:47 +0000 Subject: [PATCH] Removed enhmetafile.h. Simplified ENHMETAFILEOBJ structure a bit. --- graphics/enhmetafiledrv/init.c | 16 +++++++------ include/enhmetafile.h | 28 ----------------------- include/gdi.h | 3 +++ objects/enhmetafile.c | 42 +++++++++++++++++++--------------- 4 files changed, 35 insertions(+), 54 deletions(-) delete mode 100644 include/enhmetafile.h diff --git a/graphics/enhmetafiledrv/init.c b/graphics/enhmetafiledrv/init.c index 7e8892afda4..d5750db2cdd 100644 --- a/graphics/enhmetafiledrv/init.c +++ b/graphics/enhmetafiledrv/init.c @@ -10,7 +10,6 @@ #include "wingdi.h" #include "gdi.h" #include "heap.h" -#include "enhmetafile.h" #include "enhmetafiledrv.h" #include "debugtools.h" @@ -378,13 +377,17 @@ HENHMETAFILE WINAPI CloseEnhMetaFile(HDC hdc) /* [in] metafile DC */ if (physDev->hFile) /* disk based metafile */ { - if (SetFilePointer(physDev->hFile, 0, NULL, FILE_BEGIN) != 0) { + if (SetFilePointer(physDev->hFile, 0, NULL, FILE_BEGIN) != 0) + { + CloseHandle( physDev->hFile ); EMFDRV_DeleteDC( dc ); return 0; } if (!WriteFile(physDev->hFile, (LPSTR)physDev->emh, - sizeof(*physDev->emh), NULL, NULL)) { + sizeof(*physDev->emh), NULL, NULL)) + { + CloseHandle( physDev->hFile ); EMFDRV_DeleteDC( dc ); return 0; } @@ -394,13 +397,12 @@ HENHMETAFILE WINAPI CloseEnhMetaFile(HDC hdc) /* [in] metafile DC */ TRACE("hMapping = %08x\n", hMapping ); physDev->emh = MapViewOfFile(hMapping, FILE_MAP_READ, 0, 0, 0); TRACE("view = %p\n", physDev->emh ); + CloseHandle( hMapping ); + CloseHandle( physDev->hFile ); } - - hmf = EMF_Create_HENHMETAFILE( physDev->emh, physDev->hFile, hMapping ); + hmf = EMF_Create_HENHMETAFILE( physDev->emh, (physDev->hFile != 0) ); physDev->emh = NULL; /* So it won't be deleted */ EMFDRV_DeleteDC( dc ); return hmf; } - - diff --git a/include/enhmetafile.h b/include/enhmetafile.h deleted file mode 100644 index 616241bb224..00000000000 --- a/include/enhmetafile.h +++ /dev/null @@ -1,28 +0,0 @@ -/* - * Enhanced Metafile definitions - * - */ - -#ifndef __WINE_ENHMETAFILE_H -#define __WINE_ENHMETAFILE_H - -#include "gdi.h" -#include "windef.h" -#include "wingdi.h" - - /* GDI32 enhanced metafile object */ -typedef struct -{ - GDIOBJHDR header; - ENHMETAHEADER *emh; - HFILE hFile; /* File handle if EMF is disk-based */ - HANDLE hMapping; /* Mapping handle if EMF is disk-based */ -} ENHMETAFILEOBJ; - - -extern HENHMETAFILE EMF_Create_HENHMETAFILE(ENHMETAHEADER *emh, HFILE hFile, - HANDLE hMapping); - - -#endif /* __WINE_ENHMETAFILE_H */ - diff --git a/include/gdi.h b/include/gdi.h index 3ce380bbae9..2938ebe927e 100644 --- a/include/gdi.h +++ b/include/gdi.h @@ -589,4 +589,7 @@ INT CLIPPING_IntersectVisRect( DC * dc, INT left, INT top, INT right, INT bottom, BOOL exclude ); extern void CLIPPING_UpdateGCRegion( DC * dc ); +/* objects/enhmetafile.c */ +extern HENHMETAFILE EMF_Create_HENHMETAFILE(ENHMETAHEADER *emh, BOOL on_disk ); + #endif /* __WINE_GDI_H */ diff --git a/objects/enhmetafile.c b/objects/enhmetafile.c index 852eae18fd3..7443a6ac804 100644 --- a/objects/enhmetafile.c +++ b/objects/enhmetafile.c @@ -22,27 +22,31 @@ #include "winbase.h" #include "wingdi.h" #include "winerror.h" -#include "enhmetafile.h" #include "debugtools.h" -#include "heap.h" #include "metafile.h" DEFAULT_DEBUG_CHANNEL(enhmetafile); +typedef struct +{ + GDIOBJHDR header; + ENHMETAHEADER *emh; + BOOL on_disk; /* true if metafile is on disk */ +} ENHMETAFILEOBJ; + + /**************************************************************************** * EMF_Create_HENHMETAFILE */ -HENHMETAFILE EMF_Create_HENHMETAFILE(ENHMETAHEADER *emh, HFILE hFile, HANDLE - hMapping ) +HENHMETAFILE EMF_Create_HENHMETAFILE(ENHMETAHEADER *emh, BOOL on_disk ) { HENHMETAFILE hmf = 0; ENHMETAFILEOBJ *metaObj = GDI_AllocObject( sizeof(ENHMETAFILEOBJ), ENHMETAFILE_MAGIC, &hmf ); if (metaObj) { - metaObj->emh = emh; - metaObj->hFile = hFile; - metaObj->hMapping = hMapping; + metaObj->emh = emh; + metaObj->on_disk = on_disk; GDI_ReleaseObj( hmf ); } return hmf; @@ -56,11 +60,10 @@ static BOOL EMF_Delete_HENHMETAFILE( HENHMETAFILE hmf ) ENHMETAFILEOBJ *metaObj = (ENHMETAFILEOBJ *)GDI_GetObjPtr( hmf, ENHMETAFILE_MAGIC ); if(!metaObj) return FALSE; - if(metaObj->hMapping) { + + if(metaObj->on_disk) UnmapViewOfFile( metaObj->emh ); - CloseHandle( metaObj->hMapping ); - CloseHandle( metaObj->hFile ); - } else + else HeapFree( GetProcessHeap(), 0, metaObj->emh ); return GDI_FreeObject( hmf, metaObj ); } @@ -100,15 +103,17 @@ static HENHMETAFILE EMF_GetEnhMetaFile( HANDLE hFile ) hMapping = CreateFileMappingA( hFile, NULL, PAGE_READONLY, 0, 0, NULL ); emh = MapViewOfFile( hMapping, FILE_MAP_READ, 0, 0, 0 ); + CloseHandle( hMapping ); + + if (!emh) return 0; if (emh->iType != EMR_HEADER || emh->dSignature != ENHMETA_SIGNATURE) { WARN("Invalid emf header type 0x%08lx sig 0x%08lx.\n", emh->iType, emh->dSignature); UnmapViewOfFile( emh ); - CloseHandle( hMapping ); return 0; } - return EMF_Create_HENHMETAFILE( emh, hFile, hMapping ); + return EMF_Create_HENHMETAFILE( emh, TRUE ); } @@ -131,8 +136,7 @@ HENHMETAFILE WINAPI GetEnhMetaFileA( return 0; } hmf = EMF_GetEnhMetaFile( hFile ); - if(!hmf) - CloseHandle( hFile ); + CloseHandle( hFile ); return hmf; } @@ -152,8 +156,7 @@ HENHMETAFILE WINAPI GetEnhMetaFileW( return 0; } hmf = EMF_GetEnhMetaFile( hFile ); - if(!hmf) - CloseHandle( hFile ); + CloseHandle( hFile ); return hmf; } @@ -261,7 +264,7 @@ HENHMETAFILE WINAPI SetEnhMetaFileBits(UINT bufsize, const BYTE *buf) { ENHMETAHEADER *emh = HeapAlloc( GetProcessHeap(), 0, bufsize ); memmove(emh, buf, bufsize); - return EMF_Create_HENHMETAFILE( emh, 0, 0 ); + return EMF_Create_HENHMETAFILE( emh, FALSE ); } /***************************************************************************** @@ -1701,13 +1704,14 @@ HENHMETAFILE WINAPI CopyEnhMetaFileA( if (!file) { emrDst = HeapAlloc( GetProcessHeap(), 0, emrSrc->nBytes ); memcpy( emrDst, emrSrc, emrSrc->nBytes ); - hmfDst = EMF_Create_HENHMETAFILE( emrDst, 0, 0 ); + hmfDst = EMF_Create_HENHMETAFILE( emrDst, FALSE ); } else { HANDLE hFile; hFile = CreateFileA( file, GENERIC_WRITE | GENERIC_READ, 0, NULL, CREATE_ALWAYS, 0, 0); WriteFile( hFile, emrSrc, emrSrc->nBytes, 0, 0); hmfDst = EMF_GetEnhMetaFile( hFile ); + CloseHandle( hFile ); } EMF_ReleaseEnhMetaHeader( hmfSrc ); return hmfDst;