From cd4eb164a9cb5fd4df2290423830471d6086fd1e Mon Sep 17 00:00:00 2001 From: Chong Yidong Date: Sun, 10 Jun 2012 00:44:44 +0800 Subject: [PATCH] Add support for italic text on ttys. * src/dispextern.h: Replace unused TTY_CAP_BLINK with TTY_CAP_ITALIC. (struct face): Remove unused fields tty_dim_p, tty_blinking_p, and tty_alt_charset_p. Add tty_italic_p. * src/term.c: Support italics in capable terminals. (no_color_bit): Replace unused NC_BLINK with NC_ITALIC. (turn_on_face): Output using TS_enter_italic_mode if available. Don't handle unused blinking and alt-charset cases. (turn_off_face): Handle italic case; discard unused tty_blinking_p and tty_alt_charset_p cases. (tty_capable_p, init_tty): Support italics. * src/termchar.h (struct tty_display_info): Add field for italics. Remove unused blink field. * src/xfaces.c (tty_supports_face_attributes_p, realize_tty_face): Handle slant. Fixes: debbugs:9652 --- src/ChangeLog | 20 ++++++++++++++++++++ src/dispextern.h | 12 ++++-------- src/term.c | 41 +++++++++++++++-------------------------- src/termchar.h | 2 +- src/xfaces.c | 27 +++++++++++++++++---------- 5 files changed, 57 insertions(+), 45 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 563faaae68b..fb8b2a7b956 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,23 @@ +2012-06-09 Chong Yidong + + * term.c: Support italics in capable terminals (Bug#9652). + (no_color_bit): Replace unused NC_BLINK with NC_ITALIC. + (turn_on_face): Output using TS_enter_italic_mode if available. + Don't handle unused blinking and alt-charset cases. + (turn_off_face): Handle italic case; discard unused tty_blinking_p + and tty_alt_charset_p cases. + (tty_capable_p, init_tty): Support italics. + + * termchar.h (struct tty_display_info): Add field for italics. + Remove unused blink field. + + * xfaces.c (tty_supports_face_attributes_p, realize_tty_face): + Handle slant. + + * dispextern.h: Replace unused TTY_CAP_BLINK with TTY_CAP_ITALIC. + (struct face): Remove unused fields tty_dim_p, tty_blinking_p, and + tty_alt_charset_p. Add tty_italic_p. + 2012-06-09 Michael Albinus * dbusbind.c (XD_BASIC_DBUS_TYPE): Use dbus_type_is_valid and diff --git a/src/dispextern.h b/src/dispextern.h index 979ade70bfc..b877bf9965a 100644 --- a/src/dispextern.h +++ b/src/dispextern.h @@ -1609,15 +1609,12 @@ struct face unsigned strike_through_color_defaulted_p : 1; unsigned box_color_defaulted_p : 1; - /* TTY appearances. Blinking is not yet implemented. Colors are - found in `lface' with empty color string meaning the default - color of the TTY. */ + /* TTY appearances. Colors are found in `lface' with empty color + string meaning the default color of the TTY. */ unsigned tty_bold_p : 1; - unsigned tty_dim_p : 1; + unsigned tty_italic_p : 1; unsigned tty_underline_p : 1; - unsigned tty_alt_charset_p : 1; unsigned tty_reverse_p : 1; - unsigned tty_blinking_p : 1; /* 1 means that colors of this face may not be freed because they have been copied bitwise from a base face (see @@ -2979,8 +2976,7 @@ enum tool_bar_item_image #define TTY_CAP_UNDERLINE 0x02 #define TTY_CAP_BOLD 0x04 #define TTY_CAP_DIM 0x08 -#define TTY_CAP_BLINK 0x10 -#define TTY_CAP_ALT_CHARSET 0x20 +#define TTY_CAP_ITALIC 0x10 /*********************************************************************** diff --git a/src/term.c b/src/term.c index 3d7a677374c..8ce2efc0929 100644 --- a/src/term.c +++ b/src/term.c @@ -122,12 +122,11 @@ enum no_color_bit NC_STANDOUT = 1 << 0, NC_UNDERLINE = 1 << 1, NC_REVERSE = 1 << 2, - NC_BLINK = 1 << 3, + NC_ITALIC = 1 << 3, NC_DIM = 1 << 4, NC_BOLD = 1 << 5, NC_INVIS = 1 << 6, - NC_PROTECT = 1 << 7, - NC_ALT_CHARSET = 1 << 8 + NC_PROTECT = 1 << 7 }; /* internal state */ @@ -2022,17 +2021,16 @@ turn_on_face (struct frame *f, int face_id) if (face->tty_bold_p && MAY_USE_WITH_COLORS_P (tty, NC_BOLD)) OUTPUT1_IF (tty, tty->TS_enter_bold_mode); - if (face->tty_dim_p && MAY_USE_WITH_COLORS_P (tty, NC_DIM)) - OUTPUT1_IF (tty, tty->TS_enter_dim_mode); - - /* Alternate charset and blinking not yet used. */ - if (face->tty_alt_charset_p - && MAY_USE_WITH_COLORS_P (tty, NC_ALT_CHARSET)) - OUTPUT1_IF (tty, tty->TS_enter_alt_charset_mode); - - if (face->tty_blinking_p - && MAY_USE_WITH_COLORS_P (tty, NC_BLINK)) - OUTPUT1_IF (tty, tty->TS_enter_blink_mode); + if (face->tty_italic_p && MAY_USE_WITH_COLORS_P (tty, NC_ITALIC)) + { + if (tty->TS_enter_italic_mode) + OUTPUT1 (tty, tty->TS_enter_italic_mode); + else + /* Italics mode is unavailable on many terminals. In that + case, map slant to dimmed text; we want italic text to + appear different and dimming is not otherwise used. */ + OUTPUT1 (tty, tty->TS_enter_dim_mode); + } if (face->tty_underline_p && MAY_USE_WITH_COLORS_P (tty, NC_UNDERLINE)) OUTPUT1_IF (tty, tty->TS_enter_underline_mode); @@ -2077,27 +2075,19 @@ turn_off_face (struct frame *f, int face_id) half-bright, reverse-video, standout, underline. It may or may not turn off alt-char-mode. */ if (face->tty_bold_p - || face->tty_dim_p + || face->tty_italic_p || face->tty_reverse_p - || face->tty_alt_charset_p - || face->tty_blinking_p || face->tty_underline_p) { OUTPUT1_IF (tty, tty->TS_exit_attribute_mode); if (strcmp (tty->TS_exit_attribute_mode, tty->TS_end_standout_mode) == 0) tty->standout_mode = 0; } - - if (face->tty_alt_charset_p) - OUTPUT_IF (tty, tty->TS_exit_alt_charset_mode); } else { /* If we don't have "me" we can only have those appearances that have exit sequences defined. */ - if (face->tty_alt_charset_p) - OUTPUT_IF (tty, tty->TS_exit_alt_charset_mode); - if (face->tty_underline_p) OUTPUT_IF (tty, tty->TS_exit_underline_mode); } @@ -2128,8 +2118,7 @@ tty_capable_p (struct tty_display_info *tty, unsigned int caps, TTY_CAPABLE_P_TRY (tty, TTY_CAP_UNDERLINE, tty->TS_enter_underline_mode, NC_UNDERLINE); TTY_CAPABLE_P_TRY (tty, TTY_CAP_BOLD, tty->TS_enter_bold_mode, NC_BOLD); TTY_CAPABLE_P_TRY (tty, TTY_CAP_DIM, tty->TS_enter_dim_mode, NC_DIM); - TTY_CAPABLE_P_TRY (tty, TTY_CAP_BLINK, tty->TS_enter_blink_mode, NC_BLINK); - TTY_CAPABLE_P_TRY (tty, TTY_CAP_ALT_CHARSET, tty->TS_enter_alt_charset_mode, NC_ALT_CHARSET); + TTY_CAPABLE_P_TRY (tty, TTY_CAP_ITALIC, tty->TS_enter_italic_mode, NC_ITALIC); /* We can do it! */ return 1; @@ -3222,8 +3211,8 @@ use the Bourne shell command `TERM=... export TERM' (C-shell:\n\ tty->TS_enter_underline_mode = tgetstr ("us", address); tty->TS_exit_underline_mode = tgetstr ("ue", address); tty->TS_enter_bold_mode = tgetstr ("md", address); + tty->TS_enter_italic_mode = tgetstr ("ZH", address); tty->TS_enter_dim_mode = tgetstr ("mh", address); - tty->TS_enter_blink_mode = tgetstr ("mb", address); tty->TS_enter_reverse_mode = tgetstr ("mr", address); tty->TS_enter_alt_charset_mode = tgetstr ("as", address); tty->TS_exit_alt_charset_mode = tgetstr ("ae", address); diff --git a/src/termchar.h b/src/termchar.h index d50ee805e03..102fe45350e 100644 --- a/src/termchar.h +++ b/src/termchar.h @@ -124,8 +124,8 @@ struct tty_display_info each as vpos and hpos) */ const char *TS_enter_bold_mode; /* "md" -- turn on bold (extra bright mode). */ + const char *TS_enter_italic_mode; /* "ZH" -- turn on italics mode. */ const char *TS_enter_dim_mode; /* "mh" -- turn on half-bright mode. */ - const char *TS_enter_blink_mode; /* "mb" -- enter blinking mode. */ const char *TS_enter_reverse_mode; /* "mr" -- enter reverse video mode. */ const char *TS_exit_underline_mode; /* "us" -- start underlining. */ const char *TS_enter_underline_mode; /* "ue" -- end underlining. */ diff --git a/src/xfaces.c b/src/xfaces.c index 10d1c93fef8..772d2646291 100644 --- a/src/xfaces.c +++ b/src/xfaces.c @@ -4884,14 +4884,13 @@ static int tty_supports_face_attributes_p (struct frame *f, Lisp_Object *attrs, struct face *def_face) { - int weight; + int weight, slant; Lisp_Object val, fg, bg; XColor fg_tty_color, fg_std_color; XColor bg_tty_color, bg_std_color; unsigned test_caps = 0; Lisp_Object *def_attrs = def_face->lface; - /* First check some easy-to-check stuff; ttys support none of the following attributes, so we can just return false if any are requested (even if `nominal' values are specified, we should still return false, @@ -4907,11 +4906,9 @@ tty_supports_face_attributes_p (struct frame *f, Lisp_Object *attrs, || !UNSPECIFIEDP (attrs[LFACE_SWIDTH_INDEX]) || !UNSPECIFIEDP (attrs[LFACE_OVERLINE_INDEX]) || !UNSPECIFIEDP (attrs[LFACE_STRIKE_THROUGH_INDEX]) - || !UNSPECIFIEDP (attrs[LFACE_BOX_INDEX]) - || !UNSPECIFIEDP (attrs[LFACE_SLANT_INDEX])) + || !UNSPECIFIEDP (attrs[LFACE_BOX_INDEX])) return 0; - /* Test for terminal `capabilities' (non-color character attributes). */ /* font weight (bold/dim) */ @@ -4937,6 +4934,18 @@ tty_supports_face_attributes_p (struct frame *f, Lisp_Object *attrs, return 0; /* same as default */ } + /* font slant */ + val = attrs[LFACE_SLANT_INDEX]; + if (!UNSPECIFIEDP (val) + && (slant = FONT_SLANT_NAME_NUMERIC (val), slant >= 0)) + { + int def_slant = FONT_SLANT_NAME_NUMERIC (def_attrs[LFACE_SLANT_INDEX]); + if (slant == 100 || slant == def_slant) + return 0; /* same as default */ + else + test_caps |= TTY_CAP_ITALIC; + } + /* underlining */ val = attrs[LFACE_UNDERLINE_INDEX]; if (!UNSPECIFIEDP (val)) @@ -5857,15 +5866,13 @@ realize_tty_face (struct face_cache *cache, Lisp_Object *attrs) face->font_name = FRAME_MSDOS_P (cache->f) ? "ms-dos" : "tty"; #endif - /* Map face attributes to TTY appearances. We map slant to - dimmed text because we want italic text to appear differently - and because dimmed text is probably used infrequently. */ + /* Map face attributes to TTY appearances. */ weight = FONT_WEIGHT_NAME_NUMERIC (attrs[LFACE_WEIGHT_INDEX]); slant = FONT_SLANT_NAME_NUMERIC (attrs[LFACE_SLANT_INDEX]); if (weight > 100) face->tty_bold_p = 1; - if (weight < 100 || slant != 100) - face->tty_dim_p = 1; + if (slant != 100) + face->tty_italic_p = 1; if (!NILP (attrs[LFACE_UNDERLINE_INDEX])) face->tty_underline_p = 1; if (!NILP (attrs[LFACE_INVERSE_INDEX])) -- 2.11.4.GIT