Hi,
When 'encoding' is different from the current codepage on Windows,
:hardcopy doesn't work properly. There are three problems:
1. The result of printing is broken because TextOut() is used without
converting the encoding. TextOutW() should be used.
2. The print dialog box isn't shown properly because SetDlgItemText()
is used. SetDlgItemTextW() should be used.
3. The height of text boxes in the print dialog is not enough.
So, some parts of the texts are not visible.
Attached patch fixes them.
Best regards,
Ken Takata
--
--
You received this message from the "vim_dev" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php
---
You received this message because you are subscribed to the Google Groups
"vim_dev" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.
# HG changeset patch
# Parent 8e5a1b34b2910584ddb9c1a4ecad70c05533199d
diff --git a/src/os_mswin.c b/src/os_mswin.c
--- a/src/os_mswin.c
+++ b/src/os_mswin.c
@@ -1045,6 +1045,29 @@
#define IDC_PRINTTEXT2 402
#define IDC_PROGRESS 403
+#if !defined(FEAT_MBYTE) || defined(WIN16)
+# define vimSetDlgItemText(h, i, s) SetDlgItemText(h, i, s)
+#else
+ static BOOL
+vimSetDlgItemText(HWND hDlg, int nIDDlgItem, char_u *s)
+{
+ WCHAR *wp = NULL;
+ BOOL ret;
+
+ if (enc_codepage >= 0 && (int)GetACP() != enc_codepage)
+ {
+ wp = enc_to_utf16(s, NULL);
+ }
+ if (wp != NULL)
+ {
+ ret = SetDlgItemTextW(hDlg, nIDDlgItem, wp);
+ vim_free(wp);
+ return ret;
+ }
+ return SetDlgItemText(hDlg, nIDDlgItem, s);
+}
+#endif
+
/*
* Convert BGR to RGB for Windows GDI calls
*/
@@ -1096,18 +1119,18 @@
{
SendDlgItemMessage(hDlg, i, WM_SETFONT, (WPARAM)hfont, 1);
if (GetDlgItemText(hDlg,i, buff, sizeof(buff)))
- SetDlgItemText(hDlg,i, _(buff));
+ vimSetDlgItemText(hDlg,i, _(buff));
}
SendDlgItemMessage(hDlg, IDCANCEL,
WM_SETFONT, (WPARAM)hfont, 1);
if (GetDlgItemText(hDlg,IDCANCEL, buff, sizeof(buff)))
- SetDlgItemText(hDlg,IDCANCEL, _(buff));
+ vimSetDlgItemText(hDlg,IDCANCEL, _(buff));
}
#endif
SetWindowText(hDlg, szAppName);
if (prt_name != NULL)
{
- SetDlgItemText(hDlg, IDC_PRINTTEXT2, (LPSTR)prt_name);
+ vimSetDlgItemText(hDlg, IDC_PRINTTEXT2, (LPSTR)prt_name);
vim_free(prt_name);
prt_name = NULL;
}
@@ -1565,7 +1588,7 @@
SetAbortProc(prt_dlg.hDC, AbortProc);
#endif
wsprintf(szBuffer, _("Printing '%s'"), gettail(psettings->jobname));
- SetDlgItemText(hDlgPrint, IDC_PRINTTEXT1, (LPSTR)szBuffer);
+ vimSetDlgItemText(hDlgPrint, IDC_PRINTTEXT1, (LPSTR)szBuffer);
vim_memset(&di, 0, sizeof(DOCINFO));
di.cbSize = sizeof(DOCINFO);
@@ -1599,7 +1622,7 @@
mch_print_begin_page(char_u *msg)
{
if (msg != NULL)
- SetDlgItemText(hDlgPrint, IDC_PROGRESS, (LPSTR)msg);
+ vimSetDlgItemText(hDlgPrint, IDC_PROGRESS, (LPSTR)msg);
return (StartPage(prt_dlg.hDC) > 0);
}
@@ -1628,10 +1651,41 @@
int
mch_print_text_out(char_u *p, int len)
{
-#ifdef FEAT_PROPORTIONAL_FONTS
+#if defined(FEAT_PROPORTIONAL_FONTS) || (defined(FEAT_MBYTE) && !defined(WIN16))
SIZE sz;
#endif
-
+#if defined(FEAT_MBYTE) && !defined(WIN16)
+ WCHAR *wp = NULL;
+ int wlen = len;
+
+ if (enc_codepage >= 0 && (int)GetACP() != enc_codepage)
+ {
+ wp = enc_to_utf16(p, &wlen);
+ }
+ if (wp != NULL)
+ {
+ int ret = FALSE;
+
+ TextOutW(prt_dlg.hDC, prt_pos_x + prt_left_margin,
+ prt_pos_y + prt_top_margin, wp, wlen);
+ GetTextExtentPoint32W(prt_dlg.hDC, wp, wlen, &sz);
+ vim_free(wp);
+ prt_pos_x += (sz.cx - prt_tm.tmOverhang);
+ /* This is wrong when printing spaces for a TAB. */
+ if (p[len] != NUL)
+ {
+ wlen = MB_PTR2LEN(p + len);
+ wp = enc_to_utf16(p + len, &wlen);
+ if (wp != NULL)
+ {
+ GetTextExtentPoint32W(prt_dlg.hDC, wp, 1, &sz);
+ ret = (prt_pos_x + prt_left_margin + sz.cx > prt_right_margin);
+ vim_free(wp);
+ }
+ }
+ return ret;
+ }
+#endif
TextOut(prt_dlg.hDC, prt_pos_x + prt_left_margin,
prt_pos_y + prt_top_margin, p, len);
#ifndef FEAT_PROPORTIONAL_FONTS
diff --git a/src/vim.rc b/src/vim.rc
--- a/src/vim.rc
+++ b/src/vim.rc
@@ -116,8 +116,8 @@
FONT 8, "Helv"
BEGIN
DEFPUSHBUTTON "Cancel", IDCANCEL, 85, 60, 40, 14
- CTEXT "Printing",IDC_PRINTTEXT1,23,15,157,8
- CTEXT " ",IDC_PRINTTEXT2,23,25,157,8
- CTEXT "Initializing...",IDC_PROGRESS,24,38,157,8
+ CTEXT "Printing",IDC_PRINTTEXT1,23,15,157,9
+ CTEXT " ",IDC_PRINTTEXT2,23,25,157,9
+ CTEXT "Initializing...",IDC_PROGRESS,24,38,157,9
GROUPBOX "",IDC_BOX1,19,9,170,47
END