lib Library API Documentation

symbolfontstyle.cc

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 #include <qpainter.h>
00021 #include <qpen.h>
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 )
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     if ( !LuPixelRect( myX, myY, getWidth(), getHeight() ).intersects( r ) )
00189         return;
00190 
00191     painter.setPen(style.getDefaultColor());
00192 
00193     switch (getType()) {
00194     case LeftSquareBracket:
00195         if ( !doSimpleSquareBracket( parentSize, mySize ) ) {
00196             drawBigRoundBracket( painter, style, leftSquareBracket, myX, myY, mySize );
00197         }
00198         else {
00199             drawCharacter(painter, style, myX, myY, mySize, leftSquareBracketChar);
00200         }
00201         break;
00202     case RightSquareBracket:
00203         if ( !doSimpleSquareBracket( parentSize, mySize ) ) {
00204             drawBigRoundBracket( painter, style, rightSquareBracket, myX, myY, mySize );
00205         }
00206         else {
00207             drawCharacter(painter, style, myX, myY, mySize, rightSquareBracketChar);
00208         }
00209         break;
00210     case LeftCurlyBracket:
00211         if ( !doSimpleCurlyBracket( parentSize, mySize ) ) {
00212             drawBigCurlyBracket( painter, style, leftCurlyBracket, myX, myY, mySize );
00213         }
00214         else {
00215             drawCharacter(painter, style, myX, myY, mySize, leftCurlyBracketChar);
00216         }
00217         break;
00218     case RightCurlyBracket:
00219         if ( !doSimpleCurlyBracket( parentSize, mySize ) ) {
00220             drawBigCurlyBracket( painter, style, rightCurlyBracket, myX, myY, mySize );
00221         }
00222         else {
00223             drawCharacter(painter, style, myX, myY, mySize, rightCurlyBracketChar);
00224         }
00225         break;
00226     case LeftLineBracket:
00227         if ( !doSimpleSquareBracket( parentSize, mySize ) ) {
00228             drawBigRoundBracket( painter, style, leftLineBracket, myX, myY, mySize );
00229         }
00230         else {
00231             drawCharacter(painter, style, myX, myY, mySize, verticalLineChar);
00232         }
00233         break;
00234     case RightLineBracket:
00235         if ( !doSimpleSquareBracket( parentSize, mySize ) ) {
00236             drawBigRoundBracket( painter, style, rightLineBracket, myX, myY, mySize );
00237         }
00238         else {
00239             drawCharacter(painter, style, myX, myY, mySize, verticalLineChar);
00240         }
00241         break;
00242     case SlashBracket:
00243         //drawCharacter(painter, style, myX, myY, mySize, '/');
00244         break;
00245     case BackSlashBracket:
00246         //drawCharacter(painter, style, myX, myY, mySize, '\\');
00247         break;
00248     case LeftCornerBracket:
00249         drawCharacter(painter, style, myX, myY, mySize, leftAngleBracketChar);
00250         break;
00251     case RightCornerBracket:
00252         drawCharacter(painter, style, myX, myY, mySize, rightAngleBracketChar);
00253         break;
00254     case LeftRoundBracket:
00255         if ( !doSimpleRoundBracket( parentSize, mySize ) ) {
00256             drawBigRoundBracket( painter, style, leftRoundBracket, myX, myY, mySize );
00257         }
00258         else {
00259             drawCharacter(painter, style, myX, myY, mySize, leftParenthesisChar);
00260         }
00261         break;
00262     case RightRoundBracket:
00263         if ( !doSimpleRoundBracket( parentSize, mySize ) ) {
00264             drawBigRoundBracket( painter, style, rightRoundBracket, myX, myY, mySize );
00265         }
00266         else {
00267             drawCharacter(painter, style, myX, myY, mySize, rightParenthesisChar);
00268         }
00269         break;
00270     case EmptyBracket:
00271         break;
00272     case Integral:
00273         drawCharacter(painter, style, myX, myY, qRound( 1.5*mySize ), integralChar);
00274         break;
00275     case Sum:
00276         drawCharacter(painter, style, myX, myY, qRound( 1.5*mySize ), summationChar);
00277         break;
00278     case Product:
00279         drawCharacter(painter, style, myX, myY, qRound( 1.5*mySize ), productChar);
00280         break;
00281     }
00282 
00283     // debug
00284     //painter.setBrush(Qt::NoBrush);
00285     //painter.setPen(Qt::green);
00286     //painter.drawRect(myX, myY, getWidth(), getHeight());
00287 }
00288 
00289 
00290 KFORMULA_NAMESPACE_END
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:40:15 2006 by doxygen 1.4.2 written by Dimitri van Heesch, © 1997-2003