comparison src/macterm.c @ 74629:1accf28d80f2

(mac_query_char_extents) [USE_ATSUI]: Don't call ATSUGetGlyphBounds if not necessary. (Vmac_atsu_font_table) [USE_ATSUI]: Remove Variable. (syms_of_macterm) [USE_ATSUI]: Don't defvar it. (fm_get_style_from_font, atsu_find_font_from_family_name) (atsu_find_font_family_name, mac_atsu_font_face_attributes) [USE_ATSUI]: New functions. (init_font_name_table) [USE_ATSUI]: Use atsu_find_font_family_name. (mac_load_query_font) [USE_ATSUI]: Use atsu_find_font_from_family_name. Don't get metrics for Latin-1 right half characters. (mac_load_query_font): Don't load font if space width is not positive. [TARGET_API_MAC_CARBON] (mac_store_event_ref_as_apple_event): Use mac_wakeup_from_rne instead of mac_post_mouse_moved_event. (XTread_socket): Call SelectWindow when unfocused frame is clicked.
author YAMAMOTO Mitsuharu <mituharu@math.s.chiba-u.ac.jp>
date Fri, 15 Dec 2006 08:05:35 +0000
parents 6b41da580ac3
children d4a5d8d2cba2 17e0dd217877 6588c6259dfb
comparison
equal deleted inserted replaced
74628:6f17f4d8d9d6 74629:1accf28d80f2
1152 { 1152 {
1153 ATSUTextLayout text_layout; 1153 ATSUTextLayout text_layout;
1154 UniChar ch = c; 1154 UniChar ch = c;
1155 1155
1156 err = atsu_get_text_layout_with_text_ptr (&ch, 1, style, &text_layout); 1156 err = atsu_get_text_layout_with_text_ptr (&ch, 1, style, &text_layout);
1157 if (err == noErr) 1157 if (err == noErr
1158 && (font_ascent_return || font_descent_return || overall_return))
1158 { 1159 {
1159 ATSTrapezoid glyph_bounds; 1160 ATSTrapezoid glyph_bounds;
1160 1161
1161 err = ATSUGetGlyphBounds (text_layout, 0, 0, 1162 err = ATSUGetGlyphBounds (text_layout, 0, 0,
1162 kATSUFromTextBeginning, kATSUToTextEnd, 1163 kATSUFromTextBeginning, kATSUToTextEnd,
6985 #if USE_ATSUI 6986 #if USE_ATSUI
6986 /* Hash table linking font family names to ATSU font IDs. */ 6987 /* Hash table linking font family names to ATSU font IDs. */
6987 static Lisp_Object atsu_font_id_hash; 6988 static Lisp_Object atsu_font_id_hash;
6988 /* Alist linking Font Manager style to face attributes. */ 6989 /* Alist linking Font Manager style to face attributes. */
6989 static Lisp_Object fm_style_face_attributes_alist; 6990 static Lisp_Object fm_style_face_attributes_alist;
6990 static Lisp_Object Vmac_atsu_font_table;
6991 extern Lisp_Object QCfamily, QCweight, QCslant, Qnormal, Qbold, Qitalic; 6991 extern Lisp_Object QCfamily, QCweight, QCslant, Qnormal, Qbold, Qitalic;
6992 #endif 6992 #endif
6993 6993
6994 /* Alist linking character set strings to Mac text encoding and Emacs 6994 /* Alist linking character set strings to Mac text encoding and Emacs
6995 coding system. */ 6995 coding system. */
7222 charset)); 7222 charset));
7223 } 7223 }
7224 } 7224 }
7225 7225
7226 #if USE_ATSUI 7226 #if USE_ATSUI
7227 static FMFontStyle
7228 fm_get_style_from_font (font)
7229 FMFont font;
7230 {
7231 OSStatus err;
7232 FMFontStyle style = normal;
7233 ByteCount len;
7234 UInt16 mac_style;
7235 FMFontFamily font_family;
7236 #define FONT_HEADER_MAC_STYLE_OFFSET (4*4 + 2*2 + 8*2 + 2*4)
7237
7238 /* FMGetFontFamilyInstanceFromFont returns `normal' as the style of
7239 some font (e.g., Optima) even if it is `bold'. */
7240 err = FMGetFontTable (font, 'head', FONT_HEADER_MAC_STYLE_OFFSET,
7241 sizeof (mac_style), &mac_style, &len);
7242 if (err == noErr
7243 && len >= FONT_HEADER_MAC_STYLE_OFFSET + sizeof (mac_style))
7244 style = EndianU16_BtoN (mac_style);
7245 else
7246 FMGetFontFamilyInstanceFromFont (font, &font_family, &style);
7247
7248 return style;
7249 }
7250
7251 static ATSUFontID
7252 atsu_find_font_from_family_name (family)
7253 const char *family;
7254 {
7255 struct Lisp_Hash_Table *h = XHASH_TABLE (atsu_font_id_hash);
7256 unsigned hash_code;
7257 int i;
7258 Lisp_Object rest, best;
7259 FMFontStyle min_style, style;
7260
7261 i = hash_lookup (h, make_unibyte_string (family, strlen (family)),
7262 &hash_code);
7263 if (i < 0)
7264 return kATSUInvalidFontID;
7265
7266 rest = HASH_VALUE (h, i);
7267 if (INTEGERP (rest) || (CONSP (rest) && INTEGERP (XCDR (rest))))
7268 return cons_to_long (rest);
7269
7270 rest = Fnreverse (rest);
7271 best = XCAR (rest);
7272 rest = XCDR (rest);
7273 if (!NILP (rest)
7274 && (min_style = fm_get_style_from_font (cons_to_long (best))) != normal)
7275 do
7276 {
7277 style = fm_get_style_from_font (cons_to_long (XCAR (rest)));
7278 if (style < min_style)
7279 {
7280 best = XCAR (rest);
7281 if (style == normal)
7282 break;
7283 else
7284 min_style = style;
7285 }
7286 rest = XCDR (rest);
7287 }
7288 while (!NILP (rest));
7289
7290 HASH_VALUE (h, i) = best;
7291 return cons_to_long (best);
7292 }
7293
7227 static Lisp_Object 7294 static Lisp_Object
7228 fm_style_to_face_attributes (fm_style) 7295 fm_style_to_face_attributes (fm_style)
7229 FMFontStyle fm_style; 7296 FMFontStyle fm_style;
7230 { 7297 {
7231 Lisp_Object tem; 7298 Lisp_Object tem;
7241 fm_style_face_attributes_alist = 7308 fm_style_face_attributes_alist =
7242 Fcons (Fcons (make_number (fm_style), tem), 7309 Fcons (Fcons (make_number (fm_style), tem),
7243 fm_style_face_attributes_alist); 7310 fm_style_face_attributes_alist);
7244 7311
7245 return tem; 7312 return tem;
7313 }
7314
7315 static Lisp_Object
7316 atsu_find_font_family_name (font_id)
7317 ATSUFontID font_id;
7318 {
7319 OSStatus err;
7320 ByteCount len;
7321 Lisp_Object family = Qnil;
7322
7323 err = ATSUFindFontName (font_id, kFontFamilyName,
7324 kFontMacintoshPlatform, kFontNoScript,
7325 kFontNoLanguage, 0, NULL, &len, NULL);
7326 if (err == noErr)
7327 {
7328 family = make_uninit_string (len);
7329 err = ATSUFindFontName (font_id, kFontFamilyName,
7330 kFontMacintoshPlatform, kFontNoScript,
7331 kFontNoLanguage, len, SDATA (family),
7332 NULL, NULL);
7333 }
7334 if (err == noErr)
7335 decode_mac_font_name (SDATA (family), len + 1, Qnil);
7336
7337 return family;
7338 }
7339
7340 Lisp_Object
7341 mac_atsu_font_face_attributes (font_id)
7342 ATSUFontID font_id;
7343 {
7344 Lisp_Object family, style_attrs;
7345
7346 family = atsu_find_font_family_name (font_id);
7347 if (NILP (family))
7348 return Qnil;
7349 style_attrs = fm_style_to_face_attributes (fm_get_style_from_font (font_id));
7350 return Fcons (QCfamily, Fcons (family, style_attrs));
7246 } 7351 }
7247 #endif 7352 #endif
7248 7353
7249 /* Sets up the table font_name_table to contain the list of all fonts 7354 /* Sets up the table font_name_table to contain the list of all fonts
7250 in the system the first time the table is used so that the Resource 7355 in the system the first time the table is used so that the Resource
7273 OSStatus err; 7378 OSStatus err;
7274 struct Lisp_Hash_Table *h; 7379 struct Lisp_Hash_Table *h;
7275 unsigned hash_code; 7380 unsigned hash_code;
7276 ItemCount nfonts, i; 7381 ItemCount nfonts, i;
7277 ATSUFontID *font_ids = NULL; 7382 ATSUFontID *font_ids = NULL;
7278 Ptr name; 7383 Lisp_Object prev_family = Qnil;
7279 ByteCount name_len; 7384 int j;
7280 Lisp_Object family;
7281 7385
7282 atsu_font_id_hash = 7386 atsu_font_id_hash =
7283 make_hash_table (Qequal, make_number (DEFAULT_HASH_SIZE), 7387 make_hash_table (Qequal, make_number (DEFAULT_HASH_SIZE),
7284 make_float (DEFAULT_REHASH_SIZE), 7388 make_float (DEFAULT_REHASH_SIZE),
7285 make_float (DEFAULT_REHASH_THRESHOLD), 7389 make_float (DEFAULT_REHASH_THRESHOLD),
7293 err = ATSUGetFontIDs (font_ids, nfonts, NULL); 7397 err = ATSUGetFontIDs (font_ids, nfonts, NULL);
7294 } 7398 }
7295 if (err == noErr) 7399 if (err == noErr)
7296 for (i = 0; i < nfonts; i++) 7400 for (i = 0; i < nfonts; i++)
7297 { 7401 {
7298 err = ATSUFindFontName (font_ids[i], kFontFamilyName, 7402 Lisp_Object family;
7299 kFontMacintoshPlatform, kFontNoScript, 7403
7300 kFontNoLanguage, 0, NULL, &name_len, NULL); 7404 family = atsu_find_font_family_name (font_ids[i]);
7301 if (err != noErr) 7405 if (NILP (family) || SREF (family, 0) == '.')
7302 continue; 7406 continue;
7303 name = xmalloc (name_len + 1); 7407 if (!NILP (Fequal (prev_family, family)))
7304 name[name_len] = '\0'; 7408 family = prev_family;
7305 err = ATSUFindFontName (font_ids[i], kFontFamilyName, 7409 else
7306 kFontMacintoshPlatform, kFontNoScript, 7410 j = hash_lookup (h, family, &hash_code);
7307 kFontNoLanguage, name_len, name, 7411 if (j < 0)
7308 NULL, NULL);
7309 if (err == noErr)
7310 { 7412 {
7311 FMFontFamily ff; 7413 add_mac_font_name (SDATA (family), 0, normal, "iso10646-1");
7312 FMFontStyle style = normal; 7414 j = hash_put (h, family, Fcons (long_to_cons (font_ids[i]),
7313 7415 Qnil), hash_code);
7314 decode_mac_font_name (name, name_len + 1, Qnil);
7315 family = make_unibyte_string (name, name_len);
7316 FMGetFontFamilyInstanceFromFont (font_ids[i], &ff, &style);
7317 Fputhash ((font_ids[i] > MOST_POSITIVE_FIXNUM
7318 ? make_float (font_ids[i])
7319 : make_number (font_ids[i])),
7320 Fcons (QCfamily,
7321 Fcons (family,
7322 fm_style_to_face_attributes (style))),
7323 Vmac_atsu_font_table);
7324 if (*name != '.'
7325 && hash_lookup (h, family, &hash_code) < 0)
7326 {
7327 add_mac_font_name (name, 0, normal, "iso10646-1");
7328 hash_put (h, family, long_to_cons (font_ids[i]),
7329 hash_code);
7330 }
7331 } 7416 }
7332 xfree (name); 7417 else if (EQ (prev_family, family))
7418 HASH_VALUE (h, j) = Fcons (long_to_cons (font_ids[i]),
7419 HASH_VALUE (h, j));
7420 prev_family = family;
7333 } 7421 }
7334 if (font_ids) 7422 if (font_ids)
7335 xfree (font_ids); 7423 xfree (font_ids);
7336 } 7424 }
7337 #endif 7425 #endif
7871 &bold_p, &italic_p}; 7959 &bold_p, &italic_p};
7872 static const ATSUFontFeatureType types[] = 7960 static const ATSUFontFeatureType types[] =
7873 {kAllTypographicFeaturesType, kDiacriticsType}; 7961 {kAllTypographicFeaturesType, kDiacriticsType};
7874 static const ATSUFontFeatureSelector selectors[] = 7962 static const ATSUFontFeatureSelector selectors[] =
7875 {kAllTypeFeaturesOffSelector, kDecomposeDiacriticsSelector}; 7963 {kAllTypeFeaturesOffSelector, kDecomposeDiacriticsSelector};
7876 Lisp_Object font_id_cons;
7877 FMFontStyle style; 7964 FMFontStyle style;
7878 7965
7879 font_id_cons = Fgethash (make_unibyte_string (family, strlen (family)), 7966 font_id = atsu_find_font_from_family_name (family);
7880 atsu_font_id_hash, Qnil); 7967 if (font_id == kATSUInvalidFontID)
7881 if (NILP (font_id_cons)) 7968 return;
7882 return NULL;
7883 font_id = cons_to_long (font_id_cons);
7884 size_fixed = Long2Fix (size); 7969 size_fixed = Long2Fix (size);
7885 bold_p = (fontface & bold) != 0; 7970 bold_p = (fontface & bold) != 0;
7886 italic_p = (fontface & italic) != 0; 7971 italic_p = (fontface & italic) != 0;
7887 err = ATSUCreateStyle (&mac_style); 7972 err = ATSUCreateStyle (&mac_style);
7888 if (err != noErr) 7973 if (err != noErr)
8002 if (c == 0xad) 8087 if (c == 0xad)
8003 /* Soft hyphen is not supported in ATSUI. */ 8088 /* Soft hyphen is not supported in ATSUI. */
8004 continue; 8089 continue;
8005 else if (c == 0x7f) 8090 else if (c == 0x7f)
8006 { 8091 {
8007 c = 0x9f; 8092 #if USE_CG_TEXT_DRAWING
8008 continue; 8093 if (font->cg_glyphs)
8094 {
8095 c = 0x9f;
8096 pcm = NULL;
8097 continue;
8098 }
8099 #endif
8100 break;
8009 } 8101 }
8010 8102
8011 mac_query_char_extents (font->mac_style, c, NULL, NULL, pcm + c, 8103 mac_query_char_extents (font->mac_style, c, NULL, NULL,
8104 pcm ? pcm + c : NULL,
8012 #if USE_CG_TEXT_DRAWING 8105 #if USE_CG_TEXT_DRAWING
8013 (font->cg_glyphs ? font->cg_glyphs + c 8106 (font->cg_glyphs ? font->cg_glyphs + c
8014 : NULL) 8107 : NULL)
8015 #else 8108 #else
8016 NULL 8109 NULL
8024 ASCII or Latin-1 characters. */ 8117 ASCII or Latin-1 characters. */
8025 CGFontRelease (font->cg_font); 8118 CGFontRelease (font->cg_font);
8026 font->cg_font = NULL; 8119 font->cg_font = NULL;
8027 xfree (font->cg_glyphs); 8120 xfree (font->cg_glyphs);
8028 font->cg_glyphs = NULL; 8121 font->cg_glyphs = NULL;
8122 if (pcm == NULL)
8123 break;
8029 } 8124 }
8030 #endif 8125 #endif
8031 } 8126 }
8032 } 8127 }
8033 else 8128 else
8034 #endif 8129 #endif
8035 { 8130 {
8131 OSStatus err;
8036 FontInfo the_fontinfo; 8132 FontInfo the_fontinfo;
8037 int is_two_byte_font; 8133 int is_two_byte_font;
8038 8134
8039 #if USE_CG_DRAWING 8135 #if USE_CG_DRAWING
8040 mac_prepare_for_quickdraw (f); 8136 mac_prepare_for_quickdraw (f);
8113 xmalloc (sizeof (XCharStruct) * (0xff - 0x20 + 1)); 8209 xmalloc (sizeof (XCharStruct) * (0xff - 0x20 + 1));
8114 bzero (font->bounds.per_char, 8210 bzero (font->bounds.per_char,
8115 sizeof (XCharStruct) * (0xff - 0x20 + 1)); 8211 sizeof (XCharStruct) * (0xff - 0x20 + 1));
8116 8212
8117 space_bounds = font->bounds.per_char; 8213 space_bounds = font->bounds.per_char;
8118 mac_query_char_extents (NULL, 0x20, &font->ascent, &font->descent, 8214 err = mac_query_char_extents (NULL, 0x20, &font->ascent,
8119 space_bounds, NULL); 8215 &font->descent, space_bounds, NULL);
8216 if (err != noErr || space_bounds->width <= 0)
8217 {
8218 mac_unload_font (&one_mac_display_info, font);
8219 return NULL;
8220 }
8120 8221
8121 for (c = 0x21, pcm = space_bounds + 1; c <= 0xff; c++, pcm++) 8222 for (c = 0x21, pcm = space_bounds + 1; c <= 0xff; c++, pcm++)
8122 mac_query_char_extents (NULL, c, NULL, NULL, pcm, NULL); 8223 mac_query_char_extents (NULL, c, NULL, NULL, pcm, NULL);
8123 } 8224 }
8124 } 8225 }
9363 &apple_event); 9464 &apple_event);
9364 if (err == noErr) 9465 if (err == noErr)
9365 { 9466 {
9366 mac_store_apple_event (class_key, id_key, &apple_event); 9467 mac_store_apple_event (class_key, id_key, &apple_event);
9367 AEDisposeDesc (&apple_event); 9468 AEDisposeDesc (&apple_event);
9368 /* Post a harmless event so as to wake up from 9469 mac_wakeup_from_rne ();
9369 ReceiveNextEvent. */
9370 mac_post_mouse_moved_event ();
9371 } 9470 }
9372 } 9471 }
9373 } 9472 }
9374 9473
9375 return err; 9474 return err;
10402 #if TARGET_API_MAC_CARBON 10501 #if TARGET_API_MAC_CARBON
10403 FrontNonFloatingWindow () 10502 FrontNonFloatingWindow ()
10404 #else 10503 #else
10405 FrontWindow () 10504 FrontWindow ()
10406 #endif 10505 #endif
10407 != window_ptr) 10506 != window_ptr
10507 || (mac_window_to_frame (window_ptr)
10508 != dpyinfo->x_focus_frame))
10408 SelectWindow (window_ptr); 10509 SelectWindow (window_ptr);
10409 else 10510 else
10410 { 10511 {
10411 ControlPartCode control_part_code; 10512 ControlPartCode control_part_code;
10412 ControlHandle ch; 10513 ControlHandle ch;
11785 CODING_SYSTEM is a coding system corresponding to TEXT-ENCODING. */); 11886 CODING_SYSTEM is a coding system corresponding to TEXT-ENCODING. */);
11786 Vmac_charset_info_alist = 11887 Vmac_charset_info_alist =
11787 Fcons (list3 (build_string ("mac-roman"), 11888 Fcons (list3 (build_string ("mac-roman"),
11788 make_number (smRoman), Qnil), Qnil); 11889 make_number (smRoman), Qnil), Qnil);
11789 11890
11790 #if USE_ATSUI
11791 DEFVAR_LISP ("mac-atsu-font-table", &Vmac_atsu_font_table,
11792 doc: /* Hash table of ATSU font IDs vs plist of attributes and values. */);
11793 Vmac_atsu_font_table =
11794 make_hash_table (Qeql, make_number (DEFAULT_HASH_SIZE),
11795 make_float (DEFAULT_REHASH_SIZE),
11796 make_float (DEFAULT_REHASH_THRESHOLD),
11797 Qnil, Qnil, Qnil);
11798 #endif
11799 #if USE_MAC_TSM 11891 #if USE_MAC_TSM
11800 DEFVAR_LISP ("mac-ts-active-input-overlay", &Vmac_ts_active_input_overlay, 11892 DEFVAR_LISP ("mac-ts-active-input-overlay", &Vmac_ts_active_input_overlay,
11801 doc: /* Overlay used to display Mac TSM active input area. */); 11893 doc: /* Overlay used to display Mac TSM active input area. */);
11802 Vmac_ts_active_input_overlay = Qnil; 11894 Vmac_ts_active_input_overlay = Qnil;
11803 11895