Alexandre Julliard : gdi32: Store the reference DC in the enhanced metafile and use it to retrieve device caps .

Alexandre Julliard julliard at winehq.org
Tue Apr 10 13:52:33 CDT 2012


Module: wine
Branch: master
Commit: 88bcd13d7f39fbb786d377de12716ef498f1bf80
URL:    http://source.winehq.org/git/wine.git/?a=commit;h=88bcd13d7f39fbb786d377de12716ef498f1bf80

Author: Alexandre Julliard <julliard at winehq.org>
Date:   Tue Apr 10 14:42:50 2012 +0200

gdi32: Store the reference DC in the enhanced metafile and use it to retrieve device caps.

---

 dlls/gdi32/enhmfdrv/dc.c             |   40 +---------------------------------
 dlls/gdi32/enhmfdrv/enhmetafiledrv.h |   11 +-------
 dlls/gdi32/enhmfdrv/init.c           |   35 ++++++++++-------------------
 dlls/gdi32/tests/dc.c                |   15 +++++++++---
 4 files changed, 26 insertions(+), 75 deletions(-)

diff --git a/dlls/gdi32/enhmfdrv/dc.c b/dlls/gdi32/enhmfdrv/dc.c
index 86ad961..817872c 100644
--- a/dlls/gdi32/enhmfdrv/dc.c
+++ b/dlls/gdi32/enhmfdrv/dc.c
@@ -515,43 +515,5 @@ INT EMFDRV_GetDeviceCaps(PHYSDEV dev, INT cap)
 {
     EMFDRV_PDEVICE *physDev = (EMFDRV_PDEVICE*) dev;
 
-    switch(cap) {
-
-    case HORZRES:
-        return physDev->horzres;
-    case VERTRES:
-        return physDev->vertres;
-    case LOGPIXELSX:
-        return physDev->logpixelsx;
-    case LOGPIXELSY:
-        return physDev->logpixelsy;
-    case HORZSIZE:
-        return physDev->horzsize;
-    case VERTSIZE:
-        return physDev->vertsize;
-    case BITSPIXEL:
-        return physDev->bitspixel;
-    case TEXTCAPS:
-        return physDev->textcaps;
-    case RASTERCAPS:
-        return physDev->rastercaps;
-    case TECHNOLOGY:
-        return physDev->technology;
-    case PLANES:
-        return physDev->planes;
-    case NUMCOLORS:
-        return physDev->numcolors;
-    case CURVECAPS:
-        return (CC_CIRCLES | CC_PIE | CC_CHORD | CC_ELLIPSES | CC_WIDE |
-                CC_STYLED | CC_WIDESTYLED | CC_INTERIORS | CC_ROUNDRECT);
-    case LINECAPS:
-        return (LC_POLYLINE | LC_MARKER | LC_POLYMARKER | LC_WIDE |
-                LC_STYLED | LC_WIDESTYLED | LC_INTERIORS);
-    case POLYGONALCAPS:
-        return (PC_POLYGON | PC_RECTANGLE | PC_WINDPOLYGON | PC_SCANLINE |
-                PC_WIDE | PC_STYLED | PC_WIDESTYLED | PC_INTERIORS);
-    default:
-        FIXME("Unimplemented cap %d\n", cap);
-	return 0;
-    }
+    return GetDeviceCaps( physDev->ref_dc, cap );
 }
diff --git a/dlls/gdi32/enhmfdrv/enhmetafiledrv.h b/dlls/gdi32/enhmfdrv/enhmetafiledrv.h
index 53d69bc..03bb829 100644
--- a/dlls/gdi32/enhmfdrv/enhmetafiledrv.h
+++ b/dlls/gdi32/enhmfdrv/enhmetafiledrv.h
@@ -39,15 +39,8 @@ typedef struct
     HANDLE     hFile;              /* Handle for disk based MetaFile */
     HBRUSH     dc_brush;
     HPEN       dc_pen;
-    INT        horzres, vertres;
-    INT        horzsize, vertsize;
-    INT        logpixelsx, logpixelsy;
-    INT        bitspixel;
-    INT        textcaps;
-    INT        rastercaps;
-    INT        technology;
-    INT        planes;
-    INT        numcolors;
+    HDC        ref_dc;             /* Reference device */
+    HDC        screen_dc;          /* Screen DC if no reference device specified */
     INT        restoring;          /* RestoreDC counter */
 } EMFDRV_PDEVICE;
 
diff --git a/dlls/gdi32/enhmfdrv/init.c b/dlls/gdi32/enhmfdrv/init.c
index d254cba..883ca5a 100644
--- a/dlls/gdi32/enhmfdrv/init.c
+++ b/dlls/gdi32/enhmfdrv/init.c
@@ -317,8 +317,6 @@ HDC WINAPI CreateEnhMetaFileW(
     static const WCHAR displayW[] = {'D','I','S','P','L','A','Y',0};
     HDC ret;
     DC *dc;
-    HDC hRefDC = hdc ? hdc : CreateDCW(displayW,NULL,NULL,NULL); 
-        /* If no ref, use current display */
     EMFDRV_PDEVICE *physDev;
     HANDLE hFile;
     DWORD size = 0, length = 0;
@@ -354,19 +352,12 @@ HDC WINAPI CreateEnhMetaFileW(
     physDev->hFile = 0;
     physDev->dc_brush = 0;
     physDev->dc_pen = 0;
-    physDev->horzres = GetDeviceCaps(hRefDC, HORZRES);
-    physDev->vertres = GetDeviceCaps(hRefDC, VERTRES);
-    physDev->logpixelsx = GetDeviceCaps(hRefDC, LOGPIXELSX);
-    physDev->logpixelsy = GetDeviceCaps(hRefDC, LOGPIXELSY);
-    physDev->horzsize = GetDeviceCaps(hRefDC, HORZSIZE);
-    physDev->vertsize = GetDeviceCaps(hRefDC, VERTSIZE);
-    physDev->bitspixel = GetDeviceCaps(hRefDC, BITSPIXEL);
-    physDev->textcaps = GetDeviceCaps(hRefDC, TEXTCAPS);
-    physDev->rastercaps = GetDeviceCaps(hRefDC, RASTERCAPS);
-    physDev->technology = GetDeviceCaps(hRefDC, TECHNOLOGY);
-    physDev->planes = GetDeviceCaps(hRefDC, PLANES);
-    physDev->numcolors = GetDeviceCaps(hRefDC, NUMCOLORS);
+    physDev->screen_dc = 0;
     physDev->restoring = 0;
+    if (hdc)  /* if no ref, use current display */
+        physDev->ref_dc = hdc;
+    else
+        physDev->ref_dc = physDev->screen_dc = CreateDCW( displayW, NULL, NULL, NULL );
 
     SetVirtualResolution(physDev->dev.hdc, 0, 0, 0, 0);
 
@@ -400,16 +391,16 @@ HDC WINAPI CreateEnhMetaFileW(
     physDev->emh->nPalEntries = 0; /* I guess this should start at 0 */
 
     /* Size in pixels */
-    physDev->emh->szlDevice.cx = physDev->horzres;
-    physDev->emh->szlDevice.cy = physDev->vertres;
+    physDev->emh->szlDevice.cx = GetDeviceCaps( physDev->ref_dc, HORZRES );
+    physDev->emh->szlDevice.cy = GetDeviceCaps( physDev->ref_dc, VERTRES );
 
     /* Size in millimeters */
-    physDev->emh->szlMillimeters.cx = physDev->horzsize;
-    physDev->emh->szlMillimeters.cy = physDev->vertsize;
+    physDev->emh->szlMillimeters.cx = GetDeviceCaps( physDev->ref_dc, HORZSIZE );
+    physDev->emh->szlMillimeters.cy = GetDeviceCaps( physDev->ref_dc, VERTSIZE );
 
     /* Size in micrometers */
-    physDev->emh->szlMicrometers.cx = physDev->horzsize * 1000;
-    physDev->emh->szlMicrometers.cy = physDev->vertsize * 1000;
+    physDev->emh->szlMicrometers.cx = physDev->emh->szlMillimeters.cx * 1000;
+    physDev->emh->szlMicrometers.cy = physDev->emh->szlMillimeters.cy * 1000;
 
     memcpy((char *)physDev->emh + sizeof(ENHMETAHEADER), description, length);
 
@@ -431,9 +422,6 @@ HDC WINAPI CreateEnhMetaFileW(
     ret = physDev->dev.hdc;
     release_dc_ptr( dc );
 
-    if( !hdc )
-      DeleteDC( hRefDC );
-
     return ret;
 }
 
@@ -469,6 +457,7 @@ HENHMETAFILE WINAPI CloseEnhMetaFile(HDC hdc) /* [in] metafile DC */
 
     if (physDev->dc_brush) DeleteObject( physDev->dc_brush );
     if (physDev->dc_pen) DeleteObject( physDev->dc_pen );
+    if (physDev->screen_dc) DeleteDC( physDev->screen_dc );
 
     emr.emr.iType = EMR_EOF;
     emr.emr.nSize = sizeof(emr);
diff --git a/dlls/gdi32/tests/dc.c b/dlls/gdi32/tests/dc.c
index 5536abf..324e65b 100644
--- a/dlls/gdi32/tests/dc.c
+++ b/dlls/gdi32/tests/dc.c
@@ -383,7 +383,10 @@ static void test_device_caps( HDC hdc, HDC ref_dc, const char *descr )
         ok( GetLastError() == ERROR_INVALID_PARAMETER || broken(GetLastError() == 0xdeadbeef), /* nt4 */
             "wrong error %u on %s\n", GetLastError(), descr );
         type = GetClipBox( hdc, &rect );
-        ok( type == SIMPLEREGION, "GetClipBox returned %d on memdc for %s\n", type, descr );
+        if (GetObjectType( hdc ) == OBJ_ENHMETADC)
+            todo_wine ok( type == SIMPLEREGION, "GetClipBox returned %d on memdc for %s\n", type, descr );
+        else
+            ok( type == SIMPLEREGION, "GetClipBox returned %d on memdc for %s\n", type, descr );
 
         SetBoundsRect( hdc, NULL, DCB_RESET | DCB_ENABLE );
         SetMapMode( hdc, MM_TEXT );
@@ -494,8 +497,7 @@ static void test_CreateCompatibleDC(void)
     ok( SelectObject( hNewDC, bitmap ) != 0, "SelectObject failed\n" );
     caps = GetDeviceCaps( hdcMetafile, TECHNOLOGY );
     ok( caps == DT_RASDISPLAY, "wrong caps %u\n", caps );
-    caps = GetDeviceCaps( hNewDC, TECHNOLOGY );
-    ok( caps == DT_RASDISPLAY, "wrong caps %u\n", caps );
+    test_device_caps( hdcMetafile, hdc, "enhmetafile dc" );
     DeleteDC( hNewDC );
     DeleteEnhMetaFile( CloseEnhMetaFile( hdcMetafile ));
     ReleaseDC( 0, hdc );
@@ -1144,7 +1146,7 @@ done:
 
 static void test_printer_dc(void)
 {
-    HDC memdc, display_memdc;
+    HDC memdc, display_memdc, enhmf_dc;
     HBITMAP orig, bmp;
     DWORD ret;
     HDC hdc = create_printer_dc();
@@ -1188,6 +1190,11 @@ static void test_printer_dc(void)
     ret = GetPixel( hdc, 0, 0 );
     ok( ret == CLR_INVALID, "wrong pixel value %x\n", ret );
 
+    enhmf_dc = CreateEnhMetaFileA( hdc, NULL, NULL, NULL );
+    ok(enhmf_dc != 0, "CreateEnhMetaFileA failed\n");
+    test_device_caps( enhmf_dc, hdc, "enhmetafile printer dc" );
+    DeleteEnhMetaFile( CloseEnhMetaFile( enhmf_dc ));
+
     DeleteDC( memdc );
     DeleteDC( display_memdc );
     DeleteDC( hdc );




More information about the wine-cvs mailing list