From f3dc99c8b1091789034dea9d91ec95869b14212b Mon Sep 17 00:00:00 2001 From: Akihiro Sagawa Date: Thu, 18 Apr 2019 23:51:02 +0900 Subject: [PATCH] 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 Signed-off-by: Alexandre Julliard --- dlls/user32/edit.c | 32 ++++++++++++++++++++++++++++++-- dlls/user32/tests/edit.c | 2 -- 2 files changed, 30 insertions(+), 4 deletions(-) diff --git a/dlls/user32/edit.c b/dlls/user32/edit.c index 7eb221403ea..52c15aa8009 100644 --- a/dlls/user32/edit.c +++ b/dlls/user32/edit.c @@ -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); diff --git a/dlls/user32/tests/edit.c b/dlls/user32/tests/edit.c index 4c83d50221a..82b2cf8a955 100644 --- a/dlls/user32/tests/edit.c +++ b/dlls/user32/tests/edit.c @@ -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));