Blame SOURCES/7.4.202

22c937
To: vim_dev@googlegroups.com
22c937
Subject: Patch 7.4.202
22c937
Fcc: outbox
22c937
From: Bram Moolenaar <Bram@moolenaar.net>
22c937
Mime-Version: 1.0
22c937
Content-Type: text/plain; charset=UTF-8
22c937
Content-Transfer-Encoding: 8bit
22c937
------------
22c937
22c937
Patch 7.4.202
22c937
Problem:    MS-Windows: non-ASCII font names don't work.
22c937
Solution:   Convert between the current code page and 'encoding'. (Ken Takata)
22c937
Files:	    src/gui_w48.c, src/os_mswin.c, src/proto/winclip.pro,
22c937
	    src/winclip.c
22c937
22c937
22c937
*** ../vim-7.4.201/src/gui_w48.c	2013-09-22 15:43:34.000000000 +0200
22c937
--- src/gui_w48.c	2014-03-12 19:18:14.264927370 +0100
22c937
***************
22c937
*** 3069,3083 ****
22c937
      char	*p;
22c937
      char	*res;
22c937
      char	*charset_name;
22c937
  
22c937
      charset_name = charset_id2name((int)lf.lfCharSet);
22c937
!     res = alloc((unsigned)(strlen(lf.lfFaceName) + 20
22c937
  		    + (charset_name == NULL ? 0 : strlen(charset_name) + 2)));
22c937
      if (res != NULL)
22c937
      {
22c937
  	p = res;
22c937
  	/* make a normal font string out of the lf thing:*/
22c937
! 	sprintf((char *)p, "%s:h%d", lf.lfFaceName, pixels_to_points(
22c937
  			 lf.lfHeight < 0 ? -lf.lfHeight : lf.lfHeight, TRUE));
22c937
  	while (*p)
22c937
  	{
22c937
--- 3069,3094 ----
22c937
      char	*p;
22c937
      char	*res;
22c937
      char	*charset_name;
22c937
+     char	*font_name = lf.lfFaceName;
22c937
  
22c937
      charset_name = charset_id2name((int)lf.lfCharSet);
22c937
! #ifdef FEAT_MBYTE
22c937
!     /* Convert a font name from the current codepage to 'encoding'.
22c937
!      * TODO: Use Wide APIs (including LOGFONTW) instead of ANSI APIs. */
22c937
!     if (enc_codepage >= 0 && (int)GetACP() != enc_codepage)
22c937
!     {
22c937
! 	int	len;
22c937
! 	acp_to_enc(lf.lfFaceName, strlen(lf.lfFaceName),
22c937
! 						(char_u **)&font_name, &len;;
22c937
!     }
22c937
! #endif
22c937
!     res = alloc((unsigned)(strlen(font_name) + 20
22c937
  		    + (charset_name == NULL ? 0 : strlen(charset_name) + 2)));
22c937
      if (res != NULL)
22c937
      {
22c937
  	p = res;
22c937
  	/* make a normal font string out of the lf thing:*/
22c937
! 	sprintf((char *)p, "%s:h%d", font_name, pixels_to_points(
22c937
  			 lf.lfHeight < 0 ? -lf.lfHeight : lf.lfHeight, TRUE));
22c937
  	while (*p)
22c937
  	{
22c937
***************
22c937
*** 3102,3107 ****
22c937
--- 3113,3122 ----
22c937
  	}
22c937
      }
22c937
  
22c937
+ #ifdef FEAT_MBYTE
22c937
+     if (font_name != lf.lfFaceName)
22c937
+ 	vim_free(font_name);
22c937
+ #endif
22c937
      return res;
22c937
  }
22c937
  
22c937
*** ../vim-7.4.201/src/os_mswin.c	2014-02-11 17:05:57.278217857 +0100
22c937
--- src/os_mswin.c	2014-03-12 19:18:14.264927370 +0100
22c937
***************
22c937
*** 2867,2878 ****
22c937
--- 2867,2893 ----
22c937
  {
22c937
      char_u	*p;
22c937
      int		i;
22c937
+     int		ret = FAIL;
22c937
      static LOGFONT *lastlf = NULL;
22c937
+ #ifdef FEAT_MBYTE
22c937
+     char_u	*acpname = NULL;
22c937
+ #endif
22c937
  
22c937
      *lf = s_lfDefault;
22c937
      if (name == NULL)
22c937
  	return OK;
22c937
  
22c937
+ #ifdef FEAT_MBYTE
22c937
+     /* Convert 'name' from 'encoding' to the current codepage, because
22c937
+      * lf->lfFaceName uses the current codepage.
22c937
+      * TODO: Use Wide APIs instead of ANSI APIs. */
22c937
+     if (enc_codepage >= 0 && (int)GetACP() != enc_codepage)
22c937
+     {
22c937
+ 	int	len;
22c937
+ 	enc_to_acp(name, strlen(name), &acpname, &len;;
22c937
+ 	name = acpname;
22c937
+     }
22c937
+ #endif
22c937
      if (STRCMP(name, "*") == 0)
22c937
      {
22c937
  #if defined(FEAT_GUI_W32)
22c937
***************
22c937
*** 2887,2896 ****
22c937
  	cf.lpLogFont = lf;
22c937
  	cf.nFontType = 0 ; //REGULAR_FONTTYPE;
22c937
  	if (ChooseFont(&cf))
22c937
! 	    goto theend;
22c937
! #else
22c937
! 	return FAIL;
22c937
  #endif
22c937
      }
22c937
  
22c937
      /*
22c937
--- 2902,2910 ----
22c937
  	cf.lpLogFont = lf;
22c937
  	cf.nFontType = 0 ; //REGULAR_FONTTYPE;
22c937
  	if (ChooseFont(&cf))
22c937
! 	    ret = OK;
22c937
  #endif
22c937
+ 	goto theend;
22c937
      }
22c937
  
22c937
      /*
22c937
***************
22c937
*** 2899,2905 ****
22c937
      for (p = name; *p && *p != ':'; p++)
22c937
      {
22c937
  	if (p - name + 1 > LF_FACESIZE)
22c937
! 	    return FAIL;			/* Name too long */
22c937
  	lf->lfFaceName[p - name] = *p;
22c937
      }
22c937
      if (p != name)
22c937
--- 2913,2919 ----
22c937
      for (p = name; *p && *p != ':'; p++)
22c937
      {
22c937
  	if (p - name + 1 > LF_FACESIZE)
22c937
! 	    goto theend;			/* Name too long */
22c937
  	lf->lfFaceName[p - name] = *p;
22c937
      }
22c937
      if (p != name)
22c937
***************
22c937
*** 2927,2933 ****
22c937
  		did_replace = TRUE;
22c937
  	    }
22c937
  	if (!did_replace || init_logfont(lf) == FAIL)
22c937
! 	    return FAIL;
22c937
      }
22c937
  
22c937
      while (*p == ':')
22c937
--- 2941,2947 ----
22c937
  		did_replace = TRUE;
22c937
  	    }
22c937
  	if (!did_replace || init_logfont(lf) == FAIL)
22c937
! 	    goto theend;
22c937
      }
22c937
  
22c937
      while (*p == ':')
22c937
***************
22c937
*** 2988,3012 ****
22c937
  			    p[-1], name);
22c937
  		    EMSG(IObuff);
22c937
  		}
22c937
! 		return FAIL;
22c937
  	}
22c937
  	while (*p == ':')
22c937
  	    p++;
22c937
      }
22c937
  
22c937
- #if defined(FEAT_GUI_W32)
22c937
  theend:
22c937
- #endif
22c937
      /* ron: init lastlf */
22c937
!     if (printer_dc == NULL)
22c937
      {
22c937
  	vim_free(lastlf);
22c937
  	lastlf = (LOGFONT *)alloc(sizeof(LOGFONT));
22c937
  	if (lastlf != NULL)
22c937
  	    mch_memmove(lastlf, lf, sizeof(LOGFONT));
22c937
      }
22c937
  
22c937
!     return OK;
22c937
  }
22c937
  
22c937
  #endif /* defined(FEAT_GUI) || defined(FEAT_PRINTER) */
22c937
--- 3002,3028 ----
22c937
  			    p[-1], name);
22c937
  		    EMSG(IObuff);
22c937
  		}
22c937
! 		goto theend;
22c937
  	}
22c937
  	while (*p == ':')
22c937
  	    p++;
22c937
      }
22c937
+     ret = OK;
22c937
  
22c937
  theend:
22c937
      /* ron: init lastlf */
22c937
!     if (ret == OK && printer_dc == NULL)
22c937
      {
22c937
  	vim_free(lastlf);
22c937
  	lastlf = (LOGFONT *)alloc(sizeof(LOGFONT));
22c937
  	if (lastlf != NULL)
22c937
  	    mch_memmove(lastlf, lf, sizeof(LOGFONT));
22c937
      }
22c937
+ #ifdef FEAT_MBYTE
22c937
+     vim_free(acpname);
22c937
+ #endif
22c937
  
22c937
!     return ret;
22c937
  }
22c937
  
22c937
  #endif /* defined(FEAT_GUI) || defined(FEAT_PRINTER) */
22c937
*** ../vim-7.4.201/src/proto/winclip.pro	2013-08-10 13:37:39.000000000 +0200
22c937
--- src/proto/winclip.pro	2014-03-12 19:18:14.264927370 +0100
22c937
***************
22c937
*** 11,14 ****
22c937
--- 11,15 ----
22c937
  short_u *enc_to_utf16 __ARGS((char_u *str, int *lenp));
22c937
  char_u *utf16_to_enc __ARGS((short_u *str, int *lenp));
22c937
  void acp_to_enc __ARGS((char_u *str, int str_size, char_u **out, int *outlen));
22c937
+ void enc_to_acp __ARGS((char_u *str, int str_size, char_u **out, int *outlen));
22c937
  /* vim: set ft=c : */
22c937
*** ../vim-7.4.201/src/winclip.c	2013-07-01 21:05:53.000000000 +0200
22c937
--- src/winclip.c	2014-03-12 19:18:14.264927370 +0100
22c937
***************
22c937
*** 797,800 ****
22c937
--- 797,825 ----
22c937
  	vim_free(widestr);
22c937
      }
22c937
  }
22c937
+ 
22c937
+ /*
22c937
+  * Convert from 'encoding' to the active codepage.
22c937
+  * Input is "str[str_size]".
22c937
+  * The result is in allocated memory: "out[outlen]".  With terminating NUL.
22c937
+  */
22c937
+     void
22c937
+ enc_to_acp(str, str_size, out, outlen)
22c937
+     char_u	*str;
22c937
+     int		str_size;
22c937
+     char_u	**out;
22c937
+     int		*outlen;
22c937
+ 
22c937
+ {
22c937
+     LPWSTR	widestr;
22c937
+     int		len = str_size;
22c937
+ 
22c937
+     widestr = (WCHAR *)enc_to_utf16(str, &len;;
22c937
+     if (widestr != NULL)
22c937
+     {
22c937
+ 	WideCharToMultiByte_alloc(GetACP(), 0, widestr, len,
22c937
+ 						(LPSTR *)out, outlen, 0, 0);
22c937
+ 	vim_free(widestr);
22c937
+     }
22c937
+ }
22c937
  #endif
22c937
*** ../vim-7.4.201/src/version.c	2014-03-12 18:55:52.104906804 +0100
22c937
--- src/version.c	2014-03-12 19:19:01.388928092 +0100
22c937
***************
22c937
*** 740,741 ****
22c937
--- 740,743 ----
22c937
  {   /* Add new patch number below this line */
22c937
+ /**/
22c937
+     202,
22c937
  /**/
22c937
22c937
-- 
22c937
<Beeth> Girls are like internet domain names,
22c937
        the ones I like are already taken.
22c937
<honx>  Well, you can stil get one from a strange country :-P
22c937
22c937
 /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
22c937
///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
22c937
\\\  an exciting new programming language -- http://www.Zimbu.org        ///
22c937
 \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///