Commit 0c9bc0ed authored by Jacek Caban's avatar Jacek Caban Committed by Alexandre Julliard

gdi32: Delay writing metafile file until CloseMetaFile is called.

parent d19ac108
...@@ -325,7 +325,6 @@ HDC WINAPI CreateMetaFileW( LPCWSTR filename ) ...@@ -325,7 +325,6 @@ HDC WINAPI CreateMetaFileW( LPCWSTR filename )
DC *dc; DC *dc;
METAFILEDRV_PDEVICE *physDev; METAFILEDRV_PDEVICE *physDev;
HANDLE hFile; HANDLE hFile;
DWORD bytes_written;
TRACE("%s\n", debugstr_w(filename) ); TRACE("%s\n", debugstr_w(filename) );
...@@ -340,12 +339,6 @@ HDC WINAPI CreateMetaFileW( LPCWSTR filename ) ...@@ -340,12 +339,6 @@ HDC WINAPI CreateMetaFileW( LPCWSTR filename )
free_dc_ptr( dc ); free_dc_ptr( dc );
return 0; return 0;
} }
if (!WriteFile( hFile, physDev->mh, sizeof(*physDev->mh),
&bytes_written, NULL )) {
free_dc_ptr( dc );
CloseHandle (hFile );
return 0;
}
physDev->hFile = hFile; physDev->hFile = hFile;
/* Grow METAHEADER to include filename */ /* Grow METAHEADER to include filename */
...@@ -422,19 +415,13 @@ static DC *MFDRV_CloseMetaFile( HDC hdc ) ...@@ -422,19 +415,13 @@ static DC *MFDRV_CloseMetaFile( HDC hdc )
if (physDev->mh->mtType == METAFILE_DISK) /* disk based metafile */ if (physDev->mh->mtType == METAFILE_DISK) /* disk based metafile */
{ {
if (SetFilePointer(physDev->hFile, 0, NULL, FILE_BEGIN) != 0) {
free_dc_ptr( dc );
return 0;
}
physDev->mh->mtType = METAFILE_MEMORY; /* This is what windows does */ physDev->mh->mtType = METAFILE_MEMORY; /* This is what windows does */
if (!WriteFile(physDev->hFile, physDev->mh, sizeof(*physDev->mh), if (!WriteFile(physDev->hFile, physDev->mh, physDev->mh->mtSize * 2,
&bytes_written, NULL)) { &bytes_written, NULL)) {
free_dc_ptr( dc ); free_dc_ptr( dc );
return 0; return 0;
} }
CloseHandle(physDev->hFile); CloseHandle(physDev->hFile);
physDev->mh->mtType = METAFILE_DISK;
} }
return dc; return dc;
...@@ -481,9 +468,6 @@ BOOL MFDRV_WriteRecord( PHYSDEV dev, METARECORD *mr, DWORD rlen) ...@@ -481,9 +468,6 @@ BOOL MFDRV_WriteRecord( PHYSDEV dev, METARECORD *mr, DWORD rlen)
METAHEADER *mh; METAHEADER *mh;
METAFILEDRV_PDEVICE *physDev = (METAFILEDRV_PDEVICE *)dev; METAFILEDRV_PDEVICE *physDev = (METAFILEDRV_PDEVICE *)dev;
switch(physDev->mh->mtType)
{
case METAFILE_MEMORY:
len = physDev->mh->mtSize * 2 + rlen; len = physDev->mh->mtSize * 2 + rlen;
/* reallocate memory if needed */ /* reallocate memory if needed */
size = HeapSize( GetProcessHeap(), 0, physDev->mh ); size = HeapSize( GetProcessHeap(), 0, physDev->mh );
...@@ -497,16 +481,6 @@ BOOL MFDRV_WriteRecord( PHYSDEV dev, METARECORD *mr, DWORD rlen) ...@@ -497,16 +481,6 @@ BOOL MFDRV_WriteRecord( PHYSDEV dev, METARECORD *mr, DWORD rlen)
TRACE("Reallocated metafile: new size is %d\n",size); TRACE("Reallocated metafile: new size is %d\n",size);
} }
memcpy((WORD *)physDev->mh + physDev->mh->mtSize, mr, rlen); memcpy((WORD *)physDev->mh + physDev->mh->mtSize, mr, rlen);
break;
case METAFILE_DISK:
TRACE("Writing record to disk\n");
if (!WriteFile(physDev->hFile, mr, rlen, NULL, NULL))
return FALSE;
break;
default:
ERR("Unknown metafile type %d\n", physDev->mh->mtType );
return FALSE;
}
physDev->mh->mtSize += rlen / 2; physDev->mh->mtSize += rlen / 2;
physDev->mh->mtMaxRecord = max(physDev->mh->mtMaxRecord, rlen / 2); physDev->mh->mtMaxRecord = max(physDev->mh->mtMaxRecord, rlen / 2);
......
...@@ -3043,7 +3043,6 @@ static void test_metafile_file(void) ...@@ -3043,7 +3043,6 @@ static void test_metafile_file(void)
ok(file != INVALID_HANDLE_VALUE, "CreateFile failed: %u\n", GetLastError()); ok(file != INVALID_HANDLE_VALUE, "CreateFile failed: %u\n", GetLastError());
size = GetFileSize(file, NULL); size = GetFileSize(file, NULL);
todo_wine
ok(!size, "size = %u\n", size); ok(!size, "size = %u\n", size);
ret = MoveToEx(dc, 1, 1, NULL); ret = MoveToEx(dc, 1, 1, NULL);
...@@ -3056,7 +3055,6 @@ static void test_metafile_file(void) ...@@ -3056,7 +3055,6 @@ static void test_metafile_file(void)
ok( ret, "Ellipse error %d.\n", GetLastError()); ok( ret, "Ellipse error %d.\n", GetLastError());
size = GetFileSize(file, NULL); size = GetFileSize(file, NULL);
todo_wine
ok(!size, "size = %u\n", size); ok(!size, "size = %u\n", size);
metafile = CloseMetaFile(dc); metafile = CloseMetaFile(dc);
......
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