summaryrefslogtreecommitdiff
path: root/writerfilter
diff options
context:
space:
mode:
authorLuboš Luňák <l.lunak@suse.cz>2011-11-15 13:47:36 +0100
committerLuboš Luňák <l.lunak@suse.cz>2011-11-24 18:43:56 +0100
commit1acdbe4dfe0de152080992110efbb67e0639912d (patch)
tree134a06931453bb795ae48946750edcae12d159a0 /writerfilter
parent49e4c3e5e139f0443e5432d99d6514038b62ce84 (diff)
initial (very hacky) work on mathml ooxml import
This commit needs to be generally reworked for upstream, but it more or less works.
Diffstat (limited to 'writerfilter')
-rw-r--r--writerfilter/source/dmapper/DomainMapper.cxx8
-rw-r--r--writerfilter/source/dmapper/DomainMapper_Impl.cxx43
-rw-r--r--writerfilter/source/dmapper/DomainMapper_Impl.hxx1
-rw-r--r--writerfilter/source/dmapper/GraphicImport.cxx4
-rw-r--r--writerfilter/source/dmapper/OLEHandler.cxx4
-rw-r--r--writerfilter/source/dmapper/PropertyIds.cxx1
-rw-r--r--writerfilter/source/dmapper/PropertyIds.hxx1
-rw-r--r--writerfilter/source/ooxml/OOXMLFactory.hxx1
-rw-r--r--writerfilter/source/ooxml/OOXMLFastContextHandler.cxx64
-rw-r--r--writerfilter/source/ooxml/OOXMLFastContextHandler.hxx25
-rw-r--r--writerfilter/source/ooxml/OOXMLPropertySetImpl.cxx29
-rw-r--r--writerfilter/source/ooxml/OOXMLPropertySetImpl.hxx14
-rw-r--r--writerfilter/source/ooxml/model.xml2
13 files changed, 197 insertions, 0 deletions
diff --git a/writerfilter/source/dmapper/DomainMapper.cxx b/writerfilter/source/dmapper/DomainMapper.cxx
index f7ede2a85c39..59d05155f84f 100644
--- a/writerfilter/source/dmapper/DomainMapper.cxx
+++ b/writerfilter/source/dmapper/DomainMapper.cxx
@@ -76,6 +76,7 @@
#include <com/sun/star/text/WritingMode2.hpp>
#include <com/sun/star/text/XFootnote.hpp>
#include <com/sun/star/style/NumberingType.hpp>
+#include <com/sun/star/text/TextContentAnchorType.hpp>
#include <comphelper/types.hxx>
#include <comphelper/storagehelper.hxx>
@@ -1195,12 +1196,19 @@ 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);
m_pImpl->ImportGraphic( val.getProperties(), IMPORT_AS_DETECTED_INLINE );
}
break;
+ case NS_ooxml::LN_starmath:
+ {
+ fprintf(stderr,"STARMATH3\n");
+ m_pImpl->appendStarMath( val );
+ 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/DomainMapper_Impl.cxx b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
index a77d838f96e4..f358ea13d1fd 100644
--- a/writerfilter/source/dmapper/DomainMapper_Impl.cxx
+++ b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
@@ -25,6 +25,9 @@
* for a copy of the LGPLv3 License.
*
************************************************************************/
+
+#include <oox/export/starmathimport.hxx>
+
#include <DomainMapper_Impl.hxx>
#include <ConversionHelper.hxx>
#include <DomainMapperTableHandler.hxx>
@@ -70,6 +73,7 @@
#include <com/sun/star/util/DateTime.hpp>
#include <com/sun/star/util/XNumberFormatsSupplier.hpp>
#include <com/sun/star/util/XNumberFormats.hpp>
+#include <com/sun/star/embed/XEmbeddedObject.hpp>
#include <rtl/ustrbuf.hxx>
#include <rtl/string.h>
#include "FieldTypes.hxx"
@@ -1086,6 +1090,45 @@ 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 );
+ 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 )
+ {
+ (void)rEx;
+ OSL_FAIL( "Exception in creation of OLE object" );
+ }
+ }
+}
uno::Reference< beans::XPropertySet > DomainMapper_Impl::appendTextSectionAfter(
uno::Reference< text::XTextRange >& xBefore )
diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.hxx b/writerfilter/source/dmapper/DomainMapper_Impl.hxx
index e3b3fa11e800..926caeacebcc 100644
--- a/writerfilter/source/dmapper/DomainMapper_Impl.hxx
+++ b/writerfilter/source/dmapper/DomainMapper_Impl.hxx
@@ -408,6 +408,7 @@ public:
void appendTextContent( const ::com::sun::star::uno::Reference< ::com::sun::star::text::XTextContent >,
const uno::Sequence< beans::PropertyValue > );
void appendOLE( const ::rtl::OUString& rStreamName, OLEHandlerPtr pOleHandler );
+ void appendStarMath( const Value& v );
::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySet > appendTextSectionAfter(
::com::sun::star::uno::Reference< ::com::sun::star::text::XTextRange >& xBefore );
diff --git a/writerfilter/source/dmapper/GraphicImport.cxx b/writerfilter/source/dmapper/GraphicImport.cxx
index 744361dfc494..4e9446b49a44 100644
--- a/writerfilter/source/dmapper/GraphicImport.cxx
+++ b/writerfilter/source/dmapper/GraphicImport.cxx
@@ -874,6 +874,7 @@ 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;
@@ -950,6 +951,9 @@ 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 907e4a760b86..6e9cbbdaa0f3 100644
--- a/writerfilter/source/dmapper/OLEHandler.cxx
+++ b/writerfilter/source/dmapper/OLEHandler.cxx
@@ -102,6 +102,7 @@ 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() )
@@ -134,6 +135,9 @@ 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/dmapper/PropertyIds.cxx b/writerfilter/source/dmapper/PropertyIds.cxx
index d87d17106815..173be40f5a61 100644
--- a/writerfilter/source/dmapper/PropertyIds.cxx
+++ b/writerfilter/source/dmapper/PropertyIds.cxx
@@ -317,6 +317,7 @@ const rtl::OUString& PropertyNameSupplier::GetName( PropertyIds eId ) const
case PROP_HELP: sName = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Help")); break;
case PROP_HEADING_STYLE_NAME: sName = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("HeadingStyleName")); break;
case PROP_FRM_DIRECTION: sName = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("FRMDirection")); break;
+ case PROP_EMBEDDED_OBJECT : sName = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("EmbeddedObject")); break;
}
::std::pair<PropertyNameMap_t::iterator,bool> aInsertIt =
m_pImpl->aNameMap.insert( PropertyNameMap_t::value_type( eId, sName ));
diff --git a/writerfilter/source/dmapper/PropertyIds.hxx b/writerfilter/source/dmapper/PropertyIds.hxx
index 81afa294752c..dd20f065f11b 100644
--- a/writerfilter/source/dmapper/PropertyIds.hxx
+++ b/writerfilter/source/dmapper/PropertyIds.hxx
@@ -290,6 +290,7 @@ enum PropertyIds
,PROP_WIDTH_TYPE
,PROP_WRITING_MODE
/*253*/ ,PROP_FRM_DIRECTION
+ ,PROP_EMBEDDED_OBJECT
};
struct PropertyNameSupplier_Impl;
class PropertyNameSupplier
diff --git a/writerfilter/source/ooxml/OOXMLFactory.hxx b/writerfilter/source/ooxml/OOXMLFactory.hxx
index 28dda006ec43..ce892b457cf2 100644
--- a/writerfilter/source/ooxml/OOXMLFactory.hxx
+++ b/writerfilter/source/ooxml/OOXMLFactory.hxx
@@ -62,6 +62,7 @@ enum ResourceType_t {
RT_TextTableRow,
RT_TextTable,
RT_PropertyTable,
+ RT_Math,
RT_Any
};
diff --git a/writerfilter/source/ooxml/OOXMLFastContextHandler.cxx b/writerfilter/source/ooxml/OOXMLFastContextHandler.cxx
index b38da42943a1..10a0331d6668 100644
--- a/writerfilter/source/ooxml/OOXMLFastContextHandler.cxx
+++ b/writerfilter/source/ooxml/OOXMLFastContextHandler.cxx
@@ -39,6 +39,9 @@
#include <ooxml/OOXMLnamespaceids.hxx>
#include <dmapper/DomainMapper.hxx>
#include <GraphicHelpers.hxx>
+#include <comphelper/embeddedobjectcontainer.hxx>
+#include <tools/globname.hxx>
+#include <comphelper/classids.hxx>
#include "OOXMLFastContextHandler.hxx"
#include "OOXMLFactory.hxx"
#include "Handler.hxx"
@@ -1902,6 +1905,7 @@ 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 );
}
@@ -2361,6 +2365,66 @@ Token_t OOXMLFastContextHandlerWrapper::getToken() const
return nResult;
}
+
+/*
+ class OOXMLFastContextHandlerMath
+ */
+
+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 );
+ if (isForwardEvents())
+ {
+ OOXMLPropertySet * pProps = new OOXMLPropertySetImpl();
+ OOXMLValue::Pointer_t pVal( new OOXMLStarMathValue( ref ));
+ OOXMLProperty::Pointer_t pProp( new OOXMLPropertyImpl( NS_ooxml::LN_starmath, pVal, OOXMLPropertyImpl::ATTRIBUTE ));
+ pProps->add( pProp );
+ mpStream->props( writerfilter::Reference< Properties >::Pointer_t( pProps ));
+ }
+}
+
+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 );
+}
+
+void OOXMLFastContextHandlerMath::lcl_endFastElement(Token_t Element)
+ throw (uno::RuntimeException, xml::sax::SAXException)
+{
+ fprintf( stderr, "MMM end %d\n", Element );
+ OOXMLFastContextHandlerProperties::lcl_endFastElement( Element );
+}
+
+uno::Reference< xml::sax::XFastContextHandler >
+OOXMLFastContextHandlerMath::lcl_createFastChildContext(Token_t Element,
+ const uno::Reference< xml::sax::XFastAttributeList >& Attribs)
+ throw (uno::RuntimeException, xml::sax::SAXException)
+{
+ fprintf( stderr, "MMM child %d\n", Element );
+ uno::Reference< xml::sax::XFastContextHandler > xContextHandler;
+ xContextHandler.set( this );
+ return xContextHandler;
+}
+
+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());
+}
+
+
}}
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/writerfilter/source/ooxml/OOXMLFastContextHandler.hxx b/writerfilter/source/ooxml/OOXMLFastContextHandler.hxx
index b2f82c80fbe1..9f7c082c98ac 100644
--- a/writerfilter/source/ooxml/OOXMLFastContextHandler.hxx
+++ b/writerfilter/source/ooxml/OOXMLFastContextHandler.hxx
@@ -42,6 +42,7 @@
#include "OOXMLDocumentImpl.hxx"
#include "RefAndPointer.hxx"
#include <ooxml/OOXMLFastTokens.hxx>
+#include <svtools/embedhlp.hxx>
namespace writerfilter {
namespace ooxml
@@ -636,6 +637,30 @@ private:
OOXMLFastContextHandler * getFastContextHandler() const;
};
+
+
+class OOXMLFastContextHandlerMath: public OOXMLFastContextHandlerProperties
+{
+public:
+ explicit OOXMLFastContextHandlerMath(OOXMLFastContextHandler * pContext);
+ virtual ~OOXMLFastContextHandlerMath();
+
+ virtual string getType() const { return "Math"; }
+
+protected:
+ virtual void lcl_startFastElement(Token_t Element, const uno::Reference< xml::sax::XFastAttributeList > & Attribs)
+ throw (uno::RuntimeException, xml::sax::SAXException);
+
+ virtual void lcl_endFastElement(Token_t Element) throw (uno::RuntimeException, xml::sax::SAXException);
+
+ virtual uno::Reference< xml::sax::XFastContextHandler > lcl_createFastChildContext(Token_t Element,
+ const uno::Reference< xml::sax::XFastAttributeList > & Attribs)
+ throw (uno::RuntimeException, xml::sax::SAXException);
+
+ virtual void lcl_characters(const ::rtl::OUString & aChars) throw (uno::RuntimeException, xml::sax::SAXException);
+};
+
+
}}
#endif // INCLUDED_OOXML_FAST_CONTEXT_HANDLER_HXX
diff --git a/writerfilter/source/ooxml/OOXMLPropertySetImpl.cxx b/writerfilter/source/ooxml/OOXMLPropertySetImpl.cxx
index 384ab9ca4652..52dd4b7f1abf 100644
--- a/writerfilter/source/ooxml/OOXMLPropertySetImpl.cxx
+++ b/writerfilter/source/ooxml/OOXMLPropertySetImpl.cxx
@@ -690,6 +690,35 @@ OOXMLValue * OOXMLShapeValue::clone() const
}
/*
+ class OOXMLStarMathValue
+ */
+
+
+OOXMLStarMathValue::OOXMLStarMathValue( uno::Reference< embed::XEmbeddedObject > c )
+: component(c)
+{
+}
+
+OOXMLStarMathValue::~OOXMLStarMathValue()
+{
+}
+
+uno::Any OOXMLStarMathValue::getAny() const
+{
+ return uno::Any(component);
+}
+
+string OOXMLStarMathValue::toString() const
+{
+ return "StarMath";
+}
+
+OOXMLValue * OOXMLStarMathValue::clone() const
+{
+ return new OOXMLStarMathValue( component );
+}
+
+/*
class OOXMLTableImpl
*/
diff --git a/writerfilter/source/ooxml/OOXMLPropertySetImpl.hxx b/writerfilter/source/ooxml/OOXMLPropertySetImpl.hxx
index 34824101431d..84ecb930caed 100644
--- a/writerfilter/source/ooxml/OOXMLPropertySetImpl.hxx
+++ b/writerfilter/source/ooxml/OOXMLPropertySetImpl.hxx
@@ -31,6 +31,7 @@
#include <vector>
#include "OOXMLPropertySet.hxx"
#include "OOXMLBinaryObjectReference.hxx"
+#include <com/sun/star/embed/XEmbeddedObject.hpp>
namespace com {
namespace sun {
@@ -235,6 +236,19 @@ public:
virtual OOXMLValue * clone() const;
};
+class OOXMLStarMathValue : public OOXMLValue
+{
+protected:
+ uno::Reference< embed::XEmbeddedObject > component;
+public:
+ explicit OOXMLStarMathValue( uno::Reference< embed::XEmbeddedObject > component );
+ virtual ~OOXMLStarMathValue();
+
+ virtual uno::Any getAny() const;
+ virtual string toString() const;
+ virtual OOXMLValue * clone() const;
+};
+
class OOXMLTableImpl : public OOXMLTable
{
public:
diff --git a/writerfilter/source/ooxml/model.xml b/writerfilter/source/ooxml/model.xml
index 81d7794074b5..0a1d77a8b065 100644
--- a/writerfilter/source/ooxml/model.xml
+++ b/writerfilter/source/ooxml/model.xml
@@ -20,6 +20,7 @@
<token tokenid="ooxml:object"/>
<token tokenid="ooxml:tblStart"/>
<token tokenid="ooxml:ffdata"/>
+ <token tokenid="ooxml:starmath"/>
<namespace name="dml-stylesheet" url="http://schemas.openxmlformats.org/drawingml/2006/main" file="dml-stylesheet.rng">
<start name="theme"/>
<start name="themeOverride"/>
@@ -23622,5 +23623,6 @@
<resource name="document" resource="Stream" tag="content"/>
<resource name="glossaryDocument" resource="Stream" tag="content"/>
<resource name="CT_TxbxContent" resource="Stream" tag="shape"/>
+ <resource name="CT_OMath" resource="Math" tag="math"/>
</namespace>
</model>