GNU Octave 7.1.0
A high-level interpreted language, primarily intended for numerical computations, mostly compatible with Matlab
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 <robertknight@gmail.com>
5 Copyright (C) 1997,1998 by Lars Doelle <lars.doelle@on-line.de>
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
34typedef unsigned char LineProperty;
35
36static const int LINE_DEFAULT = 0;
37static const int LINE_WRAPPED = (1 << 0);
38static const int LINE_DOUBLEWIDTH = (1 << 1);
39static 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 */
56{
57public:
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 = ' ',
69 quint8 _r = DEFAULT_RENDITION)
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. */
91 /** The color used to draw this character's background. */
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
118inline bool operator == (const Character& a, const Character& b)
119{
120 return a.character == b.character &&
121 a.rendition == b.rendition &&
124}
125
126inline bool operator != (const Character& a, const Character& b)
127{
128 return a.character != b.character ||
129 a.rendition != b.rendition ||
132}
133
134inline bool Character::isTransparent(const ColorEntry* base) const
135{
140}
141
142inline bool Character::isBold(const ColorEntry* base) const
143{
148}
149
150extern 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 */
160{
161public:
162 /** Constructs a new character table. */
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. */
192private:
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
#define COLOR_SPACE_SYSTEM
#define COLOR_SPACE_DEFAULT
#define DEFAULT_FORE_COLOR
#define BASE_COLORS
#define DEFAULT_BACK_COLOR
static const int LINE_DOUBLEHEIGHT
Definition: Character.h:39
unsigned char LineProperty
Definition: Character.h:34
unsigned short vt100_graphics[32]
static const int LINE_WRAPPED
Definition: Character.h:37
bool operator!=(const Character &a, const Character &b)
Definition: Character.h:126
bool operator==(const Character &a, const Character &b)
Definition: Character.h:118
#define DEFAULT_RENDITION
Definition: Character.h:41
static const int LINE_DOUBLEWIDTH
Definition: Character.h:38
static const int LINE_DEFAULT
Definition: Character.h:36
Describes the color of a single character in the terminal.
A single character in the terminal which consists of a unicode character value, foreground and backgr...
Definition: Character.h:56
CharacterColor backgroundColor
The color used to draw this character's background.
Definition: Character.h:92
bool isTransparent(const ColorEntry *palette) const
Returns true if this character has a transparent background when it is drawn with the specified palet...
Definition: Character.h:134
quint16 charSequence
Experimental addition which allows a single Character instance to contain more than one unicode chara...
Definition: Character.h:83
friend bool operator!=(const Character &a, const Character &b)
Compares two characters and returns true if they have different unicode character values,...
Definition: Character.h:126
friend bool operator==(const Character &a, const Character &b)
Compares two characters and returns true if they have the same unicode character value,...
Definition: Character.h:118
CharacterColor foregroundColor
The foreground color used to draw this character.
Definition: Character.h:90
quint16 character
The unicode character value for this character.
Definition: Character.h:75
quint8 rendition
A combination of RENDITION flags which specify options for drawing the character.
Definition: Character.h:87
bool isBold(const ColorEntry *base) const
Returns true if this character should always be drawn in bold when it is drawn with the specified pal...
Definition: Character.h:142
Character(quint16 _c=' ', CharacterColor _f=CharacterColor(COLOR_SPACE_DEFAULT, DEFAULT_FORE_COLOR), CharacterColor _b=CharacterColor(COLOR_SPACE_DEFAULT, DEFAULT_BACK_COLOR), quint8 _r=0)
Constructs a new character.
Definition: Character.h:66
An entry in a terminal display's color palette.
bool bold
If true characters drawn using this color should be bold.
bool transparent
If true character backgrounds using this color should be transparent.
A table which stores sequences of unicode characters, referenced by hash keys.
Definition: Character.h:160
ushort * lookupExtendedChar(ushort hash, ushort &length) const
Looks up and returns a pointer to a sequence of unicode characters which was added to the table using...
Definition: Emulation.cpp:406
static ExtendedCharTable instance
The global ExtendedCharTable instance.
Definition: Character.h:191
ushort extendedCharHash(ushort *unicodePoints, ushort length) const
Definition: Emulation.cpp:345
ushort createExtendedChar(ushort *unicodePoints, ushort length)
Adds a sequences of unicode characters to the table and returns a hash code which can be used later t...
Definition: Emulation.cpp:371
QHash< ushort, ushort * > extendedCharTable
Definition: Character.h:201
ExtendedCharTable()
Constructs a new character table.
Definition: Emulation.cpp:424
bool extendedCharMatch(ushort hash, ushort *unicodePoints, ushort length) const
Definition: Emulation.cpp:354
std::string hash(hash_fptr hash_fcn, const std::string &str, int result_buf_len)
Definition: lo-hash.cc:45