gdiplus: Better implementation of GdipGetFontHeightGivenDPI.

Hans Leidekker hans at codeweavers.com
Fri Nov 28 10:30:48 CST 2008


diff --git a/dlls/gdiplus/font.c b/dlls/gdiplus/font.c
index ba2f1d8..2366823 100644
--- a/dlls/gdiplus/font.c
+++ b/dlls/gdiplus/font.c
@@ -153,6 +153,8 @@ GpStatus WINGDIPAPI GdipCreateFont(GDIPCONST GpFontFamily *fontFamily,
 
     (*font)->unit = unit;
     (*font)->emSize = emSize;
+    (*font)->height = tmw->ntmSizeEM;
+    (*font)->line_spacing = tmw->tmAscent + tmw->tmDescent + tmw->tmExternalLeading;
 
     return Ok;
 }
@@ -194,6 +196,9 @@ GpStatus WINGDIPAPI GdipCreateFontFromLogfontW(HDC hdc,
     (*font)->lfw.lfHeight = -textmet.tmHeight;
     (*font)->lfw.lfWeight = textmet.tmWeight;
 
+    (*font)->height = 1; /* FIXME: need NEWTEXTMETRIC.ntmSizeEM here */
+    (*font)->line_spacing = textmet.tmAscent + textmet.tmDescent + textmet.tmExternalLeading;
+
     SelectObject(hdc, oldfont);
     DeleteObject(hfont);
 
@@ -444,15 +449,31 @@ GpStatus WINGDIPAPI GdipGetFontHeight(GDIPCONST GpFont *font,
  */
 GpStatus WINGDIPAPI GdipGetFontHeightGivenDPI(GDIPCONST GpFont *font, REAL dpi, REAL *height)
 {
+    REAL font_height;
+
     TRACE("%p (%s), %f, %p\n", font,
             debugstr_w(font->lfw.lfFaceName), dpi, height);
 
     if (!(font && height)) return InvalidParameter;
 
+    font_height = font->line_spacing * (font->emSize / font->height);
+
     switch (font->unit)
     {
         case UnitPixel:
-            *height = font->emSize;
+            *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);
diff --git a/dlls/gdiplus/gdiplus_private.h b/dlls/gdiplus/gdiplus_private.h
index a279268..714739c 100644
--- a/dlls/gdiplus/gdiplus_private.h
+++ b/dlls/gdiplus/gdiplus_private.h
@@ -209,6 +209,8 @@ struct GpImageAttributes{
 struct GpFont{
     LOGFONTW lfw;
     REAL emSize;
+    UINT height;
+    LONG line_spacing;
     Unit unit;
 };
 



More information about the wine-patches mailing list