user32: Implement WM_SETFONT margins in the CJK case.

Wine-Bug: https://bugs.winehq.org/show_bug.cgi?id=46685
Signed-off-by: Akihiro Sagawa <sagawa.aki@gmail.com>
Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Akihiro Sagawa 2019-04-18 23:51:02 +09:00 committed by Alexandre Julliard
parent c8c29eebc7
commit f3dc99c8b1
2 changed files with 30 additions and 4 deletions

View File

@ -3803,6 +3803,27 @@ static void EDIT_WM_SetFocus(EDITSTATE *es)
EDIT_NOTIFY_PARENT(es, EN_SETFOCUS);
}
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);
}
/*********************************************************************
*
@ -3819,6 +3840,7 @@ static void EDIT_WM_SetFont(EDITSTATE *es, HFONT font, BOOL redraw)
HDC dc;
HFONT old_font = 0;
RECT clientRect;
DWORD cjk_margins = MAKELONG(EC_USEFONTINFO, EC_USEFONTINFO);
es->font = font;
EDIT_InvalidateUniscribeData(es);
@ -3828,6 +3850,8 @@ static void EDIT_WM_SetFont(EDITSTATE *es, HFONT font, BOOL redraw)
GetTextMetricsW(dc, &tm);
es->line_height = tm.tmHeight;
es->char_width = tm.tmAveCharWidth;
if ((tm.tmPitchAndFamily & (TMPF_VECTOR | TMPF_TRUETYPE)) && is_cjk_charset(dc))
cjk_margins = get_cjk_font_margins(dc, es->is_unicode);
if (font)
SelectObject(dc, old_font);
ReleaseDC(es->hwndSelf, dc);
@ -3835,8 +3859,12 @@ static void EDIT_WM_SetFont(EDITSTATE *es, HFONT font, BOOL redraw)
/* Reset the format rect and the margins */
GetClientRect(es->hwndSelf, &clientRect);
EDIT_SetRectNP(es, &clientRect);
EDIT_EM_SetMargins(es, EC_LEFTMARGIN | EC_RIGHTMARGIN,
EC_USEFONTINFO, EC_USEFONTINFO, FALSE);
if (cjk_margins == MAKELONG(EC_USEFONTINFO, EC_USEFONTINFO))
EDIT_EM_SetMargins(es, EC_LEFTMARGIN | EC_RIGHTMARGIN,
EC_USEFONTINFO, EC_USEFONTINFO, FALSE);
else if (cjk_margins)
EDIT_EM_SetMargins(es, EC_LEFTMARGIN | EC_RIGHTMARGIN,
LOWORD(cjk_margins), HIWORD(cjk_margins), FALSE);
if (es->style & ES_MULTILINE)
EDIT_BuildLineDefs_ML(es, 0, get_text_length(es), 0, NULL);

View File

@ -1654,7 +1654,6 @@ 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);
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));
@ -1684,7 +1683,6 @@ 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);
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));