Dmitry Timoshkov : gdiplus: Factor out units_to_pixels() helper.

Alexandre Julliard julliard at winehq.org
Wed Jul 18 12:44:41 CDT 2012


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

Author: Dmitry Timoshkov <dmitry at baikal.ru>
Date:   Mon Jul 16 14:56:30 2012 +0900

gdiplus: Factor out units_to_pixels() helper.

---

 dlls/gdiplus/font.c            |   70 ++++------------------------------------
 dlls/gdiplus/gdiplus.c         |   26 +++++++++++++++
 dlls/gdiplus/gdiplus_private.h |    1 +
 3 files changed, 34 insertions(+), 63 deletions(-)

diff --git a/dlls/gdiplus/font.c b/dlls/gdiplus/font.c
index f4b75ef..26cd49d 100644
--- a/dlls/gdiplus/font.c
+++ b/dlls/gdiplus/font.c
@@ -118,41 +118,8 @@ typedef struct
 
 static GpStatus clone_font_family(const GpFontFamily *, GpFontFamily **);
 
-static const REAL mm_per_inch = 25.4;
-static const REAL inch_per_point = 1.0/72.0;
-
 static GpFontCollection installedFontCollection = {0};
 
-static LONG em_size_to_pixel(REAL em_size, Unit unit, LONG dpi)
-{
-    switch (unit)
-    {
-    default:
-        FIXME("Unhandled unit type: %d\n", unit);
-        return 0;
-
-    case UnitPixel:
-    case UnitWorld:
-        /* FIXME: Figure out when World != Pixel */
-        return em_size;
-    case UnitDisplay:
-        FIXME("Unknown behavior for UnitDisplay! Please report!\n");
-        /* FIXME: Figure out how this works...
-         * MSDN says that if "DISPLAY" is a monitor, then pixel should be
-         * used. That's not what I got. Tests on Windows revealed no output,
-         * and the tests in tests/font crash windows */
-        return 0;
-    case UnitPoint:
-        return em_size * dpi * inch_per_point;
-    case UnitInch:
-        return em_size * dpi;
-    case UnitDocument:
-        return em_size * dpi / 300.0; /* Per MSDN */
-    case UnitMillimeter:
-        return em_size * dpi / mm_per_inch;
-    }
-}
-
 /*******************************************************************************
  * GdipCreateFont [GDIPLUS.@]
  *
@@ -195,7 +162,7 @@ GpStatus WINGDIPAPI GdipCreateFont(GDIPCONST GpFontFamily *fontFamily,
     stat = GdipGetFamilyName(fontFamily, lfw.lfFaceName, LANG_NEUTRAL);
     if (stat != Ok) return stat;
 
-    lfw.lfHeight = -em_size_to_pixel(emSize, unit, fontFamily->dpi);
+    lfw.lfHeight = -units_to_pixels(emSize, unit, fontFamily->dpi);
     lfw.lfWeight = style & FontStyleBold ? FW_BOLD : FW_REGULAR;
     lfw.lfItalic = style & FontStyleItalic;
     lfw.lfUnderline = style & FontStyleUnderline;
@@ -483,7 +450,7 @@ GpStatus WINGDIPAPI GdipGetLogFontA(GpFont *font, GpGraphics *graphics,
 void get_log_fontW(const GpFont *font, GpGraphics *graphics, LOGFONTW *lf)
 {
     /* FIXME: use graphics */
-    lf->lfHeight = -em_size_to_pixel(font->emSize, font->unit, font->family->dpi);
+    lf->lfHeight = -units_to_pixels(font->emSize, font->unit, font->family->dpi);
     lf->lfWidth = 0;
     lf->lfEscapement = 0;
     lf->lfOrientation = 0;
@@ -590,47 +557,24 @@ GpStatus WINGDIPAPI GdipGetFontHeightGivenDPI(GDIPCONST GpFont *font, REAL dpi,
     GpStatus stat;
     INT style;
     UINT16 line_spacing, em_height;
-    REAL font_height, font_size;
+    REAL font_size;
 
     if (!font || !height) return InvalidParameter;
 
     TRACE("%p (%s), %f, %p\n", font,
             debugstr_w(font->family->FamilyName), dpi, height);
 
-    font_size = get_font_size(font);
+    font_size = units_to_pixels(get_font_size(font), font->unit, dpi);
     style = get_font_style(font);
     stat = GdipGetLineSpacing(font->family, style, &line_spacing);
     if (stat != Ok) return stat;
     stat = GdipGetEmHeight(font->family, style, &em_height);
     if (stat != Ok) return stat;
 
-    font_height = (REAL)line_spacing * font_size / (REAL)em_height;
-
-    switch (font->unit)
-    {
-        case UnitPixel:
-        case UnitWorld:
-            *height = font_height;
-            break;
-        case UnitPoint:
-            *height = font_height * dpi * inch_per_point;
-            break;
-        case UnitInch:
-            *height = font_height * dpi;
-            break;
-        case UnitDocument:
-            *height = font_height * (dpi / 300.0);
-            break;
-        case UnitMillimeter:
-            *height = font_height * (dpi / mm_per_inch);
-            break;
-        default:
-            FIXME("Unhandled unit type: %d\n", font->unit);
-            return NotImplemented;
-    }
+    *height = (REAL)line_spacing * font_size / (REAL)em_height;
 
-    TRACE("%s,%d(unit %d) => %f\n",
-          debugstr_w(font->family->FamilyName), font->otm.otmTextMetrics.tmHeight, font->unit, *height);
+    TRACE("%s,%d => %f\n",
+          debugstr_w(font->family->FamilyName), font->otm.otmTextMetrics.tmHeight, *height);
 
     return Ok;
 }
diff --git a/dlls/gdiplus/gdiplus.c b/dlls/gdiplus/gdiplus.c
index 11ae2d8..d27924b 100644
--- a/dlls/gdiplus/gdiplus.c
+++ b/dlls/gdiplus/gdiplus.c
@@ -35,6 +35,9 @@
 
 WINE_DEFAULT_DEBUG_CHANNEL(gdiplus);
 
+static const REAL mm_per_inch = 25.4;
+static const REAL inch_per_point = 1.0/72.0;
+
 static Status WINAPI NotificationHook(ULONG_PTR *token)
 {
     TRACE("%p\n", token);
@@ -340,6 +343,29 @@ REAL convert_unit(REAL logpixels, GpUnit unit)
     }
 }
 
+/* converts a given unit to its value in pixels */
+REAL units_to_pixels(REAL units, GpUnit unit, REAL dpi)
+{
+    switch (unit)
+    {
+    case UnitPixel:
+    case UnitWorld:
+    case UnitDisplay:
+        return units;
+    case UnitPoint:
+        return units * dpi * inch_per_point;
+    case UnitInch:
+        return units * dpi;
+    case UnitDocument:
+        return units * dpi / 300.0; /* Per MSDN */
+    case UnitMillimeter:
+        return units * dpi / mm_per_inch;
+    default:
+        FIXME("Unhandled unit type: %d\n", unit);
+        return 0;
+    }
+}
+
 /* Calculates Bezier points from cardinal spline points. */
 void calc_curve_bezier(CONST GpPointF *pts, REAL tension, REAL *x1,
     REAL *y1, REAL *x2, REAL *y2)
diff --git a/dlls/gdiplus/gdiplus_private.h b/dlls/gdiplus/gdiplus_private.h
index 03942c0..c1d19d2 100644
--- a/dlls/gdiplus/gdiplus_private.h
+++ b/dlls/gdiplus/gdiplus_private.h
@@ -49,6 +49,7 @@ extern INT arc2polybezier(GpPointF * points, REAL x1, REAL y1, REAL x2, REAL y2,
 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 GpStatus graphics_from_image(GpImage *image, GpGraphics **graphics) DECLSPEC_HIDDEN;
 




More information about the wine-cvs mailing list