You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
1795 lines
60 KiB
1795 lines
60 KiB
15 years ago
|
/* This file is part of the KDE project
|
||
|
Copyright (C) 2001 Andrea Rizzi <rizzi@kde.org>
|
||
|
Ulrich Kuettler <ulrich.kuettler@mailbox.tu-dresden.de>
|
||
|
|
||
|
This library is free software; you can redistribute it and/or
|
||
|
modify it under the terms of the GNU Library General Public
|
||
|
License as published by the Free Software Foundation; either
|
||
|
version 2 of the License, or (at your option) any later version.
|
||
|
|
||
|
This library is distributed in the hope that it will be useful,
|
||
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||
|
Library General Public License for more details.
|
||
|
|
||
|
You should have received a copy of the GNU Library General Public License
|
||
|
along with this library; see the file COPYING.LIB. If not, write to
|
||
|
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
|
||
|
* Boston, MA 02110-1301, USA.
|
||
|
*/
|
||
|
|
||
|
#include <iostream>
|
||
14 years ago
|
#include <tqstring.h>
|
||
|
#include <tqfontmetrics.h>
|
||
15 years ago
|
|
||
12 years ago
|
#include <tdelocale.h>
|
||
|
#include <tdemessagebox.h>
|
||
15 years ago
|
|
||
|
//#include <KoUnit.h>
|
||
|
|
||
|
#include "kformulamathmlread.h"
|
||
|
#include "symboltable.h"
|
||
|
|
||
|
KFORMULA_NAMESPACE_BEGIN
|
||
|
using namespace std;
|
||
|
|
||
|
class MathML2KFormulaPrivate
|
||
|
{
|
||
|
friend class MathML2KFormula;
|
||
|
|
||
|
public:
|
||
|
MathML2KFormulaPrivate( MathML2KFormula* mml_filter,
|
||
|
const ContextStyle& contextStyle,
|
||
14 years ago
|
const TQDomDocument& formuladoc );
|
||
15 years ago
|
~MathML2KFormulaPrivate();
|
||
|
|
||
14 years ago
|
void math( TQDomElement element );
|
||
15 years ago
|
|
||
|
// Token Elements
|
||
14 years ago
|
void mi( TQDomElement element, TQDomNode docnode );
|
||
|
void mn( TQDomElement element, TQDomNode docnode );
|
||
|
void mo( TQDomElement element, TQDomNode docnode );
|
||
|
void mtext( TQDomElement element, TQDomNode docnode );
|
||
|
void mspace( TQDomElement element, TQDomNode docnode );
|
||
|
void ms( TQDomElement element, TQDomNode docnode );
|
||
15 years ago
|
// mglyph not supported
|
||
|
|
||
|
// General Layout Schemata
|
||
14 years ago
|
void mrow( TQDomElement element, TQDomNode docnode );
|
||
|
void mfrac( TQDomElement element, TQDomNode docnode );
|
||
|
void msqrt( TQDomElement element, TQDomNode docnode );
|
||
|
void mroot( TQDomElement element, TQDomNode docnode );
|
||
|
void mstyle( TQDomElement element, TQDomNode docnode );
|
||
15 years ago
|
// merror not supported
|
||
|
// mpadded not supported
|
||
|
// mphantom not supported
|
||
14 years ago
|
void mfenced( TQDomElement element, TQDomNode docnode );
|
||
15 years ago
|
// menclose not supported
|
||
|
|
||
|
// Script and Limit Schemata
|
||
14 years ago
|
void msub_msup( TQDomElement element, TQDomNode docnode );
|
||
|
void msubsup( TQDomElement element, TQDomNode docnode );
|
||
|
void munder( TQDomElement element, TQDomNode docnode, bool oasisFormat );
|
||
|
void mover( TQDomElement element, TQDomNode docnode, bool oasisFormat );
|
||
|
void munderover( TQDomElement element, TQDomNode docnode, bool oasisFormat );
|
||
15 years ago
|
// mmultiscripts not supported
|
||
|
|
||
|
// Tables and Matrices
|
||
14 years ago
|
void mtable( TQDomElement element, TQDomNode docnode );
|
||
15 years ago
|
// not much supported
|
||
|
|
||
|
// Enlivening Expressions
|
||
|
// maction not supported
|
||
|
|
||
|
protected:
|
||
14 years ago
|
void createTextElements( TQString text, TQDomNode docnode );
|
||
|
void createNameSequence( TQString text, TQDomNode docnode );
|
||
|
double convertToPoint( TQString value, bool* ok );
|
||
|
bool isEmbellishedOperator( TQDomNode node, TQDomElement* mo, bool oasisFormat );
|
||
|
bool isSpaceLike( TQDomNode node, bool oasisFormat );
|
||
15 years ago
|
|
||
|
enum MathVariant {
|
||
|
normal,
|
||
|
bold,
|
||
|
italic,
|
||
|
bold_italic,
|
||
|
double_struck,
|
||
|
bold_fraktur,
|
||
|
script,
|
||
|
bold_script,
|
||
|
fraktur,
|
||
|
sans_serif,
|
||
|
bold_sans_serif,
|
||
|
sans_serif_italic,
|
||
|
sans_serif_bold_italic,
|
||
|
monospace
|
||
|
};
|
||
|
|
||
|
struct MathStyle {
|
||
|
MathStyle()
|
||
|
: scriptsizemultiplier( 0.71 ),
|
||
|
scriptminsize( 8 ),
|
||
|
veryverythinmathspace( 1.0/18.0 ),
|
||
|
verythinmathspace( 2.0/18.0 ),
|
||
|
thinmathspace( 3.0/18.0 ),
|
||
|
mediummathspace( 4.0/18.0 ),
|
||
|
thickmathspace( 5.0/18.0 ),
|
||
|
verythickmathspace( 6.0/18.0 ),
|
||
|
veryverythickmathspace( 7.0/18.0 ),
|
||
|
|
||
|
useVariant( false )
|
||
|
{
|
||
|
}
|
||
|
|
||
|
void styleChange()
|
||
|
{
|
||
|
kdDebug( DEBUGID ) << "Style Change:"
|
||
|
<< "\n scriptlevel = " << scriptlevel
|
||
|
<< "\n displaystyle = " << displaystyle
|
||
|
<< "\n scriptsizemultiplier = "
|
||
|
<< scriptsizemultiplier
|
||
|
<< "\n scriptminsize = " << scriptminsize
|
||
|
<< endl;
|
||
|
}
|
||
|
|
||
14 years ago
|
void setStyles( TQDomElement element )
|
||
15 years ago
|
{
|
||
|
if ( !useVariant )
|
||
|
return;
|
||
|
|
||
|
switch ( mathvariant )
|
||
|
{
|
||
|
case normal:
|
||
|
element.setAttribute( "STYLE", "normal" );
|
||
|
break;
|
||
|
case bold:
|
||
|
element.setAttribute( "STYLE", "bold" );
|
||
|
break;
|
||
|
|
||
|
case bold_italic:
|
||
|
element.setAttribute( "STYLE", "bolditalic" );
|
||
|
break;
|
||
|
case italic:
|
||
|
element.setAttribute( "STYLE", "italic" );
|
||
|
break;
|
||
|
|
||
|
case double_struck:
|
||
|
element.setAttribute( "FAMILY", "doublestruck" );
|
||
|
break;
|
||
|
|
||
|
case bold_fraktur:
|
||
|
element.setAttribute( "STYLE", "bold" );
|
||
|
case fraktur:
|
||
|
element.setAttribute( "FAMILY", "fraktur" );
|
||
|
break;
|
||
|
|
||
|
case bold_script:
|
||
|
element.setAttribute( "STYLE", "bold" );
|
||
|
case script:
|
||
|
element.setAttribute( "FAMILY", "script" );
|
||
|
break;
|
||
|
|
||
|
case bold_sans_serif:
|
||
|
element.setAttribute( "STYLE", "bold" );
|
||
|
case sans_serif:
|
||
|
element.setAttribute( "FAMILY", "normal" );
|
||
|
break;
|
||
|
case sans_serif_bold_italic:
|
||
|
element.setAttribute( "STYLE", "bolditalic" );
|
||
|
element.setAttribute( "FAMILY", "normal" );
|
||
|
break;
|
||
|
case sans_serif_italic:
|
||
|
element.setAttribute( "STYLE", "italic" );
|
||
|
element.setAttribute( "FAMILY", "normal" );
|
||
|
break;
|
||
|
|
||
|
//case monospace:
|
||
|
default:
|
||
|
break;
|
||
|
}
|
||
|
}
|
||
|
|
||
14 years ago
|
void readStyles( TQDomElement mmlElement )
|
||
15 years ago
|
{
|
||
|
if ( mmlElement.hasAttribute( "mathvariant" ) )
|
||
|
{
|
||
|
useVariant = true;
|
||
|
|
||
|
if ( mmlElement.attribute( "mathvariant" ) == "normal" )
|
||
|
mathvariant = normal;
|
||
|
else if ( mmlElement.attribute( "mathvariant" ) == "bold" )
|
||
|
mathvariant = bold;
|
||
|
else if ( mmlElement.attribute( "mathvariant" ) == "italic" )
|
||
|
mathvariant = italic;
|
||
|
else if ( mmlElement.attribute( "mathvariant" ) == "bold-italic" )
|
||
|
mathvariant = bold_italic;
|
||
|
else if ( mmlElement.attribute( "mathvariant" ) == "double-struck" )
|
||
|
mathvariant = double_struck;
|
||
|
else if ( mmlElement.attribute( "mathvariant" ) == "bold-fraktur" )
|
||
|
mathvariant = bold_fraktur;
|
||
|
else if ( mmlElement.attribute( "mathvariant" ) == "script" )
|
||
|
mathvariant = script;
|
||
|
else if ( mmlElement.attribute( "mathvariant" ) == "bold-script" )
|
||
|
mathvariant = bold_script;
|
||
|
else if ( mmlElement.attribute( "mathvariant" ) == "fraktur" )
|
||
|
mathvariant = fraktur;
|
||
|
else if ( mmlElement.attribute( "mathvariant" ) == "sans-serif" )
|
||
|
mathvariant = sans_serif;
|
||
|
else if ( mmlElement.attribute( "mathvariant" ) == "bold-sans-serif" )
|
||
|
mathvariant = bold_sans_serif;
|
||
|
else if ( mmlElement.attribute( "mathvariant" ) == "sans-serif-italic" )
|
||
|
mathvariant = sans_serif_italic;
|
||
|
else if ( mmlElement.attribute( "mathvariant" ) == "sans-serif-bold-italic" )
|
||
|
mathvariant = sans_serif_bold_italic;
|
||
|
else if ( mmlElement.attribute( "mathvariant" ) == "monospace" )
|
||
|
mathvariant = monospace;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
// Styles, set by <mstyle> // default
|
||
|
|
||
|
int scriptlevel; // inherited
|
||
|
bool displaystyle; // inherited
|
||
|
double scriptsizemultiplier; // 0.71
|
||
|
double scriptminsize; // 8pt
|
||
|
// color
|
||
|
// background
|
||
|
double veryverythinmathspace; // 1/18em = 0.0555556em
|
||
|
double verythinmathspace; // 2/18em = 0.111111em
|
||
|
double thinmathspace; // 3/18em = 0.166667em
|
||
|
double mediummathspace; // 4/18em = 0.222222em
|
||
|
double thickmathspace; // 5/18em = 0.277778em
|
||
|
double verythickmathspace; // 6/18em = 0.333333em
|
||
|
double veryverythickmathspace; // 7/18em = 0.388889em
|
||
|
|
||
|
// 'Local' styles
|
||
|
|
||
|
MathVariant mathvariant;
|
||
|
bool useVariant;
|
||
|
//int mathsize;
|
||
|
};
|
||
|
|
||
|
MathStyle style;
|
||
14 years ago
|
TQDomDocument doc;
|
||
15 years ago
|
|
||
|
private:
|
||
|
const ContextStyle& context;
|
||
|
MathML2KFormula* filter;
|
||
|
};
|
||
|
|
||
14 years ago
|
MathML2KFormulaPrivate::MathML2KFormulaPrivate( MathML2KFormula* mml_filter, const ContextStyle& cs, const TQDomDocument& formuladoc )
|
||
15 years ago
|
: doc( formuladoc ), context( cs ), filter( mml_filter )
|
||
|
{
|
||
|
}
|
||
|
|
||
|
MathML2KFormulaPrivate::~MathML2KFormulaPrivate()
|
||
|
{
|
||
|
}
|
||
|
|
||
14 years ago
|
void MathML2KFormulaPrivate::math( TQDomElement element )
|
||
15 years ago
|
{
|
||
14 years ago
|
TQDomElement formula = doc.createElement( "FORMULA" );
|
||
|
TQDomNode n = element.firstChild();
|
||
15 years ago
|
|
||
14 years ago
|
TQString display = element.attribute( "display" );
|
||
15 years ago
|
|
||
|
if ( display == "block" ) {
|
||
|
style.displaystyle = true;
|
||
|
}
|
||
|
else {
|
||
|
// if display == "inline" (default) or illegal (then use default)
|
||
|
style.displaystyle = false;
|
||
|
}
|
||
|
|
||
|
style.scriptlevel = 0;
|
||
|
|
||
|
/*kdDebug( DEBUGID ) << "<math> element:\n displaystyle = "
|
||
|
<< style.displaystyle << "\n scriptlevel = "
|
||
|
<< style.scriptlevel << endl;*/
|
||
|
|
||
|
while ( !n.isNull() ) {
|
||
|
filter->processElement( n, doc, formula );
|
||
|
n = n.nextSibling();
|
||
|
}
|
||
|
|
||
|
doc.appendChild( formula );
|
||
|
}
|
||
|
|
||
14 years ago
|
void MathML2KFormulaPrivate::mi( TQDomElement element, TQDomNode docnode )
|
||
15 years ago
|
{
|
||
|
MathStyle previousStyle( style );
|
||
14 years ago
|
TQString text = element.text().stripWhiteSpace();
|
||
15 years ago
|
if ( text.length() == 1 ) { // Default italic, only when content is one char
|
||
|
style.mathvariant = italic;
|
||
|
style.useVariant = true;
|
||
|
style.readStyles( element );
|
||
|
createTextElements( text, docnode );
|
||
|
} else { // If length is 0 or >1, it should be a text sequence
|
||
|
style.readStyles( element );
|
||
|
createNameSequence( text, docnode );
|
||
|
}
|
||
|
style = previousStyle;
|
||
|
}
|
||
|
|
||
14 years ago
|
void MathML2KFormulaPrivate::mo( TQDomElement element, TQDomNode docnode )
|
||
15 years ago
|
{
|
||
|
MathStyle previousStyle( style );
|
||
|
style.readStyles( element );
|
||
|
|
||
14 years ago
|
TQString text = element.text().stripWhiteSpace();
|
||
15 years ago
|
createTextElements( text, docnode );
|
||
|
|
||
|
style = previousStyle;
|
||
|
}
|
||
|
|
||
14 years ago
|
void MathML2KFormulaPrivate::mn( TQDomElement element, TQDomNode docnode )
|
||
15 years ago
|
{
|
||
|
MathStyle previousStyle( style );
|
||
|
style.readStyles( element );
|
||
|
|
||
14 years ago
|
TQString text = element.text().stripWhiteSpace();
|
||
15 years ago
|
createTextElements( text, docnode );
|
||
|
|
||
|
style = previousStyle;
|
||
|
}
|
||
|
|
||
14 years ago
|
void MathML2KFormulaPrivate::mtext( TQDomElement element, TQDomNode docnode )
|
||
15 years ago
|
{
|
||
|
MathStyle previousStyle( style );
|
||
|
style.readStyles( element );
|
||
|
|
||
14 years ago
|
TQDomNode n = element.firstChild();
|
||
15 years ago
|
|
||
|
while ( !n.isNull() ) {
|
||
|
if ( n.isText() ) {
|
||
14 years ago
|
TQString text = n.toText().data().stripWhiteSpace();
|
||
15 years ago
|
createTextElements( text, docnode );
|
||
|
}
|
||
|
else if ( n.isElement() ) {
|
||
|
filter->processElement( n, doc, docnode );
|
||
|
}
|
||
|
else {
|
||
|
kdDebug( DEBUGID ) << "<mtext> child: " << n.nodeName() << endl;
|
||
|
}
|
||
|
|
||
|
n = n.nextSibling();
|
||
|
}
|
||
|
|
||
|
style = previousStyle;
|
||
|
}
|
||
|
|
||
14 years ago
|
void MathML2KFormulaPrivate::ms( TQDomElement element, TQDomNode docnode )
|
||
15 years ago
|
{
|
||
14 years ago
|
TQString lquote = element.attribute( "lquote", "\"" );
|
||
|
TQString rquote = element.attribute( "rquote", "\"" );
|
||
|
TQString text;
|
||
15 years ago
|
|
||
|
text = lquote;
|
||
|
text += element.text().stripWhiteSpace();
|
||
|
text += rquote;
|
||
|
|
||
|
createTextElements( text, docnode );
|
||
|
}
|
||
|
|
||
14 years ago
|
void MathML2KFormulaPrivate::mspace( TQDomElement element, TQDomNode docnode )
|
||
15 years ago
|
{
|
||
|
// we support only horizontal space
|
||
14 years ago
|
TQString width = element.attribute( "width" );
|
||
15 years ago
|
|
||
14 years ago
|
TQDomElement spaceelement = doc.createElement( "SPACE" );
|
||
15 years ago
|
|
||
|
// check for namedspace. We don't support much...
|
||
|
if ( width == "veryverythinmathspace" ) {
|
||
|
spaceelement.setAttribute( "WIDTH", "thin" );
|
||
|
}
|
||
|
else if ( width == "verythinmathspace" ) {
|
||
|
spaceelement.setAttribute( "WIDTH", "thin" );
|
||
|
}
|
||
|
else if ( width == "thinmathspace" ) {
|
||
|
spaceelement.setAttribute( "WIDTH", "thin" );
|
||
|
}
|
||
|
else if ( width == "mediummathspace" ) {
|
||
|
spaceelement.setAttribute( "WIDTH", "medium" );
|
||
|
}
|
||
|
else if ( width == "thickmathspace" ) {
|
||
|
spaceelement.setAttribute( "WIDTH", "thick" );
|
||
|
}
|
||
|
else if ( width == "verythickmathspace" ) {
|
||
|
spaceelement.setAttribute( "WIDTH", "thick" );
|
||
|
}
|
||
|
else if ( width == "veryverythickmathspace" ) {
|
||
|
spaceelement.setAttribute( "WIDTH", "quad" );
|
||
|
}
|
||
|
|
||
|
else {
|
||
|
// units
|
||
|
|
||
|
double w = 0;
|
||
|
bool ok;
|
||
|
|
||
|
if ( width.endsWith( "em" ) ) {
|
||
|
// See MathML specification, Appendix H
|
||
|
w = context.getDefaultFont().pointSize();
|
||
|
if ( w == -1 ) {
|
||
14 years ago
|
TQFontMetrics fm( context.getDefaultFont() );
|
||
15 years ago
|
w = fm.width( 'm' );
|
||
|
}
|
||
|
w = w * width.remove( width.length() - 2, 2 ).toDouble( &ok );
|
||
|
// w in points?
|
||
|
}
|
||
|
else if ( width.endsWith( "px" ) ) {
|
||
|
w = width.remove( width.length() - 2, 2 ).toDouble( &ok );
|
||
|
// w in pixels
|
||
|
}
|
||
|
else if ( width.endsWith( "in" ) ) {
|
||
|
w = width.remove( width.length() - 2, 2 ).toDouble( &ok );
|
||
|
w *= 72; // w in points
|
||
|
}
|
||
|
else if ( width.endsWith( "cm" ) ) {
|
||
|
w = width.remove( width.length() - 2, 2 ).toDouble( &ok );
|
||
|
w *= 1/2.54 * 72; // w in points
|
||
|
}
|
||
|
else if ( width.endsWith( "mm" ) ) {
|
||
|
w = width.remove( width.length() - 2, 2 ).toDouble( &ok );
|
||
|
w *= 1/25.4 * 72; // w in points
|
||
|
}
|
||
|
else if ( width.endsWith( "pt" ) ) {
|
||
|
w = width.remove( width.length() - 2, 2 ).toDouble( &ok );
|
||
|
// w in points
|
||
|
}
|
||
|
else if ( width.endsWith( "pc" ) ) {
|
||
|
w = width.remove( width.length() - 2, 2 ).toDouble( &ok );
|
||
|
w /= 12; // w in points
|
||
|
}
|
||
|
else {
|
||
|
w = width.toDouble( &ok );
|
||
|
}
|
||
|
|
||
|
if ( !ok )
|
||
|
return;
|
||
|
|
||
|
if ( w < 20 )
|
||
|
spaceelement.setAttribute( "WIDTH", "thin" );
|
||
|
else if ( w < 40 )
|
||
|
spaceelement.setAttribute( "WIDTH", "medium" );
|
||
|
else if ( w < 80 )
|
||
|
spaceelement.setAttribute( "WIDTH", "thick" );
|
||
|
else
|
||
|
spaceelement.setAttribute( "WIDTH", "quad" );
|
||
|
}
|
||
|
|
||
|
docnode.appendChild( spaceelement );
|
||
|
}
|
||
|
|
||
14 years ago
|
void MathML2KFormulaPrivate::mrow( TQDomElement element, TQDomNode docnode )
|
||
15 years ago
|
{
|
||
14 years ago
|
TQDomNode n = element.firstChild();
|
||
15 years ago
|
while ( !n.isNull() ) {
|
||
|
if ( n.isElement () ) {
|
||
14 years ago
|
TQDomElement e = n.toElement();
|
||
15 years ago
|
// We do not allow sequence inside sequence
|
||
|
filter->processElement( e, doc, docnode );
|
||
|
}
|
||
|
else {
|
||
|
kdDebug( DEBUGID ) << "<mrow> child: " << n.nodeName() << endl;
|
||
|
}
|
||
|
n = n.nextSibling();
|
||
|
}
|
||
|
}
|
||
|
|
||
14 years ago
|
void MathML2KFormulaPrivate::mfrac( TQDomElement element, TQDomNode docnode )
|
||
15 years ago
|
{
|
||
14 years ago
|
TQDomNode n = element.firstChild();
|
||
|
TQDomElement fraction = doc.createElement( "FRACTION" );
|
||
15 years ago
|
|
||
|
MathStyle previousStyle( style );
|
||
|
style.displaystyle ? style.displaystyle = false : style.scriptlevel += 1;
|
||
|
style.styleChange();
|
||
|
|
||
|
int i = 0;
|
||
|
while ( !n.isNull() && i < 2 ) {
|
||
|
if ( n.isElement() ) {
|
||
|
++i;
|
||
|
if ( i == 1 ) { //first is numerator
|
||
14 years ago
|
TQDomElement numerator =
|
||
15 years ago
|
doc.createElement( "NUMERATOR" );
|
||
14 years ago
|
TQDomElement sequence = doc.createElement( "SEQUENCE" );
|
||
15 years ago
|
numerator.appendChild( sequence );
|
||
14 years ago
|
TQDomElement e = n.toElement();
|
||
15 years ago
|
filter->processElement( e, doc, sequence );
|
||
|
fraction.appendChild( numerator );
|
||
|
|
||
|
}
|
||
|
else {
|
||
14 years ago
|
TQDomElement denominator =
|
||
15 years ago
|
doc.createElement( "DENOMINATOR" );
|
||
14 years ago
|
TQDomElement sequence = doc.createElement( "SEQUENCE" );
|
||
15 years ago
|
denominator.appendChild( sequence );
|
||
14 years ago
|
TQDomElement e = n.toElement();
|
||
15 years ago
|
filter->processElement( e, doc, sequence );
|
||
|
fraction.appendChild( denominator );
|
||
|
|
||
|
}
|
||
|
}
|
||
|
else {
|
||
|
kdDebug( DEBUGID ) << "<mfrac> child: " << n.nodeName() << endl;
|
||
|
}
|
||
|
n = n.nextSibling();
|
||
|
}
|
||
|
|
||
|
style = previousStyle;
|
||
|
docnode.appendChild( fraction );
|
||
|
}
|
||
|
|
||
14 years ago
|
void MathML2KFormulaPrivate::mroot( TQDomElement element, TQDomNode docnode )
|
||
15 years ago
|
{
|
||
14 years ago
|
TQDomNode n = element.firstChild();
|
||
15 years ago
|
int i = 0;
|
||
14 years ago
|
TQDomElement root = doc.createElement( "ROOT" );
|
||
15 years ago
|
|
||
|
while ( !n.isNull() && i < 2 ) {
|
||
|
if ( n.isElement() ) {
|
||
|
++i;
|
||
|
if ( i == 1 ) { //first is content (base)
|
||
14 years ago
|
TQDomElement content = doc.createElement( "CONTENT" );
|
||
|
TQDomElement sequence = doc.createElement( "SEQUENCE" );
|
||
15 years ago
|
content.appendChild( sequence );
|
||
14 years ago
|
TQDomElement e = n.toElement();
|
||
15 years ago
|
filter->processElement( e, doc, sequence );
|
||
|
|
||
|
root.appendChild(content);
|
||
|
}
|
||
|
else { // index
|
||
|
MathStyle previousStyle( style );
|
||
|
style.scriptlevel += 2;
|
||
|
style.displaystyle = false;
|
||
|
style.styleChange();
|
||
|
|
||
14 years ago
|
TQDomElement index = doc.createElement( "INDEX" );
|
||
|
TQDomElement sequence = doc.createElement( "SEQUENCE" );
|
||
15 years ago
|
index.appendChild( sequence );
|
||
14 years ago
|
TQDomElement e = n.toElement();
|
||
15 years ago
|
filter->processElement( e, doc, sequence );
|
||
|
root.appendChild( index );
|
||
|
|
||
|
style = previousStyle;
|
||
|
}
|
||
|
}
|
||
|
else {
|
||
|
kdDebug( DEBUGID ) << "<mroot> child: " << n.nodeName() << endl;
|
||
|
}
|
||
|
n = n.nextSibling();
|
||
|
}
|
||
|
docnode.appendChild( root );
|
||
|
}
|
||
|
|
||
14 years ago
|
void MathML2KFormulaPrivate::msqrt( TQDomElement element, TQDomNode docnode )
|
||
15 years ago
|
{
|
||
14 years ago
|
TQDomNode n = element.firstChild();
|
||
|
TQDomElement root = doc.createElement( "ROOT" );
|
||
15 years ago
|
|
||
14 years ago
|
TQDomElement content = doc.createElement( "CONTENT" );
|
||
|
TQDomElement sequence = doc.createElement( "SEQUENCE" );
|
||
15 years ago
|
content.appendChild( sequence );
|
||
|
root.appendChild( content );
|
||
|
|
||
|
while ( !n.isNull() ) {
|
||
|
if ( n.isElement() ) {
|
||
|
filter->processElement( n.toElement(), doc, sequence );
|
||
|
}
|
||
|
else {
|
||
|
kdDebug( DEBUGID ) << "<msqrt> child: " << n.nodeName() << endl;
|
||
|
}
|
||
|
n = n.nextSibling();
|
||
|
}
|
||
|
|
||
|
docnode.appendChild( root );
|
||
|
}
|
||
|
|
||
14 years ago
|
void MathML2KFormulaPrivate::mstyle( TQDomElement element, TQDomNode docnode )
|
||
15 years ago
|
{
|
||
|
bool ok;
|
||
|
|
||
|
MathStyle previousStyle( style );
|
||
|
style.readStyles( element );
|
||
|
|
||
|
if ( element.hasAttribute( "scriptlevel" ) ) {
|
||
14 years ago
|
TQString scriptlevel = element.attribute( "scriptlevel" );
|
||
15 years ago
|
if ( scriptlevel.startsWith( "+" ) || scriptlevel.startsWith( "-" ) )
|
||
|
style.scriptlevel += scriptlevel.toInt( &ok );
|
||
|
else
|
||
|
style.scriptlevel = scriptlevel.toInt( &ok );
|
||
|
if ( !ok )
|
||
|
style.scriptlevel = previousStyle.scriptlevel;
|
||
|
}
|
||
|
if ( element.hasAttribute( "displaystyle" ) ) {
|
||
14 years ago
|
TQString displaystyle = element.attribute( "displaystyle" );
|
||
15 years ago
|
if ( displaystyle == "true" )
|
||
|
style.displaystyle = true;
|
||
|
else if ( displaystyle == "false" )
|
||
|
style.displaystyle = false;
|
||
|
}
|
||
|
if ( element.hasAttribute( "scriptsizemultiplier" ) ) {
|
||
|
style.scriptsizemultiplier =
|
||
|
element.attribute( "scriptsizemultiplier" ).toDouble( &ok );
|
||
|
if ( !ok )
|
||
|
style.scriptsizemultiplier = previousStyle.scriptsizemultiplier;
|
||
|
}
|
||
|
if ( element.hasAttribute( "scriptminsize" ) ) {
|
||
14 years ago
|
TQString scriptminsize = element.attribute( "scriptminsize" );
|
||
15 years ago
|
style.scriptminsize = convertToPoint( scriptminsize, &ok );
|
||
|
if ( !ok )
|
||
|
style.scriptminsize = previousStyle.scriptminsize;
|
||
|
}
|
||
|
|
||
|
if ( element.hasAttribute( "veryverythinmathspace" ) ) {
|
||
14 years ago
|
TQString vvthinmspace = element.attribute( "veryverythinmathspace" );
|
||
15 years ago
|
style.veryverythinmathspace = convertToPoint( vvthinmspace, &ok );
|
||
|
if ( !ok )
|
||
|
style.veryverythinmathspace = previousStyle.veryverythinmathspace;
|
||
|
}
|
||
|
if ( element.hasAttribute( "verythinmathspace" ) ) {
|
||
14 years ago
|
TQString vthinmspace = element.attribute( "verythinmathspace" );
|
||
15 years ago
|
style.verythinmathspace = convertToPoint( vthinmspace, &ok );
|
||
|
if ( !ok )
|
||
|
style.verythinmathspace = previousStyle.verythinmathspace;
|
||
|
}
|
||
|
if ( element.hasAttribute( "thinmathspace" ) ) {
|
||
14 years ago
|
TQString thinmathspace = element.attribute( "thinmathspace" );
|
||
15 years ago
|
style.thinmathspace = convertToPoint( thinmathspace, &ok );
|
||
|
if ( !ok )
|
||
|
style.thinmathspace = previousStyle.thinmathspace;
|
||
|
}
|
||
|
if ( element.hasAttribute( "mediummathspace" ) ) {
|
||
14 years ago
|
TQString mediummathspace = element.attribute( "mediummathspace" );
|
||
15 years ago
|
style.mediummathspace = convertToPoint( mediummathspace, &ok );
|
||
|
if ( !ok )
|
||
|
style.mediummathspace = previousStyle.mediummathspace;
|
||
|
}
|
||
|
if ( element.hasAttribute( "thickmathspace" ) ) {
|
||
14 years ago
|
TQString thickmathspace = element.attribute( "thickmathspace" );
|
||
15 years ago
|
style.thickmathspace = convertToPoint( thickmathspace, &ok );
|
||
|
if ( !ok )
|
||
|
style.thickmathspace = previousStyle.thickmathspace;
|
||
|
}
|
||
|
if ( element.hasAttribute( "verythickmathspace" ) ) {
|
||
14 years ago
|
TQString vthickmspace = element.attribute( "verythickmathspace" );
|
||
15 years ago
|
style.verythickmathspace = convertToPoint( vthickmspace, &ok );
|
||
|
if ( !ok )
|
||
|
style.verythickmathspace = previousStyle.verythickmathspace;
|
||
|
}
|
||
|
if ( element.hasAttribute( "veryverythickmathspace" ) ) {
|
||
14 years ago
|
TQString vvthickmspace = element.attribute( "veryverythickmathspace" );
|
||
15 years ago
|
style.veryverythickmathspace = convertToPoint( vvthickmspace, &ok );
|
||
|
if ( !ok )
|
||
|
style.veryverythickmathspace =
|
||
|
previousStyle.veryverythickmathspace;
|
||
|
}
|
||
|
|
||
|
style.styleChange();
|
||
|
|
||
14 years ago
|
TQDomNode n = element.firstChild();
|
||
15 years ago
|
while ( !n.isNull() ) {
|
||
|
filter->processElement( n, doc, docnode );
|
||
|
n = n.nextSibling();
|
||
|
}
|
||
|
|
||
|
style = previousStyle;
|
||
|
}
|
||
|
|
||
14 years ago
|
void MathML2KFormulaPrivate::mfenced( TQDomElement element, TQDomNode docnode )
|
||
15 years ago
|
{
|
||
14 years ago
|
TQDomElement bracket = doc.createElement( "BRACKET" );
|
||
|
TQString value = element.attribute( "open", "(" );
|
||
|
bracket.setAttribute( "LEFT", TQString::number( value.at( 0 ).latin1() ) );
|
||
15 years ago
|
value = element.attribute( "close", ")" );
|
||
14 years ago
|
bracket.setAttribute( "RIGHT", TQString::number( value.at( 0 ).latin1() ) );
|
||
15 years ago
|
|
||
14 years ago
|
TQDomElement content = doc.createElement( "CONTENT" );
|
||
|
TQDomElement sequence = doc.createElement( "SEQUENCE" );
|
||
15 years ago
|
content.appendChild( sequence );
|
||
|
|
||
14 years ago
|
TQString separators = element.attribute( "separators", "," );
|
||
15 years ago
|
|
||
14 years ago
|
TQDomNode n = element.firstChild();
|
||
15 years ago
|
uint i = 0;
|
||
|
while ( !n.isNull() ) {
|
||
|
if ( n.isElement() ) {
|
||
|
if ( i != 0 && !separators.isEmpty() ) {
|
||
14 years ago
|
TQDomElement textelement = doc.createElement( "TEXT" );
|
||
15 years ago
|
if ( i > separators.length() )
|
||
|
i = separators.length();
|
||
14 years ago
|
textelement.setAttribute( "CHAR", TQString( separators.at( i - 1 ) ) );
|
||
15 years ago
|
//style.setStyles( textelement );
|
||
|
sequence.appendChild( textelement );
|
||
|
}
|
||
|
++i;
|
||
14 years ago
|
TQDomElement e = n.toElement();
|
||
15 years ago
|
filter->processElement( e, doc, sequence );
|
||
|
}
|
||
|
else {
|
||
|
kdDebug( DEBUGID ) << "<mfenced> child: " << n.nodeName() << endl;
|
||
|
}
|
||
|
n = n.nextSibling();
|
||
|
}
|
||
|
bracket.appendChild( content );
|
||
|
docnode.appendChild( bracket );
|
||
|
}
|
||
|
|
||
14 years ago
|
void MathML2KFormulaPrivate::mtable( TQDomElement element, TQDomNode docnode )
|
||
15 years ago
|
{
|
||
|
MathStyle previousStyle( style );
|
||
14 years ago
|
TQString displaystyle = element.attribute( "displaystyle", "false" );
|
||
15 years ago
|
if ( displaystyle == "true" ) {
|
||
|
style.displaystyle = true;
|
||
|
}
|
||
|
else {
|
||
|
// false is default and also used for illegal values
|
||
|
style.displaystyle = false;
|
||
|
}
|
||
|
style.styleChange();
|
||
|
|
||
14 years ago
|
TQString subtag;
|
||
15 years ago
|
int rows = 0; int cols = 0;
|
||
14 years ago
|
TQDomNode n = element.firstChild();
|
||
15 years ago
|
|
||
|
while ( !n.isNull() ) {
|
||
|
if ( n.isElement() ) {
|
||
14 years ago
|
TQDomElement e = n.toElement();
|
||
15 years ago
|
subtag = e.tagName();
|
||
|
if (subtag == "mtr")
|
||
|
{
|
||
|
++rows;
|
||
|
|
||
|
/* Determins the number of columns */
|
||
|
|
||
14 years ago
|
TQDomNode cellnode = e.firstChild();
|
||
15 years ago
|
int cc = 0;
|
||
|
|
||
|
while ( !cellnode.isNull() ) {
|
||
|
if ( cellnode.isElement() )
|
||
|
cc++;
|
||
|
cellnode = cellnode.nextSibling();
|
||
|
}
|
||
|
|
||
|
if ( cc > cols )
|
||
|
cols = cc;
|
||
|
|
||
|
}
|
||
|
}
|
||
|
else {
|
||
|
kdDebug( DEBUGID ) << "<mtable> child: " << n.nodeName() << endl;
|
||
|
}
|
||
|
n = n.nextSibling();
|
||
|
}
|
||
|
|
||
|
/* Again createing elements, I need to know the number
|
||
|
of rows and cols to leave empty spaces */
|
||
|
|
||
|
n = element.firstChild();
|
||
14 years ago
|
TQDomElement matrix = doc.createElement( "MATRIX" );
|
||
15 years ago
|
matrix.setAttribute( "COLUMNS", cols );
|
||
|
matrix.setAttribute( "ROWS", rows );
|
||
|
|
||
|
while ( !n.isNull() ) {
|
||
|
if ( n.isElement() ) {
|
||
14 years ago
|
TQDomElement e = n.toElement();
|
||
15 years ago
|
subtag = e.tagName();
|
||
|
if ( subtag == "mtr" ) {
|
||
14 years ago
|
TQDomNode cellnode = e.firstChild();
|
||
15 years ago
|
int cc = 0;
|
||
|
while ( !cellnode.isNull() ) {
|
||
|
if ( cellnode.isElement() ) {
|
||
|
++cc;
|
||
14 years ago
|
TQDomElement cell = doc.createElement( "SEQUENCE" );
|
||
|
TQDomElement cellelement = cellnode.toElement();
|
||
15 years ago
|
filter->processElement( cellelement, doc, cell );
|
||
|
matrix.appendChild( cell );
|
||
|
}
|
||
|
cellnode = cellnode.nextSibling();
|
||
|
}
|
||
|
|
||
|
/* Add empty elements */
|
||
|
for(; cc < cols; cc++ ) {
|
||
14 years ago
|
TQDomElement cell = doc.createElement( "SEQUENCE" );
|
||
15 years ago
|
matrix.appendChild( cell );
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
n = n.nextSibling();
|
||
|
}
|
||
|
|
||
|
style = previousStyle;
|
||
|
docnode.appendChild(matrix);
|
||
|
}
|
||
|
|
||
14 years ago
|
void MathML2KFormulaPrivate::msub_msup( TQDomElement element, TQDomNode docnode )
|
||
15 years ago
|
{
|
||
14 years ago
|
TQDomNode n = element.firstChild();
|
||
15 years ago
|
int i = 0;
|
||
14 years ago
|
TQDomElement root = doc.createElement( "INDEX" );
|
||
15 years ago
|
|
||
|
while ( !n.isNull() && i < 2 ) {
|
||
|
if ( n.isElement() ) {
|
||
|
++i;
|
||
|
if ( i == 1 ) { // first is content (base)
|
||
14 years ago
|
TQDomElement content = doc.createElement( "CONTENT" );
|
||
|
TQDomElement sequence = doc.createElement( "SEQUENCE" );
|
||
15 years ago
|
content.appendChild( sequence );
|
||
14 years ago
|
TQDomElement e = n.toElement();
|
||
15 years ago
|
filter->processElement( e, doc, sequence );
|
||
|
|
||
|
root.appendChild( content );
|
||
|
}
|
||
|
else {
|
||
14 years ago
|
TQDomElement index;
|
||
15 years ago
|
if ( element.tagName() == "msup" )
|
||
|
index = doc.createElement( "UPPERRIGHT" );
|
||
|
else
|
||
|
index = doc.createElement( "LOWERRIGHT" );
|
||
|
|
||
|
MathStyle previousStyle( style );
|
||
|
style.scriptlevel += 1;
|
||
|
style.displaystyle = false;
|
||
|
style.styleChange();
|
||
|
|
||
14 years ago
|
TQDomElement sequence = doc.createElement( "SEQUENCE" );
|
||
15 years ago
|
index.appendChild( sequence );
|
||
14 years ago
|
TQDomElement e = n.toElement();
|
||
15 years ago
|
filter->processElement( e, doc, sequence );
|
||
|
root.appendChild( index );
|
||
|
|
||
|
style = previousStyle;
|
||
|
}
|
||
|
}
|
||
|
else {
|
||
|
kdDebug( DEBUGID ) << "<" << element.tagName() << "> child: "
|
||
|
<< n.nodeName() << endl;
|
||
|
}
|
||
|
n = n.nextSibling();
|
||
|
}
|
||
|
docnode.appendChild( root );
|
||
|
}
|
||
|
|
||
14 years ago
|
void MathML2KFormulaPrivate::munder( TQDomElement element, TQDomNode docnode, bool oasisFormat )
|
||
15 years ago
|
{
|
||
|
bool accentunder;
|
||
|
|
||
14 years ago
|
TQString au = element.attribute( "accentunder" );
|
||
15 years ago
|
if ( au == "true" )
|
||
|
accentunder = true;
|
||
|
else if ( au == "false" )
|
||
|
accentunder = false;
|
||
|
else {
|
||
|
// use default
|
||
|
|
||
14 years ago
|
TQDomElement mo;
|
||
15 years ago
|
// is underscript an embellished operator?
|
||
|
if ( isEmbellishedOperator( element.childNodes().item( 1 ), &mo, oasisFormat ) ) {
|
||
|
if ( mo.attribute( "accent" ) == "true" )
|
||
|
accentunder = true;
|
||
|
else
|
||
|
accentunder = false;
|
||
|
}
|
||
|
else
|
||
|
accentunder = false;
|
||
|
}
|
||
|
|
||
14 years ago
|
TQDomNode n = element.firstChild();
|
||
15 years ago
|
int i = 0;
|
||
14 years ago
|
TQDomElement root = doc.createElement( "INDEX" );
|
||
15 years ago
|
|
||
|
while ( !n.isNull() && i < 2 ) {
|
||
|
if ( n.isElement() ) {
|
||
|
++i;
|
||
|
if ( i == 1 ) { // first is content (base)
|
||
14 years ago
|
TQDomElement content = doc.createElement( "CONTENT" );
|
||
|
TQDomElement sequence = doc.createElement( "SEQUENCE" );
|
||
15 years ago
|
content.appendChild( sequence );
|
||
14 years ago
|
TQDomElement e = n.toElement();
|
||
15 years ago
|
filter->processElement( e, doc, sequence );
|
||
|
|
||
|
root.appendChild( content );
|
||
|
}
|
||
|
else { // underscript
|
||
|
MathStyle previousStyle( style );
|
||
|
style.displaystyle = false;
|
||
|
if ( !accentunder ) {
|
||
|
style.scriptlevel += 1;
|
||
|
style.styleChange();
|
||
|
}
|
||
|
|
||
14 years ago
|
TQDomElement mo; TQDomElement index;
|
||
15 years ago
|
if ( isEmbellishedOperator( n.previousSibling(), &mo, oasisFormat ) &&
|
||
|
!previousStyle.displaystyle &&
|
||
|
mo.attribute( "movablelimits" ) == "true" )
|
||
|
{
|
||
|
index = doc.createElement( "LOWERRIGHT" );
|
||
|
}
|
||
|
else {
|
||
|
index = doc.createElement( "LOWERMIDDLE" );
|
||
|
}
|
||
|
|
||
14 years ago
|
TQDomElement sequence = doc.createElement( "SEQUENCE" );
|
||
15 years ago
|
index.appendChild( sequence );
|
||
14 years ago
|
TQDomElement e = n.toElement();
|
||
15 years ago
|
filter->processElement( e, doc, sequence );
|
||
|
root.appendChild( index );
|
||
|
|
||
|
style = previousStyle;
|
||
|
}
|
||
|
}
|
||
|
else {
|
||
|
kdDebug( DEBUGID ) << "<" << element.tagName() << "> child: "
|
||
|
<< n.nodeName() << endl;
|
||
|
}
|
||
|
n = n.nextSibling();
|
||
|
}
|
||
|
|
||
|
docnode.appendChild( root );
|
||
|
}
|
||
|
|
||
14 years ago
|
void MathML2KFormulaPrivate::mover( TQDomElement element, TQDomNode docnode, bool oasisFormat )
|
||
15 years ago
|
{
|
||
|
bool accent;
|
||
|
|
||
14 years ago
|
TQString ac = element.attribute( "accent" );
|
||
15 years ago
|
if ( ac == "true" )
|
||
|
accent = true;
|
||
|
else if ( ac == "false" )
|
||
|
accent = false;
|
||
|
else {
|
||
|
// use default
|
||
|
|
||
14 years ago
|
TQDomElement mo;
|
||
15 years ago
|
// is overscript an embellished operator?
|
||
|
if ( isEmbellishedOperator( element.childNodes().item( 1 ), &mo, oasisFormat ) ) {
|
||
|
if ( mo.attribute( "accent" ) == "true" )
|
||
|
accent = true;
|
||
|
else
|
||
|
accent = false;
|
||
|
}
|
||
|
else
|
||
|
accent = false;
|
||
|
}
|
||
|
|
||
14 years ago
|
TQDomNode n = element.firstChild();
|
||
15 years ago
|
int i = 0;
|
||
14 years ago
|
TQDomElement root = doc.createElement( "INDEX" );
|
||
15 years ago
|
|
||
|
while ( !n.isNull() && i < 2 ) {
|
||
|
if ( n.isElement() ) {
|
||
|
++i;
|
||
|
if ( i == 1 ) { // first is content (base)
|
||
14 years ago
|
TQDomElement content = doc.createElement( "CONTENT" );
|
||
|
TQDomElement sequence = doc.createElement( "SEQUENCE" );
|
||
15 years ago
|
content.appendChild( sequence );
|
||
14 years ago
|
TQDomElement e = n.toElement();
|
||
15 years ago
|
filter->processElement( e, doc, sequence );
|
||
|
|
||
|
root.appendChild( content );
|
||
|
}
|
||
|
else { // overscript
|
||
|
MathStyle previousStyle( style );
|
||
|
style.displaystyle = false;
|
||
|
if ( !accent ) {
|
||
|
style.scriptlevel += 1;
|
||
|
style.styleChange();
|
||
|
}
|
||
|
|
||
14 years ago
|
TQDomElement mo; TQDomElement index;
|
||
15 years ago
|
if ( isEmbellishedOperator( n.previousSibling(), &mo, oasisFormat ) &&
|
||
|
!previousStyle.displaystyle &&
|
||
|
mo.attribute( "movablelimits" ) == "true" )
|
||
|
{
|
||
|
index = doc.createElement( "UPPERRIGHT" );
|
||
|
}
|
||
|
else {
|
||
|
index = doc.createElement( "UPPERMIDDLE" );
|
||
|
}
|
||
|
|
||
14 years ago
|
TQDomElement sequence = doc.createElement( "SEQUENCE" );
|
||
15 years ago
|
index.appendChild( sequence );
|
||
14 years ago
|
TQDomElement e = n.toElement();
|
||
15 years ago
|
filter->processElement( e, doc, sequence );
|
||
|
root.appendChild( index );
|
||
|
|
||
|
style = previousStyle;
|
||
|
}
|
||
|
}
|
||
|
else {
|
||
|
kdDebug( DEBUGID ) << "<" << element.tagName() << "> child: "
|
||
|
<< n.nodeName() << endl;
|
||
|
}
|
||
|
n = n.nextSibling();
|
||
|
}
|
||
|
|
||
|
docnode.appendChild( root );
|
||
|
}
|
||
|
|
||
14 years ago
|
void MathML2KFormulaPrivate::munderover( TQDomElement element, TQDomNode docnode, bool oasisFormat )
|
||
15 years ago
|
{
|
||
|
bool accent;
|
||
|
bool accentunder;
|
||
|
|
||
14 years ago
|
TQString value = element.attribute( "accentunder" );
|
||
15 years ago
|
if ( value == "true" )
|
||
|
accentunder = true;
|
||
|
else if ( value == "false" )
|
||
|
accentunder = false;
|
||
|
else {
|
||
|
// use default
|
||
|
|
||
14 years ago
|
TQDomElement mo;
|
||
15 years ago
|
// is underscript an embellished operator?
|
||
|
if ( isEmbellishedOperator( element.childNodes().item( 1 ), &mo, oasisFormat ) ) {
|
||
|
if ( mo.attribute( "accent" ) == "true" )
|
||
|
accentunder = true;
|
||
|
else
|
||
|
accentunder = false;
|
||
|
}
|
||
|
else
|
||
|
accentunder = false;
|
||
|
}
|
||
|
value = element.attribute( "accent" );
|
||
|
if ( value == "true" )
|
||
|
accent = true;
|
||
|
else if ( value == "false" )
|
||
|
accent = false;
|
||
|
else {
|
||
|
// use default
|
||
|
|
||
14 years ago
|
TQDomElement mo;
|
||
15 years ago
|
// is overscript an embellished operator?
|
||
|
if ( isEmbellishedOperator( element.childNodes().item( 2 ), &mo,oasisFormat ) ) {
|
||
|
kdDebug( DEBUGID ) << "embellished operator" << endl;
|
||
|
if ( mo.attribute( "accent" ) == "true" )
|
||
|
accent = true;
|
||
|
else
|
||
|
accent = false;
|
||
|
}
|
||
|
else
|
||
|
accent = false;
|
||
|
}
|
||
|
kdDebug( DEBUGID ) << "munderover:\n accentunder = " << accentunder
|
||
|
<< "\n accent = " << accent << endl;
|
||
|
|
||
14 years ago
|
TQDomNode n = element.firstChild();
|
||
15 years ago
|
int i = 0;
|
||
14 years ago
|
TQDomElement root = doc.createElement( "INDEX" );
|
||
15 years ago
|
|
||
|
while ( !n.isNull() && i < 3 ) {
|
||
|
if ( n.isElement() ) {
|
||
|
++i;
|
||
|
if ( i == 1 ) { // base
|
||
14 years ago
|
TQDomElement content = doc.createElement( "CONTENT" );
|
||
|
TQDomElement sequence = doc.createElement( "SEQUENCE" );
|
||
15 years ago
|
content.appendChild( sequence );
|
||
14 years ago
|
TQDomElement e = n.toElement();
|
||
15 years ago
|
filter->processElement( e, doc, sequence );
|
||
|
|
||
|
root.appendChild( content );
|
||
|
}
|
||
|
else if ( i == 2 ) { // underscript
|
||
|
MathStyle previousStyle( style );
|
||
|
style.displaystyle = false;
|
||
|
if ( !accentunder ) {
|
||
|
style.scriptlevel += 1;
|
||
|
style.styleChange();
|
||
|
}
|
||
|
|
||
14 years ago
|
TQDomElement mo; TQDomElement index;
|
||
15 years ago
|
// is the base an embellished operator?
|
||
|
if ( isEmbellishedOperator( element.firstChild(), &mo, oasisFormat ) &&
|
||
|
!previousStyle.displaystyle &&
|
||
|
mo.attribute( "movablelimits" ) == "true" )
|
||
|
{
|
||
|
index = doc.createElement( "LOWERRIGHT" );
|
||
|
}
|
||
|
else {
|
||
|
index = doc.createElement( "LOWERMIDDLE" );
|
||
|
}
|
||
|
|
||
14 years ago
|
TQDomElement sequence = doc.createElement( "SEQUENCE" );
|
||
15 years ago
|
index.appendChild( sequence );
|
||
14 years ago
|
TQDomElement e = n.toElement();
|
||
15 years ago
|
filter->processElement( e, doc, sequence );
|
||
|
root.appendChild( index );
|
||
|
|
||
|
style = previousStyle;
|
||
|
}
|
||
|
else { // overscript
|
||
|
MathStyle previousStyle( style );
|
||
|
style.displaystyle = false;
|
||
|
if ( !accent ) {
|
||
|
style.scriptlevel += 1;
|
||
|
style.styleChange();
|
||
|
}
|
||
|
|
||
14 years ago
|
TQDomElement mo; TQDomElement index;
|
||
15 years ago
|
if ( isEmbellishedOperator( element.firstChild(), &mo, oasisFormat ) &&
|
||
|
!previousStyle.displaystyle &&
|
||
|
mo.attribute( "movablelimits" ) == "true" )
|
||
|
{
|
||
|
index = doc.createElement( "UPPERRIGHT" );
|
||
|
}
|
||
|
else {
|
||
|
index = doc.createElement( "UPPERMIDDLE" );
|
||
|
}
|
||
|
|
||
14 years ago
|
TQDomElement sequence = doc.createElement( "SEQUENCE" );
|
||
15 years ago
|
index.appendChild( sequence );
|
||
14 years ago
|
TQDomElement e = n.toElement();
|
||
15 years ago
|
filter->processElement( e, doc, sequence );
|
||
|
root.appendChild( index );
|
||
|
|
||
|
style = previousStyle;
|
||
|
}
|
||
|
}
|
||
|
else {
|
||
|
kdDebug( DEBUGID ) << "<" << element.tagName() << "> child: "
|
||
|
<< n.nodeName() << endl;
|
||
|
}
|
||
|
n = n.nextSibling();
|
||
|
}
|
||
|
|
||
|
docnode.appendChild( root );
|
||
|
}
|
||
|
|
||
14 years ago
|
void MathML2KFormulaPrivate::msubsup( TQDomElement element, TQDomNode docnode )
|
||
15 years ago
|
{
|
||
14 years ago
|
TQDomNode n = element.firstChild();
|
||
15 years ago
|
int i = 0;
|
||
14 years ago
|
TQDomElement root = doc.createElement("INDEX");
|
||
15 years ago
|
MathStyle previousStyle( style );
|
||
|
|
||
|
while ( !n.isNull() && i < 2 ) {
|
||
|
if ( n.isElement() ) {
|
||
|
++i;
|
||
|
if ( i == 1 ) { // base
|
||
14 years ago
|
TQDomElement content = doc.createElement( "CONTENT" );
|
||
|
TQDomElement sequence = doc.createElement( "SEQUENCE" );
|
||
15 years ago
|
content.appendChild( sequence );
|
||
14 years ago
|
TQDomElement e = n.toElement();
|
||
15 years ago
|
filter->processElement( e, doc, sequence );
|
||
|
|
||
|
root.appendChild( content );
|
||
|
}
|
||
|
else if ( i == 2 ) { // subscript
|
||
|
style.scriptlevel += 1;
|
||
|
style.displaystyle = false;
|
||
|
style.styleChange();
|
||
|
|
||
14 years ago
|
TQDomElement index;
|
||
15 years ago
|
index = doc.createElement( "LOWERRIGHT" );
|
||
|
|
||
14 years ago
|
TQDomElement sequence = doc.createElement( "SEQUENCE" );
|
||
15 years ago
|
index.appendChild( sequence );
|
||
14 years ago
|
TQDomElement e = n.toElement();
|
||
15 years ago
|
filter->processElement( e, doc, sequence );
|
||
|
root.appendChild( index );
|
||
|
}
|
||
|
else { // superscript
|
||
14 years ago
|
TQDomElement index;
|
||
15 years ago
|
index = doc.createElement( "UPPERRIGHT" );
|
||
|
|
||
14 years ago
|
TQDomElement sequence = doc.createElement( "SEQUENCE" );
|
||
15 years ago
|
index.appendChild( sequence );
|
||
14 years ago
|
TQDomElement e = n.toElement();
|
||
15 years ago
|
filter->processElement( e, doc, sequence );
|
||
|
root.appendChild( index );
|
||
|
|
||
|
style = previousStyle;
|
||
|
|
||
|
}
|
||
|
}
|
||
|
else {
|
||
|
kdDebug( DEBUGID ) << "<msubsup> child: " << n.nodeName() << endl;
|
||
|
}
|
||
|
n = n.nextSibling();
|
||
|
}
|
||
|
docnode.appendChild( root );
|
||
|
}
|
||
|
|
||
14 years ago
|
void MathML2KFormulaPrivate::createTextElements( TQString text, TQDomNode docnode )
|
||
15 years ago
|
{
|
||
|
for ( uint i = 0; i < text.length(); ++i ) {
|
||
14 years ago
|
TQDomElement textelement = doc.createElement( "TEXT" );
|
||
|
textelement.setAttribute( "CHAR", TQString( text.at( i ) ) );
|
||
15 years ago
|
style.setStyles( textelement );
|
||
|
if ( context.symbolTable().inTable( text.at( i ) ) ) {
|
||
|
// The element is a symbol.
|
||
|
textelement.setAttribute( "SYMBOL", "3" );
|
||
|
}
|
||
|
docnode.appendChild( textelement );
|
||
|
}
|
||
|
}
|
||
|
|
||
14 years ago
|
void MathML2KFormulaPrivate::createNameSequence( TQString text, TQDomNode docnode )
|
||
15 years ago
|
{
|
||
14 years ago
|
TQDomElement namesequence = doc.createElement( "NAMESEQUENCE" );
|
||
15 years ago
|
for ( uint i = 0; i < text.length(); ++i ) {
|
||
14 years ago
|
TQDomElement textelement = doc.createElement( "TEXT" );
|
||
|
textelement.setAttribute( "CHAR", TQString( text.at( i ) ) );
|
||
15 years ago
|
style.setStyles( textelement );
|
||
|
if ( context.symbolTable().inTable( text.at( i ) ) ) {
|
||
|
// The element is a symbol.
|
||
|
textelement.setAttribute( "SYMBOL", "3" );
|
||
|
}
|
||
|
namesequence.appendChild( textelement );
|
||
|
}
|
||
|
docnode.appendChild( namesequence );
|
||
|
}
|
||
|
|
||
14 years ago
|
double MathML2KFormulaPrivate::convertToPoint( TQString value, bool* ok )
|
||
15 years ago
|
{
|
||
|
double pt = 0;
|
||
|
|
||
|
if ( value.endsWith( "em" ) ) {
|
||
|
// See MathML specification, Appendix H
|
||
|
pt = context.getDefaultFont().pointSize();
|
||
|
if ( pt == -1 ) {
|
||
14 years ago
|
TQFontMetrics fm( context.getDefaultFont() );
|
||
15 years ago
|
pt = fm.width( 'M' );
|
||
|
// PIXELS!
|
||
|
}
|
||
|
pt = pt * value.remove( value.length() - 2, 2 ).toDouble( ok );
|
||
|
}
|
||
|
else if ( value.endsWith( "ex" ) ) {
|
||
14 years ago
|
TQFontMetrics fm( context.getDefaultFont() );
|
||
15 years ago
|
pt = fm.height();
|
||
|
// PIXELS, and totally wrong!
|
||
|
}
|
||
|
else if ( value.endsWith( "px" ) ) {
|
||
|
pt = value.remove( value.length() - 2, 2 ).toDouble( ok );
|
||
|
// PIXELS!
|
||
|
}
|
||
|
else if ( value.endsWith( "in" ) ) {
|
||
|
pt = value.remove( value.length() - 2, 2 ).toDouble( ok );
|
||
|
pt *= 72;
|
||
|
}
|
||
|
else if ( value.endsWith( "cm" ) ) {
|
||
|
pt = value.remove( value.length() - 2, 2 ).toDouble( ok );
|
||
|
pt *= 1/2.54 * 72;
|
||
|
}
|
||
|
else if ( value.endsWith( "mm" ) ) {
|
||
|
pt = value.remove( value.length() - 2, 2 ).toDouble( ok );
|
||
|
pt *= 1/25.4 * 72;
|
||
|
}
|
||
|
else if ( value.endsWith( "pt" ) ) {
|
||
|
pt = value.remove( value.length() - 2, 2 ).toDouble( ok );
|
||
|
}
|
||
|
else if ( value.endsWith( "pc" ) ) {
|
||
|
pt = value.remove( value.length() - 2, 2 ).toDouble( ok );
|
||
|
pt /= 12;
|
||
|
}
|
||
|
else {
|
||
|
pt = value.toDouble( ok );
|
||
|
}
|
||
|
|
||
|
return pt;
|
||
|
}
|
||
|
|
||
14 years ago
|
bool MathML2KFormulaPrivate::isEmbellishedOperator( TQDomNode node,
|
||
|
TQDomElement* mo, bool oasisFormat )
|
||
15 years ago
|
{
|
||
|
// See MathML 2.0 specification: 3.2.5.7
|
||
|
|
||
|
if ( !node.isElement() )
|
||
|
return false;
|
||
|
|
||
14 years ago
|
TQDomElement element = node.toElement();
|
||
|
TQString tag = element.tagName();
|
||
15 years ago
|
|
||
|
if ( tag == "mo" )
|
||
|
{
|
||
|
*mo = element;
|
||
|
return true;
|
||
|
}
|
||
|
if ( tag == "msub" || tag == "msup" || tag == "msubsup" ||
|
||
|
tag == "munder" || tag == "mover" || tag == "munderover" ||
|
||
|
tag == "mmultiscripts" || tag == "mfrac" || tag == "semantics" )
|
||
|
{
|
||
|
return isEmbellishedOperator( element.firstChild(), mo,oasisFormat );
|
||
|
}
|
||
|
if ( tag == "maction" )
|
||
|
{
|
||
|
return false; // not supported
|
||
|
}
|
||
|
if ( tag == "mrow" || tag == "mstyle" || tag == "mphantom" || tag == "mpadded" ) {
|
||
14 years ago
|
TQDomNode n = element.firstChild();
|
||
15 years ago
|
int i = 0;
|
||
|
|
||
|
while ( !n.isNull() ) {
|
||
|
if ( isEmbellishedOperator( n, mo,oasisFormat ) ) {
|
||
|
if ( ++i > 1 ) // one (only one) embellished operator
|
||
|
return false;
|
||
|
}
|
||
|
else if ( !isSpaceLike( n, oasisFormat ) ) { // zero or more space-like elements
|
||
|
return false;
|
||
|
}
|
||
|
n = n.nextSibling();
|
||
|
}
|
||
|
return ( i == 1 );
|
||
|
}
|
||
|
return false;
|
||
|
}
|
||
|
|
||
14 years ago
|
bool MathML2KFormulaPrivate::isSpaceLike( TQDomNode node, bool oasisFormat )
|
||
15 years ago
|
{
|
||
|
// See MathML 2.0 specification: 3.2.7.3
|
||
|
|
||
|
if ( !node.isElement() )
|
||
|
return false;
|
||
|
|
||
14 years ago
|
TQDomElement element = node.toElement();
|
||
|
TQString tag = element.tagName();
|
||
15 years ago
|
|
||
|
if ( tag == "mtext" || tag == "mspace" ||
|
||
|
tag == "maligngroup" || tag == "malignmark" ) {
|
||
|
return true;
|
||
|
}
|
||
|
if ( tag == "mstyle" || tag == "mphantom" || tag == "mpadded" || tag == "mrow" ) {
|
||
14 years ago
|
TQDomNode n = element.firstChild();
|
||
15 years ago
|
while ( !n.isNull() ) {
|
||
|
if ( isSpaceLike( n,oasisFormat ) )
|
||
|
n = n.nextSibling();
|
||
|
else
|
||
|
return false;
|
||
|
}
|
||
|
return true;
|
||
|
}
|
||
|
if ( tag == "maction" ) {
|
||
|
return false; // not supported
|
||
|
}
|
||
|
|
||
|
return false;
|
||
|
}
|
||
|
|
||
|
|
||
14 years ago
|
MathML2KFormula::MathML2KFormula( const TQDomDocument& mmldoc, const ContextStyle &contextStyle, bool _oasisFormat )
|
||
15 years ago
|
: m_error( false ), oasisFormat( _oasisFormat ), context( contextStyle )
|
||
|
{
|
||
|
orig_element = mmldoc.documentElement();
|
||
|
done = false;
|
||
|
}
|
||
|
|
||
14 years ago
|
MathML2KFormula::MathML2KFormula( const TQDomElement& mmlelm, const ContextStyle &contextStyle, bool _oasisFormat )
|
||
15 years ago
|
: m_error( false ), orig_element( mmlelm ), oasisFormat( _oasisFormat ), context( contextStyle )
|
||
|
{
|
||
|
done = false;
|
||
|
}
|
||
|
|
||
14 years ago
|
TQDomDocument MathML2KFormula::getKFormulaDom()
|
||
15 years ago
|
{
|
||
|
return formuladoc;
|
||
|
}
|
||
|
|
||
|
|
||
|
|
||
|
void MathML2KFormula::startConversion()
|
||
|
{
|
||
|
//TODO:let it be async
|
||
|
//kdDebug() << origdoc.toString() << endl;
|
||
|
done = false;
|
||
14 years ago
|
formuladoc = TQDomDocument( "KFORMULA" );
|
||
15 years ago
|
impl = new MathML2KFormulaPrivate( this, context, formuladoc );
|
||
|
if ( orig_element.tagName() == "math" ) {
|
||
|
impl->math( orig_element );
|
||
|
m_error = false;
|
||
|
}
|
||
|
else {
|
||
|
kdError() << "Not a MathML document!" << endl;
|
||
|
KMessageBox::error( 0, i18n( "The document does not seem to be MathML." ), i18n( "MathML Import Error" ) );
|
||
|
m_error = true;
|
||
|
}
|
||
|
done = true;
|
||
|
}
|
||
|
|
||
14 years ago
|
bool MathML2KFormula::processElement( TQDomNode node, TQDomDocument& doc, TQDomNode docnode )
|
||
15 years ago
|
{
|
||
|
|
||
14 years ago
|
//TQDomElement *element;
|
||
15 years ago
|
Type type = UNKNOWN;
|
||
|
|
||
|
if ( node.isElement() ) {
|
||
14 years ago
|
TQDomElement element = node.toElement();
|
||
|
TQString tag = element.tagName();
|
||
15 years ago
|
|
||
|
if ( tag == "mi" ) {
|
||
|
type = TOKEN;
|
||
|
impl->mi( element, docnode );
|
||
|
}
|
||
|
else if ( tag == "mo" ) {
|
||
|
type = TOKEN;
|
||
|
impl->mo( element, docnode );
|
||
|
}
|
||
|
else if ( tag == "mn" ) {
|
||
|
type = TOKEN;
|
||
|
impl->mn( element, docnode );
|
||
|
}
|
||
|
else if ( tag == "mtext" ) {
|
||
|
type = TOKEN;
|
||
|
impl->mtext( element, docnode );
|
||
|
}
|
||
|
else if ( tag == "ms" ) {
|
||
|
type = TOKEN;
|
||
|
impl->ms( element, docnode );
|
||
|
}
|
||
|
else if ( tag == "mspace" ) {
|
||
|
type = TOKEN;
|
||
|
impl->mspace( element, docnode );
|
||
|
}
|
||
|
else if ( tag == "mrow" ) {
|
||
|
type = LAYOUT;
|
||
|
impl->mrow( element, docnode );
|
||
|
}
|
||
|
else if ( tag == "mfrac" ) {
|
||
|
type = LAYOUT;
|
||
|
impl->mfrac( element, docnode );
|
||
|
}
|
||
|
else if ( tag == "mroot" ) {
|
||
|
type = LAYOUT;
|
||
|
impl->mroot( element, docnode );
|
||
|
}
|
||
|
else if ( tag == "msqrt" ) {
|
||
|
type = LAYOUT;
|
||
|
impl->msqrt( element, docnode );
|
||
|
}
|
||
|
else if ( tag == "mstyle" ) {
|
||
|
type = LAYOUT;
|
||
|
impl->mstyle( element, docnode );
|
||
|
}
|
||
|
else if ( tag == "mfenced" ) {
|
||
|
type = LAYOUT;
|
||
|
impl->mfenced( element, docnode );
|
||
|
}
|
||
|
else if ( tag == "mtable" ) {
|
||
|
type = TABLE;
|
||
|
impl->mtable( element, docnode );
|
||
|
}
|
||
|
else if ( tag == "msub" || tag == "msup" ) {
|
||
|
type = SCRIPT;
|
||
|
impl->msub_msup( element, docnode );
|
||
|
}
|
||
|
else if ( tag == "munder" ) {
|
||
|
type = SCRIPT;
|
||
|
impl->munder( element, docnode,oasisFormat );
|
||
|
}
|
||
|
else if ( tag == "mover" ) {
|
||
|
type = SCRIPT;
|
||
|
impl->mover( element, docnode,oasisFormat );
|
||
|
}
|
||
|
else if ( tag == "munderover" ) {
|
||
|
type = SCRIPT;
|
||
|
impl->munderover( element, docnode, oasisFormat );
|
||
|
}
|
||
|
else if ( tag == "msubsup" ) {
|
||
|
type = SCRIPT;
|
||
|
impl->msubsup( element, docnode );
|
||
|
}
|
||
|
|
||
|
// content markup (not yet complete)
|
||
|
else if ( tag == "apply" ) {
|
||
|
type = CONTENT;
|
||
14 years ago
|
TQDomNode n = element.firstChild();
|
||
|
TQDomElement op = n.toElement();
|
||
15 years ago
|
uint count = element.childNodes().count();
|
||
13 years ago
|
//adding explicit brackets to replace "apply"s implicit ones
|
||
14 years ago
|
TQDomElement brackets = doc.createElement("BRACKET");
|
||
15 years ago
|
brackets.setAttribute("RIGHT", "41");
|
||
|
brackets.setAttribute("LEFT", "40");
|
||
14 years ago
|
TQDomElement content = doc.createElement("CONTENT");
|
||
15 years ago
|
brackets.appendChild(content);
|
||
14 years ago
|
TQDomElement base = doc.createElement("SEQUENCE");
|
||
15 years ago
|
content.appendChild(base);
|
||
|
docnode.appendChild(brackets);
|
||
|
//Arithmetic, Algebra and Logic operators status
|
||
|
// quotient X
|
||
|
// factorial O
|
||
|
// divide O
|
||
|
// max, min X
|
||
|
// minus O
|
||
|
// plus O
|
||
|
// power O
|
||
|
// rem X
|
||
|
// times O
|
||
|
// root X
|
||
|
// gcd X
|
||
|
// and O
|
||
|
// or O
|
||
|
// xor O
|
||
|
// not O
|
||
|
// implies O
|
||
|
// forall X
|
||
|
// exists X
|
||
|
// abs O
|
||
|
// conjugate X
|
||
|
// arg X
|
||
|
// real X
|
||
|
// imaginary X
|
||
|
// lcm X
|
||
|
// floor X
|
||
|
// ceiling X
|
||
|
|
||
|
// n-ary
|
||
|
if ( op.tagName() == "plus" || op.tagName() == "times" ||
|
||
|
op.tagName() == "and" || op.tagName() == "or" ||
|
||
|
op.tagName() == "xor" ) {
|
||
|
|
||
|
n = n.nextSibling();
|
||
|
bool first = true;
|
||
|
|
||
|
while ( !n.isNull() ) {
|
||
|
if ( n.isElement() ) {
|
||
|
if ( !first ) {
|
||
14 years ago
|
TQDomElement text = doc.createElement( "TEXT" );
|
||
|
TQString value;
|
||
15 years ago
|
|
||
|
if ( op.tagName() == "plus" )
|
||
|
value = "+";
|
||
|
else if ( op.tagName() == "times" )
|
||
|
value = "*";
|
||
|
else if ( op.tagName() == "and" )
|
||
|
value = "&";
|
||
|
else if ( op.tagName() == "or" )
|
||
|
value = "|";
|
||
|
else if ( op.tagName() == "xor" )
|
||
|
value = "^"; // ???
|
||
|
|
||
|
text.setAttribute( "CHAR", value ); //switch to createTextElements?
|
||
|
base.appendChild( text );
|
||
|
}
|
||
|
first = false;
|
||
14 years ago
|
TQDomElement e = n.toElement();
|
||
15 years ago
|
processElement( e, doc, base );
|
||
|
}
|
||
|
n = n.nextSibling();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
else if ( op.tagName() == "factorial" ) {
|
||
14 years ago
|
TQDomElement e = n.nextSibling().toElement();
|
||
15 years ago
|
processElement( e, doc, docnode );
|
||
|
impl->createTextElements( "!", base );
|
||
|
}
|
||
|
else if ( op.tagName() == "minus" ) {
|
||
|
n = n.nextSibling();
|
||
|
if ( count == 2 ) { // unary
|
||
|
impl->createTextElements( "-", base );
|
||
14 years ago
|
TQDomElement e = n.toElement();
|
||
15 years ago
|
processElement( e, doc, base );
|
||
|
}
|
||
|
else if ( count == 3 ) { // binary
|
||
14 years ago
|
TQDomElement e = n.toElement();
|
||
15 years ago
|
processElement( e, doc, base );
|
||
|
impl->createTextElements( "-", base );
|
||
|
n = n.nextSibling();
|
||
|
e = n.toElement();
|
||
|
processElement( e, doc, base );
|
||
|
}
|
||
|
}
|
||
|
|
||
|
else if ( op.tagName() == "divide" && count == 3 ) {
|
||
|
n = n.nextSibling();
|
||
14 years ago
|
TQDomElement e = n.toElement();
|
||
15 years ago
|
processElement( e, doc, base );
|
||
|
impl->createTextElements("/", base);
|
||
|
n = n.nextSibling();
|
||
|
e = n.toElement();
|
||
|
processElement( e, doc, base );
|
||
|
}
|
||
|
else if ( op.tagName() == "power" && count == 3 ) {
|
||
|
//code duplication of msub_sup(), but I can't find a way to cleanly call it
|
||
|
n = n.nextSibling();
|
||
14 years ago
|
TQDomElement e = n.toElement();
|
||
|
TQDomElement index = doc.createElement("INDEX");
|
||
15 years ago
|
base.appendChild(index);
|
||
14 years ago
|
TQDomElement content = doc.createElement("CONTENT");
|
||
15 years ago
|
index.appendChild(content);
|
||
14 years ago
|
TQDomElement sequence = doc.createElement("SEQUENCE");
|
||
15 years ago
|
content.appendChild(sequence);
|
||
|
processElement(e, doc, sequence);
|
||
14 years ago
|
TQDomElement upper = doc.createElement("UPPERRIGHT");
|
||
15 years ago
|
index.appendChild(upper);
|
||
|
sequence = doc.createElement("SEQUENCE");
|
||
|
upper.appendChild(sequence);
|
||
|
n = n.nextSibling();
|
||
|
e = n.toElement();
|
||
|
processElement(e, doc, sequence);
|
||
|
}
|
||
|
else if ( op.tagName() == "abs" && count == 2) {
|
||
|
n = n.nextSibling();
|
||
14 years ago
|
TQDomElement e = n.toElement();
|
||
|
TQDomElement bracket = doc.createElement("BRACKET");
|
||
15 years ago
|
bracket.setAttribute("RIGHT", "257");
|
||
|
bracket.setAttribute("LEFT", "256");
|
||
|
base.appendChild(bracket);
|
||
14 years ago
|
TQDomElement content = doc.createElement("CONTENT");
|
||
15 years ago
|
bracket.appendChild(content);
|
||
14 years ago
|
TQDomElement sequence = doc.createElement("SEQUENCE");
|
||
15 years ago
|
content.appendChild(sequence);
|
||
|
processElement(e, doc, sequence);
|
||
|
}
|
||
|
else if ( op.tagName() == "not" && count == 2) {
|
||
|
n = n.nextSibling();
|
||
14 years ago
|
TQDomElement e = n.toElement();
|
||
|
impl->createTextElements(TQString(TQChar(0xAC)), base);
|
||
15 years ago
|
processElement(e, doc, base);
|
||
|
}
|
||
|
else if ( op.tagName() == "implies" && count == 3 ) {
|
||
|
n = n.nextSibling();
|
||
14 years ago
|
TQDomElement e = n.toElement();
|
||
15 years ago
|
processElement( e, doc, base );
|
||
14 years ago
|
impl->createTextElements(TQString(TQChar(0x21D2)), base);
|
||
15 years ago
|
n = n.nextSibling();
|
||
|
e = n.toElement();
|
||
|
processElement( e, doc, base );
|
||
|
}
|
||
|
// many, many more...
|
||
|
|
||
|
}
|
||
|
|
||
|
else if ( tag == "cn" ) {
|
||
|
type = CONTENT;
|
||
14 years ago
|
TQString type = element.attribute( "type", "real" );
|
||
15 years ago
|
|
||
|
if ( type == "real" || type == "constant" ) {
|
||
|
impl->createTextElements( element.text().stripWhiteSpace(),
|
||
|
docnode );
|
||
|
}
|
||
|
else if ( type == "integer" ) {
|
||
14 years ago
|
TQString base = element.attribute( "base" );
|
||
15 years ago
|
if ( !base ) {
|
||
|
impl->createTextElements( element.text().stripWhiteSpace(),
|
||
|
docnode );
|
||
|
}
|
||
|
else {
|
||
14 years ago
|
TQDomElement index = doc.createElement( "INDEX" );
|
||
|
TQDomElement content = doc.createElement( "CONTENT" );
|
||
|
TQDomElement sequence = doc.createElement( "SEQUENCE" );
|
||
15 years ago
|
impl->createTextElements( element.text().stripWhiteSpace(),
|
||
|
sequence );
|
||
|
content.appendChild( sequence );
|
||
|
index.appendChild( content );
|
||
|
|
||
14 years ago
|
TQDomElement lowerright = doc.createElement( "LOWERRIGHT" );
|
||
15 years ago
|
sequence = doc.createElement( "SEQUENCE" );
|
||
|
|
||
|
impl->createTextElements( base, sequence );
|
||
|
|
||
|
lowerright.appendChild( sequence );
|
||
|
index.appendChild( lowerright );
|
||
|
|
||
|
docnode.appendChild( index );
|
||
|
}
|
||
|
}
|
||
|
else if ( type == "rational" ) {
|
||
14 years ago
|
TQDomNode n = element.firstChild();
|
||
15 years ago
|
impl->createTextElements( n.toText().data().stripWhiteSpace(),
|
||
|
docnode );
|
||
|
|
||
|
n = n.nextSibling(); // <sep/>
|
||
|
impl->createTextElements( "/", docnode );
|
||
|
|
||
|
n = n.nextSibling();
|
||
|
impl->createTextElements( n.toText().data().stripWhiteSpace(),
|
||
|
docnode );
|
||
|
}
|
||
|
else if ( type == "complex-cartesian" ) {
|
||
14 years ago
|
TQDomNode n = element.firstChild();
|
||
15 years ago
|
impl->createTextElements( n.toText().data().stripWhiteSpace(),
|
||
|
docnode );
|
||
|
|
||
|
n = n.nextSibling(); // <sep/>
|
||
|
impl->createTextElements( "+", docnode );
|
||
|
|
||
|
n = n.nextSibling();
|
||
|
impl->createTextElements( n.toText().data().stripWhiteSpace(),
|
||
|
docnode );
|
||
|
|
||
|
impl->createTextElements( "i", docnode );
|
||
|
}
|
||
|
|
||
|
else if ( type == "complex-polar" ) {
|
||
14 years ago
|
TQDomNode n = element.firstChild();
|
||
15 years ago
|
impl->createTextElements( n.toText().data().stripWhiteSpace(),
|
||
|
docnode );
|
||
|
|
||
|
n = n.nextSibling(); // <sep/>
|
||
14 years ago
|
TQDomElement index = doc.createElement( "INDEX" );
|
||
|
TQDomElement content = doc.createElement( "CONTENT" );
|
||
|
TQDomElement sequence = doc.createElement( "SEQUENCE" );
|
||
|
TQDomElement textelement = doc.createElement( "TEXT" );
|
||
15 years ago
|
textelement.setAttribute( "CHAR", "e" );
|
||
|
sequence.appendChild( textelement );
|
||
|
content.appendChild( sequence );
|
||
|
index.appendChild( content );
|
||
|
|
||
14 years ago
|
TQDomElement upperright = doc.createElement( "UPPERRIGHT" );
|
||
15 years ago
|
sequence = doc.createElement( "SEQUENCE" );
|
||
|
textelement = doc.createElement( "TEXT" );
|
||
|
textelement.setAttribute( "CHAR", "i" );
|
||
|
sequence.appendChild( textelement );
|
||
|
|
||
|
n = n.nextSibling();
|
||
|
impl->createTextElements( n.toText().data().stripWhiteSpace(),
|
||
|
sequence );
|
||
|
|
||
|
upperright.appendChild( sequence );
|
||
|
index.appendChild( upperright );
|
||
|
|
||
|
docnode.appendChild( index );
|
||
|
}
|
||
|
}
|
||
|
|
||
|
else if ( tag == "ci" ) {
|
||
|
type = CONTENT;
|
||
14 years ago
|
TQDomNode n = element.firstChild();
|
||
15 years ago
|
|
||
|
if ( n.isText() ) {
|
||
|
impl->createTextElements( n.toText().data().stripWhiteSpace(),
|
||
|
docnode );
|
||
|
}
|
||
|
else if ( n.isElement() ) {
|
||
14 years ago
|
TQDomElement e = n.toElement();
|
||
15 years ago
|
processElement( e, doc, docnode );
|
||
|
}
|
||
|
else if ( n.isEntityReference() ) {
|
||
|
kdDebug( DEBUGID ) << "isEntityReference: "
|
||
|
<< n.toEntityReference().nodeName().latin1()
|
||
|
<< endl;
|
||
|
}
|
||
|
else
|
||
|
kdDebug( DEBUGID ) << "ci: " << n.nodeName().latin1() << endl;
|
||
|
}
|
||
|
|
||
|
else if ( tag == "list" ) {
|
||
|
type = CONTENT;
|
||
14 years ago
|
TQDomNode n = element.firstChild();
|
||
15 years ago
|
|
||
14 years ago
|
TQDomElement bracket = doc.createElement( "BRACKET" );
|
||
15 years ago
|
bracket.setAttribute( "LEFT", 91 ); // [
|
||
|
bracket.setAttribute( "RIGHT", 93 ); // ]
|
||
14 years ago
|
TQDomElement content = doc.createElement( "CONTENT" );
|
||
|
TQDomElement sequence = doc.createElement( "SEQUENCE" );
|
||
15 years ago
|
|
||
|
bool first = true;
|
||
|
|
||
|
while ( !n.isNull() ) {
|
||
|
if ( n.isElement() ) {
|
||
|
if ( !first ) {
|
||
14 years ago
|
TQDomElement textelement = doc.createElement( "TEXT" );
|
||
15 years ago
|
textelement.setAttribute( "CHAR", "," );
|
||
|
sequence.appendChild( textelement );
|
||
|
}
|
||
|
first = false;
|
||
14 years ago
|
TQDomElement e = n.toElement();
|
||
15 years ago
|
processElement( e, doc, sequence );
|
||
|
}
|
||
|
n = n.nextSibling();
|
||
|
}
|
||
|
|
||
|
content.appendChild( sequence );
|
||
|
bracket.appendChild( content );
|
||
|
docnode.appendChild( bracket );
|
||
|
}
|
||
|
}
|
||
|
|
||
14 years ago
|
if ( type == UNKNOWN && node.nodeType() != TQDomNode::AttributeNode ) {
|
||
15 years ago
|
kdDebug() << "Not an element: " << node.nodeName() << endl;
|
||
14 years ago
|
TQDomNode n = node.firstChild();
|
||
15 years ago
|
while ( !n.isNull() ) {
|
||
|
processElement( n, doc, docnode );
|
||
|
n = n.nextSibling();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
KFORMULA_NAMESPACE_END
|
||
|
|
||
|
using namespace KFormula;
|
||
|
#include "kformulamathmlread.moc"
|