summaryrefslogtreecommitdiffstats
path: root/patches/source/vim/patches/7.4.202
blob: 5c50d87805bd1ab40d906f36b1854f527e25a3f6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
To: vim_dev@googlegroups.com
Subject: Patch 7.4.202
Fcc: outbox
From: Bram Moolenaar <Bram@moolenaar.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
------------

Patch 7.4.202
Problem:    MS-Windows: non-ASCII font names don't work.
Solution:   Convert between the current code page and 'encoding'. (Ken Takata)
Files:	    src/gui_w48.c, src/os_mswin.c, src/proto/winclip.pro,
	    src/winclip.c


*** ../vim-7.4.201/src/gui_w48.c	2013-09-22 15:43:34.000000000 +0200
--- src/gui_w48.c	2014-03-12 19:18:14.264927370 +0100
***************
*** 3069,3083 ****
      char	*p;
      char	*res;
      char	*charset_name;
  
      charset_name = charset_id2name((int)lf.lfCharSet);
!     res = alloc((unsigned)(strlen(lf.lfFaceName) + 20
  		    + (charset_name == NULL ? 0 : strlen(charset_name) + 2)));
      if (res != NULL)
      {
  	p = res;
  	/* make a normal font string out of the lf thing:*/
! 	sprintf((char *)p, "%s:h%d", lf.lfFaceName, pixels_to_points(
  			 lf.lfHeight < 0 ? -lf.lfHeight : lf.lfHeight, TRUE));
  	while (*p)
  	{
--- 3069,3094 ----
      char	*p;
      char	*res;
      char	*charset_name;
+     char	*font_name = lf.lfFaceName;
  
      charset_name = charset_id2name((int)lf.lfCharSet);
! #ifdef FEAT_MBYTE
!     /* Convert a font name from the current codepage to 'encoding'.
!      * TODO: Use Wide APIs (including LOGFONTW) instead of ANSI APIs. */
!     if (enc_codepage >= 0 && (int)GetACP() != enc_codepage)
!     {
! 	int	len;
! 	acp_to_enc(lf.lfFaceName, strlen(lf.lfFaceName),
! 						(char_u **)&font_name, &len);
!     }
! #endif
!     res = alloc((unsigned)(strlen(font_name) + 20
  		    + (charset_name == NULL ? 0 : strlen(charset_name) + 2)));
      if (res != NULL)
      {
  	p = res;
  	/* make a normal font string out of the lf thing:*/
! 	sprintf((char *)p, "%s:h%d", font_name, pixels_to_points(
  			 lf.lfHeight < 0 ? -lf.lfHeight : lf.lfHeight, TRUE));
  	while (*p)
  	{
***************
*** 3102,3107 ****
--- 3113,3122 ----
  	}
      }
  
+ #ifdef FEAT_MBYTE
+     if (font_name != lf.lfFaceName)
+ 	vim_free(font_name);
+ #endif
      return res;
  }
  
*** ../vim-7.4.201/src/os_mswin.c	2014-02-11 17:05:57.278217857 +0100
--- src/os_mswin.c	2014-03-12 19:18:14.264927370 +0100
***************
*** 2867,2878 ****
--- 2867,2893 ----
  {
      char_u	*p;
      int		i;
+     int		ret = FAIL;
      static LOGFONT *lastlf = NULL;
+ #ifdef FEAT_MBYTE
+     char_u	*acpname = NULL;
+ #endif
  
      *lf = s_lfDefault;
      if (name == NULL)
  	return OK;
  
+ #ifdef FEAT_MBYTE
+     /* Convert 'name' from 'encoding' to the current codepage, because
+      * lf->lfFaceName uses the current codepage.
+      * TODO: Use Wide APIs instead of ANSI APIs. */
+     if (enc_codepage >= 0 && (int)GetACP() != enc_codepage)
+     {
+ 	int	len;
+ 	enc_to_acp(name, strlen(name), &acpname, &len);
+ 	name = acpname;
+     }
+ #endif
      if (STRCMP(name, "*") == 0)
      {
  #if defined(FEAT_GUI_W32)
***************
*** 2887,2896 ****
  	cf.lpLogFont = lf;
  	cf.nFontType = 0 ; //REGULAR_FONTTYPE;
  	if (ChooseFont(&cf))
! 	    goto theend;
! #else
! 	return FAIL;
  #endif
      }
  
      /*
--- 2902,2910 ----
  	cf.lpLogFont = lf;
  	cf.nFontType = 0 ; //REGULAR_FONTTYPE;
  	if (ChooseFont(&cf))
! 	    ret = OK;
  #endif
+ 	goto theend;
      }
  
      /*
***************
*** 2899,2905 ****
      for (p = name; *p && *p != ':'; p++)
      {
  	if (p - name + 1 > LF_FACESIZE)
! 	    return FAIL;			/* Name too long */
  	lf->lfFaceName[p - name] = *p;
      }
      if (p != name)
--- 2913,2919 ----
      for (p = name; *p && *p != ':'; p++)
      {
  	if (p - name + 1 > LF_FACESIZE)
! 	    goto theend;			/* Name too long */
  	lf->lfFaceName[p - name] = *p;
      }
      if (p != name)
***************
*** 2927,2933 ****
  		did_replace = TRUE;
  	    }
  	if (!did_replace || init_logfont(lf) == FAIL)
! 	    return FAIL;
      }
  
      while (*p == ':')
--- 2941,2947 ----
  		did_replace = TRUE;
  	    }
  	if (!did_replace || init_logfont(lf) == FAIL)
! 	    goto theend;
      }
  
      while (*p == ':')
***************
*** 2988,3012 ****
  			    p[-1], name);
  		    EMSG(IObuff);
  		}
! 		return FAIL;
  	}
  	while (*p == ':')
  	    p++;
      }
  
- #if defined(FEAT_GUI_W32)
  theend:
- #endif
      /* ron: init lastlf */
!     if (printer_dc == NULL)
      {
  	vim_free(lastlf);
  	lastlf = (LOGFONT *)alloc(sizeof(LOGFONT));
  	if (lastlf != NULL)
  	    mch_memmove(lastlf, lf, sizeof(LOGFONT));
      }
  
!     return OK;
  }
  
  #endif /* defined(FEAT_GUI) || defined(FEAT_PRINTER) */
--- 3002,3028 ----
  			    p[-1], name);
  		    EMSG(IObuff);
  		}
! 		goto theend;
  	}
  	while (*p == ':')
  	    p++;
      }
+     ret = OK;
  
  theend:
      /* ron: init lastlf */
!     if (ret == OK && printer_dc == NULL)
      {
  	vim_free(lastlf);
  	lastlf = (LOGFONT *)alloc(sizeof(LOGFONT));
  	if (lastlf != NULL)
  	    mch_memmove(lastlf, lf, sizeof(LOGFONT));
      }
+ #ifdef FEAT_MBYTE
+     vim_free(acpname);
+ #endif
  
!     return ret;
  }
  
  #endif /* defined(FEAT_GUI) || defined(FEAT_PRINTER) */
*** ../vim-7.4.201/src/proto/winclip.pro	2013-08-10 13:37:39.000000000 +0200
--- src/proto/winclip.pro	2014-03-12 19:18:14.264927370 +0100
***************
*** 11,14 ****
--- 11,15 ----
  short_u *enc_to_utf16 __ARGS((char_u *str, int *lenp));
  char_u *utf16_to_enc __ARGS((short_u *str, int *lenp));
  void acp_to_enc __ARGS((char_u *str, int str_size, char_u **out, int *outlen));
+ void enc_to_acp __ARGS((char_u *str, int str_size, char_u **out, int *outlen));
  /* vim: set ft=c : */
*** ../vim-7.4.201/src/winclip.c	2013-07-01 21:05:53.000000000 +0200
--- src/winclip.c	2014-03-12 19:18:14.264927370 +0100
***************
*** 797,800 ****
--- 797,825 ----
  	vim_free(widestr);
      }
  }
+ 
+ /*
+  * Convert from 'encoding' to the active codepage.
+  * Input is "str[str_size]".
+  * The result is in allocated memory: "out[outlen]".  With terminating NUL.
+  */
+     void
+ enc_to_acp(str, str_size, out, outlen)
+     char_u	*str;
+     int		str_size;
+     char_u	**out;
+     int		*outlen;
+ 
+ {
+     LPWSTR	widestr;
+     int		len = str_size;
+ 
+     widestr = (WCHAR *)enc_to_utf16(str, &len);
+     if (widestr != NULL)
+     {
+ 	WideCharToMultiByte_alloc(GetACP(), 0, widestr, len,
+ 						(LPSTR *)out, outlen, 0, 0);
+ 	vim_free(widestr);
+     }
+ }
  #endif
*** ../vim-7.4.201/src/version.c	2014-03-12 18:55:52.104906804 +0100
--- src/version.c	2014-03-12 19:19:01.388928092 +0100
***************
*** 740,741 ****
--- 740,743 ----
  {   /* Add new patch number below this line */
+ /**/
+     202,
  /**/

-- 
<Beeth> Girls are like internet domain names,
        the ones I like are already taken.
<honx>  Well, you can stil get one from a strange country :-P

 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///