From 8e78ac6a62764ba28b9134daabde07b328fa3bf7 Mon Sep 17 00:00:00 2001 From: James Tabor Date: Tue, 19 Jul 2005 11:18:40 +0000 Subject: [PATCH] Implement GdiGetCharDimensions by Robert Shearman rob@codeweavers.com. svn path=/trunk/; revision=16641 --- reactos/lib/gdi32/misc/stubs.c | 11 -------- reactos/lib/gdi32/objects/font.c | 46 ++++++++++++++++++++++++++++++++ reactos/lib/gdi32/objects/text.c | 2 ++ 3 files changed, 48 insertions(+), 11 deletions(-) diff --git a/reactos/lib/gdi32/misc/stubs.c b/reactos/lib/gdi32/misc/stubs.c index 48df0d06193..f083b4b45c9 100644 --- a/reactos/lib/gdi32/misc/stubs.c +++ b/reactos/lib/gdi32/misc/stubs.c @@ -2772,17 +2772,6 @@ GdiCreateLocalMetaFilePict(HENHMETAFILE hmo) return 0; } -/* - * @unimplemented - */ -DWORD -STDCALL -GdiGetCharDimensions(HDC hdc,LPTEXTMETRICW lptm,BOOL unk) -{ - UNIMPLEMENTED; - SetLastError(ERROR_CALL_NOT_IMPLEMENTED); - return 0; -} /* * @unimplemented diff --git a/reactos/lib/gdi32/objects/font.c b/reactos/lib/gdi32/objects/font.c index cb5f8bc755c..58108db0d25 100644 --- a/reactos/lib/gdi32/objects/font.c +++ b/reactos/lib/gdi32/objects/font.c @@ -782,3 +782,49 @@ RemoveFontResourceA( return rc; } + +/*********************************************************************** + * GdiGetCharDimensions + * + * Gets the average width of the characters in the English alphabet. + * + * PARAMS + * hdc [I] Handle to the device context to measure on. + * lptm [O] Pointer to memory to store the text metrics into. + * height [O] On exit, the maximum height of characters in the English alphabet. + * + * RETURNS + * The average width of characters in the English alphabet. + * + * NOTES + * This function is used by the dialog manager to get the size of a dialog + * unit. It should also be used by other pieces of code that need to know + * the size of a dialog unit in logical units without having access to the + * window handle of the dialog. + * Windows caches the font metrics from this function, but we don't and + * there doesn't appear to be an immediate advantage to do so. + * + * SEE ALSO + * GetTextExtentPointW, GetTextMetricsW, MapDialogRect. + */ +/* + * @implemented + */ +DWORD +STDCALL +GdiGetCharDimensions(HDC hdc, LPTEXTMETRICW lptm, DWORD *height) +{ + SIZE sz; + static const WCHAR alphabet[] = { + 'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q', + 'r','s','t','u','v','w','x','y','z','A','B','C','D','E','F','G','H', + 'I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z',0}; + + if(lptm && !GetTextMetricsW(hdc, lptm)) return 0; + + if(!GetTextExtentPointW(hdc, alphabet, 52, &sz)) return 0; + + if (height) *height = sz.cy; + return (sz.cx / 26 + 1) / 2; +} + diff --git a/reactos/lib/gdi32/objects/text.c b/reactos/lib/gdi32/objects/text.c index e1ecd1815eb..49678558cf0 100644 --- a/reactos/lib/gdi32/objects/text.c +++ b/reactos/lib/gdi32/objects/text.c @@ -309,3 +309,5 @@ GetTextFaceA( HDC hdc, INT count, LPSTR name ) HeapFree( GetProcessHeap(), 0, nameW ); return res; } + +