From: Aric Stewart Subject: (try 3) gdi32: GetCharWidth32A/W return positive widths for all Layouts and various DC transforms Message-Id: <5230663D.8060904@codeweavers.com> Date: Wed, 11 Sep 2013 07:46:53 -0500 Fix viewport tests to use MM_ANISOTROPIC so that they actaully do something. --- dlls/gdi32/font.c | 6 ++- dlls/gdi32/tests/font.c | 108 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 113 insertions(+), 1 deletion(-) diff --git a/dlls/gdi32/font.c b/dlls/gdi32/font.c index fbea9f7..e941078 100644 --- a/dlls/gdi32/font.c +++ b/dlls/gdi32/font.c @@ -1748,9 +1748,13 @@ BOOL WINAPI GetCharWidth32W( HDC hdc, UINT firstChar, UINT lastChar, if (ret) { +#define WDPTOLP(x) ((x<0)? \ + (-abs(INTERNAL_XDSTOWS(dc, (x)))): \ + (abs(INTERNAL_XDSTOWS(dc, (x))))) /* convert device units to logical */ for( i = firstChar; i <= lastChar; i++, buffer++ ) - *buffer = INTERNAL_XDSTOWS(dc, *buffer); + *buffer = WDPTOLP(*buffer); +#undef WDPTOLP } release_dc_ptr( dc ); return ret; diff --git a/dlls/gdi32/tests/font.c b/dlls/gdi32/tests/font.c index 97156b5..176f5ce 100644 --- a/dlls/gdi32/tests/font.c +++ b/dlls/gdi32/tests/font.c @@ -42,6 +42,8 @@ static BOOL (WINAPI *pGetCharABCWidthsI)(HDC hdc, UINT first, UINT count, LPWOR static BOOL (WINAPI *pGetCharABCWidthsA)(HDC hdc, UINT first, UINT last, LPABC abc); static BOOL (WINAPI *pGetCharABCWidthsW)(HDC hdc, UINT first, UINT last, LPABC abc); static BOOL (WINAPI *pGetCharABCWidthsFloatW)(HDC hdc, UINT first, UINT last, LPABCFLOAT abc); +static BOOL (WINAPI *pGetCharWidth32A)(HDC hdc, UINT first, UINT last, LPINT buffer); +static BOOL (WINAPI *pGetCharWidth32W)(HDC hdc, UINT first, UINT last, LPINT buffer); static DWORD (WINAPI *pGetFontUnicodeRanges)(HDC hdc, LPGLYPHSET lpgs); static DWORD (WINAPI *pGetGlyphIndicesA)(HDC hdc, LPCSTR lpstr, INT count, LPWORD pgi, DWORD flags); static DWORD (WINAPI *pGetGlyphIndicesW)(HDC hdc, LPCWSTR lpstr, INT count, LPWORD pgi, DWORD flags); @@ -83,6 +85,8 @@ static void init(void) pGetCharABCWidthsA = (void *)GetProcAddress(hgdi32, "GetCharABCWidthsA"); pGetCharABCWidthsW = (void *)GetProcAddress(hgdi32, "GetCharABCWidthsW"); pGetCharABCWidthsFloatW = (void *)GetProcAddress(hgdi32, "GetCharABCWidthsFloatW"); + pGetCharWidth32A = (void *)GetProcAddress(hgdi32, "GetCharWidth32A"); + pGetCharWidth32W = (void *)GetProcAddress(hgdi32, "GetCharWidth32W"); pGetFontUnicodeRanges = (void *)GetProcAddress(hgdi32, "GetFontUnicodeRanges"); pGetGlyphIndicesA = (void *)GetProcAddress(hgdi32, "GetGlyphIndicesA"); pGetGlyphIndicesW = (void *)GetProcAddress(hgdi32, "GetGlyphIndicesW"); @@ -5440,6 +5444,109 @@ static void test_vertical_order(void) DeleteDC( hdc ); } +static void test_GetCharWidth32(void) +{ + BOOL ret; + HDC hdc; + LOGFONTA lf; + HFONT hfont; + INT bufferA; + INT bufferW; + HWND hwnd; + + if (!pGetCharWidth32A || !pGetCharWidth32W) + { + win_skip("GetCharWidth32A/W not available on this platform\n"); + return; + } + + memset(&lf, 0, sizeof(lf)); + strcpy(lf.lfFaceName, "System"); + lf.lfHeight = 20; + + hfont = CreateFontIndirectA(&lf); + hdc = GetDC(0); + hfont = SelectObject(hdc, hfont); + + ret = pGetCharWidth32W(hdc, 'a', 'a', &bufferW); + ok(ret, "GetCharWidth32W should have succeeded\n"); + ret = pGetCharWidth32A(hdc, 'a', 'a', &bufferA); + ok(ret, "GetCharWidth32A should have succeeded\n"); + ok (bufferA == bufferW, "Widths should be the same\n"); + ok (bufferA > 0," Width should be greater than zero\n"); + + hfont = SelectObject(hdc, hfont); + DeleteObject(hfont); + ReleaseDC(NULL, hdc); + + memset(&lf, 0, sizeof(lf)); + strcpy(lf.lfFaceName, "Tahoma"); + lf.lfHeight = 20; + + hfont = CreateFontIndirectA(&lf); + hwnd = CreateWindowEx(0, "static", "", WS_POPUP, 0,0,100,100, + 0, 0, 0, NULL); + hdc = GetDC(hwnd); + SetMapMode( hdc, MM_ANISOTROPIC ); + SelectObject(hdc, hfont); + + ret = pGetCharWidth32W(hdc, 'a', 'a', &bufferW); + ok(ret, "GetCharWidth32W should have succeeded\n"); + ok (bufferW > 0," Width should be greater than zero\n"); + SetWindowExtEx(hdc, -1,-1,NULL); + SetGraphicsMode(hdc, GM_COMPATIBLE); + ret = pGetCharWidth32W(hdc, 'a', 'a', &bufferW); + ok(ret, "GetCharWidth32W should have succeeded\n"); + ok (bufferW > 0," Width should be greater than zero\n"); + SetGraphicsMode(hdc, GM_ADVANCED); + ret = pGetCharWidth32W(hdc, 'a', 'a', &bufferW); + ok(ret, "GetCharWidth32W should have succeeded\n"); + todo_wine ok (bufferW > 0," Width should be greater than zero\n"); + SetWindowExtEx(hdc, 1,1,NULL); + SetGraphicsMode(hdc, GM_COMPATIBLE); + ret = pGetCharWidth32W(hdc, 'a', 'a', &bufferW); + ok(ret, "GetCharWidth32W should have succeeded\n"); + ok (bufferW > 0," Width should be greater than zero\n"); + SetGraphicsMode(hdc, GM_ADVANCED); + ret = pGetCharWidth32W(hdc, 'a', 'a', &bufferW); + ok(ret, "GetCharWidth32W should have succeeded\n"); + ok (bufferW > 0," Width should be greater than zero\n"); + + ReleaseDC(hwnd, hdc); + DestroyWindow(hwnd); + + hwnd = CreateWindowEx(WS_EX_LAYOUTRTL, "static", "", WS_POPUP, 0,0,100,100, + 0, 0, 0, NULL); + hdc = GetDC(hwnd); + SetMapMode( hdc, MM_ANISOTROPIC ); + SelectObject(hdc, hfont); + + ret = pGetCharWidth32W(hdc, 'a', 'a', &bufferW); + ok(ret, "GetCharWidth32W should have succeeded\n"); + ok (bufferW > 0," Width should be greater than zero\n"); + SetWindowExtEx(hdc, -1,-1,NULL); + SetGraphicsMode(hdc, GM_COMPATIBLE); + ret = pGetCharWidth32W(hdc, 'a', 'a', &bufferW); + ok(ret, "GetCharWidth32W should have succeeded\n"); + ok (bufferW > 0," Width should be greater than zero\n"); + SetGraphicsMode(hdc, GM_ADVANCED); + ret = pGetCharWidth32W(hdc, 'a', 'a', &bufferW); + ok(ret, "GetCharWidth32W should have succeeded\n"); + ok (bufferW > 0," Width should be greater than zero\n"); + SetWindowExtEx(hdc, 1,1,NULL); + SetGraphicsMode(hdc, GM_COMPATIBLE); + ret = pGetCharWidth32W(hdc, 'a', 'a', &bufferW); + ok(ret, "GetCharWidth32W should have succeeded\n"); + ok (bufferW > 0," Width should be greater than zero\n"); + SetGraphicsMode(hdc, GM_ADVANCED); + ret = pGetCharWidth32W(hdc, 'a', 'a', &bufferW); + ok(ret, "GetCharWidth32W should have succeeded\n"); + todo_wine ok (bufferW > 0," Width should be greater than zero\n"); + + ReleaseDC(hwnd, hdc); + DestroyWindow(hwnd); + DeleteObject(hfont); +} START_TEST(font) { @@ -5499,6 +5606,7 @@ START_TEST(font) test_east_asian_font_selection(); test_max_height(); test_vertical_order(); + test_GetCharWidth32(); /* These tests should be last test until RemoveFontResource * is properly implemented.