ole32: Fix up the dib's resolution on loading.

Signed-off-by: Huw Davies <huw@codeweavers.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Huw Davies 2017-05-18 11:07:07 +01:00 committed by Alexandre Julliard
parent e7bb4ba269
commit 1d2860e54c
2 changed files with 31 additions and 3 deletions

View File

@ -635,6 +635,7 @@ static HRESULT load_dib( DataCacheEntry *cache_entry, IStream *stm )
HGLOBAL hglobal;
ULONG read, info_size, bi_size;
BITMAPFILEHEADER file;
BITMAPINFOHEADER *info;
if (cache_entry->stream_type != contents_stream)
{
@ -685,6 +686,18 @@ static HRESULT load_dib( DataCacheEntry *cache_entry, IStream *stm )
hr = IStream_Read( stm, (char *)dib + info_size, stat.cbSize.u.LowPart, &read );
if (hr != S_OK || read != stat.cbSize.QuadPart) goto fail;
if (bi_size >= sizeof(*info))
{
info = (BITMAPINFOHEADER *)dib;
if (info->biXPelsPerMeter == 0 || info->biYPelsPerMeter == 0)
{
HDC hdc = GetDC( 0 );
info->biXPelsPerMeter = MulDiv( GetDeviceCaps( hdc, LOGPIXELSX ), 10000, 254 );
info->biYPelsPerMeter = MulDiv( GetDeviceCaps( hdc, LOGPIXELSY ), 10000, 254 );
ReleaseDC( 0, hdc );
}
}
GlobalUnlock( hglobal );
cache_entry->data_cf = cache_entry->fmtetc.cfFormat;

View File

@ -1972,6 +1972,8 @@ static void test_data_cache_dib_contents_stream(int num)
STGMEDIUM med;
CLSID cls;
SIZEL sz;
BYTE *ptr;
BITMAPINFOHEADER expect_info;
hr = CreateDataCache( NULL, &CLSID_Picture_Metafile, &IID_IUnknown, (void **)&unk );
ok( SUCCEEDED(hr), "got %08x\n", hr );
@ -1994,11 +1996,24 @@ static void test_data_cache_dib_contents_stream(int num)
hr = IDataObject_GetData( data, &fmt, &med );
ok( SUCCEEDED(hr), "got %08x\n", hr );
if (SUCCEEDED(hr))
{
ok( med.tymed == TYMED_HGLOBAL, "got %x\n", med.tymed );
ReleaseStgMedium( &med );
ok( GlobalSize( U(med).hGlobal ) >= sizeof(dib) - sizeof(BITMAPFILEHEADER),
"got %lu\n", GlobalSize( U(med).hGlobal ) );
ptr = GlobalLock( U(med).hGlobal );
expect_info = *(BITMAPINFOHEADER *)(dib + sizeof(BITMAPFILEHEADER));
if (expect_info.biXPelsPerMeter == 0 || expect_info.biYPelsPerMeter == 0)
{
HDC hdc = GetDC( 0 );
expect_info.biXPelsPerMeter = MulDiv( GetDeviceCaps( hdc, LOGPIXELSX ), 10000, 254 );
expect_info.biYPelsPerMeter = MulDiv( GetDeviceCaps( hdc, LOGPIXELSY ), 10000, 254 );
ReleaseDC( 0, hdc );
}
ok( !memcmp( ptr, &expect_info, sizeof(expect_info) ), "mismatch\n" );
ok( !memcmp( ptr + sizeof(expect_info), dib + sizeof(BITMAPFILEHEADER) + sizeof(expect_info),
sizeof(dib) - sizeof(BITMAPFILEHEADER) - sizeof(expect_info) ), "mismatch\n" );
GlobalUnlock( U(med).hGlobal );
ReleaseStgMedium( &med );
hr = IViewObject2_GetExtent( view, DVASPECT_CONTENT, -1, NULL, &sz );
ok( SUCCEEDED(hr), "got %08x\n", hr );