aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJason Rumney2003-10-12 22:47:33 +0000
committerJason Rumney2003-10-12 22:47:33 +0000
commitf1de3410d2982719628a0d6c7e4119a6bcd08422 (patch)
treee96fc398315275ea4082a12d058385669367598f /src
parentbc78cf6e0c3225a77e0297ff91df3d3ff2dc7211 (diff)
downloademacs-f1de3410d2982719628a0d6c7e4119a6bcd08422.tar.gz
emacs-f1de3410d2982719628a0d6c7e4119a6bcd08422.zip
(w32_load_system_font): Default charset to -1.
(x_to_w32_charset): Match all fonts for unicode. (w32_to_x_charset): New parameter; matching. Don't return partial or wildcard charsets. (w32_to_all_x_charsets): Don't return partial or wildcard charsets. (w32_codepage_for_font): Return CP_UNICODE for unicode. (w32_to_x_font): Match supplied charset to a real charset. (enum_font_cb2): Always list unicode versions.
Diffstat (limited to 'src')
-rw-r--r--src/w32fns.c106
1 files changed, 83 insertions, 23 deletions
diff --git a/src/w32fns.c b/src/w32fns.c
index bf271cfa449..5d6e88b62ce 100644
--- a/src/w32fns.c
+++ b/src/w32fns.c
@@ -4791,7 +4791,7 @@ w32_load_system_font (f,fontname,size)
4791 fontp->name = (char *) xmalloc (strlen (fontname) + 1); 4791 fontp->name = (char *) xmalloc (strlen (fontname) + 1);
4792 bcopy (fontname, fontp->name, strlen (fontname) + 1); 4792 bcopy (fontname, fontp->name, strlen (fontname) + 1);
4793 4793
4794 fontp->charset = charset_unicode; 4794 fontp->charset = -1;
4795 charset = xlfd_charset_of_font (fontname); 4795 charset = xlfd_charset_of_font (fontname);
4796 4796
4797 /* Cache the W32 codepage for a font. This makes w32_encode_char 4797 /* Cache the W32 codepage for a font. This makes w32_encode_char
@@ -4970,12 +4970,16 @@ x_to_w32_charset (lpcs)
4970 if (strncmp (lpcs, "*-#", 3) == 0) 4970 if (strncmp (lpcs, "*-#", 3) == 0)
4971 return atoi (lpcs + 3); 4971 return atoi (lpcs + 3);
4972 4972
4973 /* All Windows fonts qualify as unicode. */
4974 if (!strncmp (lpcs, "iso10646", 8))
4975 return DEFAULT_CHARSET;
4976
4973 /* Handle wildcards by ignoring them; eg. treat "big5*-*" as "big5". */ 4977 /* Handle wildcards by ignoring them; eg. treat "big5*-*" as "big5". */
4974 charset = alloca (len + 1); 4978 charset = alloca (len + 1);
4975 strcpy (charset, lpcs); 4979 strcpy (charset, lpcs);
4976 lpcs = strchr (charset, '*'); 4980 lpcs = strchr (charset, '*');
4977 if (lpcs) 4981 if (lpcs)
4978 *lpcs = 0; 4982 *lpcs = '\0';
4979 4983
4980 /* Look through w32-charset-info-alist for the character set. 4984 /* Look through w32-charset-info-alist for the character set.
4981 Format of each entry is 4985 Format of each entry is
@@ -5043,11 +5047,26 @@ x_to_w32_charset (lpcs)
5043 5047
5044 5048
5045static char * 5049static char *
5046w32_to_x_charset (fncharset) 5050w32_to_x_charset (fncharset, matching)
5047 int fncharset; 5051 int fncharset;
5052 char *matching;
5048{ 5053{
5049 static char buf[32]; 5054 static char buf[32];
5050 Lisp_Object charset_type; 5055 Lisp_Object charset_type;
5056 int match_len = 0;
5057
5058 if (matching)
5059 {
5060 /* If fully specified, accept it as it is. Otherwise use a
5061 substring match. */
5062 char *wildcard = strchr (matching, '*');
5063 if (wildcard)
5064 *wildcard = '\0';
5065 else if (strchr (matching, '-'))
5066 return matching;
5067
5068 match_len = strlen (matching);
5069 }
5051 5070
5052 switch (fncharset) 5071 switch (fncharset)
5053 { 5072 {
@@ -5132,6 +5151,7 @@ w32_to_x_charset (fncharset)
5132 { 5151 {
5133 Lisp_Object rest; 5152 Lisp_Object rest;
5134 char * best_match = NULL; 5153 char * best_match = NULL;
5154 int matching_found = 0;
5135 5155
5136 /* Look through w32-charset-info-alist for the character set. 5156 /* Look through w32-charset-info-alist for the character set.
5137 Prefer ISO codepages, and prefer lower numbers in the ISO 5157 Prefer ISO codepages, and prefer lower numbers in the ISO
@@ -5167,12 +5187,34 @@ w32_to_x_charset (fncharset)
5167 /* If we don't have a match already, then this is the 5187 /* If we don't have a match already, then this is the
5168 best. */ 5188 best. */
5169 if (!best_match) 5189 if (!best_match)
5170 best_match = x_charset; 5190 {
5171 /* If this is an ISO codepage, and the best so far isn't, 5191 best_match = x_charset;
5172 then this is better. */ 5192 if (matching && !strnicmp (x_charset, matching, match_len))
5173 else if (strnicmp (best_match, "iso", 3) != 0 5193 matching_found = 1;
5174 && strnicmp (x_charset, "iso", 3) == 0) 5194 }
5175 best_match = x_charset; 5195 /* If we already found a match for MATCHING, then
5196 only consider other matches. */
5197 else if (matching_found
5198 && strnicmp (x_charset, matching, match_len))
5199 continue;
5200 /* If this matches what we want, and the best so far doesn't,
5201 then this is better. */
5202 else if (!matching_found && matching
5203 && !strnicmp (x_charset, matching, match_len))
5204 {
5205 best_match = x_charset;
5206 matching_found = 1;
5207 }
5208 /* If this is fully specified, and the best so far isn't,
5209 then this is better. */
5210 else if ((!strchr (best_match, '-') && strchr (x_charset, '-'))
5211 /* If this is an ISO codepage, and the best so far isn't,
5212 then this is better, but only if it fully specifies the
5213 encoding. */
5214 || (strnicmp (best_match, "iso", 3) != 0
5215 && strnicmp (x_charset, "iso", 3) == 0
5216 && strchr (x_charset, '-')))
5217 best_match = x_charset;
5176 /* If both are ISO8859 codepages, choose the one with the 5218 /* If both are ISO8859 codepages, choose the one with the
5177 lowest number in the encoding field. */ 5219 lowest number in the encoding field. */
5178 else if (strnicmp (best_match, "iso8859-", 8) == 0 5220 else if (strnicmp (best_match, "iso8859-", 8) == 0
@@ -5193,7 +5235,18 @@ w32_to_x_charset (fncharset)
5193 return buf; 5235 return buf;
5194 } 5236 }
5195 5237
5196 strncpy(buf, best_match, 31); 5238 strncpy (buf, best_match, 31);
5239 /* If the charset is not fully specified, put -0 on the end. */
5240 if (!strchr (best_match, '-'))
5241 {
5242 int pos = strlen (best_match);
5243 /* Charset specifiers shouldn't be very long. If it is a made
5244 up one, truncating it should not do any harm since it isn't
5245 recognized anyway. */
5246 if (pos > 29)
5247 pos = 29;
5248 strcpy (buf + pos, "-0");
5249 }
5197 buf[31] = '\0'; 5250 buf[31] = '\0';
5198 return buf; 5251 return buf;
5199 } 5252 }
@@ -5293,7 +5346,8 @@ w32_to_all_x_charsets (fncharset)
5293 { 5346 {
5294 Lisp_Object rest; 5347 Lisp_Object rest;
5295 /* Look through w32-charset-info-alist for the character set. 5348 /* Look through w32-charset-info-alist for the character set.
5296 Only return charsets for codepages which are installed. 5349 Only return fully specified charsets for codepages which are
5350 installed.
5297 5351
5298 Format of each entry in Vw32_charset_info_alist is 5352 Format of each entry in Vw32_charset_info_alist is
5299 (CHARSET_NAME . (WINDOWS_CHARSET . CODEPAGE)). 5353 (CHARSET_NAME . (WINDOWS_CHARSET . CODEPAGE)).
@@ -5316,6 +5370,9 @@ w32_to_all_x_charsets (fncharset)
5316 w32_charset = XCAR (XCDR (this_entry)); 5370 w32_charset = XCAR (XCDR (this_entry));
5317 codepage = XCDR (XCDR (this_entry)); 5371 codepage = XCDR (XCDR (this_entry));
5318 5372
5373 if (!strchr (SDATA (x_charset), '-'))
5374 continue;
5375
5319 /* Look for Same charset and a valid codepage (or non-int 5376 /* Look for Same charset and a valid codepage (or non-int
5320 which means ignore). */ 5377 which means ignore). */
5321 if (w32_charset == charset_type 5378 if (w32_charset == charset_type
@@ -5346,9 +5403,6 @@ w32_codepage_for_font (char *fontname)
5346 Lisp_Object codepage, entry; 5403 Lisp_Object codepage, entry;
5347 char *charset_str, *charset, *end; 5404 char *charset_str, *charset, *end;
5348 5405
5349 if (NILP (Vw32_charset_info_alist))
5350 return CP_DEFAULT;
5351
5352 /* Extract charset part of font string. */ 5406 /* Extract charset part of font string. */
5353 charset = xlfd_charset_of_font (fontname); 5407 charset = xlfd_charset_of_font (fontname);
5354 5408
@@ -5374,6 +5428,12 @@ w32_codepage_for_font (char *fontname)
5374 *end = '\0'; 5428 *end = '\0';
5375 } 5429 }
5376 5430
5431 if (!strcmp (charset, "iso10646"))
5432 return CP_UNICODE;
5433
5434 if (NILP (Vw32_charset_info_alist))
5435 return CP_DEFAULT;
5436
5377 entry = Fassoc (build_string(charset), Vw32_charset_info_alist); 5437 entry = Fassoc (build_string(charset), Vw32_charset_info_alist);
5378 if (NILP (entry)) 5438 if (NILP (entry))
5379 return CP_UNKNOWN; 5439 return CP_UNKNOWN;
@@ -5474,8 +5534,7 @@ w32_to_x_font (lplogfont, lpxstr, len, specific_charset)
5474 ((lplogfont->lfPitchAndFamily & 0x3) == VARIABLE_PITCH) 5534 ((lplogfont->lfPitchAndFamily & 0x3) == VARIABLE_PITCH)
5475 ? 'p' : 'c', /* spacing */ 5535 ? 'p' : 'c', /* spacing */
5476 width_pixels, /* avg width */ 5536 width_pixels, /* avg width */
5477 specific_charset ? specific_charset 5537 w32_to_x_charset (lplogfont->lfCharSet, specific_charset)
5478 : w32_to_x_charset (lplogfont->lfCharSet)
5479 /* charset registry and encoding */ 5538 /* charset registry and encoding */
5480 ); 5539 );
5481 5540
@@ -5946,14 +6005,17 @@ enum_font_cb2 (lplf, lptm, FontType, lpef)
5946 if (charset 6005 if (charset
5947 && strncmp (charset, "*-*", 3) != 0 6006 && strncmp (charset, "*-*", 3) != 0
5948 && lpef->logfont.lfCharSet == DEFAULT_CHARSET 6007 && lpef->logfont.lfCharSet == DEFAULT_CHARSET
5949 && strcmp (charset, w32_to_x_charset (DEFAULT_CHARSET)) != 0) 6008 && strcmp (charset, w32_to_x_charset (DEFAULT_CHARSET, NULL)) != 0)
5950 return 1; 6009 return 1;
5951 } 6010 }
5952 6011
5953 if (charset) 6012 if (charset)
5954 charset_list = Fcons (build_string (charset), Qnil); 6013 charset_list = Fcons (build_string (charset), Qnil);
5955 else 6014 else
5956 charset_list = w32_to_all_x_charsets (lplf->elfLogFont.lfCharSet); 6015 /* Always prefer unicode. */
6016 charset_list
6017 = Fcons (build_string ("iso10646-1"),
6018 w32_to_all_x_charsets (lplf->elfLogFont.lfCharSet));
5957 6019
5958 /* Loop through the charsets. */ 6020 /* Loop through the charsets. */
5959 for ( ; CONSP (charset_list); charset_list = Fcdr (charset_list)) 6021 for ( ; CONSP (charset_list); charset_list = Fcdr (charset_list))
@@ -5961,14 +6023,15 @@ enum_font_cb2 (lplf, lptm, FontType, lpef)
5961 Lisp_Object this_charset = Fcar (charset_list); 6023 Lisp_Object this_charset = Fcar (charset_list);
5962 charset = SDATA (this_charset); 6024 charset = SDATA (this_charset);
5963 6025
6026 enum_font_maybe_add_to_list (lpef, &(lplf->elfLogFont),
6027 charset, width);
6028
5964 /* List bold and italic variations if w32-enable-synthesized-fonts 6029 /* List bold and italic variations if w32-enable-synthesized-fonts
5965 is non-nil and this is a plain font. */ 6030 is non-nil and this is a plain font. */
5966 if (w32_enable_synthesized_fonts 6031 if (w32_enable_synthesized_fonts
5967 && lplf->elfLogFont.lfWeight == FW_NORMAL 6032 && lplf->elfLogFont.lfWeight == FW_NORMAL
5968 && lplf->elfLogFont.lfItalic == FALSE) 6033 && lplf->elfLogFont.lfItalic == FALSE)
5969 { 6034 {
5970 enum_font_maybe_add_to_list (lpef, &(lplf->elfLogFont),
5971 charset, width);
5972 /* bold. */ 6035 /* bold. */
5973 lplf->elfLogFont.lfWeight = FW_BOLD; 6036 lplf->elfLogFont.lfWeight = FW_BOLD;
5974 enum_font_maybe_add_to_list (lpef, &(lplf->elfLogFont), 6037 enum_font_maybe_add_to_list (lpef, &(lplf->elfLogFont),
@@ -5982,9 +6045,6 @@ enum_font_cb2 (lplf, lptm, FontType, lpef)
5982 enum_font_maybe_add_to_list (lpef, &(lplf->elfLogFont), 6045 enum_font_maybe_add_to_list (lpef, &(lplf->elfLogFont),
5983 charset, width); 6046 charset, width);
5984 } 6047 }
5985 else
5986 enum_font_maybe_add_to_list (lpef, &(lplf->elfLogFont),
5987 charset, width);
5988 } 6048 }
5989 } 6049 }
5990 6050