[Libreoffice-commits] .: 22 commits - oox/inc oox/Library_oox.mk oox/Package_generated.mk oox/Package_inc.mk oox/Package_source.mk oox/source starmath/inc starmath/Library_sm.mk starmath/source sw/CppunitTest_sw_swdoc_test.mk sw/inc sw/Library_sw.mk sw/source writerfilter/Library_ooxml.mk writerfilter/source

Lubos Lunak llunak at kemper.freedesktop.org
Thu Nov 24 09:44:38 PST 2011


 oox/Library_oox.mk                                    |    4 
 oox/Package_generated.mk                              |    3 
 oox/Package_inc.mk                                    |    4 
 oox/Package_source.mk                                 |   32 
 oox/inc/oox/export/ooxmlexport.hxx                    |   48 -
 oox/inc/oox/mathml/export.hxx                         |   53 +
 oox/inc/oox/mathml/import.hxx                         |   61 +
 oox/inc/oox/mathml/importutils.hxx                    |  177 ++++
 oox/source/export/ooxmlexport.cxx                     |   35 
 oox/source/mathml/export.cxx                          |   40 +
 oox/source/mathml/import.cxx                          |   44 +
 oox/source/mathml/importutils.cxx                     |  267 ++++++
 starmath/Library_sm.mk                                |    3 
 starmath/inc/document.hxx                             |    2 
 starmath/inc/unomodel.hxx                             |   10 
 starmath/source/document.cxx                          |   14 
 starmath/source/ooxml.cxx                             |  712 ------------------
 starmath/source/ooxml.hxx                             |   72 -
 starmath/source/ooxmlexport.cxx                       |  712 ++++++++++++++++++
 starmath/source/ooxmlexport.hxx                       |   72 +
 starmath/source/ooxmlimport.cxx                       |  302 +++++++
 starmath/source/ooxmlimport.hxx                       |   59 +
 starmath/source/unomodel.cxx                          |    5 
 sw/CppunitTest_sw_swdoc_test.mk                       |    1 
 sw/Library_sw.mk                                      |    1 
 sw/inc/docsh.hxx                                      |    2 
 sw/inc/unotxdoc.hxx                                   |    6 
 sw/source/core/unocore/unoframe.cxx                   |   33 
 sw/source/core/unocore/unomap.cxx                     |    2 
 sw/source/filter/ww8/docxattributeoutput.cxx          |    4 
 sw/source/ui/app/docsh2.cxx                           |   12 
 sw/source/ui/uno/unotxdoc.cxx                         |    5 
 writerfilter/Library_ooxml.mk                         |    1 
 writerfilter/source/dmapper/DomainMapper.cxx          |    4 
 writerfilter/source/dmapper/DomainMapper_Impl.cxx     |   33 
 writerfilter/source/dmapper/DomainMapper_Impl.hxx     |    1 
 writerfilter/source/dmapper/PropertyIds.cxx           |    1 
 writerfilter/source/dmapper/PropertyIds.hxx           |    1 
 writerfilter/source/ooxml/OOXMLFactory.hxx            |    1 
 writerfilter/source/ooxml/OOXMLFastContextHandler.cxx |   62 +
 writerfilter/source/ooxml/OOXMLFastContextHandler.hxx |   31 
 writerfilter/source/ooxml/OOXMLPropertySetImpl.cxx    |   29 
 writerfilter/source/ooxml/OOXMLPropertySetImpl.hxx    |   14 
 writerfilter/source/ooxml/model.xml                   |    2 
 44 files changed, 2061 insertions(+), 916 deletions(-)

New commits:
commit 8be68f44ce8298e7309d4872fb483480355b85e6
Author: Luboš Luňák <l.lunak at suse.cz>
Date:   Thu Nov 24 18:13:44 2011 +0100

    implement mathml docx import m:borderBox

diff --git a/starmath/source/ooxmlimport.cxx b/starmath/source/ooxmlimport.cxx
index ac7d520..a3b3648 100644
--- a/starmath/source/ooxmlimport.cxx
+++ b/starmath/source/ooxmlimport.cxx
@@ -83,6 +83,9 @@ OUString SmOoxmlImport::handleStream()
             case OPENING( M_TOKEN( bar )):
                 ret += STR( " " ) + handleBar();
                 break;
+            case OPENING( M_TOKEN( borderBox )):
+                ret += STR( " " ) + handleBorderBox();
+                break;
             case OPENING( M_TOKEN( f )):
                 ret += STR( " " ) + handleF();
                 break;
@@ -180,6 +183,28 @@ OUString SmOoxmlImport::handleBar()
         return STR( "underline { " ) + e + STR( " }" );
 }
 
+OUString SmOoxmlImport::handleBorderBox()
+{
+    stream.ensureOpeningTag( M_TOKEN( borderBox ));
+    bool isStrikeH = false;
+    if( stream.checkOpeningTag( M_TOKEN( borderBoxPr )))
+    {
+        if( XmlStream::Tag strikeH = stream.checkOpeningTag( M_TOKEN( strikeH )))
+        {
+            if( strikeH.attributes.attribute( M_TOKEN( val ), false ))
+                isStrikeH = true;
+            stream.ensureClosingTag( M_TOKEN( strikeH ));
+        }
+        stream.ensureClosingTag( M_TOKEN( borderBoxPr ));
+    }
+    OUString e = handleE();
+    stream.ensureClosingTag( M_TOKEN( borderBox ));
+    if( isStrikeH )
+        return STR( "overstrike { " ) + e + STR( " }" );
+    // LO does not seem to implement anything for handling the other cases
+    return e;
+}
+
 OUString SmOoxmlImport::handleE()
 {
     stream.ensureOpeningTag( M_TOKEN( e ));
diff --git a/starmath/source/ooxmlimport.hxx b/starmath/source/ooxmlimport.hxx
index 508723c..8d587f7 100644
--- a/starmath/source/ooxmlimport.hxx
+++ b/starmath/source/ooxmlimport.hxx
@@ -46,6 +46,7 @@ private:
     rtl::OUString handleStream();
     rtl::OUString handleAcc();
     rtl::OUString handleBar();
+    rtl::OUString handleBorderBox();
     rtl::OUString handleE();
     rtl::OUString handleF();
     rtl::OUString handleR();
commit 4ae08e816b9bf8e27290f54ccd051346b854bfaf
Author: Luboš Luňák <l.lunak at suse.cz>
Date:   Thu Nov 24 18:02:51 2011 +0100

    prefer widevec, widetilde and widehat for mathml docx import

diff --git a/starmath/source/ooxmlimport.cxx b/starmath/source/ooxmlimport.cxx
index b12b806..ac7d520 100644
--- a/starmath/source/ooxmlimport.cxx
+++ b/starmath/source/ooxmlimport.cxx
@@ -127,13 +127,16 @@ OUString SmOoxmlImport::handleAcc()
             acc = STR( "circle" );
             break;
         case MS_VEC:
-            acc = STR( "vec" );
+            // prefer wide variants for these 3, .docx can't seem to differentiate
+            // between e.g. 'vec' and 'widevec', if whatever the accent is above is short, this
+            // shouldn't matter, but short above a longer expression doesn't look right
+            acc = STR( "widevec" );
             break;
         case MS_TILDE:
-            acc = STR( "tilde" );
+            acc = STR( "widetilde" );
             break;
         case MS_HAT:
-            acc = STR( "hat" );
+            acc = STR( "widehat" );
             break;
         case MS_DOT:
             acc = STR( "dot" );
@@ -144,16 +147,6 @@ OUString SmOoxmlImport::handleAcc()
         case MS_DDDOT:
             acc = STR( "dddot" );
             break;
-// these characters do not exist it seems
-//        case MS_WIDETILDE:
-//            acc = STR( "widetilde" );
-//            break;
-//        case TWIDEHAT:
-//            acc = STR( "widehat" );
-//            break;
-//        case TWIDEVEC:
-//            acc = STR( "widevec" );
-//            break;
         default:
             acc = STR( "acute" );
             break;
commit 48d2a5b86e464dfb75196e440448f0319d676956
Author: Luboš Luňák <l.lunak at suse.cz>
Date:   Thu Nov 24 18:00:47 2011 +0100

    mathml docx read m:bar

diff --git a/starmath/source/ooxmlimport.cxx b/starmath/source/ooxmlimport.cxx
index 5bbb711..b12b806 100644
--- a/starmath/source/ooxmlimport.cxx
+++ b/starmath/source/ooxmlimport.cxx
@@ -80,6 +80,9 @@ OUString SmOoxmlImport::handleStream()
             case OPENING( M_TOKEN( acc )):
                 ret += STR( " " ) + handleAcc();
                 break;
+            case OPENING( M_TOKEN( bar )):
+                ret += STR( " " ) + handleBar();
+                break;
             case OPENING( M_TOKEN( f )):
                 ret += STR( " " ) + handleF();
                 break;
@@ -160,6 +163,30 @@ OUString SmOoxmlImport::handleAcc()
     return acc + STR( " { " ) + e + STR( " }" );
 }
 
+OUString SmOoxmlImport::handleBar()
+{
+    stream.ensureOpeningTag( M_TOKEN( bar ));
+    enum pos_t { top, bot } topbot = bot;
+    if( stream.checkOpeningTag( M_TOKEN( barPr )))
+    {
+        if( XmlStream::Tag pos = stream.checkOpeningTag( M_TOKEN( pos )))
+        {
+            if( pos.attributes.attribute( M_TOKEN( val )) == STR( "top" ))
+                topbot = top;
+            else if( pos.attributes.attribute( M_TOKEN( val )) == STR( "bot" ))
+                topbot = bot;
+            stream.ensureClosingTag( M_TOKEN( pos ));
+        }
+        stream.ensureClosingTag( M_TOKEN( barPr ));
+    }
+    OUString e = handleE();
+    stream.ensureClosingTag( M_TOKEN( bar ));
+    if( topbot == top )
+        return STR( "bar { " ) + e + STR( " }" );
+    else
+        return STR( "underline { " ) + e + STR( " }" );
+}
+
 OUString SmOoxmlImport::handleE()
 {
     stream.ensureOpeningTag( M_TOKEN( e ));
diff --git a/starmath/source/ooxmlimport.hxx b/starmath/source/ooxmlimport.hxx
index 42fbd05..508723c 100644
--- a/starmath/source/ooxmlimport.hxx
+++ b/starmath/source/ooxmlimport.hxx
@@ -45,6 +45,7 @@ public:
 private:
     rtl::OUString handleStream();
     rtl::OUString handleAcc();
+    rtl::OUString handleBar();
     rtl::OUString handleE();
     rtl::OUString handleF();
     rtl::OUString handleR();
commit 5e10ed16ce2ec607324206d49b1073228cacd1aa
Author: Luboš Luňák <l.lunak at suse.cz>
Date:   Thu Nov 24 17:31:42 2011 +0100

    skip elements properly

diff --git a/oox/source/mathml/importutils.cxx b/oox/source/mathml/importutils.cxx
index 927f6e9..1dcb84e 100644
--- a/oox/source/mathml/importutils.cxx
+++ b/oox/source/mathml/importutils.cxx
@@ -222,7 +222,8 @@ void XmlStream::skipElement( int token )
 {
     int closing = ( token & ~TAG_OPENING ) | TAG_CLOSING; // make it a closing tag
     assert( currentToken() == OPENING( token ));
-    // just find the matching closing tag
+    moveToNextTag();
+    // and just find the matching closing tag
     if( recoverAndFindTag( closing ))
     {
         moveToNextTag(); // and skip it too
commit 19a47cb97860a11e57deccb912f47ae19ffc1b65
Author: Luboš Luňák <l.lunak at suse.cz>
Date:   Thu Nov 24 17:14:21 2011 +0100

    mathml docx import - handle m:fPr

diff --git a/starmath/source/ooxmlimport.cxx b/starmath/source/ooxmlimport.cxx
index c0a52de..5bbb711 100644
--- a/starmath/source/ooxmlimport.cxx
+++ b/starmath/source/ooxmlimport.cxx
@@ -162,12 +162,19 @@ OUString SmOoxmlImport::handleAcc()
 
 OUString SmOoxmlImport::handleE()
 {
-    OUString ret;
     stream.ensureOpeningTag( M_TOKEN( e ));
+    OUString ret = readOMathArg( M_TOKEN( e ));
+    stream.ensureClosingTag( M_TOKEN( e ));
+    return ret;
+}
+
+OUString SmOoxmlImport::readOMathArg( int endtoken )
+{
+    OUString ret;
     while( !stream.atEnd())
     { // TODO can there really be more or just one sub-elements?
         XmlStream::Tag tag = stream.currentTag();
-        if( tag.token == CLOSING( M_TOKEN( e )))
+        if( tag.token == CLOSING( endtoken ))
             break;
         switch( tag.token )
         {
@@ -185,7 +192,6 @@ OUString SmOoxmlImport::handleE()
                 break;
         }
     }
-    stream.ensureClosingTag( M_TOKEN( e ));
     return ret;
 }
 
@@ -193,18 +199,38 @@ OUString SmOoxmlImport::handleE()
 OUString SmOoxmlImport::handleF()
 {
     stream.ensureOpeningTag( M_TOKEN( f ));
-    if( stream.currentToken() == OPENING_TAG( M_TOKEN( fPr )))
+    enum operation_t { bar, lin, noBar } operation = bar;
+    OUString oper = STR( "over" );
+    if( stream.checkOpeningTag( M_TOKEN( fPr )))
     {
-        // TODO
+        if( XmlStream::Tag type = stream.checkOpeningTag( M_TOKEN( type )))
+        {
+            if( type.attributes.attribute( M_TOKEN( val )) == STR( "bar" ))
+                operation = bar;
+            else if( type.attributes.attribute( M_TOKEN( val )) == STR( "lin" ))
+                operation = lin;
+            else if( type.attributes.attribute( M_TOKEN( val )) == STR( "noBar" ))
+                operation = noBar;
+            stream.ensureClosingTag( M_TOKEN( type ));
+        }
+        stream.ensureClosingTag( M_TOKEN( fPr ));
     }
     stream.ensureOpeningTag( M_TOKEN( num ));
-    OUString num = handleR();
+    OUString num = readOMathArg( M_TOKEN( num ));
     stream.ensureClosingTag( M_TOKEN( num ));
     stream.ensureOpeningTag( M_TOKEN( den ));
-    OUString den = handleR();
+    OUString den = readOMathArg( M_TOKEN( den ));
     stream.ensureClosingTag( M_TOKEN( den ));
     stream.ensureClosingTag( M_TOKEN( f ));
-    return STR( "{" ) + num + STR( "} over {" ) + den + STR( "}" );
+    if( operation == bar )
+        return STR( "{" ) + num + STR( "} over {" ) + den + STR( "}" );
+    else if( operation == lin )
+        return STR( "{" ) + num + STR( "} / {" ) + den + STR( "}" );
+    else // noBar
+    { // TODO we write out stack of 3 items as recursive m:f, so merge here back
+      // to 'stack { x # y # z }'
+        return STR( "binom { " ) + num + STR( " } { " ) + den + STR( " }" );
+    }
 }
 
 // NOT complete
diff --git a/starmath/source/ooxmlimport.hxx b/starmath/source/ooxmlimport.hxx
index 5cf3bf5..42fbd05 100644
--- a/starmath/source/ooxmlimport.hxx
+++ b/starmath/source/ooxmlimport.hxx
@@ -48,6 +48,7 @@ private:
     rtl::OUString handleE();
     rtl::OUString handleF();
     rtl::OUString handleR();
+    rtl::OUString readOMathArg( int endtoken );
     oox::formulaimport::XmlStream& stream;
 };
 
commit a685e8fb72614eaa678a7fc244f3e6cf85c80c0f
Author: Luboš Luňák <l.lunak at suse.cz>
Date:   Thu Nov 24 16:20:56 2011 +0100

    remove debug output

diff --git a/writerfilter/source/dmapper/DomainMapper.cxx b/writerfilter/source/dmapper/DomainMapper.cxx
index 59d0515..91a1aca 100644
--- a/writerfilter/source/dmapper/DomainMapper.cxx
+++ b/writerfilter/source/dmapper/DomainMapper.cxx
@@ -1196,7 +1196,6 @@ void DomainMapper::lcl_attribute(Id nName, Value & val)
         case NS_rtf::LN_blip: // contains the binary graphic
         case NS_ooxml::LN_shape:
         {
-            fprintf(stderr,"SHAPE3\n");
             //looks a bit like a hack - and it is. The graphic import is split into the inline_inline part and
             //afterwards the adding of the binary data.
             m_pImpl->GetGraphicImport( IMPORT_AS_DETECTED_INLINE )->attribute(nName, val);
@@ -1204,11 +1203,8 @@ void DomainMapper::lcl_attribute(Id nName, Value & val)
         }
         break;
         case NS_ooxml::LN_starmath:
-        {
-            fprintf(stderr,"STARMATH3\n");
             m_pImpl->appendStarMath( val );
-        break;
-        }
+            break;
         case NS_ooxml::LN_CT_FramePr_dropCap:
         case NS_ooxml::LN_CT_FramePr_lines:
         case NS_ooxml::LN_CT_FramePr_hAnchor:
diff --git a/writerfilter/source/dmapper/GraphicImport.cxx b/writerfilter/source/dmapper/GraphicImport.cxx
index 4e9446b..744361d 100644
--- a/writerfilter/source/dmapper/GraphicImport.cxx
+++ b/writerfilter/source/dmapper/GraphicImport.cxx
@@ -874,7 +874,6 @@ void GraphicImport::lcl_attribute(Id nName, Value & val)
             break;
         case NS_ooxml::LN_shape:
             {
-            fprintf(stderr,"SHAPE2\n");
                 uno::Reference< drawing::XShape> xShape;
                 val.getAny( ) >>= xShape;
 
@@ -951,9 +950,6 @@ void GraphicImport::lcl_attribute(Id nName, Value & val)
                 }
             }
         break;
-        case NS_ooxml::LN_starmath:
-            fprintf(stderr,"STARMATH2\n");
-        break;
         case NS_ooxml::LN_CT_Inline_distT:
         case NS_ooxml::LN_CT_Inline_distB:
         case NS_ooxml::LN_CT_Inline_distL:
diff --git a/writerfilter/source/dmapper/OLEHandler.cxx b/writerfilter/source/dmapper/OLEHandler.cxx
index 6e9cbbd..907e4a7 100644
--- a/writerfilter/source/dmapper/OLEHandler.cxx
+++ b/writerfilter/source/dmapper/OLEHandler.cxx
@@ -102,7 +102,6 @@ void OLEHandler::lcl_attribute(Id rName, Value & rVal)
         break;
         case NS_ooxml::LN_shape:
         {
-            fprintf(stderr,"SHAPE1\n");
             uno::Reference< drawing::XShape > xTempShape;
             rVal.getAny() >>= xTempShape;
             if( xTempShape.is() )
@@ -135,9 +134,6 @@ void OLEHandler::lcl_attribute(Id rName, Value & rVal)
             }
         }
         break;
-        case NS_ooxml::LN_starmath:
-            fprintf(stderr,"STARMATH1\n");
-        break;
         default:
             OSL_FAIL( "unknown attribute");
     }
diff --git a/writerfilter/source/ooxml/OOXMLFastContextHandler.cxx b/writerfilter/source/ooxml/OOXMLFastContextHandler.cxx
index 20170ba..31aa02c 100644
--- a/writerfilter/source/ooxml/OOXMLFastContextHandler.cxx
+++ b/writerfilter/source/ooxml/OOXMLFastContextHandler.cxx
@@ -1905,7 +1905,6 @@ OOXMLFastContextHandlerShape::OOXMLFastContextHandlerShape
                    (RTL_CONSTASCII_USTRINGPARAM
                     ("com.sun.star.xml.sax.FastShapeContextHandler")), xContext),
                   uno::UNO_QUERY);
-            fprintf(stderr," XXX %s\n", typeid(*mrShapeContext.get()).name());
             getDocument()->setShapeContext( mrShapeContext );
         }
 
commit f453f11129605146ba30368ceb644f128c32bf6e
Author: Luboš Luňák <l.lunak at suse.cz>
Date:   Thu Nov 24 16:13:09 2011 +0100

    remove executable bit on a source file

diff --git a/oox/inc/oox/helper/textinputstream.hxx b/oox/inc/oox/helper/textinputstream.hxx
old mode 100755
new mode 100644
commit 26032e5874587966a23984ade459be323440e683
Author: Luboš Luňák <l.lunak at suse.cz>
Date:   Thu Nov 24 16:10:30 2011 +0100

    at least partial implementation of reading mathml docx m:e

diff --git a/starmath/source/ooxmlimport.cxx b/starmath/source/ooxmlimport.cxx
index 0880ac3..c0a52de 100644
--- a/starmath/source/ooxmlimport.cxx
+++ b/starmath/source/ooxmlimport.cxx
@@ -162,7 +162,31 @@ OUString SmOoxmlImport::handleAcc()
 
 OUString SmOoxmlImport::handleE()
 {
-// TODO
+    OUString ret;
+    stream.ensureOpeningTag( M_TOKEN( e ));
+    while( !stream.atEnd())
+    { // TODO can there really be more or just one sub-elements?
+        XmlStream::Tag tag = stream.currentTag();
+        if( tag.token == CLOSING( M_TOKEN( e )))
+            break;
+        switch( tag.token )
+        {
+            case OPENING( M_TOKEN( acc )):
+                ret += STR( " " ) + handleAcc();
+                break;
+            case OPENING( M_TOKEN( f )):
+                ret += STR( " " ) + handleF();
+                break;
+            case OPENING( M_TOKEN( r )):
+                ret += STR( " " ) + handleR();
+                break;
+            default:
+                stream.handleUnexpectedTag();
+                break;
+        }
+    }
+    stream.ensureClosingTag( M_TOKEN( e ));
+    return ret;
 }
 
 // NOT complete
@@ -174,17 +198,17 @@ OUString SmOoxmlImport::handleF()
         // TODO
     }
     stream.ensureOpeningTag( M_TOKEN( num ));
-    OUString num = readR();
+    OUString num = handleR();
     stream.ensureClosingTag( M_TOKEN( num ));
     stream.ensureOpeningTag( M_TOKEN( den ));
-    OUString den = readR();
+    OUString den = handleR();
     stream.ensureClosingTag( M_TOKEN( den ));
     stream.ensureClosingTag( M_TOKEN( f ));
     return STR( "{" ) + num + STR( "} over {" ) + den + STR( "}" );
 }
 
 // NOT complete
-OUString SmOoxmlImport::readR()
+OUString SmOoxmlImport::handleR()
 {
     stream.ensureOpeningTag( M_TOKEN( r ));
     if( XmlStream::Tag rPr = stream.checkOpeningTag( OOX_TOKEN( doc, rPr )))
diff --git a/starmath/source/ooxmlimport.hxx b/starmath/source/ooxmlimport.hxx
index c378775..5cf3bf5 100644
--- a/starmath/source/ooxmlimport.hxx
+++ b/starmath/source/ooxmlimport.hxx
@@ -47,7 +47,7 @@ private:
     rtl::OUString handleAcc();
     rtl::OUString handleE();
     rtl::OUString handleF();
-    rtl::OUString readR();
+    rtl::OUString handleR();
     oox::formulaimport::XmlStream& stream;
 };
 
commit 3236f5bea9b995922a59b43818f8f92cccde9956
Author: Luboš Luňák <l.lunak at suse.cz>
Date:   Thu Nov 24 16:09:42 2011 +0100

    oox::AttributeList is actually not that usable outside

diff --git a/oox/inc/oox/mathml/importutils.hxx b/oox/inc/oox/mathml/importutils.hxx
index eb7af2b..d5d2540 100644
--- a/oox/inc/oox/mathml/importutils.hxx
+++ b/oox/inc/oox/mathml/importutils.hxx
@@ -29,6 +29,7 @@
 #define _STARMATHIMPORTUTILS_HXX
 
 #include <com/sun/star/xml/sax/XFastAttributeList.hpp>
+#include <map>
 #include <oox/helper/attributelist.hxx>
 #include <vector>
 
@@ -65,6 +66,20 @@ class OOX_DLLPUBLIC XmlStream
 public:
     XmlStream();
     /**
+     Structure representing a list of attributes.
+    */
+    // One could theoretically use oox::AttributeList, but that complains if the passed reference is empty,
+    // which would be complicated to avoid here. Also, parsers apparently reuse the same instance of XFastAttributeList,
+    // which means using oox::AttributeList would make them all point to the one instance.
+    struct AttributeList
+    {
+        bool hasAttribute( int token ) const;
+        rtl::OUString attribute( int token, const rtl::OUString& def = rtl::OUString()) const;
+        bool attribute( int token, bool def ) const;
+    protected:
+        std::map< int, rtl::OUString > attrs;
+    };
+    /**
      Structure representing a tag, including its attributes and content text immediatelly following it.
     */
     struct Tag
@@ -154,13 +169,6 @@ public:
     void appendCharacters( const rtl::OUString& characters );
 };
 
-inline XmlStream::Tag::Tag( int t, const com::sun::star::uno::Reference< com::sun::star::xml::sax::XFastAttributeList >& a, const rtl::OUString& txt )
-: token( t )
-, attributes( a )
-, text( txt )
-{
-}
-
 } // namespace
 } // namespace
 
diff --git a/oox/source/mathml/importutils.cxx b/oox/source/mathml/importutils.cxx
index bec3929..927f6e9 100644
--- a/oox/source/mathml/importutils.cxx
+++ b/oox/source/mathml/importutils.cxx
@@ -40,6 +40,71 @@ namespace oox
 namespace formulaimport
 {
 
+namespace
+{
+// a class that inherits from AttributeList, builds the internal data and then will be sliced off
+// during conversion to the base class
+class AttributeListBuilder
+    : public XmlStream::AttributeList
+{
+public:
+    AttributeListBuilder( const uno::Reference< xml::sax::XFastAttributeList >& a );
+};
+
+AttributeListBuilder::AttributeListBuilder( const uno::Reference< xml::sax::XFastAttributeList >& a )
+{
+    if( a.get() == NULL )
+        return;
+    uno::Sequence< xml::FastAttribute > aFastAttrSeq = a->getFastAttributes();
+    const xml::FastAttribute* pFastAttr = aFastAttrSeq.getConstArray();
+    sal_Int32 nFastAttrLength = aFastAttrSeq.getLength();
+    for( int i = 0;
+         i < nFastAttrLength;
+         ++i )
+    {
+        attrs[ pFastAttr[ i ].Token ] = pFastAttr[ i ].Value;
+    }
+}
+} // namespace
+
+bool XmlStream::AttributeList::hasAttribute( int token ) const
+{
+    return attrs.find( token ) != attrs.end();
+}
+
+rtl::OUString XmlStream::AttributeList::attribute( int token, const rtl::OUString& def ) const
+{
+    std::map< int, rtl::OUString >::const_iterator find = attrs.find( token );
+    if( find != attrs.end())
+        return find->second;
+    return def;
+}
+
+bool XmlStream::AttributeList::attribute( int token, bool def ) const
+{
+    std::map< int, rtl::OUString >::const_iterator find = attrs.find( token );
+    if( find != attrs.end())
+    {
+        if( find->second.equalsIgnoreAsciiCaseAscii( "true" ) || find->second.equalsIgnoreAsciiCaseAscii( "on" )
+            || find->second.equalsIgnoreAsciiCaseAscii( "t" ) || find->second.equalsIgnoreAsciiCaseAscii( "1" ))
+            return true;
+        if( find->second.equalsIgnoreAsciiCaseAscii( "false" ) || find->second.equalsIgnoreAsciiCaseAscii( "off" )
+            || find->second.equalsIgnoreAsciiCaseAscii( "f" ) || find->second.equalsIgnoreAsciiCaseAscii( "0" ))
+            return false;
+        fprintf( stderr, "Cannot convert \'%s\' to bool.\n",
+            rtl::OUStringToOString( find->second, RTL_TEXTENCODING_UTF8 ).getStr());
+    }
+    return def;
+}
+
+XmlStream::Tag::Tag( int t, const uno::Reference< xml::sax::XFastAttributeList >& a, const rtl::OUString& txt )
+: token( t )
+, attributes( AttributeListBuilder( a ))
+, text( txt )
+{
+}
+
+
 XmlStream::XmlStream::Tag::operator bool() const
 {
     return token != XML_TOKEN_INVALID;
diff --git a/starmath/source/ooxmlimport.cxx b/starmath/source/ooxmlimport.cxx
index 746bb6e..0880ac3 100644
--- a/starmath/source/ooxmlimport.cxx
+++ b/starmath/source/ooxmlimport.cxx
@@ -100,7 +100,7 @@ OUString SmOoxmlImport::handleAcc()
     {
         if( XmlStream::Tag chr = stream.checkOpeningTag( M_TOKEN( chr )))
         {
-            acc = chr.attributes.getString( M_TOKEN( val ), STR( "" ));
+            acc = chr.attributes.attribute( M_TOKEN( val ));
             stream.ensureClosingTag( M_TOKEN( chr ));
         }
         stream.ensureClosingTag( M_TOKEN( accPr ));
@@ -197,7 +197,7 @@ OUString SmOoxmlImport::readR()
     XmlStream::Tag rtag = stream.ensureOpeningTag( M_TOKEN( t ));
     // TODO bail out if failure?
     OUString text = rtag.text;
-    if( !rtag.attributes.getBool( OOX_TOKEN( xml, space ), false ))
+    if( rtag.attributes.attribute( OOX_TOKEN( xml, space )) != STR( "preserve" ))
         text = text.trim();
     stream.ensureClosingTag( M_TOKEN( t ));
     stream.ensureClosingTag( M_TOKEN( r ));
commit 199c95b3e9f4fc0f13cb0423b7f64779e4dfad9f
Author: Luboš Luňák <l.lunak at suse.cz>
Date:   Thu Nov 24 16:07:25 2011 +0100

    fix inverted bool argument

diff --git a/oox/source/mathml/importutils.cxx b/oox/source/mathml/importutils.cxx
index ac25b89..bec3929 100644
--- a/oox/source/mathml/importutils.cxx
+++ b/oox/source/mathml/importutils.cxx
@@ -79,17 +79,17 @@ void XmlStream::moveToNextTag()
 
 XmlStream::Tag XmlStream::ensureOpeningTag( int token )
 {
-    return checkTag( OPENING( token ), true, "opening" );
+    return checkTag( OPENING( token ), false, "opening" );
 }
 
 XmlStream::Tag XmlStream::checkOpeningTag( int token )
 {
-    return checkTag( OPENING( token ), false, "opening" );
+    return checkTag( OPENING( token ), true, "opening" );
 }
 
 void XmlStream::ensureClosingTag( int token )
 {
-    checkTag( CLOSING( token ), true, "closing" );
+    checkTag( CLOSING( token ), false, "closing" );
 }
 
 XmlStream::Tag XmlStream::checkTag( int token, bool optional, const char* txt )
commit 944f9e13e3942de7fec0d52c6e6d839e00e77604
Author: Luboš Luňák <l.lunak at suse.cz>
Date:   Thu Nov 24 14:39:13 2011 +0100

    mathml docx import, implement m:acc (without the inner m:e)

diff --git a/starmath/source/ooxmlimport.cxx b/starmath/source/ooxmlimport.cxx
index 6b30142..746bb6e 100644
--- a/starmath/source/ooxmlimport.cxx
+++ b/starmath/source/ooxmlimport.cxx
@@ -77,6 +77,9 @@ OUString SmOoxmlImport::handleStream()
             break;
         switch( tag.token )
         {
+            case OPENING( M_TOKEN( acc )):
+                ret += STR( " " ) + handleAcc();
+                break;
             case OPENING( M_TOKEN( f )):
                 ret += STR( " " ) + handleF();
                 break;
@@ -89,6 +92,79 @@ OUString SmOoxmlImport::handleStream()
     return ret;
 }
 
+OUString SmOoxmlImport::handleAcc()
+{
+    stream.ensureOpeningTag( M_TOKEN( acc ));
+    OUString acc;
+    if( XmlStream::Tag accPr = stream.checkOpeningTag( M_TOKEN( accPr )))
+    {
+        if( XmlStream::Tag chr = stream.checkOpeningTag( M_TOKEN( chr )))
+        {
+            acc = chr.attributes.getString( M_TOKEN( val ), STR( "" ));
+            stream.ensureClosingTag( M_TOKEN( chr ));
+        }
+        stream.ensureClosingTag( M_TOKEN( accPr ));
+    }
+    // see aTokenTable in parse.cxx
+    switch( acc.isEmpty() ? sal_Unicode( MS_ACUTE ) : acc[ 0 ] )
+    {
+        case MS_CHECK:
+            acc = STR( "check" );
+            break;
+        case MS_ACUTE:
+            acc = STR( "acute" );
+            break;
+        case MS_GRAVE:
+            acc = STR( "grave" );
+            break;
+        case MS_BREVE:
+            acc = STR( "breve" );
+            break;
+        case MS_CIRCLE:
+            acc = STR( "circle" );
+            break;
+        case MS_VEC:
+            acc = STR( "vec" );
+            break;
+        case MS_TILDE:
+            acc = STR( "tilde" );
+            break;
+        case MS_HAT:
+            acc = STR( "hat" );
+            break;
+        case MS_DOT:
+            acc = STR( "dot" );
+            break;
+        case MS_DDOT:
+            acc = STR( "ddot" );
+            break;
+        case MS_DDDOT:
+            acc = STR( "dddot" );
+            break;
+// these characters do not exist it seems
+//        case MS_WIDETILDE:
+//            acc = STR( "widetilde" );
+//            break;
+//        case TWIDEHAT:
+//            acc = STR( "widehat" );
+//            break;
+//        case TWIDEVEC:
+//            acc = STR( "widevec" );
+//            break;
+        default:
+            acc = STR( "acute" );
+            break;
+    }
+    OUString e = handleE();
+    stream.ensureClosingTag( M_TOKEN( acc ));
+    return acc + STR( " { " ) + e + STR( " }" );
+}
+
+OUString SmOoxmlImport::handleE()
+{
+// TODO
+}
+
 // NOT complete
 OUString SmOoxmlImport::handleF()
 {
diff --git a/starmath/source/ooxmlimport.hxx b/starmath/source/ooxmlimport.hxx
index 594b8d6..c378775 100644
--- a/starmath/source/ooxmlimport.hxx
+++ b/starmath/source/ooxmlimport.hxx
@@ -44,6 +44,8 @@ public:
     rtl::OUString ConvertToStarMath();
 private:
     rtl::OUString handleStream();
+    rtl::OUString handleAcc();
+    rtl::OUString handleE();
     rtl::OUString handleF();
     rtl::OUString readR();
     oox::formulaimport::XmlStream& stream;
commit 5b94957f7f25c8a607735d038c4f22e8009b99ea
Author: Luboš Luňák <l.lunak at suse.cz>
Date:   Thu Nov 24 13:19:57 2011 +0100

    more api improving in importing mathml docx

diff --git a/oox/inc/oox/mathml/importutils.hxx b/oox/inc/oox/mathml/importutils.hxx
index f7c353d..eb7af2b 100644
--- a/oox/inc/oox/mathml/importutils.hxx
+++ b/oox/inc/oox/mathml/importutils.hxx
@@ -75,6 +75,11 @@ public:
         int token; ///< tag type, or XML_TOKEN_INVALID
         AttributeList attributes;
         rtl::OUString text;
+        /**
+         Converts to true if the tag has a valid token, false otherwise. Allows simple
+         usage in if(), for example 'if( XmlStream::Tag foo = stream.checkOpeningTag( footoken ))'.
+        */
+        operator bool() const;
     };
     /**
      @return true if current position is at the end of the XML stream
@@ -92,7 +97,41 @@ public:
      Moves position to the next tag.
     */
     void moveToNextTag();
+    /**
+     Ensures that an opening tag with the given token is read. If the current tag does not match,
+     writes out a warning and tries to recover by skipping tags until found (or until the current element would end).
+     If found, the position in the stream is afterwards moved to the next tag.
+     @return the matching found opening tag, or empty tag if not found
+    */
+    Tag ensureOpeningTag( int token );
+    /**
+     Tries to find an opening tag with the given token. Works similarly like ensureOpeningTag(),
+     but if a matching tag is not found, the position in the stream is not altered. The primary
+     use of this function is to check for optional elements.
+     @return the matching found opening tag, or empty tag if not found
+    */
+    Tag checkOpeningTag( int token );
+    /**
+     Ensures that a closing tag with the given token is read. Like ensureOpeningTag(),
+     if not, writes out a warning and tries to recover by skiping tags until found (or until the current element would end).
+     If found, the position in the stream is afterwards moved to the next tag.
+    */
+    void ensureClosingTag( int token );
+    /**
+     Tries to find the given token, until either found (returns true) or end of current element.
+     Position in the stream is set to make the tag current.
+    */
+    bool recoverAndFindTag( int token );
+    /**
+     Skips the given element (i.e. reads up to and including the matching closing tag).
+    */
+    void skipElement( int token );
+    /**
+     Handle the current (unexpected) tag.
+    */
+    void handleUnexpectedTag();
 protected:
+    Tag checkTag( int token, bool optional, const char* txt );
     std::vector< Tag > tags;
     unsigned int pos;
 };
diff --git a/oox/source/mathml/importutils.cxx b/oox/source/mathml/importutils.cxx
index 95f81c8..ac25b89 100644
--- a/oox/source/mathml/importutils.cxx
+++ b/oox/source/mathml/importutils.cxx
@@ -40,6 +40,11 @@ namespace oox
 namespace formulaimport
 {
 
+XmlStream::XmlStream::Tag::operator bool() const
+{
+    return token != XML_TOKEN_INVALID;
+}
+
 XmlStream::XmlStream()
 : pos( 0 )
 {
@@ -72,6 +77,108 @@ void XmlStream::moveToNextTag()
         ++pos;
 }
 
+XmlStream::Tag XmlStream::ensureOpeningTag( int token )
+{
+    return checkTag( OPENING( token ), true, "opening" );
+}
+
+XmlStream::Tag XmlStream::checkOpeningTag( int token )
+{
+    return checkTag( OPENING( token ), false, "opening" );
+}
+
+void XmlStream::ensureClosingTag( int token )
+{
+    checkTag( CLOSING( token ), true, "closing" );
+}
+
+XmlStream::Tag XmlStream::checkTag( int token, bool optional, const char* txt )
+{
+    // either it's the following tag, or find it
+    int savedPos = pos;
+    if( currentToken() == token || recoverAndFindTag( token ))
+    {
+        Tag ret = currentTag();
+        moveToNextTag();
+        return ret; // ok
+    }
+    if( optional )
+    { // not a problem, just rewind
+        pos = savedPos;
+        return Tag();
+    }
+    fprintf( stderr, "Expected %s tag %d not found.\n", txt, token );
+    return Tag();
+}
+
+bool XmlStream::recoverAndFindTag( int token )
+{
+    int depth = 0;
+    for(;
+         !atEnd();
+         moveToNextTag())
+    {
+        if( depth > 0 ) // we're inside a nested element, skip those
+        {
+            if( currentToken() == OPENING( currentToken()))
+            {
+                fprintf( stderr, "Skipping opening tag %d\n", currentToken());
+                ++depth;
+            }
+            else if( currentToken() == CLOSING( currentToken()))
+            { // TODO debug output without the OPENING/CLOSING bits set
+                fprintf( stderr, "Skipping closing tag %d\n", currentToken());
+                --depth;
+            }
+            else
+            {
+                fprintf( stderr, "Malformed token %d\n", currentToken());
+                abort();
+            }
+            continue;
+        }
+        if( currentToken() == token )
+            return true; // ok, found
+        if( currentToken() == CLOSING( currentToken()))
+            return false; // that would be leaving current element, so not found
+        if( currentToken() == OPENING( currentToken()))
+        {
+            fprintf( stderr, "Skipping opening tag %d\n", currentToken());
+            ++depth;
+        }
+        else
+            abort();
+    }
+    fprintf( stderr, "Unexpected end of stream reached.\n" );
+    return false;
+}
+
+void XmlStream::skipElement( int token )
+{
+    int closing = ( token & ~TAG_OPENING ) | TAG_CLOSING; // make it a closing tag
+    assert( currentToken() == OPENING( token ));
+    // just find the matching closing tag
+    if( recoverAndFindTag( closing ))
+    {
+        moveToNextTag(); // and skip it too
+        return;
+    }
+    fprintf( stderr, "Expected end of element %d not found.\n", token );
+}
+
+void XmlStream::handleUnexpectedTag()
+{
+    if( atEnd())
+        return;
+    if( currentToken() == CLOSING( currentToken()))
+    {
+        moveToNextTag(); // just skip it
+        return;
+    }
+    skipElement( currentToken()); // otherwise skip the entire element
+}
+
+
 void XmlStreamBuilder::appendOpeningTag( int token, const uno::Reference< xml::sax::XFastAttributeList >& attrs )
 {
     tags.push_back( Tag( OPENING( token ), attrs ));
diff --git a/starmath/source/ooxmlimport.cxx b/starmath/source/ooxmlimport.cxx
index 16f887c..6b30142 100644
--- a/starmath/source/ooxmlimport.cxx
+++ b/starmath/source/ooxmlimport.cxx
@@ -68,7 +68,7 @@ OUString SmOoxmlImport::ConvertToStarMath()
 // NOT complete
 OUString SmOoxmlImport::handleStream()
 {
-    checkOpeningTag( M_TOKEN( oMath ));
+    stream.ensureOpeningTag( M_TOKEN( oMath ));
     OUString ret;
     while( !stream.atEnd())
     {
@@ -81,140 +81,51 @@ OUString SmOoxmlImport::handleStream()
                 ret += STR( " " ) + handleF();
                 break;
             default:
-                handleUnexpectedTag();
+                stream.handleUnexpectedTag();
                 break;
         }
     }
-    checkClosingTag( M_TOKEN( oMath ));
+    stream.ensureClosingTag( M_TOKEN( oMath ));
     return ret;
 }
 
 // NOT complete
 OUString SmOoxmlImport::handleF()
 {
-    checkOpeningTag( M_TOKEN( f ));
+    stream.ensureOpeningTag( M_TOKEN( f ));
     if( stream.currentToken() == OPENING_TAG( M_TOKEN( fPr )))
     {
         // TODO
     }
-    checkOpeningTag( M_TOKEN( num ));
+    stream.ensureOpeningTag( M_TOKEN( num ));
     OUString num = readR();
-    checkClosingTag( M_TOKEN( num ));
-    checkOpeningTag( M_TOKEN( den ));
+    stream.ensureClosingTag( M_TOKEN( num ));
+    stream.ensureOpeningTag( M_TOKEN( den ));
     OUString den = readR();
-    checkClosingTag( M_TOKEN( den ));
-    checkClosingTag( M_TOKEN( f ));
+    stream.ensureClosingTag( M_TOKEN( den ));
+    stream.ensureClosingTag( M_TOKEN( f ));
     return STR( "{" ) + num + STR( "} over {" ) + den + STR( "}" );
 }
 
 // NOT complete
 OUString SmOoxmlImport::readR()
 {
-    checkOpeningTag( M_TOKEN( r ));
-
-//    checkOpeningTag( OOX_TOKEN( doc, rPr ));
-//    checkOpeningTag( OOX_TOKEN( doc, rFonts ));
-//    checkClosingTag( OOX_TOKEN( doc, rFonts ));
-//    checkClosingTag( OOX_TOKEN( doc, rPr ));
-
+    stream.ensureOpeningTag( M_TOKEN( r ));
+    if( XmlStream::Tag rPr = stream.checkOpeningTag( OOX_TOKEN( doc, rPr )))
+    { // TODO
+//        stream.checkOpeningTag( OOX_TOKEN( doc, rFonts ));
+//        stream.ensureClosingTag( OOX_TOKEN( doc, rFonts ));
+        stream.ensureClosingTag( OOX_TOKEN( doc, rPr ));
+    }
     // TODO can there be more t's ?
-    XmlStream::Tag rtag = checkOpeningTag( M_TOKEN( t ));
+    XmlStream::Tag rtag = stream.ensureOpeningTag( M_TOKEN( t ));
+    // TODO bail out if failure?
     OUString text = rtag.text;
     if( !rtag.attributes.getBool( OOX_TOKEN( xml, space ), false ))
         text = text.trim();
-    checkClosingTag( M_TOKEN( t ));
-    checkClosingTag( M_TOKEN( r ));
+    stream.ensureClosingTag( M_TOKEN( t ));
+    stream.ensureClosingTag( M_TOKEN( r ));
     return text;
 }
 
-XmlStream::Tag SmOoxmlImport::checkOpeningTag( int token )
-{
-    return checkTag( OPENING( token ), "opening" );
-}
-
-void SmOoxmlImport::checkClosingTag( int token )
-{
-    checkTag( CLOSING( token ), "closing" );
-}
-
-XmlStream::Tag SmOoxmlImport::checkTag( int token, const char* txt )
-{
-    // either it's the following tag, or find it
-    if( stream.currentToken() == token || recoverAndFindTag( token ))
-    {
-        XmlStream::Tag ret = stream.currentTag();
-        stream.moveToNextTag();
-        return ret; // ok
-    }
-    fprintf( stderr, "Expected %s tag %d not found.\n", txt, token );
-    return XmlStream::Tag();
-}
-
-bool SmOoxmlImport::recoverAndFindTag( int token )
-{
-    int depth = 0;
-    for(;
-         !stream.atEnd();
-         stream.moveToNextTag())
-    {
-        if( depth > 0 ) // we're inside a nested element, skip those
-        {
-            if( stream.currentToken() == OPENING( stream.currentToken()))
-            {
-                fprintf( stderr, "Skipping opening tag %d\n", stream.currentToken());
-                ++depth;
-            }
-            else if( stream.currentToken() == CLOSING( stream.currentToken()))
-            { // TODO debug output without the OPENING/CLOSING bits set
-                fprintf( stderr, "Skipping closing tag %d\n", stream.currentToken());
-                --depth;
-            }
-            else
-            {
-                fprintf( stderr, "Malformed token %d\n", stream.currentToken());
-                abort();
-            }
-            continue;
-        }
-        if( stream.currentToken() == CLOSING( stream.currentToken()))
-            return false; // that would be leaving current element, so not found
-        if( stream.currentToken() == token )
-            return true; // ok, found
-        if( stream.currentToken() == OPENING( stream.currentToken()))
-        {
-            fprintf( stderr, "Skipping opening tag %d\n", stream.currentToken());
-            ++depth;
-        }
-        else
-            abort();
-    }
-    fprintf( stderr, "Unexpected end of stream reached.\n" );
-    return false;
-}
-
-void SmOoxmlImport::skipElement( int token )
-{
-    int closing = ( token & ~TAG_OPENING ) | TAG_CLOSING; // make it a closing tag
-    assert( stream.currentToken() == OPENING( token ));
-    // just find the matching closing tag
-    if( recoverAndFindTag( closing ))
-    {
-        stream.moveToNextTag(); // and skip it too
-        return;
-    }
-    fprintf( stderr, "Expected end of element %d not found.\n", token );
-}
-
-void SmOoxmlImport::handleUnexpectedTag()
-{
-    if( stream.atEnd())
-        return;
-    if( stream.currentToken() == CLOSING( stream.currentToken()))
-    {
-        stream.moveToNextTag(); // just skip it
-        return;
-    }
-    skipElement( stream.currentToken()); // otherwise skip the entire element
-}
-
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/starmath/source/ooxmlimport.hxx b/starmath/source/ooxmlimport.hxx
index 043b44a..594b8d6 100644
--- a/starmath/source/ooxmlimport.hxx
+++ b/starmath/source/ooxmlimport.hxx
@@ -46,34 +46,6 @@ private:
     rtl::OUString handleStream();
     rtl::OUString handleF();
     rtl::OUString readR();
-    /**
-     Checks that the current tag is the given opening token, if not, writes out a warning
-     and tries to recover (skips tags until found or until the current element would end).
-     In both cases the position is moved to the next tag.
-     @return the matching found opening tag, or empty tag
-    */
-    oox::formulaimport::XmlStream::Tag checkOpeningTag( int token );
-    /**
-     Checks that the current tag is the given opening token, if not, writes out a warning
-     and tries to recover (skips tags until found or until the current element would end).
-     In both cases the position is moved to the next tag.
-    */
-    void checkClosingTag( int token );
-    // helper for the two above
-    oox::formulaimport::XmlStream::Tag checkTag( int token, const char* txt );
-    /**
-     Tries to find the given token, until either found (returns true) or end of current element.
-     Position in the stream is set to make the tag current.
-    */
-    bool recoverAndFindTag( int token );
-    /**
-     Skips the given element (i.e. reads up to and including the matching closing tag).
-    */
-    void skipElement( int token );
-    /**
-     Handle the current (unexpected) tag.
-    */
-    void handleUnexpectedTag();
     oox::formulaimport::XmlStream& stream;
 };
 
commit 4d5ca442d89ee36e7b1abb622e9f3d85b36e0d0c
Author: Luboš Luňák <l.lunak at suse.cz>
Date:   Mon Nov 21 17:32:09 2011 +0100

    streamline and document the API for mathml xml stream reading

diff --git a/oox/inc/oox/mathml/importutils.hxx b/oox/inc/oox/mathml/importutils.hxx
index 01baf98..f7c353d 100644
--- a/oox/inc/oox/mathml/importutils.hxx
+++ b/oox/inc/oox/mathml/importutils.hxx
@@ -50,24 +50,60 @@ const int TAG_CLOSING = 1 << 30;
 #define OPENING( token ) ( TAG_OPENING | token )
 #define CLOSING( token ) ( TAG_CLOSING | token )
 
+/**
+ Class for storing a stream of xml tokens.
+
+ A part of an XML file can be parsed and stored in this stream, from which it can be read
+ as if parsed linearly. The purpose of this class is to allow simpler handling of XML
+ files, unlike the usual LO way of using callbacks, context handlers and similar needlesly
+ complicated stuff (YMMV).
+
+ @since 3.5.0
+*/
 class OOX_DLLPUBLIC XmlStream
 {
 public:
     XmlStream();
-    bool nextIsEnd() const;
-    int peekNextToken() const;
-    int getNextToken();
-    oox::AttributeList getAttributes();
-    rtl::OUString getCharacters();
+    /**
+     Structure representing a tag, including its attributes and content text immediatelly following it.
+    */
+    struct Tag
+    {
+        Tag( int token = XML_TOKEN_INVALID,
+            const com::sun::star::uno::Reference< com::sun::star::xml::sax::XFastAttributeList >& attributes = com::sun::star::uno::Reference< com::sun::star::xml::sax::XFastAttributeList >(),
+            const rtl::OUString& text = rtl::OUString());
+        int token; ///< tag type, or XML_TOKEN_INVALID
+        AttributeList attributes;
+        rtl::OUString text;
+    };
+    /**
+     @return true if current position is at the end of the XML stream
+    */
+    bool atEnd() const;
+    /**
+     @return data about the current tag
+    */
+    Tag currentTag() const;
+    /**
+     @return the token for the current tag
+    */
+    int currentToken() const;
+    /**
+     Moves position to the next tag.
+    */
+    void moveToNextTag();
 protected:
-    // TODO one list containing all 3?
-    std::vector< int > tokens;
-    std::vector< oox::AttributeList > attributes;
-    std::vector< rtl::OUString > characters;
-    int pos;
+    std::vector< Tag > tags;
+    unsigned int pos;
 };
 
-// use this to create the data and then cast to the base class for reading
+/**
+ This class is used for creating XmlStream.
+
+ Simply use this class and then pass it as XmlStream to the consumer.
+
+ @since 3.5.0
+*/
 class OOX_DLLPUBLIC XmlStreamBuilder
 : public XmlStream
 {
@@ -79,6 +115,13 @@ public:
     void appendCharacters( const rtl::OUString& characters );
 };
 
+inline XmlStream::Tag::Tag( int t, const com::sun::star::uno::Reference< com::sun::star::xml::sax::XFastAttributeList >& a, const rtl::OUString& txt )
+: token( t )
+, attributes( a )
+, text( txt )
+{
+}
+
 } // namespace
 } // namespace
 
diff --git a/oox/source/mathml/importutils.cxx b/oox/source/mathml/importutils.cxx
index 1381724..95f81c8 100644
--- a/oox/source/mathml/importutils.cxx
+++ b/oox/source/mathml/importutils.cxx
@@ -41,62 +41,51 @@ namespace formulaimport
 {
 
 XmlStream::XmlStream()
-: pos( -1 )
+: pos( 0 )
 {
     // make sure our extra bit does not conflict with values used by oox
     assert( TAG_OPENING > ( 1024 << NMSP_SHIFT ));
 }
 
-bool XmlStream::nextIsEnd() const
+bool XmlStream::atEnd() const
 {
-    return pos + 1 >= int( tokens.size());
+    return pos >= tags.size();
 }
 
-int XmlStream::getNextToken()
+XmlStream::Tag XmlStream::currentTag() const
 {
-    ++pos;
-    if( pos < int( tokens.size()))
-        return tokens[ pos ];
-    return XML_TOKEN_INVALID;
+    if( pos >= tags.size())
+        return Tag();
+    return tags[ pos ];
 }
 
-int XmlStream::peekNextToken() const
+int XmlStream::currentToken() const
 {
-    if( pos - 1 < int( tokens.size()))
-        return tokens[ pos + 1 ];
-    return XML_TOKEN_INVALID;
+    if( pos >= tags.size())
+        return XML_TOKEN_INVALID;
+    return tags[ pos ].token;
 }
 
-AttributeList XmlStream::getAttributes()
+void XmlStream::moveToNextTag()
 {
-    assert( pos < int( attributes.size()));
-    return attributes[ pos ];
-}
-
-rtl::OUString XmlStream::getCharacters()
-{
-    assert( pos < int( characters.size()));
-    return characters[ pos ];
+    if( pos < tags.size())
+        ++pos;
 }
 
 void XmlStreamBuilder::appendOpeningTag( int token, const uno::Reference< xml::sax::XFastAttributeList >& attrs )
 {
-    tokens.push_back( OPENING( token ));
-    attributes.push_back( AttributeList( attrs ));
-    characters.push_back( rtl::OUString());
+    tags.push_back( Tag( OPENING( token ), attrs ));
 }
 
 void XmlStreamBuilder::appendClosingTag( int token )
 {
-    tokens.push_back( CLOSING( token ));
-    attributes.push_back( AttributeList( uno::Reference< xml::sax::XFastAttributeList >()));
-    characters.push_back( rtl::OUString());
+    tags.push_back( Tag( CLOSING( token )));
 }
 
 void XmlStreamBuilder::appendCharacters( const rtl::OUString& chars )
 {
-    assert( !characters.empty());
-    characters.back() = chars;
+    assert( !tags.empty());
+    tags.back().text = chars;
 }
 
 } // namespace
diff --git a/starmath/source/ooxmlimport.cxx b/starmath/source/ooxmlimport.cxx
index dc53cc7..16f887c 100644
--- a/starmath/source/ooxmlimport.cxx
+++ b/starmath/source/ooxmlimport.cxx
@@ -70,17 +70,16 @@ OUString SmOoxmlImport::handleStream()
 {
     checkOpeningTag( M_TOKEN( oMath ));
     OUString ret;
-    bool out = false;
-    while( !out && !stream.nextIsEnd())
+    while( !stream.atEnd())
     {
-        switch( stream.peekNextToken())
+        XmlStream::Tag tag = stream.currentTag();
+        if( tag.token == CLOSING( M_TOKEN( oMath )))
+            break;
+        switch( tag.token )
         {
             case OPENING( M_TOKEN( f )):
                 ret += STR( " " ) + handleF();
                 break;
-            case CLOSING( M_TOKEN( oMath )):
-                out = true;
-                break;
             default:
                 handleUnexpectedTag();
                 break;
@@ -94,7 +93,7 @@ OUString SmOoxmlImport::handleStream()
 OUString SmOoxmlImport::handleF()
 {
     checkOpeningTag( M_TOKEN( f ));
-    if( stream.peekNextToken() == OPENING_TAG( M_TOKEN( fPr )))
+    if( stream.currentToken() == OPENING_TAG( M_TOKEN( fPr )))
     {
         // TODO
     }
@@ -119,18 +118,18 @@ OUString SmOoxmlImport::readR()
 //    checkClosingTag( OOX_TOKEN( doc, rPr ));
 
     // TODO can there be more t's ?
-    checkOpeningTag( M_TOKEN( t ));
-    OUString text = stream.getCharacters();
-    if( !stream.getAttributes().getBool( OOX_TOKEN( xml, space ), false ))
+    XmlStream::Tag rtag = checkOpeningTag( M_TOKEN( t ));
+    OUString text = rtag.text;
+    if( !rtag.attributes.getBool( OOX_TOKEN( xml, space ), false ))
         text = text.trim();
     checkClosingTag( M_TOKEN( t ));
     checkClosingTag( M_TOKEN( r ));
     return text;
 }
 
-void SmOoxmlImport::checkOpeningTag( int token )
+XmlStream::Tag SmOoxmlImport::checkOpeningTag( int token )
 {
-    checkTag( OPENING( token ), "opening" );
+    return checkTag( OPENING( token ), "opening" );
 }
 
 void SmOoxmlImport::checkClosingTag( int token )
@@ -138,80 +137,69 @@ void SmOoxmlImport::checkClosingTag( int token )
     checkTag( CLOSING( token ), "closing" );
 }
 
-void SmOoxmlImport::checkTag( int token, const char* txt )
+XmlStream::Tag SmOoxmlImport::checkTag( int token, const char* txt )
 {
-    if( stream.peekNextToken() == token )
-    {
-        stream.getNextToken(); // read it
-        return; // ok
-    }
-    if( recoverAndFindTag( token ))
+    // either it's the following tag, or find it
+    if( stream.currentToken() == token || recoverAndFindTag( token ))
     {
-        stream.getNextToken(); // read it
-        return; // ok, skipped some tokens
+        XmlStream::Tag ret = stream.currentTag();
+        stream.moveToNextTag();
+        return ret; // ok
     }
     fprintf( stderr, "Expected %s tag %d not found.\n", txt, token );
+    return XmlStream::Tag();
 }
 
 bool SmOoxmlImport::recoverAndFindTag( int token )
 {
     int depth = 0;
-    for(;;)
+    for(;
+         !stream.atEnd();
+         stream.moveToNextTag())
     {
         if( depth > 0 ) // we're inside a nested element, skip those
         {
-            int next = stream.getNextToken();
-            if( next == OPENING( next ))
+            if( stream.currentToken() == OPENING( stream.currentToken()))
             {
-                fprintf( stderr, "Skipping opening tag %d\n", next );
+                fprintf( stderr, "Skipping opening tag %d\n", stream.currentToken());
                 ++depth;
             }
-            else if( next == CLOSING( next ))
+            else if( stream.currentToken() == CLOSING( stream.currentToken()))
             { // TODO debug output without the OPENING/CLOSING bits set
-                fprintf( stderr, "Skipping closing tag %d\n", next );
+                fprintf( stderr, "Skipping closing tag %d\n", stream.currentToken());
                 --depth;
             }
-            else if( next == XML_TOKEN_INVALID ) // end of stream
-            {
-                fprintf( stderr, "Unexpected end of stream reached.\n" );
-                return false;
-            }
             else
             {
-                fprintf( stderr, "Malformed token %d\n", next );
+                fprintf( stderr, "Malformed token %d\n", stream.currentToken());
                 abort();
             }
             continue;
         }
-        int next = stream.peekNextToken();
-        if( next == CLOSING( next ))
+        if( stream.currentToken() == CLOSING( stream.currentToken()))
             return false; // that would be leaving current element, so not found
-        if( next == token )
+        if( stream.currentToken() == token )
             return true; // ok, found
-        if( next == OPENING( next ))
+        if( stream.currentToken() == OPENING( stream.currentToken()))
         {
-            fprintf( stderr, "Skipping opening tag %d\n", next );
-            stream.getNextToken();
+            fprintf( stderr, "Skipping opening tag %d\n", stream.currentToken());
             ++depth;
         }
-        else if( next == XML_TOKEN_INVALID )
-        {
-            fprintf( stderr, "Unexpected end of stream reached.\n" );
-            return false;
-        }
         else
             abort();
     }
+    fprintf( stderr, "Unexpected end of stream reached.\n" );
+    return false;
 }
 
 void SmOoxmlImport::skipElement( int token )
 {
     int closing = ( token & ~TAG_OPENING ) | TAG_CLOSING; // make it a closing tag
-    assert( stream.peekNextToken() == OPENING( token ));
+    assert( stream.currentToken() == OPENING( token ));
     // just find the matching closing tag
     if( recoverAndFindTag( closing ))
     {
-        stream.getNextToken(); // read it
+        stream.moveToNextTag(); // and skip it too
         return;
     }
     fprintf( stderr, "Expected end of element %d not found.\n", token );
@@ -219,15 +207,14 @@ void SmOoxmlImport::skipElement( int token )
 
 void SmOoxmlImport::handleUnexpectedTag()
 {
-    int next = stream.peekNextToken();
-    if( next == XML_TOKEN_INVALID )
-        return; // end of stream
-    if( next == CLOSING( next ))
+    if( stream.atEnd())
+        return;
+    if( stream.currentToken() == CLOSING( stream.currentToken()))
     {
-        stream.getNextToken(); // just skip it
+        stream.moveToNextTag(); // just skip it
         return;
     }
-    skipElement( stream.peekNextToken());
+    skipElement( stream.currentToken()); // otherwise skip the entire element
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/starmath/source/ooxmlimport.hxx b/starmath/source/ooxmlimport.hxx
index 1eebc81..043b44a 100644
--- a/starmath/source/ooxmlimport.hxx
+++ b/starmath/source/ooxmlimport.hxx
@@ -47,19 +47,23 @@ private:
     rtl::OUString handleF();
     rtl::OUString readR();
     /**
-     Checks that the next token is the given opening tag, if not, writes out a warning
+     Checks that the current tag is the given opening token, if not, writes out a warning
      and tries to recover (skips tags until found or until the current element would end).
+     In both cases the position is moved to the next tag.
+     @return the matching found opening tag, or empty tag
     */
-    void checkOpeningTag( int token );
+    oox::formulaimport::XmlStream::Tag checkOpeningTag( int token );
     /**
-     Checks that the next token is the given opening tag, if not, writes out a warning
+     Checks that the current tag is the given opening token, if not, writes out a warning
      and tries to recover (skips tags until found or until the current element would end).
+     In both cases the position is moved to the next tag.
     */
     void checkClosingTag( int token );
     // helper for the two above
-    void checkTag( int token, const char* txt );
+    oox::formulaimport::XmlStream::Tag checkTag( int token, const char* txt );
     /**
      Tries to find the given token, until either found (returns true) or end of current element.
+     Position in the stream is set to make the tag current.
     */
     bool recoverAndFindTag( int token );
     /**
commit f8f1ccbaf942adf9a6b16b13a9cddb1b96a6774b
Author: Luboš Luňák <l.lunak at suse.cz>
Date:   Fri Nov 18 21:06:54 2011 +0100

    rename and move mathml oox support classes in oox to better places

diff --git a/oox/Library_oox.mk b/oox/Library_oox.mk
index 52d7dda..7f26c8a 100644
--- a/oox/Library_oox.mk
+++ b/oox/Library_oox.mk
@@ -203,7 +203,6 @@ $(eval $(call gb_Library_add_exception_objects,oox,\
     oox/source/export/ColorPropertySet \
     oox/source/export/drawingml \
     oox/source/export/SchXMLSeriesHelper \
-    oox/source/export/ooxmlexport \
     oox/source/export/shapes \
     oox/source/export/vmlexport \
     oox/source/helper/attributelist \
@@ -219,6 +218,9 @@ $(eval $(call gb_Library_add_exception_objects,oox,\
     oox/source/helper/storagebase \
     oox/source/helper/textinputstream \
     oox/source/helper/zipstorage \
+    oox/source/mathml/export \
+    oox/source/mathml/import \
+    oox/source/mathml/importutils \
     oox/source/ole/axbinaryreader \
     oox/source/ole/axbinarywriter \
     oox/source/ole/axfontdata \
diff --git a/oox/Package_inc.mk b/oox/Package_inc.mk
index 396c24c..ac2ad7d 100644
--- a/oox/Package_inc.mk
+++ b/oox/Package_inc.mk
@@ -41,8 +41,6 @@ $(eval $(call gb_Package_add_file,oox_inc,inc/oox/export/drawingml.hxx,oox/expor
 $(eval $(call gb_Package_add_file,oox_inc,inc/oox/export/shapes.hxx,oox/export/shapes.hxx))
 $(eval $(call gb_Package_add_file,oox_inc,inc/oox/export/utils.hxx,oox/export/utils.hxx))
 $(eval $(call gb_Package_add_file,oox_inc,inc/oox/export/vmlexport.hxx,oox/export/vmlexport.hxx))
-$(eval $(call gb_Package_add_file,oox_inc,inc/oox/export/ooxmlexport.hxx,oox/export/ooxmlexport.hxx))
-$(eval $(call gb_Package_add_file,oox_inc,inc/oox/export/starmathimport.hxx,oox/export/starmathimport.hxx))
 $(eval $(call gb_Package_add_file,oox_inc,inc/oox/helper/binarystreambase.hxx,oox/helper/binarystreambase.hxx))
 $(eval $(call gb_Package_add_file,oox_inc,inc/oox/helper/containerhelper.hxx,oox/helper/containerhelper.hxx))
 $(eval $(call gb_Package_add_file,oox_inc,inc/oox/helper/graphichelper.hxx,oox/helper/graphichelper.hxx))
@@ -51,6 +49,9 @@ $(eval $(call gb_Package_add_file,oox_inc,inc/oox/helper/refmap.hxx,oox/helper/r
 $(eval $(call gb_Package_add_file,oox_inc,inc/oox/helper/refvector.hxx,oox/helper/refvector.hxx))
 $(eval $(call gb_Package_add_file,oox_inc,inc/oox/helper/storagebase.hxx,oox/helper/storagebase.hxx))
 $(eval $(call gb_Package_add_file,oox_inc,inc/oox/helper/zipstorage.hxx,oox/helper/zipstorage.hxx))
+$(eval $(call gb_Package_add_file,oox_inc,inc/oox/mathml/export.hxx,oox/mathml/export.hxx))
+$(eval $(call gb_Package_add_file,oox_inc,inc/oox/mathml/import.hxx,oox/mathml/import.hxx))
+$(eval $(call gb_Package_add_file,oox_inc,inc/oox/mathml/importutils.hxx,oox/mathml/importutils.hxx))
 $(eval $(call gb_Package_add_file,oox_inc,inc/oox/ole/olehelper.hxx,oox/ole/olehelper.hxx))
 $(eval $(call gb_Package_add_file,oox_inc,inc/oox/ole/oleobjecthelper.hxx,oox/ole/oleobjecthelper.hxx))
 $(eval $(call gb_Package_add_file,oox_inc,inc/oox/ole/olestorage.hxx,oox/ole/olestorage.hxx))
diff --git a/oox/inc/oox/export/ooxmlexport.hxx b/oox/inc/oox/export/ooxmlexport.hxx
deleted file mode 100644
index 288dbdc..0000000
--- a/oox/inc/oox/export/ooxmlexport.hxx
+++ /dev/null
@@ -1,48 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/*
- * Version: MPL 1.1 / GPLv3+ / LGPLv3+
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License or as specified alternatively below. You may obtain a copy of
- * the License at http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * Major Contributor(s):
- * Copyright (C) 2011 Lubos Lunak <l.lunak at suse.cz> (initial developer)
- *
- * All Rights Reserved.
- *
- * For minor contributions see the git repository.
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either the GNU General Public License Version 3 or later (the "GPLv3+"), or
- * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
- * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
- * instead of those above.
- */
-#ifndef _OOXMLEXPORT_HXX
-#define _OOXMLEXPORT_HXX
-
-#include <sax/fshelper.hxx>
-#include <oox/core/filterbase.hxx>
-#include <oox/dllapi.h>
-
-/**
- Interface class, StarMath will implement writeFormulaOoxml() to write out OOXML
- representing the formula.
- */
-class OOX_DLLPUBLIC OoxmlFormulaExportBase
-{
-public:
-    OoxmlFormulaExportBase();
-    virtual void writeFormulaOoxml( ::sax_fastparser::FSHelperPtr m_pSerializer, oox::core::OoxmlVersion version ) = 0;
-};
-
-#endif
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/oox/inc/oox/export/starmathimport.hxx b/oox/inc/oox/export/starmathimport.hxx
deleted file mode 100644
index a348ac8..0000000
--- a/oox/inc/oox/export/starmathimport.hxx
+++ /dev/null
@@ -1,99 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/*
- * Version: MPL 1.1 / GPLv3+ / LGPLv3+
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License or as specified alternatively below. You may obtain a copy of
- * the License at http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * Major Contributor(s):
- * Copyright (C) 2011 Lubos Lunak <l.lunak at suse.cz> (initial developer)
- *
- * All Rights Reserved.
- *
- * For minor contributions see the git repository.
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either the GNU General Public License Version 3 or later (the "GPLv3+"), or
- * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
- * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
- * instead of those above.
- */
-#ifndef _STARMATHIMPORT_HXX
-#define _STARMATHIMPORT_HXX
-
-#include <com/sun/star/embed/XEmbeddedObject.hpp>
-#include <com/sun/star/xml/sax/XFastAttributeList.hpp>
-#include <oox/helper/attributelist.hxx>
-#include <vector>
-
-#include <oox/dllapi.h>
-
-namespace ooxmlformulaimport
-{
-
-const int TAG_OPENING = 1 << 29;
-const int TAG_CLOSING = 1 << 30;
-
-// used to differentiate between tags that open or close
-// TODO
-//inline int OPENING( int token ) { return TAG_OPENING | token; }
-//inline int CLOSING( int token ) { return TAG_CLOSING | token; }
-#define OPENING( token ) ( TAG_OPENING | token )
-#define CLOSING( token ) ( TAG_CLOSING | token )
-
-class OOX_DLLPUBLIC XmlStream
-{
-public:
-    XmlStream();
-    bool nextIsEnd() const;
-    int peekNextToken() const;
-    int getNextToken();
-    oox::AttributeList getAttributes();
-    rtl::OUString getCharacters();
-protected:
-    // TODO one list containing all 3?
-    std::vector< int > tokens;
-    std::vector< oox::AttributeList > attributes;
-    std::vector< rtl::OUString > characters;
-    int pos;
-};
-
-// use this to create the data and then cast to the base class for reading
-class OOX_DLLPUBLIC XmlStreamBuilder
-: public XmlStream
-{
-public:
-    void appendOpeningTag( int token,
-        const com::sun::star::uno::Reference< com::sun::star::xml::sax::XFastAttributeList >& attributes );
-    void appendClosingTag( int token );
-    // appends the characters after the last appended token
-    void appendCharacters( const rtl::OUString& characters );
-};
-
-} // namespace
-
-class OOX_DLLPUBLIC OoxmlFormulaImportHelper
-{
-public:
-    OoxmlFormulaImportHelper();
-    virtual void addFormula( com::sun::star::uno::Reference< com::sun::star::embed::XEmbeddedObject > ) = 0;
-};
-
-class OOX_DLLPUBLIC OoxmlFormulaImportBase
-{
-public:
-    OoxmlFormulaImportBase();
-    virtual void readFormulaOoxml( ooxmlformulaimport::XmlStream& stream ) = 0;
-};
-
-
-#endif
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/oox/inc/oox/mathml/export.hxx b/oox/inc/oox/mathml/export.hxx
new file mode 100644
index 0000000..f4e0563
--- /dev/null
+++ b/oox/inc/oox/mathml/export.hxx
@@ -0,0 +1,53 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * Version: MPL 1.1 / GPLv3+ / LGPLv3+
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License or as specified alternatively below. You may obtain a copy of
+ * the License at http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * Major Contributor(s):
+ * Copyright (C) 2011 Lubos Lunak <l.lunak at suse.cz> (initial developer)
+ *
+ * All Rights Reserved.
+ *
+ * For minor contributions see the git repository.
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 3 or later (the "GPLv3+"), or
+ * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
+ * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
+ * instead of those above.
+ */
+#ifndef _OOXMLEXPORT_HXX
+#define _OOXMLEXPORT_HXX
+
+#include <sax/fshelper.hxx>
+#include <oox/core/filterbase.hxx>
+#include <oox/dllapi.h>
+
+namespace oox
+{
+
+/**
+ Interface class, StarMath will implement writeFormulaOoxml() to write out OOXML
+ representing the formula.
+ */
+class OOX_DLLPUBLIC FormulaExportBase
+{
+public:
+    FormulaExportBase();
+    virtual void writeFormulaOoxml( ::sax_fastparser::FSHelperPtr m_pSerializer, oox::core::OoxmlVersion version ) = 0;
+};
+
+} // namespace
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/oox/inc/oox/mathml/import.hxx b/oox/inc/oox/mathml/import.hxx
new file mode 100644
index 0000000..961a4f6
--- /dev/null
+++ b/oox/inc/oox/mathml/import.hxx
@@ -0,0 +1,61 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * Version: MPL 1.1 / GPLv3+ / LGPLv3+
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License or as specified alternatively below. You may obtain a copy of
+ * the License at http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * Major Contributor(s):
+ * Copyright (C) 2011 Lubos Lunak <l.lunak at suse.cz> (initial developer)
+ *
+ * All Rights Reserved.
+ *
+ * For minor contributions see the git repository.
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 3 or later (the "GPLv3+"), or
+ * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
+ * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
+ * instead of those above.
+ */
+#ifndef _STARMATHIMPORT_HXX
+#define _STARMATHIMPORT_HXX
+
+#include <com/sun/star/embed/XEmbeddedObject.hpp>
+
+#include <oox/dllapi.h>
+
+namespace oox
+{
+
+namespace formulaimport
+{
+class XmlStream;
+}
+
+class OOX_DLLPUBLIC FormulaImportHelper
+{
+public:
+    FormulaImportHelper();
+    virtual void addFormula( com::sun::star::uno::Reference< com::sun::star::embed::XEmbeddedObject > ) = 0;
+};
+
+class OOX_DLLPUBLIC FormulaImportBase
+{
+public:
+    FormulaImportBase();
+    virtual void readFormulaOoxml( oox::formulaimport::XmlStream& stream ) = 0;
+};
+
+} // namespace
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/oox/inc/oox/mathml/importutils.hxx b/oox/inc/oox/mathml/importutils.hxx
new file mode 100644
index 0000000..01baf98
--- /dev/null
+++ b/oox/inc/oox/mathml/importutils.hxx
@@ -0,0 +1,87 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * Version: MPL 1.1 / GPLv3+ / LGPLv3+
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License or as specified alternatively below. You may obtain a copy of
+ * the License at http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * Major Contributor(s):
+ * Copyright (C) 2011 Lubos Lunak <l.lunak at suse.cz> (initial developer)
+ *
+ * All Rights Reserved.
+ *
+ * For minor contributions see the git repository.
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 3 or later (the "GPLv3+"), or
+ * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
+ * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
+ * instead of those above.
+ */
+#ifndef _STARMATHIMPORTUTILS_HXX
+#define _STARMATHIMPORTUTILS_HXX
+
+#include <com/sun/star/xml/sax/XFastAttributeList.hpp>
+#include <oox/helper/attributelist.hxx>
+#include <vector>
+
+#include <oox/dllapi.h>
+
+namespace oox
+{
+
+namespace formulaimport
+{
+
+const int TAG_OPENING = 1 << 29;
+const int TAG_CLOSING = 1 << 30;
+
+// used to differentiate between tags that open or close
+// TODO
+//inline int OPENING( int token ) { return TAG_OPENING | token; }
+//inline int CLOSING( int token ) { return TAG_CLOSING | token; }
+#define OPENING( token ) ( TAG_OPENING | token )
+#define CLOSING( token ) ( TAG_CLOSING | token )
+
+class OOX_DLLPUBLIC XmlStream
+{
+public:
+    XmlStream();
+    bool nextIsEnd() const;
+    int peekNextToken() const;
+    int getNextToken();
+    oox::AttributeList getAttributes();
+    rtl::OUString getCharacters();
+protected:
+    // TODO one list containing all 3?
+    std::vector< int > tokens;
+    std::vector< oox::AttributeList > attributes;
+    std::vector< rtl::OUString > characters;
+    int pos;
+};
+
+// use this to create the data and then cast to the base class for reading
+class OOX_DLLPUBLIC XmlStreamBuilder
+: public XmlStream
+{
+public:
+    void appendOpeningTag( int token,
+        const com::sun::star::uno::Reference< com::sun::star::xml::sax::XFastAttributeList >& attributes );
+    void appendClosingTag( int token );
+    // appends the characters after the last appended token
+    void appendCharacters( const rtl::OUString& characters );
+};
+
+} // namespace
+} // namespace
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/oox/source/export/ooxmlexport.cxx b/oox/source/export/ooxmlexport.cxx
deleted file mode 100644
index 1dfc186..0000000
--- a/oox/source/export/ooxmlexport.cxx
+++ /dev/null
@@ -1,115 +0,0 @@
-/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
-/*
- * Version: MPL 1.1 / GPLv3+ / LGPLv3+
- *
- * The contents of this file are subject to the Mozilla Public License Version
- * 1.1 (the "License"); you may not use this file except in compliance with
- * the License or as specified alternatively below. You may obtain a copy of
- * the License at http://www.mozilla.org/MPL/
- *
- * Software distributed under the License is distributed on an "AS IS" basis,
- * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
- * for the specific language governing rights and limitations under the
- * License.
- *
- * Major Contributor(s):
- * Copyright (C) 2011 Tor Lillqvist <tlillqvist at suse.com> (initial developer)
- *
- * All Rights Reserved.
- *
- * For minor contributions see the git repository.
- *
- * Alternatively, the contents of this file may be used under the terms of
- * either the GNU General Public License Version 3 or later (the "GPLv3+"), or
- * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
- * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
- * instead of those above.
- */
-
-#include <oox/export/ooxmlexport.hxx>
-#include <oox/export/starmathimport.hxx>
-#include <oox/token/tokens.hxx>
-#include <oox/token/namespaces.hxx>
-
-using namespace oox;
-using namespace oox::core;
-using namespace com::sun::star;
-
-OoxmlFormulaExportBase::OoxmlFormulaExportBase()
-{
-}
-
-OoxmlFormulaImportBase::OoxmlFormulaImportBase()
-{
-}
-
-OoxmlFormulaImportHelper::OoxmlFormulaImportHelper()
-{
-}
-
-
-namespace ooxmlformulaimport
-{
-
-XmlStream::XmlStream()
-: pos( -1 )
-{
-    // make sure our extra bit does not conflict with values used by oox
-    assert( TAG_OPENING > ( 1024 << NMSP_SHIFT ));
-}
-
-bool XmlStream::nextIsEnd() const
-{
-    return pos + 1 >= int( tokens.size());
-}
-
-int XmlStream::getNextToken()
-{
-    ++pos;
-    if( pos < int( tokens.size()))
-        return tokens[ pos ];
-    return XML_TOKEN_INVALID;
-}
-
-int XmlStream::peekNextToken() const
-{
-    if( pos - 1 < int( tokens.size()))
-        return tokens[ pos + 1 ];
-    return XML_TOKEN_INVALID;
-}
-
-AttributeList XmlStream::getAttributes()
-{
-    assert( pos < int( attributes.size()));
-    return attributes[ pos ];
-}
-
-rtl::OUString XmlStream::getCharacters()
-{
-    assert( pos < int( characters.size()));
-    return characters[ pos ];
-}
-
-void XmlStreamBuilder::appendOpeningTag( int token, const uno::Reference< xml::sax::XFastAttributeList >& attrs )
-{
-    tokens.push_back( OPENING( token ));
-    attributes.push_back( AttributeList( attrs ));
-    characters.push_back( rtl::OUString());
-}
-
-void XmlStreamBuilder::appendClosingTag( int token )
-{
-    tokens.push_back( CLOSING( token ));
-    attributes.push_back( AttributeList( uno::Reference< xml::sax::XFastAttributeList >()));
-    characters.push_back( rtl::OUString());
-}
-
-void XmlStreamBuilder::appendCharacters( const rtl::OUString& chars )
-{
-    assert( !characters.empty());
-    characters.back() = chars;
-}
-
-} // namespace
-
-/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/oox/source/mathml/export.cxx b/oox/source/mathml/export.cxx
new file mode 100644
index 0000000..418b724
--- /dev/null
+++ b/oox/source/mathml/export.cxx
@@ -0,0 +1,40 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * Version: MPL 1.1 / GPLv3+ / LGPLv3+
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License or as specified alternatively below. You may obtain a copy of
+ * the License at http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * Major Contributor(s):
+ * Copyright (C) 2011 Tor Lillqvist <tlillqvist at suse.com> (initial developer)
+ *
+ * All Rights Reserved.
+ *
+ * For minor contributions see the git repository.
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 3 or later (the "GPLv3+"), or
+ * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
+ * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
+ * instead of those above.
+ */
+
+#include "oox/mathml/export.hxx"
+
+namespace oox
+{
+
+FormulaExportBase::FormulaExportBase()
+{
+}
+
+} // namespace
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/oox/source/mathml/import.cxx b/oox/source/mathml/import.cxx
new file mode 100644
index 0000000..4553006
--- /dev/null
+++ b/oox/source/mathml/import.cxx
@@ -0,0 +1,44 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * Version: MPL 1.1 / GPLv3+ / LGPLv3+
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License or as specified alternatively below. You may obtain a copy of
+ * the License at http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * Major Contributor(s):
+ * Copyright (C) 2011 Tor Lillqvist <tlillqvist at suse.com> (initial developer)
+ *
+ * All Rights Reserved.
+ *
+ * For minor contributions see the git repository.
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 3 or later (the "GPLv3+"), or
+ * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
+ * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
+ * instead of those above.
+ */
+
+#include "oox/mathml/import.hxx"
+
+namespace oox
+{
+
+FormulaImportBase::FormulaImportBase()
+{
+}
+
+FormulaImportHelper::FormulaImportHelper()
+{
+}
+
+} // namespace
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/oox/source/mathml/importutils.cxx b/oox/source/mathml/importutils.cxx
new file mode 100644
index 0000000..1381724
--- /dev/null
+++ b/oox/source/mathml/importutils.cxx
@@ -0,0 +1,105 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * Version: MPL 1.1 / GPLv3+ / LGPLv3+
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License or as specified alternatively below. You may obtain a copy of
+ * the License at http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * Major Contributor(s):
+ * Copyright (C) 2011 Tor Lillqvist <tlillqvist at suse.com> (initial developer)
+ *
+ * All Rights Reserved.
+ *
+ * For minor contributions see the git repository.
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 3 or later (the "GPLv3+"), or
+ * the GNU Lesser General Public License Version 3 or later (the "LGPLv3+"),
+ * in which case the provisions of the GPLv3+ or the LGPLv3+ are applicable
+ * instead of those above.
+ */
+
+#include "oox/mathml/importutils.hxx"
+
+#include <assert.h>
+#include <oox/token/tokens.hxx>
+#include <oox/token/namespaces.hxx>
+
+using namespace com::sun::star;
+
+namespace oox
+{
+
+namespace formulaimport
+{
+
+XmlStream::XmlStream()
+: pos( -1 )
+{
+    // make sure our extra bit does not conflict with values used by oox
+    assert( TAG_OPENING > ( 1024 << NMSP_SHIFT ));
+}
+
+bool XmlStream::nextIsEnd() const
+{
+    return pos + 1 >= int( tokens.size());
+}
+
+int XmlStream::getNextToken()
+{
+    ++pos;
+    if( pos < int( tokens.size()))
+        return tokens[ pos ];
+    return XML_TOKEN_INVALID;
+}
+
+int XmlStream::peekNextToken() const
+{
+    if( pos - 1 < int( tokens.size()))
+        return tokens[ pos + 1 ];
+    return XML_TOKEN_INVALID;
+}
+
+AttributeList XmlStream::getAttributes()
+{
+    assert( pos < int( attributes.size()));
+    return attributes[ pos ];
+}
+
+rtl::OUString XmlStream::getCharacters()
+{
+    assert( pos < int( characters.size()));
+    return characters[ pos ];
+}
+
+void XmlStreamBuilder::appendOpeningTag( int token, const uno::Reference< xml::sax::XFastAttributeList >& attrs )
+{
+    tokens.push_back( OPENING( token ));
+    attributes.push_back( AttributeList( attrs ));
+    characters.push_back( rtl::OUString());
+}
+
+void XmlStreamBuilder::appendClosingTag( int token )
+{
+    tokens.push_back( CLOSING( token ));
+    attributes.push_back( AttributeList( uno::Reference< xml::sax::XFastAttributeList >()));
+    characters.push_back( rtl::OUString());
+}
+
+void XmlStreamBuilder::appendCharacters( const rtl::OUString& chars )
+{
+    assert( !characters.empty());
+    characters.back() = chars;
+}
+
+} // namespace
+} // namespace
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/starmath/inc/document.hxx b/starmath/inc/document.hxx
index c1b4862..c8c1475 100644
--- a/starmath/inc/document.hxx
+++ b/starmath/inc/document.hxx
@@ -41,6 +41,7 @@
 #include <vcl/virdev.hxx>
 #include <sax/fshelper.hxx>
 #include <oox/core/filterbase.hxx>
+#include <oox/mathml/import.hxx>
 
 #include <set>
 
@@ -53,10 +54,6 @@ class SfxMenuBarManager;
 class SfxPrinter;
 class Printer;
 class SmCursor;
-namespace ooxmlformulaimport
-{
-class XmlStream;
-}
 
 #define HINT_DATACHANGED    1004
 
@@ -179,7 +176,7 @@ class SmDocShell : public SfxObjectShell, public SfxListener
     void                InvalidateCursor();
 
     bool writeFormulaOoxml( ::sax_fastparser::FSHelperPtr m_pSerializer, oox::core::OoxmlVersion version );
-    bool readFormulaOoxml( ooxmlformulaimport::XmlStream& stream );
+    bool readFormulaOoxml( oox::formulaimport::XmlStream& stream );
 
 public:
     TYPEINFO();
diff --git a/starmath/inc/unomodel.hxx b/starmath/inc/unomodel.hxx
index 1324c9f..5243d41 100644
--- a/starmath/inc/unomodel.hxx
+++ b/starmath/inc/unomodel.hxx
@@ -37,8 +37,8 @@
 #include <sfx2/sfxbasemodel.hxx>
 #include <comphelper/propertysethelper.hxx>
 #include <vcl/print.hxx>
-#include <oox/export/ooxmlexport.hxx>
-#include <oox/export/starmathimport.hxx>
+#include <oox/mathml/export.hxx>
+#include <oox/mathml/import.hxx>
 
 class SmFormat;
 
@@ -66,8 +66,8 @@ class SmModel : public SfxBaseModel,
                 public comphelper::PropertySetHelper,
                 public com::sun::star::lang::XServiceInfo,
                 public com::sun::star::view::XRenderable,
-                public OoxmlFormulaExportBase,
-                public OoxmlFormulaImportBase
+                public oox::FormulaExportBase,
+                public oox::FormulaImportBase
 {
     SmPrintUIOptions* m_pPrintUIOptions;
 protected:
@@ -104,10 +104,10 @@ public:
 
     virtual void SAL_CALL setParent( const ::com::sun::star::uno::Reference< ::com::sun::star::uno::XInterface >& xParent ) throw( ::com::sun::star::lang::NoSupportException, ::com::sun::star::uno::RuntimeException );
 
-    // OoxmlFormulaExportBase
+    // oox::FormulaExportBase
     virtual void writeFormulaOoxml( ::sax_fastparser::FSHelperPtr m_pSerializer, oox::core::OoxmlVersion version );
-    // OoxmlFormulaImportBase
-    virtual void readFormulaOoxml( ooxmlformulaimport::XmlStream& stream );
+    // oox::FormulaImportBase
+    virtual void readFormulaOoxml( oox::formulaimport::XmlStream& stream );
 
     static ::com::sun::star::uno::Sequence< rtl::OUString > getSupportedServiceNames_Static();
     static ::rtl::OUString getImplementationName_Static();
diff --git a/starmath/source/document.cxx b/starmath/source/document.cxx
index 36df9ae..e031e39 100644
--- a/starmath/source/document.cxx
+++ b/starmath/source/document.cxx
@@ -999,7 +999,7 @@ bool SmDocShell::writeFormulaOoxml( ::sax_fastparser::FSHelperPtr m_pSerializer,
     return aEquation.ConvertFromStarMath( m_pSerializer );
 }
 
-bool SmDocShell::readFormulaOoxml( ooxmlformulaimport::XmlStream& stream )
+bool SmDocShell::readFormulaOoxml( oox::formulaimport::XmlStream& stream )
 {
     RTL_LOGFILE_CONTEXT( aLog, "starmath: SmDocShell::readFormulaOoxml" );
 
diff --git a/starmath/source/ooxmlimport.cxx b/starmath/source/ooxmlimport.cxx
index cd7610f..dc53cc7 100644
--- a/starmath/source/ooxmlimport.cxx
+++ b/starmath/source/ooxmlimport.cxx
@@ -35,7 +35,7 @@
 #include <oox/token/namespaces.hxx>
 
 using namespace oox;
-using namespace ooxmlformulaimport;
+using namespace oox::formulaimport;
 using rtl::OUString;
 
 /*
@@ -52,7 +52,7 @@ The primary internal data structure for the formula is the text representation
 
 // TODO create IS_OPENING(), IS_CLOSING() instead of doing 'next == OPENING( next )' ?
 
-SmOoxmlImport::SmOoxmlImport( ooxmlformulaimport::XmlStream& s )
+SmOoxmlImport::SmOoxmlImport( oox::formulaimport::XmlStream& s )
 : stream( s )
 {
 }
diff --git a/starmath/source/ooxmlimport.hxx b/starmath/source/ooxmlimport.hxx
index 80be1d8..1eebc81 100644
--- a/starmath/source/ooxmlimport.hxx
+++ b/starmath/source/ooxmlimport.hxx
@@ -29,7 +29,7 @@
 #ifndef SM_OOXMLIMPORT_HXX
 #define SM_OOXMLIMPORT_HXX
 
-#include <oox/export/starmathimport.hxx>
+#include <oox/mathml/importutils.hxx>
 
 #include "node.hxx"
 
@@ -40,7 +40,7 @@
 class SmOoxmlImport
 {
 public:
-    SmOoxmlImport( ooxmlformulaimport::XmlStream& stream );
+    SmOoxmlImport( oox::formulaimport::XmlStream& stream );
     rtl::OUString ConvertToStarMath();
 private:
     rtl::OUString handleStream();
@@ -70,7 +70,7 @@ private:
      Handle the current (unexpected) tag.
     */
     void handleUnexpectedTag();
-    ooxmlformulaimport::XmlStream& stream;
+    oox::formulaimport::XmlStream& stream;
 };
 
 #endif
diff --git a/starmath/source/unomodel.cxx b/starmath/source/unomodel.cxx
index 8b7ea81..4f0d2f0 100644
--- a/starmath/source/unomodel.cxx
+++ b/starmath/source/unomodel.cxx
@@ -1137,7 +1137,7 @@ void SmModel::writeFormulaOoxml( ::sax_fastparser::FSHelperPtr m_pSerializer, oo
     static_cast< SmDocShell* >( GetObjectShell())->writeFormulaOoxml( m_pSerializer, version );
 }
 
-void SmModel::readFormulaOoxml( ooxmlformulaimport::XmlStream& stream )
+void SmModel::readFormulaOoxml( oox::formulaimport::XmlStream& stream )
 {
     static_cast< SmDocShell* >( GetObjectShell())->readFormulaOoxml( stream );
 }
diff --git a/sw/inc/unotxdoc.hxx b/sw/inc/unotxdoc.hxx
index 7c61c22..ca21090 100644
--- a/sw/inc/unotxdoc.hxx
+++ b/sw/inc/unotxdoc.hxx
@@ -78,7 +78,7 @@
 #include <cppuhelper/implbase2.hxx> // helper for implementations
 #include <cppuhelper/implbase4.hxx> // helper for implementations
 #include <RefreshListenerContainer.hxx>
-#include <oox/export/starmathimport.hxx>
+#include <oox/mathml/import.hxx>
 
 #include <viewopt.hxx>
 
@@ -182,7 +182,7 @@ SwXTextDocumentBaseClass;
 class SW_DLLPUBLIC SwXTextDocument : public SwXTextDocumentBaseClass,
     public SvxFmMSFactory,
     public SfxBaseModel,
-    public OoxmlFormulaImportHelper
+    public oox::FormulaImportHelper
 {
     ActionContextArr        aActionArr;
     SwRefreshListenerContainer  aRefreshCont;
diff --git a/sw/source/filter/ww8/docxattributeoutput.cxx b/sw/source/filter/ww8/docxattributeoutput.cxx
index 36e2860..42a132d 100644
--- a/sw/source/filter/ww8/docxattributeoutput.cxx
+++ b/sw/source/filter/ww8/docxattributeoutput.cxx
@@ -45,7 +45,7 @@
 #include <oox/export/drawingml.hxx>
 #include <oox/export/utils.hxx>
 #include <oox/export/vmlexport.hxx>
-#include <oox/export/ooxmlexport.hxx>
+#include <oox/mathml/export.hxx>
 
 #include <i18npool/mslangid.hxx>
 
@@ -2314,7 +2314,7 @@ void DocxAttributeOutput::WritePostponedMath()
         return;
     uno::Reference < embed::XEmbeddedObject > xObj(const_cast<SwOLENode*>(m_postponedMath)->GetOLEObj().GetOleRef());
     uno::Reference< uno::XInterface > xInterface( xObj->getComponent(), uno::UNO_QUERY );
-    if( OoxmlFormulaExportBase* formulaexport = dynamic_cast< OoxmlFormulaExportBase* >( xInterface.get()))
+    if( oox::FormulaExportBase* formulaexport = dynamic_cast< oox::FormulaExportBase* >( xInterface.get()))
         formulaexport->writeFormulaOoxml( m_pSerializer, GetExport().GetFilter().getVersion());
     else
         OSL_FAIL( "Math OLE object cannot write out OOXML" );
diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.cxx b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
index 0f5c787..389b2b3 100644
--- a/writerfilter/source/dmapper/DomainMapper_Impl.cxx
+++ b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
@@ -26,7 +26,7 @@
  *
  ************************************************************************/
 
-#include <oox/export/starmathimport.hxx>
+#include <oox/mathml/import.hxx>
 
 #include <DomainMapper_Impl.hxx>
 #include <ConversionHelper.hxx>
@@ -1096,7 +1096,7 @@ void DomainMapper_Impl::appendStarMath( const Value& val )
             val.getAny() >>= formula;
             if( formula.is() )
             {
-                if( OoxmlFormulaImportHelper* import = dynamic_cast< OoxmlFormulaImportHelper* >( GetTextDocument().get()))
+                if( oox::FormulaImportHelper* import = dynamic_cast< oox::FormulaImportHelper* >( GetTextDocument().get()))
                     import->addFormula( formula );
     static const rtl::OUString sEmbeddedService(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.TextEmbeddedObject"));
     try
diff --git a/writerfilter/source/ooxml/OOXMLFastContextHandler.cxx b/writerfilter/source/ooxml/OOXMLFastContextHandler.cxx
index a6dd2a9..20170ba 100644
--- a/writerfilter/source/ooxml/OOXMLFastContextHandler.cxx
+++ b/writerfilter/source/ooxml/OOXMLFastContextHandler.cxx
@@ -2382,7 +2382,7 @@ OOXMLFastContextHandlerMath::~OOXMLFastContextHandlerMath()
     rtl::OUString aName; // TODO?
     uno::Reference< embed::XEmbeddedObject > ref = container.CreateEmbeddedObject( name.GetByteSequence(), aName );
     uno::Reference< uno::XInterface > component( ref->getComponent(), uno::UNO_QUERY );
-    if( OoxmlFormulaImportBase* import = dynamic_cast< OoxmlFormulaImportBase* >( component.get()))
+    if( oox::FormulaImportBase* import = dynamic_cast< oox::FormulaImportBase* >( component.get()))
         import->readFormulaOoxml( buffer );
     if (isForwardEvents())
     {
diff --git a/writerfilter/source/ooxml/OOXMLFastContextHandler.hxx b/writerfilter/source/ooxml/OOXMLFastContextHandler.hxx
index 16eef9a..e06f4b1 100644
--- a/writerfilter/source/ooxml/OOXMLFastContextHandler.hxx
+++ b/writerfilter/source/ooxml/OOXMLFastContextHandler.hxx
@@ -44,7 +44,8 @@
 #include <ooxml/OOXMLFastTokens.hxx>
 #include <svtools/embedhlp.hxx>
 
-#include <oox/export/starmathimport.hxx>
+#include <oox/mathml/import.hxx>
+#include <oox/mathml/importutils.hxx>
 
 namespace writerfilter {
 namespace ooxml
@@ -662,7 +663,7 @@ protected:
     virtual void lcl_characters(const ::rtl::OUString & aChars) throw (uno::RuntimeException, xml::sax::SAXException);
 
 private:
-    ooxmlformulaimport::XmlStreamBuilder buffer;
+    oox::formulaimport::XmlStreamBuilder buffer;
 };
 
 
commit 0ac48a4a0673ac71e06aa588b524a60367e2ad19
Author: Luboš Luňák <l.lunak at suse.cz>
Date:   Fri Nov 18 20:52:02 2011 +0100

    oox/namespaces.txt actually is generated

diff --git a/oox/Package_generated.mk b/oox/Package_generated.mk
index 8e2b355..e1911ea 100644
--- a/oox/Package_generated.mk
+++ b/oox/Package_generated.mk
@@ -30,5 +30,6 @@ $(eval $(call gb_Package_Package,oox_generated,$(WORKDIR)/oox))
 
 $(eval $(call gb_Package_add_file,oox_generated,inc/oox/token/tokens.hxx,inc/oox/token/tokens.hxx))
 $(eval $(call gb_Package_add_file,oox_generated,inc/oox/token/namespaces.hxx,inc/oox/token/namespaces.hxx))
+$(eval $(call gb_Package_add_file,oox_generated,inc/oox/namespaces.txt,misc/namespaces.txt))
 
 # vim: set noet sw=4 ts=4:
diff --git a/oox/Package_tokens.mk b/oox/Package_tokens.mk
index 96eb521..5eb2073 100644
--- a/oox/Package_tokens.mk
+++ b/oox/Package_tokens.mk
@@ -29,6 +29,5 @@
 $(eval $(call gb_Package_Package,oox_tokens,$(SRCDIR)/oox/source/token))
 
 $(eval $(call gb_Package_add_file,oox_tokens,inc/oox/tokens.txt,tokens.txt))
-$(eval $(call gb_Package_add_file,oox_tokens,inc/oox/namespaces.txt,namespaces.txt))
 
 # vim: set noet sw=4 ts=4:
commit e443c83aa312d9baa6b5dd2921f3e22ff9578b76
Author: Luboš Luňák <l.lunak at suse.cz>
Date:   Fri Nov 18 18:15:03 2011 +0100

    remove debug output

diff --git a/writerfilter/source/ooxml/OOXMLFastContextHandler.cxx b/writerfilter/source/ooxml/OOXMLFastContextHandler.cxx
index e2040e4..a6dd2a9 100644
--- a/writerfilter/source/ooxml/OOXMLFastContextHandler.cxx
+++ b/writerfilter/source/ooxml/OOXMLFastContextHandler.cxx
@@ -2399,14 +2399,12 @@ void OOXMLFastContextHandlerMath::lcl_startFastElement(Token_t Element,
     throw (uno::RuntimeException, xml::sax::SAXException)
 {
     buffer.appendOpeningTag( Element, Attribs );
-    fprintf(stderr,"OPEN %d\n", Element);
 }
 
 void OOXMLFastContextHandlerMath::lcl_endFastElement(Token_t Element)
     throw (uno::RuntimeException, xml::sax::SAXException)
 {
     buffer.appendClosingTag( Element );
-    fprintf(stderr,"CLOSE %d\n", Element);
 }
 
 uno::Reference< xml::sax::XFastContextHandler >
commit e9462ed2d978dc3e641227ea9f553eeed4d81a97
Author: Luboš Luňák <l.lunak at suse.cz>
Date:   Fri Nov 18 18:09:43 2011 +0100

    ooxml mathml import - first very basic implementation
    
    still needs a number of cleanups (and handling more of course)

diff --git a/oox/inc/oox/export/starmathimport.hxx b/oox/inc/oox/export/starmathimport.hxx
index 712efc9..a348ac8 100644
--- a/oox/inc/oox/export/starmathimport.hxx
+++ b/oox/inc/oox/export/starmathimport.hxx
@@ -29,16 +29,71 @@
 #define _STARMATHIMPORT_HXX
 
 #include <com/sun/star/embed/XEmbeddedObject.hpp>
+#include <com/sun/star/xml/sax/XFastAttributeList.hpp>
+#include <oox/helper/attributelist.hxx>
+#include <vector>
 
 #include <oox/dllapi.h>
 
+namespace ooxmlformulaimport
+{
+
+const int TAG_OPENING = 1 << 29;
+const int TAG_CLOSING = 1 << 30;
+
+// used to differentiate between tags that open or close
+// TODO
+//inline int OPENING( int token ) { return TAG_OPENING | token; }
+//inline int CLOSING( int token ) { return TAG_CLOSING | token; }
+#define OPENING( token ) ( TAG_OPENING | token )
+#define CLOSING( token ) ( TAG_CLOSING | token )
+
+class OOX_DLLPUBLIC XmlStream
+{
+public:
+    XmlStream();
+    bool nextIsEnd() const;
+    int peekNextToken() const;
+    int getNextToken();
+    oox::AttributeList getAttributes();
+    rtl::OUString getCharacters();
+protected:
+    // TODO one list containing all 3?
+    std::vector< int > tokens;
+    std::vector< oox::AttributeList > attributes;
+    std::vector< rtl::OUString > characters;
+    int pos;
+};
+
+// use this to create the data and then cast to the base class for reading
+class OOX_DLLPUBLIC XmlStreamBuilder
+: public XmlStream
+{
+public:
+    void appendOpeningTag( int token,
+        const com::sun::star::uno::Reference< com::sun::star::xml::sax::XFastAttributeList >& attributes );
+    void appendClosingTag( int token );
+    // appends the characters after the last appended token
+    void appendCharacters( const rtl::OUString& characters );
+};
+
+} // namespace
+
+class OOX_DLLPUBLIC OoxmlFormulaImportHelper
+{
+public:
+    OoxmlFormulaImportHelper();
+    virtual void addFormula( com::sun::star::uno::Reference< com::sun::star::embed::XEmbeddedObject > ) = 0;
+};
+
 class OOX_DLLPUBLIC OoxmlFormulaImportBase
 {
 public:
     OoxmlFormulaImportBase();
-    virtual void addFormula( com::sun::star::uno::Reference< com::sun::star::embed::XEmbeddedObject > ) = 0;
+    virtual void readFormulaOoxml( ooxmlformulaimport::XmlStream& stream ) = 0;
 };
 
+
 #endif
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/oox/source/export/ooxmlexport.cxx b/oox/source/export/ooxmlexport.cxx
index b4e541c..1dfc186 100644
--- a/oox/source/export/ooxmlexport.cxx
+++ b/oox/source/export/ooxmlexport.cxx
@@ -28,6 +28,12 @@
 
 #include <oox/export/ooxmlexport.hxx>
 #include <oox/export/starmathimport.hxx>
+#include <oox/token/tokens.hxx>
+#include <oox/token/namespaces.hxx>
+
+using namespace oox;
+using namespace oox::core;
+using namespace com::sun::star;
 
 OoxmlFormulaExportBase::OoxmlFormulaExportBase()
 {
@@ -37,4 +43,73 @@ OoxmlFormulaImportBase::OoxmlFormulaImportBase()
 {
 }
 
+OoxmlFormulaImportHelper::OoxmlFormulaImportHelper()
+{
+}
+
+
+namespace ooxmlformulaimport
+{
+
+XmlStream::XmlStream()
+: pos( -1 )
+{
+    // make sure our extra bit does not conflict with values used by oox
+    assert( TAG_OPENING > ( 1024 << NMSP_SHIFT ));
+}
+
+bool XmlStream::nextIsEnd() const
+{
+    return pos + 1 >= int( tokens.size());
+}
+
+int XmlStream::getNextToken()
+{
+    ++pos;
+    if( pos < int( tokens.size()))
+        return tokens[ pos ];
+    return XML_TOKEN_INVALID;
+}
+
+int XmlStream::peekNextToken() const
+{
+    if( pos - 1 < int( tokens.size()))
+        return tokens[ pos + 1 ];
+    return XML_TOKEN_INVALID;
+}
+
+AttributeList XmlStream::getAttributes()
+{
+    assert( pos < int( attributes.size()));
+    return attributes[ pos ];
+}
+
+rtl::OUString XmlStream::getCharacters()
+{
+    assert( pos < int( characters.size()));
+    return characters[ pos ];
+}
+
+void XmlStreamBuilder::appendOpeningTag( int token, const uno::Reference< xml::sax::XFastAttributeList >& attrs )
+{
+    tokens.push_back( OPENING( token ));
+    attributes.push_back( AttributeList( attrs ));
+    characters.push_back( rtl::OUString());
+}
+
+void XmlStreamBuilder::appendClosingTag( int token )
+{
+    tokens.push_back( CLOSING( token ));
+    attributes.push_back( AttributeList( uno::Reference< xml::sax::XFastAttributeList >()));
+    characters.push_back( rtl::OUString());
+}
+
+void XmlStreamBuilder::appendCharacters( const rtl::OUString& chars )
+{
+    assert( !characters.empty());
+    characters.back() = chars;
+}
+
+} // namespace
+
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/starmath/Library_sm.mk b/starmath/Library_sm.mk
index 6b9c7ba..9c4a690 100644
--- a/starmath/Library_sm.mk
+++ b/starmath/Library_sm.mk
@@ -80,6 +80,7 @@ $(eval $(call gb_Library_add_exception_objects,sm,\
         starmath/source/mathtype \
         starmath/source/node \
         starmath/source/ooxmlexport \
+        starmath/source/ooxmlimport \
         starmath/source/parse \
         starmath/source/rect \
 		starmath/source/register \
diff --git a/starmath/inc/document.hxx b/starmath/inc/document.hxx
index 99f0d8b..c1b4862 100644
--- a/starmath/inc/document.hxx
+++ b/starmath/inc/document.hxx
@@ -53,6 +53,10 @@ class SfxMenuBarManager;
 class SfxPrinter;
 class Printer;
 class SmCursor;
+namespace ooxmlformulaimport
+{
+class XmlStream;
+}
 
 #define HINT_DATACHANGED    1004
 
@@ -175,6 +179,7 @@ class SmDocShell : public SfxObjectShell, public SfxListener
     void                InvalidateCursor();
 
     bool writeFormulaOoxml( ::sax_fastparser::FSHelperPtr m_pSerializer, oox::core::OoxmlVersion version );
+    bool readFormulaOoxml( ooxmlformulaimport::XmlStream& stream );
 
 public:
     TYPEINFO();
diff --git a/starmath/inc/unomodel.hxx b/starmath/inc/unomodel.hxx
index 66479f9..1324c9f 100644
--- a/starmath/inc/unomodel.hxx
+++ b/starmath/inc/unomodel.hxx
@@ -38,6 +38,7 @@
 #include <comphelper/propertysethelper.hxx>
 #include <vcl/print.hxx>
 #include <oox/export/ooxmlexport.hxx>
+#include <oox/export/starmathimport.hxx>
 
 class SmFormat;
 
@@ -65,7 +66,8 @@ class SmModel : public SfxBaseModel,
                 public comphelper::PropertySetHelper,
                 public com::sun::star::lang::XServiceInfo,
                 public com::sun::star::view::XRenderable,
-                public OoxmlFormulaExportBase
+                public OoxmlFormulaExportBase,
+                public OoxmlFormulaImportBase
 {
     SmPrintUIOptions* m_pPrintUIOptions;
 protected:
@@ -104,6 +106,8 @@ public:
 
     // OoxmlFormulaExportBase
     virtual void writeFormulaOoxml( ::sax_fastparser::FSHelperPtr m_pSerializer, oox::core::OoxmlVersion version );
+    // OoxmlFormulaImportBase
+    virtual void readFormulaOoxml( ooxmlformulaimport::XmlStream& stream );
 
     static ::com::sun::star::uno::Sequence< rtl::OUString > getSupportedServiceNames_Static();
     static ::rtl::OUString getImplementationName_Static();
diff --git a/starmath/source/document.cxx b/starmath/source/document.cxx
index 7586e64..36df9ae 100644
--- a/starmath/source/document.cxx
+++ b/starmath/source/document.cxx
@@ -96,6 +96,7 @@
 #include <view.hxx>
 #include "mathtype.hxx"
 #include "ooxmlexport.hxx"
+#include "ooxmlimport.hxx"
 #include "mathmlimport.hxx"
 #include "mathmlexport.hxx"
 #include <sfx2/sfxsids.hrc>
@@ -998,6 +999,15 @@ bool SmDocShell::writeFormulaOoxml( ::sax_fastparser::FSHelperPtr m_pSerializer,
     return aEquation.ConvertFromStarMath( m_pSerializer );
 }
 
+bool SmDocShell::readFormulaOoxml( ooxmlformulaimport::XmlStream& stream )
+{
+    RTL_LOGFILE_CONTEXT( aLog, "starmath: SmDocShell::readFormulaOoxml" );
+
+    SmOoxmlImport aEquation( stream );
+    SetText( aEquation.ConvertToStarMath());
+    return true; // TODO just void?
+}
+
 sal_Bool SmDocShell::SaveCompleted( const ::com::sun::star::uno::Reference< ::com::sun::star::embed::XStorage >& xStorage )
 {
     RTL_LOGFILE_CONTEXT( aLog, "starmath: SmDocShell::SaveCompleted" );
diff --git a/starmath/source/ooxmlimport.cxx b/starmath/source/ooxmlimport.cxx
new file mode 100644
index 0000000..cd7610f
--- /dev/null
+++ b/starmath/source/ooxmlimport.cxx
@@ -0,0 +1,233 @@
+/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
+/*
+ * Version: MPL 1.1 / GPLv3+ / LGPLv3+
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License or as specified alternatively below. You may obtain a copy of
+ * the License at http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License

... etc. - the rest is truncated


More information about the Libreoffice-commits mailing list