diff options
| author | YAMAMOTO Mitsuharu | 2006-12-15 08:05:35 +0000 |
|---|---|---|
| committer | YAMAMOTO Mitsuharu | 2006-12-15 08:05:35 +0000 |
| commit | 0d36bf23eaae0700ac7579470a4fff65a6558214 (patch) | |
| tree | 2e4e42c327e86cae19e8d7397d32a20e85fb3b97 /src | |
| parent | ca71dd0e529856db7542daf9da5d05ab97e88106 (diff) | |
| download | emacs-0d36bf23eaae0700ac7579470a4fff65a6558214.tar.gz emacs-0d36bf23eaae0700ac7579470a4fff65a6558214.zip | |
(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.
Diffstat (limited to 'src')
| -rw-r--r-- | src/macterm.c | 214 |
1 files changed, 153 insertions, 61 deletions
diff --git a/src/macterm.c b/src/macterm.c index 994131c4d52..08b4c147c05 100644 --- a/src/macterm.c +++ b/src/macterm.c | |||
| @@ -1154,7 +1154,8 @@ mac_query_char_extents (style, c, | |||
| 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 | ||
| @@ -6987,7 +6988,6 @@ static Lisp_Object fm_font_family_alist; | |||
| 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 | ||
| @@ -7224,6 +7224,73 @@ add_mac_font_name (name, size, style, charset) | |||
| 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; |
| @@ -7244,6 +7311,44 @@ fm_style_to_face_attributes (fm_style) | |||
| 7244 | 7311 | ||
| 7245 | return tem; | 7312 | return tem; |
| 7246 | } | 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)); | ||
| 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 |
| @@ -7275,9 +7380,8 @@ init_font_name_table () | |||
| 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), |
| @@ -7295,41 +7399,25 @@ init_font_name_table () | |||
| 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); |
| @@ -7873,14 +7961,11 @@ mac_load_query_font (f, fontname) | |||
| 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; |
| @@ -8004,11 +8089,19 @@ mac_load_query_font (f, fontname) | |||
| 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) |
| @@ -8026,6 +8119,8 @@ mac_load_query_font (f, fontname) | |||
| 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 | } |
| @@ -8033,6 +8128,7 @@ mac_load_query_font (f, fontname) | |||
| 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 | ||
| @@ -8115,8 +8211,13 @@ mac_load_query_font (f, fontname) | |||
| 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); |
| @@ -9365,9 +9466,7 @@ mac_store_event_ref_as_apple_event (class, id, class_key, id_key, | |||
| 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 | } |
| @@ -10404,7 +10503,9 @@ XTread_socket (sd, expected, hold_quit) | |||
| 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 | { |
| @@ -11787,15 +11888,6 @@ CODING_SYSTEM is a coding system corresponding to TEXT-ENCODING. */); | |||
| 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. */); |