From e9462ed2d978dc3e641227ea9f553eeed4d81a97 Mon Sep 17 00:00:00 2001 From: Luboš Luňák Date: Fri, 18 Nov 2011 18:09:43 +0100 Subject: ooxml mathml import - first very basic implementation still needs a number of cleanups (and handling more of course) --- oox/inc/oox/export/starmathimport.hxx | 57 +++++++++++++++++++++++++- oox/source/export/ooxmlexport.cxx | 75 +++++++++++++++++++++++++++++++++++ 2 files changed, 131 insertions(+), 1 deletion(-) (limited to 'oox') 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 +#include +#include +#include #include +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 #include +#include +#include + +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: */ -- cgit