home *** CD-ROM | disk | FTP | other *** search
/ vim.ftp.fu-berlin.de / 2015-02-03.vim.ftp.fu-berlin.de.tar / vim.ftp.fu-berlin.de / patches / 7.4 / 7.4.202 < prev    next >
Encoding:
Internet Message Format  |  2014-03-11  |  7.0 KB

  1. To: vim_dev@googlegroups.com
  2. Subject: Patch 7.4.202
  3. Fcc: outbox
  4. From: Bram Moolenaar <Bram@moolenaar.net>
  5. Mime-Version: 1.0
  6. Content-Type: text/plain; charset=UTF-8
  7. Content-Transfer-Encoding: 8bit
  8. ------------
  9.  
  10. Patch 7.4.202
  11. Problem:    MS-Windows: non-ASCII font names don't work.
  12. Solution:   Convert between the current code page and 'encoding'. (Ken Takata)
  13. Files:        src/gui_w48.c, src/os_mswin.c, src/proto/winclip.pro,
  14.         src/winclip.c
  15.  
  16.  
  17. *** ../vim-7.4.201/src/gui_w48.c    2013-09-22 15:43:34.000000000 +0200
  18. --- src/gui_w48.c    2014-03-12 19:18:14.264927370 +0100
  19. ***************
  20. *** 3069,3083 ****
  21.       char    *p;
  22.       char    *res;
  23.       char    *charset_name;
  24.   
  25.       charset_name = charset_id2name((int)lf.lfCharSet);
  26. !     res = alloc((unsigned)(strlen(lf.lfFaceName) + 20
  27.               + (charset_name == NULL ? 0 : strlen(charset_name) + 2)));
  28.       if (res != NULL)
  29.       {
  30.       p = res;
  31.       /* make a normal font string out of the lf thing:*/
  32. !     sprintf((char *)p, "%s:h%d", lf.lfFaceName, pixels_to_points(
  33.                lf.lfHeight < 0 ? -lf.lfHeight : lf.lfHeight, TRUE));
  34.       while (*p)
  35.       {
  36. --- 3069,3094 ----
  37.       char    *p;
  38.       char    *res;
  39.       char    *charset_name;
  40. +     char    *font_name = lf.lfFaceName;
  41.   
  42.       charset_name = charset_id2name((int)lf.lfCharSet);
  43. ! #ifdef FEAT_MBYTE
  44. !     /* Convert a font name from the current codepage to 'encoding'.
  45. !      * TODO: Use Wide APIs (including LOGFONTW) instead of ANSI APIs. */
  46. !     if (enc_codepage >= 0 && (int)GetACP() != enc_codepage)
  47. !     {
  48. !     int    len;
  49. !     acp_to_enc(lf.lfFaceName, strlen(lf.lfFaceName),
  50. !                         (char_u **)&font_name, &len);
  51. !     }
  52. ! #endif
  53. !     res = alloc((unsigned)(strlen(font_name) + 20
  54.               + (charset_name == NULL ? 0 : strlen(charset_name) + 2)));
  55.       if (res != NULL)
  56.       {
  57.       p = res;
  58.       /* make a normal font string out of the lf thing:*/
  59. !     sprintf((char *)p, "%s:h%d", font_name, pixels_to_points(
  60.                lf.lfHeight < 0 ? -lf.lfHeight : lf.lfHeight, TRUE));
  61.       while (*p)
  62.       {
  63. ***************
  64. *** 3102,3107 ****
  65. --- 3113,3122 ----
  66.       }
  67.       }
  68.   
  69. + #ifdef FEAT_MBYTE
  70. +     if (font_name != lf.lfFaceName)
  71. +     vim_free(font_name);
  72. + #endif
  73.       return res;
  74.   }
  75.   
  76. *** ../vim-7.4.201/src/os_mswin.c    2014-02-11 17:05:57.278217857 +0100
  77. --- src/os_mswin.c    2014-03-12 19:18:14.264927370 +0100
  78. ***************
  79. *** 2867,2878 ****
  80. --- 2867,2893 ----
  81.   {
  82.       char_u    *p;
  83.       int        i;
  84. +     int        ret = FAIL;
  85.       static LOGFONT *lastlf = NULL;
  86. + #ifdef FEAT_MBYTE
  87. +     char_u    *acpname = NULL;
  88. + #endif
  89.   
  90.       *lf = s_lfDefault;
  91.       if (name == NULL)
  92.       return OK;
  93.   
  94. + #ifdef FEAT_MBYTE
  95. +     /* Convert 'name' from 'encoding' to the current codepage, because
  96. +      * lf->lfFaceName uses the current codepage.
  97. +      * TODO: Use Wide APIs instead of ANSI APIs. */
  98. +     if (enc_codepage >= 0 && (int)GetACP() != enc_codepage)
  99. +     {
  100. +     int    len;
  101. +     enc_to_acp(name, strlen(name), &acpname, &len);
  102. +     name = acpname;
  103. +     }
  104. + #endif
  105.       if (STRCMP(name, "*") == 0)
  106.       {
  107.   #if defined(FEAT_GUI_W32)
  108. ***************
  109. *** 2887,2896 ****
  110.       cf.lpLogFont = lf;
  111.       cf.nFontType = 0 ; //REGULAR_FONTTYPE;
  112.       if (ChooseFont(&cf))
  113. !         goto theend;
  114. ! #else
  115. !     return FAIL;
  116.   #endif
  117.       }
  118.   
  119.       /*
  120. --- 2902,2910 ----
  121.       cf.lpLogFont = lf;
  122.       cf.nFontType = 0 ; //REGULAR_FONTTYPE;
  123.       if (ChooseFont(&cf))
  124. !         ret = OK;
  125.   #endif
  126. +     goto theend;
  127.       }
  128.   
  129.       /*
  130. ***************
  131. *** 2899,2905 ****
  132.       for (p = name; *p && *p != ':'; p++)
  133.       {
  134.       if (p - name + 1 > LF_FACESIZE)
  135. !         return FAIL;            /* Name too long */
  136.       lf->lfFaceName[p - name] = *p;
  137.       }
  138.       if (p != name)
  139. --- 2913,2919 ----
  140.       for (p = name; *p && *p != ':'; p++)
  141.       {
  142.       if (p - name + 1 > LF_FACESIZE)
  143. !         goto theend;            /* Name too long */
  144.       lf->lfFaceName[p - name] = *p;
  145.       }
  146.       if (p != name)
  147. ***************
  148. *** 2927,2933 ****
  149.           did_replace = TRUE;
  150.           }
  151.       if (!did_replace || init_logfont(lf) == FAIL)
  152. !         return FAIL;
  153.       }
  154.   
  155.       while (*p == ':')
  156. --- 2941,2947 ----
  157.           did_replace = TRUE;
  158.           }
  159.       if (!did_replace || init_logfont(lf) == FAIL)
  160. !         goto theend;
  161.       }
  162.   
  163.       while (*p == ':')
  164. ***************
  165. *** 2988,3012 ****
  166.                   p[-1], name);
  167.               EMSG(IObuff);
  168.           }
  169. !         return FAIL;
  170.       }
  171.       while (*p == ':')
  172.           p++;
  173.       }
  174.   
  175. - #if defined(FEAT_GUI_W32)
  176.   theend:
  177. - #endif
  178.       /* ron: init lastlf */
  179. !     if (printer_dc == NULL)
  180.       {
  181.       vim_free(lastlf);
  182.       lastlf = (LOGFONT *)alloc(sizeof(LOGFONT));
  183.       if (lastlf != NULL)
  184.           mch_memmove(lastlf, lf, sizeof(LOGFONT));
  185.       }
  186.   
  187. !     return OK;
  188.   }
  189.   
  190.   #endif /* defined(FEAT_GUI) || defined(FEAT_PRINTER) */
  191. --- 3002,3028 ----
  192.                   p[-1], name);
  193.               EMSG(IObuff);
  194.           }
  195. !         goto theend;
  196.       }
  197.       while (*p == ':')
  198.           p++;
  199.       }
  200. +     ret = OK;
  201.   
  202.   theend:
  203.       /* ron: init lastlf */
  204. !     if (ret == OK && printer_dc == NULL)
  205.       {
  206.       vim_free(lastlf);
  207.       lastlf = (LOGFONT *)alloc(sizeof(LOGFONT));
  208.       if (lastlf != NULL)
  209.           mch_memmove(lastlf, lf, sizeof(LOGFONT));
  210.       }
  211. + #ifdef FEAT_MBYTE
  212. +     vim_free(acpname);
  213. + #endif
  214.   
  215. !     return ret;
  216.   }
  217.   
  218.   #endif /* defined(FEAT_GUI) || defined(FEAT_PRINTER) */
  219. *** ../vim-7.4.201/src/proto/winclip.pro    2013-08-10 13:37:39.000000000 +0200
  220. --- src/proto/winclip.pro    2014-03-12 19:18:14.264927370 +0100
  221. ***************
  222. *** 11,14 ****
  223. --- 11,15 ----
  224.   short_u *enc_to_utf16 __ARGS((char_u *str, int *lenp));
  225.   char_u *utf16_to_enc __ARGS((short_u *str, int *lenp));
  226.   void acp_to_enc __ARGS((char_u *str, int str_size, char_u **out, int *outlen));
  227. + void enc_to_acp __ARGS((char_u *str, int str_size, char_u **out, int *outlen));
  228.   /* vim: set ft=c : */
  229. *** ../vim-7.4.201/src/winclip.c    2013-07-01 21:05:53.000000000 +0200
  230. --- src/winclip.c    2014-03-12 19:18:14.264927370 +0100
  231. ***************
  232. *** 797,800 ****
  233. --- 797,825 ----
  234.       vim_free(widestr);
  235.       }
  236.   }
  237. + /*
  238. +  * Convert from 'encoding' to the active codepage.
  239. +  * Input is "str[str_size]".
  240. +  * The result is in allocated memory: "out[outlen]".  With terminating NUL.
  241. +  */
  242. +     void
  243. + enc_to_acp(str, str_size, out, outlen)
  244. +     char_u    *str;
  245. +     int        str_size;
  246. +     char_u    **out;
  247. +     int        *outlen;
  248. + {
  249. +     LPWSTR    widestr;
  250. +     int        len = str_size;
  251. +     widestr = (WCHAR *)enc_to_utf16(str, &len);
  252. +     if (widestr != NULL)
  253. +     {
  254. +     WideCharToMultiByte_alloc(GetACP(), 0, widestr, len,
  255. +                         (LPSTR *)out, outlen, 0, 0);
  256. +     vim_free(widestr);
  257. +     }
  258. + }
  259.   #endif
  260. *** ../vim-7.4.201/src/version.c    2014-03-12 18:55:52.104906804 +0100
  261. --- src/version.c    2014-03-12 19:19:01.388928092 +0100
  262. ***************
  263. *** 740,741 ****
  264. --- 740,743 ----
  265.   {   /* Add new patch number below this line */
  266. + /**/
  267. +     202,
  268.   /**/
  269.  
  270. -- 
  271. <Beeth> Girls are like internet domain names,
  272.         the ones I like are already taken.
  273. <honx>  Well, you can stil get one from a strange country :-P
  274.  
  275.  /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net   \\\
  276. ///        sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ \\\
  277. \\\  an exciting new programming language -- http://www.Zimbu.org        ///
  278.  \\\            help me help AIDS victims -- http://ICCF-Holland.org    ///
  279.