gdi32: Delay writing metafile file until CloseMetaFile is called.

Signed-off-by: Jacek Caban <jacek@codeweavers.com>
Signed-off-by: Huw Davies <huw@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Jacek Caban 2021-06-29 13:41:41 +02:00 committed by Alexandre Julliard
parent d19ac108f9
commit 0c9bc0ed6b
2 changed files with 12 additions and 40 deletions

View File

@ -325,7 +325,6 @@ HDC WINAPI CreateMetaFileW( LPCWSTR filename )
DC *dc;
METAFILEDRV_PDEVICE *physDev;
HANDLE hFile;
DWORD bytes_written;
TRACE("%s\n", debugstr_w(filename) );
@ -340,12 +339,6 @@ HDC WINAPI CreateMetaFileW( LPCWSTR filename )
free_dc_ptr( dc );
return 0;
}
if (!WriteFile( hFile, physDev->mh, sizeof(*physDev->mh),
&bytes_written, NULL )) {
free_dc_ptr( dc );
CloseHandle (hFile );
return 0;
}
physDev->hFile = hFile;
/* Grow METAHEADER to include filename */
@ -422,19 +415,13 @@ static DC *MFDRV_CloseMetaFile( HDC hdc )
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 */
if (!WriteFile(physDev->hFile, physDev->mh, sizeof(*physDev->mh),
if (!WriteFile(physDev->hFile, physDev->mh, physDev->mh->mtSize * 2,
&bytes_written, NULL)) {
free_dc_ptr( dc );
return 0;
}
CloseHandle(physDev->hFile);
physDev->mh->mtType = METAFILE_DISK;
}
return dc;
@ -481,32 +468,19 @@ BOOL MFDRV_WriteRecord( PHYSDEV dev, METARECORD *mr, DWORD rlen)
METAHEADER *mh;
METAFILEDRV_PDEVICE *physDev = (METAFILEDRV_PDEVICE *)dev;
switch(physDev->mh->mtType)
len = physDev->mh->mtSize * 2 + rlen;
/* reallocate memory if needed */
size = HeapSize( GetProcessHeap(), 0, physDev->mh );
if (len > size)
{
case METAFILE_MEMORY:
len = physDev->mh->mtSize * 2 + rlen;
/* reallocate memory if needed */
size = HeapSize( GetProcessHeap(), 0, physDev->mh );
if (len > size)
{
/*expand size*/
size += size / 2 + rlen;
mh = HeapReAlloc( GetProcessHeap(), 0, physDev->mh, size);
if (!mh) return FALSE;
physDev->mh = mh;
TRACE("Reallocated metafile: new size is %d\n",size);
}
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;
/*expand size*/
size += size / 2 + rlen;
mh = HeapReAlloc( GetProcessHeap(), 0, physDev->mh, size);
if (!mh) return FALSE;
physDev->mh = mh;
TRACE("Reallocated metafile: new size is %d\n",size);
}
memcpy((WORD *)physDev->mh + physDev->mh->mtSize, mr, rlen);
physDev->mh->mtSize += rlen / 2;
physDev->mh->mtMaxRecord = max(physDev->mh->mtMaxRecord, rlen / 2);

View File

@ -3043,7 +3043,6 @@ static void test_metafile_file(void)
ok(file != INVALID_HANDLE_VALUE, "CreateFile failed: %u\n", GetLastError());
size = GetFileSize(file, NULL);
todo_wine
ok(!size, "size = %u\n", size);
ret = MoveToEx(dc, 1, 1, NULL);
@ -3056,7 +3055,6 @@ static void test_metafile_file(void)
ok( ret, "Ellipse error %d.\n", GetLastError());
size = GetFileSize(file, NULL);
todo_wine
ok(!size, "size = %u\n", size);
metafile = CloseMetaFile(dc);