user32/tests: Use calculated WM_SETFONT margins in the CJK case.

Signed-off-by: Akihiro Sagawa <sagawa.aki@gmail.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
stable
Akihiro Sagawa 2019-04-18 23:51:01 +09:00 committed by Alexandre Julliard
parent 6b2c2d39bb
commit c8c29eebc7
1 changed files with 44 additions and 8 deletions

View File

@ -1559,6 +1559,28 @@ static INT get_cjk_fontinfo_margin(INT width, INT side_bearing)
return margin;
}
static DWORD get_cjk_font_margins(HDC hdc, BOOL unicode)
{
ABC abc[256];
SHORT left, right;
UINT i;
left = right = 0;
if (unicode) {
if (!GetCharABCWidthsW(hdc, 0, 255, abc))
return 0;
}
else {
if (!GetCharABCWidthsA(hdc, 0, 255, abc))
return 0;
}
for (i = 0; i < ARRAY_SIZE(abc); i++) {
if (-abc[i].abcA > right) right = -abc[i].abcA;
if (-abc[i].abcC > left) left = -abc[i].abcC;
}
return MAKELONG(left, right);
}
static void test_margins_default(const char* facename, UINT charset)
{
HWND hwnd;
@ -1569,7 +1591,7 @@ static void test_margins_default(const char* facename, UINT charset)
LOGFONTA lf;
HFONT hfont;
RECT rect;
INT margins, expect;
INT margins, expect, font_expect;
const UINT small_margins = MAKELONG(1, 5);
const WCHAR EditW[] = {'E','d','i','t',0}, strW[] = {'W',0};
struct char_width_info {
@ -1615,9 +1637,14 @@ static void test_margins_default(const char* facename, UINT charset)
left = get_cjk_fontinfo_margin(size.cx, info.lsb);
right = get_cjk_fontinfo_margin(size.cx, info.rsb);
expect = MAKELONG(left, right);
font_expect = get_cjk_font_margins(hdc, TRUE);
if (!font_expect)
/* In this case, margins aren't updated */
font_expect = small_margins;
}
else
expect = MAKELONG(size.cx / 2, size.cx / 2);
font_expect = expect = MAKELONG(size.cx / 2, size.cx / 2);
hfont = SelectObject(hdc, hfont);
ReleaseDC(hwnd, hdc);
@ -1627,12 +1654,11 @@ static void test_margins_default(const char* facename, UINT charset)
SendMessageA(hwnd, EM_SETMARGINS, EC_LEFTMARGIN | EC_RIGHTMARGIN, small_margins);
SendMessageA(hwnd, WM_SETFONT, (WPARAM)hfont, MAKELPARAM(TRUE, 0));
margins = SendMessageA(hwnd, EM_GETMARGINS, 0, 0);
if (!cjk_charset)
ok(margins == expect, "%s:%d: got %d, %d\n", facename, charset, HIWORD(margins), LOWORD(margins));
todo_wine_if(cjk_charset)
ok(margins == font_expect, "%s:%d: expected %d, %d, got %d, %d\n", facename, charset, HIWORD(font_expect), LOWORD(font_expect), HIWORD(margins), LOWORD(margins));
SendMessageA(hwnd, EM_SETMARGINS, EC_LEFTMARGIN | EC_RIGHTMARGIN, small_margins);
SendMessageA(hwnd, EM_SETMARGINS, EC_LEFTMARGIN | EC_RIGHTMARGIN, MAKELONG(EC_USEFONTINFO, EC_USEFONTINFO));
margins = SendMessageA(hwnd, EM_GETMARGINS, 0, 0);
ok(margins == expect, "%s:%d: expected %d, %d, got %d, %d\n", facename, charset, HIWORD(expect), LOWORD(expect), HIWORD(margins), LOWORD(margins));
DestroyWindow(hwnd);
@ -1642,17 +1668,27 @@ static void test_margins_default(const char* facename, UINT charset)
GetClientRect(hwnd, &rect);
ok(!IsRectEmpty(&rect), "got rect %s\n", wine_dbgstr_rect(&rect));
if (cjk_charset) {
hdc = GetDC(hwnd);
hfont = SelectObject(hdc, hfont);
font_expect = get_cjk_font_margins(hdc, FALSE);
if (!font_expect)
/* In this case, margins aren't updated */
font_expect = small_margins;
hfont = SelectObject(hdc, hfont);
ReleaseDC(hwnd, hdc);
}
margins = SendMessageA(hwnd, EM_GETMARGINS, 0, 0);
ok(margins == 0, "got %x\n", margins);
SendMessageA(hwnd, EM_SETMARGINS, EC_LEFTMARGIN | EC_RIGHTMARGIN, small_margins);
SendMessageA(hwnd, WM_SETFONT, (WPARAM)hfont, MAKELPARAM(TRUE, 0));
margins = SendMessageA(hwnd, EM_GETMARGINS, 0, 0);
if (!cjk_charset)
ok(margins == expect, "%s:%d: got %d, %d\n", facename, charset, HIWORD(margins), LOWORD(margins));
todo_wine_if(cjk_charset)
ok(margins == font_expect, "%s:%d: expected %d, %d, got %d, %d\n", facename, charset, HIWORD(font_expect), LOWORD(font_expect), HIWORD(margins), LOWORD(margins));
SendMessageA(hwnd, EM_SETMARGINS, EC_LEFTMARGIN | EC_RIGHTMARGIN, small_margins);
SendMessageA(hwnd, EM_SETMARGINS, EC_LEFTMARGIN | EC_RIGHTMARGIN, MAKELONG(EC_USEFONTINFO, EC_USEFONTINFO));
margins = SendMessageA(hwnd, EM_GETMARGINS, 0, 0);
ok(margins == expect, "%s:%d: expected %d, %d, got %d, %d\n", facename, charset, HIWORD(expect), LOWORD(expect), HIWORD(margins), LOWORD(margins));
DestroyWindow(hwnd);