lib
oasiscreationstrategy.cc
00001 /* This file is part of the KDE project 00002 Copyright (C) 2006 Alfredo Beaumont Sainz <alfredo.beaumont@gmail.com> 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 <qdom.h> 00021 00022 #include "bracketelement.h" 00023 #include "elementtype.h" 00024 #include "fractionelement.h" 00025 #include "indexelement.h" 00026 #include "matrixelement.h" 00027 #include "rootelement.h" 00028 #include "sequenceelement.h" 00029 #include "spaceelement.h" 00030 #include "symbolelement.h" 00031 #include "textelement.h" 00032 #include "glyphelement.h" 00033 #include "styleelement.h" 00034 #include "numberelement.h" 00035 #include "identifierelement.h" 00036 #include "operatorelement.h" 00037 #include "stringelement.h" 00038 #include "paddedelement.h" 00039 #include "errorelement.h" 00040 #include "phantomelement.h" 00041 #include "actionelement.h" 00042 #include "encloseelement.h" 00043 00044 #include "oasiscreationstrategy.h" 00045 00046 KFORMULA_NAMESPACE_BEGIN 00047 00048 BasicElement* OasisCreationStrategy::createElement( QString type, const QDomElement& element ) 00049 { 00050 00051 // TODO 00052 // mlabeledtr 00053 // maligngroup 00054 // malignmark 00055 // Content elements 00056 // mtr and mtd are currently managed inside MatrixElement 00057 kdDebug( DEBUGID ) << type << endl; 00058 00059 // Token Elements ( Section 3.1.6.1 ) 00060 if ( type == "mi" ) return new IdentifierElement(); 00061 else if ( type == "mo" ) return createOperatorElement( element ); 00062 else if ( type == "mn" ) return new NumberElement(); 00063 else if ( type == "mtext" ) return new TokenElement(); 00064 else if ( type == "ms" ) return new StringElement(); 00065 else if ( type == "mspace" ) return new SpaceElement(); 00066 else if ( type == "mglyph" ) return new GlyphElement(); 00067 00068 // General Layout Schemata ( Section 3.1.6.2 ) 00069 else if ( type == "mrow" ) return new SequenceElement(); 00070 else if ( type == "mfrac" ) return new FractionElement(); 00071 else if ( type == "msqrt" 00072 || type == "mroot" ) return new RootElement(); 00073 else if ( type == "mstyle" ) return new StyleElement(); 00074 else if ( type == "merror" ) return new ErrorElement(); 00075 else if ( type == "mpadded" ) return new PaddedElement(); 00076 else if ( type == "mphantom" ) return new PhantomElement(); 00077 else if ( type == "mfenced" ) return new BracketElement(); 00078 else if ( type == "menclose" ) return new EncloseElement(); 00079 00080 // Script and Limit Schemata ( Section 3.1.6.3 ) 00081 else if ( type == "msub" 00082 || type == "msup" 00083 || type == "msubsup" 00084 || type == "munder" 00085 || type == "mover" 00086 || type == "munderover" 00087 || type == "mmultiscripts" ) return new IndexElement(); 00088 00089 // Tables and Matrices ( Section 3.1.6.4 ) 00090 else if ( type == "mtable" ) return new MatrixElement(); 00091 00092 // Enlivening Expressions ( Section 3.1.6.5 ) 00093 else if ( type == "maction" ) return new ActionElement(); 00094 return 0; 00095 } 00096 00097 00098 TextElement* OasisCreationStrategy::createTextElement( const QChar& ch, bool symbol ) 00099 { 00100 return new TextElement( ch, symbol ); 00101 } 00102 00103 EmptyElement* OasisCreationStrategy::createEmptyElement() 00104 { 00105 return new EmptyElement; 00106 } 00107 00108 NameSequence* OasisCreationStrategy::createNameSequence() 00109 { 00110 return new NameSequence; 00111 } 00112 00113 BracketElement* OasisCreationStrategy::createBracketElement( SymbolType lhs, SymbolType rhs ) 00114 { 00115 return new BracketElement( lhs, rhs ); 00116 } 00117 00118 OverlineElement* OasisCreationStrategy::createOverlineElement() 00119 { 00120 return new OverlineElement; 00121 } 00122 00123 UnderlineElement* OasisCreationStrategy::createUnderlineElement() 00124 { 00125 return new UnderlineElement; 00126 } 00127 00128 MultilineElement* OasisCreationStrategy::createMultilineElement() 00129 { 00130 return new MultilineElement; 00131 } 00132 00133 SpaceElement* OasisCreationStrategy::createSpaceElement( SpaceWidth width ) 00134 { 00135 return new SpaceElement( width ); 00136 } 00137 00138 FractionElement* OasisCreationStrategy::createFractionElement() 00139 { 00140 return new FractionElement; 00141 } 00142 00143 RootElement* OasisCreationStrategy::createRootElement() 00144 { 00145 return new RootElement; 00146 } 00147 00148 SymbolElement* OasisCreationStrategy::createSymbolElement( SymbolType type ) 00149 { 00150 return new SymbolElement( type ); 00151 } 00152 00153 MatrixElement* OasisCreationStrategy::createMatrixElement( uint rows, uint columns ) 00154 { 00155 return new MatrixElement( rows, columns ); 00156 } 00157 00158 IndexElement* OasisCreationStrategy::createIndexElement() 00159 { 00160 return new IndexElement; 00161 } 00162 00163 BasicElement* OasisCreationStrategy::createOperatorElement( const QDomElement& element ) 00164 { 00165 QDomNode n = element.firstChild(); 00166 if ( n.isNull() ) 00167 return 0; 00168 if ( n.isEntityReference() ) { 00169 QString name = n.nodeName(); 00170 if ( name == "CloseCurlyDoubleQuote" 00171 || name == "CloseCurlyQuote" 00172 || name == "LeftAngleBracket" 00173 || name == "LeftCeiling" 00174 || name == "LeftDoubleBracket" 00175 || name == "LeftFloor" 00176 || name == "OpenCurlyDoubleQuote" 00177 || name == "OpenCurlyQuote" 00178 || name == "RightAngleBracket" 00179 || name == "RightCeiling" 00180 || name == "RightDoubleBracket" 00181 || name == "RightFloor" ) { 00182 return new BracketElement(); 00183 } 00184 return new OperatorElement(); 00185 } 00186 if ( n.isText() ) { 00187 QString text = n.toText().data(); 00188 if ( text.length() == 1 && QString("()[]{}").contains(text[0]) ) { 00189 return new BracketElement(); 00190 } 00191 } 00192 return new OperatorElement(); 00193 } 00194 00195 IdentifierElement* OasisCreationStrategy::createIdentifierElement() 00196 { 00197 return new IdentifierElement(); 00198 } 00199 00200 OperatorElement* OasisCreationStrategy::createOperatorElement() 00201 { 00202 return new OperatorElement(); 00203 } 00204 00205 NumberElement* OasisCreationStrategy::createNumberElement() 00206 { 00207 return new NumberElement(); 00208 } 00209 00210 KFORMULA_NAMESPACE_END