F:/KPlato/koffice/libs/kformula/symbolfontstyle.cc

Aller à la documentation de ce fichier.
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., 51 Franklin Street, Fifth Floor,
00017  * Boston, MA 02110-1301, USA.
00018 */
00019 
00020 #include <QPainter>
00021 #include <QPen>
00022 
00023 #include <kdebug.h>
00024 #include <klocale.h>
00025 
00026 #include "kformuladefs.h"
00027 #include "symbolfontstyle.h"
00028 
00029 
00030 KFORMULA_NAMESPACE_BEGIN
00031 
00032 #include "symbolfontmapping.cc"
00033 
00034 
00035 SymbolFontHelper::SymbolFontHelper()
00036     : greek("abgdezhqiklmnxpvrstufjcywGDQLXPSUFYVW")
00037 {
00038     for ( uint i = 0; symbolMap[ i ].unicode != 0; i++ ) {
00039         compatibility[ symbolMap[ i ].pos ] = symbolMap[ i ].unicode;
00040     }
00041 }
00042 
00043 
00044 bool SymbolFontStyle::init( ContextStyle* context, bool /* install */)
00045 {
00046     // We require the symbol font to be there as it's the last resort
00047     // anyway.
00048     symbolTable()->init( context );
00049 
00050     SymbolTable::NameTable names;
00051     fillNameTable( names );
00052     symbolTable()->initFont( symbolMap, "symbol", names );
00053 
00054     return true;
00055 }
00056 
00057 
00058 Artwork* SymbolFontStyle::createArtwork( SymbolType type ) const
00059 {
00060     return new SymbolArtwork( type );
00061 }
00062 
00063 QStringList SymbolFontStyle::missingFonts()
00064 {
00065     QStringList missing;
00066 
00067     testFont( missing, "symbol" );
00068 
00069     return missing;
00070 }
00071 
00072 inline bool doSimpleRoundBracket( luPt height, luPt baseHeight )
00073 {
00074     return height < 1.5*baseHeight;
00075 }
00076 
00077 inline bool doSimpleSquareBracket( luPt height, luPt baseHeight )
00078 {
00079     return height < 1.5*baseHeight;
00080 }
00081 
00082 inline bool doSimpleCurlyBracket( luPt height, luPt baseHeight )
00083 {
00084     return height < 2*baseHeight;
00085 }
00086 
00087 
00088 void SymbolArtwork::calcSizes( const ContextStyle& style,
00089                                ContextStyle::TextStyle tstyle,
00090                                luPt parentSize )
00091 {
00092     setBaseline( -1 );
00093     luPt mySize = style.getAdjustedSize( tstyle );
00094     switch (getType()) {
00095     case LeftSquareBracket:
00096         if ( doSimpleSquareBracket( parentSize, mySize ) ) {
00097             calcCharSize( style, mySize, leftSquareBracketChar );
00098             return;
00099         }
00100         calcRoundBracket( style, leftSquareBracket, parentSize, mySize );
00101         break;
00102     case RightSquareBracket:
00103         if ( doSimpleSquareBracket( parentSize, mySize ) ) {
00104             calcCharSize(style, mySize, rightSquareBracketChar);
00105             return;
00106         }
00107         calcRoundBracket( style, rightSquareBracket, parentSize, mySize );
00108         break;
00109     case LeftLineBracket:
00110         if ( doSimpleSquareBracket( parentSize, mySize ) ) {
00111             calcCharSize(style, mySize, verticalLineChar);
00112             return;
00113         }
00114         calcRoundBracket( style, leftLineBracket, parentSize, mySize );
00115         break;
00116     case RightLineBracket:
00117         if ( doSimpleSquareBracket( parentSize, mySize ) ) {
00118             calcCharSize(style, mySize, verticalLineChar);
00119             return;
00120         }
00121         calcRoundBracket( style, rightLineBracket, parentSize, mySize );
00122         break;
00123     case SlashBracket:
00124         //calcCharSize(style, mySize, '/');
00125         break;
00126     case BackSlashBracket:
00127         //calcCharSize(style, mySize, '\\');
00128         break;
00129     case LeftCornerBracket:
00130         calcCharSize(style, mySize, leftAngleBracketChar);
00131         break;
00132     case RightCornerBracket:
00133         calcCharSize(style, mySize, rightAngleBracketChar);
00134         break;
00135     case LeftRoundBracket:
00136         if ( doSimpleRoundBracket( parentSize, mySize ) ) {
00137             calcCharSize(style, mySize, leftParenthesisChar);
00138             return;
00139         }
00140         calcRoundBracket( style, leftRoundBracket, parentSize, mySize );
00141         break;
00142     case RightRoundBracket:
00143         if ( doSimpleRoundBracket( parentSize, mySize ) ) {
00144             calcCharSize(style, mySize, rightParenthesisChar);
00145             return;
00146         }
00147         calcRoundBracket( style, rightRoundBracket, parentSize, mySize );
00148         break;
00149     case EmptyBracket:
00150         setHeight(parentSize);
00151         //setWidth(style.getEmptyRectWidth());
00152         setWidth(0);
00153         break;
00154     case LeftCurlyBracket:
00155         if ( doSimpleCurlyBracket( parentSize, mySize ) ) {
00156             calcCharSize(style, mySize, leftCurlyBracketChar);
00157             return;
00158         }
00159         calcCurlyBracket( style, leftCurlyBracket, parentSize, mySize );
00160         break;
00161     case RightCurlyBracket:
00162         if ( doSimpleCurlyBracket( parentSize, mySize ) ) {
00163             calcCharSize(style, mySize, rightCurlyBracketChar);
00164             return;
00165         }
00166         calcCurlyBracket( style, rightCurlyBracket, parentSize, mySize );
00167         break;
00168     case Integral:
00169         calcCharSize( style, qRound( 1.5*mySize ), integralChar );
00170         break;
00171     case Sum:
00172         calcCharSize( style, qRound( 1.5*mySize ), summationChar );
00173         break;
00174     case Product:
00175         calcCharSize( style, qRound( 1.5*mySize ), productChar );
00176         break;
00177     }
00178 }
00179 
00180 
00181 void SymbolArtwork::draw(QPainter& painter, const LuPixelRect& /*r*/,
00182                          const ContextStyle& style, ContextStyle::TextStyle tstyle,
00183                          luPt parentSize, const LuPixelPoint& origin)
00184 {
00185     luPt mySize = style.getAdjustedSize( tstyle );
00186     luPixel myX = origin.x() + getX();
00187     luPixel myY = origin.y() + getY();
00188     /*
00189     if ( !LuPixelRect( myX, myY, getWidth(), getHeight() ).intersects( r ) )
00190         return;
00191     */
00192 
00193     painter.setPen(style.getDefaultColor());
00194 
00195     switch (getType()) {
00196     case LeftSquareBracket:
00197         if ( !doSimpleSquareBracket( parentSize, mySize ) ) {
00198             drawBigRoundBracket( painter, style, leftSquareBracket, myX, myY, mySize );
00199         }
00200         else {
00201             drawCharacter(painter, style, myX, myY, mySize, leftSquareBracketChar);
00202         }
00203         break;
00204     case RightSquareBracket:
00205         if ( !doSimpleSquareBracket( parentSize, mySize ) ) {
00206             drawBigRoundBracket( painter, style, rightSquareBracket, myX, myY, mySize );
00207         }
00208         else {
00209             drawCharacter(painter, style, myX, myY, mySize, rightSquareBracketChar);
00210         }
00211         break;
00212     case LeftCurlyBracket:
00213         if ( !doSimpleCurlyBracket( parentSize, mySize ) ) {
00214             drawBigCurlyBracket( painter, style, leftCurlyBracket, myX, myY, mySize );
00215         }
00216         else {
00217             drawCharacter(painter, style, myX, myY, mySize, leftCurlyBracketChar);
00218         }
00219         break;
00220     case RightCurlyBracket:
00221         if ( !doSimpleCurlyBracket( parentSize, mySize ) ) {
00222             drawBigCurlyBracket( painter, style, rightCurlyBracket, myX, myY, mySize );
00223         }
00224         else {
00225             drawCharacter(painter, style, myX, myY, mySize, rightCurlyBracketChar);
00226         }
00227         break;
00228     case LeftLineBracket:
00229         if ( !doSimpleSquareBracket( parentSize, mySize ) ) {
00230             drawBigRoundBracket( painter, style, leftLineBracket, myX, myY, mySize );
00231         }
00232         else {
00233             drawCharacter(painter, style, myX, myY, mySize, verticalLineChar);
00234         }
00235         break;
00236     case RightLineBracket:
00237         if ( !doSimpleSquareBracket( parentSize, mySize ) ) {
00238             drawBigRoundBracket( painter, style, rightLineBracket, myX, myY, mySize );
00239         }
00240         else {
00241             drawCharacter(painter, style, myX, myY, mySize, verticalLineChar);
00242         }
00243         break;
00244     case SlashBracket:
00245         //drawCharacter(painter, style, myX, myY, mySize, '/');
00246         break;
00247     case BackSlashBracket:
00248         //drawCharacter(painter, style, myX, myY, mySize, '\\');
00249         break;
00250     case LeftCornerBracket:
00251         drawCharacter(painter, style, myX, myY, mySize, leftAngleBracketChar);
00252         break;
00253     case RightCornerBracket:
00254         drawCharacter(painter, style, myX, myY, mySize, rightAngleBracketChar);
00255         break;
00256     case LeftRoundBracket:
00257         if ( !doSimpleRoundBracket( parentSize, mySize ) ) {
00258             drawBigRoundBracket( painter, style, leftRoundBracket, myX, myY, mySize );
00259         }
00260         else {
00261             drawCharacter(painter, style, myX, myY, mySize, leftParenthesisChar);
00262         }
00263         break;
00264     case RightRoundBracket:
00265         if ( !doSimpleRoundBracket( parentSize, mySize ) ) {
00266             drawBigRoundBracket( painter, style, rightRoundBracket, myX, myY, mySize );
00267         }
00268         else {
00269             drawCharacter(painter, style, myX, myY, mySize, rightParenthesisChar);
00270         }
00271         break;
00272     case EmptyBracket:
00273         break;
00274     case Integral:
00275         drawCharacter(painter, style, myX, myY, qRound( 1.5*mySize ), integralChar);
00276         break;
00277     case Sum:
00278         drawCharacter(painter, style, myX, myY, qRound( 1.5*mySize ), summationChar);
00279         break;
00280     case Product:
00281         drawCharacter(painter, style, myX, myY, qRound( 1.5*mySize ), productChar);
00282         break;
00283     }
00284 
00285     // debug
00286     //painter.setBrush(Qt::NoBrush);
00287     //painter.setPen(Qt::green);
00288     //painter.drawRect(myX, myY, getWidth(), getHeight());
00289 }
00290 
00291 
00292 KFORMULA_NAMESPACE_END

Généré le Wed Nov 22 23:41:01 2006 pour KPlato par  doxygen 1.5.1-p1