ole32: Correctly save the remaining formats if their data has not been set.

Signed-off-by: Huw Davies <huw@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Huw Davies 2017-12-14 13:17:38 +00:00 committed by Alexandre Julliard
parent 179daf67a8
commit 33be9fc78f
2 changed files with 68 additions and 45 deletions

View File

@ -829,17 +829,16 @@ static HRESULT save_dib(DataCacheEntry *entry, BOOL contents, IStream *stream)
if (hr == S_OK && data_size)
hr = IStream_Write(stream, bmi, data_size, NULL);
}
else
else if(data_size)
{
BITMAPFILEHEADER bmp_fhdr;
bmp_fhdr.bfType = 0x4d42;
bmp_fhdr.bfSize = data_size + sizeof(BITMAPFILEHEADER);
bmp_fhdr.bfReserved1 = bmp_fhdr.bfReserved2 = 0;
if (data_size)
bmp_fhdr.bfOffBits = bitmap_info_size(bmi, DIB_RGB_COLORS) + sizeof(BITMAPFILEHEADER);
bmp_fhdr.bfOffBits = bitmap_info_size(bmi, DIB_RGB_COLORS) + sizeof(BITMAPFILEHEADER);
hr = IStream_Write(stream, &bmp_fhdr, sizeof(BITMAPFILEHEADER), NULL);
if (hr == S_OK && data_size)
if (hr == S_OK)
hr = IStream_Write(stream, bmi, data_size, NULL);
}
@ -897,25 +896,22 @@ static HRESULT save_mfpict(DataCacheEntry *entry, BOOL contents, IStream *stream
hr = IStream_Write(stream, data, data_size, NULL);
HeapFree(GetProcessHeap(), 0, data);
}
else
else if (entry->stgmedium.tymed != TYMED_NULL)
{
struct meta_placeable meta_place_rec;
WORD *check;
if (entry->stgmedium.tymed != TYMED_NULL)
mfpict = GlobalLock(entry->stgmedium.u.hMetaFilePict);
if (!mfpict)
return DV_E_STGMEDIUM;
data_size = GetMetaFileBitsEx(mfpict->hMF, 0, NULL);
data = HeapAlloc(GetProcessHeap(), 0, data_size);
if (!data)
{
mfpict = GlobalLock(entry->stgmedium.u.hMetaFilePict);
if (!mfpict)
return DV_E_STGMEDIUM;
data_size = GetMetaFileBitsEx(mfpict->hMF, 0, NULL);
data = HeapAlloc(GetProcessHeap(), 0, data_size);
if (!data)
{
GlobalUnlock(entry->stgmedium.u.hMetaFilePict);
return E_OUTOFMEMORY;
}
GetMetaFileBitsEx(mfpict->hMF, data_size, data);
GlobalUnlock(entry->stgmedium.u.hMetaFilePict);
return E_OUTOFMEMORY;
}
GetMetaFileBitsEx(mfpict->hMF, data_size, data);
/* units are in 1/8th of a point (1 point is 1/72th of an inch) */
meta_place_rec.key = 0x9ac6cdd7;
@ -927,13 +923,12 @@ static HRESULT save_mfpict(DataCacheEntry *entry, BOOL contents, IStream *stream
meta_place_rec.bounding_box[3] = 0;
meta_place_rec.checksum = 0;
meta_place_rec.reserved = 0;
if (mfpict)
{
/* These values are rounded down so MulDiv won't do the right thing */
meta_place_rec.bounding_box[2] = (LONGLONG)mfpict->xExt * meta_place_rec.inch / 2540;
meta_place_rec.bounding_box[3] = (LONGLONG)mfpict->yExt * meta_place_rec.inch / 2540;
GlobalUnlock(entry->stgmedium.u.hMetaFilePict);
}
/* These values are rounded down so MulDiv won't do the right thing */
meta_place_rec.bounding_box[2] = (LONGLONG)mfpict->xExt * meta_place_rec.inch / 2540;
meta_place_rec.bounding_box[3] = (LONGLONG)mfpict->yExt * meta_place_rec.inch / 2540;
GlobalUnlock(entry->stgmedium.u.hMetaFilePict);
for (check = (WORD *)&meta_place_rec; check != (WORD *)&meta_place_rec.checksum; check++)
meta_place_rec.checksum ^= *check;
hr = IStream_Write(stream, &meta_place_rec, sizeof(struct meta_placeable), NULL);
@ -982,7 +977,7 @@ static HRESULT save_emf(DataCacheEntry *entry, BOOL contents, IStream *stream)
hr = IStream_Write(stream, data, data_size, NULL);
HeapFree(GetProcessHeap(), 0, data);
}
else
else if (entry->stgmedium.tymed != TYMED_NULL)
{
data_size = GetEnhMetaFileBits(entry->stgmedium.u.hEnhMetaFile, 0, NULL);
data = HeapAlloc(GetProcessHeap(), 0, sizeof(DWORD) + sizeof(ENHMETAHEADER) + data_size);
@ -991,8 +986,7 @@ static HRESULT save_emf(DataCacheEntry *entry, BOOL contents, IStream *stream)
GetEnhMetaFileBits(entry->stgmedium.u.hEnhMetaFile, data_size, data + sizeof(DWORD) + sizeof(ENHMETAHEADER));
memcpy(data + sizeof(DWORD), data + sizeof(DWORD) + sizeof(ENHMETAHEADER), sizeof(ENHMETAHEADER));
data_size += sizeof(DWORD) + sizeof(ENHMETAHEADER);
if (hr == S_OK && data_size)
hr = IStream_Write(stream, data, data_size, NULL);
hr = IStream_Write(stream, data, data_size, NULL);
HeapFree(GetProcessHeap(), 0, data);
}

View File

@ -4226,30 +4226,31 @@ static void test_data_cache_save_data(void)
{
{
{ CF_DIB, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL },
},
1, 1, &CLSID_WineTest,
{
&CLSID_WineTestOld, 1, { { "\2OlePres000", CF_DIB, DVASPECT_CONTENT, 0, NULL, 0 } }
}
},
{
{
{ CF_METAFILEPICT, 0, DVASPECT_CONTENT, -1, TYMED_MFPICT },
},
1, 1, &CLSID_WineTest,
{
&CLSID_WineTestOld, 1, { { "\2OlePres000", CF_METAFILEPICT, DVASPECT_CONTENT, 0, NULL, 0 } }
}
},
{
{
{ CF_ENHMETAFILE, 0, DVASPECT_CONTENT, -1, TYMED_ENHMF },
},
1, 1, &CLSID_WineTest,
3, 3, &CLSID_WineTest,
{
&CLSID_WineTestOld, 1, { { "\2OlePres000", CF_ENHMETAFILE, DVASPECT_CONTENT, 0, NULL, 0 } }
&CLSID_WineTestOld, 3, { { "\2OlePres000", CF_DIB, DVASPECT_CONTENT, 0, NULL, 0 },
{ "\2OlePres001", CF_METAFILEPICT, DVASPECT_CONTENT, 0, NULL, 0 },
{ "\2OlePres002", CF_ENHMETAFILE, DVASPECT_CONTENT, 0, NULL, 0 } }
}
},
/* without setting data */
{
{
{ CF_DIB, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL },
{ CF_METAFILEPICT, 0, DVASPECT_CONTENT, -1, TYMED_MFPICT },
{ CF_ENHMETAFILE, 0, DVASPECT_CONTENT, -1, TYMED_ENHMF },
},
3, 0, &CLSID_WineTest,
{
&CLSID_WineTestOld, 3, { { "\2OlePres000", CF_DIB, DVASPECT_CONTENT, 0, NULL, 0 },
{ "\2OlePres001", CF_METAFILEPICT, DVASPECT_CONTENT, 0, NULL, 0 },
{ "\2OlePres002", CF_ENHMETAFILE, DVASPECT_CONTENT, 0, NULL, 0 } }
}
},
/* static picture clsids */
{
{
{ CF_DIB, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL },
@ -4277,6 +4278,34 @@ static void test_data_cache_save_data(void)
&CLSID_WineTestOld, 1, { { "CONTENTS", -1, 0, 0, NULL, 0 } }
}
},
/* static picture clsids without setting any data */
{
{
{ CF_DIB, 0, DVASPECT_CONTENT, -1, TYMED_HGLOBAL },
},
1, 0, &CLSID_Picture_Dib,
{
&CLSID_WineTestOld, 1, { { "CONTENTS", -1, 0, 0, NULL, 0 } }
}
},
{
{
{ CF_METAFILEPICT, 0, DVASPECT_CONTENT, -1, TYMED_MFPICT },
},
1, 0, &CLSID_Picture_Metafile,
{
&CLSID_WineTestOld, 1, { { "CONTENTS", -1, 0, 0, NULL, 0 } }
}
},
{
{
{ CF_ENHMETAFILE, 0, DVASPECT_CONTENT, -1, TYMED_ENHMF },
},
1, 0, &CLSID_Picture_EnhMetafile,
{
&CLSID_WineTestOld, 1, { { "CONTENTS", -1, 0, 0, NULL, 0 } }
}
},
{
{
{ 0 }