Commit c359b4a0 authored by Jacek Caban's avatar Jacek Caban Committed by Alexandre Julliard

gdi32: Delay writing to enhanced metafile file until CreateEnhMetaFile is called.

parent 80aed7ca
...@@ -196,8 +196,7 @@ static BOOL CDECL EMFDRV_DeleteDC( PHYSDEV dev ) ...@@ -196,8 +196,7 @@ static BOOL CDECL EMFDRV_DeleteDC( PHYSDEV dev )
*/ */
BOOL EMFDRV_WriteRecord( PHYSDEV dev, EMR *emr ) BOOL EMFDRV_WriteRecord( PHYSDEV dev, EMR *emr )
{ {
DWORD len; DWORD len, size;
DWORD bytes_written;
ENHMETAHEADER *emh; ENHMETAHEADER *emh;
EMFDRV_PDEVICE *physDev = get_emf_physdev( dev ); EMFDRV_PDEVICE *physDev = get_emf_physdev( dev );
...@@ -209,21 +208,16 @@ BOOL EMFDRV_WriteRecord( PHYSDEV dev, EMR *emr ) ...@@ -209,21 +208,16 @@ BOOL EMFDRV_WriteRecord( PHYSDEV dev, EMR *emr )
physDev->emh->nBytes += emr->nSize; physDev->emh->nBytes += emr->nSize;
physDev->emh->nRecords++; physDev->emh->nRecords++;
if(physDev->hFile) { size = HeapSize(GetProcessHeap(), 0, physDev->emh);
if (!WriteFile(physDev->hFile, emr, emr->nSize, &bytes_written, NULL)) len = physDev->emh->nBytes;
return FALSE; if (len > size) {
} else { size += (size / 2) + emr->nSize;
DWORD nEmfSize = HeapSize(GetProcessHeap(), 0, physDev->emh); emh = HeapReAlloc(GetProcessHeap(), 0, physDev->emh, size);
len = physDev->emh->nBytes; if (!emh) return FALSE;
if (len > nEmfSize) { physDev->emh = emh;
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);
} }
memcpy((CHAR *)physDev->emh + physDev->emh->nBytes - emr->nSize, emr,
emr->nSize);
return TRUE; return TRUE;
} }
...@@ -337,7 +331,6 @@ HDC WINAPI CreateEnhMetaFileW( ...@@ -337,7 +331,6 @@ HDC WINAPI CreateEnhMetaFileW(
EMFDRV_PDEVICE *physDev; EMFDRV_PDEVICE *physDev;
HANDLE hFile; HANDLE hFile;
DWORD size = 0, length = 0; DWORD size = 0, length = 0;
DWORD bytes_written;
int cap; int cap;
TRACE("(%p %s %s %s)\n", hdc, debugstr_w(filename), wine_dbgstr_rect(rect), debugstr_w(description) ); TRACE("(%p %s %s %s)\n", hdc, debugstr_w(filename), wine_dbgstr_rect(rect), debugstr_w(description) );
...@@ -439,11 +432,6 @@ HDC WINAPI CreateEnhMetaFileW( ...@@ -439,11 +432,6 @@ HDC WINAPI CreateEnhMetaFileW(
free_dc_ptr( dc ); free_dc_ptr( dc );
return 0; return 0;
} }
if (!WriteFile( hFile, physDev->emh, size, &bytes_written, NULL )) {
free_dc_ptr( dc );
CloseHandle( hFile );
return 0;
}
physDev->hFile = hFile; physDev->hFile = hFile;
} }
...@@ -508,14 +496,7 @@ HENHMETAFILE WINAPI CloseEnhMetaFile(HDC hdc) /* [in] metafile DC */ ...@@ -508,14 +496,7 @@ HENHMETAFILE WINAPI CloseEnhMetaFile(HDC hdc) /* [in] metafile DC */
if (physDev->hFile) /* disk based metafile */ if (physDev->hFile) /* disk based metafile */
{ {
if (SetFilePointer(physDev->hFile, 0, NULL, FILE_BEGIN) != 0) if (!WriteFile(physDev->hFile, physDev->emh, physDev->emh->nBytes,
{
CloseHandle( physDev->hFile );
free_dc_ptr( dc );
return 0;
}
if (!WriteFile(physDev->hFile, physDev->emh, sizeof(*physDev->emh),
NULL, NULL)) NULL, NULL))
{ {
CloseHandle( physDev->hFile ); CloseHandle( physDev->hFile );
......
...@@ -3123,7 +3123,6 @@ static void test_enhmetafile_file(void) ...@@ -3123,7 +3123,6 @@ static void test_enhmetafile_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);
pts[0].x = pts[0].y = 10; pts[0].x = pts[0].y = 10;
...@@ -3142,7 +3141,6 @@ static void test_enhmetafile_file(void) ...@@ -3142,7 +3141,6 @@ static void test_enhmetafile_file(void)
ok( ret, "PolyBezierTo failed\n" ); ok( ret, "PolyBezierTo failed\n" );
size = GetFileSize(file, NULL); size = GetFileSize(file, NULL);
todo_wine
ok(!size, "size = %u\n", size); ok(!size, "size = %u\n", size);
metafile = CloseEnhMetaFile(dc); metafile = CloseEnhMetaFile(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