comparison src/w32fns.c @ 89594:169b2685d6f6

(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.
author Jason Rumney <jasonr@gnu.org>
date Sun, 12 Oct 2003 22:47:33 +0000
parents f89c9d4bd81c
children 68c22ea6027c
comparison
equal deleted inserted replaced
89593:45b6fc5c8be5 89594:169b2685d6f6
4789 fontp->font = font; 4789 fontp->font = font;
4790 fontp->font_idx = i; 4790 fontp->font_idx = i;
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
4798 (called for every glyph during redisplay) much faster. */ 4798 (called for every glyph during redisplay) much faster. */
4799 fontp->codepage = codepage; 4799 fontp->codepage = codepage;
4968 4968
4969 /* Support "*-#nnn" format for unknown charsets. */ 4969 /* Support "*-#nnn" format for unknown charsets. */
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
4982 (CHARSET_NAME . (WINDOWS_CHARSET . CODEPAGE)). 4986 (CHARSET_NAME . (WINDOWS_CHARSET . CODEPAGE)).
4983 */ 4987 */
5041 return DEFAULT_CHARSET; 5045 return DEFAULT_CHARSET;
5042 } 5046 }
5043 5047
5044 5048
5045 static char * 5049 static char *
5046 w32_to_x_charset (fncharset) 5050 w32_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 {
5054 case ANSI_CHARSET: 5073 case ANSI_CHARSET:
5055 /* Handle startup case of w32-charset-info-alist not 5074 /* Handle startup case of w32-charset-info-alist not
5130 } 5149 }
5131 5150
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
5138 range. Only return charsets for codepages which are installed. 5158 range. Only return charsets for codepages which are installed.
5139 5159
5165 || IsValidCodePage (XINT (codepage)))) 5185 || IsValidCodePage (XINT (codepage))))
5166 { 5186 {
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
5179 && strnicmp (x_charset, "iso8859-", 8) == 0) 5221 && strnicmp (x_charset, "iso8859-", 8) == 0)
5180 { 5222 {
5191 { 5233 {
5192 sprintf (buf, "*-#%u", fncharset); 5234 sprintf (buf, "*-#%u", 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 }
5200 } 5253 }
5201 5254
5291 } 5344 }
5292 5345
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)).
5300 */ 5354 */
5301 for (rest = Vw32_charset_info_alist; CONSP (rest); rest = XCDR (rest)) 5355 for (rest = Vw32_charset_info_alist; CONSP (rest); rest = XCDR (rest))
5313 continue; 5367 continue;
5314 5368
5315 x_charset = XCAR (this_entry); 5369 x_charset = XCAR (this_entry);
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));
5372
5373 if (!strchr (SDATA (x_charset), '-'))
5374 continue;
5318 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
5322 && (!INTEGERP (codepage) || codepage == CP_DEFAULT 5379 && (!INTEGERP (codepage) || codepage == CP_DEFAULT
5344 w32_codepage_for_font (char *fontname) 5401 w32_codepage_for_font (char *fontname)
5345 { 5402 {
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
5355 if (!charset) 5409 if (!charset)
5356 return CP_UNKNOWN; 5410 return CP_UNKNOWN;
5371 { 5425 {
5372 if (end > charset && *(end-1) == '-') 5426 if (end > charset && *(end-1) == '-')
5373 end--; 5427 end--;
5374 *end = '\0'; 5428 *end = '\0';
5375 } 5429 }
5430
5431 if (!strcmp (charset, "iso10646"))
5432 return CP_UNICODE;
5433
5434 if (NILP (Vw32_charset_info_alist))
5435 return CP_DEFAULT;
5376 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;
5380 5440
5472 display_resx, /* resx */ 5532 display_resx, /* resx */
5473 display_resy, /* resy */ 5533 display_resy, /* resy */
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
5482 lpxstr[len - 1] = 0; /* just to be sure */ 5541 lpxstr[len - 1] = 0; /* just to be sure */
5483 return (TRUE); 5542 return (TRUE);
5944 /* We already checked charsets above, but DEFAULT_CHARSET 6003 /* We already checked charsets above, but DEFAULT_CHARSET
5945 slipped through. So only allow exact matches for DEFAULT_CHARSET. */ 6004 slipped through. So only allow exact matches for DEFAULT_CHARSET. */
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))
5960 { 6022 {
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);
6025
6026 enum_font_maybe_add_to_list (lpef, &(lplf->elfLogFont),
6027 charset, width);
5963 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),
5975 charset, width); 6038 charset, width);
5976 /* bold italic. */ 6039 /* bold italic. */
5980 /* italic. */ 6043 /* italic. */
5981 lplf->elfLogFont.lfWeight = FW_NORMAL; 6044 lplf->elfLogFont.lfWeight = FW_NORMAL;
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
5991 return 1; 6051 return 1;
5992 } 6052 }