Skip to content

Commit 61c2078

Browse files
committed
updated for version 7.3.1211
Problem: MS-Windows: When 'encoding' differs from the current codepage ":hardcopy" does not work properly. Solution: Use TextOutW() and SetDlgItemTextW(). (Ken Takata)
1 parent 240f142 commit 61c2078

3 files changed

Lines changed: 67 additions & 11 deletions

File tree

src/os_mswin.c

Lines changed: 62 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1045,6 +1045,29 @@ static char_u *prt_name = NULL;
10451045
#define IDC_PRINTTEXT2 402
10461046
#define IDC_PROGRESS 403
10471047

1048+
#if !defined(FEAT_MBYTE) || defined(WIN16)
1049+
# define vimSetDlgItemText(h, i, s) SetDlgItemText(h, i, s)
1050+
#else
1051+
static BOOL
1052+
vimSetDlgItemText(HWND hDlg, int nIDDlgItem, char_u *s)
1053+
{
1054+
WCHAR *wp = NULL;
1055+
BOOL ret;
1056+
1057+
if (enc_codepage >= 0 && (int)GetACP() != enc_codepage)
1058+
{
1059+
wp = enc_to_utf16(s, NULL);
1060+
}
1061+
if (wp != NULL)
1062+
{
1063+
ret = SetDlgItemTextW(hDlg, nIDDlgItem, wp);
1064+
vim_free(wp);
1065+
return ret;
1066+
}
1067+
return SetDlgItemText(hDlg, nIDDlgItem, s);
1068+
}
1069+
#endif
1070+
10481071
/*
10491072
* Convert BGR to RGB for Windows GDI calls
10501073
*/
@@ -1096,18 +1119,18 @@ PrintDlgProc(HWND hDlg, UINT message, WPARAM wParam, LPARAM lParam)
10961119
{
10971120
SendDlgItemMessage(hDlg, i, WM_SETFONT, (WPARAM)hfont, 1);
10981121
if (GetDlgItemText(hDlg,i, buff, sizeof(buff)))
1099-
SetDlgItemText(hDlg,i, _(buff));
1122+
vimSetDlgItemText(hDlg,i, _(buff));
11001123
}
11011124
SendDlgItemMessage(hDlg, IDCANCEL,
11021125
WM_SETFONT, (WPARAM)hfont, 1);
11031126
if (GetDlgItemText(hDlg,IDCANCEL, buff, sizeof(buff)))
1104-
SetDlgItemText(hDlg,IDCANCEL, _(buff));
1127+
vimSetDlgItemText(hDlg,IDCANCEL, _(buff));
11051128
}
11061129
#endif
11071130
SetWindowText(hDlg, szAppName);
11081131
if (prt_name != NULL)
11091132
{
1110-
SetDlgItemText(hDlg, IDC_PRINTTEXT2, (LPSTR)prt_name);
1133+
vimSetDlgItemText(hDlg, IDC_PRINTTEXT2, (LPSTR)prt_name);
11111134
vim_free(prt_name);
11121135
prt_name = NULL;
11131136
}
@@ -1565,7 +1588,7 @@ mch_print_begin(prt_settings_T *psettings)
15651588
SetAbortProc(prt_dlg.hDC, AbortProc);
15661589
#endif
15671590
wsprintf(szBuffer, _("Printing '%s'"), gettail(psettings->jobname));
1568-
SetDlgItemText(hDlgPrint, IDC_PRINTTEXT1, (LPSTR)szBuffer);
1591+
vimSetDlgItemText(hDlgPrint, IDC_PRINTTEXT1, (LPSTR)szBuffer);
15691592

15701593
vim_memset(&di, 0, sizeof(DOCINFO));
15711594
di.cbSize = sizeof(DOCINFO);
@@ -1599,7 +1622,7 @@ mch_print_end_page(void)
15991622
mch_print_begin_page(char_u *msg)
16001623
{
16011624
if (msg != NULL)
1602-
SetDlgItemText(hDlgPrint, IDC_PROGRESS, (LPSTR)msg);
1625+
vimSetDlgItemText(hDlgPrint, IDC_PROGRESS, (LPSTR)msg);
16031626
return (StartPage(prt_dlg.hDC) > 0);
16041627
}
16051628

@@ -1628,10 +1651,41 @@ mch_print_start_line(margin, page_line)
16281651
int
16291652
mch_print_text_out(char_u *p, int len)
16301653
{
1631-
#ifdef FEAT_PROPORTIONAL_FONTS
1654+
#if defined(FEAT_PROPORTIONAL_FONTS) || (defined(FEAT_MBYTE) && !defined(WIN16))
16321655
SIZE sz;
16331656
#endif
1657+
#if defined(FEAT_MBYTE) && !defined(WIN16)
1658+
WCHAR *wp = NULL;
1659+
int wlen = len;
16341660

1661+
if (enc_codepage >= 0 && (int)GetACP() != enc_codepage)
1662+
{
1663+
wp = enc_to_utf16(p, &wlen);
1664+
}
1665+
if (wp != NULL)
1666+
{
1667+
int ret = FALSE;
1668+
1669+
TextOutW(prt_dlg.hDC, prt_pos_x + prt_left_margin,
1670+
prt_pos_y + prt_top_margin, wp, wlen);
1671+
GetTextExtentPoint32W(prt_dlg.hDC, wp, wlen, &sz);
1672+
vim_free(wp);
1673+
prt_pos_x += (sz.cx - prt_tm.tmOverhang);
1674+
/* This is wrong when printing spaces for a TAB. */
1675+
if (p[len] != NUL)
1676+
{
1677+
wlen = MB_PTR2LEN(p + len);
1678+
wp = enc_to_utf16(p + len, &wlen);
1679+
if (wp != NULL)
1680+
{
1681+
GetTextExtentPoint32W(prt_dlg.hDC, wp, 1, &sz);
1682+
ret = (prt_pos_x + prt_left_margin + sz.cx > prt_right_margin);
1683+
vim_free(wp);
1684+
}
1685+
}
1686+
return ret;
1687+
}
1688+
#endif
16351689
TextOut(prt_dlg.hDC, prt_pos_x + prt_left_margin,
16361690
prt_pos_y + prt_top_margin, p, len);
16371691
#ifndef FEAT_PROPORTIONAL_FONTS
@@ -1947,8 +2001,8 @@ Messaging_WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
19472001
reply.cbData = (DWORD)STRLEN(res) + 1;
19482002

19492003
serverSendEnc(sender);
1950-
retval = (int)SendMessage(sender, WM_COPYDATA, (WPARAM)message_window,
1951-
(LPARAM)(&reply));
2004+
retval = (int)SendMessage(sender, WM_COPYDATA,
2005+
(WPARAM)message_window, (LPARAM)(&reply));
19522006
vim_free(res);
19532007
return retval;
19542008

src/version.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -728,6 +728,8 @@ static char *(features[]) =
728728

729729
static int included_patches[] =
730730
{ /* Add new patch number below this line */
731+
/**/
732+
1211,
731733
/**/
732734
1210,
733735
/**/

src/vim.rc

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,8 @@ STYLE DS_MODALFRAME | WS_POPUP | WS_VISIBLE | WS_CAPTION | WS_SYSMENU
116116
FONT 8, "Helv"
117117
BEGIN
118118
DEFPUSHBUTTON "Cancel", IDCANCEL, 85, 60, 40, 14
119-
CTEXT "Printing",IDC_PRINTTEXT1,23,15,157,8
120-
CTEXT " ",IDC_PRINTTEXT2,23,25,157,8
121-
CTEXT "Initializing...",IDC_PROGRESS,24,38,157,8
119+
CTEXT "Printing",IDC_PRINTTEXT1,23,15,157,9
120+
CTEXT " ",IDC_PRINTTEXT2,23,25,157,9
121+
CTEXT "Initializing...",IDC_PROGRESS,24,38,157,9
122122
GROUPBOX "",IDC_BOX1,19,9,170,47
123123
END

0 commit comments

Comments
 (0)