• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • applications API Reference
  • KDE Home
  • Contact Us
 

Konsole

  • kde-4.14
  • applications
  • konsole
  • src
Character.h
Go to the documentation of this file.
1 /*
2  This file is part of Konsole, KDE's terminal.
3 
4  Copyright 2007-2008 by Robert Knight <robertknight@gmail.com>
5  Copyright 1997,1998 by Lars Doelle <lars.doelle@on-line.de>
6 
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.
11 
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.
16 
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
20  02110-1301 USA.
21 */
22 
23 #ifndef CHARACTER_H
24 #define CHARACTER_H
25 
26 // Konsole
27 #include "CharacterColor.h"
28 
29 namespace Konsole
30 {
31 typedef unsigned char LineProperty;
32 
33 const int LINE_DEFAULT = 0;
34 const int LINE_WRAPPED = (1 << 0);
35 const int LINE_DOUBLEWIDTH = (1 << 1);
36 const int LINE_DOUBLEHEIGHT = (1 << 2);
37 
38 const int DEFAULT_RENDITION = 0;
39 const int RE_BOLD = (1 << 0);
40 const int RE_BLINK = (1 << 1);
41 const int RE_UNDERLINE = (1 << 2);
42 const int RE_REVERSE = (1 << 3); // Screen only
43 const int RE_INTENSIVE = (1 << 3); // Widget only
44 const int RE_ITALIC = (1 << 4);
45 const int RE_CURSOR = (1 << 5);
46 const int RE_EXTENDED_CHAR = (1 << 6);
47 
56 inline bool isSupportedLineChar(quint16 codePoint)
57 {
58  if ((codePoint & 0xFF80) != 0x2500) {
59  return false;
60  }
61 
62  uchar index = (codePoint & 0x007F);
63  if ((index >= 0x04 && index <= 0x0B) ||
64  (index >= 0x4C && index <= 0x4F) ||
65  (index >= 0x6D && index <= 0x73)) {
66  return false;
67  } else {
68  return true;
69  }
70 }
71 
77 class Character
78 {
79 public:
91  explicit inline Character(quint16 _c = ' ',
92  CharacterColor _f = CharacterColor(COLOR_SPACE_DEFAULT, DEFAULT_FORE_COLOR),
93  CharacterColor _b = CharacterColor(COLOR_SPACE_DEFAULT, DEFAULT_BACK_COLOR),
94  quint8 _r = DEFAULT_RENDITION,
95  bool _real = true)
96  : character(_c)
97  , rendition(_r)
98  , foregroundColor(_f)
99  , backgroundColor(_b)
100  , isRealCharacter(_real) { }
101 
108  quint16 character;
109 
111  quint8 rendition;
112 
114  CharacterColor foregroundColor;
115 
117  CharacterColor backgroundColor;
118 
128  bool isRealCharacter;
129 
135  ColorEntry::FontWeight fontWeight(const ColorEntry* base) const;
136 
140  bool equalsFormat(const Character& other) const;
141 
146  friend bool operator == (const Character& a, const Character& b);
147 
152  friend bool operator != (const Character& a, const Character& b);
153 
154  inline bool isLineChar() const {
155  if (rendition & RE_EXTENDED_CHAR) {
156  return false;
157  } else {
158  return isSupportedLineChar(character);
159  }
160  }
161 
162  inline bool isSpace() const {
163  if (rendition & RE_EXTENDED_CHAR) {
164  return false;
165  } else {
166  return QChar(character).isSpace();
167  }
168  }
169 };
170 
171 inline bool operator == (const Character& a, const Character& b)
172 {
173  return a.character == b.character && a.equalsFormat(b);
174 }
175 
176 inline bool operator != (const Character& a, const Character& b)
177 {
178  return !operator==(a, b);
179 }
180 
181 inline bool Character::equalsFormat(const Character& other) const
182 {
183  return backgroundColor == other.backgroundColor &&
184  foregroundColor == other.foregroundColor &&
185  rendition == other.rendition;
186 }
187 
188 inline ColorEntry::FontWeight Character::fontWeight(const ColorEntry* base) const
189 {
190  if (foregroundColor._colorSpace == COLOR_SPACE_DEFAULT)
191  return base[foregroundColor._u + 0 + (foregroundColor._v ? BASE_COLORS : 0)].fontWeight;
192  else if (foregroundColor._colorSpace == COLOR_SPACE_SYSTEM)
193  return base[foregroundColor._u + 2 + (foregroundColor._v ? BASE_COLORS : 0)].fontWeight;
194  else
195  return ColorEntry::UseCurrentFormat;
196 }
197 }
198 Q_DECLARE_TYPEINFO(Konsole::Character, Q_MOVABLE_TYPE);
199 
200 #endif // CHARACTER_H
201 
Konsole::Character::Character
Character(quint16 _c= ' ', CharacterColor _f=CharacterColor(COLOR_SPACE_DEFAULT, DEFAULT_FORE_COLOR), CharacterColor _b=CharacterColor(COLOR_SPACE_DEFAULT, DEFAULT_BACK_COLOR), quint8 _r=DEFAULT_RENDITION, bool _real=true)
Constructs a new character.
Definition: Character.h:91
Konsole::Character::operator==
friend bool operator==(const Character &a, const Character &b)
Compares two characters and returns true if they have the same unicode character value, rendition and colors.
Definition: Character.h:171
Konsole::Character::character
quint16 character
The unicode character value for this character.
Definition: Character.h:108
DEFAULT_FORE_COLOR
#define DEFAULT_FORE_COLOR
Definition: CharacterColor.h:119
QChar
CharacterColor.h
COLOR_SPACE_DEFAULT
#define COLOR_SPACE_DEFAULT
Definition: CharacterColor.h:139
Konsole::LINE_WRAPPED
const int LINE_WRAPPED
Definition: Character.h:34
Konsole::LINE_DOUBLEWIDTH
const int LINE_DOUBLEWIDTH
Definition: Character.h:35
Konsole::LineProperty
unsigned char LineProperty
Definition: Character.h:31
Konsole::RE_UNDERLINE
const int RE_UNDERLINE
Definition: Character.h:41
Konsole::RE_BLINK
const int RE_BLINK
Definition: Character.h:40
Konsole::RE_INTENSIVE
const int RE_INTENSIVE
Definition: Character.h:43
Konsole::RE_ITALIC
const int RE_ITALIC
Definition: Character.h:44
Konsole::Character
A single character in the terminal which consists of a unicode character value, foreground and backgr...
Definition: Character.h:77
Konsole::Character::isRealCharacter
bool isRealCharacter
Indicate whether this character really exists, or exists simply as place holder.
Definition: Character.h:128
QChar::isSpace
bool isSpace() const
Konsole::Character::equalsFormat
bool equalsFormat(const Character &other) const
returns true if the format (color, rendition flag) of the compared characters is equal ...
Definition: Character.h:181
Konsole::ColorEntry
An entry in a terminal display's color palette.
Definition: CharacterColor.h:40
Konsole::isSupportedLineChar
bool isSupportedLineChar(quint16 codePoint)
Unicode character in the range of U+2500 ~ U+257F are known as line characters, or box-drawing charac...
Definition: Character.h:56
BASE_COLORS
#define BASE_COLORS
Definition: CharacterColor.h:115
Konsole::RE_REVERSE
const int RE_REVERSE
Definition: Character.h:42
Konsole::ColorEntry::FontWeight
FontWeight
Specifies the weight to use when drawing text with this color.
Definition: CharacterColor.h:44
Konsole::operator==
bool operator==(const Character &a, const Character &b)
Definition: Character.h:171
Konsole::Character::operator!=
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:176
Konsole::Character::isLineChar
bool isLineChar() const
Definition: Character.h:154
Konsole::Character::backgroundColor
CharacterColor backgroundColor
The color used to draw this character's background.
Definition: Character.h:117
Konsole::DEFAULT_RENDITION
const int DEFAULT_RENDITION
Definition: Character.h:38
Konsole::CharacterColor
Describes the color of a single character in the terminal.
Definition: CharacterColor.h:147
Konsole::Character::fontWeight
ColorEntry::FontWeight fontWeight(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:188
Konsole::LINE_DEFAULT
const int LINE_DEFAULT
Definition: Character.h:33
Konsole::operator!=
bool operator!=(const Character &a, const Character &b)
Definition: Character.h:176
Konsole::RE_BOLD
const int RE_BOLD
Definition: Character.h:39
Konsole::Character::isSpace
bool isSpace() const
Definition: Character.h:162
Konsole::ColorEntry::UseCurrentFormat
Use the current font weight set by the terminal application.
Definition: CharacterColor.h:53
COLOR_SPACE_SYSTEM
#define COLOR_SPACE_SYSTEM
Definition: CharacterColor.h:140
Q_DECLARE_TYPEINFO
Q_DECLARE_TYPEINFO(Konsole::Character, Q_MOVABLE_TYPE)
Konsole::Character::rendition
quint8 rendition
A combination of RENDITION flags which specify options for drawing the character. ...
Definition: Character.h:111
Konsole::RE_CURSOR
const int RE_CURSOR
Definition: Character.h:45
Konsole::Character::foregroundColor
CharacterColor foregroundColor
The foreground color used to draw this character.
Definition: Character.h:114
Konsole::RE_EXTENDED_CHAR
const int RE_EXTENDED_CHAR
Definition: Character.h:46
Konsole::LINE_DOUBLEHEIGHT
const int LINE_DOUBLEHEIGHT
Definition: Character.h:36
DEFAULT_BACK_COLOR
#define DEFAULT_BACK_COLOR
Definition: CharacterColor.h:120
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Sat May 9 2020 03:56:27 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

Konsole

Skip menu "Konsole"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Related Pages

applications API Reference

Skip menu "applications API Reference"
  •   kate
  •       kate
  •   KTextEditor
  •   Kate
  • Konsole

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal