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 00064 inline bool doSimpleRoundBracket( luPt height, luPt baseHeight ) 00065 { 00066 return height < 1.5*baseHeight; 00067 } 00068 00069 inline bool doSimpleSquareBracket( luPt height, luPt baseHeight ) 00070 { 00071 return height < 1.5*baseHeight; 00072 } 00073 00074 inline bool doSimpleCurlyBracket( luPt height, luPt baseHeight ) 00075 { 00076 return height < 2*baseHeight; 00077 } 00078 00079 00080 void SymbolArtwork::calcSizes( const ContextStyle& style, 00081 ContextStyle::TextStyle tstyle, 00082 luPt parentSize ) 00083 { 00084 setBaseline( -1 ); 00085 luPt mySize = style.getAdjustedSize( tstyle ); 00086 switch (getType()) { 00087 case LeftSquareBracket: 00088 if ( doSimpleSquareBracket( parentSize, mySize ) ) { 00089 calcCharSize( style, mySize, leftSquareBracketChar ); 00090 return; 00091 } 00092 calcRoundBracket( style, leftSquareBracket, parentSize, mySize ); 00093 break; 00094 case RightSquareBracket: 00095 if ( doSimpleSquareBracket( parentSize, mySize ) ) { 00096 calcCharSize(style, mySize, rightSquareBracketChar); 00097 return; 00098 } 00099 calcRoundBracket( style, rightSquareBracket, parentSize, mySize ); 00100 break; 00101 case LeftLineBracket: 00102 if ( doSimpleSquareBracket( parentSize, mySize ) ) { 00103 calcCharSize(style, mySize, verticalLineChar); 00104 return; 00105 } 00106 calcRoundBracket( style, leftLineBracket, parentSize, mySize ); 00107 break; 00108 case RightLineBracket: 00109 if ( doSimpleSquareBracket( parentSize, mySize ) ) { 00110 calcCharSize(style, mySize, verticalLineChar); 00111 return; 00112 } 00113 calcRoundBracket( style, rightLineBracket, parentSize, mySize ); 00114 break; 00115 case SlashBracket: 00116 //calcCharSize(style, mySize, '/'); 00117 break; 00118 case BackSlashBracket: 00119 //calcCharSize(style, mySize, '\\'); 00120 break; 00121 case LeftCornerBracket: 00122 calcCharSize(style, mySize, leftAngleBracketChar); 00123 break; 00124 case RightCornerBracket: 00125 calcCharSize(style, mySize, rightAngleBracketChar); 00126 break; 00127 case LeftRoundBracket: 00128 if ( doSimpleRoundBracket( parentSize, mySize ) ) { 00129 calcCharSize(style, mySize, leftParenthesisChar); 00130 return; 00131 } 00132 calcRoundBracket( style, leftRoundBracket, parentSize, mySize ); 00133 break; 00134 case RightRoundBracket: 00135 if ( doSimpleRoundBracket( parentSize, mySize ) ) { 00136 calcCharSize(style, mySize, rightParenthesisChar); 00137 return; 00138 } 00139 calcRoundBracket( style, rightRoundBracket, parentSize, mySize ); 00140 break; 00141 case EmptyBracket: 00142 setHeight(parentSize); 00143 //setWidth(style.getEmptyRectWidth()); 00144 setWidth(0); 00145 break; 00146 case LeftCurlyBracket: 00147 if ( doSimpleCurlyBracket( parentSize, mySize ) ) { 00148 calcCharSize(style, mySize, leftCurlyBracketChar); 00149 return; 00150 } 00151 calcCurlyBracket( style, leftCurlyBracket, parentSize, mySize ); 00152 break; 00153 case RightCurlyBracket: 00154 if ( doSimpleCurlyBracket( parentSize, mySize ) ) { 00155 calcCharSize(style, mySize, rightCurlyBracketChar); 00156 return; 00157 } 00158 calcCurlyBracket( style, rightCurlyBracket, parentSize, mySize ); 00159 break; 00160 case Integral: 00161 calcCharSize( style, qRound( 1.5*mySize ), integralChar ); 00162 break; 00163 case Sum: 00164 calcCharSize( style, qRound( 1.5*mySize ), summationChar ); 00165 break; 00166 case Product: 00167 calcCharSize( style, qRound( 1.5*mySize ), productChar ); 00168 break; 00169 } 00170 } 00171 00172 00173 void SymbolArtwork::draw(QPainter& painter, const LuPixelRect& r, 00174 const ContextStyle& style, ContextStyle::TextStyle tstyle, 00175 luPt parentSize, const LuPixelPoint& origin) 00176 { 00177 luPt mySize = style.getAdjustedSize( tstyle ); 00178 luPixel myX = origin.x() + getX(); 00179 luPixel myY = origin.y() + getY(); 00180 if ( !LuPixelRect( myX, myY, getWidth(), getHeight() ).intersects( r ) ) 00181 return; 00182 00183 painter.setPen(style.getDefaultColor()); 00184 00185 switch (getType()) { 00186 case LeftSquareBracket: 00187 if ( !doSimpleSquareBracket( parentSize, mySize ) ) { 00188 drawBigRoundBracket( painter, style, leftSquareBracket, myX, myY, mySize ); 00189 } 00190 else { 00191 drawCharacter(painter, style, myX, myY, mySize, leftSquareBracketChar); 00192 } 00193 break; 00194 case RightSquareBracket: 00195 if ( !doSimpleSquareBracket( parentSize, mySize ) ) { 00196 drawBigRoundBracket( painter, style, rightSquareBracket, myX, myY, mySize ); 00197 } 00198 else { 00199 drawCharacter(painter, style, myX, myY, mySize, rightSquareBracketChar); 00200 } 00201 break; 00202 case LeftCurlyBracket: 00203 if ( !doSimpleCurlyBracket( parentSize, mySize ) ) { 00204 drawBigCurlyBracket( painter, style, leftCurlyBracket, myX, myY, mySize ); 00205 } 00206 else { 00207 drawCharacter(painter, style, myX, myY, mySize, leftCurlyBracketChar); 00208 } 00209 break; 00210 case RightCurlyBracket: 00211 if ( !doSimpleCurlyBracket( parentSize, mySize ) ) { 00212 drawBigCurlyBracket( painter, style, rightCurlyBracket, myX, myY, mySize ); 00213 } 00214 else { 00215 drawCharacter(painter, style, myX, myY, mySize, rightCurlyBracketChar); 00216 } 00217 break; 00218 case LeftLineBracket: 00219 if ( !doSimpleSquareBracket( parentSize, mySize ) ) { 00220 drawBigRoundBracket( painter, style, leftLineBracket, myX, myY, mySize ); 00221 } 00222 else { 00223 drawCharacter(painter, style, myX, myY, mySize, verticalLineChar); 00224 } 00225 break; 00226 case RightLineBracket: 00227 if ( !doSimpleSquareBracket( parentSize, mySize ) ) { 00228 drawBigRoundBracket( painter, style, rightLineBracket, myX, myY, mySize ); 00229 } 00230 else { 00231 drawCharacter(painter, style, myX, myY, mySize, verticalLineChar); 00232 } 00233 break; 00234 case SlashBracket: 00235 //drawCharacter(painter, style, myX, myY, mySize, '/'); 00236 break; 00237 case BackSlashBracket: 00238 //drawCharacter(painter, style, myX, myY, mySize, '\\'); 00239 break; 00240 case LeftCornerBracket: 00241 drawCharacter(painter, style, myX, myY, mySize, leftAngleBracketChar); 00242 break; 00243 case RightCornerBracket: 00244 drawCharacter(painter, style, myX, myY, mySize, rightAngleBracketChar); 00245 break; 00246 case LeftRoundBracket: 00247 if ( !doSimpleRoundBracket( parentSize, mySize ) ) { 00248 drawBigRoundBracket( painter, style, leftRoundBracket, myX, myY, mySize ); 00249 } 00250 else { 00251 drawCharacter(painter, style, myX, myY, mySize, leftParenthesisChar); 00252 } 00253 break; 00254 case RightRoundBracket: 00255 if ( !doSimpleRoundBracket( parentSize, mySize ) ) { 00256 drawBigRoundBracket( painter, style, rightRoundBracket, myX, myY, mySize ); 00257 } 00258 else { 00259 drawCharacter(painter, style, myX, myY, mySize, rightParenthesisChar); 00260 } 00261 break; 00262 case EmptyBracket: 00263 break; 00264 case Integral: 00265 drawCharacter(painter, style, myX, myY, qRound( 1.5*mySize ), integralChar); 00266 break; 00267 case Sum: 00268 drawCharacter(painter, style, myX, myY, qRound( 1.5*mySize ), summationChar); 00269 break; 00270 case Product: 00271 drawCharacter(painter, style, myX, myY, qRound( 1.5*mySize ), productChar); 00272 break; 00273 } 00274 00275 // debug 00276 //painter.setBrush(Qt::NoBrush); 00277 //painter.setPen(Qt::green); 00278 //painter.drawRect(myX, myY, getWidth(), getHeight()); 00279 } 00280 00281 00282 KFORMULA_NAMESPACE_END
KDE Logo
This file is part of the documentation for lib Library Version 1.3.5.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Wed Nov 17 06:54:20 2004 by doxygen 1.3.7 written by Dimitri van Heesch, © 1997-2003