From a2f80d0873e9642a6120960cddec822f8cfa522c Mon Sep 17 00:00:00 2001 From: James Tabor Date: Mon, 25 Jul 2005 04:21:29 +0000 Subject: [PATCH] Patch by Robert Shearman rob@codeweavers.com, Use GdiGetCharDimensions Instead of DIALOG_GetCharSize. svn path=/trunk/; revision=16722 --- reactos/lib/gdi32/objects/font.c | 6 ++++++ reactos/lib/user32/include/user32.h | 1 + reactos/lib/user32/windows/dialog.c | 8 ++++++-- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/reactos/lib/gdi32/objects/font.c b/reactos/lib/gdi32/objects/font.c index 58108db0d25..f5e89a17325 100644 --- a/reactos/lib/gdi32/objects/font.c +++ b/reactos/lib/gdi32/objects/font.c @@ -806,6 +806,12 @@ RemoveFontResourceA( * * SEE ALSO * GetTextExtentPointW, GetTextMetricsW, MapDialogRect. + * + * Despite most of MSDN insisting that the horizontal base unit is + * tmAveCharWidth it isn't. Knowledge base article Q145994 + * "HOWTO: Calculate Dialog Units When Not Using the System Font", + * says that we should take the average of the 52 English upper and lower + * case characters. */ /* * @implemented diff --git a/reactos/lib/user32/include/user32.h b/reactos/lib/user32/include/user32.h index e21ec1194de..33c413a3bed 100644 --- a/reactos/lib/user32/include/user32.h +++ b/reactos/lib/user32/include/user32.h @@ -33,5 +33,6 @@ /* FIXME: FILIP */ HGDIOBJ STDCALL NtGdiSelectObject(HDC hDC, HGDIOBJ hGDIObj); +DWORD STDCALL GdiGetCharDimensions(HDC, LPTEXTMETRICW, DWORD *); #endif /* USER32_H */ diff --git a/reactos/lib/user32/windows/dialog.c b/reactos/lib/user32/windows/dialog.c index f29f8714405..b61d4926483 100644 --- a/reactos/lib/user32/windows/dialog.c +++ b/reactos/lib/user32/windows/dialog.c @@ -692,11 +692,14 @@ static HWND DIALOG_CreateIndirect( HINSTANCE hInst, LPCVOID dlgTemplate, if (dlgInfo->hUserFont) { SIZE charSize; - if (DIALOG_GetCharSize( dc, dlgInfo->hUserFont, &charSize )) + HFONT hOldFont = SelectObject( dc, dlgInfo->hUserFont ); + charSize.cx = GdiGetCharDimensions( dc, NULL, &charSize.cy ); + if (charSize.cx) { dlgInfo->xBaseUnit = charSize.cx; dlgInfo->yBaseUnit = charSize.cy; } + SelectObject( dc, hOldFont ); } ReleaseDC(0, dc); } @@ -1828,7 +1831,8 @@ GetDialogBaseUnits(VOID) if ((hdc = GetDC(0))) { - if (DIALOG_GetCharSize( hdc, 0, &size )) units = MAKELONG( size.cx, size.cy ); + size.cx = GdiGetCharDimensions( hdc, NULL, &size.cy ); + if (size.cx) units = MAKELONG( size.cx, size.cy ); ReleaseDC( 0, hdc ); } }