/* Terminal hooks for GNU Emacs on the Microsoft W32 API.
- Copyright (C) 1992, 1999, 2001, 2002, 2003, 2004,
- 2005, 2006, 2007 Free Software Foundation, Inc.
+ Copyright (C) 1992, 1999, 2001, 2002, 2003, 2004, 2005, 2006, 2007,
+ 2008 Free Software Foundation, Inc.
This file is part of GNU Emacs.
-GNU Emacs is free software; you can redistribute it and/or modify
+GNU Emacs is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 3, or (at your option)
-any later version.
+the Free Software Foundation, either version 3 of the License, or
+(at your option) any later version.
GNU Emacs is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
-along with GNU Emacs; see the file COPYING. If not, write to
-the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
-Boston, MA 02110-1301, USA.
+along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. */
+/*
Tim Fleehart (apollo@online.com) 1-17-92
Geoff Voelker (voelker@cs.washington.edu) 9-12-93
*/
#include <string.h>
#include "lisp.h"
-#include "charset.h"
+#include "character.h"
#include "coding.h"
#include "disptab.h"
#include "frame.h"
char_attr = char_attr_normal;
- if (face->foreground != FACE_TTY_DEFAULT_FG_COLOR
- && face->foreground != FACE_TTY_DEFAULT_COLOR)
- char_attr = (char_attr & 0xfff0) + (face->foreground % 16);
-
- if (face->background != FACE_TTY_DEFAULT_BG_COLOR
- && face->background != FACE_TTY_DEFAULT_COLOR)
- char_attr = (char_attr & 0xff0f) + ((face->background % 16) << 4);
-
- /* Before the terminal is properly initialized, all colors map to 0.
- If we get a face like this, use the normal terminal attributes. */
- if (NILP (Vtty_defined_color_alist))
- char_attr = char_attr_normal;
-
+ /* Reverse the default color if requested. If background and
+ foreground are specified, then they have been reversed already. */
if (face->tty_reverse_p)
char_attr = (char_attr & 0xff00) + ((char_attr & 0x000f) << 4)
+ ((char_attr & 0x00f0) >> 4);
+ /* Before the terminal is properly initialized, all colors map to 0.
+ Don't try to resolve them. */
+ if (NILP (Vtty_defined_color_alist))
+ return char_attr;
+
+ /* Colors should be in the range 0...15 unless they are one of
+ FACE_TTY_DEFAULT_COLOR, FACE_TTY_DEFAULT_FG_COLOR or
+ FACE_TTY_DEFAULT_BG_COLOR. Other out of range colors are
+ invalid, so it is better to use the default color if they ever
+ get through to here. */
+ if (face->foreground >= 0 && face->foreground < 16)
+ char_attr = (char_attr & 0xfff0) + face->foreground;
+
+ if (face->background >= 0 && face->background < 16)
+ char_attr = (char_attr & 0xff0f) + (face->background << 4);
+
return char_attr;
}