summaryrefslogtreecommitdiff
path: root/starmath
diff options
context:
space:
mode:
authordante <dante19031999@gmail.com>2021-08-20 04:35:20 +0200
committerNoel Grandin <noel.grandin@collabora.co.uk>2021-08-20 12:46:40 +0200
commit58a5bd793a2ed57077fc598281cc74e16373b877 (patch)
tree9f3161ee7d32ba8f0380a12dc0b439f829e88c96 /starmath
parent4f7dd4985dd11e2e797f0ab05eaa7982b5a83b46 (diff)
Fine tune new sm import / export
Change-Id: I7e7ec875b3d0f8f1d62f22270a306bc2f57421ba Reviewed-on: https://gerrit.libreoffice.org/c/core/+/120768 Tested-by: Jenkins Reviewed-by: Noel Grandin <noel.grandin@collabora.co.uk>
Diffstat (limited to 'starmath')
-rw-r--r--starmath/inc/mathml/export.hxx5
-rw-r--r--starmath/inc/mathml/import.hxx5
-rw-r--r--starmath/source/mathml/export.cxx103
-rw-r--r--starmath/source/mathml/import.cxx123
4 files changed, 158 insertions, 78 deletions
diff --git a/starmath/inc/mathml/export.hxx b/starmath/inc/mathml/export.hxx
index fa442b10d881..3209c5aadb46 100644
--- a/starmath/inc/mathml/export.hxx
+++ b/starmath/inc/mathml/export.hxx
@@ -82,6 +82,7 @@ public:
, m_bFlat(true)
, m_bUseHTMLMLEntities(false)
, m_pElementTree(nullptr)
+ , m_bUseExportTag(false)
{
}
@@ -101,7 +102,7 @@ protected:
const css::uno::Reference<css::lang::XComponent>& xComponent,
css::uno::Reference<css::uno::XComponentContext> const& rxContext,
css::uno::Reference<css::beans::XPropertySet> const& rPropSet,
- const char16_t* pComponentName);
+ const char16_t* pComponentName, int_fast16_t nSyntaxVersion);
/** export through an XML exporter component (storage version)
*/
@@ -110,7 +111,7 @@ protected:
const char16_t* pStreamName,
css::uno::Reference<css::uno::XComponentContext> const& rxContext,
css::uno::Reference<css::beans::XPropertySet> const& rPropSet,
- const char16_t* pComponentName);
+ const char16_t* pComponentName, int_fast16_t nSyntaxVersion);
/** export through an XML exporter component (memory stream version)
*/
diff --git a/starmath/inc/mathml/import.hxx b/starmath/inc/mathml/import.hxx
index ae72b7b89b6e..6266b5ede6c0 100644
--- a/starmath/inc/mathml/import.hxx
+++ b/starmath/inc/mathml/import.hxx
@@ -62,7 +62,8 @@ public:
const css::uno::Reference<css::lang::XComponent>& xModelComponent,
css::uno::Reference<css::uno::XComponentContext> const& rxContext,
css::uno::Reference<css::beans::XPropertySet> const& rPropSet,
- const char16_t* pFilterName, bool bEncrypted);
+ const char16_t* pFilterName, bool bEncrypted,
+ int_fast16_t nSyntaxVersion);
/** read a component from storage
*/
@@ -71,7 +72,7 @@ public:
const char16_t* pStreamName,
css::uno::Reference<css::uno::XComponentContext> const& rxContext,
css::uno::Reference<css::beans::XPropertySet> const& rPropSet,
- const char16_t* pFilterName);
+ const char16_t* pFilterName, int_fast16_t nSyntaxVersion);
/** read a component from text
*/
diff --git a/starmath/source/mathml/export.cxx b/starmath/source/mathml/export.cxx
index 76e79f1b7e75..11e91e35cbfc 100644
--- a/starmath/source/mathml/export.cxx
+++ b/starmath/source/mathml/export.cxx
@@ -53,6 +53,9 @@
#include <xparsmlbase.hxx>
#include <starmathdatabase.hxx>
+// Old parser
+#include <mathmlexport.hxx>
+
using namespace ::com::sun::star;
using namespace xmloff::token;
@@ -113,7 +116,7 @@ bool SmMLExportWrapper::Export(SfxMedium& rMedium)
if (pDocShell->GetMedium() != &rMedium)
{
SAL_WARN("starmath", "Input medium and sm document medium do not match");
- return false;
+ //return false;
}
// Fetch progress bar
@@ -156,7 +159,6 @@ bool SmMLExportWrapper::Export(SfxMedium& rMedium)
SAL_WARN("starmath", "Failed to fetch output storage");
return false;
}
- bool bOASIS = SotStorage::GetVersion(xStg) > SOFFICE_FILEFORMAT_60;
// TODO/LATER: handle the case of embedded links gracefully
if (bEmbedded) //&& !pStg->IsRoot() )
@@ -177,8 +179,7 @@ bool SmMLExportWrapper::Export(SfxMedium& rMedium)
xStatusIndicator->setValue(1);
bRet = WriteThroughComponentS(xStg, xModelComp, u"meta.xml", xContext, xInfoSet,
- bOASIS ? u"com.sun.star.comp.Math.XMLOasisMetaExporter"
- : u"com.sun.star.comp.Math.XMLMetaExporter");
+ u"com.sun.star.comp.Math.MLOasisMetaExporter", 6);
}
// Write starmath formula
@@ -188,8 +189,12 @@ bool SmMLExportWrapper::Export(SfxMedium& rMedium)
if (xStatusIndicator.is())
xStatusIndicator->setValue(2);
- bRet = WriteThroughComponentS(xStg, xModelComp, u"content.xml", xContext, xInfoSet,
- u"com.sun.star.comp.Math.XMLContentExporter");
+ if (pDocShell->GetSmSyntaxVersion() == 5)
+ bRet = WriteThroughComponentS(xStg, xModelComp, u"content.xml", xContext, xInfoSet,
+ u"com.sun.star.comp.Math.XMLContentExporter", 5);
+ else
+ bRet = WriteThroughComponentS(xStg, xModelComp, u"content.xml", xContext, xInfoSet,
+ u"com.sun.star.comp.Math.MLContentExporter", 6);
}
// Write starmath settings
@@ -199,10 +204,8 @@ bool SmMLExportWrapper::Export(SfxMedium& rMedium)
if (xStatusIndicator.is())
xStatusIndicator->setValue(3);
- bRet
- = WriteThroughComponentS(xStg, xModelComp, u"settings.xml", xContext, xInfoSet,
- bOASIS ? u"com.sun.star.comp.Math.XMLOasisSettingsExporter"
- : u"com.sun.star.comp.Math.XMLSettingsExporter");
+ bRet = WriteThroughComponentS(xStg, xModelComp, u"settings.xml", xContext, xInfoSet,
+ u"com.sun.star.comp.Math.MLOasisSettingsExporter", 6);
}
}
else
@@ -221,8 +224,12 @@ bool SmMLExportWrapper::Export(SfxMedium& rMedium)
// Write everything in the same place
// Note: export through an XML exporter component (output stream version)
- bRet = WriteThroughComponentOS(xOut, xModelComp, xContext, xInfoSet,
- u"com.sun.star.comp.Math.XMLContentExporter");
+ if (pDocShell->GetSmSyntaxVersion() == 5)
+ bRet = WriteThroughComponentOS(xOut, xModelComp, xContext, xInfoSet,
+ u"com.sun.star.comp.Math.XMLContentExporter", 5);
+ else
+ bRet = WriteThroughComponentOS(xOut, xModelComp, xContext, xInfoSet,
+ u"com.sun.star.comp.Math.MLContentExporter", 6);
}
if (xStatusIndicator.is())
@@ -287,7 +294,8 @@ bool SmMLExportWrapper::WriteThroughComponentOS(const Reference<io::XOutputStrea
const Reference<XComponent>& xComponent,
Reference<uno::XComponentContext> const& rxContext,
Reference<beans::XPropertySet> const& rPropSet,
- const char16_t* pComponentName)
+ const char16_t* pComponentName,
+ int_fast16_t nSyntaxVersion)
{
// We need a output stream but it is already checked by caller
// We need a component but it is already checked by caller
@@ -322,9 +330,23 @@ bool SmMLExportWrapper::WriteThroughComponentOS(const Reference<io::XOutputStrea
// connect model and filter
xExporter->setSourceDocument(xComponent);
+ Reference<XFilter> xFilter(xExporter, UNO_QUERY);
+ uno::Sequence<PropertyValue> aProps(0);
+
+ // filter
+ if (nSyntaxVersion == 5)
+ {
+ SmXMLExport* pFilter = comphelper::getUnoTunnelImplementation<SmXMLExport>(xFilter);
+ if (pFilter == nullptr)
+ {
+ SAL_WARN("starmath", "Failed to fetch SmMLExport");
+ return false;
+ }
+ xFilter->filter(aProps);
+ return pFilter->GetSuccess();
+ }
// filter
- Reference<XFilter> xFilter(xExporter, UNO_QUERY);
SmMLExport* pFilter = comphelper::getUnoTunnelImplementation<SmMLExport>(xFilter);
// Setup filter
@@ -337,7 +359,6 @@ bool SmMLExportWrapper::WriteThroughComponentOS(const Reference<io::XOutputStrea
pFilter->setElementTree(m_pElementTree);
// Execute operation
- uno::Sequence<PropertyValue> aProps(0);
xFilter->filter(aProps);
return pFilter->getSuccess();
}
@@ -348,7 +369,8 @@ bool SmMLExportWrapper::WriteThroughComponentS(const Reference<embed::XStorage>&
const char16_t* pStreamName,
Reference<uno::XComponentContext> const& rxContext,
Reference<beans::XPropertySet> const& rPropSet,
- const char16_t* pComponentName)
+ const char16_t* pComponentName,
+ int_fast16_t nSyntaxVersion)
{
// We need a storage name but it is already checked by caller
// We need a component name but it is already checked by caller
@@ -383,7 +405,7 @@ bool SmMLExportWrapper::WriteThroughComponentS(const Reference<embed::XStorage>&
// write the stuff
// Note: export through an XML exporter component (output stream version)
return WriteThroughComponentOS(xStream->getOutputStream(), xComponent, rxContext, rPropSet,
- pComponentName);
+ pComponentName, nSyntaxVersion);
}
// export through an XML exporter component (memory stream version)
@@ -407,7 +429,7 @@ SmMLExportWrapper::WriteThroughComponentMS(const Reference<XComponent>& xCompone
// write the stuff
// Note: export through an XML exporter component (output stream version)
bool bOk = WriteThroughComponentOS(xStream, xComponent, rxContext, rPropSet,
- u"com.sun.star.comp.Math.XMLContentExporter");
+ u"com.sun.star.comp.Mathml.MLContentExporter", 6);
// We don't want to read uninitialized data
if (!bOk)
@@ -444,14 +466,6 @@ Math_MLExporter_get_implementation(css::uno::XComponentContext* context,
}
extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
-Math_MLMetaExporter_get_implementation(css::uno::XComponentContext* context,
- css::uno::Sequence<css::uno::Any> const&)
-{
- return cppu::acquire(
- new SmMLExport(context, "com.sun.star.comp.Math.XMLMetaExporter", SvXMLExportFlags::META));
-}
-
-extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
Math_MLOasisMetaExporter_get_implementation(css::uno::XComponentContext* context,
css::uno::Sequence<css::uno::Any> const&)
{
@@ -460,14 +474,6 @@ Math_MLOasisMetaExporter_get_implementation(css::uno::XComponentContext* context
}
extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
-Math_MLSettingsExporter_get_implementation(css::uno::XComponentContext* context,
- css::uno::Sequence<css::uno::Any> const&)
-{
- return cppu::acquire(new SmMLExport(context, "com.sun.star.comp.Math.XMLSettingsExporter",
- SvXMLExportFlags::SETTINGS));
-}
-
-extern "C" SAL_DLLPUBLIC_EXPORT css::uno::XInterface*
Math_MLOasisSettingsExporter_get_implementation(css::uno::XComponentContext* context,
css::uno::Sequence<css::uno::Any> const&)
{
@@ -500,24 +506,19 @@ ErrCode SmMLExport::exportDoc(enum XMLTokenEnum eClass)
return ERRCODE_NONE;
}
- /* Needs to be commented out for now otherwise clang complains
- // Checks if it has to export a particular tree
- if (m_pElementTree == nullptr)
+ // Checks if it has to export a particular tree
+ if (m_pElementTree == nullptr)
+ {
+ // Set element tree
+ SmDocShell* pDocShell = getSmDocShell();
+ if (pDocShell != nullptr)
+ m_pElementTree = pDocShell->GetMlElementTree();
+ else
{
- // Set element tree
- SmDocShell* pDocShell = getSmDocShell();
- if (pDocShell != nullptr)
- {
- // TODO implement this when available
- (void)pDocShell;
- }
- else
- {
- m_bSuccess = false;
- return SVSTREAM_INVALID_PARAMETER;
- }
+ m_bSuccess = false;
+ return SVSTREAM_INVALID_PARAMETER;
}
- */
+ }
// Start document and encrypt if necessary
GetDocHandler()->startDocument();
@@ -614,7 +615,7 @@ SmMLExport::SmMLExport(const css::uno::Reference<css::uno::XComponentContext>& r
: SvXMLExport(rContext, implementationName, util::MeasureUnit::INCH, XML_MATH, nExportFlags)
, m_pElementTree(nullptr)
, m_bSuccess(true)
- , m_bUseExportTag(false)
+ , m_bUseExportTag(true)
{
}
diff --git a/starmath/source/mathml/import.cxx b/starmath/source/mathml/import.cxx
index cdb2a7487658..b16933fbff22 100644
--- a/starmath/source/mathml/import.cxx
+++ b/starmath/source/mathml/import.cxx
@@ -57,6 +57,9 @@
#include <starmathdatabase.hxx>
#include <unomodel.hxx>
+// Old parser
+#include <mathmlimport.hxx>
+
using namespace ::com::sun::star;
using namespace ::com::sun::star::beans;
using namespace ::com::sun::star::container;
@@ -187,17 +190,27 @@ ErrCode SmMLImportWrapper::Import(SfxMedium& rMedium)
xInfoSet->setPropertyValue("StreamRelPath", makeAny(aName));
}
- // Check if use OASIS
+ // Check if use OASIS ( new document format )
bool bOASIS = SotStorage::GetVersion(rMedium.GetStorage()) > SOFFICE_FILEFORMAT_60;
if (xStatusIndicator.is())
xStatusIndicator->setValue(1);
+ // Error code in case of needed
+ ErrCode nWarn = ERRCODE_NONE;
+
// Read metadata
// read a component from storage
- ErrCode nWarn = ReadThroughComponentS(rMedium.GetStorage(), xModelComp, u"meta.xml",
+ if (!bEmbedded)
+ {
+ if (bOASIS)
+ nWarn = ReadThroughComponentS(rMedium.GetStorage(), xModelComp, u"meta.xml",
xContext, xInfoSet,
- bOASIS ? u"com.sun.star.comp.Math.MLOasisMetaImporter"
- : u"com.sun.star.comp.Math.MLMetaImporter");
+ u"com.sun.star.comp.Math.MLOasisMetaImporter", 6);
+ else
+ nWarn
+ = ReadThroughComponentS(rMedium.GetStorage(), xModelComp, u"meta.xml", xContext,
+ xInfoSet, u"com.sun.star.comp.Math.XMLMetaImporter", 5);
+ }
// Check if successful
if (nWarn != ERRCODE_NONE)
@@ -214,13 +227,17 @@ ErrCode SmMLImportWrapper::Import(SfxMedium& rMedium)
// Read settings
// read a component from storage
- nWarn = ReadThroughComponentS(rMedium.GetStorage(), xModelComp, u"settings.xml", xContext,
- xInfoSet,
- bOASIS ? u"com.sun.star.comp.Math.MLOasisSettingsImporter"
- : u"com.sun.star.comp.Math.MLSettingsImporter");
+ if (bOASIS)
+ nWarn = ReadThroughComponentS(rMedium.GetStorage(), xModelComp, u"settings.xml",
+ xContext, xInfoSet,
+ u"com.sun.star.comp.Math.MLOasisSettingsImporter", 6);
+ else
+ nWarn
+ = ReadThroughComponentS(rMedium.GetStorage(), xModelComp, u"settings.xml", xContext,
+ xInfoSet, u"com.sun.star.comp.Math.XMLSettingsImporter", 5);
// Check if successful
- if (nWarn != ERRCODE_NONE)
+ if (nWarn == ERRCODE_IO_BROKENPACKAGE)
{
if (xStatusIndicator.is())
xStatusIndicator->end();
@@ -234,8 +251,14 @@ ErrCode SmMLImportWrapper::Import(SfxMedium& rMedium)
// Read document
// read a component from storage
- nWarn = ReadThroughComponentS(rMedium.GetStorage(), xModelComp, u"content.xml", xContext,
- xInfoSet, u"com.sun.star.comp.Math.MLImporter");
+ if (m_pDocShell->GetSmSyntaxVersion() == 5)
+ nWarn
+ = ReadThroughComponentS(rMedium.GetStorage(), xModelComp, u"content.xml", xContext,
+ xInfoSet, u"com.sun.star.comp.Math.XMLImporter", 5);
+ else
+ nWarn
+ = ReadThroughComponentS(rMedium.GetStorage(), xModelComp, u"content.xml", xContext,
+ xInfoSet, u"com.sun.star.comp.Math.MLImporter", 6);
// Check if successful
if (nWarn != ERRCODE_NONE)
{
@@ -262,8 +285,13 @@ ErrCode SmMLImportWrapper::Import(SfxMedium& rMedium)
// Read data
// read a component from input stream
- ErrCode nError = ReadThroughComponentIS(xInputStream, xModelComp, xContext, xInfoSet,
- u"com.sun.star.comp.Math.MLImporter", false);
+ ErrCode nError = ERRCODE_NONE;
+ if (m_pDocShell->GetSmSyntaxVersion() == 5)
+ nError = ReadThroughComponentIS(xInputStream, xModelComp, xContext, xInfoSet,
+ u"com.sun.star.comp.Math.XMLImporter", false, 5);
+ else
+ nError = ReadThroughComponentIS(xInputStream, xModelComp, xContext, xInfoSet,
+ u"com.sun.star.comp.Math.MLImporter", false, 6);
// Finish
if (xStatusIndicator.is())
@@ -271,12 +299,9 @@ ErrCode SmMLImportWrapper::Import(SfxMedium& rMedium)
// Declare any error
if (nError != ERRCODE_NONE)
- {
SAL_WARN("starmath", "Failed to read file");
- return nError;
- }
- return ERRCODE_NONE;
+ return nError;
}
}
@@ -353,7 +378,8 @@ ErrCode SmMLImportWrapper::Import(std::u16string_view aSource)
ErrCode SmMLImportWrapper::ReadThroughComponentIS(
const Reference<io::XInputStream>& xInputStream, const Reference<XComponent>& xModelComponent,
Reference<uno::XComponentContext> const& rxContext,
- Reference<beans::XPropertySet> const& rPropSet, const char16_t* pFilterName, bool bEncrypted)
+ Reference<beans::XPropertySet> const& rPropSet, const char16_t* pFilterName, bool bEncrypted,
+ int_fast16_t nSyntaxVersion)
{
// Needs an input stream but checked by caller
// Needs a context but checked by caller
@@ -409,6 +435,18 @@ ErrCode SmMLImportWrapper::ReadThroughComponentIS(
xParser->parseStream(aParserInput);
}
+ if (nSyntaxVersion == 5)
+ {
+ SmXMLImport* pXMlImport = comphelper::getUnoTunnelImplementation<SmXMLImport>(xFilter);
+ if (pXMlImport != nullptr && pXMlImport->GetSuccess())
+ return ERRCODE_NONE;
+ else
+ {
+ SAL_WARN("starmath", "Filter failed on file input");
+ return ERRCODE_SFX_DOLOADFAILED;
+ }
+ }
+
m_pMlImport = comphelper::getUnoTunnelImplementation<SmMLImport>(xFilter);
if (m_pMlImport != nullptr && m_pMlImport->getSuccess())
return ERRCODE_NONE;
@@ -479,7 +517,8 @@ ErrCode SmMLImportWrapper::ReadThroughComponentS(const uno::Reference<embed::XSt
const char16_t* pStreamName,
Reference<uno::XComponentContext> const& rxContext,
Reference<beans::XPropertySet> const& rPropSet,
- const char16_t* pFilterName)
+ const char16_t* pFilterName,
+ int_fast16_t nSyntaxVersion)
{
// Needs a storage but checked by caller
// Needs a model but checked by caller
@@ -507,7 +546,7 @@ ErrCode SmMLImportWrapper::ReadThroughComponentS(const uno::Reference<embed::XSt
// Execute read
return ReadThroughComponentIS(xStream, xModelComponent, rxContext, rPropSet, pFilterName,
- bEncrypted);
+ bEncrypted, nSyntaxVersion);
}
catch (packages::WrongPasswordException&)
{
@@ -549,7 +588,7 @@ ErrCode SmMLImportWrapper::ReadThroughComponentMS(
// Execute read
return ReadThroughComponentIS(xStream, xModelComponent, rxContext, rPropSet,
- u"com.sun.star.comp.Math.MLImporter", false);
+ u"com.sun.star.comp.Math.MLImporter", false, 6);
}
catch (packages::WrongPasswordException&)
{
@@ -568,6 +607,33 @@ ErrCode SmMLImportWrapper::ReadThroughComponentMS(
return ERRCODE_SFX_DOLOADFAILED;
}
+// SmMLImport technical
+/*************************************************************************************************/
+
+extern "C" SAL_DLLPUBLIC_EXPORT uno::XInterface*
+Math_MLImporter_get_implementation(uno::XComponentContext* pCtx,
+ uno::Sequence<uno::Any> const& /*rSeq*/)
+{
+ return cppu::acquire(
+ new SmMLImport(pCtx, "com.sun.star.comp.Math.XMLImporter", SvXMLImportFlags::ALL));
+}
+
+extern "C" SAL_DLLPUBLIC_EXPORT uno::XInterface*
+Math_MLOasisMetaImporter_get_implementation(uno::XComponentContext* pCtx,
+ uno::Sequence<uno::Any> const& /*rSeq*/)
+{
+ return cppu::acquire(new SmMLImport(pCtx, "com.sun.star.comp.Math.XMLOasisMetaImporter",
+ SvXMLImportFlags::META));
+}
+
+extern "C" SAL_DLLPUBLIC_EXPORT uno::XInterface*
+Math_MLOasisSettingsImporter_get_implementation(uno::XComponentContext* pCtx,
+ uno::Sequence<uno::Any> const& /*rSeq*/)
+{
+ return cppu::acquire(new SmMLImport(pCtx, "com.sun.star.comp.Math.XMLOasisSettingsImporter",
+ SvXMLImportFlags::SETTINGS));
+}
+
// SmMLImportContext
/*************************************************************************************************/
@@ -1163,6 +1229,8 @@ SmMLImport::CreateFastContext(sal_Int32 nElement,
{
case XML_ELEMENT(OFFICE, XML_DOCUMENT):
{
+ if (m_pElementTree == nullptr)
+ m_pElementTree = new SmMlElement(SmMlElementType::NMlEmpty);
uno::Reference<document::XDocumentPropertiesSupplier> xDPS(GetModel(),
uno::UNO_QUERY_THROW);
pContext = new SmMLImportContext(*this, &m_pElementTree);
@@ -1215,7 +1283,16 @@ void SmMLImport::endDocument()
return;
}
- // TODO handle aftermatch
+ // Check if there is element tree
+ if (m_pElementTree == nullptr)
+ {
+ m_bSuccess = true;
+ SvXMLImport::endDocument();
+ return;
+ }
+
+ // Get element tree and setup
+
if (m_pElementTree->getSubElementsCount() == 0)
{
delete m_pElementTree;
@@ -1227,9 +1304,9 @@ void SmMLImport::endDocument()
delete m_pElementTree;
m_pElementTree = pTmpElememt;
}
+ pDocShell->SetMlElementTree(m_pElementTree);
m_bSuccess = true;
-
SvXMLImport::endDocument();
}