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