2015-04-15 07:55:15 -05:00
|
|
|
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
|
|
|
|
/*
|
|
|
|
* This file is part of the LibreOffice project.
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
* file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <memory>
|
|
|
|
|
|
|
|
#include <unotools/mediadescriptor.hxx>
|
|
|
|
#include <unotools/ucbstreamhelper.hxx>
|
|
|
|
|
|
|
|
#include <document.hxx>
|
|
|
|
#include <mathtype.hxx>
|
|
|
|
#include <unomodel.hxx>
|
|
|
|
|
|
|
|
using namespace ::com::sun::star;
|
|
|
|
|
|
|
|
/// Invokes the MathType importer via UNO.
|
|
|
|
class MathTypeFilter : public cppu::WeakImplHelper
|
|
|
|
<
|
|
|
|
document::XFilter,
|
|
|
|
document::XImporter,
|
|
|
|
lang::XServiceInfo
|
|
|
|
>
|
|
|
|
{
|
|
|
|
uno::Reference<lang::XComponent> m_xDstDoc;
|
|
|
|
|
|
|
|
public:
|
2015-12-21 05:44:24 -06:00
|
|
|
MathTypeFilter();
|
2015-04-15 07:55:15 -05:00
|
|
|
virtual ~MathTypeFilter();
|
|
|
|
|
|
|
|
// XFilter
|
2015-10-12 09:04:04 -05:00
|
|
|
virtual sal_Bool SAL_CALL filter(const uno::Sequence<beans::PropertyValue>& rDescriptor) throw (uno::RuntimeException, std::exception) override;
|
|
|
|
virtual void SAL_CALL cancel() throw (uno::RuntimeException, std::exception) override;
|
2015-04-15 07:55:15 -05:00
|
|
|
|
|
|
|
// XImporter
|
2015-10-12 09:04:04 -05:00
|
|
|
virtual void SAL_CALL setTargetDocument(const uno::Reference<lang::XComponent>& xDoc) throw (lang::IllegalArgumentException, uno::RuntimeException, std::exception) override;
|
2015-04-15 07:55:15 -05:00
|
|
|
|
|
|
|
// XServiceInfo
|
2015-10-12 09:04:04 -05:00
|
|
|
virtual OUString SAL_CALL getImplementationName() throw (uno::RuntimeException, std::exception) override;
|
|
|
|
virtual sal_Bool SAL_CALL supportsService(const OUString& ServiceName) throw (uno::RuntimeException, std::exception) override;
|
|
|
|
virtual uno::Sequence<OUString> SAL_CALL getSupportedServiceNames() throw (uno::RuntimeException, std::exception) override;
|
2015-04-15 07:55:15 -05:00
|
|
|
};
|
|
|
|
|
2015-12-21 05:44:24 -06:00
|
|
|
MathTypeFilter::MathTypeFilter()
|
2015-04-15 07:55:15 -05:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
MathTypeFilter::~MathTypeFilter()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
sal_Bool MathTypeFilter::filter(const uno::Sequence<beans::PropertyValue>& rDescriptor) throw(uno::RuntimeException, std::exception)
|
|
|
|
{
|
|
|
|
bool bSuccess = false;
|
2015-04-20 02:37:40 -05:00
|
|
|
try
|
2015-04-15 07:55:15 -05:00
|
|
|
{
|
2015-04-20 02:37:40 -05:00
|
|
|
utl::MediaDescriptor aMediaDesc(rDescriptor);
|
|
|
|
aMediaDesc.addInputStream();
|
|
|
|
uno::Reference<io::XInputStream> xInputStream;
|
|
|
|
aMediaDesc[utl::MediaDescriptor::PROP_INPUTSTREAM()] >>= xInputStream;
|
|
|
|
std::unique_ptr<SvStream> pStream(utl::UcbStreamHelper::CreateStream(xInputStream));
|
|
|
|
if (pStream)
|
2015-04-15 07:55:15 -05:00
|
|
|
{
|
2015-04-20 02:37:40 -05:00
|
|
|
if (SotStorage::IsStorageFile(pStream.get()))
|
2015-04-15 07:55:15 -05:00
|
|
|
{
|
2015-05-06 09:33:19 -05:00
|
|
|
tools::SvRef<SotStorage> aStorage(new SotStorage(pStream.get(), false));
|
2015-04-20 02:37:40 -05:00
|
|
|
// Is this a MathType Storage?
|
2015-11-06 02:37:28 -06:00
|
|
|
if (aStorage->IsStream("Equation Native"))
|
2015-04-15 07:55:15 -05:00
|
|
|
{
|
2015-04-20 02:37:40 -05:00
|
|
|
if (SmModel* pModel = dynamic_cast<SmModel*>(m_xDstDoc.get()))
|
2015-04-15 07:55:15 -05:00
|
|
|
{
|
2015-04-20 02:37:40 -05:00
|
|
|
SmDocShell* pDocShell = static_cast<SmDocShell*>(pModel->GetObjectShell());
|
|
|
|
OUString aText = pDocShell->GetText();
|
|
|
|
MathType aEquation(aText);
|
2016-01-25 06:28:48 -06:00
|
|
|
bSuccess = aEquation.Parse(aStorage);
|
2015-04-20 02:37:40 -05:00
|
|
|
if (bSuccess)
|
|
|
|
{
|
|
|
|
pDocShell->SetText(aText);
|
|
|
|
pDocShell->Parse();
|
|
|
|
}
|
2015-04-15 07:55:15 -05:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2015-04-20 02:37:40 -05:00
|
|
|
catch (const uno::Exception& rException)
|
|
|
|
{
|
|
|
|
SAL_WARN("starmath", "Exception caught: " << rException.Message);
|
|
|
|
}
|
2015-04-15 07:55:15 -05:00
|
|
|
return bSuccess;
|
|
|
|
}
|
|
|
|
|
|
|
|
void MathTypeFilter::cancel() throw(uno::RuntimeException, std::exception)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
void MathTypeFilter::setTargetDocument(const uno::Reference< lang::XComponent >& xDoc) throw(lang::IllegalArgumentException, uno::RuntimeException, std::exception)
|
|
|
|
{
|
|
|
|
m_xDstDoc = xDoc;
|
|
|
|
}
|
|
|
|
|
|
|
|
OUString MathTypeFilter::getImplementationName() throw(uno::RuntimeException, std::exception)
|
|
|
|
{
|
|
|
|
return OUString("com.sun.star.comp.Math.MathTypeFilter");
|
|
|
|
}
|
|
|
|
|
|
|
|
sal_Bool MathTypeFilter::supportsService(const OUString& rServiceName) throw(uno::RuntimeException, std::exception)
|
|
|
|
{
|
|
|
|
return cppu::supportsService(this, rServiceName);
|
|
|
|
}
|
|
|
|
|
|
|
|
uno::Sequence<OUString> MathTypeFilter::getSupportedServiceNames() throw(uno::RuntimeException, std::exception)
|
|
|
|
{
|
|
|
|
uno::Sequence<OUString> aRet =
|
|
|
|
{
|
|
|
|
OUString("com.sun.star.document.ImportFilter")
|
|
|
|
};
|
|
|
|
return aRet;
|
|
|
|
}
|
|
|
|
|
2015-12-22 06:43:57 -06:00
|
|
|
extern "C" SAL_DLLPUBLIC_EXPORT uno::XInterface* SAL_CALL com_sun_star_comp_Math_MathTypeFilter_get_implementation(uno::XComponentContext*, uno::Sequence<uno::Any> const&)
|
2015-04-15 07:55:15 -05:00
|
|
|
{
|
2015-12-21 05:44:24 -06:00
|
|
|
return cppu::acquire(new MathTypeFilter);
|
2015-04-15 07:55:15 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|