gdiplus: Don't require an HDC for the convert_unit function.
authorVincent Povirk <vincent@codeweavers.com>
Sun, 8 Aug 2010 20:24:45 +0000 (15:24 -0500)
committerAlexandre Julliard <julliard@winehq.org>
Tue, 17 Aug 2010 09:55:33 +0000 (11:55 +0200)
dlls/gdiplus/gdiplus.c
dlls/gdiplus/gdiplus_private.h
dlls/gdiplus/graphics.c
dlls/gdiplus/image.c

index 383f53621fba8ca2a201c361aa3d8b0cb27758ec..9bb9fab10057518d47a6d1a270762ef0e6f82117 100644 (file)
@@ -314,18 +314,18 @@ GpStatus hresult_to_status(HRESULT res)
 }
 
 /* converts a given unit to its value in pixels */
-REAL convert_unit(HDC hdc, GpUnit unit)
+REAL convert_unit(REAL logpixels, GpUnit unit)
 {
     switch(unit)
     {
         case UnitInch:
-            return (REAL) GetDeviceCaps(hdc, LOGPIXELSX);
+            return logpixels;
         case UnitPoint:
-            return ((REAL)GetDeviceCaps(hdc, LOGPIXELSX)) / 72.0;
+            return logpixels / 72.0;
         case UnitDocument:
-            return ((REAL)GetDeviceCaps(hdc, LOGPIXELSX)) / 300.0;
+            return logpixels / 300.0;
         case UnitMillimeter:
-            return ((REAL)GetDeviceCaps(hdc, LOGPIXELSX)) / 25.4;
+            return logpixels / 25.4;
         case UnitWorld:
             ERR("cannot convert UnitWorld\n");
             return 0.0;
index eafed7c820e18cbcc5f6501f03264291a49de980..908a1b721c7faf6c3e8c946937d3002c648f9847 100644 (file)
@@ -47,7 +47,7 @@ extern INT arc2polybezier(GpPointF * points, REAL x1, REAL y1, REAL x2, REAL y2,
     REAL startAngle, REAL sweepAngle);
 extern REAL gdiplus_atan2(REAL dy, REAL dx);
 extern GpStatus hresult_to_status(HRESULT res);
-extern REAL convert_unit(HDC hdc, GpUnit unit);
+extern REAL convert_unit(REAL logpixels, GpUnit unit);
 
 extern void calc_curve_bezier(CONST GpPointF *pts, REAL tension, REAL *x1,
     REAL *y1, REAL *x2, REAL *y2);
index ada2c583952e746034bc4c131d5cdf5ab3a00d8b..094ed6167715964f97c06888a6fe5d7e8b42b4f3 100644 (file)
@@ -84,6 +84,12 @@ static BYTE convert_path_point_type(BYTE type)
     return ret;
 }
 
+static REAL graphics_res(GpGraphics *graphics)
+{
+    if (graphics->image) return graphics->image->xres;
+    else return (REAL)GetDeviceCaps(graphics->hdc, LOGPIXELSX);
+}
+
 static INT prepare_dc(GpGraphics *graphics, GpPen *pen)
 {
     HPEN gdipen;
@@ -108,7 +114,7 @@ static INT prepare_dc(GpGraphics *graphics, GpPen *pen)
         width = sqrt((pt[1].X - pt[0].X) * (pt[1].X - pt[0].X) +
                      (pt[1].Y - pt[0].Y) * (pt[1].Y - pt[0].Y)) / sqrt(2.0);
 
-        width *= pen->width * convert_unit(graphics->hdc,
+        width *= pen->width * convert_unit(graphics_res(graphics),
                               pen->unit == UnitWorld ? graphics->unit : pen->unit);
     }
 
@@ -156,7 +162,7 @@ static void transform_and_round_points(GpGraphics *graphics, POINT *pti,
     GpMatrix *matrix;
     int i;
 
-    unitscale = convert_unit(graphics->hdc, graphics->unit);
+    unitscale = convert_unit(graphics_res(graphics), graphics->unit);
 
     /* apply page scale */
     if(graphics->unit != UnitDisplay)
@@ -4602,7 +4608,7 @@ GpStatus WINGDIPAPI GdipTransformPoints(GpGraphics *graphics, GpCoordinateSpace
     stat = GdipCreateMatrix(&matrix);
     if (stat == Ok)
     {
-        unitscale = convert_unit(graphics->hdc, graphics->unit);
+        unitscale = convert_unit(graphics_res(graphics), graphics->unit);
 
         if(graphics->unit != UnitDisplay)
             unitscale *= graphics->scale;
index d72ae8d37755864d21b413418a8d2559175c3f4c..57c9f83161bd08fb4a6a3314d2a3e7bc7fdd1782 100644 (file)
@@ -2008,14 +2008,15 @@ GpStatus WINGDIPAPI GdipGetImageDimension(GpImage *image, REAL *width,
 
     if(image->type == ImageTypeMetafile){
         HDC hdc = GetDC(0);
+        REAL res = (REAL)GetDeviceCaps(hdc, LOGPIXELSX);
 
-        *height = convert_unit(hdc, ((GpMetafile*)image)->unit) *
+        ReleaseDC(0, hdc);
+
+        *height = convert_unit(res, ((GpMetafile*)image)->unit) *
                         ((GpMetafile*)image)->bounds.Height;
 
-        *width = convert_unit(hdc, ((GpMetafile*)image)->unit) *
+        *width = convert_unit(res, ((GpMetafile*)image)->unit) *
                         ((GpMetafile*)image)->bounds.Width;
-
-        ReleaseDC(0, hdc);
     }
 
     else if(image->type == ImageTypeBitmap){
@@ -2072,11 +2073,12 @@ GpStatus WINGDIPAPI GdipGetImageHeight(GpImage *image, UINT *height)
 
     if(image->type == ImageTypeMetafile){
         HDC hdc = GetDC(0);
-
-        *height = roundr(convert_unit(hdc, ((GpMetafile*)image)->unit) *
-                        ((GpMetafile*)image)->bounds.Height);
+        REAL res = (REAL)GetDeviceCaps(hdc, LOGPIXELSX);
 
         ReleaseDC(0, hdc);
+
+        *height = roundr(convert_unit(res, ((GpMetafile*)image)->unit) *
+                        ((GpMetafile*)image)->bounds.Height);
     }
     else if(image->type == ImageTypeBitmap)
         *height = ((GpBitmap*)image)->height;
@@ -2178,11 +2180,12 @@ GpStatus WINGDIPAPI GdipGetImageWidth(GpImage *image, UINT *width)
 
     if(image->type == ImageTypeMetafile){
         HDC hdc = GetDC(0);
-
-        *width = roundr(convert_unit(hdc, ((GpMetafile*)image)->unit) *
-                        ((GpMetafile*)image)->bounds.Width);
+        REAL res = (REAL)GetDeviceCaps(hdc, LOGPIXELSX);
 
         ReleaseDC(0, hdc);
+
+        *width = roundr(convert_unit(res, ((GpMetafile*)image)->unit) *
+                        ((GpMetafile*)image)->bounds.Width);
     }
     else if(image->type == ImageTypeBitmap)
         *width = ((GpBitmap*)image)->width;