Mercurial > emacs
comparison src/macterm.c @ 59034:2dd8aacd82ce
* term/mac-win.el (encoding-vector, mac-font-encoder-list)
(ccl-encode-mac-centraleurroman-font): Use centraleurroman
instead of centraleuropean as the name
* macterm.c (endif, x_font_name_to_mac_font_name): Use
maccentraleurroman instead of maccentraleuropean
(mac_c_string_match, mac_do_list_fonts): Speed up font search by
quickly finding a specific font without needing regexps.
author | Steven Tamm <steventamm@mac.com> |
---|---|
date | Sat, 18 Dec 2004 16:36:31 +0000 |
parents | 95d38c47c806 |
children | b978ab01b88e |
comparison
equal
deleted
inserted
replaced
59033:baa093a1f30a | 59034:2dd8aacd82ce |
---|---|
5974 #if TARGET_API_MAC_CARBON | 5974 #if TARGET_API_MAC_CARBON |
5975 case kTextEncodingMacCyrillic: | 5975 case kTextEncodingMacCyrillic: |
5976 strcpy(cs, "mac-cyrillic"); | 5976 strcpy(cs, "mac-cyrillic"); |
5977 break; | 5977 break; |
5978 case kTextEncodingMacCentralEurRoman: | 5978 case kTextEncodingMacCentralEurRoman: |
5979 strcpy(cs, "mac-centraleuropean"); | 5979 strcpy(cs, "mac-centraleurroman"); |
5980 break; | 5980 break; |
5981 case kTextEncodingMacSymbol: | 5981 case kTextEncodingMacSymbol: |
5982 case kTextEncodingMacDingbats: | 5982 case kTextEncodingMacDingbats: |
5983 strcpy(cs, "adobe-fontspecific"); | 5983 strcpy(cs, "adobe-fontspecific"); |
5984 break; | 5984 break; |
6032 coding_system = Qsjis; | 6032 coding_system = Qsjis; |
6033 else if (strcmp (cs, "ksc5601.1989-0") == 0) | 6033 else if (strcmp (cs, "ksc5601.1989-0") == 0) |
6034 coding_system = Qeuc_kr; | 6034 coding_system = Qeuc_kr; |
6035 else if (strcmp (cs, "mac-roman") == 0 | 6035 else if (strcmp (cs, "mac-roman") == 0 |
6036 || strcmp (cs, "mac-cyrillic") == 0 | 6036 || strcmp (cs, "mac-cyrillic") == 0 |
6037 || strcmp (cs, "mac-centraleuropean") == 0 | 6037 || strcmp (cs, "mac-centraleurroman") == 0 |
6038 || strcmp (cs, "adobe-fontspecific") == 0) | 6038 || strcmp (cs, "adobe-fontspecific") == 0) |
6039 strcpy (mf, family); | 6039 strcpy (mf, family); |
6040 else | 6040 else |
6041 sprintf (mf, "%s-%s-%s", foundry, family, cs); | 6041 sprintf (mf, "%s-%s-%s", foundry, family, cs); |
6042 | 6042 |
6274 11, /* AVGWIDTH */ | 6274 11, /* AVGWIDTH */ |
6275 -1 | 6275 -1 |
6276 }; | 6276 }; |
6277 | 6277 |
6278 static Lisp_Object | 6278 static Lisp_Object |
6279 mac_c_string_match (regexp, string, nonspecial, exact) | |
6280 Lisp_Object regexp; | |
6281 const char *string, *nonspecial; | |
6282 int exact; | |
6283 { | |
6284 if (exact) | |
6285 { | |
6286 if (strcmp (string, nonspecial) == 0) | |
6287 return build_string (string); | |
6288 } | |
6289 else if (strstr (string, nonspecial)) | |
6290 { | |
6291 Lisp_Object str = build_string (string); | |
6292 | |
6293 if (fast_string_match (regexp, str) >= 0) | |
6294 return str; | |
6295 } | |
6296 | |
6297 return Qnil; | |
6298 } | |
6299 | |
6300 static Lisp_Object | |
6279 mac_do_list_fonts (pattern, maxnames) | 6301 mac_do_list_fonts (pattern, maxnames) |
6280 char *pattern; | 6302 char *pattern; |
6281 int maxnames; | 6303 int maxnames; |
6282 { | 6304 { |
6283 int i, n_fonts = 0; | 6305 int i, n_fonts = 0; |
6284 Lisp_Object font_list = Qnil, pattern_regex, fontname; | 6306 Lisp_Object font_list = Qnil, pattern_regex, fontname; |
6285 char *regex = (char *) alloca (strlen (pattern) * 2 + 3); | 6307 char *regex = (char *) alloca (strlen (pattern) * 2 + 3); |
6286 char scaled[256]; | 6308 char scaled[256]; |
6287 char *ptr; | 6309 char *ptr; |
6288 int scl_val[XLFD_SCL_LAST], *field, *val; | 6310 int scl_val[XLFD_SCL_LAST], *field, *val; |
6311 char *longest_start, *cur_start, *nonspecial; | |
6312 int longest_len, cur_len, exact; | |
6289 | 6313 |
6290 for (i = 0; i < XLFD_SCL_LAST; i++) | 6314 for (i = 0; i < XLFD_SCL_LAST; i++) |
6291 scl_val[i] = -1; | 6315 scl_val[i] = -1; |
6292 | 6316 |
6293 /* If the pattern contains 14 dashes and one of PIXEL_SIZE, | 6317 /* If the pattern contains 14 dashes and one of PIXEL_SIZE, |
6341 scl_val[XLFD_SCL_PIXEL_SIZE] = -1; | 6365 scl_val[XLFD_SCL_PIXEL_SIZE] = -1; |
6342 | 6366 |
6343 ptr = regex; | 6367 ptr = regex; |
6344 *ptr++ = '^'; | 6368 *ptr++ = '^'; |
6345 | 6369 |
6346 /* Turn pattern into a regexp and do a regexp match. */ | 6370 longest_start = cur_start = ptr; |
6371 longest_len = cur_len = 0; | |
6372 exact = 1; | |
6373 | |
6374 /* Turn pattern into a regexp and do a regexp match. Also find the | |
6375 longest substring containing no special characters. */ | |
6347 for (; *pattern; pattern++) | 6376 for (; *pattern; pattern++) |
6348 { | 6377 { |
6349 if (*pattern == '?') | 6378 if (*pattern == '?' || *pattern == '*') |
6350 *ptr++ = '.'; | 6379 { |
6351 else if (*pattern == '*') | 6380 if (cur_len > longest_len) |
6352 { | 6381 { |
6353 *ptr++ = '.'; | 6382 longest_start = cur_start; |
6354 *ptr++ = '*'; | 6383 longest_len = cur_len; |
6355 } | 6384 } |
6385 cur_len = 0; | |
6386 exact = 0; | |
6387 | |
6388 if (*pattern == '?') | |
6389 *ptr++ = '.'; | |
6390 else /* if (*pattern == '*') */ | |
6391 { | |
6392 *ptr++ = '.'; | |
6393 *ptr++ = '*'; | |
6394 } | |
6395 } | |
6356 else | 6396 else |
6357 *ptr++ = tolower (*pattern); | 6397 { |
6358 } | 6398 if (cur_len == 0) |
6399 cur_start = ptr; | |
6400 cur_len++; | |
6401 | |
6402 *ptr++ = tolower (*pattern); | |
6403 } | |
6404 } | |
6405 | |
6406 if (cur_len > longest_len) | |
6407 { | |
6408 longest_start = cur_start; | |
6409 longest_len = cur_len; | |
6410 } | |
6411 | |
6359 *ptr = '$'; | 6412 *ptr = '$'; |
6360 *(ptr + 1) = '\0'; | 6413 *(ptr + 1) = '\0'; |
6361 | 6414 |
6415 nonspecial = xmalloc (longest_len + 1); | |
6416 strncpy (nonspecial, longest_start, longest_len); | |
6417 nonspecial[longest_len] = '\0'; | |
6418 | |
6362 pattern_regex = build_string (regex); | 6419 pattern_regex = build_string (regex); |
6363 | 6420 |
6364 for (i = 0; i < font_name_count; i++) | 6421 for (i = 0; i < font_name_count; i++) |
6365 { | 6422 { |
6366 fontname = build_string (font_name_table[i]); | 6423 fontname = mac_c_string_match (pattern_regex, font_name_table[i], |
6367 if (fast_string_match (pattern_regex, fontname) >= 0) | 6424 nonspecial, exact); |
6425 if (!NILP (fontname)) | |
6368 { | 6426 { |
6369 font_list = Fcons (fontname, font_list); | 6427 font_list = Fcons (fontname, font_list); |
6370 | 6428 if (exact || maxnames > 0 && ++n_fonts >= maxnames) |
6371 n_fonts++; | 6429 return font_list; |
6372 if (maxnames > 0 && n_fonts >= maxnames) | |
6373 break; | |
6374 } | 6430 } |
6375 else if (scl_val[XLFD_SCL_PIXEL_SIZE] > 0 | 6431 else if (scl_val[XLFD_SCL_PIXEL_SIZE] > 0 |
6376 && (ptr = strstr (font_name_table[i], "-0-0-75-75-m-0-"))) | 6432 && (ptr = strstr (font_name_table[i], "-0-0-75-75-m-0-"))) |
6377 { | 6433 { |
6378 int former_len = ptr - font_name_table[i]; | 6434 int former_len = ptr - font_name_table[i]; |
6382 "-%d-%d-75-75-m-%d-%s", | 6438 "-%d-%d-75-75-m-%d-%s", |
6383 scl_val[XLFD_SCL_PIXEL_SIZE], | 6439 scl_val[XLFD_SCL_PIXEL_SIZE], |
6384 scl_val[XLFD_SCL_POINT_SIZE], | 6440 scl_val[XLFD_SCL_POINT_SIZE], |
6385 scl_val[XLFD_SCL_AVGWIDTH], | 6441 scl_val[XLFD_SCL_AVGWIDTH], |
6386 ptr + sizeof ("-0-0-75-75-m-0-") - 1); | 6442 ptr + sizeof ("-0-0-75-75-m-0-") - 1); |
6387 fontname = build_string (scaled); | 6443 fontname = mac_c_string_match (pattern_regex, scaled, |
6388 if (fast_string_match (pattern_regex, fontname) >= 0) | 6444 nonspecial, exact); |
6445 if (!NILP (fontname)) | |
6389 { | 6446 { |
6390 font_list = Fcons (fontname, font_list); | 6447 font_list = Fcons (fontname, font_list); |
6391 | 6448 if (exact || maxnames > 0 && ++n_fonts >= maxnames) |
6392 n_fonts++; | 6449 return font_list; |
6393 if (maxnames > 0 && n_fonts >= maxnames) | |
6394 break; | |
6395 } | 6450 } |
6396 } | 6451 } |
6397 } | 6452 } |
6453 | |
6454 xfree (nonspecial); | |
6455 | |
6398 return font_list; | 6456 return font_list; |
6399 } | 6457 } |
6400 | 6458 |
6401 /* Return a list of at most MAXNAMES font specs matching the one in | 6459 /* Return a list of at most MAXNAMES font specs matching the one in |
6402 PATTERN. Cache matching fonts for patterns in | 6460 PATTERN. Cache matching fonts for patterns in |