Re: Implement GdiGetCharDimensions
Robert Shearman <rob(a)codeweavers.com> writes:
+LONG WINAPI GdiGetCharDimensions(HDC hdc, LPTEXTMETRICW lptm, LONG *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; +}
Again I think you should be using tmHeight instead of sz.cy for the height. Some fonts may well have characters larger than the alphabet ones, and the current behavior is always to use tmHeight. -- Alexandre Julliard julliard(a)winehq.org
On Mon, Jul 18, 2005 at 05:03:49PM +0200, Alexandre Julliard wrote:
Robert Shearman <rob(a)codeweavers.com> writes:
+LONG WINAPI GdiGetCharDimensions(HDC hdc, LPTEXTMETRICW lptm, LONG *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; +}
Again I think you should be using tmHeight instead of sz.cy for the height. Some fonts may well have characters larger than the alphabet ones, and the current behavior is always to use tmHeight.
Actually GetTextExtentPoint returns tm.tmHeight for cy, so there shouldn't be any difference. Huw. -- Huw Davies huw(a)codeweavers.com
Huw D M Davies <h.davies1(a)physics.ox.ac.uk> writes:
Actually GetTextExtentPoint returns tm.tmHeight for cy, so there shouldn't be any difference.
Ah right, in that case of course it makes no difference. But is that really the correct behavior for GetTextExtentPoint? -- Alexandre Julliard julliard(a)winehq.org
On Mon, Jul 18, 2005 at 05:24:42PM +0200, Alexandre Julliard wrote:
Huw D M Davies <h.davies1(a)physics.ox.ac.uk> writes:
Actually GetTextExtentPoint returns tm.tmHeight for cy, so there shouldn't be any difference.
Ah right, in that case of course it makes no difference. But is that really the correct behavior for GetTextExtentPoint?
Yup. Here's a test. Huw Davies <huw(a)codeweavers.com> Test to show that the height returned by GetTextExtentPoint is the same as tmHeight. -- Huw Davies huw(a)codeweavers.com Index: dlls/gdi/tests/gdiobj.c =================================================================== RCS file: /home/wine/wine/dlls/gdi/tests/gdiobj.c,v retrieving revision 1.6 diff -u -p -r1.6 gdiobj.c --- dlls/gdi/tests/gdiobj.c 20 May 2005 18:58:19 -0000 1.6 +++ dlls/gdi/tests/gdiobj.c 18 Jul 2005 15:41:06 -0000 @@ -266,9 +266,34 @@ static void test_gdi_objects(void) ReleaseDC(NULL, hdc); } +static void test_text_extents(void) +{ + LOGFONTA lf; + TEXTMETRICA tm; + HDC hdc; + HFONT hfont; + SIZE sz; + + memset(&lf, 0, sizeof(lf)); + strcpy(lf.lfFaceName, "Arial"); + lf.lfHeight = 20; + + hfont = CreateFontIndirectA(&lf); + hdc = GetDC(0); + hfont = SelectObject(hdc, hfont); + GetTextMetricsA(hdc, &tm); + GetTextExtentPointA(hdc, "o", 1, &sz); + ok(sz.cy == tm.tmHeight, "cy %ld tmHeight %ld\n", sz.cy, tm.tmHeight); + + SelectObject(hdc, hfont); + DeleteObject(hfont); + ReleaseDC(NULL, hdc); +} + START_TEST(gdiobj) { test_logfont(); test_bitmap_font(); test_gdi_objects(); + test_text_extents(); }
participants (2)
-
Alexandre Julliard -
Huw D M Davies