jkunstle / rpms / vim

Forked from rpms/vim 3 years ago
Clone
Blob Blame History Raw
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    ///