00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
#ifndef FONTSTYLE_H
00021
#define FONTSTYLE_H
00022
00023
#include <qstring.h>
00024
#include <qfont.h>
00025
00026
#include "contextstyle.h"
00027
#include "kformuladefs.h"
00028
#include "symboltable.h"
00029
00030
00031 KFORMULA_NAMESPACE_BEGIN
00032
00033
class AlphaTable;
00034
class Artwork;
00035
class ContextStyle;
00036
class SymbolTable;
00037
00038
00042 class FontStyle {
00043
public:
00044
00045
virtual ~
FontStyle() {}
00046
00048
virtual bool init(
ContextStyle* context ) = 0;
00049
00051 virtual const SymbolTable*
symbolTable()
const {
return &m_symbolTable; }
00052
virtual SymbolTable*
symbolTable() {
return &m_symbolTable; }
00053
00055 virtual const AlphaTable*
alphaTable()
const {
return 0; };
00056
00057
virtual Artwork* createArtwork(SymbolType type = EmptyBracket)
const = 0;
00058
00059
protected:
00060
00061
00062
void fillNameTable(
SymbolTable::NameTable& names );
00063
00064
private:
00065
00066
SymbolTable m_symbolTable;
00067 };
00068
00069
00073 class AlphaTableEntry {
00074
public:
00075
00076
AlphaTableEntry() : pos( -1 ) {}
00077
00078
bool valid()
const {
return pos > -1; }
00079
00080
QFont font;
00081
short pos;
00082 };
00083
00084
00088 class AlphaTable {
00089
public:
00090
00091
virtual ~
AlphaTable() {}
00092
virtual AlphaTableEntry entry(
short pos, CharFamily family, CharStyle style )
const = 0;
00093 };
00094
00095
00096
const QChar spaceChar = 0x0020;
00097
const QChar leftParenthesisChar = 0x0028;
00098
const QChar rightParenthesisChar = 0x0029;
00099
const QChar leftSquareBracketChar = 0x005B;
00100
const QChar rightSquareBracketChar = 0x005D;
00101
const QChar leftCurlyBracketChar = 0x007B;
00102
const QChar verticalLineChar = 0x007C;
00103
const QChar rightCurlyBracketChar = 0x007D;
00104
const QChar leftAngleBracketChar = 0x2329;
00105
const QChar rightAngleBracketChar = 0x232A;
00106
const QChar slashChar = 0x002F;
00107
const QChar backSlashChar = 0x005C;
00108
const QChar integralChar = 0x222B;
00109
const QChar summationChar = 0x2211;
00110
const QChar productChar = 0x220F;
00111
00112
extern const QChar leftRoundBracket[];
00113
extern const QChar leftSquareBracket[];
00114
extern const QChar leftCurlyBracket[];
00115
00116
extern const QChar leftLineBracket[];
00117
extern const QChar rightLineBracket[];
00118
00119
extern const QChar rightRoundBracket[];
00120
extern const QChar rightSquareBracket[];
00121
extern const QChar rightCurlyBracket[];
00122
00123
00124
00125
00126
class Artwork {
00127
public:
00128
00129 Artwork(SymbolType type = EmptyBracket);
00130
virtual ~Artwork() {}
00131
00132
virtual void calcSizes(
const ContextStyle& style,
00133 ContextStyle::TextStyle tstyle,
00134 luPt parentSize ) = 0;
00135
virtual void calcSizes(
const ContextStyle& style,
00136 ContextStyle::TextStyle tstyle );
00137
00138
virtual void draw(
QPainter& painter,
const LuPixelRect& r,
00139
const ContextStyle& style,
00140 ContextStyle::TextStyle tstyle,
00141 luPt parentSize,
const LuPixelPoint& origin ) = 0;
00142
virtual void draw(
QPainter& painter,
const LuPixelRect& r,
00143
const ContextStyle& style,
00144 ContextStyle::TextStyle tstyle,
00145
const LuPixelPoint& parentOrigin );
00146
00147 luPixel getWidth()
const {
return size.width(); }
00148 luPixel getHeight()
const {
return size.height(); }
00149
00150
void setWidth( luPixel width ) { size.setWidth(width); }
00151
void setHeight( luPixel height ) { size.setHeight(height); }
00152
00153 luPixel getBaseline()
const {
return baseline; }
00154
void setBaseline( luPixel line ) { baseline = line; }
00155
00156 luPixel getX()
const {
return point.x(); }
00157 luPixel getY()
const {
return point.y(); }
00158
00159
void setX( luPixel x ) { point.setX( x ); }
00160
void setY( luPixel y ) { point.setY( y ); }
00161
00162 SymbolType getType()
const {
return type; }
00163
void setType(SymbolType t) { type = t; }
00164
00165
virtual bool isNormalChar()
const {
return getBaseline() != -1; }
00166
00167
virtual double slant()
const {
return 0; }
00168
00169
protected:
00170
00171
void calcCharSize(
const ContextStyle& style, luPt height,
QChar ch );
00172
void drawCharacter(
QPainter& painter,
const ContextStyle& style,
00173 luPixel x, luPixel y, luPt height,
QChar ch );
00174
00175
void calcCharSize(
const ContextStyle& style,
QFont f,
00176 luPt height, uchar c );
00177
void drawCharacter(
QPainter& painter,
const ContextStyle& style,
00178
QFont f,
00179 luPixel x, luPixel y, luPt height, uchar c );
00180
00181
void calcRoundBracket(
const ContextStyle& style,
const QChar chars[], luPt height, luPt charHeight );
00182
void calcCurlyBracket(
const ContextStyle& style,
const QChar chars[], luPt height, luPt charHeight );
00183
00184
void drawBigRoundBracket(
QPainter& p,
const ContextStyle& style,
const QChar chars[], luPixel x, luPixel y, luPt charHeight );
00185
void drawBigCurlyBracket(
QPainter& p,
const ContextStyle& style,
const QChar chars[], luPixel x, luPixel y, luPt charHeight );
00186
00187
private:
00188
00189
LuPixelSize size;
00190
LuPixelPoint point;
00191
00195 luPixel baseline;
00196
00197 SymbolType type;
00198 };
00199
00200
00201 KFORMULA_NAMESPACE_END
00202
00203
#endif