lib Library API Documentation

fontstyle.h

00001 /* This file is part of the KDE project
00002    Copyright (C) 2003 Ulrich Kuettler <ulrich.kuettler@gmx.de>
00003 
00004    This library is free software; you can redistribute it and/or
00005    modify it under the terms of the GNU Library General Public
00006    License as published by the Free Software Foundation; either
00007    version 2 of the License, or (at your option) any later version.
00008 
00009    This library is distributed in the hope that it will be useful,
00010    but WITHOUT ANY WARRANTY; without even the implied warranty of
00011    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00012    Library General Public License for more details.
00013 
00014    You should have received a copy of the GNU Library General Public License
00015    along with this library; see the file COPYING.LIB.  If not, write to
00016    the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
00017    Boston, MA 02111-1307, USA.
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     // This is going to disappear in favour of a real macro facility some day.
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  * A piece of art that may be used by any element.
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
KDE Logo
This file is part of the documentation for lib Library Version 1.4.2.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Mon Feb 13 09:39:56 2006 by doxygen 1.4.2 written by Dimitri van Heesch, © 1997-2003