comparison src/macterm.c @ 90729:6588c6259dfb

Merge from emacs--devo--0 Patches applied: * emacs--devo--0 (patch 545-562) - Update from CVS - Update from erc--emacs--22 - Merge from gnus--rel--5.10 - erc-iswitchb: Temporarily enable iswitchb mode * gnus--rel--5.10 (patch 172-176) - Merge from emacs--devo--0 - Update from CVS - Update from CVS: lisp/legacy-gnus-agent.el: Add Copyright notice. Revision: emacs@sv.gnu.org/emacs--unicode--0--patch-156
author Miles Bader <miles@gnu.org>
date Sat, 16 Dec 2006 01:29:26 +0000
parents dbe3f29e61d6 1accf28d80f2
children 95d0cdf160ea
comparison
equal deleted inserted replaced
90728:a65a92d83186 90729:6588c6259dfb
1154 { 1154 {
1155 ATSUTextLayout text_layout; 1155 ATSUTextLayout text_layout;
1156 UniChar ch = c; 1156 UniChar ch = c;
1157 1157
1158 err = atsu_get_text_layout_with_text_ptr (&ch, 1, style, &text_layout); 1158 err = atsu_get_text_layout_with_text_ptr (&ch, 1, style, &text_layout);
1159 if (err == noErr) 1159 if (err == noErr
1160 && (font_ascent_return || font_descent_return || overall_return))
1160 { 1161 {
1161 ATSTrapezoid glyph_bounds; 1162 ATSTrapezoid glyph_bounds;
1162 1163
1163 err = ATSUGetGlyphBounds (text_layout, 0, 0, 1164 err = ATSUGetGlyphBounds (text_layout, 0, 0,
1164 kATSUFromTextBeginning, kATSUToTextEnd, 1165 kATSUFromTextBeginning, kATSUToTextEnd,
7004 #if USE_ATSUI 7005 #if USE_ATSUI
7005 /* Hash table linking font family names to ATSU font IDs. */ 7006 /* Hash table linking font family names to ATSU font IDs. */
7006 static Lisp_Object atsu_font_id_hash; 7007 static Lisp_Object atsu_font_id_hash;
7007 /* Alist linking Font Manager style to face attributes. */ 7008 /* Alist linking Font Manager style to face attributes. */
7008 static Lisp_Object fm_style_face_attributes_alist; 7009 static Lisp_Object fm_style_face_attributes_alist;
7009 static Lisp_Object Vmac_atsu_font_table;
7010 extern Lisp_Object QCfamily, QCweight, QCslant, Qnormal, Qbold, Qitalic; 7010 extern Lisp_Object QCfamily, QCweight, QCslant, Qnormal, Qbold, Qitalic;
7011 #endif 7011 #endif
7012 7012
7013 /* Alist linking character set strings to Mac text encoding and Emacs 7013 /* Alist linking character set strings to Mac text encoding and Emacs
7014 coding system. */ 7014 coding system. */
7241 charset)); 7241 charset));
7242 } 7242 }
7243 } 7243 }
7244 7244
7245 #if USE_ATSUI 7245 #if USE_ATSUI
7246 static FMFontStyle
7247 fm_get_style_from_font (font)
7248 FMFont font;
7249 {
7250 OSStatus err;
7251 FMFontStyle style = normal;
7252 ByteCount len;
7253 UInt16 mac_style;
7254 FMFontFamily font_family;
7255 #define FONT_HEADER_MAC_STYLE_OFFSET (4*4 + 2*2 + 8*2 + 2*4)
7256
7257 /* FMGetFontFamilyInstanceFromFont returns `normal' as the style of
7258 some font (e.g., Optima) even if it is `bold'. */
7259 err = FMGetFontTable (font, 'head', FONT_HEADER_MAC_STYLE_OFFSET,
7260 sizeof (mac_style), &mac_style, &len);
7261 if (err == noErr
7262 && len >= FONT_HEADER_MAC_STYLE_OFFSET + sizeof (mac_style))
7263 style = EndianU16_BtoN (mac_style);
7264 else
7265 FMGetFontFamilyInstanceFromFont (font, &font_family, &style);
7266
7267 return style;
7268 }
7269
7270 static ATSUFontID
7271 atsu_find_font_from_family_name (family)
7272 const char *family;
7273 {
7274 struct Lisp_Hash_Table *h = XHASH_TABLE (atsu_font_id_hash);
7275 unsigned hash_code;
7276 int i;
7277 Lisp_Object rest, best;
7278 FMFontStyle min_style, style;
7279
7280 i = hash_lookup (h, make_unibyte_string (family, strlen (family)),
7281 &hash_code);
7282 if (i < 0)
7283 return kATSUInvalidFontID;
7284
7285 rest = HASH_VALUE (h, i);
7286 if (INTEGERP (rest) || (CONSP (rest) && INTEGERP (XCDR (rest))))
7287 return cons_to_long (rest);
7288
7289 rest = Fnreverse (rest);
7290 best = XCAR (rest);
7291 rest = XCDR (rest);
7292 if (!NILP (rest)
7293 && (min_style = fm_get_style_from_font (cons_to_long (best))) != normal)
7294 do
7295 {
7296 style = fm_get_style_from_font (cons_to_long (XCAR (rest)));
7297 if (style < min_style)
7298 {
7299 best = XCAR (rest);
7300 if (style == normal)
7301 break;
7302 else
7303 min_style = style;
7304 }
7305 rest = XCDR (rest);
7306 }
7307 while (!NILP (rest));
7308
7309 HASH_VALUE (h, i) = best;
7310 return cons_to_long (best);
7311 }
7312
7246 static Lisp_Object 7313 static Lisp_Object
7247 fm_style_to_face_attributes (fm_style) 7314 fm_style_to_face_attributes (fm_style)
7248 FMFontStyle fm_style; 7315 FMFontStyle fm_style;
7249 { 7316 {
7250 Lisp_Object tem; 7317 Lisp_Object tem;
7260 fm_style_face_attributes_alist = 7327 fm_style_face_attributes_alist =
7261 Fcons (Fcons (make_number (fm_style), tem), 7328 Fcons (Fcons (make_number (fm_style), tem),
7262 fm_style_face_attributes_alist); 7329 fm_style_face_attributes_alist);
7263 7330
7264 return tem; 7331 return tem;
7332 }
7333
7334 static Lisp_Object
7335 atsu_find_font_family_name (font_id)
7336 ATSUFontID font_id;
7337 {
7338 OSStatus err;
7339 ByteCount len;
7340 Lisp_Object family = Qnil;
7341
7342 err = ATSUFindFontName (font_id, kFontFamilyName,
7343 kFontMacintoshPlatform, kFontNoScript,
7344 kFontNoLanguage, 0, NULL, &len, NULL);
7345 if (err == noErr)
7346 {
7347 family = make_uninit_string (len);
7348 err = ATSUFindFontName (font_id, kFontFamilyName,
7349 kFontMacintoshPlatform, kFontNoScript,
7350 kFontNoLanguage, len, SDATA (family),
7351 NULL, NULL);
7352 }
7353 if (err == noErr)
7354 decode_mac_font_name (SDATA (family), len + 1, Qnil);
7355
7356 return family;
7357 }
7358
7359 Lisp_Object
7360 mac_atsu_font_face_attributes (font_id)
7361 ATSUFontID font_id;
7362 {
7363 Lisp_Object family, style_attrs;
7364
7365 family = atsu_find_font_family_name (font_id);
7366 if (NILP (family))
7367 return Qnil;
7368 style_attrs = fm_style_to_face_attributes (fm_get_style_from_font (font_id));
7369 return Fcons (QCfamily, Fcons (family, style_attrs));
7265 } 7370 }
7266 #endif 7371 #endif
7267 7372
7268 /* Sets up the table font_name_table to contain the list of all fonts 7373 /* Sets up the table font_name_table to contain the list of all fonts
7269 in the system the first time the table is used so that the Resource 7374 in the system the first time the table is used so that the Resource
7292 OSStatus err; 7397 OSStatus err;
7293 struct Lisp_Hash_Table *h; 7398 struct Lisp_Hash_Table *h;
7294 unsigned hash_code; 7399 unsigned hash_code;
7295 ItemCount nfonts, i; 7400 ItemCount nfonts, i;
7296 ATSUFontID *font_ids = NULL; 7401 ATSUFontID *font_ids = NULL;
7297 Ptr name; 7402 Lisp_Object prev_family = Qnil;
7298 ByteCount name_len; 7403 int j;
7299 Lisp_Object family;
7300 7404
7301 atsu_font_id_hash = 7405 atsu_font_id_hash =
7302 make_hash_table (Qequal, make_number (DEFAULT_HASH_SIZE), 7406 make_hash_table (Qequal, make_number (DEFAULT_HASH_SIZE),
7303 make_float (DEFAULT_REHASH_SIZE), 7407 make_float (DEFAULT_REHASH_SIZE),
7304 make_float (DEFAULT_REHASH_THRESHOLD), 7408 make_float (DEFAULT_REHASH_THRESHOLD),
7312 err = ATSUGetFontIDs (font_ids, nfonts, NULL); 7416 err = ATSUGetFontIDs (font_ids, nfonts, NULL);
7313 } 7417 }
7314 if (err == noErr) 7418 if (err == noErr)
7315 for (i = 0; i < nfonts; i++) 7419 for (i = 0; i < nfonts; i++)
7316 { 7420 {
7317 err = ATSUFindFontName (font_ids[i], kFontFamilyName, 7421 Lisp_Object family;
7318 kFontMacintoshPlatform, kFontNoScript, 7422
7319 kFontNoLanguage, 0, NULL, &name_len, NULL); 7423 family = atsu_find_font_family_name (font_ids[i]);
7320 if (err != noErr) 7424 if (NILP (family) || SREF (family, 0) == '.')
7321 continue; 7425 continue;
7322 name = xmalloc (name_len + 1); 7426 if (!NILP (Fequal (prev_family, family)))
7323 name[name_len] = '\0'; 7427 family = prev_family;
7324 err = ATSUFindFontName (font_ids[i], kFontFamilyName, 7428 else
7325 kFontMacintoshPlatform, kFontNoScript, 7429 j = hash_lookup (h, family, &hash_code);
7326 kFontNoLanguage, name_len, name, 7430 if (j < 0)
7327 NULL, NULL);
7328 if (err == noErr)
7329 { 7431 {
7330 FMFontFamily ff; 7432 add_mac_font_name (SDATA (family), 0, normal, "iso10646-1");
7331 FMFontStyle style = normal; 7433 j = hash_put (h, family, Fcons (long_to_cons (font_ids[i]),
7332 7434 Qnil), hash_code);
7333 decode_mac_font_name (name, name_len + 1, Qnil);
7334 family = make_unibyte_string (name, name_len);
7335 FMGetFontFamilyInstanceFromFont (font_ids[i], &ff, &style);
7336 Fputhash ((font_ids[i] > MOST_POSITIVE_FIXNUM
7337 ? make_float (font_ids[i])
7338 : make_number (font_ids[i])),
7339 Fcons (QCfamily,
7340 Fcons (family,
7341 fm_style_to_face_attributes (style))),
7342 Vmac_atsu_font_table);
7343 if (*name != '.'
7344 && hash_lookup (h, family, &hash_code) < 0)
7345 {
7346 add_mac_font_name (name, 0, normal, "iso10646-1");
7347 hash_put (h, family, long_to_cons (font_ids[i]),
7348 hash_code);
7349 }
7350 } 7435 }
7351 xfree (name); 7436 else if (EQ (prev_family, family))
7437 HASH_VALUE (h, j) = Fcons (long_to_cons (font_ids[i]),
7438 HASH_VALUE (h, j));
7439 prev_family = family;
7352 } 7440 }
7353 if (font_ids) 7441 if (font_ids)
7354 xfree (font_ids); 7442 xfree (font_ids);
7355 } 7443 }
7356 #endif 7444 #endif
7890 &bold_p, &italic_p}; 7978 &bold_p, &italic_p};
7891 static const ATSUFontFeatureType types[] = 7979 static const ATSUFontFeatureType types[] =
7892 {kAllTypographicFeaturesType, kDiacriticsType}; 7980 {kAllTypographicFeaturesType, kDiacriticsType};
7893 static const ATSUFontFeatureSelector selectors[] = 7981 static const ATSUFontFeatureSelector selectors[] =
7894 {kAllTypeFeaturesOffSelector, kDecomposeDiacriticsSelector}; 7982 {kAllTypeFeaturesOffSelector, kDecomposeDiacriticsSelector};
7895 Lisp_Object font_id_cons;
7896 FMFontStyle style; 7983 FMFontStyle style;
7897 7984
7898 font_id_cons = Fgethash (make_unibyte_string (family, strlen (family)), 7985 font_id = atsu_find_font_from_family_name (family);
7899 atsu_font_id_hash, Qnil); 7986 if (font_id == kATSUInvalidFontID)
7900 if (NILP (font_id_cons)) 7987 return;
7901 return NULL;
7902 font_id = cons_to_long (font_id_cons);
7903 size_fixed = Long2Fix (size); 7988 size_fixed = Long2Fix (size);
7904 bold_p = (fontface & bold) != 0; 7989 bold_p = (fontface & bold) != 0;
7905 italic_p = (fontface & italic) != 0; 7990 italic_p = (fontface & italic) != 0;
7906 err = ATSUCreateStyle (&mac_style); 7991 err = ATSUCreateStyle (&mac_style);
7907 if (err != noErr) 7992 if (err != noErr)
8021 if (c == 0xad) 8106 if (c == 0xad)
8022 /* Soft hyphen is not supported in ATSUI. */ 8107 /* Soft hyphen is not supported in ATSUI. */
8023 continue; 8108 continue;
8024 else if (c == 0x7f) 8109 else if (c == 0x7f)
8025 { 8110 {
8026 c = 0x9f; 8111 #if USE_CG_TEXT_DRAWING
8027 continue; 8112 if (font->cg_glyphs)
8113 {
8114 c = 0x9f;
8115 pcm = NULL;
8116 continue;
8117 }
8118 #endif
8119 break;
8028 } 8120 }
8029 8121
8030 mac_query_char_extents (font->mac_style, c, NULL, NULL, pcm + c, 8122 mac_query_char_extents (font->mac_style, c, NULL, NULL,
8123 pcm ? pcm + c : NULL,
8031 #if USE_CG_TEXT_DRAWING 8124 #if USE_CG_TEXT_DRAWING
8032 (font->cg_glyphs ? font->cg_glyphs + c 8125 (font->cg_glyphs ? font->cg_glyphs + c
8033 : NULL) 8126 : NULL)
8034 #else 8127 #else
8035 NULL 8128 NULL
8043 ASCII or Latin-1 characters. */ 8136 ASCII or Latin-1 characters. */
8044 CGFontRelease (font->cg_font); 8137 CGFontRelease (font->cg_font);
8045 font->cg_font = NULL; 8138 font->cg_font = NULL;
8046 xfree (font->cg_glyphs); 8139 xfree (font->cg_glyphs);
8047 font->cg_glyphs = NULL; 8140 font->cg_glyphs = NULL;
8141 if (pcm == NULL)
8142 break;
8048 } 8143 }
8049 #endif 8144 #endif
8050 } 8145 }
8051 } 8146 }
8052 else 8147 else
8053 #endif 8148 #endif
8054 { 8149 {
8150 OSStatus err;
8055 FontInfo the_fontinfo; 8151 FontInfo the_fontinfo;
8056 int is_two_byte_font; 8152 int is_two_byte_font;
8057 8153
8058 #if USE_CG_DRAWING 8154 #if USE_CG_DRAWING
8059 mac_prepare_for_quickdraw (f); 8155 mac_prepare_for_quickdraw (f);
8132 xmalloc (sizeof (XCharStruct) * (0xff - 0x20 + 1)); 8228 xmalloc (sizeof (XCharStruct) * (0xff - 0x20 + 1));
8133 bzero (font->bounds.per_char, 8229 bzero (font->bounds.per_char,
8134 sizeof (XCharStruct) * (0xff - 0x20 + 1)); 8230 sizeof (XCharStruct) * (0xff - 0x20 + 1));
8135 8231
8136 space_bounds = font->bounds.per_char; 8232 space_bounds = font->bounds.per_char;
8137 mac_query_char_extents (NULL, 0x20, &font->ascent, &font->descent, 8233 err = mac_query_char_extents (NULL, 0x20, &font->ascent,
8138 space_bounds, NULL); 8234 &font->descent, space_bounds, NULL);
8235 if (err != noErr || space_bounds->width <= 0)
8236 {
8237 mac_unload_font (&one_mac_display_info, font);
8238 return NULL;
8239 }
8139 8240
8140 for (c = 0x21, pcm = space_bounds + 1; c <= 0xff; c++, pcm++) 8241 for (c = 0x21, pcm = space_bounds + 1; c <= 0xff; c++, pcm++)
8141 mac_query_char_extents (NULL, c, NULL, NULL, pcm, NULL); 8242 mac_query_char_extents (NULL, c, NULL, NULL, pcm, NULL);
8142 } 8243 }
8143 } 8244 }
9384 &apple_event); 9485 &apple_event);
9385 if (err == noErr) 9486 if (err == noErr)
9386 { 9487 {
9387 mac_store_apple_event (class_key, id_key, &apple_event); 9488 mac_store_apple_event (class_key, id_key, &apple_event);
9388 AEDisposeDesc (&apple_event); 9489 AEDisposeDesc (&apple_event);
9389 /* Post a harmless event so as to wake up from 9490 mac_wakeup_from_rne ();
9390 ReceiveNextEvent. */
9391 mac_post_mouse_moved_event ();
9392 } 9491 }
9393 } 9492 }
9394 } 9493 }
9395 9494
9396 return err; 9495 return err;
10399 #if TARGET_API_MAC_CARBON 10498 #if TARGET_API_MAC_CARBON
10400 FrontNonFloatingWindow () 10499 FrontNonFloatingWindow ()
10401 #else 10500 #else
10402 FrontWindow () 10501 FrontWindow ()
10403 #endif 10502 #endif
10404 != window_ptr) 10503 != window_ptr
10504 || (mac_window_to_frame (window_ptr)
10505 != dpyinfo->x_focus_frame))
10405 SelectWindow (window_ptr); 10506 SelectWindow (window_ptr);
10406 else 10507 else
10407 { 10508 {
10408 ControlPartCode control_part_code; 10509 ControlPartCode control_part_code;
10409 ControlHandle ch; 10510 ControlHandle ch;
11671 /* We don't yet support this, but defining this here avoids whining 11772 /* We don't yet support this, but defining this here avoids whining
11672 from cus-start.el and other places, like "M-x set-variable". */ 11773 from cus-start.el and other places, like "M-x set-variable". */
11673 DEFVAR_BOOL ("x-use-underline-position-properties", 11774 DEFVAR_BOOL ("x-use-underline-position-properties",
11674 &x_use_underline_position_properties, 11775 &x_use_underline_position_properties,
11675 doc: /* *Non-nil means make use of UNDERLINE_POSITION font properties. 11776 doc: /* *Non-nil means make use of UNDERLINE_POSITION font properties.
11676 nil means ignore them. If you encounter fonts with bogus 11777 A value of nil means ignore them. If you encounter fonts with bogus
11677 UNDERLINE_POSITION font properties, for example 7x13 on XFree prior 11778 UNDERLINE_POSITION font properties, for example 7x13 on XFree prior
11678 to 4.1, set this to nil. 11779 to 4.1, set this to nil.
11679 11780
11680 NOTE: Not supported on Mac yet. */); 11781 NOTE: Not supported on Mac yet. */);
11681 x_use_underline_position_properties = 0; 11782 x_use_underline_position_properties = 0;
11682 11783
11683 DEFVAR_BOOL ("x-underline-at-descent-line", 11784 DEFVAR_BOOL ("x-underline-at-descent-line",
11684 &x_underline_at_descent_line, 11785 &x_underline_at_descent_line,
11685 doc: /* *Non-nil means to draw the underline at the same place as the descent line. 11786 doc: /* *Non-nil means to draw the underline at the same place as the descent line.
11686 nil means to draw the underline according to the value of the variable 11787 A value of nil means to draw the underline according to the value of the
11687 `x-use-underline-position-properties', which is usually at the baseline 11788 variable `x-use-underline-position-properties', which is usually at the
11688 level. The default value is nil. */); 11789 baseline level. The default value is nil. */);
11689 x_underline_at_descent_line = 0; 11790 x_underline_at_descent_line = 0;
11690 11791
11691 DEFVAR_LISP ("x-toolkit-scroll-bars", &Vx_toolkit_scroll_bars, 11792 DEFVAR_LISP ("x-toolkit-scroll-bars", &Vx_toolkit_scroll_bars,
11692 doc: /* If not nil, Emacs uses toolkit scroll bars. */); 11793 doc: /* If not nil, Emacs uses toolkit scroll bars. */);
11693 #ifdef USE_TOOLKIT_SCROLL_BARS 11794 #ifdef USE_TOOLKIT_SCROLL_BARS
11730 11831
11731 DEFVAR_LISP ("mac-emulate-three-button-mouse", 11832 DEFVAR_LISP ("mac-emulate-three-button-mouse",
11732 &Vmac_emulate_three_button_mouse, 11833 &Vmac_emulate_three_button_mouse,
11733 doc: /* *Specify a way of three button mouse emulation. 11834 doc: /* *Specify a way of three button mouse emulation.
11734 The value can be nil, t, or the symbol `reverse'. 11835 The value can be nil, t, or the symbol `reverse'.
11735 nil means that no emulation should be done and the modifiers should be 11836 A value of nil means that no emulation should be done and the modifiers
11736 placed on the mouse-1 event. 11837 should be placed on the mouse-1 event.
11737 t means that when the option-key is held down while pressing the mouse 11838 t means that when the option-key is held down while pressing the mouse
11738 button, the click will register as mouse-2 and while the command-key 11839 button, the click will register as mouse-2 and while the command-key
11739 is held down, the click will register as mouse-3. 11840 is held down, the click will register as mouse-3.
11740 The symbol `reverse' means that the option-key will register for 11841 The symbol `reverse' means that the option-key will register for
11741 mouse-3 and the command-key will register for mouse-2. */); 11842 mouse-3 and the command-key will register for mouse-2. */);
11782 CODING_SYSTEM is a coding system corresponding to TEXT-ENCODING. */); 11883 CODING_SYSTEM is a coding system corresponding to TEXT-ENCODING. */);
11783 Vmac_charset_info_alist = 11884 Vmac_charset_info_alist =
11784 Fcons (list3 (build_string ("mac-roman"), 11885 Fcons (list3 (build_string ("mac-roman"),
11785 make_number (smRoman), Qnil), Qnil); 11886 make_number (smRoman), Qnil), Qnil);
11786 11887
11787 #if USE_ATSUI
11788 DEFVAR_LISP ("mac-atsu-font-table", &Vmac_atsu_font_table,
11789 doc: /* Hash table of ATSU font IDs vs plist of attributes and values. */);
11790 Vmac_atsu_font_table =
11791 make_hash_table (Qeql, make_number (DEFAULT_HASH_SIZE),
11792 make_float (DEFAULT_REHASH_SIZE),
11793 make_float (DEFAULT_REHASH_THRESHOLD),
11794 Qnil, Qnil, Qnil);
11795 #endif
11796 #if USE_MAC_TSM 11888 #if USE_MAC_TSM
11797 DEFVAR_LISP ("mac-ts-active-input-overlay", &Vmac_ts_active_input_overlay, 11889 DEFVAR_LISP ("mac-ts-active-input-overlay", &Vmac_ts_active_input_overlay,
11798 doc: /* Overlay used to display Mac TSM active input area. */); 11890 doc: /* Overlay used to display Mac TSM active input area. */);
11799 Vmac_ts_active_input_overlay = Qnil; 11891 Vmac_ts_active_input_overlay = Qnil;
11800 11892