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 static void testFont( QStringList& missing, const QString& fontName );
00065
00066 private:
00067
00068 SymbolTable m_symbolTable;
00069 };
00070
00071
00075 class AlphaTableEntry {
00076 public:
00077
00078 AlphaTableEntry() : pos( -1 ) {}
00079
00080 bool valid() const { return pos > -1; }
00081
00082 QFont font;
00083 short pos;
00084 };
00085
00086
00090 class AlphaTable {
00091 public:
00092
00093 virtual ~AlphaTable() {}
00094 virtual AlphaTableEntry entry( short pos, CharFamily family, CharStyle style ) const = 0;
00095 };
00096
00097
00098 const QChar spaceChar = 0x0020;
00099 const QChar leftParenthesisChar = 0x0028;
00100 const QChar rightParenthesisChar = 0x0029;
00101 const QChar leftSquareBracketChar = 0x005B;
00102 const QChar rightSquareBracketChar = 0x005D;
00103 const QChar leftCurlyBracketChar = 0x007B;
00104 const QChar verticalLineChar = 0x007C;
00105 const QChar rightCurlyBracketChar = 0x007D;
00106 const QChar leftAngleBracketChar = 0x2329;
00107 const QChar rightAngleBracketChar = 0x232A;
00108 const QChar slashChar = 0x002F;
00109 const QChar backSlashChar = 0x005C;
00110 const QChar integralChar = 0x222B;
00111 const QChar summationChar = 0x2211;
00112 const QChar productChar = 0x220F;
00113
00114 extern const QChar leftRoundBracket[];
00115 extern const QChar leftSquareBracket[];
00116 extern const QChar leftCurlyBracket[];
00117
00118 extern const QChar leftLineBracket[];
00119 extern const QChar rightLineBracket[];
00120
00121 extern const QChar rightRoundBracket[];
00122 extern const QChar rightSquareBracket[];
00123 extern const QChar rightCurlyBracket[];
00124
00125
00126
00127
00128 class Artwork {
00129 public:
00130
00131 Artwork(SymbolType type = EmptyBracket);
00132 virtual ~Artwork() {}
00133
00134 virtual void calcSizes( const ContextStyle& style,
00135 ContextStyle::TextStyle tstyle,
00136 luPt parentSize ) = 0;
00137 virtual void calcSizes( const ContextStyle& style,
00138 ContextStyle::TextStyle tstyle );
00139
00140 virtual void draw( QPainter& painter, const LuPixelRect& r,
00141 const ContextStyle& style,
00142 ContextStyle::TextStyle tstyle,
00143 luPt parentSize, const LuPixelPoint& origin ) = 0;
00144 virtual void draw( QPainter& painter, const LuPixelRect& r,
00145 const ContextStyle& style,
00146 ContextStyle::TextStyle tstyle,
00147 const LuPixelPoint& parentOrigin );
00148
00149 luPixel getWidth() const { return size.width(); }
00150 luPixel getHeight() const { return size.height(); }
00151
00152 void setWidth( luPixel width ) { size.setWidth(width); }
00153 void setHeight( luPixel height ) { size.setHeight(height); }
00154
00155 luPixel getBaseline() const { return baseline; }
00156 void setBaseline( luPixel line ) { baseline = line; }
00157
00158 luPixel getX() const { return point.x(); }
00159 luPixel getY() const { return point.y(); }
00160
00161 void setX( luPixel x ) { point.setX( x ); }
00162 void setY( luPixel y ) { point.setY( y ); }
00163
00164 SymbolType getType() const { return type; }
00165 void setType(SymbolType t) { type = t; }
00166
00167 virtual bool isNormalChar() const { return getBaseline() != -1; }
00168
00169 virtual double slant() const { return 0; }
00170
00171 protected:
00172
00173 void calcCharSize( const ContextStyle& style, luPt height, QChar ch );
00174 void drawCharacter( QPainter& painter, const ContextStyle& style,
00175 luPixel x, luPixel y, luPt height, QChar ch );
00176
00177 void calcCharSize( const ContextStyle& style, QFont f,
00178 luPt height, uchar c );
00179 void drawCharacter( QPainter& painter, const ContextStyle& style,
00180 QFont f,
00181 luPixel x, luPixel y, luPt height, uchar c );
00182
00183 void calcRoundBracket( const ContextStyle& style, const QChar chars[], luPt height, luPt charHeight );
00184 void calcCurlyBracket( const ContextStyle& style, const QChar chars[], luPt height, luPt charHeight );
00185
00186 void drawBigRoundBracket( QPainter& p, const ContextStyle& style, const QChar chars[], luPixel x, luPixel y, luPt charHeight );
00187 void drawBigCurlyBracket( QPainter& p, const ContextStyle& style, const QChar chars[], luPixel x, luPixel y, luPt charHeight );
00188
00189 private:
00190
00191 LuPixelSize size;
00192 LuPixelPoint point;
00193
00197 luPixel baseline;
00198
00199 SymbolType type;
00200 };
00201
00202
00203 KFORMULA_NAMESPACE_END
00204
00205 #endif