summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuboš Luňák <l.lunak@suse.cz>2011-11-18 18:09:43 +0100
committerLuboš Luňák <l.lunak@suse.cz>2011-11-24 18:43:57 +0100
commite9462ed2d978dc3e641227ea9f553eeed4d81a97 (patch)
tree8b77274817348852458ed19be1bd46bb66d0a749
parent1d163e4835b4906eb4559851e5ab2470b26332fe (diff)
ooxml mathml import - first very basic implementation
still needs a number of cleanups (and handling more of course)
-rw-r--r--oox/inc/oox/export/starmathimport.hxx57
-rw-r--r--oox/source/export/ooxmlexport.cxx75
-rw-r--r--starmath/Library_sm.mk1
-rw-r--r--starmath/inc/document.hxx5
-rw-r--r--starmath/inc/unomodel.hxx6
-rw-r--r--starmath/source/document.cxx10
-rw-r--r--starmath/source/ooxmlimport.cxx233
-rw-r--r--starmath/source/ooxmlimport.hxx78
-rw-r--r--starmath/source/unomodel.cxx5
-rw-r--r--sw/inc/unotxdoc.hxx2
-rw-r--r--writerfilter/Library_ooxml.mk1
-rw-r--r--writerfilter/source/dmapper/DomainMapper_Impl.cxx12
-rw-r--r--writerfilter/source/ooxml/OOXMLFastContextHandler.cxx19
-rw-r--r--writerfilter/source/ooxml/OOXMLFastContextHandler.hxx5
14 files changed, 486 insertions, 23 deletions
diff --git a/oox/inc/oox/export/starmathimport.hxx b/oox/inc/oox/export/starmathimport.hxx
index 712efc94845a..a348ac8a3566 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 b4e541cc3a1d..1dfc18645a48 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 6b9c7babdca4..9c4a6904450e 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 99f0d8b4cc79..c1b48629a454 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 66479f988ec5..1324c9f8bc88 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 7586e64d3089..36df9ae505dc 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 000000000000..cd7610fd215a
--- /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
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * Major Contributor(s):
+ * Copyright (C) 2011 Lubos Lunak <l.lunak@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.
+ */
+
+// MARKER(update_precomp.py): autogen include statement, do not remove
+#include "precompiled_starmath.hxx"
+
+#include "ooxmlimport.hxx"
+
+#include <oox/token/tokens.hxx>
+#include <oox/token/namespaces.hxx>
+
+using namespace oox;
+using namespace ooxmlformulaimport;
+using rtl::OUString;
+
+/*
+The primary internal data structure for the formula is the text representation
+(the SmNode tree is built from it), so read data must be converted into this format.
+*/
+
+#define M_TOKEN( token ) OOX_TOKEN( officeMath, token )
+#define OPENING_TAG( token ) OPENING( token )
+#define CLOSING_TAG( token ) CLOSING( token )
+
+// *sigh*
+#define STR( str ) OUString( RTL_CONSTASCII_USTRINGPARAM( str ))
+
+// TODO create IS_OPENING(), IS_CLOSING() instead of doing 'next == OPENING( next )' ?
+
+SmOoxmlImport::SmOoxmlImport( ooxmlformulaimport::XmlStream& s )
+: stream( s )
+{
+}
+
+OUString SmOoxmlImport::ConvertToStarMath()
+{
+ return handleStream();
+}
+
+// "toplevel" of reading, there will be oMath (if there was oMathPara, that was
+// up to the parent component to handle)
+
+// NOT complete
+OUString SmOoxmlImport::handleStream()
+{
+ checkOpeningTag( M_TOKEN( oMath ));
+ OUString ret;
+ bool out = false;
+ while( !out && !stream.nextIsEnd())
+ {
+ switch( stream.peekNextToken())
+ {
+ case OPENING( M_TOKEN( f )):
+ ret += STR( " " ) + handleF();
+ break;
+ case CLOSING( M_TOKEN( oMath )):
+ out = true;
+ break;
+ default:
+ handleUnexpectedTag();
+ break;
+ }
+ }
+ checkClosingTag( M_TOKEN( oMath ));
+ return ret;
+}
+
+// NOT complete
+OUString SmOoxmlImport::handleF()
+{
+ checkOpeningTag( M_TOKEN( f ));
+ if( stream.peekNextToken() == OPENING_TAG( M_TOKEN( fPr )))
+ {
+ // TODO
+ }
+ checkOpeningTag( M_TOKEN( num ));
+ OUString num = readR();
+ checkClosingTag( M_TOKEN( num ));
+ checkOpeningTag( M_TOKEN( den ));
+ OUString den = readR();
+ checkClosingTag( M_TOKEN( den ));
+ checkClosingTag( 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 ));
+
+ // TODO can there be more t's ?
+ checkOpeningTag( M_TOKEN( t ));
+ OUString text = stream.getCharacters();
+ if( !stream.getAttributes().getBool( OOX_TOKEN( xml, space ), false ))
+ text = text.trim();
+ checkClosingTag( M_TOKEN( t ));
+ checkClosingTag( M_TOKEN( r ));
+ return text;
+}
+
+void SmOoxmlImport::checkOpeningTag( int token )
+{
+ checkTag( OPENING( token ), "opening" );
+}
+
+void SmOoxmlImport::checkClosingTag( int token )
+{
+ checkTag( CLOSING( token ), "closing" );
+}
+
+void SmOoxmlImport::checkTag( int token, const char* txt )
+{
+ if( stream.peekNextToken() == token )
+ {
+ stream.getNextToken(); // read it
+ return; // ok
+ }
+ if( recoverAndFindTag( token ))
+ {
+ stream.getNextToken(); // read it
+ return; // ok, skipped some tokens
+ }
+ fprintf( stderr, "Expected %s tag %d not found.\n", txt, token );
+}
+
+bool SmOoxmlImport::recoverAndFindTag( int token )
+{
+ int depth = 0;
+ for(;;)
+ {
+ if( depth > 0 ) // we're inside a nested element, skip those
+ {
+ int next = stream.getNextToken();
+ if( next == OPENING( next ))
+ {
+ fprintf( stderr, "Skipping opening tag %d\n", next );
+ ++depth;
+ }
+ else if( next == CLOSING( next ))
+ { // TODO debug output without the OPENING/CLOSING bits set
+ fprintf( stderr, "Skipping closing tag %d\n", next );
+ --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 );
+ abort();
+ }
+ continue;
+ }
+ int next = stream.peekNextToken();
+ if( next == CLOSING( next ))
+ return false; // that would be leaving current element, so not found
+ if( next == token )
+ return true; // ok, found
+ if( next == OPENING( next ))
+ {
+ fprintf( stderr, "Skipping opening tag %d\n", next );
+ stream.getNextToken();
+ ++depth;
+ }
+ else if( next == XML_TOKEN_INVALID )
+ {
+ fprintf( stderr, "Unexpected end of stream reached.\n" );
+ return false;
+ }
+ else
+ abort();
+ }
+}
+
+void SmOoxmlImport::skipElement( int token )
+{
+ int closing = ( token & ~TAG_OPENING ) | TAG_CLOSING; // make it a closing tag
+ assert( stream.peekNextToken() == OPENING( token ));
+ // just find the matching closing tag
+ if( recoverAndFindTag( closing ))
+ {
+ stream.getNextToken(); // read it
+ return;
+ }
+ fprintf( stderr, "Expected end of element %d not found.\n", token );
+}
+
+void SmOoxmlImport::handleUnexpectedTag()
+{
+ int next = stream.peekNextToken();
+ if( next == XML_TOKEN_INVALID )
+ return; // end of stream
+ if( next == CLOSING( next ))
+ {
+ stream.getNextToken(); // just skip it
+ return;
+ }
+ skipElement( stream.peekNextToken());
+}
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/starmath/source/ooxmlimport.hxx b/starmath/source/ooxmlimport.hxx
new file mode 100644
index 000000000000..80be1d836b5c
--- /dev/null
+++ b/starmath/source/ooxmlimport.hxx
@@ -0,0 +1,78 @@
+/* -*- 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@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 SM_OOXMLIMPORT_HXX
+#define SM_OOXMLIMPORT_HXX
+
+#include <oox/export/starmathimport.hxx>
+
+#include "node.hxx"
+
+/**
+ Class implementing reading of formulas from OOXML. The toplevel element is expected
+ to be oMath (handle oMathPara outside of this code).
+ */
+class SmOoxmlImport
+{
+public:
+ SmOoxmlImport( ooxmlformulaimport::XmlStream& stream );
+ rtl::OUString ConvertToStarMath();
+private:
+ rtl::OUString handleStream();
+ rtl::OUString handleF();
+ rtl::OUString readR();
+ /**
+ Checks that the next token is the given opening tag, if not, writes out a warning
+ and tries to recover (skips tags until found or until the current element would end).
+ */
+ void checkOpeningTag( int token );
+ /**
+ Checks that the next token is the given opening tag, if not, writes out a warning
+ and tries to recover (skips tags until found or until the current element would end).
+ */
+ void checkClosingTag( int token );
+ // helper for the two above
+ void checkTag( int token, const char* txt );
+ /**
+ Tries to find the given token, until either found (returns true) or end of current element.
+ */
+ 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();
+ ooxmlformulaimport::XmlStream& stream;
+};
+
+#endif
+
+/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/starmath/source/unomodel.cxx b/starmath/source/unomodel.cxx
index 2cb17987b2ac..8b7ea8169235 100644
--- a/starmath/source/unomodel.cxx
+++ b/starmath/source/unomodel.cxx
@@ -1137,4 +1137,9 @@ void SmModel::writeFormulaOoxml( ::sax_fastparser::FSHelperPtr m_pSerializer, oo
static_cast< SmDocShell* >( GetObjectShell())->writeFormulaOoxml( m_pSerializer, version );
}
+void SmModel::readFormulaOoxml( ooxmlformulaimport::XmlStream& stream )
+{
+ static_cast< SmDocShell* >( GetObjectShell())->readFormulaOoxml( stream );
+}
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/inc/unotxdoc.hxx b/sw/inc/unotxdoc.hxx
index a821e38cc6c3..7c61c22a4719 100644
--- a/sw/inc/unotxdoc.hxx
+++ b/sw/inc/unotxdoc.hxx
@@ -182,7 +182,7 @@ SwXTextDocumentBaseClass;
class SW_DLLPUBLIC SwXTextDocument : public SwXTextDocumentBaseClass,
public SvxFmMSFactory,
public SfxBaseModel,
- public OoxmlFormulaImportBase
+ public OoxmlFormulaImportHelper
{
ActionContextArr aActionArr;
SwRefreshListenerContainer aRefreshCont;
diff --git a/writerfilter/Library_ooxml.mk b/writerfilter/Library_ooxml.mk
index 53a0342d114f..d2f52f5e5569 100644
--- a/writerfilter/Library_ooxml.mk
+++ b/writerfilter/Library_ooxml.mk
@@ -59,6 +59,7 @@ $(eval $(call gb_Library_add_linked_libs,ooxml,\
doctok \
i18nisolang1 \
i18npaper \
+ oox \
resourcemodel \
sal \
tl \
diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.cxx b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
index f358ea13d1fd..0f5c78740e4a 100644
--- a/writerfilter/source/dmapper/DomainMapper_Impl.cxx
+++ b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
@@ -1092,34 +1092,24 @@ void DomainMapper_Impl::appendOLE( const ::rtl::OUString& rStreamName, OLEHandle
void DomainMapper_Impl::appendStarMath( const Value& val )
{
- fprintf(stderr,"SM 1 %s\n", typeid(*GetTextDocument().get()).name());
uno::Reference< embed::XEmbeddedObject > formula;
val.getAny() >>= formula;
if( formula.is() )
{
- if( OoxmlFormulaImportBase* import = dynamic_cast< OoxmlFormulaImportBase* >( GetTextDocument().get()))
- {
- fprintf( stderr,"SM 3 %p\n", import );
+ if( OoxmlFormulaImportHelper* import = dynamic_cast< OoxmlFormulaImportHelper* >( GetTextDocument().get()))
import->addFormula( formula );
- }
static const rtl::OUString sEmbeddedService(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.text.TextEmbeddedObject"));
try
{
uno::Reference< text::XTextContent > xOLE( m_xTextFactory->createInstance(sEmbeddedService), uno::UNO_QUERY_THROW );
- fprintf(stderr,"SM4\n");
uno::Reference< beans::XPropertySet > xOLEProperties(xOLE, uno::UNO_QUERY_THROW);
- fprintf(stderr,"SM5\n");
- sleep(10);
xOLEProperties->setPropertyValue(PropertyNameSupplier::GetPropertyNameSupplier().GetName( PROP_STREAM_NAME ),
val.getAny());
- fprintf(stderr,"SM6\n");
// mimic the treatment of graphics here.. it seems anchoring as character
// gives a better ( visually ) result
xOLEProperties->setPropertyValue(PropertyNameSupplier::GetPropertyNameSupplier().GetName( PROP_ANCHOR_TYPE ), uno::makeAny( text::TextContentAnchorType_AS_CHARACTER ) );
- fprintf(stderr,"SM7\n");
appendTextContent( xOLE, uno::Sequence< beans::PropertyValue >() );
- fprintf(stderr,"SM8\n");
}
catch( const uno::Exception& rEx )
diff --git a/writerfilter/source/ooxml/OOXMLFastContextHandler.cxx b/writerfilter/source/ooxml/OOXMLFastContextHandler.cxx
index 10a0331d6668..e2040e4a0132 100644
--- a/writerfilter/source/ooxml/OOXMLFastContextHandler.cxx
+++ b/writerfilter/source/ooxml/OOXMLFastContextHandler.cxx
@@ -2373,16 +2373,17 @@ Token_t OOXMLFastContextHandlerWrapper::getToken() const
OOXMLFastContextHandlerMath::OOXMLFastContextHandlerMath(OOXMLFastContextHandler* pContext)
: OOXMLFastContextHandlerProperties(pContext)
{
- fprintf( stderr, "MMM ctor\n" );
}
OOXMLFastContextHandlerMath::~OOXMLFastContextHandlerMath()
{
- fprintf( stderr, "MMM dtor\n" );
SvGlobalName name( SO3_SM_CLASSID );
comphelper::EmbeddedObjectContainer container;
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()))
+ import->readFormulaOoxml( buffer );
if (isForwardEvents())
{
OOXMLPropertySet * pProps = new OOXMLPropertySetImpl();
@@ -2397,22 +2398,22 @@ void OOXMLFastContextHandlerMath::lcl_startFastElement(Token_t Element,
const uno::Reference< xml::sax::XFastAttributeList >& Attribs)
throw (uno::RuntimeException, xml::sax::SAXException)
{
- fprintf( stderr, "MMM start %d\n", Element );
+ buffer.appendOpeningTag( Element, Attribs );
+ fprintf(stderr,"OPEN %d\n", Element);
}
void OOXMLFastContextHandlerMath::lcl_endFastElement(Token_t Element)
throw (uno::RuntimeException, xml::sax::SAXException)
{
- fprintf( stderr, "MMM end %d\n", Element );
- OOXMLFastContextHandlerProperties::lcl_endFastElement( Element );
+ buffer.appendClosingTag( Element );
+ fprintf(stderr,"CLOSE %d\n", Element);
}
uno::Reference< xml::sax::XFastContextHandler >
-OOXMLFastContextHandlerMath::lcl_createFastChildContext(Token_t Element,
- const uno::Reference< xml::sax::XFastAttributeList >& Attribs)
+OOXMLFastContextHandlerMath::lcl_createFastChildContext(Token_t,
+ const uno::Reference< xml::sax::XFastAttributeList >&)
throw (uno::RuntimeException, xml::sax::SAXException)
{
- fprintf( stderr, "MMM child %d\n", Element );
uno::Reference< xml::sax::XFastContextHandler > xContextHandler;
xContextHandler.set( this );
return xContextHandler;
@@ -2421,7 +2422,7 @@ OOXMLFastContextHandlerMath::lcl_createFastChildContext(Token_t Element,
void OOXMLFastContextHandlerMath::lcl_characters(const ::rtl::OUString& aChars)
throw (uno::RuntimeException, xml::sax::SAXException)
{
- fprintf( stderr, "MMM chars %s\n", rtl::OUStringToOString( aChars, RTL_TEXTENCODING_UTF8 ).getStr());
+ buffer.appendCharacters( aChars );
}
diff --git a/writerfilter/source/ooxml/OOXMLFastContextHandler.hxx b/writerfilter/source/ooxml/OOXMLFastContextHandler.hxx
index 9f7c082c98ac..16eef9abfdd6 100644
--- a/writerfilter/source/ooxml/OOXMLFastContextHandler.hxx
+++ b/writerfilter/source/ooxml/OOXMLFastContextHandler.hxx
@@ -44,6 +44,8 @@
#include <ooxml/OOXMLFastTokens.hxx>
#include <svtools/embedhlp.hxx>
+#include <oox/export/starmathimport.hxx>
+
namespace writerfilter {
namespace ooxml
{
@@ -658,6 +660,9 @@ protected:
throw (uno::RuntimeException, xml::sax::SAXException);
virtual void lcl_characters(const ::rtl::OUString & aChars) throw (uno::RuntimeException, xml::sax::SAXException);
+
+private:
+ ooxmlformulaimport::XmlStreamBuilder buffer;
};