From 1d2860e54c26592e44f3f3c463f692aa3882f497 Mon Sep 17 00:00:00 2001 From: Huw Davies Date: Thu, 18 May 2017 11:07:07 +0100 Subject: [PATCH] ole32: Fix up the dib's resolution on loading. Signed-off-by: Huw Davies Signed-off-by: Alexandre Julliard --- dlls/ole32/datacache.c | 13 +++++++++++++ dlls/ole32/tests/ole2.c | 21 ++++++++++++++++++--- 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/dlls/ole32/datacache.c b/dlls/ole32/datacache.c index 0db55517f02..40d4ab8c230 100644 --- a/dlls/ole32/datacache.c +++ b/dlls/ole32/datacache.c @@ -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; diff --git a/dlls/ole32/tests/ole2.c b/dlls/ole32/tests/ole2.c index afff6baa5a6..65abb3e489c 100644 --- a/dlls/ole32/tests/ole2.c +++ b/dlls/ole32/tests/ole2.c @@ -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 ); + 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) { - ok( med.tymed == TYMED_HGLOBAL, "got %x\n", med.tymed ); - ReleaseStgMedium( &med ); + 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 );