2
This file is part of Konsole, KDE's terminal.
4
Copyright 2007-2008 by Robert Knight <robertknight@gmail.com>
5
Copyright 1997,1998 by Lars Doelle <lars.doelle@on-line.de>
7
This program is free software; you can redistribute it and/or modify
8
it under the terms of the GNU General Public License as published by
9
the Free Software Foundation; either version 2 of the License, or
10
(at your option) any later version.
12
This program is distributed in the hope that it will be useful,
13
but WITHOUT ANY WARRANTY; without even the implied warranty of
14
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
GNU General Public License for more details.
17
You should have received a copy of the GNU General Public License
18
along with this program; if not, write to the Free Software
19
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
30
#include "CharacterColor.h"
35
typedef unsigned char LineProperty;
37
static const int LINE_DEFAULT = 0;
38
static const int LINE_WRAPPED = (1 << 0);
39
static const int LINE_DOUBLEWIDTH = (1 << 1);
40
static const int LINE_DOUBLEHEIGHT = (1 << 2);
42
#define DEFAULT_RENDITION 0
43
#define RE_BOLD (1 << 0)
44
#define RE_BLINK (1 << 1)
45
#define RE_UNDERLINE (1 << 2)
46
#define RE_REVERSE (1 << 3) // Screen only
47
#define RE_INTENSIVE (1 << 3) // Widget only
48
#define RE_CURSOR (1 << 4)
49
#define RE_EXTENDED_CHAR (1 << 5)
52
* A single character in the terminal which consists of a unicode character
53
* value, foreground and background colors and a set of rendition attributes
54
* which specify how it should be drawn.
60
* Constructs a new character.
62
* @param _c The unicode character value of this character.
63
* @param _f The foreground color used to draw the character.
64
* @param _b The color used to draw the character's background.
65
* @param _r A set of rendition flags which specify how this character is to be drawn.
67
inline Character(quint16 _c = ' ',
68
CharacterColor _f = CharacterColor(COLOR_SPACE_DEFAULT,DEFAULT_FORE_COLOR),
69
CharacterColor _b = CharacterColor(COLOR_SPACE_DEFAULT,DEFAULT_BACK_COLOR),
70
quint8 _r = DEFAULT_RENDITION)
71
: character(_c), rendition(_r), foregroundColor(_f), backgroundColor(_b) {}
75
/** The unicode character value for this character. */
78
* Experimental addition which allows a single Character instance to contain more than
79
* one unicode character.
81
* charSequence is a hash code which can be used to look up the unicode
82
* character sequence in the ExtendedCharTable used to create the sequence.
87
/** A combination of RENDITION flags which specify options for drawing the character. */
90
/** The foreground color used to draw this character. */
91
CharacterColor foregroundColor;
92
/** The color used to draw this character's background. */
93
CharacterColor backgroundColor;
96
* Returns true if this character has a transparent background when
97
* it is drawn with the specified @p palette.
99
bool isTransparent(const ColorEntry* palette) const;
101
* Returns true if this character should always be drawn in bold when
102
* it is drawn with the specified @p palette, independent of whether
103
* or not the character has the RE_BOLD rendition flag.
105
ColorEntry::FontWeight fontWeight(const ColorEntry* base) const;
108
* returns true if the format (color, rendition flag) of the compared characters is equal
110
bool equalsFormat(const Character &other) const;
113
* Compares two characters and returns true if they have the same unicode character value,
114
* rendition and colors.
116
friend bool operator == (const Character& a, const Character& b);
118
* Compares two characters and returns true if they have different unicode character values,
119
* renditions or colors.
121
friend bool operator != (const Character& a, const Character& b);
124
inline bool operator == (const Character& a, const Character& b)
126
return a.character == b.character &&
127
a.rendition == b.rendition &&
128
a.foregroundColor == b.foregroundColor &&
129
a.backgroundColor == b.backgroundColor;
132
inline bool operator != (const Character& a, const Character& b)
134
return a.character != b.character ||
135
a.rendition != b.rendition ||
136
a.foregroundColor != b.foregroundColor ||
137
a.backgroundColor != b.backgroundColor;
140
inline bool Character::isTransparent(const ColorEntry* base) const
142
return ((backgroundColor._colorSpace == COLOR_SPACE_DEFAULT) &&
143
base[backgroundColor._u+0+(backgroundColor._v?BASE_COLORS:0)].transparent)
144
|| ((backgroundColor._colorSpace == COLOR_SPACE_SYSTEM) &&
145
base[backgroundColor._u+2+(backgroundColor._v?BASE_COLORS:0)].transparent);
148
inline bool Character::equalsFormat(const Character& other) const
151
backgroundColor==other.backgroundColor &&
152
foregroundColor==other.foregroundColor &&
153
rendition==other.rendition;
156
inline ColorEntry::FontWeight Character::fontWeight(const ColorEntry* base) const
158
if (backgroundColor._colorSpace == COLOR_SPACE_DEFAULT)
159
return base[backgroundColor._u+0+(backgroundColor._v?BASE_COLORS:0)].fontWeight;
160
else if (backgroundColor._colorSpace == COLOR_SPACE_SYSTEM)
161
return base[backgroundColor._u+2+(backgroundColor._v?BASE_COLORS:0)].fontWeight;
163
return ColorEntry::UseCurrentFormat;
166
extern unsigned short vt100_graphics[32];
170
* A table which stores sequences of unicode characters, referenced
171
* by hash keys. The hash key itself is the same size as a unicode
172
* character ( ushort ) so that it can occupy the same space in
175
class ExtendedCharTable
178
/** Constructs a new character table. */
180
~ExtendedCharTable();
183
* Adds a sequences of unicode characters to the table and returns
184
* a hash code which can be used later to look up the sequence
185
* using lookupExtendedChar()
187
* If the same sequence already exists in the table, the hash
188
* of the existing sequence will be returned.
190
* @param unicodePoints An array of unicode character points
191
* @param length Length of @p unicodePoints
193
ushort createExtendedChar(ushort* unicodePoints , ushort length);
195
* Looks up and returns a pointer to a sequence of unicode characters
196
* which was added to the table using createExtendedChar().
198
* @param hash The hash key returned by createExtendedChar()
199
* @param length This variable is set to the length of the
200
* character sequence.
202
* @return A unicode character sequence of size @p length.
204
ushort* lookupExtendedChar(ushort hash , ushort& length) const;
206
/** The global ExtendedCharTable instance. */
207
static ExtendedCharTable instance;
209
// calculates the hash key of a sequence of unicode points of size 'length'
210
ushort extendedCharHash(ushort* unicodePoints , ushort length) const;
211
// tests whether the entry in the table specified by 'hash' matches the
212
// character sequence 'unicodePoints' of size 'length'
213
bool extendedCharMatch(ushort hash , ushort* unicodePoints , ushort length) const;
214
// internal, maps hash keys to character sequence buffers. The first ushort
215
// in each value is the length of the buffer, followed by the ushorts in the buffer
217
QHash<ushort,ushort*> extendedCharTable;
221
Q_DECLARE_TYPEINFO(Konsole::Character, Q_MOVABLE_TYPE);
223
#endif // CHARACTER_H