Commit f3dc99c8 authored by Akihiro Sagawa's avatar Akihiro Sagawa Committed by Alexandre Julliard

user32: Implement WM_SETFONT margins in the CJK case.

parent c8c29eeb
...@@ -3803,6 +3803,27 @@ static void EDIT_WM_SetFocus(EDITSTATE *es) ...@@ -3803,6 +3803,27 @@ static void EDIT_WM_SetFocus(EDITSTATE *es)
EDIT_NOTIFY_PARENT(es, EN_SETFOCUS); 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) ...@@ -3819,6 +3840,7 @@ static void EDIT_WM_SetFont(EDITSTATE *es, HFONT font, BOOL redraw)
HDC dc; HDC dc;
HFONT old_font = 0; HFONT old_font = 0;
RECT clientRect; RECT clientRect;
DWORD cjk_margins = MAKELONG(EC_USEFONTINFO, EC_USEFONTINFO);
es->font = font; es->font = font;
EDIT_InvalidateUniscribeData(es); EDIT_InvalidateUniscribeData(es);
...@@ -3828,6 +3850,8 @@ static void EDIT_WM_SetFont(EDITSTATE *es, HFONT font, BOOL redraw) ...@@ -3828,6 +3850,8 @@ static void EDIT_WM_SetFont(EDITSTATE *es, HFONT font, BOOL redraw)
GetTextMetricsW(dc, &tm); GetTextMetricsW(dc, &tm);
es->line_height = tm.tmHeight; es->line_height = tm.tmHeight;
es->char_width = tm.tmAveCharWidth; 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) if (font)
SelectObject(dc, old_font); SelectObject(dc, old_font);
ReleaseDC(es->hwndSelf, dc); ReleaseDC(es->hwndSelf, dc);
...@@ -3835,8 +3859,12 @@ static void EDIT_WM_SetFont(EDITSTATE *es, HFONT font, BOOL redraw) ...@@ -3835,8 +3859,12 @@ static void EDIT_WM_SetFont(EDITSTATE *es, HFONT font, BOOL redraw)
/* Reset the format rect and the margins */ /* Reset the format rect and the margins */
GetClientRect(es->hwndSelf, &clientRect); GetClientRect(es->hwndSelf, &clientRect);
EDIT_SetRectNP(es, &clientRect); EDIT_SetRectNP(es, &clientRect);
EDIT_EM_SetMargins(es, EC_LEFTMARGIN | EC_RIGHTMARGIN, if (cjk_margins == MAKELONG(EC_USEFONTINFO, EC_USEFONTINFO))
EC_USEFONTINFO, EC_USEFONTINFO, FALSE); 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) if (es->style & ES_MULTILINE)
EDIT_BuildLineDefs_ML(es, 0, get_text_length(es), 0, NULL); EDIT_BuildLineDefs_ML(es, 0, get_text_length(es), 0, NULL);
......
...@@ -1654,7 +1654,6 @@ static void test_margins_default(const char* facename, UINT charset) ...@@ -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, EM_SETMARGINS, EC_LEFTMARGIN | EC_RIGHTMARGIN, small_margins);
SendMessageA(hwnd, WM_SETFONT, (WPARAM)hfont, MAKELPARAM(TRUE, 0)); SendMessageA(hwnd, WM_SETFONT, (WPARAM)hfont, MAKELPARAM(TRUE, 0));
margins = SendMessageA(hwnd, EM_GETMARGINS, 0, 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)); 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, small_margins);
SendMessageA(hwnd, EM_SETMARGINS, EC_LEFTMARGIN | EC_RIGHTMARGIN, MAKELONG(EC_USEFONTINFO, EC_USEFONTINFO)); 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) ...@@ -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, EM_SETMARGINS, EC_LEFTMARGIN | EC_RIGHTMARGIN, small_margins);
SendMessageA(hwnd, WM_SETFONT, (WPARAM)hfont, MAKELPARAM(TRUE, 0)); SendMessageA(hwnd, WM_SETFONT, (WPARAM)hfont, MAKELPARAM(TRUE, 0));
margins = SendMessageA(hwnd, EM_GETMARGINS, 0, 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)); 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, small_margins);
SendMessageA(hwnd, EM_SETMARGINS, EC_LEFTMARGIN | EC_RIGHTMARGIN, MAKELONG(EC_USEFONTINFO, EC_USEFONTINFO)); SendMessageA(hwnd, EM_SETMARGINS, EC_LEFTMARGIN | EC_RIGHTMARGIN, MAKELONG(EC_USEFONTINFO, EC_USEFONTINFO));
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment