comparison src/w32fns.c @ 39548:6192be048459

(x_to_w32_color): Fix argument to alloca. (w32_load_system_font): Don't believe what GetLanguageFontInfo says; query codepage info directly to determine if font is double byte. (x_to_w32_charset): Handle private format for unknown charsets. Handle wildcards in charset spec, by ignoring them. (w32_codepage_for_font): Fix argument to alloca. Don't remove "*-" prefix from charset. (x_to_w32_font): Enlarge remainder array for safety. Specifically handle the truncated font spec form constructed by font_list_1, so that we correctly identify the charset fields. Don't remove "*-" prefix from charset. (w32_list_synthesized_fonts): Fix argument to alloca.
author Andrew Innes <andrewi@gnu.org>
date Thu, 04 Oct 2001 17:14:01 +0000
parents 2d2b989f4a4b
children 66e0816837a8
comparison
equal deleted inserted replaced
39547:99e89f7ad24e 39548:6192be048459
1644 { 1644 {
1645 int len = strlen (colorname); 1645 int len = strlen (colorname);
1646 1646
1647 if (isdigit (colorname[len - 1])) 1647 if (isdigit (colorname[len - 1]))
1648 { 1648 {
1649 char *ptr, *approx = alloca (len); 1649 char *ptr, *approx = alloca (len + 1);
1650 1650
1651 strcpy (approx, colorname); 1651 strcpy (approx, colorname);
1652 ptr = &approx[len - 1]; 1652 ptr = &approx[len - 1];
1653 while (ptr > approx && isdigit (*ptr)) 1653 while (ptr > approx && isdigit (*ptr))
1654 *ptr-- = '\0'; 1654 *ptr-- = '\0';
5623 5623
5624 ok = GetTextMetrics (hdc, &font->tm); 5624 ok = GetTextMetrics (hdc, &font->tm);
5625 if (codepage == CP_UNICODE) 5625 if (codepage == CP_UNICODE)
5626 font->double_byte_p = 1; 5626 font->double_byte_p = 1;
5627 else 5627 else
5628 font->double_byte_p = GetFontLanguageInfo(hdc) & GCP_DBCS; 5628 {
5629 /* Unfortunately, some fonts (eg. MingLiU, a big5 ttf font)
5630 don't report themselves as double byte fonts, when
5631 patently they are. So instead of trusting
5632 GetFontLanguageInfo, we check the properties of the
5633 codepage directly, since that is ultimately what we are
5634 working from anyway. */
5635 /* font->double_byte_p = GetFontLanguageInfo(hdc) & GCP_DBCS; */
5636 CPINFO cpi = {0};
5637 GetCPInfo (codepage, &cpi);
5638 font->double_byte_p = cpi.MaxCharSize > 1;
5639 }
5629 5640
5630 SelectObject (hdc, oldobj); 5641 SelectObject (hdc, oldobj);
5631 ReleaseDC (dpyinfo->root_window, hdc); 5642 ReleaseDC (dpyinfo->root_window, hdc);
5632 /* Fill out details in lf according to the font that was 5643 /* Fill out details in lf according to the font that was
5633 actually loaded. */ 5644 actually loaded. */
5844 static LONG 5855 static LONG
5845 x_to_w32_charset (lpcs) 5856 x_to_w32_charset (lpcs)
5846 char * lpcs; 5857 char * lpcs;
5847 { 5858 {
5848 Lisp_Object this_entry, w32_charset; 5859 Lisp_Object this_entry, w32_charset;
5860 char *charset;
5861 int len = strlen (lpcs);
5862
5863 /* Support "*-#nnn" format for unknown charsets. */
5864 if (strncmp (lpcs, "*-#", 3) == 0)
5865 return atoi (lpcs + 3);
5866
5867 /* Handle wildcards by ignoring them; eg. treat "big5*-*" as "big5". */
5868 charset = alloca (len + 1);
5869 strcpy (charset, lpcs);
5870 lpcs = strchr (charset, '*');
5871 if (lpcs)
5872 *lpcs = 0;
5849 5873
5850 /* Look through w32-charset-info-alist for the character set. 5874 /* Look through w32-charset-info-alist for the character set.
5851 Format of each entry is 5875 Format of each entry is
5852 (CHARSET_NAME . (WINDOWS_CHARSET . CODEPAGE)). 5876 (CHARSET_NAME . (WINDOWS_CHARSET . CODEPAGE)).
5853 */ 5877 */
5854 this_entry = Fassoc (build_string(lpcs), Vw32_charset_info_alist); 5878 this_entry = Fassoc (build_string(charset), Vw32_charset_info_alist);
5855 5879
5856 if (NILP(this_entry)) 5880 if (NILP(this_entry))
5857 { 5881 {
5858 /* At startup, we want iso8859-1 fonts to come up properly. */ 5882 /* At startup, we want iso8859-1 fonts to come up properly. */
5859 if (stricmp(lpcs, "iso8859-1") == 0) 5883 if (stricmp(charset, "iso8859-1") == 0)
5860 return ANSI_CHARSET; 5884 return ANSI_CHARSET;
5861 else 5885 else
5862 return DEFAULT_CHARSET; 5886 return DEFAULT_CHARSET;
5863 } 5887 }
5864 5888
6086 charset = xlfd_charset_of_font (fontname); 6110 charset = xlfd_charset_of_font (fontname);
6087 6111
6088 if (!charset) 6112 if (!charset)
6089 return CP_UNKNOWN; 6113 return CP_UNKNOWN;
6090 6114
6091 charset_str = (char *) alloca (strlen (charset)); 6115 charset_str = (char *) alloca (strlen (charset) + 1);
6092 strcpy (charset_str, charset); 6116 strcpy (charset_str, charset);
6093 6117
6118 #if 0
6094 /* Remove leading "*-". */ 6119 /* Remove leading "*-". */
6095 if (strncmp ("*-", charset_str, 2) == 0) 6120 if (strncmp ("*-", charset_str, 2) == 0)
6096 charset = charset_str + 2; 6121 charset = charset_str + 2;
6097 else 6122 else
6123 #endif
6098 charset = charset_str; 6124 charset = charset_str;
6099 6125
6100 /* Stop match at wildcard (including preceding '-'). */ 6126 /* Stop match at wildcard (including preceding '-'). */
6101 if (end = strchr (charset, '*')) 6127 if (end = strchr (charset, '*'))
6102 { 6128 {
6248 6274
6249 if (*lpxstr == '-') 6275 if (*lpxstr == '-')
6250 { 6276 {
6251 int fields, tem; 6277 int fields, tem;
6252 char name[50], weight[20], slant, pitch, pixels[10], height[10], 6278 char name[50], weight[20], slant, pitch, pixels[10], height[10],
6253 width[10], resy[10], remainder[20]; 6279 width[10], resy[10], remainder[50];
6254 char * encoding; 6280 char * encoding;
6255 int dpi = one_w32_display_info.resy; 6281 int dpi = one_w32_display_info.resy;
6256 6282
6257 fields = sscanf (lpxstr, 6283 fields = sscanf (lpxstr,
6258 "-%*[^-]-%49[^-]-%19[^-]-%c-%*[^-]-%*[^-]-%9[^-]-%9[^-]-%*[^-]-%9[^-]-%c-%9[^-]-%19s", 6284 "-%*[^-]-%49[^-]-%19[^-]-%c-%*[^-]-%*[^-]-%9[^-]-%9[^-]-%*[^-]-%9[^-]-%c-%9[^-]-%49s",
6259 name, weight, &slant, pixels, height, resy, &pitch, width, remainder); 6285 name, weight, &slant, pixels, height, resy, &pitch, width, remainder);
6260 if (fields == EOF) return (FALSE); 6286 if (fields == EOF)
6261 6287 return (FALSE);
6262 /* If wildcards cover more than one field, we don't know which 6288
6263 field is which, so don't fill any in. */ 6289 /* In the general case when wildcards cover more than one field,
6264 6290 we don't know which field is which, so don't fill any in.
6265 if (fields < 9) 6291 However, we need to cope with this particular form, which is
6266 fields = 0; 6292 generated by font_list_1 (invoked by try_font_list):
6293 "-raster-6x10-*-gb2312*-*"
6294 and make sure to correctly parse the charset field. */
6295 if (fields == 3)
6296 {
6297 fields = sscanf (lpxstr,
6298 "-%*[^-]-%49[^-]-*-%49s",
6299 name, remainder);
6300 }
6301 else if (fields < 9)
6302 {
6303 fields = 0;
6304 remainder[0] = 0;
6305 }
6267 6306
6268 if (fields > 0 && name[0] != '*') 6307 if (fields > 0 && name[0] != '*')
6269 { 6308 {
6270 int bufsize; 6309 int bufsize;
6271 unsigned char *buf; 6310 unsigned char *buf;
6329 int len = strlen (remainder); 6368 int len = strlen (remainder);
6330 if (len > 0 && remainder[len-1] == '-') 6369 if (len > 0 && remainder[len-1] == '-')
6331 remainder[len-1] = 0; 6370 remainder[len-1] = 0;
6332 } 6371 }
6333 encoding = remainder; 6372 encoding = remainder;
6373 #if 0
6334 if (strncmp (encoding, "*-", 2) == 0) 6374 if (strncmp (encoding, "*-", 2) == 0)
6335 encoding += 2; 6375 encoding += 2;
6336 lplogfont->lfCharSet = x_to_w32_charset (fields > 0 ? encoding : ""); 6376 #endif
6377 lplogfont->lfCharSet = x_to_w32_charset (encoding);
6337 } 6378 }
6338 else 6379 else
6339 { 6380 {
6340 int fields; 6381 int fields;
6341 char name[100], height[10], width[10], weight[20]; 6382 char name[100], height[10], width[10], weight[20];
6951 char style[20], slant; 6992 char style[20], slant;
6952 Lisp_Object matches, tem, synthed_matches = Qnil; 6993 Lisp_Object matches, tem, synthed_matches = Qnil;
6953 6994
6954 full_pattn = XSTRING (pattern)->data; 6995 full_pattn = XSTRING (pattern)->data;
6955 6996
6956 pattn_part2 = alloca (XSTRING (pattern)->size); 6997 pattn_part2 = alloca (XSTRING (pattern)->size + 1);
6957 /* Allow some space for wildcard expansion. */ 6998 /* Allow some space for wildcard expansion. */
6958 new_pattn = alloca (XSTRING (pattern)->size + 100); 6999 new_pattn = alloca (XSTRING (pattern)->size + 100);
6959 7000
6960 fields = sscanf (full_pattn, "-%49[^-]-%49[^-]-%19[^-]-%c-%s", 7001 fields = sscanf (full_pattn, "-%49[^-]-%49[^-]-%19[^-]-%c-%s",
6961 foundary, family, style, &slant, pattn_part2); 7002 foundary, family, style, &slant, pattn_part2);