Dmitry Timoshkov : gdiplus: Replace convert_unit() by a clearer units_to_pixels() helper.

Alexandre Julliard julliard at winehq.org
Wed Aug 15 14:08:34 CDT 2012


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

Author: Dmitry Timoshkov <dmitry at baikal.ru>
Date:   Wed Aug 15 12:04:52 2012 +0900

gdiplus: Replace convert_unit() by a clearer units_to_pixels() helper.

---

 dlls/gdiplus/gdiplus.c         |   23 -----------------------
 dlls/gdiplus/gdiplus_private.h |    1 -
 dlls/gdiplus/graphics.c        |   11 +++++------
 dlls/gdiplus/image.c           |   35 ++++++-----------------------------
 4 files changed, 11 insertions(+), 59 deletions(-)

diff --git a/dlls/gdiplus/gdiplus.c b/dlls/gdiplus/gdiplus.c
index 0146a0f..9ada462 100644
--- a/dlls/gdiplus/gdiplus.c
+++ b/dlls/gdiplus/gdiplus.c
@@ -320,29 +320,6 @@ GpStatus hresult_to_status(HRESULT res)
     }
 }
 
-/* converts a given unit to its value in inches */
-REAL convert_unit(REAL logpixels, GpUnit unit)
-{
-    switch(unit)
-    {
-        case UnitInch:
-            return logpixels;
-        case UnitPoint:
-            return logpixels / 72.0;
-        case UnitDocument:
-            return logpixels / 300.0;
-        case UnitMillimeter:
-            return logpixels / 25.4;
-        case UnitWorld:
-            ERR("cannot convert UnitWorld\n");
-            return 0.0;
-        case UnitPixel:
-        case UnitDisplay:
-        default:
-            return 1.0;
-    }
-}
-
 /* converts a given unit to its value in pixels */
 REAL units_to_pixels(REAL units, GpUnit unit, REAL dpi)
 {
diff --git a/dlls/gdiplus/gdiplus_private.h b/dlls/gdiplus/gdiplus_private.h
index ac070fe..fbc6772 100644
--- a/dlls/gdiplus/gdiplus_private.h
+++ b/dlls/gdiplus/gdiplus_private.h
@@ -48,7 +48,6 @@ extern INT arc2polybezier(GpPointF * points, REAL x1, REAL y1, REAL x2, REAL y2,
     REAL startAngle, REAL sweepAngle) DECLSPEC_HIDDEN;
 extern REAL gdiplus_atan2(REAL dy, REAL dx) DECLSPEC_HIDDEN;
 extern GpStatus hresult_to_status(HRESULT res) DECLSPEC_HIDDEN;
-extern REAL convert_unit(REAL logpixels, GpUnit unit) DECLSPEC_HIDDEN;
 extern REAL units_to_pixels(REAL units, GpUnit unit, REAL dpi) DECLSPEC_HIDDEN;
 extern REAL pixels_to_units(REAL pixels, GpUnit unit, REAL dpi) DECLSPEC_HIDDEN;
 extern REAL units_scale(GpUnit from, GpUnit to, REAL dpi) DECLSPEC_HIDDEN;
diff --git a/dlls/gdiplus/graphics.c b/dlls/gdiplus/graphics.c
index 16e1bc0..5c0ddf9 100644
--- a/dlls/gdiplus/graphics.c
+++ b/dlls/gdiplus/graphics.c
@@ -254,8 +254,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->xres,
-                              pen->unit == UnitWorld ? graphics->unit : pen->unit);
+        width *= units_to_pixels(pen->width, pen->unit == UnitWorld ? graphics->unit : pen->unit, graphics->xres);
     }
 
     if(pen->dash == DashStyleCustom){
@@ -311,8 +310,8 @@ static void transform_and_round_points(GpGraphics *graphics, POINT *pti,
     GpMatrix *matrix;
     int i;
 
-    scale_x = convert_unit(graphics->xres, graphics->unit);
-    scale_y = convert_unit(graphics->yres, graphics->unit);
+    scale_x = units_to_pixels(1.0, graphics->unit, graphics->xres);
+    scale_y = units_to_pixels(1.0, graphics->unit, graphics->yres);
 
     /* apply page scale */
     if(graphics->unit != UnitDisplay)
@@ -5990,8 +5989,8 @@ static GpStatus get_graphics_transform(GpGraphics *graphics, GpCoordinateSpace d
 
     if (dst_space != src_space && stat == Ok)
     {
-        scale_x = convert_unit(graphics->xres, graphics->unit);
-        scale_y = convert_unit(graphics->yres, graphics->unit);
+        scale_x = units_to_pixels(1.0, graphics->unit, graphics->xres);
+        scale_y = units_to_pixels(1.0, graphics->unit, graphics->yres);
 
         if(graphics->unit != UnitDisplay)
         {
diff --git a/dlls/gdiplus/image.c b/dlls/gdiplus/image.c
index f415a45..64ce8b6 100644
--- a/dlls/gdiplus/image.c
+++ b/dlls/gdiplus/image.c
@@ -2256,18 +2256,9 @@ GpStatus WINGDIPAPI GdipGetImageDimension(GpImage *image, REAL *width,
         return InvalidParameter;
 
     if(image->type == ImageTypeMetafile){
-        HDC hdc = GetDC(0);
-        REAL res = (REAL)GetDeviceCaps(hdc, LOGPIXELSX);
-
-        ReleaseDC(0, hdc);
-
-        *height = convert_unit(res, ((GpMetafile*)image)->unit) *
-                        ((GpMetafile*)image)->bounds.Height;
-
-        *width = convert_unit(res, ((GpMetafile*)image)->unit) *
-                        ((GpMetafile*)image)->bounds.Width;
+        *height = units_to_pixels(((GpMetafile*)image)->bounds.Height, ((GpMetafile*)image)->unit, image->yres);
+        *width = units_to_pixels(((GpMetafile*)image)->bounds.Width, ((GpMetafile*)image)->unit, image->xres);
     }
-
     else if(image->type == ImageTypeBitmap){
         *height = ((GpBitmap*)image)->height;
         *width = ((GpBitmap*)image)->width;
@@ -2326,15 +2317,8 @@ GpStatus WINGDIPAPI GdipGetImageHeight(GpImage *image, UINT *height)
     if(!image || !height)
         return InvalidParameter;
 
-    if(image->type == ImageTypeMetafile){
-        HDC hdc = GetDC(0);
-        REAL res = (REAL)GetDeviceCaps(hdc, LOGPIXELSX);
-
-        ReleaseDC(0, hdc);
-
-        *height = roundr(convert_unit(res, ((GpMetafile*)image)->unit) *
-                        ((GpMetafile*)image)->bounds.Height);
-    }
+    if(image->type == ImageTypeMetafile)
+        *height = units_to_pixels(((GpMetafile*)image)->bounds.Height, ((GpMetafile*)image)->unit, image->yres);
     else if(image->type == ImageTypeBitmap)
         *height = ((GpBitmap*)image)->height;
     else
@@ -2433,15 +2417,8 @@ GpStatus WINGDIPAPI GdipGetImageWidth(GpImage *image, UINT *width)
     if(!image || !width)
         return InvalidParameter;
 
-    if(image->type == ImageTypeMetafile){
-        HDC hdc = GetDC(0);
-        REAL res = (REAL)GetDeviceCaps(hdc, LOGPIXELSX);
-
-        ReleaseDC(0, hdc);
-
-        *width = roundr(convert_unit(res, ((GpMetafile*)image)->unit) *
-                        ((GpMetafile*)image)->bounds.Width);
-    }
+    if(image->type == ImageTypeMetafile)
+        *width = units_to_pixels(((GpMetafile*)image)->bounds.Width, ((GpMetafile*)image)->unit, image->xres);
     else if(image->type == ImageTypeBitmap)
         *width = ((GpBitmap*)image)->width;
     else




More information about the wine-cvs mailing list