[Libreoffice-commits] .: Branch 'feature/ooxmlmathimport' - 4 commits - oox/inc oox/source starmath/inc starmath/source sw/inc sw/source writerfilter/source
Lubos Lunak
llunak at kemper.freedesktop.org
Fri Nov 25 08:08:56 PST 2011
oox/inc/oox/mathml/import.hxx | 14 ++---
oox/inc/oox/mathml/importutils.hxx | 21 +++++++
oox/source/mathml/import.cxx | 4 -
starmath/inc/unomodel.hxx | 1
starmath/source/ooxmlimport.cxx | 16 +++---
starmath/source/unomodel.cxx | 5 +
sw/inc/docsh.hxx | 2
sw/inc/unotxdoc.hxx | 5 -
sw/source/core/unocore/unoframe.cxx | 10 +++
sw/source/ui/app/docsh2.cxx | 12 ----
sw/source/ui/uno/unotxdoc.cxx | 5 -
writerfilter/source/dmapper/DomainMapper_Impl.cxx | 58 ++++++++++++----------
12 files changed, 85 insertions(+), 68 deletions(-)
New commits:
commit dc4ca1bd0cf5e42009c92bd76c0d7d5ed23cb3ab
Author: LuboÅ¡ LuÅák <l.lunak at suse.cz>
Date: Fri Nov 25 17:08:17 2011 +0100
set properly initial size of starmath component when importing docx
diff --git a/oox/inc/oox/mathml/import.hxx b/oox/inc/oox/mathml/import.hxx
index 7154264..8c922ab 100644
--- a/oox/inc/oox/mathml/import.hxx
+++ b/oox/inc/oox/mathml/import.hxx
@@ -29,6 +29,7 @@
#define _STARMATHIMPORT_HXX
#include <com/sun/star/embed/XEmbeddedObject.hpp>
+#include <tools/gen.hxx>
#include <oox/dllapi.h>
@@ -40,11 +41,17 @@ namespace formulaimport
class XmlStream;
}
+/**
+ Interface class, StarMath will implement readFormulaOoxml() to read OOXML
+ representing the formula and getFormulaSize() to provide the size of the resulting
+ formula.
+ */
class OOX_DLLPUBLIC FormulaImportBase
{
public:
FormulaImportBase();
virtual void readFormulaOoxml( oox::formulaimport::XmlStream& stream ) = 0;
+ virtual Size getFormulaSize() const = 0;
};
} // namespace
diff --git a/starmath/inc/unomodel.hxx b/starmath/inc/unomodel.hxx
index 5243d41..cf01ec4 100644
--- a/starmath/inc/unomodel.hxx
+++ b/starmath/inc/unomodel.hxx
@@ -108,6 +108,7 @@ public:
virtual void writeFormulaOoxml( ::sax_fastparser::FSHelperPtr m_pSerializer, oox::core::OoxmlVersion version );
// oox::FormulaImportBase
virtual void readFormulaOoxml( oox::formulaimport::XmlStream& stream );
+ virtual Size getFormulaSize() const;
static ::com::sun::star::uno::Sequence< rtl::OUString > getSupportedServiceNames_Static();
static ::rtl::OUString getImplementationName_Static();
diff --git a/starmath/source/unomodel.cxx b/starmath/source/unomodel.cxx
index 4f0d2f0..35cb20d 100644
--- a/starmath/source/unomodel.cxx
+++ b/starmath/source/unomodel.cxx
@@ -1142,4 +1142,9 @@ void SmModel::readFormulaOoxml( oox::formulaimport::XmlStream& stream )
static_cast< SmDocShell* >( GetObjectShell())->readFormulaOoxml( stream );
}
+Size SmModel::getFormulaSize() const
+{
+ return static_cast< SmDocShell* >( GetObjectShell())->GetSize();
+}
+
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.cxx b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
index 5892864..4174964 100644
--- a/writerfilter/source/dmapper/DomainMapper_Impl.cxx
+++ b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
@@ -75,6 +75,7 @@
#include <rtl/ustrbuf.hxx>
#include <rtl/string.h>
#include "FieldTypes.hxx"
+#include <oox/mathml/import.hxx>
#include <tools/string.hxx>
#ifdef DEBUG_DOMAINMAPPER
@@ -1102,6 +1103,15 @@ void DomainMapper_Impl::appendStarMath( const Value& val )
xStarMathProperties->setPropertyValue(PropertyNameSupplier::GetPropertyNameSupplier().GetName( PROP_STREAM_NAME ),
val.getAny());
+
+ uno::Reference< uno::XInterface > xInterface( formula->getComponent(), uno::UNO_QUERY );
+ Size size( 1000, 1000 );
+ if( oox::FormulaImportBase* formulaimport = dynamic_cast< oox::FormulaImportBase* >( xInterface.get()))
+ size = formulaimport->getFormulaSize();
+ xStarMathProperties->setPropertyValue(PropertyNameSupplier::GetPropertyNameSupplier().GetName( PROP_WIDTH ),
+ uno::makeAny( int(size.Width())));
+ xStarMathProperties->setPropertyValue(PropertyNameSupplier::GetPropertyNameSupplier().GetName( PROP_HEIGHT ),
+ uno::makeAny( int(size.Height())));
// mimic the treatment of graphics here.. it seems anchoring as character
// gives a better ( visually ) result
xStarMathProperties->setPropertyValue(PropertyNameSupplier::GetPropertyNameSupplier().GetName( PROP_ANCHOR_TYPE ),
commit 0f73f21fd1aef26222f2568d343dcffe3e2a6c17
Author: LuboÅ¡ LuÅák <l.lunak at suse.cz>
Date: Fri Nov 25 15:15:47 2011 +0100
the bit hackish addFormula() shortcut is no longer necessary
diff --git a/oox/inc/oox/mathml/import.hxx b/oox/inc/oox/mathml/import.hxx
index 961a4f6..7154264 100644
--- a/oox/inc/oox/mathml/import.hxx
+++ b/oox/inc/oox/mathml/import.hxx
@@ -40,13 +40,6 @@ 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:
diff --git a/oox/source/mathml/import.cxx b/oox/source/mathml/import.cxx
index 4553006..bb13db3 100644
--- a/oox/source/mathml/import.cxx
+++ b/oox/source/mathml/import.cxx
@@ -35,10 +35,6 @@ FormulaImportBase::FormulaImportBase()
{
}
-FormulaImportHelper::FormulaImportHelper()
-{
-}
-
} // namespace
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sw/inc/docsh.hxx b/sw/inc/docsh.hxx
index e62699a..96a1eaa 100644
--- a/sw/inc/docsh.hxx
+++ b/sw/inc/docsh.hxx
@@ -143,8 +143,6 @@ protected:
public:
using SotObject::GetInterface;
- void addFormula( com::sun::star::uno::Reference< com::sun::star::embed::XEmbeddedObject > p);
-
// but we implement this ourselves.
SFX_DECL_INTERFACE(SW_DOCSHELL)
SFX_DECL_OBJECTFACTORY()
diff --git a/sw/inc/unotxdoc.hxx b/sw/inc/unotxdoc.hxx
index ca21090..5d61a9a 100644
--- a/sw/inc/unotxdoc.hxx
+++ b/sw/inc/unotxdoc.hxx
@@ -181,8 +181,7 @@ SwXTextDocumentBaseClass;
class SW_DLLPUBLIC SwXTextDocument : public SwXTextDocumentBaseClass,
public SvxFmMSFactory,
- public SfxBaseModel,
- public oox::FormulaImportHelper
+ public SfxBaseModel
{
ActionContextArr aActionArr;
SwRefreshListenerContainer aRefreshCont;
@@ -254,8 +253,6 @@ public:
virtual void SAL_CALL acquire( ) throw();
virtual void SAL_CALL release( ) throw();
- virtual void addFormula( com::sun::star::uno::Reference< com::sun::star::embed::XEmbeddedObject > p );
-
//XWeak
virtual css::uno::Reference< css::uno::XAdapter > SAL_CALL queryAdapter( ) throw(css::uno::RuntimeException);
diff --git a/sw/source/core/unocore/unoframe.cxx b/sw/source/core/unocore/unoframe.cxx
index 91e2152..8579f4a 100644
--- a/sw/source/core/unocore/unoframe.cxx
+++ b/sw/source/core/unocore/unoframe.cxx
@@ -2312,6 +2312,16 @@ void SwXFrame::attachToRange(const uno::Reference< text::XTextRange > & xTextRan
pDoc->GetIDocumentUndoRedo().StartUndo(UNDO_INSERT, NULL);
+ // Not sure if these setParent() and InsertEmbeddedObject() calls are really
+ // needed, it seems to work without, but logic from code elsewhere suggests
+ // they should be done.
+ SfxObjectShell& mrPers = *pDoc->GetPersist();
+ uno::Reference < container::XChild > xChild( obj, uno::UNO_QUERY );
+ if ( xChild.is() )
+ xChild->setParent( mrPers.GetModel() );
+ ::rtl::OUString rName;
+ mrPers.GetEmbeddedObjectContainer().InsertEmbeddedObject( obj, rName );
+
SwFlyFrmFmt* pFrmFmt = 0;
pFrmFmt = pDoc->Insert( aPam, xObj, &aFrmSet, NULL, NULL );
pDoc->GetIDocumentUndoRedo().EndUndo(UNDO_INSERT, NULL);
diff --git a/sw/source/ui/app/docsh2.cxx b/sw/source/ui/app/docsh2.cxx
index aa1d5d1..1c649e1 100644
--- a/sw/source/ui/app/docsh2.cxx
+++ b/sw/source/ui/app/docsh2.cxx
@@ -157,18 +157,6 @@ SfxDocumentInfoDialog* SwDocShell::CreateDocumentInfoDialog(
return pDlg;
}
-void SwDocShell::addFormula( uno::Reference< embed::XEmbeddedObject > p )
-{
- SfxObjectShell& mrPers = *GetDoc()->GetPersist();
- uno::Reference < container::XChild > xChild( p, uno::UNO_QUERY );
- if ( xChild.is() )
- xChild->setParent( mrPers.GetModel() );
- ::rtl::OUString rName;
- bool bSuccess = mrPers.GetEmbeddedObjectContainer().InsertEmbeddedObject( p, rName );
- if (bSuccess)
- {}
-}
-
// Disable "multiple layout"
void SwDocShell::ToggleBrowserMode(sal_Bool bSet, SwView* _pView )
diff --git a/sw/source/ui/uno/unotxdoc.cxx b/sw/source/ui/uno/unotxdoc.cxx
index 4b57686..b55cc3f 100644
--- a/sw/source/ui/uno/unotxdoc.cxx
+++ b/sw/source/ui/uno/unotxdoc.cxx
@@ -409,11 +409,6 @@ SwXTextDocument::~SwXTextDocument()
delete m_pRenderData;
}
-void SwXTextDocument::addFormula( uno::Reference< embed::XEmbeddedObject > p )
-{
- pDocShell->addFormula(p);
-}
-
SwXDocumentPropertyHelper * SwXTextDocument::GetPropertyHelper ()
{
if(!xPropertyHelper.is())
diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.cxx b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
index 4833bba..5892864 100644
--- a/writerfilter/source/dmapper/DomainMapper_Impl.cxx
+++ b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
@@ -26,8 +26,6 @@
*
************************************************************************/
-#include <oox/mathml/import.hxx>
-
#include <DomainMapper_Impl.hxx>
#include <ConversionHelper.hxx>
#include <DomainMapperTableHandler.hxx>
@@ -1096,8 +1094,6 @@ void DomainMapper_Impl::appendStarMath( const Value& val )
val.getAny() >>= formula;
if( formula.is() )
{
- 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
{
commit be696e6c416b49a58ab18d13a0e4b43b2334b2de
Author: LuboÅ¡ LuÅák <l.lunak at suse.cz>
Date: Fri Nov 25 13:43:52 2011 +0100
clean up and format code
diff --git a/writerfilter/source/dmapper/DomainMapper_Impl.cxx b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
index 389b2b3..4833bba 100644
--- a/writerfilter/source/dmapper/DomainMapper_Impl.cxx
+++ b/writerfilter/source/dmapper/DomainMapper_Impl.cxx
@@ -1092,32 +1092,32 @@ void DomainMapper_Impl::appendOLE( const ::rtl::OUString& rStreamName, OLEHandle
void DomainMapper_Impl::appendStarMath( const Value& val )
{
- uno::Reference< embed::XEmbeddedObject > formula;
- val.getAny() >>= formula;
- if( formula.is() )
- {
- 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
+ uno::Reference< embed::XEmbeddedObject > formula;
+ val.getAny() >>= formula;
+ if( formula.is() )
{
- uno::Reference< text::XTextContent > xOLE( m_xTextFactory->createInstance(sEmbeddedService), uno::UNO_QUERY_THROW );
- uno::Reference< beans::XPropertySet > xOLEProperties(xOLE, uno::UNO_QUERY_THROW);
-
- xOLEProperties->setPropertyValue(PropertyNameSupplier::GetPropertyNameSupplier().GetName( PROP_STREAM_NAME ),
- val.getAny());
- // 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 ) );
- appendTextContent( xOLE, uno::Sequence< beans::PropertyValue >() );
+ 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
+ {
+ uno::Reference< text::XTextContent > xStarMath( m_xTextFactory->createInstance(sEmbeddedService), uno::UNO_QUERY_THROW );
+ uno::Reference< beans::XPropertySet > xStarMathProperties(xStarMath, uno::UNO_QUERY_THROW);
+ xStarMathProperties->setPropertyValue(PropertyNameSupplier::GetPropertyNameSupplier().GetName( PROP_STREAM_NAME ),
+ val.getAny());
+ // mimic the treatment of graphics here.. it seems anchoring as character
+ // gives a better ( visually ) result
+ xStarMathProperties->setPropertyValue(PropertyNameSupplier::GetPropertyNameSupplier().GetName( PROP_ANCHOR_TYPE ),
+ uno::makeAny( text::TextContentAnchorType_AS_CHARACTER ) );
+ appendTextContent( xStarMath, uno::Sequence< beans::PropertyValue >() );
+ }
+ catch( const uno::Exception& rEx )
+ {
+ (void)rEx;
+ OSL_FAIL( "Exception in creation of StarMath object" );
+ }
}
- catch( const uno::Exception& rEx )
- {
- (void)rEx;
- OSL_FAIL( "Exception in creation of OLE object" );
- }
- }
}
uno::Reference< beans::XPropertySet > DomainMapper_Impl::appendTextSectionAfter(
commit 16ebc1b2bf568f1c569b09e6250dfe4a59c94db2
Author: LuboÅ¡ LuÅák <l.lunak at suse.cz>
Date: Fri Nov 25 13:16:04 2011 +0100
simplify attribute retrieval syntax a bit
diff --git a/oox/inc/oox/mathml/importutils.hxx b/oox/inc/oox/mathml/importutils.hxx
index ad6ad6b..9a915bb 100644
--- a/oox/inc/oox/mathml/importutils.hxx
+++ b/oox/inc/oox/mathml/importutils.hxx
@@ -91,6 +91,15 @@ public:
AttributeList attributes;
rtl::OUString text;
/**
+ This function returns value of the given attribute, or the passed default value if not found.
+ The type of the default value selects the return type (OUString here).
+ */
+ rtl::OUString attribute( int token, const rtl::OUString& def = rtl::OUString()) const;
+ /**
+ @overload
+ */
+ bool attribute( int token, bool def ) const;
+ /**
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 ))'.
*/
@@ -169,6 +178,18 @@ public:
void appendCharacters( const rtl::OUString& characters );
};
+inline
+rtl::OUString XmlStream::Tag::attribute( int t, const rtl::OUString& def ) const
+{
+ return attributes.attribute( t, def );
+}
+
+inline
+bool XmlStream::Tag::attribute( int t, bool def ) const
+{
+ return attributes.attribute( t, def );
+}
+
} // namespace
} // namespace
diff --git a/starmath/source/ooxmlimport.cxx b/starmath/source/ooxmlimport.cxx
index a3b3648..b4a2ee0 100644
--- a/starmath/source/ooxmlimport.cxx
+++ b/starmath/source/ooxmlimport.cxx
@@ -106,7 +106,7 @@ OUString SmOoxmlImport::handleAcc()
{
if( XmlStream::Tag chr = stream.checkOpeningTag( M_TOKEN( chr )))
{
- acc = chr.attributes.attribute( M_TOKEN( val ));
+ acc = chr.attribute( M_TOKEN( val ));
stream.ensureClosingTag( M_TOKEN( chr ));
}
stream.ensureClosingTag( M_TOKEN( accPr ));
@@ -167,9 +167,9 @@ OUString SmOoxmlImport::handleBar()
{
if( XmlStream::Tag pos = stream.checkOpeningTag( M_TOKEN( pos )))
{
- if( pos.attributes.attribute( M_TOKEN( val )) == STR( "top" ))
+ if( pos.attribute( M_TOKEN( val )) == STR( "top" ))
topbot = top;
- else if( pos.attributes.attribute( M_TOKEN( val )) == STR( "bot" ))
+ else if( pos.attribute( M_TOKEN( val )) == STR( "bot" ))
topbot = bot;
stream.ensureClosingTag( M_TOKEN( pos ));
}
@@ -191,7 +191,7 @@ OUString SmOoxmlImport::handleBorderBox()
{
if( XmlStream::Tag strikeH = stream.checkOpeningTag( M_TOKEN( strikeH )))
{
- if( strikeH.attributes.attribute( M_TOKEN( val ), false ))
+ if( strikeH.attribute( M_TOKEN( val ), false ))
isStrikeH = true;
stream.ensureClosingTag( M_TOKEN( strikeH ));
}
@@ -250,11 +250,11 @@ OUString SmOoxmlImport::handleF()
{
if( XmlStream::Tag type = stream.checkOpeningTag( M_TOKEN( type )))
{
- if( type.attributes.attribute( M_TOKEN( val )) == STR( "bar" ))
+ if( type.attribute( M_TOKEN( val )) == STR( "bar" ))
operation = bar;
- else if( type.attributes.attribute( M_TOKEN( val )) == STR( "lin" ))
+ else if( type.attribute( M_TOKEN( val )) == STR( "lin" ))
operation = lin;
- else if( type.attributes.attribute( M_TOKEN( val )) == STR( "noBar" ))
+ else if( type.attribute( M_TOKEN( val )) == STR( "noBar" ))
operation = noBar;
stream.ensureClosingTag( M_TOKEN( type ));
}
@@ -292,7 +292,7 @@ OUString SmOoxmlImport::handleR()
XmlStream::Tag rtag = stream.ensureOpeningTag( M_TOKEN( t ));
// TODO bail out if failure?
OUString text = rtag.text;
- if( rtag.attributes.attribute( OOX_TOKEN( xml, space )) != STR( "preserve" ))
+ if( rtag.attribute( OOX_TOKEN( xml, space )) != STR( "preserve" ))
text = text.trim();
stream.ensureClosingTag( M_TOKEN( t ));
stream.ensureClosingTag( M_TOKEN( r ));
More information about the Libreoffice-commits
mailing list