Dmitry Timoshkov : gdi32: ntmCellHeight and ntmAvgWidth should be in font units.

Alexandre Julliard julliard at winehq.org
Tue Apr 24 13:14:42 CDT 2012


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

Author: Dmitry Timoshkov <dmitry at baikal.ru>
Date:   Tue Apr 24 17:03:35 2012 +0900

gdi32: ntmCellHeight and ntmAvgWidth should be in font units.

---

 dlls/gdi32/freetype.c   |   13 ++++++++++---
 dlls/gdi32/tests/font.c |    8 ++++++++
 2 files changed, 18 insertions(+), 3 deletions(-)

diff --git a/dlls/gdi32/freetype.c b/dlls/gdi32/freetype.c
index 401cfd1..3de31f6 100644
--- a/dlls/gdi32/freetype.c
+++ b/dlls/gdi32/freetype.c
@@ -342,6 +342,7 @@ struct tagGdiFont {
     SHORT yMax;
     SHORT yMin;
     DWORD ntmFlags;
+    UINT ntmCellHeight, ntmAvgWidth;
     FONTSIGNATURE fs;
     GdiFont *base_font;
     VOID *GSUB_Table;
@@ -5070,6 +5071,8 @@ static void GetEnumStructs(Face *face, LPENUMLOGFONTEXW pelf,
         memcpy(&pntm->ntmTm, &font->potm->otmTextMetrics, sizeof(TEXTMETRICW));
 
         pntm->ntmTm.ntmSizeEM = font->potm->otmEMSquare;
+        pntm->ntmTm.ntmCellHeight = font->ntmCellHeight;
+        pntm->ntmTm.ntmAvgWidth = font->ntmAvgWidth;
 
         lstrcpynW(pelf->elfLogFont.lfFaceName,
                  (WCHAR*)((char*)font->potm + (ULONG_PTR)font->potm->otmpFamilyName),
@@ -5086,6 +5089,8 @@ static void GetEnumStructs(Face *face, LPENUMLOGFONTEXW pelf,
         get_text_metrics(font, (TEXTMETRICW *)&pntm->ntmTm);
 
         pntm->ntmTm.ntmSizeEM = pntm->ntmTm.tmHeight - pntm->ntmTm.tmInternalLeading;
+        pntm->ntmTm.ntmCellHeight = pntm->ntmTm.tmHeight;
+        pntm->ntmTm.ntmAvgWidth = pntm->ntmTm.tmAveCharWidth;
 
         lstrcpynW(pelf->elfLogFont.lfFaceName, face->family->FamilyName, LF_FACESIZE);
         if (face->FullName)
@@ -5096,8 +5101,6 @@ static void GetEnumStructs(Face *face, LPENUMLOGFONTEXW pelf,
     }
 
     pntm->ntmTm.ntmFlags = face->ntmFlags;
-    pntm->ntmTm.ntmCellHeight = pntm->ntmTm.tmHeight;
-    pntm->ntmTm.ntmAvgWidth = pntm->ntmTm.tmAveCharWidth;
     pntm->ntmFontSig = face->fs;
 
     pelf->elfScript[0] = '\0'; /* This will get set in WineEngEnumFonts */
@@ -6611,9 +6614,10 @@ static BOOL get_outline_text_metrics(GdiFont *font)
 
     pPost = pFT_Get_Sfnt_Table(ft_face, ft_sfnt_post); /* we can live with this failing */
 
-    TRACE("OS/2 winA = %d winD = %d typoA = %d typoD = %d typoLG = %d FT_Face a = %d, d = %d, h = %d: HORZ a = %d, d = %d lg = %d maxY = %ld minY = %ld\n",
+    TRACE("OS/2 winA = %d winD = %d typoA = %d typoD = %d typoLG = %d avgW %d FT_Face a = %d, d = %d, h = %d: HORZ a = %d, d = %d lg = %d maxY = %ld minY = %ld\n",
 	  pOS2->usWinAscent, pOS2->usWinDescent,
 	  pOS2->sTypoAscender, pOS2->sTypoDescender, pOS2->sTypoLineGap,
+	  pOS2->xAvgCharWidth,
 	  ft_face->ascender, ft_face->descender, ft_face->height,
 	  pHori->Ascender, pHori->Descender, pHori->Line_Gap,
 	  ft_face->bbox.yMax, ft_face->bbox.yMin);
@@ -6631,6 +6635,9 @@ static BOOL get_outline_text_metrics(GdiFont *font)
         descent = pOS2->usWinDescent;
     }
 
+    font->ntmCellHeight = ascent + descent;
+    font->ntmAvgWidth = pOS2->xAvgCharWidth;
+
     if(font->yMax) {
 	TM.tmAscent = font->yMax;
 	TM.tmDescent = -font->yMin;
diff --git a/dlls/gdi32/tests/font.c b/dlls/gdi32/tests/font.c
index bda8fc8..1708c49 100644
--- a/dlls/gdi32/tests/font.c
+++ b/dlls/gdi32/tests/font.c
@@ -2056,11 +2056,15 @@ struct enum_font_dataW
 static INT CALLBACK arial_enum_proc(const LOGFONT *lf, const TEXTMETRIC *tm, DWORD type, LPARAM lParam)
 {
     struct enum_font_data *efd = (struct enum_font_data *)lParam;
+    const NEWTEXTMETRIC *ntm = (const NEWTEXTMETRIC *)tm;
 
     ok(lf->lfHeight == tm->tmHeight, "lfHeight %d != tmHeight %d\n", lf->lfHeight, tm->tmHeight);
     ok(lf->lfHeight > 0 && lf->lfHeight < 200, "enumerated font height %d\n", lf->lfHeight);
 
     if (type != TRUETYPE_FONTTYPE) return 1;
+
+    ok(ntm->ntmCellHeight + ntm->ntmCellHeight/5 >= ntm->ntmSizeEM, "ntmCellHeight %d should be close to ntmSizeEM %d\n", ntm->ntmCellHeight, ntm->ntmSizeEM);
+
     if (0) /* Disabled to limit console spam */
         trace("enumed font \"%s\", charset %d, height %d, weight %d, italic %d\n",
               lf->lfFaceName, lf->lfCharSet, lf->lfHeight, lf->lfWeight, lf->lfItalic);
@@ -2075,11 +2079,15 @@ static INT CALLBACK arial_enum_proc(const LOGFONT *lf, const TEXTMETRIC *tm, DWO
 static INT CALLBACK arial_enum_procw(const LOGFONTW *lf, const TEXTMETRICW *tm, DWORD type, LPARAM lParam)
 {
     struct enum_font_dataW *efd = (struct enum_font_dataW *)lParam;
+    const NEWTEXTMETRICW *ntm = (const NEWTEXTMETRICW *)tm;
 
     ok(lf->lfHeight == tm->tmHeight, "lfHeight %d != tmHeight %d\n", lf->lfHeight, tm->tmHeight);
     ok(lf->lfHeight > 0 && lf->lfHeight < 200, "enumerated font height %d\n", lf->lfHeight);
 
     if (type != TRUETYPE_FONTTYPE) return 1;
+
+    ok(ntm->ntmCellHeight + ntm->ntmCellHeight/5 >= ntm->ntmSizeEM, "ntmCellHeight %d should be close to ntmSizeEM %d\n", ntm->ntmCellHeight, ntm->ntmSizeEM);
+
     if (0) /* Disabled to limit console spam */
         trace("enumed font %s, charset %d, height %d, weight %d, italic %d\n",
               wine_dbgstr_w(lf->lfFaceName), lf->lfCharSet, lf->lfHeight, lf->lfWeight, lf->lfItalic);




More information about the wine-cvs mailing list