Akihiro Sagawa : user32: Implement WM_SETFONT margins in the CJK case.

Alexandre Julliard julliard at winehq.org
Fri Apr 19 17:30:46 CDT 2019


Module: wine
Branch: master
Commit: f3dc99c8b1091789034dea9d91ec95869b14212b
URL:    https://source.winehq.org/git/wine.git/?a=commit;h=f3dc99c8b1091789034dea9d91ec95869b14212b

Author: Akihiro Sagawa <sagawa.aki at gmail.com>
Date:   Thu Apr 18 23:51:02 2019 +0900

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 at gmail.com>
Signed-off-by: Alexandre Julliard <julliard at winehq.org>

---

 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 7eb2214..52c15aa 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 4c83d50..82b2cf8 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));




More information about the wine-cvs mailing list