gdi32: Delay writing to enhanced metafile file until CreateEnhMetaFile 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:42:09 +02:00 committed by Alexandre Julliard
parent 80aed7cae6
commit c359b4a0e9
2 changed files with 11 additions and 32 deletions

View File

@ -196,8 +196,7 @@ static BOOL CDECL EMFDRV_DeleteDC( PHYSDEV dev )
*/
BOOL EMFDRV_WriteRecord( PHYSDEV dev, EMR *emr )
{
DWORD len;
DWORD bytes_written;
DWORD len, size;
ENHMETAHEADER *emh;
EMFDRV_PDEVICE *physDev = get_emf_physdev( dev );
@ -209,21 +208,16 @@ BOOL EMFDRV_WriteRecord( PHYSDEV dev, EMR *emr )
physDev->emh->nBytes += emr->nSize;
physDev->emh->nRecords++;
if(physDev->hFile) {
if (!WriteFile(physDev->hFile, emr, emr->nSize, &bytes_written, NULL))
return FALSE;
} else {
DWORD nEmfSize = HeapSize(GetProcessHeap(), 0, physDev->emh);
len = physDev->emh->nBytes;
if (len > nEmfSize) {
nEmfSize += (nEmfSize / 2) + emr->nSize;
emh = HeapReAlloc(GetProcessHeap(), 0, physDev->emh, nEmfSize);
if (!emh) return FALSE;
physDev->emh = emh;
}
memcpy((CHAR *)physDev->emh + physDev->emh->nBytes - emr->nSize, emr,
emr->nSize);
size = HeapSize(GetProcessHeap(), 0, physDev->emh);
len = physDev->emh->nBytes;
if (len > size) {
size += (size / 2) + emr->nSize;
emh = HeapReAlloc(GetProcessHeap(), 0, physDev->emh, size);
if (!emh) return FALSE;
physDev->emh = emh;
}
memcpy((CHAR *)physDev->emh + physDev->emh->nBytes - emr->nSize, emr,
emr->nSize);
return TRUE;
}
@ -337,7 +331,6 @@ HDC WINAPI CreateEnhMetaFileW(
EMFDRV_PDEVICE *physDev;
HANDLE hFile;
DWORD size = 0, length = 0;
DWORD bytes_written;
int cap;
TRACE("(%p %s %s %s)\n", hdc, debugstr_w(filename), wine_dbgstr_rect(rect), debugstr_w(description) );
@ -439,11 +432,6 @@ HDC WINAPI CreateEnhMetaFileW(
free_dc_ptr( dc );
return 0;
}
if (!WriteFile( hFile, physDev->emh, size, &bytes_written, NULL )) {
free_dc_ptr( dc );
CloseHandle( hFile );
return 0;
}
physDev->hFile = hFile;
}
@ -508,14 +496,7 @@ HENHMETAFILE WINAPI CloseEnhMetaFile(HDC hdc) /* [in] metafile DC */
if (physDev->hFile) /* disk based metafile */
{
if (SetFilePointer(physDev->hFile, 0, NULL, FILE_BEGIN) != 0)
{
CloseHandle( physDev->hFile );
free_dc_ptr( dc );
return 0;
}
if (!WriteFile(physDev->hFile, physDev->emh, sizeof(*physDev->emh),
if (!WriteFile(physDev->hFile, physDev->emh, physDev->emh->nBytes,
NULL, NULL))
{
CloseHandle( physDev->hFile );

View File

@ -3123,7 +3123,6 @@ static void test_enhmetafile_file(void)
ok(file != INVALID_HANDLE_VALUE, "CreateFile failed: %u\n", GetLastError());
size = GetFileSize(file, NULL);
todo_wine
ok(!size, "size = %u\n", size);
pts[0].x = pts[0].y = 10;
@ -3142,7 +3141,6 @@ static void test_enhmetafile_file(void)
ok( ret, "PolyBezierTo failed\n" );
size = GetFileSize(file, NULL);
todo_wine
ok(!size, "size = %u\n", size);
metafile = CloseEnhMetaFile(dc);