Vincent Povirk : gdiplus: Don' t require an HDC for the convert_unit function.

Alexandre Julliard julliard at winehq.org
Tue Aug 17 11:31:11 CDT 2010


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

Author: Vincent Povirk <vincent at codeweavers.com>
Date:   Sun Aug  8 15:24:45 2010 -0500

gdiplus: Don't require an HDC for the convert_unit function.

---

 dlls/gdiplus/gdiplus.c         |   10 +++++-----
 dlls/gdiplus/gdiplus_private.h |    2 +-
 dlls/gdiplus/graphics.c        |   12 +++++++++---
 dlls/gdiplus/image.c           |   23 +++++++++++++----------
 4 files changed, 28 insertions(+), 19 deletions(-)

diff --git a/dlls/gdiplus/gdiplus.c b/dlls/gdiplus/gdiplus.c
index 383f536..9bb9fab 100644
--- a/dlls/gdiplus/gdiplus.c
+++ b/dlls/gdiplus/gdiplus.c
@@ -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;
diff --git a/dlls/gdiplus/gdiplus_private.h b/dlls/gdiplus/gdiplus_private.h
index eafed7c..908a1b7 100644
--- a/dlls/gdiplus/gdiplus_private.h
+++ b/dlls/gdiplus/gdiplus_private.h
@@ -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);
diff --git a/dlls/gdiplus/graphics.c b/dlls/gdiplus/graphics.c
index ada2c58..094ed61 100644
--- a/dlls/gdiplus/graphics.c
+++ b/dlls/gdiplus/graphics.c
@@ -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;
diff --git a/dlls/gdiplus/image.c b/dlls/gdiplus/image.c
index d72ae8d..57c9f83 100644
--- a/dlls/gdiplus/image.c
+++ b/dlls/gdiplus/image.c
@@ -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;




More information about the wine-cvs mailing list