GNU Octave
3.8.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
Main Page
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Pages
libgui
qterminal
libqterminal
unix
Character.h
Go to the documentation of this file.
1
/*
2
This file is part of Konsole, KDE's terminal.
3
4
Copyright (C) 2007, 2013 by Robert Knight <
[email protected]
>
5
Copyright (C) 1997,1998 by Lars Doelle <
[email protected]
>
6
7
Rewritten for QT4 by e_k <e_k at users.sourceforge.net>, Copyright (C)2008
8
9
This program is free software; you can redistribute it and/or modify
10
it under the terms of the GNU General Public License as published by
11
the Free Software Foundation; either version 2 of the License, or
12
(at your option) any later version.
13
14
This program is distributed in the hope that it will be useful,
15
but WITHOUT ANY WARRANTY; without even the implied warranty of
16
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17
GNU General Public License for more details.
18
19
You should have received a copy of the GNU General Public License
20
along with this program; if not, write to the Free Software
21
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
22
02110-1301 USA.
23
*/
24
25
#ifndef CHARACTER_H
26
#define CHARACTER_H
27
28
// Qt
29
#include <QtCore/QHash>
30
31
// Local
32
#include "
unix/CharacterColor.h
"
33
34
typedef
unsigned
char
LineProperty
;
35
36
static
const
int
LINE_DEFAULT
= 0;
37
static
const
int
LINE_WRAPPED
= (1 << 0);
38
static
const
int
LINE_DOUBLEWIDTH
= (1 << 1);
39
static
const
int
LINE_DOUBLEHEIGHT
= (1 << 2);
40
41
#define DEFAULT_RENDITION 0
42
#define RE_BOLD (1 << 0)
43
#define RE_BLINK (1 << 1)
44
#define RE_UNDERLINE (1 << 2)
45
#define RE_REVERSE (1 << 3) // Screen only
46
#define RE_INTENSIVE (1 << 3) // Widget only
47
#define RE_CURSOR (1 << 4)
48
#define RE_EXTENDED_CHAR (1 << 5)
49
50
/**
51
* A single character in the terminal which consists of a unicode character
52
* value, foreground and background colors and a set of rendition attributes
53
* which specify how it should be drawn.
54
*/
55
class
Character
56
{
57
public
:
58
/**
59
* Constructs a new character.
60
*
61
* @param _c The unicode character value of this character.
62
* @param _f The foreground color used to draw the character.
63
* @param _b The color used to draw the character's background.
64
* @param _r A set of rendition flags which specify how this character is to be drawn.
65
*/
66
inline
Character
(quint16 _c =
' '
,
67
CharacterColor
_f =
CharacterColor
(
COLOR_SPACE_DEFAULT
,
DEFAULT_FORE_COLOR
),
68
CharacterColor
_b =
CharacterColor
(
COLOR_SPACE_DEFAULT
,
DEFAULT_BACK_COLOR
),
69
quint8 _r =
DEFAULT_RENDITION
)
70
:
character
(_c),
rendition
(_r),
foregroundColor
(_f),
backgroundColor
(_b) {}
71
72
union
73
{
74
/** The unicode character value for this character. */
75
quint16
character
;
76
/**
77
* Experimental addition which allows a single Character instance to contain more than
78
* one unicode character.
79
*
80
* charSequence is a hash code which can be used to look up the unicode
81
* character sequence in the ExtendedCharTable used to create the sequence.
82
*/
83
quint16
charSequence
;
84
};
85
86
/** A combination of RENDITION flags which specify options for drawing the character. */
87
quint8
rendition
;
88
89
/** The foreground color used to draw this character. */
90
CharacterColor
foregroundColor
;
91
/** The color used to draw this character's background. */
92
CharacterColor
backgroundColor
;
93
94
/**
95
* Returns true if this character has a transparent background when
96
* it is drawn with the specified @p palette.
97
*/
98
bool
isTransparent
(
const
ColorEntry
* palette)
const
;
99
/**
100
* Returns true if this character should always be drawn in bold when
101
* it is drawn with the specified @p palette, independent of whether
102
* or not the character has the RE_BOLD rendition flag.
103
*/
104
bool
isBold
(
const
ColorEntry
* base)
const
;
105
106
/**
107
* Compares two characters and returns true if they have the same unicode character value,
108
* rendition and colors.
109
*/
110
friend
bool
operator ==
(
const
Character
& a,
const
Character
& b);
111
/**
112
* Compares two characters and returns true if they have different unicode character values,
113
* renditions or colors.
114
*/
115
friend
bool
operator !=
(
const
Character
& a,
const
Character
& b);
116
};
117
118
inline
bool
operator ==
(
const
Character
& a,
const
Character
& b)
119
{
120
return
a.
character
== b.
character
&&
121
a.
rendition
== b.
rendition
&&
122
a.
foregroundColor
== b.
foregroundColor
&&
123
a.
backgroundColor
== b.
backgroundColor
;
124
}
125
126
inline
bool
operator !=
(
const
Character
& a,
const
Character
& b)
127
{
128
return
a.
character
!= b.
character
||
129
a.
rendition
!= b.
rendition
||
130
a.
foregroundColor
!= b.
foregroundColor
||
131
a.
backgroundColor
!= b.
backgroundColor
;
132
}
133
134
inline
bool
Character::isTransparent
(
const
ColorEntry
* base)
const
135
{
136
return
((
backgroundColor
.
_colorSpace
==
COLOR_SPACE_DEFAULT
) &&
137
base[
backgroundColor
.
_u
+0+(
backgroundColor
.
_v
?
BASE_COLORS
:0)].
transparent
)
138
|| ((
backgroundColor
.
_colorSpace
==
COLOR_SPACE_SYSTEM
) &&
139
base[
backgroundColor
.
_u
+2+(
backgroundColor
.
_v
?
BASE_COLORS
:0)].
transparent
);
140
}
141
142
inline
bool
Character::isBold
(
const
ColorEntry
* base)
const
143
{
144
return
((
backgroundColor
.
_colorSpace
==
COLOR_SPACE_DEFAULT
) &&
145
base[
backgroundColor
.
_u
+0+(
backgroundColor
.
_v
?
BASE_COLORS
:0)].
bold
)
146
|| ((
backgroundColor
.
_colorSpace
==
COLOR_SPACE_SYSTEM
) &&
147
base[
backgroundColor
.
_u
+2+(
backgroundColor
.
_v
?
BASE_COLORS
:0)].
bold
);
148
}
149
150
extern
unsigned
short
vt100_graphics
[32];
151
152
153
/**
154
* A table which stores sequences of unicode characters, referenced
155
* by hash keys. The hash key itself is the same size as a unicode
156
* character ( ushort ) so that it can occupy the same space in
157
* a structure.
158
*/
159
class
ExtendedCharTable
160
{
161
public
:
162
/** Constructs a new character table. */
163
ExtendedCharTable
();
164
~ExtendedCharTable
();
165
166
/**
167
* Adds a sequences of unicode characters to the table and returns
168
* a hash code which can be used later to look up the sequence
169
* using lookupExtendedChar()
170
*
171
* If the same sequence already exists in the table, the hash
172
* of the existing sequence will be returned.
173
*
174
* @param unicodePoints An array of unicode character points
175
* @param length Length of @p unicodePoints
176
*/
177
ushort
createExtendedChar
(ushort* unicodePoints , ushort
length
);
178
/**
179
* Looks up and returns a pointer to a sequence of unicode characters
180
* which was added to the table using createExtendedChar().
181
*
182
* @param hash The hash key returned by createExtendedChar()
183
* @param length This variable is set to the length of the
184
* character sequence.
185
*
186
* @return A unicode character sequence of size @p length.
187
*/
188
ushort*
lookupExtendedChar
(ushort hash , ushort& length)
const
;
189
190
/** The global ExtendedCharTable instance. */
191
static
ExtendedCharTable
instance
;
192
private
:
193
// calculates the hash key of a sequence of unicode points of size 'length'
194
ushort
extendedCharHash
(ushort* unicodePoints , ushort length)
const
;
195
// tests whether the entry in the table specified by 'hash' matches the
196
// character sequence 'unicodePoints' of size 'length'
197
bool
extendedCharMatch
(ushort hash , ushort* unicodePoints , ushort length)
const
;
198
// internal, maps hash keys to character sequence buffers. The first ushort
199
// in each value is the length of the buffer, followed by the ushorts in the buffer
200
// themselves.
201
QHash<ushort,ushort*>
extendedCharTable
;
202
};
203
204
#endif // CHARACTER_H
205
Generated on Mon Dec 30 2013 03:04:20 for GNU Octave by
1.8.1.2