diff options
author | Luboš Luňák <l.lunak@suse.cz> | 2011-11-18 18:09:43 +0100 |
---|---|---|
committer | Luboš Luňák <l.lunak@suse.cz> | 2011-11-24 18:43:57 +0100 |
commit | e9462ed2d978dc3e641227ea9f553eeed4d81a97 (patch) | |
tree | 8b77274817348852458ed19be1bd46bb66d0a749 /oox | |
parent | 1d163e4835b4906eb4559851e5ab2470b26332fe (diff) |
ooxml mathml import - first very basic implementation
still needs a number of cleanups (and handling more of course)
Diffstat (limited to 'oox')
-rw-r--r-- | oox/inc/oox/export/starmathimport.hxx | 57 | ||||
-rw-r--r-- | oox/source/export/ooxmlexport.cxx | 75 |
2 files changed, 131 insertions, 1 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: */ |