Commit 726c106f authored by Robert Knight's avatar Robert Knight
Browse files

Move Character class to its own header.

svn path=/trunk/KDE/kdebase/apps/konsole/; revision=677276
parent dbedf8d4
/*
This file is part of Konsole, KDE's terminal.
Copyright (C) 2007 by Robert Knight <robertknight@gmail.com>
Copyright (C) 1997,1998 by Lars Doelle <lars.doelle@on-line.de>
This program 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 2 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.
*/
#ifndef CHARACTER_H
#define CHARACTER_H
// Qt
#include <QtCore/QHash>
// Local
#include "TECommon.h"
namespace Konsole
{
typedef unsigned char LineProperty;
static const int LINE_DEFAULT = 0;
static const int LINE_WRAPPED = (1 << 0);
static const int LINE_DOUBLEWIDTH = (1 << 1);
static const int LINE_DOUBLEHEIGHT = (1 << 2);
#define DEFAULT_RENDITION 0
#define RE_BOLD (1 << 0)
#define RE_BLINK (1 << 1)
#define RE_UNDERLINE (1 << 2)
#define RE_REVERSE (1 << 3) // Screen only
#define RE_INTENSIVE (1 << 3) // Widget only
#define RE_CURSOR (1 << 4)
#define RE_EXTENDED_CHAR (1 << 5)
/**
* A single character in the terminal which consists of a unicode character
* value, foreground and background colors and a set of rendition attributes
* which specify how it should be drawn.
*/
class Character
{
public:
/**
* Constructs a new character.
*
* @param _c The unicode character value of this character.
* @param _f The foreground color used to draw the character.
* @param _b The color used to draw the character's background.
* @param _r A set of rendition flags which specify how this character is to be drawn.
*/
inline 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)
: character(_c), rendition(_r), foregroundColor(_f), backgroundColor(_b) {}
union
{
/** The unicode character value for this character. */
quint16 character;
/**
* Experimental addition which allows a single Character instance to contain more than
* one unicode character.
*
* charSequence is a hash code which can be used to look up the unicode
* character sequence in the ExtendedCharTable used to create the sequence.
*/
quint16 charSequence;
};
/** A combination of *_RENDITION flags which specify options for drawing the character. */
quint8 rendition;
/** The foreground color used to draw this character. */
CharacterColor foregroundColor;
/** The color used to draw this character's background. */
CharacterColor backgroundColor;
/**
* Returns true if this character has a transparent background when
* it is drawn with the specified @p palette.
*/
bool isTransparent(const ColorEntry* palette) const;
/**
* Returns true if this character should always be drawn in bold when
* it is drawn with the specified @p palette, independant of whether
* or not the character has the RE_BOLD rendition flag.
*/
bool isBold(const ColorEntry* base) const;
/**
* Compares two characters and returns true if they have the same unicode character value,
* rendition and colors.
*/
friend bool operator == (const Character& a, const Character& b);
/**
* Compares two characters and returns true if they have different unicode character values,
* renditions or colors.
*/
friend bool operator != (const Character& a, const Character& b);
};
inline bool operator == (const Character& a, const Character& b)
{
return a.character == b.character &&
a.rendition == b.rendition &&
a.foregroundColor == b.foregroundColor &&
a.backgroundColor == b.backgroundColor;
}
inline bool operator != (const Character& a, const Character& b)
{
return a.character != b.character ||
a.rendition != b.rendition ||
a.foregroundColor != b.foregroundColor ||
a.backgroundColor != b.backgroundColor;
}
inline bool Character::isTransparent(const ColorEntry* base) const
{
return ((backgroundColor._colorSpace == COLOR_SPACE_DEFAULT) &&
base[backgroundColor._u+0+(backgroundColor._v?BASE_COLORS:0)].transparent)
|| ((backgroundColor._colorSpace == COLOR_SPACE_SYSTEM) &&
base[backgroundColor._u+2+(backgroundColor._v?BASE_COLORS:0)].transparent);
}
inline bool Character::isBold(const ColorEntry* base) const
{
return (backgroundColor._colorSpace == COLOR_SPACE_DEFAULT) &&
base[backgroundColor._u+0+(backgroundColor._v?BASE_COLORS:0)].bold
|| (backgroundColor._colorSpace == COLOR_SPACE_SYSTEM) &&
base[backgroundColor._u+2+(backgroundColor._v?BASE_COLORS:0)].bold;
}
extern unsigned short vt100_graphics[32];
/**
* A table which stores sequences of unicode characters, referenced
* by hash keys. The hash key itself is the same size as a unicode
* character ( ushort ) so that it can occupy the same space in
* a structure.
*/
class ExtendedCharTable
{
public:
/** Constructs a new character table. */
ExtendedCharTable();
~ExtendedCharTable();
/**
* Adds a sequences of unicode characters to the table and returns
* a hash code which can be used later to look up the sequence
* using lookupExtendedChar()
*
* If the same sequence already exists in the table, the hash
* of the existing sequence will be returned.
*
* @param unicodePoints An array of unicode character points
* @param length Length of @p unicodePoints
*/
ushort createExtendedChar(ushort* unicodePoints , ushort length);
/**
* Looks up and returns a pointer to a sequence of unicode characters
* which was added to the table using createExtendedChar().
*
* @param hash The hash key returned by createExtendedChar()
* @param length This variable is set to the length of the
* character sequence.
*
* @return A unicode character sequence of size @p length.
*/
ushort* lookupExtendedChar(ushort hash , ushort& length) const;
/** The global ExtendedCharTable instance. */
static ExtendedCharTable instance;
private:
// calculates the hash key of a sequence of unicode points of size 'length'
ushort extendedCharHash(ushort* unicodePoints , ushort length) const;
// tests whether the entry in the table specified by 'hash' matches the
// character sequence 'unicodePoints' of size 'length'
bool extendedCharMatch(ushort hash , ushort* unicodePoints , ushort length) const;
// internal, maps hash keys to character sequence buffers. The first ushort
// in each value is the length of the buffer, followed by the ushorts in the buffer
// themselves.
QHash<ushort,ushort*> extendedCharTable;
};
}
#endif // CHARACTER_H
......@@ -31,9 +31,6 @@
#include <KLocale>
#include <KStandardDirs>
// Konsole
#include "TECommon.h"
using namespace Konsole;
const ColorEntry ColorScheme::defaultTable[TABLE_COLORS] =
......
......@@ -31,7 +31,7 @@
// Konsole
#include "BlockArray.h"
#include "TECommon.h"
#include "Character.h"
namespace Konsole
{
......
......@@ -29,7 +29,7 @@
#include <QtCore/QVarLengthArray>
// Konsole
#include "TECommon.h"
#include "Character.h"
#include "History.h"
#define MODE_Origin 0
......@@ -437,7 +437,7 @@ private: // helper
CharacterColor cu_fg; // foreground
CharacterColor cu_bg; // background
UINT8 cu_re; // rendition
quint8 cu_re; // rendition
// margins ----------------
......@@ -464,7 +464,7 @@ private: // helper
CharacterColor ef_fg; // These are derived from
CharacterColor ef_bg; // the cu_* variables above
UINT8 ef_re; // to speed up operation
quint8 ef_re; // to speed up operation
//
// save cursor, rendition & states ------------
......@@ -477,7 +477,7 @@ private: // helper
// rendition info
UINT8 sa_cu_re;
quint8 sa_cu_re;
CharacterColor sa_cu_fg;
CharacterColor sa_cu_bg;
......
......@@ -26,7 +26,7 @@
#include <QtCore/QRect>
// Konsole
#include "TECommon.h"
#include "Character.h"
namespace Konsole
{
......
......@@ -20,24 +20,15 @@
02110-1301 USA.
*/
#ifndef TECOMMON_H
#define TECOMMON_H
#ifndef CHARACTERCOLOR_H
#define CHARACTERCOLOR_H
// Qt
#include <QtGui/QColor>
#include <QtCore/QHash>
namespace Konsole
{
#ifndef UINT8
typedef unsigned char UINT8;
#endif
#ifndef UINT16
typedef unsigned short UINT16;
#endif
/**
* An entry in a terminal display's color palette.
*
......@@ -129,72 +120,6 @@ static const ColorEntry base_color_table[TABLE_COLORS] =
ColorEntry(QColor(0x54,0xFF,0xFF), 0, 0 ), ColorEntry( QColor(0xFF,0xFF,0xFF), 0, 0 )
};
#define DEFAULT_RENDITION 0
#define RE_BOLD (1 << 0)
#define RE_BLINK (1 << 1)
#define RE_UNDERLINE (1 << 2)
#define RE_REVERSE (1 << 3) // Screen only
#define RE_INTENSIVE (1 << 3) // Widget only
#define RE_CURSOR (1 << 4)
#define RE_EXTENDED_CHAR (1 << 5)
/**
* A table which stores sequences of unicode characters, referenced
* by hash keys. The hash key itself is the same size as a unicode
* character ( ushort ) so that it can occupy the same space in
* a structure.
*/
class ExtendedCharTable
{
public:
/** Constructs a new character table. */
ExtendedCharTable();
~ExtendedCharTable();
/**
* Adds a sequences of unicode characters to the table and returns
* a hash code which can be used later to look up the sequence
* using lookupExtendedChar()
*
* If the same sequence already exists in the table, the hash
* of the existing sequence will be returned.
*
* @param unicodePoints An array of unicode character points
* @param length Length of @p unicodePoints
*/
ushort createExtendedChar(ushort* unicodePoints , ushort length);
/**
* Looks up and returns a pointer to a sequence of unicode characters
* which was added to the table using createExtendedChar().
*
* @param hash The hash key returned by createExtendedChar()
* @param length This variable is set to the length of the
* character sequence.
*
* @return A unicode character sequence of size @p length.
*/
ushort* lookupExtendedChar(ushort hash , ushort& length) const;
/** The global ExtendedCharTable instance. */
static ExtendedCharTable instance;
private:
// calculates the hash key of a sequence of unicode points of size 'length'
ushort extendedCharHash(ushort* unicodePoints , ushort length) const;
// tests whether the entry in the table specified by 'hash' matches the
// character sequence 'unicodePoints' of size 'length'
bool extendedCharMatch(ushort hash , ushort* unicodePoints , ushort length) const;
// internal, maps hash keys to character sequence buffers. The first ushort
// in each value is the length of the buffer, followed by the ushorts in the buffer
// themselves.
QHash<ushort,ushort*> extendedCharTable;
};
typedef unsigned char LineProperty;
static const int LINE_DEFAULT = 0;
static const int LINE_WRAPPED = (1 << 0);
static const int LINE_DOUBLEWIDTH = (1 << 1);
static const int LINE_DOUBLEHEIGHT = (1 << 2);
/* CharacterColor is a union of the various color spaces.
......@@ -244,7 +169,7 @@ public:
*
* TODO : Add documentation about available color spaces.
*/
CharacterColor(UINT8 colorSpace, int co)
CharacterColor(quint8 colorSpace, int co)
: _colorSpace(colorSpace),
_u(0),
_v(0),
......@@ -301,12 +226,12 @@ public:
friend bool operator != (const CharacterColor& a, const CharacterColor& b);
private:
UINT8 _colorSpace;
quint8 _colorSpace;
// bytes storing the character color
UINT8 _u;
UINT8 _v;
UINT8 _w;
quint8 _u;
quint8 _v;
quint8 _w;
};
inline bool operator == (const CharacterColor& a, const CharacterColor& b)
......@@ -321,7 +246,7 @@ inline bool operator != (const CharacterColor& a, const CharacterColor& b)
*reinterpret_cast<const quint32*>(&b._colorSpace);
}
inline const QColor color256(UINT8 u, const ColorEntry* base)
inline const QColor color256(quint8 u, const ColorEntry* base)
{
// 0.. 16: system colors
if (u < 8) return base[u+2 ].color; u -= 8;
......@@ -360,108 +285,8 @@ inline void CharacterColor::toggleIntensive()
}
}
/**
* A single character in the terminal which consists of a unicode character
* value, foreground and background colors and a set of rendition attributes
* which specify how it should be drawn.
*/
class Character
{
public:
/**
* Constructs a new character.
*
* @param _c The unicode character value of this character.
* @param _f The foreground color used to draw the character.
* @param _b The color used to draw the character's background.
* @param _r A set of rendition flags which specify how this character is to be drawn.
*/
inline Character(UINT16 _c = ' ',
CharacterColor _f = CharacterColor(COLOR_SPACE_DEFAULT,DEFAULT_FORE_COLOR),
CharacterColor _b = CharacterColor(COLOR_SPACE_DEFAULT,DEFAULT_BACK_COLOR),
UINT8 _r = DEFAULT_RENDITION)
: character(_c), rendition(_r), foregroundColor(_f), backgroundColor(_b) {}
union
{
/** The unicode character value for this character. */
UINT16 character;
/**
* Experimental addition which allows a single Character instance to contain more than
* one unicode character.
*
* charSequence is a hash code which can be used to look up the unicode
* character sequence in the ExtendedCharTable used to create the sequence.
*/
UINT16 charSequence;
};
/** A combination of *_RENDITION flags which specify options for drawing the character. */
UINT8 rendition;
/** The foreground color used to draw this character. */
CharacterColor foregroundColor;
/** The color used to draw this character's background. */
CharacterColor backgroundColor;
/**
* Returns true if this character has a transparent background when
* it is drawn with the specified @p palette.
*/
bool isTransparent(const ColorEntry* palette) const;
/**
* Returns true if this character should always be drawn in bold when
* it is drawn with the specified @p palette, independant of whether
* or not the character has the RE_BOLD rendition flag.
*/
bool isBold(const ColorEntry* base) const;
/**
* Compares two characters and returns true if they have the same unicode character value,
* rendition and colors.
*/
friend bool operator == (const Character& a, const Character& b);
/**
* Compares two characters and returns true if they have different unicode character values,
* renditions or colors.
*/
friend bool operator != (const Character& a, const Character& b);
};
inline bool operator == (const Character& a, const Character& b)
{
return a.character == b.character &&
a.rendition == b.rendition &&
a.foregroundColor == b.foregroundColor &&
a.backgroundColor == b.backgroundColor;
}
inline bool operator != (const Character& a, const Character& b)
{
return a.character != b.character ||
a.rendition != b.rendition ||
a.foregroundColor != b.foregroundColor ||
a.backgroundColor != b.backgroundColor;
}
inline bool Character::isTransparent(const ColorEntry* base) const
{
return ((backgroundColor._colorSpace == COLOR_SPACE_DEFAULT) &&
base[backgroundColor._u+0+(backgroundColor._v?BASE_COLORS:0)].transparent)
|| ((backgroundColor._colorSpace == COLOR_SPACE_SYSTEM) &&
base[backgroundColor._u+2+(backgroundColor._v?BASE_COLORS:0)].transparent);
}
inline bool Character::isBold(const ColorEntry* base) const
{
return (backgroundColor._colorSpace == COLOR_SPACE_DEFAULT) &&
base[backgroundColor._u+0+(backgroundColor._v?BASE_COLORS:0)].bold
|| (backgroundColor._colorSpace == COLOR_SPACE_SYSTEM) &&
base[backgroundColor._u+2+(backgroundColor._v?BASE_COLORS:0)].bold;
}
extern unsigned short vt100_graphics[32];
}
#endif // CHARACTERCOLOR_H
#endif // TECOMMON_H
......@@ -22,7 +22,7 @@
#ifndef TERMINAL_CHARACTER_DECODER_H
#define TERMINAL_CHARACTER_DECODER_H
#include "TECommon.h"
#include "Character.h"
class QTextStream;
......@@ -126,7 +126,7 @@ private:
QTextStream* _output;
const ColorEntry* _colorTable;
bool _innerSpanOpen;
UINT8 _lastRendition;
quint8 _lastRendition;
CharacterColor _lastForeColor;
CharacterColor _lastBackColor;
......
......@@ -1266,7 +1266,7 @@ void TerminalDisplay::paintContents(QPainter &paint, const QRect &rect)
bool doubleWidth = (_image[ qMin(loc(x,y)+1,_imageSize) ].character == 0);
CharacterColor currentForeground = _image[loc(x,y)].foregroundColor;
CharacterColor currentBackground = _image[loc(x,y)].backgroundColor;
UINT8 currentRendition = _image[loc(x,y)].rendition;
quint8 currentRendition = _image[loc(x,y)].rendition;
while (x+len <= rlx &&
_image[loc(x+len,y)].foregroundColor == currentForeground &&
......@@ -2172,7 +2172,7 @@ bool TerminalDisplay::focusNextPrevChild( bool next )
}
int TerminalDisplay::charClass(UINT16 ch) const
int TerminalDisplay::charClass(quint16 ch) const
{
QChar qch=QChar(ch);
if ( qch.isSpace() ) return ' ';
......
......@@ -28,7 +28,7 @@
// Konsole
#include "Filter.h"
#include "TECommon.h"
#include "Character.h"
class QDrag;
class QDragEnterEvent;
......@@ -503,7 +503,7 @@ protected:
QDrag *dragObject;
} dragInfo;
virtual int charClass(UINT16) const;
virtual int charClass(quint16) const;
void clearImage();
......
......@@ -242,16 +242,16 @@ void Vt102Emulation::pushToToken(int cc)
#define CPS 64
void Vt102Emulation::initTokenizer()
{ int i; UINT8* s;
{ int i; quint8* s;
for(i = 0; i < 256; i++) tbl[ i] = 0;
for(i = 0; i < 32; i++) tbl[ i] |= CTL;
for(i = 32; i < 256; i++) tbl[ i] |= CHR;
for(s = (UINT8*)"@ABCDGHILMPSTXZcdfry"; *s; s++) tbl[*s] |= CPN;
for(s = (quint8*)"@ABCDGHILMPSTXZcdfry"; *s; s++) tbl[*s] |= CPN;
// resize = \e[8;<row>;<col>t
for(s = (UINT8*)"t"; *s; s++) tbl[*s] |= CPS;
for(s = (UINT8*)"0123456789" ; *s; s++) tbl[*s] |= DIG;
for(s = (UINT8*)"()+*%" ; *s; s++) tbl[*s] |= SCS;
for(s = (UINT8*)"()+*#[]%" ; *s; s++) tbl[*s] |= GRP;
for(s = (quint8*)"t"; *s; s++) tbl[*s] |= CPS;
for(s = (quint8*)"0123456789" ; *s; s++) tbl[*s] |= DIG;
for(s = (quint8*)"()+*%" ; *s; s++) tbl[*s] |= SCS;
for(s = (quint8*)"()+*#[]%" ; *s; s++) tbl[*s] |= GRP;
resetToken();
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment